Cadence :

  • Look at the output of the OpSim Database

Requirements

  • sqlite
  • setup the sims stack before running the notebook (if not at least have healpy installed)
  • setup an environment variable OPSIMDBPATH to point to the absolute path of the OpSim Database (unzipped)

The Observing Strategy White Paper


In [1]:
import numpy as np
import pandas as pd
import os

In [2]:
import sqlite3
from sqlalchemy import create_engine

In [3]:
%matplotlib inline
import matplotlib.pyplot as plt

In [4]:
opsimdbpath = os.environ.get('OPSIMDBPATH')

In [5]:
print(opsimdbpath)


minion_1016_sqlite.db

In [6]:
engine = create_engine('sqlite:///' + opsimdbpath)

In [7]:
conn = sqlite3.connect(opsimdbpath)

In [8]:
cursor = conn.cursor()
print cursor


<sqlite3.Cursor object at 0x10600f420>

In [ ]:
query = 'SELECT COUNT(*) FROM Summary'
cursor.execute(query)

In [ ]:
cursor.fetchall()

In [9]:
opsimdf = pd.read_sql_query('SELECT * FROM Summary WHERE night < 1000', engine)

In [10]:
opsimdf.head()


Out[10]:
obsHistID sessionID propID fieldID fieldRA fieldDec filter expDate expMJD night ... moonBright darkBright rawSeeing wind humidity slewDist slewTime fiveSigmaDepth ditheredRA ditheredDec
0 1 1016 54 316 1.676483 -1.082473 y 2922 59580.033829 0 ... 0.0 105.610378 0.920473 0.0 0.0 1.620307 0.000000 21.021236 1.643930 -1.108924
1 2 1016 54 372 1.694120 -1.033972 y 2961 59580.034275 0 ... 0.0 105.167017 0.920473 0.0 0.0 0.049266 4.574944 21.026646 1.664257 -1.060423
2 3 1016 54 441 1.708513 -0.985271 y 2999 59580.034722 0 ... 0.0 104.849578 0.920473 0.0 0.0 0.049298 4.595615 21.030520 1.680878 -1.011722
3 4 1016 54 505 1.720374 -0.936476 y 3038 59580.035169 0 ... 0.0 104.669398 0.920473 0.0 0.0 0.049266 4.605366 21.032718 1.694604 -0.962927
4 5 1016 54 587 1.730248 -0.887672 y 3077 59580.035616 0 ... 0.0 104.627207 0.920473 0.0 0.0 0.049177 4.604023 21.033233 1.706054 -0.914123

5 rows × 47 columns


In [11]:
# Definitions of the columns are 
opsimdf[['obsHistID', 'filter', 'night', 'expMJD',
         'fieldID', 'fieldRA', 'ditheredRA', 'ditheredRA', 'ditheredDec',
         'propID', 'fiveSigmaDepth']].head()


Out[11]:
obsHistID filter night expMJD fieldID fieldRA ditheredRA ditheredRA ditheredDec propID fiveSigmaDepth
0 1 y 0 59580.033829 316 1.676483 1.643930 1.643930 -1.108924 54 21.021236
1 2 y 0 59580.034275 372 1.694120 1.664257 1.664257 -1.060423 54 21.026646
2 3 y 0 59580.034722 441 1.708513 1.680878 1.680878 -1.011722 54 21.030520
3 4 y 0 59580.035169 505 1.720374 1.694604 1.694604 -0.962927 54 21.032718
4 5 y 0 59580.035616 587 1.730248 1.706054 1.706054 -0.914123 54 21.033233

In [12]:
opsimdf.propID.unique()


Out[12]:
array([54, 53, 52, 56, 55])

In [13]:
xx = opsimdf.query('fieldID == 316')

In [14]:
xx.head()


Out[14]:
obsHistID sessionID propID fieldID fieldRA fieldDec filter expDate expMJD night ... moonBright darkBright rawSeeing wind humidity slewDist slewTime fiveSigmaDepth ditheredRA ditheredDec
0 1 1016 54 316 1.676483 -1.082473 y 2922 59580.033829 0 ... 0.000000 105.610378 0.920473 0.0 0.0 1.620307 0.000000 21.021236 1.643930 -1.108924
725 726 1016 54 316 1.676483 -1.082473 z 89526 59581.036182 1 ... 0.000000 104.494636 0.866146 0.0 0.0 0.049266 4.600973 21.568639 1.652068 -1.108924
757 758 1016 54 316 1.676483 -1.082473 z 90773 59581.050623 1 ... 0.000000 101.552611 0.782034 0.0 0.0 0.049266 4.670846 21.682759 1.652068 -1.108924
1461 1462 1016 54 316 1.676483 -1.082473 z 175972 59582.036724 2 ... 0.098683 103.794559 0.725074 0.0 0.0 0.049266 4.618406 21.719760 1.660207 -1.108924
1505 1506 1016 54 316 1.676483 -1.082473 z 177711 59582.056845 2 ... 0.000000 99.916092 0.752420 0.0 0.0 0.049266 4.702940 21.730181 1.660207 -1.108924

5 rows × 47 columns

Some unexpected issues


In [15]:
xx.query('propID == 54')


Out[15]:
obsHistID sessionID propID fieldID fieldRA fieldDec filter expDate expMJD night ... moonBright darkBright rawSeeing wind humidity slewDist slewTime fiveSigmaDepth ditheredRA ditheredDec
0 1 1016 54 316 1.676483 -1.082473 y 2922 59580.033829 0 ... 0.000000 105.610378 0.920473 0.0 0.0 1.620307 0.000000 21.021236 1.643930 -1.108924
725 726 1016 54 316 1.676483 -1.082473 z 89526 59581.036182 1 ... 0.000000 104.494636 0.866146 0.0 0.0 0.049266 4.600973 21.568639 1.652068 -1.108924
757 758 1016 54 316 1.676483 -1.082473 z 90773 59581.050623 1 ... 0.000000 101.552611 0.782034 0.0 0.0 0.049266 4.670846 21.682759 1.652068 -1.108924
1461 1462 1016 54 316 1.676483 -1.082473 z 175972 59582.036724 2 ... 0.098683 103.794559 0.725074 0.0 0.0 0.049266 4.618406 21.719760 1.660207 -1.108924
1505 1506 1016 54 316 1.676483 -1.082473 z 177711 59582.056845 2 ... 0.000000 99.916092 0.752420 0.0 0.0 0.049266 4.702940 21.730181 1.660207 -1.108924
10924 10924 1016 54 316 1.676483 -1.082473 y 1303174 59595.083037 15 ... 571.503724 92.155250 0.818293 0.0 0.0 0.049176 4.531808 21.432880 1.688690 -1.105618
15458 15458 1016 54 316 1.676483 -1.082473 r 1820990 59601.076275 21 ... 51.964691 91.453006 0.741071 0.0 0.0 0.049266 4.566115 23.862206 1.652068 -1.102311
15492 15492 1016 54 316 1.676483 -1.082473 r 1822322 59601.091694 21 ... 118.839262 90.592868 0.590093 0.0 0.0 0.049266 4.656183 24.051254 1.652068 -1.102311
15682 15682 1016 54 316 1.676483 -1.082473 i 1829892 59601.179312 21 ... 259.841966 91.695314 0.632563 0.0 0.0 0.054638 4.686846 23.189492 1.652068 -1.102311
15705 15705 1016 54 316 1.676483 -1.082473 i 1830791 59601.189715 21 ... 270.529541 92.504537 0.559097 0.0 0.0 0.190777 11.925649 23.249306 1.652068 -1.102311
21758 21758 1016 54 316 1.676483 -1.082473 g 2519815 59609.164530 29 ... 0.000000 92.232859 0.816412 0.0 0.0 0.054825 4.691043 24.264455 1.717174 -1.102311
21789 21789 1016 54 316 1.676483 -1.082473 g 2521036 59609.178661 29 ... 0.000000 93.510029 0.785107 0.0 0.0 0.224657 14.248022 24.276015 1.717174 -1.102311
30183 30182 1016 54 316 1.676483 -1.082473 y 3544963 59621.029671 41 ... 200.390696 90.966158 0.555084 0.0 0.0 0.049266 4.615241 21.579041 1.721241 -1.099005
30213 30212 1016 54 316 1.676483 -1.082473 y 3546134 59621.043229 41 ... 199.049860 90.339546 0.552169 0.0 0.0 0.054172 4.703669 21.738687 1.721241 -1.099005
44534 44533 1016 54 316 1.676483 -1.082473 z 5099102 59639.017394 59 ... 0.000000 89.833076 1.097259 0.0 0.0 0.053898 5.173779 21.510117 1.656138 -1.092392
52518 52516 1016 54 316 1.676483 -1.082473 y 5962259 59649.007629 69 ... 105.144479 89.920424 0.729760 0.0 0.0 0.191059 15.157424 21.402085 1.619518 -1.089086
58212 58210 1016 54 316 1.676483 -1.082473 z 6575397 59656.104132 76 ... 988.546380 101.222797 0.564075 0.0 0.0 0.054172 4.722416 22.210219 1.676483 -1.089086
58242 58240 1016 54 316 1.676483 -1.082473 z 6576550 59656.117480 76 ... 1032.979743 103.883602 0.667614 0.0 0.0 0.134120 5.989231 22.043725 1.676483 -1.089086
60974 60972 1016 54 316 1.676483 -1.082473 i 6833759 59659.094442 79 ... 390.090383 100.944375 0.486339 0.0 0.0 0.049176 4.402156 23.143461 1.700898 -1.089086
60999 60997 1016 54 316 1.676483 -1.082473 i 6834743 59659.105829 79 ... 416.490672 103.165802 0.495479 0.0 0.0 0.049266 4.410169 23.077911 1.700898 -1.089086
74060 74057 1016 54 316 1.676483 -1.082473 y 8292444 59675.977365 96 ... 30.427200 91.874176 1.025171 0.0 0.0 0.517630 37.736436 21.095489 1.713105 -1.085779
81920 81917 1016 54 316 1.676483 -1.082473 y 8983116 59683.971250 104 ... 502.834048 93.221867 0.384107 0.0 0.0 0.553749 38.411003 21.744542 1.643930 -1.082473
84018 84015 1016 54 316 1.676483 -1.082473 y 9160501 59686.024328 106 ... 904.486195 101.617717 0.453639 0.0 0.0 0.088077 6.849871 21.711689 1.660207 -1.082473
103074 103071 1016 54 316 1.676483 -1.082473 y 11141862 59708.956747 129 ... 145.881863 100.654986 0.641003 0.0 0.0 0.541194 39.159697 21.364513 1.713105 -1.079167
107212 107209 1016 54 316 1.676483 -1.082473 y 11488940 59712.973846 133 ... 568.884764 106.564269 0.685334 0.0 0.0 0.049266 4.415315 21.393117 1.619518 -1.075860
179271 179260 1016 54 316 1.676483 -1.082473 u 20597566 59818.397765 238 ... 0.000000 102.220424 0.496553 0.0 0.0 0.384837 41.965623 23.132531 1.652068 -1.102311
195832 195813 1016 54 316 1.676483 -1.082473 r 22665468 59842.331807 262 ... 20.154031 102.219608 0.534598 0.0 0.0 0.049266 4.655980 24.134962 1.652068 -1.095699
195869 195850 1016 54 316 1.676483 -1.082473 r 22666918 59842.348598 262 ... 21.071142 99.162644 0.680936 0.0 0.0 0.054638 4.589429 24.000313 1.652068 -1.095699
200997 200976 1016 54 316 1.676483 -1.082473 u 23441972 59851.319128 271 ... 0.000000 100.003616 0.517738 0.0 0.0 0.054638 4.615579 23.149374 1.725310 -1.095699
201796 201775 1016 54 316 1.676483 -1.082473 r 23612041 59853.287517 273 ... 0.000000 105.211558 0.703991 0.0 0.0 0.049266 4.582841 23.902982 1.631725 -1.092392
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
499513 499446 1016 54 316 1.676483 -1.082473 z 63336326 60313.059330 733 ... 0.000000 99.305638 0.631616 0.0 0.0 0.329836 34.473782 22.944008 1.725310 -1.089086
505980 505913 1016 54 316 1.676483 -1.082473 z 64111949 60322.036450 742 ... 1.518275 98.964336 0.442475 0.0 0.0 0.054638 4.582788 22.090117 1.672414 -1.085779
506007 505940 1016 54 316 1.676483 -1.082473 z 64113001 60322.048633 742 ... 1.449147 97.070298 0.442475 0.0 0.0 0.049266 4.729663 22.109541 1.672414 -1.085779
513505 513437 1016 54 316 1.676483 -1.082473 y 64981417 60332.099735 752 ... 448.902988 90.224016 0.701141 0.0 0.0 0.053898 4.643437 21.576936 1.619518 -1.082473
521016 520948 1016 54 316 1.676483 -1.082473 r 66016587 60344.080869 764 ... 0.000000 89.896577 0.608535 0.0 0.0 0.049266 4.752769 24.266983 1.717174 -1.082473
521057 520989 1016 54 316 1.676483 -1.082473 r 66018262 60344.100258 764 ... 0.000000 89.863543 0.608535 0.0 0.0 0.053898 5.464431 24.267546 1.717174 -1.082473
521931 521863 1016 54 316 1.676483 -1.082473 y 66185149 60346.031820 766 ... 0.000000 91.788842 0.798561 0.0 0.0 0.049266 4.534213 21.308511 1.733448 -1.082473
526366 526298 1016 54 316 1.676483 -1.082473 z 66789910 60353.031376 773 ... 7.310009 90.665782 0.671598 0.0 0.0 0.049266 4.647890 21.912813 1.656138 -1.079167
531455 531386 1016 54 316 1.676483 -1.082473 i 67406345 60360.166032 780 ... 296.755620 99.363479 0.455034 0.0 0.0 0.053898 4.744736 23.262001 1.713105 -1.079167
531491 531422 1016 54 316 1.676483 -1.082473 i 67407812 60360.183013 780 ... 297.011076 102.493784 0.455034 0.0 0.0 0.053898 4.453802 23.224859 1.713105 -1.079167
536210 536141 1016 54 316 1.676483 -1.082473 y 67924209 60366.159831 786 ... 720.936067 101.175322 0.730940 0.0 0.0 0.132408 6.552301 21.410799 1.635792 -1.075860
551809 551739 1016 54 316 1.676483 -1.082473 y 70075506 60391.059108 811 ... 452.331661 95.993138 1.196745 0.0 0.0 0.109158 5.633983 21.051543 1.721241 -1.072554
553459 553389 1016 54 316 1.676483 -1.082473 y 70250594 60393.085580 813 ... 831.302785 101.081050 1.020580 0.0 0.0 0.049266 4.400603 21.134879 1.627656 -1.069247
553485 553415 1016 54 316 1.676483 -1.082473 y 70251617 60393.097428 813 ... 863.449926 103.385325 1.020580 0.0 0.0 0.268917 16.010681 21.106741 1.627656 -1.069247
555516 555446 1016 54 316 1.676483 -1.082473 y 70510972 60396.099214 816 ... 698.937268 105.576996 0.635211 0.0 0.0 0.053898 4.461228 21.459316 1.652068 -1.069247
561447 561377 1016 54 316 1.676483 -1.082473 z 71106191 60402.988323 823 ... 0.000000 92.012869 0.984817 0.0 0.0 0.054638 4.628132 21.585170 1.709036 -1.069247
561713 561643 1016 54 316 1.676483 -1.082473 z 71192480 60403.987039 824 ... 0.000000 92.125849 0.673429 0.0 0.0 0.049266 4.718230 21.895439 1.717174 -1.069247
567167 567096 1016 54 316 1.676483 -1.082473 r 72317972 60417.013567 837 ... 155.429327 99.909825 0.558865 0.0 0.0 0.053898 4.690044 23.842871 1.721241 -1.065941
568677 568606 1016 54 316 1.676483 -1.082473 z 72579573 60420.041358 840 ... 436.059532 107.370605 0.599278 0.0 0.0 0.049266 4.415333 22.358497 1.652068 -1.062635
570480 570409 1016 54 316 1.676483 -1.082473 y 72835902 60423.008134 843 ... 839.991778 101.929761 0.892675 0.0 0.0 0.054638 4.884297 21.240801 1.676483 -1.062635
570482 570411 1016 54 316 1.676483 -1.082473 y 72835979 60423.009025 843 ... 843.360938 102.104378 0.892675 0.0 0.0 0.053898 4.487204 21.238668 1.676483 -1.062635
573456 573385 1016 54 316 1.676483 -1.082473 z 73264911 60427.973517 848 ... 0.000000 98.242478 0.657376 0.0 0.0 0.049266 4.459233 21.849749 1.717174 -1.062635
573520 573449 1016 54 316 1.676483 -1.082473 z 73267921 60428.008352 848 ... 104.059606 104.799316 0.657376 0.0 0.0 0.049266 4.413853 22.466798 1.717174 -1.062635
654837 654756 1016 54 316 1.676483 -1.082473 z 83756933 60549.408958 969 ... 55.359577 99.805183 0.607038 0.0 0.0 0.054638 4.609685 21.890173 1.619518 -1.082473
655759 655678 1016 54 316 1.676483 -1.082473 r 83842133 60550.395066 970 ... 30.107031 101.855251 0.649782 0.0 0.0 0.049266 4.664200 23.964143 1.627656 -1.082473
668433 668343 1016 54 316 1.676483 -1.082473 y 85654677 60571.373577 991 ... 831.799904 96.016252 0.507699 0.0 0.0 0.054638 4.631214 21.718804 1.664276 -1.079167
669276 669186 1016 54 316 1.676483 -1.082473 z 85738875 60572.348097 992 ... 685.717030 99.471151 0.677582 0.0 0.0 0.054638 4.599386 22.254227 1.672414 -1.079167
669325 669235 1016 54 316 1.676483 -1.082473 z 85741109 60572.373956 992 ... 621.245581 95.608617 0.677582 0.0 0.0 0.054638 4.700976 22.341779 1.672414 -1.079167
670126 670036 1016 54 316 1.676483 -1.082473 y 85910710 60574.336930 994 ... 355.676190 100.472773 0.562058 0.0 0.0 0.054638 4.628898 21.602749 1.688690 -1.079167
670138 670048 1016 54 316 1.676483 -1.082473 y 85911175 60574.342304 994 ... 350.490273 99.527919 0.562058 0.0 0.0 0.054638 4.601171 21.614304 1.688690 -1.079167

172 rows × 47 columns

How to read the table:

  • obsHistID indexes a pointing ('fieldRA', 'fieldDec', 'ditheredRA', 'ditheredDec')
  • Additionally a pointing may be assigned a propID to describe what a pointing achieves
  • The meaning of the propID is given in the Proposal Table. For minion_1016_sqlite.db, the WFD is 54, and the DDF is 56, but this coding might change.
  • If a pointing achieves the task of succeeding in two different proposals, this is represented by haveing two records with the same pointng and different propID

In [16]:
test = opsimdf.drop_duplicates()

In [17]:
all(test == opsimdf)


Out[17]:
True

In [18]:
test = opsimdf.drop_duplicates(subset='obsHistID')

In [19]:
len(test) == len(opsimdf)


Out[19]:
False

In [20]:
opsimdf.obsHistID.size


Out[20]:
672917

In [21]:
opsimdf.obsHistID.unique().size


Out[21]:
672825

In [22]:
test.obsHistID.size


Out[22]:
672825

Using OpSimSummary


In [27]:
import opsimsummary as oss


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-27-53b4a326a7c8> in <module>()
----> 1 import opsimsummary as oss

/Users/lluisgalbany/.local/lib/python2.7/site-packages/opsimsummary/__init__.py in <module>()
      1 from __future__ import absolute_import
      2 from .summarize_opsim import *
----> 3 from . import summarize_opsim
      4 from . import simlib
      5 from .version import __VERSION__

ImportError: cannot import name summarize_opsim

In [24]:
# Read in the combined summary.

In [25]:
opsimout = oss.OpSimOutput.fromOpSimDB(opsimdbpath)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-25-1fca3171929d> in <module>()
----> 1 opsimout = oss.OpSimOutput.fromOpSimDB(opsimdbpath)

NameError: name 'oss' is not defined

In [ ]:
help(oss.OpSimOutput)

In [ ]:
opsimDeep = oss.OpSimOutput.fromOpSimDB(opsimdbpath, subset='DDF')

In [ ]:
oss.OpSimOutput.get_allowed_subsets()

In [ ]:
odeep = oss.summarize_opsim.SummaryOpsim(opsimDeep.summary)

Recover some familiar numbers from this


In [ ]:
xx = opsimout.summary.groupby('fieldID').expMJD.agg('count')

In [ ]:
fig, ax = plt.subplots()
xx.hist(histtype='step', bins=np.arange(0., 5000, 50.), ax=ax)
ax.set_xlabel('fieldID')
ax.set_ylabel('Number of visits to field during survey')

In [ ]:
#DDF 
fig, ax = plt.subplots()
xx.hist(bins=np.arange(15000, 25000, 50), histtype='step')
ax.set_xlabel('fieldID')
ax.set_ylabel('Number of visits to field during survey DDF')

In [ ]:
xx[xx > 5000]

In [ ]:
# 1000 visits just in terms of exposure is 9 hrs 25 mins
fig, ax = plt.subplots()
xx = opsimout.summary.groupby(['night']).expMJD.agg('count')
xx.hist(histtype='step', bins=np.arange(0., 5000, 100.), ax=ax)
ax.set_xlabel('Number of visits in a night')

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: