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]:
In [4]:
type(d)
Out[4]:
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]:
In [8]:
type(results)
Out[8]:
Is this the same thing as my original dict?
In [9]:
d == results
Out[9]:
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]:
In [16]:
with open('mcmcRes.json', 'w') as fp:
json.dump(fitOut[0].samples.tolist(), fp)
.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
LC widget
In [13]:
sn.meta['key']
Out[13]: