In [1]:
import opsimsummary as oss
In [2]:
import os
In [3]:
example_dir = os.path.join(oss.__path__[0], 'example_data')
In [4]:
dbName = os.path.join(example_dir, 'enigma_1189_micro.db')
In [5]:
hdfName = os.path.join(example_dir, 'enigma_1189_micro.hdf')
In [6]:
from sqlalchemy import create_engine as create_engine
In [7]:
from opsimsummary import OpSimOutput
In [8]:
opout_hdf = OpSimOutput.fromOpSimHDF(hdfName=hdfName, subset='Combined')
In [7]:
opout = OpSimOutput.fromOpSimDB(dbname=dbName, subset='_all')
In [8]:
opout.proposalTable
Out[8]:
In [9]:
opout.propIDDict
Out[9]:
In [10]:
opout.summary.propID.unique()
Out[10]:
In [11]:
opout.propIDVals('combined', opout.propIDDict, opout.proposalTable)
Out[11]:
In [12]:
opout.propIds
Out[12]:
In [13]:
opout.subset
Out[13]:
In [14]:
opout.summary.head()
Out[14]:
In [15]:
opout.summary[['fieldID', 'fieldRA', 'fieldDec', 'filter', 'expMJD', 'ditheredRA', 'ditheredDec']]
Out[15]:
In [15]:
print(len(opout.summary))
In [16]:
# Write to hdf file
In [17]:
opout.writeOpSimHDF('/tmp/opsim_small.hdf')
In [22]:
opsim_from_hdf = OpSimOutput.fromOpSimHDF('/tmp/opsim_small.hdf', subset='_all')
In [20]:
from pandas.util.testing import assert_frame_equal
In [23]:
opsim_from_hdf.subset
Out[23]:
In [24]:
assert_frame_equal(opsim_from_hdf.summary, opout.summary)
In [16]:
opsim_comb = OpSimOutput.fromOpSimDB(dbname=dbName)
In [17]:
opsim_comb.writeOpSimHDF('tmp/hdfFile.hdf')
In [18]:
opsim_all = OpSimOutput.fromOpSimDB(dbname=dbName, subset='_all')
In [20]:
opsim_all.writeOpSimHDF('test_hdf.hdf')
In [21]:
opsim_fromhdf = OpSimOutput.fromOpSimHDF('test_hdf.hdf', subset='_all')
In [12]:
from sqlalchemy import create_engine
In [13]:
engine = create_engine('sqlite:///'+dbName)
In [14]:
import pandas as pd
In [15]:
_ = pd.read_sql_query('SELECT * FROM Summary WHERE propID in (364, 366) LIMIT 5', con=engine)
In [21]:
_
Out[21]:
In [22]:
pids = [364, 366]
In [23]:
x = ', '.join(list(str(pid) for pid in pids))
In [24]:
'SELECT * FROM Summary WHERE propID == ({})'.format(x)
Out[24]:
In [25]:
opout_comb = oss.OpSimOutput.fromOpSimDB(dbname=dbName, subset='combined')
In [38]:
opout_comb.summary.propID.unique()
Out[38]:
In [26]:
import pandas as pd
In [27]:
summarydf = pd.read_hdf('/tmp/opsim_small.hdf', key='Summary')
In [28]:
from pandas.util.testing import assert_frame_equal
In [29]:
assert_frame_equal(summarydf, opout.summary)
In [30]:
engine = create_engine('sqlite:///' + dbName)
In [31]:
import pandas as pd
In [32]:
pids = tuple([366])
In [33]:
pids = [366, 364]
In [34]:
', '.join('{}'.format(x) for x in pids)
Out[34]:
In [35]:
pids = [344, 366]
In [36]:
sql_query = "SELECT * FROM Summary WHERE PROPID == "
In [37]:
sql_query += "({})".format(pid) for pid in pids
In [ ]:
sql_query += ", ".join(list("({})".format(pid) for pid in pids))
In [ ]:
sql_query
In [ ]:
pids
In [ ]:
df = pd.read_sql_query(sql_query, con=engine)
In [ ]:
df = pd.read_sql_query("SELECT * FROM Summary WHERE PROPID in (362, 366)", con=engine)
In [ ]:
df.head()
In [ ]:
pids = [366]
In [ ]:
df.query('propID == @pids')
In [ ]:
df.propID.unique()
In [ ]:
df = oss.OpSimOutput.fromOpSimDB(dbName, subset='ddf')
In [ ]:
In [ ]:
df.summary.head()
In [ ]:
pids = df.propIDVals('wfd', df.propIDDict, df.proposalTable)
In [ ]:
df.summary.query('propID == {}'.format(pids)).propID.unique()
In [ ]:
import sqlite3
In [ ]:
engine
In [ ]:
alldf = oss.summarize_opsim.OpSimOutput.fromOpSimDB(dbName, subset='_all')
In [ ]:
len(alldf.summary.drop_duplicates())
In [ ]:
len(alldf.summary.reset_index().drop_duplicates(subset='obsHistID'))== len(alldf.summary)
In [ ]:
len(alldf.summary)
In [ ]:
unique_alldf = oss.summarize_opsim.OpSimOutput.fromOpSimDB(dbName, subset='unique_all')
In [ ]:
len(unique_alldf.summary)
In [ ]:
unique_alldf.summary.query('propID == [364, 366]').propID.unique()
In [ ]:
def myfunc(*args):
if len
return args[0]**2
In [ ]:
myfunc(2)
In [ ]:
alldf.
In [ ]:
alldf.propIDDict
In [ ]:
alldf.summary.head()
In [ ]: