Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Atan and Erf baseline models for pre-edge peak fitting #558

Open
maurov opened this issue Feb 21, 2025 · 4 comments
Open

Implement Atan and Erf baseline models for pre-edge peak fitting #558

maurov opened this issue Feb 21, 2025 · 4 comments
Milestone

Comments

@maurov
Copy link
Member

maurov commented Feb 21, 2025

@newville I usually get a request for having an arctangent-like baseline model for the pre-edge peak fitting in Larix. I think this is justified for tender X-ray energy range, light-elements K-edges (like Sulphur) or 4d transition metals. Furthermore, for HERFD XAS is useful having an error function (erf) baseline.

Here an example of how I successfully define and use such baselines in Fityk:

define Erf(step=0.5, e0=6550, width=1) = step*(erf((x-e0)/width)+1)
define Atan(step=1, e0=6545, width=1) = step*(atan((x-e0)/width)/pi+0.5)

The example above is given for Mn K-edge, but the step and e0 can be easily guessed automatically for the input XAS spectrum. width can stay 1 by default.

Since you are the lmfit and Larix master, would it be possible for you to to add the above functions to the pre-edge peaks panel in Larix? Otherwise I will implement it by myself, even if it will require me more time to get into the Wx technicalities.

Below I paste an example for S K-edge done, respectively, with Fityk using arctangent and Larix using constant+Lorentzian as baseline

Image

Image

@newville
Copy link
Member

@maurov -- yes, we could add an arc-tan and error function for baselines. The "Other Models" dropdown list does have arc-tan and error-function step functions.

So... perhaps the best thing to do is to have a separate "General Peak Fitting" Tab that doesn't do the sort of weird "pre-edge peak baseline" thing, and just assumes: Fit this X/Y or E/Mu curve as a sum of model components.

@newville
Copy link
Member

@maurov Constant + ArcTan Step and Constant + Error Function Step and now available as baseline models.

@maurov
Copy link
Member Author

maurov commented Feb 24, 2025

@newville thanks for your comments and quickly implementing this.

I think that the Pre-edge Peaks tab could be renamed to Peak fitting. I do not find weird the "baseline fit workflow", but very helpful for non experts. In most peak fitting there is a baseline to fit first and add components later. What I would suggest changing in this workflow is too fix the fitted baseline parameters, such that are not changed when one clicks on "fit current group".

By the way, I found a bug: when changing from the "XAS Normalization" tab to the "Pre-edge Peaks" tab, the "Fit X/Energy Range" is changed back to default. The expected behavior is that this energy range, when manually changed, it stay fixed (should be saved also in the session file).

Furthermore, we should also extend the documentation of the peak fitting feature of Larix.

Going back to the ArcTan/ErrorFunction Step models, I gave a try and I realized that the definition of StepModel in Lmfit is too steep for XAS. I was not able to get a good fit of the data above with such baseline models. Even by strongly changing the initial guess values by hand, they converge to very steep results. Here a comparison of the two behaviours:

Larix Fityk
Image Image

IMHO, the definition I gave above works much better and I would propose implementing it in larch. What do you think?

@maurov maurov added this to the 2025.2.x milestone Feb 24, 2025
@newville
Copy link
Member

@maurov Thanks -- I'll look into the ranges when switching from XAS Normalization to Pre-edge Peak.

I'm not sure what is happening there for the arc-tangent fit. It should completely ignore the data in the "Baseline Skip Range" (between the light gray lines).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants