Skip to content

Instantly share code, notes, and snippets.

@rbiswas4
Created November 11, 2015 21:17
Show Gist options
  • Save rbiswas4/961474d38ef3209139c9 to your computer and use it in GitHub Desktop.
Save rbiswas4/961474d38ef3209139c9 to your computer and use it in GitHub Desktop.
getting a csv from the opsim sqlite db
# 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__
# Change dbname to point at your own location of the opsim output
dbname = '/Users/rbiswas/data/LSST/OpSimData/enigma_1189_sqlite.db'
# Read the Summary (WFD and DDF fields) into a DataFrame
# This is a slow step and can take about 2 minutes on my laptop
engine = create_engine('sqlite:///' + dbname)
MainDeep = pd.read_sql_query('SELECT * FROM SUMMARY WHERE PROPID is 366 OR PROPID is 364', engine, index_col='obsHistID')
len(MainDeep)
MainDeep.to_csv('/Users/rbiswas/tmp/MainDeep.csv')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment