Skip to content

Commit

Permalink
re #9612 done 1-9 inclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
NickDraper committed Jun 19, 2014
1 parent 844dd04 commit 898b9de
Show file tree
Hide file tree
Showing 10 changed files with 357 additions and 2 deletions.
46 changes: 46 additions & 0 deletions Code/Mantid/docs/source/algorithms/AddLogDerivative-v1.rst
Expand Up @@ -23,4 +23,50 @@ If any of the times in the logs are repeated, then those repeated time
values will be skipped, and the output derivative log will have fewer
points than the input.

Usage
-----

**Example: Taking the derivative of logs**

.. testcode:: AddLogDerivative

ws = CreateSampleWorkspace()
AddTimeSeriesLog(ws,"MyLog","2010-01-01T00:00:00",1.0,DeleteExisting=False)
AddTimeSeriesLog(ws,"MyLog","2010-01-01T00:00:10",2.0,DeleteExisting=False)
AddTimeSeriesLog(ws,"MyLog","2010-01-01T00:00:20",0.0,DeleteExisting=False)
AddTimeSeriesLog(ws,"MyLog","2010-01-01T00:00:30",5.0,DeleteExisting=False)

AddLogDerivative(ws,"MyLog",derivative=1,NewLogName="Derivative1")
AddLogDerivative(ws,"MyLog",derivative=2,NewLogName="Derivative2")
AddLogDerivative(ws,"MyLog",derivative=3,NewLogName="Derivative3")

for logName in ["MyLog","Derivative1","Derivative2","Derivative3"]:
print "Log: " + logName
print ws.getRun().getProperty(logName).valueAsString()


Output:

.. testoutput:: AddLogDerivative
:options: +NORMALIZE_WHITESPACE

Log: MyLog
2010-Jan-01 00:00:00 1
2010-Jan-01 00:00:10 2
2010-Jan-01 00:00:20 0
2010-Jan-01 00:00:30 5

Log: Derivative1
2010-Jan-01 00:00:05 0.1
2010-Jan-01 00:00:15 -0.2
2010-Jan-01 00:00:25 0.5

Log: Derivative2
2010-Jan-01 00:00:10 -0.03
2010-Jan-01 00:00:20 0.07

Log: Derivative3
2010-Jan-01 00:00:15 0.01


.. categories::
38 changes: 38 additions & 0 deletions Code/Mantid/docs/source/algorithms/CreateFlatEventWorkspace-v1.rst
Expand Up @@ -13,4 +13,42 @@ This creates a new event workspace from an existing one by sampling an area of t
source workspaces background and then using this to create a new workspace that covers
the same data range as the input workspace.

Usage
-----

**Example: Extract the background into another workspace**

.. testcode:: Extractbackground

ws = CreateSampleWorkspace("Event","Multiple Peaks")
wsOut=CreateFlatEventWorkspace(ws,RangeStart=15000,RangeEnd=18000)

#to compare we need to match the bins
wsOut=RebinToWorkspace(wsOut,ws,PreserveEvents=True)

print "The values for every 10th bin."
print "bin\tws\twsOut"
for i in range (0,ws.blocksize(),10):
print "%i\t%.2f\t%.2f" % (i,ws.readY(0)[i],wsOut.readY(0)[i])

Output:

.. testoutput:: Extractbackground
:options: +NORMALIZE_WHITESPACE

The values for every 10th bin.
bin ws wsOut
0 16.00 16.00
10 16.00 16.00
20 16.00 16.00
30 572.00 16.00
40 16.00 16.00
50 16.00 16.00
60 461.00 16.00
70 16.00 16.00
80 16.00 16.00
90 16.00 16.00



.. categories::
Expand Up @@ -42,4 +42,36 @@ shape must have been defined using, e.g.,
:ref:`algm-CreateSampleShape` and the gauge volume must be
fully within the sample.


Usage
-----

**Example: A simple spherical sample with a cuboid guage volume**

.. testcode:: ExCuboidGuageSimpleSpere

#setup the sample shape
sphere = '''<sphere id="sample-sphere">
<centre x="0" y="0" z="0"/>
<radius val=".2" />
</sphere>'''
ws = CreateSampleWorkspace("Histogram",NumBanks=1,BankPixelWidth=1)
ws = ConvertUnits(ws,"Wavelength")
ws = Rebin(ws,Params=[1])
CreateSampleShape(ws,sphere)
SetSampleMaterial(ws,ChemicalFormula="V")

#restrict the number of wavelength points to speed up the example
wsOut = CuboidGaugeVolumeAbsorption(ws, NumberOfWavelengthPoints=5, ElementSize=3,
SampleHeight=1,SampleWidth=2,SampleThickness=3)

print "The created workspace has one entry for each spectra: %i" % wsOut.getNumberHistograms()

Output:

.. testoutput:: ExCuboidGuageSimpleSpere

The created workspace has one entry for each spectra: 1


.. categories::
45 changes: 44 additions & 1 deletion Code/Mantid/docs/source/algorithms/FilterByLogValue-v1.rst
Expand Up @@ -60,12 +60,55 @@ nexus file. Some of these files have a sample log called
"veto\_pulse\_time" that only contains times of the pulses to be
rejected. For example, this call will filter out veto pulses:

``FilterByLogValue(InputWorkspace="ws", OutputWorkspace="ws", LogName="veto_pulse_time", PulseFilter="1")``
.. testsetup:: VetoPulseTime

ws=CreateSampleWorkspace("Event")
AddTimeSeriesLog(ws, Name="veto_pulse_time", Time="2010-01-01T00:00:00", Value=1)
AddTimeSeriesLog(ws, Name="veto_pulse_time", Time="2010-01-01T00:10:00", Value=0)
AddTimeSeriesLog(ws, Name="veto_pulse_time", Time="2010-01-01T00:20:00", Value=1)
AddTimeSeriesLog(ws, Name="veto_pulse_time", Time="2010-01-01T00:30:00", Value=0)
AddTimeSeriesLog(ws, Name="veto_pulse_time", Time="2010-01-01T00:40:00", Value=1)
AddTimeSeriesLog(ws, Name="veto_pulse_time", Time="2010-01-01T00:50:00", Value=0)

.. testcode:: VetoPulseTime

ws = FilterByLogValue(ws, LogName="veto_pulse_time", PulseFilter="1")

Comparing with other event filtering algorithms
###############################################

Wiki page `EventFiltering <http://www.mantidproject.org/EventFiltering>`__ has a detailed
introduction on event filtering in MantidPlot.


Usage
-----

**Example - Filtering by a simple time series Log**

.. testcode:: Filter

ws = CreateSampleWorkspace("Event",BankPixelWidth=1)
AddTimeSeriesLog(ws, Name="proton_charge", Time="2010-01-01T00:00:00", Value=100)
AddTimeSeriesLog(ws, Name="proton_charge", Time="2010-01-01T00:10:00", Value=100)
AddTimeSeriesLog(ws, Name="proton_charge", Time="2010-01-01T00:20:00", Value=100)
AddTimeSeriesLog(ws, Name="proton_charge", Time="2010-01-01T00:30:00", Value=100)
AddTimeSeriesLog(ws, Name="proton_charge", Time="2010-01-01T00:40:00", Value=15)
AddTimeSeriesLog(ws, Name="proton_charge", Time="2010-01-01T00:50:00", Value=100)

print "The unfiltered workspace %s has %i events and a peak value of %.2f" % (ws, ws.getNumberEvents(),ws.readY(0)[50])

wsOut = FilterByLogValue(ws,"proton_charge",MinimumValue=75, MaximumValue=150)

print "The filtered workspace %s has %i events and a peak value of %.2f" % (wsOut, wsOut.getNumberEvents(),wsOut.readY(0)[50])


Output:

.. testoutput:: Filter

The unfiltered workspace ws has 8000 events and a peak value of 1030.00
The filtered workspace wsOut has 4058 events and a peak value of 502.00


.. categories::
1 change: 1 addition & 0 deletions Code/Mantid/docs/source/algorithms/GetEi-v1.rst
Expand Up @@ -48,4 +48,5 @@ The distances between the monitors are read from the instrument
definition file. It is assumed that the source and the monitors all lie
on one line and that the monitors have the same delay time.


.. categories::
75 changes: 75 additions & 0 deletions Code/Mantid/docs/source/algorithms/GetEi-v2.rst
Expand Up @@ -51,4 +51,79 @@ The distances between the monitors are read from the instrument
definition file. It is assumed that the source and the monitors all lie
on one line and that the monitors have the same delay time.

Usage
-----

**Example: Calculating the Ei**

.. testcode:: calcEi

import numpy as np
import math

#create a workspace wth two pixels to act as monitors
ws = CreateSampleWorkspace(bankPixelWidth=1,binWidth=10)

#set the data values
peakOneCentre = 8500.0
sigmaSqOne = 250.0*250.0
peakTwoCentre = 10800.0
sigmaSqTwo = 50*50
peakOneHeight = 3000.0
peakTwoHeight = 1000.0
xArray = []
yArray0 = []
yArray1 = []
for i in range (ws.blocksize()):
xValue = 5.0 + 5.5*i
xArray.append(xValue)
yArray0.append(peakOneHeight * math.exp(-0.5*pow(xValue - peakOneCentre, 2.)/sigmaSqOne))
yArray1.append(peakTwoHeight * math.exp(-0.5*pow(xValue - peakTwoCentre, 2.)/sigmaSqTwo))
xArray.append(5.0 + 5.5*ws.blocksize())

ws.setX(0, np.array(xArray))
ws.setX(1, np.array(xArray))
ws.setY(0, np.array(yArray0))
ws.setY(1, np.array(yArray1))

(ei, firstMonitorPeak, FirstMonitorIndex, tzero) = GetEi(ws,Monitor1Spec=1,Monitor2Spec=2,EnergyEstimate=15.0)

print "ei: %.2f" % ei
print "firstMonitorPeak: %.2f" % firstMonitorPeak
print "FirstMonitorIndex: %i" % FirstMonitorIndex
print "tzero: %.2f" % tzero

Output:

.. testoutput:: calcEi
:options: +NORMALIZE_WHITESPACE

ei: 24.99
firstMonitorPeak: 8516.03
FirstMonitorIndex: 0
tzero: 1655.69

**Example: Fixing the Ei**

.. testcode:: fixEi

ws = CreateSampleWorkspace(bankPixelWidth=1,binWidth=10)

(ei, firstMonitorPeak, FirstMonitorIndex, tzero) = GetEi(ws,Monitor1Spec=1,Monitor2Spec=2,EnergyEstimate=15.0,FixEi=True)

print "ei: %.2f" % ei
print "firstMonitorPeak: %.2f" % firstMonitorPeak
print "FirstMonitorIndex: %i" % FirstMonitorIndex
print "tzero: %.2f" % tzero

Output:

.. testoutput:: fixEi
:options: +NORMALIZE_WHITESPACE

ei: 15.00
firstMonitorPeak: 8854.69
FirstMonitorIndex: 0
tzero: 0.00

.. categories::
24 changes: 23 additions & 1 deletion Code/Mantid/docs/source/algorithms/HRPDSlabCanAbsorption-v1.rst
Expand Up @@ -34,7 +34,7 @@ Restrictions on the input workspace
###################################

The input workspace must have units of wavelength. The
`instrument <instrument>`__ associated with the workspace must be fully
`instrument <http://www.mantidproject.org/instrument>`__ associated with the workspace must be fully
defined because detector, source & sample position are needed.

ChildAlgorithms used
Expand All @@ -43,4 +43,26 @@ ChildAlgorithms used
The :ref:`algm-FlatPlateAbsorption` algorithm is used to
calculate the correction due to the sample itself.

Usage
-----

**Example:**

.. testcode:: ExSimpleHRPDSlab

ws = CreateSampleWorkspace("Histogram",NumBanks=1,BankPixelWidth=1)
ws = ConvertUnits(ws,"Wavelength")
ws = Rebin(ws,Params=[1])
SetSampleMaterial(ws,ChemicalFormula="V")

wsOut = HRPDSlabCanAbsorption (ws,Thickness='0.2',ElementSize=3)

print "The created workspace has one entry for each spectra: %i" % wsOut.getNumberHistograms()

Output:

.. testoutput:: ExSimpleHRPDSlab

The created workspace has one entry for each spectra: 1

.. categories::
39 changes: 39 additions & 0 deletions Code/Mantid/docs/source/algorithms/RecordPythonScript-v1.rst
Expand Up @@ -6,6 +6,45 @@

.. properties::

This algorithm records the python commans of any algoithms that execute while it is running and saves them out to a file.

This is similar to extracting the history of a workspace, but outputs evey algorithm that occurs during it's execution rather than just for a specific workspace.

The file is written out once this algotithm is cancelled, either using the running algorithm details button or via python.


Usage
-----

**Example:**

.. This example is written as code blocks as it would require multi threading to run singly
.. Which is too complicated for a usage example
.. code-block:: python
RecordPythonScript("MyRecording.py")
# Run some algorithms in another python tab or via the GUI
# For example:
# ws = CreateSampleWorkspace("Event","Multiple Peaks")
# wsOut=CreateFlatEventWorkspace(ws,RangeStart=15000,RangeEnd=18000)
# wsOut=RebinToWorkspace(wsOut,ws,PreserveEvents=True)
# Then cancel the algorithm either using the GUI
# or executing this in another python tab
# AlgorithmManager.cancelAll()
Output:

.. code-block:: python
#a file containing the following:
CreateSampleWorkspace(OutputWorkspace='ws',WorkspaceType='Event',Function='Multiple Peaks',UserDefinedFunction='',NumBanks='2',BankPixelWidth='10',NumEvents='1000',Random='0',XUnit='TOF',XMin='0',XMax='20000',BinWidth='200')
CreateFlatEventWorkspace(InputWorkspace='ws',RangeStart='15000',RangeEnd='18000',OutputWorkspace='wsOut')
RebinToWorkspace(WorkspaceToRebin='wsOut',WorkspaceToMatch='ws',OutputWorkspace='wsOut',PreserveEvents='1')
.. categories::
36 changes: 36 additions & 0 deletions Code/Mantid/docs/source/algorithms/SignalOverError-v1.rst
Expand Up @@ -12,4 +12,40 @@ Description
Take a `MatrixWorkspace <http://www.mantidproject.org/MatrixWorkspace>`__ as input, and replaces the
Y values by Y/E (signal divided by error)


Usage
-----

**Example: Taking the derivative of logs**

.. testcode:: AddLogDerivative

ws = CreateSampleWorkspace("Event")
wsOut = SignalOverError(ws)

print "Values from every 10th bin"
print "bin\tY\tE\tY_New"
for i in range (0,ws.blocksize(),10):
print "%i\t%.2f\t%.2f\t%.2f" % (i,ws.readY(0)[i],ws.readE(0)[i],wsOut.readY(0)[i])


Output:

.. testoutput:: AddLogDerivative
:options: +NORMALIZE_WHITESPACE

Values from every 10th bin
bin Y E Y_New
0 30.00 5.48 5.48
10 30.00 5.48 5.48
20 30.00 5.48 5.48
30 30.00 5.48 5.48
40 30.00 5.48 5.48
50 1030.00 32.09 32.09
60 30.00 5.48 5.48
70 30.00 5.48 5.48
80 30.00 5.48 5.48
90 30.00 5.48 5.48


.. categories::

0 comments on commit 898b9de

Please sign in to comment.