cf.Field.coord

Field.coord(arg, role=None, key=False, exact=False, dim=False, one_d=False, maximal_match=True)

Return a coordinate of the field.

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

>>> f.coord('height').long_name
AttributeError: 'Coordinate' object has no CF property 'long_name'
>>> f.coord('hei').long_name = 'HEIGHT'
>>> f.coord('heigh').long_name
'HEIGHT'

Or a deep copy may be made:

>>> c = f.coord('height').copy()
Parameters :
arg : str or dict or int

The identify of the coordinate. One of:

  • A string containing (an abbreviation) of its standard name (such as ‘time’).
  • A string containing its identifier in the field’s space (such as ‘dim2’).
  • A dictionary containing one or more (abbreviations of ) property names and their values as its key/value pairs (such as {‘long_name’: ‘something’}). If two or more properties are specified then the returned coordinate must satisfy all criteria, unless maximal_match is False in which case the returned coordinate will satisfy all criteria at least one of the criteria.
  • An integer given the position of a dimension in the field’s data array.
exact : bool, optional

If True then assume that the value of a name given by arg is exact. By default it is considered to be an abbreviation.

key : bool, optional

Return the field’s space’s identifier for the coordinate.

role : bool, optional

Restrict the search to coordinates of the given role. Valid values are ‘dim’ and ‘aux’, for dimension and auxiliary coordinate constructs. By default both types are considered.

Returns :
out : Coordinate or str or None

The requested coordinate, or the field’s space’s identifier for the coordinate, or None if no coordinate could be found.

Examples

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

Previous topic

cf.Field.clip

Next topic

cf.Field.copy

This Page