Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 58 additions & 11 deletions imap_processing/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
from imap_processing.glows.l1a.glows_l1a import glows_l1a
from imap_processing.glows.l1b.glows_l1b import glows_l1b, glows_l1b_de
from imap_processing.glows.l2.glows_l2 import glows_l2
from imap_processing.hi import hi_l1a, hi_l1b, hi_l1c, hi_l2
from imap_processing.hi import hi_goodtimes, hi_l1a, hi_l1b, hi_l1c, hi_l2
from imap_processing.hit.l1a.hit_l1a import hit_l1a
from imap_processing.hit.l1b.hit_l1b import hit_l1b
from imap_processing.hit.l2.hit_l2 import hit_l2
Expand Down Expand Up @@ -770,7 +770,7 @@ def do_processing(
class Hi(ProcessInstrument):
"""Process IMAP-Hi."""

def do_processing(
def do_processing( # noqa: PLR0912
self, dependencies: ProcessingInputCollection
) -> list[xr.Dataset]:
Comment on lines +773 to 775
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.
"""
Expand All @@ -789,6 +789,10 @@ def do_processing(
print(f"Processing IMAP-Hi {self.data_level}")
datasets: list[xr.Dataset] = []

# Check self.repointing is not None (for mypy type checking)
if self.repointing is None:
raise ValueError("Repointing must be provided for Hi processing.")

if self.data_level == "l1a":
science_files = dependencies.get_file_paths(source="hi")
if len(science_files) != 1:
Expand All @@ -813,17 +817,60 @@ def do_processing(
load_cdf(l1a_de_file), load_cdf(l1b_hk_file), esa_energies_csv
)
elif self.data_level == "l1c":
science_paths = dependencies.get_file_paths(source="hi", data_type="l1b")
if len(science_paths) != 1:
raise ValueError(
f"Expected only one science dependency. Got {science_paths}"
if "goodtimes" in self.descriptor:
# Goodtimes processing
l1b_de_paths = dependencies.get_file_paths(
source="hi", data_type="l1b", descriptor="de"
)
anc_paths = dependencies.get_file_paths(data_type="ancillary")
if len(anc_paths) != 1:
raise ValueError(
f"Expected only one ancillary dependency. Got {anc_paths}"
if not l1b_de_paths:
raise ValueError("No L1B DE files found for goodtimes processing")

l1b_hk_paths = dependencies.get_file_paths(
source="hi", data_type="l1b", descriptor="hk"
)
datasets = hi_l1c.hi_l1c(load_cdf(science_paths[0]), anc_paths[0])
if len(l1b_hk_paths) != 1:
raise ValueError(
f"Expected one L1B HK file, got {len(l1b_hk_paths)}"
)

cal_prod_paths = dependencies.get_file_paths(
data_type="ancillary", descriptor="cal-prod"
)
if len(cal_prod_paths) != 1:
raise ValueError(
f"Expected one cal-prod ancillary file, "
f"got {len(cal_prod_paths)}"
)

# Load CDFs before passing to hi_goodtimes
l1b_de_datasets = [load_cdf(path) for path in l1b_de_paths]
l1b_hk = load_cdf(l1b_hk_paths[0])

output_paths = hi_goodtimes.hi_goodtimes(
l1b_de_datasets,
self.repointing,
l1b_hk,
cal_prod_paths[0],
Path(imap_data_access.config["DATA_DIR"]),
self.start_date,
self.version,
)
return output_paths
elif "pset" in self.descriptor:
# L1C PSET processing
science_paths = dependencies.get_file_paths(
source="hi", data_type="l1b"
)
if len(science_paths) != 1:
raise ValueError(
f"Expected only one science dependency. Got {science_paths}"
)
anc_paths = dependencies.get_file_paths(data_type="ancillary")
if len(anc_paths) != 1:
raise ValueError(
f"Expected only one ancillary dependency. Got {anc_paths}"
)
datasets = hi_l1c.hi_l1c(load_cdf(science_paths[0]), anc_paths[0])
elif self.data_level == "l2":
science_paths = dependencies.get_file_paths(source="hi", data_type="l1c")
anc_dependencies = dependencies.get_processing_inputs(data_type="ancillary")
Expand Down
Loading