# cf.FieldList.select_field¶

FieldList.select_field(identity, default=ValueError())[source]

Select a unique field construct by its identity.

New in version 3.0.4.

Parameters
identity:

Select the field construct. May be:

• 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 re.search.

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()
['air_temperature',
'long_name=Air Temperature',
'foo=bar',
'standard_name=air_temperature',
'ncvar%tas']


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 identity argument.

default: optional

Return the value of the default parameter if a unique field construct can not be found. If set to an Exception instance then it will be raised instead.

Returns
Field

The unique matching field construct.

Examples:

>>> fl
[<CF Field: specific_humidity(latitude(73), longitude(96)) 1>,
<CF Field: specific_humidity(latitude(73), longitude(96)) 1>,
<CF Field: air_temperature(time(12), latitude(64), longitude(128)) K>]
>>> fl.select_field('air_temperature')
<CF Field: air_temperature(time(12), latitude(64), longitude(128)) K>
>>> f.select_field('specific_humidity')
ValueError: Multiple fields found
>>> f.select_field('specific_humidity', 'No unique field')
'No unique field'
>>> f.select_field('snowfall_amount')
ValueError: No fields found