Exemplo n.º 1
0
def test_fitzpatrick99_r_v():
    """Test that we can access the `r_v` attribute."""

    f = extinction.Fitzpatrick99()
    assert f.r_v == 3.1
    f = extinction.Fitzpatrick99(2.1)
    assert f.r_v == 2.1
Exemplo n.º 2
0
def get_F99(this_rest_lambs):
    ff = extinction.Fitzpatrick99(3.1)
    fprime = extinction.Fitzpatrick99(3.11)
    F99_31 = ff(this_rest_lambs, 3.1)
    F99_dAdRV = (fprime(this_rest_lambs, 3.11) - F99_31) / 0.01

    return F99_31, F99_dAdRV
Exemplo n.º 3
0
def get_jacobian(rest_waves, redshift, params, electrons_per_sec, fund_cal_fns,
                 crnl_fns):

    # "PSF_wghtd_e_allbutdark"

    if redshift > 0.1:
        EBV_step = 0.01 * params["mw_norm"]
    else:
        EBV_step = 0.05 * params["mw_norm"]

    jacobian = []
    jacobian_names = []

    for fund_cal_fn in fund_cal_fns:
        jacobian.append(fund_cal_fn(rest_waves * (1. + redshift)))
        jacobian_names.append("Fundamental Calibration")

    for crnl_fn in crnl_fns:
        jacobian.append(crnl_fn(electrons_per_sec))
        jacobian_names.append("Count-Rate Nonlinearity")

    ff = extinction.Fitzpatrick99(3.1)
    jacobian.append(ff(rest_waves * (1. + redshift), 3.1 * EBV_step))
    jacobian_names.append("MW Extinction Normalization")

    jacobian.append(
        ff(rest_waves * (1. + redshift), 3.1 * params["mw_zeropoint"])
    )  # Independent zeropoint uncertainty of this in E(B-V)
    jacobian_names.append("MW Extinction Zeropoint")

    if redshift < 0.1:  # R_V uncertainty of 0.2; E(B-V) of 0.01; ignore nearby SNe as these are spread on sky.
        jacobian.append([0] * rest_waves)
    else:
        R_V_prime = 3.1 - params["mw_RV_uncertainty"]
        ff_prime = extinction.Fitzpatrick99(R_V_prime)

        jacobian.append(
            ff_prime(rest_waves * (1. + redshift), 3.1 * EBV_step) -
            ff(rest_waves * (1. + redshift), 3.1 * EBV_step))
    jacobian_names.append("MW Extinction $R_V$")

    jacobian.append(
        getIGextinction(redshift, rest_waves) * params["ig_extinction"])
    jacobian_names.append("IG Extinction")

    jacobian = transpose(array(jacobian))
    #save_img(jacobian, "jacobian.fits")

    return jacobian, jacobian_names
Exemplo n.º 4
0
def test_fitzpatrick99_rv_knots():
    """Test that Fitzpatrick function has the right R_V dependence at
    the knots."""

    wave = np.array([26500., 12200., 6000., 5470., 4670., 4110.])

    # "the IR points at 1/lambda < 1 invum are simply scaled by R/3.1"
    # "the optical points are vertically offset by an amount R - 3.1 , with
    # slight corrections made to preserve the normalization"

    for r in [1., 2., 3., 4., 5., 6.]:
        # `expected` gives expected A(lambda) for E(B-V) = 1 (A_V = R)
        expected = [
            r / 3.1 * 0.265,  # Table 3 scaled by R/3.1
            r / 3.1 * 0.829,  # Table 3 scaled by R/3.1
            -0.426 + 1.0044 * r,  # Table 4
            -0.050 + 1.0016 * r,  # Table 4
            0.701 + 1.0016 * r,  # Table 4
            1.208 + 1.0032 * r - 0.00033 * r**2
        ]  # Table 4

        result = extinction.Fitzpatrick99(r)(wave, r)

        # Note that we don't expect an exact match because, as noted in the
        # code, "the optical spline points are not taken from F99 table 4,
        # but rather updated versions from E. Fitzpatrick (matching the IDL
        # astrolib routine FM_UNRED).
        assert_allclose(result, expected, rtol=0.003)
Exemplo n.º 5
0
def test_fitzpatrick99_func():
    """Check passing R_V."""

    wave = np.array([2000., 30000.])
    for r_v in (3.1, 4.0):
        assert np.all(
            extinction.Fitzpatrick99(r_v)(wave, 1.0) ==
            extinction.fitzpatrick99(wave, 1.0, r_v))
Exemplo n.º 6
0
def test_fitzpatrick99_idl():
    """Test that result matches implementation in IDL procedure FM_UNRED"""

    for r_v in (2.3, 3.1, 4.0, 5.3):
        fname = os.path.join('testdata', 'fm_unred_{:3.1f}.dat'.format(r_v))
        wave, a_lambda_ref = np.loadtxt(fname, unpack=True)
        a_lambda = extinction.Fitzpatrick99(r_v)(wave, 1.0)
        assert_allclose(a_lambda, a_lambda_ref, rtol=0.00005)
Exemplo n.º 7
0
import extinction
import astropy.io.ascii as ascii
import numpy as np
f=extinction.Fitzpatrick99(1.766)
A_lamda=f(np.array([4400,5400,6500,8100]),1.06)
mwdust=[0.123, 0.095, 0.076, 0.055]

bandlist  = ['B', 'V', 'R', 'I']#,'g','r','i']#, 'J', 'H', 'K']

incat1=incat[incat['DET']=='Y'] # use data detected only
Rcat=incat1[incat1['FILTER']=='R']
Vcat=incat1[incat1['FILTER']=='V']
Bcat=incat1[incat1['FILTER']=='B']
Icat=incat1[incat1['FILTER']=='I']

B1cat=Bcat[(Bcat['MJD']>Tmax-10) & (Bcat['MJD']<Tmax+20)]
x_data    = B1cat['MJD']
y_data    = B1cat['MAG']
yerr_data = B1cat['MAGERR']


Rv=1.766

def EarlyFit1(incat_name='hgDcSN2019ein.LCfinal.txt', fitcat_name='SN2019ein-PolyFitRes.dat'):
    """
    multi band, calculate T0
    Minimize the sum of the square of the residual.
    """
    case = 1
    # Polynomial or Spline fitting result
    fitcat = ascii.read(fitcat_name)
Exemplo n.º 8
0
Arquivo: ml.py Projeto: jpierel14/sntd
 def __init__(self, r_v=3.1):
     self._param_names = ['ebv']
     self.param_names_latex = ['E(B-V)']
     self._parameters = np.array([0.])
     self._r_v = r_v
     self._f = extinction.Fitzpatrick99(r_v=r_v)
Exemplo n.º 9
0
def fitExtBlackbod(waves,
                   fluxes,
                   fluxerrs=None,
                   EBV=None,
                   Rv=3.1,
                   plot=False,
                   ptitle=""):

    import extinction as extn
    from scipy.optimize import curve_fit
    import astropy.units as u

    if EBV is None:
        #blackbody+extinction(Rv=3.1) flux function
        #exBBflux = lambda x, T, r, EBV: extn.apply(extn.fm07(x*u.AA, EBV*3.1), planck(x,T)*r)
        exBBflux = lambda x, T, r, EBV: extn.apply(
            extn.Fitzpatrick99(Rv)(x * u.AA, Rv * EBV),
            planck(x, T) * r)
        #estimate temperature
        est = [10000.0, 1e20, 10]
    else:
        #exBBflux = lambda x, T, r: extn.apply(extn.fm07(x*u.AA, EBV*3.1), planck(x,T)*r)
        exBBflux = lambda x, T, r: extn.apply(
            extn.Fitzpatrick99(Rv)(x * u.AA, Rv * EBV),
            planck(x, T) * r)
        est = [10000.0, 1e25]
        if EBV < 0:
            est = [1000.0, 1e18]
        else:
            est = [10000.0, 1e20]

    #fit blackbody temperature
    if fluxerrs is not None:
        popt, pcov = curve_fit(exBBflux,
                               waves,
                               fluxes,
                               sigma=fluxerrs,
                               p0=est,
                               absolute_sigma=True,
                               maxfev=1000000)
    else:
        popt, pcov = curve_fit(exBBflux,
                               waves,
                               fluxes,
                               p0=est,
                               maxfev=10000000)
    perr = np.sqrt(np.diag(pcov))
    T, Terr = popt[0], perr[0]  #K
    r, rerr = popt[1], perr[1]  #dimensionless
    if EBV is None:
        EBV, EBVerr = popt[2], perr[2]  #mag
        print "E(B-V) for Rv=" + str(Rv) + ":", EBV, EBVerr
        print "T=", T, Terr
    else:
        EBVerr = 0
    #plot fit if given
    if plot:
        import matplotlib.pyplot as plt

        print "Temperature [K]:", T, Terr
        print "Received/Emitted:", r, rerr
        if fluxerrs is not None:
            plt.errorbar(waves, fluxes, yerr=fluxerrs, fmt='g+')
        else:
            plt.plot(waves, fluxes, color='g')
        w = np.linspace(min(waves), max(waves), 100)
        plt.plot(
            w,
            exBBflux(w, *popt),
            c='r',
            label=
            "T = {:.0f} ({:.0f}) K\nr = {:.3f} ({:.3f})\nEBV = {:.3f} ({:.3f})"
            .format(T, Terr, r, rerr, EBV, EBVerr))
        #plt.plot(w, extn.remove(extn.fm07(w*u.AA, EBV*3.1), exBBflux(w, *popt)), c='b',
        #         label="dereddened")
        plt.xlabel("Wavelength [A]")
        plt.ylabel("Flux")
        plt.title(ptitle)
        plt.legend(loc='lower right')
        plt.tight_layout()
        plt.show()
    w = np.linspace(min(waves), max(waves), 100)
    #return blackbody temperature
    return T, Terr, r, rerr, EBV, EBVerr, w, exBBflux(w, *popt)