sncosmo.read_lc(file_or_dir, format='ascii', **kwargs)[source]

Read light curve data for a single supernova.


Filename (formats ‘ascii’, ‘json’, ‘salt2’) or directory name (format ‘salt2-old’). For ‘salt2-old’ format, directory must contain a file named ‘lightfile’. All other files in the directory are assumed to be photometry files, unless the filenames keyword argument is set.

format{‘ascii’, ‘json’, ‘salt2’, ‘salt2-old’}, optional

Format of file. Default is ‘ascii’. ‘salt2’ is the new format available in snfit version >= 2.3.0.

read_covmatbool, optional

[salt2 only] If True, and if a COVMAT keyword is present in header, read the covariance matrix from the filename specified by COVMAT (assumed to be in the same directory as the lightcurve file) and include it as a column named Fluxcov in the returned table. Default is False.

New in version 1.5.0

expand_bandsbool, optional

[salt2 only] If True, convert band names into equivalent Bandpass objects. This is particularly useful for position-dependent bandpasses in the salt2 file format: the position information is read from the header and used when creating the bandpass objects.

New in version 1.5.0

delimstr, optional

[ascii only] Used to split entries on a line. Default is None. Extra whitespace is ignored.

metacharstr, optional

[ascii only] Lines whose first non-whitespace character is metachar are treated as metadata lines, where the key and value are split on the first whitespace. Default is '@'

commentcharstr, optional

[ascii only] One-character string indicating a comment. Default is ‘#’.

filenameslist, optional

[salt2-old only] Only try to read the given filenames as photometry files. Default is to try to read all files in directory.

tastropy Table

Table of data. Metadata (as an OrderedDict) can be accessed via the t.meta attribute. For example: t.meta['key']. The key is case-sensitive.


Read an ascii format file that includes metadata (StringIO behaves like a file object):

>>> from io import StringIO
>>> f = StringIO('''
... @id 1
... @RA 36.0
... @description good
... time band flux fluxerr zp zpsys
... 50000. g 1. 0.1 25. ab
... 50000.1 r 2. 0.1 25. ab
... ''')
>>> t = read_lc(f, format='ascii')
>>> print(t)
  time  band flux fluxerr  zp  zpsys
------- ---- ---- ------- ---- -----
50000.0    g  1.0     0.1 25.0    ab
50000.1    r  2.0     0.1 25.0    ab
>>> t.meta
OrderedDict([('id', 1), ('RA', 36.0), ('description', 'good')])