cf.Query.__init__

Query.__init__(operator, value, units=None, exact=True, attr=None)[source]

Initialization

Parameters:
operator: str

The query operator.

value:

The right hand side of the query operation.

units: str or cf.Units, optional

The units of value. By default, the same units, if any, as the left hand side of the query operation are assumed.

exact: bool, optional

If False then string values are treated as a regular expressions as understood by the re module and are evaluated using the re.match method. Ignored for all operators except 'eq', 'ne' and 'set'.

attr: str, optional

Specify an attribute (or an attribute of an attribute, etc.) of a left hand side operand which is compared, rather than the operand itself.

Example:

cf.Query('ge', 2, attr='ndim') will return True when evaluated for a numpy array with two or more dimensions.

Example:

q=cf.Query('ge', 2, attr='lower_bounds.month') will compare the month attribute of the lower_bounds attribute. I.e. q==x is equivalent to cf.Query('ge', 2)==x.lower_bounds.month.

Examples:
>>> cf.Query('le', 5.6)
<CF Query: (le 5.6)>
>>> cf.Query('gt', 5.6, 'metres')
<CF Query: (gt <CF Data: 5.6 metres>)>
>>> cf.Query('gt', cf.Data(5.6, 'metres'))
<CF Query: (gt <CF Data: 5.6 metres>)>
>>> cf.Query('wi', [2, 56])
<CF Query: (wi [2, 56])>
>>> cf.Query('set', [2, 56], 'seconds')
<CF Query: (set <CF Data: [2, 56] seconds>)>
>>> cf.Query('set', cf.Data([2, 56], 'seconds'))
<CF Query: (set <CF Data: [2, 56] seconds>)>
>>> cf.Query('eq', 'air_temperature')
<CF Query: (eq 'air_temperature')>
>>> cf.Query('eq', 'temperature', exact=False)
<CF Query: (eq 'temperature')>
>>> cf.Query('gt', 1, attr='ndim')
<CF Query: ndim(gt 1)>