def PyExec(self): from IndirectCommon import convertToElasticQ progress_tracker = Progress(self, start=0.05, end=0.95, nreports=2) # Convert sample workspace to elastic Q self._temporary_fit_name = '__fit_ws' self._crop_workspace(self._sample_workspace, self._temporary_fit_name, self._e_min, self._e_max) self._convert_to_histogram(self._temporary_fit_name) convertToElasticQ(self._temporary_fit_name) # Perform fits progress_tracker.report('Fitting 1 peak...') self._fit('1L') progress_tracker.report('Fitting 2 peaks...') self._fit('2L') self._delete_workspace(self._temporary_fit_name) # Appends the chi workspaces and replaces the y labels self._append_chi_squared_workspaces() # Appends the result workspaces and replaces the y labels self._append_result_workspaces()
def PyExec(self): from IndirectCommon import (convertToElasticQ, transposeFitParametersTable) setup_prog = Progress(self, start=0.0, end=0.1, nreports=4) setup_prog.report('generating output name') output_workspace = self._fit_group_name # check if the naming convention used is already correct chopped_name = self._fit_group_name.split('_') if 'WORKSPACE' in chopped_name[-1].upper(): output_workspace = '_'.join(chopped_name[:-1]) option = self._fit_type[:-2] logger.information('Option: ' + option) logger.information('Function: ' + str(self._function)) setup_prog.report('Cropping workspace') # prepare input workspace for fitting tmp_fit_workspace = "__Iqtfit_fit_ws" if self._spec_max is None: crop_alg = self.createChildAlgorithm("CropWorkspace", enableLogging=False) crop_alg.setProperty("InputWorkspace", self._input_ws) crop_alg.setProperty("OutputWorkspace", tmp_fit_workspace) crop_alg.setProperty("XMin", self._start_x) crop_alg.setProperty("XMax", self._end_x) crop_alg.setProperty("StartWorkspaceIndex", self._spec_min) crop_alg.execute() else: crop_alg = self.createChildAlgorithm("CropWorkspace", enableLogging=False) crop_alg.setProperty("InputWorkspace", self._input_ws) crop_alg.setProperty("OutputWorkspace", tmp_fit_workspace) crop_alg.setProperty("XMin", self._start_x) crop_alg.setProperty("XMax", self._end_x) crop_alg.setProperty("StartWorkspaceIndex", self._spec_min) crop_alg.setProperty("EndWorkspaceIndex", self._spec_max) crop_alg.execute() 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_workspace) convert_to_hist_alg.execute() mtd.addOrReplace(tmp_fit_workspace, convert_to_hist_alg.getProperty("OutputWorkspace").value) setup_prog.report('Convert to Elastic Q') convertToElasticQ(tmp_fit_workspace) # fit multi-domain function to workspace fit_prog = Progress(self, start=0.1, end=0.8, nreports=2) multi_domain_func, kwargs = _create_multi_domain_func(self._function, tmp_fit_workspace) fit_prog.report('Fitting...') ms.Fit(Function=multi_domain_func, InputWorkspace=tmp_fit_workspace, WorkspaceIndex=0, Output=output_workspace, CreateOutput=True, Minimizer=self._minimizer, MaxIterations=self._max_iterations, OutputCompositeMembers=self._do_extract_members, **kwargs) fit_prog.report('Fitting complete') conclusion_prog = Progress(self, start=0.8, end=1.0, nreports=5) 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 + "_Parameters" != self._parameter_name: rename_alg.setProperty("InputWorkspace", output_workspace + "_Parameters") rename_alg.setProperty("OutputWorkspace", self._parameter_name) rename_alg.execute() conclusion_prog.report('Transposing parameter table') transposeFitParametersTable(self._parameter_name) # set first column of parameter table to be axis values x_axis = mtd[tmp_fit_workspace].getAxis(1) axis_values = x_axis.extractValues() for i, value in enumerate(axis_values): mtd[self._parameter_name].setCell('axis-1', i, value) # convert parameters to matrix 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() result_workspace = pifp_alg.getProperty("OutputWorkspace").value mtd.addOrReplace(self._result_name, result_workspace) # create and add sample logs sample_logs = {'start_x': self._start_x, 'end_x': self._end_x, 'fit_type': self._fit_type[:-2], 'intensities_constrained': self._intensities_constrained, 'beta_constrained': True} conclusion_prog.report('Copying sample logs') copy_log_alg = self.createChildAlgorithm("CopyLogs", enableLogging=False) copy_log_alg.setProperty("InputWorkspace", self._input_ws) copy_log_alg.setProperty("OutputWorkspace", result_workspace) copy_log_alg.execute() copy_log_alg.setProperty("InputWorkspace", self._input_ws) copy_log_alg.setProperty("OutputWorkspace", self._fit_group_name) copy_log_alg.execute() log_names = [item for item in sample_logs] log_values = [sample_logs[item] for item in sample_logs] conclusion_prog.report('Adding sample logs') add_sample_log_multi = self.createChildAlgorithm("AddSampleLogMultiple", enableLogging=False) add_sample_log_multi.setProperty("Workspace", result_workspace.name()) add_sample_log_multi.setProperty("LogNames", log_names) add_sample_log_multi.setProperty("LogValues", log_values) add_sample_log_multi.execute() add_sample_log_multi.setProperty("Workspace", self._fit_group_name) add_sample_log_multi.setProperty("LogNames", log_names) add_sample_log_multi.setProperty("LogValues", log_values) add_sample_log_multi.execute() delete_alg = self.createChildAlgorithm("DeleteWorkspace", enableLogging=False) delete_alg.setProperty("Workspace", tmp_fit_workspace) delete_alg.execute() if self._do_extract_members: ms.ExtractQENSMembers(InputWorkspace=self._input_ws, ResultWorkspace=self._fit_group_name, OutputWorkspace=self._fit_group_name.rsplit('_', 1)[0] + "_Members") self.setProperty('OutputResultWorkspace', result_workspace) self.setProperty('OutputParameterWorkspace', self._parameter_name) self.setProperty('OutputWorkspaceGroup', self._fit_group_name) conclusion_prog.report('Algorithm complete')
def PyExec(self): from IndirectCommon import (convertToElasticQ, transposeFitParametersTable) setup_prog = Progress(self, start=0.0, end=0.1, nreports=4) setup_prog.report('generating output name') output_workspace = self._fit_group_name # check if the naming convention used is alreay correct chopped_name = self._fit_group_name.split('_') if 'WORKSPACE' in chopped_name[-1].upper(): output_workspace = ('_').join(chopped_name[:-1]) option = self._fit_type[:-2] logger.information('Option: ' + option) logger.information('Function: ' + self._function) setup_prog.report('Cropping workspace') #prepare input workspace for fitting tmp_fit_workspace = "__Iqtfit_fit_ws" if self._spec_max is None: CropWorkspace(InputWorkspace=self._input_ws, OutputWorkspace=tmp_fit_workspace, XMin=self._start_x, XMax=self._end_x, StartWorkspaceIndex=self._spec_min) else: CropWorkspace(InputWorkspace=self._input_ws, OutputWorkspace=tmp_fit_workspace, XMin=self._start_x, XMax=self._end_x, StartWorkspaceIndex=self._spec_min, EndWorkspaceIndex=self._spec_max) setup_prog.report('Converting to Histogram') ConvertToHistogram(tmp_fit_workspace, OutputWorkspace=tmp_fit_workspace) setup_prog.report('Convert to Elastic Q') convertToElasticQ(tmp_fit_workspace) #fit multi-domian functino to workspace fit_prog = Progress(self, start=0.1, end=0.8, nreports=2) multi_domain_func, kwargs = self._create_mutli_domain_func( self._function, tmp_fit_workspace) fit_prog.report('Fitting...') Fit(Function=multi_domain_func, InputWorkspace=tmp_fit_workspace, WorkspaceIndex=0, Output=output_workspace, CreateOutput=True, Minimizer=self._minimizer, MaxIterations=self._max_iterations, **kwargs) fit_prog.report('Fitting complete') conclusion_prog = Progress(self, start=0.8, end=1.0, nreports=5) conclusion_prog.report('Renaming workspaces') # rename workspaces to match user input if output_workspace + "_Workspaces" != self._fit_group_name: RenameWorkspace(InputWorkspace=output_workspace + "_Workspaces", OutputWorkspace=self._fit_group_name) if output_workspace + "_Parameters" != self._parameter_name: RenameWorkspace(InputWorkspace=output_workspace + "_Parameters", OutputWorkspace=self._parameter_name) conclusion_prog.report('Tansposing parameter table') transposeFitParametersTable(self._parameter_name) #set first column of parameter table to be axis values x_axis = mtd[tmp_fit_workspace].getAxis(1) axis_values = x_axis.extractValues() for i, value in enumerate(axis_values): mtd[self._parameter_name].setCell('axis-1', i, value) #convert parameters to matrix workspace parameter_names = 'A0,Intensity,Tau,Beta' conclusion_prog.report('Processing indirect fit parameters') result_workspace = ProcessIndirectFitParameters( InputWorkspace=self._parameter_name, ColumnX="axis-1", XAxisUnit="MomentumTransfer", ParameterNames=parameter_names, OutputWorkspace=self._result_name) # create and add sample logs sample_logs = { 'start_x': self._start_x, 'end_x': self._end_x, 'fit_type': self._fit_type[:-2], 'intensities_constrained': self._intensities_constrained, 'beta_constrained': True } conclusion_prog.report('Copying sample logs') CopyLogs(InputWorkspace=self._input_ws, OutputWorkspace=result_workspace) CopyLogs(InputWorkspace=self._input_ws, OutputWorkspace=self._fit_group_name) log_names = [item for item in sample_logs] log_values = [sample_logs[item] for item in sample_logs] conclusion_prog.report('Adding sample logs') AddSampleLogMultiple(Workspace=result_workspace, LogNames=log_names, LogValues=log_values) AddSampleLogMultiple(Workspace=self._fit_group_name, LogNames=log_names, LogValues=log_values) DeleteWorkspace(tmp_fit_workspace) self.setProperty('OutputResultWorkspace', result_workspace) self.setProperty('OutputParameterWorkspace', self._parameter_name) self.setProperty('OutputWorkspaceGroup', self._fit_group_name) conclusion_prog.report('Algorithm complete')
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')
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')
def PyExec(self): from IndirectCommon import (convertToElasticQ, transposeFitParametersTable) setup_prog = Progress(self, start=0.0, end=0.1, nreports=4) setup_prog.report('generating output name') output_workspace = self._fit_group_name # check if the naming convention used is alreay correct chopped_name = self._fit_group_name.split('_') if 'WORKSPACE' in chopped_name[-1].upper(): output_workspace = ('_').join(chopped_name[:-1]) option = self._fit_type[:-2] logger.information('Option: '+ option) logger.information('Function: '+ self._function) setup_prog.report('Cropping workspace') #prepare input workspace for fitting tmp_fit_workspace = "__Iqtfit_fit_ws" if self._spec_max is None: CropWorkspace(InputWorkspace=self._input_ws, OutputWorkspace=tmp_fit_workspace, XMin=self._start_x, XMax=self._end_x, StartWorkspaceIndex=self._spec_min) else: CropWorkspace(InputWorkspace=self._input_ws, OutputWorkspace=tmp_fit_workspace, XMin=self._start_x, XMax=self._end_x, StartWorkspaceIndex=self._spec_min, EndWorkspaceIndex=self._spec_max) setup_prog.report('Converting to Histogram') ConvertToHistogram(tmp_fit_workspace, OutputWorkspace=tmp_fit_workspace) setup_prog.report('Convert to Elastic Q') convertToElasticQ(tmp_fit_workspace) #fit multi-domian functino to workspace fit_prog = Progress(self, start=0.1, end=0.8, nreports=2) multi_domain_func, kwargs = self._create_mutli_domain_func(self._function, tmp_fit_workspace) fit_prog.report('Fitting...') Fit(Function=multi_domain_func, InputWorkspace=tmp_fit_workspace, WorkspaceIndex=0, Output=output_workspace, CreateOutput=True, Minimizer=self._minimizer, MaxIterations=self._max_iterations, **kwargs) fit_prog.report('Fitting complete') conclusion_prog = Progress(self, start=0.8, end=1.0, nreports=5) conclusion_prog.report('Renaming workspaces') # rename workspaces to match user input if output_workspace + "_Workspaces" != self._fit_group_name: RenameWorkspace(InputWorkspace=output_workspace + "_Workspaces", OutputWorkspace=self._fit_group_name) if output_workspace + "_Parameters" != self._parameter_name: RenameWorkspace(InputWorkspace=output_workspace + "_Parameters", OutputWorkspace=self._parameter_name) conclusion_prog.report('Tansposing parameter table') transposeFitParametersTable(self._parameter_name) #set first column of parameter table to be axis values x_axis = mtd[tmp_fit_workspace].getAxis(1) axis_values = x_axis.extractValues() for i, value in enumerate(axis_values): mtd[self._parameter_name].setCell('axis-1', i, value) #convert parameters to matrix workspace parameter_names = 'A0,Intensity,Tau,Beta' conclusion_prog.report('Processing indirect fit parameters') result_workspace = ProcessIndirectFitParameters(InputWorkspace=self._parameter_name, ColumnX="axis-1", XAxisUnit="MomentumTransfer", ParameterNames=parameter_names, OutputWorkspace=self._result_name) # create and add sample logs sample_logs = {'start_x': self._start_x, 'end_x': self._end_x, 'fit_type': self._fit_type[:-2], 'intensities_constrained': self._intensities_constrained, 'beta_constrained': True} conclusion_prog.report('Copying sample logs') CopyLogs(InputWorkspace=self._input_ws, OutputWorkspace=result_workspace) CopyLogs(InputWorkspace=self._input_ws, OutputWorkspace=self._fit_group_name) log_names = [item for item in sample_logs] log_values = [sample_logs[item] for item in sample_logs] conclusion_prog.report('Adding sample logs') AddSampleLogMultiple(Workspace=result_workspace, LogNames=log_names, LogValues=log_values) AddSampleLogMultiple(Workspace=self._fit_group_name, LogNames=log_names, LogValues=log_values) DeleteWorkspace(tmp_fit_workspace) self.setProperty('OutputResultWorkspace', result_workspace) self.setProperty('OutputParameterWorkspace', self._parameter_name) self.setProperty('OutputWorkspaceGroup', self._fit_group_name) conclusion_prog.report('Algorithm complete')