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

Normalise units of coordinate bounds #5746

Merged
merged 7 commits into from Feb 16, 2024

Conversation

bjlittle
Copy link
Member

@bjlittle bjlittle commented Feb 15, 2024

🚀 Pull Request

Description

This pull request ensures that during the NetCDF loading pipeline, coordinates are constructed with points and bounds equal to the units of the points.

This is to resolve the issue where coordinates can be constructed and attached to a cube, but the units of the points and bounds of the coordinate are encoded differently within the source NetCDF file.

The following cases are handled:

  1. Bounds that have invalid units i.e., not recognised by cf-units, will result in a warning being raised and the bounds attached "as-is" to the coordinate. This provides the user to option to keep, remove or replace the bounds as they choose.
  2. Bounds with units that are different but convertible to the units of the points will be automatically converted to the units of the points.
  3. Bounds with units that are different and not convertible to the units of the points will result in a warning being raised and the bounds being ignored i.e., not attached to the coordinate.
  4. Bounds with no associated NetCDF metadata specifying their units will be assumed to have the same units of the points i.e., they will be attached to the coordinate "as-is".

Note that, the test_build_auxiliary_coordinate.TestBoundsVertexDim and test_build_dimension_coordinate.TestBoundsVertexDim tests have been extended to include test coverage of converting bounds to the units of the points, [2] above. This is to avoid heavy replication of boiler-plate mocking infrastructure.

TODO:

  • Add whatsnew entry.

Finally, this one's for you @andreas-h.

Closes #1801


Consult Iris pull request check list

@bjlittle bjlittle changed the title Normalise coordinate bounds units Normalise units of coordinate bounds Feb 15, 2024
Copy link

codecov bot commented Feb 15, 2024

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (a47fd34) 89.71% compared to head (35a629f) 89.74%.
Report is 14 commits behind head on main.

Files Patch % Lines
lib/iris/fileformats/_nc_load_rules/helpers.py 80.95% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5746      +/-   ##
==========================================
+ Coverage   89.71%   89.74%   +0.02%     
==========================================
  Files          90       91       +1     
  Lines       22815    22925     +110     
  Branches     5438     5462      +24     
==========================================
+ Hits        20468    20573     +105     
- Misses       1617     1620       +3     
- Partials      730      732       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@trexfeathers
Copy link
Contributor

Finally, this one's for you @andreas-h.

Copy link
Contributor

@stephenworsley stephenworsley left a comment

Choose a reason for hiding this comment

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

Looks good, just a small suggestion about warnings. This is a warning that already existed, so there may be a case for seperating it out into its own issue if changing it impacts a lot of the existing tests.

Copy link
Contributor

@stephenworsley stephenworsley left a comment

Choose a reason for hiding this comment

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

Looks good

@stephenworsley stephenworsley merged commit 63b44f0 into SciTools:main Feb 16, 2024
17 checks passed
@bjlittle
Copy link
Member Author

andreas_hilboll
“Andreas Hilboll” Scholarship for researchers

tkknight added a commit to tkknight/iris that referenced this pull request Feb 20, 2024
…umpydoc-pre-commit

* 'numpydoc-pre-commit' of github.com:tkknight/iris:
  Update CF standard names to v84. (SciTools#5761)
  Regrid docs fix (SciTools#5758)
  Improve ncdata and CF information on "iris heart xarray" page (SciTools#5752)
  Pin ASV - airspeed-velocity/asv#1385. (SciTools#5756)
  Normalise units of coordinate bounds (SciTools#5746)
  Add "Which Regridder?" Documentation (SciTools#5742)
  Document `Coord.ignore_axis` (SciTools#5744)
  Disable navidation with keys for docs HTML theme options (SciTools#5747)
  Shapefile masking (SciTools#5470)
  [pre-commit.ci] pre-commit autoupdate (SciTools#5739)
  DOCS: Add whatsnew for ruff pydocstyle compliance (SciTools#5700)
  update docstring (SciTools#5737)
  Updated environment lockfiles (SciTools#5738)
  Consider NaNs equal when comparing cubes (SciTools#5713)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏁 Done
Development

Successfully merging this pull request may close these issues.

loading cubes with differing units for time and time_bounds
3 participants