Skip to content

Commit

Permalink
Add ability for ObsCore record facility name to vary by instrument
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Dec 3, 2024
1 parent 1efb2aa commit 207cb10
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
10 changes: 8 additions & 2 deletions python/lsst/daf/butler/registry/obscore/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class SpatialPluginConfig(pydantic.BaseModel):
cls: str
"""Name of the class implementing plugin methods."""

config: dict[str, Any] = {}
config: dict[str, Any] = pydantic.Field(default_factory=dict)
"""Configuration object passed to plugin ``initialize()`` method."""


Expand Down Expand Up @@ -144,7 +144,13 @@ class ObsCoreConfig(pydantic.BaseModel):
"""

facility_name: str
"""Value for the ``facility_name`` column."""
"""Default value for the ``facility_name`` column. If an instrument
is listed in ``facility_map`` that will be used in preference but this
value must always be set as a fallback."""

facility_map: dict[str, str] = pydantic.Field(default_factory=dict)
"""Mapping of instrument name to facility name. Takes precedence over
the ``facility_name``."""

extra_columns: None | (
dict[str, StrictFloat | StrictInt | StrictBool | StrictStr | ExtraColumnConfig]
Expand Down
6 changes: 4 additions & 2 deletions python/lsst/daf/butler/registry/obscore/_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,20 @@ def __call__(self, ref: DatasetRef) -> Record | None:
record["dataproduct_type"] = dataset_config.dataproduct_type
record["dataproduct_subtype"] = dataset_config.dataproduct_subtype
record["o_ucd"] = dataset_config.o_ucd
record["facility_name"] = self.config.facility_name
record["calib_level"] = dataset_config.calib_level
if dataset_config.obs_collection is not None:
record["obs_collection"] = dataset_config.obs_collection
else:
record["obs_collection"] = self.config.obs_collection
record["access_format"] = dataset_config.access_format

record["instrument_name"] = dataId.get("instrument")
instrument_name = cast(str, dataId.get("instrument"))
record["instrument_name"] = instrument_name
if self.schema.dataset_fk is not None:
record[self.schema.dataset_fk.name] = ref.id

record["facility_name"] = self.config.facility_map.get(instrument_name, self.config.facility_name)

timespan = dataId.timespan
if timespan is not None:
if timespan.begin is not None:
Expand Down
2 changes: 2 additions & 0 deletions tests/config/basic/obscore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ version: 0
table_name: obscore
collection_type: RUN
facility_name: daf_butler_test
facility_map:
DummyCam: derived_facility
obs_collection: daf_butler_obs_collection
collections: []
use_butler_uri: false
Expand Down
3 changes: 2 additions & 1 deletion tests/test_obscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def test_update_exposure_region(self) -> None:
)
self.assertEqual(count, 2)

with obscore.query(["s_ra", "s_dec", "s_region", "lsst_detector"]) as result:
with obscore.query(["s_ra", "s_dec", "s_region", "lsst_detector", "facility_name"]) as result:
rows = list(result)
self.assertEqual(len(rows), 4)
for row in rows:
Expand All @@ -491,6 +491,7 @@ def test_update_exposure_region(self) -> None:
self.assertIsNone(row.s_ra)
self.assertIsNone(row.s_dec)
self.assertIsNone(row.s_region)
self.assertEqual(row.facility_name, "derived_facility")


class SQLiteObsCoreTest(ObsCoreTests, unittest.TestCase):
Expand Down

0 comments on commit 207cb10

Please sign in to comment.