Skip to content

2510 hi goodtimes set up cli call to processing 1#2779

Draft
subagonsouth wants to merge 5 commits intoIMAP-Science-Operations-Center:devfrom
subagonsouth:2510-hi-goodtimes---set-up-cli-call-to-processing-1
Draft

2510 hi goodtimes set up cli call to processing 1#2779
subagonsouth wants to merge 5 commits intoIMAP-Science-Operations-Center:devfrom
subagonsouth:2510-hi-goodtimes---set-up-cli-call-to-processing-1

Conversation

@subagonsouth
Copy link
Contributor

Change Summary

Overview

This PR adds the top-level hi_goodtimes orchestrator function and integrates it with the CLI for IMAP-Hi L1C goodtimes processing.

Changes

imap_processing/hi/hi_goodtimes.py

  • Added hi_goodtimes() top-level function that orchestrates all goodtimes culling operations
  • Added _find_current_pointing_index() helper to locate the current pointing in the datasets list
  • Added _apply_goodtimes_filters() helper that applies all 6 culling filters (incomplete spin sets, DRF times, overflow packets, statistical filters 0-2)
  • Added _write_goodtimes_output() helper that generates the output filename and writes the goodtimes text file
  • Implements repoint availability check: processing only proceeds if current_repointing + 3 has occurred
  • Handles incomplete DE file sets by marking all times as bad (CullCode.LOOSE)
  • Output filename pattern: imap_hi_sensor{45|90}-goodtimes_{start_date}{start_date}{version}.txt
    • TODO: Add repointing to filename when allowed in ancillary filenames

imap_processing/cli.py

  • Added Hi L1C goodtimes processing branch in Hi.do_processing()
  • Loads L1B DE and HK CDFs before passing to hi_goodtimes
  • Validates required dependencies (DE files, 1 HK file, 1 cal-prod ancillary)
  • Passes start_date and version from CLI arguments to hi_goodtimes

imap_processing/tests/hi/test_hi_goodtimes.py

  • Added TestFindCurrentPointingIndex - tests for finding current pointing index in datasets
  • Added TestWriteGoodtimesOutput - tests filename generation and write_txt calls
  • Added TestApplyGoodtimesFilters - tests all 6 filters are called and errors are handled
  • Added TestHiGoodtimes - tests the main orchestrator including repoint checks, incomplete DE handling, and filter application

imap_processing/tests/test_cli.py

  • Added test_hi_l1c_goodtimes - tests CLI integration with proper mocking of load_cdf and hi_goodtimes

Design Decisions

  1. CDF loading in CLI: CDFs are loaded in cli.py before passing to hi_goodtimes, consistent with other Hi processing levels
  2. Repoint availability check: Uses get_repoint_data() to verify current_repointing + 3 has completed before processing
  3. Graceful degradation: Returns empty list if repointing not ready; marks all times bad if incomplete DE set
  4. Statistical filter error handling: ValueError from statistical filters is caught and logged (doesn't fail processing)

Closes: #2510

Copy link
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 implements the top-level Hi goodtimes orchestrator function and integrates it with the CLI for IMAP-Hi L1C goodtimes processing. The goodtimes processing identifies and culls bad time intervals for Hi sensor data using 6 different filtering algorithms (incomplete spin sets, DRF times, overflow packets, and 3 statistical filters). The implementation includes repointing availability checks to ensure sufficient surrounding pointings exist for statistical analysis before proceeding with processing.

Changes:

  • Added hi_goodtimes() orchestrator function and helper functions (_find_current_pointing_index, _apply_goodtimes_filters, _write_goodtimes_output) to manage the goodtimes culling workflow
  • Integrated goodtimes processing into the CLI with proper dependency validation and CDF loading
  • Updated sensor naming convention from "Hi45"/"Hi90" to "sensor45"/"sensor90" to maintain consistency
  • Added comprehensive test coverage for the new orchestrator, helpers, and CLI integration

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
imap_processing/hi/hi_goodtimes.py Adds hi_goodtimes() orchestrator and helper functions for goodtimes processing; updates sensor naming convention in create_goodtimes_dataset()
imap_processing/cli.py Adds L1C goodtimes processing branch in Hi.do_processing() with dependency validation and CDF loading; refactors L1C pset processing into explicit elif branch
imap_processing/tests/hi/test_hi_goodtimes.py Adds comprehensive test coverage for new functions (TestFindCurrentPointingIndex, TestWriteGoodtimesOutput, TestApplyGoodtimesFilters, TestHiGoodtimes); updates sensor names in existing tests
imap_processing/tests/test_cli.py Adds test_hi_l1c_goodtimes for CLI integration testing; updates parametrize decorator in test_hi to include data_descriptor parameter

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

logger.info("Starting Hi goodtimes processing")

# Parse the current repoint ID and check if we can process yet
current_repoint_id = int(current_repointing.replace("repoint", ""))
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

The parsing of current_repointing at line 114 using simple string replacement could fail silently if the format is unexpected (e.g., if it doesn't start with "repoint"). Consider using a regex match or adding validation to raise a clear error if the format is invalid, rather than potentially creating an incorrect repoint_id.

Suggested change
current_repoint_id = int(current_repointing.replace("repoint", ""))
match = re.fullmatch(r"repoint(\d+)", current_repointing)
if not match:
msg = (
f"Invalid current_repointing format: {current_repointing!r}. "
"Expected format 'repointNNNNN' where NNNNN are digits."
)
logger.error(msg)
raise ValueError(msg)
current_repoint_id = int(match.group(1))

Copilot uses AI. Check for mistakes.
Comment on lines +773 to 775
def do_processing( # noqa: PLR0912
self, dependencies: ProcessingInputCollection
) -> list[xr.Dataset]:
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

The return type annotation for Hi.do_processing should be list[xr.Dataset | Path] instead of list[xr.Dataset] because the goodtimes processing path returns a list of Path objects (line 858). This is consistent with the Spacecraft instrument's do_processing method which also returns list[xr.Dataset | Path] and aligns with the post_processing method's signature which accepts list[xr.Dataset | Path].

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@subagonsouth subagonsouth marked this pull request as draft February 26, 2026 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Hi Goodtimes - Set up cli call to processing

2 participants