def _create_matrix_workspaces_for_parameter_combination( self, workspace_group: WorkspaceGroup, x_parameter_name: str, y_parameter_name: str) -> None: """Creates the matrix workspace for a specific x and y parameter, and adds it to the workspace group.""" if x_parameter_name != y_parameter_name and x_parameter_name in self.x_parameters() \ and y_parameter_name in self.y_parameters(): x_values = self._convert_str_column_values_to_int( self.fitting_context.x_parameters[x_parameter_name]) x_errors = self.fitting_context.x_parameter_errors[ x_parameter_name] y_values = self._convert_str_column_values_to_int( self.fitting_context.y_parameters[y_parameter_name]) y_errors = self.fitting_context.y_parameter_errors[ y_parameter_name] # Sort the data based on the x_values being in ascending order x_values, x_errors, y_values, y_errors = zip( *sorted(zip(x_values, x_errors, y_values, y_errors))) output_name = self.parameter_combination_workspace_name( x_parameter_name, y_parameter_name) if not self._parameter_combination_workspace_exists( output_name, x_values, y_values, y_errors): self._create_workspace(x_values, x_errors, x_parameter_name, y_values, y_errors, y_parameter_name, output_name) workspace_group.add(output_name)
def _create_matrix_workspaces_for_parameter_combinations( self, workspace_group: WorkspaceGroup) -> list: """Creates a MatrixWorkspace for each parameter combination. These are the workspaces that will be fitted.""" workspace_names = [] for x_parameter_name in self.x_parameters(): for y_parameter_name in self.y_parameters(): if x_parameter_name != y_parameter_name: x_values = self._convert_str_column_values_to_int( x_parameter_name, self.fitting_context.x_parameters) x_errors = self.fitting_context.x_parameter_errors[ x_parameter_name] y_values = self._convert_str_column_values_to_int( y_parameter_name, self.fitting_context.y_parameters) y_errors = self.fitting_context.y_parameter_errors[ y_parameter_name] # Sort the data based on the x_values being in ascending order x_values, x_errors, y_values, y_errors = zip( *sorted(zip(x_values, x_errors, y_values, y_errors))) output_name = self.parameter_combination_workspace_name( x_parameter_name, y_parameter_name) if not self._parameter_combination_workspace_exists( output_name, x_values, y_values, y_errors): self._create_workspace( x_values, x_errors, x_parameter_name, y_values, y_errors, self._create_y_label(y_parameter_name), output_name) workspace_group.add(output_name) workspace_names.append(output_name) return workspace_names
def test_that_can_add_workspaces_to_WorkspaceGroup_when_in_ADS(self): self.create_matrix_workspace_in_ADS("ws1") self.create_matrix_workspace_in_ADS("ws2") ws_group = WorkspaceGroup() mtd.add("group1", ws_group) ws_group.add("ws1") ws_group.add("ws2") self.assertTrue("ws1" in mtd["group1"]) self.assertTrue("ws2" in mtd["group1"])
def add_copy_to_ads(self) -> None: """Adds the output workspaces for this fit to the ADS. Must be a copy so the fit history remains a history.""" workspace_group = WorkspaceGroup() add_ws_to_ads(self.output_group_name(), workspace_group) for output_workspace in self.output_workspaces: add_ws_to_ads(output_workspace.workspace_name, output_workspace.workspace_copy()) workspace_group.add(output_workspace.workspace_name) add_ws_to_ads(self.parameter_workspace.workspace_name, self.parameter_workspace.workspace_copy()) workspace_group.add(self.parameter_workspace.workspace_name) add_ws_to_ads(self.covariance_workspace.workspace_name, self.covariance_workspace.workspace_copy()) workspace_group.add(self.covariance_workspace.workspace_name)