Skip to content

Commit

Permalink
Fixed plot type order and monitor recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
schlunma committed Sep 7, 2023
1 parent f94da83 commit 1be2106
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 146 deletions.
13 changes: 7 additions & 6 deletions doc/sphinx/source/recipes/recipe_monitor.rst
Expand Up @@ -211,15 +211,16 @@ Zonal mean profile of ta including a reference dataset.

1D profile of ta including a reference dataset.

.. _fig_hovmoeller_z_vs_time_with_ref:
.. figure:: /recipes/figures/monitor/hovmoeller_z_vs_time_with_ref.png
.. _fig_variable_vs_lat_with_ref:
.. figure:: /recipes/figures/monitor/variable_vs_lat_with_ref.png
:align: center
:width: 14cm

Hovmoeller plot (pressure vs time) of ta including a reference dataset.
.. _fig_variable_vs_lat_with_ref:
.. figure:: /recipes/figures/monitor/variable_vs_lat_with_ref.png
Zonal mean pr including a reference dataset.

.. _fig_hovmoeller_z_vs_time_with_ref:
.. figure:: /recipes/figures/monitor/hovmoeller_z_vs_time_with_ref.png
:align: center
:width: 14cm

1D profile of pr over latitude.
Hovmoeller plot (pressure vs time) of ta including a reference dataset.
201 changes: 99 additions & 102 deletions esmvaltool/diag_scripts/monitor/multi_datasets.py
Expand Up @@ -31,22 +31,7 @@
datasets need to be given on the same horizontal and vertical grid (you
can use the preprocessors :func:`esmvalcore.preprocessor.regrid` and
:func:`esmvalcore.preprocessor.extract_levels` for this). Input data
needs to be 2D with dimensions `latitude`, `height`/`air_pressure`.
<<<<<<< HEAD
- Hovmoeller altitude vs time (plot type ``hovmoeller_z_vs_time``):
for each variable and dataset, an individual profile is plotted. If a
reference dataset is defined, also include this dataset and a bias plot
into the figure. Note that if a reference dataset is defined, all input
datasets need to be given on the same horizontal and vertical grid (you
can use the preprocessors :func:`esmvalcore.preprocessor.regrid` and
:func:`esmvalcore.preprocessor.extract_levels` for this). Input data
needs to be 2D with dimensions `time`, `height`/`air_pressure`.
=======
>>>>>>> origin/main
- Variable vs. latitude plot (plot type ``variable_vs_lat``):
for each variable separately, all datasets are plotted in one
single figure. Input data needs to be 1D with single
dimension `latitude`.
needs to be 2D with dimensions `latitude`, `altitude`/`air_pressure`.
.. warning::
Expand All @@ -57,7 +42,19 @@
- 1D profiles (plot type ``1d_profile``): for each variable separately, all
datasets are plotted in one single figure. Input data needs to be 1D with
single dimension `height` / `air_pressure`
single dimension `altitude` / `air_pressure`
- Variable vs. latitude plot (plot type ``variable_vs_lat``):
for each variable separately, all datasets are plotted in one
single figure. Input data needs to be 1D with single
dimension `latitude`.
- Hovmoeller Z vs time (plot type ``hovmoeller_z_vs_time``): for each
variable and dataset, an individual profile is plotted. If a reference
dataset is defined, also include this dataset and a bias plot into the
figure. Note that if a reference dataset is defined, all input datasets
need to be given on the same horizontal and vertical grid (you can use
the preprocessors :func:`esmvalcore.preprocessor.regrid` and
:func:`esmvalcore.preprocessor.extract_levels` for this). Input data
needs to be 2D with dimensions `time`, `altitude`/`air_pressure`.
Author
------
Expand All @@ -81,7 +78,7 @@
plots: dict, optional
Plot types plotted by this diagnostic (see list above). Dictionary keys
must be ``timeseries``, ``annual_cycle``, ``map``, ``zonal_mean_profile``,
``1d_profile`` or ``hovmoeller_z_vs_time``.
``1d_profile``, ``variable_vs_lat``, or ``hovmoeller_z_vs_time``.
Dictionary values are dictionaries used as options for the corresponding
plot. The allowed options for the different plot types are given below.
plot_filename: str, optional
Expand Down Expand Up @@ -138,9 +135,9 @@
to something like ``ambiguous_project``. Examples: ``title: 'Awesome Plot
of {long_name}'``, ``xlabel: '{short_name}'``, ``xlim: [0, 5]``.
time_format: str, optional (default: None)
:func:`~datetime.strftime` format string that is used to format the time
axis using :class:`matplotlib.dates.DateFormatter`. If ``None``, use the
default formatting imposed by the iris plotting function.
:func:`~datetime.datetime.strftime` format string that is used to format
the time axis using :class:`matplotlib.dates.DateFormatter`. If ``None``,
use the default formatting imposed by the iris plotting function.
Configuration options for plot type ``annual_cycle``
----------------------------------------------------
Expand Down Expand Up @@ -292,7 +289,7 @@
plot_func: str, optional (default: 'contourf')
Plot function used to plot the profiles. Must be a function of
:mod:`iris.plot` that supports plotting of 2D cubes with coordinates
latitude and height/air_pressure.
latitude and altitude/air_pressure.
plot_kwargs: dict, optional
Optional keyword arguments for the plot function defined by ``plot_func``.
Dictionary keys are elements identified by ``facet_used_for_labels`` or
Expand Down Expand Up @@ -334,6 +331,75 @@
coordinates. Can be adjusted to avoid overlap with the figure. Only
relevant if ``show_stats: true``.
Configuration options for plot type ``1d_profile``
--------------------------------------------------
aspect_ratio: float, optional (default: 1.5)
Aspect ratio of the plot. The default value results in a slender upright
plot.
gridline_kwargs: dict, optional
Optional keyword arguments for grid lines. By default, ``color: lightgrey,
alpha: 0.5`` are used. Use ``gridline_kwargs: false`` to not show grid
lines.
legend_kwargs: dict, optional
Optional keyword arguments for :func:`matplotlib.pyplot.legend`. Use
``legend_kwargs: false`` to not show legends.
log_x: bool, optional (default: False)
Use logarithmic X-axis. Note that for the logarithmic x axis tickmarks are
set so that minor tickmarks show up. Setting of individual tickmarks by
pyplot_kwargs is not recommended in this case.
log_y: bool, optional (default: True)
Use logarithmic Y-axis.
plot_kwargs: dict, optional
Optional keyword arguments for :func:`iris.plot.plot`. Dictionary keys are
elements identified by ``facet_used_for_labels`` or ``default``, e.g.,
``CMIP6`` if ``facet_used_for_labels: project`` or ``historical`` if
``facet_used_for_labels: exp``. Dictionary values are dictionaries used as
keyword arguments for :func:`iris.plot.plot`. String arguments can include
facets in curly brackets which will be derived from the corresponding
dataset, e.g., ``{project}``, ``{short_name}``, ``{exp}``. Examples:
``default: {linestyle: '-', label: '{project}'}, CMIP6: {color: red,
linestyle: '--'}, OBS: {color: black}``.
pyplot_kwargs: dict, optional
Optional calls to functions of :mod:`matplotlib.pyplot`. Dictionary keys
are functions of :mod:`matplotlib.pyplot`. Dictionary values are used as
single argument for these functions. String arguments can include facets in
curly brackets which will be derived from the datasets plotted in the
corresponding plot, e.g., ``{short_name}``, ``{exp}``. Facets like
``{project}`` that vary between the different datasets will be transformed
to something like ``ambiguous_project``. Examples: ``title: 'Awesome Plot
of {long_name}'``, ``xlabel: '{short_name}'``, ``xlim: [0, 5]``.
show_y_minor_ticklabels: bool, optional (default: False)
Show tick labels for the minor ticks on the Y axis.
Configuration options for plot type ``variable_vs_lat``
-------------------------------------------------------
gridline_kwargs: dict, optional
Optional keyword arguments for grid lines. By default, ``color: lightgrey,
alpha: 0.5`` are used. Use ``gridline_kwargs: false`` to not show grid
lines.
legend_kwargs: dict, optional
Optional keyword arguments for :func:`matplotlib.pyplot.legend`. Use
``legend_kwargs: false`` to not show legends.
plot_kwargs: dict, optional
Optional keyword arguments for :func:`iris.plot.plot`. Dictionary keys are
elements identified by ``facet_used_for_labels`` or ``default``, e.g.,
``CMIP6`` if ``facet_used_for_labels: project`` or ``historical`` if
``facet_used_for_labels: exp``. Dictionary values are dictionaries used as
keyword arguments for :func:`iris.plot.plot`. String arguments can include
facets in curly brackets which will be derived from the corresponding
dataset, e.g., ``{project}``, ``{short_name}``, ``{exp}``. Examples:
``default: {linestyle: '-', label: '{project}'}, CMIP6: {color: red,
linestyle: '--'}, OBS: {color: black}``.
pyplot_kwargs: dict, optional
Optional calls to functions of :mod:`matplotlib.pyplot`. Dictionary keys
are functions of :mod:`matplotlib.pyplot`. Dictionary values are used as
single argument for these functions. String arguments can include facets in
curly brackets which will be derived from the datasets plotted in the
corresponding plot, e.g., ``{short_name}``, ``{exp}``. Facets like
``{project}`` that vary between the different datasets will be transformed
to something like ``ambiguous_project``. Examples: ``title: 'Awesome Plot
of {long_name}'``, ``xlabel: '{short_name}'``, ``xlim: [0, 5]``.
Configuration options for plot type ``hovmoeller_z_vs_time``
------------------------------------------------------------
cbar_label: str, optional (default: '{short_name} [{units}]')
Expand Down Expand Up @@ -370,7 +436,7 @@
plot_func: str, optional (default: 'contourf')
Plot function used to plot the profiles. Must be a function of
:mod:`iris.plot` that supports plotting of 2D cubes with coordinates
latitude and height/air_pressure.
latitude and altitude/air_pressure.
plot_kwargs: dict, optional
Optional keyword arguments for the plot function defined by ``plot_func``.
Dictionary keys are elements identified by ``facet_used_for_labels`` or
Expand Down Expand Up @@ -412,78 +478,9 @@
coordinates. Can be adjusted to avoid overlap with the figure. Only
relevant if ``show_stats: true``.
time_format: str, optional (default: None)
:func:`~datetime.strftime` format string that is used to format the time
axis using :class:`matplotlib.dates.DateFormatter`. If ``None``, use the
default formatting imposed by the iris plotting function.
Configuration options for plot type ``1d_profile``
--------------------------------------------------
aspect_ratio: float, optional (default: 1.5)
Aspect ratio of the plot. The default value results in a slender upright
plot.
gridline_kwargs: dict, optional
Optional keyword arguments for grid lines. By default, ``color: lightgrey,
alpha: 0.5`` are used. Use ``gridline_kwargs: false`` to not show grid
lines.
legend_kwargs: dict, optional
Optional keyword arguments for :func:`matplotlib.pyplot.legend`. Use
``legend_kwargs: false`` to not show legends.
log_x: bool, optional (default: False)
Use logarithmic X-axis. Note that for the logarithmic x axis tickmarks are
set so that minor tickmarks show up. Setting of individual tickmarks by
pyplot_kwargs is not recommended in this case.
log_y: bool, optional (default: True)
Use logarithmic Y-axis.
plot_kwargs: dict, optional
Optional keyword arguments for :func:`iris.plot.plot`. Dictionary keys are
elements identified by ``facet_used_for_labels`` or ``default``, e.g.,
``CMIP6`` if ``facet_used_for_labels: project`` or ``historical`` if
``facet_used_for_labels: exp``. Dictionary values are dictionaries used as
keyword arguments for :func:`iris.plot.plot`. String arguments can include
facets in curly brackets which will be derived from the corresponding
dataset, e.g., ``{project}``, ``{short_name}``, ``{exp}``. Examples:
``default: {linestyle: '-', label: '{project}'}, CMIP6: {color: red,
linestyle: '--'}, OBS: {color: black}``.
pyplot_kwargs: dict, optional
Optional calls to functions of :mod:`matplotlib.pyplot`. Dictionary keys
are functions of :mod:`matplotlib.pyplot`. Dictionary values are used as
single argument for these functions. String arguments can include facets in
curly brackets which will be derived from the datasets plotted in the
corresponding plot, e.g., ``{short_name}``, ``{exp}``. Facets like
``{project}`` that vary between the different datasets will be transformed
to something like ``ambiguous_project``. Examples: ``title: 'Awesome Plot
of {long_name}'``, ``xlabel: '{short_name}'``, ``xlim: [0, 5]``.
show_y_minor_ticklabels: bool, optional (default: False)
Show tick labels for the minor ticks on the Y axis.
Configuration options for plot type ``variable_vs_lat``
-------------------------------------------------------
gridline_kwargs: dict, optional
Optional keyword arguments for grid lines. By default, ``color: lightgrey,
alpha: 0.5`` are used. Use ``gridline_kwargs: false`` to not show grid
lines.
legend_kwargs: dict, optional
Optional keyword arguments for :func:`matplotlib.pyplot.legend`. Use
``legend_kwargs: false`` to not show legends.
plot_kwargs: dict, optional
Optional keyword arguments for :func:`iris.plot.plot`. Dictionary keys are
elements identified by ``facet_used_for_labels`` or ``default``, e.g.,
``CMIP6`` if ``facet_used_for_labels: project`` or ``historical`` if
``facet_used_for_labels: exp``. Dictionary values are dictionaries used as
keyword arguments for :func:`iris.plot.plot`. String arguments can include
facets in curly brackets which will be derived from the corresponding
dataset, e.g., ``{project}``, ``{short_name}``, ``{exp}``. Examples:
``default: {linestyle: '-', label: '{project}'}, CMIP6: {color: red,
linestyle: '--'}, OBS: {color: black}``.
pyplot_kwargs: dict, optional
Optional calls to functions of :mod:`matplotlib.pyplot`. Dictionary keys
are functions of :mod:`matplotlib.pyplot`. Dictionary values are used as
single argument for these functions. String arguments can include facets in
curly brackets which will be derived from the datasets plotted in the
corresponding plot, e.g., ``{short_name}``, ``{exp}``. Facets like
``{project}`` that vary between the different datasets will be transformed
to something like ``ambiguous_project``. Examples: ``title: 'Awesome Plot
of {long_name}'``, ``xlabel: '{short_name}'``, ``xlim: [0, 5]``.
:func:`~datetime.datetime.strftime` format string that is used to format
the time axis using :class:`matplotlib.dates.DateFormatter`. If ``None``,
use the default formatting imposed by the iris plotting function.
.. hint::
Expand Down Expand Up @@ -757,10 +754,10 @@ def _add_stats(self, plot_type, axes, dim_coords, dataset,
# Different options for the different plots types
fontsize = 6.0
y_pos = 0.95
if plot_type == 'map':
x_pos_bias = self.plots[plot_type]['x_pos_stats_bias']
x_pos = self.plots[plot_type]['x_pos_stats_avg']
elif plot_type in ['zonal_mean_profile', 'hovmoeller_z_vs_time']:
if all([
'x_pos_stats_avg' in self.plots[plot_type],
'x_pos_stats_bias' in self.plots[plot_type],
]):
x_pos_bias = self.plots[plot_type]['x_pos_stats_bias']
x_pos = self.plots[plot_type]['x_pos_stats_avg']
else:
Expand Down Expand Up @@ -1295,14 +1292,14 @@ def _plot_hovmoeller_z_vs_time_without_ref(self, plot_func, dataset):
axes = fig.add_subplot()
plot_kwargs = self._get_plot_kwargs(plot_type, dataset)
plot_kwargs['axes'] = axes
plot_zonal_mean_profile = plot_func(cube, **plot_kwargs)
plot_hovmoeller = plot_func(cube, **plot_kwargs)

# Print statistics if desired
self._add_stats(plot_type, axes, dim_coords_dat, dataset)

# Setup colorbar
fontsize = self.plots[plot_type]['fontsize']
colorbar = fig.colorbar(plot_zonal_mean_profile,
colorbar = fig.colorbar(plot_hovmoeller,
ax=axes,
**self._get_cbar_kwargs(plot_type))
colorbar.set_label(self._get_cbar_label(plot_type, dataset),
Expand Down Expand Up @@ -2126,8 +2123,8 @@ def compute(self):
self.create_map_plot(datasets)
self.create_zonal_mean_profile_plot(datasets)
self.create_1d_profile_plot(datasets)
self.create_hovmoeller_z_vs_time_plot(datasets)
self.create_variable_vs_lat_plot(datasets)
self.create_hovmoeller_z_vs_time_plot(datasets)


def main():
Expand Down

0 comments on commit 1be2106

Please sign in to comment.