Skip to content
Snippets Groups Projects
Commit c868b1c8 authored by Owen Arnold's avatar Owen Arnold
Browse files

refs #13890. Improve docs and progress reporting

parent b34f2d81
No related branches found
No related tags found
No related merge requests found
from mantid.api import DataProcessorAlgorithm, AlgorithmFactory, MatrixWorkspaceProperty, WorkspaceUnitValidator from mantid.api import DataProcessorAlgorithm, AlgorithmFactory, MatrixWorkspaceProperty, WorkspaceUnitValidator, \
Progress
from mantid.kernel import Direction, FloatArrayProperty, FloatArrayBoundedValidator from mantid.kernel import Direction, FloatArrayProperty, FloatArrayBoundedValidator
...@@ -81,6 +82,8 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): ...@@ -81,6 +82,8 @@ class DetectorFloodWeighting(DataProcessorAlgorithm):
def PyExec(self): def PyExec(self):
progress = Progress(self, 0, 1, 4) # Four coarse steps
in_ws = self.getProperty('InputWorkspace').value in_ws = self.getProperty('InputWorkspace').value
bands = self.getProperty('Bands').value bands = self.getProperty('Bands').value
...@@ -91,6 +94,7 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): ...@@ -91,6 +94,7 @@ class DetectorFloodWeighting(DataProcessorAlgorithm):
upper = bands[i+1] upper = bands[i+1]
step = upper - lower step = upper - lower
params.append((lower, step, upper)) params.append((lower, step, upper))
progress.report()
accumulated_output = None accumulated_output = None
rebin = self.createChildAlgorithm("Rebin") rebin = self.createChildAlgorithm("Rebin")
...@@ -98,6 +102,7 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): ...@@ -98,6 +102,7 @@ class DetectorFloodWeighting(DataProcessorAlgorithm):
rebin.setProperty("InputWorkspace", in_ws) rebin.setProperty("InputWorkspace", in_ws)
rebin.execute() rebin.execute()
accumulated_output = rebin.getProperty("OutputWorkspace").value accumulated_output = rebin.getProperty("OutputWorkspace").value
progress.report()
# Determine the max across all spectra # Determine the max across all spectra
y_values = accumulated_output.extractY() y_values = accumulated_output.extractY()
...@@ -111,6 +116,7 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): ...@@ -111,6 +116,7 @@ class DetectorFloodWeighting(DataProcessorAlgorithm):
# Divide each entry by max # Divide each entry by max
normalized = self._divide(accumulated_output, max_ws) normalized = self._divide(accumulated_output, max_ws)
progress.report()
# Perform solid angle correction. Calculate solid angle then divide through. # Perform solid angle correction. Calculate solid angle then divide through.
if self.getProperty("SolidAngleCorrection").value: if self.getProperty("SolidAngleCorrection").value:
...@@ -119,6 +125,7 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): ...@@ -119,6 +125,7 @@ class DetectorFloodWeighting(DataProcessorAlgorithm):
solidAngle.execute() solidAngle.execute()
solid_angle_weighting = solidAngle.getProperty("OutputWorkspace").value solid_angle_weighting = solidAngle.getProperty("OutputWorkspace").value
normalized = self._divide(normalized, solid_angle_weighting); normalized = self._divide(normalized, solid_angle_weighting);
progress.report()
self.setProperty('OutputWorkspace', normalized) self.setProperty('OutputWorkspace', normalized)
......
...@@ -11,7 +11,7 @@ Description ...@@ -11,7 +11,7 @@ Description
This algorithm is used to calculate the detector flood weighting workspace use for pixel flood corrections. It was originally developed for the ANSTO Bilby instrument. This algorithm is used to calculate the detector flood weighting workspace use for pixel flood corrections. It was originally developed for the ANSTO Bilby instrument.
This algorithm crops the data over the specified wavelength region, then normalizes each spectrum to the workspace spectrum maxima. The algorithm will then This algorithm crops the data over the specified wavelength region, then normalizes each spectrum to the workspace spectrum maxima. The algorithm will then
perform a solid angle correction on each spectra. perform a solid angle correction on each spectra via :ref:`algm-SolidAngle`.
Usage Usage
----- -----
...@@ -26,7 +26,7 @@ Usage ...@@ -26,7 +26,7 @@ Usage
dataY = [1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2] # or use dataY=[1]*9 dataY = [1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2] # or use dataY=[1]*9
ws = CreateWorkspace(dataX, dataY, NSpec=2, UnitX="Wavelength") ws = CreateWorkspace(dataX, dataY, NSpec=2, UnitX="Wavelength")
out_ws = DetectorFloodWeighting(InputWorkspace=ws, Bands=[0,10]) out_ws = DetectorFloodWeighting(InputWorkspace=ws, Bands=[0,10], SolidAngleCorrection=False)
print 'Number Histograms',out_ws.getNumberHistograms() print 'Number Histograms',out_ws.getNumberHistograms()
print 'Min X:', out_ws.readX(0)[0], 'Max X:', out_ws.readX(0)[1] print 'Min X:', out_ws.readX(0)[0], 'Max X:', out_ws.readX(0)[1]
...@@ -41,6 +41,24 @@ Output: ...@@ -41,6 +41,24 @@ Output:
Min X: 0.0 Max X: 10.0 Min X: 0.0 Max X: 10.0
Min Y: 0.5 Max Y: 1.0 Min Y: 0.5 Max Y: 1.0
**Example - With Solid Angle Correction **
.. testcode:: DetectorFloodWeightingExampleWithCorrection
ws = CreateSimulationWorkspace(Instrument='LOQ', BinParams=[1,1,10], UnitX="Wavelength")
out_ws = DetectorFloodWeighting(InputWorkspace=ws, Bands=[0,10], SolidAngleCorrection=True)
print 'Number Histograms',out_ws.getNumberHistograms()
print 'Number of Bins', out_ws.blocksize()
print 'X units', out_ws.getAxis(0).getUnit().unitID()
Output:
.. testoutput:: DetectorFloodWeightingExampleWithCorrection
Number Histograms 17776
Number of Bins 1
X units Wavelength
.. categories:: .. categories::
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment