cfdm.Field.del_construct

Field.del_construct(*identity, default=ValueError(), **filter_kwargs)[source]

Remove a metadata construct.

If a domain axis construct is selected for removal then it can’t be spanned by any data arrays of the field nor metadata constructs, nor be referenced by any cell method constructs. However, a domain ancillary construct may be removed even if it is referenced by coordinate reference construct.

New in version (cfdm): 1.7.0

Parameters
identity:

Select the unique construct that has the identity, defined by its identities method, that matches the given values.

Additionally, the values are matched against construct identifiers, with or without the 'key%' prefix.

A value may be any object that can match via the == operator, or a re.Pattern object that matches via its search method.

Note that in the output of a dump method or print call, a construct is always described by an identity that will select it.

default: optional

Return the value of the default parameter if the data axes have not been set.

If set to an Exception instance then it will be raised instead.

filter_kwargs: optional

Keyword arguments as accepted by Constructs.filter that define additional construct selection criteria.

New in version (cfdm): 1.8.9.0

Returns

The removed metadata construct.

Examples

>>> f = cfdm.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.del_construct('time')
<DimensionCoordinate: time(1) days since 2018-12-01 >
>>> f.del_construct('time')
Traceback (most recent call last):
    ...
ValueError: Can't find unique construct to remove
>>> f.del_construct('time', default='No time')
'No time'
>>> f.del_construct('dimensioncoordinate1')
<DimensionCoordinate: longitude(8) degrees_east>
>>> print(f)
Field: specific_humidity (ncvar%q)
----------------------------------
Data            : specific_humidity(latitude(5), ncdim%lon(8)) 1
Cell methods    : area: mean
Dimension coords: latitude(5) = [-75.0, ..., 75.0] degrees_north