Skip to content

Commit d56824c

Browse files
authored
Meshcoord metadata follows face/edge coords where present. (#5020)
* Meshcoords take metadata from face/edge coords. * Test fixes. * Added tests for missing-vs-present standard-names and units. * Slight code tidying. * Review changes. * Added whatsnew.
1 parent fd241df commit d56824c

25 files changed

+366
-252
lines changed

docs/src/whatsnew/latest.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ This document explains the changes made to Iris for this release
3838
#. `@trexfeathers`_ and `Julian Heming`_ added new mappings between CF
3939
standard names and UK Met Office LBFC codes. (:pull:`4859`)
4040

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

4251
🐛 Bugs Fixed
4352
=============

lib/iris/experimental/ugrid/mesh.py

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,16 +2841,60 @@ def __init__(
28412841

28422842
# Get the 'coord identity' metadata from the relevant node-coordinate.
28432843
node_coord = self.mesh.coord(include_nodes=True, axis=self.axis)
2844+
node_metadict = node_coord.metadata._asdict()
2845+
# Use node metadata, unless location is face/edge.
2846+
use_metadict = node_metadict.copy()
2847+
if location != "node":
2848+
# Location is either "edge" or "face" - get the relevant coord.
2849+
kwargs = {f"include_{location}s": True, "axis": axis}
2850+
location_coord = self.mesh.coord(**kwargs)
2851+
2852+
# Take the MeshCoord metadata from the 'location' coord.
2853+
use_metadict = location_coord.metadata._asdict()
2854+
unit_unknown = Unit(None)
2855+
2856+
# N.B. at present, coords in a Mesh are stored+accessed by 'axis', which
2857+
# means they must have a standard_name. So ...
2858+
# (a) the 'location' (face/edge) coord *always* has a useable phenomenon
2859+
# identity.
2860+
# (b) we still want to check that location+node coords have the same
2861+
# phenomenon (i.e. physical meaning identity + units), **but** ...
2862+
# (c) we will accept/ignore some differences : not just "var_name", but
2863+
# also "long_name" *and* "attributes". So it is *only* "standard_name"
2864+
# and "units" that cause an error if they differ.
2865+
for key in ("standard_name", "units"):
2866+
bounds_value = use_metadict[key]
2867+
nodes_value = node_metadict[key]
2868+
if key == "units" and (
2869+
bounds_value == unit_unknown or nodes_value == unit_unknown
2870+
):
2871+
# Allow "any" unit to match no-units (for now)
2872+
continue
2873+
if bounds_value != nodes_value:
2874+
2875+
def fix_repr(val):
2876+
# Tidy values appearance by converting Unit to string, and
2877+
# wrapping strings in '', but leaving other types as a
2878+
# plain str() representation.
2879+
if isinstance(val, Unit):
2880+
val = str(val)
2881+
if isinstance(val, str):
2882+
val = repr(val)
2883+
return val
2884+
2885+
nodes_value, bounds_value = [
2886+
fix_repr(val) for val in (nodes_value, bounds_value)
2887+
]
2888+
msg = (
2889+
f"Node coordinate {node_coord!r} disagrees with the "
2890+
f"{location} coordinate {location_coord!r}, "
2891+
f'in having a "{key}" value of {nodes_value} '
2892+
f"instead of {bounds_value}."
2893+
)
2894+
raise ValueError(msg)
2895+
28442896
# Call parent constructor to handle the common constructor args.
2845-
super().__init__(
2846-
points,
2847-
bounds=bounds,
2848-
standard_name=node_coord.standard_name,
2849-
long_name=node_coord.long_name,
2850-
var_name=None, # We *don't* "represent" the underlying node var
2851-
units=node_coord.units,
2852-
attributes=node_coord.attributes,
2853-
)
2897+
super().__init__(points, bounds=bounds, **use_metadict)
28542898

28552899
# Define accessors for MeshCoord-specific properties mesh/location/axis.
28562900
# These are all read-only.

lib/iris/tests/results/experimental/ugrid/2D_1t_face_half_levels.cml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
...,
2121
[-42.7342, -40.8934, -46.161, -48.912],
2222
[-40.8934, -38.4268, -42.6612, -46.161],
23-
[-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,
24-
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32"/>
23+
[-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,
24+
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_y"/>
2525
</coord>
2626
<coord datadims="[1]">
2727
<meshCoord bounds="[[-45.0, -37.5, -37.5, -45.0],
@@ -30,8 +30,8 @@
3030
...,
3131
[-112.5, -120.0, -126.958, -118.361],
3232
[-120.0, -127.5, -135.0, -126.958],
33-
[-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,
34-
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32"/>
33+
[-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,
34+
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_x"/>
3535
</coord>
3636
<coord datadims="[0]">
3737
<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">

lib/iris/tests/results/experimental/ugrid/2D_72t_face_half_levels.cml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
...,
2121
[-42.7342, -40.8934, -46.161, -48.912],
2222
[-40.8934, -38.4268, -42.6612, -46.161],
23-
[-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,
24-
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32"/>
23+
[-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,
24+
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_y"/>
2525
</coord>
2626
<coord datadims="[1]">
2727
<meshCoord bounds="[[-45.0, -37.5, -37.5, -45.0],
@@ -30,8 +30,8 @@
3030
...,
3131
[-112.5, -120.0, -126.958, -118.361],
3232
[-120.0, -127.5, -135.0, -126.958],
33-
[-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,
34-
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32"/>
33+
[-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,
34+
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_x"/>
3535
</coord>
3636
<coord datadims="[0]">
3737
<auxCoord bounds="[[300.0, 300.0],

lib/iris/tests/results/experimental/ugrid/3D_1t_face_full_levels.cml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
...,
3232
[-42.7342, -40.8934, -46.161, -48.912],
3333
[-40.8934, -38.4268, -42.6612, -46.161],
34-
[-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,
35-
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32"/>
34+
[-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,
35+
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_full_levels_face_y"/>
3636
</coord>
3737
<coord datadims="[2]">
3838
<meshCoord bounds="[[-45.0, -37.5, -37.5, -45.0],
@@ -41,8 +41,8 @@
4141
...,
4242
[-112.5, -120.0, -126.958, -118.361],
4343
[-120.0, -127.5, -135.0, -126.958],
44-
[-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,
45-
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32"/>
44+
[-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,
45+
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_full_levels_face_x"/>
4646
</coord>
4747
<coord datadims="[0]">
4848
<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">

lib/iris/tests/results/experimental/ugrid/3D_1t_face_half_levels.cml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
...,
3232
[-42.7342, -40.8934, -46.161, -48.912],
3333
[-40.8934, -38.4268, -42.6612, -46.161],
34-
[-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,
35-
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32"/>
34+
[-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,
35+
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_y"/>
3636
</coord>
3737
<coord datadims="[2]">
3838
<meshCoord bounds="[[-45.0, -37.5, -37.5, -45.0],
@@ -41,8 +41,8 @@
4141
...,
4242
[-112.5, -120.0, -126.958, -118.361],
4343
[-120.0, -127.5, -135.0, -126.958],
44-
[-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,
45-
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32"/>
44+
[-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,
45+
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_x"/>
4646
</coord>
4747
<coord datadims="[0]">
4848
<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">

lib/iris/tests/results/experimental/ugrid/3D_snow_pseudo_levels.cml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
...,
2121
[-42.7342, -40.8934, -46.161, -48.912],
2222
[-40.8934, -38.4268, -42.6612, -46.161],
23-
[-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,
24-
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32"/>
23+
[-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,
24+
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_y"/>
2525
</coord>
2626
<coord datadims="[2]">
2727
<meshCoord bounds="[[-45.0, -37.5, -37.5, -45.0],
@@ -30,8 +30,8 @@
3030
...,
3131
[-112.5, -120.0, -126.958, -118.361],
3232
[-120.0, -127.5, -135.0, -126.958],
33-
[-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,
34-
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32"/>
33+
[-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,
34+
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_x"/>
3535
</coord>
3636
<coord datadims="[0]">
3737
<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">

lib/iris/tests/results/experimental/ugrid/3D_soil_pseudo_levels.cml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
...,
2121
[-42.7342, -40.8934, -46.161, -48.912],
2222
[-40.8934, -38.4268, -42.6612, -46.161],
23-
[-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,
24-
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32"/>
23+
[-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,
24+
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_y"/>
2525
</coord>
2626
<coord datadims="[2]">
2727
<meshCoord bounds="[[-45.0, -37.5, -37.5, -45.0],
@@ -30,8 +30,8 @@
3030
...,
3131
[-112.5, -120.0, -126.958, -118.361],
3232
[-120.0, -127.5, -135.0, -126.958],
33-
[-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,
34-
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32"/>
33+
[-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,
34+
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_x"/>
3535
</coord>
3636
<coord datadims="[0]">
3737
<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">

lib/iris/tests/results/experimental/ugrid/3D_tile_pseudo_levels.cml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
...,
2121
[-42.7342, -40.8934, -46.161, -48.912],
2222
[-40.8934, -38.4268, -42.6612, -46.161],
23-
[-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,
24-
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32"/>
23+
[-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,
24+
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_y"/>
2525
</coord>
2626
<coord datadims="[2]">
2727
<meshCoord bounds="[[-45.0, -37.5, -37.5, -45.0],
@@ -30,8 +30,8 @@
3030
...,
3131
[-112.5, -120.0, -126.958, -118.361],
3232
[-120.0, -127.5, -135.0, -126.958],
33-
[-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,
34-
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32"/>
33+
[-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,
34+
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_x"/>
3535
</coord>
3636
<coord datadims="[0]">
3737
<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">

lib/iris/tests/results/experimental/ugrid/3D_veg_pseudo_levels.cml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
...,
2121
[-42.7342, -40.8934, -46.161, -48.912],
2222
[-40.8934, -38.4268, -42.6612, -46.161],
23-
[-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,
24-
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32"/>
23+
[-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,
24+
-42.1583, -38.815]" shape="(864,)" standard_name="latitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_y"/>
2525
</coord>
2626
<coord datadims="[2]">
2727
<meshCoord bounds="[[-45.0, -37.5, -37.5, -45.0],
@@ -30,8 +30,8 @@
3030
...,
3131
[-112.5, -120.0, -126.958, -118.361],
3232
[-120.0, -127.5, -135.0, -126.958],
33-
[-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,
34-
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32"/>
33+
[-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,
34+
-127.321, -135.0]" shape="(864,)" standard_name="longitude" units="Unit('degrees')" value_type="float32" var_name="Mesh2d_half_levels_face_x"/>
3535
</coord>
3636
<coord datadims="[0]">
3737
<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">

0 commit comments

Comments
 (0)