Skip to content

nabu.testutils

source module nabu.testutils

Classes

Functions

source generate_tests_scenarios(configurations)

Generate "scenarios" of tests.

The parameter is a dictionary where

  • the key is the name of a parameter
  • the value is a list of possible parameters

This function returns a list of dictionary where

  • the key is the name of a parameter
  • the value is one value of this parameter

source get_data(*dataset_path)

Get a dataset file from silx.org/pub/nabu/data dataset_args is a list describing a nested folder structures, ex. ["path", "to", "my", "dataset.h5"]

source dataclass SimpleNXTomoDescription(n_darks: int = 0, n_flats1: int = 0, n_projs: int = 0, n_flats2: int = 0, n_align: int = 0, frame_shape: tuple = None, dtype: np.dtype = np.uint16)

source get_dummy_nxtomo_info()

source get_array_of_given_shape(img, shape, dtype)

From a given image, returns an array of the wanted shape and dtype.

source get_big_data(filename)

source uncompress_file(compressed_file_path, target_directory)

Raises

  • ValueError

source get_file(fname)

source compare_arrays(arr1, arr2, tol, diff=None, absolute_value=True, percent=None, method='max', return_residual=False)

Utility to compare two arrays.

Parameters

  • arr1 : numpy.ndarray First array to compare

  • arr2 : numpy.ndarray Second array to compare

  • tol : float Tolerance indicating whether arrays are close to eachother.

  • diff : numpy.ndarray, optional Difference arr1 - arr2. If provided, this array is taken instead of arr1 and arr2.

  • absolute_value : bool, optional Whether to take absolute value of the difference.

  • percent : float If set, a "relative" comparison is performed instead of a subtraction: red(|arr1 - arr2|) / (red(|arr1|) * percent) < tol where "red" is the reduction method (mean, max or median).

  • method Reduction method. Can be "max", "mean", or "median".

Returns

  • (is_close, residual) if return_residual is set to True

  • is_close otherwise

Examples

When using method="mean" and absolute_value=True, this function computes the Mean Absolute Difference (MAD) metric. When also using percent=1.0, this computes the Relative Mean Absolute Difference (RMD) metric.

Raises

  • ValueError

source gaussian_apodization_window(shape, fwhm_ratio=0.7)

source compare_shifted_images(img1, img2, fwhm_ratio=0.7, return_upper_bound=False)

Compare two images that are slightly shifted from one another. Typically, tomography reconstruction wight slightly different CoR. Each image is Fourier-transformed, and the modulus is taken to get rid of the shift between the images. An apodization is done to filter the high frequencies that are usually less relevant.

Parameters

  • img1 : numpy.ndarray First image

  • img2 : numpy.ndarray Second image

  • fwhm_ratio : float, optional Ratio defining the apodization in the frequency domain. A small value (eg. 0.2) means that essentually only the low frequencies will be compared. A value of 1.0 means no apodization

  • return_upper_bound : bool, optional Whether to return a (coarse) upper bound of the comparison metric

Notes

This function roughly computes |phi(F(img1)) - phi(F(img2))| where F is the absolute value of the Fourier transform, and phi some shrinking function (here arcsinh).

source generate_nx_dataset(out_fname, image_key, data_volume=None, rotation_angle=None)