Skip to content
Snippets Groups Projects
Unverified Commit 0a5db4e7 authored by Martyn Gigg's avatar Martyn Gigg Committed by GitHub
Browse files

Merge pull request #22337 from mantidproject/21967_ConvertToDistribution

Convert the workspace into distribution in DirectILLReduction
parents c9a1563d 4601795e
No related branches found
No related tags found
No related merge requests found
......@@ -6,8 +6,9 @@ import DirectILL_common as common
from mantid.api import (AlgorithmFactory, DataProcessorAlgorithm, InstrumentValidator,
MatrixWorkspaceProperty, Progress, PropertyMode, WorkspaceProperty, WorkspaceUnitValidator)
from mantid.kernel import (CompositeValidator, Direction, FloatArrayProperty, StringListValidator)
from mantid.simpleapi import (BinWidthAtX, CloneWorkspace, ConvertSpectrumAxis, ConvertUnits, CorrectKiKf, DetectorEfficiencyCorUser,
Divide, GroupDetectors, MaskDetectors, Rebin, Scale, SofQWNormalisedPolygon, Transpose)
from mantid.simpleapi import (BinWidthAtX, CloneWorkspace, ConvertSpectrumAxis, ConvertToDistribution, ConvertUnits, CorrectKiKf,
DetectorEfficiencyCorUser, Divide, GroupDetectors, MaskDetectors, Rebin, Scale, SofQWNormalisedPolygon,
Transpose)
import math
import numpy
import roundinghelper
......@@ -225,6 +226,9 @@ class DirectILLReduction(DataProcessorAlgorithm):
mainWS = self._rebinInW(mainWS, wsNames, wsCleanup, report,
subalgLogging)
# Divide the energy transfer workspace by bin widths.
mainWS = self._convertToDistribution(mainWS, wsNames, wsCleanup, subalgLogging)
# Detector efficiency correction.
progress.report('Correcting detector efficiency')
mainWS = self._correctByDetectorEfficiency(mainWS, wsNames,
......@@ -340,6 +344,17 @@ class DirectILLReduction(DataProcessorAlgorithm):
wsCleanup.cleanup(mainWS)
return maskedWS
def _convertToDistribution(self, mainWS, wsNames, wsCleanup, subalgLogging):
"""Convert the workspace into a distribution."""
distributionWSName = wsNames.withSuffix('as_distribution')
distributionWS = CloneWorkspace(InputWorkspace=mainWS,
OutputWorkspace=distributionWSName,
EnableLogging=subalgLogging)
wsCleanup.cleanup(mainWS)
ConvertToDistribution(Workspace=distributionWS,
EnableLogging=subalgLogging)
return distributionWS
def _convertTOFToDeltaE(self, mainWS, wsNames, wsCleanup, subalgLogging):
"""Convert the X axis units from time-of-flight to energy transfer."""
energyConvertedWSName = wsNames.withSuffix('energy_converted')
......
......@@ -78,6 +78,22 @@ class DirectILLReductionTest(unittest.TestCase):
groupIds = groupedWS.getDetector(0).getDetectorIDs()
self.assertEqual(collections.Counter(detectorIds), collections.Counter(groupIds))
def testOutputIsDistribution(self):
outWSName = 'outWS'
algProperties = {
'InputWorkspace': self._TEST_WS_NAME,
'OutputWorkspace': outWSName,
'OutputSofThetaEnergyWorkspace': 'SofThetaE',
'rethrow': True
}
run_algorithm('DirectILLReduction', **algProperties)
self.assertTrue(mtd.doesExist(outWSName))
ws = mtd[outWSName]
self.assertTrue(ws.isDistribution())
self.assertTrue(mtd.doesExist('SofThetaE'))
ws = mtd['SofThetaE']
self.assertTrue(ws.isDistribution())
def _checkAlgorithmsInHistory(self, ws, *args):
"""Return true if algorithm names listed in *args are found in the
workspace's history.
......
......@@ -23,6 +23,7 @@ digraph DirectILLReduction {
$algorithm_style
AbsoluteUnits [label="Scale to absolute units"]
ApplyDiagnostics [label="Mask spectra"]
ConvertToDistribution [label="ConvertToDistribution"]
ConvertToEnergy [label="Convert TOF to energy transfer"]
CorrectKiKf [label="CorrectKiKf"]
DetectorEfficiency [label="DetectorEfficiencyCorUser"]
......@@ -49,7 +50,8 @@ digraph DirectILLReduction {
ConvertToEnergy -> CorrectKiKf
CorrectKiKf -> Rebin
wRebinParams -> Rebin
Rebin -> DetectorEfficiency
Rebin -> ConvertToDistribution
ConvertToDistribution -> DetectorEfficiency
DetectorEfficiency -> GroupDetectors
GroupDetectors -> outputOptionalWS
GroupDetectors -> SofQW
......
......@@ -20,6 +20,8 @@ New features
Improvements
############
- :ref:`DirectILLReduction <algm-DirectILLReduction>` now converts all its output workspaces to distributions, i.e. divides the histograms by the bin width.
Bug fixes
#########
......
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