shnitsel.units.conversion

Attributes

convert_energy

convert_force

convert_dipole

convert_length

convert_time

convert_nacs

convert_socs

convert_charge

convert_velocity

_CONVERTERS

Classes

Converter

Implements a generic Callable object to convert DataArrays between different units.

Functions

convert_all_units_to_shnitsel_defaults(data)

convert_datarray_with_unitdim_to_shnitsel_defaults(data)

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.

Parameters:
__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:
  • da (xr.DataArray) – The input DataArray whose data should be converted

  • to (str) – The unit to which the data should be converted

  • convert_from (str | None, optional) – The Unit from which conversion should be started if da does not have a units attribute. Defaults to None.

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_value(value, convert_from, to)
Parameters:
Return type:

float

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:

xarray.Dataset

_CONVERTERS: Dict[str, Callable[[xarray.DataArray, str], xarray.DataArray]]
convert_datarray_with_unitdim_to_shnitsel_defaults(data)
Parameters:

data (xarray.DataArray)

Return type:

xarray.DataArray