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
e650f8b6
Commit
e650f8b6
authored
5 years ago
by
Bert Palm
🎇
Browse files
Options
Downloads
Patches
Plain Diff
rewrote flagConstant to make it easier, faster, and fix bugs
parent
979b9ae2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!3
rewrote flagConstant to make it easier, faster, and fix bugs
Pipeline
#2378
passed with stage
in 8 minutes and 29 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
saqc/__main__.py
+1
-0
1 addition, 0 deletions
saqc/__main__.py
saqc/funcs/constants_detection.py
+21
-11
21 additions, 11 deletions
saqc/funcs/constants_detection.py
with
22 additions
and
11 deletions
saqc/__main__.py
+
1
−
0
View file @
e650f8b6
...
...
@@ -31,6 +31,7 @@ def main(config, data, flagger, outfile, nodata, fail):
nodata
=
nodata
,
error_policy
=
"
raise
"
if
fail
else
"
warn
"
,
)
[
cols_out
].
to_csv
(
outfile
,
header
=
True
,
index
=
True
)
if
outfile
:
flags
=
flagger_result
.
getFlags
()
...
...
This diff is collapsed.
Click to expand it.
saqc/funcs/constants_detection.py
+
21
−
11
View file @
e650f8b6
...
...
@@ -11,21 +11,31 @@ from saqc.lib.tools import valueRange, slidingWindowIndices, retrieveTrustworthy
@register
(
"
constant
"
)
def
flagConstant
(
data
,
field
,
flagger
,
thresh
,
window
,
**
kwargs
):
"""
Flag values are (semi-)constant.
:param data: dataframe
:param field: column in data
:param flagger: saqc flagger obj
:param thresh: the difference between two values must be below that
:param window: sliding window
"""
d
=
data
[
field
]
# find all constant values in forward search
r
=
d
.
rolling
(
window
=
window
)
mask
=
(
r
.
max
()
-
r
.
min
())
<=
thresh
window
=
pd
.
tseries
.
frequencies
.
to_offset
(
window
)
# backward rolling for offset windows hack
bw
=
mask
[::
-
1
].
copy
()
bw
.
index
=
bw
.
index
.
max
()
-
bw
.
index
col
=
data
[
field
]
index
=
col
.
index
flagger_mask
=
pd
.
Series
(
data
=
np
.
zeros_like
(
col
),
index
=
index
,
name
=
field
,
dtype
=
bool
)
# propagate the mask(!), backwards
bwmask
=
bw
.
rolling
(
window
=
window
).
sum
()
>
0
for
srs
in
groupConsecutives
(
col
.
diff
().
abs
().
le
(
thresh
)):
if
np
.
all
(
srs
):
start
=
index
[
index
.
get_loc
(
srs
.
index
[
0
])
-
1
]
stop
=
srs
.
index
[
-
1
]
if
stop
-
start
>=
window
:
flagger_mask
[
start
:
stop
]
=
True
mask
|=
bwmask
[::
-
1
].
values
flagger
=
flagger
.
setFlags
(
field
,
flagger_
mask
,
**
kwargs
)
flagger
=
flagger
.
setFlags
(
field
,
mask
,
**
kwargs
)
return
data
,
flagger
...
...
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