Exemplo n.º 1
0
def read_and_eval(interpfns):
    f = fits.open("input/LSST_Ia_HEAD.FITS")
    head = f[1].data
    f.close()

    dat = sncosmo.read_snana_fits("input/LSST_Ia_HEAD.FITS", "input/LSST_Ia_PHOT.FITS")
    pdf = PdfPages("LC_plots.pdf")

    for i in range(len(head.PEAKMJD)):
        if (head.REDSHIFT_HELIO[i] > 0.4) and (head.REDSHIFT_HELIO[i] < 0.6):
            plt.figure()

            phase = (dat[i]["MJD"] - head.PEAKMJD[i])/(1. + head.REDSHIFT_HELIO[i])
            
            errs = LC_eval(interpfns, phase, magerr = dat[i]["MAGERR"], filt = dat[i]["FLT"], redshift = head.REDSHIFT_HELIO[i])
            
            for filt in 'ugrizY':
                inds = np.where((dat[i]["FLT"] == filt)*(dat[i]["MAGERR"] > 0))
                plt.plot(phase[inds], dat[i]["MAGERR"][inds], '.', color = {'u': 'm', 'g': 'b', 'r': 'cyan', 'i': 'g', 'z': 'orange', 'Y': 'r'}[filt], label = filt)
            plt.legend(loc = 'best')
            plt.ylim(0, 0.2)
            title = "$\sigma$Mag=%.3f" % errs[0]
            for pc in range(1,5):
                title += " $\sigma$PC%i=%.3f" % (pc, errs[pc])

            plt.title(title)
            plt.xlabel("Phase")
            plt.ylabel("Mag Err")
            pdf.savefig(plt.gcf(), bbox_inches = 'tight')
    pdf.close()
Exemplo n.º 2
0
    def fromSNANAfileroot(cls, snanafileroot, location='./', snids=None,
                          n=None):
        """
        Class constructor from a root file and a location

        Parameters
        ----------
        snanafileroot : string, mandatory
            root file name for the SNANA which is the prefix to
            '_HEAD.FITS', or '_PHOT.FITS'
        location : string, optional defaults to current working directory './' 
            Relative or absolute path to the directory where the head and phot
            files are located
        snids : integer/string, optional defaults to None
            if not None, only SN observations corresponding to SNID snid
            are loaded
        n : Integer, defaults to None
            if not None, only the first n SN light curves are loaded
        """

        headfile = cls.snanadatafile(snanafileroot, filetype='head',
                                     location=location)
        photfile = cls.snanadatafile(snanafileroot, filetype='phot',
                                     location=location)
        print headfile
        data = sncosmo.read_snana_fits(head_file=headfile,
                                       phot_file=photfile,
                                       snids=snids, n=n)
        return cls(headFile=headfile, photFile=photfile, snids=snids,
                   n=n)
Exemplo n.º 3
0
def get_sndataset(headfile):
    photfile = headfile.replace('HEAD', 'PHOT')
    sndataset = sncosmo.read_snana_fits(headfile, photfile)
    for i in xrange(len(sndataset)):
        sndataset[i] = standardize_sn_data(sndataset[i],
                                           headfile=os.path.basename(headfile))
    return sndataset
Exemplo n.º 4
0
def get_test_sn(headfile='random', snid='random', verbose=True):
    if headfile == 'random':
        headfilelist = glob('data/*HEAD.FITS')
        headfile = choice(headfilelist)

    if snid == 'random':
        # Get metadata for all the SNe
        head_data = pyfits.getdata(headfile, 1, view=np.ndarray)

        # Strip trailing whitespace characters from SNID.
        if 'SNID' in head_data.dtype.names:
            snidlist = np.char.strip(head_data['SNID'])
            snid = choice(snidlist)

    sndataset = sncosmo.read_snana_fits(headfile,
                                        headfile.replace('HEAD', 'PHOT'),
                                        snids=[str(snid)])
    sn = sndataset[0]
    if verbose:
        print "SNID=%s from %s" % (snid, os.path.basename(headfile))
        excludelist = get_sncosmo_excludelist(sn)
        if excludelist:
            modelname = excludelist[0]
        elif sn.meta['SIM_NON1a']:
            modelname = 'NON1a.%03i' % sn.meta['SIM_MODEL_INDEX']
        else:
            modelname = sn.meta['SIM_MODEL_NAME']
        print "Type=%s  model=%s" % (sn.meta['SIM_TYPE_NAME'].strip(),
                                     modelname)
    return sn
Exemplo n.º 5
0
def loadSNANAData(snanafileroot, location='/.', snids=None, n=None):
    '''
    load a SNANA fits file into a list of `~astropy.Table.table` objects.
    
    
    Parameters
    ----------
    snanafileroot: string, mandatory
        root file name for the SNANA which is the prefix to '_HEAD.FITS', or '_PHOT.FITS'
    location: string, optional defaults to current working directory './' 
        directory where the head and phot files are located
    snids: integer/string, optional defaults to None
        if not None, only SN observations corresponding to SNID snid are loaded
    n: Integer, defaults to None
        if not None, only the first n SN light curves are loaded
        
        
    Returns: data
        list of `~astropy.Table.Table` each Table containing a light curve of a SN. 
        
    ..note: The column names of the SNANA data files are not reformated for SNCosmo use
    '''
    headfile = snanadatafile(snanafileroot, filetype='head', location=location)
    photfile = snanadatafile(snanafileroot, filetype='phot', location=location)
    data = sncosmo.read_snana_fits(head_file=headfile, phot_file=photfile, snids=snids, n=None)
    return data
Exemplo n.º 6
0
    def __init__(self, headfile, photfile, snids=None, n=None):
        """
        Instantiate class from SNANA simulation output files in fits format

        Parameters
        ----------
        snids : integer/string, optional defaults to None
            if not None, only SN observations corresponding to SNID snid
            are loaded
        n : Integer, defaults to None
            if not None, only the first n SN light curves are loaded


        ..note: The column names of the SNANA data files are not reformated
                 for SNCosmo use


        """
        self.snList = sncosmo.read_snana_fits(
            head_file=headfile, phot_file=photfile, snids=snids, n=n)
Exemplo n.º 7
0
def test_read_snana_fits():
    fname1 = join(dirname(__file__), "data", "snana_fits_example_head.fits")
    fname2 = join(dirname(__file__), "data", "snana_fits_example_phot.fits")
    sne = sncosmo.read_snana_fits(fname1, fname2)
    assert len(sne) == 2
def test_read_snana_fits():
    fname1 = join(dirname(__file__), "data", "snana_fits_example_head.fits")
    fname2 = join(dirname(__file__), "data", "snana_fits_example_phot.fits")
    sne = sncosmo.read_snana_fits(fname1, fname2)
    assert len(sne) == 2