cf.Data.override_units

Data.override_units(units, inplace=False, i=False)[source]

Override the data array units.

Not to be confused with setting the Units attribute to units which are equivalent to the original units. This is different because in this case the new units need not be equivalent to the original ones and the data array elements will not be changed to reflect the new units.

Parameters
units: str or Units

The new units for the data array.

inplace: bool, optional

If True then do the operation in-place and return None.

i: deprecated at version 3.0.0

Use the inplace parameter instead.

Returns
Data or None

The new data, or None if the operation was in-place.

Examples

>>> d = cf.Data(1012.0, 'hPa')
>>> e = d.override_units('km')
>>> e.Units
<Units: km>
>>> e.datum()
1012.0
>>> d.override_units(cf.Units('watts'), inplace=True)
>>> d.Units
<Units: watts>
>>> d.datum()
1012.0