Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SaQC
Manage
Activity
Members
Labels
Plan
Issues
36
Issue boards
Milestones
Wiki
Code
Merge requests
8
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rdm-software
SaQC
Commits
f6b2c2a3
Commit
f6b2c2a3
authored
2 years ago
by
Peter Lünenschloß
Browse files
Options
Downloads
Patches
Plain Diff
black
parent
39102bb3
No related branches found
No related tags found
1 merge request
!600
Inter limit fix
Pipeline
#143701
failed with stages
in 1 minute and 3 seconds
This commit is part of merge request
!600
. Comments created here will be created in the context of that merge request.
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
saqc/funcs/interpolation.py
+2
-2
2 additions, 2 deletions
saqc/funcs/interpolation.py
saqc/lib/ts_operators.py
+33
-13
33 additions, 13 deletions
saqc/lib/ts_operators.py
with
35 additions
and
15 deletions
saqc/funcs/interpolation.py
+
2
−
2
Edit
View file @
f6b2c2a3
...
...
@@ -144,7 +144,7 @@ class InterpolationMixin:
method
:
_SUPPORTED_METHODS
,
order
:
int
=
2
,
limit
:
int
|
None
=
None
,
extrapolate
:
Literal
[
'
forward
'
,
'
backward
'
,
'
both
'
]
=
None
,
extrapolate
:
Literal
[
"
forward
"
,
"
backward
"
,
"
both
"
]
=
None
,
flag
:
float
=
UNFLAGGED
,
**
kwargs
,
)
->
"
SaQC
"
:
...
...
@@ -187,7 +187,7 @@ class InterpolationMixin:
method
,
order
=
order
,
gap_limit
=
limit
,
extrapolate
=
extrapolate
extrapolate
=
extrapolate
,
)
interpolated
=
self
.
_data
[
field
].
isna
()
&
inter_data
.
notna
()
...
...
This diff is collapsed.
Click to expand it.
saqc/lib/ts_operators.py
+
33
−
13
Edit
View file @
f6b2c2a3
...
...
@@ -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
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
,
'
piecewise_polynomial
'
:
2
,
'
pchip
'
:
2
,
'
akima
'
:
2
,
'
cubicspline
'
:
2
}
min_vals_dict
=
{
"
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
)
if
(
x
.
size
<
3
)
|
(
x
.
count
()
<
min_vals
):
return
x
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
(
data
,
method
,
order
=
2
,
gap_limit
=
2
,
extrapolate
=
None
):
def
interpolateNANs
(
data
,
method
,
order
=
2
,
gap_limit
=
2
,
extrapolate
=
None
):
"""
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
...
...
@@ -338,7 +353,9 @@ def interpolateNANs(
gap_mask
=
gap_mask
&
gap_mask
.
shift
(
-
1
,
fill_value
=
True
)
else
:
# 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
pre_index
=
data
.
index
...
...
@@ -350,7 +367,12 @@ def interpolateNANs(
if
method
in
[
"
linear
"
,
"
time
"
]:
# 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:
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
:
# 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(
"
order
"
:
order
,
"
method
"
:
method
,
"
limit_area
"
:
limit_area
,
"
limit_direction
"
:
extrapolate
"
limit_direction
"
:
extrapolate
,
},
)
# finally reinsert the dropped data gaps
...
...
@@ -612,6 +634,4 @@ def linearInterpolation(data, inter_limit=2):
def
polynomialInterpolation
(
data
,
inter_limit
=
2
,
inter_order
=
2
):
return
interpolateNANs
(
data
,
"
polynomial
"
,
gap_limit
=
inter_limit
,
order
=
inter_order
)
return
interpolateNANs
(
data
,
"
polynomial
"
,
gap_limit
=
inter_limit
,
order
=
inter_order
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment