This notebook demonstrates the method to produce the most basic simulation under consideration using the package varsim. The inputs here are:

  • a set of pointings (for simplicity, read in from a csv file)
  • a population of astrophysical sources described by a subclass of varsim.BasePopulation. This class must implement the abstract methods of varsim.BasePopulation, and provide an index for each source and the model parameters
  • a model for the sources described by a subclass of varsim.BaseModel. Again this subclass must implement all of the abstract methods and properties of varsim.BaseModel. The essential functionality of this class is to represent an astrophysical source as a model with model parameters, given which, this class has methods of predicting the model flux as a function of time at the top of the earth's atmosphere (ie. no sky noise included).
  • The simulation will be performed using the class varsim.BasicSimulation which is a subclass of the abstract base class varsim.BaseSimulation and implements concrete methods and properties necessary for the simulation. These methods and properties only use the abstract properties and methods of BaseModel and BasePopulation, and are therefore guaranteed to with any subclass.

Imports


In [1]:
import os

In [2]:
from opsimsummary import HealpixTiles, OpSimOutput

In [3]:
import numpy as np
import pandas as pd

In [5]:
from lsst.sims.photUtils import BandpassDict

In [6]:
from varsim import BasePopulation, BasicSimulation, BaseModel

In [7]:
#hptiles = HealpixTiles(nside=256, 
#                       preComputedMap='/Users/rbiswas/data/LSST/OpSimData/healpixelized_MINION_1016_256_64_indexed.db')

In [8]:
from lsst.sims.catUtils.supernovae import SNObject

In [9]:
import analyzeSN as ans

In [10]:
import varsim

The quantities of interest

Pointings


In [11]:
# The set of pointings randomly kept for convenience.
example_data = varsim.example_data
pointings_File = os.path.join(example_data, 'example_pointings.csv')
pointings = pd.read_csv(pointings_File, index_col='obsHistID')

In [12]:
# To show what this looks like
print(len(pointings))
pointings.head()


14
Out[12]:
sessionID propID fieldID fieldRA fieldDec filter expDate expMJD night visitTime ... moonBright darkBright rawSeeing wind humidity slewDist slewTime fiveSigmaDepth ditheredRA ditheredDec
obsHistID
1 1016 54 316 1.676483 -1.082473 y 2922 59580.033829 0 34.0 ... 0.0 105.610378 0.920473 0.0 0.0 1.620307 0.000000 21.021236 1.643930 -1.108924
14 1016 54 1118 1.709686 -0.607725 y 3424 59580.039637 0 34.0 ... 0.0 103.104582 0.903960 0.0 0.0 0.055856 4.599568 21.067249 1.691083 -0.634176
13 1016 54 1220 1.664386 -0.566519 y 3386 59580.039190 0 34.0 ... 0.0 101.147431 0.903960 0.0 0.0 0.048200 4.776511 21.091149 1.646286 -0.592970
12 1016 54 1212 1.608166 -0.575819 y 3347 59580.038741 0 34.0 ... 0.0 98.109397 0.903960 0.0 0.0 0.055665 4.739998 21.128319 1.589958 -0.602270
11 1016 54 1110 1.651280 -0.618574 y 3308 59580.038293 0 34.0 ... 0.0 100.125895 0.903960 0.0 0.0 0.056173 4.499824 21.103635 1.632535 -0.645025

5 rows × 46 columns


In [13]:
# We did not need to have all these columns. The essential columns are ra, dec, filter, 
# fivesigmadepth. It is also good to have fieldID, etc.

Population of astrophysical sources.

Here I use supernovae with the SALT model. I keep two supernovae in a completely random way without attempting to make sense. The important parts are that no matter how the Population model is implemented, it has:

  • modelparams : the method which takes the unique index of a supernova in the population and provides its model parameters as a dictionary. An important requirement is that the dictionary as the keys ra, dec, while the other parameters are completely user dependent
  • idxvalues : a property which is a sequence of indices. Here the sequence is implemented as a tuple, which is perhaps how it should be for large simulations.

In [14]:
class SALTPopulation(BasePopulation):
    def __init__(self):
        self.x0 = [5.0e-2, 3.e-5]
        self.x1 = [0, .1]
        self.c = [-0.2, 0.5]
        self.t0 = [59581., 59580. ]
        self.z = [0.5, 0.6]
        self.ra = [30., 30.]
        self.dec = [-45., -45.]
        
    def modelparams(self, idx):
        return dict(x0=self.x0[idx], x1=self.x1[idx], c=self.c[idx], t0=self.t0[idx],
                    z=self.z[idx], ra=self.ra[idx], dec=self.dec[idx])
    
    @property
    def idxvalues(self):
        return (x for x in (0, 1))
    @property
    def hasPositions(self):
        return True
    @property
    def positions(self):
        return (0, 1)

Instantiate the population and demonstrate


In [15]:
sp = SALTPopulation()

In [16]:
# The indices
idxs = tuple(sp.idxvalues)
print(idxs)


(0, 1)

In [17]:
# The model parameters
sp.modelparams(1)


Out[17]:
{'c': 0.5,
 'dec': -45.0,
 'ra': 30.0,
 't0': 59580.0,
 'x0': 3e-05,
 'x1': 0.1,
 'z': 0.6}

and the other one


In [18]:
sp.modelparams(0)


Out[18]:
{'c': -0.2,
 'dec': -45.0,
 'ra': 30.0,
 't0': 59581.0,
 'x0': 0.05,
 'x1': 0,
 'z': 0.5}

Model of source

  • Model : Subclass of varsim.BaseModel with its methods implemented. Here I use lsst.sims.catUtils.supernovae.SNObject functionality to provide functions
  • Provides minMjd and maxMjd to restrict the set of pointings over which we will build the light curve.
  • modelFlux: concrete implementation of abstract method BaseModel.modelFlux providing the flux, given the model parameters and mjd, bandpass.

In [19]:
# We will need the LSST bandpasses. Let us load them using the catsim method
bandpassdict = BandpassDict.loadTotalBandpassesFromFiles()

In [20]:
class Model(SNObject, BaseModel):
    def setModelParameters(self, **params):
        paramDict = params.copy()
        self.setCoords(ra=params['ra'], dec=params['dec'])
        for key in ('ra', 'dec'):
            params.pop(key)
        self.set(**params)
        self.mwEBVfromMaps()
    
    @property
    def minMjd(self):
        return self.mintime()
    @property
    def maxMjd(self):
        return self.maxtime()
    
    def modelFlux(self, mjd, bandpassobj):
        return self.catsimBandFlux(bandpassobject=bandpassobj,
                                      time=mjd)

Instantiate the model and demonstrate the functionality


In [21]:
model = Model()

In [22]:
# Let us set parameters (using the method `setModelParameters` in the abstract class
# to the parameters of the first object in SALTParameters)
model.setModelParameters(**sp.modelparams(0))

In [23]:
# Now, this should predict fluxes (in maggies) given a time, and a bandpassobject
f = (model.modelFlux(mjd=59580, bandpassobj=bandpassdict['y']), model.modelFlux(mjd=59580, bandpassobj=bandpassdict['g']))
print(f, -2.5 * np.log10(f))


((2.6960816540605439e-06, 2.5625595265137595e-06), array([ 13.9231674 ,  13.97831509]))

Simulation

Now we are ready to do the simulation using the class BasicSimulation


In [24]:
bsim = BasicSimulation(sp, model, pointings=pointings, rng=np.random.RandomState(0), 
                       maxObsHistID=1000000, pointingColumnDict=None,
                       pruneWithRadius=False)

In [38]:
!rm *.hdf

In [39]:
bsim.write_simulation(phot_output='sim_phot_all.hdf', pop_output='sim_pop.hdf', method='hdf', key='sim1')


writing 0, False, sim1
writing 1, False, sim1

In [40]:
phot_sim_df = pd.read_hdf('sim_phot_all.hdf', key='sim1')

In [41]:
phot_sim_df


Out[41]:
obsHistID objid expMJD filter ModelFlux fieldID flux fluxerr deviations zp zpsys
pid
1000000 1 0 59580.033829 y 2.696882e-06 316 2.694083e-06 1.640065e-09 -1.706270 0.0 ab
14000000 14 0 59580.039637 y 2.697018e-06 1118 2.700188e-06 1.624962e-09 1.950775 0.0 ab
13000000 13 0 59580.039190 y 2.697008e-06 1220 2.696183e-06 1.617539e-09 -0.509652 0.0 ab
12000000 12 0 59580.038741 y 2.696997e-06 1212 2.696293e-06 1.606565e-09 -0.438074 0.0 ab
11000000 11 0 59580.038293 y 2.696986e-06 1110 2.694965e-06 1.613773e-09 -1.252795 0.0 ab
10000000 10 0 59580.037847 y 2.696976e-06 1021 2.698242e-06 1.628304e-09 0.777490 0.0 ab
9000000 9 0 59580.037401 y 2.696965e-06 957 2.694317e-06 1.641323e-09 -1.613898 0.0 ab
8000000 8 0 59580.036955 y 2.696955e-06 857 2.696606e-06 1.639033e-09 -0.212740 0.0 ab
7000000 7 0 59580.036509 y 2.696945e-06 770 2.695478e-06 1.637419e-09 -0.895467 0.0 ab
6000000 6 0 59580.036062 y 2.696934e-06 680 2.697567e-06 1.636423e-09 0.386902 0.0 ab
5000000 5 0 59580.035616 y 2.696924e-06 587 2.696088e-06 1.636018e-09 -0.510805 0.0 ab
4000000 4 0 59580.035169 y 2.696913e-06 505 2.694981e-06 1.636188e-09 -1.180632 0.0 ab
3000000 3 0 59580.034722 y 2.696903e-06 441 2.696856e-06 1.636923e-09 -0.028182 0.0 ab
2000000 2 0 59580.034275 y 2.696892e-06 372 2.697594e-06 1.638228e-09 0.428332 0.0 ab
1000001 1 1 59580.033829 y 5.087947e-09 316 5.139922e-09 7.813779e-10 0.066517 0.0 ab
14000001 14 1 59580.039637 y 5.088211e-09 1118 5.314790e-09 7.490886e-10 0.302472 0.0 ab
13000001 13 1 59580.039190 y 5.088191e-09 1220 4.623326e-09 7.328528e-10 -0.634322 0.0 ab
12000001 12 1 59580.038741 y 5.088171e-09 1212 4.831238e-09 7.083070e-10 -0.362741 0.0 ab
11000001 11 1 59580.038293 y 5.088150e-09 1110 4.600944e-09 7.245128e-10 -0.672460 0.0 ab
10000001 10 1 59580.037847 y 5.088130e-09 1021 4.816188e-09 7.563333e-10 -0.359553 0.0 ab
9000001 9 1 59580.037401 y 5.088110e-09 957 4.450624e-09 7.839736e-10 -0.813146 0.0 ab
8000001 8 1 59580.036955 y 5.088089e-09 857 3.743016e-09 7.791733e-10 -1.726283 0.0 ab
7000001 7 1 59580.036509 y 5.088069e-09 770 5.225712e-09 7.757777e-10 0.177426 0.0 ab
6000001 6 1 59580.036062 y 5.088049e-09 680 4.777200e-09 7.736770e-10 -0.401781 0.0 ab
5000001 5 1 59580.035616 y 5.088029e-09 587 3.828169e-09 7.728259e-10 -1.630198 0.0 ab
4000001 4 1 59580.035169 y 5.088008e-09 505 5.445827e-09 7.731910e-10 0.462782 0.0 ab
3000001 3 1 59580.034722 y 5.087988e-09 441 4.385057e-09 7.747515e-10 -0.907298 0.0 ab
2000001 2 1 59580.034275 y 5.087968e-09 372 5.128356e-09 7.775096e-10 0.051945 0.0 ab

In [42]:
pop_sim_df = pd.read_hdf('sim_pop.hdf', key='sim1')

In [43]:
pop_sim_df


Out[43]:
c dec ra t0 x0 x1 z
0 -0.2 -45.0 30.0 59581.0 0.05000 0.0 0.5
1 0.5 -45.0 30.0 59580.0 0.00003 0.1 0.6

Scratch


In [38]:
bsim.lc(1).index.values.size


Out[38]:
14

In [24]:
np.unique(bsim.lc(0).index.values).size


Out[24]:
14

In [25]:
bsim.lc(0).columns


Out[25]:
Index([u'objid', u'expMJD', u'filter', u'ModelFlux', u'fieldID', u'flux',
       u'fluxerr', u'deviations', u'zp', u'zpsys'],
      dtype='object')

In [26]:
bsim.write_lc(0, 'test_0.hdf', 'hdf')


0 a
/usr/local/miniconda/lib/python2.7/site-packages/tables/path.py:100: NaturalNameWarning: object name is not a valid Python identifier: '0'; it does not match the pattern ``^[a-zA-Z_][a-zA-Z0-9_]*$``; you will not be able to use natural naming to access this object; using ``getattr()`` will still work, though
  NaturalNameWarning)

In [27]:
lc_0 = pd.read_hdf('test_0.hdf')

In [28]:
lc_0


Out[28]:
objid expMJD filter ModelFlux fieldID flux fluxerr deviations zp zpsys
pid
1000000 0 59580.033829 y 0.000003 316 0.000003 1.640065e-09 -1.706270 0.0 ab
14000000 0 59580.039637 y 0.000003 1118 0.000003 1.624962e-09 1.950775 0.0 ab
13000000 0 59580.039190 y 0.000003 1220 0.000003 1.617539e-09 -0.509652 0.0 ab
12000000 0 59580.038741 y 0.000003 1212 0.000003 1.606565e-09 -0.438074 0.0 ab
11000000 0 59580.038293 y 0.000003 1110 0.000003 1.613773e-09 -1.252795 0.0 ab
10000000 0 59580.037847 y 0.000003 1021 0.000003 1.628304e-09 0.777490 0.0 ab
9000000 0 59580.037401 y 0.000003 957 0.000003 1.641323e-09 -1.613898 0.0 ab
8000000 0 59580.036955 y 0.000003 857 0.000003 1.639033e-09 -0.212740 0.0 ab
7000000 0 59580.036509 y 0.000003 770 0.000003 1.637419e-09 -0.895467 0.0 ab
6000000 0 59580.036062 y 0.000003 680 0.000003 1.636423e-09 0.386902 0.0 ab
5000000 0 59580.035616 y 0.000003 587 0.000003 1.636018e-09 -0.510805 0.0 ab
4000000 0 59580.035169 y 0.000003 505 0.000003 1.636188e-09 -1.180632 0.0 ab
3000000 0 59580.034722 y 0.000003 441 0.000003 1.636923e-09 -0.028182 0.0 ab
2000000 0 59580.034275 y 0.000003 372 0.000003 1.638228e-09 0.428332 0.0 ab

In [22]:
bsim.write_simulation('test_sim.hdf', 'hdf', key='test', clobber=False)


writing 0, False, test
writing 1, False, test

In [23]:
simdf = pd.read_hdf('test_sim.hdf')

In [24]:
simdf


Out[24]:
objid expMJD filter ModelFlux fieldID flux fluxerr deviations zp zpsys
pid
1000000 0 59580.033829 y 2.696882e-06 316 2.696991e-06 1.640065e-09 0.066517 0.0 ab
14000000 0 59580.039637 y 2.697018e-06 1118 2.697510e-06 1.624962e-09 0.302472 0.0 ab
13000000 0 59580.039190 y 2.697008e-06 1220 2.695981e-06 1.617539e-09 -0.634322 0.0 ab
12000000 0 59580.038741 y 2.696997e-06 1212 2.696414e-06 1.606565e-09 -0.362741 0.0 ab
11000000 0 59580.038293 y 2.696986e-06 1110 2.695901e-06 1.613773e-09 -0.672460 0.0 ab
10000000 0 59580.037847 y 2.696976e-06 1021 2.696391e-06 1.628304e-09 -0.359553 0.0 ab
9000000 0 59580.037401 y 2.696965e-06 957 2.695631e-06 1.641323e-09 -0.813146 0.0 ab
8000000 0 59580.036955 y 2.696955e-06 857 2.694126e-06 1.639033e-09 -1.726283 0.0 ab
7000000 0 59580.036509 y 2.696945e-06 770 2.697235e-06 1.637419e-09 0.177426 0.0 ab
6000000 0 59580.036062 y 2.696934e-06 680 2.696277e-06 1.636423e-09 -0.401781 0.0 ab
5000000 0 59580.035616 y 2.696924e-06 587 2.694257e-06 1.636018e-09 -1.630198 0.0 ab
4000000 0 59580.035169 y 2.696913e-06 505 2.697670e-06 1.636188e-09 0.462782 0.0 ab
3000000 0 59580.034722 y 2.696903e-06 441 2.695417e-06 1.636923e-09 -0.907298 0.0 ab
2000000 0 59580.034275 y 2.696892e-06 372 2.696977e-06 1.638228e-09 0.051945 0.0 ab
1000001 1 59580.033829 y 5.087947e-09 316 5.657642e-09 7.813779e-10 0.729091 0.0 ab
14000001 1 59580.039637 y 5.088211e-09 1118 5.184831e-09 7.490886e-10 0.128983 0.0 ab
13000001 1 59580.039190 y 5.088191e-09 1220 5.923204e-09 7.328528e-10 1.139401 0.0 ab
12000001 1 59580.038741 y 5.088171e-09 1212 4.213535e-09 7.083070e-10 -1.234826 0.0 ab
11000001 1 59580.038293 y 5.088150e-09 1110 5.379652e-09 7.245128e-10 0.402342 0.0 ab
10000001 1 59580.037847 y 5.088130e-09 1021 4.570185e-09 7.563333e-10 -0.684810 0.0 ab
9000001 1 59580.037401 y 5.088110e-09 957 4.405428e-09 7.839736e-10 -0.870797 0.0 ab
8000001 1 59580.036955 y 5.088089e-09 857 4.637065e-09 7.791733e-10 -0.578850 0.0 ab
7000001 1 59580.036509 y 5.088069e-09 770 4.846374e-09 7.757777e-10 -0.311553 0.0 ab
6000001 1 59580.036062 y 5.088049e-09 680 5.131503e-09 7.736770e-10 0.056165 0.0 ab
5000001 1 59580.035616 y 5.088029e-09 587 4.187571e-09 7.728259e-10 -1.165150 0.0 ab
4000001 1 59580.035169 y 5.088008e-09 505 5.784519e-09 7.731910e-10 0.900826 0.0 ab
3000001 1 59580.034722 y 5.087988e-09 441 5.448761e-09 7.747515e-10 0.465662 0.0 ab
2000001 1 59580.034275 y 5.087968e-09 372 3.893523e-09 7.775096e-10 -1.536244 0.0 ab
1000000 0 59580.033829 y 2.696882e-06 316 2.696991e-06 1.640065e-09 0.066517 0.0 ab
14000000 0 59580.039637 y 2.697018e-06 1118 2.697510e-06 1.624962e-09 0.302472 0.0 ab
... ... ... ... ... ... ... ... ... ... ...
3000001 1 59580.034722 y 5.087988e-09 441 5.448761e-09 7.747515e-10 0.465662 0.0 ab
2000001 1 59580.034275 y 5.087968e-09 372 3.893523e-09 7.775096e-10 -1.536244 0.0 ab
1000000 0 59580.033829 y 2.696882e-06 316 2.699775e-06 1.640065e-09 1.764052 0.0 ab
14000000 0 59580.039637 y 2.697018e-06 1118 2.697668e-06 1.624962e-09 0.400157 0.0 ab
13000000 0 59580.039190 y 2.697008e-06 1220 2.698591e-06 1.617539e-09 0.978738 0.0 ab
12000000 0 59580.038741 y 2.696997e-06 1212 2.700597e-06 1.606565e-09 2.240893 0.0 ab
11000000 0 59580.038293 y 2.696986e-06 1110 2.700000e-06 1.613773e-09 1.867558 0.0 ab
10000000 0 59580.037847 y 2.696976e-06 1021 2.695385e-06 1.628304e-09 -0.977278 0.0 ab
9000000 0 59580.037401 y 2.696965e-06 957 2.698525e-06 1.641323e-09 0.950088 0.0 ab
8000000 0 59580.036955 y 2.696955e-06 857 2.696707e-06 1.639033e-09 -0.151357 0.0 ab
7000000 0 59580.036509 y 2.696945e-06 770 2.696776e-06 1.637419e-09 -0.103219 0.0 ab
6000000 0 59580.036062 y 2.696934e-06 680 2.697606e-06 1.636423e-09 0.410599 0.0 ab
5000000 0 59580.035616 y 2.696924e-06 587 2.697159e-06 1.636018e-09 0.144044 0.0 ab
4000000 0 59580.035169 y 2.696913e-06 505 2.699293e-06 1.636188e-09 1.454274 0.0 ab
3000000 0 59580.034722 y 2.696903e-06 441 2.698148e-06 1.636923e-09 0.761038 0.0 ab
2000000 0 59580.034275 y 2.696892e-06 372 2.697091e-06 1.638228e-09 0.121675 0.0 ab
1000001 1 59580.033829 y 5.087947e-09 316 5.434772e-09 7.813779e-10 0.443863 0.0 ab
14000001 1 59580.039637 y 5.088211e-09 1118 5.338163e-09 7.490886e-10 0.333674 0.0 ab
13000001 1 59580.039190 y 5.088191e-09 1220 6.183131e-09 7.328528e-10 1.494079 0.0 ab
12000001 1 59580.038741 y 5.088171e-09 1212 4.942856e-09 7.083070e-10 -0.205158 0.0 ab
11000001 1 59580.038293 y 5.088150e-09 1110 5.314972e-09 7.245128e-10 0.313068 0.0 ab
10000001 1 59580.037847 y 5.088130e-09 1021 4.442149e-09 7.563333e-10 -0.854096 0.0 ab
9000001 1 59580.037401 y 5.088110e-09 957 3.086633e-09 7.839736e-10 -2.552990 0.0 ab
8000001 1 59580.036955 y 5.088089e-09 857 5.597372e-09 7.791733e-10 0.653619 0.0 ab
7000001 1 59580.036509 y 5.088069e-09 770 5.758679e-09 7.757777e-10 0.864436 0.0 ab
6000001 1 59580.036062 y 5.088049e-09 680 4.513853e-09 7.736770e-10 -0.742165 0.0 ab
5000001 1 59580.035616 y 5.088029e-09 587 6.842154e-09 7.728259e-10 2.269755 0.0 ab
4000001 1 59580.035169 y 5.088008e-09 505 3.963506e-09 7.731910e-10 -1.454366 0.0 ab
3000001 1 59580.034722 y 5.087988e-09 441 5.123439e-09 7.747515e-10 0.045759 0.0 ab
2000001 1 59580.034275 y 5.087968e-09 372 4.942430e-09 7.775096e-10 -0.187184 0.0 ab

84 rows × 10 columns


In [25]:
bsim.write_population()


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-25-6fc3f6cf0e39> in <module>()
----> 1 bsim.write_population()

TypeError: write_population() takes at least 3 arguments (1 given)

In [23]:
df = pd.read_hdf('test.hdf', key='test')

In [36]:
bsim.lc(1).to_hdf('test.hdf', key='test', mode='w', append=True, format='t')

In [37]:
bsim.lc(0).to_hdf('test.hdf', key='test', mode='a', append=True, format='t')

In [38]:
df = pd.read_hdf('test.hdf', key='test')

In [39]:
df


Out[39]:
objid expMJD filter ModelFlux fieldID flux fluxerr deviations zp zpsys
pid
1000001 1 59580.033829 y 5.087947e-09 316 4.585038e-09 7.813779e-10 -0.643618 0.0 ab
14000001 1 59580.039637 y 5.088211e-09 1118 3.422685e-09 7.490886e-10 -2.223403 0.0 ab
13000001 1 59580.039190 y 5.088191e-09 1220 5.546394e-09 7.328528e-10 0.625231 0.0 ab
12000001 1 59580.038741 y 5.088171e-09 1212 3.953422e-09 7.083070e-10 -1.602058 0.0 ab
11000001 1 59580.038293 y 5.088150e-09 1110 4.288010e-09 7.245128e-10 -1.104383 0.0 ab
10000001 1 59580.037847 y 5.088130e-09 1021 5.127584e-09 7.563333e-10 0.052165 0.0 ab
9000001 1 59580.037401 y 5.088110e-09 957 4.508312e-09 7.839736e-10 -0.739563 0.0 ab
8000001 1 59580.036955 y 5.088089e-09 857 6.290365e-09 7.791733e-10 1.543015 0.0 ab
7000001 1 59580.036509 y 5.088069e-09 770 4.085100e-09 7.757777e-10 -1.292857 0.0 ab
6000001 1 59580.036062 y 5.088049e-09 680 5.294660e-09 7.736770e-10 0.267051 0.0 ab
5000001 1 59580.035616 y 5.088029e-09 587 5.057670e-09 7.728259e-10 -0.039283 0.0 ab
4000001 1 59580.035169 y 5.088008e-09 505 4.184849e-09 7.731910e-10 -1.168093 0.0 ab
3000001 1 59580.034722 y 5.087988e-09 441 5.493397e-09 7.747515e-10 0.523277 0.0 ab
2000001 1 59580.034275 y 5.087968e-09 372 4.954589e-09 7.775096e-10 -0.171546 0.0 ab
1000000 0 59580.033829 y 2.696882e-06 316 2.698147e-06 1.640065e-09 0.771791 0.0 ab
14000000 0 59580.039637 y 2.697018e-06 1118 2.698356e-06 1.624962e-09 0.823504 0.0 ab
13000000 0 59580.039190 y 2.697008e-06 1220 2.700507e-06 1.617539e-09 2.163236 0.0 ab
12000000 0 59580.038741 y 2.696997e-06 1212 2.699144e-06 1.606565e-09 1.336528 0.0 ab
11000000 0 59580.038293 y 2.696986e-06 1110 2.696391e-06 1.613773e-09 -0.369182 0.0 ab
10000000 0 59580.037847 y 2.696976e-06 1021 2.696586e-06 1.628304e-09 -0.239379 0.0 ab
9000000 0 59580.037401 y 2.696965e-06 957 2.698770e-06 1.641323e-09 1.099660 0.0 ab
8000000 0 59580.036955 y 2.696955e-06 857 2.698029e-06 1.639033e-09 0.655264 0.0 ab
7000000 0 59580.036509 y 2.696945e-06 770 2.697993e-06 1.637419e-09 0.640132 0.0 ab
6000000 0 59580.036062 y 2.696934e-06 680 2.694288e-06 1.636423e-09 -1.616956 0.0 ab
5000000 0 59580.035616 y 2.696924e-06 587 2.696884e-06 1.636018e-09 -0.024326 0.0 ab
4000000 0 59580.035169 y 2.696913e-06 505 2.695705e-06 1.636188e-09 -0.738031 0.0 ab
3000000 0 59580.034722 y 2.696903e-06 441 2.697361e-06 1.636923e-09 0.279925 0.0 ab
2000000 0 59580.034275 y 2.696892e-06 372 2.696731e-06 1.638228e-09 -0.098150 0.0 ab

In [23]:
bsim.write_lc(0, 'test_0.csv', 'csv', key=None)


0 a

In [25]:
dfcsv = pd.read_csv('test_0.csv')

In [25]:
bsim.write_simulation('test.hdf', 'hdf', key=None)


writing 0, False, None
0 a
writing 1, False, None
1 a

In [40]:
df = pd.read_hdf('test.hdf', key='0')

In [41]:
df.to_sql('')


Out[41]:
objid expMJD filter ModelFlux fieldID flux fluxerr deviations zp zpsys
pid
1000000 0 59580.033829 y 0.000003 316 0.000003 1.640065e-09 0.066517 0.0 ab
14000000 0 59580.039637 y 0.000003 1118 0.000003 1.624962e-09 0.302472 0.0 ab
13000000 0 59580.039190 y 0.000003 1220 0.000003 1.617539e-09 -0.634322 0.0 ab
12000000 0 59580.038741 y 0.000003 1212 0.000003 1.606565e-09 -0.362741 0.0 ab
11000000 0 59580.038293 y 0.000003 1110 0.000003 1.613773e-09 -0.672460 0.0 ab
10000000 0 59580.037847 y 0.000003 1021 0.000003 1.628304e-09 -0.359553 0.0 ab
9000000 0 59580.037401 y 0.000003 957 0.000003 1.641323e-09 -0.813146 0.0 ab
8000000 0 59580.036955 y 0.000003 857 0.000003 1.639033e-09 -1.726283 0.0 ab
7000000 0 59580.036509 y 0.000003 770 0.000003 1.637419e-09 0.177426 0.0 ab
6000000 0 59580.036062 y 0.000003 680 0.000003 1.636423e-09 -0.401781 0.0 ab
5000000 0 59580.035616 y 0.000003 587 0.000003 1.636018e-09 -1.630198 0.0 ab
4000000 0 59580.035169 y 0.000003 505 0.000003 1.636188e-09 0.462782 0.0 ab
3000000 0 59580.034722 y 0.000003 441 0.000003 1.636923e-09 -0.907298 0.0 ab
2000000 0 59580.034275 y 0.000003 372 0.000003 1.638228e-09 0.051945 0.0 ab

In [24]:
bsim.write_population('pop.hdf', method='hdf')


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-24-4d9bb8eb2d85> in <module>()
----> 1 bsim.write_population('pop.hdf', method='hdf')

NameError: name 'bsim' is not defined

In [ ]:
sp.idxvalues

In [28]:
dfcsv.equals(df, )


Out[28]:
False

In [24]:
bsim = BasicSimulation(population=sp, model=Model, pointings=)


  File "<ipython-input-24-a94f7f6b7efb>", line 1
    bsim = BasicSimulation(population=sp, model=Model, pointings=)
                                                                 ^
SyntaxError: invalid syntax

In [21]:
bsim.write_lc(0, 'lc_0.hdf', 'hdf')


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-21-c68c5c9654d2> in <module>()
----> 1 bsim.write_lc(0, 'lc_0.hdf', 'hdf')

/Users/rbiswas/.local/lib/python2.7/site-packages/varsim/simulations.pyc in write_lc(self, idx, output, method, clobber)
    123 
    124         if method == 'hdf':
--> 125             lc.to_hdf(output, mode=mode)
    126         elif method == 'csv':
    127             lc.to_csv(output, model=mode)

TypeError: to_hdf() takes exactly 3 arguments (2 given)

In [ ]:
pd.DataFrame.to_hdf()

In [28]:
bsim.write_simulation('test.hdf', 'hdf', key='test')


writing 0, False, test
0 a
writing 1, False, test
1 a

In [29]:
simdf = pd.read_hdf('test.hdf', key='test')

In [30]:
simdf


Out[30]:
objid expMJD filter ModelFlux fieldID flux fluxerr deviations zp zpsys
pid
1000001 1 59580.033829 y 5.087947e-09 316 4.585038e-09 7.813779e-10 -0.643618 0.0 ab
14000001 1 59580.039637 y 5.088211e-09 1118 3.422685e-09 7.490886e-10 -2.223403 0.0 ab
13000001 1 59580.039190 y 5.088191e-09 1220 5.546394e-09 7.328528e-10 0.625231 0.0 ab
12000001 1 59580.038741 y 5.088171e-09 1212 3.953422e-09 7.083070e-10 -1.602058 0.0 ab
11000001 1 59580.038293 y 5.088150e-09 1110 4.288010e-09 7.245128e-10 -1.104383 0.0 ab
10000001 1 59580.037847 y 5.088130e-09 1021 5.127584e-09 7.563333e-10 0.052165 0.0 ab
9000001 1 59580.037401 y 5.088110e-09 957 4.508312e-09 7.839736e-10 -0.739563 0.0 ab
8000001 1 59580.036955 y 5.088089e-09 857 6.290365e-09 7.791733e-10 1.543015 0.0 ab
7000001 1 59580.036509 y 5.088069e-09 770 4.085100e-09 7.757777e-10 -1.292857 0.0 ab
6000001 1 59580.036062 y 5.088049e-09 680 5.294660e-09 7.736770e-10 0.267051 0.0 ab
5000001 1 59580.035616 y 5.088029e-09 587 5.057670e-09 7.728259e-10 -0.039283 0.0 ab
4000001 1 59580.035169 y 5.088008e-09 505 4.184849e-09 7.731910e-10 -1.168093 0.0 ab
3000001 1 59580.034722 y 5.087988e-09 441 5.493397e-09 7.747515e-10 0.523277 0.0 ab
2000001 1 59580.034275 y 5.087968e-09 372 4.954589e-09 7.775096e-10 -0.171546 0.0 ab
1000000 0 59580.033829 y 2.696882e-06 316 2.698147e-06 1.640065e-09 0.771791 0.0 ab
14000000 0 59580.039637 y 2.697018e-06 1118 2.698356e-06 1.624962e-09 0.823504 0.0 ab
13000000 0 59580.039190 y 2.697008e-06 1220 2.700507e-06 1.617539e-09 2.163236 0.0 ab
12000000 0 59580.038741 y 2.696997e-06 1212 2.699144e-06 1.606565e-09 1.336528 0.0 ab
11000000 0 59580.038293 y 2.696986e-06 1110 2.696391e-06 1.613773e-09 -0.369182 0.0 ab
10000000 0 59580.037847 y 2.696976e-06 1021 2.696586e-06 1.628304e-09 -0.239379 0.0 ab
9000000 0 59580.037401 y 2.696965e-06 957 2.698770e-06 1.641323e-09 1.099660 0.0 ab
8000000 0 59580.036955 y 2.696955e-06 857 2.698029e-06 1.639033e-09 0.655264 0.0 ab
7000000 0 59580.036509 y 2.696945e-06 770 2.697993e-06 1.637419e-09 0.640132 0.0 ab
6000000 0 59580.036062 y 2.696934e-06 680 2.694288e-06 1.636423e-09 -1.616956 0.0 ab
5000000 0 59580.035616 y 2.696924e-06 587 2.696884e-06 1.636018e-09 -0.024326 0.0 ab
4000000 0 59580.035169 y 2.696913e-06 505 2.695705e-06 1.636188e-09 -0.738031 0.0 ab
3000000 0 59580.034722 y 2.696903e-06 441 2.697361e-06 1.636923e-09 0.279925 0.0 ab
2000000 0 59580.034275 y 2.696892e-06 372 2.696731e-06 1.638228e-09 -0.098150 0.0 ab
1000000 0 59580.033829 y 2.696882e-06 316 2.699322e-06 1.640065e-09 1.488252 0.0 ab
14000000 0 59580.039637 y 2.697018e-06 1118 2.700099e-06 1.624962e-09 1.895889 0.0 ab
13000000 0 59580.039190 y 2.697008e-06 1220 2.698914e-06 1.617539e-09 1.178780 0.0 ab
12000000 0 59580.038741 y 2.696997e-06 1212 2.696708e-06 1.606565e-09 -0.179925 0.0 ab
11000000 0 59580.038293 y 2.696986e-06 1110 2.695258e-06 1.613773e-09 -1.070753 0.0 ab
10000000 0 59580.037847 y 2.696976e-06 1021 2.698693e-06 1.628304e-09 1.054452 0.0 ab
9000000 0 59580.037401 y 2.696965e-06 957 2.696304e-06 1.641323e-09 -0.403177 0.0 ab
8000000 0 59580.036955 y 2.696955e-06 857 2.698959e-06 1.639033e-09 1.222445 0.0 ab
7000000 0 59580.036509 y 2.696945e-06 770 2.697286e-06 1.637419e-09 0.208275 0.0 ab
6000000 0 59580.036062 y 2.696934e-06 680 2.698532e-06 1.636423e-09 0.976639 0.0 ab
5000000 0 59580.035616 y 2.696924e-06 587 2.697507e-06 1.636018e-09 0.356366 0.0 ab
4000000 0 59580.035169 y 2.696913e-06 505 2.698069e-06 1.636188e-09 0.706573 0.0 ab
3000000 0 59580.034722 y 2.696903e-06 441 2.696920e-06 1.636923e-09 0.010500 0.0 ab
2000000 0 59580.034275 y 2.696892e-06 372 2.699818e-06 1.638228e-09 1.785870 0.0 ab
1000001 1 59580.033829 y 5.087947e-09 316 5.187114e-09 7.813779e-10 0.126912 0.0 ab
14000001 1 59580.039637 y 5.088211e-09 1118 5.389337e-09 7.490886e-10 0.401989 0.0 ab
13000001 1 59580.039190 y 5.088191e-09 1220 6.468263e-09 7.328528e-10 1.883151 0.0 ab
12000001 1 59580.038741 y 5.088171e-09 1212 4.133543e-09 7.083070e-10 -1.347759 0.0 ab
11000001 1 59580.038293 y 5.088150e-09 1110 4.167668e-09 7.245128e-10 -1.270485 0.0 ab
10000001 1 59580.037847 y 5.088130e-09 1021 5.821317e-09 7.563333e-10 0.969397 0.0 ab
9000001 1 59580.037401 y 5.088110e-09 957 4.168412e-09 7.839736e-10 -1.173123 0.0 ab
8000001 1 59580.036955 y 5.088089e-09 857 6.602507e-09 7.791733e-10 1.943621 0.0 ab
7000001 1 59580.036509 y 5.088069e-09 770 4.767193e-09 7.757777e-10 -0.413619 0.0 ab
6000001 1 59580.036062 y 5.088049e-09 680 4.509760e-09 7.736770e-10 -0.747455 0.0 ab
5000001 1 59580.035616 y 5.088029e-09 587 6.574128e-09 7.728259e-10 1.922942 0.0 ab
4000001 1 59580.035169 y 5.088008e-09 505 6.232729e-09 7.731910e-10 1.480515 0.0 ab
3000001 1 59580.034722 y 5.087988e-09 441 6.534882e-09 7.747515e-10 1.867559 0.0 ab
2000001 1 59580.034275 y 5.087968e-09 372 5.792426e-09 7.775096e-10 0.906045 0.0 ab

In [ ]:
sp.positions

In [ ]:
model = Model()

In [ ]:
sp.modelparams(0)

In [ ]:
sp.modelparams(0)

In [ ]:
model.setModelParameters(**sp.modelparams(0))

In [ ]:
model.sn.SNstate

In [ ]:
sn = SNObject()

In [ ]:
params

In [ ]:
sn.setCoords(params['ra'], params['dec'])

In [ ]:
sn.set(**params)

In [ ]:
sn.mwEBVfromMaps()

In [ ]:
sn.SNstate

In [ ]:
model = Model()

In [ ]:
params = sp.modelparams(0).copy()

In [ ]:
for key in ('ra', 'dec'):
    params.pop(key)

In [ ]:
params

In [ ]:
sn.set(**params)

In [ ]:
sn.SNstate

In [ ]:
model.setModelParameters(**sp.modelparams(0))

In [ ]:
model.sn.SNstate

In [ ]:
bandpassobj = bandpassdict['y']

In [ ]:
model.setModelParameters(**sp.modelparams(0))

In [ ]:
model.modelFlux(59580., bandpassobj=bandpassobj)

In [ ]:
bsim = BasicSimulation(sp, model, pointings, rng=np.random.RandomState(0), 
                       maxObsHistID=1000000, pointingColumnDict=None,
                       timeRange=
                      pruneWithRadius=False)

In [ ]:
bsim.model.maxMjd

In [ ]:
bsim.model.r

In [ ]:
scrtch__

In [ ]:
opsout = _OpSimOutput.fromOpSimDB('/Users/rbiswas/data/LSST/OpSimData/minion_1016_sqlite.db',
                                 )

In [ ]:
pointings = opsout.summary.query('expMJD < 59580.04')

In [ ]:
pointings.expMJD.min()

In [ ]:
len(pointings)

In [ ]:
pointings.to_csv('check_poinx``tings.csv')

In [ ]:
!head check_pointings.csv

In [ ]:
from var

In [ ]:
from varsim import BaseExcep

In [ ]:
import pandas as pd

In [ ]:
import numpy as np

In [ ]:
df = pd.DataFrame()

In [ ]:
df['objid'] = np.arange(10)

In [ ]:
df

In [24]:
280 *2 /4 + 20


Out[24]:
160

In [116]:
from collections import namedtuple, OrderedDict as odict

In [129]:
keys = 'abcde'
vals = np.arange(5)
idx = 'pq'
s1 = (dict( (k, v) for (i, k,v) in zip(idx, keys, vals)))
s2 = (dict( (k, v) for (i, k,v) in zip(idx, keys, vals)))

In [117]:
s = namedtuple(idx, s1)

In [123]:
s = list()
_ = list(s.append(x) for x in (s1, s2))

In [127]:
s1


Out[127]:
{'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4}

In [102]:
xx = list()

In [107]:
xx = tuple(s)

In [103]:
xx.append(s)

In [133]:
idx = (l for l in idx)

In [135]:
df = pd.DataFrame(s, index=idx)

In [136]:
df


Out[136]:
a b c d e
p 0 1 2 3 4
q 0 1 2 3 4

In [57]:
df = pd.DataFrame()

In [58]:
type(s)


Out[58]:
dict

In [56]:
df.append(s)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-56-0cd6682a1d65> in <module>()
----> 1 df.append(s)

/usr/local/miniconda/lib/python2.7/site-packages/pandas/core/frame.pyc in append(self, other, ignore_index, verify_integrity)
   4414                 other = Series(other)
   4415             if other.name is None and not ignore_index:
-> 4416                 raise TypeError('Can only append a Series if ignore_index=True'
   4417                                 ' or if the Series has a name')
   4418 

TypeError: Can only append a Series if ignore_index=True or if the Series has a name

In [ ]: