Skip to content

Commit

Permalink
Add RecordFactory method for determining relevant region dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jan 14, 2025
1 parent fd4b009 commit 833ac22
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions python/lsst/daf/butler/registry/obscore/_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from ._spatial import RegionTypeError, RegionTypeWarning

if TYPE_CHECKING:
from lsst.daf.butler import DimensionGroup
from lsst.sphgeom import Region

from ._config import DatasetTypeConfig
Expand Down Expand Up @@ -122,6 +123,32 @@ def __init__(
self.visit = universe["visit"]
self.physical_filter = cast(Dimension, universe["physical_filter"])

@abstractmethod
def region_dimension(self, dimensions: DimensionGroup) -> tuple[str | None, str | None]:
"""Return the dimension to use to obtain a region.
Parameters
----------
dimensions : `DimensionGroup`
The dimensions to be examined.
Returns
-------
region_dim : `str` or `None`
The dimension to use to get the region information. Can be `None`
if there is no relevant dimension for a region.
region_metadata : `str` or `None`
The metadata field for the ``region_dim`` that specifies the
region itself.
Notes
-----
This is universe specific. For example, in the ``daf_butler`` namespace
the region for an ``exposure`` is obtained by looking for the relevant
``visit`` or ``visit_detector_region``.
"""
raise NotImplementedError()

def make_generic_records(self, ref: DatasetRef, dataset_config: DatasetTypeConfig) -> Record:
"""Fill record content that is not associated with a specific universe.
Expand Down Expand Up @@ -421,3 +448,16 @@ def _visit_records(self, dimension_record: DimensionRecord, record: dict[str, An
"""Extract all needed info from an exposure dimension record."""
record["t_exptime"] = dimension_record.exposure_time
record["target_name"] = dimension_record.target_name

def region_dimension(self, dimensions: DimensionGroup) -> tuple[str | None, str | None]:
# Inherited doc string.
region_dim = dimensions.region_dimension
if not region_dim:
if "exposure" in dimensions:
if "detector" in dimensions:
region_dim = "visit_detector_region"
else:
region_dim = "visit"
else:
return None, None
return region_dim, "region"

0 comments on commit 833ac22

Please sign in to comment.