cf.FieldList.select_field

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

Select a unique field construct by its identity.

New in version 3.0.4.

Parameters
identities: optional

Select the field construct by one or more of

  • A construct identity.

    A construct has a number of string-valued identities

defined by its identities method, and is selected if any of them match the identity parameter. identity may be a string that equals one of a construct’s identities; or a re.Pattern object that matches one of a construct’s identities via re.search.

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

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