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")ConvertUnits
ConvertUnits(
*args ,
data_units: Any = None,
**kwargs ,
)-> None
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 |
|---|---|
| patch | The patch whose units should be converted. |
| 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
Methods
| Name | Description |
|---|---|
| check | Refuse a patch which does not carry what the operation needs. |
| get_metadata | Return converted metadata and the affine factors for the data. |
| kernel | Return the data converted; the data if their units stand. |
| model_copy | Copy the model, dropping cached values the update invalidates. |
| new | Create new instance with some attributed updated. |
| convert_units | Convert the patch data or coordinate units. |
| reconcile | Return metadata or a patch holding the final data; default as is. |
| run | Run the operation: check, get_metadata, kernel, reconcile, record. |