def test_that_when_new_fit_is_performed_function_name_is_set_to_lastest_fit_name( self): parameters = OrderedDict([('Height', (100, 0.1)), ('Cost function value', (1.5, 0))]) fits_func1 = create_test_fits(('ws1', ), 'func1', parameters, []) parameters = OrderedDict([('Height', (100, 0.1)), ('A0', (1, 0.001)), ('Cost function value', (1.5, 0))]) fits_func2 = create_test_fits(('ws2', ), 'func2', parameters, []) model = ResultsTabModel(FittingContext(fits_func1 + fits_func2)) model.on_new_fit_performed() self.assertEqual(model.selected_fit_function(), 'func2')
def create_test_model(input_workspaces, function_name, parameters, output_workspace_names=None, logs=None, global_parameters=None): """ Create a list of fits with time series logs on the workspaces :param input_workspaces: See create_test_fits :param function_name: See create_test_fits :param parameters: See create_test_fits :param logs: A list of (name, (values...), (name, (values...))) :param global_parameters: An optional list of tied parameters :return: A list of Fits with workspaces/logs attached """ fits = create_test_fits(input_workspaces, function_name, parameters, output_workspace_names, global_parameters) logs = logs if logs is not None else [] for fit, workspace_name in zip(fits, input_workspaces): add_logs(workspace_name, logs) fitting_context = FittingContext() for fit in fits: fitting_context.add_fit(fit) return fitting_context, ResultsTabModel(fitting_context)
def __init__(self, fit_context, context, parent): """ Initialize the widget. :param fit_context: A reference to the a FitContext object used to store fit results :param parent: A parent widget for the view """ self.results_tab_view = ResultsTabView(parent=parent) self.results_tab_presenter = ResultsTabPresenter( self.results_tab_view, ResultsTabModel(fit_context)) context.update_view_from_model_notifier.add_subscriber( self.results_tab_presenter.update_view_from_model_observer)
def test_create_results_table_raises_error_if_number_params_different( self): parameters = OrderedDict([('Height', (100, 0.1)), ('Cost function value', (1.5, 0))]) fits_func1 = create_test_fits(('ws1', ), 'func1', parameters, []) parameters = OrderedDict([('Height', (100, 0.1)), ('A0', (1, 0.001)), ('Cost function value', (1.5, 0))]) fits_func2 = create_test_fits(('ws2', ), 'func2', parameters, []) model = ResultsTabModel(FittingContext(fits_func1 + fits_func2)) selected_results = [('ws1', 0), ('ws2', 1)] self.assertRaises(RuntimeError, model.create_results_table, [], selected_results)
def test_create_results_table_with_mixed_global_non_global_raises_error( self): parameters = OrderedDict([('f0.Height', (100, 0.1)), ('f1.Height', (90, 0.001)), ('Cost function value', (1.5, 0))]) fits_func1 = create_test_fits(('ws1', ), 'func1', parameters, []) fits_globals = create_test_fits(('ws2', ), 'func1', parameters, [], global_parameters=['Height']) model = ResultsTabModel(FittingContext(fits_func1 + fits_globals)) selected_results = [('ws1', 0), ('ws2', 1)] self.assertRaises(RuntimeError, model.create_results_table, [], selected_results)
def test_create_results_table_with_logs_missing_from_some_workspaces_raises( self): parameters = OrderedDict([('f0.Height', (100, 0.1))]) logs = [('log1', (1., 2.)), ('log2', (3., 4.)), ('log3', (4., 5.)), ('log4', (5., 6.))] fits_logs1 = create_test_fits(('ws1', ), 'func1', parameters, output_workspace_names=('ws1', )) add_logs(fits_logs1[0].input_workspaces[0], logs[:2]) fits_logs2 = create_test_fits(('ws2', ), 'func1', parameters, output_workspace_names=('ws2', )) add_logs(fits_logs2[0].input_workspaces[0], logs[2:]) model = ResultsTabModel(FittingContext(fits_logs1 + fits_logs2)) selected_results = [('ws1', 0), ('ws2', 1)] selected_logs = ['log1', 'log3'] self.assertRaises(RuntimeError, model.create_results_table, selected_logs, selected_results)
def test_create_results_table_raises_error_if_number_params_different( self): parameters = OrderedDict([('Height', (100, 0.1)), ('Cost function value', (1.5, 0))]) fits_func1 = create_test_fits(('ws1',), 'func1', parameters) parameters = OrderedDict([('Height', (100, 0.1)), ('A0', (1, 0.001)), ('Cost function value', (1.5, 0))]) fits_func2 = create_test_fits(('ws2',), 'func2', parameters) fitting_context = TFAsymmetryFittingContext() fitting_context.fit_list = fits_func1 + fits_func2 model = ResultsTabModel(fitting_context, ResultsContext()) selected_results = [('ws1', 0), ('ws2', 1)] self.assertRaises(IndexError, model.create_results_table, [], selected_results)
def test_create_results_table_with_logs_missing_from_some_workspaces_raises(self): workspace = WorkspaceFactory.create("Workspace2D", NVectors=3, YLength=5, XLength=5) parameters = OrderedDict([('f0.Height', (100, 0.1))]) logs = [('log1', (1., 2.)), ('log2', (3., 4.)), ('log3', (4., 5.)), ('log4', (5., 6.))] fits_logs1 = create_test_fits(('ws1',), 'func1', parameters, output_workspace_names=[StaticWorkspaceWrapper('test-ws1-ws', workspace)]) add_logs(fits_logs1[0].input_workspaces[0], logs[:2]) fits_logs2 = create_test_fits(('ws2',), 'func1', parameters, output_workspace_names=[StaticWorkspaceWrapper('test-ws2-ws', workspace)]) add_logs(fits_logs2[0].input_workspaces[0], logs[2:]) fitting_context = TFAsymmetryFittingContext() fitting_context.fit_list = fits_logs1 + fits_logs2 model = ResultsTabModel(fitting_context, ResultsContext()) selected_results = [('ws1', 0), ('ws2', 1)] selected_logs = ['log1', 'log3'] self.assertRaises(IndexError, model.create_results_table, selected_logs, selected_results)
def test_model_returns_no_log_selection_if_no_fits_present(self): model = ResultsTabModel(FittingContext()) self.assertEqual(0, len(model.log_selection({})))
def test_updating_model_selected_fit_function(self): model = ResultsTabModel(FittingContext()) new_selection = 'func2' model.set_selected_fit_function(new_selection) self.assertEqual(model.selected_fit_function(), new_selection)
def test_default_model_has_no_selected_function_without_fits(self): model = ResultsTabModel(FittingContext()) self.assertTrue(model.selected_fit_function() is None)
def test_updating_model_results_table_name(self): table_name = 'table_name' model = ResultsTabModel(FittingContext()) model.set_results_table_name(table_name) self.assertEqual(model.results_table_name(), table_name)
def test_default_model_has_results_table_name(self): model = ResultsTabModel(FittingContext()) self.assertEqual(model.results_table_name(), DEFAULT_TABLE_NAME)
def test_model_returns_no_fit_selection_if_no_fits_present(self): model = ResultsTabModel(TFAsymmetryFittingContext(), ResultsContext()) self.assertEqual(0, len(model.fit_selection({})))