Commit 6aab5d7f authored by Anthony Lim's avatar Anthony Lim
Browse files

refs #32519 muon rebin phasequad tests

parent d7d760e2
......@@ -278,20 +278,26 @@ class MuonContext(object):
self.last_good_data(runs[0]))
phase_quad = run_PhaseQuad(parameters, ws_name)
tmp = retrieve_ws(phase_quad)
dt = tmp.readX(0)[1]-tmp.readX(0)[0]
phase_quad = self._run_rebin(phase_quad, rebin)
phase_quad = self._average_by_bin_widths(phase_quad, dt)
if rebin:
dt = self._get_bin_width(phase_quad)
phase_quad = self._run_rebin(phase_quad, True)
phase_quad = self._average_by_bin_widths(phase_quad, dt)
workspaces = split_phasequad(phase_quad)
return workspaces
def _get_bin_width(self, name):
tmp = self._get_x_data(name)
return tmp[1]-tmp[0]
def _get_x_data(self, name):
tmp = retrieve_ws(name)
return tmp.readX(0)
def _average_by_bin_widths(self, ws_name, dt):
#convert to Histogram to get bin widths and divide by how much bin widths have changed
ws_name= run_convert_to_histogram(ws_name)
data = retrieve_ws(ws_name)
ws_x = data.readX(0)
ws_x = self._get_x_data(ws_name)
# assume constant binning in raw data
dx = [ (ws_x[j+1]-ws_x[j])/(dt) for j in range(len(ws_x)-1)]
......
......@@ -38,6 +38,18 @@ def crop_side_effect(name, xmin, xmax):
return name
def average_side_effect(name, dt):
return name
def convert_side_effect(name):
return name
def divide_side_effect(LHS, RHS, name):
return name
@start_qapplication
class MuonContextTest(unittest.TestCase):
def setUp(self):
......@@ -489,6 +501,10 @@ class MuonContextTest(unittest.TestCase):
# 2 + 1
self.assertEqual(3, self.context._calculate_phasequads.call_count)
def set_up_phasequad_rebin_mock(self):
self.context._get_bin_width = mock.Mock(return_value = 0.1)
self.context._average_by_bin_widths = mock.Mock(side_effect=average_side_effect)
@mock.patch('Muon.GUI.Common.contexts.muon_context.run_PhaseQuad')
@mock.patch('Muon.GUI.Common.contexts.muon_context.split_phasequad')
@mock.patch('Muon.GUI.Common.contexts.muon_context.run_crop_workspace')
......@@ -502,14 +518,17 @@ class MuonContextTest(unittest.TestCase):
self.context._run_rebin = mock.Mock(side_effect=rebin_side_effect)
split_mock.side_effect = return_list
crop_mock.side_effect = crop_side_effect
self.set_up_phasequad_rebin_mock()
result = self.context.calculate_phasequad(phasequad, 5234, False)
# names are wrong due to split mock
self.assertEqual(result, [name+"1", name+"2"])
self.context._run_rebin.assert_called_with(name, False)
self.context._run_rebin.assert_not_called()
run_mock.assert_called_with({"PhaseTable": table, 'InputWorkspace': name}, name)
split_mock.assert_called_with(name)
crop_mock.assert_called_with(name, 0.0, 0.0)
self.context._get_bin_width.assert_not_called()
self.context._average_by_bin_widths.assert_not_called()
@mock.patch('Muon.GUI.Common.contexts.muon_context.run_PhaseQuad')
@mock.patch('Muon.GUI.Common.contexts.muon_context.split_phasequad')
......@@ -524,6 +543,7 @@ class MuonContextTest(unittest.TestCase):
self.context._run_rebin = mock.Mock(side_effect=rebin_side_effect)
split_mock.side_effect = return_list
crop_mock.side_effect = crop_side_effect
self.set_up_phasequad_rebin_mock()
result = self.context.calculate_phasequad(phasequad, 5234, True)
# names are wrong due to split mock
......@@ -532,6 +552,8 @@ class MuonContextTest(unittest.TestCase):
run_mock.assert_called_with({"PhaseTable": table, 'InputWorkspace': name}, name)
split_mock.assert_called_with(name)
crop_mock.assert_called_with(name, 0.0, 0.0)
self.context._get_bin_width.assert_called_once_with(name)
self.context._average_by_bin_widths.assert_called_once_with(name,0.1)
@mock.patch('Muon.GUI.Common.contexts.muon_context.run_PhaseQuad')
@mock.patch('Muon.GUI.Common.contexts.muon_context.split_phasequad')
......@@ -545,15 +567,18 @@ class MuonContextTest(unittest.TestCase):
self.context._run_rebin = mock.Mock(side_effect=rebin_side_effect)
split_mock.side_effect = return_list
crop_mock.side_effect = crop_side_effect
self.set_up_phasequad_rebin_mock()
result = self.context.calculate_phasequad(phasequad, 5234, False)
# names are wrong due to split mock
name = "EMU5234; PhaseQuad; test_Re__Im_; MA"
self.assertEqual(result, [name+"1", name+"2"])
self.context._run_rebin.assert_called_with(name, False)
self.context._run_rebin.assert_not_called()
run_mock.assert_called_with({"PhaseTable": table, 'InputWorkspace': name}, name)
split_mock.assert_called_with(name)
crop_mock.asser_called_with(name, 0.0, 0.0)
self.context._get_bin_width.assert_not_called()
self.context._average_by_bin_widths.assert_not_called()
@mock.patch('Muon.GUI.Common.contexts.muon_context.run_PhaseQuad')
@mock.patch('Muon.GUI.Common.contexts.muon_context.split_phasequad')
......@@ -567,6 +592,7 @@ class MuonContextTest(unittest.TestCase):
self.context._run_rebin = mock.Mock(side_effect=rebin_side_effect)
split_mock.side_effect = return_list
crop_mock.side_effect = crop_side_effect
self.set_up_phasequad_rebin_mock()
result = self.context.calculate_phasequad(phasequad, 5234, True)
# names are wrong due to split mock
......@@ -576,6 +602,31 @@ class MuonContextTest(unittest.TestCase):
run_mock.assert_called_with({"PhaseTable": table, 'InputWorkspace': name}, name)
split_mock.assert_called_with(name)
crop_mock.assert_called_with(name, 0.0, 0.0)
self.context._get_bin_width.assert_called_once_with(name)
self.context._average_by_bin_widths.assert_called_once_with(name,0.1)
@mock.patch('Muon.GUI.Common.contexts.muon_context.run_convert_to_histogram')
@mock.patch('Muon.GUI.Common.contexts.muon_context.run_convert_to_points')
@mock.patch('Muon.GUI.Common.contexts.muon_context.run_create_workspace')
@mock.patch('Muon.GUI.Common.contexts.muon_context.run_divide')
@mock.patch('Muon.GUI.Common.contexts.muon_context.delete_ws')
def test_average_by_bin_widths(self, delete, divide, create, points, histo):
self.context._get_x_data = mock.Mock(return_value = [0,1,3,4,6])
divide.side_effect = divide_side_effect
name = "test"
tmp = "tmp"
create.return_value = tmp
points.side_effect = convert_side_effect
histo.side_effect = convert_side_effect
self.context._average_by_bin_widths(name, .5)
histo.assert_called_once_with(name)
create.assert_called_once_with([0,1,3,4,6], [2, 4, 2, 4], tmp)
self.assertEqual(points.call_count, 2)
points.assert_any_call(name)
points.assert_any_call(tmp)
divide.assert_called_once_with(name, tmp, name)
delete.assert_called_once_with(tmp)
@mock.patch('Muon.GUI.Common.contexts.muon_context.get_raw_data_workspace_name')
@mock.patch('Muon.GUI.Common.contexts.muon_context.apply_deadtime')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment