Skip to content
Snippets Groups Projects
Commit 20fe62af authored by Anton Piccardo-Selg's avatar Anton Piccardo-Selg
Browse files

Merge pull request #13891 from mantidproject/13890_detector_flood_weighting_solid_angle

Solid angle correction for DetectorFloodWeighting
parents 4c37e364 dd225b74
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
...@@ -32,6 +33,8 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): ...@@ -32,6 +33,8 @@ class DetectorFloodWeighting(DataProcessorAlgorithm):
direction=Direction.Output), direction=Direction.Output),
doc='Normalized flood weighting measurement') doc='Normalized flood weighting measurement')
self.declareProperty("SolidAngleCorrection", True, direction=Direction.Input, doc="Perform final solid angle correction")
def validateInputs(self): def validateInputs(self):
""" """
...@@ -69,9 +72,18 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): ...@@ -69,9 +72,18 @@ class DetectorFloodWeighting(DataProcessorAlgorithm):
return issues return issues
def _divide(self, lhs, rhs):
divide = self.createChildAlgorithm("Divide")
divide.setProperty("LHSWorkspace", lhs)
divide.setProperty("RHSWorkspace", rhs)
divide.execute()
return divide.getProperty("OutputWorkspace").value
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
...@@ -82,6 +94,7 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): ...@@ -82,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")
...@@ -89,6 +102,7 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): ...@@ -89,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()
...@@ -101,11 +115,17 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): ...@@ -101,11 +115,17 @@ class DetectorFloodWeighting(DataProcessorAlgorithm):
max_ws = create.getProperty("OutputWorkspace").value max_ws = create.getProperty("OutputWorkspace").value
# Divide each entry by max # Divide each entry by max
divide = self.createChildAlgorithm("Divide") normalized = self._divide(accumulated_output, max_ws)
divide.setProperty("LHSWorkspace", accumulated_output) progress.report()
divide.setProperty("RHSWorkspace", max_ws)
divide.execute() # Perform solid angle correction. Calculate solid angle then divide through.
normalized = divide.getProperty("OutputWorkspace").value if self.getProperty("SolidAngleCorrection").value:
solidAngle = self.createChildAlgorithm("SolidAngle")
solidAngle.setProperty("InputWorkspace", normalized)
solidAngle.execute()
solid_angle_weighting = solidAngle.getProperty("OutputWorkspace").value
normalized = self._divide(normalized, solid_angle_weighting)
progress.report()
self.setProperty('OutputWorkspace', normalized) self.setProperty('OutputWorkspace', normalized)
......
import unittest import unittest
from mantid.api import AlgorithmManager from mantid.api import AlgorithmManager
from mantid.simpleapi import CreateSampleWorkspace, DeleteWorkspace
class DetectorFloodWeightingTest(unittest.TestCase): class DetectorFloodWeightingTest(unittest.TestCase):
...@@ -47,10 +48,11 @@ class DetectorFloodWeightingTest(unittest.TestCase): ...@@ -47,10 +48,11 @@ class DetectorFloodWeightingTest(unittest.TestCase):
alg.setPropertyValue("OutputWorkspace", "dummy") alg.setPropertyValue("OutputWorkspace", "dummy")
self.assertRaises(RuntimeError, alg.execute) self.assertRaises(RuntimeError, alg.execute)
def test_execute_single(self): def test_execute_single_no_solid_angle(self):
alg = AlgorithmManager.create("DetectorFloodWeighting") alg = AlgorithmManager.create("DetectorFloodWeighting")
alg.setChild(True) alg.setChild(True)
alg.initialize() alg.initialize()
alg.setProperty("SolidAngleCorrection", False)
signal_value = 2 signal_value = 2
in_ws = self._create_ws(units="Wavelength", signal_value=signal_value, data_x=range(0,10,1)) in_ws = self._create_ws(units="Wavelength", signal_value=signal_value, data_x=range(0,10,1))
alg.setProperty("InputWorkspace", in_ws) alg.setProperty("InputWorkspace", in_ws)
...@@ -69,12 +71,23 @@ class DetectorFloodWeightingTest(unittest.TestCase): ...@@ -69,12 +71,23 @@ class DetectorFloodWeightingTest(unittest.TestCase):
print out_ws.readY(0)[0] print out_ws.readY(0)[0]
self.assertEquals(out_ws.readY(0)[0], 1.0) self.assertEquals(out_ws.readY(0)[0], 1.0)
def test_execute_single_with_solid_angle(self):
alg = AlgorithmManager.create("DetectorFloodWeighting")
alg.setChild(True)
alg.initialize()
alg.setProperty("SolidAngleCorrection", True)
signal_value = 2
in_ws = CreateSampleWorkspace(NumBanks=1, XUnit="Wavelength")
alg.setProperty("InputWorkspace", in_ws)
bands = [1,10]
alg.setProperty("Bands", bands) # One band
alg.setPropertyValue("OutputWorkspace", "dummy")
alg.execute()
out_ws = alg.getProperty("OutputWorkspace").value
self.assertEqual(1, out_ws.blocksize())
self.assertEqual("Wavelength", out_ws.getAxis(0).getUnit().unitID())
self.assertEqual(in_ws.getNumberHistograms(), out_ws.getNumberHistograms(), msg="Number of histograms should be unchanged.")
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -10,7 +10,8 @@ Description ...@@ -10,7 +10,8 @@ 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. 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 via :ref:`algm-SolidAngle`.
Usage Usage
----- -----
...@@ -25,7 +26,7 @@ Usage ...@@ -25,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]
...@@ -40,6 +41,24 @@ Output: ...@@ -40,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