diff --git a/python/lsst/daf/butler/registry/obscore/_config.py b/python/lsst/daf/butler/registry/obscore/_config.py index 928c7132d7..e7f454d716 100644 --- a/python/lsst/daf/butler/registry/obscore/_config.py +++ b/python/lsst/daf/butler/registry/obscore/_config.py @@ -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.""" @@ -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] diff --git a/python/lsst/daf/butler/registry/obscore/_records.py b/python/lsst/daf/butler/registry/obscore/_records.py index e4c0ab1905..bbd29bfadf 100644 --- a/python/lsst/daf/butler/registry/obscore/_records.py +++ b/python/lsst/daf/butler/registry/obscore/_records.py @@ -163,7 +163,6 @@ 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 @@ -171,10 +170,13 @@ def __call__(self, ref: DatasetRef) -> Record | None: 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: diff --git a/tests/config/basic/obscore.yaml b/tests/config/basic/obscore.yaml index 966f8a9cbf..5cbdcd26b9 100644 --- a/tests/config/basic/obscore.yaml +++ b/tests/config/basic/obscore.yaml @@ -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 diff --git a/tests/test_obscore.py b/tests/test_obscore.py index e9bb88d610..830282cc00 100644 --- a/tests/test_obscore.py +++ b/tests/test_obscore.py @@ -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: @@ -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):