Ejemplo n.º 1
0
 def create_EAGroup(self, group_name, detector, run_number):
     # This method should be used to create EAGroups as it sets error notifier
     group = EAGroup(group_name=group_name,
                     detector=detector,
                     run_number=run_number)
     group.set_error_notifier(self.error_notifier)
     return group
Ejemplo n.º 2
0
    def test_rebin(self, mock_get_item, mock_remove_ws, mock_retrieve_ws):
        mock_get_item.return_value = EAGroup("9999; Detector 1", "detector 1",
                                             "9999")
        name = '9999; Detector 1'
        rebinned_name = '9999; Detector 1' + REBINNED_VARIABLE_WS_SUFFIX
        mock_params = "0, 2, 9"

        x_data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
        y_data = [1, 1, 1, 1, 1, 1, 1, 1, 1]

        CreateWorkspace(OutputWorkspace=name, DataX=x_data, DataY=y_data)
        self.context._run_rebin("9999; Detector 1", "Variable", mock_params)

        correct_data = CreateWorkspace(OutputWorkspace="correct_data",
                                       DataX=[0, 2, 4, 6, 8, 9],
                                       DataY=[2, 2, 2, 2, 1])

        # Assert Statements
        self.assert_workspace_equal(correct_data, retrieve_ws(rebinned_name))
        mock_remove_ws.assert_has_calls([mock.call(rebinned_name)])
        mock_retrieve_ws.assert_has_calls([mock.call("9999")])
        mock_get_item.assert_has_calls([mock.call(name)])

        # clean up
        remove_ws_if_present(name)
        remove_ws_if_present("correct_data")
        remove_ws_if_present(rebinned_name)
Ejemplo n.º 3
0
    def test_create_tiled_keys_returns_correctly_for_tiled_by_group(self):
        self.context.group_context.add_group(
            EAGroup(group_name="9998; Detector 1",
                    detector="Detector 1",
                    run_number="9999"))
        self.context.group_context.add_group(
            EAGroup(group_name="9999; Detector 2",
                    detector="Detector 2",
                    run_number="9998"))
        self.context.group_context._selected_groups = [
            "9999; Detector 1", "9998; Detector 1", "9999; Detector 2"
        ]
        runs = [[9999], [9998]]
        self.context.data_context.current_runs = runs
        keys = self.model.create_tiled_keys("Detector")

        self.assertEqual(keys, ["Detector 1", "Detector 2"])
Ejemplo n.º 4
0
 def test_remove_workspace_from_group_when_not_in_group(
         self, mock_remove_matches, mock_remove_peak, mock_remove_rebinned):
     mock_group = EAGroup("9999; Detector 1", "detector 1", "9999")
     self.context.add_group(mock_group)
     self.context.remove_workspace_from_group('mock_workspace')
     mock_remove_rebinned.assert_not_called()
     mock_remove_peak.aassert_not_called()
     mock_remove_matches.assert_not_called()
Ejemplo n.º 5
0
 def setUp(self):
     setup_context_for_ea_tests(self)
     self.model = EAPlotDataPaneModel(context=self.context)
     self.name = "9999; Detector 1"
     test_group = EAGroup(group_name=self.name,
                          detector="Detector 1",
                          run_number="9999")
     self.context.group_context._groups = [test_group]
     self.context.group_context._selected_groups = [self.name]
Ejemplo n.º 6
0
 def test_remove_matches_table_from_group(self, mock_remove_matches,
                                          mock_remove_peak,
                                          mock_remove_rebinned):
     mock_group = EAGroup("9999; Detector 1", "detector 1", "9999")
     self.context.add_group(mock_group)
     self.context.remove_workspace_from_group('9999; Detector 1_EA_matches')
     mock_remove_rebinned.assert_not_called()
     mock_remove_peak.aassert_not_called()
     mock_remove_matches.assert_called_once()
Ejemplo n.º 7
0
    def test_create_tiled_keys_returns_correctly_for_tiled_by_run(self):
        self.context.group_context.add_group(
            EAGroup(group_name="9997; Detector 2",
                    detector="Detector 2",
                    run_number="9997"))
        self.context.group_context.add_group(
            EAGroup(group_name="9998; Detector 3",
                    detector="Detector 3",
                    run_number="9998"))
        self.context.group_context.add_group(
            EAGroup(group_name="9999; Detector 4",
                    detector="Detector 4",
                    run_number="9999"))
        self.context.group_context._selected_groups = [
            "9997; Detector 2", "9999; Detector 4"
        ]
        runs = [[9997, 9998, 9999]]
        self.context.data_context.current_runs = runs
        keys = self.model.create_tiled_keys("Run")

        self.assertEqual(keys, ['9997', '9999'])
Ejemplo n.º 8
0
    def test_remove_workspace_with_a_string(self, mock_notify_subscirbers):
        mock_group = EAGroup("mock_workspace", "detector 1", "9999")
        self.context.group_context.add_group(mock_group)
        self.context.group_context.remove_group = mock.Mock()
        # call remove_workspace function
        self.context.remove_workspace("mock_workspace")

        # assert statement
        mock_notify_subscirbers.assert_has_calls(
            [mock.call("mock_workspace"),
             mock.call("mock_workspace")])
        self.context.group_context.remove_group.assert_called_once_with(
            "mock_workspace")
Ejemplo n.º 9
0
    def test_clear_group(self):
        # setup
        self.assert_context_empty()
        self.context.data_context.current_runs.append("mock_run_1")
        self.context.data_context.current_runs.append("mock_run_2")
        self.context.group_context.add_group(
            EAGroup("9999; Detector 1", "detector 1", "9999"))
        self.context.group_context.add_group(
            EAGroup("9999; Detector 2", "detector 2", "9999"))
        self.context.data_context._loaded_data.add_data(
            workspace="mock_workspace_1")
        self.context.data_context._loaded_data.add_data(
            workspace="mock_workspace_2")

        # check if context is not empty
        with self.assertRaises(AssertionError):
            self.assert_context_empty()

        # call clear function
        self.context.clear_context()

        # check context is empty
        self.assert_context_empty()
Ejemplo n.º 10
0
    def setUp(self):
        workspaces = [
            "9999; Detector 1", "9999; Detector 2", "9999; Detector 3",
            "9999; Detector 4"
        ]
        self.group_context = EAGroupContext()
        for group_name in workspaces:
            self.group_context.add_group(
                EAGroup(group_name,
                        group_name.split(";")[1].strip(),
                        group_name.split(";")[0].strip()))

        self.context = ElementalAnalysisContext(None, self.group_context)
        self.model = EAAutoTabModel(self.context)
Ejemplo n.º 11
0
def get_default_grouping(loadedData, error_notifier=None):
    """this creates the first set of groups listed in the grouping table of the Elemental Analysis GUI
        For single workspace names the detector is found by taking everything after ; in the name
        For example : 2695; Detector 1 --> Detector 1
        For co-added workspaces the detector is found by taking everything before
        For example : Detector 1_2695-2686 --> Detector 1
    """
    groups = []
    run_list = loadedData.get_parameter("run")
    for run_item in run_list:
        for workspace in loadedData.get_data(run=run_item)["workspace"]:
            group_name = str(workspace)
            if not is_group_valid(group_name):
                continue
            detector_name = (group_name.split(';',
                                              1)[-1].lstrip()).split('_', 1)[0]
            run_number = str(run_item).replace('[', '').replace(']', '')
            group = EAGroup(group_name=group_name,
                            detector=detector_name,
                            run_number=run_number)
            if error_notifier is not None:
                group.set_error_notifier(error_notifier)
            groups += [group]
    return groups
Ejemplo n.º 12
0
    def setUp(self):
        workspaces = ["9999; Detector 1", "9999; Detector 2", "9999; Detector 3", "9999; Detector 4"]
        self.group_context = EAGroupContext()
        for group_name in workspaces:
            group = EAGroup(group_name, group_name.split(";")[1].strip(),
                            group_name.split(";")[0].strip())
            group.update_peak_table(group_name + PEAKS_WS_SUFFIX)
            group.update_matches_table(group_name + MATCH_GROUP_WS_SUFFIX)
            self.group_context.add_group(group)

        self.context = ElementalAnalysisContext(None, self.group_context)
        self.presenter = EAAutoTabPresenter(self.context, mock.Mock(), mock.Mock(), mock.Mock())
Ejemplo n.º 13
0
    def test_remove_workspace_with_a_workspace(self, mock_notify_subscirbers):
        # setup
        self.context.group_context.remove_group = mock.Mock()
        mock_group = EAGroup("mock_workspace", "detector 1", "9999")
        self.context.group_context.add_group(mock_group)
        mock_ws = CreateWorkspace(OutputWorkspace="mock_workspace",
                                  DataX=[0, 2, 4, 6, 8, 9],
                                  DataY=[2, 2, 2, 2, 1])

        # call remove_workspace function
        self.context.remove_workspace(mock_ws)

        # assert statement
        mock_notify_subscirbers.assert_has_calls(
            [mock.call("mock_workspace"),
             mock.call(mock_ws)])
        self.context.group_context.remove_group.assert_called_once_with(
            "mock_workspace")
 def test_add_group_from_table_with_valid_argument(self):
     mock_group = EAGroup("9999; Detector 1", "detector 1", "9999")
     self.model.add_group_from_table(mock_group)
     self.model._groups.add_group.assert_called_once_with(mock_group)
 def test_add_group_with_valid_argument(self):
     mock_group = EAGroup("9999; Detector 1", "detector 1", "9999")
     self.model.add_group(mock_group)
     self.model._groups.add_new_group.assert_called_once_with(
         mock_group, self.model._data._loaded_data)