cf.Transform

class cf.Transform(*args, **kwargs)

Bases: cf.space.CfDict

A CF transform object defining a coordinate’s transformation in a dictionary-like object.

The named parameters and their values of the transformation (i.e. the transformation’s mappings) comprise the object’s key-value pairs.

A transformation is equivalent to either a netCDF(CF) ‘formula_terms’ or ‘grid_mapping’ property. The latter is identified by the presence of the ‘grid_mapping_name’ key which contains the mapping’s name.

In the ‘formula_terms’ case, a mapping to a coordinate uses the coordinate’s grid key name as a value. A mapping to another space might be a shallow copy of another space in memory.

Parameters:
  • *args

    Keys and values are initialized exactly as for a built-in dict.

  • **kwargs

    Keys and values are initialized exactly as for a built-in dict.

Overloaded operators

The in (set membership) operator is overloaded to use numerically tolerant equality.

Examples

>>> t
<CF Transform: atmosphere_sigma_coordinate>
>>> dump(t)
atmosphere_sigma_coordinate transform
-------------------------------------
Transform['ps'] = <CF Space: surface_air_pressure(73, 96)>
Transform['ptop'] = 0.05
Transform['sigma'] = 'dim0'
>>> t
<CF Transform: rotated_latitude_longitude>
>>> dump(t)
rotated_latitude_longitude transformation
-----------------------------------------
Transform['grid_mapping_name'] = 'rotated_latitude_longitude'
Transform['grid_north_pole_latitude'] = 33.67
Transform['grid_north_pole_longitude'] = 190.0
Attribute (type) Description
transform_name (str) Optional. The identifying name of the transformation. Typically a netCDF(CF) ‘formula_terms’ or ‘grid_mapping_name’.
_atol (NoneType or float) Optional. Absolute tolerance for numeric equality. Unset is equivalent to None, which implies a default value. Refer to cf.
_rtol (NoneType or float) Optional. Relative tolerance for numeric equality. Unset is equivalent to None, which implies a default value. Refer to cf.
Method Description
clear() As for a built-in dict.
copy() Create a deep copy.
equals() Determine whether two instances are congruent with each other.
get() As for a built-in dict.
get_keys() Return grid keys which match a pattern.
has_key() As for a built-in dict but using numerically tolerant equality.
items`() As for a built-in dict.
iteritems() As for a built-in dict.
iterkeys() As for a built-in dict.
itervalues() As for a built-in dict.
keys() As for a built-in dict.
pop() As for a built-in dict.
popitem() As for a built-in dict.
properties() Return a set of writable, public attributes.
setdefault() As for a built-in dict.
update() As for a built-in dict.
values() As for a built-in dict.
dump(id=None, nc=False, omit=())

Return a string containing a full description of the transformation.

Parameters:
  • id (str) – Optional. Set the common prefix of component names. If None then defaults to the class name.
  • nc (bool) – Optional. If True then include attributes whose names begin “nc”.
  • omit (sequence) – Optional. Omit the given attributes from the description.
Returns:

A string containing the description of the object.

See also

cf.dump()

equals(other, rtol=None, atol=None, override=True)

Return True if two instances are congruent in that they have the equal sets of keys and for each key, the two values are equal.

Equality of numbers is to within a tolerance. Refer to cf for details.

Parameters:
  • other (object) – The variable to compare against for equality.
  • atol (None or float) – Optional. If None then use the default method for setting the absolute tolerance for equality of real numbers (refer to cf for details). If a float then set the absolute tolerance to this value for all comparisons (refer to the override parameter).
  • override (bool) – Optional. If False then only use a float value of the rtol or atol parameters if it can not be set from attributes of the objects being compared.
  • rtol (None or float) – Optional. If None then use the default method for setting the relative tolerance for equality of real numbers (refer to cf for details). If a float then set the relative tolerance to this value for all comparisons (refer to the override parameter).
Returns:

True if the two objects are congruent, False otherwise.

get_keys(regex)

Return a list of the cf dictionary’s key names which, at their beginning, match the given regular expression.

Parameters:regex (str) – The regular expression with which to identify key names. A leading ‘^’ special character is assumed if not given.
Returns:A list of keys names.

Examples

>>> d.keys()
['dim2', 'dim0', 'dim1', 'aux0', 'cm0']
>>> d.get_keys('dim')
['dim2', 'dim0', 'dim1']
>>> d.get_keys('aux|dim')
['dim2', 'dim0', 'dim1', 'aux0']
>>> d.get_keys('dim[12]')
['dim2', 'dim1']
has_key(key)
Returns:True if the key exists, using numerically tolerant equality.
properties(nc=False)

Return a set of writable, public attribute names, excluding methods.

An attribute created by assigning directly to the __dict__ dictionary (as opposed to using setattr()) will not appear in this set.

Parameters:nc (bool) – If False then exclude attributes whose names begin “nc”.
Returns:A set of attribute names.

Previous topic

cf.SpaceList

Next topic

cf.Variable

This Page