Skip to content

Commit

Permalink
move connectivity to experimental (#3995)
Browse files Browse the repository at this point in the history
* move connectivity to experimental

* drop pyugrid from py38.yml

* Update lib/iris/coords.py

Co-authored-by: Martin Yeo <40734014+trexfeathers@users.noreply.github.com>

* Update lib/iris/common/metadata.py

Co-authored-by: Martin Yeo <40734014+trexfeathers@users.noreply.github.com>

* Update lib/iris/experimental/ugrid.py

Co-authored-by: Martin Yeo <40734014+trexfeathers@users.noreply.github.com>

* review actions - drop logger

Co-authored-by: Martin Yeo <40734014+trexfeathers@users.noreply.github.com>
  • Loading branch information
bjlittle and trexfeathers authored Feb 10, 2021
1 parent 1c699a3 commit e0fb557
Show file tree
Hide file tree
Showing 13 changed files with 631 additions and 681 deletions.
139 changes: 8 additions & 131 deletions lib/iris/common/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"AncillaryVariableMetadata",
"BaseMetadata",
"CellMeasureMetadata",
"ConnectivityMetadata",
"CoordMetadata",
"CubeMetadata",
"DimCoordMetadata",
Expand Down Expand Up @@ -877,126 +876,6 @@ 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 @@ -1577,46 +1456,44 @@ def values(self):


#: Convenience collection of lenient metadata combine services.
SERVICES_COMBINE = (
# TODO: change lists back to tuples once CellMeasureMetadata is re-integrated
# here (currently in experimental.ugrid).
SERVICES_COMBINE = [
AncillaryVariableMetadata.combine,
BaseMetadata.combine,
CellMeasureMetadata.combine,
ConnectivityMetadata.combine,
CoordMetadata.combine,
CubeMetadata.combine,
DimCoordMetadata.combine,
)
]


#: Convenience collection of lenient metadata difference services.
SERVICES_DIFFERENCE = (
SERVICES_DIFFERENCE = [
AncillaryVariableMetadata.difference,
BaseMetadata.difference,
CellMeasureMetadata.difference,
ConnectivityMetadata.difference,
CoordMetadata.difference,
CubeMetadata.difference,
DimCoordMetadata.difference,
)
]


#: Convenience collection of lenient metadata equality services.
SERVICES_EQUAL = (
SERVICES_EQUAL = [
AncillaryVariableMetadata.__eq__,
AncillaryVariableMetadata.equal,
BaseMetadata.__eq__,
BaseMetadata.equal,
CellMeasureMetadata.__eq__,
CellMeasureMetadata.equal,
ConnectivityMetadata.__eq__,
ConnectivityMetadata.equal,
CoordMetadata.__eq__,
CoordMetadata.equal,
CubeMetadata.__eq__,
CubeMetadata.equal,
DimCoordMetadata.__eq__,
DimCoordMetadata.equal,
)
]


#: Convenience collection of lenient metadata services.
Expand Down
Loading

0 comments on commit e0fb557

Please sign in to comment.