iris icon indicating copy to clipboard operation
iris copied to clipboard

Can't collapse mesh

Open bblay opened this issue 1 year ago • 3 comments

🐛 Bug Report

It's not possible to collapse a mesh cube. There's an error as it tries to collapse the mesh coord.

    return newcube.collapsed(coords, aggregator, **aggkeys)
  File "/home/h02/bblay/.conda/envs/autoassess_new/lib/python3.10/site-packages/iris/cube.py", line 3904, in collapsed
    collapsed_cube.replace_coord(coord.collapsed(local_dims))
  File "/home/h02/bblay/.conda/envs/autoassess_new/lib/python3.10/site-packages/iris/coords.py", line 2284, in collapsed
    coord = self.copy(points=points, bounds=bounds)
  File "/home/h02/bblay/.conda/envs/autoassess_new/lib/python3.10/site-packages/iris/experimental/ugrid/mesh.py", line 2973, in copy
    raise ValueError(msg)
ValueError: Cannot change the content of a MeshCoord.

@pp-mo suggests, "I think this is probably a little bug introduced because MeshCoords are "like" AuxCoords but a bit different.", and also suggests a workaround is to remove the mesh coords, "You need to index the cube on the mesh dimension, with something other than ':' or 'slice(None)'." e.g with cube[..., 0:] or cube[tuple(slice(0, None) for _ in cube.shape)]).

Environment

  • Iris Version: 3.6

bblay avatar Jul 13 '23 09:07 bblay

Thamks for raising @bblay! For the future developer looking at this: do you have an easy way to reproduce the above stack trace? We have some sample 'mesh Cubes' somewhere in iris.tests.stock.

trexfeathers avatar Jul 19 '23 09:07 trexfeathers

I've encountered the same issue, I'm trying to compare something UM and LFRic and its nice and easy to do a weighted average on a regular cube:

grid_areas = iris.analysis.cartography.area_weights(um_in_cube)

um_in_cube_mean = um_in_cube.collapsed(['longitude', 'latitude'], iris.analysis.MEAN, weights=grid_areas)

But not as easy (if not just impossible) to do in LFRic mesh world!

rsdavies avatar Nov 06 '23 14:11 rsdavies

Yup, we need to make this easier out the box for the community to use 👍

bjlittle avatar Nov 06 '23 14:11 bjlittle