Skip to content

Commit

Permalink
add docstrings and test of function reload_all_files
Browse files Browse the repository at this point in the history
  • Loading branch information
backmari committed Aug 8, 2024
1 parent 819e5de commit dcce379
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
1 change: 0 additions & 1 deletion reflectivity_ui/interfaces/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion reflectivity_ui/interfaces/data_handling/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -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":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import os
import sys

from test.ui import ui_utilities

this_module_path = sys.modules[__name__].__file__


Expand All @@ -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(
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit dcce379

Please sign in to comment.