Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add max, min and std operators to multimodel #602

Merged
merged 3 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions doc/recipe/preprocessor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -635,13 +635,13 @@ to observational data, these biases have a significantly lower statistical
impact when using a multi-model ensemble. ESMValTool has the capability of
computing a number of multi-model statistical measures: using the preprocessor
module ``multi_model_statistics`` will enable the user to ask for either a
multi-model ``mean`` and/or ``median`` with a set of argument parameters passed
to ``multi_model_statistics``.
multi-model ``mean``, ``median``, ``max``, ``min`` and / or ``std`` with a set
of argument parameters passed to ``multi_model_statistics``.

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

Restrictive computation is also available by excluding any set of models that
the user will not want to include in the statistics (by setting ``exclude:
Expand Down
9 changes: 8 additions & 1 deletion esmvalcore/preprocessor/_multimodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ def _compute_statistic(data, statistic_name):
statistic_function = np.ma.median
elif statistic_name == 'mean':
statistic_function = np.ma.mean
elif statistic_name == 'std':
statistic_function = np.ma.std
elif statistic_name == 'max':
statistic_function = np.ma.max
elif statistic_name == 'min':
statistic_function = np.ma.min
else:
raise NotImplementedError

Expand Down Expand Up @@ -326,7 +332,8 @@ def multi_model_statistics(products, span, output_products, statistics):
output_products: dict
dictionary of output products.
statistics: str
statistical measure to be computed (mean or median).
statistical measure to be computed. Available options: mean, median,
max, min, std
Returns
-------
list
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/preprocessor/_multimodel/test_multimodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,29 @@ def test_compute_statistic(self):
self.assert_array_equal(stat_mean, expected_mean)
self.assert_array_equal(stat_median, expected_median)

def test_compute_std(self):
"""Test statistic."""
data = [self.cube1.data[0], self.cube2.data[0] * 2]
stat = _compute_statistic(data, "std")
expected = np.ma.ones((3, 2, 2)) * 0.5
expected[0, 0, 0] = 0
self.assert_array_equal(stat, expected)

def test_compute_max(self):
"""Test statistic."""
data = [self.cube1.data[0] * 0.5, self.cube2.data[0] * 2]
stat = _compute_statistic(data, "max")
expected = np.ma.ones((3, 2, 2)) * 2
expected[0, 0, 0] = 0.5
self.assert_array_equal(stat, expected)

def test_compute_min(self):
"""Test statistic."""
data = [self.cube1.data[0] * 0.5, self.cube2.data[0] * 2]
stat = _compute_statistic(data, "min")
expected = np.ma.ones((3, 2, 2)) * 0.5
self.assert_array_equal(stat, expected)

def test_put_in_cube(self):
"""Test put in cube."""
cube_data = np.ma.ones((2, 3, 2, 2))
Expand Down