Skip to content

Commit

Permalink
refs #10384 Doctest and error in multithreading
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Oct 31, 2014
1 parent 0104f3e commit 39e7547
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 190 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/Algorithms/src/RemoveBackground.cpp
Expand Up @@ -105,7 +105,7 @@ namespace Mantid
}

//
int nThreads = PARALLEL_NUMBER_OF_THREADS;
int nThreads = PARALLEL_GET_MAX_THREADS;
m_BackgroundHelper.initialize(bkgWksp,inputWS,eMode,&g_log,nThreads,inPlace);

Progress prog(this,0.0,1.0,histnumber);
Expand Down
202 changes: 13 additions & 189 deletions Code/Mantid/docs/source/algorithms/RemoveBackground-v1.rst
Expand Up @@ -8,94 +8,22 @@

Description
-----------

The algorithm rebins data with new bin boundaries. The 'params' property
defines new boundaries in intervals :math:`x_i-x_{i+1}\,`. Positive
:math:`\Delta x_i\,` make constant width bins, whilst negative ones
create logarithmic binning using the formula
:math:`x(j+1)=x(j)(1+|\Delta x_i|)\,`

This algorithms is useful both in data reduction, but also in remapping
`ragged workspaces <http://www.mantidproject.org/Ragged_Workspace>`__ to a regular set of bin
boundaries.

Unless the FullBinsOnly option is enabled, the bin immediately before
the specified boundaries :math:`x_2`, :math:`x_3`, ... :math:`x_i` is
likely to have a different width from its neighbours because there can
be no gaps between bins. Rebin ensures that any of these space filling
bins cannot be less than 25% or more than 125% of the width that was
specified.


.. _rebin-example-strings:

Example Rebin param strings
###########################

* **"-0.0001"**: from min(TOF) to max(TOF) among all events in Logarithmic bins of 0.0001
* **"*0,100,20000"**: from 0 rebin in constant size bins of 100 up to 20,000
* **"2,-0.035,10"**: from 10 rebin in Logarithmic bins of 0.035 up to 10
* **"0,100,10000,200,20000"**: from 0 rebin in steps of 100 to 10,000 then steps of 200 to 20,000

For EventWorkspaces
###################

If the input is an `EventWorkspace <www.mantidproject.org/EventWorkspace>`__ and the "Preserve
Events" property is True, the rebinning is performed in place, and only
the X axes of the workspace are set. The actual Y histogram data will
only be requested as needed, for example, when plotting or displaying
the data.

If "Preserve Events" is false., then the output workspace will be
created as a :ref:`Workspace2D <Workspace2D>`, with fixed histogram bins,
and all Y data will be computed immediately. All event-specific data is
lost at that point.

For Data-Point Workspaces
#########################

If the input workspace contains data points, rather than histograms,
then Rebin will automatically use the
:ref:`ConvertToHistogram <algm-ConvertToHistogram>` and
:ref:`ConvertToHistogram <algm-ConvertToPointData>` algorithms before and after
the rebinning has taken place.

FullBinsOnly option
###################

If FullBinsOnly option is enabled, each range will only contain bins of
the size equal to the step specified. In other words, the will be no
space filling bins which are bigger or smaller than the other ones.

This, however, means that specified bin boundaries might get amended in
the process of binning. For example, if rebin *Param* string is
specified as "0, 2, 4.5, 3, 11" and FullBinsOnly is enabled, the
following will happen:

- From 0 rebin in bins of size 2 **up to 4**. 4.5 is ignored, because
otherwise we would need to create a filling bin of size 0.5.
- **From 4** rebin in bins of size 3 **up to 10**.

Hence the actual *Param* string used is "0, 2, 4, 3, 10".


Remove Background during rebinning options
##########################################

These options allow you to remove flat background, defined by the a single bin
histogram workspace with X-axis in the units of TOF from a workspace in any
units with known conversion into TOF. The background removal occurs during rebinning
Algorithm removes flat background, defined by the a single bin
histogram workspace with X-axis in the units of TOF from a histogram workspace in any
units with known conversion into TOF.

These options are especially useful during reduction
of event workspaces in multirep mode, where different event regions are associated with
different incident energies and rebinned into appropriate energy range together with
background removal on-the-fly.
different incident energies and rebinned into appropriate energy range.

The algorithm used during background removal is equivalent to the proof-of concept one,
presented below, except intermediate workspaces are not created and the background removal calculations
performed during rebinning.

Errors of the background workspace are currently ignored and their value
is calculated as the square root of correspondent background signal::
is calculated as the square root of correspondent background signal.

Proof of concept background removal algorithm::

from mantid.simpleapi import *
from mantid import config
Expand Down Expand Up @@ -240,114 +168,8 @@ are identical::
Usage
-----

**Example - simple rebin of a histogram workspace:**

.. testcode:: ExHistSimple

# create histogram workspace
dataX = [0,1,2,3,4,5,6,7,8,9] # or use dataX=range(0,10)
dataY = [1,1,1,1,1,1,1,1,1] # or use dataY=[1]*9
ws = CreateWorkspace(dataX, dataY)

# rebin from min to max with size bin = 2
ws = Rebin(ws, 2)

print "The rebinned X values are: " + str(ws.readX(0))
print "The rebinned Y values are: " + str(ws.readY(0))

Output:

.. testoutput:: ExHistSimple

The rebinned X values are: [ 0. 2. 4. 6. 8. 9.]
The rebinned Y values are: [ 2. 2. 2. 2. 1.]

**Example - logarithmic rebinning:**

.. testcode:: ExHistLog

# create histogram workspace
dataX = [1,2,3,4,5,6,7,8,9,10] # or use dataX=range(1,11)
dataY = [1,2,3,4,5,6,7,8,9] # or use dataY=range(1,10)
ws = CreateWorkspace(dataX, dataY)

# rebin from min to max with logarithmic bins of 0.5
ws = Rebin(ws, -0.5)

print "The 2nd and 3rd rebinned X values are: " + str(ws.readX(0)[1:3])

Output:

.. testoutput:: ExHistLog

The 2nd and 3rd rebinned X values are: [ 1.5 2.25]

**Example - custom two regions rebinning:**

.. testcode:: ExHistCustom

# create histogram workspace
dataX = [0,1,2,3,4,5,6,7,8,9] # or use dataX=range(0,10)
dataY = [0,1,2,3,4,5,6,7,8] # or use dataY=range(0,9)
ws = CreateWorkspace(dataX, dataY)

# rebin from 0 to 3 in steps of 2 and from 3 to 9 in steps of 3
ws = Rebin(ws, "1,2,3,3,9")

print "The rebinned X values are: " + str(ws.readX(0))

Output:

.. testoutput:: ExHistCustom

The rebinned X values are: [ 1. 3. 6. 9.]

**Example - use option FullBinsOnly:**

.. testcode:: ExHistFullBinsOnly

# create histogram workspace
dataX = [0,1,2,3,4,5,6,7,8,9] # or use dataX=range(0,10)
dataY = [1,1,1,1,1,1,1,1,1] # or use dataY=[1]*9
ws = CreateWorkspace(dataX, dataY)

# rebin from min to max with size bin = 2
ws = Rebin(ws, 2, FullBinsOnly=True)

print "The rebinned X values are: " + str(ws.readX(0))
print "The rebinned Y values are: " + str(ws.readY(0))

Output:

.. testoutput:: ExHistFullBinsOnly

The rebinned X values are: [ 0. 2. 4. 6. 8.]
The rebinned Y values are: [ 2. 2. 2. 2.]

**Example - use option PreserveEvents:**

.. testcode:: ExEventRebin

# create some event workspace
ws = CreateSampleWorkspace(WorkspaceType="Event")

print "What type is the workspace before 1st rebin: " + str(type(ws))
# rebin from min to max with size bin = 2 preserving event workspace (default behaviour)
ws = Rebin(ws, 2)
print "What type is the workspace after 1st rebin: " + str(type(ws))
ws = Rebin(ws, 2, PreserveEvents=False)
print "What type is the workspace after 2nd rebin: " + str(type(ws))
# note you can also check the type of a workspace using: print isinstance(ws, IEventWorkspace)

Output:

.. testoutput:: ExEventRebin

What type is the workspace before 1st rebin: <class 'mantid.api._api.IEventWorkspace'>
What type is the workspace after 1st rebin: <class 'mantid.api._api.IEventWorkspace'>
What type is the workspace after 2nd rebin: <class 'mantid.api._api.MatrixWorkspace'>

**Example - Background removal during rebinning**
**Example - Background removal from a workspace in energy transfer units**

.. testcode:: ExRebinWithBkgRemoval

Expand All @@ -365,8 +187,10 @@ Output:

# Calculate histograms for event workspace in energy binning
Sample = Rebin(Test_BgDE,Params='-20,2,20',PreserveEvents=False);
# Calculate histograms for event workspace in energy binning and background removed
Result = Rebin(Test_BgDE,Params='-20,2,20',PreserveEvents=False,FlatBkgWorkspace='Bg',EMode='Direct');
# Calculate histograms for event workspace in energy binning
Result = Rebin(Test_BgDE,Params='-20,2,20',PreserveEvents=False);
# Remove flat background in-place
Result = RemoveBackground(Result,FlatBkgWorkspace='Bg',EMode='Direct');

# Get access to the results
XS = Sample.dataX(0);
Expand Down

0 comments on commit 39e7547

Please sign in to comment.