cf.Field.replace_construct¶

Field.
replace_construct
(identity, construct, copy=True)[source]¶ Replace a metadata construct.
Replacement assigns the same construct key and, if applicable, the domain axes of the original construct to the new, replacing construct.
New in version 3.0.0.
See also
Parameters:  identity:
Select the metadata construct to be replaced by one of:
 The identity or key of a metadata construct.
 The identity or key of a domain axis construct that is spanned by a metadata construct’s data.
A construct identity is specified by a string (e.g.
'latitude'
,'long_name=time'
,'ncvar%lat'
, etc.); aQuery
object (e.g.cf.eq('longitude')
); or a compiled regular expression (e.g.re.compile('^atmosphere')
) that selects the relevant constructs whose identities match viare.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 constructx
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 ordump
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='Y'
 Parameter example:
identity='latitude'
 Parameter example:
identity='long_name=Latitude'
 Parameter example:
identity='dimensioncoordinate1'
 Parameter example:
identity='domainaxis2'
 Parameter example:
identity='ncdim%y'
 construct:
The new construct to replace that selected by the identity parameter.
 copy:
bool
, optional If True then set a copy of the new construct. By default the construct is not copied.
Returns: The construct that was replaced.
Examples:
>>> f.replace_construct('X', new_X_construct)