Equal intensity 1D binning

Binning of data is often done to SAXS data in order to reduce the size of the data, “improve statistics” or otherwise retransform the data to better suit the subsequent plotting or fitting of the data. Common 2D and 1D binning methods are “linear” binning, where the q-range is divided into bins of equal size, and “logarithmic” binning, where the q range is divided just so, that the bins are equidistant on a logarithmic q-scale.

Depending on your binning method, you may be weighting your data differently in subsequent fits of no weighting is done by uncertainty or error of the intensity. If you would like to weigh your data points in the fitting by their errors, you need to compute the error for each pixel, which is often given as the square root of the number of counts on your detector. This does imply that you either need a single photon counting detector or that you need to scale your detector output to photon counts.

An alternative to this is to rebin your data just so, that all points have the same intensity, meaning that you have wider bins at higher q than at low q. Since each bin then contains the same relative amount of intensity, the error in each bin should be the same (similar solutions can be achieved with non-position sensitive detectors such as the cyberstar, by counting in each position until a certain threshold value has been reached).

I have written a small Matlab program which achieves just this, and is fast enough to do this for large datasets (i.e. 2D images consisting of 2048×2048 pixels) within seconds. I invite you all to take a look at it, and, as always, suggestions or alternative methods are more than welcome. The input is self-explanatory, but the output isn’t necessarily. The output consists of four vectors:

  • qbin: the mean centres of the bins
  • dqbin: the width of the bins
  • Ibin: the intensity in each bin
  • Ibdq: the binned intensity divided by the width of the bins. This is given for plotting purposes (since plotting qbin vs. Ibin would give you more or less a straight line).

Good luck!

equal intensity binning routine:

function [qbin,dqbin,Ibin,Idqb]=binning_equalintensity(q,I,nbins)

%this function implements binning of intensity into bins of equal

%intensity. qbin is the middle of the bin, and dqbin is the size of

%the bin (in the same units as q). Idqb is the normalised binned intensity,

%normalised to the bin size.

%reshape q and I to x by 1 vector



%sort q,I to q



%determine amount of intensity per bin


%cumsum. This we're going to need a few times


binnumber=ceil(Icum/Iperbin); %now every pixel has a bin number assigned

%first implementation: using a loop function

%find indices

%in case the intensity in one pixel is enough to span several bins,
%the intensity is divided over a number of bins:



for bini=bdiv+1:max(binnumber)

%find indices



if ~isempty(starti)

%determine number of bins in this section






end %otherwise skip



2 Trackbacks / Pingbacks

  1. Looking At Nothing » Blog Archive » SASFIT software
  2. What to do with Q? – Looking At Nothing

Leave a Reply

Your email address will not be published.



This site uses Akismet to reduce spam. Learn how your comment data is processed.