diff --git a/qt/python/mantidqt/_common.sip b/qt/python/mantidqt/_common.sip index 4ddfdbb8ffdd6814108d456bd2489d8b82ba9859..634300b3e5331bf2471f8c7d08b9655598e88f7e 100644 --- a/qt/python/mantidqt/_common.sip +++ b/qt/python/mantidqt/_common.sip @@ -896,6 +896,7 @@ public: QString getText(); QString getFirstFilename() const; + QStringList getFilenames() const; void isForRunFiles(bool /*mode*/); void isForDirectory(bool /*mode*/); void allowMultipleFiles(bool /*allow*/); diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/model.py b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/model.py index 80575eceb9daae211eb64787c7514bc576f3659c..b18ee2016c08b6bc8b385487af718efda90fa824 100644 --- a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/model.py +++ b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/model.py @@ -21,10 +21,10 @@ FOCUSED_OUTPUT_WORKSPACE_NAME = "engggui_focusing_output_ws_bank_" class FocusModel(object): - def focus_run(self, sample_path, banks, plot_output, instrument, rb_num, spectrum_numbers): + def focus_run(self, sample_paths, banks, plot_output, instrument, rb_num, spectrum_numbers): """ Focus some data using the current calibration. - :param sample_path: The path to the data to be focused. + :param sample_paths: The paths to the data to be focused. :param banks: The banks that should be focused. :param plot_output: True if the output should be plotted. :param instrument: The instrument that the data came from. @@ -36,8 +36,7 @@ class FocusModel(object): return integration_workspace = Ads.retrieve(vanadium_corrections.INTEGRATED_WORKSPACE_NAME) curves_workspace = Ads.retrieve(vanadium_corrections.CURVES_WORKSPACE_NAME) - sample_workspace = path_handling.load_workspace(sample_path) - output_workspaces = [] + output_workspaces = [] # List of collated workspaces to plot. full_calib_path = get_setting(path_handling.INTERFACES_SETTINGS_GROUP, path_handling.ENGINEERING_PREFIX, "full_calibration") if full_calib_path is not None and path.exists(full_calib_path): @@ -45,22 +44,31 @@ class FocusModel(object): else: full_calib_workspace = None if spectrum_numbers is None: - for name in banks: - output_workspace_name = FOCUSED_OUTPUT_WORKSPACE_NAME + str(name) - self._run_focus(sample_workspace, output_workspace_name, integration_workspace, - curves_workspace, name, full_calib_workspace) - output_workspaces.append(output_workspace_name) - # Save the output to the file system. - self._save_output(instrument, sample_path, name, output_workspace_name, rb_num) + for sample_path in sample_paths: + sample_workspace = path_handling.load_workspace(sample_path) + run_no = path_handling.get_run_number_from_path(sample_path, instrument) + workspaces_for_run = [] + for name in banks: + output_workspace_name = str(run_no) + "_" + FOCUSED_OUTPUT_WORKSPACE_NAME + str(name) + self._run_focus(sample_workspace, output_workspace_name, integration_workspace, + curves_workspace, name, full_calib_workspace) + workspaces_for_run.append(output_workspace_name) + # Save the output to the file system. + self._save_output(instrument, sample_path, name, output_workspace_name, rb_num) + output_workspaces.append(workspaces_for_run) else: - output_workspace_name = FOCUSED_OUTPUT_WORKSPACE_NAME + "cropped" - self._run_focus(sample_workspace, output_workspace_name, integration_workspace, - curves_workspace, None, full_calib_workspace, spectrum_numbers) - output_workspaces.append(output_workspace_name) - self._save_output(instrument, sample_path, "cropped", output_workspace_name, rb_num) + for sample_path in sample_paths: + sample_workspace = path_handling.load_workspace(sample_path) + run_no = path_handling.get_run_number_from_path(sample_path, instrument) + output_workspace_name = str(run_no) + "_" + FOCUSED_OUTPUT_WORKSPACE_NAME + "cropped" + self._run_focus(sample_workspace, output_workspace_name, integration_workspace, + curves_workspace, None, full_calib_workspace, spectrum_numbers) + output_workspaces.append([output_workspace_name]) + self._save_output(instrument, sample_path, "cropped", output_workspace_name, rb_num) # Plot the output if plot_output: - self._plot_focused_workspaces(output_workspaces) + for ws_names in output_workspaces: + self._plot_focused_workspaces(ws_names) @staticmethod def _run_focus(input_workspace, diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/presenter.py b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/presenter.py index 8a9bad5d4bfa4759948cec671bf322f195d854b5..a33e9b1d533361119cf5181065bb9a69969940e3 100644 --- a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/presenter.py +++ b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/presenter.py @@ -40,20 +40,20 @@ class FocusPresenter(object): if not self._validate(): return banks, spectrum_numbers = self._get_banks() - focus_path = self.view.get_focus_filename() - self.start_focus_worker(focus_path, banks, self.view.get_plot_output(), self.rb_num, spectrum_numbers) + focus_paths = self.view.get_focus_filenames() + self.start_focus_worker(focus_paths, banks, self.view.get_plot_output(), self.rb_num, spectrum_numbers) - def start_focus_worker(self, focus_path, banks, plot_output, rb_num, spectrum_numbers=None): + def start_focus_worker(self, focus_paths, banks, plot_output, rb_num, spectrum_numbers=None): """ Focus data in a separate thread to stop the main GUI from hanging. - :param focus_path: The path to the file containing the data to focus. + :param focus_paths: List of paths to the files containing the data to focus. :param banks: A list of banks that are to be focused. :param plot_output: True if the output should be plotted. :param rb_num: The RB Number from the main window (often an experiment id) :param spectrum_numbers: Optional parameter to crop to a specific list of spectrum numbers. """ self.worker = AsyncTask(self.model.focus_run, - (focus_path, banks, plot_output, self.instrument, rb_num, spectrum_numbers), + (focus_paths, banks, plot_output, self.instrument, rb_num, spectrum_numbers), error_cb=self._on_worker_error, finished_cb=self.emit_enable_button_signal) self.set_focus_controls_enabled(False) diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/test/test_focus_model.py b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/test/test_focus_model.py index 99a1d3aa44ae8d429b3525c0a4567e68f078888c..5698ddd9fa3d7fa764cb15b1b8965bc5bcca37da 100644 --- a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/test/test_focus_model.py +++ b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/test/test_focus_model.py @@ -41,11 +41,12 @@ class FocusModelTest(unittest.TestCase): banks = ["1", "2"] load_focus.return_value = "mocked_sample" - self.model.focus_run("305761", banks, False, "ENGINX", "0", None) + self.model.focus_run(["305761"], banks, False, "ENGINX", "0", None) + self.assertEqual(len(banks), run_focus.call_count) run_focus.assert_called_with("mocked_sample", - model.FOCUSED_OUTPUT_WORKSPACE_NAME + banks[-1], "test_wsp", - "test_wsp", banks[-1], None) + "305761_" + model.FOCUSED_OUTPUT_WORKSPACE_NAME + banks[-1], + "test_wsp", "test_wsp", banks[-1], None) @patch(file_path + ".Ads") @patch(file_path + ".FocusModel._save_output") @@ -56,11 +57,12 @@ class FocusModelTest(unittest.TestCase): spectra = "20-50" load_focus.return_value = "mocked_sample" - self.model.focus_run("305761", None, False, "ENGINX", "0", spectra) + self.model.focus_run(["305761"], None, False, "ENGINX", "0", spectra) + self.assertEqual(1, run_focus.call_count) run_focus.assert_called_with("mocked_sample", - model.FOCUSED_OUTPUT_WORKSPACE_NAME + "cropped", "test_wsp", - "test_wsp", None, None, spectra) + "305761_" + model.FOCUSED_OUTPUT_WORKSPACE_NAME + "cropped", + "test_wsp", "test_wsp", None, None, spectra) @patch(file_path + ".Ads") @patch(file_path + ".FocusModel._save_output") @@ -75,7 +77,8 @@ class FocusModelTest(unittest.TestCase): banks = ["1", "2"] load_focus.return_value = "mocked_sample" - self.model.focus_run("305761", banks, True, "ENGINX", "0", None) + self.model.focus_run(["305761"], banks, True, "ENGINX", "0", None) + self.assertEqual(1, plot_focus.call_count) @patch(file_path + ".Ads") diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/test/test_focus_presenter.py b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/test/test_focus_presenter.py index 4ced5e5601aa5235764cd90f465ae2dd444b5492..1e8458de003b6d40919f75e3be18c0eb5be7a742 100644 --- a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/test/test_focus_presenter.py +++ b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/test/test_focus_presenter.py @@ -30,7 +30,7 @@ class FocusPresenterTest(unittest.TestCase): self.presenter.current_calibration = CalibrationInfo(vanadium_path="Fake/Path", sample_path="Fake/Path", instrument="ENGINX") - self.view.get_focus_filename.return_value = "305738" + self.view.get_focus_filenames.return_value = "305738" self.presenter.cropping_widget.get_bank.return_value = "2" self.presenter.cropping_widget.is_custom.return_value = False self.view.get_plot_output.return_value = True @@ -46,7 +46,7 @@ class FocusPresenterTest(unittest.TestCase): self.presenter.current_calibration = CalibrationInfo(vanadium_path="Fake/Path", sample_path="Fake/Path", instrument="ENGINX") - self.view.get_focus_filename.return_value = "305738" + self.view.get_focus_filenames.return_value = "305738" self.presenter.cropping_widget.get_custom_spectra.return_value = "2-45" self.view.get_plot_output.return_value = True self.view.is_searching.return_value = False diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/view.py b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/view.py index c05c51e041c409c8a30cbaddf2254e9bf9108c5c..078b312d859ffedb166780bdd9be9d504e2d20f0 100644 --- a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/view.py +++ b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/view.py @@ -23,6 +23,7 @@ class FocusView(QtWidgets.QWidget, Ui_focus): self.finder_focus.setLabelText("Sample Run #") self.finder_focus.setInstrumentOverride(instrument) + self.finder_focus.allowMultipleFiles(True) # ================= # Slot Connectors @@ -57,8 +58,8 @@ class FocusView(QtWidgets.QWidget, Ui_focus): # Component Getters # ================= - def get_focus_filename(self): - return self.finder_focus.getFirstFilename() + def get_focus_filenames(self): + return self.finder_focus.getFilenames() def get_focus_valid(self): return self.finder_focus.isValid()