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.

__call__(data, err_data)

Compute the directional average of the supplied intensity & error data.

Parameters:
  • data – intensity data from the origninal Data2D object.

  • err_data – the corresponding errors for the intensity data.

__dict__ = mappingproxy({'__module__': 'sasdata.data_util.binning', '__firstlineno__': 9, '__doc__': '\nAverage along one coordinate axis of 2D data and return data for a 1D plot.\nThis can also be thought of as a projection onto the major axis: 2D -> 1D.\n\nThis class operates on a decomposed Data2D object, and returns data needed\nto construct a Data1D object. The class is instantiated with two arrays of\northogonal coordinate data (depending on the coordinate system, these may\nhave undergone some pre-processing) and two corresponding two-element\ntuples/lists defining the lower and upper limits on the Region of Interest\n(ROI) for each coordinate axis. One of these axes is averaged along, and\nthe other is divided into bins and becomes the dependent variable of the\neventual 1D plot. These are called the minor and major axes respectively.\nWhen a class instance is called, it is passed the intensity and error data\nfrom the original Data2D object. These should not have undergone any\ncoordinate system dependent pre-processing.\n\nNote that the old version of manipulations.py had an option for logarithmic\nbinning which is used by SectorQ.\n', '__init__': <function DirectionalAverage.__init__>, '_validate_coordinate_arrays': <function DirectionalAverage._validate_coordinate_arrays>, '_parse_lims': <function DirectionalAverage._parse_lims>, '_coerce_nbins': <function DirectionalAverage._coerce_nbins>, '_assign_axes_and_check_lengths': <function DirectionalAverage._assign_axes_and_check_lengths>, '_set_default_lims_and_bin_limits': <function DirectionalAverage._set_default_lims_and_bin_limits>, 'bin_widths': <property object>, 'bin_width_n': <function DirectionalAverage.bin_width_n>, 'get_bin_interval': <function DirectionalAverage.get_bin_interval>, 'get_bin_index': <function DirectionalAverage.get_bin_index>, 'compute_weights': <function DirectionalAverage.compute_weights>, '__call__': <function DirectionalAverage.__call__>, '__static_attributes__': ('base', 'bin_limits', 'major_axis', 'major_lims', 'minor_axis', 'minor_lims', 'nbins'), '__dict__': <attribute '__dict__' of 'DirectionalAverage' objects>, '__weakref__': <attribute '__weakref__' of 'DirectionalAverage' objects>, '__annotations__': {}})
__doc__ = '\nAverage along one coordinate axis of 2D data and return data for a 1D plot.\nThis can also be thought of as a projection onto the major axis: 2D -> 1D.\n\nThis class operates on a decomposed Data2D object, and returns data needed\nto construct a Data1D object. The class is instantiated with two arrays of\northogonal coordinate data (depending on the coordinate system, these may\nhave undergone some pre-processing) and two corresponding two-element\ntuples/lists defining the lower and upper limits on the Region of Interest\n(ROI) for each coordinate axis. One of these axes is averaged along, and\nthe other is divided into bins and becomes the dependent variable of the\neventual 1D plot. These are called the minor and major axes respectively.\nWhen a class instance is called, it is passed the intensity and error data\nfrom the original Data2D object. These should not have undergone any\ncoordinate system dependent pre-processing.\n\nNote that the old version of manipulations.py had an option for logarithmic\nbinning which is used by SectorQ.\n'
__firstlineno__ = 9
__init__(major_axis: ArrayLike, minor_axis: ArrayLike, lims: tuple[tuple[float, float] | None, tuple[float, float] | None] | None = None, nbins: int = 100, base=None)

Set up direction of averaging, limits on the ROI, & the number of bins.

Parameters:
  • major_axis – Coordinate data for axis onto which the 2D data is projected.

  • minor_axis – Coordinate data for the axis perpendicular to the major axis.

  • lims – Tuple (major_lims, minor_lims). Each element may be a 2-tuple or None.

  • nbins – The number of bins the major axis is divided up into.

  • base – the base used for log, linear binning if None.

__module__ = 'sasdata.data_util.binning'
__static_attributes__ = ('base', 'bin_limits', 'major_axis', 'major_lims', 'minor_axis', 'minor_lims', 'nbins')
__weakref__

list of weak references to the object

_assign_axes_and_check_lengths(major_axis, minor_axis)

Assign axes to numpy arrays and check they have equal length.

_coerce_nbins(nbins)

Coerce nbins to int, raising a TypeError with the original message on failure.

_parse_lims(lims)

Validate the lims parameter and return (major_lims, minor_lims). Accepts None or a 2-tuple (major_lims, minor_lims). Each of the two elements may be None or a 2-tuple of floats.

_set_default_lims_and_bin_limits(major_lims, minor_lims)

Determine final major and minor limits (using data min/max if None) and compute bin_limits based on major_lims and self.nbins. Returns (major_lims_final, minor_lims_final).

_validate_coordinate_arrays(major_axis, minor_axis) None

Ensure both major and minor coordinate inputs are array-like.

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