Commit c199ff62 authored by whooie's avatar whooie
Browse files

account for possible angling in lmfit_gaussian

parent 28a28a9d
......@@ -299,8 +299,13 @@ def lmfit_gaussian(data, dA, k=None):
sx = params["sx"]
y0 = params["y0"]
sy = params["sy"]
th = params["theta"]
B = params["B"]
return A * np.exp(-((_X - x0) / sx)**2 - ((_Y - y0) / sy)**2) + B
_Xrel = _X - x0
_Yrel = _Y - y0
_Xrot = np.cos(th) * _Xrel + np.sin(th) * _Yrel
_Yrot = -np.sin(th) * _Xrel + np.cos(th) * _Yrel
return A * np.exp(-(_Xrot / sx)**2 - (_Yrot / sy)**2) + B
def residual(params: lmfit.Parameters):
m = model(params)
......@@ -312,6 +317,7 @@ def lmfit_gaussian(data, dA, k=None):
params.add("sx", value=(x.max() - x.min()) / 12)
params.add("y0", value=y0)
params.add("sy", value=(y.max() - y.min()) / 12)
params.add("theta", value=0.0, min=0.0, max=np.pi / 2)
params.add("B", value=data.mean())
fit = lmfit.minimize(residual, params)
if not fit.success:
......@@ -331,5 +337,6 @@ def lmfit_gaussian(data, dA, k=None):
print(fit.params["sx"])
print(fit.params["y0"])
print(fit.params["sy"])
print(fit.params["theta"])
return float(fit.params["sx"]), float(fit.params["sy"])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment