cf.Domain.match_by_construct

Domain.match_by_construct(*identities, OR=False, **conditions)[source]

Whether or not there are particular metadata constructs.

New in version 3.11.0.

Parameters
identities: optional

Identify the metadata constructs by one or more of

  • A metadata construct identity.

    A construct has a number of string-valued identities

defined by its identities method, and is selected if any of them match the identity parameter. identity may be a string that equals one of a construct’s identities; or a re.Pattern object that matches one of a construct’s identities via re.search.

Note that in the output of a dump method or print call, a metadata construct is always described by one of its identities, and so this description may always be used as an identity value.

  • The key of a metadata construct

If a cell method construct identity is given (such as 'method:mean') then it will only be compared with the most recently applied cell method operation.

Alternatively, one or more cell method constructs may be identified in a single string with a CF-netCDF cell methods-like syntax for describing both the collapse dimensions, the collapse method, and any cell method construct qualifiers. If N cell methods are described in this way then they will collectively identify the N most recently applied cell method operations. For example, 'T: maximum within years T: mean over years' will be compared with the most two most recently applied cell method operations.

Parameter example:

identity='latitude'

Parameter example:

``’T’

Parameter example:

'latitude'

Parameter example:

'long_name=Cell Area'

Parameter example:

'cellmeasure1'

Parameter example:

'measure:area'

Parameter example:

cf.eq('time')'

Parameter example:

re.compile('^lat')

Parameter example:

'domainancillary2', 'longitude'

Parameter example:

'area: mean T: maximum'

Parameter example:

'grid_latitude', 'area: mean T: maximum'

conditions: optional

Identify the metadata constructs that have any of the given identities or construct keys, and whose data satisfy conditions.

A construct identity or construct key (as defined by the identities parameter) is given as a keyword name and a condition on its data is given as the keyword value.

The condition is satisfied if any of its data values equals the value provided.

Parameter example:

longitude=180.0

Parameter example:

time=cf.dt('1959-12-16')

Parameter example:

latitude=cf.ge(0)

Parameter example:

latitude=cf.ge(0), air_pressure=500

Parameter example:

**{'latitude': cf.ge(0), 'long_name=soil_level': 4}

OR: bool, optional

If True then return True if at least one metadata construct matches at least one of the criteria given by the identities or conditions arguments. By default True is only returned if the field constructs matches each of the given criteria.

Returns
bool

Whether or not the domain construct contains the specified metadata constructs.

Examples

>>> d = cf.example_field(0).domain
>>> print(d)
Dimension coords: latitude(5) = [-75.0, ..., 75.0] degrees_north
                : longitude(8) = [22.5, ..., 337.5] degrees_east
                : time(1) = [2019-01-01 00:00:00]
>>> d.match_by_construct("latitude")
True
>>> d.match_by_construct("air_pressure")
False
>>> d.match_by_construct("longitude", "time")
True
>>> d.match_by_construct(longitude=22.5)
True
>>> d.match_by_construct(longitude=15.5)
False
>>> d.match_by_construct(longitude=cf.gt(340))
False
>>> d.match_by_construct(longitude=cf.gt(240))
True
>>> d.match_by_construct(time=cf.dt("2019-01-01"))
True
>>> d.match_by_construct(time=cf.dt("2020-01-01"))
False