BinWidthAtX v1

../_images/BinWidthAtX-v1_dlg.png

BinWidthAtX dialog.

Summary

Calculates the bin width at X, averaged over all histograms.

Properties

Name Direction Type Default Description
InputWorkspace Input MatrixWorkspace Mandatory A workspace containing the input histograms
X Input number 0 The x value of the bin to use.
Rounding Input string None Bin width rounding. Allowed values: [‘None’, ‘10^n’]
BinWidth Output number   The averaged bin width

Description

This algorithm takes the bin width at X of each histogram in InputWorkspace and calculates the average. This value is then placed in the BinWidth output property.

Rounding

If the Rounding property is set to 10^n, the bin width will be rounded down to the nearest power of 10. For example, 0.11 and 0.99 will be rounded to 0.1, while 0.011 and 0.099 will be rounded to 0.01.

Restrictions on properties

The InputWorkspace has to contain histogram data. For point data, ConvertToHistogram v1 can be used first, but care should be taken if the points are not equally spaced.

Usage

Example: rebin a workspace to equidistant bin boundaries.

import numpy

# Create non-equidistant bin boundaries.
xs = [x * x for x in  numpy.arange(0.0, 10.0, 0.05)]
# Convert xs to numpy array.
xs = numpy.array(xs)
# There is one less bin than the number of boundaries.
ys = numpy.zeros(len(xs) - 1)
ws = CreateWorkspace(DataX=xs, DataY=ys)

newWidth = BinWidthAtX(InputWorkspace=ws, X=1.0, Rounding='10^n')
print('New bin width: {0}'.format(newWidth))

# Rebin to equidistant grid
rebinned = Rebin(InputWorkspace=ws, Params=[newWidth], FullBinsOnly=True)

def firstAndLastBinWidths(workspace):
    first = workspace.readX(0)[1] - workspace.readX(0)[0]
    last = workspace.readX(0)[-1] - workspace.readX(0)[-2]
    return (first, last)

first, last = firstAndLastBinWidths(ws)
print('Bin widths before rebinning, first: {0:.4f}, last: {1:.4f}'.format(first, last))
first, last = firstAndLastBinWidths(rebinned)
print('Bin widths after rebinning, first: {0:.2f}, last: {1:.2f}'.format(first, last))

Output:

New bin width: 0.01
Bin widths before rebinning, first: 0.0025, last: 0.9925
Bin widths after rebinning, first: 0.01, last: 0.01

Categories: AlgorithmIndex | Utility\Calculation

Source

Python: BinWidthAtX.py (last modified: 2019-02-26)