Skip to content

Redirect ALL un-loadable NetCDF objects to LOAD_PROBLEMS #6465

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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

trexfeathers
Copy link
Contributor

@trexfeathers trexfeathers commented May 13, 2025

🚀 Pull Request

Description

Closes #6319

Objects

  • Auxiliary coordinates
  • Introduce LoadProblems.Problem.handled flag
  • Introduce LoadProblems.Problem.destination attribute, for maximum context
  • Refactor existing changes to capture objects being added to non-Cube objects too
  • Cube units
  • Cell methods
  • Cube attributes
  • Coordinate systems
  • Cell measures
  • Ancillary variables
  • Mesh content

Consult Iris pull request check list


Add any of the below labels to trigger actions on this PR:

  • benchmark_this Request that this pull request be benchmarked to check if it introduces performance shifts

Copy link

codecov bot commented May 13, 2025

Codecov Report

Attention: Patch coverage is 98.34254% with 3 lines in your changes missing coverage. Please review.

Project coverage is 89.86%. Comparing base (16c6a33) to head (5716e53).
Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
lib/iris/fileformats/_nc_load_rules/helpers.py 97.22% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6465      +/-   ##
==========================================
+ Coverage   89.80%   89.86%   +0.05%     
==========================================
  Files          90       90              
  Lines       23755    23866     +111     
  Branches     4418     4434      +16     
==========================================
+ Hits        21334    21447     +113     
+ Misses       1672     1669       -3     
- Partials      749      750       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -48,7 +48,7 @@
<dimCoord id="62e940e0" points="[10, 20, 30]" shape="(3,)" standard_name="longitude" units="Unit('degrees')" value_type="int32" var_name="lon"/>
</coord>
<coord datadims="[0]">
<auxCoord id="cb784457" points="[ 1, 100, 3]" shape="(3,)" standard_name="time" units="Unit('hours since 1970-01-01 00:00:00', calendar='standard')" value_type="int32" var_name="time3"/>
<auxCoord id="cb784457" points="[ 1, --, 3]" shape="(3,)" standard_name="time" units="Unit('hours since 1970-01-01 00:00:00', calendar='standard')" value_type="int32" var_name="time3"/>
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 may look like I'm just changing the test to suit me! But I believe my changes have actually improved how Iris works. Our previous graceful fallback on to AuxCoord involved using the DimCoord arguments for AuxCoord creation - so no masking - whereas we are now fully retrying the whole process if DimCoord fails.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is good, but see comment above.

problem.stack_trace.__notes__ = stack_notes
problem.handled = True

_ = _add_or_capture(
Copy link
Contributor

Choose a reason for hiding this comment

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

This changes the behaviour slightly (as shown by your test) as the potentially masked array of point data is no longer "Gracefully filled" (line 1294ish). I think it is a good thing that masked data is retained in the AuxCoord, but maybe worth highlighting in the release notes as it might break some downstream tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -1554,25 +1552,15 @@ def build_and_add_auxiliary_coordinate(


################################################################################
def build_cell_measures(engine, cf_cm_var):
"""Create a CellMeasure instance and add it to the cube."""
Copy link
Contributor

@ukmo-ccbunney ukmo-ccbunney May 28, 2025

Choose a reason for hiding this comment

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

Is it normal to ditch the docscting when making a method private?
Is it not still useful? Should it not be kept as a comment (#) perhaps?

Edit: I know they are not necessary for private methods, but we did have one, now we don't...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a little unclear since this is in a private module too. I have now gone for short docstrings in the build_and_add_ functions, but no docstrings in the _build or _add 'sub-functions'.

816a114

# Calculate the offset of each common dimension.
data_dims = [cf_var.dimensions.index(dim) for dim in common_dims]
# TODO: go the whole way and remove the 2nd parameter from _get_cf_var_data?
data = _get_cf_var_data(cf_cm_var, cf_cm_var.filename)
Copy link
Contributor

@ukmo-ccbunney ukmo-ccbunney May 28, 2025

Choose a reason for hiding this comment

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

# TODO: go the whole way and remove the 2nd parameter from _get_cf_var_data?
It would be more consistent with other changes you've made w.r.t. explicitly passing in filename...
Could be raised as a separate issue to keep changes to this PR minimal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +1353 to +1364
_ = _add_or_capture(
build_func=partial(lambda: coord_system),
add_method=partial(setattr, coord, "coord_system"),
# cf_var is usually the variable for the thing we are building.
# In this case coord_system was built earlier; cf_coord_var is here
# only to provide the filename.
cf_var=cf_coord_var,
destination=LoadProblems.Problem.Destination(
iris_class=iris.coords.DimCoord,
identifier=coord.var_name,
),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth commenting here that this is the "add" part of what is usually a single call to _add_or_capture and is related to the _add_or_capture call in actions.py:action_provides_grid_mapping (assuming I've understood this correctly).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

climatological=climatological,
)

assert coord.var_name is not None
_ = _add_or_capture(
Copy link
Contributor

Choose a reason for hiding this comment

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

And similarly here (see above comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -373,8 +373,12 @@ def test_missing_latlon_radius(self):
# One of very few cases where activation may encounter an error.
# N.B. doesn't really test rules-activation, but maybe worth doing.
# (no rules trigger)
with self.assertRaisesRegex(ValueError, "No ellipsoid"):
self.run_testcase(mapping_missingradius=True)
# with self.assertRaisesRegex(ValueError, "No ellipsoid"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete commented out line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@ukmo-ccbunney ukmo-ccbunney left a comment

Choose a reason for hiding this comment

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

Hey @trexfeathers
I've reviewed up to commit 8887c69 (Cell methods) and other than a few minor comments I think this is looking ace so far. 👍

Copy link
Contributor

@scitools-ci scitools-ci bot left a comment

Choose a reason for hiding this comment

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

@trexfeathers trexfeathers marked this pull request as ready for review May 30, 2025 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
benchmark_this Request that this pull request be benchmarked to check if it introduces performance shifts Feature: NetCDF + CF-conventions Release: Minor Type: Enhancement
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Capture ALL un-loadable NetCDF objects
2 participants