convert_units

function of dascore.proc.units source

convert_units(
    patch: Patch ,
    data_units: str | pint.registry.Quantity | pint.registry.Unit | None[str, Quantity, Unit, None] = None,
    **kwargs ,
)-> ‘PatchType’

Convert the patch data or coordinate units.

Perform proper conversions from one unit to another, changing patch data and dimension labels to the new unit specified. If the data or coordinates whose units are to be converted are not set, the new units will simply be set without performing any conversions.

See also set_units and simplify_units

Parameters

Parameter Description
data_units If provided, new units for the patch data.
**kwargs Used to specify the new units of the coordinates.

Raises

UnitError if any of the new units are not compatible with the old units.

Examples

import dascore as dc
patch = dc.get_example_patch()

# Set initial units
patch_with_units = patch.set_units("m/s", distance="m", time="s")

# Convert data units from m/s to km/s
converted_data = patch_with_units.convert_units(data_units="km/s")

# Convert coordinate units
converted_coords = patch_with_units.convert_units(distance="km")