spectrochempy.to
- to(other, inplace=False, force=False)[source]
- Return the object with data rescaled to different units. - Parameters:
- other ( - Quantityor str) – Destination units.
- inplace (bool, optional, default=`False`) – Flag to say that the method return a new object (default) or not (inplace=True). 
- force (bool, optional, default=False) – If True the change of units is forced, even for incompatible units. 
 
- Returns:
- rescaled 
 - See also - ito
- Inplace rescaling of the current object data to different units. 
- to_base_units
- Rescaling of the current object data to different units. 
- ito_base_units
- Inplace rescaling of the current object data to different units. 
- to_reduced_units
- Rescaling to reduced_units. 
- ito_reduced_units
- Inplace rescaling to reduced units. 
 - Examples - >>> np.random.seed(12345) >>> ndd = scp.NDArray(data=np.random.random((3, 3)), ... mask=[[True, False, False], ... [False, True, False], ... [False, False, True]], ... units='meters') >>> print(ndd) NDArray: [float64] m (shape: (y:3, x:3)) - We want to change the units to seconds for instance but there is no relation with meters, so an error is generated during the change - >>> ndd.to('second') Traceback (most recent call last): ... pint.errors.DimensionalityError: Cannot convert from 'meter' ([length]) to 'second' ([time]) - However, we can force the change - >>> ndd.to('second', force=True) NDArray: [float64] s (shape: (y:3, x:3)) - By default the conversion is not done inplace, so the original is not modified : - >>> print(ndd) NDArray: [float64] m (shape: (y:3, x:3))