Utils

Collection of secondary functions used in the principal modules.

structure_factor.utils.get_random_number_generator(seed=None)[source]

Turn seed into a np.random.Generator instance.

structure_factor.utils.set_nan_inf_to_zero(array, nan=0, posinf=0, neginf=0)[source]

Set nan, posinf, and neginf values of array to the corresponding input arguments. Defaults to zero.

structure_factor.utils.bessel1(order, x)[source]

Evaluate Bessel function of the first kind.

structure_factor.utils.bessel1_zeros(order, nb_zeros)[source]

Evaluate zeros of the Bessel function of the first kind.

structure_factor.utils.bessel2(order, x)[source]

Evaluate Bessel function of the second kind.

structure_factor.utils.meshgrid_to_column_matrix(X)[source]

Transform output X of numpy.meshgrid to a 2d numpy array with columns formed by flattened versions of the elements of X.

np.column_stack([x.ravel() for x in X])
Parameters

X (list) – output of numpy.meshgrid.

Returns

2d array.

Return type

np.ndarray

structure_factor.utils.sort_by_keys(keys, *arrays, **argsort_params)[source]

Return a sorted version of arrays according to the indices that would sort keys by calling numpy.argsort(keys, **argsort_params).

Parameters
  • keys (array_like) – Array to extract the sorting indices from.

  • arrays (array_like) – Sequence of arrays to be sorted. These arrays must have a length larger or equal to the length of keys.

Returns

sorted version of arrays.

Return type

list

structure_factor.utils._sort_vectors(k, x_k, y_k=None)[source]

Sort k by increasing order and rearranging the associated vectors to k, x_k``and ``y_k.

Parameters
  • k (numpy.ndarray) – Vector to be sorted by increasing order.

  • x_k (numpy.ndarray) – Vector of evaluations associated with k.

  • y_k (numpy.ndarray, optional) – Vector of evaluations associated with k. Defaults to None.

Returns

k sorted by increasing order and the associated vectors x_k``and ``y_k.

Return type

(numpy.ndarray, numpy.ndarray, numpy.ndarray)

structure_factor.utils._bin_statistics(x, y, **params)[source]

Divide x into bins and evaluate the mean and the standard deviation of the corresponding elements of y over each bin.

Parameters
  • x (numpy.ndarray) – Vector of data.

  • y (numpy.ndarray) – Vector of data associated with the vector x.

Keyword Arguments

params (dict) – Keyword arguments (except "x", "values" and "statistic") of scipy.stats.binned_statistic.

Returns

  • bin_centers: Vector of centers of the bins associated to x.

  • bin_mean: Vector of means of y over the bins.

  • std_mean: Vector of standard deviations of y over the bins.

Return type

tuple(numpy.ndarray, numpy.ndarray, numpy.ndarray)