abtem.core.units#

Module for handling units and unit conversion.

Module Contents#

Functions#

format_units

Format units as a string.

get_conversion_factor

Get the conversion factor between two units.

validate_units

Validate units and convert to a standard format.

Data#

API#

abtem.core.units.format_units(...) str[source]#

Format units as a string.

Parameters:

units (str) – The units to format.

Returns:

The formatted units.

Return type:

str

abtem.core.units.get_conversion_factor(...) float[source]#

Get the conversion factor between two units.

Parameters:
  • units (str, optional) – The units to convert to.

  • old_units (str, optional) – The units to convert from.

  • energy (float, optional) – The energy to use for conversion from reciprocal space to angular units [eV].

Returns:

The conversion factor.

Return type:

float

abtem.core.units.units_type#

None

abtem.core.units.validate_units(...) Optional[str][source]#

Validate units and convert to a standard format.

If old_units is provided, the function will check if the conversion is possible and raise an error if not.

Parameters:
  • units (str) – The units to validate.

  • old_units (str, optional) – The optional units to check whether conversion from is possible.

Returns:

The validated units

Return type:

str

Raises:

ValueError – If the units are invalid or if conversion from old_units is not possible.