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 np.random.RandomState instance.

Parameters
  • seed (None or int or np.random.RandomState or dask.array.random.RandomState) –

    If None:

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

    If int:

    Return a new RandomState instance seeded with seed.

    If np.random.RandomState:

    Return it.

    If dask.array.random.RandomState:

    Return it.

  • lazy (bool, default False) – If True, and seed is None or int, return a dask.array.random.RandomState instance instead.

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) –

Returns

Return type

Float

hyperspy.misc.math_tools.outer_nd(*vec)

Calculates outer product of n vectors

Parameters

vec (vector) –

Returns

out

Return type

ndarray