Example #1
0
def koala(ax):
    z = 0.2714
    dat = ascii.read("../../data/koala_lc/ZTF18abvkwla_lct.csv")
    filts = np.array([val[2:3] for val in dat['filter']])

    # Plot the r-band light curve (rest-frame g)
    choose = np.logical_and(filts=='r', dat['mag'] > 0)
    jd = dat['jdobs'][choose]
    t0 = jd[0]
    dt = (jd-t0)/(1+z)
    gmag = dat['mag'][choose] - 0.115 #extinction in SDSS r
    egmag = dat['mag_unc'][choose]
    Gmag = gmag-Planck15.distmod(z=z).value+2.5*np.log10(1+z)
    ax.errorbar(
            dt, Gmag, yerr=egmag, fmt='s', c='k', lw=1, ms=5, zorder=5)
    ax.plot(dt, Gmag, c='k', lw=3, zorder=5)
    choose = np.logical_and(filts=='g', dat['mag'] == 0)
    jd = dat['jdobs'][choose]
    dt = (jd-t0)/(1+z)
    lims = dat['limmag'][choose] - 0.167 # extinction in SDSS g
    Lims = lims - Planck15.distmod(z=z).value + 2.5*np.log10(1+z)
    ax.scatter(
            dt, Lims, edgecolor='k', facecolor='white', marker='s', label=None,
            zorder=5)
    for ii,dt_val in enumerate(dt):
        ax.arrow(dt_val, Lims[ii], 0, +0.1, color='k',
                length_includes_head=True,
                head_width=0.2, head_length=0.05, label=None, zorder=5)
Example #2
0
def slsne(ax):
    """ Data points from Dan Perley """
    dat = Table.read(
        "../data/from_dan_perley.txt", delimiter='|',
        format='ascii.fast_no_header')
    cl = np.array([val.split(" ")[0] for val in dat['col7']])
    z = np.array([val[13:20] for val in dat['col7']])
    maxcol = dat['col3']
    filt = np.array([val.split(" ")[1] for val in maxcol])
    maxmag = np.array([val.split(" ")[2] for val in maxcol]).astype(float)
    timecol = dat['col6']
    rise = np.array([val[0:6] for val in timecol])
    fade = np.array([val[6:] for val in timecol])

    slind = np.where(['SLSN' in val for val in cl])[0]
    leg = True
    for ii in slind:
        bad = np.logical_or('+' in rise[ii], '+' in fade[ii])
        if bad==False: 
            timescale = float(rise[ii]) + float(fade[ii])
            if leg:
                ax.scatter(
                    timescale, maxmag[ii]-Planck15.distmod(float(z[ii])).value,
                    marker='v', color='#7570b3', label="43 SLSNe")
                leg = False
            else:
                ax.scatter(
                    timescale, maxmag[ii]-Planck15.distmod(float(z[ii])).value,
                    marker='v', color='#7570b3', label="_nolegend_")

    # Background
    x = [32+61,  29+45,  21+54,  29+25,  33+25,  13+27,  15+24,  29+49,  28+36,  21+19]
    y = [-21.78, -22.09, -22.03, -20.31, -21.94, -21.39, -20.88, -21.61, -19.90, -22.42]
    ax.scatter(x, y, marker='v', color='lightgrey', label="_nolegend_", zorder=0)
Example #3
0
def plot_98bw(ax):
    offset = 0.5
    dat = ascii.read(data_dir + "/sn1998bw.dat", delimiter=';')
    jd = dat['JD']
    rband = dat['Rcmag']
    erband = dat['e_Rcmag']
    # Extinction is 0.127 in R-band in this direction
    dm = Planck15.distmod(z=z).value - Planck15.distmod(z=0.0085).value
    ax.plot(jd - jd[0],
            rband + dm - 0.127,
            color='#e55c30',
            lw=1.5,
            label="98bw $Rc$")
    ax.plot((jd - jd[0]) / (1.0085), (rband + dm) + offset - 0.127,
            color='#e55c30',
            lw=0.5,
            ls='--',
            label="98bw $Rc$+%s mag" % offset)
    gband = dat['Bmag']
    egband = dat['e_Bmag']
    # Extinction is 0.212 in B-band in this direction
    ax.plot(jd - jd[0],
            gband + dm - 0.212,
            color='#140b34',
            lw=1.5,
            label="98bw $B$")
    ax.plot((jd - jd[0]) / (1.0085), (gband + dm) + offset - 0.212,
            color='#140b34',
            lw=0.5,
            ls='--',
            label="98bw $B$+%s mag" % offset)
    ax.axvline(x=-0.1, c='k', lw=0.5)
    ax.text(0, 18.7, 'GRB 980425', fontsize=10, rotation=270)
    def random_parameters(redshifts, model, r_v=2., ebv_rate=0.11, **kwargs):
        # Amplitude
        amp = []
        for z in redshifts:
            amp.append(10**(-0.4 * Planck15.distmod(z).value))

        if modeltype == 'DES' or viewingangle_dependece == False:
            return {
                'amplitude': np.array(amp),
                'hostr_v': r_v * np.ones(len(redshifts)),
                'hostebv': np.random.exponential(ebv_rate, len(redshifts))
            }
        elif modeltype == 'Bulla' and fixedtheta:
            return {
                'amplitude': np.array(amp),
                'theta': np.array([theta] * len(redshifts)),
                'hostr_v': r_v * np.ones(len(redshifts)),
                'hostebv': np.random.exponential(ebv_rate, len(redshifts))
            }
        elif modeltype == 'Bulla' and fixedtheta == False:
            return {
                'amplitude': np.array(amp),
                #'theta': np.random.uniform(0,90,size=len(redshifts)), # distribution of angles.Uniform distribution of theta (viewing angle) ($\^$
                'theta': np.arccos(np.random.random(len(redshifts))) / np.pi *
                180,  # distribution of angles. Sine distribution of theta (viewing angle) ($\^{circ}$)
                'hostr_v': r_v * np.ones(len(redshifts)),
                'hostebv': np.random.exponential(ebv_rate, len(redshifts))
            }
Example #5
0
def sn2009bb(ax):
    """ got this from the open SN catalog """
    ddir = "/Users/annaho/Dropbox/Projects/Research/ZTF18abukavn/data/lc"
    dat = np.loadtxt(ddir + "/sn2009bb.txt", delimiter=',', dtype='str')
    mjd = dat[:, 1].astype(float)
    mag = dat[:, 2].astype(float)
    #emag = dat[:,3].astype(float)
    band = dat[:, 5]
    dt = mjd - mjd[0]
    choose = band == 'g'
    g = mag[choose]
    gdt = dt[choose]

    choose = np.logical_or(band == 'r', band == 'R')
    r = mag[choose]
    rdt = dt[choose]

    distmod = Planck15.distmod(z=0.0104).value
    dt_grid = np.arange(0, 50, 1)
    gplt = np.interp(dt_grid, gdt, g)
    rplt = np.interp(dt_grid, rdt, r)
    gr = gplt - rplt
    ax.plot(gr,
            gplt - distmod,
            c='orange',
            lw=3,
            alpha=0.3,
            label="Radio, no GRB")
    ax.text(gr[0], gplt[0] - distmod, "SN2009bb")
Example #6
0
def at2018cow(ax,c):
    z = 0.0141
    dat = pd.read_fwf("../../data/fbot_lc/at2018cow_photometry_table.dat")
    mjd = dat['MJD']
    filt = dat['Filt']
    mag = dat['ABMag']
    emag = dat['Emag']
    choose = filt == 'g'

    xall = mjd[choose][1:].values
    yall = mag[choose][1:].values.astype(float)-0.287
    yerrall = emag[choose][1:].values.astype(float)

    # Add the i-band detection prior to peak
    xall = np.insert(xall, 0, 58286.1950)
    yall = np.insert(yall, 0, 14.32-0.147-0.7)
    yerrall = np.insert(yerrall, 0, 0.03)

    # Add the o-band detection prior to peak
    xall = np.insert(xall, 0, 58285.44)
    yall = np.insert(yall, 0, 14.70-0.198-0.4)
    yerrall = np.insert(yerrall, 0, 0.10)

    dt = xall-xall[0]
    Yall = yall-Planck15.distmod(z=0.0141).value
    ax.plot(dt, Yall, c=c)
Example #7
0
def main():
    x1 = input('Redshift:')
    z = float(x1)
    mu = Planck15.distmod(z).value
    d = 10**(mu / 5 + 1)

    x2 = input('Convert from [arsec]/coords/dist:')

    if (x2 == '') or (x2 == 'arsec'):
        x3 = input('Arcsec:')
        theta = Angle(f'0d0m{x3}s').degree

        a = d * np.tan(theta)
        print('-------------------------------------')
        print('Distance:', a, '[parsec]')

    elif x2 == 'coords':  # not ready
        ra, dec = float(x1.split()[0]), float(x1.split()[1])
        c = SkyCoord(ra=ra * u.degree, dec=dec * u.degree, frame=FK5)
        print('-------------------------------------')
        print('RA DEC (2000):', c.to_string('hmsdms'))

    elif x2 == 'dist':
        x3 = input('Distance [parsec]:')
        a = float(x3)

        theta = np.arctan(a / d)
        ang = Angle(np.arctan(a / d), unit=u.deg)
        dms = ang.to_string(unit=u.degree, sep=('deg', 'm', 's'))

        arsec = dms.split('m')[-1]
        print('-------------------------------------')
        print('Arsec:', arsec)
Example #8
0
def iptf17cw(ax):
    # R-band
    g = np.array([19.041, 19.235, 19.294, 20.93])
    r = np.array([18.703, 18.721, 18.793, 19.998])
    distmod = Planck15.distmod(z=0.093).value
    gr = g - r
    ax.plot(gr, g - distmod, c='orange', lw=3, alpha=0.3)
    ax.text(gr[0], g[0] - distmod, "iPTF17cw")
Example #9
0
def at2018gep(ax, shift=3):
    """ LC of AT2018gep
    
    shifted to the left by some number of days. 
    for example, to align with g-band max,
    you would shift the whole thing left by 3 days
    """
    DATA_DIR = "/Users/annaho/Dropbox/Projects/Research/ZTF18abukavn/data/phot"
    f = DATA_DIR + "/ZTF18abukavn_opt_phot.dat"
    dat = np.loadtxt(f, dtype=str, delimiter=' ')
    instr = dat[:, 0]
    jd = dat[:, 1].astype(float)
    zp = 2458370.6473
    dt = jd - zp - shift
    filt = dat[:, 2]
    mag = dat[:, 3].astype(float)
    emag = dat[:, 4].astype(float)
    distmod = Planck15.distmod(z=0.033).value
    choose = np.logical_and(mag < 99, filt == 'u')
    order = np.argsort(dt[choose])

    ls = ':'
    lw = 1.0

    ax.plot(dt[choose][order],
            mag[choose][order] - distmod,
            ls=ls,
            c='cyan',
            lw=lw)
    choose = np.logical_and(mag < 99, filt == 'g')
    order = np.argsort(dt[choose])
    ax.plot(dt[choose][order],
            mag[choose][order] - distmod,
            ls=ls,
            c='g',
            lw=lw)
    choose = np.logical_and(mag < 99, filt == 'r')
    order = np.argsort(dt[choose])
    ax.plot(dt[choose][order],
            mag[choose][order] - distmod,
            ls=ls,
            c='r',
            lw=lw)
    choose = np.logical_and(mag < 99, filt == 'i')
    order = np.argsort(dt[choose])
    ax.plot(dt[choose][order],
            mag[choose][order] - distmod,
            ls=ls,
            c='pink',
            lw=lw)
    choose = np.logical_and(mag < 99, filt == 'z')
    order = np.argsort(dt[choose])
    ax.plot(dt[choose][order],
            mag[choose][order] - distmod,
            ls=ls,
            c='grey',
            lw=lw)
Example #10
0
def ps1_10ah(ax):
    """ the only Drout gold transient with z < 0.1 """
    gr = np.array([0, -0.2, 0.05])
    phase = np.array([-3, 0, 14])
    g = np.array([22.18, 19.95, 21.64])
    distmod = Planck15.distmod(z=0.074).value
    G = g - distmod
    ax.plot(gr, G, ls='-', c='grey', zorder=0, lw=3, alpha=0.5)
    ax.text(gr[0], G[0], 'PS1-10ah', fontsize=12)
Example #11
0
def test_template_spectra():

    from astropy import units
    from skypy.utils.photometry import mag_ab, SpectrumTemplates
    from astropy.cosmology import Planck15
    from speclite.filters import FilterResponse

    class TestTemplates(SpectrumTemplates):
        '''Three flat templates'''
        def __init__(self):
            self.wavelength = np.logspace(-1, 4, 1000) * units.AA
            A = np.array([[2], [3], [4]]) * 0.10885464149979998
            self.templates = A * units.Unit(
                'erg s-1 cm-2 AA') / self.wavelength**2

    test_templates = TestTemplates()
    lam, flam = test_templates.wavelength, test_templates.templates

    # Gaussian bandpass
    filt_lam = np.logspace(0, 4, 1000) * units.AA
    filt_tx = np.exp(-((filt_lam - 1000 * units.AA) / (100 * units.AA))**2)
    filt_tx[[0, -1]] = 0
    FilterResponse(wavelength=filt_lam,
                   response=filt_tx,
                   meta=dict(group_name='test', band_name='filt'))

    # Each test galaxy is exactly one of the templates
    coefficients = np.eye(3)

    # Test absolute magnitudes
    mt = test_templates.absolute_magnitudes(coefficients, 'test-filt')
    m = mag_ab(lam, flam, 'test-filt')
    np.testing.assert_allclose(mt, m)

    # Test apparent magnitudes
    redshift = np.array([1, 2, 3])
    dm = Planck15.distmod(redshift).value
    mt = test_templates.apparent_magnitudes(coefficients, redshift,
                                            'test-filt', Planck15)
    np.testing.assert_allclose(mt, m - 2.5 * np.log10(1 + redshift) + dm)

    # Redshift interpolation test; linear interpolation sufficient over a small
    # redshift range at low relative tolerance
    z = np.linspace(0.1, 0.2, 3)
    m_true = test_templates.apparent_magnitudes(coefficients,
                                                z,
                                                'test-filt',
                                                Planck15,
                                                resolution=4)
    m_interp = test_templates.apparent_magnitudes(coefficients,
                                                  z,
                                                  'test-filt',
                                                  Planck15,
                                                  resolution=2)
    np.testing.assert_allclose(m_true, m_interp, rtol=1e-5)
    assert not np.all(m_true == m_interp)
Example #12
0
def d2bk(ax):
    ax = axarr[1,0]
    name = 'SNLS05D2bk'
    z = 0.699
    dm = Planck15.distmod(z=z).value
    choose = np.logical_and.reduce((names == name, ~islim, filt=='i'))
    # R-band light curve
    ax.errorbar(
            (jd[choose]-jd[choose][0])/(1+z), mag[choose]-dm,
            yerr=emag[choose].astype(float), c='k', fmt='s')
    plot_18gep(ax, 'g')
Example #13
0
def iptf15ul(ax,c):
    z = 0.066
    dat = ascii.read("../../data/fbot_lc/iptf15ul_corr.txt")
    mjd = dat['col2']
    filt = dat['col3']
    dm = Planck15.distmod(z=z).value
    mag = dat['col4']
    emag = dat['col5']
    choose = np.logical_and(filt == 'g', mag != '>')
    dt = (mjd[choose]-mjd[choose][0])/(1+z)
    dm = -21.1-min(mag[choose].astype(float))
    ax.plot(
        dt-1.2, mag[choose].astype(float)+dm+2.5*np.log10(1+z), c=c)
Example #14
0
def test_template_spectra():

    from astropy import units
    from skypy.galaxy.spectrum import mag_ab, magnitudes_from_templates
    from astropy.cosmology import Planck15

    # 3 Flat Templates
    lam = np.logspace(0, 4, 1000) * units.AA
    A = np.array([[2], [3], [4]])
    flam = A * 0.10884806248538730623 * units.Unit('erg s-1 cm-2 AA') / lam**2
    spec = specutils.Spectrum1D(spectral_axis=lam, flux=flam)

    # Gaussian bandpass
    bp_lam = np.logspace(0, 4, 1000) * units.AA
    bp_tx = np.exp(-((bp_lam - 1000 * units.AA) /
                     (100 * units.AA))**2) * units.dimensionless_unscaled
    bp = specutils.Spectrum1D(spectral_axis=bp_lam, flux=bp_tx)

    # Each test galaxy is exactly one of the templates
    coefficients = np.diag(np.ones(3))
    mt = magnitudes_from_templates(coefficients, spec, bp)
    m = mag_ab(spec, bp)
    np.testing.assert_allclose(mt, m)

    # Test distance modulus
    redshift = np.array([0, 1, 2])
    dm = Planck15.distmod(redshift).value
    mt = magnitudes_from_templates(coefficients, spec, bp, distance_modulus=dm)
    np.testing.assert_allclose(mt, m + dm)

    # Test stellar mass
    sm = np.array([1, 2, 3])
    mt = magnitudes_from_templates(coefficients, spec, bp, stellar_mass=sm)
    np.testing.assert_allclose(mt, m - 2.5 * np.log10(sm))

    # Redshift interpolation test; linear interpolation sufficient over a small
    # redshift range at low relative tolerance
    z = np.linspace(0, 0.1, 3)
    m_true = magnitudes_from_templates(coefficients,
                                       spec,
                                       bp,
                                       redshift=z,
                                       resolution=4)
    m_interp = magnitudes_from_templates(coefficients,
                                         spec,
                                         bp,
                                         redshift=z,
                                         resolution=2)
    np.testing.assert_allclose(m_true, m_interp, rtol=1e-2)
    with pytest.raises(AssertionError):
        np.testing.assert_allclose(m_true, m_interp, rtol=1e-5)
Example #15
0
def gap(ax):
    """ Data points from Dan Perley """
    dat = Table.read("../data/from_dan_perley.txt",
                     delimiter='|',
                     format='ascii.fast_no_header')
    cl = np.array([val.split(" ")[0] for val in dat['col7']])
    z = np.array([val[13:20] for val in dat['col7']])
    maxcol = dat['col3']
    filt = np.array([val.split(" ")[1] for val in maxcol])
    maxmag = np.array([val.split(" ")[2] for val in maxcol]).astype(float)
    timecol = dat['col6']
    rise = np.array([val[0:6] for val in timecol])
    fade = np.array([val[6:] for val in timecol])

    useind = np.where(['Gap' in val for val in cl])[0]
    leg = 'Ca-rich Gap'
    for ii in useind:
        bad = np.logical_or('+' in rise[ii], '+' in fade[ii])
        if bad == False:
            timescale = float(rise[ii]) + float(fade[ii])
            ax.scatter(timescale,
                       maxmag[ii] - Planck15.distmod(float(z[ii])).value,
                       marker='^',
                       c='k',
                       label=leg)
            leg = '_nolegend_'
    """ Data from KDE """
    cadata = ascii.read('../data/carich_gap.txt')
    name = cadata['Object']
    risetime = cadata['Rise']
    falltime = cadata['Fade']
    peakmag = cadata['PeakMag']

    for i in range(len(name)):
        if risetime[i] == -99 or falltime[i] == -99:
            continue
        timescale = risetime[i] + falltime[i]

        if ('ZTF' in name[i]):
            ax.scatter(timescale,
                       peakmag[i],
                       marker='^',
                       c='k',
                       label='_nolegend_',
                       zorder=5)
        else:
            ax.scatter(timescale,
                       peakmag[i],
                       marker='^',
                       c='lightgrey',
                       label='_nolegend_')
Example #16
0
def sn2002bj(ax):
    distmod = Planck15.distmod(z=0.012108).value
    dt = np.array([1, 3, 4, 5, 9, 11, 15])
    B = np.array([14.79, 14.97, 15.03, 15.15, 15.75, 16.27, 17.92])
    V = np.array([14.91, 15.03, 15.10, 15.20, 15.71, 16.04, 17.93])
    R = np.array([14.97, 15.06, 15.08, 15.21, 15.65, 16.06, 17.32])
    ax.plot(B - R,
            B - distmod,
            ls='-',
            c='purple',
            zorder=0,
            lw=3,
            alpha=0.3,
            label="SN2002bj")
Example #17
0
def drout(axarr):
    """ Comparison to the transients from Drout+14 """
    # redshift key
    z = {
        '10ah': 0.074,
        '10bjp': 0.113,
        '11qr': 0.324,
        '12bb': 0.101,
        '12bv': 0.405,
        '12brf': 0.275,
        '11bbq': 0.646,
        '13duy': 0.270,
        '13dwm': 0.245,
        '13ess': 0.296
    }
    inputf = ddir + "/drout14.txt"
    dat = np.loadtxt(inputf, delimiter=';', dtype=str)
    names = np.array([val.strip() for val in dat[:, 0]])
    unames = np.unique(names)
    for ii, ax in enumerate(axarr.reshape(-1)):
        name = unames[ii]
        choose = names == name
        redshift = z[name]
        # only do this if there is a known redshift
        filt = np.array(dat[:, 1][choose]).astype(str)
        dt = dat[:, 2][choose].astype(float)
        islim = dat[:, 3][choose]
        mag = dat[:, 4][choose].astype(float)
        distmod = Planck15.distmod(z=redshift).value
        isdet = np.array([val == " " for val in islim])
        isfilt = np.array(['g' in val for val in filt])
        c = np.logical_and(isdet, isfilt)
        ax.plot(dt[c], mag[c] - distmod, ls='-', c='g')
        isfilt = np.array(['r' in val for val in filt])
        c = np.logical_and(isdet, isfilt)
        ax.plot(dt[c], mag[c] - distmod, ls='-', c='r')
        isfilt = np.array(['i' in val for val in filt])
        c = np.logical_and(isdet, isfilt)
        ax.plot(dt[c], mag[c] - distmod, ls='-', c='pink')
        isfilt = np.array(['z' in val for val in filt])
        c = np.logical_and(isdet, isfilt)
        ax.plot(dt[c], mag[c] - distmod, ls='-', c='grey')
        ax.text(0.9,
                0.9,
                'PS1-%s' % name,
                fontsize=12,
                transform=ax.transAxes,
                horizontalalignment='right',
                verticalalignment='top')
Example #18
0
def core_collapse(ax):
    """ Light curves of CC SNe from RCF provided by Yashvi Sharma """
    # Load the table of events
    df = pd.read_csv("../data/ccsne/ccsne_final_new.csv")
    keep = df['redshift'] != 'None'

    nearby = df['redshift'][keep].astype(float) < 0.05
    sampled = df['numpoints_lc'][keep] > 50
    choose = np.logical_and(nearby, sampled)
    z = df['redshift'][keep].values[choose].astype(float)

    # Load the array of light curves
    lcs = np.load("../data/ccsne/ccsne_lcs_new.npy",
                  allow_pickle=True,
                  encoding='latin1')
    lcs = lcs[keep][choose]

    # Plot one of them
    leg = True
    for ii in np.arange(sum(choose)):
        lc = lcs[ii]
        filt = lc['filter']
        jd = lc['jd']
        mag = lc['mag']
        gband = filt == 'g'
        if sum(gband) > 30:
            x = jd[gband] - jd[gband].values[0]
            y = mag[gband]
            peakmag = np.min(mag)
            thalf = np.interp(peakmag + 0.75, y, x)
            absmag = peakmag - Planck15.distmod(z=z[ii]).value
            if leg:
                ax.scatter(thalf,
                           absmag,
                           c='cornflowerblue',
                           marker='s',
                           zorder=0,
                           s=12,
                           label="871 CC SNe")
                leg = False
            else:
                ax.scatter(thalf,
                           absmag,
                           c='cornflowerblue',
                           marker='s',
                           zorder=0,
                           s=12,
                           label="_nolegend_")
            leg = False
Example #19
0
def iptf16asu(ax,c):
    z = 0.187
    dat = pd.read_fwf("../../data/fbot_lc/iptf16asu.txt")
    filt = dat['filt']
    # choose = filt == 'r'
    # dt = dat['dt'][choose] / (1+z)
    # mag = dat['mag'][choose]
    # Mag = mag[0:10].astype(float) - Planck15.distmod(z=z).value + 2.5*np.log10(1+z)
    # ax.plot(dt[0:10], Mag, c=c)

    choose = filt == 'g'
    dt = dat['dt'][choose] / (1+z)
    mag = dat['mag'][choose][16:30].astype(float).values
    Mag = mag - Planck15.distmod(z=z).value + 2.5*np.log10(1+z)
    ax.plot(dt[16:30]+3, Mag, c=c)
Example #20
0
def plot_18gep(ax, band, c='k'):
    """ Plot 18gep lc for a given band """
    z = 0.03154
    dm = Planck15.distmod(z=z).value
    dt_gep, filt_gep, mag_gep, emag_gep = get_lc()
    isdet_gep = np.logical_and(mag_gep<99, ~np.isnan(mag_gep))
    choose = np.logical_and(filt_gep == band, isdet_gep)
    x = dt_gep[choose]/(1+z)
    y = mag_gep[choose]-dm
    # ax.errorbar(x, y,
    #         yerr=emag_gep[choose],
    #         c='k', fmt='s')
    order = np.argsort(x)
    ax.plot(
            x[order], y[order], c=c, 
            lw=0.5, label="18gep, $%s$" %band, ls='--')
Example #21
0
def short_log_likelihood(params):
    alpha = params[0]
    beta = params[1]
    MB = params[2]
    sigma_int = params[3]
    omega_m = params[4]

    if omega_m < 0:
        return -np.inf
    if sigma_int < 0:
        return -np.inf

    cosmo = FlatLambdaCDM(H0=70, Om0=omega_m)
    mu_cosmo = cosmo.distmod(z).value
    dmu = mb_obs - mu_cosmo - MB + alpha * x1_obs - beta * c_obs
    dmue = np.sqrt(mbe**2 + (alpha * x1e)**2 + (beta * ce)**2 + sigma_int**2)
    return -0.5 * np.sum((dmu / dmue)**2) - 0.5 * np.sum(np.log(dmue**2))
Example #22
0
def at2018cow(ax):
    distmod = Planck15.distmod(z=0.014).value
    DATA_DIR = "/Users/annaho/Dropbox/Projects/Research/ZTF18abukavn/data/lc"
    f = DATA_DIR + "/18cow.txt"
    dat = np.loadtxt(f, dtype=str)
    jd = dat[:, 0].astype(float)
    filt = dat[:, 2]
    mag = dat[:, 4].astype(float)
    emag = dat[:, 5].astype(float)

    zp = 58285
    dt = jd - zp
    print(dt)

    tgrid = np.arange(dt[0], 30, 1)

    band = filt == 'g'
    choose = band
    order = np.argsort(dt[choose])
    g = np.interp(tgrid, dt[choose][order], mag[choose][order])

    band = filt == 'r'
    choose = band
    order = np.argsort(dt[choose])
    r = np.interp(tgrid, dt[choose][order], mag[choose][order])

    gr = g - r
    xdata = gr
    ydata = g - distmod
    ax.plot(xdata, ydata, c='k', ls='--', lw=2, zorder=2)
    markt = np.array([1.8, 10, 20])
    labs = np.array(["1 day", "10 days", "20 days"])
    cols = np.array(['#e55c30', '#84206b', '#140b34'])
    for ii, t in enumerate(markt):
        prevptx = np.interp(t - 0.1, tgrid, xdata)  #xdata[tgrid<t][-1]
        prevpty = np.interp(t - 0.1, tgrid, ydata)  #ydata[tgrid<t][-1]
        newptx = np.interp(t, tgrid, xdata)
        newpty = np.interp(t, tgrid, ydata)
        ax.annotate('',
                    xytext=(prevptx, prevpty),
                    xy=(newptx, newpty),
                    arrowprops=dict(color=cols[ii], width=1, headlength=10))
        # ax.text(newptx, newpty, "$\Delta t$= %s" %labs[ii], fontsize=12,
        #         horizontalalignment='left', verticalalignment='top')
    ax.text(-0.37, -20.4, "AT2018cow", fontsize=14)
Example #23
0
def snls05d2bk(ax, c):
    z = 0.699
    mw_ext = 0.029

    dat = pd.read_fwf("../../data/fbot_lc/SNLS05D2bk.txt")
    jd = dat['JD']
    filt = dat['F']
    mag = dat['mag']
    emag = dat['emag']

    choose = filt == 'i'
    xall = jd[choose][0:-2].values.astype(float)
    yall = mag[choose][0:-2].values.astype(float)
    yerrall = emag[choose][0:-2].values.astype(float)
    ax.plot(
            (xall-xall[0]-4)/(1+z), 
            yall-mw_ext-Planck15.distmod(z=z).value+2.5*np.log10(1+z), 
            c=c)
Example #24
0
def d4ec(ax):
    ax = axarr[0,1]
    name = 'SNLS04D4ec'
    z = 0.593
    offset = 3
    dm = Planck15.distmod(z=z).value
    choose = np.logical_and.reduce((names == name, ~islim, filt=='i'))
    ax.errorbar(
            (jd[choose]-jd[choose][0])/(1+z)+offset, mag[choose]-dm,
            yerr=emag[choose].astype(float), mec='k', mfc='white', fmt='s',
            label="D4ec, $i$", c='k')
    choose = np.logical_and.reduce((names == name, ~islim, filt=='g'))
    ax.errorbar(
            (jd[choose]-jd[choose][0])/(1+z)+offset, mag[choose]-dm,
            yerr=emag[choose].astype(float), mec='k', mfc='white', fmt='D',
            label="D4ec, $i$", c='k')
    plot_18gep(ax, 'g')
    plot_18gep(ax, 'UVW1', c='grey')
Example #25
0
def ksn2015k(ax):
    diff = Planck15.distmod(z=0.09).value
    gr = -0.17
    G = 20.01 - diff
    ax.errorbar(gr,
                G,
                xerr=0.20,
                yerr=0.12,
                fmt='v',
                c='#84206b',
                mfc='#84206b',
                ms=12,
                label=None)
    ax.text(gr,
            G,
            "KSN2015K",
            fontsize=14,
            horizontalalignment='right',
            verticalalignment='bottom')
Example #26
0
def full_log_likelihood(params):
    alpha = params[0]
    beta = params[1]
    MB = params[2]
    sigma_int = params[3]
    meanx = params[4]
    meanc = params[5]
    sigpriorx = params[6]
    sigpriorc = params[7]
    if sigma_int < 0:
        return -np.inf
    if sigpriorx < 0:
        return -np.inf
    if sigpriorc < 0:
        return -np.inf

    cosmomu = cosmo.distmod(z).value
    return np.sum(
        negtwoLL(alpha, beta, cosmomu, MB, mb_obs, x1_obs, c_obs, mbe**2,
                 sigma_int**2, x1e**2, ce**2, 0.0, 0.0, 0.0, meanx, meanc,
                 sigpriorx**2, sigpriorc**2)) / (-2.0)
Example #27
0
def sn2006aj(ax):
    t0 = Time('2006-02-18').mjd + 0.149
    t = np.array([
        Time('2006-02-20').mjd + 0.162,
        Time('2006-02-21').mjd + 0.196,
        Time('2006-02-23').mjd + 0.196,
        Time('2006-02-25').mjd + 0.112,
        Time('2006-02-27').mjd + 0.167,
        Time('2006-03-04').mjd + 0.097
    ])
    dt = t - t0
    V = np.array([17.84, 17.73, 17.30, 17.10, 17.0, 17.09])
    R = np.array([17.76, 17.22, 17.22, 16.96, 16.84, 16.88])
    gr = V - R
    distmod = Planck15.distmod(z=0.033023).value
    plt.scatter(gr,
                V - distmod,
                marker='o',
                edgecolor='orange',
                facecolor='white',
                label='Ic-BL')
    plt.plot(gr, V - distmod, c='orange')
Example #28
0
def sn2007ru(ax):
    """ got this from the open SN catalog """
    ddir = "/Users/annaho/Dropbox/Projects/Research/ZTF18abukavn/data/lc"
    dat = np.loadtxt(ddir + "/sn2007ru.txt", delimiter=',', dtype='str')
    mjd = dat[:, 1].astype(float)
    mag = dat[:, 2].astype(float)
    band = dat[:, 5]
    dt = mjd - mjd[0]

    choose = band == 'V'
    g = mag[choose]
    gdt = dt[choose]

    choose = np.logical_or(band == 'R_c', band == "r'")
    r = mag[choose]
    rdt = dt[choose]

    distmod = Planck15.distmod(z=0.0593).value
    dt_grid = np.arange(5, 34, 1)
    gplt = np.interp(dt_grid, gdt, g)
    rplt = np.interp(dt_grid, rdt, r)
    gr = gplt - rplt
    ax.plot(gr, gplt - distmod, c='purple', lw=3, alpha=0.3)
    ax.text(gr[1], gplt[1] - distmod, "SN2010bh", horizontalalignment='right')
Example #29
0
def novae(ax):
    """ Data points from Dan Perley """
    dat = Table.read("../data/from_dan_perley.txt",
                     delimiter='|',
                     format='ascii.fast_no_header')
    cl = np.array([val.split(" ")[0] for val in dat['col7']])
    maxcol = dat['col3']
    filt = np.array([val.split(" ")[1] for val in maxcol])
    maxmag = np.array([val.split(" ")[2] for val in maxcol]).astype(float)
    timecol = dat['col6']
    rise = np.array([val[0:6] for val in timecol])
    fade = np.array([val[6:] for val in timecol])

    useind = np.where(
        [np.logical_or('nova' in val, 'Nova' in val) for val in cl])[0]
    leg = '6 Novae'
    for ii in useind:
        bad = np.logical_or('+' in rise[ii], '+' in fade[ii])
        if bad == False:
            timescale = float(rise[ii]) + float(fade[ii])
            lum = maxmag[ii] - Planck15.distmod(z=0.000177).value
            if timescale > 3:
                ax.scatter(timescale, lum, marker='*', c='k', label=leg)
                leg = '_nolegend_'
Example #30
0
if __name__ == "__main__":
    fig, ax = plt.subplots(1, 1, figsize=(7, 6))

    load_lc(ax)
    plot_98bw(ax)

    ax.set_xlabel("Days (Rest-frame) Since Last Non-Detection of ZTF18aaqjovh",
                  fontsize=16)
    ax.set_ylabel("Apparent Mag (AB)", fontsize=16)
    ax.set_ylim(17.5, 21.5)
    ax.set_xlim(-1, 52)
    ax.tick_params(axis='both', labelsize=14)
    ax.invert_yaxis()
    #ax2.invert_yaxis()

    # Put a twin axis with the absolute magnitude
    ax2 = ax.twinx()
    y_f = lambda y_i: y_i - Planck15.distmod(z=z).value
    ymin, ymax = ax.get_ylim()
    ax2.set_ylim((y_f(ymin), y_f(ymax)))
    ax2.plot([], [])
    ax2.tick_params(axis='both', labelsize=14)
    ax2.set_ylabel("Absolute Mag (AB)", fontsize=16, rotation=270, va='bottom')
    ax2.set_xlim(-1, 52)

    ax.legend(loc='lower center', fontsize=12, ncol=2)
    fig.tight_layout()
    #plt.show()
    plt.savefig('lc.eps', dpi=300)