SciTools / iris

A powerful, format-agnostic, and community-driven Python package for analysing and visualising Earth science data
https://scitools-iris.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
626 stars 283 forks source link

MeshCoord cannot compare with an 'equivalent' ordinary AuxCoord #4671

Open pp-mo opened 2 years ago

pp-mo commented 2 years ago

The definitive metadata of a MeshCoord is just mesh, location + axis.

These can be leniently compared with another one, e.g. to fetch the matching coord from a cube on a different mesh : For example...

>>> import  iris.tests.stock.mesh as ism
>>> cube1 = ism.sample_mesh_cube(mesh=ism.sample_mesh(n_nodes=10, n_faces=3, n_edges=0))
>>> cube2 = ism.sample_mesh_cube(mesh=ism.sample_mesh(n_nodes=10, n_faces=4, n_edges=0))
>>> co = cube1.coord('latitude')
>>> co
<MeshCoord: latitude / (unknown)  mesh(<Mesh object at 0x7ff8906fc580>) location(face)  [...]+bounds  shape(3,)>
>>> cube2.coord(co)
<MeshCoord: latitude / (unknown)  mesh(<Mesh object at 0x7ff8906cbdf0>) location(face)  [...]+bounds  shape(4,)>
>>> 

However, a MeshCoord can be "reduced" to an equivalent AuxCoord (i.e. with same names, units, points + bounds). This happens automatically when a cube is sub-indexed, e.g. "meshcube[..., 2]" or just "meshcube[..., 0:]". However, the AuxCoord can never "compare with" the original, since the metadata structure is too different. Hence, code analagous to the above won't work...

>>> import  iris.tests.stock.mesh as ism
>>> cube = ism.sample_mesh_cube()
>>> cube1 = ism.sample_mesh_cube()
>>> cube2 = cube1[..., 0:]
>>> co1 = cube1.coord('latitude')
>>> co1
<MeshCoord: latitude / (unknown)  mesh(<Mesh object at 0x7ff8906590a0>) location(face)  [...]+bounds  shape(3,)>
>>> co2 = cube2.coord('latitude')
>>> co2
<AuxCoord: latitude / (unknown)  [3200, 3201, 3202]+bounds  shape(3,)>
>>> cube2.coord(co1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/h05/itpp/git/iris/iris_main/lib/iris/cube.py", line 1919, in coord
    raise iris.exceptions.CoordinateNotFoundError(emsg)
iris.exceptions.CoordinateNotFoundError: "Expected to find exactly 1 'latitude' coordinate, but found none."
>>> 

I.E. you cannot find the "equivalent" coord in this way, when one is a MeshCoord and the other a 'normal' Coord. However, that does work for a "normal" cube, including finding matching coords of a different type i.e. DimCoord <-> AuxCoord.

This is likely to cause problems in some generic operations, e.g. regridding.

github-actions[bot] commented 1 year ago

In order to maintain a backlog of relevant issues, we automatically label them as stale after 500 days of inactivity.

If this issue is still important to you, then please comment on this issue and the stale label will be removed.

Otherwise this issue will be automatically closed in 28 days time.

trexfeathers commented 3 months ago

See #4751 and #5991