Example #1
0
    def _setup(self):
        """
        Gets algorithm properties.
        """

        from IndirectCommon import getWSprefix

        self._sample = self.getPropertyValue('SampleWorkspace')
        self._resolution = self.getPropertyValue('ResolutionWorkspace')

        self._e_min = self.getProperty('EnergyMin').value
        self._e_max = self.getProperty('EnergyMax').value
        self._number_points_per_bin = self.getProperty(
            'BinReductionFactor').value

        self._parameter_table = self.getPropertyValue('ParameterWorkspace')
        if self._parameter_table == '':
            self._parameter_table = getWSprefix(
                self._sample) + 'TransformToIqtParameters'

        self._calculate_errors = self.getProperty("CalculateErrors").value
        self._number_of_iterations = self.getProperty(
            "NumberOfIterations").value
        self._seed = self.getProperty("SeedValue").value

        self._output_workspace = self.getPropertyValue('OutputWorkspace')
        if self._output_workspace == '':
            self._output_workspace = getWSprefix(self._sample) + 'iqt'

        self._dry_run = self.getProperty('DryRun').value
Example #2
0
    def _setup(self):
        """
        Gets algorithm properties.
        """

        from IndirectCommon import getWSprefix

        self._sample = self.getPropertyValue('SampleWorkspace')
        self._resolution = self.getPropertyValue('ResolutionWorkspace')

        self._e_min = self.getProperty('EnergyMin').value
        self._e_max = self.getProperty('EnergyMax').value
        self._number_points_per_bin = self.getProperty(
            'BinReductionFactor').value

        self._parameter_table = self.getPropertyValue('ParameterWorkspace')
        if self._parameter_table == '':
            self._parameter_table = getWSprefix(
                self._sample) + 'TransformToIqtParameters'

        self._number_of_iterations = self.getProperty(
            "NumberOfIterations").value
        self._seed = self.getProperty("SeedValue").value

        self._output_workspace = self.getPropertyValue('OutputWorkspace')
        if self._output_workspace == '':
            self._output_workspace = getWSprefix(self._sample) + 'iqt'

        self._dry_run = self.getProperty('DryRun').value
Example #3
0
    def _setup(self):
        """
        Gets algorithm properties.
        """
        from IndirectCommon import getWSprefix

        self._sample = self.getPropertyValue('Sample')
        self._resolution = self.getPropertyValue('Resolution')

        self._e_min = self.getProperty('EnergyMin').value
        self._e_max = self.getProperty('EnergyMax').value
        self._number_points_per_bin = self.getProperty('NumBins').value

        self._parameter_table = self.getPropertyValue('ParameterWorkspace')
        if self._parameter_table == '':
            self._parameter_table = getWSprefix(
                self._sample) + 'FuryParameters'

        self._output_workspace = self.getPropertyValue('OutputWorkspace')
        if self._output_workspace == '':
            self._output_workspace = getWSprefix(self._sample) + 'iqt'

        self._verbose = self.getProperty('Verbose').value
        self._plot = self.getProperty('Plot').value
        self._save = self.getProperty('Save').value
        self._dry_run = self.getProperty('DryRun').value
Example #4
0
    def PyExec(self):
        from IndirectCommon import getWSprefix
        if self._create_output:
            self._out_ws_table = self.getPropertyValue('OutputWorkspaceTable')

        # Process vanadium workspace
        van_ws = ConvertSpectrumAxis(InputWorkspace=self._van_ws,
                                     OutputWorkspace='__ResNorm_vanadium',
                                     Target='ElasticQ',
                                     EMode='Indirect')

        num_hist = van_ws.getNumberHistograms()

        v_values = van_ws.getAxis(1).extractValues()
        v_unit = van_ws.getAxis(1).getUnit().unitID()

        # Process resolution workspace
        padded_res_ws = self._process_res_ws(num_hist)
        prog_namer = Progress(self, start=0.0, end=0.02, nreports=num_hist)
        input_str = ''
        for idx in range(num_hist):
            input_str += '%s,i%d;' % (padded_res_ws, idx)
            prog_namer.report('Generating PlotPeak input string')

        out_name = getWSprefix(self._res_ws) + 'ResNorm_Fit'
        function = 'name=TabulatedFunction,Workspace=%s,Scaling=1,Shift=0,XScaling=1,ties=(Shift=0)' % self._van_ws

        plot_peaks = self.createChildAlgorithm(name='PlotPeakByLogValue', startProgress=0.02, endProgress=0.94, enableLogging=True)
        plot_peaks.setProperty('Input', input_str)
        plot_peaks.setProperty('OutputWorkspace', out_name)
        plot_peaks.setProperty('Function', function)
        plot_peaks.setProperty('FitType', 'Individual')
        plot_peaks.setProperty('PassWSIndexToFunction', True)
        plot_peaks.setProperty('CreateOutput', self._create_output)
        plot_peaks.setProperty('StartX', self._e_min)
        plot_peaks.setProperty('EndX', self._e_max)
        plot_peaks.execute()
        fit_params = plot_peaks.getProperty('OutputWorkspace').value

        params = {'XScaling':'Stretch', 'Scaling':'Intensity'}
        result_workspaces = []
        prog_process = Progress(self, start=0.94, end=1.0, nreports=3)
        for param_name, output_name in params.items():
            result_workspaces.append(self._process_fit_params(fit_params, param_name, v_values, v_unit, output_name))
            prog_process.report('Processing Fit data')

        GroupWorkspaces(InputWorkspaces=result_workspaces,
                        OutputWorkspace=self._out_ws)
        self.setProperty('OutputWorkspace', self._out_ws)

        DeleteWorkspace(van_ws)
        DeleteWorkspace(padded_res_ws)
        prog_process.report('Deleting workspaces')

        if self._create_output:
            self.setProperty('OutputWorkspaceTable', fit_params)
Example #5
0
    def PyExec(self):
        from IndirectCommon import StartTime, EndTime, getWSprefix
        import inelastic_indirect_reducer

        StartTime('IndirectResolution')
        self._setup()

        InelasticIndirectReduction(Instrument=self._instrument,
                                   Analyser=self._analyser,
                                   Reflection=self._reflection,
                                   Grouping='All',
                                   SumFiles=True,
                                   InputFiles=self._input_files,
                                   DetectorRange=self._detector_range,
                                   OutputWorkspace='__icon_ws_group')

        icon_ws = mtd['__icon_ws_group'].getItem(0).getName()

        if self._out_ws == "":
            self._out_ws = getWSprefix(icon_ws) + 'res'

        if self._scale_factor != 1.0:
            Scale(InputWorkspace=icon_ws,
                  OutputWorkspace=icon_ws,
                  Factor=self._scale_factor)

        CalculateFlatBackground(InputWorkspace=icon_ws,
                                OutputWorkspace=self._out_ws,
                                StartX=self._background[0],
                                EndX=self._background[1],
                                Mode='Mean',
                                OutputMode='Subtract Background')

        Rebin(InputWorkspace=self._out_ws,
              OutputWorkspace=self._out_ws,
              Params=self._rebin_string)

        if self._smooth:
            WienerSmooth(InputWorkspace=self._out_ws,
                         OutputWorkspace='__smooth_temp')
            CopyLogs(InputWorkspace=self._out_ws,
                     OutputWorkspace='__smooth_temp')
            RenameWorkspace(InputWorkspace='__smooth_temp',
                            OutputWorkspace=self._out_ws)

        self._post_process()
        self.setProperty('OutputWorkspace', self._out_ws)

        EndTime('IndirectResolution')
Example #6
0
    def _setup(self):
        """
        Gets algorithm properties.
        """
        from IndirectCommon import getWSprefix

        self._sample = self.getPropertyValue('Sample')
        self._resolution = self.getPropertyValue('Resolution')

        self._e_min = self.getProperty('EnergyMin').value
        self._e_max = self.getProperty('EnergyMax').value
        self._number_points_per_bin = self.getProperty('NumBins').value

        self._parameter_table = self.getPropertyValue('ParameterWorkspace')
        if self._parameter_table == '':
            self._parameter_table = getWSprefix(self._sample) + 'FuryParameters'

        self._output_workspace = self.getPropertyValue('OutputWorkspace')
        if self._output_workspace == '':
            self._output_workspace = getWSprefix(self._sample) + 'iqt'

        self._plot = self.getProperty('Plot').value
        self._save = self.getProperty('Save').value
        self._dry_run = self.getProperty('DryRun').value
Example #7
0
    def PyExec(self):
        from IndirectCommon import getWSprefix

        # Process vanadium workspace
        van_ws = ConvertSpectrumAxis(
            InputWorkspace=self._van_ws, OutputWorkspace="__ResNorm_vanadium", Target="ElasticQ", EMode="Indirect"
        )

        num_hist = van_ws.getNumberHistograms()

        v_values = van_ws.getAxis(1).extractValues()
        v_unit = van_ws.getAxis(1).getUnit().unitID()

        # Process resolution workspace
        padded_res_ws = self._process_res_ws(num_hist)

        input_str = ""
        for idx in range(num_hist):
            input_str += "%s,i%d;" % (padded_res_ws, idx)

        out_name = getWSprefix(self._res_ws) + "ResNorm_Fit"
        function = "name=TabulatedFunction,Workspace=%s,Scaling=1,Shift=0,XScaling=1,ties=(Shift=0)" % self._van_ws

        fit_params = PlotPeakByLogValue(
            Input=input_str,
            OutputWorkspace=out_name,
            Function=function,
            FitType="Individual",
            PassWSIndexToFunction=True,
            CreateOutput=self._create_output,
            StartX=self._e_min,
            EndX=self._e_max,
        )

        params = {"XScaling": "Stretch", "Scaling": "Intensity"}
        result_workspaces = []
        for param_name, output_name in params.items():
            result_workspaces.append(self._process_fit_params(fit_params, param_name, v_values, v_unit, output_name))

        GroupWorkspaces(InputWorkspaces=result_workspaces, OutputWorkspace=self._out_ws)
        self.setProperty("OutputWorkspace", self._out_ws)

        DeleteWorkspace(van_ws)
        DeleteWorkspace(padded_res_ws)
        if not self._create_output:
            DeleteWorkspace(fit_params)
Example #8
0
    def PyExec(self):
        from IndirectCommon import (getWSprefix, convertToElasticQ)

        setup_prog = Progress(self, start=0.0, end=0.1, nreports=4)
        self._fit_type = self._fit_type[:-2]
        logger.information('Option: ' + self._fit_type)
        logger.information(self._function)

        setup_prog.report('Cropping workspace')
        tmp_fit_name = "__IqtFit_ws"
        crop_alg = self.createChildAlgorithm("CropWorkspace")
        crop_alg.setProperty("InputWorkspace", self._input_ws)
        crop_alg.setProperty("OutputWorkspace", tmp_fit_name)
        crop_alg.setProperty("XMin", self._start_x)
        crop_alg.setProperty("XMax", self._end_x)
        crop_alg.execute()

        num_hist = self._input_ws.getNumberHistograms()
        if self._spec_max is None:
            self._spec_max = num_hist - 1

        # Name stem for generated workspace
        output_workspace = '%sIqtFit_%s_s%d_to_%d' % (getWSprefix(
            self._input_ws.getName()), self._fit_type, self._spec_min,
                                                      self._spec_max)

        setup_prog.report('Converting to Histogram')
        convert_to_hist_alg = self.createChildAlgorithm("ConvertToHistogram")
        convert_to_hist_alg.setProperty(
            "InputWorkspace",
            crop_alg.getProperty("OutputWorkspace").value)
        convert_to_hist_alg.setProperty("OutputWorkspace", tmp_fit_name)
        convert_to_hist_alg.execute()
        mtd.addOrReplace(
            tmp_fit_name,
            convert_to_hist_alg.getProperty("OutputWorkspace").value)

        setup_prog.report('Convert to Elastic Q')
        convertToElasticQ(tmp_fit_name)

        # Build input string for PlotPeakByLogValue
        input_str = [
            tmp_fit_name + ',i%d' % i
            for i in range(self._spec_min, self._spec_max + 1)
        ]
        input_str = ';'.join(input_str)

        fit_prog = Progress(self, start=0.1, end=0.8, nreports=2)
        fit_prog.report('Fitting...')
        ms.PlotPeakByLogValue(Input=input_str,
                              OutputWorkspace=output_workspace,
                              Function=self._function,
                              Minimizer=self._minimizer,
                              MaxIterations=self._max_iterations,
                              StartX=self._start_x,
                              EndX=self._end_x,
                              FitType='Sequential',
                              CreateOutput=True)
        fit_prog.report('Fitting complete')

        conclusion_prog = Progress(self, start=0.8, end=1.0, nreports=5)
        # Remove unsused workspaces
        delete_alg = self.createChildAlgorithm("DeleteWorkspace")
        delete_alg.setProperty(
            "Workspace", output_workspace + '_NormalisedCovarianceMatrices')
        delete_alg.execute()
        delete_alg.setProperty("Workspace", output_workspace + '_Parameters')
        delete_alg.execute()
        delete_alg.setProperty("Workspace", tmp_fit_name)
        delete_alg.execute()

        conclusion_prog.report('Renaming workspaces')
        # rename workspaces to match user input
        rename_alg = self.createChildAlgorithm("RenameWorkspace")
        if output_workspace + "_Workspaces" != self._fit_group_name:
            rename_alg.setProperty("InputWorkspace",
                                   output_workspace + "_Workspaces")
            rename_alg.setProperty("OutputWorkspace", self._fit_group_name)
            rename_alg.execute()
        if output_workspace != self._parameter_name:
            rename_alg.setProperty("InputWorkspace", output_workspace)
            rename_alg.setProperty("OutputWorkspace", self._parameter_name)
            rename_alg.execute()

        # Create *_Result workspace
        parameter_names = 'A0,Intensity,Tau,Beta'
        conclusion_prog.report('Processing indirect fit parameters')
        pifp_alg = self.createChildAlgorithm("ProcessIndirectFitParameters")
        pifp_alg.setProperty("InputWorkspace", self._parameter_name)
        pifp_alg.setProperty("ColumnX", "axis-1")
        pifp_alg.setProperty("XAxisUnit", "MomentumTransfer")
        pifp_alg.setProperty("ParameterNames", parameter_names)
        pifp_alg.setProperty("OutputWorkspace", self._result_name)
        pifp_alg.execute()
        self._result_ws = pifp_alg.getProperty("OutputWorkspace").value

        mtd.addOrReplace(self._result_name, self._result_ws)

        # Process generated workspaces
        wsnames = mtd[self._fit_group_name].getNames()
        for i, workspace in enumerate(wsnames):
            output_ws = output_workspace + '_Workspace_%d' % i
            rename_alg.setProperty("InputWorkspace", workspace)
            rename_alg.setProperty("OutputWorkspace", output_ws)
            rename_alg.execute()

        conclusion_prog.report('Copying and transfering sample logs')
        self._transfer_sample_logs()

        self.setProperty('OutputParameterWorkspace', self._parameter_name)
        self.setProperty('OutputWorkspaceGroup', self._fit_group_name)
        self.setProperty('OutputResultWorkspace', self._result_ws)
        conclusion_prog.report('Algorithm complete')
Example #9
0
    def PyExec(self):
        from IndirectCommon import (getWSprefix, convertToElasticQ)

        setup_prog = Progress(self, start=0.0, end=0.1, nreports=4)
        self._fit_type = self._fit_type[:-2]
        logger.information('Option: ' + self._fit_type)
        logger.information(self._function)

        setup_prog.report('Cropping workspace')
        tmp_fit_name = "__IqtFit_ws"
        crop_alg = self.createChildAlgorithm("CropWorkspace", enableLogging=False)
        crop_alg.setProperty("InputWorkspace", self._input_ws)
        crop_alg.setProperty("OutputWorkspace", tmp_fit_name)
        crop_alg.setProperty("XMin", self._start_x)
        crop_alg.setProperty("XMax", self._end_x)
        crop_alg.execute()

        num_hist = self._input_ws.getNumberHistograms()
        if self._spec_max is None:
            self._spec_max = num_hist - 1

        # Name stem for generated workspace
        output_workspace = '%sIqtFit_%s_s%d_to_%d' % (getWSprefix(self._input_ws.name()),
                                                      self._fit_type, self._spec_min,
                                                      self._spec_max)

        setup_prog.report('Converting to Histogram')
        convert_to_hist_alg = self.createChildAlgorithm("ConvertToHistogram", enableLogging=False)
        convert_to_hist_alg.setProperty("InputWorkspace", crop_alg.getProperty("OutputWorkspace").value)
        convert_to_hist_alg.setProperty("OutputWorkspace", tmp_fit_name)
        convert_to_hist_alg.execute()
        mtd.addOrReplace(tmp_fit_name, convert_to_hist_alg.getProperty("OutputWorkspace").value)

        setup_prog.report('Convert to Elastic Q')
        convertToElasticQ(tmp_fit_name)

        # Build input string for PlotPeakByLogValue
        input_str = [tmp_fit_name + ',i%d' % i for i in range(self._spec_min, self._spec_max + 1)]
        input_str = ';'.join(input_str)

        fit_prog = Progress(self, start=0.1, end=0.8, nreports=2)
        fit_prog.report('Fitting...')
        ms.PlotPeakByLogValue(Input=input_str,
                              OutputWorkspace=output_workspace,
                              Function=self._function,
                              Minimizer=self._minimizer,
                              MaxIterations=self._max_iterations,
                              StartX=self._start_x,
                              EndX=self._end_x,
                              FitType='Sequential',
                              CreateOutput=True)
        fit_prog.report('Fitting complete')

        conclusion_prog = Progress(self, start=0.8, end=1.0, nreports=5)
        # Remove unused workspaces
        delete_alg = self.createChildAlgorithm("DeleteWorkspace", enableLogging=False)
        delete_alg.setProperty("Workspace", output_workspace + '_NormalisedCovarianceMatrices')
        delete_alg.execute()
        delete_alg.setProperty("Workspace", output_workspace + '_Parameters')
        delete_alg.execute()
        delete_alg.setProperty("Workspace", tmp_fit_name)
        delete_alg.execute()

        conclusion_prog.report('Renaming workspaces')
        # rename workspaces to match user input
        rename_alg = self.createChildAlgorithm("RenameWorkspace", enableLogging=False)
        if output_workspace + "_Workspaces" != self._fit_group_name:
            rename_alg.setProperty("InputWorkspace", output_workspace + "_Workspaces")
            rename_alg.setProperty("OutputWorkspace", self._fit_group_name)
            rename_alg.execute()
        if output_workspace != self._parameter_name:
            rename_alg.setProperty("InputWorkspace", output_workspace)
            rename_alg.setProperty("OutputWorkspace", self._parameter_name)
            rename_alg.execute()

        # Create *_Result workspace
        parameter_names = 'A0,Height,Lifetime,Stretching'
        conclusion_prog.report('Processing indirect fit parameters')
        pifp_alg = self.createChildAlgorithm("ProcessIndirectFitParameters")
        pifp_alg.setProperty("InputWorkspace", self._parameter_name)
        pifp_alg.setProperty("ColumnX", "axis-1")
        pifp_alg.setProperty("XAxisUnit", "MomentumTransfer")
        pifp_alg.setProperty("ParameterNames", parameter_names)
        pifp_alg.setProperty("OutputWorkspace", self._result_name)
        pifp_alg.execute()
        self._result_ws = pifp_alg.getProperty("OutputWorkspace").value

        mtd.addOrReplace(self._result_name, self._result_ws)

        # Process generated workspaces
        wsnames = mtd[self._fit_group_name].getNames()
        for i, workspace in enumerate(wsnames):
            output_ws = output_workspace + '_Workspace_%d' % i
            rename_alg.setProperty("InputWorkspace", workspace)
            rename_alg.setProperty("OutputWorkspace", output_ws)
            rename_alg.execute()

        conclusion_prog.report('Copying and transferring sample logs')
        self._transfer_sample_logs()

        self.setProperty('OutputParameterWorkspace', self._parameter_name)
        self.setProperty('OutputWorkspaceGroup', self._fit_group_name)
        self.setProperty('OutputResultWorkspace', self._result_ws)
        conclusion_prog.report('Algorithm complete')