Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhassell committed Aug 22, 2023
1 parent 1aee1e5 commit 0e368b8
Show file tree
Hide file tree
Showing 13 changed files with 690 additions and 45 deletions.
4 changes: 4 additions & 0 deletions cf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,18 @@
from .dimensioncoordinate import DimensionCoordinate
from .auxiliarycoordinate import AuxiliaryCoordinate
from .coordinatereference import CoordinateReference
from .cellconnectivity import CellConnectivity
from .cellmethod import CellMethod
from .cellmeasure import CellMeasure
from .domainancillary import DomainAncillary
from .domainaxis import DomainAxis
from .domaintopology import DomainTopology
from .fieldancillary import FieldAncillary
from .field import Field
from .data import Data
from .data.array import (
BoundsFromNodesArray,
CellConnectivityArray,
CFANetCDFArray,
FullArray,
GatheredArray,
Expand Down
188 changes: 188 additions & 0 deletions cf/cellconnectivity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
import cfdm

from . import mixin
from .decorators import _deprecated_kwarg_check


class CellConnectivity(mixin.PropertiesData, cfdm.CellConnectivity):
"""A cell connectivity construct of the CF data model.
TODOUGRID
A cell measure construct provides information that is needed about
the size or shape of the cells and that depends on a subset of the
domain axis constructs. Cell measure constructs have to be used
when the size or shape of the cells cannot be deduced from the
dimension or auxiliary coordinate constructs without special
knowledge that a generic application cannot be expected to have.
The connectivity measure construct consists of a numeric array of the
metric data which spans a subset of the domain axis constructs,
and properties to describe the data. The connectivity measure construct
specifies a "measure" to indicate which metric of the space it
supplies, e.g. connectivity horizontal areas, and must have a units
property consistent with the measure, e.g. square metres. It is
assumed that the metric does not depend on axes of the domain
which are not spanned by the array, along which the values are
implicitly propagated. CF-netCDF connectivity measure variables correspond
to connectivity measure constructs.
**NetCDF interface**
{{netCDF variable}}
.. versionadded:: TODOUGRIDVER
"""

def __repr__(self):
"""Called by the `repr` built-in function.
x.__repr__() <==> repr(x)
"""
return super().__repr__().replace("<", "<CF ", 1)

@property
def connectivity(self):
"""TODOUGRID Measure which indicates the metric of space supplied.
.. versionadded:: TODOUGRIDVER
"""
return self.get_connectivity(default=AttributeError())

@connectivity.setter
def connectivity(self, value):
self.set_connectivity(value)

@connectivity.deleter
def connectivity(self):
self.del_connectivity(default=AttributeError())

def identity(
self,
default="",
strict=None,
relaxed=False,
nc_only=False,
relaxed_identity=None,
):
"""Return the canonical identity.
By default the identity is the first found of the following:
* The connectivity type type, preceded by ``'connectivity:'``.
* The `standard_name` property.
* The `id` attribute, preceded by ``'id%'``.
* The `long_name` property, preceded by ``'long_name='``.
* The netCDF variable name, preceded by ``'ncvar%'``.
* The value of the *default* parameter.
.. versionadded:: TODOUGRIDVER
.. seealso:: `id`, `identities`, `long_name`, `connectivity`,
`nc_get_variable`, `standard_name`
:Parameters:
default: optional
If no identity can be found then return the value of the
default parameter.
strict: `bool`, optional
If True then the identity is the first found of only
the `connectivity` attribute, "standard_name" property
or the "id" attribute.
relaxed: `bool`, optional
If True then the identity is the first found of only
the `connectivity `attribute, the "standard_name"
property, the "id" attribute, the "long_name" property
or the netCDF variable name.
nc_only: `bool`, optional
If True then only take the identity from the netCDF
variable name.
:Returns:
The identity.
**Examples**
TODOUGRID
>>> c.measure
'area'
>>> c.properties()
{'long_name': 'connectivity_area',
'foo': 'bar'}
>>> c.nc_get_variable()
'areaconnectivityo'
>>> c.identity()
'measure:area'
>>> del c.measure
>>> c.identity()
'long_name=connectivity_area'
>>> del c.long_name
>>> c.identity()
'ncvar%areaconnectivityo'
>>> c.nc_del_variable()
'areaconnectivityo'
>>> c.identity()
''
>>> c.identity('no identity')
'no identity'
"""
if nc_only:
if strict:
raise ValueError(
"'strict' and 'nc_only' parameters cannot both be True")

if relaxed:
raise ValueError(
"'relaxed' and 'nc_only' parameters cannot both be True")

n = self.nc_get_variable(None)
if n is not None:
return f"ncvar%{n}"

return default

n = self.get_connectivity(default=None)
if n is not None:
return f"connectivity:{n}"

n = self.get_property("standard_name", None)
if n is not None:
return f"{n}"

n = getattr(self, "id", None)
if n is not None:
return f"id%{n}"

if relaxed:
n = self.get_property("long_name", None)
if n is not None:
return f"long_name={n}"

n = self.nc_get_variable(None)
if n is not None:
return f"ncvar%{n}"

return default

if strict:
return default

n = self.get_property("long_name", None)
if n is not None:
return f"long_name={n}"

n = self.nc_get_variable(None)
if n is not None:
return f"ncvar%{n}"

return default
12 changes: 12 additions & 0 deletions cf/cfimplementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from . import (
AuxiliaryCoordinate,
Bounds,
CellConnectivity,
CellMeasure,
CellMethod,
CoordinateConversion,
Expand All @@ -13,6 +14,7 @@
Domain,
DomainAncillary,
DomainAxis,
DomainTopology,
Field,
FieldAncillary,
Index,
Expand All @@ -25,6 +27,8 @@
)
from .data import Data
from .data.array import (
BoundsFromNodesArray,
CellConnectivityArray,
CFANetCDFArray,
GatheredArray,
NetCDFArray,
Expand Down Expand Up @@ -144,6 +148,7 @@ def initialise_CFANetCDFArray(
_implementation = CFImplementation(
cf_version=CF(),
AuxiliaryCoordinate=AuxiliaryCoordinate,
CellConnectivity=CellConnectivity,
CellMeasure=CellMeasure,
CellMethod=CellMethod,
CFANetCDFArray=CFANetCDFArray,
Expand All @@ -152,6 +157,7 @@ def initialise_CFANetCDFArray(
Domain=Domain,
DomainAncillary=DomainAncillary,
DomainAxis=DomainAxis,
DomainTopology=DomainTopology,
Field=Field,
FieldAncillary=FieldAncillary,
Bounds=Bounds,
Expand All @@ -165,6 +171,8 @@ def initialise_CFANetCDFArray(
NodeCountProperties=NodeCountProperties,
PartNodeCountProperties=PartNodeCountProperties,
Data=Data,
BoundsFromNodesArray=BoundsFromNodesArray,
CellConnectivityArray= CellConnectivityArray,
GatheredArray=GatheredArray,
NetCDFArray=NetCDFArray,
RaggedContiguousArray=RaggedContiguousArray,
Expand Down Expand Up @@ -194,6 +202,9 @@ def implementation():
<CFImplementation: >
>>> i.classes()
{'AuxiliaryCoordinate': cf.auxiliarycoordinate.AuxiliaryCoordinate,
'BoundsFromNodesArray': cf.data.array.boundsfromnodesarray.BoundsFromNodesArray,
'CellConnectivity': cf.cellconnectivity.CellConnectivity,
'CellConnectivityArray': cf.data.array.cellconnectivityarray.CellConnectivityArray,
'CellMeasure': cf.cellmeasure.CellMeasure,
'CellMethod': cf.cellmethod.CellMethod,
'CFANetCDFArray': cf.data.array.cfanetcdfarray.CFANetCDFArray,
Expand All @@ -202,6 +213,7 @@ def implementation():
'Domain': cf.domain.Domain,
'DomainAncillary': cf.domainancillary.DomainAncillary,
'DomainAxis': cf.domainaxis.DomainAxis,
'DomainTopology': cf.domaintopology.DomainTopology,
'Field': cf.field.Field,
'FieldAncillary': cf.fieldancillary.FieldAncillary,
'Bounds': cf.bounds.Bounds,
Expand Down
2 changes: 2 additions & 0 deletions cf/data/array/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .boundsfromnodesarray import BoundsFromNodesArray
from .cellconnectivityarray import CellConnectivityArray
from .cfanetcdfarray import CFANetCDFArray
from .fullarray import FullArray
from .gatheredarray import GatheredArray
Expand Down
Loading

0 comments on commit 0e368b8

Please sign in to comment.