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

refs #13919. Transmission fix.

parent 016d34c5
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 PropertyMode, Progress
from mantid.kernel import Direction, FloatArrayProperty, FloatArrayBoundedValidator from mantid.kernel import Direction, FloatArrayProperty, FloatArrayBoundedValidator
...@@ -23,6 +23,10 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): ...@@ -23,6 +23,10 @@ class DetectorFloodWeighting(DataProcessorAlgorithm):
self.declareProperty(MatrixWorkspaceProperty('InputWorkspace', '', self.declareProperty(MatrixWorkspaceProperty('InputWorkspace', '',
direction=Direction.Input, validator=WorkspaceUnitValidator("Wavelength")), direction=Direction.Input, validator=WorkspaceUnitValidator("Wavelength")),
doc='Flood weighting measurement') doc='Flood weighting measurement')
self.declareProperty(MatrixWorkspaceProperty('TransmissionWorkspace', '',
direction=Direction.Input, optional=PropertyMode.Optional, validator=WorkspaceUnitValidator("Wavelength")),
doc='Flood weighting measurement')
validator = FloatArrayBoundedValidator() validator = FloatArrayBoundedValidator()
validator.setLower(0.) validator.setLower(0.)
...@@ -66,6 +70,14 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): ...@@ -66,6 +70,14 @@ class DetectorFloodWeighting(DataProcessorAlgorithm):
all_limits.append(limits) all_limits.append(limits)
if lower >= upper: if lower >= upper:
issues['Bands'] = 'Bands should form lower, upper pairs' issues['Bands'] = 'Bands should form lower, upper pairs'
input_ws = self.getProperty('InputWorkspace').value
trans_ws = self.getProperty('TransmissionWorkspace').value
if trans_ws:
if not trans_ws.getNumberHistograms() == input_ws.getNumberHistograms():
issues['TransmissionWorkspace'] = 'Transmission should have same number of histograms as flood input workspace'
if not trans_ws.blocksize() == input_ws.blocksize():
issues['TransmissionWorkspace'] = 'Transmission workspace should be rebinned the same as the flood input workspace'
return issues return issues
...@@ -82,24 +94,14 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): ...@@ -82,24 +94,14 @@ class DetectorFloodWeighting(DataProcessorAlgorithm):
divide.setProperty("RHSWorkspace", rhs) divide.setProperty("RHSWorkspace", rhs)
divide.execute() divide.execute()
return divide.getProperty("OutputWorkspace").value return divide.getProperty("OutputWorkspace").value
def _integrate_bands(self, bands, in_ws):
def PyExec(self):
progress = Progress(self, 0, 1, 4) # Four coarse steps
in_ws = self.getProperty('InputWorkspace').value
bands = self.getProperty('Bands').value
x_range = max(bands)-min(bands)
sum_steps = 0
# Formulate bands, integrate and sum # Formulate bands, integrate and sum
accumulated_output = None accumulated_output = None
for i in range(0, len(bands), 2): for i in range(0, len(bands), 2):
lower = bands[i] lower = bands[i]
upper = bands[i+1] upper = bands[i+1]
step = upper - lower step = upper - lower
sum_steps += step
rebin = self.createChildAlgorithm("Rebin") rebin = self.createChildAlgorithm("Rebin")
rebin.setProperty("Params", [lower, step, upper]) rebin.setProperty("Params", [lower, step, upper])
...@@ -112,9 +114,23 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): ...@@ -112,9 +114,23 @@ class DetectorFloodWeighting(DataProcessorAlgorithm):
else: else:
# First band # First band
accumulated_output = integrated accumulated_output = integrated
return accumulated_output
progress.report()
def PyExec(self):
progress = Progress(self, 0, 1, 4) # Four coarse steps
in_ws = self.getProperty('InputWorkspace').value
trans_ws = self.getProperty('TransmissionWorkspace').value
bands = self.getProperty('Bands').value
x_range = max(bands)-min(bands)
accumulated_output = self._integrate_bands(bands, in_ws)
if trans_ws:
accumulated_trans_output = self._integrate_bands(bands, trans_ws)
progress.report()
# Perform solid angle correction. Calculate solid angle then divide through. # Perform solid angle correction. Calculate solid angle then divide through.
normalized=accumulated_output normalized=accumulated_output
...@@ -126,6 +142,10 @@ class DetectorFloodWeighting(DataProcessorAlgorithm): ...@@ -126,6 +142,10 @@ class DetectorFloodWeighting(DataProcessorAlgorithm):
normalized = self._divide(normalized, solid_angle_weighting) normalized = self._divide(normalized, solid_angle_weighting)
progress.report() progress.report()
# Divide through by the transmission workspace provided
if trans_ws:
normalized = self._divide(normalized, accumulated_output)
# Determine the max across all spectra # Determine the max across all spectra
y_values = normalized.extractY() y_values = normalized.extractY()
mean_val = np.mean(y_values) mean_val = np.mean(y_values)
......
...@@ -68,7 +68,6 @@ class DetectorFloodWeightingTest(unittest.TestCase): ...@@ -68,7 +68,6 @@ class DetectorFloodWeightingTest(unittest.TestCase):
x_axis = out_ws.readX(0) x_axis = out_ws.readX(0)
self.assertEquals(x_axis[0], bands[0]) self.assertEquals(x_axis[0], bands[0])
self.assertEquals(x_axis[-1], bands[-1]) self.assertEquals(x_axis[-1], bands[-1])
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_multiple_bands_no_solid_angle(self): def test_execute_multiple_bands_no_solid_angle(self):
...@@ -91,9 +90,32 @@ class DetectorFloodWeightingTest(unittest.TestCase): ...@@ -91,9 +90,32 @@ class DetectorFloodWeightingTest(unittest.TestCase):
x_axis = out_ws.readX(0) x_axis = out_ws.readX(0)
self.assertEquals(x_axis[0], bands[0]) self.assertEquals(x_axis[0], bands[0])
self.assertEquals(x_axis[-1], bands[-1]) self.assertEquals(x_axis[-1], bands[-1])
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_multiple_bands_no_solid_angle_with_transmission(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)
alg.setProperty("TransmissionWorkspace", in_ws)
bands = [1,2,3,4]
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.")
x_axis = out_ws.readX(0)
self.assertEquals(x_axis[0], bands[0])
self.assertEquals(x_axis[-1], bands[-1])
self.assertEquals(out_ws.readY(0)[0], 1.0)
def test_execute_single_with_solid_angle(self): def test_execute_single_with_solid_angle(self):
alg = AlgorithmManager.create("DetectorFloodWeighting") alg = AlgorithmManager.create("DetectorFloodWeighting")
alg.setChild(True) alg.setChild(True)
......
...@@ -10,8 +10,7 @@ Description ...@@ -10,8 +10,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, and sums it. The algorithm will then perform a solid angle correction on each spectra via :ref:`algm-SolidAngle` if specified, and divides through by the provided transmission workspace if provided. The result is divided by the mean spectrum value in the previous result.
perform a solid angle correction on each spectra via :ref:`algm-SolidAngle`.
Usage Usage
----- -----
......
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