Skip to content

Implement center/delta epoch values for most CoDICE L1a products#1906

Merged
bourque merged 5 commits intoIMAP-Science-Operations-Center:devfrom
bourque:codice-l1a-center-epoch-bins
Jul 3, 2025
Merged

Implement center/delta epoch values for most CoDICE L1a products#1906
bourque merged 5 commits intoIMAP-Science-Operations-Center:devfrom
bourque:codice-l1a-center-epoch-bins

Conversation

@bourque
Copy link
Copy Markdown
Collaborator

@bourque bourque commented Jul 2, 2025

This PR implements epoch values that are centered within the acquisition time window, as well as data variables for their corresponding delta_minus and delta_plus for most CoDICE L1a data products. These calculations for the hskp, hi-omni, and hi-ialirt are a bit trickier and will be addressed in a separate PR.

Another thing to note is that this PR will be the first of several that makes (relatively) small changes to CoDICE L1a data products. The goal is to eventually re-validate against updated validation data once all of those fixes are in. In the meantime, I may need to tweak or turn off certain unit tests to get tests passing in this middle-ground state between sets of validation data.

Partially completes #1501

@bourque bourque added this to the July 2025 milestone Jul 2, 2025
@bourque bourque requested a review from Copilot July 2, 2025 21:38
@bourque bourque self-assigned this Jul 2, 2025
@bourque bourque added the Ins: CoDICE Related to the CoDICE instrument label Jul 2, 2025
@bourque bourque added this to IMAP Jul 2, 2025
@bourque bourque added the Level: L1 Level 1 processing label Jul 2, 2025
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 centered epoch computation and corresponding delta-minus/plus variables to CoDICE L1a products, updates coordinate definitions and dataset creation routines, and introduces a new test for epoch values.

  • Introduce calculate_epoch_values helper to compute centered epoch and deltas.
  • Update define_coordinates, create_direct_event_dataset, and related functions to include epoch_delta_minus and epoch_delta_plus.
  • Add a parametrized test test_l1a_validate_epoch_values and extend YAML configs with new variable attributes.

Reviewed Changes

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

File Description
imap_processing/tests/codice/test_codice_l1a.py Add test for validating epoch values
imap_processing/codice/codice_l1a.py Extract epoch/delta logic, update coordinate setup and dataset creation
imap_processing/cdf/config/imap_codice_l1b_variable_attrs.yaml Add YAML entries for epoch_delta_minus/plus
imap_processing/cdf/config/imap_codice_l1a_variable_attrs.yaml Add YAML entries for epoch_delta_minus/plus
Comments suppressed due to low confidence (1)

imap_processing/tests/codice/test_codice_l1a.py:286

  • The new test asserts only the centered epoch matches validation but doesn't cover epoch_delta_minus or epoch_delta_plus. Add assertions for these two arrays to ensure full coverage of the new output variables.
    np.testing.assert_allclose(

Comment thread imap_processing/codice/codice_l1a.py Outdated
dims=[name],
attrs=self.cdf_attrs.get_variable_attributes(name, check_schema=False),
)
self.coords[name] = var
Copy link

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

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

Here you're storing the raw ndarray instead of the DataArray you just created. It should be self.coords[name] = coord so downstream logic receives the DataArray.

Suggested change
self.coords[name] = var
self.coords[name] = coord

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Great catch robot overlord!

Comment thread imap_processing/codice/codice_l1a.py Outdated
Comment on lines +700 to +707
epoch = (acq_start[:-1] + acq_start[1:]) / 2
epoch_delta_minus = epoch - acq_start[:-1]
epoch_delta_plus = acq_start[1:] - epoch

# The end values are calculated differently
epoch = np.concatenate([epoch, [acq_start[-1]]])
epoch_delta_minus = np.concatenate([epoch_delta_minus, [epoch_delta_minus[-1]]])
epoch_delta_plus = np.concatenate([epoch_delta_plus, [epoch_delta_plus[-1]]])
Copy link

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

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

This division produces floats but your function signature and attributes imply integer nanoseconds. Consider rounding or casting the result to an integer type to maintain consistency.

Suggested change
epoch = (acq_start[:-1] + acq_start[1:]) / 2
epoch_delta_minus = epoch - acq_start[:-1]
epoch_delta_plus = acq_start[1:] - epoch
# The end values are calculated differently
epoch = np.concatenate([epoch, [acq_start[-1]]])
epoch_delta_minus = np.concatenate([epoch_delta_minus, [epoch_delta_minus[-1]]])
epoch_delta_plus = np.concatenate([epoch_delta_plus, [epoch_delta_plus[-1]]])
epoch = np.round((acq_start[:-1] + acq_start[1:]) / 2).astype(int)
epoch_delta_minus = np.round(epoch - acq_start[:-1]).astype(int)
epoch_delta_plus = np.round(acq_start[1:] - epoch).astype(int)
# The end values are calculated differently
epoch = np.concatenate([epoch, [int(acq_start[-1])]])
epoch_delta_minus = np.concatenate([epoch_delta_minus, [int(epoch_delta_minus[-1])]])
epoch_delta_plus = np.concatenate([epoch_delta_plus, [int(epoch_delta_plus[-1])]])

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think just adding .astype(int) to the end of line 700 fixes all of this. I think the other changes are not necessary?

epoch_delta_minus = xr.DataArray(
epochs_delta_minus,
name="epoch_delta_minus",
dims=["epoch_delta_minus"],
Copy link

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

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

The dimension name should match the coordinate dimension 'epoch', not its own name. Update to dims=["epoch"] so the deltas align with the epoch axis.

Copilot uses AI. Check for mistakes.
self.plan_step = plan_step
self.view_id = view_id

def calculate_epoch_values(self) -> NDArray[int]:
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I moved this method outside of the class and made it a function so I can re-use it in multiple places in the code.

Comment thread imap_processing/codice/codice_l1a.py Outdated
acq_start = met_to_ttj2000ns(acq_start_seconds + acq_start_subseconds / 1e6)

# Apply correction to center the epoch bin
epoch = ((acq_start[:-1] + acq_start[1:]) / 2).astype(int)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Another option is to use integer division.

Suggested change
epoch = ((acq_start[:-1] + acq_start[1:]) / 2).astype(int)
epoch = ((acq_start[:-1] + acq_start[1:]) // 2)

Comment thread imap_processing/codice/codice_l1a.py Outdated
epoch_delta_minus = epoch - acq_start[:-1]
epoch_delta_plus = acq_start[1:] - epoch

# The end values are calculated differently
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How? Could you add a comment here saying what you are doing. I would have naively assumed you would handle the minus and plus differently because they are going off different ends of the array. (one prepend, the other append)

@bourque bourque merged commit 1605508 into IMAP-Science-Operations-Center:dev Jul 3, 2025
14 checks passed
@bourque bourque deleted the codice-l1a-center-epoch-bins branch July 3, 2025 17:28
@github-project-automation github-project-automation bot moved this to Done in IMAP Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ins: CoDICE Related to the CoDICE instrument Level: L1 Level 1 processing

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants