Skip to content

Commit dd596d3

Browse files
authored
Merge pull request #602 from ESMValGroup/add_operators_to_multimodel
Add max, min and std operators to multimodel
2 parents cac2f35 + 70c79ae commit dd596d3

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

doc/recipe/preprocessor.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -646,13 +646,13 @@ to observational data, these biases have a significantly lower statistical
646646
impact when using a multi-model ensemble. ESMValTool has the capability of
647647
computing a number of multi-model statistical measures: using the preprocessor
648648
module ``multi_model_statistics`` will enable the user to ask for either a
649-
multi-model ``mean`` and/or ``median`` with a set of argument parameters passed
650-
to ``multi_model_statistics``.
649+
multi-model ``mean``, ``median``, ``max``, ``min`` and / or ``std`` with a set
650+
of argument parameters passed to ``multi_model_statistics``.
651651

652-
Multimodel statistics in ESMValTool are computed along the time axis, and as
653-
such, can be computed across a common overlap in time (by specifying ``span:
654-
overlap`` argument) or across the full length in time of each model (by
655-
specifying ``span: full`` argument).
652+
Note that current multimodel statistics in ESMValTool are local (not global),
653+
and are computed along the time axis. As such, can be computed across a common
654+
overlap in time (by specifying ``span: overlap`` argument) or across the full
655+
length in time of each model (by specifying ``span: full`` argument).
656656

657657
Restrictive computation is also available by excluding any set of models that
658658
the user will not want to include in the statistics (by setting ``exclude:

esmvalcore/preprocessor/_multimodel.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ def _compute_statistic(data, statistic_name):
6262
statistic_function = np.ma.median
6363
elif statistic_name == 'mean':
6464
statistic_function = np.ma.mean
65+
elif statistic_name == 'std':
66+
statistic_function = np.ma.std
67+
elif statistic_name == 'max':
68+
statistic_function = np.ma.max
69+
elif statistic_name == 'min':
70+
statistic_function = np.ma.min
6571
else:
6672
raise NotImplementedError
6773

@@ -326,7 +332,8 @@ def multi_model_statistics(products, span, output_products, statistics):
326332
output_products: dict
327333
dictionary of output products.
328334
statistics: str
329-
statistical measure to be computed (mean or median).
335+
statistical measure to be computed. Available options: mean, median,
336+
max, min, std
330337
Returns
331338
-------
332339
list

tests/unit/preprocessor/_multimodel/test_multimodel.py

+23
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,29 @@ def test_compute_statistic(self):
9090
self.assert_array_equal(stat_mean, expected_mean)
9191
self.assert_array_equal(stat_median, expected_median)
9292

93+
def test_compute_std(self):
94+
"""Test statistic."""
95+
data = [self.cube1.data[0], self.cube2.data[0] * 2]
96+
stat = _compute_statistic(data, "std")
97+
expected = np.ma.ones((3, 2, 2)) * 0.5
98+
expected[0, 0, 0] = 0
99+
self.assert_array_equal(stat, expected)
100+
101+
def test_compute_max(self):
102+
"""Test statistic."""
103+
data = [self.cube1.data[0] * 0.5, self.cube2.data[0] * 2]
104+
stat = _compute_statistic(data, "max")
105+
expected = np.ma.ones((3, 2, 2)) * 2
106+
expected[0, 0, 0] = 0.5
107+
self.assert_array_equal(stat, expected)
108+
109+
def test_compute_min(self):
110+
"""Test statistic."""
111+
data = [self.cube1.data[0] * 0.5, self.cube2.data[0] * 2]
112+
stat = _compute_statistic(data, "min")
113+
expected = np.ma.ones((3, 2, 2)) * 0.5
114+
self.assert_array_equal(stat, expected)
115+
93116
def test_put_in_cube(self):
94117
"""Test put in cube."""
95118
cube_data = np.ma.ones((2, 3, 2, 2))

0 commit comments

Comments
 (0)