cfdm.Constructs.filter_by_property

Constructs.filter_by_property(*mode, **properties)[source]

Select metadata constructs by property.

New in version 1.7.0.

Parameters:
mode: optional

Define the behaviour when multiple properties are provided.

By default (or if the mode parameter is 'and') a construct is selected if it matches all of the given properties, but if the mode parameter is 'or' then a construct will be selected when at least one of its properties matches.

properties: optional

Select constructs that have properties with the given values.

By default a construct is selected if it matches all of the given properties, but it may alternatively be selected when at least one of its properties matches (see the mode positional parameter).

A property value is given by a keyword parameter of the property name. The value may be a scalar or vector (e.g. 'latitude', 4, ['foo', 'bar']); or a compiled regular expression (e.g. re.compile('^ocean')), for which all constructs whose methods match (via re.search) are selected.

If no properties are provided then all constructs that have properties, with any values, are selected.

Returns:
Constructs

The selected constructs and their construct keys.

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

>>> d = c.filter_by_property(standard_name='latitude')

Select constructs that have a “long_name” of ‘height’ and “units” of ‘m’:

>>> d = c.filter_by_property(long_name='height', units='m')

Select constructs that have a “long_name” of ‘height’ or a “foo” of ‘bar’:

>>> d = c.filter_by_property('or', long_name='height', foo='bar')

Select constructs that have a “standard_name” which contains start with the string ‘air’:

>>> import re
>>> d = c.filter_by_property(standard_name=re.compile('^air'))