diff --git a/scripts/Engineering/gui/engineering_diffraction/engineering_diffraction.py b/scripts/Engineering/gui/engineering_diffraction/engineering_diffraction.py index bfb03af5406423359bacc1aed41705c377a401fe..749c42455041ee24d1edfdda062260109d702f7e 100644 --- a/scripts/Engineering/gui/engineering_diffraction/engineering_diffraction.py +++ b/scripts/Engineering/gui/engineering_diffraction/engineering_diffraction.py @@ -49,7 +49,7 @@ class EngineeringDiffractionGui(QtWidgets.QMainWindow, Ui_main_window): cal_view = CalibrationView(parent=self.tabs) self.calibration_presenter = CalibrationPresenter(cal_model, cal_view) self.set_on_instrument_changed(self.calibration_presenter.set_instrument_override) - self.set_on_rb_num_changed(self.calibration_presenter.set_rb_number) + self.set_on_rb_num_changed(self.calibration_presenter.set_rb_num) self.tabs.addTab(cal_view, "Calibration") def setup_focus(self): @@ -57,7 +57,7 @@ class EngineeringDiffractionGui(QtWidgets.QMainWindow, Ui_main_window): focus_view = FocusView() self.focus_presenter = FocusPresenter(focus_model, focus_view) self.set_on_instrument_changed(self.focus_presenter.set_instrument_override) - self.set_on_rb_num_changed(self.focus_presenter.set_rb_number) + self.set_on_rb_num_changed(self.focus_presenter.set_rb_num) self.tabs.addTab(focus_view, "Focus") def setup_calibration_notifier(self): diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/model.py b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/model.py index b49f4e89d74e100a7a32ad1fd58e796470b2e5d4..6616e2367296727778d173acfd411e730fc61424 100644 --- a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/model.py +++ b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/model.py @@ -46,7 +46,7 @@ class CalibrationModel(object): :param rb_num: The RB number for file creation. """ van_integration, van_curves = vanadium_corrections.fetch_correction_workspaces( - vanadium_path, instrument, rb_number=rb_num) + vanadium_path, instrument, rb_num=rb_num) sample_workspace = self.load_sample(sample_path) output = self.run_calibration(sample_workspace, van_integration, van_curves) if plot_output: diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/presenter.py b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/presenter.py index a98de060d2ce05a45438020230d7392123721197..d7b7cb19acf49c3991730b684a7dec859cfce762 100644 --- a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/presenter.py +++ b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/presenter.py @@ -39,17 +39,7 @@ class CalibrationPresenter(object): def on_calibrate_clicked(self): plot_output = self.view.get_plot_output() - if self.view.get_new_checked(): - # Do nothing if run numbers are invalid or view is searching. - if not self.validate_run_numbers(): - if self.view.is_searching(): - create_error_message(self.view, "GUI is searching for data files. Please wait.") - else: - create_error_message(self.view, "Check run numbers/path is valid.") - return - if self.view.is_searching(): - create_error_message(self.view, "Mantid is searching for the file. Please wait.") - return + if self.view.get_new_checked() and self._validate(): vanadium_file = self.view.get_vanadium_filename() sample_file = self.view.get_sample_filename() self.start_calibration_worker(vanadium_file, sample_file, plot_output, self.rb_num) @@ -98,14 +88,21 @@ class CalibrationPresenter(object): self.view.set_instrument_override(instrument) self.instrument = instrument - def set_rb_number(self, rb_number): - self.rb_num = rb_number + def set_rb_num(self, rb_num): + self.rb_num = rb_num - def validate_run_numbers(self): - if self.view.get_sample_valid() and self.view.get_vanadium_valid(): - return True - else: + def _validate(self): + # Do nothing if run numbers are invalid or view is searching. + if self.view.is_searching(): + create_error_message(self.view, "Mantid is searching for data files. Please wait.") return False + if not self.validate_run_numbers(): + create_error_message(self.view, "Check run numbers/path is valid.") + return False + return True + + def validate_run_numbers(self): + return self.view.get_sample_valid() and self.view.get_vanadium_valid() def validate_path(self): return self.view.get_path_valid() diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/test/test_calib_model.py b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/test/test_calib_model.py index 43b51080a7a767bb413c50533b30ce2d79d1ee8e..60e8d530feb89353e116cd204610f5244169e85b 100644 --- a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/test/test_calib_model.py +++ b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/test/test_calib_model.py @@ -36,8 +36,8 @@ class CalibrationModelTest(unittest.TestCase): @patch(class_path + '.run_calibration') @patch(class_path + '.load_sample') @patch(file_path + '.vanadium_corrections.fetch_correction_workspaces') - def test_EnggVanadiumCorrections_algorithm_is_called(self, van, load_sample, calib, output_files, - update_table): + def test_EnggVanadiumCorrections_algorithm_is_called(self, van, load_sample, calib, + output_files, update_table): van.return_value = ("A", "B") self.model.create_new_calibration(VANADIUM_NUMBER, CERIUM_NUMBER, False, "ENGINX") van.assert_called_once() @@ -61,8 +61,8 @@ class CalibrationModelTest(unittest.TestCase): @patch(class_path + '._generate_difc_tzero_workspace') @patch(class_path + '._plot_difc_tzero') @patch(class_path + '.run_calibration') - def test_plotting_check(self, calib, plot_difc_zero, gen_difc, plot_van, van, sample, output_files, - update_table): + def test_plotting_check(self, calib, plot_difc_zero, gen_difc, plot_van, van, sample, + output_files, update_table): van.return_value = ("A", "B") self.model.create_new_calibration(VANADIUM_NUMBER, CERIUM_NUMBER, False, "ENGINX") plot_van.assert_not_called() @@ -81,7 +81,8 @@ class CalibrationModelTest(unittest.TestCase): @patch(class_path + '._plot_difc_tzero') @patch(class_path + '.run_calibration') def test_present_RB_number_results_in_user_output_files(self, calib, plot_difc_zero, plot_van, - van, sample, output_files, update_table): + van, sample, output_files, + update_table): van.return_value = ("A", "B") self.model.create_new_calibration(VANADIUM_NUMBER, CERIUM_NUMBER, @@ -141,30 +142,32 @@ class CalibrationModelTest(unittest.TestCase): self.assertEqual(self.model._generate_table_workspace_name(20), "engggui_calibration_bank_21") - def test_generate_output_file_name_for_valid_bank(self): - filename = self.model._generate_output_file_name( - "test/20.raw", "test/10.raw", "ENGINX", "north") + def test_generate_output_file_name_for_north_bank(self): + filename = self.model._generate_output_file_name("test/20.raw", "test/10.raw", "ENGINX", + "north") self.assertEqual(filename, "ENGINX_20_10_bank_North.prm") - filename = self.model._generate_output_file_name( - "test/20.raw", "test/10.raw", "ENGINX", "south") + def test_generate_output_file_name_for_south_bank(self): + filename = self.model._generate_output_file_name("test/20.raw", "test/10.raw", "ENGINX", + "south") self.assertEqual(filename, "ENGINX_20_10_bank_South.prm") - filename = self.model._generate_output_file_name( - "test/20.raw", "test/10.raw", "ENGINX", "all") + def test_generate_output_file_name_for_both_banks(self): + filename = self.model._generate_output_file_name("test/20.raw", "test/10.raw", "ENGINX", + "all") self.assertEqual(filename, "ENGINX_20_10_all_banks.prm") def test_generate_output_file_name_for_invalid_bank(self): self.assertRaises(ValueError, self.model._generate_output_file_name, "test/20.raw", "test/10.raw", "ENGINX", "INVALID") - def test_generate_output_file_name_for_unconventional_filename(self): - filename = self.model._generate_output_file_name( - "test/20", "test/10.raw", "ENGINX", "north") + def test_generate_output_file_name_with_no_ext_in_filename(self): + filename = self.model._generate_output_file_name("test/20", "test/10.raw", "ENGINX", + "north") self.assertEqual(filename, "ENGINX_20_10_bank_North.prm") - filename = self.model._generate_output_file_name( - "20", "test/10.raw", "ENGINX", "north") + def test_generate_output_file_name_with_no_path_in_filename(self): + filename = self.model._generate_output_file_name("20.raw", "test/10.raw", "ENGINX", "north") self.assertEqual(filename, "ENGINX_20_10_bank_North.prm") @patch("Engineering.gui.engineering_diffraction.tabs.calibration.model.Ads") diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/test/test_calib_presenter.py b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/test/test_calib_presenter.py index c04b9d6ff109233d8da32e64f4bd71804f785f5f..ae703fd3a142df1e47c183f897dcf8e292d130f6 100644 --- a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/test/test_calib_presenter.py +++ b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/test/test_calib_presenter.py @@ -39,6 +39,7 @@ class CalibrationPresenterTest(unittest.TestCase): self.view.get_vanadium_filename.return_value = "307521" self.view.get_sample_filename.return_value = "305738" self.view.get_plot_output.return_value = True + self.view.get_load_checked.return_value = False self.view.is_searching.return_value = True self.presenter.on_calibrate_clicked() @@ -53,6 +54,7 @@ class CalibrationPresenterTest(unittest.TestCase): self.view.get_sample_filename.return_value = "305738" self.view.get_plot_output.return_value = True self.view.is_searching.return_value = False + self.view.get_load_checked.return_value = False validator.return_value = False self.presenter.on_calibrate_clicked() @@ -126,7 +128,6 @@ class CalibrationPresenterTest(unittest.TestCase): blank = CalibrationInfo() self.presenter.current_calibration = current - self.assertEqual(self.presenter.current_calibration, current) self.presenter.set_current_calibration() self.check_calibration_equal(self.presenter.current_calibration, pendcpy) diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/common/vanadium_corrections.py b/scripts/Engineering/gui/engineering_diffraction/tabs/common/vanadium_corrections.py index 89958249ba21ef10a29278753deb98451ba840d3..2f79c91c4990f585815bb7e6186540be7c01085a 100644 --- a/scripts/Engineering/gui/engineering_diffraction/tabs/common/vanadium_corrections.py +++ b/scripts/Engineering/gui/engineering_diffraction/tabs/common/vanadium_corrections.py @@ -25,12 +25,12 @@ SAVED_FILE_CURVE_SUFFIX = "_precalculated_vanadium_run_bank_curves.nxs" SAVED_FILE_INTEG_SUFFIX = "_precalculated_vanadium_run_integration.nxs" -def fetch_correction_workspaces(vanadium_path, instrument, rb_number=""): +def fetch_correction_workspaces(vanadium_path, instrument, rb_num=""): """ Fetch workspaces from the file system or create new ones. :param vanadium_path: The path to the requested vanadium run raw data. :param instrument: The instrument the data came from. - :param rb_number: + :param rb_num: A user identifier, usually an experiment number. :return: The resultant integration and curves workspaces. """ vanadium_number = path_handling.get_run_number_from_path(vanadium_path, instrument) @@ -39,9 +39,9 @@ def fetch_correction_workspaces(vanadium_path, instrument, rb_number=""): try: integ_workspace = Load(Filename=integ_path, OutputWorkspace=INTEGRATED_WORKSPACE_NAME) curves_workspace = Load(Filename=curves_path, OutputWorkspace=CURVES_WORKSPACE_NAME) - if rb_number: + if rb_num: user_integ, user_curves = _generate_saved_workspace_file_paths(vanadium_number, - rb_num=rb_number) + rb_num=rb_num) if not path.exists(user_integ) and not path.exists(user_curves): _save_correction_files(integ_workspace, user_integ, curves_workspace, user_curves) @@ -52,9 +52,9 @@ def fetch_correction_workspaces(vanadium_path, instrument, rb_number=""): + str(e)) integ_workspace, curves_workspace = _calculate_vanadium_correction(vanadium_path) _save_correction_files(integ_workspace, integ_path, curves_workspace, curves_path) - if rb_number: + if rb_num: user_integ, user_curves = _generate_saved_workspace_file_paths(vanadium_number, - rb_num=rb_number) + rb_num=rb_num) _save_correction_files(integ_workspace, user_integ, curves_workspace, user_curves) return integ_workspace, curves_workspace @@ -107,6 +107,7 @@ def _generate_saved_workspace_file_paths(vanadium_number, rb_num=""): """ Generate file paths based on a vanadium run number. :param vanadium_number: The number of the vanadium run. + :param rb_num: User identifier, usually an experiment number. :return: The full path to the file. """ integrated_filename = vanadium_number + SAVED_FILE_INTEG_SUFFIX diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/model.py b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/model.py index 00ebd59d1e29f50d98ad5a4bddf02e943dbbd4d9..656876e13cfa6d380dfeac46481e852876cfc674 100644 --- a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/model.py +++ b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/model.py @@ -19,14 +19,14 @@ FOCUSED_OUTPUT_WORKSPACE_NAME = "engggui_focusing_output_ws_bank_" class FocusModel(object): - def focus_run(self, sample_path, banks, plot_output, instrument, rb_number): + def focus_run(self, sample_path, banks, plot_output, instrument, rb_num): """ Focus some data using the current calibration. :param sample_path: The path 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. - :param rb_number: The experiment number, used to create directories. Can be None + :param rb_num: The experiment number, used to create directories. Can be None """ if not Ads.doesExist(vanadium_corrections.INTEGRATED_WORKSPACE_NAME) and not Ads.doesExist( vanadium_corrections.CURVES_WORKSPACE_NAME): @@ -41,7 +41,7 @@ class FocusModel(object): curves_workspace, name) output_workspaces.append(output_workspace_name) # Save the output to the file system. - self._save_output(instrument, sample_path, name, output_workspace_name, rb_number) + self._save_output(instrument, sample_path, name, output_workspace_name, rb_num) # Plot the output if plot_output: self._plot_focused_workspaces(output_workspaces) @@ -82,7 +82,7 @@ class FocusModel(object): ax.set_title(ws_name) fig.show() - def _save_output(self, instrument, sample_path, bank, sample_workspace, rb_number): + def _save_output(self, instrument, sample_path, bank, sample_workspace, rb_num): """ Save a focused workspace to the file system. Saves separate copies to a User directory if an rb number has been set. @@ -90,48 +90,48 @@ class FocusModel(object): :param sample_path: The path to the data file that was focused. :param bank: The name of the bank being saved. :param sample_workspace: The name of the workspace to be saved. - :param rb_number: Usually an experiment id, defines the name of the user directory. + :param rb_num: Usually an experiment id, defines the name of the user directory. """ self._save_focused_output_files_as_nexus(instrument, sample_path, bank, sample_workspace, - rb_number) + rb_num) self._save_focused_output_files_as_gss(instrument, sample_path, bank, sample_workspace, - rb_number) + rb_num) self._save_focused_output_files_as_xye(instrument, sample_path, bank, sample_workspace, - rb_number) + rb_num) def _save_focused_output_files_as_gss(self, instrument, sample_path, bank, sample_workspace, - rb_number): + rb_num): gss_output_path = path.join( path_handling.OUT_FILES_ROOT_DIR, "Focus", self._generate_output_file_name(instrument, sample_path, bank, ".gss")) SaveGSS(InputWorkspace=sample_workspace, Filename=gss_output_path) - if rb_number is not None: + if rb_num is not None: gss_output_path = path.join( - path_handling.OUT_FILES_ROOT_DIR, "User", rb_number, "Focus", + path_handling.OUT_FILES_ROOT_DIR, "User", rb_num, "Focus", self._generate_output_file_name(instrument, sample_path, bank, ".gss")) SaveGSS(InputWorkspace=sample_workspace, Filename=gss_output_path) def _save_focused_output_files_as_nexus(self, instrument, sample_path, bank, sample_workspace, - rb_number): + rb_num): nexus_output_path = path.join( path_handling.OUT_FILES_ROOT_DIR, "Focus", self._generate_output_file_name(instrument, sample_path, bank, ".nxs")) SaveNexus(InputWorkspace=sample_workspace, Filename=nexus_output_path) - if rb_number is not None: + if rb_num is not None: nexus_output_path = path.join( - path_handling.OUT_FILES_ROOT_DIR, "User", rb_number, "Focus", + path_handling.OUT_FILES_ROOT_DIR, "User", rb_num, "Focus", self._generate_output_file_name(instrument, sample_path, bank, ".nxs")) SaveNexus(InputWorkspace=sample_workspace, Filename=nexus_output_path) def _save_focused_output_files_as_xye(self, instrument, sample_path, bank, sample_workspace, - rb_number): + rb_num): xye_output_path = path.join( path_handling.OUT_FILES_ROOT_DIR, "Focus", self._generate_output_file_name(instrument, sample_path, bank, ".dat")) SaveFocusedXYE(InputWorkspace=sample_workspace, Filename=xye_output_path, SplitFiles=False) - if rb_number is not None: + if rb_num is not None: xye_output_path = path.join( - path_handling.OUT_FILES_ROOT_DIR, "User", rb_number, "Focus", + path_handling.OUT_FILES_ROOT_DIR, "User", rb_num, "Focus", self._generate_output_file_name(instrument, sample_path, bank, ".dat")) SaveFocusedXYE(InputWorkspace=sample_workspace, Filename=xye_output_path, diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/presenter.py b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/presenter.py index 0424365c9f6f761fd43f2f87ef203fb2633d092e..6a6a3ae77f5ffb33e9171ca0183038b90c4655cc 100644 --- a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/presenter.py +++ b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/presenter.py @@ -44,7 +44,7 @@ class FocusPresenter(object): :param focus_path: The path to the file 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 rb_num: The RB Number from the main window (often an experiment id) """ self.worker = AsyncTask(self.model.focus_run, (focus_path, banks, plot_output, self.instrument, rb_num), @@ -58,8 +58,8 @@ class FocusPresenter(object): self.view.set_instrument_override(instrument) self.instrument = instrument - def set_rb_number(self, rb_number): - self.rb_num = rb_number + def set_rb_num(self, rb_num): + self.rb_num = rb_num def _validate(self, banks): """ @@ -67,11 +67,11 @@ class FocusPresenter(object): :param banks: A list of banks to focus. :return: True if the worker can be started safely. """ + if self.view.is_searching(): + create_error_message(self.view, "Mantid is searching for data files. Please wait.") + return False if not self.view.get_focus_valid(): - if self.view.is_searching(): - create_error_message(self.view, "GUI is searching for data files. Please wait.") - else: - create_error_message(self.view, "Check run numbers/path is valid.") + create_error_message(self.view, "Check run numbers/path is valid.") return False if not check_workspaces_exist() or not self.current_calibration.is_valid(): create_error_message( @@ -87,9 +87,6 @@ class FocusPresenter(object): if len(banks) == 0: create_error_message(self.view, "Please select at least one bank.") return False - if self.view.is_searching(): - create_error_message(self.view, "GUI is searching for data files. Please wait.") - return False return True def _on_worker_error(self, failure_info): 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 f24b66143bcf26776069d7706290ad515eabbbee..2d4c9df683bf9006f2e8b060135ac650c37b7bb5 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 @@ -106,6 +106,7 @@ class FocusPresenterTest(unittest.TestCase): self.presenter.current_calibration = CalibrationInfo(vanadium_path=None, sample_path=None, instrument=None) + self.view.is_searching.return_value = False banks = ["North", "South"] self.presenter._validate(banks)