Skip to content

Commit

Permalink
re #9590 done up to and including 27
Browse files Browse the repository at this point in the history
  • Loading branch information
NickDraper committed Jun 18, 2014
1 parent a4c286e commit da5133c
Show file tree
Hide file tree
Showing 17 changed files with 431 additions and 28 deletions.
Expand Up @@ -14,6 +14,9 @@ columns ColumnX, ColumnY, and ColumnE respectively. If ColumnE is not
set the E vector will be filled with 1s. The type of the columns must be
convertible to C++ double.

Usage
-----

**Example**

.. testcode:: ExConvertTabletoMatrix
Expand Down
26 changes: 26 additions & 0 deletions Code/Mantid/docs/source/algorithms/CreatePSDBleedMask-v1.rst
Expand Up @@ -20,5 +20,31 @@ Restrictions on the input workspace
###################################

- The workspace must contain either raw counts or counts/us.
Usage
-----

**Example:**

.. testcode:: ExPSDMask

import numpy as np

ws=CreateSampleWorkspace()
AddSampleLog(ws,"goodfrm","10","Number")
noisyY = np.array(ws.readY(0))
noisyY[0]=1e20
ws.setY(50,noisyY)
(wsOut, numFailures) = CreatePSDBleedMask(ws,MaxTubeFramerate=10, NIgnoredCentralPixels=2)

print "%i spectra have been masked in wsOut" % numFailures


Output:

.. testoutput:: ExPSDMask

10 spectra have been masked in wsOut



.. categories::
36 changes: 36 additions & 0 deletions Code/Mantid/docs/source/algorithms/DeleteTableRows-v1.rst
Expand Up @@ -12,4 +12,40 @@ Description
If the specified rows exist they will be deleted form the workspace. If
the row list is empty the algorithm does nothing.

Usage
-----

**Example**

.. testcode:: ExDeteleTableRows

t=WorkspaceFactory.createTable()
t.addColumn("double","A")
t.addColumn("double","B")
t.addColumn("double","BError")
for i in range(20):
t.addRow([i,i*2,1])

#add it to the Mantid workspace list
mtd.addOrReplace("myTable",t)

#delete a single row
DeleteTableRows(t,Rows=0) #The row index starts at 0

#delete a List of rows, you can also refer to the workspace using the name in the Workspace List
DeleteTableRows(t,Rows=[2,4,6,8]) #Note: the previous delete will have moved all the rows up 1

#delete a range of rows, you can also refer to the workspace using the name in the Workspace List
DeleteTableRows("myTable",Rows=range(7,14))

print "The remaining values in the first column"
print t.column(0)

Output:

.. testoutput:: ExDeteleTableRows

The remaining values in the first column
[1.0, 2.0, 4.0, 6.0, 8.0, 10.0, 11.0, 19.0]

.. categories::
Expand Up @@ -9,6 +9,6 @@
Description
-----------

Documentation to come.
This algoirthm is not intended for use directly, it is part of the SNS SANS reduction workflow.

.. categories::
42 changes: 42 additions & 0 deletions Code/Mantid/docs/source/algorithms/ExtractMask-v1.rst
Expand Up @@ -18,4 +18,46 @@ new MatrixWorkspace with a single X bin where:
The spectra containing 0 are also marked as masked and the instrument
link is preserved so that the instrument view functions correctly.


Usage
-----

**Example**

.. testcode:: ExExtractMask

#create a workspace with a 3*3 pixel detector
bankPixelWidth = 3
ws = CreateSampleWorkspace(NumBanks=1,BankPixelWidth=bankPixelWidth)

#Mask out every other detector
MaskDetectors(ws,WorkspaceIndexList=range(0,bankPixelWidth*bankPixelWidth,2))

wsMask = ExtractMask(ws)

#This mask can then be applied to another workspace
ws2 = CreateSampleWorkspace(NumBanks=1,BankPixelWidth=bankPixelWidth)
MaskDetectors(ws2,MaskedWorkspace="wsMask")

print "Masked Detectors"
print "n ws ws2"
for i in range (ws.getNumberHistograms()):
print "%i %-5s %s" % (i, ws.getDetector(i).isMasked(), ws2.getDetector(i).isMasked())

Output:

.. testoutput:: ExExtractMask

Masked Detectors
n ws ws2
0 True True
1 False False
2 True True
3 False False
4 True True
5 False False
6 True True
7 False False
8 True True

.. categories::
32 changes: 32 additions & 0 deletions Code/Mantid/docs/source/algorithms/ExtractSingleSpectrum-v1.rst
Expand Up @@ -12,4 +12,36 @@ Description
Extracts a single spectrum from a `Workspace2D <Workspace2D>`__ and
stores it in a new workspace.

Usage
-----

**Example**

.. testcode:: ExExtractSingleSpectrum

ws = CreateSampleWorkspace()
print "Workspace %s contains %i spectra" % (ws, ws.getNumberHistograms())
print "Counts for every 10th bin for workspace index 5"
print ws.readY(5)[0:100:10]

wsOut = ExtractSingleSpectrum(ws,WorkspaceIndex=5)
print "After extracting one spectra at workspace index 5"

print "Workspace %s contains %i spectra" % (wsOut, wsOut.getNumberHistograms())
print "Counts for every 10th bin for workspace index 0 (now it's 0 as wsOut only contains 1 spectra)"
print wsOut.readY(0)[0:100:10]


Output:

.. testoutput:: ExExtractSingleSpectrum

Workspace ws contains 200 spectra
Counts for every 10th bin for workspace index 5
[ 0.3 0.3 0.3 0.3 0.3 10.3 0.3 0.3 0.3 0.3]
After extracting one spectra at workspace index 5
Workspace wsOut contains 1 spectra
Counts for every 10th bin for workspace index 0 (now it's 0 as wsOut only contains 1 spectra)
[ 0.3 0.3 0.3 0.3 0.3 10.3 0.3 0.3 0.3 0.3]

.. categories::
55 changes: 55 additions & 0 deletions Code/Mantid/docs/source/algorithms/FFTDerivative-v1.rst
Expand Up @@ -9,6 +9,61 @@
Description
-----------

Calcuates the derivative of the specta in a workspace using :ref:`algm-FFT`.

Usage
-----

**Example: Different Orders of Derivative**

.. testcode:: ExFFTDerivOrders

wsOriginal = CreateSampleWorkspace(XMax=20,BinWidth=0.2,BankPixelWidth=1,NumBanks=1)
wsOrder1 = FFTDerivative(wsOriginal,Order=1)
wsOrder2 = FFTDerivative(wsOriginal,Order=2)
wsOrder3 = FFTDerivative(wsOriginal,Order=3)

print "bin Orig 1st 2nd 3rd"
for i in range (40,66,5):
print "%i %.2f %.2f %.2f %.2f" % (i, wsOriginal.readY(0)[i], wsOrder1.readY(0)[i], wsOrder2.readY(0)[i], wsOrder3.readY(0)[i])

.. figure:: /images/FFTDerivativeExample.png
:align: right
:height: 200px

Output:

.. testoutput:: ExFFTDerivOrders

bin Orig 1st 2nd 3rd
40 0.47 0.69 2.47 7.26
45 3.90 7.36 7.66 -14.40
50 10.30 0.00 -20.41 -0.00
55 3.90 -7.36 7.66 14.40
60 0.47 -0.69 2.47 -7.26
65 0.30 -0.01 0.04 -0.20


**Example: Different Orders of Derivative**

.. testcode:: ExFFTDerivOrderCheck2Ways

wsOriginal = CreateSampleWorkspace(XMax=20,BinWidth=0.2,BankPixelWidth=1,NumBanks=1)
wsOrder1 = FFTDerivative(wsOriginal,Order=1)
wsOrder2 = FFTDerivative(wsOriginal,Order=2)

wsOrder2Test = FFTDerivative(wsOrder1,Order=1)

print "The direct 2nd order derivative and the derivative of a derivative should match"
print CheckWorkspacesMatch(wsOrder2,wsOrder2Test,CheckAllData=True,Tolerance=1e10)

Output:

.. testoutput:: ExFFTDerivOrderCheck2Ways

The direct 2nd order derivative and the derivative of a derivative should match
Success!



.. categories::
62 changes: 44 additions & 18 deletions Code/Mantid/docs/source/algorithms/FFTSmooth-v1.rst
Expand Up @@ -13,7 +13,7 @@ FFTSmooth uses the FFT algorithm to create a Fourier transform of a
spectrum, applies a filter to it and transforms it back. The filters
remove higher frequencies from the spectrum which reduces the noise.

The second version of the FFTSmooth algorithm has two filters:
This version of the FFTSmooth algorithm has one filter:

Zeroing
#######
Expand All @@ -23,26 +23,52 @@ Zeroing
coefficients with frequencies outside the 1/n of the original range
will be set to zero.

Butterworth
###########

- Filter: "Butterworth"
- Params: A string containing two positive integer parameters separated
by a comma, such as 20,2.
Usage
-----

"n"- the first integer, specifies the cutoff frequency for the filter,
in the same way as for the "Zeroing" filter. That is, the cutoff is at
m/n where m is the original range. "n" is required to be strictly more
than 1.
**Example: Zeroing with Params=2**

"order"- the second integer, specifies the order of the filter. For low
order values, such as 1 or 2, the Butterworth filter will smooth the
data without the strong "ringing" artifacts produced by the abrupt
cutoff of the "Zeroing" filter. As the order parameter is increased, the
action of the "Butterworth" filter will approach the action of the
"Zeroing" filter.
.. testcode:: ExFFTSmoothZeroing

For both filter types, the resulting spectrum has the same size as the
original one.
ws = CreateSampleWorkspace(function="Multiple Peaks",XMax=20,BinWidth=0.2,BankPixelWidth=1,NumBanks=1)

#add a bit of predictable noise
noiseAmp=0.1
noiseArray= []
for i in range(ws.blocksize()):
noiseAmp = -noiseAmp
noiseArray.append(noiseAmp)

for j in range(ws.getNumberHistograms()):
ws.setY(j,ws.readY(j)+noiseArray)


wsSmooth = FFTSmooth(ws, Params='2', Version=1)

print "bin Orig Smoothed"
for i in range (0,100,10):
print "%i %.2f %.2f" % (i, ws.readY(0)[i], wsSmooth.readY(0)[i])


.. figure:: /images/FFTSmoothZeroing.png
:align: right
:height: 280px

Output:

.. testoutput:: ExFFTSmoothZeroing

bin Orig Smoothed
0 0.20 0.30
10 0.20 0.30
20 0.37 0.47
30 10.20 10.30
40 0.37 0.47
50 0.20 0.30
60 8.20 8.30
70 0.20 0.30
80 0.20 0.30
90 0.20 0.30

.. categories::

0 comments on commit da5133c

Please sign in to comment.