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

If a face-coord in an unstructured cube has a non-None coordinate system, this breaks cube.copy() #5557

Open
pp-mo opened this issue Oct 30, 2023 · 0 comments 路 May be fixed by #6016
Open

If a face-coord in an unstructured cube has a non-None coordinate system, this breaks cube.copy() #5557

pp-mo opened this issue Oct 30, 2023 · 0 comments 路 May be fixed by #6016

Comments

@pp-mo
Copy link
Member

pp-mo commented Oct 30, 2023

馃悰 Bug Report

How To Reproduce

Minimal (non!-)working example :

>>> from iris.coord_systems import GeogCS
>>> from iris.tests.stock.mesh import sample_mesh_cube
>>> 
>>> cube = sample_mesh_cube()
>>> coord = cube.mesh.coords(include_faces=True)[0]
>>> coord.coord_system = GeogCS(1.0)
>>> cube2 = cube.copy()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/persistent/newconda-envs/own_antsdev/lib/python3.10/site-packages/iris/cube.py", line 3579, in copy
    cube = self._deepcopy(memo, data=data)
  File "/tmp/persistent/newconda-envs/own_antsdev/lib/python3.10/site-packages/iris/cube.py", line 3595, in _deepcopy
    new_aux_coords_and_dims = deepcopy(self._aux_coords_and_dims, memo)
  File "/tmp/persistent/newconda-envs/own_antsdev/lib/python3.10/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/tmp/persistent/newconda-envs/own_antsdev/lib/python3.10/copy.py", line 206, in _deepcopy_list
    append(deepcopy(a, memo))
  File "/tmp/persistent/newconda-envs/own_antsdev/lib/python3.10/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/tmp/persistent/newconda-envs/own_antsdev/lib/python3.10/copy.py", line 211, in _deepcopy_tuple
    y = [deepcopy(a, memo) for a in x]
  File "/tmp/persistent/newconda-envs/own_antsdev/lib/python3.10/copy.py", line 211, in <listcomp>
    y = [deepcopy(a, memo) for a in x]
  File "/tmp/persistent/newconda-envs/own_antsdev/lib/python3.10/copy.py", line 153, in deepcopy
    y = copier(memo)
  File "/tmp/persistent/newconda-envs/own_antsdev/lib/python3.10/site-packages/iris/experimental/ugrid/mesh.py", line 2991, in __deepcopy__
    return self.copy()
  File "/tmp/persistent/newconda-envs/own_antsdev/lib/python3.10/site-packages/iris/experimental/ugrid/mesh.py", line 2977, in copy
    new_coord = MeshCoord(
  File "/tmp/persistent/newconda-envs/own_antsdev/lib/python3.10/site-packages/iris/experimental/ugrid/mesh.py", line 2897, in __init__
    super().__init__(points, bounds=bounds, **use_metadict)
  File "/tmp/persistent/newconda-envs/own_antsdev/lib/python3.10/site-packages/iris/coords.py", line 2995, in __init__
    super().__init__(*args, **kwargs)
  File "/tmp/persistent/newconda-envs/own_antsdev/lib/python3.10/site-packages/iris/coords.py", line 1590, in __init__
    self.coord_system = coord_system
  File "/tmp/persistent/newconda-envs/own_antsdev/lib/python3.10/site-packages/iris/experimental/ugrid/mesh.py", line 2928, in coord_system
    raise ValueError(msg)
ValueError: Cannot set the coordinate-system of a MeshCoord.
>>> 

Expected behaviour

We should be able to assign a coordinate system to a coordinate in a mesh without breaking the copying of the cube.

From brief inspection, it seems that when the cube copies itself, it make new MeshCoords, and this fails because (somewhere) the mesh-facecoord coordinate metadata gets copied to the new MeshCoord, but that metadata includes a non-None mesh.

Environment

Iris 3.7.0, or latest main

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

Successfully merging a pull request may close this issue.

1 participant