From f284e15a5705d13e62706317f7e47f0e9b3fac7f Mon Sep 17 00:00:00 2001 From: Ansgar Wehrhahn <31626864+AWehrhahn@users.noreply.github.com> Date: Wed, 2 Jun 2021 17:32:24 +0200 Subject: [PATCH] improved continuum fit --- src/pysme/continuum_and_radial_velocity.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/pysme/continuum_and_radial_velocity.py b/src/pysme/continuum_and_radial_velocity.py index 423c92d8..b03503e7 100644 --- a/src/pysme/continuum_and_radial_velocity.py +++ b/src/pysme/continuum_and_radial_velocity.py @@ -676,12 +676,11 @@ def cont_fit(sme, segment, x_syn, y_syn, rvel=0, only_mask=False): deg = sme.cscale_degree p0 = sme.cscale[segment] - func = lambda x, *p: yp * np.polyval(p, x) + func = lambda x, *p: (yp * np.polyval(p, xs) - y) / u try: - popt, pcov = curve_fit( - func, xs, y, sigma=u, p0=p0, loss="soft_l1", method="trf", xtol=None - ) - except RuntimeError: + res = least_squares(func, x0=p0, loss="soft_l1", method="trf", xtol=None) + popt = res.x + except RuntimeError as ex: logger.warning("Could not determine the continuum") popt = p0 # popt = res.x