forked from NCAS-CMS/cf-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1aee1e5
commit 0e368b8
Showing
13 changed files
with
690 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.