CoDICE: Fixing attrs bugs for CAVA#2891
CoDICE: Fixing attrs bugs for CAVA#2891tech3371 merged 2 commits intoIMAP-Science-Operations-Center:devfrom
Conversation
|
@jtniehof pining you for awareness. |
There was a problem hiding this comment.
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_minuscoordinates 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.
imap_processing/cdf/config/imap_codice_l2-lo-species_variable_attrs.yaml
Show resolved
Hide resolved
imap_processing/cdf/config/imap_codice_l2-hi-sectored_variable_attrs.yaml
Show resolved
Hide resolved
subagonsouth
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I think the fix there is to change the type of the variable, as Tim suggested, not the fill (and the format).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
imap_processing/codice/codice_l2.py
Outdated
| 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 |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
I tried but something going on. Can I implement this change in the upcoming PR?
imap_processing/codice/codice_l2.py
Outdated
|
|
||
| # 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() |
There was a problem hiding this comment.
Same question about needing to copy and reassign the epoch attrs here.
| "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), | ||
| ), |
There was a problem hiding this comment.
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),
)
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
28fec45
into
IMAP-Science-Operations-Center:dev
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