cf.Grid

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

Bases: cf.utils.CfDict

A CF grid object defining a space’s dimensionality, coordinates, cell measures and transformations in a dictionary-like object. Refer to the Grid Structure section of the cf module for details.

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.

Special attributes:

Attribute Description
dimension_sizes The size of each dimension.
dimensions The dimensions belonging to each grid component.
nc_dimensions The netCDF dimension name for each dimension in the dimension_sizes attribute. If present when the grid is written to a netCDF file, then used for output netCDF dimension names.
transform A dictionary of Transform objects.

Methods and attributes defined here:

coord(name, role=None, key=False, exact=False)

Find a coordinate of the grid by name.

The given name argument is an abbreviation for (or equal to if the exact parameter is True) the standard name of desired coordinate If the key parameter is True then return the coordinate’s grid key name instead of the Coordinate variable. If a coordinate does not have standard_name attribute, then name will be matched against its ncvar attribute is used.

Note that the returned coordinate is an object identity to the coordinate stored in the grid so, for example, a coordinate’s attributes may be changed in-place as follows:

>>> g.coord('height').long_name
AttributeError: 'Coordinate' object has no attribute 'long_name'
>>> g.coord('hei').long_name = 'HEIGHT'
>>> g.coord('heigh').long_name
'HEIGHT'

Or a deep copy may be made with the coordinate’s copy method:

>>> h = g.coord('height').copy()
Parameters:
  • name (str) – The string to identify a coordinate by name.
  • exact (bool) – Optional. If True then assume that the value of the name argument is equal to exactly one coordinate’s name.
  • key (str) – Optional. Return the grid key name instead of the coordinate.
  • role (str or None) – Optional. Restrict the search to coordinates of the given role. Valid values are ‘dim’ and ‘aux’, for dimension and auxiliary coordinate types respectively. If None then both types of coordinates will be searched.
Returns:

If a coordinate has been identified, return either a Coordinate instance or, if the keys parameter is True, a grid key name string. otherwise, return None.

Examples:

>>> g.coord('lon')
<CF Coordinate: longitude(128)>
>>> g.coord('lon', key=True)
'dim2'
>>> g.coord('lonX', key=True)
None
>>> g.coord('lon', exact=True)
None
>>> g.coord('longitude', exact=True)
<CF Coordinate: longitude(128)>
copy()

CFD.copy() -> a deep copy of CFD

dump(id=None, omit=())

Return a string containing a full description of the grid.

Parameters:
  • idOptional. Set the common prefix of variable component names. If None then defaults to the class name.
  • id – str
  • omit (sequence) – Optional. Omit the given attributes the description.
Returns:

A string containing the description of the grid.

See also

cf.dump

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

Return True if two instances are congruent in that

  1. For each group of grid component types (dimension coordinate, auxiliary coordinate, cell measures, etc.) there are an equal number of keys and each key’s value equals a value in the other grid. Note that within a group of component types, the key names need not be the same.
  2. Each dimension in one grid has an equally sized dimension in the other grid.
  3. The unordered set of transforms in one grid equals that of the other grid. Noe that The keys of the transform attribute dictionary need not be the same.

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 numerical equality (refer to cf for details). If a number then set the absolute tolerance to this value for all such comparisons.
  • rtol (None or float) – Optional. If None then use the default method for setting the relative tolerance for numerical equality (refer to cf for details). If a number then set the relative tolerance to this value for all such comparisons.
Returns:

True if the two objects are congruent, False otherwise.

get_keys(regex=None)

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

Parameters:regex (str) – Optional. The regular expression with which to identify key names.
Returns:A list of keys names.

Examples:

>>> d.keys()
['dim2', 'dim0', 'dim1', 'aux0', 'cm0']
>>> d.get_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[123]')
['dim2', 'dim1']
has_key(key)

CFD.has_key(k) -> True if CFD has a key k, else False

Previous topic

cf.CellMeasures

Next topic

cf.Transform

This Page