scipp.to_unit#

scipp.to_unit(x, unit, *, copy=True)#

Convert the variable to a different unit.

Raises a scipp.UnitError if the input unit is not compatible with the provided unit, e.g., m cannot be converted to s.

If the input dtype is an integer type or datetime64, the output is rounded and returned with the same dtype as the input.

Parameters
  • x (Variable) – Input variable.

  • unit (Union[Unit, str]) – Desired target unit.

  • copy (bool, default: True) – If False, return the input object if possible, i.e. if the unit is unchanged. If True, the function always returns a new object.

Returns

Variable – Input converted to the given unit.

Examples

>>> var = 1.2 * sc.Unit('m')
>>> sc.to_unit(var, unit='mm')
<scipp.Variable> ()    float64             [mm]  [1200]