cf.Constructs.filter_by_method¶
-
Constructs.
filter_by_method
(*methods, todict=False, cached=None)[source]¶ Select cell method constructs by method.
New in version (cfdm): 1.7.0
See also
filter
,filters_applied
,inverse_filter
,clear_filters_applied
,unfilter
- Parameters
- methods: optional
Select cell method constructs that have a method, defined by their
get_method
methods, that matches any of the given values.If no methods are provided then all cell method constructs are selected.
A value may be any object that can match via the
==
operator, or are.Pattern
object that matches via itssearch
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
ordict
or cachedThe selected constructs, or a cached valued.
Examples:
>>> print(c.constructs.filter_by_type('cell_method')) Constructs: {'cellmethod0': <CellMethod: domainaxis1: domainaxis2: mean where land (interval: 0.1 degrees)>, 'cellmethod1': <CellMethod: domainaxis3: maximum>}
Select cell method constructs that have a method of ‘mean’:
>>> print(c.filter_by_method('mean')) Constructs: {'cellmethod0': <CellMethod: domainaxis1: domainaxis2: mean where land (interval: 0.1 degrees)>}
Select cell method constructs that have a method of ‘mean’ or ‘maximum’:
>>> print(c.filter_by_method('mean', 'maximum')) Constructs: {'cellmethod0': <CellMethod: domainaxis1: domainaxis2: mean where land (interval: 0.1 degrees)>, 'cellmethod1': <CellMethod: domainaxis3: maximum>}
Select cell method constructs that have a method that contain the letter ‘x’:
>>> import re >>> print(c.filter_by_method(re.compile('x'))) Constructs: {'cellmethod1': <CellMethod: domainaxis3: maximum>}
Select cell method constructs that have a method of any value:
>>> print(c.filter_by_method()) Constructs: {'cellmethod0': <CellMethod: domainaxis1: domainaxis2: mean where land (interval: 0.1 degrees)>, 'cellmethod1': <CellMethod: domainaxis3: maximum>}