Skip to content

2935 hi l1c backgrounds utilities#2936

Merged
subagonsouth merged 9 commits intoIMAP-Science-Operations-Center:devfrom
subagonsouth:2935-hi-l1c-backgrounds---utilities
Apr 9, 2026
Merged

2935 hi l1c backgrounds utilities#2936
subagonsouth merged 9 commits intoIMAP-Science-Operations-Center:devfrom
subagonsouth:2935-hi-l1c-backgrounds---utilities

Conversation

@subagonsouth
Copy link
Copy Markdown
Contributor

@subagonsouth subagonsouth commented Apr 8, 2026

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

  • Refactored configuration accessors: Created _BaseConfigAccessor base class to eliminate code duplication between CalibrationProductConfig and new BackgroundConfig
  • Added BackgroundConfig accessor: Pandas DataFrame accessor for background configuration
  • Added background filtering utilities: iter_background_events_by_config() generator and _filter_events_by_config_row() helper
  • Bug fixes:
    • Fixed validation logic: if index_name in df.indexif index_name not in df.index.names
    • Fixed pandas FutureWarning in EsaEnergyStepLookupTable by using explicit dtypes

imap_processing/tests/hi/test_utils.py

  • Added TestBackgroundConfig class with 7 tests covering CSV loading, validation, rate/uncertainty calculations
  • Fixed TestCalibrationProductConfig.test_wrong_columns to properly test column validation

imap_processing/tests/hi/conftest.py

  • Added hi_test_background_config_path fixture

Related Issues

Closes: #2935

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 _BaseConfigAccessor and updates CalibrationProductConfig to use it.
  • Introduces BackgroundConfig DataFrame 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.

Comment on lines 554 to 563
@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.

Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +614 to 623
@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.

Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@laspsandoval laspsandoval left a comment

Choose a reason for hiding this comment

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

Just a minor suggestion.

"coincidence_type_list",
*[
f"tof_{det_pair}_{limit}"
for det_pair in tof_detector_pairs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

for det_pair in _BaseConfigAccessor.tof_detector_pairs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good catch. That was a bit sloppy :)

"calibration_prod",
"esa_energy_step",
)
tof_detector_pairs = ("ab", "ac1", "bc1", "c1c2")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove the above line.

"coincidence_type_list",
*[
f"tof_{det_pair}_{limit}"
for det_pair in CalibrationProductConfig.tof_detector_pairs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

for det_pair in _BaseConfigAccessor.tof_detector_pairs

"calibration_prod",
"background_index",
)
tof_detector_pairs = CalibrationProductConfig.tof_detector_pairs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove above.

@subagonsouth subagonsouth merged commit a5dec5a into IMAP-Science-Operations-Center:dev Apr 9, 2026
14 checks passed
@subagonsouth subagonsouth deleted the 2935-hi-l1c-backgrounds---utilities branch April 9, 2026 21:01
@github-project-automation github-project-automation bot moved this to Done in IMAP Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Hi L1C Backgrounds - utilities

3 participants