Skip to content

Commit

Permalink
Generate climatology on the fly for AutoAssess soil moisture (#3197)
Browse files Browse the repository at this point in the history
Co-authored-by: Bouwe Andela <b.andela@esciencecenter.nl>
  • Loading branch information
2 people authored and Javier Vegas-Regidor committed Jan 14, 2024
1 parent 121cff0 commit 90f4a61
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 153 deletions.
4 changes: 0 additions & 4 deletions doc/sphinx/source/recipes/broken_recipe_list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ More details can be found in the :ref:`broken recipe policy
- Affected diagnostics
- Problem
- GitHub issue
* - :ref:`recipe_autoassess_landsurface_soilmoisture.yml <recipe_autoassess_landsurface_soilmoisture.rst>`
- All
- Dependency on some external climatology files
- `#2309 <https://github.com/ESMValGroup/ESMValTool/issues/2309>`_
* - `recipe_check_obs.yml`
- `ERA5_native6`
- Derivation of custom variables `rlus` and `rsus`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Performance metrics:

Metrics are calculated using model and observation multi-year climatologies (seasonal means)
for meteorological seasons:

* December-January-February (djf)
* March-April-May (mam)
* June-July-August (jja)
Expand All @@ -38,7 +39,6 @@ Recipes are stored in esmvaltool/recipes/

Diagnostics are stored in esmvaltool/diag_scripts/autoassess/

* autoassess_area_base.py: wrapper for autoassess scripts
* land_surface_soilmoisture/soilmoisture.py: script to calculate soil moisture
metrics
* plot_autoassess_metrics.py: plot normalised assessment metrics
Expand All @@ -47,21 +47,17 @@ Diagnostics are stored in esmvaltool/diag_scripts/autoassess/
User settings in recipe
-----------------------

#. Script autoassess_area_base.py
#. Script soilmoisture.py

*Required settings for script*

* area: must equal land_surface_soilmoisture to select this diagnostic
* control_model: name of model to be used as control
* exp_model: name of model to be used as experiment
* start: date (YYYY/MM/DD) at which period begins (see note on time gating)
* end: date (YYYY/MM/DD) at which period ends (see note on time gating)
* climfiles_root: path to observation climatologies

*Optional settings for script*

* title: arbitrary string with name of diagnostic
* obs_models: unused for this recipe
none

*Required settings for variables*

Expand Down Expand Up @@ -97,7 +93,8 @@ User settings in recipe
Variables
---------

* mrsos (land, monthly mean, longitude latitude time)
* mrsos (from models: land, monthly mean, longitude latitude time)
* sm (from observations: land, monthly mean, longitude latitude time)


Observations and reformat scripts
Expand All @@ -122,56 +119,3 @@ Example plots
:alt: Soilmoisture_Metrics.png

Normalised metrics plot comparing a control and experiment simulation


Additional notes on usage
-------------------------
The ``landsurface_soilmoisture`` area metric is part of the ``esmvaltool/diag_scripts/autoassess`` diagnostics,
and, as any other ``autoassess`` metric, it uses the ``autoassess_area_base.py`` as general purpose
wrapper. This wrapper accepts a number of input arguments that are read through from the recipe.

This recipe is part of the larger group of Autoassess metrics ported to ESMValTool
from the native Autoassess package from the UK's Met Office. The ``diagnostics`` settings
are almost the same as for the other Autoassess metrics.

**Currently this recipe is marked as broken, because it only runs on Jasmin due to a dependency on some
external climatology files.**

.. note::

**Time gating for autoassess metrics.**

To preserve the native Autoassess functionalities,
data loading and selection on time is done somewhat
differently for ESMValTool's autoassess metrics: the
time selection is done in the preprocessor as per usual but
a further time selection is performed as part of the diagnostic.
For this purpose the user will specify a ``start:`` and ``end:``
pair of arguments of ``scripts: autoassess_script`` (see below
for example). These are formatted as ``YYYY/MM/DD``; this is
necessary since the Autoassess metrics are computed from 1-Dec
through 1-Dec rather than 1-Jan through 1-Jan. This is a temporary
implementation to fully replicate the native Autoassess functionality
and a minor user inconvenience since they need to set an extra set of
``start`` and ``end`` arguments in the diagnostic; this will be phased
when all the native Autoassess metrics have been ported to ESMValTool
review has completed.


An example of standard inputs as read by ``autoassess_area_base.py`` and passed
over to the diagnostic/metric is listed below.


.. code-block:: yaml
scripts:
autoassess_landsurf_soilmoisture: &autoassess_landsurf_soilmoisture_settings
script: autoassess/autoassess_area_base.py
title: "Autoassess Land-Surface Soilmoisture Diagnostic"
area: land_surface_soilmoisture
control_model: IPSL-CM5A-LR
exp_model: inmcm4
obs_models: []
start: 1997/12/01
end: 2002/12/01
climfiles_root: '/gws/nopw/j04/esmeval/autoassess_specific_files/files' # on JASMIN
6 changes: 5 additions & 1 deletion esmvaltool/config-references.yml
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ authors:
sellar_alistair:
name: Sellar, Alistair
institute: MetOffice, UK
orcid:
orcid: 0000-0002-2955-7254
wyser_klaus:
name: Wyser, Klaus
institute: SMHI, Sweden
Expand Down Expand Up @@ -668,6 +668,10 @@ authors:
institute:
orcid:
github: mcreader97
rumbold_heather:
name: Heather, Rumbold
institute: Met Office, UK
orcid:
senftleben_daniel:
name: Senftleben, Daniel
institute: DLR, Germany
Expand Down
34 changes: 27 additions & 7 deletions esmvaltool/diag_scripts/autoassess/_plot_mo_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import matplotlib.pyplot as plt
import numpy as np

from esmvaltool.diag_scripts.shared import save_figure

# Define some colours
BLACK = '#000000'
RED = '#FF0000'
Expand Down Expand Up @@ -596,7 +598,8 @@ def plot_nac(cref,
acc=None,
extend_y=False,
title=None,
ofile=None):
ofile=None,
config=None):
"""
Routine to produce NAC plot.
Expand All @@ -611,6 +614,7 @@ def plot_nac(cref,
:param bool extend_y: Extend y-axis to include obs/acc ranges
:param str title: Plot title
:param str ofile: Plot file name
:param dict config: ESMValTool configuration object
"""
# initialize
if metrics is None:
Expand Down Expand Up @@ -682,15 +686,31 @@ def plot_nac(cref,
legend.set_title('Vs %s' % cref, prop={'size': 'small'})

# Display or produce file
if ofile:
# Create directory to write file to
odir = os.path.dirname(ofile)
if not os.path.isdir(odir):
os.makedirs(odir)
if ofile and config:
os.makedirs(config['plot_dir'], exist_ok=True)
provenance = get_provenance_record(config)
# Note that bbox_inches only works for png plots
plt.savefig(ofile, bbox_extra_artists=(legend, ), bbox_inches='tight')
save_figure(ofile, provenance, config, fig,
bbox_extra_artists=(legend, ), bbox_inches='tight')
else:
# Need the following to attempt to display legend in frame
fig.subplots_adjust(right=0.85)
plt.show()
plt.close()


def get_provenance_record(config):
"""Create a provenance record describing the diagnostic data and plot."""
filenames = [item["filename"] for item in config["input_data"].values()]
record = {
'caption': 'Normalised assessment criteria plot',
'plot_type': 'metrics',
'authors': [
'williams_keith',
'predoi_valeriu',
'sellar_alistair'
],
"ancestors": filenames,
}

return record

0 comments on commit 90f4a61

Please sign in to comment.