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

Updates to recipe_seaborn.yml and seaborn diagnostic #3808

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions esmvaltool/config-references.yml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ authors:
institute: DLR, Germany
orcid:
github: jeremykraftdlr
pacal_aytac:
name: Pacal, Aytac
institute: DLR, Germany
orcid: https://orcid.org/0000-0002-1324-2389
github: aytacpacal
krasting_john:
name: Krasting, John
institute: NOAA, USA
Expand Down
11 changes: 10 additions & 1 deletion esmvaltool/diag_scripts/seaborn_diag.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def _create_plot(
plot_func_str,
_get_str_from_kwargs(plot_kwargs),
)

plot_obj = plot_func(data=data_frame, **plot_kwargs)

# Adjust plot appearance
Expand All @@ -171,7 +172,10 @@ def _create_plot(
getattr(plot_obj, func_name)(func_args)
if cfg['suptitle'] is not None:
logger.debug("Setting `suptitle='%s'`", cfg['suptitle'])
plt.suptitle(cfg['suptitle'], y=1.05)
if plot_func_str in ['jointplot']:
plt.suptitle(cfg['suptitle'].format(data_frame["shape_id"].unique()[0]), y=1.05)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause the diagnostic to fail if no shape_id is present. Is this change necessary because you created a multi-panel plot (as far as I understand, this is not possible with jointplot)? If you need such a change, it would be better to hardcode the format string into the recipe Like Plot of {shape_id} and then let the diagnostic fill this. This will be much more general.

else:
plt.suptitle(cfg['suptitle'], y=1.05)
if cfg['legend_title'] is not None:
_set_legend_title(plot_obj, cfg['legend_title'])

Expand Down Expand Up @@ -443,6 +447,11 @@ def _set_legend_title(plot_obj, legend_title: str) -> None:
legend = plot_obj.get_legend()
elif hasattr(plot_obj, 'legend'): # FacetGrid, PairGrid
legend = plot_obj.legend
elif isinstance(plot_obj, sns.axisgrid.JointGrid): # JointGrid
# Manually create a legend if needed in JointGrid
handles, labels = plot_obj.ax_joint.get_legend_handles_labels()
if handles and labels:
legend = plot_obj.ax_joint.legend(handles=handles, labels=labels, title=legend_title)
else:
raise ValueError(
f"Cannot set legend title, `{type(plot_obj).__name__}` does not "
Expand Down
215 changes: 210 additions & 5 deletions esmvaltool/recipes/recipe_seaborn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ documentation:

authors:
- schlund_manuel
- debeire_kevin
- kraft_jeremy
- pacal_aytac

maintainer:
- schlund_manuel
Expand All @@ -26,13 +29,10 @@ documentation:
- isenes3
- usmile


preprocessors:

zonal_mean:
zonal_statistics:
operator: mean

zonal_statistics:
operator: mean
extract_ar6_regions:
regrid:
target_grid: 5x5
Expand All @@ -51,10 +51,215 @@ preprocessors:
- Equatorial.Indic-Ocean
convert_units:
units: mm day-1

extract_regions_pr:
regrid_time: &regrid_time
calendar: standard
frequency: mon
regrid:
target_grid: 5x5
scheme: linear
extract_shape:
shapefile: ar6
crop: true
decomposed: true
ids:
Name: &regions_to_regrid
- N.Europe
- West&Central-Europe
- Mediterranean
- E.Europe
- Caribbean
- E.Antarctica
convert_units:
units: mm day-1

extract_regions_clivi:
regrid_time: *regrid_time
regrid:
target_grid: 5x5
scheme: linear
extract_shape:
shapefile: ar6
crop: true
decomposed: true
ids:
Name: *regions_to_regrid
convert_units:
units: g m-2

extract_region_pr_jointplot:
regrid_time: *regrid_time
regrid:
target_grid: 5x5
scheme: linear
extract_shape:
shapefile: ar6
crop: true
decomposed: true
ids:
Name: &region_to_regrid
- N.Europe
convert_units:
units: mm day-1

extract_region_clivi_jointplot:
regrid_time: *regrid_time
regrid:
target_grid: 5x5
scheme: linear
extract_shape:
shapefile: ar6
crop: true
decomposed: true
ids:
Name: *region_to_regrid
convert_units:
units: g m-2

extract_region_clt_jointplot:
regrid_time: *regrid_time
regrid:
target_grid: 5x5
scheme: linear
extract_shape:
shapefile: ar6
crop: true
decomposed: true
ids:
Name: *region_to_regrid

diagnostics:
plot_precipitation_vs_clivi_jointplot:
description: Scatter plot and histograms of precipitation vs. clivi in grid cells for a single region.
variables:
pr:
mip: Amon
preprocessor: extract_region_pr_jointplot
exp: historical
timerange: '1991/2014'
clivi:
mip: Amon
preprocessor: extract_region_clivi_jointplot
exp: historical
timerange: '1991/2014'
additional_datasets:
- {project: CMIP6, dataset: CESM2-WACCM, grid: gn, ensemble: r1i1p1f1}
- {project: CMIP6, dataset: GFDL-ESM4, grid: gr1, ensemble: r1i1p1f1}
- {project: CMIP6, dataset: ACCESS-CM2, grid: gn, ensemble: r1i1p1f1}
- {project: native6, dataset: ERA5, type: reanaly, version: v1, tier: 3}

scripts:
plot:
script: seaborn_diag.py
seaborn_func: jointplot
groupby_facet: dataset
seaborn_kwargs:
x: pr
y: clivi
marker: .
hue: dataset
add_aux_coords: true
reset_index: true
legend_title: Model
plot_object_methods:
set_axis_labels:
xlabel: 'Precipitation [mm/day]'
ylabel: 'Cloud Ice Water Path [g/m^2]'
suptitle: 'Simulated Precipitation vs. Cloud Ice Water Path (1991-2014) in {}'

plot_precipitation_vs_clt_jointplot:
description: Scatter plot and histograms of precipitation vs. cloud area fraction in grid cells for a single region.
variables:
pr:
mip: Amon
preprocessor: extract_region_pr_jointplot
exp: historical
timerange: '1991/2014'
clt:
mip: Amon
preprocessor: extract_region_clt_jointplot
exp: historical
timerange: '1991/2014'
additional_datasets:
- {project: CMIP6, dataset: CESM2-WACCM, grid: gn, ensemble: r1i1p1f1}
- {project: CMIP6, dataset: GFDL-ESM4, grid: gr1, ensemble: r1i1p1f1}
- {project: CMIP6, dataset: ACCESS-CM2, grid: gn, ensemble: r1i1p1f1}
- {project: native6, dataset: ERA5, type: reanaly, version: v1, tier: 3}

scripts:
plot:
script: seaborn_diag.py
seaborn_func: jointplot
groupby_facet: dataset
seaborn_kwargs:
x: pr
y: clt
marker: .
hue: dataset
add_aux_coords: true
reset_index: true
legend_title: Model
plot_object_methods:
set_axis_labels:
xlabel: 'Precipitation [mm/day]'
ylabel: 'Cloud Area fraction [%]'
suptitle: 'Simulated Precipitation vs. Cloud Area fraction (1991-2014) in {}'

plot_precipitation_vs_clivi:
description: Scatter plots precipitation vs. clivi in grid cells
variables:
pr:
mip: Amon
preprocessor: extract_regions_pr
project: CMIP6
exp: historical
timerange: '1991/2014'
clivi:
mip: Amon
preprocessor: extract_regions_clivi
project: CMIP6
exp: historical
timerange: '1991/2014'
additional_datasets:
- {dataset: CESM2-WACCM, grid: gn, ensemble: r1i1p1f1}
- {dataset: GFDL-ESM4, grid: gr1, ensemble: r1i1p1f1}
- {dataset: ACCESS-CM2, grid: gn, ensemble: r1i1p1f1}
- {dataset: ERA5, project: native6, type: reanaly, version: v1, tier: 3}
scripts:
plot:
script: seaborn_diag.py
seaborn_func: relplot
groupby_facet: dataset
seaborn_kwargs:
x: pr
y: clivi
col: shape_id
col_order: *regions_to_regrid
col_wrap: 3
hue: dataset
marker: .
s: 5
facet_kws:
sharey: false
sharex: false
add_aux_coords: true
dropna_kwargs:
axis: 0
how: any
legend_title: Model
plot_object_methods:
set:
xlabel: 'Precipitation [mm/day]'
ylabel: 'Cloud Ice Water Path [g/m^2]'
set_titles: '{col_name}'
seaborn_settings:
style: ticks
rc:
axes.titlepad: 15.0
suptitle: Simulated Precipitation vs. Cloud Ice Water Path (1991-2014)


plot_temperature_vs_lat:
description: Plot air temperature vs. latitude (pressure levels = colors).
variables:
Expand Down