Skip to content

Commit

Permalink
Support v6 universe for exposure day_obs/group dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jan 31, 2024
1 parent cae4ff8 commit d5ed208
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 2 deletions.
30 changes: 30 additions & 0 deletions tests/data/visits/exp_v6_347.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"definition": "exposure",
"record": {
"instrument": "DummyCam",
"id": 2022040500347,
"physical_filter": "dummy_u",
"obs_id": "AT_O_20220405_000347",
"exposure_time": 30.0,
"dark_time": 30.6038341522217,
"observation_type": "science",
"observation_reason": "object",
"day_obs": 20220405,
"seq_num": 347,
"seq_start": 347,
"seq_end": 347,
"group": "2022-04-06T02:56:53.255",
"target_name": "LATISS_E6A_00000027",
"science_program": "LATISS_E6A",
"tracking_ra": 221.548879575131,
"tracking_dec": -44.9667044639895,
"sky_angle": 358.536486388154,
"azimuth": 125.098359365453,
"zenith_angle": 44.1117566243774,
"has_simulated": false,
"timespan": [
1649213928006500400,
1649213958233000000
]
}
}
30 changes: 30 additions & 0 deletions tests/data/visits/exp_v6_348.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"definition": "exposure",
"record": {
"instrument": "DummyCam",
"id": 2022040500348,
"physical_filter": "dummy_u",
"obs_id": "AT_O_20220405_000348",
"exposure_time": 30.0,
"dark_time": 30.3176279067993,
"observation_type": "science",
"observation_reason": "object",
"day_obs": 20220405,
"seq_num": 348,
"seq_start": 348,
"seq_end": 349,
"group": "2022-04-06T02:58:07.181",
"target_name": "LATISS_E6A_00000040",
"science_program": "LATISS_E6A",
"tracking_ra": 222.00924897194,
"tracking_dec": -45.0610184451745,
"sky_angle": 358.485103614766,
"azimuth": 125.230189044465,
"zenith_angle": 44.3171011821396,
"has_simulated": false,
"timespan": [
1649213969056954600,
1649213999288000000
]
}
}
30 changes: 30 additions & 0 deletions tests/data/visits/exp_v6_349.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"definition": "exposure",
"record": {
"instrument": "DummyCam",
"id": 2022040500349,
"physical_filter": "dummy_u",
"obs_id": "AT_O_20220405_000349",
"exposure_time": 30.0,
"dark_time": 30.2387452125549,
"observation_type": "science",
"observation_reason": "object",
"day_obs": 20220405,
"seq_num": 349,
"seq_start": 348,
"seq_end": 349,
"group": "2022-04-06T02:58:07.181",
"target_name": "LATISS_E6A_00000040",
"science_program": "LATISS_E6A",
"tracking_ra": 222.009071979566,
"tracking_dec": -45.060372917262,
"sky_angle": 358.484761155294,
"azimuth": 125.230292756547,
"zenith_angle": 44.2227120117313,
"has_simulated": false,
"timespan": [
1649214001607843600,
1649214031842000000
]
}
}
32 changes: 30 additions & 2 deletions tests/test_defineVisits.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@ def setUp(self):
# Need to register the instrument.
DummyCam().register(self.butler.registry)

# Choose serializations based on universe.
if "group" in self.butler.dimensions["exposure"].implied:
v = "_v6"
else:
v = ""

# Read the exposure records.
self.records: dict[int, DimensionRecord] = {}
for i in (347, 348, 349):
with open(os.path.join(DATADIR, f"exp_{i}.json")) as fh:
with open(os.path.join(DATADIR, f"exp{v}_{i}.json")) as fh:
simple = SerializedDimensionRecord.model_validate_json(fh.read())
self.records[i] = DimensionRecord.from_simple(simple, registry=self.butler.registry)

Expand Down Expand Up @@ -92,7 +98,18 @@ def define_visits(
self, exposures: list[DimensionRecord | list[DimensionRecord]], incremental: bool
) -> None:
for records in exposures:
self.butler.registry.insertDimensionData("exposure", *ensure_iterable(records))
records = list(ensure_iterable(records))
if "group" in self.butler.dimensions["exposure"].implied:
# This is a group + day_obs universe.
for rec in records:
self.butler.registry.syncDimensionData(
"group", dict(instrument=rec.instrument, name=rec.group)
)
self.butler.registry.syncDimensionData(
"day_obs", dict(instrument=rec.instrument, id=rec.day_obs)
)

self.butler.registry.insertDimensionData("exposure", *records)
# Include all records so far in definition.
dataIds = list(self.butler.registry.queryDataIds("exposure", instrument="DummyCam"))
self.task.run(dataIds, incremental=incremental)
Expand All @@ -116,6 +133,17 @@ def test_incremental_cumulative_reverse(self):
self.assertVisits()

def define_visits_incrementally(self, exposure: DimensionRecord) -> None:
if "group" in self.butler.dimensions["exposure"].implied:
self.butler.registry.syncDimensionData(
"group", dict(instrument=exposure.instrument, name=exposure.group)
)
self.butler.registry.syncDimensionData(
"day_obs",
dict(
instrument=exposure.instrument,
id=exposure.day_obs,
),
)
self.butler.registry.insertDimensionData("exposure", exposure)
dataIds = [
DataCoordinate.standardize(
Expand Down

0 comments on commit d5ed208

Please sign in to comment.