Ticket #7741 (assigned)
Python fit function attributes cannot be set from fit browser
Reported by: | Martyn Gigg | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | Backlog |
Component: | Framework | Keywords: | |
Cc: | Blocked By: | ||
Blocking: | Tester: |
Description (last modified by Martyn Gigg) (diff)
I've written a Python function with Attributes as well as parameters. I can select it in the Fit Function pane and the attributes are listed (first) and initialised to the default values specified in the code. If I then change the numbers in the pane, the function does not vary as expected but keeps the initial values of the attributes. Even Fitting, changing the parameters manually, or removing and adding the Guess curve does not prompt it to look again at the attributes.
Instead, if I call Fit(...) from the Python window I can initialise the Attributes to any values I want and it all seems to work OK.
James Lord. (Mantid 2.6)
Simplified code below, based on the examples:
class AttributeExample(IFunction1D): def init(self): self.declareParameter("Amplitude",0.2) self.declareParameter("Baseline",0.1) self.declareAttribute("Frequency",0.26) self.declareAttribute("Sine",False) def setAttributeValue(self,name,value): if name == "Frequency": self._freq = value if name == "Sine": self._sine = value def function1D(self,xvals): ampl=self.getParameterValue("Amplitude") base=self.getParameterValue("Baseline") if(self._sine): ybins=numpy.sin(xvals*self._freq*2.0*math.pi)*ampl+base else: ybins=numpy.cos(xvals*self._freq*2.0*math.pi)*ampl+base return ybins FunctionFactory.subscribe(AttributeExample)