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
8be35da3
Commit
8be35da3
authored
5 years ago
by
Peter Lünenschloß
Browse files
Options
Downloads
Patches
Plain Diff
increased soil moisture tests test coverage
parent
2319b322
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
saqc/funcs/soil_moisture_tests.py
+19
-5
19 additions, 5 deletions
saqc/funcs/soil_moisture_tests.py
test/funcs/test_soil_moisture_tests.py
+19
-2
19 additions, 2 deletions
test/funcs/test_soil_moisture_tests.py
with
38 additions
and
7 deletions
saqc/funcs/soil_moisture_tests.py
+
19
−
5
View file @
8be35da3
...
...
@@ -265,17 +265,17 @@ def flagSoilMoistureByConstantsDetection(
plateau_window_min
=
"
12h
"
,
plateau_var_limit
=
0.0005
,
rainfall_window_range
=
"
12h
"
,
filter_window_size
=
"
3h
"
,
filter_window_size
=
None
,
var_total_nans
=
np
.
inf
,
var_consec_nans
=
np
.
inf
,
derivative_maximum_lb
=
0.0025
,
derivative_minimum_ub
=
0
,
data_max_tolerance
=
0.95
,
smooth_poly_order
=
2
,
**
kwargs
):
"""
Function is not ready to use yet: we are waiting for response from the author of [Paper] in order of getting
able to exclude some sources of confusion.
"""
Note, function has to be harmonized to equidistant freq_grid
...
...
@@ -322,13 +322,27 @@ def flagSoilMoistureByConstantsDetection(
# 2. extend forwards:
if
period_diff
>
0
:
cond1_sets
=
cond1_sets
.
replace
(
1
,
method
=
'
ffill
'
,
limit
=
period_diff
)
# get first derivative
if
filter_window_size
is
None
:
filter_window_size
=
3
*
pd
.
Timedelta
(
moist_rate
)
else
:
filter_window_size
=
pd
.
Timedelta
(
filter_window_size
)
first_derivative
=
dataseries
.
diff
()
# cumsum trick to seperate continous plateau groups from each other
filter_window_seconds
=
filter_window_size
.
seconds
smoothing_periods
=
int
(
np
.
ceil
((
filter_window_seconds
/
moist_rate
.
n
)))
first_derivate
=
savgol_filter
(
dataseries
,
window_length
=
smoothing_periods
,
polyorder
=
smooth_poly_order
,
deriv
=
1
,
)
first_derivate
=
pd
.
Series
(
data
=
first_derivate
,
index
=
dataseries
.
index
,
name
=
dataseries
.
name
)
# cumsumming to seperate continous plateau groups from each other:
group_counter
=
cond1_sets
.
cumsum
()
group_counter
=
group_counter
[
group_counter
.
diff
()
==
0
]
group_counter
.
name
=
'
group_counter
'
group_frame
=
pd
.
merge
(
group_counter
,
first_derivat
iv
e
,
left_index
=
True
,
right_index
=
True
,
how
=
'
inner
'
)
group_frame
=
pd
.
merge
(
group_counter
,
first_derivate
,
left_index
=
True
,
right_index
=
True
,
how
=
'
inner
'
)
group_frame
=
group_frame
.
groupby
(
'
group_counter
'
)
condition_passed
=
group_frame
.
filter
(
lambda
x
:
(
x
[
field
].
max
()
>=
derivative_maximum_lb
)
&
(
x
[
field
].
min
()
<=
derivative_minimum_ub
))
...
...
This diff is collapsed.
Click to expand it.
test/funcs/test_soil_moisture_tests.py
+
19
−
2
View file @
8be35da3
...
...
@@ -8,9 +8,10 @@ import pandas as pd
from
saqc.funcs.soil_moisture_tests
import
(
flagSoilMoistureBySoilFrost
,
flagSoilMoistureByPrecipitationEvents
,
flagSoilMoistureByConstantsDetection
)
from
test.common
import
TESTFLAGGER
from
test.common
import
TESTFLAGGER
,
initData
@pytest.mark.parametrize
(
"
flagger
"
,
TESTFLAGGER
)
...
...
@@ -58,6 +59,22 @@ def test_flagSoilMoisturePrecipitationEvents(flagger):
test_sum
=
(
flag_result
[
flag_assertion
]
==
flagger
.
BAD
).
sum
()
assert
test_sum
==
len
(
flag_assertion
)
@pytest.mark.parametrize
(
"
flagger
"
,
TESTFLAGGER
)
def
test_flagSoilMoistureByConstantsDetection
(
flagger
):
data
=
initData
(
1
,
start_date
=
"
2011-01-01 00:00:00
"
,
end_date
=
"
2011-01-02 00:00:00
"
,
freq
=
"
5min
"
)
data
.
iloc
[
5
:
25
]
=
0
data
.
iloc
[
100
:
120
]
=
data
.
max
()[
0
]
field
=
data
.
columns
[
0
]
flagger
=
flagger
.
initFlags
(
data
)
data
,
flagger
=
flagSoilMoistureByConstantsDetection
(
data
,
field
,
flagger
,
plateau_window_min
=
'
1h
'
,
rainfall_window_range
=
'
1h
'
)
assert
~
(
flagger
.
isFlagged
()[
5
:
25
]).
all
()[
0
]
assert
(
flagger
.
isFlagged
()[
100
:
120
]).
all
()[
0
]
if
__name__
==
"
__main__
"
:
flagger
=
TESTFLAGGER
[
2
]
test_flagSoilMoistureBy
SoilFrost
(
flagger
)
test_flagSoilMoistureBy
ConstantsDetection
(
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