From dcce379e78046b090063f1ece4681acd821617a9 Mon Sep 17 00:00:00 2001 From: Marie Backman Date: Thu, 8 Aug 2024 12:42:43 -0400 Subject: [PATCH] add docstrings and test of function reload_all_files --- reflectivity_ui/interfaces/configuration.py | 1 - .../interfaces/data_handling/instrument.py | 13 ++++++- .../event_handlers/test_main_handler.py | 34 +++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/reflectivity_ui/interfaces/configuration.py b/reflectivity_ui/interfaces/configuration.py index 0d5e83e..d149019 100644 --- a/reflectivity_ui/interfaces/configuration.py +++ b/reflectivity_ui/interfaces/configuration.py @@ -37,7 +37,6 @@ class Configuration(object): polynomial_stitching = False polynomial_stitching_degree = 3 polynomial_stitching_points = 3 - # Dead time options apply_deadtime = False paralyzable_deadtime = True diff --git a/reflectivity_ui/interfaces/data_handling/instrument.py b/reflectivity_ui/interfaces/data_handling/instrument.py index 2278eaf..d0699d6 100644 --- a/reflectivity_ui/interfaces/data_handling/instrument.py +++ b/reflectivity_ui/interfaces/data_handling/instrument.py @@ -11,7 +11,7 @@ from reflectivity_ui.interfaces.data_handling.filepath import FilePath # 3rd party -from mantid.api import WorkspaceGroup +from mantid.api import WorkspaceGroup, PythonAlgorithm from mantid.dataobjects import EventWorkspace import numpy as np import mantid.simpleapi as api @@ -68,6 +68,14 @@ def get_cross_section_label(ws, entry_name): def mantid_algorithm_exec(algorithm_class, **kwargs): + """ + Helper function for executing a Mantid-style algorithm + + :param PythonAlgorithm algorithm_class: the algorithm class to execute + :param kwargs: keyword arguments + :returns Workspace: if ``OutputWorkspace`` is passed as a keyword argument, the value of the + algorithm property ``OutputWorkspace`` will be returned + """ algorithm_instance = algorithm_class() assert algorithm_instance.PyInit, "str(algorithm_class) is not a Mantid Python algorithm" algorithm_instance.PyInit() @@ -225,7 +233,9 @@ def load_data(self, file_path, configuration=None): ws = api.LoadEventNexus(Filename=path, OutputWorkspace="raw_events") _path_xs_list = self.dummy_filter_cross_sections(ws, name_prefix=temp_workspace_root_name) if configuration is not None and configuration.apply_deadtime: + # Load error events from the bank_error_events entry err_ws = api.LoadErrorEventsNexus(path) + # Split error events by cross-section for compatibility with normal events _err_list = api.MRFilterCrossSections( InputWorkspace=err_ws, PolState=self.pol_state, @@ -235,6 +245,7 @@ def load_data(self, file_path, configuration=None): CrossSectionWorkspaces="%s_err_entry" % temp_workspace_root_name, ) path_xs_list = [] + # Apply dead-time correction for each cross-section workspace for ws in _path_xs_list: xs_name = ws.getRun()["cross_section_id"].value if not xs_name == "unfiltered": diff --git a/test/unit/reflectivity_ui/interfaces/event_handlers/test_main_handler.py b/test/unit/reflectivity_ui/interfaces/event_handlers/test_main_handler.py index 25ca796..cbb9ce6 100644 --- a/test/unit/reflectivity_ui/interfaces/event_handlers/test_main_handler.py +++ b/test/unit/reflectivity_ui/interfaces/event_handlers/test_main_handler.py @@ -17,6 +17,8 @@ import os import sys +from test.ui import ui_utilities + this_module_path = sys.modules[__name__].__file__ @@ -37,6 +39,7 @@ class TestMainHandler(object): handler = MainHandler(application) @pytest.mark.datarepo + @pytest.mark.skip(reason="WIP") def test_congruency_fail_report(self, data_server): # Selected subset of log names with an invalid one message = self.handler._congruency_fail_report( @@ -144,6 +147,37 @@ def dialog_click_button(button_type): assert answer is False +@pytest.mark.datarepo +def test_reload_all_files(qtbot): + """Test function reload_all_files""" + main_window = MainWindow() + handler = MainHandler(main_window) + data_manager = main_window.data_manager + qtbot.addWidget(main_window) + selected_row = 0 + + # Add one direct beam run and two data runs + ui_utilities.setText(main_window.numberSearchEntry, str(40786), press_enter=True) + ui_utilities.set_current_file_by_run_number(main_window, 40786) + main_window.actionNorm.triggered.emit() + ui_utilities.set_current_file_by_run_number(main_window, 40785) + main_window.actionAddPlot.triggered.emit() + ui_utilities.set_current_file_by_run_number(main_window, 40782) + main_window.actionAddPlot.triggered.emit() + + # Select/plot the first data run + main_window.reduction_cell_activated(selected_row, 0) + + # Test that reloading all files does not change the active run + assert main_window.ui.reductionTable.rowCount() == 2 + assert len(data_manager.reduction_list) == 2 + assert data_manager._nexus_data == data_manager.reduction_list[selected_row] + handler.reload_all_files() + assert main_window.ui.reductionTable.rowCount() == 2 + assert len(main_window.data_manager.reduction_list) == 2 + assert data_manager._nexus_data == data_manager.reduction_list[selected_row] + + def _get_nexus_data(): """Data for testing""" config = Configuration()