cf.FieldList.select_by_units

FieldList.select_by_units(*units, exact=True)[source]

Select field constructs by units.

To find the inverse of the selection, use a list comprehension with match_by_units method of the field constucts. For example, to select all field constructs whose units are not 'km':

>>> gl = cf.FieldList(f for f in fl if not f.match_by_units('km'))

New in version 3.0.0.

Parameters
units: optional

Select field constructs. By default all field constructs are selected. May be one or more of:

  • The units of a field construct.

Units are specified by a string or compiled regular expression (e.g. ‘km’, ‘m s-1’, re.compile('^kilo'), etc.) or a Units object (e.g. Units('km'), Units('m s-1'), etc.).

exact: bool, optional

If False then select field constructs whose units are equivalent to any of those given by units. For example, metres and are equivalent to kilometres. By default, field constructs whose units are exactly one of those given by units are selected. Note that the format of the units is not important, i.e. ‘m’ is exactly the same as ‘metres’ for this purpose.

Returns
FieldList

The matching field constructs.

Examples:

>>> gl = fl.select_by_units('metres')
>>> gl = fl.select_by_units('m')
>>> gl = fl.select_by_units('m', 'kilogram')
>>> gl = fl.select_by_units(Units('m'))
>>> gl = fl.select_by_units('km', exact=False)
>>> gl = fl.select_by_units(Units('km'), exact=False)
>>> gl = fl.select_by_units(re.compile('^met'))
>>> gl = fl.select_by_units(Units('km'))
>>> gl = fl.select_by_units(Units('kg m-2'))