In [1]:
import numpy as np
In [2]:
import sncosmo
In [3]:
%matplotlib inline
import matplotlib.pyplot as plt
In [ ]:
In [4]:
import sncosmo
In [5]:
from analyzeSN import LightCurve
In [6]:
lco = LightCurve.fromSALTFormat('/Users/rbiswas/data/JLA_Calibration_OnlineData/cosmology/jla_light_curves/lc-03D1au.list')
In [7]:
sncosmo.plot_lc(lco.snCosmoLC())
Out[7]:
In [8]:
lco = LightCurve.fromSALTFormat('/Users/rbiswas/data/JLA_Calibration_OnlineData/cosmology/jla_light_curves/lc-SDSS14331.list')
In [9]:
sncosmo.plot_lc(lco.snCosmoLC())
Out[9]:
In [9]:
t = sncosmo.read_lc('/Users/rbiswas/data/JLA_Calibration_OnlineData/cosmology/jla_light_curves/lc-SDSS14331.list',
format='salt2')
In [10]:
t
Out[10]:
In [8]:
lco._lightCurve
Out[8]:
In [7]:
lco.lightCurve.head()
Out[7]:
In [5]:
sncosmo.plot_lc(lco.snCosmoLC())`
In [4]:
lc = sncosmo.read_lc('/Users/rbiswas/data/JLA_Calibration_OnlineData/cosmology/jla_light_curves/lc-SDSS14331.list',
format='salt2')
In [21]:
meta = lc.meta
In [23]:
lcp = lc.to_pandas()
#lcp['Filter'] = lcp['Filter'].apply(lambda x: 'sdss' + x[-1])
lcp['MagSys'] = 'ab'
In [24]:
lco = LightCurve(lcp)
In [25]:
lcp.Filter.unique()
Out[25]:
In [26]:
bandDict = dict((x.lower(), x[:-3].lower() + x[-1]) for x in lcp.Filter.unique())
In [30]:
sncosmo.get_bandpass('mega_g')
Out[30]:
In [11]:
bandDict
Out[11]:
In [12]:
LightCurve.remap_filters('SDSS::g', bandDict, True)
Out[12]:
In [6]:
lco = LightCurve(lcp, bandNameDict=bandDict, ignore_case=True)
In [14]:
lco.lightCurve.head()
Out[14]:
In [15]:
dust = sncosmo.CCM89Dust()
model = sncosmo.Model(source='salt2', effects=[dust], effect_names=['mw'], effect_frames=['obs'])
model.set(mwebv=meta['MWEBV'])
#model.set(z=0.21)
In [16]:
import statsmodels
In [12]:
from scipy import stats
In [13]:
fitres = sncosmo.mcmc_lc(lco.snCosmoLC(), model=model, bounds=dict(z=(0.01,1.05), c=(-0.5, 0.5), x1=(-5.,5.)),
vparam_names=['x0', 'x1', 'c', 't0', 'z'],
priors=dict(z=lambda x: stats.norm.pdf(x, 1.13, 0.1)),
modelcov=True)
In [23]:
fitres = sncosmo.mcmc_lc(lco.snCosmoLC(), model=model, bounds=dict(z=(0.05, 0.8), c=(-0.5, 0.5), x1=(-5., 5.)),
vparam_names=['x0', 'x1', 'c', 't0', 'z'],
# priors=dict(z=lambda x: stats.norm.pdf(x,0.213, 0.2)),
modelcov=True)
In [16]:
from analyzeSN import ResChar
In [17]:
mcmc_reschar = ResChar.fromSNCosmoRes(fitres)
In [18]:
mcmc_reschar.salt_samples().z.std()
Out[18]:
In [19]:
np.histogram(mcmc_reschar.salt_samples().z)[1][np.histogram(mcmc_reschar.salt_samples().z)[0].argmax()]
Out[19]:
In [20]:
fig, ax = plt.subplots()
mcmc_reschar.salt_samples().mu.hist(histtype='step',
bins=np.arange(10., 14.,0.05),
ax=ax)
#x = np.arange(0.1, 0.4, 0.001)
#ax.plot(x, 120. *stats.norm.pdf(x, 0.213, 0.4), 'r--')
Out[20]:
In [21]:
fig, ax = plt.subplots()
mcmc_reschar.salt_samples().z.hist(histtype='step',
#bins=np.arange(0.126, 0.3126,0.005),
ax=ax)
x = np.arange(0.1, 1.4, 0.001)
ax.plot(x, 120.*stats.norm.pdf(x, 1.13, 0.1), 'r--')
Out[21]:
In [148]:
ax.plot(z, )
In [ ]:
import seaborn as sns
sns.set_style('whitegrid')
In [149]:
sns.pairplot(data=mcmc_reschar.salt_samples())
Out[149]:
In [131]:
ResChar.fromSNCosmoRes(fitres).parameters
Out[131]:
In [132]:
fig = sncosmo.plot_lc(lco.snCosmoLC(), model=fitres[1])
In [15]:
fig
Out[15]:
In [16]:
model.set(x1=0.141351)
model.set(z=0.213)
model.set(c=0.0142)
In [17]:
print model
In [20]:
fitres_JLAparams = sncosmo.fit_lc(lco.snCosmoLC(), model=model, vparam_names=['x0', 't0'], modelcov=True)
In [21]:
fitres_JLAparams[0].parameters
Out[21]:
In [22]:
fig = sncosmo.plot_lc(lco.snCosmoLC(), model=(fitres[1], fitres_JLAparams[1]))
In [23]:
fig
Out[23]:
In [20]:
mcmcres_JLAparams = sncosmo.mcmc_lc(lco.snCosmoLC(), model=model, vparam_names=['x0', 't0'], modelcov=True)
In [21]:
ResChar.fromSNCosmoRes(mcmcres_JLAparams).parameters
Out[21]:
In [22]:
sncosmo.plot_lc(lco.snCosmoLC(), model=[fitres[1], fitres_JLAparams[1], mcmcres_JLAparams[1]], color='k')
Out[22]:
In [27]:
fitres_JLAparams = sncosmo.fit_lc(lco.snCosmoLC(), model=model, vparam_names=['x0', 't0'], modelcov=False, minsnr=5.)
In [28]:
fitres_JLAparams[0].parameters
Out[28]:
In [ ]: