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 The data to convert. Anything supporting * and + works, as does
a Quantity. Deliberately not a narrower annotation: the return type
follows the input rather than matching it (an int in yields a float
out) and callers legitimately pass values the checker only knows as
object. Note that data is returned untouched whenever from_units
is None, so None survives that path but raises a TypeError once
there are real factors to apply.
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])