Commit 0ff96c73 authored by Klaus Zimmermann's avatar Klaus Zimmermann
Browse files

Fix comparison operators in CountPercentileOccurrences (fixes #224)

parent e2dabd16
......@@ -4,7 +4,7 @@ import cftime
import dask.array as da
import numpy as np
from .support import IndexFunction, parse_timerange
from .support import IndexFunction, parse_timerange, NUMPY_OPERATORS, DASK_OPERATORS
from ..dask_setup import progress
from ..dask_take_along_axis import dask_take_along_axis
......@@ -186,6 +186,8 @@ class CountPercentileOccurrences(IndexFunction):
self.base = timerange
percentile.convert_units('1')
self.percentile = float(percentile.points)
self.condition = NUMPY_OPERATORS[condition]
self.lazy_condition = DASK_OPERATORS[condition]
self.bootstrapping = bootstrapping
def preprocess(self, cubes, client):
......@@ -269,7 +271,7 @@ class CountPercentileOccurrences(IndexFunction):
quantiles = self.quantiler.quantiles(
ignore_year=year,
duplicate_year=duplicate_year)
cond = data[...] < quantiles
cond = self.lazy_condition(data[...], quantiles)
count = da.count_nonzero(cond, axis=0)
counts.append(count)
counts = da.stack(counts, axis=-1)
......@@ -278,7 +280,7 @@ class CountPercentileOccurrences(IndexFunction):
percents = avg_counts/(data.shape[0]/100.)
else:
logging.info('Not using bootstrapping')
cond = data < self.out_of_base_quantiles
cond = self.lazy_condition(data, self.out_of_base_quantiles)
counts = da.count_nonzero(cond, axis=0).astype(np.float32)
percents = counts/(data.shape[0]/100.)
return percents
Markdown is supported
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