ess.imaging.tools.analysis.resample#

ess.imaging.tools.analysis.resample(image, sizes, method='sum')[source]#

Resample an image by folding it into blocks of specified sizes and applying a reduction method. The sizes should be provided as a dictionary where the keys are dimension names and the values are the sizes of the blocks. The shape of the input image must be divisible by the block sizes.

Parameters:
  • image (Variable | DataArray) – The image to resample.

  • sizes (dict[str, int]) – A dictionary specifying the block sizes for each dimension. For example, {'x': 4, 'y': 4} will create blocks of size 4x4. Any dimensions with size 1 will be ignored. If all sizes are set to 1, it will not apply method and return a copy of the input resampling image.

  • method (str | Callable, default: 'sum') – The reduction method to apply to the blocks. This can be a string referring to any valid Scipp reduction method, such as ‘sum’, ‘mean’, ‘max’, etc. Alternatively, a custom reduction function can be provided. The function signature should accept a scipp.Variable or scipp.DataArray as first argument and a set of dimensions to reduce over as second argument. The function should return a scipp.Variable or scipp.DataArray.

Return type:

Variable | DataArray

Notes

If the image is a scipp.DataArray, bin edges in the resampling dimensions will be preserved if they are 1-dimensional and sorted (they are dropped otherwise). New bin edges will be chosen according to the resampling sizes. For midpoint coordinates, new coordinates will be average values of each resampled block.

Warning

The coordinates in the output may not be correct if they are not sorted or not linear.