Ticket #7741 (assigned)

Opened 7 years ago

Last modified 5 years ago

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)

Change History

comment:1 Changed 7 years ago by Martyn Gigg

  • Description modified (diff)

comment:2 Changed 7 years ago by Nick Draper

  • Status changed from new to assigned

Bulk move to assigned at the introduction of the triage step

comment:3 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 8586

Note: See TracTickets for help on using tickets.