classmethod Units.conform(x, from_units, to_units, inplace=False)[source]

Conforms values to equivalent values in a compatible unit.

Returns the conformed values.

The values may either be a numpy array, a Python numeric type, or a list or tuple. The returned value is of the same type, except that input integers are converted to floats and Python sequences are converted to numpy arrays (see the inplace keyword).


Do not change the calendar of reference time units in the current version. Whilst this is possible, it will almost certainly result in an incorrect interpretation of the data or an error.


x: numpy.ndarray or Python numeric type or list or tuple

from_units: Units

The original units of x

to_units: Units

The units to which x should be conformed to.

inplace: bool, optional

If True and x is a numpy array then change it in place, creating no temporary copies, with one exception: If x is of integer type and the conversion is not null, then it will not be changed inplace and the returned conformed array will be of float type.

If x is a list or tuple then the inplace parameter is ignored and a numpy array is returned.

numpy.ndarray or Python numeric

The modified numeric values.


>>> Units.conform(2, Units('km'), Units('m'))
>>> import numpy
>>> a = numpy.arange(5.0)
>>> Units.conform(a, Units('minute'), Units('second'))
array([   0.,   60.,  120.,  180.,  240.])
>>> print(a)
[0. 1. 2. 3. 4.]
>>> Units.conform(
...     a,
...     Units('days since 2000-12-1'),
...     Units('days since 2001-1-1'),
...     inplace=True
... )
array([-31., -30., -29., -28., -27.])
>>> print(a)
[-31. -30. -29. -28. -27.]