cf.Units.conform¶
-
static
Units.
conform
(x, from_units, to_units, inplace=False)[source]¶ Conform values in one unit to equivalent values in another, compatible unit. Returns the conformed values.
The values may either be a numpy array or a python numeric type. The returned value is of the same type, except that input integers are converted to floats (see the inplace keyword).
Parameters: x : numpy.ndarray or python numeric
- 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: Ifx
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.
Returns: - out : numpy.ndarray or python numeric
The modified numeric values.
Examples: >>> Units.conform(2, Units('km'), Units('m')) 2000.0
>>> import numpy >>> a = numpy.arange(5.0) >>> Units.conform(a, Units('minute'), Units('second')) array([ 0., 60., 120., 180., 240.]) >>> a array([ 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.]) >>> a array([-31., -30., -29., -28., -27.])
Warning
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. Allowing the calendar to be changed is under development and will be available soon.