In [1]:
import sncosmo
import json
import os
import numpy as np
from astropy.units import Unit

In [2]:
d = {'test': 'i work!'}

In [3]:
d


Out[3]:
{'test': 'i work!'}

In [4]:
type(d)


Out[4]:
dict

In [5]:
with open('result.json', 'w') as fp:
    json.dump(d, fp)

In [6]:
with open('result.json', 'r') as fp:
    results = json.load(fp)

In [7]:
results


Out[7]:
{u'test': u'i work!'}

In [8]:
type(results)


Out[8]:
dict

Is this the same thing as my original dict?


In [9]:
d == results


Out[9]:
True

So this method is okay? Should I close the file pointer like in C?


In [10]:
bandPassList = ['u', 'g', 'r', 'i', 'z', 'y']
banddir = os.path.join(os.getenv('THROUGHPUTS_DIR'), 'baseline')
# lsstbands = list()
# lsstbp = dict()

for band in bandPassList:

    # setup sncosmo bandpasses
    bandfname = banddir + "/total_" + band + '.dat'


    # register the LSST bands to the SNCosmo registry
    # Not needed for LSST, but useful to compare independent codes
    # Usually the next two lines can be merged,
    # but there is an astropy bug currently which affects only OSX.
    numpyband = np.loadtxt(bandfname)
    sncosmoband = sncosmo.Bandpass(wave=numpyband[:, 0],
                                   trans=numpyband[:, 1],
                                   wave_unit=Unit('nm'),
                                   name='LSST_' + band)

    sncosmo.registry.register(sncosmoband, force=True)

In [11]:
sn = sncosmo.read_lc('sn.dat')
model = sncosmo.Model(source='salt2-extended')
params = {'z': 1.06371, 't0': 50916.5, 'x0': 1.695e-06, 'x1': -0.708466, 'c': 0.0178018}
model.set(z=params['z'], t0=params['t0'], x0=params['x0'], x1=params['x1'], c=params['c'])

In [12]:
fitOut = sncosmo.fit_lc(sn, model, vparam_names=['x0', 'x1', 'c', 't0'])

In [13]:
mcmcOut = sncosmo.mcmc_lc(sn, model, vparam_names=['x0', 'x1', 'c', 't0'])

In [14]:
type(mcmcOut[0].samples.tolist())


Out[14]:
list

In [16]:
with open('mcmcRes.json', 'w') as fp:
    json.dump(fitOut[0].samples.tolist(), fp)


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-16-05fb0647459b> in <module>()
      1 with open('mcmcRes.json', 'w') as fp:
----> 2     json.dump(fitOut[0].samples.tolist(), fp)

/Users/lisaleemcb/.local/lib/python2.7/site-packages/sncosmo-1.1.dev518-py2.7-macosx-10.5-x86_64.egg/sncosmo/utils.pyc in __getattr__(self, name)
     95             return self[name]
     96         except KeyError:
---> 97             raise AttributeError(name)
     98 
     99     __setattr__ = dict.__setitem__

AttributeError: samples
  • model.set(**sn.meta) doesn't work with 'real' file
  • can't get json to work
  • don't think fitting methods should be static
  • how to define all for variables
  • list comprehension for getting bias
  • confused about if bias is with the mean of the samples or the 'true' value
  1. take obstable in sncosmo and run 5 times and should get slightly different realizations
  2. should be 1d set of positive numbers, might be eb-v from dust maps
  3. or use fits files
  4. r_v = 3.1, read from dust maps load into array np.random
  5. .3 -.5 redshift SN

    1 simulation of SN w/ host extinction 1 and w/o host extinction 2 fit setup w/ and w/o host extinction 3 corner plots

  6. LC widget


In [13]:
sn.meta['key']


Out[13]:
OrderedDict([('SNID', 44), ('IAUC', 'NULL'), ('FAKE', 2), ('RA', 209.882553), ('DECL', -12.400555), ('PIXSIZE', 0.2), ('NXPIX', -9), ('NYPIX', -9), ('SNTYPE', 1), ('NOBS', 83), ('PTROBS_MIN', 73), ('PTROBS_MAX', 155), ('MWEBV', 0.0829484), ('MWEBV_ERR', 0.0132717), ('REDSHIFT_HELIO', 1.06465), ('REDSHIFT_HELIO_ERR', 0.0005), ('REDSHIFT_FINAL', 1.06656), ('REDSHIFT_FINAL_ERR', 0.0005), ('HOSTGAL_OBJID', 29144), ('HOSTGAL_PHOTOZ', 1.20071), ('HOSTGAL_PHOTOZ_ERR', 0.05), ('HOSTGAL_SPECZ', 0.0), ('HOSTGAL_SPECZ_ERR', 0.0), ('HOSTGAL_SNSEP', -999.0), ('HOSTGAL_LOGMASS', -9.0), ('HOSTGAL_LOGMASS_ERR', -9.0), ('HOSTGAL_MAG_u', 999.0), ('HOSTGAL_MAG_g', 999.0), ('HOSTGAL_MAG_r', 999.0), ('HOSTGAL_MAG_i', 999.0), ('HOSTGAL_MAG_z', 999.0), ('HOSTGAL_MAG_Y', 999.0), ('HOSTGAL_SB_FLUXCAL_u', -9.0), ('HOSTGAL_SB_FLUXCAL_g', -9.0), ('HOSTGAL_SB_FLUXCAL_r', -9.0), ('HOSTGAL_SB_FLUXCAL_i', -9.0), ('HOSTGAL_SB_FLUXCAL_z', -9.0), ('HOSTGAL_SB_FLUXCAL_Y', -9.0), ('PEAKMJD', 50915.8), ('SEARCH_TYPE', -9), ('SIM_MODEL_NAME', 'SALT2.Guy10_LAMOPEN'), ('SIM_MODEL_INDEX', 6), ('SIM_TYPE_INDEX', 1), ('SIM_TYPE_NAME', 'Ia'), ('SIM_NON1a', 0), ('SIM_LIBID', 2082), ('SIM_SEARCHEFF_MASK', 3), ('SIM_REDSHIFT_HELIO', 1.06371), ('SIM_REDSHIFT_CMB', 1.06562), ('SIM_VPEC', -0.0), ('SIM_DLMU', 44.2709), ('SIM_RA', 209.882553101), ('SIM_DECL', -12.400554657), ('SIM_MWEBV', 0.0821098), ('SIM_PEAKMJD', 50916.5), ('SIM_SALT2x0', 1.695e-06), ('SIM_SALT2x1', -0.708466), ('SIM_SALT2c', 0.0178018), ('SIM_SALT2mB', 25.0621), ('SIM_SALT2alpha', 0.14), ('SIM_SALT2beta', 3.2), ('SIM_PEAKMAG_u', -9.0), ('SIM_PEAKMAG_g', -9.0), ('SIM_PEAKMAG_r', 26.5509), ('SIM_PEAKMAG_i', 25.0618), ('SIM_PEAKMAG_z', 24.534), ('SIM_PEAKMAG_Y', 24.5804), ('SIM_EXPOSURE_u', 1.0), ('SIM_EXPOSURE_g', 1.0), ('SIM_EXPOSURE_r', 1.0), ('SIM_EXPOSURE_i', 1.0), ('SIM_EXPOSURE_z', 1.0), ('SIM_EXPOSURE_Y', 1.0), ('SIM_GALFRAC_u', -9.0), ('SIM_GALFRAC_g', -9.0), ('SIM_GALFRAC_r', -9.0), ('SIM_GALFRAC_i', -9.0), ('SIM_GALFRAC_z', -9.0), ('SIM_GALFRAC_Y', -9.0)])