In [16]:
%matplotlib inline

In [1]:
import analyzeSN

In [2]:
import sncosmo

In [3]:
model = sncosmo.Model(source='salt2')

In [4]:
data = sncosmo.load_example_data()

In [5]:
data.meta


Out[5]:
OrderedDict([('x1', 0.5),
             ('c', 0.2),
             ('z', 0.5),
             ('x0', 1.20482820761e-05),
             ('t0', 55100.0)])

In [6]:
model.set(z=0.5)

In [7]:
res = sncosmo.fit_lc(data, model, vparam_names=['t0', 'x0', 'x1', 'c'], )

In [8]:
reschar = analyzeSN.ResChar.fromSNCosmoRes(res)

In [24]:
varmu = reschar.mu_variance_linear(alpha=0.14, beta=3.14)


          mB        x1         c
mB  0.001239  0.006771  0.000706
x1  0.006771  0.116810  0.001399
c   0.000706  0.001399  0.000820 [ 1.    0.14 -3.14]

In [25]:
print(varmu**0.5)


0.08859394617261082

In [ ]:
# If we use mcmc to do this:

In [10]:
res_mcmc = sncosmo.mcmc_lc(data, model, vparam_names=['t0', 'x0', 'x1', 'c'], )

In [11]:
reschar_mcmc = reschar.fromSNCosmoRes(res_mcmc)

In [ ]:
# Note that mu might need additional constants

In [23]:
reschar_mcmc.salt_samples(alpha=0.1, beta=-3.14).mu.std()


Out[23]:
0.0866330665243906

In [ ]: