sasdata.data_util.binning module

class sasdata.data_util.binning.DirectionalAverage(major_axis: ArrayLike, minor_axis: ArrayLike, lims: tuple[tuple[float, float] | None, tuple[float, float] | None] | None = None, nbins: int = 100, base=None)

Bases: object

Average along one coordinate axis of 2D data and return data for a 1D plot. This can also be thought of as a projection onto the major axis: 2D -> 1D.

This class operates on a decomposed Data2D object, and returns data needed to construct a Data1D object. The class is instantiated with two arrays of orthogonal coordinate data (depending on the coordinate system, these may have undergone some pre-processing) and two corresponding two-element tuples/lists defining the lower and upper limits on the Region of Interest (ROI) for each coordinate axis. One of these axes is averaged along, and the other is divided into bins and becomes the dependent variable of the eventual 1D plot. These are called the minor and major axes respectively. When a class instance is called, it is passed the intensity and error data from the original Data2D object. These should not have undergone any coordinate system dependent pre-processing.

Note that the old version of manipulations.py had an option for logarithmic binning which is used by SectorQ.

bin_width_n(bin_number: int) float

Calculate the bin width for the nth bin. :param bin_number: The starting array index of the bin between 0 and self.nbins - 1. :return: The bin width, as a float.

property bin_widths: ndarray

Return a numpy array of all bin widths, regardless of the point spacings.

compute_weights()

Return weights array for the contribution of each datapoint to each bin

Each row of the weights array corresponds to the bin with the same index.

get_bin_index(value)

Return the index of the bin to which the supplied value belongs. Beware that min_value should always be numerically smaller than max_value. Take particular care when binning angles across the 2pi to 0 discontinuity.

Parameters:

value – A coordinate value in the binning interval along the major axis,

whose bin index should be returned. Must be between min_value and max_value.

The general formula logarithm binning is: bin = floor(N * (log(x) - log(min)) / (log(max) - log(min)))

get_bin_interval(bin_number: int) tuple[float, float]

Return the lower and upper limits defining a bin, given its index.

Parameters:

bin_number – The index of the bin (between 0 and self.nbins - 1)

Returns:

A tuple of the interval limits as (lower, upper).