From c2896218a56b3e7dfe8cbedb28b89baf0b3f5658 Mon Sep 17 00:00:00 2001 From: David Fairbrother Date: Wed, 16 Aug 2017 16:05:50 +0100 Subject: [PATCH] Re #20252 ISIS Powder clarify error if diff TOF subtracting empty --- .../isis_powder/routines/common.py | 7 +++- scripts/test/ISISPowderCommonTest.py | 40 ++++++++++++------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/scripts/Diffraction/isis_powder/routines/common.py b/scripts/Diffraction/isis_powder/routines/common.py index 0b55cc03c93f..e25eaeb42fd4 100644 --- a/scripts/Diffraction/isis_powder/routines/common.py +++ b/scripts/Diffraction/isis_powder/routines/common.py @@ -391,7 +391,12 @@ def subtract_summed_runs(ws_to_correct, empty_sample_ws_string, instrument, scal if scale_factor: empty_sample = mantid.Scale(InputWorkspace=empty_sample, OutputWorkspace=empty_sample, Factor=scale_factor, Operation="Multiply") - mantid.Minus(LHSWorkspace=ws_to_correct, RHSWorkspace=empty_sample, OutputWorkspace=ws_to_correct) + try: + mantid.Minus(LHSWorkspace=ws_to_correct, RHSWorkspace=empty_sample, OutputWorkspace=ws_to_correct) + except ValueError: + raise ValueError("The empty run(s) specified for this file do not have matching binning. Do the TOF windows of" + " the empty and sample match?") + remove_intermediate_workspace(empty_sample) return ws_to_correct diff --git a/scripts/test/ISISPowderCommonTest.py b/scripts/test/ISISPowderCommonTest.py index 65133094f585..80eba229b04d 100644 --- a/scripts/test/ISISPowderCommonTest.py +++ b/scripts/test/ISISPowderCommonTest.py @@ -465,6 +465,23 @@ def test_run_normalise_by_current(self): common.run_normalise_by_current(ws) self.assertAlmostEqual(expected_value, ws.dataY(0)[0], delta=1e-8) + def test_spline_workspaces(self): + ws_list = [] + for i in range(1, 4): + out_name = "test_spline_vanadium-" + str(i) + ws_list.append(mantid.CreateSampleWorkspace(OutputWorkspace=out_name, NumBanks=1, BankPixelWidth=1, + XMax=100, BinWidth=1)) + + splined_list = common.spline_workspaces(focused_vanadium_spectra=ws_list, num_splines=10) + for ws in splined_list: + self.assertAlmostEqual(ws.dataY(0)[25], 0.28576649, delta=1e-8) + self.assertAlmostEqual(ws.dataY(0)[50], 0.37745918, delta=1e-8) + self.assertAlmostEqual(ws.dataY(0)[75], 0.28133096, delta=1e-8) + + for input_ws, splined_ws in zip(ws_list, splined_list): + mantid.DeleteWorkspace(input_ws) + mantid.DeleteWorkspace(splined_ws) + def test_subtract_summed_runs(self): # Load a vanadium workspace for this test sample_empty_number = "100" @@ -490,22 +507,17 @@ def test_subtract_summed_runs(self): mantid.DeleteWorkspace(returned_ws) mantid.DeleteWorkspace(scaled_ws) - def test_spline_workspaces(self): - ws_list = [] - for i in range(1, 4): - out_name = "test_spline_vanadium-" + str(i) - ws_list.append(mantid.CreateSampleWorkspace(OutputWorkspace=out_name, NumBanks=1, BankPixelWidth=1, - XMax=100, BinWidth=1)) + def test_subtract_summed_runs_throw_on_tof_mismatch(self): + # Create a sample workspace which will have mismatched TOF range + sample_ws = mantid.CreateSampleWorkspace() + ws_file_name = "100" # Load POL100 - splined_list = common.spline_workspaces(focused_vanadium_spectra=ws_list, num_splines=10) - for ws in splined_list: - self.assertAlmostEqual(ws.dataY(0)[25], 0.28576649, delta=1e-8) - self.assertAlmostEqual(ws.dataY(0)[50], 0.37745918, delta=1e-8) - self.assertAlmostEqual(ws.dataY(0)[75], 0.28133096, delta=1e-8) + # This should throw as the TOF ranges do not match + with assertRaisesRegex(self, ValueError, "specified for this file do not have matching binning. Do the "): + common.subtract_summed_runs(ws_to_correct=sample_ws, instrument=ISISPowderMockInst(), + empty_sample_ws_string=ws_file_name) - for input_ws, splined_ws in zip(ws_list, splined_list): - mantid.DeleteWorkspace(input_ws) - mantid.DeleteWorkspace(splined_ws) + mantid.DeleteWorkspace(sample_ws) class ISISPowderMockInst(object):