From a89c0218a34e7ce2deaa258daeaf96a0da748c1a Mon Sep 17 00:00:00 2001 From: Gagik Vardanyan <vardanyan@ill.fr> Date: Mon, 16 Apr 2018 09:03:53 +0200 Subject: [PATCH] Re #21550 renamed system test, fixed reference, review comments --- .../Algorithms/src/SumOverlappingTubes.cpp | 5 +--- .../PowderDiffILLDetEffCorr.py | 26 ++++++++++--------- .../ApplyDetectorScanEffCorrTest.py | 4 +-- ...y => ILLPowderDiffDetScanReductionTest.py} | 6 ++--- .../analysis/reference/D2B_scan_test.nxs.md5 | 2 +- .../algorithms/PowderDiffILLDetEffCorr-v1.rst | 2 ++ 6 files changed, 23 insertions(+), 22 deletions(-) rename Testing/SystemTests/tests/analysis/{PowderDiffILLDetScanReductionTest.py => ILLPowderDiffDetScanReductionTest.py} (93%) diff --git a/Framework/Algorithms/src/SumOverlappingTubes.cpp b/Framework/Algorithms/src/SumOverlappingTubes.cpp index 09317967c72..fac9121644d 100644 --- a/Framework/Algorithms/src/SumOverlappingTubes.cpp +++ b/Framework/Algorithms/src/SumOverlappingTubes.cpp @@ -128,10 +128,7 @@ void SumOverlappingTubes::exec() { void SumOverlappingTubes::getInputParameters() { // This is flag for flipping the sign of 2theta - m_mirrorDetectors = 1; - if (getProperty("MirrorScatteringAngles")) { - m_mirrorDetectors = -1; - } + m_mirrorDetectors = getProperty("MirrorScatteringAngles") ? -1 : 1; const std::vector<std::string> inputWorkspaces = getProperty("InputWorkspaces"); diff --git a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/PowderDiffILLDetEffCorr.py b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/PowderDiffILLDetEffCorr.py index e6b7451ddc1..81877ccdcff 100644 --- a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/PowderDiffILLDetEffCorr.py +++ b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/PowderDiffILLDetEffCorr.py @@ -100,7 +100,7 @@ class PowderDiffILLDetEffCorr(PythonAlgorithm): doc='Choose sequential for D20 (1D detector), global for D2B (2D detector).') self.declareProperty(name='InterpolateOverlappingAngles', defaultValue=False, - doc='Wheter to interpolate scattering angle values in overlapping regions.') + doc='Whether to interpolate scattering angle values in overlapping regions (D20 only).') self.declareProperty(name='NormaliseTo', defaultValue='None', @@ -117,7 +117,7 @@ class PowderDiffILLDetEffCorr(PythonAlgorithm): self.declareProperty(FloatArrayProperty(name='ExcludedRange', values=[], validator=thetaRangeValidator), doc='Scattering angle regions to exclude from the computation of ' - 'relative calibration constants, e.g. beam stop [degrees]. ') + 'relative calibration constants; for example, the beam stop [degrees]. ') pixelRangeValidator = CompositeValidator() greaterThanOne = IntArrayBoundedValidator() @@ -130,8 +130,8 @@ class PowderDiffILLDetEffCorr(PythonAlgorithm): pixelRangeValidator.add(orderedPairsValidator) self.declareProperty(IntArrayProperty(name='PixelRange', values=[1,3072], validator=pixelRangeValidator), - doc='Range of the pixel numbers to compute the calibration factors for. ' - 'For the other pixels outside the range, the factor will be set to 1.') + doc='Range of the pixel numbers to compute the calibration factors for (D20 only); ' + 'for the other pixels outside the range, the factor will be set to 1.') self.declareProperty(MatrixWorkspaceProperty('OutputResponseWorkspace', '', optional=PropertyMode.Optional, direction=Direction.Output), @@ -144,7 +144,7 @@ class PowderDiffILLDetEffCorr(PythonAlgorithm): self.declareProperty(name='NumberOfIterations', defaultValue=1, validator=IntBoundedValidator(lower=0, upper=10), - doc='Number of iterations to perform. 0 means auto; i.e. the ' + doc='Number of iterations to perform (D2B only): 0 means auto; that is, the ' 'iterations will terminate after reaching some Chi2/NdoF.') def validateInputs(self): @@ -297,9 +297,7 @@ class PowderDiffILLDetEffCorr(PythonAlgorithm): start = self._pixels_to_trim end = self._n_pixels_per_tube - self._pixels_to_trim y = mtd[calib_current].extractY()[:,start:end] - ones = np.ones(y.shape) - diff = np.absolute(y - ones) - diff *= diff + diff = (y-1)**2 chi2 = np.sum(diff) ndof = (self._n_pixels_per_tube - 2 * self._pixels_to_trim) * self._n_tubes return chi2/ndof @@ -574,6 +572,8 @@ class PowderDiffILLDetEffCorr(PythonAlgorithm): self._derive_calibration_sequential(ws_2d, constants_ws, response_ws) DeleteWorkspace(ws_2d) self._perform_absolute_normalisation(constants_ws) + mtd[constants_ws].getAxis(1).setUnit('Label').setLabel('Cell #', '') + mtd[constants_ws].setYUnitLabel('Calibration constant') def _process_global(self): """ @@ -582,7 +582,6 @@ class PowderDiffILLDetEffCorr(PythonAlgorithm): 2. Loop over tubes, make ratios wrt reference, obtain constants 3. Apply the constants, and iterate over if requested """ - mon_ws = self._hide('mon') constants_ws = self._hide('constants') response_ws = self._hide('resp') calib_ws = self._hide('calib') @@ -602,8 +601,7 @@ class PowderDiffILLDetEffCorr(PythonAlgorithm): self._configure_global(ws_name) if self._normalise_to == 'Monitor': NormaliseToMonitor(InputWorkspace=ws_name, OutputWorkspace=ws_name, MonitorID=0) - ExtractMonitors(InputWorkspace=ws_name, DetectorWorkspace=ws_name, MonitorWorkspace=mon_ws) - DeleteWorkspace(mon_ws) + ExtractMonitors(InputWorkspace=ws_name, DetectorWorkspace=ws_name) ConvertSpectrumAxis(InputWorkspace=ws_name, OrderAxis=False, Target="SignedTheta", OutputWorkspace=ws_name) if self._calib_file: ApplyDetectorScanEffCorr(InputWorkspace=ws_name, DetectorEfficiencyWorkspace=calib_ws, OutputWorkspace=ws_name) @@ -620,7 +618,7 @@ class PowderDiffILLDetEffCorr(PythonAlgorithm): CloneWorkspace(InputWorkspace=constants_ws, OutputWorkspace=calib_current) iteration = 0 - chi2_ndof = 10000. # set a large number to start with + chi2_ndof = np.inf # set a large number to start with self._pixels_to_trim = 28 chi2_ndof_threshold = 1. inst = mtd[numors[0]].getInstrument() @@ -650,6 +648,9 @@ class PowderDiffILLDetEffCorr(PythonAlgorithm): DeleteWorkspace(ref_ws) DeleteWorkspaces(numors) DeleteWorkspace(calib_current) + mtd[constants_ws].getAxis(0).setUnit('Label').setLabel('Tube #', '') + mtd[constants_ws].getAxis(1).setUnit('Label').setLabel('Pixel #', '') + mtd[constants_ws].setYUnitLabel('Calibration constant') def _derive_calibration_global(self, numors): """ @@ -738,6 +739,7 @@ class PowderDiffILLDetEffCorr(PythonAlgorithm): self._input_files = self._input_files.replace(',','+') LoadAndMerge(Filename=self._input_files, OutputWorkspace=raw_ws, LoaderName='LoadILLDiffraction') if not mtd[raw_ws].getInstrument().getName().startswith('D20'): + DeleteWorkspace(raw_ws) raise RuntimeError('Sequential reference method is not supported for the instrument given') self._validate_scan(raw_ws) self._configure_sequential(raw_ws) diff --git a/Framework/PythonInterface/test/python/plugins/algorithms/ApplyDetectorScanEffCorrTest.py b/Framework/PythonInterface/test/python/plugins/algorithms/ApplyDetectorScanEffCorrTest.py index 81c9e1e2e16..0a13784999a 100644 --- a/Framework/PythonInterface/test/python/plugins/algorithms/ApplyDetectorScanEffCorrTest.py +++ b/Framework/PythonInterface/test/python/plugins/algorithms/ApplyDetectorScanEffCorrTest.py @@ -15,7 +15,7 @@ class ApplyDetectorScanEffCorrTest(unittest.TestCase): calibration_ws = CreateWorkspace(DataX=calibration_x, DataY=calibration_y, Nspec=calibration_y.size) calibrated_ws = ApplyDetectorScanEffCorr(input_ws, calibration_ws) - for i in range(0, 6): + for i in range(6): self.assertEquals(calibrated_ws.readY(i), input_ws.readY(i) * (i+1)) self.assertEquals(calibrated_ws.readE(i), input_ws.readE(i) * (i+1)) @@ -30,7 +30,7 @@ class ApplyDetectorScanEffCorrTest(unittest.TestCase): expected = np.repeat(calibration_y, 2) calibrated_ws = ApplyDetectorScanEffCorr(input_ws, calibration_ws) - for i in range(0, 12): + for i in range(12): self.assertEquals(calibrated_ws.readY(i), input_ws.readY(i) * expected[i]) self.assertEquals(calibrated_ws.readE(i), input_ws.readE(i) * expected[i]) diff --git a/Testing/SystemTests/tests/analysis/PowderDiffILLDetScanReductionTest.py b/Testing/SystemTests/tests/analysis/ILLPowderDiffDetScanReductionTest.py similarity index 93% rename from Testing/SystemTests/tests/analysis/PowderDiffILLDetScanReductionTest.py rename to Testing/SystemTests/tests/analysis/ILLPowderDiffDetScanReductionTest.py index aac26fb9ca0..0dfd1243a2b 100644 --- a/Testing/SystemTests/tests/analysis/PowderDiffILLDetScanReductionTest.py +++ b/Testing/SystemTests/tests/analysis/ILLPowderDiffDetScanReductionTest.py @@ -5,10 +5,10 @@ from mantid.simpleapi import PowderDiffILLDetScanReduction, \ from mantid import config -class PowderDiffILLDetScanReductionTest(stresstesting.MantidStressTest): +class ILLPowderDiffDetScanReductionTest(stresstesting.MantidStressTest): def __init__(self): - super(PowderDiffILLDetScanReductionTest, self).__init__() + super(ILLPowderDiffDetScanReductionTest, self).__init__() self.setUp() def setUp(self): @@ -17,7 +17,7 @@ class PowderDiffILLDetScanReductionTest(stresstesting.MantidStressTest): config.appendDataSearchSubDir('ILL/D2B/') def requiredFiles(self): - return ["508093.nxs, 508094.nxs, 508095.nxs, D2B_scan_test.nxs"] + return ["508093.nxs, 508094.nxs, 508095.nxs"] def d2b_2d_tubes_test(self): ws_2d_tubes = PowderDiffILLDetScanReduction( diff --git a/Testing/SystemTests/tests/analysis/reference/D2B_scan_test.nxs.md5 b/Testing/SystemTests/tests/analysis/reference/D2B_scan_test.nxs.md5 index 184dcf64eac..64f587253a4 100644 --- a/Testing/SystemTests/tests/analysis/reference/D2B_scan_test.nxs.md5 +++ b/Testing/SystemTests/tests/analysis/reference/D2B_scan_test.nxs.md5 @@ -1 +1 @@ -a07900a0131f43f0c4a92d37dd004db8 +6726846e1fcd84952bc28ec9e1eee441 diff --git a/docs/source/algorithms/PowderDiffILLDetEffCorr-v1.rst b/docs/source/algorithms/PowderDiffILLDetEffCorr-v1.rst index a75276bce13..bb2ecc3d790 100644 --- a/docs/source/algorithms/PowderDiffILLDetEffCorr-v1.rst +++ b/docs/source/algorithms/PowderDiffILLDetEffCorr-v1.rst @@ -150,6 +150,8 @@ D20 Workflow .. diagram:: PowderDiffILLDetEffCorr-v1_D20_wkflw.dot +.. include:: ../usagedata-note.txt + **Example - D20** .. code-block:: python -- GitLab