abtem.core.utils#

Module for various convenient utilities.

Module Contents#

Classes#

Functions#

array_row_intersection

cos_sin_deg

Cosine and sine of an angle given in degrees.

ensure_list

expand_dims_to_broadcast

Expand the dimensions of two arrays to make them broadcastable.

flatten_list_of_lists

Flatten a list of lists into a single list.

get_data_path

get_dtype

Get the numpy dtype from the config precision setting.

insert_empty_axis

interleave

Interleave two lists or tuples.

is_broadcastable

is_scalar

Check if the value is a float, int, or a NumPy scalar.

itemset

label_to_index

Returns a generator that yields indices for each label in the labels array.

normalize_axes

Normalize the axes tuple so that all axes are non-negative.

number_to_tuple

safe_ceiling_int

safe_equality

safe_floor_int

tuple_range

Data#

T

API#

class abtem.core.utils.CopyMixin[source]#
copy() Self[source]#

Make a copy.

class abtem.core.utils.EqualityMixin[source]#
abtem.core.utils.T#

‘TypeVar(…)’

abtem.core.utils.array_row_intersection(...)[source]#
abtem.core.utils.cos_sin_deg(...) tuple[float, float][source]#

Cosine and sine of an angle given in degrees.

abtem.core.utils.ensure_list(...)[source]#
abtem.core.utils.expand_dims_to_broadcast(...) tuple[ndarray | dask.array.core.Array, ndarray | dask.array.core.Array][source]#

Expand the dimensions of two arrays to make them broadcastable.

Parameters:
  • arr1 (ndarray) – The first array.

  • arr2 (ndarray) – The second array.

  • match_dims (list, optional) – A list of two tuples, each containing the dimensions that should match (i.e. not be broadcasted) between the two arrays.

  • broadcast (bool, optional) – If True, broadcast the arrays to the same shape, otherwise only expand the dimensions. Defaults to False.

Returns:

A tuple containing the expanded arrays.

Return type:

tuple

abtem.core.utils.flatten_list_of_lists(...) list[source]#

Flatten a list of lists into a single list.

abtem.core.utils.get_data_path(...) str[source]#
abtem.core.utils.get_dtype(...) dtype[source]#

Get the numpy dtype from the config precision setting.

Parameters:

complex (bool, optional) – If True, return a complex dtype. Defaults to False.

abtem.core.utils.insert_empty_axis(...)[source]#
abtem.core.utils.interleave(...) list | tuple[source]#

Interleave two lists or tuples.

abtem.core.utils.is_broadcastable(...) bool | tuple[int, ...][source]#
abtem.core.utils.is_scalar(...) TypeGuard[float | int | floating | integer][source]#

Check if the value is a float, int, or a NumPy scalar.

Parameters:

value (any) – The value to check.

Returns:

True if the value is a float, int, or a NumPy scalar, False otherwise.

Return type:

bool

abtem.core.utils.itemset(...) None[source]#
abtem.core.utils.label_to_index(...)[source]#

Returns a generator that yields indices for each label in the labels array.

Parameters:
  • labels (ndarray) – An array of integers.

  • max_label (int, optional) – The assumed maximum label in the array. If None, the maximum the array is used.

  • min_label (int, optional) – The assumed minimum label in the array. Defaults to 0.

abtem.core.utils.normalize_axes(...) tuple[int, ...][source]#

Normalize the axes tuple so that all axes are non-negative.

Parameters:
  • axes (tuple) – The axes to normalize.

  • shape (tuple) – The shape of the array.

Returns:

The normalized axes tuple.

Return type:

tuple

abtem.core.utils.number_to_tuple(...) tuple[abtem.core.utils.T, ...][source]#
abtem.core.utils.safe_ceiling_int(...) int[source]#
abtem.core.utils.safe_equality(...) bool[source]#
abtem.core.utils.safe_floor_int(...) int[source]#
abtem.core.utils.tuple_range(...) tuple[int, ...][source]#