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

recreate perfmetrics portrait plot in python #3551

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
bc2a6b2
example variables and models
lukruh Mar 14, 2024
b74414f
added some datasets for fixed calendar
lukruh Mar 14, 2024
f78d2e5
first approach group gaps WIP
lukruh Mar 20, 2024
93c5544
imagegrid for grouping, labels, colorbar, docstring
lukruh Mar 20, 2024
db30131
WIP triangle overlays
lukruh Mar 20, 2024
215ee95
added CMIP6 experiments
diegokam Mar 21, 2024
b4f8238
WIP split by reference
lukruh Mar 21, 2024
5c30d4a
added icon example
lukruh Mar 21, 2024
07e676a
Merge branch 'perfmetric_python' of github.com:ESMValGroup/ESMValTool…
lukruh Mar 21, 2024
42fdd81
split square feature, xarray instead of nested dicts
lukruh Mar 27, 2024
4ab76cb
3 recipe examples
lukruh Mar 27, 2024
32ad034
fix config overwrite
lukruh Mar 27, 2024
d66e5e2
legend for multiple references
lukruh Mar 28, 2024
e1bb9c4
Merge branch 'main' into perfmetric_python
lukruh Apr 2, 2024
30541be
pre-commit
lukruh Apr 2, 2024
5eb01f2
Merge branch 'perfmetric_python' of github.com:ESMValGroup/ESMValTool…
lukruh Apr 2, 2024
d6a541f
add normalization for metrics
lukruh Apr 2, 2024
7fb8a10
codacy fixes
lukruh Apr 3, 2024
eba93db
WIP Documentation
lukruh Apr 3, 2024
ffee698
adding myself to list of authors
diegokam Apr 3, 2024
54ad3d8
number of local vars, alphabetical sorting by x labels
lukruh Apr 5, 2024
7cbcf86
add dpi option and plot legend only for multiple splits
lukruh Apr 16, 2024
f7b6c87
WIP recreate example perfmetric recipe
lukruh Apr 16, 2024
39df74e
add optional calculation of distance metrics
lukruh May 2, 2024
a896ce6
fix bug for non default "split" facet
lukruh May 2, 2024
62086aa
recipe CMIP5 python, new python script creating netcdf file
diegokam Nov 4, 2024
8c9aa90
comparison script NetCDF files
diegokam Nov 4, 2024
9b20ac3
fixed pp heights, name changed, add provenance
lukruh Nov 5, 2024
db01441
format recipe (pre commit)
lukruh Nov 5, 2024
efc026a
simplify recipe p1
lukruh Nov 6, 2024
af917bc
MM stats as first columns (wip)
lukruh Nov 6, 2024
d25290e
simpler cmip5 vs cmip6 plot
lukruh Nov 6, 2024
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
20 changes: 20 additions & 0 deletions doc/sphinx/source/api/esmvaltool.diag_scripts.perfmetrics.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. _api.esmvaltool.diag_scripts.perfmetrics:

Performance Metrics
===================

This module contains various reusable diagnostics and plot scripts.


Examples
--------

* :ref:`recipe_perfmetrics_python <recipe_perfmetrics_python>`


Diagnostic scripts
------------------
.. toctree::
:maxdepth: 1

esmvaltool.diag_scripts.perfmetrics/portrait_plot.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _api.esmvaltool.diag_scripts.perfmetrics.portrait_plot:

Plot performance metrics of multiple datasets vs up to four references
======================================================================

.. automodule:: esmvaltool.diag_scripts.perfmetrics.portrait_plot
1 change: 1 addition & 0 deletions doc/sphinx/source/api/esmvaltool.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ Diagnostic Scripts
esmvaltool.diag_scripts.ocean
esmvaltool.diag_scripts.psyplot_diag
esmvaltool.diag_scripts.seaborn_diag
esmvaltool.diag_scripts.perfmetrics
1 change: 1 addition & 0 deletions doc/sphinx/source/recipes/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Climate metrics
:maxdepth: 1

recipe_perfmetrics
recipe_perfmetrics_python
recipe_smpi

Future projections
Expand Down
92 changes: 71 additions & 21 deletions doc/sphinx/source/recipes/recipe_perfmetrics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,26 @@
Performance metrics for essential climate parameters
====================================================

.. note::

We are working on a reimplemenation of the
:ref:`performance metrics in python <recipe_perfmetrics_python>`.

Overview
--------

The goal is to create a standard recipe for the calculation of performance metrics to quantify the ability of the models to reproduce the climatological mean annual cycle for selected "Essential Climate Variables" (ECVs) plus some additional corresponding diagnostics and plots to better understand and interpret the results.
The goal is to create a standard recipe for the calculation of performance
metrics to quantify the ability of the models to reproduce the climatological
mean annual cycle for selected "Essential Climate Variables" (ECVs) plus some
additional corresponding diagnostics and plots to better understand and
interpret the results.

The recipe can be used to calculate performance metrics at different vertical
levels (e.g., 5, 30, 200, 850 hPa as in
`Gleckler et al. (2008) <http://dx.doi.org/10.1029/2007JD008972>`_) and in
different regions. As an additional reference, we consider
`Righi et al. (2015) <https://doi.org/10.5194/gmd-8-733-2015>`_.

The recipe can be used to calculate performance metrics at different vertical levels (e.g., 5, 30, 200, 850 hPa as in `Gleckler et al. (2008) <http://dx.doi.org/10.1029/2007JD008972>`_ and in different regions. As an additional reference, we consider `Righi et al. (2015) <https://doi.org/10.5194/gmd-8-733-2015>`_.

Available recipes and diagnostics
-----------------------------------
Expand All @@ -21,12 +35,19 @@ Recipes are stored in recipes/

Diagnostics are stored in diag_scripts/perfmetrics/

* main.ncl: calculates and (optionally) plots annual/seasonal cycles, zonal means, lat-lon fields and time-lat-lon fields. The calculated fields can also be plotted as difference w.r.t. a given reference dataset. main.ncl also calculates RMSD, bias and taylor metrics. Input data have to be regridded to a common grid in the preprocessor. Each plot type is created by a separated routine, as detailed below.
* main.ncl: calculates and (optionally) plots annual/seasonal cycles, zonal
means, lat-lon fields and time-lat-lon fields. The calculated fields can also
be plotted as difference w.r.t. a given reference dataset. main.ncl also
calculates RMSD, bias and taylor metrics. Input data have to be regridded to
a common grid in the preprocessor. Each plot type is created by a separated
routine, as detailed below.
* cycle.ncl: creates an annual/seasonal cycle plot.
* zonal.ncl: creates a zonal (lat-pressure) plot.
* latlon.ncl: creates a lat-lon plot.
* cycle_latlon.ncl: precalculates the metrics for a time-lat-lon field, with different options for normalization.
* collect.ncl: collects and plots the metrics previously calculated by cycle_latlon.ncl.
* cycle_latlon.ncl: precalculates the metrics for a time-lat-lon field, with
different options for normalization.
* collect.ncl: collects and plots the metrics previously calculated by
cycle_latlon.ncl.

User settings in recipe
-----------------------
Expand All @@ -37,9 +58,12 @@ User settings in recipe

*Required settings (scripts)*

* plot_type: cycle (time), zonal (plev, lat), latlon (lat, lon), cycle_latlon (time, lat, lon), cycle_zonal (time, plev, lat)
* plot_type: cycle (time), zonal (plev, lat), latlon (lat, lon), cycle_latlon
(time, lat, lon), cycle_zonal (time, plev, lat)
* time_avg: type of time average (monthlyclim, seasonalclim, annualclim)
* region: selected region (global, trop, nhext, shext, nhtrop, shtrop, nh, sh, nhmidlat, shmidlat, nhpolar, shpolar, eq)
* region: selected region (global, trop, nhext, shext, nhtrop, shtrop, nh,
sh, nhmidlat, shmidlat, nhpolar, shpolar, eq)


*Optional settings (scripts)*

Expand All @@ -51,9 +75,12 @@ User settings in recipe
* projection: map projection for plot_type latlon (default: CylindricalEquidistant)
* plot_diff: draws difference plots (default: False)
* calc_grading: calculates grading metrics (default: False)
* stippling: uses stippling to mark statistically significant differences (default: False = mask out non-significant differences in gray)
* show_global_avg: diplays the global avaerage of the input field as string at the top-right of lat-lon plots (default: False)
* annots: choose the annotation style, e.g. ```alias``` which would display the alias of the dataset as title (applies to plot_type zonal and cycle_zonal)
* stippling: uses stippling to mark statistically significant differences
(default: False = mask out non-significant differences in gray)
* show_global_avg: displays the global avaerage of the input field as string
at the top-right of lat-lon plots (default: False)
* annots: choose the annotation style, e.g. ```alias``` which would display
the alias of the dataset as title (applies to plot_type zonal and cycle_zonal)
* metric: chosen grading metric(s) (if calc_grading is True)
* normalization: metric normalization (for RMSD and BIAS metrics only)
* abs_levs: list of contour levels for absolute plot
Expand Down Expand Up @@ -114,8 +141,8 @@ User settings in recipe

*Optional settings (scripts)*

* label_lo: adds lower triange for values outside range
* label_hi: adds upper triange for values outside range
* label_lo: adds lower triangle for values outside range
* label_hi: adds upper triangle for values outside range
* cm_interval: min and max color of the color table
* cm_reverse: reverses the color table
* sort: sorts datasets in alphabetic order (excluding MMM)
Expand Down Expand Up @@ -157,14 +184,21 @@ Variables
Observations and reformat scripts
---------------------------------

The following list shows the currently used observational data sets for this recipe with their variable names and the reference to their respective reformat scripts in parentheses. Please note that obs4MIPs data can be used directly without any reformating. For non-obs4MIPs data use `esmvaltool data info DATASET` or see headers of cmorization scripts (in `/esmvaltool/cmorizers/data/formatters/datasets/
<https://github.com/ESMValGroup/ESMValTool/blob/main/esmvaltool/cmorizers/data/formatters/datasets/>`_) for downloading and processing instructions.
The following list shows the currently used observational data sets for this
recipe with their variable names and the reference to their respective reformat
scripts in parentheses. Please note that obs4MIPs data can be used directly
without any reformatitng. For non-obs4MIPs data use `esmvaltool data info DATASET`
or see headers of cmorization scripts (in `/esmvaltool/cmorizers/data/formatters/datasets/
<https://github.com/ESMValGroup/ESMValTool/blob/main/esmvaltool/cmorizers/data/formatters/datasets/>`_)
for downloading and processing instructions.

#. recipe_perfmetrics_CMIP5.yml

* AIRS (hus - obs4MIPs)
* CERES-EBAF (rlut, rlutcs, rsut, rsutcs - obs4MIPs)
* ERA-Interim (tas, ta, ua, va, zg, hus - esmvaltool/cmorizers/data/formatters/datasets/era-interim.py)
* ESACCI-AEROSOL (od550aer, od870aer, od550abs, od550lt1aer - esmvaltool/cmorizers/data/formatters/datasets/esacci-aerosol.ncl)
* ESACCI-AEROSOL (od550aer, od870aer, od550abs, od550lt1aer -
esmvaltool/cmorizers/data/formatters/datasets/esacci-aerosol.ncl)
* ESACCI-CLOUD (clt - esmvaltool/cmorizers/data/formatters/datasets/esacci-cloud.ncl)
* ESACCI-OZONE (toz - esmvaltool/cmorizers/data/formatters/datasets/esacci-ozone.ncl)
* ESACCI-SOILMOISTURE (sm - esmvaltool/cmorizers/data/formatters/datasets/esacci_soilmoisture.ncl)
Expand All @@ -190,27 +224,38 @@ The following list shows the currently used observational data sets for this rec
References
----------

* Gleckler, P. J., K. E. Taylor, and C. Doutriaux, Performance metrics for climate models, J. Geophys. Res., 113, D06104, doi: 10.1029/2007JD008972 (2008).
* Gleckler, P. J., K. E. Taylor, and C. Doutriaux, Performance metrics for climate models, J.
Geophys. Res., 113, D06104, doi: 10.1029/2007JD008972 (2008).

* Righi, M., Eyring, V., Klinger, C., Frank, F., Gottschaldt, K.-D., JΓΆckel, P.,
and Cionni, I.: Quantitative evaluation of oone and selected climate parameters in a set of EMAC simulations,
Geosci. Model Dev., 8, 733, doi: 10.5194/gmd-8-733-2015 (2015).

* Righi, M., Eyring, V., Klinger, C., Frank, F., Gottschaldt, K.-D., JΓΆckel, P., and Cionni, I.: Quantitative evaluation of oone and selected climate parameters in a set of EMAC simulations, Geosci. Model Dev., 8, 733, doi: 10.5194/gmd-8-733-2015 (2015).

Example plots
-------------

.. figure:: /recipes/figures/perfmetrics/perfmetrics_fig_1.png
:width: 90%

Annual cycle of globally averaged temperature at 850 hPa (time period 1980-2005) for different CMIP5 models (historical simulation) (thin colored lines) in comparison to ERA-Interim (thick yellow line) and NCEP-NCAR-R1 (thick black dashed line) reanalysis data.
Annual cycle of globally averaged temperature at 850 hPa (time period 1980-2005)
for different CMIP5 models (historical simulation) (thin colored lines) in comparison to
ERA-Interim (thick yellow line) and NCEP-NCAR-R1 (thick black dashed line) reanalysis data.

.. figure:: /recipes/figures/perfmetrics/perfmetrics_fig_2.png
:width: 90%

Taylor diagram of globally averaged temperature at 850 hPa (ta) and longwave cloud radiative effect (lwcre) for different CMIP5 models (historical simulation, 1980-2005). Reference data (REF) are ERA-Interim for temperature (1980-2005) and CERES-EBAF (2001-2012) for longwave cloud radiative effect.
Taylor diagram of globally averaged temperature at 850 hPa (ta) and longwave cloud
radiative effect (lwcre) for different CMIP5 models (historical simulation, 1980-2005).
Reference data (REF) are ERA-Interim for temperature (1980-2005) and CERES-EBAF (2001-2012)
for longwave cloud radiative effect.

.. figure:: /recipes/figures/perfmetrics/perfmetrics_fig_3.png
:width: 90%

Difference in annual mean of zonally averaged temperature (time period 1980-2005) between the CMIP5 model MPI-ESM-MR (historical simulation) and ERA-Interim. Stippled areas indicdate differences that are statistically significant at a 95% confidence level.
Difference in annual mean of zonally averaged temperature (time period 1980-2005) between the
CMIP5 model MPI-ESM-MR (historical simulation) and ERA-Interim. Stippled areas indicdate
differences that are statistically significant at a 95% confidence level.

.. figure:: /recipes/figures/perfmetrics/perfmetrics_fig_4.png
:width: 90%
Expand All @@ -221,4 +266,9 @@ Example plots
:width: 90%
:align: center

Relative space-time root-mean-square deviation (RMSD) calculated from the climatological seasonal cycle of CMIP5 simulations. A relative performance is displayed, with blue shading indicating better and red shading indicating worse performance than the median of all model results. A diagonal split of a grid square shows the relative error with respect to the reference data set (lower right triangle) and the alternative data set (upper left triangle). White boxes are used when data are not available for a given model and variable.
Relative space-time root-mean-square deviation (RMSD) calculated from the climatological
seasonal cycle of CMIP5 simulations. A relative performance is displayed, with blue shading
indicating better and red shading indicating worse performance than the median of all model results.
A diagonal split of a grid square shows the relative error with respect to the reference data set
(lower right triangle) and the alternative data set (upper left triangle).
White boxes are used when data are not available for a given model and variable.
146 changes: 146 additions & 0 deletions doc/sphinx/source/recipes/recipe_perfmetrics_python.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
.. _recipe_perfmetrics_python:

Performance metrics for essential climate parameters in python
==============================================================

.. note::

This recipe uses python diagnostics to reproduce parts of the evaluation
done in the
:ref:`original recipe based on NCL diagnostics <nml_perfmetrics>`:
It aims for a complete replacement of all involved NCL diagnostics. So
far, only portrait plots (including performance metrics) are supported.

Overview
--------

The goal is to create a standard recipe for the calculation of performance metrics to quantify the ability of the models to reproduce the climatological mean annual cycle for selected "Essential Climate Variables" (ECVs) plus some additional corresponding diagnostics and plots to better understand and interpret the results.

The recipe can be used to calculate performance metrics at different vertical levels (e.g., 5, 30, 200, 850 hPa as in `Gleckler et al. (2008) <http://dx.doi.org/10.1029/2007JD008972>`_) and in different regions. As an additional reference, we consider `Righi et al. (2015) <https://doi.org/10.5194/gmd-8-733-2015>`_.
Brief description of the diagnostic.


Available recipes and diagnostics
---------------------------------

Recipes are stored in esmvaltool/recipes/

* recipe_perfmetrics_python.yml
* recipe_perfmetrics_CMIP5_python.yml

Diagnostics are stored in esmvaltool/diag_scripts/perfmetrics/

* portrait_plot.py: Plot metrics for any variable for multiple datasets and
up to four references.


User settings in recipe
-----------------------

#. Script perfmetrics/portrait_plot.py

This plot expects a scalar value in each input file and at most one input
file for each subset of metadata that belongs to a cell or part of cell in
the figure.
By default cells are plotted for combinations of `short_name`,
`dataset`, `project` and `split`.
Where `split` is an optional extra_facet for variables.
However, all this can be customized using the `x_by`,
`y_by`, `group_by` and `split_by` script settings.
For a complete and detailed list of settings see the
:ref:`API documentation <api.esmvaltool.diag_scripts.perfmetrics.portrait_plot>`.
While this allows very flexible use for any kind of data, there are some
limitations as well: The grouping (separated
plots in the figure) and normalization is always applied along the x-axis.
With default settings this means normalizing all metrics for each variable
and grouping all datasets by project.

To plot distance metrics like RMSE, pearson R, bias etc. the
:func:`distance_metrics <esmvalcore.preprocessor.derive>` preprocessor or
custom diagnostics can be used.



Variables
---------

.. note::

The recipe generally works for any variable that is preprocessed correctly.
To use different preprocessors or reference datasets it could be useful
to create different variable groups and link them with the same extra_facet
like `variable_name` See recipe for examples. Below listed are the variables
needed to produce the example figures.


#. recipe_perfmetrics_CMIP5.yml

* clt (atmos, monthly mean, longitude latitude time)
* hus (atmos, monthly mean, longitude latitude lev time)
* od550aer, od870aer, od550abs, od550lt1aer (aero, monthly mean, longitude latitude time)
* pr (atmos, monthly mean, longitude latitude time)
* rlut, rlutcs, rsut, rsutcs (atmos, monthly mean, longitude latitude time)
* sm (land, monthly mean, longitude latitude time)
* ta (atmos, monthly mean, longitude latitude lev time)
* tas (atmos, monthly mean, longitude latitude time)
* toz (atmos, monthly mean, longitude latitude time)
* ts (atmos, monthly mean, longitude latitude time)
* ua (atmos, monthly mean, longitude latitude lev time)
* va (atmos, monthly mean, longitude latitude lev time)
* zg (atmos, monthly mean, longitude latitude lev time)


Observations and reformat scripts
---------------------------------

*Note: (1) obs4MIPs data can be used directly without any preprocessing;
(2) see headers of reformat scripts for non-obs4MIPs data for download
instructions.*

The following list shows the currently used observational data sets for this recipe with their variable names and the reference to their respective reformat scripts in parentheses. Please note that obs4MIPs data can be used directly without any reformatting. For non-obs4MIPs data use `esmvaltool data info DATASET` or see headers of cmorization scripts (in `/esmvaltool/cmorizers/data/formatters/datasets/
<https://github.com/ESMValGroup/ESMValTool/blob/main/esmvaltool/cmorizers/data/formatters/datasets/>`_) for downloading and processing instructions.

#. recipe_perfmetrics_CMIP5.yml

* AIRS (hus - obs4MIPs)
* CERES-EBAF (rlut, rlutcs, rsut, rsutcs - obs4MIPs)
* ERA-Interim (tas, ta, ua, va, zg, hus - esmvaltool/cmorizers/data/formatters/datasets/era-interim.py)
* ESACCI-AEROSOL (od550aer, od870aer, od550abs, od550lt1aer - esmvaltool/cmorizers/data/formatters/datasets/esacci-aerosol.ncl)
* ESACCI-CLOUD (clt - esmvaltool/cmorizers/data/formatters/datasets/esacci-cloud.ncl)
* ESACCI-OZONE (toz - esmvaltool/cmorizers/data/formatters/datasets/esacci-ozone.ncl)
* ESACCI-SOILMOISTURE (sm - esmvaltool/cmorizers/data/formatters/datasets/esacci_soilmoisture.ncl)
* ESACCI-SST (ts - esmvaltool/ucmorizers/data/formatters/datasets/esacci-sst.py)
* GPCP-SG (pr - obs4MIPs)
* HadISST (ts - esmvaltool/cmorizers/data/formatters/datasets/hadisst.ncl)
* MODIS (od550aer - esmvaltool/cmorizers/data/formatters/datasets/modis.ncl)
* NCEP-NCAR-R1 (tas, ta, ua, va, zg - esmvaltool/cmorizers/data/formatters/datasets/ncep_ncar_r1.py)
* NIWA-BS (toz - esmvaltool/cmorizers/data/formatters/datasets/niwa_bs.ncl)
* PATMOS-x (clt - esmvaltool/cmorizers/data/formatters/datasets/patmos_x.ncl)


References
----------


* Gleckler, P. J., K. E. Taylor, and C. Doutriaux, Performance metrics for climate models, J.
Geophys. Res., 113, D06104, doi: 10.1029/2007JD008972 (2008).

* Righi, M., Eyring, V., Klinger, C., Frank, F., Gottschaldt, K.-D., JΓΆckel, P.,
and Cionni, I.: Quantitative evaluation of oone and selected climate parameters in a set of EMAC simulations,
Geosci. Model Dev., 8, 733, doi: 10.5194/gmd-8-733-2015 (2015).


Example plots
-------------

.. _fig_perfmetrics_python_portrait_plot:

.. figure:: /recipes/figures/perfmetrics/perfmetrics_fig_5_python.png
:width: 90%
:align: center


Relative space-time root-mean-square deviation (RMSD) calculated from the climatological
seasonal cycle of CMIP5 simulations. A relative performance is displayed, with blue shading
indicating better and red shading indicating worse performance than the median of all model results.
A diagonal split of a grid square shows the relative error with respect to the reference data set
Loading