In [5]:
%matplotlib inline

import matplotlib.pyplot as plt
import os
import numpy as np
from astropy.units import Unit
from astropy.table import Table, join
import collections
import pandas as pd


import sncosmo
import triangle

import lc

In [6]:
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 [9]:
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(**params)

vparams = ['t0', 'x0', 'x1', 'c']

In [11]:
test = lc.LC(model, vparams)

In [12]:
test.fitOut


running chi^2 fit
Out[12]:
(       errors: OrderedDict([('t0', 0.869705464632716), ('x0', 6.352280833289825e-08), ('x1', 0.5247654629885447), ('c', 0.048283506458290146)])
   parameters: array([  1.06371000e+00,   5.09155364e+04,   1.19022208e-06,
        -1.37443229e+00,  -2.74520718e-02])
      success: True
         ndof: 79
   covariance: array([[  7.56396247e-01,  -1.47415535e-08,   9.27513342e-02,
          8.97227286e-03],
       [ -1.47415535e-08,   4.03514718e-15,  -1.57647791e-08,
          8.09694619e-10],
       [  9.27513342e-02,  -1.57647791e-08,   2.79008873e-01,
          1.00106837e-02],
       [  8.97227286e-03,   8.09694619e-10,   1.00106837e-02,
          2.35188405e-03]])
 vparam_names: ['t0', 'x0', 'x1', 'c']
        chisq: 94.67428083189289
  param_names: ['z', 't0', 'x0', 'x1', 'c']
      message: 'Minimization exited successfully.'
        ncall: 98,
 <sncosmo.models.Model at 0x1099caa90>)

In [13]:
test.mcmcOut


running MCMC fit
Out[13]:
(             vparam_names: ['t0', 'x0', 'x1', 'c']
                   errors: OrderedDict([('t0', 0.88242822432987356), ('x0', 6.3059478638814828e-08), ('x1', 0.55133200330569565), ('c', 0.048456459016122687)])
                  samples: array([[  5.09155120e+04,   1.27245993e-06,  -1.49497570e+00,
          3.98771060e-02],
       [  5.09155111e+04,   1.26055332e-06,  -8.60896914e-01,
          1.27648389e-01],
       [  5.09150388e+04,   1.29711144e-06,  -1.28057683e+00,
          7.30852715e-02],
       ..., 
       [  5.09160799e+04,   1.14867979e-06,  -1.79794620e+00,
         -2.11202630e-02],
       [  5.09160799e+04,   1.14867979e-06,  -1.79794620e+00,
         -2.11202630e-02],
       [  5.09160874e+04,   1.14752087e-06,  -1.85012883e+00,
         -2.32719008e-02]])
               parameters: array([  1.06371000e+00,   5.09155341e+04,   1.18813513e-06,
        -1.28359261e+00,  -1.86142461e-02])
              param_names: ['z', 't0', 'x0', 'x1', 'c']
 mean_acceptance_fraction: 0.5949000000000001
               covariance: array([[  7.78679571e-01,  -1.59321223e-08,   8.51380619e-02,
          9.78822092e-03],
       [ -1.59321223e-08,   3.97649785e-15,  -1.86754903e-08,
          6.10686117e-10],
       [  8.51380619e-02,  -1.86754903e-08,   3.03966978e-01,
          1.04446978e-02],
       [  9.78822092e-03,   6.10686117e-10,   1.04446978e-02,
          2.34802842e-03]]),
 <sncosmo.models.Model at 0x1099feb90>)

In [8]:
test.nestOut


running nest fit
 iter=  1759 logz=-60.010636calls=5874 time=366.552s
Out[8]:
(        niter: 1760
       errors: OrderedDict([('t0', 0.85742511468250004), ('x0', 5.9701297955410924e-08), ('x1', 0.54883393935394575), ('c', 0.046513560076824161)])
   param_dict: OrderedDict([('z', 1.0637099999999999), ('t0', 50915.583689761028), ('x0', 1.1901297391798577e-06), ('x1', -1.2930222192277765), ('c', -0.013866206262653951)])
   parameters: array([  1.06371000e+00,   5.09155837e+04,   1.19012974e-06,
        -1.29302222e+00,  -1.38662063e-02])
       bounds: {'c': (-0.3, 0.3), 'x1': (-3.0, 3.0), 'x0': (0.0, 1.4249497311936984e-05), 't0': (50774.025500000011, 51071.31319999999)}
            h: 10.754864600379349
     logprior: array([ -4.61016602,  -4.62016602,  -4.63016602, ..., -22.20517019,
       -22.20517019, -22.20517019])
         logz: -60.003945649733957
         ndof: 79
        ncall: 5874
 vparam_names: ['t0', 'x0', 'x1', 'c']
      weights: array([  0.00000000e+00,   0.00000000e+00,   0.00000000e+00, ...,
         6.41661791e-05,   6.41845196e-05,   6.97861864e-05])
      samples: array([[  5.09385662e+04,   1.23407639e-05,   2.68993850e+00,
         -2.28523390e-01],
       [  5.10179700e+04,   1.28536942e-05,   2.91668209e+00,
         -7.32081711e-02],
       [  5.09446366e+04,   1.29721452e-05,   3.93476084e-01,
         -1.68417964e-01],
       ..., 
       [  5.09156868e+04,   1.17499309e-06,  -1.15829051e+00,
         -2.87343242e-02],
       [  5.09157918e+04,   1.17731202e-06,  -1.16223178e+00,
         -1.13884232e-02],
       [  5.09156968e+04,   1.19094105e-06,  -1.42429118e+00,
         -3.13606659e-02]])
         time: 366.55178594589233
      logzerr: 0.32794610228480153
   covariance: array([[  7.35177827e-01,  -1.61738900e-08,   1.08167116e-01,
          8.75533195e-03],
       [ -1.61738900e-08,   3.56424498e-15,  -1.63261178e-08,
          4.20679770e-10],
       [  1.08167116e-01,  -1.63261178e-08,   3.01218693e-01,
          1.05207411e-02],
       [  8.75533195e-03,   4.20679770e-10,   1.05207411e-02,
          2.16351127e-03]])
         logl: array([ -1.16532500e+05,  -5.86006312e+04,  -4.96322202e+04, ...,
        -4.74528098e+01,  -4.74525240e+01,  -4.73688499e+01]),
 <sncosmo.models.Model at 0x1096c2750>)

In [231]:
test.mcmcRes.samples.shape


Out[231]:
(10000, 4)

Write fit_lc() output


In [28]:
# syntactic sugar
fit_errors = test.fitRes.errors

In [29]:
fit_table = Table()

for keys in fit_errors:
    fit_table[keys] = [fit_errors[keys]]
    
for key in test.fitRes.keys():
    if key == 'errors':
        continue
    fit_table.meta[key] = test.fitRes[key]

In [30]:
fit_table, fit_table.meta


Out[30]:
(<Table masked=False length=1>
       t0               x0              x1              c       
    float64          float64         float64         float64    
 -------------- ----------------- -------------- ---------------
 0.869705464633 6.35228083329e-08 0.524765462989 0.0482835064583,
 OrderedDict([('parameters', array([  1.06371000e+00,   5.09155364e+04,   1.19022208e-06,
        -1.37443229e+00,  -2.74520718e-02])), ('success', True), ('ndof', 79), ('covariance', array([[  7.56396247e-01,  -1.47415535e-08,   9.27513342e-02,
          8.97227286e-03],
       [ -1.47415535e-08,   4.03514718e-15,  -1.57647791e-08,
          8.09694619e-10],
       [  9.27513342e-02,  -1.57647791e-08,   2.79008873e-01,
          1.00106837e-02],
       [  8.97227286e-03,   8.09694619e-10,   1.00106837e-02,
          2.35188405e-03]])), ('vparam_names', ['t0', 'x0', 'x1', 'c']), ('chisq', 94.67428083189289), ('param_names', ['z', 't0', 'x0', 'x1', 'c']), ('message', 'Minimization exited successfully.'), ('ncall', 98)]))

In [173]:
fit_table.write('Fits.hdf5', 'MLEfit')

Write mcmc_lc() output


In [174]:
# syntactic sugar
mcmc_errors = test.mcmcRes.errors
mcmc_table = Table(test.mcmcRes.samples, names=test.mcmcRes.vparam_names)

for key in test.mcmcRes.keys():
    if key == 'errors' or key =='samples':
        continue
    mcmc_table.meta[key] = test.mcmcRes[key]
    
mcmc_table.add_row(mcmc_errors.values())
    
mcmc_table, mcmc_table.meta


Out[174]:
(<Table masked=False length=10001>
       t0               x0              x1              c        
    float64          float64         float64         float64     
 -------------- ----------------- -------------- ----------------
  50914.5837515 1.21335746635e-06 -1.05353753723  -0.036530890977
  50914.4528424 1.21116512188e-06  -1.1280001169  -0.032604044596
  50914.3379628 1.21227916839e-06 -1.26100101789 -0.0363678365377
  50914.9396536 1.20551121949e-06 -1.30599510054 -0.0299586917057
   50914.650823 1.20876004829e-06 -1.28439652267 -0.0330352832392
   50914.650823 1.20876004829e-06 -1.28439652267 -0.0330352832392
  50914.1401582 1.22163431178e-06 -1.51077501302 -0.0757278429348
  50914.1850659 1.22009592848e-06 -1.51733333533 -0.0708267111496
    50914.45691 1.21037109779e-06 -1.43132675444 -0.0683250150405
    50914.45691 1.21037109779e-06 -1.43132675444 -0.0683250150405
            ...               ...            ...              ...
  50916.9989558 1.16593550026e-06 -1.84529251782 -0.0831614191108
  50917.0702404 1.14539022024e-06 -1.87698611853 -0.0941274363767
  50916.9724259 1.17414515884e-06 -1.82887544761 -0.0784701309272
  50916.9724259 1.17414515884e-06 -1.82887544761 -0.0784701309272
  50916.9724259 1.17414515884e-06 -1.82887544761 -0.0784701309272
    50916.62638 1.17074784063e-06 -1.57106087808  -0.040862064577
  50916.6625339 1.17747415838e-06 -1.50733542752 -0.0360605417446
  50916.5756525 1.16131012926e-06 -1.66047419926 -0.0475990919253
  50916.5756525 1.16131012926e-06 -1.66047419926 -0.0475990919253
 0.879976530108 6.20004827911e-08 0.581865009407  0.0489108504602,
 OrderedDict([('vparam_names', ['t0', 'x0', 'x1', 'c']), ('parameters', array([  1.06371000e+00,   5.09155774e+04,   1.18878859e-06,
        -1.28091282e+00,  -1.27719980e-02])), ('param_names', ['z', 't0', 'x0', 'x1', 'c']), ('mean_acceptance_fraction', 0.59329999999999994), ('covariance', array([[  7.74358694e-01,  -1.25954070e-08,   1.32319075e-01,
          1.27031554e-02],
       [ -1.25954070e-08,   3.84405987e-15,  -1.83816813e-08,
          6.98442137e-10],
       [  1.32319075e-01,  -1.83816813e-08,   3.38566889e-01,
          1.07035450e-02],
       [  1.27031554e-02,   6.98442137e-10,   1.07035450e-02,
          2.39227129e-03]]))]))

In [175]:
mcmc_table.write('Fits.hdf5', 'mcmc', append=True)

Write nest_lc() output


In [176]:
test.nestRes


Out[176]:
        niter: 1760
       errors: OrderedDict([('t0', 0.85742511468250004), ('x0', 5.9701297955410924e-08), ('x1', 0.54883393935394575), ('c', 0.046513560076824161)])
   param_dict: OrderedDict([('z', 1.0637099999999999), ('t0', 50915.583689761028), ('x0', 1.1901297391798577e-06), ('x1', -1.2930222192277765), ('c', -0.013866206262653951)])
   parameters: array([  1.06371000e+00,   5.09155837e+04,   1.19012974e-06,
        -1.29302222e+00,  -1.38662063e-02])
       bounds: {'c': (-0.3, 0.3), 'x1': (-3.0, 3.0), 'x0': (0.0, 1.4249497311936984e-05), 't0': (50774.025500000011, 51071.31319999999)}
            h: 10.754864600379349
     logprior: array([ -4.61016602,  -4.62016602,  -4.63016602, ..., -22.20517019,
       -22.20517019, -22.20517019])
         logz: -60.003945649733957
         ndof: 79
        ncall: 5874
 vparam_names: ['t0', 'x0', 'x1', 'c']
      weights: array([  0.00000000e+00,   0.00000000e+00,   0.00000000e+00, ...,
         6.41661791e-05,   6.41845196e-05,   6.97861864e-05])
      samples: array([[  5.09385662e+04,   1.23407639e-05,   2.68993850e+00,
         -2.28523390e-01],
       [  5.10179700e+04,   1.28536942e-05,   2.91668209e+00,
         -7.32081711e-02],
       [  5.09446366e+04,   1.29721452e-05,   3.93476084e-01,
         -1.68417964e-01],
       ..., 
       [  5.09156868e+04,   1.17499309e-06,  -1.15829051e+00,
         -2.87343242e-02],
       [  5.09157918e+04,   1.17731202e-06,  -1.16223178e+00,
         -1.13884232e-02],
       [  5.09156968e+04,   1.19094105e-06,  -1.42429118e+00,
         -3.13606659e-02]])
         time: 366.55178594589233
      logzerr: 0.32794610228480153
   covariance: array([[  7.35177827e-01,  -1.61738900e-08,   1.08167116e-01,
          8.75533195e-03],
       [ -1.61738900e-08,   3.56424498e-15,  -1.63261178e-08,
          4.20679770e-10],
       [  1.08167116e-01,  -1.63261178e-08,   3.01218693e-01,
          1.05207411e-02],
       [  8.75533195e-03,   4.20679770e-10,   1.05207411e-02,
          2.16351127e-03]])
         logl: array([ -1.16532500e+05,  -5.86006312e+04,  -4.96322202e+04, ...,
        -4.74528098e+01,  -4.74525240e+01,  -4.73688499e+01])

In [177]:
# syntactic sugar
nest_errors = test.nestRes.errors
nest_param_dict = test.nestRes.param_dict
nest_bounds = test.nestRes.bounds

nest_table = Table(test.nestRes.samples, names=test.nestRes.vparam_names)

In [179]:
for key in test.nestRes.keys():
    if key == 'errors' or key =='samples' or key =='param_dict' or key == 'bounds':
        continue
    nest_table.meta[key] = test.nestRes[key]
    
nest_table.add_row(nest_errors.values())

temp_z = np.zeros((len(nest_table['t0'])))
col_z = Table.Column(name='z', data=temp_z)
nest_table.add_column(col_z)

In [180]:
param_list = []
for colname in nest_table.colnames:
    param_list.append(nest_param_dict[colname])

nest_table.add_row(param_list)

In [182]:
for key in nest_bounds.keys():
    nest_table.meta[key] = nest_bounds[key]

In [183]:
nest_table.write('Fits.hdf5', 'nest', append=True)

Read fit_lc() output


In [184]:
fit_read = Table.read('Fits.hdf5', 'MLEfit')
fit_read, fit_read.meta


Out[184]:
(<Table masked=False length=1>
       t0               x0              x1              c       
    float64          float64         float64         float64    
 -------------- ----------------- -------------- ---------------
 0.869705464633 6.35228083329e-08 0.524765462989 0.0482835064583,
 OrderedDict([(u'parameters', array([  1.06371000e+00,   5.09155364e+04,   1.19022208e-06,
        -1.37443229e+00,  -2.74520718e-02])), (u'success', True), (u'ndof', 79), (u'covariance', array([[  7.56396247e-01,  -1.47415535e-08,   9.27513342e-02,
          8.97227286e-03],
       [ -1.47415535e-08,   4.03514718e-15,  -1.57647791e-08,
          8.09694619e-10],
       [  9.27513342e-02,  -1.57647791e-08,   2.79008873e-01,
          1.00106837e-02],
       [  8.97227286e-03,   8.09694619e-10,   1.00106837e-02,
          2.35188405e-03]])), (u'vparam_names', array(['t0', 'x0', 'x1', 'c'], 
      dtype='|S2')), (u'chisq', 94.674280831892887), (u'param_names', array(['z', 't0', 'x0', 'x1', 'c'], 
      dtype='|S2')), (u'message', 'Minimization exited successfully.'), (u'ncall', 98)]))

In [185]:
fit_errors_dict = collections.OrderedDict()

for colnames in fit_read.colnames:
    fit_errors_dict[colnames] = fit_read[colnames][0]

In [186]:
fit_dict = fit_read.meta
fit_dict['errors'] = fit_errors_dict


Out[186]:
OrderedDict([(u'parameters', array([  1.06371000e+00,   5.09155364e+04,   1.19022208e-06,
        -1.37443229e+00,  -2.74520718e-02])), (u'success', True), (u'ndof', 79), (u'covariance', array([[  7.56396247e-01,  -1.47415535e-08,   9.27513342e-02,
          8.97227286e-03],
       [ -1.47415535e-08,   4.03514718e-15,  -1.57647791e-08,
          8.09694619e-10],
       [  9.27513342e-02,  -1.57647791e-08,   2.79008873e-01,
          1.00106837e-02],
       [  8.97227286e-03,   8.09694619e-10,   1.00106837e-02,
          2.35188405e-03]])), (u'vparam_names', array(['t0', 'x0', 'x1', 'c'], 
      dtype='|S2')), (u'chisq', 94.674280831892887), (u'param_names', array(['z', 't0', 'x0', 'x1', 'c'], 
      dtype='|S2')), (u'message', 'Minimization exited successfully.'), (u'ncall', 98), ('errors', OrderedDict([('t0', 0.86970546463271603), ('x0', 6.3522808332898253e-08), ('x1', 0.52476546298854465), ('c', 0.048283506458290146)]))])

In [187]:
fit_result = sncosmo.utils.Result(fit_dict)
fit_result


Out[187]:
       errors: OrderedDict([('t0', 0.86970546463271603), ('x0', 6.3522808332898253e-08), ('x1', 0.52476546298854465), ('c', 0.048283506458290146)])
      success: True
   parameters: array([  1.06371000e+00,   5.09155364e+04,   1.19022208e-06,
        -1.37443229e+00,  -2.74520718e-02])
   covariance: array([[  7.56396247e-01,  -1.47415535e-08,   9.27513342e-02,
          8.97227286e-03],
       [ -1.47415535e-08,   4.03514718e-15,  -1.57647791e-08,
          8.09694619e-10],
       [  9.27513342e-02,  -1.57647791e-08,   2.79008873e-01,
          1.00106837e-02],
       [  8.97227286e-03,   8.09694619e-10,   1.00106837e-02,
          2.35188405e-03]])
         ndof: 79
 vparam_names: array(['t0', 'x0', 'x1', 'c'], 
      dtype='|S2')
        chisq: 94.674280831892887
  param_names: array(['z', 't0', 'x0', 'x1', 'c'], 
      dtype='|S2')
      message: 'Minimization exited successfully.'
        ncall: 98

Read mcmc_lc() output


In [188]:
mcmc_read = Table.read('Fits.hdf5', 'mcmc')


Out[188]:
(OrderedDict([(u'vparam_names', array(['t0', 'x0', 'x1', 'c'], 
      dtype='|S2')), (u'parameters', array([  1.06371000e+00,   5.09155774e+04,   1.18878859e-06,
        -1.28091282e+00,  -1.27719980e-02])), (u'param_names', array(['z', 't0', 'x0', 'x1', 'c'], 
      dtype='|S2')), (u'mean_acceptance_fraction', 0.59329999999999994), (u'covariance', array([[  7.74358694e-01,  -1.25954070e-08,   1.32319075e-01,
          1.27031554e-02],
       [ -1.25954070e-08,   3.84405987e-15,  -1.83816813e-08,
          6.98442137e-10],
       [  1.32319075e-01,  -1.83816813e-08,   3.38566889e-01,
          1.07035450e-02],
       [  1.27031554e-02,   6.98442137e-10,   1.07035450e-02,
          2.39227129e-03]]))]),
 <Table masked=False length=10001>
       t0               x0              x1              c        
    float64          float64         float64         float64     
 -------------- ----------------- -------------- ----------------
  50914.5837515 1.21335746635e-06 -1.05353753723  -0.036530890977
  50914.4528424 1.21116512188e-06  -1.1280001169  -0.032604044596
  50914.3379628 1.21227916839e-06 -1.26100101789 -0.0363678365377
  50914.9396536 1.20551121949e-06 -1.30599510054 -0.0299586917057
   50914.650823 1.20876004829e-06 -1.28439652267 -0.0330352832392
   50914.650823 1.20876004829e-06 -1.28439652267 -0.0330352832392
  50914.1401582 1.22163431178e-06 -1.51077501302 -0.0757278429348
  50914.1850659 1.22009592848e-06 -1.51733333533 -0.0708267111496
    50914.45691 1.21037109779e-06 -1.43132675444 -0.0683250150405
    50914.45691 1.21037109779e-06 -1.43132675444 -0.0683250150405
            ...               ...            ...              ...
  50916.9989558 1.16593550026e-06 -1.84529251782 -0.0831614191108
  50917.0702404 1.14539022024e-06 -1.87698611853 -0.0941274363767
  50916.9724259 1.17414515884e-06 -1.82887544761 -0.0784701309272
  50916.9724259 1.17414515884e-06 -1.82887544761 -0.0784701309272
  50916.9724259 1.17414515884e-06 -1.82887544761 -0.0784701309272
    50916.62638 1.17074784063e-06 -1.57106087808  -0.040862064577
  50916.6625339 1.17747415838e-06 -1.50733542752 -0.0360605417446
  50916.5756525 1.16131012926e-06 -1.66047419926 -0.0475990919253
  50916.5756525 1.16131012926e-06 -1.66047419926 -0.0475990919253
 0.879976530108 6.20004827911e-08 0.581865009407  0.0489108504602)

In [189]:
mcmc_errors_dict = collections.OrderedDict()

for colnames in mcmc_read.colnames:
    mcmc_errors_dict[colnames] = mcmc_read[colnames][len(mcmc_read.columns[0]) - 1]

In [190]:
mcmc_read.remove_row(len(mcmc_read.columns[0]) - 1)

In [255]:
mcmc_samples = np.array([np.array(mcmc_read.columns[0]),
                         np.array(mcmc_read.columns[1]),
                         np.array(mcmc_read.columns[2]),
                         np.array(mcmc_read.columns[3])])

In [256]:
mcmc_dict = mcmc_read.meta
mcmc_dict['errors'] = mcmc_errors_dict
mcmc_dict['samples'] = mcmc_samples.T

mcmc_result = sncosmo.utils.Result(mcmc_dict)
mcmc_result


Out[256]:
             vparam_names: array(['t0', 'x0', 'x1', 'c'], 
      dtype='|S2')
                   errors: OrderedDict([('t0', 0.87997653010821397), ('x0', 6.2000482791081062e-08), ('x1', 0.58186500940736841), ('c', 0.048910850460173697)])
                  samples: array([[  5.09145838e+04,   1.21335747e-06,  -1.05353754e+00,
         -3.65308910e-02],
       [  5.09144528e+04,   1.21116512e-06,  -1.12800012e+00,
         -3.26040446e-02],
       [  5.09143380e+04,   1.21227917e-06,  -1.26100102e+00,
         -3.63678365e-02],
       ..., 
       [  5.09166625e+04,   1.17747416e-06,  -1.50733543e+00,
         -3.60605417e-02],
       [  5.09165757e+04,   1.16131013e-06,  -1.66047420e+00,
         -4.75990919e-02],
       [  5.09165757e+04,   1.16131013e-06,  -1.66047420e+00,
         -4.75990919e-02]])
               parameters: array([  1.06371000e+00,   5.09155774e+04,   1.18878859e-06,
        -1.28091282e+00,  -1.27719980e-02])
              param_names: array(['z', 't0', 'x0', 'x1', 'c'], 
      dtype='|S2')
 mean_acceptance_fraction: 0.59329999999999994
               covariance: array([[  7.74358694e-01,  -1.25954070e-08,   1.32319075e-01,
          1.27031554e-02],
       [ -1.25954070e-08,   3.84405987e-15,  -1.83816813e-08,
          6.98442137e-10],
       [  1.32319075e-01,  -1.83816813e-08,   3.38566889e-01,
          1.07035450e-02],
       [  1.27031554e-02,   6.98442137e-10,   1.07035450e-02,
          2.39227129e-03]])

Read nest_lc() output


In [257]:
nest_read = Table.read('Fits.hdf5', 'nest')

In [258]:
nest_param_dict = collections.OrderedDict()

for colnames in nest_read.colnames:
    nest_param_dict[colnames] = nest_read[colnames][len(nest_read.columns[0]) - 1]
    
nest_read.remove_row(len(nest_read.columns[0]) - 1)
nest_read.remove_column('z')

nest_errors_dict = collections.OrderedDict()

for colnames in nest_read.colnames:
    nest_errors_dict[colnames] = nest_read[colnames][len(nest_read.columns[0]) - 1]

nest_read.remove_row(len(nest_read.columns[0]) - 1)

In [259]:
nest_samples = np.array([np.array(nest_read.columns[0]),
                         np.array(nest_read.columns[1]),
                         np.array(nest_read.columns[2]),
                         np.array(nest_read.columns[3])])

In [260]:
nest_bounds = {}

for colnames in nest_read.colnames:
    nest_bounds[colnames] = tuple(nest_read.meta[colnames])
    del nest_read.meta[colnames]

In [261]:
nest_dict = nest_read.meta
nest_dict['errors'] = nest_errors_dict
nest_dict['param_dict'] = nest_param_dict
nest_dict['samples'] = nest_samples.T
nest_dict['bounds'] = nest_bounds

In [262]:
nest_result = sncosmo.utils.Result(nest_dict)
nest_result


Out[262]:
         logz: -60.003945649733957
         ndof: 79
        ncall: 5874
 vparam_names: array(['t0', 'x0', 'x1', 'c'], 
      dtype='|S2')
         logl: array([ -1.16532500e+05,  -5.86006312e+04,  -4.96322202e+04, ...,
        -4.74528098e+01,  -4.74525240e+01,  -4.73688499e+01])
   covariance: array([[  7.35177827e-01,  -1.61738900e-08,   1.08167116e-01,
          8.75533195e-03],
       [ -1.61738900e-08,   3.56424498e-15,  -1.63261178e-08,
          4.20679770e-10],
       [  1.08167116e-01,  -1.63261178e-08,   3.01218693e-01,
          1.05207411e-02],
       [  8.75533195e-03,   4.20679770e-10,   1.05207411e-02,
          2.16351127e-03]])
        niter: 1760
       errors: OrderedDict([('t0', 0.85742511468250004), ('x0', 5.9701297955410924e-08), ('x1', 0.54883393935394575), ('c', 0.046513560076824161)])
   parameters: array([  1.06371000e+00,   5.09155837e+04,   1.19012974e-06,
        -1.29302222e+00,  -1.38662063e-02])
            h: 10.754864600379349
     logprior: array([ -4.61016602,  -4.62016602,  -4.63016602, ..., -22.20517019,
       -22.20517019, -22.20517019])
       bounds: {'x0': (0.0, 1.4249497311936984e-05), 'x1': (-3.0, 3.0), 'c': (-0.29999999999999999, 0.29999999999999999), 't0': (50774.025500000011, 51071.31319999999)}
   param_dict: OrderedDict([('t0', 50915.583689761028), ('x0', 1.1901297391798577e-06), ('x1', -1.2930222192277765), ('c', -0.013866206262653951), ('z', 1.0637099999999999)])
      weights: array([  0.00000000e+00,   0.00000000e+00,   0.00000000e+00, ...,
         6.41661791e-05,   6.41845196e-05,   6.97861864e-05])
      samples: array([[  5.09385662e+04,   1.23407639e-05,   2.68993850e+00,
         -2.28523390e-01],
       [  5.10179700e+04,   1.28536942e-05,   2.91668209e+00,
         -7.32081711e-02],
       [  5.09446366e+04,   1.29721452e-05,   3.93476084e-01,
         -1.68417964e-01],
       ..., 
       [  5.09156868e+04,   1.17499309e-06,  -1.15829051e+00,
         -2.87343242e-02],
       [  5.09157918e+04,   1.17731202e-06,  -1.16223178e+00,
         -1.13884232e-02],
       [  5.09156968e+04,   1.19094105e-06,  -1.42429118e+00,
         -3.13606659e-02]])
         time: 366.55178594589233
      logzerr: 0.32794610228480153

Testing with LC


In [263]:
io_check = lc.LC(model)

In [264]:
io_check.fitRes = fit_result
io_check.mcmcRes = mcmc_result
io_check.nestRes = nest_result

In [265]:
io_check.fitRes


Out[265]:
       errors: OrderedDict([('t0', 0.86970546463271603), ('x0', 6.3522808332898253e-08), ('x1', 0.52476546298854465), ('c', 0.048283506458290146)])
      success: True
   parameters: array([  1.06371000e+00,   5.09155364e+04,   1.19022208e-06,
        -1.37443229e+00,  -2.74520718e-02])
   covariance: array([[  7.56396247e-01,  -1.47415535e-08,   9.27513342e-02,
          8.97227286e-03],
       [ -1.47415535e-08,   4.03514718e-15,  -1.57647791e-08,
          8.09694619e-10],
       [  9.27513342e-02,  -1.57647791e-08,   2.79008873e-01,
          1.00106837e-02],
       [  8.97227286e-03,   8.09694619e-10,   1.00106837e-02,
          2.35188405e-03]])
         ndof: 79
 vparam_names: array(['t0', 'x0', 'x1', 'c'], 
      dtype='|S2')
        chisq: 94.674280831892887
  param_names: array(['z', 't0', 'x0', 'x1', 'c'], 
      dtype='|S2')
      message: 'Minimization exited successfully.'
        ncall: 98

In [269]:
fit_model_dict = {}
index = 0

for vals in io_check.fitRes.param_names:
    fit_model_dict[vals] = io_check.fitRes.parameters[index]
    index = index + 1

In [270]:
mcmc_model_dict = {}
index = 0
for vals in io_check.mcmcRes.param_names:
    mcmc_model_dict[vals] = io_check.mcmcRes.parameters[index]
    index = index + 1

In [271]:
nest_model_dict = io_check.nestRes.param_dict

In [272]:
fitmodel = sncosmo.Model(source='salt2-extended')
fitmodel.set(**fit_model_dict)
io_check.fitModel = fitmodel
print io_check.fitModel


<Model at 0x10a287d90>
source:
  class      : SALT2Source
  name       : 'salt2-extended'
  version    : 1.0
  phases     : [-20, .., 50] days
  wavelengths: [300, .., 18000] Angstroms
parameters:
  z  = 1.0637099999999999
  t0 = 50915.536364681364
  x0 = 1.190222083157737e-06
  x1 = -1.3744322896350136
  c  = -0.027452071819882795

In [273]:
mcmcmodel = sncosmo.Model(source='salt2-extended')
mcmcmodel.set(**mcmc_model_dict)
io_check.mcmcModel = mcmcmodel
print io_check.mcmcModel


<Model at 0x10a287d50>
source:
  class      : SALT2Source
  name       : 'salt2-extended'
  version    : 1.0
  phases     : [-20, .., 50] days
  wavelengths: [300, .., 18000] Angstroms
parameters:
  z  = 1.0637099999999999
  t0 = 50915.577438789565
  x0 = 1.1887885909227794e-06
  x1 = -1.2809128198996882
  c  = -0.012771997963720442

In [274]:
nestmodel = sncosmo.Model(source='salt2-extended')
nestmodel.set(**nest_model_dict)
io_check.nestModel = nestmodel
print io_check.nestModel


<Model at 0x10a287210>
source:
  class      : SALT2Source
  name       : 'salt2-extended'
  version    : 1.0
  phases     : [-20, .., 50] days
  wavelengths: [300, .., 18000] Angstroms
parameters:
  z  = 1.0637099999999999
  t0 = 50915.583689761028
  x0 = 1.1901297391798577e-06
  x1 = -1.2930222192277765
  c  = -0.013866206262653951

In [275]:
fig = lc.LC.plotLC(io_check)



In [276]:
lc.LC.plotCorner(io_check)


Out[276]:
(<matplotlib.figure.Figure at 0x10ca7a750>,
 <matplotlib.figure.Figure at 0x10b1707d0>)

In [277]:
lc.LC.plotTrace(io_check)


Out[277]:

In [ ]: