silx icon indicating copy to clipboard operation
silx copied to clipboard

Adding a custom theory to the FitManager

Open alexmarie78 opened this issue 4 years ago • 3 comments

Good afternoon.

I am using a FitWidget, and I would like to add a pearson7 theory to the FitWidget with the FitManager. Although my pearson7 function seems to be fine, when I try to estimate a peak in the application, I get only 1 for every parameter, and when I fit I get this display :

Capture d’écran du 2021-03-30 12-54-23

I am adding the theory to the FitWidget like mentioned in the tutorial :

fit = FitManager()
fit.loadtheories(fittheories)
fit.addtheory("pearson7", function=pearson7, parameters=["backgr", "slopeLin", "amplitude", "center", "fwhmLike", "exposant"])

window = FitWidget(parent=self.plot, fitmngr=fit)

By the way, I tried with lmfit.lineshapes.pearson7 function, and with a custom one :

def pearson7(x, backgr, slopeLin, amplitude, center, fwhmLike, exposant):
    return backgr + slopeLin * x + amplitude * (1 + ((x-center) / fwhmLike) ** 2.0) ** (-exposant)

But both gave me the same result, that you can see up above. Is there something wrong with my FitManager's approach ?

alexmarie78 avatar Mar 30 '21 11:03 alexmarie78

I understood I was loading a theory in a dirty way, so I added this to the addtheory function :

 fit.addtheory("pearson7", function=pearson7bg,
                      parameters=["backgr", "slopeLin", "a", "amplitude", "center", "fwhmLike", "exposant"],
                      estimate=pearson7,
                      configure=FitTheories().configure)

It still does not work but I know the errors come from my estimate function.

alexmarie78 avatar Apr 02 '21 08:04 alexmarie78

I'm not familiar with silx fit, but the following doesn't sounds correct, you have no way to get the configured values: configure=FitTheories().configure)

t20100 avatar Apr 07 '21 12:04 t20100

The simplest is to pass None as configure. The interface should request the user to fill the estimation by hand in that case.

vasole avatar Apr 07 '21 12:04 vasole

I'm closing this since discussion is stalled and there is no clear issue to fix. Please re-open to discuss further.

t20100 avatar Sep 09 '22 09:09 t20100