def test_that_can_add_workspaces_to_WorkspaceGroup_when_not_in_ADS(self): ws1 = WorkspaceFactory.create("Workspace2D", 2, 2, 2) ws2 = WorkspaceFactory.create("Workspace2D", 2, 2, 2) ws_group = WorkspaceGroup() ws_group.addWorkspace(ws1) ws_group.addWorkspace(ws2) self.assertEqual(ws_group.size(), 2)
def set_output_workspaces(self, reduction_mode_vs_output_workspaces, reduction_mode_vs_workspace_names): """ Sets the output workspaces which can be HAB, LAB or Merged. At this step we also provide a workspace name to the sample logs which can be used later on for saving :param reduction_mode_vs_output_workspaces: map from reduction mode to output workspace :param reduction_mode_vs_workspace_names: map from reduction mode to output workspace name """ workspace_group_merged = WorkspaceGroup() workspace_group_lab = WorkspaceGroup() workspace_group_hab = WorkspaceGroup() # Note that this breaks the flexibility that we have established with the reduction mode. We have not hardcoded # HAB or LAB anywhere which means that in the future there could be other detectors of relevance. Here we # reference HAB and LAB directly since we currently don't want to rely on dynamic properties. See also in PyInit for reduction_mode, output_workspaces in list( reduction_mode_vs_output_workspaces.items()): workspace_names = reduction_mode_vs_workspace_names[reduction_mode] for output_workspace, output_name in zip(output_workspaces, workspace_names): # In an MPI reduction output_workspace is produced on the master rank, skip others. if output_workspace is None: continue else: AnalysisDataService.addOrReplace(output_name, output_workspace) if reduction_mode is ReductionMode.Merged: workspace_group_merged.addWorkspace(output_workspace) elif reduction_mode is ISISReductionMode.LAB: workspace_group_lab.addWorkspace(output_workspace) elif reduction_mode is ISISReductionMode.HAB: workspace_group_hab.addWorkspace(output_workspace) else: raise RuntimeError( "SANSSingleReduction: Cannot set the output workspace. " "The selected reduction mode {0} is unknown.".format( reduction_mode)) if workspace_group_merged.size() > 0: self.setProperty("OutputWorkspaceMerged", workspace_group_merged) if workspace_group_lab.size() > 0: self.setProperty("OutputWorkspaceLAB", workspace_group_lab) if workspace_group_hab.size() > 0: self.setProperty("OutputWorkspaceHAB", workspace_group_hab)
def test_that_can_add_workspaces_to_WorkspaceGroup_when_not_in_ADS(self): ws1 = WorkspaceFactory.create("Workspace2D", 2, 2, 2) ws2 = WorkspaceFactory.create("Workspace2D", 2, 2, 2) ws_group = WorkspaceGroup() ws_group.addWorkspace(ws1) ws_group.addWorkspace(ws2) self.assertEqual(ws_group.size(), 2)
def set_reduced_can_workspace_on_output(self, output_bundles): """ Sets the reduced can group workspaces on the output properties. The reduced can workspaces can be: LAB Can or HAB Can :param output_bundles: a list of output bundles """ workspace_group_lab_can = WorkspaceGroup() workspace_group_hab_can = WorkspaceGroup() # Find the LAB Can and HAB Can entries if they exist for component_bundle in output_bundles: for output_bundle in component_bundle: if output_bundle.data_type is DataType.Can: reduction_mode = output_bundle.reduction_mode output_workspace = output_bundle.output_workspace # Make sure that the output workspace is not None which can be the case if there has never been a # can set for the reduction. if output_workspace is not None and not does_can_workspace_exist_on_ads( output_workspace): name = self._get_output_workspace_name( output_bundle.state, output_bundle.reduction_mode, can=True) AnalysisDataService.addOrReplace( name, output_workspace) if reduction_mode is ISISReductionMode.LAB: workspace_group_lab_can.addWorkspace( output_workspace) elif reduction_mode is ISISReductionMode.HAB: workspace_group_hab_can.addWorkspace( output_workspace) else: raise RuntimeError( "SANSSingleReduction: The reduction mode {0} should not" " be set with a can.".format(reduction_mode)) if workspace_group_lab_can.size() > 0: # LAB group workspace is non-empty, so we want to set it as output self.setProperty("OutputWorkspaceLABCan", workspace_group_lab_can) if workspace_group_hab_can.size() > 0: self.setProperty("OutputWorkspaceHABCan", workspace_group_hab_can)
def set_can_and_sam_on_output(self, output_bundles): """ Sets the reduced can and sam workspaces. These can be: 1. LAB Can 2. HAB Can 3. LAB Sample 4. HAB Sample Cans are also output for optimization, so check for double output. :param output_bundles: a list of output_bundles """ workspace_group_lab_can = WorkspaceGroup() workspace_group_hab_can = WorkspaceGroup() workspace_group_lab_sample = WorkspaceGroup() workspace_group_hab_sample = WorkspaceGroup() for component_bundle in output_bundles: for output_bundle in component_bundle: if output_bundle.data_type is DataType.Can: reduction_mode = output_bundle.reduction_mode output_workspace = output_bundle.output_workspace if output_workspace is not None and not does_can_workspace_exist_on_ads( output_workspace): can_name = self._get_output_workspace_name( output_bundle.state, output_bundle.reduction_mode, can=True) AnalysisDataService.addOrReplace( can_name, output_workspace) if reduction_mode is ISISReductionMode.LAB: workspace_group_lab_can.addWorkspace( output_workspace) elif reduction_mode is ISISReductionMode.HAB: workspace_group_hab_can.addWorkspace( output_workspace) else: raise RuntimeError( "SANSSingleReduction: The reduction mode {0} should not" " be set with a can.".format(reduction_mode)) elif output_bundle.data_type is DataType.Sample: reduction_mode = output_bundle.reduction_mode output_workspace = output_bundle.output_workspace if output_workspace is not None: sample_name = self._get_output_workspace_name( output_bundle.state, output_bundle.reduction_mode, sample=True) AnalysisDataService.addOrReplace( sample_name, output_workspace) if reduction_mode is ISISReductionMode.LAB: workspace_group_lab_sample.addWorkspace( output_workspace) elif reduction_mode is ISISReductionMode.HAB: workspace_group_hab_sample.addWorkspace( output_workspace) else: raise RuntimeError( "SANSSingleReduction: The reduction mode {0} should not" " be set with a sample.".format( reduction_mode)) if workspace_group_hab_can.size() > 0: self.setProperty("OutputWorkspaceHABCan", workspace_group_hab_can) if workspace_group_hab_sample.size() > 0: self.setProperty("OutputWorkspaceHABSample", workspace_group_hab_sample) if workspace_group_lab_can.size() > 0: self.setProperty("OutputWorkspaceLABCan", workspace_group_lab_can) if workspace_group_lab_sample.size() > 0: self.setProperty("OutputWorkspaceLABSample", workspace_group_lab_sample)
def set_reduced_can_count_and_norm_on_output(self, output_bundles_parts): """ Sets the reduced can count and norm group workspaces on the output properties. The reduced can workspaces can be: 1. LAB Can Count 2. LAB Can Norm 3. HAB Can Count 4. HAB Can Norm :param output_bundles_parts: a list of output bundle parts """ workspace_group_lab_can_count = WorkspaceGroup() workspace_group_lab_can_norm = WorkspaceGroup() workspace_group_hab_can_count = WorkspaceGroup() workspace_group_hab_can_norm = WorkspaceGroup() # Find the partial output bundles fo LAB Can and HAB Can if they exist for event_slice_bundles in output_bundles_parts: for output_bundle_part in event_slice_bundles: if output_bundle_part.data_type is DataType.Can: reduction_mode = output_bundle_part.reduction_mode output_workspace_count = output_bundle_part.output_workspace_count output_workspace_norm = output_bundle_part.output_workspace_norm # Make sure that the output workspace is not None which can be the case if there has never been a # can set for the reduction. if output_workspace_norm is not None and output_workspace_count is not None and \ not does_can_workspace_exist_on_ads(output_workspace_norm) and \ not does_can_workspace_exist_on_ads(output_workspace_count): name = self._get_output_workspace_name( output_bundle_part.state, output_bundle_part.reduction_mode) count_name = name + "_hab_can_count" norm_name = name + "_hab_can_norm" AnalysisDataService.addOrReplace( count_name, output_workspace_count) AnalysisDataService.addOrReplace( norm_name, output_workspace_norm) if reduction_mode is ISISReductionMode.LAB: workspace_group_lab_can_count.addWorkspace( output_workspace_count) workspace_group_lab_can_norm.addWorkspace( output_workspace_norm) elif reduction_mode is ISISReductionMode.HAB: workspace_group_hab_can_count.addWorkspace( output_workspace_count) workspace_group_hab_can_norm.addWorkspace( output_workspace_norm) else: raise RuntimeError( "SANSSingleReduction: The reduction mode {0} should not" " be set with a partial can.".format( reduction_mode)) if workspace_group_lab_can_count.size() > 0: self.setProperty("OutputWorkspaceLABCanCount", workspace_group_lab_can_count) if workspace_group_lab_can_norm.size() > 0: self.setProperty("OutputWorkspaceLABCanNorm", workspace_group_lab_can_norm) if workspace_group_hab_can_count.size() > 0: self.setProperty("OutputWorkspaceHABCanCount", workspace_group_hab_can_count) if workspace_group_hab_can_norm.size() > 0: self.setProperty("OutputWorkspaceHABCanNorm", workspace_group_hab_can_norm)