The LightCurve class is a class which enables repeating simple calculations that are often used for light curves:

  • The native format is a dataframe with flux, and flux uncertainties and bandpasses in columns.
  • The output light curve uses standardized names for these quantities. These names are automatically produced from a sequence of aliases usually used to name these quantities. The sequence of aliases can be expanded (though obvious problems can come up because of this)
  • It produces a coadded light curve if requested using a simple (not weighted) mean. Such coadds are constructed using pandas aggregation mechanisms. The number of points combined in a coadd is shown. The coadds require a time (in units of days) over which the coadd is performed. Additionally, a minMJD value or an offset to the minimum MJD value in the light curve can be used to fix the phase.
  • It can produce the native light curve or a coadded light curve in SNCosmo format. This enables SNCosmo plots of the light curve as also SNCosmo fits.
  • It is easy to obtain the SNR of each data point.

TODO :

  • Coadd functionality : Use weighted mean will be added later.
  • Coadd functionality : Show the obsHistID of coadded points, Alternatively provide indices that can reconstruct the obsHistID.
  • Coadd functionality : Input user specified groups of obsHistIDs to coadd together

In [20]:
import snsims

In [21]:
import sncosmo

In [22]:
%matplotlib inline

In [23]:
import matplotlib.pyplot as plt

In [9]:
import seaborn as sns
sns.set()


/usr/local/miniconda/lib/python2.7/site-packages/IPython/html.py:14: ShimWarning: The `IPython.html` package has been deprecated. You should import from `notebook` instead. `IPython.html.widgets` has moved to `ipywidgets`.
  "`IPython.html.widgets` has moved to `ipywidgets`.", ShimWarning)

Here is a simple example

We will consider data that is used as an example in SNCosmo, and look at the LightCurve functionality on this.


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

model = sncosmo.Model(source='salt2')

In [7]:
model.set(**data.meta)

In [8]:
print model


<Model at 0x1196a0150>
source:
  class      : SALT2Source
  name       : 'salt2'
  version    : 2.4
  phases     : [-20, .., 50] days
  wavelengths: [2000, .., 9200] Angstroms
parameters:
  z  = 0.5
  t0 = 55100.0
  x0 = 1.20482820761e-05
  x1 = 0.5
  c  = 0.20000000000000001

In [10]:
fig = sncosmo.plot_lc(data, model=model, color='k')



In [11]:
lc = snsims.LightCurve(data.to_pandas())

In [12]:
lc.lightCurve


Out[12]:
mjd band flux fluxerr zp zpsys
0 55070.000000 sdssg 0.363512 0.672844 25.0 ab
1 55072.051282 sdssr -0.200801 0.672844 25.0 ab
2 55074.102564 sdssi 0.307494 0.672844 25.0 ab
3 55076.153846 sdssz 1.087761 0.672844 25.0 ab
4 55078.205128 sdssg -0.436679 0.672844 25.0 ab
5 55080.256410 sdssr 1.097810 0.672844 25.0 ab
6 55082.307692 sdssi 3.756269 0.672844 25.0 ab
7 55084.358974 sdssz 5.348589 0.672844 25.0 ab
8 55086.410256 sdssg 2.826142 0.672844 25.0 ab
9 55088.461538 sdssr 7.565470 0.672844 25.0 ab
10 55090.512821 sdssi 7.433170 0.672844 25.0 ab
11 55092.564103 sdssz 10.703299 0.672844 25.0 ab
12 55094.615385 sdssg 1.578237 0.672844 25.0 ab
13 55096.666667 sdssr 9.420167 0.672844 25.0 ab
14 55098.717949 sdssi 12.111621 0.672844 25.0 ab
15 55100.769231 sdssz 13.644534 0.672844 25.0 ab
16 55102.820513 sdssg 2.208754 0.672844 25.0 ab
17 55104.871795 sdssr 9.634420 0.672844 25.0 ab
18 55106.923077 sdssi 11.372477 0.672844 25.0 ab
19 55108.974359 sdssz 12.573904 0.672844 25.0 ab
20 55111.025641 sdssg 0.608391 0.672844 25.0 ab
21 55113.076923 sdssr 5.916429 0.672844 25.0 ab
22 55115.128205 sdssi 7.994282 0.672844 25.0 ab
23 55117.179487 sdssz 7.908628 0.672844 25.0 ab
24 55119.230769 sdssg 0.679196 0.672844 25.0 ab
25 55121.282051 sdssr 4.034473 0.672844 25.0 ab
26 55123.333333 sdssi 7.035843 0.672844 25.0 ab
27 55125.384615 sdssz 6.840864 0.672844 25.0 ab
28 55127.435897 sdssg 0.325443 0.672844 25.0 ab
29 55129.487179 sdssr 2.659749 0.672844 25.0 ab
30 55131.538462 sdssi 3.995204 0.672844 25.0 ab
31 55133.589744 sdssz 5.739895 0.672844 25.0 ab
32 55135.641026 sdssg 0.330702 0.672844 25.0 ab
33 55137.692308 sdssr 0.565287 0.672844 25.0 ab
34 55139.743590 sdssi 3.043183 0.672844 25.0 ab
35 55141.794872 sdssz 5.626927 0.672844 25.0 ab
36 55143.846154 sdssg -0.722655 0.672844 25.0 ab
37 55145.897436 sdssr 1.120918 0.672844 25.0 ab
38 55147.948718 sdssi 2.124670 0.672844 25.0 ab
39 55150.000000 sdssz 5.348218 0.672844 25.0 ab

In [13]:
newdata = data.to_pandas()

In [14]:
newdata.columns


Out[14]:
Index([u'time', u'band', u'flux', u'fluxerr', u'zp', u'zpsys'], dtype='object')

In [15]:
newdata.rename(columns={'time': 'expMJD'}, inplace=True)

In [16]:
newdata


Out[16]:
expMJD band flux fluxerr zp zpsys
0 55070.000000 sdssg 0.363512 0.672844 25.0 ab
1 55072.051282 sdssr -0.200801 0.672844 25.0 ab
2 55074.102564 sdssi 0.307494 0.672844 25.0 ab
3 55076.153846 sdssz 1.087761 0.672844 25.0 ab
4 55078.205128 sdssg -0.436679 0.672844 25.0 ab
5 55080.256410 sdssr 1.097810 0.672844 25.0 ab
6 55082.307692 sdssi 3.756269 0.672844 25.0 ab
7 55084.358974 sdssz 5.348589 0.672844 25.0 ab
8 55086.410256 sdssg 2.826142 0.672844 25.0 ab
9 55088.461538 sdssr 7.565470 0.672844 25.0 ab
10 55090.512821 sdssi 7.433170 0.672844 25.0 ab
11 55092.564103 sdssz 10.703299 0.672844 25.0 ab
12 55094.615385 sdssg 1.578237 0.672844 25.0 ab
13 55096.666667 sdssr 9.420167 0.672844 25.0 ab
14 55098.717949 sdssi 12.111621 0.672844 25.0 ab
15 55100.769231 sdssz 13.644534 0.672844 25.0 ab
16 55102.820513 sdssg 2.208754 0.672844 25.0 ab
17 55104.871795 sdssr 9.634420 0.672844 25.0 ab
18 55106.923077 sdssi 11.372477 0.672844 25.0 ab
19 55108.974359 sdssz 12.573904 0.672844 25.0 ab
20 55111.025641 sdssg 0.608391 0.672844 25.0 ab
21 55113.076923 sdssr 5.916429 0.672844 25.0 ab
22 55115.128205 sdssi 7.994282 0.672844 25.0 ab
23 55117.179487 sdssz 7.908628 0.672844 25.0 ab
24 55119.230769 sdssg 0.679196 0.672844 25.0 ab
25 55121.282051 sdssr 4.034473 0.672844 25.0 ab
26 55123.333333 sdssi 7.035843 0.672844 25.0 ab
27 55125.384615 sdssz 6.840864 0.672844 25.0 ab
28 55127.435897 sdssg 0.325443 0.672844 25.0 ab
29 55129.487179 sdssr 2.659749 0.672844 25.0 ab
30 55131.538462 sdssi 3.995204 0.672844 25.0 ab
31 55133.589744 sdssz 5.739895 0.672844 25.0 ab
32 55135.641026 sdssg 0.330702 0.672844 25.0 ab
33 55137.692308 sdssr 0.565287 0.672844 25.0 ab
34 55139.743590 sdssi 3.043183 0.672844 25.0 ab
35 55141.794872 sdssz 5.626927 0.672844 25.0 ab
36 55143.846154 sdssg -0.722655 0.672844 25.0 ab
37 55145.897436 sdssr 1.120918 0.672844 25.0 ab
38 55147.948718 sdssi 2.124670 0.672844 25.0 ab
39 55150.000000 sdssz 5.348218 0.672844 25.0 ab

In [17]:
newlc = snsims.LightCurve(newdata)

In [18]:
newlc.columnAliases


Out[18]:
{'band': ['filter', 'filtername', 'bandname', 'bands'],
 'fluxerr': ['flux_err', 'flux_errs', 'fluxerror'],
 'mjd': ['time', 'expmjd']}

In [19]:
newlc._lightCurve.columns


Out[19]:
Index([u'expMJD', u'band', u'flux', u'fluxerr', u'zp', u'zpsys'], dtype='object')

In [19]:
snsims.aliasDictionary(newlc._lightCurve.columns, newlc.columnAliases)


Out[19]:
{'expMJD': 'mjd'}

In [20]:
snsims.aliasDictionary(data.columns, newlc.columnAliases)


Out[20]:
{'time': 'mjd'}

In [21]:
newlc.lightCurve


Out[21]:
mjd band flux fluxerr zp zpsys
0 55070.000000 sdssg 0.363512 0.672844 25.0 ab
1 55072.051282 sdssr -0.200801 0.672844 25.0 ab
2 55074.102564 sdssi 0.307494 0.672844 25.0 ab
3 55076.153846 sdssz 1.087761 0.672844 25.0 ab
4 55078.205128 sdssg -0.436679 0.672844 25.0 ab
5 55080.256410 sdssr 1.097810 0.672844 25.0 ab
6 55082.307692 sdssi 3.756269 0.672844 25.0 ab
7 55084.358974 sdssz 5.348589 0.672844 25.0 ab
8 55086.410256 sdssg 2.826142 0.672844 25.0 ab
9 55088.461538 sdssr 7.565470 0.672844 25.0 ab
10 55090.512821 sdssi 7.433170 0.672844 25.0 ab
11 55092.564103 sdssz 10.703299 0.672844 25.0 ab
12 55094.615385 sdssg 1.578237 0.672844 25.0 ab
13 55096.666667 sdssr 9.420167 0.672844 25.0 ab
14 55098.717949 sdssi 12.111621 0.672844 25.0 ab
15 55100.769231 sdssz 13.644534 0.672844 25.0 ab
16 55102.820513 sdssg 2.208754 0.672844 25.0 ab
17 55104.871795 sdssr 9.634420 0.672844 25.0 ab
18 55106.923077 sdssi 11.372477 0.672844 25.0 ab
19 55108.974359 sdssz 12.573904 0.672844 25.0 ab
20 55111.025641 sdssg 0.608391 0.672844 25.0 ab
21 55113.076923 sdssr 5.916429 0.672844 25.0 ab
22 55115.128205 sdssi 7.994282 0.672844 25.0 ab
23 55117.179487 sdssz 7.908628 0.672844 25.0 ab
24 55119.230769 sdssg 0.679196 0.672844 25.0 ab
25 55121.282051 sdssr 4.034473 0.672844 25.0 ab
26 55123.333333 sdssi 7.035843 0.672844 25.0 ab
27 55125.384615 sdssz 6.840864 0.672844 25.0 ab
28 55127.435897 sdssg 0.325443 0.672844 25.0 ab
29 55129.487179 sdssr 2.659749 0.672844 25.0 ab
30 55131.538462 sdssi 3.995204 0.672844 25.0 ab
31 55133.589744 sdssz 5.739895 0.672844 25.0 ab
32 55135.641026 sdssg 0.330702 0.672844 25.0 ab
33 55137.692308 sdssr 0.565287 0.672844 25.0 ab
34 55139.743590 sdssi 3.043183 0.672844 25.0 ab
35 55141.794872 sdssz 5.626927 0.672844 25.0 ab
36 55143.846154 sdssg -0.722655 0.672844 25.0 ab
37 55145.897436 sdssr 1.120918 0.672844 25.0 ab
38 55147.948718 sdssi 2.124670 0.672844 25.0 ab
39 55150.000000 sdssz 5.348218 0.672844 25.0 ab

In [22]:
sncosmo.plot_lc(newlc.snCosmoLC(), model, color='k')


Out[22]:

In [32]:
lc.coaddedLC(coaddTimes=10.)


Out[32]:
band mjd fluxerr zpsys flux numCoadded zp SNR
discreteTime
0 sdssg 55074.102564 0.475772 ab -0.036584 2 25.0 -0.076893
0 sdssi 55074.102564 0.672844 ab 0.307494 1 25.0 0.457007
0 sdssr 55072.051282 0.672844 ab -0.200801 1 25.0 -0.298437
0 sdssz 55076.153846 0.672844 ab 1.087761 1 25.0 1.616662
1 sdssg 55086.410256 0.672844 ab 2.826142 1 25.0 4.200294
1 sdssi 55082.307692 0.672844 ab 3.756269 1 25.0 5.582675
1 sdssr 55084.358974 0.475772 ab 4.331640 2 25.0 9.104437
1 sdssz 55084.358974 0.672844 ab 5.348589 1 25.0 7.949228
2 sdssg 55094.615385 0.672844 ab 1.578237 1 25.0 2.345621
2 sdssi 55094.615385 0.475772 ab 9.772395 2 25.0 20.540061
2 sdssr 55096.666667 0.672844 ab 9.420167 1 25.0 14.000525
2 sdssz 55092.564103 0.672844 ab 10.703299 1 25.0 15.907553
3 sdssg 55102.820513 0.672844 ab 2.208754 1 25.0 3.282714
3 sdssi 55106.923077 0.672844 ab 11.372477 1 25.0 16.902104
3 sdssr 55104.871795 0.672844 ab 9.634420 1 25.0 14.318954
3 sdssz 55104.871795 0.475772 ab 13.109219 2 25.0 27.553547
4 sdssg 55115.128205 0.475772 ab 0.643794 2 25.0 1.353155
4 sdssi 55115.128205 0.672844 ab 7.994282 1 25.0 11.881333
4 sdssr 55113.076923 0.672844 ab 5.916429 1 25.0 8.793167
4 sdssz 55117.179487 0.672844 ab 7.908628 1 25.0 11.754031
5 sdssg 55127.435897 0.672844 ab 0.325443 1 25.0 0.483683
5 sdssi 55123.333333 0.672844 ab 7.035843 1 25.0 10.456873
5 sdssr 55125.384615 0.475772 ab 3.347111 2 25.0 7.035109
5 sdssz 55125.384615 0.672844 ab 6.840864 1 25.0 10.167090
6 sdssg 55135.641026 0.672844 ab 0.330702 1 25.0 0.491499
6 sdssi 55135.641026 0.475772 ab 3.519194 2 25.0 7.396800
6 sdssr 55137.692308 0.672844 ab 0.565287 1 25.0 0.840145
6 sdssz 55133.589744 0.672844 ab 5.739895 1 25.0 8.530797
7 sdssg 55143.846154 0.672844 ab -0.722655 1 25.0 -1.074030
7 sdssi 55147.948718 0.672844 ab 2.124670 1 25.0 3.157745
7 sdssr 55145.897436 0.672844 ab 1.120918 1 25.0 1.665940
7 sdssz 55141.794872 0.672844 ab 5.626927 1 25.0 8.362902
8 sdssz 55150.000000 0.672844 ab 5.348218 1 25.0 7.948676

In [33]:
lcc = lc.lightCurve.copy()

In [34]:
grouped = lcc.groupby(['band'])

In [35]:
import numpy as np

In [36]:
grouped.agg({'mjd':np.mean, 'band': 'count'})


Out[36]:
mjd band
band
sdssg 55106.923077 10
sdssi 55111.025641 10
sdssr 55108.974359 10
sdssz 55113.076923 10

In [27]:
sncosmo.plot_lc(lc.snCosmoLC(coaddTimes=10., mjdBefore=1.), model, color='k')


Out[27]:

In [28]:
lc.lightCurve.query('band == "sdssg"')


Out[28]:
mjd band flux fluxerr zp zpsys
0 55070.000000 sdssg 0.363512 0.672844 25.0 ab
4 55078.205128 sdssg -0.436679 0.672844 25.0 ab
8 55086.410256 sdssg 2.826142 0.672844 25.0 ab
12 55094.615385 sdssg 1.578237 0.672844 25.0 ab
16 55102.820513 sdssg 2.208754 0.672844 25.0 ab
20 55111.025641 sdssg 0.608391 0.672844 25.0 ab
24 55119.230769 sdssg 0.679196 0.672844 25.0 ab
28 55127.435897 sdssg 0.325443 0.672844 25.0 ab
32 55135.641026 sdssg 0.330702 0.672844 25.0 ab
36 55143.846154 sdssg -0.722655 0.672844 25.0 ab

In [29]:
all(lc.coaddedLC(coaddTimes=None) == lc.lightCurve)


Out[29]:
True

In [30]:
lc.coaddedLC(coaddTimes=20., mjdBefore=1)


Out[30]:
band mjd fluxerr zpsys flux numCoadded zp SNR
discreteTime
0 sdssg 55078.205128 0.388467 ab 0.917658 3 25.0 2.362258
0 sdssi 55078.205128 0.475772 ab 2.031881 2 25.0 4.270700
0 sdssr 55080.256410 0.388467 ab 2.820826 3 25.0 7.261439
0 sdssz 55080.256410 0.475772 ab 3.218175 2 25.0 6.764105
1 sdssg 55098.717949 0.475772 ab 1.893495 2 25.0 3.979833
1 sdssi 55098.717949 0.388467 ab 10.305756 3 25.0 26.529324
1 sdssr 55100.769231 0.475772 ab 9.527294 2 25.0 20.024896
1 sdssz 55100.769231 0.388467 ab 12.307246 3 25.0 31.681607
2 sdssg 55119.230769 0.388467 ab 0.537677 3 25.0 1.384100
2 sdssi 55119.230769 0.475772 ab 7.515062 2 25.0 15.795497
2 sdssr 55117.179487 0.475772 ab 4.975451 2 25.0 10.457627
2 sdssz 55121.282051 0.475772 ab 7.374746 2 25.0 15.500573
3 sdssg 55139.743590 0.475772 ab -0.195976 2 25.0 -0.411912
3 sdssi 55139.743590 0.388467 ab 3.054352 3 25.0 7.862587
3 sdssr 55137.692308 0.388467 ab 1.448651 3 25.0 3.729152
3 sdssz 55137.692308 0.475772 ab 5.683411 2 25.0 11.945649
4 sdssz 55150.000000 0.672844 ab 5.348218 1 25.0 7.948676

In [31]:
lc.coaddedLC(coaddTimes=20., mjdBefore=1).reset_index('band', inplace=True)

In [4]:
12* 256 * 256 /2 * 5/ 1000


Out[4]:
1966

In [5]:
12* 256 * 256 /2  / 1e6


Out[5]:
0.393216

In [6]:
8 * 200 * 5


Out[6]:
8000

In [8]:
9216 /60. / 218.


Out[8]:
0.7045871559633027

In [10]:
import analyzeSN as ans

In [11]:
import sncosmo

In [14]:
sncosmo.get_bandpass('lsst_g')


Out[14]:
<Bandpass 'LSST_g' at 0x10ff9ab90>

In [ ]: