cfdm.core.bounds¶
Classes
|
A cell bounds component. |
- class cfdm.core.bounds.Bounds(*args, **kwargs)[source]¶
Bases:
PropertiesDataA cell bounds component.
That is, a cell bounds component of a coordinate or domain ancillary construct of the CF data model.
An array of cell bounds spans the same domain axes as its coordinate array, with the addition of an extra dimension whose size is that of the number of vertices of each cell. This extra dimension does not correspond to a domain axis construct since it does not relate to an independent axis of the domain. Note that, for climatological time axes, the bounds are interpreted in a special way indicated by the cell method constructs.
Added in version (cfdm): 1.7.0
Initialisation
- Parameters:
- properties:
dict, optional Set descriptive properties. The dictionary keys are property names, with corresponding values.
Properties may also be set after initialisation with the
set_propertiesandset_propertymethods.- Parameter example:
properties={'standard_name': 'longitude'}
- data: data_like, optional
Set the data.
A data_like object is any object that can be converted to a
Dataobject, i.e.numpyarray_like objects,Dataobjects, and cfdm.core instances that containDataobjects.The data also may be set after initialisation with the
set_datamethod.- source: optional
Convert source, which can be any type of object, to a
Boundsinstance.All other parameters, apart from copy, are ignored and their values are instead inferred from source by assuming that it has the
BoundsAPI. Any parameters that can not be retrieved from source in this way are assumed to have their default value.Note that if
xis also aBoundsinstance thencfdm.core.Bounds(source=x)is equivalent tox.copy().- copy:
bool, optional If True (the default) then deep copy the input parameters prior to initialisation. By default the parameters are not deep copied.
- properties:
- clear_properties()[source]¶
Remove all properties.
Added in version (cfdm): 1.7.0
See also
- Returns:
dictThe properties that have been removed.
Examples
>>> f = cfdm.core.Bounds() >>> f.properties() {} >>> f.set_properties({'standard_name': 'air_pressure', ... 'long_name': 'Air Pressure'}) >>> f.properties() {'standard_name': 'air_pressure', 'long_name': 'Air Pressure'} >>> f.set_properties({'standard_name': 'air_pressure', 'foo': 'bar'}) >>> f.properties() {'standard_name': 'air_pressure', 'long_name': 'Air Pressure', 'foo': 'bar'} >>> f.clear_properties() {'standard_name': 'air_pressure', 'long_name': 'Air Pressure', 'foo': 'bar'} >>> f.properties() {}
- copy(data=True)[source]¶
Return a deep copy.
f.copy()is equivalent tocopy.deepcopy(f).Arrays within
Datainstances are copied with a copy-on-write technique. This means that a copy takes up very little extra memory, even when the original contains very large data arrays, and the copy operation is fast.Added in version (cfdm): 1.7.0
- Parameters:
- data:
bool, optional If True (the default) then copy data, else the data is not copied.
- data:
- Returns:
BoundsThe deep copy.
Examples
>>> g = f.copy() >>> g = f.copy(data=False) >>> g.has_data() False
- del_data(default=ValueError())[source]¶
Remove the data.
Added in version (cfdm): 1.7.0
- Parameters:
- default: optional
Return the value of the default parameter if data have not been set.
If set to an
Exceptioninstance then it will be raised instead.
- Returns:
DataThe removed data.
Examples
>>> f = cfdm.core.Bounds() >>> f.set_data([1, 2, 3]) >>> f.has_data() True >>> f.get_data() <Data(3): [1, 2, 3]> >>> f.data <Data(3): [1, 2, 3]> >>> f.del_data() <Data(3): [1, 2, 3]> >>> g = f.set_data([4, 5, 6], inplace=False) >>> g.data <Data(3): [4, 5, 6]> >>> f.has_data() False >>> print(f.get_data(None)) None >>> print(f.del_data(None)) None
- del_properties(properties)[source]¶
Remove properties.
Added in version (cfdm): 1.10.0.3
See also
- Parameters:
- Returns:
dictThe removed property values, keyed by property name.
Examples
>>> f = cfdm.core.Bounds() >>> f.set_properties({'project': 'CMIP7', 'comment': 'model'}) >>> removed_properties = f.del_properties('project') >>> removed_properties {'project': 'CMIP7'} >>> f.properties() {'comment': 'model'} >>> f.set_properties(removed_properties) >>> f.properties() {'comment': 'model', 'project': 'CMIP7'} >>> f.del_properties('foo') {}
- del_property(prop, default=ValueError())[source]¶
Remove a property.
Added in version (cfdm): 1.7.0
See also
clear_properties,get_property,has_property,properties,set_property- Parameters:
- Returns:
The removed property value.
Examples
>>> f = cfdm.core.Bounds() >>> f.set_property('project', 'CMIP7') >>> f.has_property('project') True >>> f.get_property('project') 'CMIP7' >>> f.del_property('project') 'CMIP7' >>> f.has_property('project') False >>> print(f.del_property('project', None)) None >>> print(f.get_property('project', None)) None
- get_data(default=ValueError(), _units=True, _fill_value=True)[source]¶
Return the data.
Note that a
Datainstance is returned. Use itsarrayattribute to return the data as an independentnumpyarray.The units, calendar and fill value properties are, if set, inserted into the data.
Added in version (cfdm): 1.7.0
See also
- Parameters:
- default: optional
Return the value of the default parameter if data have not been set.
If set to an
Exceptioninstance then it will be raised instead.
- Returns:
DataThe data.
Examples
>>> f = cfdm.core.Bounds() >>> f.set_data([1, 2, 3]) >>> f.has_data() True >>> f.get_data() <Data(3): [1, 2, 3]> >>> f.data <Data(3): [1, 2, 3]> >>> f.del_data() <Data(3): [1, 2, 3]> >>> g = f.set_data([4, 5, 6], inplace=False) >>> g.data <Data(3): [4, 5, 6]> >>> f.has_data() False >>> print(f.get_data(None)) None >>> print(f.del_data(None)) None
- get_property(prop, default=ValueError())[source]¶
Return a property.
Added in version (cfdm): 1.7.0
See also
- Parameters:
- Returns:
The value of the property.
Examples
>>> f = cfdm.core.Bounds() >>> f.set_property('project', 'CMIP7') >>> f.has_property('project') True >>> f.get_property('project') 'CMIP7' >>> f.del_property('project') 'CMIP7' >>> f.has_property('project') False >>> print(f.del_property('project', None)) None >>> print(f.get_property('project', None)) None
- has_bounds()[source]¶
Whether or not there are cell bounds.
This is always False.
Added in version (cfdm): 1.7.4
See also
- Returns:
boolAlways False.
Examples
>>> f = cfdm.core.Bounds() >>> f.has_bounds() False
- has_data()[source]¶
Whether or not the construct has data.
Added in version (cfdm): 1.7.0
- Returns:
boolTrue if data have been set, otherwise False.
Examples
>>> f = cfdm.core.Bounds() >>> f.set_data([1, 2, 3]) >>> f.has_data() True >>> f.get_data() <Data(3): [1, 2, 3]> >>> f.data <Data(3): [1, 2, 3]> >>> f.del_data() <Data(3): [1, 2, 3]> >>> g = f.set_data([4, 5, 6], inplace=False) >>> g.data <Data(3): [4, 5, 6]> >>> f.has_data() False >>> print(f.get_data(None)) None >>> print(f.del_data(None)) None
- has_property(prop)[source]¶
Whether a property has been set.
Added in version (cfdm): 1.7.0
See also
- Parameters:
- prop:
str The name of the property.
- Parameter example:
prop='long_name'
- prop:
- Returns:
boolTrue if the property has been set, otherwise False.
Examples
>>> f = cfdm.core.Bounds() >>> f.set_property('project', 'CMIP7') >>> f.has_property('project') True >>> f.get_property('project') 'CMIP7' >>> f.del_property('project') 'CMIP7' >>> f.has_property('project') False >>> print(f.del_property('project', None)) None >>> print(f.get_property('project', None)) None
- properties()[source]¶
Return all properties.
Added in version (cfdm): 1.7.0
See also
- Returns:
dictThe properties.
Examples
>>> f = cfdm.core.Bounds() >>> f.properties() {} >>> f.set_properties({'standard_name': 'air_pressure', ... 'long_name': 'Air Pressure'}) >>> f.properties() {'standard_name': 'air_pressure', 'long_name': 'Air Pressure'} >>> f.set_properties({'standard_name': 'air_pressure', 'foo': 'bar'}) >>> f.properties() {'standard_name': 'air_pressure', 'long_name': 'Air Pressure', 'foo': 'bar'} >>> f.clear_properties() {'standard_name': 'air_pressure', 'long_name': 'Air Pressure', 'foo': 'bar'} >>> f.properties() {}
- set_data(data, copy=True, inplace=True)[source]¶
Set the data.
The units, calendar and fill value of the incoming
Datainstance are removed prior to insertion.Added in version (cfdm): 1.7.0
- Parameters:
- data: data_like
The data to be inserted.
A data_like object is any object that can be converted to a
Dataobject, i.e.numpyarray_like objects,Dataobjects, and cfdm.core instances that containDataobjects.- copy:
bool, optional If True (the default) then copy the data prior to insertion, else the data is not copied.
- inplace:
bool, optional: If True (the default) then do the operation in-place and return
None. If False a new, modifiedBoundsinstance is returned.Added in version (cfdm): 1.8.7.0
- Returns:
Examples
>>> f = cfdm.core.Bounds() >>> f.set_data([1, 2, 3]) >>> f.has_data() True >>> f.get_data() <Data(3): [1, 2, 3]> >>> f.data <Data(3): [1, 2, 3]> >>> f.del_data() <Data(3): [1, 2, 3]> >>> g = f.set_data([4, 5, 6], inplace=False) >>> g.data <Data(3): [4, 5, 6]> >>> f.has_data() False >>> print(f.get_data(None)) None >>> print(f.del_data(None)) None
- set_properties(properties, copy=True)[source]¶
Set properties.
Added in version (cfdm): 1.7.0
See also
- Parameters:
- Returns:
Examples
>>> f = cfdm.core.Bounds() >>> f.properties() {} >>> f.set_properties({'standard_name': 'air_pressure', ... 'long_name': 'Air Pressure'}) >>> f.properties() {'standard_name': 'air_pressure', 'long_name': 'Air Pressure'} >>> f.set_properties({'standard_name': 'air_pressure', 'foo': 'bar'}) >>> f.properties() {'standard_name': 'air_pressure', 'long_name': 'Air Pressure', 'foo': 'bar'} >>> f.clear_properties() {'standard_name': 'air_pressure', 'long_name': 'Air Pressure', 'foo': 'bar'} >>> f.properties() {}
- set_property(prop, value, copy=True)[source]¶
Set a property.
Added in version (cfdm): 1.7.0
See also
del_property,get_property,has_property,properties,set_properties- Parameters:
- Returns:
Examples
>>> f = cfdm.core.Bounds() >>> f.set_property('project', 'CMIP7') >>> f.has_property('project') True >>> f.get_property('project') 'CMIP7' >>> f.del_property('project') 'CMIP7' >>> f.has_property('project') False >>> print(f.del_property('project', None)) None >>> print(f.get_property('project', None)) None
- property data¶
The data.
f.datais equivalent tof.get_data().Note that a
Datainstance is returned. Use thearrayattribute to get the data as anumpyarray.The units, calendar and fill value properties are, if set, inserted into the data.
Added in version (cfdm): 1.7.0
See also
cfdm.core.Data.array,del_data,get_data,has_data,set_data- Returns:
DataThe data.
Examples
>>> f = cfdm.core.Bounds() >>> f.set_data(cfdm.core.Data(numpy.arange(10.))) >>> f.has_data() True >>> d = f.data >>> d <Data(10): [0.0, ..., 9.0]> >>> f.data.shape (10,)
- property dtype¶
Data-type of the data elements.
Examples
>>> d.dtype dtype('float64') >>> type(d.dtype) <type 'numpy.dtype'>
- property ndim¶
The number of data dimensions.
Only dimensions that correspond to domain axis constructs are included.
Examples
>>> f.shape (73, 96) >>> f.ndim 2 >>> f.size 7008
>>> f.shape (73, 1, 96) >>> f.ndim 3 >>> f.size 7008
>>> f.shape (73,) >>> f.ndim 1 >>> f.size 73
>>> f.shape () >>> f.ndim 0 >>> f.size 1
- property shape¶
A tuple of the data array’s dimension sizes.
Only dimensions that correspond to domain axis constructs are included.
Examples
>>> f.shape (73, 96) >>> f.ndim 2 >>> f.size 7008
>>> f.shape (73, 1, 96) >>> f.ndim 3 >>> f.size 7008
>>> f.shape (73,) >>> f.ndim 1 >>> f.size 73
>>> f.shape () >>> f.ndim 0 >>> f.size 1
- property size¶
The number elements in the data.
sizeis equal to the product ofshape, that only includes the sizes of dimensions that correspond to domain axis constructs.Examples
>>> f.shape (73, 96) >>> f.ndim 2 >>> f.size 7008
>>> f.shape (73, 1, 96) >>> f.ndim 3 >>> f.size 7008
>>> f.shape (73,) >>> f.ndim 1 >>> f.size 73
>>> f.shape () >>> f.ndim 0 >>> f.size 1