cfdm.datum¶
Classes
|
A datum component of a CF data model coordinate reference. |
- class cfdm.datum.Datum(parameters=None, source=None, copy=True)[source]¶
Bases:
Parameters,NetCDFVariable,Files,DatumA datum component of a CF data model coordinate reference.
A datum is a complete or partial definition of the zeroes of the dimension and auxiliary coordinate constructs which define a coordinate system.
The datum may contain the definition of a geophysical surface which corresponds to the zero of a vertical coordinate construct, and this may be required for both horizontal and vertical coordinate systems.
Elements of the datum not specified may be implied by the properties of the dimension and auxiliary coordinate constructs referenced by the
CoordinateReferenceinstance that contains the datum.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.Added in version (cfdm): 1.7.0
Initialisation
- Parameters:
- parameters:
dict, optional Set parameters. The dictionary keys are parameter names, with corresponding values.
Parameters may also be set after initialisation with the
set_parametersandset_parametermethods.- Parameter example:
parameters={'earth_radius': 6371007.}
- source: optional
Convert source, which can be any type of object, to a
Datuminstance.All other parameters, apart from copy, are ignored and their values are instead inferred from source by assuming that it has the
DatumAPI. Any parameters that can not be retrieved from source in this way are assumed to have their default value.Note that if
xis also aDatuminstance thencfdm.Datum(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.
- parameters:
- clear_parameters()[source]¶
Remove all parameters.
Added in version (cfdm): 1.7.0
See also
- Returns:
dictThe parameters that have been removed.
Examples
>>> f = cfdm.Datum() >>> f.parameters() {} >>> p = {'standard_parallel': 25.0, ... 'longitude_of_central_meridian': 265.0, ... 'latitude_of_projection_origin': 25.0} >>> f.set_parameters(p) >>> f.parameters() {'standard_parallel': 25.0, 'longitude_of_central_meridian': 265.0, 'latitude_of_projection_origin': 25.0}
>>> old = f.clear_parameters() >>> old {'standard_parallel': 25.0, 'longitude_of_central_meridian': 265.0, 'latitude_of_projection_origin': 25.0} >>> f.set_parameters(old)
- copy()[source]¶
Return a deep copy.
f.copy()is equivalent tocopy.deepcopy(f).Added in version (cfdm): 1.7.0
- Returns:
DatumThe deep copy.
Examples
>>> f = cfdm.Datum() >>> g = f.copy()
- creation_commands(namespace=None, indent=0, string=True, name='p', header=True)[source]¶
Return the commands that would create the component.
Added in version (cfdm): 1.12.2.0
See also
- Parameters:
- 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
Datuminstance created by the returned commands.- header:
bool, optional If True (the default) output a comment describing the components. If False no such comment is returned.
- namespace:
- Returns:
Examples
>>> x = cfdm.Datum({'algorithm': 'granular_bitround'}) >>> x.nc_set_variable('var') >>> print(x.creation_commands(header=False)) p = cfdm.Datum() p.set_parameters({'algorithm': 'granular_bitround'}) p.nc_set_variable('var')
- del_parameter(parameter, default=ValueError())[source]¶
Delete a parameter.
Added in version (cfdm): 1.7.0
See also
- Parameters:
- Returns:
The removed parameter value.
Examples
>>> f = cfdm.Datum() >>> f.set_parameter('earth_radius', 6371007) >>> f.has_parameter('earth_radius') True >>> f.get_parameter('earth_radius') 6371007 >>> f.del_parameter('earth_radius') 6371007 >>> f.has_parameter('earth_radius') False >>> print(f.del_parameter('earth_radius', None)) None >>> print(f.get_parameter('earth_radius', None)) None
- equals(**kwargs)[source]¶
Whether two instances are the same.
Equality is strict by default. This means that:
the named parameters must be the same, with the same values and data types, and vector-valued parameters must also have same the size 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.
- 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_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_type:
bool, optional Any type of object may be tested but, in general, equality is only possible with another
Datuminstance, or a subclass of one. If ignore_type is True thencfdm.Datum(source=other)is tested, rather than theotherdefined by the other parameter.- 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.
- Returns:
boolWhether the two instances are equal.
Examples
>>> d.equals(d) True >>> d.equals(d.copy()) True >>> d.equals(None) False
- 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
Datumshould 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
Datumwill not generally change the collection of original files. However if theDatumwas 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_parameter(parameter, default=ValueError())[source]¶
Get a parameter value.
Added in version (cfdm): 1.7.0
- Parameters:
- Returns:
The value of the parameter.
Examples
>>> f = cfdm.Datum() >>> f.set_parameter('earth_radius', 6371007) >>> f.has_parameter('earth_radius') True >>> f.get_parameter('earth_radius') 6371007 >>> f.del_parameter('earth_radius') 6371007 >>> f.has_parameter('earth_radius') False >>> print(f.del_parameter('earth_radius', None)) None >>> print(f.get_parameter('earth_radius', None)) None
- has_parameter(parameter)[source]¶
Whether a parameter has been set.
Added in version (cfdm): 1.7.0
See also
- Parameters:
- parameter:
str The name of the parameter.
- Parameter example:
parameter='geoid_name'
- parameter:
- Returns:
boolTrue if the parameter has been set, otherwise False.
Examples
>>> f = cfdm.Datum() >>> f.set_parameter('earth_radius', 6371007) >>> f.has_parameter('earth_radius') True >>> f.get_parameter('earth_radius') 6371007 >>> f.del_parameter('earth_radius') 6371007 >>> f.has_parameter('earth_radius') False >>> print(f.del_parameter('earth_radius', None)) None >>> print(f.get_parameter('earth_radius', None)) None
- 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_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_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_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_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() ()
- parameters()[source]¶
Return all parameters.
Added in version (cfdm): 1.7.0
See also
clear_parameters,get_parameter,has_parameterset_parameters- Returns:
dictThe parameters.
Examples
>>> f = cfdm.Datum() >>> f.parameters() {} >>> p = {'standard_parallel': 25.0, ... 'longitude_of_central_meridian': 265.0, ... 'latitude_of_projection_origin': 25.0} >>> f.set_parameters(p) >>> f.parameters() {'standard_parallel': 25.0, 'longitude_of_central_meridian': 265.0, 'latitude_of_projection_origin': 25.0}
>>> old = f.clear_parameters() >>> old {'standard_parallel': 25.0, 'longitude_of_central_meridian': 265.0, 'latitude_of_projection_origin': 25.0} >>> f.set_parameters(old)
- set_parameter(term, value, copy=True)[source]¶
Set a parameter-valued term.
Added in version (cfdm): 1.7.0
See also
- Returns:
Examples
>>> f = cfdm.Datum() >>> f.set_parameter('earth_radius', 6371007) >>> f.has_parameter('earth_radius') True >>> f.get_parameter('earth_radius') 6371007 >>> f.del_parameter('earth_radius') 6371007 >>> f.has_parameter('earth_radius') False >>> print(f.del_parameter('earth_radius', None)) None >>> print(f.get_parameter('earth_radius', None)) None
- set_parameters(parameters, copy=True)[source]¶
Set parameters.
Added in version (cfdm): 1.7.0
See also
- Parameters:
- Returns:
Examples
>>> f = cfdm.Datum() >>> f.parameters() {} >>> p = {'standard_parallel': 25.0, ... 'longitude_of_central_meridian': 265.0, ... 'latitude_of_projection_origin': 25.0} >>> f.set_parameters(p) >>> f.parameters() {'standard_parallel': 25.0, 'longitude_of_central_meridian': 265.0, 'latitude_of_projection_origin': 25.0}
>>> old = f.clear_parameters() >>> old {'standard_parallel': 25.0, 'longitude_of_central_meridian': 265.0, 'latitude_of_projection_origin': 25.0} >>> f.set_parameters(old)