cf.Domain.coord

Domain.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.
  • 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 : cf.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

>>> d['dim2'].shape
(360,)
>>> d['dim2'].properties
{'_FillValue': None,
 'axis': 'X',
 'long_name': 'longitude',
 'standard_name': 'longitude',
 'units': 'degrees_east'}
>>> d.coord('longitude')
<CF Coordinate: longitude(360)>
>>> d.coord('long')
<CF Coordinate: longitude(360)>
>>> d.coord('long', key=True)
'dim2'
>>> d.coord('long', dimensions=True)
['dim2']
>>> d.coord('long', oned_d=True)
<CF Coordinate: longitude(360)>
>>> d.coord('lon', exact=True)
None
>>> d.coord('longitude', exact=True)
<CF Coordinate: longitude(360)>
>>> d.coord({'standard_name': 'long', 'axis': X})
<CF Coordinate: longitude(360)>
>>> d.coord({'standard_name': 'long', 'axis': 'X'}, maximal_match=False)
<CF Coordinate: longitude(360)>
>>> d.coord({'standard_name': 'long', 'axis': 'Y'})
None
>>> d.coord({'standard_name': 'long', 'axis': 'Y'}, maximal_match=False)
<CF Coordinate: longitude(360)>
>>> d.coord('long', role='dim')
<CF Coordinate: longitude(360)>
>>> d.coord('long', role='aux')
None

Previous topic

cf.Domain.close

Next topic

cf.Domain.coordinates

This Page