Skip to content
Snippets Groups Projects
Commit e629fe81 authored by Peter Lünenschloß's avatar Peter Lünenschloß
Browse files

fixed center index bug for polynomial fits to irregularly sampled data

parent b8712bce
No related branches found
No related tags found
3 merge requests!685Release 2.4,!684Release 2.4,!631fixed center index bug for polynomial fits to irregularly sampled data
......@@ -31,6 +31,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
- python 3.7 support
### Fixed
- Error for interpolations with limits set to be greater than 2 (`interpolateNANs`)
- Error when fitting polynomials to irregularly sampled data (`fitPolynomial`)
## [2.2.1](https://git.ufz.de/rdm-software/saqc/-/tags/v2.2.1) - 2022-10-29
[List of commits](https://git.ufz.de/rdm-software/saqc/-/compare/v2.2.0...v2.2.1)
......
......@@ -180,31 +180,14 @@ def _fitPolynomial(
"sample series."
)
# get interval centers
centers = (
to_fit.rolling(
pd.Timedelta(window) / 2, closed="both", min_periods=min_periods
).count()
).floor()
centers = to_fit.rolling(
pd.Timedelta(window) / 2, closed="both", min_periods=min_periods
).count()
centers = centers.drop(centers[centers.isna()].index)
centers = centers.astype(int)
fitted = to_fit.rolling(
pd.Timedelta(window), closed="both", min_periods=min_periods
pd.Timedelta(window), closed="both", min_periods=min_periods, center=True
).apply(polyRollerIrregular, args=(centers, order))
def center_func(x, y=centers):
pos = x.index[int(len(x) - y[x.index[-1]])]
return y.index.get_loc(pos)
centers_iloc = (
centers.rolling(window, closed="both")
.apply(center_func, raw=False)
.astype(int)
)
temp = fitted.copy()
for k in centers_iloc.iteritems():
fitted.iloc[k[1]] = temp[k[0]]
fitted[fitted.index[0] : fitted.index[centers_iloc[0]]] = np.nan
fitted[fitted.index[centers_iloc[-1]] : fitted.index[-1]] = np.nan
else:
if isinstance(window, str):
window = pd.Timedelta(window) // regular
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment