The set of quantities related to supernovae used in Twinkles are in a table called TwinkSN
on a computer at UW. This code in the Monitor
package accesses this data to have a complete
characterization of the SN truth parameters.
It then creates an instance of lsst.sims.catUtils.supernovae.SNObject
using these values.
Since SNObject has methods that estimate flux, and estimated flux uncertainty given
parameters that characterize the observation, we can use this to find the light curves of
the supernovae. The light curves have two main quantities, the measured flux and uncertainty
on the measured flux. These quantities depend on the properties of the astrophysical objects,
and the properties of the observation. By properties of observation, we mean site/Hardware
properties and the properties of the sky at the time of the observation. The most important of
these are the bandpasses (transmissions) and fivesigma depth (obtained from OpSim).
Thus, monitor.RefLightCuves
must be passed these quantities in order to obtain the light curve.
However, for analyzing the Twinkles run, where we have a clearer idea of both the bandpasses (LSST)
and the properties of the observation (from a selection of OpSim visits), we have a simple method to
set this up:
monitor.RefLightCurve.fromTwinklesData
.
In [1]:
from __future__ import absolute_import, division, print_function
In [2]:
import os
In [3]:
import numpy as np
import pandas as pd
In [4]:
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
In [5]:
# Import from monitor
from desc.monitor import RefLightCurves
import desc.monitor as monitor
The quantities needed for the light curves are time (MJD), and fiveSigmaDepth. While this can come
from various formats, right now, there is only one that has been implemented: a dataframe. The data directory
of the package desc.Monitor
contains a csv file which has the necessary pointings
In [6]:
data_dir = os.path.join(os.environ['MONITOR_DIR'], 'data')
opsimCsv = os.path.join(data_dir, 'SelectedKrakenVisits.csv')
opsimdf = pd.read_csv(opsimCsv, index_col='obsHistID')
df = opsimdf[['expMJD', 'filter', 'fiveSigmaDepth']]
In [7]:
import pymssql
from lsst.utils import getPackageDir
import lsst.sims.catUtils.baseCatalogModels as bcm
from lsst.daf.persistence import DbAuth
In [8]:
config = bcm.BaseCatalogConfig()
config.load(os.path.join(getPackageDir("sims_catUtils"), "config", "db.py"))
In [9]:
username = DbAuth.username(config.host, config.port)
password = DbAuth.password(config.host, config.port)
hostname = config.host
DBConnection = pymssql.connect(user=username,
password=password,
host=hostname,
database=config.database,
port=config.port)
db = DBConnection.cursor()
In [10]:
# The ids are obtained from Instance Catalogs
reflc = RefLightCurves(idSequence=(6144007055260714, 6144158471480362),
tableName='TwinkSN',
dbConnection=DBConnection,
dbCursor=db)
In [11]:
reflc.dbConnection
Out[11]:
In [12]:
print(reflc.get_numObjects())
In [13]:
reflc.get_numObjects()
Out[13]:
What are the IDs in the table (unique IDs)?
In [14]:
ids = reflc.allIdinTable(chunksize=None)
print(ids.astype(int).values.flatten())
The astrophysical object properties can be obtained by using the following function in the form of a pd.DataFrame
Or if the table is too large, and you only want to get a few of the IDs
In [15]:
ids = reflc.allIdinTable(chunksize=10)
print(ids.next().astype(int).values.flatten())
Get the parameters for an object
In [16]:
reflc.get_params(6144007055260714)
Out[16]:
In [17]:
allParamsInIdSequence = reflc.get_params()
allParamsInIdSequence
Out[17]:
In [18]:
reflcAll = RefLightCurves(tableName='TwinkSN',
dbConnection=DBConnection,
dbCursor=db)
In [19]:
# Slow because all rows
allParams = reflcAll.get_params()
In [20]:
allParams.head()
Out[20]:
The instance of the class representing the astrophysical object itself can be obtained by the following method for SN
In [21]:
sn = reflc.astro_object(idValue=6144007055260714)
Following the usual methods in sims.catUtils.supernovae.SNObject
the properties of this SN can be seen using
In [22]:
from lsst.sims.photUtils import BandpassDict
In [23]:
# Get the `bandpassDict` instance from files using catsim methods
lsstBP = BandpassDict.loadBandpassesFromFiles()
# This is a tuple, the first component gives the total bandpass, while the second gives the hardware bandpass
In [24]:
# Pass the bandpass and get the lightcurve for the observations
reflc.lightCurve(idValue=6144007055260714, observations=df, bandPassDict=lsstBP[0])
Out[24]:
For the Twinkles Data Analysis, we can use a simpler method. The full API is shown below:
In [25]:
reflcTwink = RefLightCurves.fromTwinklesData(tableName='TwinkSN',
idCol='id',
objectTypeID=42,
dbHostName=None,
columns=('id', 'redshift', 'snra', 'sndec', 't0',
'x0', 'x1', 'c'),
idSequence=None)
The tableName, idCol, objectTypeID, and columns will change from one astrophysical object to another. The defaults are currently correct for SN, so one could simply do
reflcTwink = RefLightCurves.fromTwinklesData(tableName='TwinkSN")
The light Curves can be accessed in the following way
In [26]:
reflcTwink.idCol
Out[26]:
In [27]:
reflcTwink.lightCurve(idValue=6144007055260714)
Out[27]:
We can get the light curves for each band by
In [28]:
reflcTwink.lightCurve(idValue=6144007055260714, bandName='r')
Out[28]:
In [ ]: