From 82fb2346f791f5e979474f9ad19d3c8476cce769 Mon Sep 17 00:00:00 2001 From: Matthew Newville Date: Wed, 10 Jul 2024 06:47:48 -0500 Subject: [PATCH] automatically coerce coerce coefficients for SV smoothing --- larch/math/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/larch/math/utils.py b/larch/math/utils.py index a3f6b0ae3..be6e91368 100644 --- a/larch/math/utils.py +++ b/larch/math/utils.py @@ -409,11 +409,11 @@ def savitzky_golay(y, window_size, order, deriv=0): window_size = abs(int(window_size)) order = abs(int(order)) except ValueError: - raise ValueError("window_size and order have to be of type int") - if window_size % 2 != 1 or window_size < 1: - raise TypeError("window_size size must be a positive odd number") + raise ValueError("window_size and order must be integers") if window_size < order + 2: - raise TypeError("window_size is too small for the polynomials order") + window_size = order + 3 + if window_size % 2 != 1 or window_size < 1: + window_size = window_size + 1 order_range = range(order+1) half_window = (window_size -1) // 2 # precompute coefficients