cf.Field.coord

Field.coord(arg, role=None, key=False, exact=False, dimensions=False, one_d=False, maximal_match=True)[source]

Return a coordinate of the domain.

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

>>> f.coord('height').long_name
AttributeError: Coordinate has no CF property 'long_name'
>>> f.coord('height').long_name = 'height'
>>> f.coord('height').long_name
'height'
Parameters :
arg : str or dict or int

The identify of the coordinate. One of:

  • A string containing an unambiguous abbreviation (see the exact parameter) of its identity as returned by the coordinate’s identity.
  • A string containing a 1-d coordinate’s dimension identifier in the domain (see the cf.Domain.coordinates method).
  • A dictionary containing one or more CF property names and their unambiguous abbreviations (see the exact parameter) values as its key/value pairs (such as {'long_name': 'temperature'}). See the maximal_match parameter for when two or more properties are specified in this manner.
  • An integer giving the position of a 1-d coordinate’s dimension in the field’s data array (negative integers count from the slowest moving domension).
exact : bool, optional

If True then do not string abbreviations given by the arg parameter will not match, nor will different but equivalent units. By default unambiguous string abbreviations will match, as will different but equivalent units.

role : str, optional

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

one_d : bool, optional

Restrict the search to one dimensionsal coordinates. By default coordinates with any number of dimensions are considered.

key : bool, optional

If True then return the domain’s identifier for the coordinate. By default the unique coordinate itself is returned.

dimensions : bool, optional

If True then return a list of the unique coordinate’s dimensions described by their domain identifiers. By default the unique coordinate itself is returned.

maximal_match : bool, optional

If False and two or more properties are specified by the arg parameter then a unique coordinate will satisfy at least one of the properties’ criteria. By default a unique coordinate will satisfy all of the properties’ criteria.

Returns :
out : Coordinate or str or list or None

The unique coordinate or, if key is True, the unique coordinate’s identifier in the domain or, if dimensions is True, the unique coordinate’s dimensions described by their domain identifiers, if no unique coordinate could be found, None.

Examples

>>> print f
Data            : air_temperature(time(12), latitude(73), longitude(96)) K
Cell methods    : time: mean
Dimensions      : time(12) = [15, ..., 345] days since 1860-1-1
                : latitude(73) = [-90, ..., 90] degrees_north
                : longitude(96) = [0, ..., 356.25] degrees_east
                : height(1) = [2] m
>>> f.domain['dim2'].properties
{'_FillValue': None,
 'axis': 'X',
 'long_name': 'longitude',
 'standard_name': 'longitude',
 'units': 'degrees_east'}
>>> f.domain['dim2'].shape
(360,)
>>> f.coord('longitude')
<CF Coordinate: longitude(96)>
>>> f.coord('long')
<CF Coordinate: longitude(96)>
>>> f.coord('long', key=True)
'dim2'
>>> f.coord('long', dimensions=True)
['dim2']
>>> f.coord('long', oned_d=True)
<CF Coordinate: longitude(96)>
>>> f.coord('lon', exact=True)
None
>>> f.coord('longitude', exact=True)
<CF Coordinate: longitude(96)>
>>> f.coord({'standard_name': 'long', 'axis': X})
<CF Coordinate: longitude(96)>
>>> f.coord({'standard_name': 'long', 'axis': 'X'}, maximal_match=False)
<CF Coordinate: longitude(96)>
>>> f.coord({'standard_name': 'long', 'axis': 'Y'})
None
>>> f.coord({'standard_name': 'long', 'axis': 'Y'}, maximal_match=False)
<CF Coordinate: longitude(96)>
>>> f.coord('long', role='dim')
<CF Coordinate: longitude(96)>
>>> f.coord('long', role='aux')
None

Previous topic

cf.Field.close

Next topic

cf.Field.copy

This Page