shnitsel.units.conversion¶
Attributes¶
Classes¶
Implements a generic Callable object to convert DataArrays between different units. |
Functions¶
Module Contents¶
- class Converter(quantity_name, conversions)¶
Implements a generic Callable object to convert DataArrays between different units.
See documentation of the
__call__method for details on the implementation of the conversion.- __name__ = 'convert_Uninferable'¶
- quantity_name¶
- conversions¶
- case_sensitive_mapping¶
- targets¶
- __call__(da, to, convert_from=None)¶
Function to convert an xr.DataArray between two different units.
The function needs to be provided with a target unit to as well as with either an attribute units of the input data array or by setting the input unit convert_from. A new datarray with converted units will be returned, if successful. The resulting array will have the new unit set as its units attribute and if no prior conversion has happened, the previous unit will be set to the original_units attribute.
- Parameters:
- Raises:
KeyError – Raised if the convert_from parameter is not set and the da input has no units attribute set.
ValueError – Raised if the target unit to is not known in the conversions dictionary.
ValueError – Raised if the original unit convert_from or da.attr[‘units’] is not known in the conversions dictionary.
- Returns:
The array containing the unit-converted data out of da with a new units and potentially original_units attribute set.
- Return type:
xr.DataArray
- convert_energy¶
- convert_force¶
- convert_dipole¶
- convert_length¶
- convert_time¶
- convert_nacs¶
- convert_socs¶
- convert_charge¶
- convert_velocity¶
- convert_all_units_to_shnitsel_defaults(data)¶
- Parameters:
data (xarray.Dataset)
- Return type:
- _CONVERTERS: Dict[str, Callable[[xarray.DataArray, str], xarray.DataArray]]¶
- convert_datarray_with_unitdim_to_shnitsel_defaults(data)¶
- Parameters:
data (xarray.DataArray)
- Return type: