cf.Constructs.filter_by_property¶
- Constructs.filter_by_property(*property_mode, **properties)[source]¶
Select metadata constructs by property.
Unlike the other “filter_by_” methods, this method has no todict or cached parameters. To get the results as a dictionary, use the
todictmethod on the result, or for faster performance use thefiltermethod. For instance, to get a dictionary of all constructs with a long_name of'time'you could doc.filter_by_property(long_name="time").todict(), or the fasterd = c.filter(filter_by_property={"long_name": "time"}, todict=True). To return a cached result, you have to use thefiltermethod:c.filter(filter_by_property={"long_name": "time"}, cached=x).Added in version (cfdm): 1.7.0
See also
filter,filters_applied,inverse_filter,clear_filters_applied,unfilter- Parameters:
- property_mode: optional
Define the behaviour when multiple properties are provided:
property_mode
Description
'and'A construct is selected if it matches all of the given properties.
'or'A construct is selected when at least one of its properties matches.
By default property_mode is
'and'.- properties: optional
Select constructs that have a CF property, defined by their
propertiesmethods, that matches any of the given values.A property names and their given values are specified by keyword argument names and values.
A value may be any object that can match via the
==operator, or are.Patternobject that matches via itssearchmethod.The special value of
Noneselects any construct that has that property, regardless of the construct’s property value.If no properties are provided then all constructs that do or could have CF properties, with any values, are selected.
- Returns:
ConstructsThe selected constructs.
Examples
Select constructs that have a
standard_nameof ‘latitude’:>>> d = c.filter_by_property(standard_name='latitude')
Select constructs that have a
long_nameof ‘height’ andunitsof ‘m’:>>> d = c.filter_by_property(long_name='height', units='m')
Select constructs that have a
long_nameof ‘height’ or afooof ‘bar’:>>> d = c.filter_by_property('or', long_name='height', foo='bar')
Select constructs that have a
standard_namewhich contains start with the string ‘air’:>>> import re >>> d = c.filter_by_property(standard_name=re.compile('^air'))