Skip to content

Commit

Permalink
Re mantidproject#20252 ISIS Powder clarify error if diff TOF subtract…
Browse files Browse the repository at this point in the history
…ing empty
  • Loading branch information
DavidFair committed Aug 16, 2017
1 parent afa66a8 commit c289621
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
7 changes: 6 additions & 1 deletion scripts/Diffraction/isis_powder/routines/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 26 additions & 14 deletions scripts/test/ISISPowderCommonTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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):
Expand Down

0 comments on commit c289621

Please sign in to comment.