# hyperspy.misc.math_tools module

hyperspy.misc.math_tools.anyfloatin(things)

Check if iterable contains any non integer.

hyperspy.misc.math_tools.check_random_state(seed, lazy=False)

Turn a random seed into a RandomState or Generator instance.

Parameters:
• seed (None or int or np.random.RandomState or np.random.Generator or) –

Return the random state singleton used by np.random or dask.array.random

If int:

Return a new random state instance seeded with `seed`.

Return seed.

• lazy (bool, default False) – If True, and seed is `None` or `int`, return a dask.array.random.RandomState instance instead for dask < 2023.2.1, otherwise returns a dask.array.random.Generator instance

Return type:

np.random.Generator instance or

hyperspy.misc.math_tools.get_linear_interpolation(p1, p2, x)

Given two points in 2D returns y for a given x for y = ax + b

Parameters:
• p1 ((x, y)) –

• p2 ((x, y)) –

• x (float) –

Returns:

y

Return type:

float

hyperspy.misc.math_tools.hann_window_nth_order(m, order)

Calculates 1D Hann window of nth order

Parameters:
• m (int) – number of points in window (typically the length of a signal)

• order (int) – Filter order

Returns:

window – window

Return type:

array

hyperspy.misc.math_tools.isfloat(number)

Check if a number or array is of float type.

This is necessary because e.g. isinstance(np.float32(2), float) is False.

hyperspy.misc.math_tools.optimal_fft_size(target, real=False)

Wrapper around scipy function next_fast_len() for calculating optimal FFT padding.

scipy.fft was only added in 1.4.0, so we fall back to scipy.fftpack if it is not available. The main difference is that next_fast_len() does not take a second argument in the older implementation.

Parameters:
• target (int) – Length to start searching from. Must be a positive integer.

• real (bool, optional) – True if the FFT involves real input or output, only available for scipy > 1.4.0

Returns:

Optimal FFT size.

Return type:

int

hyperspy.misc.math_tools.order_of_magnitude(number)

Order of magnitude of the given number

Parameters:

number (float) –

Return type:

Float

hyperspy.misc.math_tools.outer_nd(*vec)

Calculates outer product of n vectors

Parameters:

vec (vector) –

Returns:

out

Return type:

ndarray