cfdm.bounds¶
Classes
|
A cell bounds component. |
- class cfdm.bounds.Bounds(*args, **kwargs)[source]¶
Bases:
BoundsMixin,NetCDFVariable,NetCDFDimension,PropertiesData,Files,BoundsA cell bounds component.
Specifically, 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.
In the CF data model, a bounds component does not have its own properties because they can not logically be different to those of the coordinate construct itself. However, it is sometimes desired to store attributes on a CF-netCDF bounds variable, so it is also allowed to provide properties to a bounds component.
NetCDF interface
The netCDF variable name may be accessed with the
nc_set_variable,nc_get_variable,nc_del_variable, andnc_has_variablemethods.The netCDF variable group structure may be accessed with the
nc_set_variable,nc_get_variable,nc_variable_groups,nc_clear_variable_groups, andnc_set_variable_groupsmethods.The name of the trailing netCDF dimension spanned by bounds (which does not correspond to a domain axis construct) may be accessed with the
nc_set_dimension,nc_get_dimension,nc_del_dimension, andnc_has_dimensionmethods.{{netCDF variable group}}
The dataset chunks may be accessed with the
nc_dataset_chunksizes,nc_set_dataset_chunksizes, andnc_clear_datset_chunksizesmethods.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 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.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:
- classmethod concatenate(variables, axis=0, cull_graph=False, relaxed_units=False, copy=True)[source]¶
Join a together sequence of
Bounds.Added in version (cfdm): 1.12.0.0
See also
Data.concatenate,Data.cull_graph- Parameters:
variables: sequence of constructs.
- axis:
int, optional Select the axis along which to concatenate, defined by its position in the data array. By default concatenation is along the axis in position 0.
- cull_graph:
bool, optional If True then unnecessary tasks are removed (culled) from each array’s dask graph before concatenation. This process can have a considerable overhead but can sometimes improve the overall performance of a workflow. If False (the default) then dask graphs are not culled. See
dask.optimization.cullfor details.- relaxed_units:
bool, optional If True then allow the concatenation of data with invalid but otherwise equal units. By default, if any data array has invalid units then the concatenation will fail. A
Unitsobject is considered to be invalid if itsisvalidattribute isFalse.- copy:
bool, optional If True (the default) then make copies of the
Boundsobjects prior to the concatenation, thereby ensuring that the input constructs are not changed by the concatenation process. If False then some or all input constructs might be changed in-place, but the concatenation process will be faster.
- axis:
- Returns:
BoundsThe concatenated construct.
- apply_masking(*args, **kwargs)[source]¶
Apply masking as defined by the CF conventions.
Masking is applied according to any of the following criteria that are applicable:
where data elements are equal to the value of the
missing_valueproperty;where data elements are equal to the value of the
_FillValueproperty;where data elements are strictly less than the value of the
valid_minproperty;where data elements are strictly greater than the value of the
valid_maxproperty;where data elements are within the inclusive range specified by the two values of
valid_rangeproperty.
If any of the above properties have not been set the no masking is applied for that method.
Elements that are already masked remain so.
Note
If using the
apply_maskingmethod on a construct that has been read from a dataset with themask=Falseparameter to thereadfunction, then the mask defined in the dataset can only be recreated if themissing_value,_FillValue,valid_min,valid_max, andvalid_rangeproperties have not been updated.Added in version (cfdm): 1.8.2
See also
Data.apply_masking,read,write- Parameters:
- Returns:
A new instance with masked values, or
Noneif the operation was in-place.
Examples
>>> print(v.data.array) [9.96920997e+36, 9.96920997e+36, 9.96920997e+36, 9.96920997e+36, 9.96920997e+36, 9.96920997e+36, 9.96920997e+36, 9.96920997e+36], [0.023 0.036 0.045 0.062 0.046 0.073 0.006 0.066] [0.11 0.131 0.124 0.146 0.087 0.103 0.057 0.011] [0.029 0.059 0.039 0.07 0.058 0.072 0.009 0.017] [9.96920997e+36, 9.96920997e+36, 9.96920997e+36, 9.96920997e+36, 9.96920997e+36, 9.96920997e+36, 9.96920997e+36, 9.96920997e+36]]) >>> masked_v = v.apply_masking() >>> print(masked_v.data.array) [[ -- -- -- -- -- -- -- --] [0.023 0.036 0.045 0.062 0.046 0.073 0.006 0.066] [0.11 0.131 0.124 0.146 0.087 0.103 0.057 0.011] [0.029 0.059 0.039 0.07 0.058 0.072 0.009 0.017] [ -- -- -- -- -- -- -- --]]
- 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.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
- creation_commands(representative_data=False, namespace=None, indent=0, string=True, name='c', data_name='data', quantization_name='q', header=True)[source]¶
Return the commands that would create the construct.
Added in version (cfdm): 1.8.7.0
- Parameters:
- representative_data:
bool, optional Return one-line representations of
Datainstances, which are not executable code but prevent the data being converted in its entirety to a string representation.- namespace:
str, optional The name space containing classes of the cfdm package. This is prefixed to the class name in commands that instantiate instances of cfdm objects. By default, or if
None, the name space is assumed to be consistent with cfdm being imported asimport cfdm.- Parameter example:
If cfdm was imported as
import cfdm as xyzthen setnamespace='xyz'- Parameter example:
If cfdm was imported as
from cfdm import *then setnamespace=''
- indent:
int, optional Indent each line by this many spaces. By default no indentation is applied. Ignored if string is False.
- string:
bool, optional If False then return each command as an element of a
list. By default the commands are concatenated into a string, with a new line inserted between each command.- name:
str, optional The name of the
Boundsinstance created by the returned commands.- data_name:
str, optional The name of the construct’s
Datainstance created by the returned commands.- quantization_name:
str, optional The name of the construct’s
Quantizationinstance created by the returned commands.Added in version (cfdm): 1.12.2.0
- header:
bool, optional If True (the default) output a comment describing the components. If False no such comment is returned.
- representative_data:
- Returns:
Examples
>>> x = cfdm.Bounds( ... properties={'units': 'Kelvin', ... 'standard_name': 'air_temperature'} ... ) >>> x.set_data([271.15, 274.15, 280]) >>> print(x.creation_commands(header=False)) c = cfdm.Bounds() c.set_properties({'units': 'Kelvin', 'standard_name': 'air_temperature'}) data = cfdm.Data([271.15, 274.15, 280.0], units='Kelvin', dtype='f8') c.set_data(data)
- 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.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.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.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
- dump(data=None, display=True, _key=None, _title=None, _create_title=True, _prefix='', _level=0, _omit_properties=None, _axes=None, _axis_names=None)[source]¶
A full description of the bounds component.
Returns a description of all properties and provides selected values of all data arrays.
Added in version (cfdm): 1.7.0
- Parameters:
- data:
boolorNone, optional If True then show the first and last data elements (and possibly others, depending on the data shape) when displaying data. This can take a long time if getting these data elements needs an expensive computation, possibly including a slow read from local or remote disk.
If False then do not show such data elements, unless data elements have been previously cached, thereby avoiding a potentially high computational cost.
If
None(the default) then the value of data will be taken from thecfdm.display_datafunction.Note that whenever data elements are displayed, they are cached for fast future retrieval.
Added in version (cfdm): 1.13.0.0
- display:
bool, optional If False then return the description as a string. By default the description is printed.
- data:
- Returns:
- equals(**kwargs)[source]¶
Whether two instances are the same.
Equality is strict by default. This means that:
the same descriptive properties must be present, with the same values and data types, and vector-valued properties must also have same the size and be element-wise equal (see the ignore_properties and ignore_data_type parameters), and
if there are data arrays then they must have same shape and data type, the same missing data mask, and be element-wise equal (see the ignore_data_type parameter).
Two real numbers
xandyare considered equal if|x-y|<=atol+rtol|y|, whereatol(the tolerance on absolute differences) andrtol(the tolerance on relative differences) are positive, typically very small numbers. See the atol and rtol parameters.Any type of object may be tested but, in general, equality is only possible with another object of the same type, or a subclass of one. See the ignore_type parameter.
Any compression is ignored by default, with only the arrays in their uncompressed forms being compared. See the ignore_compression parameter.
NetCDF elements, such as netCDF variable and dimension names, do not constitute part of the CF data model and so are not checked.
Added in version (cfdm): 1.7.0
- Parameters:
- other:
The object to compare for equality.
- atol: number, optional
The tolerance on absolute differences between real numbers. The default value is set by the
cfdm.atolfunction.- rtol: number, optional
The tolerance on relative differences between real numbers. The default value is set by the
cfdm.rtolfunction.- ignore_fill_value:
bool, optional If True then all
_FillValueandmissing_valueproperties are omitted from the comparison.- verbose:
intorstrorNone, optional If an integer from
-1to3, or an equivalent string equal ignoring case to one of:'DISABLE'(0)'WARNING'(1)'INFO'(2)'DETAIL'(3)'DEBUG'(-1)
set for the duration of the method call only as the minimum cut-off for the verboseness level of displayed output (log) messages, regardless of the globally-configured
cfdm.log_level. Note that increasing numerical value corresponds to increasing verbosity, with the exception of-1as a special case of maximal and extreme verbosity.Otherwise, if
None(the default value), output messages will be shown according to the value of thecfdm.log_levelsetting.Overall, the higher a non-negative integer or equivalent string that is set (up to a maximum of
3/'DETAIL') for increasing verbosity, the more description that is printed to convey information about the operation.- ignore_properties: (sequence of)
str, optional The names of properties to omit from the comparison.
- ignore_data_type:
bool, optional If True then ignore the data types in all numerical comparisons. By default different numerical data types imply inequality, regardless of whether the elements are within the tolerance for equality.
- ignore_compression:
bool, optional If False then the compression type and, if applicable, the underlying compressed arrays must be the same, as well as the arrays in their uncompressed forms. By default only the arrays in their uncompressed forms are compared.
- ignore_type:
bool, optional Any type of object may be tested but, in general, equality is only possible with another
Boundsinstance, or a subclass of one. If ignore_type is True thencfdm.Bounds(source=other)is tested, rather than theotherdefined by the other parameter.
- Returns:
boolWhether the two instances are equal.
Examples
>>> x.equals(x) True >>> x.equals(x.copy()) True >>> x.equals('something else') False
- file_directories()[source]¶
The directories of files containing parts of the data.
Returns the locations of any files referenced by the data.
Added in version (cfdm): 1.12.0.0
See also
- Returns:
setThe unique set of file directories as absolute paths.
Examples
>>> d.file_directories() {'/home/data1', 'file:///data2'}
- get_data(default=ValueError(), _units=True, _fill_value=True)[source]¶
Return the data.
Note that the data are returned in a
Dataobject. Use thearrayattribute of theDatainstance to return the data as an independentnumpyarray.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 data.
Examples
>>> f = cfdm.Field( ... properties={'standard_name': 'surface_altitude'}) >>> d = cfdm.Data(range(10)) >>> f.set_data(d) >>> f.has_data() True >>> f.get_data() <Data(10): [0, ..., 9]>
>>> f.del_data() <Data(10): [0, ..., 9]> >>> f.has_data() False >>> print(f.get_data(None)) None >>> print(f.del_data(None)) None
- get_original_filenames()[source]¶
The names of files containing the original data and metadata.
The original files are those that contain some or all of the data and metadata when it was first instantiated, and are necessary (but perhaps not sufficient) to recreate the
Boundsshould the need arise. Thecfdm.readfunction automatically records the original file names on all data that it creates.The original files of any constituent components are also included.
In-place changes to the
Boundswill not generally change the collection of original files. However if theBoundswas produced by combining other objects that also store their original file names, then the returned files will be the collection of original files from all contributing sources.Added in version (cfdm): 1.10.0.1
- 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.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_quantization(default=ValueError())[source]¶
Get quantization metadata.
Quantization eliminates false precision, usually by rounding the least significant bits of floating-point mantissas to zeros, so that a subsequent compression on disk is more efficient.
Boundsdata can not be quantized, so the default is always returned.Added in version (cfdm): 1.12.2.0
See also
- get_quantize_on_write(default=ValueError())[source]¶
Get a quantize-on-write instruction.
Quantization eliminates false precision, usually by rounding the least significant bits of floating-point mantissas to zeros, so that a subsequent compression on disk is more efficient.
Boundsdata can not be quantized, so the default is always returned.Added in version (cfdm): 1.12.2.0
See also
- 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.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.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.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
- identities(generator=False, **kwargs)[source]¶
Return all possible identities.
The identities comprise:
The
standard_nameproperty.All properties, preceded by the property name and an equals e.g.
'long_name=Air temperature'.The netCDF variable name, preceded by
'ncvar%'.
Added in version (cfdm): 1.7.0
See also
- Parameters:
- generator:
bool, optional If True then return a generator for the identities, rather than a list.
Added in version (cfdm): 1.8.9.0
- kwargs: optional
Additional configuration parameters that may be used by subclasses.
Added in version (cfdm): 1.8.9.0
- generator:
- Returns:
listor generatorThe identities.
Examples
>>> f.properties() {'foo': 'bar', 'long_name': 'Air Temperature', 'standard_name': 'air_temperature'} >>> f.nc_get_variable() 'tas' >>> f.identities() ['air_temperature', 'long_name=Air Temperature', 'foo=bar', 'standard_name=air_temperature', 'ncvar%tas'] >>> for i in f.identities(generator=True): ... print(i) ... air_temperature long_name=Air Temperature foo=bar standard_name=air_temperature ncvar%tas
- identity(default='')[source]¶
Return the canonical identity.
By default the identity is the first found of the following:
The
standard_nameproperty.The
cf_roleproperty, preceded by'cf_role='.The
long_nameproperty, preceded by'long_name='.The netCDF variable name, preceded by
'ncvar%'.The value of the default parameter.
Properties include any inherited properties.
Added in version (cfdm): 1.7.0
See also
- Parameters:
- default: optional
If no identity can be found then return the value of the default parameter.
- Returns:
The identity.
Examples
>>> f = cfdm.example_field(6) >>> d = f.constructs('longitude').value() >>> b = d.bounds >>> b <Bounds: longitude(2, 3, 4) degrees_east> >>> b.identity() 'longitude'
- inherited_properties()[source]¶
Return the properties inherited from a coordinate construct.
Added in version (cfdm): 1.7.0
See also
- Returns:
dictThe inherited properties.
Examples
>>> f = cfdm.example_field(6) >>> d = f.constructs('longitude').value() >>> b = d.bounds >>> b <Bounds: longitude(2, 3, 4) degrees_east>
>>> b.inherited_properties() {'units': 'degrees_east', 'standard_name': 'longitude'}
- insert_dimension(*args, **kwargs)[source]¶
Expand the shape of the data array.
Inserts a new size 1 axis into the data array.
Added in version (cfdm): 1.7.0
- Parameters:
- position:
int, optional Specify the position that the new axis will have in the data array. By default the new axis has position 0, the slowest varying position. Negative integers counting from the last position are allowed.
- Parameter example:
position=2- Parameter example:
position=-1
- inplace:
bool, optional If True then do the operation in-place and return
None.
- position:
- Returns:
Examples
>>> f.shape (19, 73, 96) >>> f.insert_dimension(position=3).shape (19, 73, 96, 1) >>> f.insert_dimension(position=-1).shape (19, 73, 1, 96)
- nc_clear_dataset_chunksizes()[source]¶
Clear the dataset chunking strategy for the data.
Added in version (cfdm): 1.12.2.0
- nc_clear_dimension_groups()[source]¶
Remove the netCDF dimension group hierarchy.
The group hierarchy is defined by the netCDF name. Groups are delimited by
/(slash) characters in the netCDF name. The groups are returned, in hierarchical order, as a sequence of strings. If the name is not set, or contains no/characters then an empty sequence is returned, signifying the root group.An alternative technique for removing the group structure is to set the netCDF dimension name, with
nc_set_dimension, with no/characters.Added in version (cfdm): 1.8.6
See also
Examples
>>> f.nc_set_dimension('time') >>> f.nc_dimension_groups() () >>> f.nc_set_dimension_groups(['forecast', 'model']) >>> f.nc_dimension_groups() ('forecast', 'model') >>> f.nc_get_dimension() '/forecast/model/time' >>> f.nc_clear_dimension_groups() ('forecast', 'model') >>> f.nc_get_dimension() 'time'
>>> f.nc_set_dimension('/forecast/model/time') >>> f.nc_dimension_groups() ('forecast', 'model') >>> f.nc_del_dimension('/forecast/model/time') '/forecast/model/time' >>> f.nc_dimension_groups() ()
- nc_clear_hdf5_chunksizes()[source]¶
Clear the HDF5 chunking strategy for the data.
Deprecated at version 1.12.2.0 and is no longer available. Use
nc_clear_dataset_chunksizesinstead.Added in version (cfdm): 1.12.0.0
- nc_clear_variable_groups()[source]¶
Remove the netCDF variable group hierarchy.
The group hierarchy is defined by the netCDF name. Groups are delimited by
/(slash) characters in the netCDF name. The groups are returned, in hierarchical order, as a sequence of strings. If the name is not set, or contains no/characters then an empty sequence is returned, signifying the root group.An alternative technique for removing the group structure is to set the netCDF variable name, with
nc_set_variable, with no/characters.Added in version (cfdm): 1.8.6
See also
Examples
>>> f.nc_set_variable('time') >>> f.nc_variable_groups() () >>> f.nc_set_variable_groups(['forecast', 'model']) >>> f.nc_variable_groups() ('forecast', 'model') >>> f.nc_get_variable() '/forecast/model/time' >>> f.nc_clear_variable_groups() ('forecast', 'model') >>> f.nc_get_variable() 'time'
>>> f.nc_set_variable('/forecast/model/time') >>> f.nc_variable_groups() ('forecast', 'model') >>> f.nc_del_variable('/forecast/model/time') '/forecast/model/time' >>> f.nc_variable_groups() ()
- nc_dataset_chunksizes(todict=False)[source]¶
Get the dataset chunking strategy for the data.
Added in version (cfdm): 1.12.2.0
- Parameters:
- Returns:
NoneorstrorintordictortupleofintThe current chunking strategy when writing to a netCDF4 file. One of:
None: No dataset chunking strategy has been defined. The chunking strategy will be determined at write time bycfdm.write.'contiguous': The data will be written to the file contiguously, i.e. no chunking.intorstr: The size in bytes of the dataset chunks. A string represents a quantity of byte units. “Square-like” chunk shapes are preferred, maximising the amount of chunks that are completely filled with data values (see thecfdm.writedataset_chunks parameter for details). For instance a chunksize of 1024 bytes may be specified with any of1024,'1024','1024 B','1 KiB','0.0009765625 MiB', etc. Recognised byte units are (case insensitive):B,KiB,MiB,GiB,TiB,PiB,KB,MB,GB,TB, andPB.tupleofint: The maximum number of array elements in a chunk along each data axis. This chunking strategy may get automatically modified by methods that change the data shape (such asinsert_dimension).dict: If todict is True, the maximum number of array elements in a chunk along each axis. This chunking strategy may get automatically modified by methods that change the data shape (such asinsert_dimension).
- nc_del_dimension(default=ValueError())[source]¶
Remove the netCDF dimension name.
Added in version (cfdm): 1.7.0
See also
- Parameters:
- default: optional
Return the value of the default parameter if the netCDF dimension name has not been set. If set to an
Exceptioninstance then it will be raised instead.
- Returns:
strThe removed netCDF dimension name.
Examples
>>> f.nc_set_dimension('time') >>> f.nc_has_dimension() True >>> f.nc_get_dimension() 'time' >>> f.nc_del_dimension() 'time' >>> f.nc_has_dimension() False >>> print(f.nc_get_dimension(None)) None >>> print(f.nc_del_dimension(None)) None
- nc_del_variable(default=ValueError())[source]¶
Remove the netCDF variable name.
Added in version (cfdm): 1.7.0
See also
- Parameters:
- default: optional
Return the value of the default parameter if the netCDF variable name has not been set. If set to an
Exceptioninstance then it will be raised instead.
- Returns:
strThe removed netCDF variable name.
Examples
>>> f.nc_set_variable('tas') >>> f.nc_has_variable() True >>> f.nc_get_variable() 'tas' >>> f.nc_del_variable() 'tas' >>> f.nc_has_variable() False >>> print(f.nc_get_variable(None)) None >>> print(f.nc_del_variable(None)) None
- nc_dimension_groups()[source]¶
Return the netCDF dimension group hierarchy.
The group hierarchy is defined by the netCDF name. Groups are delimited by
/(slash) characters in the netCDF name. The groups are returned, in hierarchical order, as a sequence of strings. If the name is not set, or contains no/characters then an empty sequence is returned, signifying the root group.Added in version (cfdm): 1.8.6
Examples
>>> f.nc_set_dimension('time') >>> f.nc_dimension_groups() () >>> f.nc_set_dimension_groups(['forecast', 'model']) >>> f.nc_dimension_groups() ('forecast', 'model') >>> f.nc_get_dimension() '/forecast/model/time' >>> f.nc_clear_dimension_groups() ('forecast', 'model') >>> f.nc_get_dimension() 'time'
>>> f.nc_set_dimension('/forecast/model/time') >>> f.nc_dimension_groups() ('forecast', 'model') >>> f.nc_del_dimension('/forecast/model/time') '/forecast/model/time' >>> f.nc_dimension_groups() ()
- nc_get_dimension(default=ValueError())[source]¶
Return the netCDF dimension name.
Added in version (cfdm): 1.7.0
See also
- Parameters:
- default: optional
Return the value of the default parameter if the netCDF dimension name has not been set. If set to an
Exceptioninstance then it will be raised instead.
- Returns:
strThe netCDF dimension name.
Examples
>>> f.nc_set_dimension('time') >>> f.nc_has_dimension() True >>> f.nc_get_dimension() 'time' >>> f.nc_del_dimension() 'time' >>> f.nc_has_dimension() False >>> print(f.nc_get_dimension(None)) None >>> print(f.nc_del_dimension(None)) None
- nc_get_variable(default=ValueError())[source]¶
Return the netCDF variable name.
Added in version (cfdm): 1.7.0
See also
- Parameters:
- default: optional
Return the value of the default parameter if the netCDF variable name has not been set. If set to an
Exceptioninstance then it will be raised instead.
- Returns:
strThe netCDF variable name. If unset then default is returned, if provided.
Examples
>>> f.nc_set_variable('tas') >>> f.nc_has_variable() True >>> f.nc_get_variable() 'tas' >>> f.nc_del_variable() 'tas' >>> f.nc_has_variable() False >>> print(f.nc_get_variable(None)) None >>> print(f.nc_del_variable(None)) None
- nc_has_dimension()[source]¶
Whether the netCDF dimension name has been set.
Added in version (cfdm): 1.7.0
See also
Examples
>>> f.nc_set_dimension('time') >>> f.nc_has_dimension() True >>> f.nc_get_dimension() 'time' >>> f.nc_del_dimension() 'time' >>> f.nc_has_dimension() False >>> print(f.nc_get_dimension(None)) None >>> print(f.nc_del_dimension(None)) None
- nc_has_variable()[source]¶
Whether the netCDF variable name has been set.
Added in version (cfdm): 1.7.0
See also
Examples
>>> f.nc_set_variable('tas') >>> f.nc_has_variable() True >>> f.nc_get_variable() 'tas' >>> f.nc_del_variable() 'tas' >>> f.nc_has_variable() False >>> print(f.nc_get_variable(None)) None >>> print(f.nc_del_variable(None)) None
- nc_hdf5_chunksizes(todict=False)[source]¶
Get the HDF5 chunking strategy for the data.
Deprecated at version 1.12.2.0 and is no longer available. Use
nc_dataset_chunksizesinstead.Added in version (cfdm): 1.11.2.0
- nc_set_dataset_chunksizes(chunksizes)[source]¶
Set the dataset chunking strategy.
Added in version (cfdm): 1.12.2.0
- Parameters:
- chunksizes:
Noneorstrorintorfloatordictor a sequence Set the chunking strategy for writing to a netCDF4 file. One of:
None: No dataset chunking strategy has been defined. The chunking strategy will be determined at write time bycfdm.write.'contiguous'The data will be written to the file contiguously, i.e. no chunking.
-
The size in bytes of the dataset chunks. A floating point value is rounded down to the nearest integer, and a string represents a quantity of byte units. “Square-like” chunk shapes are preferred, maximising the amount of chunks that are completely filled with data values (see the
cfdm.writedataset_chunks parameter for details). For instance a chunksize of 1024 bytes may be specified with any of1024,1024.9,'1024','1024.9','1024 B','1 KiB','0.0009765625 MiB', etc. Recognised byte units are (case insensitive):B,KiB,MiB,GiB,TiB,PiB,KB,MB,GB,TB, andPB. Spaces in strings are optional. -
The maximum number of array elements in a chunk along each data axis, provided in the same order as the data axes. Values are automatically limited to the full size of their corresponding data axis, but the special values
Noneor-1may be used to indicate the full axis size. This chunking strategy may get automatically modified by methods that change the data shape (such asinsert_dimension). -
The maximum number of array elements in a chunk along the axes specified by the dictionary keys. Integer values are automatically limited to the full size of their corresponding data axis, and the special values
Noneor-1may be used to indicate the full axis size. The chunk size for an unspecified axis defaults to an existing chunk size for that axis, if there is one, or else the axis size. This chunking strategy may get automatically modified by methods that change the data shape (such asinsert_dimension).Each dictionary key is an integer that specifies an axis by its position in the data array.
- chunksizes:
- Returns:
- nc_set_dimension(value)[source]¶
Set the netCDF dimension name.
If there are any
/(slash) characters in the netCDF name then these act as delimiters for a group hierarchy. By default, or if the name starts with a/character and contains no others, the name is assumed to be in the root group.Added in version (cfdm): 1.7.0
See also
Examples
>>> f.nc_set_dimension('time') >>> f.nc_has_dimension() True >>> f.nc_get_dimension() 'time' >>> f.nc_del_dimension() 'time' >>> f.nc_has_dimension() False >>> print(f.nc_get_dimension(None)) None >>> print(f.nc_del_dimension(None)) None
- nc_set_dimension_groups(groups)[source]¶
Set the netCDF dimension group hierarchy.
The group hierarchy is defined by the netCDF name. Groups are delimited by
/(slash) characters in the netCDF name. The groups are returned, in hierarchical order, as a sequence of strings. If the name is not set, or contains no/characters then an empty sequence is returned, signifying the root group.An alternative technique for setting the group structure is to set the netCDF dimension name, with
nc_set_dimension, with the group structure delimited by/characters.Added in version (cfdm): 1.8.6
See also
- Parameters:
- groups: sequence of
str The new group structure.
- groups: sequence of
- Returns:
Examples
>>> f.nc_set_dimension('time') >>> f.nc_dimension_groups() () >>> f.nc_set_dimension_groups(['forecast', 'model']) >>> f.nc_dimension_groups() ('forecast', 'model') >>> f.nc_get_dimension() '/forecast/model/time' >>> f.nc_clear_dimension_groups() ('forecast', 'model') >>> f.nc_get_dimension() 'time'
>>> f.nc_set_dimension('/forecast/model/time') >>> f.nc_dimension_groups() ('forecast', 'model') >>> f.nc_del_dimension('/forecast/model/time') '/forecast/model/time' >>> f.nc_dimension_groups() ()
- nc_set_hdf5_chunksizes(chunksizes)[source]¶
Set the HDF5 chunking strategy.
Deprecated at version 1.12.2.0 and is no longer available. Use
nc_set_dataset_chunksizesinstead.Added in version (cfdm): 1.11.2.0
- nc_set_variable(value)[source]¶
Set the netCDF variable name.
If there are any
/(slash) characters in the netCDF name then these act as delimiters for a group hierarchy. By default, or if the name starts with a/character and contains no others, the name is assumed to be in the root group.Added in version (cfdm): 1.7.0
See also
Examples
>>> f.nc_set_variable('tas') >>> f.nc_has_variable() True >>> f.nc_get_variable() 'tas' >>> f.nc_del_variable() 'tas' >>> f.nc_has_variable() False >>> print(f.nc_get_variable(None)) None >>> print(f.nc_del_variable(None)) None
- nc_set_variable_groups(groups)[source]¶
Set the netCDF variable group hierarchy.
The group hierarchy is defined by the netCDF name. Groups are delimited by
/(slash) characters in the netCDF name. The groups are returned, in hierarchical order, as a sequence of strings. If the name is not set, or contains no/characters then an empty sequence is returned, signifying the root group.An alternative technique for setting the group structure is to set the netCDF variable name, with
nc_set_variable, with the group structure delimited by/characters.Added in version (cfdm): 1.8.6
See also
- Parameters:
- groups: sequence of
str The new group structure.
- groups: sequence of
- Returns:
Examples
>>> f.nc_set_variable('time') >>> f.nc_variable_groups() () >>> f.nc_set_variable_groups(['forecast', 'model']) >>> f.nc_variable_groups() ('forecast', 'model') >>> f.nc_get_variable() '/forecast/model/time' >>> f.nc_clear_variable_groups() ('forecast', 'model') >>> f.nc_get_variable() 'time'
>>> f.nc_set_variable('/forecast/model/time') >>> f.nc_variable_groups() ('forecast', 'model') >>> f.nc_del_variable('/forecast/model/time') '/forecast/model/time' >>> f.nc_variable_groups() ()
- nc_variable_groups()[source]¶
Return the netCDF variable group hierarchy.
The group hierarchy is defined by the netCDF name. Groups are delimited by
/(slash) characters in the netCDF name. The groups are returned, in hierarchical order, as a sequence of strings. If the name is not set, or contains no/characters then an empty sequence is returned, signifying the root group.Added in version (cfdm): 1.8.6
Examples
>>> f.nc_set_variable('time') >>> f.nc_variable_groups() () >>> f.nc_set_variable_groups(['forecast', 'model']) >>> f.nc_variable_groups() ('forecast', 'model') >>> f.nc_get_variable() '/forecast/model/time' >>> f.nc_clear_variable_groups() ('forecast', 'model') >>> f.nc_get_variable() 'time'
>>> f.nc_set_variable('/forecast/model/time') >>> f.nc_variable_groups() ('forecast', 'model') >>> f.nc_del_variable('/forecast/model/time') '/forecast/model/time' >>> f.nc_variable_groups() ()
- persist(*args, **kwargs)[source]¶
Persist data into memory.
Persisting turns an underlying lazy dask array into an equivalent chunked dask array, but now with the results fully computed and cached in memory. This can avoid the expense of re-reading the data from disk, or re-computing it, when the data is accessed on multiple occasions.
Performance
persistcauses delayed operations to be computed.Added in version (cfdm): 1.12.0.0
See also
- properties()[source]¶
Return all properties.
Added in version (cfdm): 1.7.0
See also
- Returns:
dictThe properties.
Examples
>>> f = cfdm.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() {}
- replace_directory(old=None, new=None, normalise=False, common=False)[source]¶
Replace a file directory in-place.
Added in version (cfdm): 1.12.0.0
See also
- Parameters:
- old:
strorNone, optional The base directory structure to be replaced by new. If
None(the default) or an empty string, and normalise is False, then new (if set) is prepended to each file name.- new:
strorNone, optional The new directory that replaces the base directory structure identified by old. If
None(the default) or an empty string, then old (if set) is replaced with an empty string.- normalise:
bool, optional If True then old and new directories, and the file names, are normalised to absolute paths prior to the replacement. If False (the default) then no normalisation is done.
- common:
bool, optional If True the base directory structure that is common to all files with new.
- old:
- Returns:
- 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 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.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.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.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
- squeeze(*args, **kwargs)[source]¶
Remove size one axes from the data array.
By default all size one axes are removed, but particular size one axes may be selected for removal.
Added in version (cfdm): 1.7.0
See also
- Parameters:
- axes: (sequence of)
int, optional The positions of the size one axes to be removed. By default all size one axes are removed.
Each axis is identified by its integer position in the data. Negative integers counting from the last position are allowed.
- Parameter example:
axes=0- Parameter example:
axes=-1- Parameter example:
axes=[1, -2]
- inplace:
bool, optional If True then do the operation in-place and return
None.
- axes: (sequence of)
- Returns:
Examples
>>> f = cfdm.Bounds() >>> d = cfdm.Data(numpy.arange(7008).reshape((1, 73, 1, 96))) >>> f.set_data(d) >>> f.shape (1, 73, 1, 96) >>> f.squeeze().shape (73, 96) >>> f.squeeze(0).shape (73, 1, 96) >>> f.squeeze([-3, 2]).shape (73, 96)
- to_memory(*args, **kwargs)[source]¶
Bring data on disk into memory.
There is no change to data that is already in memory.
- transpose(*args, **kwargs)[source]¶
Permute the axes of the data array.
Added in version (cfdm): 1.7.0
See also
- Parameters:
- axes: (sequence of)
int, optional The new axis order. By default the order is reversed.
Each axis is identified by its integer position in the data. Negative integers counting from the last position are allowed.
- Parameter example:
axes=0- Parameter example:
axes=-1- Parameter example:
axes=[1, -2]
- inplace:
bool, optional If True then do the operation in-place and return
None.
- axes: (sequence of)
- Returns:
Examples
>>> f.shape (19, 73, 96) >>> f.transpose().shape (96, 73, 19) >>> f.transpose([1, 0, 2]).shape (73, 19, 96)
- uncompress(*args, **kwargs)[source]¶
Uncompress the construct.
Whether or not the construct is compressed does not alter its functionality nor external appearance.
A construct that is already uncompressed will be returned uncompressed.
The following type of compression are available:
Ragged arrays for discrete sampling geometries (DSG). Three different types of ragged array representation are supported.
Compression by gathering.
Compression by coordinate subsampling
Added in version (cfdm): 1.7.11
- Parameters:
- Returns:
Examples
>>> f.data.get_compression_type() 'ragged contiguous' >>> g = f.uncompress() >>> g.data.get_compression_type() '' >>> g.equals(f) True
- property array¶
A numpy array deep copy of the data.
Changing the returned numpy array does not change the data array.
Added in version (cfdm): 1.10.0.0
See also
Examples
>>> f.data <Data(5): [0, ... 4] kg m-1 s-2> >>> a = f.array >>> type(a) <type 'numpy.ndarray'> >>> print(a) [0 1 2 3 4] >>> a[0] = 999 >>> print(a) [999 1 2 3 4] >>> print(f.array) [0 1 2 3 4] >>> f.data <Data(5): [0, ... 4] kg m-1 s-2>
- 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
- Returns:
DataThe data.
Examples
>>> f = cfdm.Bounds() >>> f.set_data(cfdm.Data(numpy.arange(10.))) >>> f.has_data() True >>> d = f.data >>> d <Data(10): [0.0, ..., 9.0]> >>> f.data.shape (10,)
- property datetime_array¶
An independent numpy array of date-time objects.
Only applicable for data with reference time units.
If the calendar has not been set then the CF default calendar will be used and the units will be updated accordingly.
Added in version (cfdm): 1.10.0.0
Examples
>>> f.units 'days since 2000-01-01' >>> print(f.array) [ 0 31 60 91] >>> print(f.datetime_array) [cftime.DatetimeGregorian(2000-01-01 00:00:00) cftime.DatetimeGregorian(2000-02-01 00:00:00) cftime.DatetimeGregorian(2000-03-01 00:00:00) cftime.DatetimeGregorian(2000-04-01 00:00:00)]
- 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