Commit c0216671 authored by Lars Bärring's avatar Lars Bärring Committed by Klaus Zimmermann
Browse files

Index function statistics (closes #79)

parent 7bfceb07
......@@ -65,6 +65,13 @@ index_functions:
reducer:
kind: reducer
statistics:
description: |
Calculates a simple statistic of the data.
parameters:
reducer:
kind: reducer
thresholded_statistics:
description: |
Calculates a simple statistic of the data for which some condition is met.
......
......@@ -241,6 +241,27 @@ class SpellLength:
return float(res)
class Statistics:
def __init__(self, reducer):
self.reducer = NUMPY_REDUCERS[reducer]
self.lazy_reducer = DASK_REDUCERS[reducer]
self.extra_coords = []
def prepare(self, input_cube):
self.standard_name = input_cube.standard_name
self.units = input_cube.units
def call_func(self, data, axis, **kwargs):
axis = normalize_axis(axis, data.ndim)
res = self.reducer(data, axis=axis)
return res.astype('float32')
def lazy_func(self, data, axis, **kwargs):
axis = normalize_axis(axis, data.ndim)
res = self.lazy_reducer(data, axis=axis)
return res.astype('float32')
class ThresholdedStatistics:
def __init__(self, threshold, condition, reducer):
self.threshold = threshold
......
......@@ -55,6 +55,7 @@ setuptools.setup(
'first_occurrence=climix.index_functions:FirstOccurrence',
'last_occurrence=climix.index_functions:LastOccurrence',
'spell_length=climix.index_functions:SpellLength',
'statistics=climix.index_functions:Statistics',
'thresholded_statistics=climix.index_functions:ThresholdedStatistics',
],
},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment