From a18c39f469eae1d76bef2c311ddfd5152c44085e Mon Sep 17 00:00:00 2001 From: Nick Draper <nick.draper@stfc.ac.uk> Date: Wed, 4 Jun 2014 16:35:07 +0100 Subject: [PATCH] re #9575 completed 1-3, next one is NormaliseByDetector.cpp --- .../Algorithms/src/CreateSampleWorkspace.cpp | 2 +- .../algorithms/CreateSampleWorkspace-v1.rst | 120 +++++++++++++++++- .../docs/source/algorithms/Pause-v1.rst | 19 +++ .../ResizeRectangularDetector-v1.rst | 25 ++++ 4 files changed, 163 insertions(+), 3 deletions(-) diff --git a/Code/Mantid/Framework/Algorithms/src/CreateSampleWorkspace.cpp b/Code/Mantid/Framework/Algorithms/src/CreateSampleWorkspace.cpp index 1437f59a379..d2a1d22f498 100644 --- a/Code/Mantid/Framework/Algorithms/src/CreateSampleWorkspace.cpp +++ b/Code/Mantid/Framework/Algorithms/src/CreateSampleWorkspace.cpp @@ -87,7 +87,7 @@ namespace Algorithms functionOptions.push_back(iterator->first); } declareProperty("Function","One Peak",boost::make_shared<StringListValidator>(functionOptions), - "The type of workspace to create (default: Histogram)"); + "Preset options of the data to fill the workspace with"); declareProperty("UserDefinedFunction","","Parameters defining the fitting function and its initial values"); declareProperty("NumBanks", 2,boost::make_shared<BoundedValidator<int> >(0,100), "The Number of banks in the instrument (default:2)"); diff --git a/Code/Mantid/docs/source/algorithms/CreateSampleWorkspace-v1.rst b/Code/Mantid/docs/source/algorithms/CreateSampleWorkspace-v1.rst index e65a833a0ba..25155aca0c9 100644 --- a/Code/Mantid/docs/source/algorithms/CreateSampleWorkspace-v1.rst +++ b/Code/Mantid/docs/source/algorithms/CreateSampleWorkspace-v1.rst @@ -21,13 +21,129 @@ will become positive. For event workspaces the intensity of the graph will be affected by the number of events selected. Here is an example of a user defined formula containing two peaks and a -background. +background.:: -``name=LinearBackground, A0=0.5;name=Gaussian, PeakCentre=10000, Height=50, Sigma=0.5;name=Gaussian, PeakCentre=1000, Height=80, Sigma=0.5`` + "name=LinearBackground, A0=0.5; + name=Gaussian, PeakCentre=10000, Height=50, Sigma=0.5; + name=Gaussian, PeakCentre=1000, Height=80, Sigma=0.5" Random also affects the distribution of events within bins for event workspaces. If Random is selected the results will differ between runs of the algorithm and will not be comparable. If comparing the output is important set Random to false or uncheck the box. +Usage +----- + +**Example - create a simple histogram workspace:** + +.. testcode:: ExHistSimple + + # create histogram workspace + ws = CreateSampleWorkspace() + + print "Number of spectra: " + str(ws.getNumberHistograms()) + print "Number of bins: " + str(ws.blocksize()) + print "Each spectra has a level backgound of " + str(ws.readY(0)[0]) + \ + " counts and a peak in the centre of " + str(ws.readY(0)[50]) + " counts." +Output: + +.. testoutput:: ExHistSimple + + Number of spectra: 200 + Number of bins: 100 + Each spectra has a level backgound of 0.3 counts and a peak in the centre of 10.3 counts. + +**Example - create a simple event workspace:** + +.. testcode:: ExEventSimple + + # create event workspace + ws = CreateSampleWorkspace("Event") + + print "Number of spectra: " + str(ws.getNumberHistograms()) + print "Number of bins: " + str(ws.blocksize()) + print "Number of events: " + str(ws.getNumberEvents()) + print "Event Workspaces come with bins set by default to a bin width of " + str(ws.readX(0)[1]-ws.readX(0)[0]) + #The data itensity of an EventWorkspce is scaled by the number of events used, so the values differ from the histogram above. + print "Each spectra has a level backgound of " + str(ws.readY(0)[0]) + \ + " counts and a peak in the centre of " + str(ws.readY(0)[50]) + " counts." +Output: + +.. testoutput:: ExEventSimple + + Number of spectra: 200 + Number of bins: 100 + Number of events: 800000 + Event Workspaces come with bins set by default to a bin width of 200.0 + Each spectra has a level backgound of 30.0 counts and a peak in the centre of 1030.0 counts. + +**Example - Using the preset functions:** + +.. testcode:: ExHistPresets + + # create a workspace with Flat Background + wsFlat = CreateSampleWorkspace("Histogram","Flat background") + print "Flat background has a constant value of " + str(wsFlat.readY(0)[0]) + " counts." + + # create a workspace with multiple peaks + wsMulti = CreateSampleWorkspace("Histogram","Multiple Peaks") + print "Multiple Peaks has a level backgound of " + str(wsMulti.readY(0)[0]), + print "counts and two gaussian peaks, the largest of which is " + str(wsMulti.readY(0)[60]) + " counts." + + # create a workspace with Exponential Decay + wsExp = CreateSampleWorkspace("Histogram","Exp Decay") + print ("Exp Decay starts high and drops rapidly to %.2f counts at 8,000 us (with the default binning)." % wsExp.readY(0)[40]) + +Output: + +.. testoutput:: ExHistPresets + + Flat background has a constant value of 1.0 counts. + Multiple Peaks has a level backgound of 0.3 counts and two gaussian peaks, the largest of which is 8.3 counts. + Exp Decay starts high and drops rapidly to 0.03 counts at 8,000 us (with the default binning). + + +**Example - Using the your own function:** + +.. testcode:: ExHistUserFunc + + # create a workspace with data defined using the function string below + myFunc = "name=LinearBackground, A0=0.5;name=Gaussian, PeakCentre=10000, Height=50, Sigma=0.5;name=Gaussian, PeakCentre=1000, Height=80, Sigma=0.5" + + ws = CreateSampleWorkspace("Histogram","User Defined",myFunc) + + print "My function defined a background of "+ str(ws.readY(0)[0]) + " counts." + print "With a peak reaching "+ str(ws.readY(0)[5]) + " counts at 1,000 us," + print "and another reaching "+ str(ws.readY(0)[50]) + " counts at 10,000 us." + + +Output: + +.. testoutput:: ExHistUserFunc + + My function defined a background of 0.5 counts. + With a peak reaching 80.5 counts at 1,000 us, + and another reaching 50.5 counts at 10,000 us. + +**Example - Setting every Option:** + +.. testcode:: ExEveryOption + + #Random adds a little random noise to the data function + ws=CreateSampleWorkspace(WorkspaceType="Event",Function="One Peak",NumBanks=4,BankPixelWidth=5,NumEvents=500,Random=True,XUnit="tof",XMin=0, XMax=8000, BinWidth=100) + + print "Number of spectra: " + str(ws.getNumberHistograms()) + print "Number of bins: " + str(ws.blocksize()) + +Output: + +.. testoutput:: ExEveryOption + + Number of spectra: 100 + Number of bins: 80 + .. categories:: + + + diff --git a/Code/Mantid/docs/source/algorithms/Pause-v1.rst b/Code/Mantid/docs/source/algorithms/Pause-v1.rst index 14cbc7cde9f..2418a469dc3 100644 --- a/Code/Mantid/docs/source/algorithms/Pause-v1.rst +++ b/Code/Mantid/docs/source/algorithms/Pause-v1.rst @@ -15,4 +15,23 @@ seconds. This can be used during debugging, for example, to slow down the execution of a fast script. + +Usage +----- + +**Example - Slowing down a loop:** + +.. testcode:: ExPauseString + import time + + start_time = time.clock() + Pause(0.05) + end_time = time.clock() + print ("The algorithm paused for %.2f seconds." % (end_time-start_time)) +Output: + +.. testoutput:: ExPauseString + + The algorithm paused for 0.05 seconds. + .. categories:: diff --git a/Code/Mantid/docs/source/algorithms/ResizeRectangularDetector-v1.rst b/Code/Mantid/docs/source/algorithms/ResizeRectangularDetector-v1.rst index 8b734c1959f..26559bca88a 100644 --- a/Code/Mantid/docs/source/algorithms/ResizeRectangularDetector-v1.rst +++ b/Code/Mantid/docs/source/algorithms/ResizeRectangularDetector-v1.rst @@ -34,4 +34,29 @@ See also :ref:`algm-MoveInstrumentComponent` and :ref:`algm-RotateInstrumentComponent` for other ways to move components. +Usage +----- + +**Example - Resize bank 1:** + +.. testcode:: ExScaleBank1 + + # a sample workspace with rectangular detectors + ws = CreateSampleWorkspace() + + ResizeRectangularDetector(ws,"bank1",2.0,0.5) + + i=ws.getInstrument() + bank1=i.getComponentByName('bank1') + bank2=i.getComponentByName('bank2') + + print ("bank 1 was scaled and is now %.2f by %.2f" % (bank1.xsize(), bank1.ysize())) + print ("bank 2 was not scaled and remains %.2f by %.2f" % (bank2.xsize(), bank2.ysize())) +Output: + +.. testoutput:: ExScaleBank1 + + bank 1 was scaled and is now 0.16 by 0.04 + bank 2 was not scaled and remains 0.08 by 0.08 + .. categories:: -- GitLab