Ejemplo n.º 1
0
 def do_reduction(self, reduction_alg, reduction_setting_bundles, use_optimizations, progress):
     """
     Perform the main reduction.
     :param reduction_alg: SANSReductionCore algorithm
     :param reduction_setting_bundles: a list of lists containing workspaces to be reduced.
                                       The outer list is for compatibility with version 2
                                       and only contains one inner list
     :param use_optimizations: bool. If true, use can optimizations
     :param progress: a progress bar
     :return: output_bundles: a list containing a single list of output workspaces
              output_parts_bundles: a list containing a single list of output workspaces
              output_transmission_bundles: a list containing transmission workspaces
     """
     reduction_setting_bundles = reduction_setting_bundles[0]
     output_bundles = []
     output_parts_bundles = []
     output_transmission_bundles = []
     for reduction_setting_bundle in reduction_setting_bundles:
         progress.report("Running a single reduction ...")
         # We want to make use of optimizations here. If a can workspace has already been reduced with the same can
         # settings and is stored in the ADS, then we should use it (provided the user has optimizations enabled).
         if use_optimizations and reduction_setting_bundle.data_type is DataType.CAN:
             output_bundle, output_parts_bundle, \
                 output_transmission_bundle = run_optimized_for_can(reduction_alg, reduction_setting_bundle)
         else:
             output_bundle, output_parts_bundle, \
                 output_transmission_bundle = run_core_reduction(reduction_alg, reduction_setting_bundle)
         output_bundles.append(output_bundle)
         output_parts_bundles.append(output_parts_bundle)
         output_transmission_bundles.append(output_transmission_bundle)
     return [output_bundles], [output_parts_bundles], output_transmission_bundles
Ejemplo n.º 2
0
    def do_reduction(self, reduction_alg, reduction_setting_bundles,
                     use_optimizations, progress):
        """
        Perform the main reduction
        :param reduction_alg: SANSReductionCoreEventSlice algorithm
        :param reduction_setting_bundles: a list of list containing workspaces to be reduced.
        :param use_optimizations: bool. If true, use can optimizations in reduction
        :param progress: a progress bar
        :return: output_bundles: a list of list containing output workspaces
                 output_parts_bundles: a list of lists containing output workspaces
                 output_transmission_bundles: a list containing transmission workspaces
        """
        output_bundles = []
        output_parts_bundles = []
        output_transmission_bundles = []
        for event_slice_bundles in reduction_setting_bundles:
            # Output bundles and parts bundles need to be separated by a event slices, but grouped by component
            # e.g. [[workspaces for slice1], [workspaces for slice2]]
            slice_bundles = []
            slice_parts_bundles = []
            for slice_bundle in event_slice_bundles:
                progress.report("Running a single reduction ...")
                # We want to make use of optimizations here.
                # If a can workspace has already been reduced with the same can
                # settings and is stored in the ADS, then we should use it
                # (provided the user has optimizations enabled).
                if use_optimizations and slice_bundle.data_type is DataType.Can:
                    output_bundle, output_parts_bundle, \
                        output_transmission_bundle = run_optimized_for_can(reduction_alg,
                                                                           slice_bundle,
                                                                           event_slice_optimisation=True)
                else:
                    output_bundle, output_parts_bundle, \
                        output_transmission_bundle = run_core_event_slice_reduction(reduction_alg, slice_bundle)
                slice_bundles.append(output_bundle)
                slice_parts_bundles.append(output_parts_bundle)
                output_transmission_bundles.append(output_transmission_bundle)
            output_bundles.append(slice_bundles)
            output_parts_bundles.append(slice_parts_bundles)

        return output_bundles, output_parts_bundles, output_transmission_bundles
Ejemplo n.º 3
0
    def PyExec(self):
        # Get state
        state = self._get_state()

        # Get reduction mode
        overall_reduction_mode = self._get_reduction_mode(state)

        # Decide which core reduction information to run, i.e. HAB, LAB, ALL, MERGED. In the case of ALL and MERGED,
        # the required simple reduction modes need to be run. Normally this is HAB and LAB, future implementations
        # might have more detectors though (or different types)
        reduction_setting_bundles = self._get_reduction_setting_bundles(
            state, overall_reduction_mode)

        # Run core reductions
        use_optimizations = self.getProperty("UseOptimizations").value

        # Create the reduction core algorithm
        reduction_name = "SANSReductionCore"
        reduction_options = {}
        reduction_alg = create_child_algorithm(self, reduction_name,
                                               **reduction_options)

        # Set up progress
        progress = self._get_progress(len(reduction_setting_bundles),
                                      overall_reduction_mode)

        # --------------------------------------------------------------------------------------------------------------
        # Reduction
        # --------------------------------------------------------------------------------------------------------------
        output_bundles = []
        output_parts_bundles = []

        for reduction_setting_bundle in reduction_setting_bundles:
            progress.report("Running a single reduction ...")
            # We want to make use of optimizations here. If a can workspace has already been reduced with the same can
            # settings and is stored in the ADS, then we should use it (provided the user has optimizations enabled).
            if use_optimizations and reduction_setting_bundle.data_type is DataType.Can:
                output_bundle, output_parts_bundle = run_optimized_for_can(
                    reduction_alg, reduction_setting_bundle)
            else:
                output_bundle, output_parts_bundle = run_core_reduction(
                    reduction_alg, reduction_setting_bundle)
            output_bundles.append(output_bundle)
            output_parts_bundles.append(output_parts_bundle)

        # --------------------------------------------------------------------------------------------------------------
        # Deal with merging
        # --------------------------------------------------------------------------------------------------------------
        reduction_mode_vs_output_workspaces = {}
        # Merge if required with stitching etc.
        if overall_reduction_mode is ReductionMode.Merged:
            progress.report("Merging reductions ...")
            merge_bundle = get_merge_bundle_for_merge_request(
                output_parts_bundles, self)
            self.set_shift_and_scale_output(merge_bundle)
            reduction_mode_vs_output_workspaces.update(
                {ReductionMode.Merged: merge_bundle.merged_workspace})

        # --------------------------------------------------------------------------------------------------------------
        # Deal with non-merged
        # Note that we have non-merged workspaces even in the case of a merged reduction, ie LAB and HAB results
        # --------------------------------------------------------------------------------------------------------------
        progress.report("Final clean up...")
        output_workspaces_non_merged = get_final_output_workspaces(
            output_bundles, self)
        reduction_mode_vs_output_workspaces.update(
            output_workspaces_non_merged)

        # --------------------------------------------------------------------------------------------------------------
        # Set the output workspaces
        # --------------------------------------------------------------------------------------------------------------
        # Set sample logs
        # Todo: Set sample log -> Userfile and unfitted transmission workspace. Should probably set on
        # higher level (SANSBatch)
        # Set the output workspaces
        self.set_output_workspaces(reduction_mode_vs_output_workspaces)

        # --------------------------------------------------------------------------------------------------------------
        # Set the reduced can workspaces on the output if optimizations are
        # enabled. This will allow SANSBatchReduction to add them to the ADS.
        # --------------------------------------------------------------------------------------------------------------
        if use_optimizations:
            self.set_reduced_can_workspace_on_output(output_bundles,
                                                     output_parts_bundles)
Ejemplo n.º 4
0
    def PyExec(self):
        # Get state
        state = self._get_state()

        # Get reduction mode
        overall_reduction_mode = self._get_reduction_mode(state)

        # Decide which core reduction information to run, i.e. HAB, LAB, ALL, MERGED. In the case of ALL and MERGED,
        # the required simple reduction modes need to be run. Normally this is HAB and LAB, future implementations
        # might have more detectors though (or different types)
        reduction_setting_bundles = self._get_reduction_setting_bundles(state, overall_reduction_mode)

        # Run core reductions
        use_optimizations = self.getProperty("UseOptimizations").value
        save_can = self.getProperty("SaveCan").value

        # Create the reduction core algorithm
        reduction_name = "SANSReductionCore"
        reduction_options = {}
        reduction_alg = create_child_algorithm(self, reduction_name, **reduction_options)

        # Set up progress
        progress = self._get_progress(len(reduction_setting_bundles), overall_reduction_mode)

        # --------------------------------------------------------------------------------------------------------------
        # Reduction
        # --------------------------------------------------------------------------------------------------------------
        output_bundles = []
        output_parts_bundles = []
        output_transmission_bundles = []
        for reduction_setting_bundle in reduction_setting_bundles:
            progress.report("Running a single reduction ...")
            # We want to make use of optimizations here. If a can workspace has already been reduced with the same can
            # settings and is stored in the ADS, then we should use it (provided the user has optimizations enabled).
            if use_optimizations and reduction_setting_bundle.data_type is DataType.Can:
                output_bundle, output_parts_bundle, output_transmission_bundle = run_optimized_for_can(reduction_alg,
                                                                                                       reduction_setting_bundle)
            else:
                output_bundle, output_parts_bundle, output_transmission_bundle = run_core_reduction(reduction_alg,
                                                                                                    reduction_setting_bundle)
            output_bundles.append(output_bundle)
            output_parts_bundles.append(output_parts_bundle)
            output_transmission_bundles.append(output_transmission_bundle)

        reduction_mode_vs_output_workspaces = {}

        # --------------------------------------------------------------------------------------------------------------
        # Deal with non-merged
        # Note that we have non-merged workspaces even in the case of a merged reduction, ie LAB and HAB results
        # --------------------------------------------------------------------------------------------------------------
        progress.report("Final clean up...")
        output_workspaces_non_merged = get_final_output_workspaces(output_bundles, self)
        reduction_mode_vs_output_workspaces.update(output_workspaces_non_merged)

        # --------------------------------------------------------------------------------------------------------------
        # Deal with merging
        # --------------------------------------------------------------------------------------------------------------
        # Merge if required with stitching etc.
        if overall_reduction_mode is ReductionMode.Merged:
            progress.report("Merging reductions ...")
            merge_bundle = get_merge_bundle_for_merge_request(output_parts_bundles, self)
            self.set_shift_and_scale_output(merge_bundle)
            reduction_mode_vs_output_workspaces.update({ReductionMode.Merged: merge_bundle.merged_workspace})
            scaled_HAB = strip_end_nans(merge_bundle.scaled_hab_workspace, self)
            reduction_mode_vs_output_workspaces.update({ISISReductionMode.HAB: scaled_HAB})

        # --------------------------------------------------------------------------------------------------------------
        # Set the output workspaces
        # --------------------------------------------------------------------------------------------------------------
        # Set sample logs
        # Todo: Set sample log -> Userfile and unfitted transmission workspace. Should probably set on
        # higher level (SANSBatch)
        # Set the output workspaces
        self.set_output_workspaces(reduction_mode_vs_output_workspaces)

        # --------------------------------------------------------------------------------------------------------------
        # Set the reduced can workspaces on the output if optimizations are
        # enabled. This will allow SANSBatchReduction to add them to the ADS.
        # --------------------------------------------------------------------------------------------------------------
        if use_optimizations:
            self.set_reduced_can_workspace_on_output(output_bundles, output_parts_bundles)

        if save_can:
            self.set_can_and_sam_on_output(output_bundles)

        self.set_transmission_workspaces_on_output(output_transmission_bundles,
                                                   state.adjustment.calculate_transmission.fit)