def test_direct_evaluation(self): l0 = FunctionWrapper( "LinearBackground", A0=0, A1=2) l1 = FunctionWrapper( "LinearBackground", A0=5, A1=-1) ws = CreateWorkspace(DataX=[0,1,2,3,4], DataY=[5,5,5,5]) c = CompositeFunctionWrapper(l0, l1) cws = EvaluateFunction(c,"ws", OutputWorkspace='out') cvals = cws.readY(1) self.assertAlmostEqual(cvals[0], 5.5) self.assertAlmostEqual(cvals[1], 6.5) self.assertAlmostEqual(cvals[2], 7.5) self.assertAlmostEqual(cvals[3], 8.5) p = ProductFunctionWrapper(l0, l1) pws = EvaluateFunction(p,"ws", OutputWorkspace='out') pvals = pws.readY(1) self.assertAlmostEqual(pvals[0], 4.5) self.assertAlmostEqual(pvals[1], 10.5) self.assertAlmostEqual(pvals[2], 12.5) self.assertAlmostEqual(pvals[3], 10.5) sq = Polynomial(attributes={'n': 2}, A0=0, A1=0.0, A2=1.0) sqws = EvaluateFunction(sq,"ws", OutputWorkspace='out') sqvals = sqws.readY(1) self.assertAlmostEqual(sqvals[0], 0.25) self.assertAlmostEqual(sqvals[1], 2.25) self.assertAlmostEqual(sqvals[2], 6.25)
def change_plot_guess(self, plot_guess, parameter_dict): try: fit_function = parameter_dict['Function'] data_ws_name = parameter_dict['InputWorkspace'] except KeyError: return if self.context.workspace_suffix == MUON_ANALYSIS_SUFFIX: guess_ws_name = MUON_ANALYSIS_GUESS_WS elif self.context.workspace_suffix == FREQUENCY_DOMAIN_ANALYSIS_SUFFIX: guess_ws_name = FREQUENCY_DOMAIN_ANALYSIS_GUESS_WS else: guess_ws_name = '__unknown_interface_fitting_guess' # Handle case of function removed if fit_function is None and plot_guess: self.context.fitting_context.notify_plot_guess_changed( plot_guess, None) elif fit_function is None or data_ws_name == '': return else: # evaluate the current function on the workspace if plot_guess: try: EvaluateFunction(InputWorkspace=data_ws_name, Function=fit_function, StartX=parameter_dict['StartX'], EndX=parameter_dict['EndX'], OutputWorkspace=guess_ws_name) except RuntimeError: mantid.logger.error('Could not evaluate the function.') return if AnalysisDataService.doesExist(guess_ws_name): self.context.fitting_context.notify_plot_guess_changed( plot_guess, guess_ws_name)
def evaluate_plot_guess(self, workspace_names: str, plot_guess: bool, index: int): fit_function, data_ws_name = self._get_guess_parameters( workspace_names, index) if not data_ws_name: return if self.context.workspace_suffix == MUON_ANALYSIS_SUFFIX: guess_ws_name = MUON_ANALYSIS_GUESS_WS + data_ws_name elif self.context.workspace_suffix == FREQUENCY_DOMAIN_ANALYSIS_SUFFIX: guess_ws_name = FREQUENCY_DOMAIN_ANALYSIS_GUESS_WS + data_ws_name else: guess_ws_name = '__unknown_interface_fitting_guess' # Handle case of function removed if fit_function is None and plot_guess: self.context.fitting_context.notify_plot_guess_changed( plot_guess, None) elif fit_function is None or not workspace_names: return else: # evaluate the current function on the workspace if plot_guess: try: EvaluateFunction(InputWorkspace=data_ws_name, Function=fit_function, StartX=self.fitting_options["startX"], EndX=self.fitting_options["endX"], OutputWorkspace=guess_ws_name) except RuntimeError: mantid.logger.error('Could not evaluate the function.') return return guess_ws_name
def test_arithmetic(self): l0 = FunctionWrapper( "LinearBackground", A0=0, A1=2) l1 = FunctionWrapper( "LinearBackground", A0=5, A1=-1) ws = CreateWorkspace(DataX=[0,1], DataY=[5]) c = CompositeFunctionWrapper(l0, l1) p = ProductFunctionWrapper(l0, l1) s1 = c + p s1ws = EvaluateFunction(s1,"ws", OutputWorkspace='out') s1vals = s1ws.readY(1) self.assertAlmostEqual(s1vals[0], 10.0) s2 = p + c s2ws = EvaluateFunction(s2,"ws", OutputWorkspace='out') s2vals = s2ws.readY(1) self.assertAlmostEqual(s2vals[0], 10.0)
def update_plot_guess(self, fit_function, workspace_name): if self.context.workspace_suffix == MUON_ANALYSIS_SUFFIX: guess_ws_name = MUON_ANALYSIS_GUESS_WS elif self.context.workspace_suffix == FREQUENCY_DOMAIN_ANALYSIS_SUFFIX: guess_ws_name = FREQUENCY_DOMAIN_ANALYSIS_GUESS_WS else: guess_ws_name = '__unknown_interface_fitting_guess' try: EvaluateFunction(InputWorkspace=workspace_name, Function=fit_function, StartX=self.startX, EndX=self.endX, OutputWorkspace=guess_ws_name) except RuntimeError: mantid.logger.error('Could not evaluate the function.') return if AnalysisDataService.doesExist(guess_ws_name): self.context.fitting_context.notify_plot_guess_changed(True, guess_ws_name)