Skip to content

Commit 0e368b8

Browse files
committed
dev
1 parent 1aee1e5 commit 0e368b8

File tree

13 files changed

+690
-45
lines changed

13 files changed

+690
-45
lines changed

cf/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,18 @@
248248
from .dimensioncoordinate import DimensionCoordinate
249249
from .auxiliarycoordinate import AuxiliaryCoordinate
250250
from .coordinatereference import CoordinateReference
251+
from .cellconnectivity import CellConnectivity
251252
from .cellmethod import CellMethod
252253
from .cellmeasure import CellMeasure
253254
from .domainancillary import DomainAncillary
254255
from .domainaxis import DomainAxis
256+
from .domaintopology import DomainTopology
255257
from .fieldancillary import FieldAncillary
256258
from .field import Field
257259
from .data import Data
258260
from .data.array import (
261+
BoundsFromNodesArray,
262+
CellConnectivityArray,
259263
CFANetCDFArray,
260264
FullArray,
261265
GatheredArray,

cf/cellconnectivity.py

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
import cfdm
2+
3+
from . import mixin
4+
from .decorators import _deprecated_kwarg_check
5+
6+
7+
class CellConnectivity(mixin.PropertiesData, cfdm.CellConnectivity):
8+
"""A cell connectivity construct of the CF data model.
9+
10+
TODOUGRID
11+
12+
A cell measure construct provides information that is needed about
13+
the size or shape of the cells and that depends on a subset of the
14+
domain axis constructs. Cell measure constructs have to be used
15+
when the size or shape of the cells cannot be deduced from the
16+
dimension or auxiliary coordinate constructs without special
17+
knowledge that a generic application cannot be expected to have.
18+
19+
The connectivity measure construct consists of a numeric array of the
20+
metric data which spans a subset of the domain axis constructs,
21+
and properties to describe the data. The connectivity measure construct
22+
specifies a "measure" to indicate which metric of the space it
23+
supplies, e.g. connectivity horizontal areas, and must have a units
24+
property consistent with the measure, e.g. square metres. It is
25+
assumed that the metric does not depend on axes of the domain
26+
which are not spanned by the array, along which the values are
27+
implicitly propagated. CF-netCDF connectivity measure variables correspond
28+
to connectivity measure constructs.
29+
30+
**NetCDF interface**
31+
32+
{{netCDF variable}}
33+
34+
.. versionadded:: TODOUGRIDVER
35+
36+
"""
37+
38+
def __repr__(self):
39+
"""Called by the `repr` built-in function.
40+
41+
x.__repr__() <==> repr(x)
42+
43+
"""
44+
return super().__repr__().replace("<", "<CF ", 1)
45+
46+
@property
47+
def connectivity(self):
48+
"""TODOUGRID Measure which indicates the metric of space supplied.
49+
50+
.. versionadded:: TODOUGRIDVER
51+
52+
"""
53+
return self.get_connectivity(default=AttributeError())
54+
55+
@connectivity.setter
56+
def connectivity(self, value):
57+
self.set_connectivity(value)
58+
59+
@connectivity.deleter
60+
def connectivity(self):
61+
self.del_connectivity(default=AttributeError())
62+
63+
def identity(
64+
self,
65+
default="",
66+
strict=None,
67+
relaxed=False,
68+
nc_only=False,
69+
relaxed_identity=None,
70+
):
71+
"""Return the canonical identity.
72+
73+
By default the identity is the first found of the following:
74+
75+
* The connectivity type type, preceded by ``'connectivity:'``.
76+
* The `standard_name` property.
77+
* The `id` attribute, preceded by ``'id%'``.
78+
* The `long_name` property, preceded by ``'long_name='``.
79+
* The netCDF variable name, preceded by ``'ncvar%'``.
80+
* The value of the *default* parameter.
81+
82+
.. versionadded:: TODOUGRIDVER
83+
84+
.. seealso:: `id`, `identities`, `long_name`, `connectivity`,
85+
`nc_get_variable`, `standard_name`
86+
87+
:Parameters:
88+
89+
default: optional
90+
If no identity can be found then return the value of the
91+
default parameter.
92+
93+
strict: `bool`, optional
94+
If True then the identity is the first found of only
95+
the `connectivity` attribute, "standard_name" property
96+
or the "id" attribute.
97+
98+
relaxed: `bool`, optional
99+
If True then the identity is the first found of only
100+
the `connectivity `attribute, the "standard_name"
101+
property, the "id" attribute, the "long_name" property
102+
or the netCDF variable name.
103+
104+
nc_only: `bool`, optional
105+
If True then only take the identity from the netCDF
106+
variable name.
107+
108+
:Returns:
109+
110+
The identity.
111+
112+
**Examples**
113+
114+
TODOUGRID
115+
116+
>>> c.measure
117+
'area'
118+
>>> c.properties()
119+
{'long_name': 'connectivity_area',
120+
'foo': 'bar'}
121+
>>> c.nc_get_variable()
122+
'areaconnectivityo'
123+
>>> c.identity()
124+
'measure:area'
125+
>>> del c.measure
126+
>>> c.identity()
127+
'long_name=connectivity_area'
128+
>>> del c.long_name
129+
>>> c.identity()
130+
'ncvar%areaconnectivityo'
131+
>>> c.nc_del_variable()
132+
'areaconnectivityo'
133+
>>> c.identity()
134+
''
135+
>>> c.identity('no identity')
136+
'no identity'
137+
138+
"""
139+
if nc_only:
140+
if strict:
141+
raise ValueError(
142+
"'strict' and 'nc_only' parameters cannot both be True")
143+
144+
if relaxed:
145+
raise ValueError(
146+
"'relaxed' and 'nc_only' parameters cannot both be True")
147+
148+
n = self.nc_get_variable(None)
149+
if n is not None:
150+
return f"ncvar%{n}"
151+
152+
return default
153+
154+
n = self.get_connectivity(default=None)
155+
if n is not None:
156+
return f"connectivity:{n}"
157+
158+
n = self.get_property("standard_name", None)
159+
if n is not None:
160+
return f"{n}"
161+
162+
n = getattr(self, "id", None)
163+
if n is not None:
164+
return f"id%{n}"
165+
166+
if relaxed:
167+
n = self.get_property("long_name", None)
168+
if n is not None:
169+
return f"long_name={n}"
170+
171+
n = self.nc_get_variable(None)
172+
if n is not None:
173+
return f"ncvar%{n}"
174+
175+
return default
176+
177+
if strict:
178+
return default
179+
180+
n = self.get_property("long_name", None)
181+
if n is not None:
182+
return f"long_name={n}"
183+
184+
n = self.nc_get_variable(None)
185+
if n is not None:
186+
return f"ncvar%{n}"
187+
188+
return default

cf/cfimplementation.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from . import (
44
AuxiliaryCoordinate,
55
Bounds,
6+
CellConnectivity,
67
CellMeasure,
78
CellMethod,
89
CoordinateConversion,
@@ -13,6 +14,7 @@
1314
Domain,
1415
DomainAncillary,
1516
DomainAxis,
17+
DomainTopology,
1618
Field,
1719
FieldAncillary,
1820
Index,
@@ -25,6 +27,8 @@
2527
)
2628
from .data import Data
2729
from .data.array import (
30+
BoundsFromNodesArray,
31+
CellConnectivityArray,
2832
CFANetCDFArray,
2933
GatheredArray,
3034
NetCDFArray,
@@ -144,6 +148,7 @@ def initialise_CFANetCDFArray(
144148
_implementation = CFImplementation(
145149
cf_version=CF(),
146150
AuxiliaryCoordinate=AuxiliaryCoordinate,
151+
CellConnectivity=CellConnectivity,
147152
CellMeasure=CellMeasure,
148153
CellMethod=CellMethod,
149154
CFANetCDFArray=CFANetCDFArray,
@@ -152,6 +157,7 @@ def initialise_CFANetCDFArray(
152157
Domain=Domain,
153158
DomainAncillary=DomainAncillary,
154159
DomainAxis=DomainAxis,
160+
DomainTopology=DomainTopology,
155161
Field=Field,
156162
FieldAncillary=FieldAncillary,
157163
Bounds=Bounds,
@@ -165,6 +171,8 @@ def initialise_CFANetCDFArray(
165171
NodeCountProperties=NodeCountProperties,
166172
PartNodeCountProperties=PartNodeCountProperties,
167173
Data=Data,
174+
BoundsFromNodesArray=BoundsFromNodesArray,
175+
CellConnectivityArray= CellConnectivityArray,
168176
GatheredArray=GatheredArray,
169177
NetCDFArray=NetCDFArray,
170178
RaggedContiguousArray=RaggedContiguousArray,
@@ -194,6 +202,9 @@ def implementation():
194202
<CFImplementation: >
195203
>>> i.classes()
196204
{'AuxiliaryCoordinate': cf.auxiliarycoordinate.AuxiliaryCoordinate,
205+
'BoundsFromNodesArray': cf.data.array.boundsfromnodesarray.BoundsFromNodesArray,
206+
'CellConnectivity': cf.cellconnectivity.CellConnectivity,
207+
'CellConnectivityArray': cf.data.array.cellconnectivityarray.CellConnectivityArray,
197208
'CellMeasure': cf.cellmeasure.CellMeasure,
198209
'CellMethod': cf.cellmethod.CellMethod,
199210
'CFANetCDFArray': cf.data.array.cfanetcdfarray.CFANetCDFArray,
@@ -202,6 +213,7 @@ def implementation():
202213
'Domain': cf.domain.Domain,
203214
'DomainAncillary': cf.domainancillary.DomainAncillary,
204215
'DomainAxis': cf.domainaxis.DomainAxis,
216+
'DomainTopology': cf.domaintopology.DomainTopology,
205217
'Field': cf.field.Field,
206218
'FieldAncillary': cf.fieldancillary.FieldAncillary,
207219
'Bounds': cf.bounds.Bounds,

cf/data/array/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from .boundsfromnodesarray import BoundsFromNodesArray
2+
from .cellconnectivityarray import CellConnectivityArray
13
from .cfanetcdfarray import CFANetCDFArray
24
from .fullarray import FullArray
35
from .gatheredarray import GatheredArray

0 commit comments

Comments
 (0)