cfunits.Units.conform¶
-
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
numpyarray, a Python numeric type, or alistortuple. The returned value is of the same type, except that input integers are converted to floats and Python sequences are converted tonumpyarrays (see the inplace keyword).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.
- Parameters
x:
numpy.ndarrayor Python numeric type orlistortuple- 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
numpyarray 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
listortuplethen the inplace parameter is ignored and anumpyarray is returned.
- from_units:
- Returns
numpy.ndarrayor Python numericThe 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.]) >>> 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.]