We fairly commonly need to fit 2D peaks, such a Lorentzian or Lorentzian squared or Gaussian peaks.
This can be done in lmfit, but my experience is that people often find it pretty hard.
If so, I'd further prefer to add a function and model with form similar to that copied below. Would a PR on this topic be welcomed?
def twodpeak(x, y, height=1., centerx=0., centery=0., sigmax=1., sigmay=1.,
rotation=0., power=1., form='gaussian'):
"""Return a two dimensional gaussian or lorentzian raised to a power.
``form`` sets the functional form
form='gaussian' (default)
=height*exp(-R**2)**power
form='lorentzian' (default)
=height*(1/(1+R**2))**power
Where radius, ``R`` is defined in terms of ``centerx`` and ``centery``
with widths ``sigmax`` and ``sigmay``. The peak can be rotated by choosing
the value of ``rotation`` in radians.
xp = (x - centerx)*cos(rotation) - (y - centery)*sin(rotation)
yp = (x - centerx)*sin(rotation) + (y - centery)*cos(rotation)
R = (xp/sigmax)**2 + (yp/sigmay)**2
Intensity is defined by ``height`` i.e. the value at ``centerx``=``centery``=0
"""
xp = (x - centerx)*cos(rotation) - (y - centery)*sin(rotation)
yp = (x - centerx)*sin(rotation) + (y - centery)*cos(rotation)
R = (xp/sigmax)**2 + (yp/sigmay)**2
if form.lower() == 'gaussian':
return height*exp(-R**2)**power
elif form.lower() == 'lorentzian':
return height*(1/(1+R**2))**power
else:
msg = ("Invalid value '{}' for argument 'form'".format(form)
+ "; should be 'gaussian' or 'lorentzian'")
raise ValueError(msg)