convert_units

function of dascore.units source

convert_units(
    data: Any ,
    to_units: str | bytes | pint.registry.Quantity | pint.facets.plain.unit.PlainUnit | numpy.datetime64 | numpy.timedelta64 | int | float | ellipsis | None[str, <class ’bytes, Quantity, PlainUnit, datetime64, timedelta64, int, float, <class ’ellipsis, None] ,
    from_units: str | bytes | pint.registry.Quantity | pint.facets.plain.unit.PlainUnit | numpy.datetime64 | numpy.timedelta64 | int | float | ellipsis | None[str, <class ’bytes, Quantity, PlainUnit, datetime64, timedelta64, int, float, <class ’ellipsis, None] = None,
)-> ‘Any’

Convert units in array from one type of units to another.

Parameters

Parameter Description
data Data supporting * and +, including a Quantity. Conversion may change its
type (e.g., int to float). Returned unchanged when from_units is None or matches
to_units; otherwise None raises TypeError.
to_units The desired units after the conversion
from_units The current units of the data. If None, simply set the units.

Raises

UnitError if conversion is not possible or if the datatype is not compatible (e.g., datetime must always be [time])