[SciPy-User] Asymmetric peak fitting

Matt Newville newville at cars.uchicago.edu
Wed Mar 18 21:16:26 EDT 2015


Pawel,

On Wed, Mar 18, 2015 at 10:06 AM, Paweł Kwaśniewski <pawel.kw at gmail.com>
wrote:

> Hi All,
>
> I'm currently trying to fit some experimental data in the form of
> asymmetric peaks. In principle it's difficult to find a distribution
> describing this kind of data. My goal is to get the full width half maximum
> of the peak and the peak position. I tried to look for some ready solutions
> within scipy but could not find any. I did find a nice paper though:
>
> http://arxiv.org/abs/0711.4449
>
> Since it's not so trivial (at least not for me) to implement this, I'd
> like to ask if anyone in the community has already done this (or something
> similar) and would like to share the code.
>
> Cheers,
>
> Pawel Kwasniewski
>

You might find the lmfit module (http://lmfit.github.io/lmfit-py/) useful.
This is a module for least-squares minimization and curve-fitting, built on
top of scipy.optimize.  It includes several built-in Models, a few
representing asymmetric peaks such as an exponentially damped Gaussian (
http://lmfit.github.io/lmfit-py/builtin_models.html#exponentialgaussianmodel).
A quick look at the paper you referenced suggests this function might be
sufficient, but if this or one of the other built-in Models isn't exactly
what you're looking forward, it's very easy to make a new Model class from
a Python function that calculates and returns the model function.  Lmfit
Models can also be added  or multiplied together to make composite models
(say, Gaussian + Step + Quadratic), and allow you to place bounds and/or
constraints on any of the Parameters in the fit.

Though there are many features you can use to set up models and their
parameters, using these models (either built-in or one that you define
yourself) for curve-fitting data is pretty straightforward.  See
http://lmfit.github.io/lmfit-py/builtin_models.html#example-1-fit-peaked-data-to-gaussian-lorentzian-and-voigt-profiles
for a simple example.   That example uses symmetric peaks, but the use of
any Model for curve-fitting is basically the same.

Hope that helps,

--Matt Newville
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20150318/3e972c8e/attachment.html>


More information about the SciPy-User mailing list