Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Klaus Zimmermann
climix
Commits
ac2bcc73
Commit
ac2bcc73
authored
Aug 04, 2021
by
Klaus Zimmermann
Browse files
Index function thresholded running statistics (closes
#157
)
parent
15957296
Changes
4
Hide whitespace changes
Inline
Side-by-side
climix/etc/metadata.yml
View file @
ac2bcc73
...
...
@@ -159,6 +159,22 @@ index_functions:
reducer
:
kind
:
reducer
thresholded_running_statistics
:
description
:
|
First calculate a statistic within a moving window, then calculate a
different statistic across the moving windows.
parameters
:
threshold
:
kind
:
quantity
condition
:
kind
:
operator
rolling_aggregator
:
kind
:
reducer
window_size
:
kind
:
quantity
reducer
:
kind
:
reducer
temperature_sum
:
description
:
|
Calculates the temperature sum above/below a threshold. First, the threshold
...
...
climix/index_functions/__init__.py
View file @
ac2bcc73
...
...
@@ -13,6 +13,7 @@ from .index_functions import ( # noqa: F401
ThresholdedPercentile
,
ThresholdedStatistics
,
RunningStatistics
,
ThresholdedRunningStatistics
,
TemperatureSum
,
)
...
...
climix/index_functions/index_functions.py
View file @
ac2bcc73
...
...
@@ -432,6 +432,21 @@ class RunningStatistics(RollingWindowMixin, IndexFunction):
return
cube
,
res_data
class
ThresholdedRunningStatistics
(
ThresholdMixin
,
RunningStatistics
):
def
__init__
(
self
,
threshold
,
condition
,
rolling_aggregator
,
window_size
,
reducer
):
super
().
__init__
(
threshold
,
condition
,
rolling_aggregator
,
window_size
,
reducer
)
def
call_func
(
self
,
data
,
axis
,
**
kwargs
):
comb
=
self
.
condition
(
data
,
self
.
threshold
.
points
)
thresholded_data
=
np
.
where
(
comb
,
data
,
0.0
)
return
super
().
call_func
(
thresholded_data
,
axis
,
**
kwargs
)
def
lazy_func
(
self
,
data
,
axis
,
**
kwargs
):
comb
=
self
.
condition
(
data
,
self
.
threshold
.
points
)
thresholded_data
=
da
.
where
(
comb
,
data
,
0.0
)
return
super
().
call_func
(
thresholded_data
,
axis
,
**
kwargs
)
class
TemperatureSum
(
ThresholdMixin
,
IndexFunction
):
def
__init__
(
self
,
threshold
,
condition
):
super
().
__init__
(
threshold
,
condition
,
units
=
Unit
(
"days"
))
...
...
setup.py
View file @
ac2bcc73
...
...
@@ -64,6 +64,7 @@ setuptools.setup(
"statistics=climix.index_functions:Statistics"
,
"temperature_sum=climix.index_functions:TemperatureSum"
,
"thresholded_percentile=climix.index_functions:ThresholdedPercentile"
,
"thresholded_running_statistics=climix.index_functions:ThresholdedRunningStatistics"
,
# noqa: E501
"thresholded_statistics=climix.index_functions:ThresholdedStatistics"
,
],
},
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment