Skip to content

Commit

Permalink
Merge pull request #478 from LSSTDESC/u/jchiang/opsim_db_dayobs_seqnum
Browse files Browse the repository at this point in the history
bug-fix for seqnum calculation
  • Loading branch information
jchiang87 authored Jun 17, 2024
2 parents c85d643 + 81c645c commit b1f0cb1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion imsim/opsim_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def _read_opsim_db(self):
# Determine the daily sequence number for this exposure by
# counting the number of snaps since int(observationStartMJD)
# with a half-day offset to account for Rubin's dayobs definition.
t0 = int(self.meta['observationStartMJD']) - 0.5
t0 = int(self.meta['observationStartMJD'] - 0.5) + 0.5
sql = f'''select numExposures from observations where
{t0} <= observationStartMJD and
observationId < {self.visit}'''
Expand Down
Binary file added tests/data/opsim_db_seqnum_test_data.db
Binary file not shown.
27 changes: 27 additions & 0 deletions tests/test_OpsimDataLoader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from pathlib import Path
import numpy as np
from imsim import OpsimDataLoader

DATA_DIR = Path(__file__).parent / "data"


def test_seqnum_calculation():
"""Test the values of seqnum computed by OpsimDataLoader from
an opsim db file."""
opsim_db_file = str(DATA_DIR / "opsim_db_seqnum_test_data.db")
visits = sorted(np.random.choice(range(2173), 10, replace=False))
for visit in visits:
opsim_data = OpsimDataLoader(opsim_db_file, visit=visit)
# The seqnum_ref column was added to an existing opsim db
# file. It contains the sequence number computed by hand
# based on the definition of DAYOBS (See appendix A of
# https://docushare.lsst.org/docushare/dsweb/Get/LSE-400).
# The test data file contains an excerpt covering two days of
# observations.
assert opsim_data.meta["seqnum"] == opsim_data.meta["seqnum_ref"]


if __name__ == "__main__":
testfns = [v for k, v in vars().items() if k[:5] == "test_" and callable(v)]
for testfn in testfns:
testfn()

0 comments on commit b1f0cb1

Please sign in to comment.