Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,44 @@ def _check_multi_dim_metadata(self, metadata, data_dims):

def _add_unique_aux_coord(self, coord, data_dims):
data_dims = self._check_multi_dim_metadata(coord, data_dims)
if hasattr(coord, "mesh"):
mesh = self.mesh()
if mesh:
msg = (
"{item} of Meshcoord {coord!r} is "
"{thisval!r}, which does not match existing "
"cube {item} of {ownval!r}."
)
if coord.mesh != mesh:
raise ValueError(
msg.format(
item="mesh",
coord=coord,
thisval=coord.mesh,
ownval=mesh,
)
)
location = self.location()
if coord.location != location:
raise ValueError(
msg.format(
item="location",
coord=coord,
thisval=coord.location,
ownval=location,
)
)
mesh_dims = (self.mesh_dim(),)
if data_dims != mesh_dims:
raise ValueError(
msg.format(
item="mesh dimension",
coord=coord,
thisval=data_dims,
ownval=mesh_dims,
)
)

self._aux_coords_and_dims.append((coord, data_dims))

def add_aux_factory(self, aux_factory):
Expand Down Expand Up @@ -1919,6 +1957,73 @@ def coord_system(self, spec=None):

return result

def _a_meshcoord(self):
Comment thread
bjlittle marked this conversation as resolved.
Outdated
mesh_coords = self.coords(mesh_coords=True)
if mesh_coords:
result = mesh_coords[0]
else:
result = None
return result

def mesh(self):
Comment thread
bjlittle marked this conversation as resolved.
"""
Return the unstructured :class:`~iris.experimental.ugrid.Mesh`
associated with the cube, if the cube has any
:class:`~iris.experimental.ugrid.MeshCoord`\\ s,
or ``None`` if it has none.

Returns:

* mesh (:class:`iris.experimental.ugrid.Mesh` or None):
The mesh of the cube
:class:`~iris.experimental.ugrid.MeshCoord`\\s,
or ``None``.

"""
result = self._a_meshcoord()
if result is not None:
result = result.mesh
return result

def location(self):
Comment thread
bjlittle marked this conversation as resolved.
"""
Return the mesh "location" of the cube data, if the cube has any
:class:`~iris.experimental.ugrid.MeshCoord`\\ s,
or ``None`` if it has none.

Returns:

* location (str or None):
The mesh location of the cube
:class:`~iris.experimental.ugrid.MeshCoord`\\s
(i.e. one of 'face' / 'edge' / 'node'),
or ``None``.

"""
result = self._a_meshcoord()
if result is not None:
result = result.location
return result

def mesh_dim(self):
Comment thread
pp-mo marked this conversation as resolved.
"""
Return the cube dimension of the mesh, if the cube has any
:class:`~iris.experimental.ugrid.MeshCoord`\\ s,
or ``None`` if it has none.

Returns:

* mesh_dim (int, or None):
the cube dimension which the cube
:class:`~iris.experimental.ugrid.MeshCoord`\\s map to,
or ``None``.

"""
result = self._a_meshcoord()
if result is not None:
(result,) = self.coord_dims(result) # result is a 1-tuple
return result

def cell_measures(self, name_or_cell_measure=None):
"""
Return a list of cell measures in this cube fitting the given criteria.
Expand Down
Loading