diff --git a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/DetectorFloodWeighting.py b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/DetectorFloodWeighting.py index 473dffd5a2cd9ceb3b3e4d0f63a9fcd9d8a9ec27..014e69d9200d7be65124fda0de55087be38c78ab 100644 --- a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/DetectorFloodWeighting.py +++ b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/DetectorFloodWeighting.py @@ -32,6 +32,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,6 +71,13 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): return issues + def _divide(self, a, b): + divide = self.createChildAlgorithm("Divide") + divide.setProperty("LHSWorkspace", a) + divide.setProperty("RHSWorkspace", b) + divide.execute() + return divide.getProperty("OutputWorkspace").value + def PyExec(self): @@ -101,11 +110,15 @@ 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) + + # 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); 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..65d29aae4ba2c4ae1b4ddfaf86575055cd5c4af3 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. Usage -----