cfdm.Constructs.filter_by_identity

Constructs.filter_by_identity(*identities)[source]

Select metadata constructs by identity.

New in version 1.7.0.

Parameters:

identities: optional

Select constructs that have any of the given identities.

An identity is specified by a string (e.g. 'latitude', 'long_name=time', etc.); or a compiled regular expression (e.g. re.compile('^atmosphere')), for which all constructs whose identities match (via re.search) are selected.

If no identities are provided then all constructs are selected.

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 c has four identities:

>>> c.identities()
['time', 'long_name=Time', 'foo=bar', 'ncvar%T']

In addition, each construct also has an identity based its construct key (e.g. 'key%dimensioncoordinate2')

Note that the identifiers of a metadata construct in the output of a print or dump call are always one of its identities, and so may always be used as an identities argument.

Returns:
Constructs

The selected constructs and their construct keys.

Examples:

Select constructs that have a “standard_name” property of ‘latitude’:

>>> d = c.filter_by_identity('latitude')

Select constructs that have a “long_name” property of ‘Height’:

>>> d = c.filter_by_identity('long_name=Height')

Select constructs that have a “standard_name” property of ‘latitude’ or a “foo” property of ‘bar’:

>>> d = c.filter_by_identity('latitude', 'foo=bar')

Select constructs that have a netCDF variable name of ‘time’:

>>> d = c.filter_by_identity('ncvar%time')