Closed
Description
🐛 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