cf.Field.refs¶
-
Field.
refs
(description=None, axes=None, axes_all=None, axes_subset=None, axes_superset=None, ndim=None, match_and=True, exact=False, inverse=False, copy=False)[source]¶ Return coordinate reference objects.
In this documentation, a coordinate reference object is referred to as an item.
Items are selected with the criteria specified by the keyword parameters. If no parameters are set then all items are selected. If multiple criteria are given then items that meet all of them are selected (see the match_and parameter).
See also
Examples 1: >>> d = f.refs()
Parameters: - description: optional
Select the items whose descriptive attributes or CF properties satisfy the given conditions. The description parameter may be one, or a sequence, of:
None
or an empty dictionary. All items are selected. This is the default.
A string specifying one of the CF coordinate types:
'T'
,'X'
,'Y'
or'Z'
. An item has an attribute for each coordinate type and is selected if the attribute for the specified type is True.- Example:
To select CF time items:
description='T'
.
A string which identifies items based on their string-valued metadata. The value may take one of the following forms:
Value Interpretation Contains :
Selects on the CF property specified before the first :
Contains %
Selects on the attribute specified before the first %
Anything else Selects on identity as returned by an item’s identity
methodBy default the part of the string to be compared with an item is treated as a regular expression understood by the
re
module and an item is selected if its corresponding value matches the regular expression using there.match
method (i.e. if zero or more characters at the beginning of item’s value match the regular expression pattern). See the exact parameter for details.- Example:
To select items with standard names which begin “lat”:
description='lat'
.- Example:
To select items with long names which begin “air”:
description='long_name:air'
.- Example:
To select items with netCDF variable names which begin “lon”:
description='ncvar%lon'
.- Example:
To select items with identities which end with the letter “z”:
description='.*z$'
.- Example:
To select items with long names which start with the string “.*a”:
description='long_name%\.\*a'
.
A dictionary that identifies properties of the items with corresponding tests on their values. An item is selected if all of the tests in the dictionary are passed.
In general, each dictionary key is a CF property name with a corresponding value to be compared against the item’s CF property value.
If the dictionary value is a string then by default it is treated as a regular expression understood by the
re
module and an item is selected if its corresponding value matches the regular expression using there.match
method (i.e. if zero or more characters at the beginning of item’s value match the regular expression pattern). See the exact parameter for details.- Example:
To select items with standard name of exactly “air_temperature” and long name beginning with the letter “a”:
description={'standard_name': cf.eq('air_temperature'), 'long_name': 'a'}
(seecf.eq
).
Some key/value pairs have a special interpretation:
Special key Value 'units'
The value must be a string and by default is evaluated for equivalence, rather than equality, with an item’s units
property, for example a value of'Pa'
will match units of Pascals or hectopascals, etc. See the exact parameter.'calendar'
The value must be a string and by default is evaluated for equivalence, rather than equality, with an item’s calendar
property, for example a value of'noleap'
will match a calendar of noleap or 365_day. See the exact parameter.None
The value is interpreted as for a string value of the description parameter. For example, description={None: 'air'}
is equivalent todescription='air'
,description={None: 'ncvar%pressure'}
is equivalent todescription='ncvar%pressure'
anddescription={None: 'Y'}
is equivalent todescription='Y'
.- Example:
To select items with standard name starting with “air”, units of temperature and a netCDF variable name of “tas” you could set
description={'standard_name': 'air', 'units': 'K', None: 'ncvar%tas$'}
.
A domain item identifier (such as
'dim1'
,'aux0'
,'msr2'
,'ref0'
, etc.). Selects the corresponding item.- Example:
To select the item with domain identifier “dim1”:
description='dim1'
.
If description is a sequence of any combination of the above then the selected items are the union of those selected by each element of the sequence. If the sequence is empty then no items are selected.
Example:
>>> x = f.items(['ref1', 'latitude_longitude']) >>> y = {} >>> for items in ['ref1', 'latitude_longitude']: ... y.update(f.items(items)) ... >>> set(x) == set(y) True
- match_and:
bool
, optional By default match_and is True and items are selected if they satisfy the all of the specified conditions.
If match_and is False then items are selected if they satisfy at least one of the specified conditions.
- Example:
To select items with identity beginning with “ocean” and two data array axes:
f.refs('ocean', ndim=2)
.- Example:
To select items with identity beginning with “ocean” or two data array axes:
f.refs('ocean', ndim=2, match_and=False)
.
- exact:
bool
, optional The exact parameter applies to the interpretation of string-valued conditions given by the description parameter. By default exact is False, which means that:
- A string-valued condition is treated as a regular
expression understood by the
re
module and an item is selected if its corresponding value matches the regular expression using there.match
method (i.e. if zero or more characters at the beginning of item’s value match the regular expression pattern). - Units and calendar strings are evaluated for equivalence
rather then equality (e.g.
'metre'
is equivalent to'm'
and to'km'
).
- Example:
To select items with with any units of pressure:
f.refs('units:hPa')
. To select items with a standard name which begins with “air” and with any units of pressure:f.refs({'standard_name': 'air', 'units': 'hPa'})
.
If exact is True then:
- A string-valued condition is not treated as a regular expression and an item is selected if its corresponding value equals the string.
- Units and calendar strings are evaluated for exact
equality rather than equivalence (e.g.
'metre'
is equal to'm'
, but not to'km'
).
- Example:
To select items with with units of hectopascals but not, for example, Pascals:
f.refs('units:hPa', exact=True)
. To select items with a standard name of exactly “air_pressure” and with units of exactly hectopascals:f.refs({'standard_name': 'air_pressure', 'units': 'hPa'}, exact=True)
.
Note that
cf.Query
objects provide a mechanism for overriding the exact parameter for individual values.- Example:
f.refs({'standard_name': cf.eq('air', exact=False), 'units': 'hPa'}, exact=True)
will select items with a standard name which begins “air” but with units of exactly hectopascals (seecf.eq
).- Example:
f.refs({'standard_name': cf.eq('air_pressure'), 'units': 'hPa'})
will select items with a standard name of exactly “air_pressure” but with any units of pressure (seecf.eq
).
- A string-valued condition is treated as a regular
expression understood by the
- inverse:
bool
, optional If True then select items other than those selected by all other criteria.
- copy:
bool
, optional If True then a returned item is a copy. By default it is not copied.
Returns: - out:
dict
A dictionary whose keys are domain item identifiers with corresponding values of coordinate references objects. The dictionary may be empty.
Examples: