Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ This document explains the changes made to Iris for this release
#. `@trexfeathers`_ and `Julian Heming`_ added new mappings between CF
standard names and UK Met Office LBFC codes. (:pull:`4859`)

#. `@pp-mo`_ changed the metadata of a face/edge-type
:class:`~iris.experimental.ugrid.mesh.MeshCoord`, to be same as the face/edge
coordinate in the mesh from which it takes its ``.points``. Previously, all MeshCoords
took their metadata from the node coord, but only a node-type MeshCoord now does
that. Also, the MeshCoord ``.var_name`` is now that of the underlying coord, whereas
previously this was always None. These changes make MeshCoord more like an ordinary
:class:`~iris.coords.AuxCoord`, which avoids some specific known usage problems.
(:issue:`4860`, :pull:`5020`)


🐛 Bugs Fixed
=============
Expand Down
62 changes: 53 additions & 9 deletions lib/iris/experimental/ugrid/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -2841,16 +2841,60 @@ def __init__(

# Get the 'coord identity' metadata from the relevant node-coordinate.
node_coord = self.mesh.coord(include_nodes=True, axis=self.axis)
node_metadict = node_coord.metadata._asdict()
# Use node metadata, unless location is face/edge.
use_metadict = node_metadict.copy()
if location != "node":
# Location is either "edge" or "face" - get the relevant coord.
kwargs = {f"include_{location}s": True, "axis": axis}
location_coord = self.mesh.coord(**kwargs)

# Take the MeshCoord metadata from the 'location' coord.
use_metadict = location_coord.metadata._asdict()
unit_unknown = Unit(None)

# N.B. at present, coords in a Mesh are stored+accessed by 'axis', which
# means they must have a standard_name. So ...
# (a) the 'location' (face/edge) coord *always* has a useable phenomenon
# identity.
# (b) we still want to check that location+node coords have the same
# phenomenon (i.e. physical meaning identity + units), **but** ...
# (c) we will accept/ignore some differences : not just "var_name", but
# also "long_name" *and* "attributes". So it is *only* "standard_name"
# and "units" that cause an error if they differ.
for key in ("standard_name", "units"):
bounds_value = use_metadict[key]
nodes_value = node_metadict[key]
if key == "units" and (
bounds_value == unit_unknown or nodes_value == unit_unknown
):
# Allow "any" unit to match no-units (for now)
continue
if bounds_value != nodes_value:

def fix_repr(val):
# Tidy values appearance by converting Unit to string, and
# wrapping strings in '', but leaving other types as a
# plain str() representation.
if isinstance(val, Unit):
val = str(val)
if isinstance(val, str):
val = repr(val)
return val

nodes_value, bounds_value = [
fix_repr(val) for val in (nodes_value, bounds_value)
]
msg = (
f"Node coordinate {node_coord!r} disagrees with the "
f"{location} coordinate {location_coord!r}, "
f'in having a "{key}" value of {nodes_value} '
f"instead of {bounds_value}."
)
raise ValueError(msg)

# Call parent constructor to handle the common constructor args.
super().__init__(
points,
bounds=bounds,
standard_name=node_coord.standard_name,
long_name=node_coord.long_name,
var_name=None, # We *don't* "represent" the underlying node var
units=node_coord.units,
attributes=node_coord.attributes,
)
super().__init__(points, bounds=bounds, **use_metadict)

# Define accessors for MeshCoord-specific properties mesh/location/axis.
# These are all read-only.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
...,
[-42.7342, -40.8934, -46.161, -48.912],
[-40.8934, -38.4268, -42.6612, -46.161],
[-38.4268, -35.2644, -38.4268, -42.6612]]" id="21594c35" long_name="Latitude of mesh nodes." points="[33.4328, 36.1226, 38.2012, ..., -44.791,
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32"/>
[-38.4268, -35.2644, -38.4268, -42.6612]]" id="72da1058" long_name="Characteristic latitude of mesh faces." points="[33.4328, 36.1226, 38.2012, ..., -44.791,
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_y"/>
</coord>
<coord datadims="[1]">
<meshCoord bounds="[[-45.0, -37.5, -37.5, -45.0],
Expand All @@ -30,8 +30,8 @@
...,
[-112.5, -120.0, -126.958, -118.361],
[-120.0, -127.5, -135.0, -126.958],
[-127.5, -135.0, -142.5, -135.0]]" id="fac9555b" long_name="Longitude of mesh nodes." points="[-41.3152, -33.8068, -26.296, ..., -119.377,
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32"/>
[-127.5, -135.0, -142.5, -135.0]]" id="b5c6bdeb" long_name="Characteristic longitude of mesh faces." points="[-41.3152, -33.8068, -26.296, ..., -119.377,
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_x"/>
</coord>
<coord datadims="[0]">
<auxCoord bounds="[[21600.0, 21600.0]]" id="17a27d05" long_name="Time axis" points="[21600.0]" shape="(1,)" standard_name="time" units="Unit('seconds since 2016-01-01 15:00:00', calendar='standard')" value_type="float64" var_name="time_instant">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
...,
[-42.7342, -40.8934, -46.161, -48.912],
[-40.8934, -38.4268, -42.6612, -46.161],
[-38.4268, -35.2644, -38.4268, -42.6612]]" id="21594c35" long_name="Latitude of mesh nodes." points="[33.4328, 36.1226, 38.2012, ..., -44.791,
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32"/>
[-38.4268, -35.2644, -38.4268, -42.6612]]" id="72da1058" long_name="Characteristic latitude of mesh faces." points="[33.4328, 36.1226, 38.2012, ..., -44.791,
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_y"/>
</coord>
<coord datadims="[1]">
<meshCoord bounds="[[-45.0, -37.5, -37.5, -45.0],
Expand All @@ -30,8 +30,8 @@
...,
[-112.5, -120.0, -126.958, -118.361],
[-120.0, -127.5, -135.0, -126.958],
[-127.5, -135.0, -142.5, -135.0]]" id="fac9555b" long_name="Longitude of mesh nodes." points="[-41.3152, -33.8068, -26.296, ..., -119.377,
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32"/>
[-127.5, -135.0, -142.5, -135.0]]" id="b5c6bdeb" long_name="Characteristic longitude of mesh faces." points="[-41.3152, -33.8068, -26.296, ..., -119.377,
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_x"/>
</coord>
<coord datadims="[0]">
<auxCoord bounds="[[300.0, 300.0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
...,
[-42.7342, -40.8934, -46.161, -48.912],
[-40.8934, -38.4268, -42.6612, -46.161],
[-38.4268, -35.2644, -38.4268, -42.6612]]" id="21594c35" long_name="Latitude of mesh nodes." points="[33.4328, 36.1226, 38.2012, ..., -44.791,
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32"/>
[-38.4268, -35.2644, -38.4268, -42.6612]]" id="72da1058" long_name="Characteristic latitude of mesh faces." points="[33.4328, 36.1226, 38.2012, ..., -44.791,
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_full_levels_face_y"/>
</coord>
<coord datadims="[2]">
<meshCoord bounds="[[-45.0, -37.5, -37.5, -45.0],
Expand All @@ -41,8 +41,8 @@
...,
[-112.5, -120.0, -126.958, -118.361],
[-120.0, -127.5, -135.0, -126.958],
[-127.5, -135.0, -142.5, -135.0]]" id="fac9555b" long_name="Longitude of mesh nodes." points="[-41.3152, -33.8068, -26.296, ..., -119.377,
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32"/>
[-127.5, -135.0, -142.5, -135.0]]" id="b5c6bdeb" long_name="Characteristic longitude of mesh faces." points="[-41.3152, -33.8068, -26.296, ..., -119.377,
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_full_levels_face_x"/>
</coord>
<coord datadims="[0]">
<auxCoord bounds="[[21600.0, 21600.0]]" id="17a27d05" long_name="Time axis" points="[21600.0]" shape="(1,)" standard_name="time" units="Unit('seconds since 2016-01-01 15:00:00', calendar='standard')" value_type="float64" var_name="time_instant">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
...,
[-42.7342, -40.8934, -46.161, -48.912],
[-40.8934, -38.4268, -42.6612, -46.161],
[-38.4268, -35.2644, -38.4268, -42.6612]]" id="21594c35" long_name="Latitude of mesh nodes." points="[33.4328, 36.1226, 38.2012, ..., -44.791,
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32"/>
[-38.4268, -35.2644, -38.4268, -42.6612]]" id="72da1058" long_name="Characteristic latitude of mesh faces." points="[33.4328, 36.1226, 38.2012, ..., -44.791,
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_y"/>
</coord>
<coord datadims="[2]">
<meshCoord bounds="[[-45.0, -37.5, -37.5, -45.0],
Expand All @@ -41,8 +41,8 @@
...,
[-112.5, -120.0, -126.958, -118.361],
[-120.0, -127.5, -135.0, -126.958],
[-127.5, -135.0, -142.5, -135.0]]" id="fac9555b" long_name="Longitude of mesh nodes." points="[-41.3152, -33.8068, -26.296, ..., -119.377,
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32"/>
[-127.5, -135.0, -142.5, -135.0]]" id="b5c6bdeb" long_name="Characteristic longitude of mesh faces." points="[-41.3152, -33.8068, -26.296, ..., -119.377,
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_x"/>
</coord>
<coord datadims="[0]">
<auxCoord bounds="[[21600.0, 21600.0]]" id="17a27d05" long_name="Time axis" points="[21600.0]" shape="(1,)" standard_name="time" units="Unit('seconds since 2016-01-01 15:00:00', calendar='standard')" value_type="float64" var_name="time_instant">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
...,
[-42.7342, -40.8934, -46.161, -48.912],
[-40.8934, -38.4268, -42.6612, -46.161],
[-38.4268, -35.2644, -38.4268, -42.6612]]" id="21594c35" long_name="Latitude of mesh nodes." points="[33.4328, 36.1226, 38.2012, ..., -44.791,
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32"/>
[-38.4268, -35.2644, -38.4268, -42.6612]]" id="72da1058" long_name="Characteristic latitude of mesh faces." points="[33.4328, 36.1226, 38.2012, ..., -44.791,
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_y"/>
</coord>
<coord datadims="[2]">
<meshCoord bounds="[[-45.0, -37.5, -37.5, -45.0],
Expand All @@ -30,8 +30,8 @@
...,
[-112.5, -120.0, -126.958, -118.361],
[-120.0, -127.5, -135.0, -126.958],
[-127.5, -135.0, -142.5, -135.0]]" id="fac9555b" long_name="Longitude of mesh nodes." points="[-41.3152, -33.8068, -26.296, ..., -119.377,
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32"/>
[-127.5, -135.0, -142.5, -135.0]]" id="b5c6bdeb" long_name="Characteristic longitude of mesh faces." points="[-41.3152, -33.8068, -26.296, ..., -119.377,
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_x"/>
</coord>
<coord datadims="[0]">
<auxCoord bounds="[[21600.0, 21600.0]]" id="17a27d05" long_name="Time axis" points="[21600.0]" shape="(1,)" standard_name="time" units="Unit('seconds since 2016-01-01 15:00:00', calendar='standard')" value_type="float64" var_name="time_instant">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
...,
[-42.7342, -40.8934, -46.161, -48.912],
[-40.8934, -38.4268, -42.6612, -46.161],
[-38.4268, -35.2644, -38.4268, -42.6612]]" id="21594c35" long_name="Latitude of mesh nodes." points="[33.4328, 36.1226, 38.2012, ..., -44.791,
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32"/>
[-38.4268, -35.2644, -38.4268, -42.6612]]" id="72da1058" long_name="Characteristic latitude of mesh faces." points="[33.4328, 36.1226, 38.2012, ..., -44.791,
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_y"/>
</coord>
<coord datadims="[2]">
<meshCoord bounds="[[-45.0, -37.5, -37.5, -45.0],
Expand All @@ -30,8 +30,8 @@
...,
[-112.5, -120.0, -126.958, -118.361],
[-120.0, -127.5, -135.0, -126.958],
[-127.5, -135.0, -142.5, -135.0]]" id="fac9555b" long_name="Longitude of mesh nodes." points="[-41.3152, -33.8068, -26.296, ..., -119.377,
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32"/>
[-127.5, -135.0, -142.5, -135.0]]" id="b5c6bdeb" long_name="Characteristic longitude of mesh faces." points="[-41.3152, -33.8068, -26.296, ..., -119.377,
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_x"/>
</coord>
<coord datadims="[0]">
<auxCoord bounds="[[21600.0, 21600.0]]" id="17a27d05" long_name="Time axis" points="[21600.0]" shape="(1,)" standard_name="time" units="Unit('seconds since 2016-01-01 15:00:00', calendar='standard')" value_type="float64" var_name="time_instant">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
...,
[-42.7342, -40.8934, -46.161, -48.912],
[-40.8934, -38.4268, -42.6612, -46.161],
[-38.4268, -35.2644, -38.4268, -42.6612]]" id="21594c35" long_name="Latitude of mesh nodes." points="[33.4328, 36.1226, 38.2012, ..., -44.791,
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32"/>
[-38.4268, -35.2644, -38.4268, -42.6612]]" id="72da1058" long_name="Characteristic latitude of mesh faces." points="[33.4328, 36.1226, 38.2012, ..., -44.791,
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_y"/>
</coord>
<coord datadims="[2]">
<meshCoord bounds="[[-45.0, -37.5, -37.5, -45.0],
Expand All @@ -30,8 +30,8 @@
...,
[-112.5, -120.0, -126.958, -118.361],
[-120.0, -127.5, -135.0, -126.958],
[-127.5, -135.0, -142.5, -135.0]]" id="fac9555b" long_name="Longitude of mesh nodes." points="[-41.3152, -33.8068, -26.296, ..., -119.377,
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32"/>
[-127.5, -135.0, -142.5, -135.0]]" id="b5c6bdeb" long_name="Characteristic longitude of mesh faces." points="[-41.3152, -33.8068, -26.296, ..., -119.377,
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_x"/>
</coord>
<coord datadims="[0]">
<auxCoord bounds="[[21600.0, 21600.0]]" id="17a27d05" long_name="Time axis" points="[21600.0]" shape="(1,)" standard_name="time" units="Unit('seconds since 2016-01-01 15:00:00', calendar='standard')" value_type="float64" var_name="time_instant">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
...,
[-42.7342, -40.8934, -46.161, -48.912],
[-40.8934, -38.4268, -42.6612, -46.161],
[-38.4268, -35.2644, -38.4268, -42.6612]]" id="21594c35" long_name="Latitude of mesh nodes." points="[33.4328, 36.1226, 38.2012, ..., -44.791,
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32"/>
[-38.4268, -35.2644, -38.4268, -42.6612]]" id="72da1058" long_name="Characteristic latitude of mesh faces." points="[33.4328, 36.1226, 38.2012, ..., -44.791,
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_y"/>
</coord>
<coord datadims="[2]">
<meshCoord bounds="[[-45.0, -37.5, -37.5, -45.0],
Expand All @@ -30,8 +30,8 @@
...,
[-112.5, -120.0, -126.958, -118.361],
[-120.0, -127.5, -135.0, -126.958],
[-127.5, -135.0, -142.5, -135.0]]" id="fac9555b" long_name="Longitude of mesh nodes." points="[-41.3152, -33.8068, -26.296, ..., -119.377,
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32"/>
[-127.5, -135.0, -142.5, -135.0]]" id="b5c6bdeb" long_name="Characteristic longitude of mesh faces." points="[-41.3152, -33.8068, -26.296, ..., -119.377,
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_x"/>
</coord>
<coord datadims="[0]">
<auxCoord bounds="[[21600.0, 21600.0]]" id="17a27d05" long_name="Time axis" points="[21600.0]" shape="(1,)" standard_name="time" units="Unit('seconds since 2016-01-01 15:00:00', calendar='standard')" value_type="float64" var_name="time_instant">
Expand Down
Loading