Skip to content
Snippets Groups Projects
Commit ac63e738 authored by Antti Soininen's avatar Antti Soininen
Browse files

DirectILLDiagnostics: small fixes

- Replace the '*=' operator by CreateSingleWorkspace & Multiply
algorithm to remove the extra logging.
- Handle the output of ExtractMask as named tuple, don't unpack. Just to
be future proof.
- Add some unit tests.

Re #23597
parent 9422b760
No related branches found
No related tags found
No related merge requests found
......@@ -9,8 +9,8 @@ from mantid.api import (AlgorithmFactory, DataProcessorAlgorithm, InstrumentVali
WorkspaceProperty, WorkspaceUnitValidator)
from mantid.kernel import (CompositeValidator, Direction, FloatBoundedValidator, IntArrayBoundedValidator,
IntArrayProperty, Property, StringArrayProperty, StringListValidator)
from mantid.simpleapi import (ClearMaskFlag, CloneWorkspace, CreateEmptyTableWorkspace, Divide,
ExtractMask, Integration, LoadMask, MaskDetectors, MedianDetectorTest, Plus, SolidAngle)
from mantid.simpleapi import (ClearMaskFlag, CloneWorkspace, CreateEmptyTableWorkspace, CreateSingleValuedWorkspace, Divide,
ExtractMask, Integration, LoadMask, MaskDetectors, MedianDetectorTest, Multiply, Plus, SolidAngle)
import numpy
import os.path
......@@ -83,10 +83,17 @@ def _createDiagnosticsReportTable(reportWSName, numberHistograms, algorithmLoggi
def _createMaskWS(ws, name, algorithmLogging):
"""Return a single bin workspace with same number of histograms as ws."""
maskWS, detList = ExtractMask(InputWorkspace=ws,
OutputWorkspace=name,
EnableLogging=algorithmLogging)
maskWS *= 0.0
extractResult = ExtractMask(InputWorkspace=ws,
OutputWorkspace=name,
EnableLogging=algorithmLogging)
zeroWS = CreateSingleValuedWorkspace(DataValue=0.,
ErrorValue=0.,
EnableLogging=algorithmLogging,
StoreInADS=False)
maskWS = Multiply(LHSWorkspace=extractResult.OutputWorkspace,
RHSWorkspace=zeroWS,
OutputWorkspace=name,
EnableLogging=algorithmLogging)
return maskWS
......@@ -793,10 +800,10 @@ class DirectILLDiagnostics(DataProcessorAlgorithm):
DetectorList=userMask,
ComponentList=maskComponents,
EnableLogging=algorithmLogging)
maskWS, detectorList = ExtractMask(InputWorkspace=maskWS,
OutputWorkspace=maskWSName,
EnableLogging=algorithmLogging)
return maskWS
extractResult = ExtractMask(InputWorkspace=maskWS,
OutputWorkspace=maskWSName,
EnableLogging=algorithmLogging)
return extractResult.OutputWorkspace
def _value(self, ws, propertyName, instrumentParameterName, defaultValue):
"""Return a suitable value either from a property, the IPF or the supplied defaultValue."""
......
......@@ -181,6 +181,34 @@ class DirectILLDiagnosticsTest(unittest.TestCase):
else:
self.assertEquals(ys[0], 0)
def testMaskedComponents(self):
inWS = mtd[self._RAW_WS_NAME]
spectraCount = inWS.getNumberHistograms()
outWSName = 'diagnosticsWS'
kwargs = {
'InputWorkspace': self._RAW_WS_NAME,
'OutputWorkspace': outWSName,
'ElasticPeakDiagnostics': 'Peak Diagnostics OFF',
'BkgDiagnostics': 'Bkg Diagnostics OFF',
'BeamStopDiagnostics': 'Beam Stop Diagnostics OFF',
'DefaultMask': 'Default Mask OFF',
'MaskedComponents': 'tube_1',
'rethrow': True
}
run_algorithm('DirectILLDiagnostics', **kwargs)
self.assertTrue(mtd.doesExist(outWSName))
outWS = mtd[outWSName]
self.assertEquals(outWS.getNumberHistograms(), spectraCount)
self.assertEquals(outWS.blocksize(), 1)
for i in range(spectraCount):
Ys = outWS.readY(i)
detector = outWS.getDetector(i)
componentName = detector.getFullName()
if 'tube_1' in componentName:
self.assertEquals(Ys[0], 1)
else:
self.assertEquals(Ys[0], 0)
def testOutputIsUsable(self):
inWS = mtd[self._RAW_WS_NAME]
spectraCount = inWS.getNumberHistograms()
......
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