From c868b1c85225f71b26d09a0f49e27563c86db264 Mon Sep 17 00:00:00 2001
From: Owen Arnold <owen.arnold@stfc.ac.uk>
Date: Thu, 8 Oct 2015 09:38:31 +0100
Subject: [PATCH] refs #13890. Improve docs and progress reporting

---
 .../DetectorFloodWeighting.py                 |  9 +++++++-
 .../algorithms/DetectorFloodWeighting-v1.rst  | 22 +++++++++++++++++--
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/DetectorFloodWeighting.py b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/DetectorFloodWeighting.py
index 014e69d9200..c159531bd73 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
 
@@ -81,6 +82,8 @@ class DetectorFloodWeighting(DataProcessorAlgorithm):
 
     def PyExec(self):
 
+        progress = Progress(self, 0, 1, 4) # Four coarse steps
+
         in_ws = self.getProperty('InputWorkspace').value
         bands = self.getProperty('Bands').value
 
@@ -91,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")
@@ -98,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()
@@ -111,6 +116,7 @@ class DetectorFloodWeighting(DataProcessorAlgorithm):
 
         # Divide each entry by max
         normalized = self._divide(accumulated_output, max_ws)
+        progress.report()
 
         # Perform solid angle correction. Calculate solid angle then divide through.
         if self.getProperty("SolidAngleCorrection").value:
@@ -119,6 +125,7 @@ class DetectorFloodWeighting(DataProcessorAlgorithm):
             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/docs/source/algorithms/DetectorFloodWeighting-v1.rst b/docs/source/algorithms/DetectorFloodWeighting-v1.rst
index 65d29aae4ba..b248c4b9d90 100644
--- a/docs/source/algorithms/DetectorFloodWeighting-v1.rst
+++ b/docs/source/algorithms/DetectorFloodWeighting-v1.rst
@@ -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 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
 -----
@@ -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
    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]  
@@ -41,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::
 
-- 
GitLab