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
92f05333
Commit
92f05333
authored
5 years ago
by
Peter Lünenschloß
Browse files
Options
Downloads
Patches
Plain Diff
fixed the try-to-access-flags-as-Dataframe-while-its-a-series bug
parent
26c1649c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
saqc/funcs/functions.py
+18
-6
18 additions, 6 deletions
saqc/funcs/functions.py
with
18 additions
and
6 deletions
saqc/funcs/functions.py
+
18
−
6
View file @
92f05333
...
...
@@ -395,7 +395,10 @@ def flagSoilMoistureBySpikeDetection(data, flags, field, flagger, filter_window_
spikes
[
spike
]
=
False
spikes
=
spikes
[
spikes
==
True
]
flags
.
loc
[
spikes
.
index
,
field
]
=
flagger
.
setFlag
(
flags
.
loc
[
spikes
.
index
,
field
],
**
kwargs
)
if
isinstance
(
flags
,
pd
.
Series
):
flags
.
loc
[
spikes
.
index
,
field
]
=
flagger
.
setFlag
(
flags
.
loc
[
spikes
.
index
,
field
],
**
kwargs
)
else
:
flags
.
loc
[
spikes
.
index
]
=
flagger
.
setFlag
(
flags
.
loc
[
spikes
.
index
],
**
kwargs
)
return
data
,
flags
...
...
@@ -490,14 +493,18 @@ def flagSoilMoistureByBreakDetection(data, flags, field, flagger, filter_window_
breaks
[
brake
]
=
False
breaks
=
breaks
[
breaks
==
True
]
flags
.
loc
[
breaks
.
index
,
field
]
=
flagger
.
setFlag
(
flags
.
loc
[
breaks
.
index
,
field
],
**
kwargs
)
if
isinstance
(
flags
,
pd
,
Series
):
flags
.
loc
[
breaks
.
index
]
=
flagger
.
setFlag
(
flags
.
loc
[
breaks
.
index
],
**
kwargs
)
else
:
flags
.
loc
[
breaks
.
index
,
field
]
=
flagger
.
setFlag
(
flags
.
loc
[
breaks
.
index
,
field
],
**
kwargs
)
return
data
,
flags
def
flagSoilMoistureByConstantsDetection
(
data
,
flags
,
field
,
flagger
,
plateau_window_min
=
'
12h
'
,
plateau_var_limit
=
0.0005
,
rainfall_window
=
'
12h
'
,
filter_window_size
=
'
3h
'
,
i_start_infimum
=
0.0025
,
i_end_supremum
=
0
,
data_max_tolerance
=
0.95
):
i_start_infimum
=
0.0025
,
i_end_supremum
=
0
,
data_max_tolerance
=
0.95
,
**
kwargs
):
"""
Function:
:param data: The pandas dataframe holding the data-to-be flagged.
Data must be indexed by a datetime series and be harmonized onto a
time raster with seconds precision (skips allowed).
...
...
@@ -516,8 +523,8 @@ def flagSoilMoistureByConstantsDetection(data, flags, field, flagger, plateau_wi
# get data max
data_max
=
dataseries
.
max
()
# identify minimal plateaus:
plateaus
=
dataseries
.
rolling
(
window
=
plateau_window_min
).
apply
(
lambda
x
:
x
.
var
()
<
plateau_var_limit
,
raw
=
False
)
\
.
astype
(
bool
)
plateaus
=
dataseries
.
rolling
(
window
=
plateau_window_min
).
apply
(
lambda
x
:
x
.
var
()
>
plateau_var_limit
,
raw
=
False
)
.
astype
(
bool
)
plateaus
=
~
plateaus
# are there any candidates for beeing flagged plateau-ish
if
plateaus
.
sum
()
==
0
:
...
...
@@ -536,7 +543,7 @@ def flagSoilMoistureByConstantsDetection(data, flags, field, flagger, plateau_wi
plateaus
=
plateaus
[
'
interval_nr
'
]
invalids
=
pd
.
Series
([])
# loop through the intervals to be checked:
for
interval_2_check
in
range
(
1
,
plateaus
.
max
()):
for
interval_2_check
in
range
(
1
,
plateaus
.
max
()
+
1
):
# how big is the interval?
interval_delimeter
=
plateaus
[
plateaus
==
interval_2_check
].
index
[
-
1
]
-
\
plateaus
[
plateaus
==
interval_2_check
].
index
[
0
]
...
...
@@ -597,4 +604,9 @@ def flagSoilMoistureByConstantsDetection(data, flags, field, flagger, plateau_wi
if
potential_invalid
.
mean
()
>
data_max
*
data_max_tolerance
:
invalids
=
pd
.
concat
([
invalids
,
potential_invalid
])
if
isinstance
(
flags
,
pd
.
Series
):
flags
.
loc
[
invalids
.
index
]
=
flagger
.
setFlag
(
flags
.
loc
[
invalids
.
index
],
**
kwargs
)
else
:
flags
.
loc
[
invalids
.
index
,
field
]
=
flagger
.
setFlag
(
flags
.
loc
[
invalids
.
index
,
field
],
**
kwargs
)
return
data
,
flags
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