Skip to content

Commit

Permalink
Merge pull request #98 from lsst/tickets/PREOPS-5245
Browse files Browse the repository at this point in the history
tickets/PREOPS-5245: Add support for reading visits from ConsDB
  • Loading branch information
ehneilsen authored Sep 13, 2024
2 parents 4cfe30b + bde8938 commit 6e22267
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
18 changes: 18 additions & 0 deletions schedview/collect/consdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import numpy as np
import pandas as pd
import rubin_sim.maf
from rubin_scheduler.utils.consdb import load_consdb_visits


def read_consdb(
instrument: str = "lsstcomcamsim",
*args,
stackers: list[rubin_sim.maf.stackers.base_stacker.BaseStacker] = [],
**kwargs,
) -> pd.DataFrame:
consdb_visits = load_consdb_visits(instrument, *args, **kwargs)
visit_records: np.recarray = consdb_visits.opsim.to_records()
for stacker in stackers:
visit_records = stacker.run(visit_records)
visits = pd.DataFrame(visit_records)
return visits
21 changes: 21 additions & 0 deletions tests/test_consdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import unittest

import pandas as pd
from rubin_sim import maf

from schedview.collect.consdb import read_consdb


class TestConsdb(unittest.TestCase):

@unittest.skip("avoid requiring access to consdb for tests.")
def test_consdb_read_consdb(self):
day_obs: str = "2024-06-26"
stackers = [
maf.stackers.OverheadStacker(),
maf.HourAngleStacker(),
maf.stackers.ObservationStartDatetime64Stacker(),
]
visits: pd.DataFrame = read_consdb("lsstcomcamsim", day_obs, stackers=stackers)
assert "HA" in visits.columns
assert "overhead" in visits.columns

0 comments on commit 6e22267

Please sign in to comment.