diff --git a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/DetectorFloodWeighting.py b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/DetectorFloodWeighting.py index 473dffd5a2cd9ceb3b3e4d0f63a9fcd9d8a9ec27..c929a3c23b3afe00c1ed0770e6b38ef0424e4a96 100644 --- a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/DetectorFloodWeighting.py +++ b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/DetectorFloodWeighting.py @@ -1,4 +1,5 @@ -from mantid.api import DataProcessorAlgorithm, AlgorithmFactory, MatrixWorkspaceProperty, WorkspaceUnitValidator +from mantid.api import DataProcessorAlgorithm, AlgorithmFactory, MatrixWorkspaceProperty, WorkspaceUnitValidator, \ + Progress from mantid.kernel import Direction, FloatArrayProperty, FloatArrayBoundedValidator @@ -32,6 +33,8 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): direction=Direction.Output), doc='Normalized flood weighting measurement') + self.declareProperty("SolidAngleCorrection", True, direction=Direction.Input, doc="Perform final solid angle correction") + def validateInputs(self): """ @@ -69,9 +72,18 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): 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): + progress = Progress(self, 0, 1, 4) # Four coarse steps + in_ws = self.getProperty('InputWorkspace').value bands = self.getProperty('Bands').value @@ -82,6 +94,7 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): upper = bands[i+1] step = upper - lower params.append((lower, step, upper)) + progress.report() accumulated_output = None rebin = self.createChildAlgorithm("Rebin") @@ -89,6 +102,7 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): rebin.setProperty("InputWorkspace", in_ws) rebin.execute() accumulated_output = rebin.getProperty("OutputWorkspace").value + progress.report() # Determine the max across all spectra y_values = accumulated_output.extractY() @@ -101,11 +115,17 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): max_ws = create.getProperty("OutputWorkspace").value # Divide each entry by max - divide = self.createChildAlgorithm("Divide") - divide.setProperty("LHSWorkspace", accumulated_output) - divide.setProperty("RHSWorkspace", max_ws) - divide.execute() - normalized = divide.getProperty("OutputWorkspace").value + normalized = self._divide(accumulated_output, max_ws) + progress.report() + + # Perform solid angle correction. Calculate solid angle then divide through. + 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) diff --git a/Framework/PythonInterface/test/python/plugins/algorithms/DetectorFloodWeightingTest.py b/Framework/PythonInterface/test/python/plugins/algorithms/DetectorFloodWeightingTest.py index 64167eec36dcf9ad6c674f1a367c0180d6965fe1..b2ca793e6254f263fb1d48b216104cfcf7f6b3fc 100644 --- a/Framework/PythonInterface/test/python/plugins/algorithms/DetectorFloodWeightingTest.py +++ b/Framework/PythonInterface/test/python/plugins/algorithms/DetectorFloodWeightingTest.py @@ -1,5 +1,6 @@ import unittest from mantid.api import AlgorithmManager +from mantid.simpleapi import CreateSampleWorkspace, DeleteWorkspace class DetectorFloodWeightingTest(unittest.TestCase): @@ -47,10 +48,11 @@ class DetectorFloodWeightingTest(unittest.TestCase): alg.setPropertyValue("OutputWorkspace", "dummy") self.assertRaises(RuntimeError, alg.execute) - def test_execute_single(self): + def test_execute_single_no_solid_angle(self): alg = AlgorithmManager.create("DetectorFloodWeighting") alg.setChild(True) alg.initialize() + alg.setProperty("SolidAngleCorrection", False) signal_value = 2 in_ws = self._create_ws(units="Wavelength", signal_value=signal_value, data_x=range(0,10,1)) alg.setProperty("InputWorkspace", in_ws) @@ -69,12 +71,23 @@ class DetectorFloodWeightingTest(unittest.TestCase): print out_ws.readY(0)[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__': diff --git a/docs/source/algorithms/DetectorFloodWeighting-v1.rst b/docs/source/algorithms/DetectorFloodWeighting-v1.rst index d6e206df0200079cb6bfe31681cb3d1beafbaf5e..b248c4b9d900d79aff5dd5ec4825d7438e445d8b 100644 --- a/docs/source/algorithms/DetectorFloodWeighting-v1.rst +++ b/docs/source/algorithms/DetectorFloodWeighting-v1.rst @@ -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 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 ----- @@ -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 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 'Min X:', out_ws.readX(0)[0], 'Max X:', out_ws.readX(0)[1] @@ -40,6 +41,24 @@ Output: Min X: 0.0 Max X: 10.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::