def PyExec(self):

        from IndirectReductionCommon import (
            get_multi_frame_rebin, identify_bad_detectors, unwrap_monitor,
            process_monitor_efficiency, scale_monitor, scale_detectors,
            rebin_reduction, group_spectra, fold_chopped, rename_reduction)

        self._setup()

        load_opts = dict()
        if self._instrument_name == 'VESUVIO':
            load_opts['InstrumentParFile'] = self._par_filename
            load_opts['Mode'] = 'FoilOut'
            load_opts['LoadMonitors'] = True

        self._workspace_names, self._chopped_data = load_file_ranges(
            self._data_files,
            self._ipf_filename,
            self._spectra_range[0],
            self._spectra_range[1],
            sum_files=self._sum_files,
            load_logs=self._load_logs,
            load_opts=load_opts)

        # applies the changes in the provided calibration file
        self._apply_calibration()
        # Load container if run is given
        self._load_and_scale_container(self._container_scale_factor, load_opts)

        # Load vanadium runs if given
        if self._vanadium_runs:
            self._vanadium_ws, _, _ = load_files(self._vanadium_runs,
                                                 self._ipf_filename,
                                                 self._spectra_range[0],
                                                 self._spectra_range[1],
                                                 load_logs=self._load_logs,
                                                 load_opts=load_opts)

            if len(self._workspace_names) > len(self._vanadium_runs):
                raise RuntimeError(
                    "There cannot be more sample runs than vanadium runs.")

        for index, c_ws_name in enumerate(self._workspace_names):
            is_multi_frame = isinstance(mtd[c_ws_name], WorkspaceGroup)

            # Get list of workspaces
            if is_multi_frame:
                workspaces = mtd[c_ws_name].getNames()
            else:
                workspaces = [c_ws_name]

            # Process rebinning for framed data
            rebin_string_2, num_bins = get_multi_frame_rebin(
                c_ws_name, self._rebin_string)

            masked_detectors = identify_bad_detectors(workspaces[0])

            # Process workspaces
            for ws_name in workspaces:
                monitor_ws_name = ws_name + '_mon'

                # Subtract empty container if there is one
                if self._container_workspace is not None:
                    Minus(LHSWorkspace=ws_name,
                          RHSWorkspace=self._container_workspace,
                          OutputWorkspace=ws_name)

                if self._vanadium_ws:
                    van_ws_name = self._vanadium_ws[index]
                    van_ws = mtd[van_ws_name]
                    if self._container_workspace is not None:
                        cont_ws = mtd[self._container_workspace]

                        if van_ws.blocksize() > cont_ws.blocksize():
                            RebinToWorkspace(
                                WorkspaceToRebin=van_ws_name,
                                WorkspaceToMatch=self._container_workspace,
                                OutputWorkspace=van_ws_name)
                        elif cont_ws.blocksize() > van_ws.blocksize():
                            RebinToWorkspace(
                                WorkspaceToRebin=self._container_workspace,
                                WorkspaceToMatch=van_ws_name,
                                OutputWorkspace=self._container_workspace)

                        Minus(LHSWorkspace=van_ws_name,
                              RHSWorkspace=self._container_workspace,
                              OutputWorkspace=van_ws_name)

                    if mtd[ws_name].blocksize() > van_ws.blocksize():
                        RebinToWorkspace(WorkspaceToRebin=ws_name,
                                         WorkspaceToMatch=van_ws_name,
                                         OutputWorkspace=ws_name)
                    elif van_ws.blocksize() > mtd[ws_name].blocksize():
                        RebinToWorkspace(WorkspaceToRebin=van_ws_name,
                                         WorkspaceToMatch=ws_name,
                                         OutputWorkspace=van_ws_name)

                    replacement_value = 0.1 * find_minimum_non_zero_y_in_workspace(
                        van_ws)
                    logger.information(
                        'Replacing zeros in {0} with {1}.'.format(
                            van_ws_name, replacement_value))
                    ReplaceSpecialValues(
                        InputWorkspace=van_ws_name,
                        SmallNumberThreshold=0.0000001,
                        SmallNumberValue=replacement_value,
                        OutputWorkspace=self._replace_zeros_name)

                    Divide(LHSWorkspace=ws_name,
                           RHSWorkspace=self._replace_zeros_name,
                           OutputWorkspace=ws_name,
                           AllowDifferentNumberSpectra=True)

                    DeleteWorkspace(self._replace_zeros_name)

                # Process monitor
                if not unwrap_monitor(ws_name):
                    ConvertUnits(InputWorkspace=monitor_ws_name,
                                 OutputWorkspace=monitor_ws_name,
                                 Target='Wavelength',
                                 EMode='Elastic')

                process_monitor_efficiency(ws_name)
                scale_monitor(ws_name)

                # Scale detector data by monitor intensities
                scale_detectors(ws_name, 'Elastic')

                # Remove the no longer needed monitor workspace
                DeleteWorkspace(monitor_ws_name)

                # Convert to dSpacing
                ConvertUnits(InputWorkspace=ws_name,
                             OutputWorkspace=ws_name,
                             Target='dSpacing',
                             EMode='Elastic')

                # Handle rebinning
                rebin_reduction(ws_name, self._rebin_string, rebin_string_2,
                                num_bins)

                # Group spectra
                group_spectra(ws_name,
                              masked_detectors=masked_detectors,
                              method=self._grouping_method,
                              group_ws=self._grouping_workspace)

            if is_multi_frame:
                fold_chopped(c_ws_name)

        # Remove the container workspaces
        if self._container_workspace is not None:
            self._delete_all([self._container_workspace])

        # Remove the vanadium workspaces
        if self._vanadium_ws:
            self._delete_all(self._vanadium_ws)

        # Rename output workspaces
        output_workspace_names = [
            rename_reduction(ws_name, self._sum_files)
            for ws_name in self._workspace_names
        ]

        # Group result workspaces
        GroupWorkspaces(InputWorkspaces=output_workspace_names,
                        OutputWorkspace=self._output_ws)

        self.setProperty('OutputWorkspace', self._output_ws)
Пример #2
0
    def PyExec(self):
        from IndirectReductionCommon import (
            load_files, get_multi_frame_rebin, identify_bad_detectors,
            unwrap_monitor, process_monitor_efficiency, scale_monitor,
            scale_detectors, rebin_reduction, group_spectra, fold_chopped,
            rename_reduction)

        self._setup()
        load_prog = Progress(self, start=0.0, end=0.10, nreports=2)
        load_prog.report('loading files')
        self._workspace_names, self._chopped_data = load_files(
            self._data_files, self._ipf_filename, self._spectra_range[0],
            self._spectra_range[1], self._sum_files, self._load_logs)
        load_prog.report('files loaded')

        process_prog = Progress(self,
                                start=0.1,
                                end=0.9,
                                nreports=len(self._workspace_names))
        for c_ws_name in self._workspace_names:
            process_prog.report('processing workspace' + c_ws_name)
            is_multi_frame = isinstance(mtd[c_ws_name], WorkspaceGroup)

            # Get list of workspaces
            if is_multi_frame:
                workspaces = mtd[c_ws_name].getNames()
            else:
                workspaces = [c_ws_name]

            # Process rebinning for framed data
            rebin_string_2, num_bins = get_multi_frame_rebin(
                c_ws_name, self._rebin_string)

            masked_detectors = identify_bad_detectors(workspaces[0])

            # Process workspaces
            for ws_name in workspaces:
                # Set Efixed if given to algorithm
                if self._efixed != Property.EMPTY_DBL:
                    SetInstrumentParameter(Workspace=ws_name,
                                           ComponentName=self._analyser,
                                           ParameterName='Efixed',
                                           ParameterType='Number',
                                           Value=str(self._efixed))

                monitor_ws_name = ws_name + '_mon'

                # Process monitor
                if not unwrap_monitor(ws_name):
                    ConvertUnits(InputWorkspace=monitor_ws_name,
                                 OutputWorkspace=monitor_ws_name,
                                 Target='Wavelength',
                                 EMode='Elastic')

                process_monitor_efficiency(ws_name)
                scale_monitor(ws_name)

                # Do background removal if a range was provided
                if self._background_range is not None:
                    ConvertToDistribution(Workspace=ws_name)
                    CalculateFlatBackground(InputWorkspace=ws_name,
                                            OutputWorkspace=ws_name,
                                            StartX=self._background_range[0],
                                            EndX=self._background_range[1],
                                            Mode='Mean')
                    ConvertFromDistribution(Workspace=ws_name)

                # Divide by the calibration workspace if one was provided
                if self._calibration_ws is not None:
                    index_min = self._calibration_ws.getIndexFromSpectrumNumber(
                        int(self._spectra_range[0]))
                    index_max = self._calibration_ws.getIndexFromSpectrumNumber(
                        int(self._spectra_range[1]))

                    CropWorkspace(InputWorkspace=self._calibration_ws,
                                  OutputWorkspace=self._calibration_ws,
                                  StartWorkspaceIndex=index_min,
                                  EndWorkspaceIndex=index_max)

                    Divide(LHSWorkspace=ws_name,
                           RHSWorkspace=self._calibration_ws,
                           OutputWorkspace=ws_name)

                # Scale detector data by monitor intensities
                scale_detectors(ws_name, 'Indirect')

                # Remove the no longer needed monitor workspace
                DeleteWorkspace(monitor_ws_name)

                # Convert to energy
                ConvertUnits(InputWorkspace=ws_name,
                             OutputWorkspace=ws_name,
                             Target='DeltaE',
                             EMode='Indirect')
                CorrectKiKf(InputWorkspace=ws_name,
                            OutputWorkspace=ws_name,
                            EMode='Indirect')

                # Handle rebinning
                rebin_reduction(ws_name, self._rebin_string, rebin_string_2,
                                num_bins)

                # Detailed balance
                if self._detailed_balance != Property.EMPTY_DBL:
                    corr_factor = 11.606 / (2 * self._detailed_balance)
                    ExponentialCorrection(InputWorkspace=ws_name,
                                          OutputWorkspace=ws_name,
                                          C0=1.0,
                                          C1=corr_factor,
                                          Operation='Multiply')

                # Scale
                if self._scale_factor != 1.0:
                    Scale(InputWorkspace=ws_name,
                          OutputWorkspace=ws_name,
                          Factor=self._scale_factor,
                          Operation='Multiply')

                # Group spectra
                group_spectra(ws_name,
                              masked_detectors=masked_detectors,
                              method=self._grouping_method,
                              group_file=self._grouping_map_file,
                              group_ws=self._grouping_ws)

            if self._fold_multiple_frames and is_multi_frame:
                fold_chopped(c_ws_name)

            # Convert to output units if needed
            if self._output_x_units != 'DeltaE':
                ConvertUnits(InputWorkspace=c_ws_name,
                             OutputWorkspace=c_ws_name,
                             EMode='Indirect',
                             Target=self._output_x_units)

        # Rename output workspaces
        output_workspace_names = [
            rename_reduction(ws_name, self._sum_files)
            for ws_name in self._workspace_names
        ]

        summary_prog = Progress(self, start=0.9, end=1.0, nreports=4)

        # Group result workspaces
        summary_prog.report('grouping workspaces')
        GroupWorkspaces(InputWorkspaces=output_workspace_names,
                        OutputWorkspace=self._output_ws)

        self.setProperty('OutputWorkspace', mtd[self._output_ws])

        summary_prog.report('Algorithm complete')
Пример #3
0
    def PyExec(self):
        from IndirectReductionCommon import (load_files,
                                             get_multi_frame_rebin,
                                             identify_bad_detectors,
                                             unwrap_monitor,
                                             process_monitor_efficiency,
                                             scale_monitor,
                                             scale_detectors,
                                             rebin_reduction,
                                             group_spectra,
                                             fold_chopped,
                                             rename_reduction)

        self._setup()

        load_opts = dict()
        load_opts['Mode'] = 'FoilOut'
        load_opts['InstrumentParFile'] = self._par_filename

        prog_reporter = Progress(self, start=0.0, end=1.0, nreports=1)

        prog_reporter.report("Loading Files")

        self._workspace_names, self._chopped_data = load_files(self._data_files,
                                                               ipf_filename=self._ipf_filename,
                                                               spec_min=self._spectra_range[0],
                                                               spec_max=self._spectra_range[1],
                                                               sum_files=self._sum_files,
                                                               load_opts=load_opts)


        prog_reporter.resetNumSteps(self._workspace_names.__len__(), 0.0, 1.0)

        for c_ws_name in self._workspace_names:
            is_multi_frame = isinstance(mtd[c_ws_name], WorkspaceGroup)

            # Get list of workspaces
            if is_multi_frame:
                workspaces = mtd[c_ws_name].getNames()
            else:
                workspaces = [c_ws_name]

            # Process rebinning for framed data
            rebin_string_2, num_bins = get_multi_frame_rebin(c_ws_name,
                                                             self._rebin_string)

            masked_detectors = identify_bad_detectors(workspaces[0])

            # Process workspaces
            for ws_name in workspaces:
                monitor_ws_name = ws_name + '_mon'

                # Process monitor
                if not unwrap_monitor(ws_name):
                    ConvertUnits(InputWorkspace=monitor_ws_name,
                                 OutputWorkspace=monitor_ws_name,
                                 Target='Wavelength',
                                 EMode='Elastic')

                process_monitor_efficiency(ws_name)
                scale_monitor(ws_name)

                # Scale detector data by monitor intensities
                scale_detectors(ws_name, 'Elastic')

                # Remove the no longer needed monitor workspace
                DeleteWorkspace(monitor_ws_name)

                # Convert to dSpacing
                ConvertUnits(InputWorkspace=ws_name,
                             OutputWorkspace=ws_name,
                             Target='dSpacing',
                             EMode='Elastic')

                # Handle rebinning
                rebin_reduction(ws_name,
                                self._rebin_string,
                                rebin_string_2,
                                num_bins)

                # Group spectra
                group_spectra(ws_name,
                              masked_detectors,
                              self._grouping_method)


            if is_multi_frame:
                fold_chopped(c_ws_name)

            prog_reporter.report()

        # Rename output workspaces
        output_workspace_names = [rename_reduction(ws_name, self._sum_files) for ws_name in self._workspace_names]

        # Group result workspaces
        GroupWorkspaces(InputWorkspaces=output_workspace_names,
                        OutputWorkspace=self._output_ws)

        self.setProperty('OutputWorkspace', self._output_ws)
Пример #4
0
    def PyExec(self):
        from IndirectReductionCommon import (
            get_multi_frame_rebin, identify_bad_detectors, unwrap_monitor,
            process_monitor_efficiency, scale_monitor, scale_detectors,
            rebin_reduction, group_spectra, fold_chopped, rename_reduction)

        self._setup()

        load_opts = dict()
        if self._instrument_name == 'VESUVIO':
            load_opts['Mode'] = 'FoilOut'

        self._workspace_names, self._chopped_data = load_files(
            self._data_files,
            self._ipf_filename,
            self._spectra_range[0],
            self._spectra_range[1],
            sum_files=self._sum_files,
            load_logs=self._load_logs,
            load_opts=load_opts)

        # applies the changes in the provided calibration file
        self._apply_calibration()
        # Load container if run is given
        self._load_and_scale_container(self._container_scale_factor, load_opts)

        for c_ws_name in self._workspace_names:
            is_multi_frame = isinstance(mtd[c_ws_name], WorkspaceGroup)

            # Get list of workspaces
            if is_multi_frame:
                workspaces = mtd[c_ws_name].getNames()
            else:
                workspaces = [c_ws_name]

            # Process rebinning for framed data
            rebin_string_2, num_bins = get_multi_frame_rebin(
                c_ws_name, self._rebin_string)

            masked_detectors = identify_bad_detectors(workspaces[0])

            # Process workspaces
            for ws_name in workspaces:
                # Subtract empty container if there is one
                if self._container_workspace is not None:
                    Minus(LHSWorkspace=ws_name,
                          RHSWorkspace=self._container_workspace,
                          OutputWorkspace=ws_name)

                monitor_ws_name = ws_name + '_mon'

                # Process monitor
                if not unwrap_monitor(ws_name):
                    ConvertUnits(InputWorkspace=monitor_ws_name,
                                 OutputWorkspace=monitor_ws_name,
                                 Target='Wavelength',
                                 EMode='Elastic')

                process_monitor_efficiency(ws_name)
                scale_monitor(ws_name)

                # Scale detector data by monitor intensities
                scale_detectors(ws_name, 'Elastic')

                # Remove the no longer needed monitor workspace
                DeleteWorkspace(monitor_ws_name)

                # Convert to dSpacing
                ConvertUnits(InputWorkspace=ws_name,
                             OutputWorkspace=ws_name,
                             Target='dSpacing',
                             EMode='Elastic')

                # Handle rebinning
                rebin_reduction(ws_name, self._rebin_string, rebin_string_2,
                                num_bins)

                # Group spectra
                group_spectra(ws_name, masked_detectors, self._grouping_method)

            if is_multi_frame:
                fold_chopped(c_ws_name)

        # Remove the container workspaces
        if self._container_workspace is not None:
            DeleteWorkspace(self._container_workspace)
            DeleteWorkspace(self._container_workspace + '_mon')

        # Rename output workspaces
        output_workspace_names = [
            rename_reduction(ws_name, self._sum_files)
            for ws_name in self._workspace_names
        ]

        # Group result workspaces
        GroupWorkspaces(InputWorkspaces=output_workspace_names,
                        OutputWorkspace=self._output_ws)

        self.setProperty('OutputWorkspace', self._output_ws)
    def PyExec(self):

        from IndirectReductionCommon import (get_multi_frame_rebin,
                                             identify_bad_detectors,
                                             unwrap_monitor,
                                             process_monitor_efficiency,
                                             scale_monitor,
                                             scale_detectors,
                                             rebin_reduction,
                                             group_spectra,
                                             fold_chopped,
                                             rename_reduction)

        self._setup()

        load_opts = dict()
        if self._instrument_name == 'VESUVIO':
            load_opts['InstrumentParFile'] = self._par_filename
            load_opts['Mode'] = 'FoilOut'
            load_opts['LoadMonitors'] = True

        self._workspace_names, self._chopped_data = load_file_ranges(self._data_files,
                                                                     self._ipf_filename,
                                                                     self._spectra_range[0],
                                                                     self._spectra_range[1],
                                                                     sum_files=self._sum_files,
                                                                     load_logs=self._load_logs,
                                                                     load_opts=load_opts)

        # applies the changes in the provided calibration file
        self._apply_calibration()
        # Load container if run is given
        self._load_and_scale_container(self._container_scale_factor, load_opts)

        # Load vanadium runs if given
        if self._vanadium_runs:
            self._vanadium_ws, _ = load_files(self._vanadium_runs,
                                              self._ipf_filename,
                                              self._spectra_range[0],
                                              self._spectra_range[1],
                                              load_logs=self._load_logs,
                                              load_opts=load_opts)

            if len(self._workspace_names) > len(self._vanadium_runs):
                raise RuntimeError("There cannot be more sample runs than vanadium runs.")

        for index, c_ws_name in enumerate(self._workspace_names):
            is_multi_frame = isinstance(mtd[c_ws_name], WorkspaceGroup)

            # Get list of workspaces
            if is_multi_frame:
                workspaces = mtd[c_ws_name].getNames()
            else:
                workspaces = [c_ws_name]

            # Process rebinning for framed data
            rebin_string_2, num_bins = get_multi_frame_rebin(c_ws_name,
                                                             self._rebin_string)

            masked_detectors = identify_bad_detectors(workspaces[0])

            # Process workspaces
            for ws_name in workspaces:
                monitor_ws_name = ws_name + '_mon'

                # Subtract empty container if there is one
                if self._container_workspace is not None:
                    Minus(LHSWorkspace=ws_name,
                          RHSWorkspace=self._container_workspace,
                          OutputWorkspace=ws_name)

                if self._vanadium_ws:
                    van_ws_name = self._vanadium_ws[index]
                    van_ws = mtd[van_ws_name]
                    if self._container_workspace is not None:
                        cont_ws = mtd[self._container_workspace]

                        if van_ws.blocksize() > cont_ws.blocksize():
                            RebinToWorkspace(WorkspaceToRebin=van_ws_name,
                                             WorkspaceToMatch=self._container_workspace,
                                             OutputWorkspace=van_ws_name)
                        elif cont_ws.blocksize() > van_ws.blocksize():
                            RebinToWorkspace(WorkspaceToRebin=self._container_workspace,
                                             WorkspaceToMatch=van_ws_name,
                                             OutputWorkspace=self._container_workspace)

                        Minus(LHSWorkspace=van_ws_name,
                              RHSWorkspace=self._container_workspace,
                              OutputWorkspace=van_ws_name)

                    if mtd[ws_name].blocksize() > van_ws.blocksize():
                        RebinToWorkspace(WorkspaceToRebin=ws_name,
                                         WorkspaceToMatch=van_ws_name,
                                         OutputWorkspace=ws_name)
                    elif van_ws.blocksize() > mtd[ws_name].blocksize():
                        RebinToWorkspace(WorkspaceToRebin=van_ws_name,
                                         WorkspaceToMatch=ws_name,
                                         OutputWorkspace=van_ws_name)

                    Divide(LHSWorkspace=ws_name,
                           RHSWorkspace=van_ws_name,
                           OutputWorkspace=ws_name,
                           AllowDifferentNumberSpectra=True)

                # Process monitor
                if not unwrap_monitor(ws_name):
                    ConvertUnits(InputWorkspace=monitor_ws_name,
                                 OutputWorkspace=monitor_ws_name,
                                 Target='Wavelength',
                                 EMode='Elastic')

                process_monitor_efficiency(ws_name)
                scale_monitor(ws_name)

                # Scale detector data by monitor intensities
                scale_detectors(ws_name, 'Elastic')

                # Remove the no longer needed monitor workspace
                DeleteWorkspace(monitor_ws_name)

                # Convert to dSpacing
                ConvertUnits(InputWorkspace=ws_name,
                             OutputWorkspace=ws_name,
                             Target='dSpacing',
                             EMode='Elastic')

                # Handle rebinning
                rebin_reduction(ws_name,
                                self._rebin_string,
                                rebin_string_2,
                                num_bins)

                # Group spectra
                group_spectra(ws_name,
                              masked_detectors=masked_detectors,
                              method=self._grouping_method,
                              group_ws=self._grouping_workspace)

            if is_multi_frame:
                fold_chopped(c_ws_name)

        # Remove the container workspaces
        if self._container_workspace is not None:
            self._delete_all([self._container_workspace])

        # Remove the vanadium workspaces
        if self._vanadium_ws:
            self._delete_all(self._vanadium_ws)

        # Rename output workspaces
        output_workspace_names = [rename_reduction(ws_name, self._sum_files) for ws_name in self._workspace_names]

        # Group result workspaces
        GroupWorkspaces(InputWorkspaces=output_workspace_names,
                        OutputWorkspace=self._output_ws)

        self.setProperty('OutputWorkspace', self._output_ws)
Пример #6
0
    def PyExec(self):
        from IndirectReductionCommon import (load_files,
                                             get_multi_frame_rebin,
                                             identify_bad_detectors,
                                             unwrap_monitor,
                                             process_monitor_efficiency,
                                             scale_monitor,
                                             scale_detectors,
                                             rebin_reduction,
                                             group_spectra,
                                             fold_chopped,
                                             rename_reduction,
                                             save_reduction,
                                             plot_reduction)

        self._setup()
        load_prog = Progress(self, start=0.0, end=0.10, nreports=2)
        load_prog.report('loading files')
        self._workspace_names, self._chopped_data = load_files(self._data_files,
                                                               self._ipf_filename,
                                                               self._spectra_range[0],
                                                               self._spectra_range[1],
                                                               self._sum_files,
                                                               self._load_logs)
        load_prog.report('files loaded')

        process_prog = Progress(self, start=0.1, end=0.9, nreports=len(self._workspace_names))
        for c_ws_name in self._workspace_names:
            process_prog.report('processing workspace' + c_ws_name)
            is_multi_frame = isinstance(mtd[c_ws_name], WorkspaceGroup)

            # Get list of workspaces
            if is_multi_frame:
                workspaces = mtd[c_ws_name].getNames()
            else:
                workspaces = [c_ws_name]

            # Process rebinning for framed data
            rebin_string_2, num_bins = get_multi_frame_rebin(c_ws_name,
                                                             self._rebin_string)

            masked_detectors = identify_bad_detectors(workspaces[0])

            # Process workspaces
            for ws_name in workspaces:
                # Set Efixed if given to algorithm
                if self._efixed != Property.EMPTY_DBL:
                    SetInstrumentParameter(Workspace=ws_name,
                                           ComponentName=self._analyser,
                                           ParameterName='Efixed',
                                           ParameterType='Number',
                                           Value=str(self._efixed))

                monitor_ws_name = ws_name + '_mon'

                # Process monitor
                if not unwrap_monitor(ws_name):
                    ConvertUnits(InputWorkspace=monitor_ws_name,
                                 OutputWorkspace=monitor_ws_name,
                                 Target='Wavelength',
                                 EMode='Elastic')

                process_monitor_efficiency(ws_name)
                scale_monitor(ws_name)

                # Do background removal if a range was provided
                if self._background_range is not None:
                    ConvertToDistribution(Workspace=ws_name)
                    CalculateFlatBackground(InputWorkspace=ws_name,
                                            OutputWorkspace=ws_name,
                                            StartX=self._background_range[0],
                                            EndX=self._background_range[1],
                                            Mode='Mean')
                    ConvertFromDistribution(Workspace=ws_name)

                # Divide by the calibration workspace if one was provided
                if self._calibration_ws is not None:
                    index_min = self._calibration_ws.getIndexFromSpectrumNumber(int(self._spectra_range[0]))
                    index_max = self._calibration_ws.getIndexFromSpectrumNumber(int(self._spectra_range[1]))

                    CropWorkspace(InputWorkspace=self._calibration_ws,
                                  OutputWorkspace=self._calibration_ws,
                                  StartWorkspaceIndex=index_min,
                                  EndWorkspaceIndex=index_max)

                    Divide(LHSWorkspace=ws_name,
                           RHSWorkspace=self._calibration_ws,
                           OutputWorkspace=ws_name)

                # Scale detector data by monitor intensities
                scale_detectors(ws_name, 'Indirect')

                # Remove the no longer needed monitor workspace
                DeleteWorkspace(monitor_ws_name)

                # Convert to energy
                ConvertUnits(InputWorkspace=ws_name,
                             OutputWorkspace=ws_name,
                             Target='DeltaE',
                             EMode='Indirect')
                CorrectKiKf(InputWorkspace=ws_name,
                            OutputWorkspace=ws_name,
                            EMode='Indirect')

                # Handle rebinning
                rebin_reduction(ws_name,
                                self._rebin_string,
                                rebin_string_2,
                                num_bins)

                # Detailed balance
                if self._detailed_balance != Property.EMPTY_DBL:
                    corr_factor = 11.606 / (2 * self._detailed_balance)
                    ExponentialCorrection(InputWorkspace=ws_name,
                                          OutputWorkspace=ws_name,
                                          C0=1.0,
                                          C1=corr_factor,
                                          Operation='Multiply')

                # Scale
                if self._scale_factor != 1.0:
                    Scale(InputWorkspace=ws_name,
                          OutputWorkspace=ws_name,
                          Factor=self._scale_factor,
                          Operation='Multiply')

                # Group spectra
                group_spectra(ws_name,
                              masked_detectors=masked_detectors,
                              method=self._grouping_method,
                              group_file=self._grouping_map_file,
                              group_ws=self._grouping_ws)

            if self._fold_multiple_frames and is_multi_frame:
                fold_chopped(c_ws_name)

            # Convert to output units if needed
            if self._output_x_units != 'DeltaE':
                ConvertUnits(InputWorkspace=c_ws_name,
                             OutputWorkspace=c_ws_name,
                             EMode='Indirect',
                             Target=self._output_x_units)

        # Rename output workspaces
        output_workspace_names = [rename_reduction(ws_name, self._sum_files) for ws_name in self._workspace_names]

        summary_prog = Progress(self, start=0.9, end=1.0, nreports=4)

        # Save result workspaces
        if self._save_formats is not None:
            summary_prog.report('saving')
            save_reduction(output_workspace_names,
                           self._save_formats,
                           self._output_x_units)

        # Group result workspaces
        summary_prog.report('grouping workspaces')
        GroupWorkspaces(InputWorkspaces=output_workspace_names,
                        OutputWorkspace=self._output_ws)

        self.setProperty('OutputWorkspace', mtd[self._output_ws])

        # Plot result workspaces
        if self._plot_type != 'None':
            summary_prog.report('Plotting')
            for ws_name in mtd[self._output_ws].getNames():
                plot_reduction(ws_name, self._plot_type)
        summary_prog.report('Algorithm complete')
Пример #7
0
    def PyExec(self):
        from IndirectReductionCommon import (load_files,
                                             get_multi_frame_rebin,
                                             identify_bad_detectors,
                                             unwrap_monitor,
                                             process_monitor_efficiency,
                                             scale_monitor,
                                             scale_detectors,
                                             rebin_reduction,
                                             group_spectra,
                                             fold_chopped,
                                             rename_reduction,
                                             save_reduction,
                                             plot_reduction)

        self._setup()
        self._workspace_names, self._chopped_data = load_files(self._data_files,
                                                              self._ipf_filename,
                                                              self._spectra_range[0],
                                                              self._spectra_range[1],
                                                              self._sum_files,
                                                              self._load_logs)

        for c_ws_name in self._workspace_names:
            is_multi_frame = isinstance(mtd[c_ws_name], WorkspaceGroup)

            # Get list of workspaces
            if is_multi_frame:
                workspaces = mtd[c_ws_name].getNames()
            else:
                workspaces = [c_ws_name]

            # Process rebinning for framed data
            rebin_string_2, num_bins = get_multi_frame_rebin(c_ws_name,
                                                             self._rebin_string)

            masked_detectors = identify_bad_detectors(workspaces[0])

            # Process workspaces
            for ws_name in workspaces:
                monitor_ws_name = ws_name + '_mon'

                # Process monitor
                if not unwrap_monitor(ws_name):
                    ConvertUnits(InputWorkspace=monitor_ws_name,
                                 OutputWorkspace=monitor_ws_name,
                                 Target='Wavelength',
                                 EMode='Elastic')

                process_monitor_efficiency(ws_name)
                scale_monitor(ws_name)

                # Do background removal if a range was provided
                if self._background_range is not None:
                    ConvertToDistribution(Workspace=ws_name)
                    CalculateFlatBackground(InputWorkspace=ws_name,
                                            OutputWorkspace=ws_name,
                                            StartX=self._background_range[0],
                                            EndX=self._background_range[1],
                                            Mode='Mean')
                    ConvertFromDistribution(Workspace=ws_name)

                # Divide by the calibration workspace if one was provided
                if self._calibration_ws is not None:
                    Divide(LHSWorkspace=ws_name,
                           RHSWorkspace=self._calibration_ws,
                           OutputWorkspace=ws_name)

                # Scale detector data by monitor intensities
                scale_detectors(ws_name, 'Indirect')

                # Remove the no longer needed monitor workspace
                DeleteWorkspace(monitor_ws_name)

                # Convert to energy
                ConvertUnits(InputWorkspace=ws_name,
                             OutputWorkspace=ws_name,
                             Target='DeltaE',
                             EMode='Indirect')
                CorrectKiKf(InputWorkspace=ws_name,
                            OutputWorkspace=ws_name,
                            EMode='Indirect')

                # Handle rebinning
                rebin_reduction(ws_name,
                                self._rebin_string,
                                rebin_string_2,
                                num_bins)

                # Detailed balance
                if self._detailed_balance is not None:
                    corr_factor = 11.606 / (2 * self._detailed_balance)
                    ExponentialCorrection(InputWorkspace=ws_name,
                                          OutputWorkspace=ws_name,
                                          C0=1.0,
                                          C1=corr_factor,
                                          Operation='Multiply')

                # Scale
                if self._scale_factor != 1.0:
                    Scale(InputWorkspaces=ws_name,
                          OutputWorkspace=ws_name,
                          Factor=self._scale_factor,
                          Operation='Multiply')

                # Group spectra
                group_spectra(ws_name,
                              masked_detectors,
                              self._grouping_method,
                              self._grouping_map_file,
                              self._grouping_ws)

            if self._fold_multiple_frames and is_multi_frame:
                fold_chopped(c_ws_name)

            # Convert to output units if needed
            if self._output_x_units != 'DeltaE':
                ConvertUnits(InputWorkspace=c_ws_name,
                             OutputWorkspace=c_ws_name,
                             EMode='Indirect',
                             Target=self._output_x_units)

        # Rename output workspaces
        output_workspace_names = [rename_reduction(ws_name, self._sum_files) for ws_name in self._workspace_names]

        # Save result workspaces
        if self._save_formats is not None:
            save_reduction(output_workspace_names,
                           self._save_formats,
                           self._output_x_units)

        # Group result workspaces
        GroupWorkspaces(InputWorkspaces=output_workspace_names,
                        OutputWorkspace=self._output_ws)

        self.setProperty('OutputWorkspace', self._output_ws)

        # Plot result workspaces
        if self._plot_type != 'None':
            for ws_name in mtd[self._output_ws].getNames():
                plot_reduction(ws_name, self._plot_type)
    def PyExec(self):
        from IndirectReductionCommon import (load_files,
                                             get_multi_frame_rebin,
                                             identify_bad_detectors,
                                             unwrap_monitor,
                                             process_monitor_efficiency,
                                             scale_monitor,
                                             scale_detectors,
                                             rebin_reduction,
                                             group_spectra,
                                             fold_chopped,
                                             rename_reduction)

        self._setup()

        load_opts = dict()
        if self._instrument_name == 'VESUVIO':
            load_opts['Mode'] = 'FoilOut'

        self._workspace_names, self._chopped_data = load_files(self._data_files,
                                                               self._ipf_filename,
                                                               self._spectra_range[0],
                                                               self._spectra_range[1],
                                                               sum_files=self._sum_files,
                                                               load_logs=self._load_logs,
                                                               load_opts=load_opts)

        # Load container if run is given
        if self._container_data_files is not None:
            self._container_workspace, _ = load_files(self._container_data_files,
                                                      self._ipf_filename,
                                                      self._spectra_range[0],
                                                      self._spectra_range[1],
                                                      sum_files=True,
                                                      load_logs=self._load_logs,
                                                      load_opts=load_opts)
            self._container_workspace = self._container_workspace[0]

            # Scale container if factor is given
            if self._container_scale_factor != 1.0:
                Scale(InputWorkspace=self._container_workspace,
                      OutputWorkspace=self._container_workspace,
                      Factor=self._container_scale_factor,
                      Operation='Multiply')

        for c_ws_name in self._workspace_names:
            is_multi_frame = isinstance(mtd[c_ws_name], WorkspaceGroup)

            # Get list of workspaces
            if is_multi_frame:
                workspaces = mtd[c_ws_name].getNames()
            else:
                workspaces = [c_ws_name]

            # Process rebinning for framed data
            rebin_string_2, num_bins = get_multi_frame_rebin(c_ws_name,
                                                             self._rebin_string)

            masked_detectors = identify_bad_detectors(workspaces[0])

            # Process workspaces
            for ws_name in workspaces:
                # Subtract empty container if there is one
                if self._container_workspace is not None:
                    Minus(LHSWorkspace=ws_name,
                          RHSWorkspace=self._container_workspace,
                          OutputWorkspace=ws_name)

                monitor_ws_name = ws_name + '_mon'

                # Process monitor
                if not unwrap_monitor(ws_name):
                    ConvertUnits(InputWorkspace=monitor_ws_name,
                                 OutputWorkspace=monitor_ws_name,
                                 Target='Wavelength',
                                 EMode='Elastic')

                process_monitor_efficiency(ws_name)
                scale_monitor(ws_name)

                # Scale detector data by monitor intensities
                scale_detectors(ws_name, 'Elastic')

                # Remove the no longer needed monitor workspace
                DeleteWorkspace(monitor_ws_name)

                # Convert to dSpacing
                ConvertUnits(InputWorkspace=ws_name,
                             OutputWorkspace=ws_name,
                             Target='dSpacing',
                             EMode='Elastic')

                # Handle rebinning
                rebin_reduction(ws_name,
                                self._rebin_string,
                                rebin_string_2,
                                num_bins)

                # Group spectra
                group_spectra(ws_name,
                              masked_detectors,
                              self._grouping_method)

            if is_multi_frame:
                fold_chopped(c_ws_name)

        # Remove the container workspaces
        if self._container_workspace is not None:
            DeleteWorkspace(self._container_workspace)
            DeleteWorkspace(self._container_workspace + '_mon')

        # Rename output workspaces
        output_workspace_names = [rename_reduction(ws_name, self._sum_files) for ws_name in self._workspace_names]

        # Group result workspaces
        GroupWorkspaces(InputWorkspaces=output_workspace_names,
                        OutputWorkspace=self._output_ws)

        self.setProperty('OutputWorkspace', self._output_ws)
Пример #9
0
    def PyExec(self):

        warnings.warn("This algorithm is depreciated (April-2017). Please use ISISIndirectDiffractionReduction")

        from IndirectReductionCommon import (load_files,
                                             get_multi_frame_rebin,
                                             identify_bad_detectors,
                                             unwrap_monitor,
                                             process_monitor_efficiency,
                                             scale_monitor,
                                             scale_detectors,
                                             rebin_reduction,
                                             group_spectra,
                                             fold_chopped,
                                             rename_reduction)

        self._setup()

        load_opts = dict()
        load_opts['Mode'] = 'FoilOut'
        load_opts['InstrumentParFile'] = self._par_filename
        # Tell LoadVesuvio to load the monitors and keep them in the output
        load_opts['LoadMonitors'] = True

        prog_reporter = Progress(self, start=0.0, end=1.0, nreports=1)

        prog_reporter.report("Loading Files")
        self._workspace_names, self._chopped_data = load_files(self._data_files,
                                                               ipf_filename=self._ipf_filename,
                                                               spec_min=self._spectra_range[0],
                                                               spec_max=self._spectra_range[1],
                                                               sum_files=self._sum_files,
                                                               load_opts=load_opts)

        prog_reporter.resetNumSteps(len(self._workspace_names), 0.0, 1.0)

        for c_ws_name in self._workspace_names:
            is_multi_frame = isinstance(mtd[c_ws_name], WorkspaceGroup)

            # Get list of workspaces
            if is_multi_frame:
                workspaces = mtd[c_ws_name].getNames()
            else:
                workspaces = [c_ws_name]

            # Process rebinning for framed data
            rebin_string_2, num_bins = get_multi_frame_rebin(c_ws_name,
                                                             self._rebin_string)

            masked_detectors = identify_bad_detectors(workspaces[0])

            # Process workspaces
            for ws_name in workspaces:
                monitor_ws_name = ws_name + '_mon'

                # Process monitor
                if not unwrap_monitor(ws_name):
                    ConvertUnits(InputWorkspace=monitor_ws_name,
                                 OutputWorkspace=monitor_ws_name,
                                 Target='Wavelength',
                                 EMode='Elastic')

                process_monitor_efficiency(ws_name)
                scale_monitor(ws_name)

                # Scale detector data by monitor intensities
                scale_detectors(ws_name, 'Elastic')

                # Remove the no longer needed monitor workspace
                DeleteWorkspace(monitor_ws_name)

                # Convert to dSpacing
                ConvertUnits(InputWorkspace=ws_name,
                             OutputWorkspace=ws_name,
                             Target='dSpacing',
                             EMode='Elastic')

                # Handle rebinning
                rebin_reduction(ws_name,
                                self._rebin_string,
                                rebin_string_2,
                                num_bins)

                # Group spectra
                group_spectra(ws_name,
                              masked_detectors,
                              self._grouping_method)

            if is_multi_frame:
                fold_chopped(c_ws_name)

            prog_reporter.report()

        # Rename output workspaces
        output_workspace_names = [rename_reduction(ws_name, self._sum_files) for ws_name in self._workspace_names]

        # Group result workspaces
        GroupWorkspaces(InputWorkspaces=output_workspace_names,
                        OutputWorkspace=self._output_ws)

        self.setProperty('OutputWorkspace', self._output_ws)