def setUp(self): self.filepath = FileFinder.findRuns('EMU00019489.nxs')[0] self.load_result, self.run_number, self.filename, _ = load_workspace_from_filename( self.filepath) self.loaded_data = MuonLoadData() self.context = MuonDataContext(load_data=self.loaded_data) self.context.instrument = 'EMU' self.loaded_data.add_data(workspace=self.load_result, run=[self.run_number], filename=self.filename, instrument='EMU') self.context.current_runs = [[self.run_number]] self.context.update_current_data()
def setup_context(freq=False): loaded_data = MuonLoadData() loaded_data.get_main_field_direction = mock.MagicMock(return_value='transverse') data_context = MuonDataContext(load_data=loaded_data) gui_context = MuonGuiContext() group_context = MuonGroupPairContext(data_context.check_group_contains_valid_detectors) corrections_context = CorrectionsContext(loaded_data) phase_table_context = PhaseTableContext() freq_context = FrequencyContext() plot_panes_context = PlotPanesContext() if freq: return FrequencyDomainAnalysisContext(muon_data_context=data_context, muon_group_context=group_context, muon_gui_context=gui_context, muon_phase_context=phase_table_context, corrections_context=corrections_context, fitting_context=BasicFittingContext(allow_double_pulse_fitting=True), frequency_context=freq_context, plot_panes_context=plot_panes_context) else: return DataAnalysisContext(muon_data_context=data_context, muon_group_context=group_context, muon_gui_context=gui_context, corrections_context=corrections_context, muon_phase_context=phase_table_context, fitting_context=TFAsymmetryFittingContext(allow_double_pulse_fitting=True), results_context=ResultsContext(), model_fitting_context=ModelFittingContext(), plot_panes_context=plot_panes_context)
def setup_context_for_tests(parent_object): parent_object.loaded_data = MuonLoadData() parent_object.loaded_data.get_main_field_direction = mock.MagicMock(return_value='transverse') parent_object.data_context = MuonDataContext(load_data=parent_object.loaded_data) parent_object.gui_context = MuonGuiContext() parent_object.group_context = MuonGroupPairContext(parent_object.data_context.check_group_contains_valid_detectors) parent_object.corrections_context = CorrectionsContext(parent_object.loaded_data) parent_object.phase_table_context = PhaseTableContext() parent_object.fitting_context = TFAsymmetryFittingContext(allow_double_pulse_fitting=True) parent_object.results_context = ResultsContext() parent_object.plot_panes_context = PlotPanesContext() parent_object.model_fitting_context = ModelFittingContext() parent_object.context = DataAnalysisContext(muon_data_context=parent_object.data_context, muon_group_context=parent_object.group_context, muon_gui_context=parent_object.gui_context, muon_phase_context=parent_object.phase_table_context, corrections_context=parent_object.corrections_context, fitting_context=parent_object.fitting_context, results_context=parent_object.results_context, model_fitting_context=parent_object.model_fitting_context, plot_panes_context=parent_object.plot_panes_context)
def __init__(self, parent=None, window_flags=None): super(FrequencyAnalysisGui, self).__init__(parent) if window_flags: self.setWindowFlags(window_flags) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.setFocusPolicy(QtCore.Qt.StrongFocus) try: check_facility() except AttributeError as error: self.warning_popup(error.args[0]) # load the feature flags feature_dict = load_features() # initialise the data storing classes of the interface self.loaded_data = MuonLoadData() self.data_context = MuonDataContext('Frequency Domain Data', self.loaded_data) self.gui_context = MuonGuiContext() self.plot_panes_context = PlotPanesContext() self.group_pair_context = MuonGroupPairContext( self.data_context.check_group_contains_valid_detectors) self.corrections_context = CorrectionsContext(self.loaded_data) self.phase_context = PhaseTableContext() self.fitting_context = BasicFittingContext( allow_double_pulse_fitting=True) self.results_context = ResultsContext() self.model_fitting_context = ModelFittingContext( allow_double_pulse_fitting=False) self.frequency_context = FrequencyContext() self.context = FrequencyDomainAnalysisContext( muon_data_context=self.data_context, muon_gui_context=self.gui_context, muon_group_context=self.group_pair_context, corrections_context=self.corrections_context, muon_phase_context=self.phase_context, plot_panes_context=self.plot_panes_context, fitting_context=self.fitting_context, results_context=self.results_context, model_fitting_context=self.model_fitting_context, frequency_context=self.frequency_context) # create the dockable widget self.plot_widget = FrequencyAnalysisPlotWidget(self.context, parent=self) self.dockable_plot_widget_window = PlottingDockWidget( parent=self, plotting_widget=self.plot_widget.view) self.dockable_plot_widget_window.setMinimumWidth(575) # Add dock widget to main Muon analysis window self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.dockable_plot_widget_window) # Need this line to stop the bug where the dock window snaps back to its original size after resizing. # 0 argument is arbitrary and has no effect on fit widget size # This is a qt bug reported at (https://bugreports.qt.io/browse/QTBUG-65592) if QT_VERSION >= LooseVersion("5.6"): self.resizeDocks({self.dockable_plot_widget_window}, {1}, QtCore.Qt.Horizontal) # construct all the widgets. self.load_widget = LoadWidget(self.loaded_data, self.context, self) self.grouping_tab_widget = GroupingTabWidget(self.context, parent) self.corrections_tab = CorrectionsTabWidget(self.context, self) self.home_tab = HomeTabWidget(self.context, self) self.phase_tab = PhaseTabWidget(self.context, self) self.transform = TransformWidget(self.context, FFTWidget, MaxEntWidget, parent=self) self.fitting_tab = FittingTabWidget(self.context, self) self.seq_fitting_tab = SeqFittingTabWidget( self.context, self.fitting_tab.fitting_tab_model, self) self.results_tab = ResultsTabWidget(self.context.fitting_context, self.context, self) self.add_model_analysis = AddModelAnalysis(self, feature_dict) self.add_raw_plots = AddRawPlots(self, feature_dict) self.add_fitting = AddFitting(self, feature_dict) setup_group_ws = AddGroupingWorkspaces(self, feature_dict) self.setup_tabs() self.plot_widget.insert_plot_panes() self.help_widget = HelpWidget(self.context.window_title) central_widget = QtWidgets.QWidget() vertical_layout = QtWidgets.QVBoxLayout() vertical_layout.addWidget(self.load_widget.load_widget_view) vertical_layout.addWidget(self.tabs) vertical_layout.addWidget(self.help_widget.view) central_widget.setLayout(vertical_layout) central_widget.setSizePolicy( QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)) self.disable_notifier = GenericObservable() self.disable_observer = GenericObserver( self.disable_notifier.notify_subscribers) self.enable_notifier = GenericObservable() self.enable_observer = GenericObserver( self.enable_notifier.notify_subscribers) self.setup_disable_notifier() self.setup_enable_notifier() self.setCentralWidget(central_widget) self.setWindowTitle(self.context.window_title) self.setup_load_observers() self.setup_gui_variable_observers() self.setup_grouping_changed_observers() self.setup_corrections_changed_observers() self.setup_instrument_changed_notifier() self.setup_group_calculation_enable_notifier() self.setup_group_calculation_disabler_notifier() self.setup_on_load_enabler() self.setup_on_load_disabler() self.setup_phase_quad_changed_notifier() self.setup_phase_table_changed_notifier() self.setup_fitting_notifier() self.setup_counts_calculation_finished_notifier() self.setup_asymmetry_pair_and_diff_calculations_finished_notifier() self.setup_transform() self.context.data_context.message_notifier.add_subscriber( self.grouping_tab_widget.group_tab_presenter.message_observer) self.add_model_analysis.add_observers_to_feature(self) self.add_model_analysis.set_feature_observables(self) self.add_raw_plots.add_observers_to_feature(self) setup_group_ws.add_observers_to_feature(self)
class MuonDataContextTest(unittest.TestCase): def setUp(self): self.filepath = FileFinder.findRuns('EMU00019489.nxs')[0] self.load_result, self.run_number, self.filename, _ = load_workspace_from_filename( self.filepath) self.loaded_data = MuonLoadData() self.context = MuonDataContext(load_data=self.loaded_data) self.context.instrument = 'EMU' self.loaded_data.add_data(workspace=self.load_result, run=[self.run_number], filename=self.filename, instrument='EMU') self.context.current_runs = [[self.run_number]] self.context.update_current_data() def tearDown(self): AnalysisDataService.clear() def test_setting_current_data_with_a_different_field_sends_message_signal( self): self.context.current_data['MainFieldDirection'] = 'transverse' self.context.message_notifier.notify_subscribers = mock.MagicMock() self.context.update_current_data() self.context.message_notifier.notify_subscribers.assert_called_once_with( 'MainFieldDirection has changed between' ' data sets, click default to reset grouping if required') self.context.current_data['MainFieldDirection'] = 'longitudinal' def test_that_setting_current_runs_with_mixture_of_transverse_and_longitudanal_runs_raises_warning( self): loaded_data = copy.copy(self.context.current_data) self.context.message_notifier.notify_subscribers = mock.MagicMock() loaded_data['MainFieldDirection'] = 'transverse' self.loaded_data.add_data(workspace=loaded_data, run=[1], filename='filename', instrument='EMU') self.context.current_runs = [[19489], [1]] self.context.message_notifier.notify_subscribers.assert_called_once_with( 'MainFieldDirection changes within current run set:\ntransverse field runs 1\nlongitudinal field runs 19489\n' ) def test_is_data_loaded_returns_true_if_data_loaded(self): self.assertTrue(self.context.is_data_loaded()) def test_is_data_loaded_returns_false_if_no_data_loaded(self): self.context._loaded_data.clear() self.assertFalse(self.context.is_data_loaded()) def test_current_filenames_returns_path_to_current_file(self): self.assertEqual(self.context.current_filenames, [self.filepath]) def test_current_runs_set_correctly(self): self.assertEqual(self.context.current_runs, [[19489]]) def test_current_workspaces_returns_correctly(self): self.assertEqual(self.context.current_workspaces, [self.load_result]) def test_get_loaded_data_for_run_returns_correctly(self): self.assertEqual(self.context.get_loaded_data_for_run([19489]), self.load_result) def test_num_detectors_returns_correctly(self): self.assertEqual(self.context.num_detectors, 96) def test_num_periods_returns_correctly(self): self.assertEqual(self.context.num_periods([19489]), 1) def test_main_field_direction_returns_correctly(self): self.assertEqual(self.context.main_field_direction, 'Longitudinal') def test_dead_time_table_returns_correctly(self): self.assertEqual(self.context.dead_time_table, self.load_result['DeadTimeTable']) def test_return_sample_log_returns_correctly(self): self.assertEqual(self.context.get_sample_log('goodfrm').value, 31369.0) def test_that_is_multi_period_returns_false_for_single_period_data(self): is_multi_period = self.context.is_multi_period() self.assertTrue(not is_multi_period) def test_that_any_multi_period_data_will_mark_everything_as_multiperiod( self): multi_period_worspace_list = [ MuonWorkspaceWrapper(f'raw_data_{period_index + 1}') for period_index in range(4) ] load_result = {'OutputWorkspace': multi_period_worspace_list} self.loaded_data.add_data(workspace=load_result, run=[84447], filename='workspace_filename', instrument='EMU') self.context._current_runs = [[84447], [19489]] is_multi_period = self.context.is_multi_period() self.assertTrue(is_multi_period)