cf.Space

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

Bases: cf.utils.CfDict

Completely describe a field’s coordinate system (space).

It contains the dimension constructs, auxiliary coordinate constructs, cell measure constructs and transform constructs defined by the CF data model.

The space is a dictionary-like object whose key/value pairs identify and store the coordinate and cell measure constructs which describe it.

The dimensionality of the space’s components and its transforms are stored as attributes.

Initialization

Parameters :
*args, **kwargs

Keys and values are initialized exactly as for a built-in dict. Keys are coordinate and cell measure construct identifiers (such as dim1, aux0, and cm2) and values are coordinate and cell measure instances.

add_coordinate(coord, dim_name_map=None, dim=False, aux=False, space=None, key=None)

Add a new dimension or auxiliary coordinate to the space in place.

Parameters :
coord : Coordinate

The new coordinate.

dim_name_map : dict, optional

dim : bool, optional

True if the new coordinate is to be a dimension coordinate.

aux : bool, optional

True if the new coordinate is to be an auxiliary coordinate.

space : Space, optional

Provide a space which contains both the new coordinate and its transforms, thus enabling transforms of the new coordinate to be included. By default, transforms of the new coordinate are not included.

key : str, optional

The identifier for the new coordinate. By default a unique identifier will be generated.

Returns :

None

Examples

>>>
aux_coords(dim=None)

Return a dictionary whose values are the auxiliary coordinates which span the given dimension with keys of the space’s auxiliary coordinate keys.

Parameters :
dim : str, optional

The identifier of the dimension to be spanned. By default all dimensions are considered (so all auxiliary coordinate are returned).

Returns :
out : dict

The auxiliary coordinate objects and their identifiers.

Examples

>>> s.dimensions
{'data': ['dim0', 'dim1', 'dim2'],
 'aux0': ['dim1', 'dim2'],
 'aux1': ['dim0'],
 'aux2': ['dim2', 'dim1'],
 'dim0': ['dim0'],
 'dim1': ['dim1'],
 'dim2': ['dim2']}
>>> s.aux_coords()
{'aux0': <CF Coordinate>,
 'aux1': <CF Coordinate>,
 'aux2': <CF Coordinate>}
>>> s.aux_coords('dim2')
{'aux0': <CF Coordinate>,
 'aux2': <CF Coordinate>}
coord(arg, role=None, key=False, exact=False, maximal_match=True)

Find a coordinate of the space by name. Refer to cf.Field.coord for details.

copy()

Return a deep copy.

Equivalent to copy.deepcopy(x)

Returns :
out :

The deep copy.

Examples

>>> x.copy()
direction(dim)
dump(id=None, omit=())

Return a string containing a full description of the space.

Parameters :
id: str, optional

Set the common prefix of variable component names. Defaults to to the class name.

Returns :
out : str

A string containing the description of the space.

Examples

>>> s.dump()
>>> s.dump(id='foobar')
equals(other, rtol=None, atol=None)

Return True if two spaces are equal.

Equality is defined as follows:

  • There is one-to-one coorespondence between dimensions and dimension sizes between the two spaces.
  • For each space component type (dimension coordinate, auxiliary coordinate and cell measures), the set of constructs in one space equals that of the other space. The component indentifiers need not be the same.
  • The set of transforms in one space equals that of the other space. The transform indentifiers need not be the same.

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

Parameters :
other : Space

The other space.

Returns :
out : bool

True if the two spaces are equal, False otherwise.

Examples

>>> s.equals(t)
True
expand_dims(coord=None, size=1)

Expand the space with a new dimension in place.

The new dimension may by of any size greater then 0.

Parameters :
coord : Coordinate, optional

A dimension coordinate for the new dimension. The new dimenion’s size is set to the size of the coordinate’s array.

size : int, optional

The size of the new dimension. By default a dimension of size 1 is introduced. Ignored if coord is set.

Returns :

None

Examples

>>> s.expand_dims()
>>> s.expand_dims(size=12)
>>> c
<CF Coordinate: >
>>> s.expand_dims(coord=c)
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(k) → True if CFD has a key k, else False
new_auxiliary()

Return a new

new_dimension()

Return a new

new_transform()

Return a new

remove_coordinate(key)

Remove a coordinate from the space in place.

Parameters :
key : str

The coordinate’s identifier.

Returns :

None

Examples

>>> s.remove_coordinate('dim0')
>>> s.remove_coordinate('aux1')
squeeze(dim)

Remove a size 1 dimension from the space in place.

If the dimension has a dimension coordinate then it is removed, as are 1-d auxiliary coordinates and cell measures which span the dimension. The dimension is squeezed from multidimensional auxiliary coordinates and cell measures if they span it.

The dimension is not squeezed from the field’s data array if it spans it, therefore the field’s data array may need to be squeezed concurrently.

Parameters :
dim : str

The identifier of the dimension to remove.

Returns :

None

Examples

>>> s.dimension_sizes
{'dim0': 12, 'dim1': 73, 'dim2': 1}
>>> s.dimensions
{'data': ['dim0', 'dim1', 'dim2'],
 'aux0': ['dim1', 'dim2'],
 'aux1': ['dim2', 'dim1'],
 'dim0': ['dim0'],
 'dim1': ['dim1'],
 'dim2': ['dim2'],
 'cm0' : ['dim1', 'dim2']}
>>> s.squeeze('dim2')
>>> s.dimension_sizes
{'dim0': 12, 'dim1': 73}
>>> s.dimensions
{'data': ['dim0', 'dim1', 'dim2'],
 'aux0': ['dim1'],
 'aux1': ['dim1'],
 'dim0': ['dim0'],
 'dim1': ['dim1'],
 'cm0' : ['dim1']}
dimension_sizes = None

The sizes of the space’s dimensions.

Examples

>>> s.dimension_sizes
{'dim2': 96,
 'dim1': 73,
 'dim0': 1}
dimensions = None

The dimensions of each of the space’s components and of the its field’s data array.

>>> s.dimensions
{'data': ['dim0', 'dim1', 'dim2'],
 'aux0': ['dim1', 'dim2'],
 'aux1': ['dim2', 'dim1'],
 'dim0': ['dim0'],
 'dim1': ['dim1'],
 'dim2': ['dim2'],
 'cm0' : ['dim1', 'dim2']}
transforms = None

The space’s transform constructs.

>>> s.transforms
{'trans0': <CF Transform: ocean_sigma_z_coordinate>
>>> type(s.transforms)
'cf.utils.CfDict'

Previous topic

cf.Flags

Next topic

cf.Transform

This Page