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

fix time bounds in daily and monthly statistics #399

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 2 additions & 1 deletion doc/esmvalcore/preprocessor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,8 @@ The ``_time.py`` module contains the following preprocessor functions:
Statistics functions are applied by default in the order they appear in the
list. For example, the following example applied to hourly data will retrieve
the minimum values for the full period (by season) of the monthly mean of the
daily maximum of any given variable.
daily maximum of any given variable. The representative time for statistics
is (hour=12:00) in daily periods and (day=15, hour=12:00) in monthly periods.

.. code-block:: yaml

Expand Down
24 changes: 22 additions & 2 deletions esmvalcore/preprocessor/_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ def daily_statistics(cube, operator='mean'):
"""
Compute daily statistics.

Chunks time in daily periods and computes statistics over them;
Chunks time in daily periods and computes statistics over them.
The statistics are assigned to a specific time (hour=12:00) in
daily period;

Parameters
----------
Expand All @@ -207,14 +209,24 @@ def daily_statistics(cube, operator='mean'):

operator = get_iris_analysis_operation(operator)
cube = cube.aggregated_by(['day_of_year', 'year'], operator)

# Correct the time coordinate
cube.coord('time').points = cube.coord('time').units.date2num([
cell.point.replace(hour=12, minute=0)
for cell in cube.coord('time').cells()])

cube.coord('time').bounds = None
cube.coord('time').guess_bounds()
return cube


def monthly_statistics(cube, operator='mean'):
"""
Compute monthly statistics.

Chunks time in monthly periods and computes statistics over them;
Chunks time in monthly periods and computes statistics over them.
The statistics are assigned to a specific time (day=15, hour=12:00)
in monthly period;

Parameters
----------
Expand All @@ -237,6 +249,14 @@ def monthly_statistics(cube, operator='mean'):

operator = get_iris_analysis_operation(operator)
cube = cube.aggregated_by(['month_number', 'year'], operator)

# Correct the time coordinate
cube.coord('time').points = cube.coord('time').units.date2num([
cell.point.replace(day=15, hour=12, minute=0)
for cell in cube.coord('time').cells()])

cube.coord('time').bounds = None
cube.coord('time').guess_bounds()
return cube


Expand Down