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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't collapse mesh #5377

Closed
bblay opened this issue Jul 13, 2023 · 3 comments 路 Fixed by #6003
Closed

Can't collapse mesh #5377

bblay opened this issue Jul 13, 2023 · 3 comments 路 Fixed by #6003

Comments

@bblay
Copy link
Contributor

bblay commented Jul 13, 2023

馃悰 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
@trexfeathers
Copy link
Contributor

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.

@rsdavies
Copy link
Contributor

rsdavies commented Nov 6, 2023

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!

@bjlittle
Copy link
Member

bjlittle commented Nov 6, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants