cf.Field.has_construct

Field.has_construct(identity=None)[source]

Whether a metadata construct exists.

New in version 3.4.0.

Parameters
identity: optional

Select the construct. Must be

  • The identity or key of a metadata construct.

A construct identity is specified by a string (e.g. 'latitude', 'long_name=time', 'ncvar%lat', etc.); a Query object (e.g. cf.eq('longitude')); or a compiled regular expression (e.g. re.compile('^atmosphere')) that selects the relevant constructs whose identities match via re.search.

A construct has a number of identities, and is selected if any of them match any of those provided. A construct’s identities are those returned by its identities method. In the following example, the construct x has six identities:

>>> x.identities()
['time',
 'long_name=Time',
 'foo=bar',
 'standard_name=time',
 'ncvar%t',
 'T']

A construct key may optionally have the 'key%' prefix. For example 'dimensioncoordinate2' and 'key%dimensioncoordinate2' are both acceptable keys.

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

Parameter example:

``identity=’T’

Parameter example:

identity='measure:area'

Parameter example:

identity='cell_area'

Parameter example:

identity='long_name=Cell Area'

Parameter example:

identity='cellmeasure1'

Returns
bool

True if the construct exists, otherwise False.

Examples:

>>> f = cf.example_field(0)
>>> print(f)
Field: specific_humidity (ncvar%q)
----------------------------------
Data            : specific_humidity(latitude(5), longitude(8)) 1
Cell methods    : area: mean
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]
>>> f.has_construct('T')
True
>>> f.has_construct('longitude')
True
>>> f.has_construct('Z')
False