2935 hi l1c backgrounds utilities#2936
2935 hi l1c backgrounds utilities#2936subagonsouth merged 9 commits intoIMAP-Science-Operations-Center:devfrom
Conversation
Add background counts binning helper to hi utils
There was a problem hiding this comment.
Pull request overview
This PR adds initial infrastructure for HI L1C “background” configuration handling by introducing a shared DataFrame accessor base class, a new BackgroundConfig accessor, and utilities to filter direct-event datasets by background config selections.
Changes:
- Refactors existing HI calibration-product DataFrame accessor logic into a shared
_BaseConfigAccessorand updatesCalibrationProductConfigto use it. - Introduces
BackgroundConfigDataFrame accessor with CSV loading + validation and adds background event filtering generator/helpers. - Updates/extends HI unit tests and fixtures to cover the new background config accessor and improves column-validation testing.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
imap_processing/hi/utils.py |
Adds _BaseConfigAccessor, introduces BackgroundConfig, and adds background event filtering utilities; also adjusts lookup table DataFrame initialization dtypes. |
imap_processing/tests/hi/test_utils.py |
Adds tests for BackgroundConfig CSV loading/validation and fixes CalibrationProductConfig wrong-column test setup. |
imap_processing/tests/hi/conftest.py |
Adds a fixture for a backgrounds config CSV path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @classmethod | ||
| def from_csv(cls, path: str | Path) -> pd.DataFrame: | ||
| """ | ||
| Read configuration CSV file into a pandas.DataFrame. | ||
| Read calibration product configuration CSV file into a pandas.DataFrame. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| path : str or pathlib.Path | ||
| Location of the Calibration Product configuration CSV file. | ||
| Location of the calibration product configuration CSV file. | ||
|
|
There was a problem hiding this comment.
Type hint for from_csv is path: str | Path, but callers/tests pass file-like objects (e.g., io.StringIO) which pd.read_csv supports. Consider widening the annotation (and docstring wording) to include file-like inputs (e.g., str | Path | IO[str]) to reflect the actual supported API.
| @classmethod | ||
| def from_csv(cls, path: str | Path) -> pd.DataFrame: | ||
| """ | ||
| Get the calibration product numbers from the current configuration. | ||
| Read background configuration CSV file into a pandas.DataFrame. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| path : str or pathlib.Path | ||
| Location of the background configuration CSV file. | ||
|
|
There was a problem hiding this comment.
Type hint for BackgroundConfig.from_csv is path: str | Path, but tests pass file-like objects (e.g., io.StringIO) which pd.read_csv supports. Consider widening the annotation (and docstring wording) to include file-like inputs so the public API matches real usage.
laspsandoval
left a comment
There was a problem hiding this comment.
Just a minor suggestion.
imap_processing/hi/utils.py
Outdated
| "coincidence_type_list", | ||
| *[ | ||
| f"tof_{det_pair}_{limit}" | ||
| for det_pair in tof_detector_pairs |
There was a problem hiding this comment.
for det_pair in _BaseConfigAccessor.tof_detector_pairs
There was a problem hiding this comment.
Yeah, good catch. That was a bit sloppy :)
imap_processing/hi/utils.py
Outdated
| "calibration_prod", | ||
| "esa_energy_step", | ||
| ) | ||
| tof_detector_pairs = ("ab", "ac1", "bc1", "c1c2") |
There was a problem hiding this comment.
Remove the above line.
imap_processing/hi/utils.py
Outdated
| "coincidence_type_list", | ||
| *[ | ||
| f"tof_{det_pair}_{limit}" | ||
| for det_pair in CalibrationProductConfig.tof_detector_pairs |
There was a problem hiding this comment.
for det_pair in _BaseConfigAccessor.tof_detector_pairs
imap_processing/hi/utils.py
Outdated
| "calibration_prod", | ||
| "background_index", | ||
| ) | ||
| tof_detector_pairs = CalibrationProductConfig.tof_detector_pairs |
a5dec5a
into
IMAP-Science-Operations-Center:dev
Summary
Adds background configuration infrastructure for HI L1C processing. Refactors configuration accessor pattern to support both calibration products and backgrounds with shared validation logic.
Key Changes
imap_processing/hi/utils.py_BaseConfigAccessorbase class to eliminate code duplication betweenCalibrationProductConfigand newBackgroundConfigBackgroundConfigaccessor: Pandas DataFrame accessor for background configurationiter_background_events_by_config()generator and_filter_events_by_config_row()helperif index_name in df.index→if index_name not in df.index.namesEsaEnergyStepLookupTableby using explicit dtypesimap_processing/tests/hi/test_utils.pyTestBackgroundConfigclass with 7 tests covering CSV loading, validation, rate/uncertainty calculationsTestCalibrationProductConfig.test_wrong_columnsto properly test column validationimap_processing/tests/hi/conftest.pyhi_test_background_config_pathfixtureRelated Issues
Closes: #2935