Select field constructs by identity.

To find the inverse of the selection, use a list comprehension with the match_by_identity method of the field constucts. For example, to select all field constructs whose identity is not 'air_temperature':

>>> gl = cf.FieldList(f for f in fl
...                   if not f.match_by_identity('air_temperature'))

New in version 3.0.0.

identities: optional

Select field constructs. By default all field constructs are selected. May be one or more of:

  • The identity of a field construct.

A construct identity is specified by a string (e.g. 'air_temperature', 'long_name=Air Temperature', ``'ncvar%tas', etc.); or a compiled regular expression (e.g. re.compile('^air_')) that selects the relevant constructs whose identities match via

Each construct has a number of identities, and is selected if any of them match any of those provided. A construct’s identities are those returned by its identities method. In the following example, the construct x has five identities:

>>> x.identities()
 'long_name=Air Temperature',

Note that in the output of a print call or dump method, a construct is always described by one of its identities, and so this description may always be used as an identities argument.


The matching field constructs.


>>> fl
[<CF Field: specific_humidity(latitude(73), longitude(96)) 1>,
 <CF Field: air_temperature(time(12), latitude(64), longitude(128)) K>]
[<CF Field: air_temperature(time(12), latitude(64), longitude(128)) K>]