In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
from sqlalchemy import create_engine

import numpy as np
import pandas as pd
import seaborn as sb
import os
import healpy as hp

In [2]:
from lsst.sims.photUtils import noiseUtilities
from lsst.sims.photUtils import Bandpass, Photometry, PhotometryBase

In [3]:
engine = create_engine('sqlite:////Users/rbiswas/data/LSST/OpSimData/enigma_1189_sqlite.db')

In [4]:
Summary  = pd.read_sql_table('Summary', engine)
Proposal = pd.read_sql_table('Proposal', engine)
Seeing   = pd.read_sql_table('Seeing', engine)
Field    = pd.read_sql_table('Field', engine)

In [5]:
Summary.drop_duplicates('expMJD', inplace=True)

In [6]:
Summary.shape, Proposal.shape, Seeing.shape, Field.shape


Out[6]:
((2469307, 45), (5, 6), (210384, 3), (5292, 8))

In [7]:
Summary.columns


Out[7]:
Index([u'obsHistID', u'sessionID', u'propID', u'fieldID', u'fieldRA', u'fieldDec', u'filter', u'expDate', u'expMJD', u'night', u'visitTime', u'visitExpTime', u'finRank', u'finSeeing', u'transparency', u'airmass', u'vSkyBright', u'filtSkyBrightness', u'rotSkyPos', u'lst', u'altitude', u'azimuth', u'dist2Moon', u'solarElong', u'moonRA', u'moonDec', u'moonAlt', u'moonAZ', u'moonPhase', u'sunAlt', u'sunAz', u'phaseAngle', u'rScatter', u'mieScatter', u'moonIllum', u'moonBright', u'darkBright', u'rawSeeing', u'wind', u'humidity', u'slewDist', u'slewTime', u'fiveSigmaDepth', u'ditheredRA', u'ditheredDec'], dtype='object')

In [8]:
# Read in LSST bandpasses.
bpdir = os.getenv("LSST_THROUGHPUTS_BASELINE")
filterlist = ('u', 'g', 'r', 'i', 'z', 'y')
lsstbp = {}
for f in filterlist:
    lsstbp[f] = Bandpass()
    lsstbp[f].readThroughput(os.path.join(bpdir, 'total_'+f+'.dat'))
#dt, t = dtime(t)

In [11]:
# Add gamma to dataframe
Summary['gamma'] = Summary[['filter','fiveSigmaDepth','visitExpTime']].apply(lambda x:
                                                    noiseUtilities.calcGamma(bandpass=lsstbp[x[0]], m5=x[1], expTime=x[2]), 
                                                    axis=1)

In [12]:
Summary['N0sq'] = Summary['gamma'] * 10.0 **(-0.2 * Summary['fiveSigmaDepth'])
Summary['alpha'] = Summary['gamma']

In [27]:
Summary['alpha'].hist(by=Summary['filter'], histtype='step', lw=2.0, color='k', sharex=True, sharey=True)


Out[27]:
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x151167fd0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x142bac610>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x142555150>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x1421e55d0>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x141b0f2d0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x11f56fad0>]], dtype=object)

In [ ]:
fig, ax = plt.subplots(3, 2, sharex=True, sharey=True)
Summary['gamma'].hist(by=Summary['filter'], histtype='step', lw=2., color='k', normed=1, bins=20, ax=ax)

In [36]:
store = pd.HDFStore('storage.h5')

In [34]:
hdf.close()

In [40]:
print store


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-40-58b22339095b> in <module>()
----> 1 print store

/usr/local/manual/anaconda/lib/python2.7/site-packages/pandas/core/base.pyc in __str__(self)
     44         if compat.PY3:
     45             return self.__unicode__()
---> 46         return self.__bytes__()
     47 
     48     def __bytes__(self):

/usr/local/manual/anaconda/lib/python2.7/site-packages/pandas/core/base.pyc in __bytes__(self)
     56 
     57         encoding = get_option("display.encoding")
---> 58         return self.__unicode__().encode(encoding, 'replace')
     59 
     60     def __repr__(self):

/usr/local/manual/anaconda/lib/python2.7/site-packages/pandas/io/pytables.pyc in __unicode__(self)
    459                                       % pprint_thing(detail))
    460 
--> 461                 output += adjoin(12, keys, values)
    462             else:
    463                 output += 'Empty'

/usr/local/manual/anaconda/lib/python2.7/site-packages/pandas/core/common.pyc in adjoin(space, *lists)
   2180     out_lines = []
   2181     newLists = []
-> 2182     lengths = [max(map(len, x)) + space for x in lists[:-1]]
   2183 
   2184     # not the last one

ValueError: max() arg is an empty sequence

In [38]:
Summary.to_hdf('storage.h5', 'table')


/usr/local/manual/anaconda/lib/python2.7/site-packages/pandas/io/pytables.py:2558: PerformanceWarning: 
your performance may suffer as PyTables will pickle object types that it cannot
map directly to c-types [inferred_type->mixed,key->axis0] [items->None]

  warnings.warn(ws, PerformanceWarning)
/usr/local/manual/anaconda/lib/python2.7/site-packages/pandas/io/pytables.py:2558: PerformanceWarning: 
your performance may suffer as PyTables will pickle object types that it cannot
map directly to c-types [inferred_type->mixed,key->block0_items] [items->None]

  warnings.warn(ws, PerformanceWarning)
/usr/local/manual/anaconda/lib/python2.7/site-packages/pandas/io/pytables.py:2558: PerformanceWarning: 
your performance may suffer as PyTables will pickle object types that it cannot
map directly to c-types [inferred_type->unicode,key->block1_items] [items->None]

  warnings.warn(ws, PerformanceWarning)
/usr/local/manual/anaconda/lib/python2.7/site-packages/pandas/io/pytables.py:2558: PerformanceWarning: 
your performance may suffer as PyTables will pickle object types that it cannot
map directly to c-types [inferred_type->unicode,key->block2_values] [items->[u'filter']]

  warnings.warn(ws, PerformanceWarning)
/usr/local/manual/anaconda/lib/python2.7/site-packages/pandas/io/pytables.py:2558: PerformanceWarning: 
your performance may suffer as PyTables will pickle object types that it cannot
map directly to c-types [inferred_type->unicode,key->block2_items] [items->None]

  warnings.warn(ws, PerformanceWarning)

In [41]:
store.close()

In [42]:
print store


<class 'pandas.io.pytables.HDFStore'>
File path: storage.h5
File is CLOSED

In [190]:
fig.savefig('GammaHist.pdf')

In [43]:
!du -h storage.h5


923M	storage.h5

In [160]:
type(ax)


Out[160]:
numpy.ndarray

In [158]:
plt.savefig('gammaHists.pdf')


<matplotlib.figure.Figure at 0x1a4198490>

In [131]:
fs = Summary.groupby('filter')

In [132]:
fs.groups.keys()


Out[132]:
[u'g', u'i', u'r', u'u', u'y', u'z']

In [205]:
fig, ax  = plt.subplots()
zip (fs.groups.keys(), map(lambda x: fs.get_group(x)['gamma'].hist(histtype='step', lw=2, normed=1, label=x, ax=ax), fs.groups.keys()))
ax.legend(loc='best')
ax.axvline(0.037, lw=2., color='b')
ax.axvline(0.038, lw=2., color='g')
ax.axvline(0.039, lw=2., color='r')
ax.axvline(0.039, lw=2., color='m')
ax.axvline(0.040, lw=2., color='y')
ax.axvline(0.040, lw=2., color='c')


Out[205]:
<matplotlib.lines.Line2D at 0x13760a150>

In [206]:
fig.savefig('Gamma_paperVals_hist.pdf')