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

black

parent 39102bb3
No related branches found
No related tags found
1 merge request!600Inter limit fix
Pipeline #143701 failed with stages
in 1 minute and 3 seconds
...@@ -144,7 +144,7 @@ class InterpolationMixin: ...@@ -144,7 +144,7 @@ class InterpolationMixin:
method: _SUPPORTED_METHODS, method: _SUPPORTED_METHODS,
order: int = 2, order: int = 2,
limit: int | None = None, limit: int | None = None,
extrapolate: Literal['forward', 'backward', 'both'] = None, extrapolate: Literal["forward", "backward", "both"] = None,
flag: float = UNFLAGGED, flag: float = UNFLAGGED,
**kwargs, **kwargs,
) -> "SaQC": ) -> "SaQC":
...@@ -187,7 +187,7 @@ class InterpolationMixin: ...@@ -187,7 +187,7 @@ class InterpolationMixin:
method, method,
order=order, order=order,
gap_limit=limit, gap_limit=limit,
extrapolate=extrapolate extrapolate=extrapolate,
) )
interpolated = self._data[field].isna() & inter_data.notna() interpolated = self._data[field].isna() & inter_data.notna()
......
...@@ -275,25 +275,40 @@ def meanQC(data, max_nan_total=np.inf, max_nan_consec=np.inf): ...@@ -275,25 +275,40 @@ def meanQC(data, max_nan_total=np.inf, max_nan_consec=np.inf):
) )
def _interpolWrapper(x, order=1, method="time", limit_area='inside', limit_direction=None): def _interpolWrapper(
x, order=1, method="time", limit_area="inside", limit_direction=None
):
""" """
Function that automatically modifies the interpolation level or returns uninterpolated Function that automatically modifies the interpolation level or returns uninterpolated
input data if the data configuration breaks the interpolation method at the selected degree. input data if the data configuration breaks the interpolation method at the selected degree.
""" """
min_vals_dict = {'nearest': 2, 'slinear': 2, 'quadratic': 3, 'cubic':4, 'spline':order+1, 'polynomial':order+1, min_vals_dict = {
'piecewise_polynomial': 2, 'pchip': 2, 'akima': 2, 'cubicspline': 2} "nearest": 2,
"slinear": 2,
"quadratic": 3,
"cubic": 4,
"spline": order + 1,
"polynomial": order + 1,
"piecewise_polynomial": 2,
"pchip": 2,
"akima": 2,
"cubicspline": 2,
}
min_vals = min_vals_dict.get(method, 0) min_vals = min_vals_dict.get(method, 0)
if (x.size < 3) | (x.count() < min_vals): if (x.size < 3) | (x.count() < min_vals):
return x return x
else: else:
return x.interpolate(method=method, order=order, limit_area=limit_area, limit_direction=limit_direction) return x.interpolate(
method=method,
order=order,
limit_area=limit_area,
limit_direction=limit_direction,
)
def interpolateNANs( def interpolateNANs(data, method, order=2, gap_limit=2, extrapolate=None):
data, method, order=2, gap_limit=2, extrapolate=None
):
""" """
The function interpolates nan-values (and nan-grids) in timeseries data. It can The function interpolates nan-values (and nan-grids) in timeseries data. It can
be passed all the method keywords from the pd.Series.interpolate method and will be passed all the method keywords from the pd.Series.interpolate method and will
...@@ -338,7 +353,9 @@ def interpolateNANs( ...@@ -338,7 +353,9 @@ def interpolateNANs(
gap_mask = gap_mask & gap_mask.shift(-1, fill_value=True) gap_mask = gap_mask & gap_mask.shift(-1, fill_value=True)
else: else:
# If the gap_size is bigger we make an flip-rolling combo to backpropagate the False values # If the gap_size is bigger we make an flip-rolling combo to backpropagate the False values
gap_mask = ~((~gap_mask[::-1]).rolling(gap_limit, min_periods=0).sum() > 0)[::-1] gap_mask = ~(
(~gap_mask[::-1]).rolling(gap_limit, min_periods=0).sum() > 0
)[::-1]
# memorizing the index for later reindexing # memorizing the index for later reindexing
pre_index = data.index pre_index = data.index
...@@ -350,7 +367,12 @@ def interpolateNANs( ...@@ -350,7 +367,12 @@ def interpolateNANs(
if method in ["linear", "time"]: if method in ["linear", "time"]:
# in the case of linear interpolation, not much can go wrong/break so this conditional branch has efficient # in the case of linear interpolation, not much can go wrong/break so this conditional branch has efficient
# finish by just calling pandas interpolation routine to fill the gaps remaining in the data: # finish by just calling pandas interpolation routine to fill the gaps remaining in the data:
data.interpolate(method=method, inplace=True, limit_area=limit_area, limit_direction=extrapolate) data.interpolate(
method=method,
inplace=True,
limit_area=limit_area,
limit_direction=extrapolate,
)
else: else:
# if the method that is interpolated with, depends on not only the left and right border points of any gap, # if the method that is interpolated with, depends on not only the left and right border points of any gap,
...@@ -365,7 +387,7 @@ def interpolateNANs( ...@@ -365,7 +387,7 @@ def interpolateNANs(
"order": order, "order": order,
"method": method, "method": method,
"limit_area": limit_area, "limit_area": limit_area,
"limit_direction": extrapolate "limit_direction": extrapolate,
}, },
) )
# finally reinsert the dropped data gaps # finally reinsert the dropped data gaps
...@@ -612,6 +634,4 @@ def linearInterpolation(data, inter_limit=2): ...@@ -612,6 +634,4 @@ def linearInterpolation(data, inter_limit=2):
def polynomialInterpolation(data, inter_limit=2, inter_order=2): def polynomialInterpolation(data, inter_limit=2, inter_order=2):
return interpolateNANs( return interpolateNANs(data, "polynomial", gap_limit=inter_limit, order=inter_order)
data, "polynomial", gap_limit=inter_limit, order=inter_order
)
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