SNANA simlibs are an input to SNANA simulations and summarize the LSST OpSIM output. This notebook illustrates how to create these files from OpSim outputs.
In [1]:
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
import os
In [2]:
# Required packages sqlachemy, pandas (both are part of anaconda distribution, or can be installed with a python installer)
# One step requires the LSST stack, can be skipped for a particular OPSIM database in question
import OpSimSummary.summarize_opsim as so
from sqlalchemy import create_engine
import pandas as pd
print so.__file__
In [3]:
!ls /Users/rbiswas/.local/lib/python2.7/site-packages/OpSimSummary-0.0.1.dev0-py2.7.egg/OpSimSummary/summarize_opsim.pyc
In [4]:
# This step requires LSST SIMS package MAF. The main goal of this step is to set DD and WFD to integer keys that
# label an observation as Deep Drilling or for Wide Fast Deep.
# If you want to skip this step, you can use the next cell by uncommenting it, and commenting out this cell, if all you
# care about is the database used in this example. But there is no guarantee that the numbers in the cell below will work
# on other versions of opsim database outputs
from lsst.sims.maf import db
from lsst.sims.maf.utils import opsimUtils
In [5]:
# DD = 366
# WFD = 364
Description of OpSim outputs are available on the page https://confluence.lsstcorp.org/display/SIM/OpSim+Datasets+for+Cadence+Workshop+LSST2015http://tusken.astro.washington.edu:8080 Here we will use the opsim output http://ops2.tuc.noao.edu/runs/enigma_1189/data/enigma_1189_sqlite.db.gz I have downloaded this database, unzipped and use the variable dbname to point to its location
In [6]:
dbname = '/Users/rbiswas/data/LSST/OpSimData/enigma_1189_sqlite.db'
opsdb = db.OpsimDatabase(dbname)
propID, propTags = opsdb.fetchPropInfo()
DD = propTags['DD'][0]
WFD = propTags['WFD'][0]
In [7]:
WFD
Out[7]:
In [7]:
enginefile = 'sqlite:///' + dbname
In [8]:
engine = create_engine(enginefile)
The opsim database is a large file (approx 4.0 GB), but still possible to read into memory on new computers. You usually only need the Summary Table, which is about 900 MB. If you are only interested in the Deep Drilling Fields, you can use the read_sql_query to only select information pertaining to Deep Drilling Observations. This has a memory footprint of about 40 MB. Obviously, you can reduce this further by narrowing down the columns to those of interest only. For the entire Summary Table, this step takes a few minutes on my computer.
In [9]:
# Load to a dataframe
# Summary = pd.read_hdf('storage.h5', 'table')
Summary = pd.read_sql_table('Summary', engine)
In [10]:
EnigmaMain = Summary.query('propID == [364]')
In [11]:
EnigmaMainSummary = so.SummaryOpsim(EnigmaMain)
In [12]:
len(EnigmaMainSummary.fieldIds)
Out[12]:
In [13]:
EnigmaMainSummary.writeSimlib('Enigma_1189.SIMLIB.MAIN.FULL')
In [14]:
clear(EnigmaMain, EnigmaMainSummary)
In [15]:
EnigmaMain = None
In [16]:
EnigmaMainSummary = None
In [17]:
EnigmaDeep = Summary.query('propID == [366]')
In [18]:
EnigmaDeepSummary = so.SummaryOpsim(EnigmaDeep)
In [19]:
EnigmaDeepSummary.writeSimlib('Enigma_1189.SIMLIB.DEEP.FULL')
In [20]:
DeepFields = EnigmaDeepSummary.fieldIds
In [21]:
EnigmaCombined = Summary.query('propID == [364,366]')
In [22]:
EnigmaCombined = EnigmaCombined[EnigmaCombined['fieldID'].isin(DeepFields)]
In [23]:
EnigmaCombined.drop_duplicates('expMJD', inplace=True)
In [24]:
EnigmaCombinedSummary = so.SummaryOpsim(EnigmaCombined)
In [25]:
EnigmaCombinedSummary.writeSimlib('Enigma_1189.SIMLIB.DEEP.COMBINED')
In [26]:
dbname_2168 = '/Users/rbiswas/data/LSST/OpSimData/opsim2_168_sqlite.db'
engine_name_2168 = 'sqlite:///' + dbname
engine_2168 = create_engine(engine_name_2168)
# dbAddressDict = {'dbAddress': dbname_2168, 'Summary':'summary'}
# print dbAddressDict
opsimDb2168 = opsimUtils.connectOpsimDb(engine_name_2168)
In [27]:
propID, propTags = opsimDb2168.fetchPropInfo()
In [28]:
propTags
Out[28]:
This does not work for the old format. Read the SSTar document: http://opsimcvs.tuc.noao.edu/runs/opsim2.168/SSTAR-opsim2-168.pdf and find the deep drilling propIDs from Table 1.
In [29]:
DDold = 359, 360
In [30]:
OpSim_2168_all = pd.read_sql_query('SELECT * FROM SUMMARY WHERE PROPID is 359 or PROPID is 360 or PROPID is 361', engine_2168)
As shown from a similar command as above this OpSim database has 197332 rows (close to about twice as the enigma case) and 46 columns. The memory on disc is also larger by a similar factor and is 70 MB
In [31]:
OpSim_2168_all.columns
Out[31]:
In [32]:
OpSim_2168_Deep = OpSim_2168_all.query('propID == [359, 360]')
In [33]:
Opsim2168_Deep_FI = OpSim_2168_Deep.fieldID.unique()
In [34]:
Opsim_2168_Main = OpSim_2168_all.query('propID == [361]')
In [35]:
OpSim_2168_Main_summary = so.SummaryOpsim(Opsim_2168_Main)
In [36]:
OpSim_2168_Main_summary.writeSimlib('opsim_2168.SIMLIB.MAIN.FULL')
In [37]:
OpSim_2168_Main = None
Opsim_2168_Main_summary = None
In [38]:
OpSim_2168_Combined = OpSim_2168_all[OpSim_2168_all['fieldID'].isin(Opsim2168_Deep_FI)]
In [39]:
OpSim_2168_Deep_Summary = so.SummaryOpsim(OpSim_2168_Deep)
In [40]:
OpSim_2168_Deep_Summary.writeSimlib('opsim_2168.SIMLIB.DEEP.FULL_new')
In [41]:
OpSim_2168_Deep_Summary = None
OpSim_2168_Deep = None
In [42]:
OpSim_2168_Combined_Summary = so.SummaryOpsim(OpSim_2168_Combined)
In [43]:
OpSim_2168_Combined_Summary.writeSimlib('opsim_2168.SIMLIB.COMBINED.FULL')
In [49]:
opsim_test_df = pd.read_csv('test_opsimObsData.dat', delimiter='\s+')
In [50]:
opsim_test_df
Out[50]:
In [52]:
testopsim = so.SummaryOpsim(opsim_test_df)
In [55]:
testopsim.simlib(519)
Out[55]:
In [58]:
EnigmaDeepSummary.df.simLibSkySig.max()
Out[58]:
In [ ]: