cf.Constructs.filter_by_key

Constructs.filter_by_key(*keys, todict=False, cached=None)[source]

Select metadata constructs by key.

New in version (cfdm): 1.7.0

Parameters
key: optional

Select constructs that have a construct identifier (e.g. 'dimensioncoordinate1') that matches any of the given values.

If no keys are provided then all constructs are selected.

A value may be any object that can match via the == operator, or a re.Pattern object that matches via its search method.

todict: bool, optional

If True then return a dictionary of constructs keyed by their construct identifiers, instead of a Constructs object. This is a faster option.

New in version (cfdm): 1.8.9.0

cached: optional

If any value other than None then return cached without selecting any constructs.

New in version (cfdm): 1.8.9.0

Returns
Constructs or dict or cached

The selected constructs, or a cached valued.

Examples:

Select the construct with key ‘domainancillary0’:

>>> d = c.filter_by_key('domainancillary0')

Select the constructs with keys ‘dimensioncoordinate1’ or ‘fieldancillary0’:

>>> d = c.filter_by_key('dimensioncoordinate1', 'fieldancillary0')