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 RMS iris analysis operator to statistics preprocessor functions #747

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 7 additions & 7 deletions doc/recipe/preprocessor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ This function produces statistics for each day in the dataset.

Parameters:
* operator: operation to apply. Accepted values are 'mean',
'median', 'std_dev', 'min', 'max' and 'sum'. Default is 'mean'
'median', 'std_dev', 'min', 'max', 'sum' and 'rms'. Default is 'mean'

See also :func:`esmvalcore.preprocessor.daily_statistics`.

Expand All @@ -811,7 +811,7 @@ This function produces statistics for each month in the dataset.

Parameters:
* operator: operation to apply. Accepted values are 'mean',
'median', 'std_dev', 'min', 'max' and 'sum'. Default is 'mean'
'median', 'std_dev', 'min', 'max', 'sum' and 'rms'. Default is 'mean'

See also :func:`esmvalcore.preprocessor.monthly_statistics`.

Expand All @@ -831,7 +831,7 @@ December and remove such biased initial datapoints.

Parameters:
* operator: operation to apply. Accepted values are 'mean',
'median', 'std_dev', 'min', 'max' and 'sum'. Default is 'mean'
'median', 'std_dev', 'min', 'max', 'sum' and 'rms'. Default is 'mean'

See also :func:`esmvalcore.preprocessor.seasonal_mean`.

Expand All @@ -844,7 +844,7 @@ This function produces statistics for each year.

Parameters:
* operator: operation to apply. Accepted values are 'mean',
'median', 'std_dev', 'min', 'max' and 'sum'. Default is 'mean'
'median', 'std_dev', 'min', 'max', 'sum' and 'rms'. Default is 'mean'

See also :func:`esmvalcore.preprocessor.annual_statistics`.

Expand All @@ -857,7 +857,7 @@ This function produces statistics for each decade.

Parameters:
* operator: operation to apply. Accepted values are 'mean',
'median', 'std_dev', 'min', 'max' and 'sum'. Default is 'mean'
'median', 'std_dev', 'min', 'max', 'sum' and 'rms'. Default is 'mean'

See also :func:`esmvalcore.preprocessor.decadal_statistics`.

Expand All @@ -871,7 +871,7 @@ This function produces statistics for the whole dataset. It can produce scalars

Parameters:
* operator: operation to apply. Accepted values are 'mean', 'median',
'std_dev', 'min', 'max' and 'sum'. Default is 'mean'
'std_dev', 'min', 'max', 'sum' and 'rms'. Default is 'mean'

* period: define the granularity of the statistics: get values for the
full period, for each month or day of year.
Expand Down Expand Up @@ -1152,7 +1152,7 @@ areas of the region. This function takes the argument, ``operator``: the name
of the operation to apply.

This function can be used to apply several different operations in the
horizontal plane: mean, standard deviation, median variance, minimum and maximum.
horizontal plane: mean, standard deviation, median, variance, minimum, maximum and root mean square.

Note that this function is applied over the entire dataset. If only a specific
region, depth layer or time period is required, then those regions need to be
Expand Down
10 changes: 7 additions & 3 deletions esmvalcore/preprocessor/_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def zonal_statistics(cube, operator):

operator: str, optional
Select operator to apply.
Available operators: 'mean', 'median', 'std_dev', 'sum', 'min', 'max'.
Available operators: 'mean', 'median', 'std_dev', 'sum', 'min',
'max', 'rms'.

Returns
-------
Expand Down Expand Up @@ -133,7 +134,8 @@ def meridional_statistics(cube, operator):

operator: str, optional
Select operator to apply.
Available operators: 'mean', 'median', 'std_dev', 'sum', 'min', 'max'.
Available operators: 'mean', 'median', 'std_dev', 'sum', 'min',
'max', 'rms'.

Returns
-------
Expand Down Expand Up @@ -224,14 +226,16 @@ def area_statistics(cube, operator, fx_variables=None):
+------------+--------------------------------------------------+
| `max` | Maximum value |
+------------+--------------------------------------------------+
| `rms` | Area weighted root mean square. |
+------------+--------------------------------------------------+

Parameters
----------
cube: iris.cube.Cube
Input cube.
operator: str
The operation, options: mean, median, min, max, std_dev, sum,
variance
variance, rms.
fx_variables: dict
dictionary of field:filename for the fx_variables

Expand Down
8 changes: 5 additions & 3 deletions esmvalcore/preprocessor/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ def get_iris_analysis_operation(operator):
------
ValueError
operator not in allowed operators list.
allowed operators: mean, median, std_dev, sum, variance, min, max
allowed operators: mean, median, std_dev, sum, variance, min, max, rms
"""
operators = ['mean', 'median', 'std_dev', 'sum', 'variance', 'min', 'max']
operators = [
'mean', 'median', 'std_dev', 'sum', 'variance', 'min', 'max', 'rms'
]
operator = operator.lower()
if operator not in operators:
raise ValueError("operator {} not recognised. "
Expand All @@ -66,4 +68,4 @@ def operator_accept_weights(operator):
bool: True if operator support weights, False otherwise

"""
return operator.lower() in ('mean', 'sum')
return operator.lower() in ('mean', 'sum', 'rms')
18 changes: 12 additions & 6 deletions esmvalcore/preprocessor/_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ def daily_statistics(cube, operator='mean'):

operator: str, optional
Select operator to apply.
Available operators: 'mean', 'median', 'std_dev', 'sum', 'min', 'max'
Available operators: 'mean', 'median', 'std_dev', 'sum', 'min',
'max', 'rms'

Returns
-------
Expand Down Expand Up @@ -228,7 +229,8 @@ def monthly_statistics(cube, operator='mean'):

operator: str, optional
Select operator to apply.
Available operators: 'mean', 'median', 'std_dev', 'sum', 'min', 'max'
Available operators: 'mean', 'median', 'std_dev', 'sum', 'min',
'max', 'rms'

Returns
-------
Expand Down Expand Up @@ -258,7 +260,8 @@ def seasonal_statistics(cube, operator='mean'):

operator: str, optional
Select operator to apply.
Available operators: 'mean', 'median', 'std_dev', 'sum', 'min', 'max'
Available operators: 'mean', 'median', 'std_dev', 'sum', 'min',
'max', 'rms'

Returns
-------
Expand Down Expand Up @@ -313,7 +316,8 @@ def annual_statistics(cube, operator='mean'):

operator: str, optional
Select operator to apply.
Available operators: 'mean', 'median', 'std_dev', 'sum', 'min', 'max'
Available operators: 'mean', 'median', 'std_dev', 'sum', 'min',
'max', 'rms'

Returns
-------
Expand Down Expand Up @@ -345,7 +349,8 @@ def decadal_statistics(cube, operator='mean'):

operator: str, optional
Select operator to apply.
Available operators: 'mean', 'median', 'std_dev', 'sum', 'min', 'max'
Available operators: 'mean', 'median', 'std_dev', 'sum', 'min',
'max', 'rms'

Returns
-------
Expand Down Expand Up @@ -384,7 +389,8 @@ def climate_statistics(cube, operator='mean', period='full'):

operator: str, optional
Select operator to apply.
Available operators: 'mean', 'median', 'std_dev', 'sum', 'min', 'max'
Available operators: 'mean', 'median', 'std_dev', 'sum', 'min',
'max', 'rms'

period: str, optional
Period to compute the statistic over.
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/preprocessor/_area/test_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ def test_area_statistics_neg_lon(self):
expected = np.array([1.])
self.assert_array_equal(result.data, expected)

def test_area_statistics_rms(self):
"""Test for area rms of a 2D field."""
result = area_statistics(self.grid, 'rms')
expected = np.array([1.])
self.assert_array_equal(result.data, expected)

def test_extract_region(self):
"""Test for extracting a region from a 2D field."""
result = extract_region(self.grid, 1.5, 2.5, 1.5, 2.5)
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/preprocessor/_time/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,17 @@ def test_time_median(self):
expected = np.array([1.])
assert_array_equal(result.data, expected)

def test_time_rms(self):
"""Test for time rms of a 1D field."""
data = np.arange((3))
times = np.array([15., 45., 75.])
bounds = np.array([[0., 30.], [30., 60.], [60., 90.]])
cube = self._create_cube(data, times, bounds)

result = climate_statistics(cube, operator='rms')
expected = np.array([(5/3)**0.5])
assert_array_equal(result.data, expected)


class TestSeasonalStatistics(tests.Test):
"""Test :func:`esmvalcore.preprocessor._time.seasonal_statistics`"""
Expand Down