In [1]:
from metrics import PerSNMetric
from efficiencyTable import EfficiencyTable
In [2]:
from OpSimSummary import summarize_opsim as oss
In [3]:
import pandas as pd
import sncosmo
In [4]:
%matplotlib inline
import matplotlib.pyplot as plt
import os
import numpy as np
import copy
In [5]:
from lsst.sims.photUtils import BandpassDict
In [6]:
# Catsim bandpasses
lsst_bp = BandpassDict.loadTotalBandpassesFromFiles()
In [7]:
# sncosmo Bandpasses required for fitting
throughputsdir = os.getenv('THROUGHPUTS_DIR')
from astropy.units import Unit
bandPassList = ['u', 'g', 'r', 'i', 'z', 'y']
banddir = os.path.join(os.getenv('THROUGHPUTS_DIR'), 'baseline')
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)
print band
sncosmoband = sncosmo.Bandpass(wave=numpyband[:, 0],
trans=numpyband[:, 1],
wave_unit=Unit('nm'),
name=band)
sncosmo.registry.register(sncosmoband, force=True)
In [8]:
et = EfficiencyTable.fromDES_EfficiencyFile('example_data/SEARCHEFF_PIPELINE_DES.DAT')
In [9]:
from lsst.sims.catUtils.mixins import SNObject
In [10]:
opsimHDF = os.path.join(os.getenv('HOME'), 'data', 'LSST', 'OpSimData', 'storage.h5')
summarydf = pd.read_hdf(opsimHDF, 'table')
# df = df.query('propID == [364, 366]')
In [11]:
summarydf.head()
Out[11]:
In [12]:
summarydf = summarydf.query('propID == [364, 366]').query('night < 365')
In [13]:
# Create the summary instance
so = oss.SummaryOpsim(summarydf)
In [14]:
ss = so.simlib(fieldID=309)
In [15]:
ss.head()
Out[15]:
In [16]:
_ = so.cadence_plot(fieldID=309, mjd_center=49540)
In [17]:
# 1st season by default
_ = so.cadence_plot(fieldID=309)
In [18]:
qm = PerSNMetric(fieldID=309, t0=49540, summarydf=summarydf, lsst_bp=lsst_bp)
In [19]:
qm.lcplot()
In [20]:
qm.lcplot(nightlyCoadd=True)
In [21]:
qm.writeLightCurve('coadded_lc.dat',nightlyCoadd=True)
In [22]:
cm = qm.cadence_Matrix(fieldID=309, mjd_center=49540, mjd_range=[-30., 50.])
In [23]:
cm.head()
Out[23]:
In [24]:
cm = qm.cadence_plot(fieldID=309, mjd_center=49540, mjd_range=[-30, 5])
In [25]:
qm = PerSNMetric(fieldID=309, t0=49540, summarydf=ss, lsst_bp=lsst_bp, efficiency=et)
In [26]:
qm.SNCadence[0]
Out[26]:
In [27]:
qm.summary.head()
Out[27]:
In [28]:
qm.discoveryMetric()
Out[28]:
In [29]:
qm.qualityMetric()
Out[29]:
In [30]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import healpy as hp
import lsst.sims.maf.db as db
import lsst.sims.maf.utils as utils
import lsst.sims.maf.metrics as metrics
import lsst.sims.maf.slicers as slicers
import lsst.sims.maf.metricBundles as metricBundles
In [31]:
outDir ='LightCurve'
dbFile = 'enigma_1189_sqlite.db'
opsimdb = utils.connectOpsimDb(dbFile)
resultsDb = db.ResultsDb(outDir=outDir)
In [32]:
filters = ['u','g','r','i','z','y']
colors={'u':'cyan','g':'g','r':'y','i':'r','z':'m', 'y':'k'}
In [33]:
# Set RA, Dec for a single point in the sky. in radians.
ra = np.radians(0.)
dec = np.radians(0.)
# SNR limit (Don't use points below this limit)
snrLimit = 5.
# Demand this many points above SNR limit before plotting LC
nPtsLimit = 6
In [34]:
# The pass metric just passes data straight through.
metric = metrics.PassMetric(cols=['filter','fieldID','finSeeing','fiveSigmaDepth',
'expMJD','airmass', 'propID', 'night', 'filtSkyBrightness'])
slicer = slicers.UserPointsSlicer(ra,dec,lonCol='fieldRA',latCol='fieldDec')
sql = 'night < 366'
bundle = metricBundles.MetricBundle(metric,slicer,sql)
bg = metricBundles.MetricBundleGroup({0:bundle}, opsimdb,
outDir=outDir, resultsDb=resultsDb)
In [35]:
bg.runAll()
In [36]:
llc = pd.DataFrame.from_records(bundle.metricValues.data[0])
In [37]:
llc.head()
Out[37]:
In [38]:
llc.expMJD.hist()
Out[38]:
In [39]:
q2 = PerSNMetric(t0=49580, summarydf=llc, lsst_bp=lsst_bp, efficiency=et, raCol='fieldRA',
decCol='fieldDec')
In [40]:
ss.columns
Out[40]:
In [41]:
llc.columns
Out[41]:
In [42]:
q2.raCol
Out[42]:
In [43]:
q2.summary[q2.raCol].iloc[0]
Out[43]:
In [44]:
q2.radeg
Out[44]:
In [45]:
q2.decdeg
Out[45]:
In [46]:
q2.SN.SNstate
Out[46]:
In [47]:
q2.lcplot(nightlyCoadd=False)
In [48]:
q2.lcplot(nightlyCoadd=True)
In [49]:
q2.writeLightCurve(fname='test.dat', nightlyCoadd=True)
In [50]:
!cat test.dat
In [51]:
q2.coaddedLightCurve.reset_index()[q2.coaddedLightCurve.reset_index()['band'] == 'y']
Out[51]:
In [52]:
q2.qualityMetric()
Out[52]:
In [53]:
q2.discoveryMetric()
Out[53]:
In [54]:
_ = q2.cadence_plot(summarydf=llc, racol='fieldRA', deccol='fieldDec', mjd_center=49580)
In [55]:
# Defaults to full season
_ = q2.cadence_plot(summarydf=llc, racol='fieldRA', deccol='fieldDec')
In [56]:
xx = llc[['expMJD', 'filter', 'fiveSigmaDepth', 'fieldRA', 'fieldDec', 'fieldID']].copy(deep=True)
In [57]:
xx
Out[57]:
In [58]:
q3 = PerSNMetric(t0=49580, summarydf=xx, lsst_bp=lsst_bp, efficiency=et, raCol='fieldRA',
decCol='fieldDec')
In [59]:
q3.lightcurve
Out[59]:
In [60]:
q3.SNCosmoLC()
Out[60]:
In [61]:
q3.SN.SNstate
Out[61]:
In [62]:
q3.qualityMetric()
Out[62]:
In [63]:
q3.discoveryMetric()
Out[63]:
In [ ]: