Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SaQC
Manage
Activity
Members
Labels
Plan
Issues
35
Issue boards
Milestones
Wiki
Code
Merge requests
7
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
6ae582ff
Commit
6ae582ff
authored
3 years ago
by
Peter Lünenschloß
Browse files
Options
Downloads
Patches
Plain Diff
filterAdde to lib.ts_operators
parent
df2bb0a4
No related branches found
No related tags found
1 merge request
!256
Filter funcs
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
saqc/lib/ts_operators.py
+30
-0
30 additions, 0 deletions
saqc/lib/ts_operators.py
with
30 additions
and
0 deletions
saqc/lib/ts_operators.py
+
30
−
0
View file @
6ae582ff
...
...
@@ -12,6 +12,7 @@ import numpy as np
import
numba
as
nb
from
sklearn.neighbors
import
NearestNeighbors
from
scipy.stats
import
iqr
,
median_abs_deviation
from
scipy.signal
import
filtfilt
,
butter
import
numpy.polynomial.polynomial
as
poly
logger
=
logging
.
getLogger
(
"
SaQC
"
)
...
...
@@ -328,6 +329,35 @@ def shift2Freq(data: Union[pd.Series, pd.DataFrame], method: str, freq: str, fil
return
data
.
reindex
(
target_ind
,
method
=
direction
,
tolerance
=
tolerance
,
fill_value
=
fill_value
)
def
butterFilter
(
x
,
cut_off_freq
,
nyq_freq
=
0.5
,
filter_order
=
2
,
fill_method
=
'
linear
'
,
filter_type
=
'
low
'
):
"""
Applies butter filter.
X is expected to be regularly sampled.
Parameters
----------
x: pd.Series
input timeseries
cut_off_freq: float
The cutoff frequencie. Relates to multiples of the sampling freq
nyq_freq: float
The niquist frequencie. relates to multiples if the sampling rate
fill_method: str
Any method keword, accepted by pandas.Series.interpolate.
Returns
-------
"""
na_mask
=
x
.
isna
()
x
=
x
.
interpolate
(
fill_method
).
interpolate
(
'
ffill
'
).
interpolate
(
'
bfill
'
)
b
,
a
=
butter
(
N
=
filter_order
,
Wn
=
cut_off_freq
/
nyq_freq
,
btype
=
filter_type
)
y
=
pd
.
Series
(
filtfilt
(
b
,
a
,
x
),
x
.
index
,
name
=
x
.
name
)
y
[
na_mask
]
=
np
.
nan
return
y
@nb.njit
def
_coeffMat
(
x
,
deg
):
# helper function to construct numba-compatible polynomial fit function
...
...
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