This notebook checks that the outputs from running sncosmo fitting functions, then writing those outputs to an hdf5 file, match the outputs of reading the same fits from the aforementioned hdf5 file.
It finds thats all output is the same within a good tolerance, except for the param_dict
attribute in nest_lc()
result, which has been reordered. This reordering may present an issue for some functionality but probably won't be fixed in the near future.
In [72]:
%matplotlib inline
import os
import numpy as np
from numpy.random import normal, uniform
import math
import collections
import pandas as pd
from astropy.table import Table
import triangle
import sncosmo
import simulate_lsst as sl
import lc
In [2]:
lightc = sncosmo.read_lc('sn.dat')
lightc.meta
Out[2]:
In [3]:
model = sncosmo.Model(source='salt2-extended')
params = {'t0': lightc.meta['SIM_PEAKMJD'], 'x0': lightc.meta['SIM_SALT2x0'], 'x1': lightc.meta['SIM_SALT2x1'],
'c': lightc.meta['SIM_SALT2c'], 'z': lightc.meta['SIM_REDSHIFT_HELIO']}
model.set(**params)
vparams = ['t0', 'x0', 'x1', 'c']
In [13]:
lightc
Out[13]:
In [15]:
fits_run = lc.LC(model, lightc, vparams)
fits_readfromfile = lc.LC(model, lightc, vparams)
In [16]:
fits_run.fitOut
Out[16]:
In [18]:
fits_run.mcmcOut
Out[18]:
In [19]:
fits_run.nestOut
Out[19]:
In [20]:
fits_run.writeFits('serial_test.hdf5', 'sn')
In [21]:
fits_readfromfile.fitOut, fits_readfromfile.mcmcOut, fits_readfromfile.nestOut = fits_readfromfile.readFits('serial_test.hdf5', 'sn')
In [22]:
fits_readfromfile.plotLC()
Out[22]:
In [49]:
fits_run.fitRes
Out[49]:
In [48]:
fits_run.fitRes.errors == fits_readfromfile.fitRes.errors
Out[48]:
In [50]:
np.allclose(fits_run.fitRes.parameters, fits_readfromfile.fitRes.parameters)
Out[50]:
In [73]:
np.isclose(fits_run.fitRes.ndof, fits_readfromfile.fitRes.ndof)
Out[73]:
In [51]:
np.allclose(fits_run.fitRes.covariance, fits_readfromfile.fitRes.covariance)
Out[51]:
In [74]:
np.isclose(fits_run.fitRes.chisq, fits_readfromfile.fitRes.chisq)
Out[74]:
In [75]:
np.isclose(fits_run.fitRes.ncall, fits_readfromfile.fitRes.ncall)
Out[75]:
In [52]:
fits_run.mcmcRes
Out[52]:
In [53]:
fits_run.mcmcRes.errors == fits_readfromfile.mcmcRes.errors
Out[53]:
In [56]:
np.allclose(fits_run.mcmcRes.samples, fits_readfromfile.mcmcRes.samples)
Out[56]:
In [57]:
np.allclose(fits_run.mcmcRes.parameters, fits_readfromfile.mcmcRes.parameters)
Out[57]:
In [77]:
np.isclose(fits_run.mcmcRes.mean_acceptance_fraction,
fits_readfromfile.mcmcRes.mean_acceptance_fraction)
Out[77]:
In [58]:
np.allclose(fits_run.mcmcRes.covariance, fits_readfromfile.mcmcRes.covariance)
Out[58]:
In [59]:
fits_run.nestRes
Out[59]:
In [78]:
np.isclose(fits_run.nestRes.niter, fits_readfromfile.nestRes.niter)
Out[78]:
In [60]:
fits_run.nestRes.errors == fits_readfromfile.nestRes.errors
Out[60]:
In [61]:
fits_run.nestRes.param_dict == fits_readfromfile.nestRes.param_dict
Out[61]:
In [71]:
fits_run.nestRes.param_dict, fits_readfromfile.nestRes.param_dict
Out[71]:
In [63]:
np.allclose(fits_run.nestRes.parameters, fits_readfromfile.nestRes.parameters)
Out[63]:
In [64]:
fits_run.nestRes.bounds == fits_readfromfile.nestRes.bounds
Out[64]:
In [79]:
np.isclose(fits_run.nestRes.h, fits_readfromfile.nestRes.h)
Out[79]:
In [65]:
np.allclose(fits_run.nestRes.logprior, fits_readfromfile.nestRes.logprior)
Out[65]:
In [80]:
np.isclose(fits_run.nestRes.logz, fits_readfromfile.nestRes.logz)
Out[80]:
In [81]:
np.isclose(fits_run.nestRes.ndof, fits_readfromfile.nestRes.ndof)
Out[81]:
In [82]:
np.isclose(fits_run.nestRes.ncall, fits_readfromfile.nestRes.ncall)
Out[82]:
In [66]:
np.allclose(fits_run.nestRes.weights, fits_readfromfile.nestRes.weights)
Out[66]:
In [67]:
np.allclose(fits_run.nestRes.samples, fits_readfromfile.nestRes.samples)
Out[67]:
In [83]:
np.isclose(fits_run.nestRes.time, fits_readfromfile.nestRes.time)
Out[83]:
In [84]:
np.isclose(fits_run.nestRes.logzerr, fits_readfromfile.nestRes.logzerr)
Out[84]:
In [68]:
np.allclose(fits_run.nestRes.covariance, fits_readfromfile.nestRes.covariance)
Out[68]:
In [69]:
np.allclose(fits_run.nestRes.logl, fits_readfromfile.nestRes.logl)
Out[69]:
In [ ]: