Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT: Cdflib update #991

Merged
merged 8 commits into from
Oct 11, 2024

Conversation

tech3371
Copy link
Contributor

@tech3371 tech3371 commented Oct 8, 2024

Change Summary

closes #606

Overview

Updated cdflib to it's latest version. Made changes where I can but some was outside of what I can do. For those, I marked pytest to skip and need to address in future PR.

Updated Files

Instruments updated

  • CoDICE
    • removed label axis because many of variable using the default has more than one dimension. As a result, it would error because ISTP doesn't allow to set both label axis and PTR label.
    • skipped few tests because sample data was not increasing monotonically.
  • GLOWS
    • added changes to include LABL_PTR_1
  • IMAP-Hi
    • added changes to include LABL_PTR_1
  • MAG
    • added changes to include LABL_PTR_1
  • SWE
    • removed label axis because ISTP doesn't allow to set both label axis and PTR label.
  • imap_processing/cdf/config/shared/default_variable_cdf_attrs_schema.yaml
    • set some of attrs's required to false because some those are only required for epoch variable and not other data type. Also, LABLAXIS is not required if 'LABL_PTR_iis set. These will be taken care of insammi`. Changes I made is temporary fixes.

Testing

I had to skip few tests due to data not increasing monotonically. I will create issue for those that needs update.

@tech3371 tech3371 added bug Something isn't working enhancement New feature or request CDF Related to CDF files labels Oct 8, 2024
@tech3371 tech3371 self-assigned this Oct 8, 2024
Copy link
Contributor

@maxinelasp maxinelasp left a comment

Choose a reason for hiding this comment

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

Why doesn't LABLAXIS work here? Is that an error out of cdflib? Overall it looks good to me, I'm just wondering why LABLAXIS doesn't work...

@tech3371
Copy link
Contributor Author

tech3371 commented Oct 8, 2024

Why doesn't LABLAXIS work here? Is that an error out of cdflib? Overall it looks good to me, I'm just wondering why LABLAXIS doesn't work...

@maxinelasp There is two parts to this. If schema defines a required field, it will add that and fill it with empty string even if we don't include it our own YAML file. This happens from this line. Since ISTP doesn't allow to set both LABLAXIS and LABL_PTR_i, cdflib will complain that we had set LABLAXIS and LABL_PTR_i even though user didn't but schema did.

@@ -89,6 +89,7 @@ def test_l1a_data(request) -> xr.Dataset:
return dataset


@pytest.mark.xfail(reason="Epoch variable data needs to monotonically increase")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created new issue to capture this #992

@@ -167,6 +169,7 @@ def test_l1a_data_array_values(test_l1a_data: xr.Dataset, validation_data: Path)
)


@pytest.mark.xfail(reason="Epoch variable data needs to monotonically increase")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

captured this work in #993

@maxinelasp
Copy link
Contributor

But, if we mark both as required: false then do we need to update the yaml files? I thought that was the only change needed.

@tech3371
Copy link
Contributor Author

tech3371 commented Oct 8, 2024

But, if we mark both as required: false then do we need to update the yaml files? I thought that was the only change needed.

Copy of Slack conversation in case someone is wondering same thing.

(Tenzin) If I understand what you are thinking, are you thinking that we set both false and then update our own attrs YAML to include LABLAXIS or LABL_PTR_i? If so, yes. That’s what I did in that PR with data variable who had more than one dimensions. cdflib requires to add LABL_PTR_i for data variable who had more than one dimension. Therefore, I had to make those additional changes to be ISTP compliant. For 2d or higher dimension data, we remove LABLAXIS and replace with LABL_PTR_i.

Copy link
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.

Thanks for taking this on! I have a couple of nit picks for Hi changes. One thing that we should make consistent across all instruments is that label variables should be variables, not coordinates. It would make sense to put that in it's own PR.

For my Hi nits, I am happy to make a commit with the changes since they are purely stylistic things.

@@ -108,6 +108,13 @@ def allocate_histogram_dataset(num_packets: int) -> xr.Dataset:
dims=["angle"],
attrs=attr_mgr.get_variable_attributes("hi_hist_angle"),
)
coords["angle_label"] = xr.DataArray(
Copy link
Contributor

Choose a reason for hiding this comment

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

Label variables should not be added to the coordinates list. They are just variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This LABL_PTR_i confused me a lot. Changes in this file and XML file is related to that. This is something SPDF and ISTP caused. When your data has great than 1D array, it requires to have label for each DEPEND_1 and onward. And we need to create xr.DataArray for those labels and need to add those to coordinate, otherwise cdflib will throw error.

FAILED imap_processing/tests/hi/test_l1a.py::test_app_hist_decom - cdflib.xarray.xarray_to_cdf.ISTPError: ISTP Compliance Warning: variable qual_ab listed angle_label as its LABL_PTR_1.  However, it was not found in the dataset.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
coords["angle_label"] = xr.DataArray(
data_vars["angle_label"] = xr.DataArray(

I think that is what @subagonsouth is suggesting. cdflib fails with that as well? Coordinates should be optional, so this might be an issue to raise with cdflib.

Copy link
Contributor Author

@tech3371 tech3371 Oct 11, 2024

Choose a reason for hiding this comment

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

moving this to data variable. I will refactor other instrument's label in new PR. I do want to point out that other past mission did store their coordinate label in coordinate as well. I wonder if they did that to be able to select and filter data easier later on. That's something we should think about. I will check with Andriy first before I refactor other instrument.

imap_processing/cdf/config/imap_hi_variable_attrs.yaml Outdated Show resolved Hide resolved
imap_processing/hi/l1a/histogram.py Outdated Show resolved Hide resolved
@tech3371 tech3371 changed the title Cdflib update MNT: Cdflib update Oct 10, 2024
Copy link
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.

Thanks for doing this!

@@ -62,6 +63,9 @@ def test_app_nhk_decom(hi_l0_test_data_path):
assert cem_raw_cdf_filepath.name == "imap_hi_l1a_45sensor-hk_20100313_v001.cdf"


@pytest.mark.skip(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

captured this work in #1009

@tech3371 tech3371 merged commit 01d3464 into IMAP-Science-Operations-Center:dev Oct 11, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working CDF Related to CDF files enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Update cdflib version
4 participants