Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-31924: add more flexible system for getting data ID packers from Instruments #320

Merged
merged 2 commits into from Apr 27, 2023

Conversation

TallJimbo
Copy link
Member

@TallJimbo TallJimbo commented Apr 18, 2023

Checklist

  • ran Jenkins
  • added a release note for user-visible changes to doc/changes

@TallJimbo TallJimbo force-pushed the tickets/DM-31924 branch 2 times, most recently from 819d063 to bafb5cd Compare April 18, 2023 17:28
@TallJimbo
Copy link
Member Author

Build failures here are just due to it not seeing the pex_config ticket branch. I'm just going to merge that first instead of changing the dependency here temporarily.

Copy link
Contributor

@parejkoj parejkoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit surprised that we don't have any instrument-specific implementations of this: what instruments do you expect would need something other than the default? As noted in your long comment, the logic here is rather complicated, so do you think we truly need the flexibility?

python/lsst/pipe/base/_instrument.py Outdated Show resolved Hide resolved
python/lsst/pipe/base/_observation_dimension_packer.py Outdated Show resolved Hide resolved
python/lsst/pipe/base/_observation_dimension_packer.py Outdated Show resolved Hide resolved
self._n_observations = fixed.records["instrument"].exposure_max # type: ignore[union-attr]
else:
self._n_observations = fixed.records["instrument"].visit_max # type: ignore[union-attr]
self._maxBits = (self._n_observations * self._n_detectors - 1).bit_length()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why _maxBits and not _max_bits for consistency with the others?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change. I'm stuck with the maxBits property as an inherited public and pre-existing interface, but I did intend to be consistently snake_case with the internals and new interfaces here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth deprecating the maxBits property and adding a new max_bits property?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, my bar for an API change to modernize capitalization is really high, even when the expected level of disruption is low.

tests/test_instrument.py Outdated Show resolved Hide resolved
tests/test_instrument.py Outdated Show resolved Hide resolved
tests/test_instrument.py Outdated Show resolved Hide resolved
visit_packers=[
config.packer.apply(visit_data_id),
config.packer.apply(full_data_id),
config.packer.apply(instrument_data_id, is_exposure=False),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must be misunderstanding something here, because I don't see how this works; there's no visit in the dataId to pack.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling apply here just constructs the ObservationDimensionPacker instance. It isn't until pack is called that you need the full data ID.

I'm guessing this is confusing in part because you've just looked at the meas_base PR, where calling apply on a config field ends up both constructing a packer and calling pack on it. It all boils down to DimensionPacker being a per-instrument-and-dimensions or (or per-skymap-and-dimensions) thing, while IdGenerator is a per-data-ID thing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth a comment to that effect here? Or maybe I'm just confused by having reviewed all this.

python/lsst/pipe/base/_instrument.py Show resolved Hide resolved
Copy link
Member Author

@TallJimbo TallJimbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit surprised that we don't have any instrument-specific implementations of this: what instruments do you expect would need something other than the default? As noted in your long comment, the logic here is rather complicated, so do you think we truly need the flexibility?

This is all very much focused on having LSSTCam, LATISS, ComCam, and some of the LSST simulators override the behavior. I'm just trying to keep this ticket limited to structural changes rather than behavioral changes. The ticket for that override is DM-38688.

python/lsst/pipe/base/_instrument.py Show resolved Hide resolved
python/lsst/pipe/base/_instrument.py Outdated Show resolved Hide resolved
python/lsst/pipe/base/_observation_dimension_packer.py Outdated Show resolved Hide resolved
self._n_observations = fixed.records["instrument"].exposure_max # type: ignore[union-attr]
else:
self._n_observations = fixed.records["instrument"].visit_max # type: ignore[union-attr]
self._maxBits = (self._n_observations * self._n_detectors - 1).bit_length()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change. I'm stuck with the maxBits property as an inherited public and pre-existing interface, but I did intend to be consistently snake_case with the internals and new interfaces here.


def _pack(self, dataId: DataCoordinate) -> int:
# Docstring inherited from DimensionPacker._pack
detector_id = cast(int, dataId["detector"])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a static-typing only cast that does nothing at runtime; it's just a signal to MyPy that says "I know this is going to be an integer so don't complain to me about it maybe being something else"; daf_butler tells MyPy that data ID values can be str or int, here it needs to be told that detector implies int.

visit_packers=[
config.packer.apply(visit_data_id),
config.packer.apply(full_data_id),
config.packer.apply(instrument_data_id, is_exposure=False),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling apply here just constructs the ObservationDimensionPacker instance. It isn't until pack is called that you need the full data ID.

I'm guessing this is confusing in part because you've just looked at the meas_base PR, where calling apply on a config field ends up both constructing a packer and calling pack on it. It all boils down to DimensionPacker being a per-instrument-and-dimensions or (or per-skymap-and-dimensions) thing, while IdGenerator is a per-data-ID thing.

tests/test_instrument.py Outdated Show resolved Hide resolved
@TallJimbo TallJimbo force-pushed the tickets/DM-31924 branch 2 times, most recently from a3b6118 to b7b10cc Compare April 26, 2023 18:07
@TallJimbo TallJimbo merged commit 47e39a0 into main Apr 27, 2023
8 checks passed
@TallJimbo TallJimbo deleted the tickets/DM-31924 branch April 27, 2023 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants