to_nrv_unit
- nrv.utils.to_nrv_unit(value, unit)[source]
Convert a quantity
value
from unit to the default nrvunit
.- Parameters:
value (int, float, list or np.ndarray) – value or values wich should be converted.
unit (int or str) – unit to which value should be converted, see examples.
- Returns:
rounded value or values, with the same type and shape than
value
.- Return type:
int, float, list or np.ndarray
Example
Here are three ways of converting 0.12 MHz into the default unit of the corresponding nrv (kHz):
>>> import nrv >>> val_MHz = 0.12 # MHz >>> val_MHz * nrv.MHz 120.0 >>> nrv.to_nrv_unit(val_MHz, nrv.MHz) 120.0 >>> nrv.to_nrv_unit(val_MHz, "MHz") 120.0
Here is how to convert a
list
ornp.array
of values in seconds to milliseconds (nrv’s default unit):>>> import numpy as np >>> vals_s = [[1, 2, 3], [4, 5, 6]] # s >>> nrv.to_nrv_unit(vals_s, nrv.s) # ms [[1000.0, 2000.0, 3000.0], [4000.0, 5000.0, 6000.0]] >>> nrv.to_nrv_unit(np.array(vals_s), nrv.s) # ms array([[1000., 2000., 3000.], [4000., 5000., 6000.]])