Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
55ae823
TopologyMetadata class.
trexfeathers Jan 19, 2021
fe79cf1
Connectivity class first pass.
trexfeathers Jan 21, 2021
74b9fe7
Enhanced Connectivity intelligence for masked elements.
trexfeathers Jan 22, 2021
e06798e
ConnectivityMetadata tests.
trexfeathers Jan 22, 2021
0f0f67b
Connectivity correct xml behaviour and better _values setting.
trexfeathers Jan 25, 2021
f6fb732
Connectivity better shape validation message.
trexfeathers Jan 25, 2021
ca8f7fa
Connectivity: corrected element size validation message.
trexfeathers Jan 25, 2021
dbeed89
Connectivity unit tests.
trexfeathers Jan 25, 2021
9477b14
Connectivity additional unit tests.
trexfeathers Jan 25, 2021
c0ac359
Connectivity in other unit tests.
trexfeathers Jan 26, 2021
0e9ee05
Connectivity __init__ docstring.
trexfeathers Jan 26, 2021
c5b6caf
Connectivity complete docstrings.
trexfeathers Jan 28, 2021
ff08a8c
Merge existing work onto latest master.
trexfeathers Jan 28, 2021
c2ac0fc
Alphabetise ConnectivityMetadata usages.
trexfeathers Feb 5, 2021
6139e56
Connectivity clearer handling of locations and dims.
trexfeathers Feb 5, 2021
85b98c9
Connectivity handle standard_name and units if provided.
trexfeathers Feb 5, 2021
52aa5c2
Connectivity align start_index docstring with UGRID conventions.
trexfeathers Feb 5, 2021
b9f470a
Connectivity UGRID_CF_ROLES class attribute.
trexfeathers Feb 5, 2021
d512fa2
Connectivity improved validate_arg_vs_list().
trexfeathers Feb 5, 2021
97310e7
Make Connectivity's extra attributes truly read-only.
trexfeathers Feb 5, 2021
2808afe
Connectivity stop overriding str and repr.
trexfeathers Feb 5, 2021
c04f230
Connectivity improved src_lengths and lazy operations.
trexfeathers Feb 5, 2021
8d14157
Connectivity indices typo.
trexfeathers Feb 5, 2021
7354e89
Connectivity resource-light indices validation.
trexfeathers Feb 5, 2021
116a683
Connectivity enable transposed equivalence.
trexfeathers Feb 5, 2021
16c5e75
Connectivity defaults stated in docstrings.
trexfeathers Feb 5, 2021
f1340a4
Docstring corrections.
trexfeathers Feb 5, 2021
bbbd195
test_class_connectivitymetadata updated to use src_dim.
trexfeathers Feb 5, 2021
191a743
Connectivity transpose creates a new class from scratch instead of co…
trexfeathers Feb 8, 2021
6c9c765
Connectivity final review improvements.
trexfeathers Feb 8, 2021
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
130 changes: 128 additions & 2 deletions lib/iris/common/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"AncillaryVariableMetadata",
"BaseMetadata",
"CellMeasureMetadata",
"ConnectivityMetadata",
"CoordMetadata",
"CubeMetadata",
"DimCoordMetadata",
Expand Down Expand Up @@ -181,9 +182,10 @@ def func(field):
return result

# Note that, for strict we use "_fields" not "_members".
# The "circular" member does not participate in strict equivalence.
# The "circular" and "src_dim" members do not participate in strict equivalence.
fields = filter(
lambda field: field != "circular", self._fields
lambda field: field not in ("circular", "src_dim"),
self._fields,
)
result = all([func(field) for field in fields])

Expand Down Expand Up @@ -875,6 +877,126 @@ def equal(self, other, lenient=None):
return super().equal(other, lenient=lenient)


class ConnectivityMetadata(BaseMetadata):
"""
Metadata container for a :class:`~iris.coords.Connectivity`.

"""

# The "src_dim" member is stateful only, and does not participate in
# lenient/strict equivalence.
_members = ("cf_role", "start_index", "src_dim")

__slots__ = ()

@wraps(BaseMetadata.__eq__, assigned=("__doc__",), updated=())
@lenient_service
def __eq__(self, other):
return super().__eq__(other)

def _combine_lenient(self, other):
"""
Perform lenient combination of metadata members for connectivities.

Args:

* other (ConnectivityMetadata):
The other connectivity metadata participating in the lenient
combination.

Returns:
A list of combined metadata member values.

"""
# Perform "strict" combination for "cf_role", "start_index", "src_dim".
def func(field):
left = getattr(self, field)
right = getattr(other, field)
return left if left == right else None

# Note that, we use "_members" not "_fields".
values = [func(field) for field in ConnectivityMetadata._members]
# Perform lenient combination of the other parent members.
result = super()._combine_lenient(other)
result.extend(values)

return result

def _compare_lenient(self, other):
"""
Perform lenient equality of metadata members for connectivities.

Args:

* other (ConnectivityMetadata):
The other connectivity metadata participating in the lenient
comparison.

Returns:
Boolean.

"""
# Perform "strict" comparison for "cf_role", "start_index".
# The "src_dim" member is not part of lenient equivalence.
members = filter(
lambda member: member != "src_dim", ConnectivityMetadata._members
)
result = all(
[
getattr(self, field) == getattr(other, field)
for field in members
]
)
if result:
# Perform lenient comparison of the other parent members.
result = super()._compare_lenient(other)

return result

def _difference_lenient(self, other):
"""
Perform lenient difference of metadata members for connectivities.

Args:

* other (ConnectivityMetadata):
The other connectivity metadata participating in the lenient
difference.

Returns:
A list of difference metadata member values.

"""
# Perform "strict" difference for "cf_role", "start_index", "src_dim".
def func(field):
left = getattr(self, field)
right = getattr(other, field)
return None if left == right else (left, right)

# Note that, we use "_members" not "_fields".
values = [func(field) for field in ConnectivityMetadata._members]
# Perform lenient difference of the other parent members.
result = super()._difference_lenient(other)
result.extend(values)

return result

@wraps(BaseMetadata.combine, assigned=("__doc__",), updated=())
@lenient_service
def combine(self, other, lenient=None):
return super().combine(other, lenient=lenient)

@wraps(BaseMetadata.difference, assigned=("__doc__",), updated=())
@lenient_service
def difference(self, other, lenient=None):
return super().difference(other, lenient=lenient)

@wraps(BaseMetadata.equal, assigned=("__doc__",), updated=())
@lenient_service
def equal(self, other, lenient=None):
return super().equal(other, lenient=lenient)


class CoordMetadata(BaseMetadata):
"""
Metadata container for a :class:`~iris.coords.Coord`.
Expand Down Expand Up @@ -1459,6 +1581,7 @@ def values(self):
AncillaryVariableMetadata.combine,
BaseMetadata.combine,
CellMeasureMetadata.combine,
ConnectivityMetadata.combine,
CoordMetadata.combine,
CubeMetadata.combine,
DimCoordMetadata.combine,
Expand All @@ -1470,6 +1593,7 @@ def values(self):
AncillaryVariableMetadata.difference,
BaseMetadata.difference,
CellMeasureMetadata.difference,
ConnectivityMetadata.difference,
CoordMetadata.difference,
CubeMetadata.difference,
DimCoordMetadata.difference,
Expand All @@ -1484,6 +1608,8 @@ def values(self):
BaseMetadata.equal,
CellMeasureMetadata.__eq__,
CellMeasureMetadata.equal,
ConnectivityMetadata.__eq__,
ConnectivityMetadata.equal,
CoordMetadata.__eq__,
CoordMetadata.equal,
CubeMetadata.__eq__,
Expand Down
Loading