cfdm.core.Constructs.filter_by_type

Constructs.filter_by_type(*types, todict=True, cached=None)[source]

Select metadata constructs by type.

New in version (cfdm): 1.7.0

Parameters
types: optional

Select constructs that have are of any of the given types.

A type is specified by one of the following strings:

type

Construct selected

'domain_ancillary'

Domain ancillary

'dimension_coordinate'

Dimension coordinate

'domain_axis'

Domain axis

'auxiliary_coordinate'

Auxiliary coordinate

'cell_measure'

Cell measure

'coordinate_reference'

Coordinate reference

'cell_method'

Cell method

'field_ancillary'

Field ancillary

If no types are provided then all constructs are selected.

Parameters
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.

cached: optional

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

Returns
Constructs or dict

The selected constructs and their construct keys.

Examples:

Select dimension coordinate constructs:

>>> f = cfdm.core.example_field(1)
>>> c = f.constructs
>>> d = c.filter_by_type('dimension_coordinate')
>>> d
<Constructs: dimension_coordinate(4)>

Select dimension coordinate and field ancillary constructs:

>>> k = c.filter_by_type(
...     'dimension_coordinate', 'field_ancillary')
>>> k
<Constructs: dimension_coordinate(4), field_ancillary(1)>