Skip to content

CoDICE: Fixing attrs bugs for CAVA#2891

Merged
tech3371 merged 2 commits intoIMAP-Science-Operations-Center:devfrom
tech3371:cod_l2_attrs
Mar 31, 2026
Merged

CoDICE: Fixing attrs bugs for CAVA#2891
tech3371 merged 2 commits intoIMAP-Science-Operations-Center:devfrom
tech3371:cod_l2_attrs

Conversation

@tech3371
Copy link
Copy Markdown
Contributor

Change Summary

closes #2765

Overview

Fixes for three products that needed fixes for CAVA, L2 omni, sectored and lo-sw-species.

File changes

Updated CDF attr YAML and code to not carry l1b attrs which caused few issues. L2 needs to read from L2 attrs file.

Testing

@tech3371
Copy link
Copy Markdown
Contributor Author

@jtniehof pining you for awareness.

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 updates CoDICE L2 metadata handling (primarily CDF variable attributes) to improve CAVA compliance and avoid incorrectly carrying L1B attributes into L2 products (per #2765).

Changes:

  • Rebuild several L2 coordinate variables as explicit xr.DataArrays with L2 CDF attributes (instead of reusing L1B coordinate DataArrays/attrs).
  • Add/propagate epoch_delta_plus / epoch_delta_minus coordinates for hi-omni and hi-sectored products and adjust related attribute handling.
  • Update multiple CoDICE CDF attribute YAMLs (formats, fill values, display types, scaling, and species placeholder replacement support).

Reviewed changes

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

Show a summary per file
File Description
imap_processing/codice/codice_l2.py Reworks L2 coordinate construction/attrs; adds epoch delta coordinates; applies species attribute placeholder replacements.
imap_processing/cdf/config/imap_codice_l2-lo-species_variable_attrs.yaml Updates lo-species coordinate and data variable attribute definitions (formats/scales/valid ranges).
imap_processing/cdf/config/imap_codice_l2-hi-sectored_variable_attrs.yaml Updates hi-sectored coordinate/data attribute definitions, including species placeholder-based DEPEND/LABL_PTR wiring.
imap_processing/cdf/config/imap_codice_l2-hi-omni_variable_attrs.yaml Updates hi-omni attribute definitions (formats, scales, display types, etc.).
imap_processing/cdf/config/imap_codice_l1a_variable_attrs.yaml Minor attribute value/type tweaks and reordering/augmentation for DE attrs.

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

Copy link
Copy Markdown
Contributor

@subagonsouth subagonsouth left a comment

Choose a reason for hiding this comment

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

Nothing blocking a merge, but a couple questions and an idea to reduce duplicated code.

FIELDNAM: epoch delta minus
FILLVAL: -9223372036854775808
FORMAT: I18
FILLVAL: *real_fillval
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.

I'm not sure that I understand this change. I would expect epoch_delta_minus/plus to be int64 to match the epoch datatype and contain integer nanoseconds.

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.

I was getting this warning when running ISTP checks. I remember now. Epoch delta were double because we had to divide by something and so on. That's why deltas were double type.

epoch_delta_plus
		FILLVAL value of '9.223372036854776E18' is non-standard.
		    The recommended value is '-1.0E31'.
		FORMAT 'I32' is invalid for a CDF_DOUBLE type variable

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.

I think the fix there is to change the type of the variable, as Tim suggested, not the fill (and the format).

Copy link
Copy Markdown
Contributor Author

@tech3371 tech3371 Mar 31, 2026

Choose a reason for hiding this comment

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

so if delta's data is float, convert to int? I haven't looked closely but it's ok to round up for delta if they are float type? If that is ok, I can totally revert and change data type of delta.

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.

This is a mildly uninformed opinion since I haven't tracked the time handling through the l1 code.

Since the deltas are in ns, rounding shouldn't cause an issue in terms of scientific interpretation or anything like that. There might be some slight weirdness with certain tools if adjacent times get rounded differently, which might imply a small gap between successive measurements or overlap between them. I did a chunk check of an existing omni hi l2 and it looks like the fractional part of all the deltas is zero, so that feels like something not worth worrying about right now.

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.

Perfect! Thank you for that information! It's scientific user experience that I don't enough and didn't want to assume :)

I will make changes Tim suggested!

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.

I am going to revert these epoch updates and update l1a to convert to int in upcoming PR. Want to get this CAVA support for Leng Yeng.

Comment on lines +951 to +954
epoch_attrs = l1b_dataset["epoch"].attrs.copy()
epoch_attrs["DELTA_MINUS_VAR"] = "epoch_delta_minus"
epoch_attrs["DELTA_PLUS_VAR"] = "epoch_delta_plus"
l1b_dataset["epoch"].attrs = epoch_attrs
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.

Is the copy() needed here? Is it not possible to just do:

l1b_dataset["epoch"].attrs["DELTA_MINUS_VAR"] = "epoch_delta_minus"
l1b_dataset["epoch"].attrs["DELTA_PLUS_VAR"] = "epoch_delta_plus"

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.

true!

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.

I tried but something going on. Can I implement this change in the upcoming PR?


# TODO: remove this addition once SAMMI or CDF attr manager handles this
# Update epoch attrs to add epoch_delta_plus and epoch_delta_minus
epoch_attrs = l1b_dataset["epoch"].attrs.copy()
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.

Same question about needing to copy and reassign the epoch attrs here.

Comment on lines +818 to +834
"energy_h": xr.DataArray(
l1b_dataset["energy_h"].values,
dims=("energy_h",),
attrs=cdf_attrs.get_variable_attributes("energy_h", check_schema=False),
),
"energy_h_label": xr.DataArray(
l1b_dataset["energy_h"].values.astype(str),
dims=("energy_h",),
attrs=cdf_attrs.get_variable_attributes(
"energy_h_label", check_schema=False
),
),
"energy_he3": l1b_dataset["energy_he3"],
"energy_he3": xr.DataArray(
l1b_dataset["energy_he3"].values,
dims=("energy_he3",),
attrs=cdf_attrs.get_variable_attributes("energy_he3", check_schema=False),
),
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.

Lots of repeated code here. I wonder if it would be possible to do something like:

for coord in LIST_OF_COORDS:
    new_coords[coord] = xr.DataArray(
        l1b_dataset[coord].values,
        dims=(coord,),
        attrs=cdf_attrs.get_variable_attributes(coord, check_schema=False),
    )

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.

I am going to make this change in upcoming PR. Really good suggestion!

VALIDMAX: 16777216.0
VALIDMIN: 0.0
DICT_KEY: SPASE>Particle>ParticleType:Ion,ParticleQuantity:NumberFlux,Qualifier:Differential
CATDESC: c (Root 2 spacing)
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.

Just a comment but not needed for this PR - It might be worth considering a more descriptive CATDESC for the particle variables. HIT L2 attrs have some examples of more descriptive strings for this field.

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.

I hoping to get minimal changes needed for CAVA today to unblock scientist. But I plan to go back and do more thorough updates for CoDICE L2. I will keep this in mind!

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.

I hoping to get minimal changes needed for CAVA today to unblock scientist. But I plan to go back and do more thorough updates for CoDICE L2. I will keep this in mind!

👍 Once the CoDICE team can look at the data in CAVA I think they can give much better feedback on the metadata...otherwise it's hard to tell the CATDESC from the FIELDNAM from the LABLAXIS.

@tech3371 tech3371 merged commit 28fec45 into IMAP-Science-Operations-Center:dev Mar 31, 2026
14 checks passed
@tech3371 tech3371 mentioned this pull request Mar 31, 2026
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CoDICE: CAVA metadata support

5 participants