import matplotlib.pyplot as plt
import numpy as np
from spectractor.tools import gauss, compute_fwhm
from spectractor.extractor.psf import MoffatGauss
x = np.arange(0, 100, 1)
p = [2,40,40,4,2,-0.4,1,10]
psf = MoffatGauss(p)
fwhm, half, center, a, b = compute_fwhm(x, psf.evaluate(x), full_output=True)
plt.figure()
plt.plot(x, psf.evaluate(x, p), label="function")
plt.axvline(center, color="gray", label="center")
plt.axvline(a, color="k", label="edges at half max")
plt.axvline(b, color="k", label="edges at half max")
plt.axhline(half, color="r", label="half max")
plt.legend()
plt.title(f"FWHM={fwhm:.3f}")
plt.xlabel("x")
plt.ylabel("y")
plt.show()