Skip to content

Update MeshXY's .filters method to work with coordinates that do not have a standard name and allow the mesh to be saved#7185

Merged
pp-mo merged 25 commits into
SciTools:mainfrom
pt331:no-standard-name-mesh-errors
Jul 9, 2026
Merged

Update MeshXY's .filters method to work with coordinates that do not have a standard name and allow the mesh to be saved#7185
pp-mo merged 25 commits into
SciTools:mainfrom
pt331:no-standard-name-mesh-errors

Conversation

@pt331

@pt331 pt331 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Description

closes #4863

In investgating the issue, we found that when saving a Mesh and converting them to MeshCoords had root a root problem in Mesh.filters(), where it was ultimately trying to guess the coord's axis, which relies on the standard_name.

This pull request addresses the issue by adding mesh_filters, which directly pulls the coordinates out of the mesh, without needing to consider their names. The construction of the mesh already gave us the information needed to do this. The original filters function calls mesh_filters before sending it to the metadata_filter like before, but removing the axis from the call because it is already accounted for.

To make the filter slightly more intelligent and to avoid the hasattr(self, "face_coords") line, _Mesh2DCoordinateManager implements its own mesh_filters to deal with face coordinates separately. It also gave the added benefit of raising a ValueError specific to the _Mesh1DCoordinateManager case, where it mentions that it only expects node and edge locations (not face). This also results in a slight change in behaviour, which is now reflected in the tests.

In the case for saving coordinates without a standard_name, we decided that naming it as "unknown" should be suffice, like what is done for cubes. In the case of using ncdump with the MWE:

ncdump -h ~/mesh_new.nc 
netcdf mesh_new {
dimensions:
        Mesh2d_node = 3 ;
        Mesh2d_face = 1 ;
        Mesh_2d_face_N_nodes = 3 ;
variables:
        int Mesh_2d ;
                Mesh_2d:cf_role = "mesh_topology" ;
                Mesh_2d:topology_dimension = 2 ;
                Mesh_2d:node_coordinates = "unknown unknown_0" ;
                Mesh_2d:face_coordinates = "unknown_1 unknown_2" ;
                Mesh_2d:face_node_connectivity = "mesh2d_face" ;
        int64 unknown(Mesh2d_node) ;
        int64 unknown_0(Mesh2d_node) ;
        int64 unknown_1(Mesh2d_face) ;
        int64 unknown_2(Mesh2d_face) ;
        int64 mesh2d_face(Mesh2d_face, Mesh_2d_face_N_nodes) ;
                mesh2d_face:cf_role = "face_node_connectivity" ;
                mesh2d_face:start_index = 0LL ;

// global attributes:
                :Conventions = "CF-1.7" ;
}

There may be some way to give a more meaningful name, but it will involve making assumptions which may not apply to everyone.

I have tried my hand at adding types as I go along, but most areas are beyond my knowledge and needed input from the team.

Checklist

Important

The Iris core developers are here to help! If anything below is unclear, just post a comment asking for help 😊


Tip

Things you can trigger on this PR:

  • Add this label to trigger benchmarks: benchmark_this Request that this pull request be benchmarked to check if it introduces performance shifts
  • Visit this URL - swapping 9999 for this PR's number - to re-trigger the CLA check:
    https://cla-assistant.io/check/SciTools/iris?pullRequest=9999

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.16%. Comparing base (5d7ca14) to head (11d6072).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7185      +/-   ##
==========================================
+ Coverage   90.15%   90.16%   +0.01%     
==========================================
  Files          91       91              
  Lines       24990    25026      +36     
  Branches     4687     4695       +8     
==========================================
+ Hits        22529    22565      +36     
  Misses       1683     1683              
  Partials      778      778              

☔ View full report in Codecov by Harness.
📢 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.

@pt331 pt331 changed the title Fix MeshXY's .coords method Allow for saving Mesh dat that have coordinates without a standard-name MeshXY's .coords method Jul 3, 2026
@pt331 pt331 changed the title Allow for saving Mesh dat that have coordinates without a standard-name MeshXY's .coords method Allow for saving Mesh dat that have coordinates without a standard-name MeshXY's .filters method Jul 3, 2026
@pt331 pt331 changed the title Allow for saving Mesh dat that have coordinates without a standard-name MeshXY's .filters method Update MeshXY's .filters method to work with coordinates that do not have a standard name and allow the mesh to be saved Jul 3, 2026

@trexfeathers trexfeathers left a comment

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.

This looks lovely!

I imagine you're looking into the test failures. I don't know what to make of the docs failure though; I'll look into that.

Comment thread lib/iris/common/metadata.py
Comment thread lib/iris/common/metadata.py Outdated
Comment thread lib/iris/common/metadata.py Outdated
Comment thread lib/iris/mesh/components.py Outdated
Comment thread lib/iris/mesh/components.py Outdated
Comment thread lib/iris/mesh/components.py Outdated
@trexfeathers

Copy link
Copy Markdown
Contributor

Explanation for the docs failure: #7191 (comment)

Our docs builds on Readthedocs are vulnerable because we have not yet managed to lock the dependency versions there - unlike all our tests, which is why the rest of the CI on this PR is still fine. See SciTools/workflows#38

Comment thread lib/iris/tests/unit/mesh/components/test_MeshXY.py Outdated
Comment thread lib/iris/tests/unit/mesh/components/test_MeshXY.py

@trexfeathers trexfeathers left a comment

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 have confirmed:

  • Benchmarks don't need updating
  • Documentation doesn't need updating

Comment thread lib/iris/__init__.py
Comment thread lib/iris/tests/unit/mesh/components/test_MeshXY.py Outdated
Comment thread lib/iris/mesh/components.py
Comment thread lib/iris/fileformats/netcdf/saver.py
Comment thread lib/iris/cube.py
@pt331 pt331 marked this pull request as ready for review July 8, 2026 14:03

@trexfeathers trexfeathers left a comment

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.

  • Type-checking adds plenty of imports, and we discovered yesterday that at least one new import might have been harming performance or introducing circularity. I've double-checked to confirm that this is all OK now 👍
  • The docs render nicely 👍
    • What's New entries
    • Type hints in public operations
  • Up to you want you want to happen with the remaining open conversation.

@pp-mo pp-mo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Discussed the test skip question with @pt331, and agreed to our satisfaction!
Rescanned the discussions. Checked the WhatsNew build reads OK.
All good for me!

@pp-mo pp-mo merged commit 39dd5eb into SciTools:main Jul 9, 2026
22 checks passed
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.

save_mesh and Mesh.to_MeshCoord fails with confusing errors when input coordinates do not have standard_name

3 participants