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
climix
climix
Commits
c5750cc9
Commit
c5750cc9
authored
Feb 20, 2020
by
Lars Bärring
Committed by
Klaus Zimmermann
Feb 20, 2020
Browse files
Index function percentile (closes
#80
)
parent
1c899f47
Changes
4
Hide whitespace changes
Inline
Side-by-side
climix/etc/metadata.yml
View file @
c5750cc9
...
...
@@ -123,6 +123,13 @@ index_functions:
reducer
:
kind
:
reducer
percentile
:
description
:
|
Calculates percentiles, default method is "linear" option of numpy and dask.
parameters
:
percentiles
:
kind
:
quantity
temperature_sum
:
description
:
|
Calculates the temperature sum above/below a threshold. First, the threshold
...
...
climix/index_functions/__init__.py
View file @
c5750cc9
...
...
@@ -8,6 +8,7 @@ from .index_functions import ( # noqa: F401
ExtremeTemperatureRange
,
FirstOccurrence
,
LastOccurrence
,
Percentile
,
SpellLength
,
Statistics
,
ThresholdedStatistics
,
...
...
climix/index_functions/index_functions.py
View file @
c5750cc9
...
...
@@ -286,6 +286,39 @@ class ThresholdedStatistics(ThresholdMixin, ReducerMixin, IndexFunction):
return
res
.
astype
(
'float32'
)
class
Percentile
(
IndexFunction
):
def
__init__
(
self
,
percentiles
,
interpolation
=
'linear'
):
super
().
__init__
(
units
=
Unit
(
'days'
))
points
=
percentiles
.
points
assert
np
.
all
(
points
>
0
)
assert
np
.
all
(
points
<
100
)
self
.
percentiles
=
percentiles
self
.
interpolation
=
interpolation
self
.
units
=
'%'
def
prepare
(
self
,
input_cubes
):
super
().
prepare
(
input_cubes
)
ref_cube
=
next
(
iter
(
input_cubes
.
values
()))
self
.
standard_name
=
ref_cube
.
standard_name
self
.
units
=
ref_cube
.
units
def
call_func
(
self
,
data
,
axis
,
**
kwargs
):
axis
=
normalize_axis
(
axis
,
data
.
ndim
)
res
=
np
.
percentile
(
data
,
q
=
self
.
percentiles
,
axis
=
axis
,
interpolation
=
self
.
interpolation
)
return
res
.
astype
(
'float32'
)
def
lazy_func
(
self
,
data
,
axis
,
**
kwargs
):
axis
=
normalize_axis
(
axis
,
data
.
ndim
)
def
percentile
(
arr
):
return
np
.
percentile
(
arr
,
q
=
self
.
percentiles
.
points
,
interpolation
=
self
.
interpolation
)
res
=
da
.
apply_along_axis
(
percentile
,
axis
=
axis
,
arr
=
data
).
squeeze
()
return
res
.
astype
(
'float32'
)
class
TemperatureSum
(
ThresholdMixin
,
IndexFunction
):
def
__init__
(
self
,
threshold
,
condition
):
super
().
__init__
(
threshold
,
condition
,
units
=
Unit
(
'days'
))
...
...
setup.py
View file @
c5750cc9
...
...
@@ -58,6 +58,7 @@ setuptools.setup(
'last_occurrence=climix.index_functions:LastOccurrence'
,
'spell_length=climix.index_functions:SpellLength'
,
'statistics=climix.index_functions:Statistics'
,
'percentile=climix.index_functions:Percentile'
,
'thresholded_statistics=climix.index_functions:ThresholdedStatistics'
,
'temperature_sum=climix.index_functions:TemperatureSum'
,
'diurnal_temperature_range=climix.index_functions:DiurnalTemperatureRange'
,
...
...
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