Skip to content

Commit

Permalink
WIP: start getting group-by-metadata working with new universe
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jan 31, 2024
1 parent a147b68 commit e499c15
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions python/lsst/obs/base/defineVisits.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class VisitSystem(enum.Enum):
"""Each exposure is assigned to its own visit."""

BY_GROUP_METADATA = 1
"""Visit membership is defined by the value of the exposure.group_id."""
"""Visit membership is defined by the value of the group dimension or, for
older implementations, exposure.group_id."""

BY_SEQ_START_END = 2
"""Visit membership is defined by the values of the ``exposure.day_obs``,
Expand Down Expand Up @@ -890,10 +891,12 @@ class _GroupExposuresByGroupMetadataConfig(GroupExposuresConfig):

@registerConfigurable("by-group-metadata", GroupExposuresTask.registry)
class _GroupExposuresByGroupMetadataTask(GroupExposuresTask, metaclass=ABCMeta):
"""An exposure grouping algorithm that uses exposure.group_name and
exposure.group_id.
"""An exposure grouping algorithm that uses the exposure group.
This algorithm _assumes_ exposure.group_id (generally populated from
This algorithm uses the ``group`` dimension for modern universes and the
``exposure.group_id`` for older universes.
This algorithm _assumes_ group ID (generally populated from
`astro_metadata_translator.ObservationInfo.visit_id`) is not just unique,
but disjoint from all `ObservationInfo.exposure_id` values - if it isn't,
it will be impossible to ever use both this grouping algorithm and the
Expand All @@ -906,6 +909,11 @@ def find_missing(
self, exposures: list[DimensionRecord], registry: lsst.daf.butler.Registry
) -> list[DimensionRecord]:
groups = self.group_exposures(exposures)
# Determine which group implementation we are using.
if "group" in registry.dimensions["exposure"].implied:
group_key = "group"
else:
group_key = "group_name"
missing_exposures: list[DimensionRecord] = []
for exposures_in_group in groups.values():
# We can not tell how many exposures are expected to be in the
Expand All @@ -914,8 +922,8 @@ def find_missing(
records = set(
registry.queryDimensionRecords(
"exposure",
where="exposure.group_name = group",
bind={"group": first.group_name},
where=f"exposure.{group_key} = groupnam",
bind={"groupnam": getattr(first, group_key)},
instrument=first.instrument,
)
)
Expand All @@ -925,8 +933,11 @@ def find_missing(

def group_exposures(self, exposures: list[DimensionRecord]) -> dict[Any, list[DimensionRecord]]:
groups = defaultdict(list)
group_key = "group"
if exposures and hasattr(exposures[0], "group_name"):
group_key = "group_name"
for exposure in exposures:
groups[exposure.group_name].append(exposure)
groups[getattr(exposure, group_key)].append(exposure)
return groups

def group(self, exposures: list[DimensionRecord]) -> Iterable[VisitDefinitionData]:
Expand Down

0 comments on commit e499c15

Please sign in to comment.