eolearn.core.utils.common

The utilities module is a collection of classes and functions used across the eolearn package, such as checking whether two objects are deeply equal, padding of an image, etc.

eolearn.core.utils.common.deep_eq(fst_obj, snd_obj)[source]

Compares whether fst_obj and snd_obj are deeply equal.

In case when both fst_obj and snd_obj are of type np.ndarray or either np.memmap, they are compared using np.array_equal(fst_obj, snd_obj). Otherwise, when they are lists or tuples, they are compared for length and then deep_eq is applied component-wise. When they are dict, they are compared for key set equality, and then deep_eq is applied value-wise. For all other data types that are not list, tuple, dict, or np.ndarray, the method falls back to the __eq__ method.

Because np.ndarray is not a hashable object, it is impossible to form a set of numpy arrays, hence deep_eq works correctly.

Parameters:
  • fst_obj (object) – First object compared

  • snd_obj (object) – Second object compared

Returns:

True if objects are deeply equal, False otherwise

Return type:

bool

eolearn.core.utils.common.generate_uid(prefix)[source]

Generates a (sufficiently) unique ID starting with the prefix.

The ID is composed of the prefix, a hexadecimal string obtained from the current time and a random hexadecimal string. This makes the uid sufficiently unique.

Parameters:

prefix (str) –

Return type:

str

eolearn.core.utils.common.is_discrete_type(number_type)[source]

Checks if a given numpy type is a discrete numerical type.

Parameters:

number_type (dtype | type) –

Return type:

bool