From f02e29563c18659d2757edf917586963dc7c43e4 Mon Sep 17 00:00:00 2001 From: Aytac Pacal Date: Tue, 5 Nov 2024 17:34:08 +0100 Subject: [PATCH 1/3] Update seaborn diagnostics for scatter plot - Modified the seaborn_diag.py for jointplot - Modified the recipe_seaborn.yml to plot the figures - Added Pacal, Aytac to config-references.yml --- esmvaltool/config-references.yml | 5 + esmvaltool/diag_scripts/seaborn_diag.py | 13 +- esmvaltool/recipes/recipe_seaborn.yml | 213 +++++++++++++++++++++++- 3 files changed, 225 insertions(+), 6 deletions(-) diff --git a/esmvaltool/config-references.yml b/esmvaltool/config-references.yml index 199dc671e0..580ab4f5c2 100644 --- a/esmvaltool/config-references.yml +++ b/esmvaltool/config-references.yml @@ -311,6 +311,11 @@ authors: institute: DLR, Germany orcid: github: jeremykraftdlr + pacal_aytac: + name: Pacal, Aytac + institute: DLR, Germany + orcid: + github: aytacpacal krasting_john: name: Krasting, John institute: NOAA, USA diff --git a/esmvaltool/diag_scripts/seaborn_diag.py b/esmvaltool/diag_scripts/seaborn_diag.py index aa6ca1b504..b02ec6c10d 100644 --- a/esmvaltool/diag_scripts/seaborn_diag.py +++ b/esmvaltool/diag_scripts/seaborn_diag.py @@ -148,6 +148,9 @@ def _create_plot( plot_func_str, _get_str_from_kwargs(plot_kwargs), ) + if plot_func_str in ['jointplot']: + data_frame = data_frame.reset_index() + plot_obj = plot_func(data=data_frame, **plot_kwargs) # Adjust plot appearance @@ -171,7 +174,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) + else: + plt.suptitle(cfg['suptitle'], y=1.05) if cfg['legend_title'] is not None: _set_legend_title(plot_obj, cfg['legend_title']) @@ -443,6 +449,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 workaround + # 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 " diff --git a/esmvaltool/recipes/recipe_seaborn.yml b/esmvaltool/recipes/recipe_seaborn.yml index 983efae0be..08f90f7501 100644 --- a/esmvaltool/recipes/recipe_seaborn.yml +++ b/esmvaltool/recipes/recipe_seaborn.yml @@ -13,6 +13,9 @@ documentation: authors: - schlund_manuel + - debeire_kevin + - kraft_jeremy + - pacal_aytac maintainer: - schlund_manuel @@ -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 @@ -51,10 +51,213 @@ preprocessors: - Equatorial.Indic-Ocean convert_units: units: mm day-1 + + extract_regions_pr: + regrid_time: ®rid_time + calendar: standard + frequency: mon + regrid: + target_grid: 5x5 + scheme: linear + extract_shape: + shapefile: ar6 + crop: true + decomposed: true + ids: + Name: ®ions_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: ®ion_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 + 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 + 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: From d51c422a7504b473fe13046614f6d094550041eb Mon Sep 17 00:00:00 2001 From: Aytac Pacal Date: Thu, 7 Nov 2024 14:10:46 +0100 Subject: [PATCH 2/3] Add ORCID link for author Pacal, Aytac in config-references.yml --- esmvaltool/config-references.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esmvaltool/config-references.yml b/esmvaltool/config-references.yml index 580ab4f5c2..7357f908fc 100644 --- a/esmvaltool/config-references.yml +++ b/esmvaltool/config-references.yml @@ -314,7 +314,7 @@ authors: pacal_aytac: name: Pacal, Aytac institute: DLR, Germany - orcid: + orcid: https://orcid.org/0000-0002-1324-2389 github: aytacpacal krasting_john: name: Krasting, John From d8de7fddd0e01dbe9139582e3ab8b91838240bb2 Mon Sep 17 00:00:00 2001 From: Kevin Debeire Date: Mon, 18 Nov 2024 15:26:37 +0100 Subject: [PATCH 3/3] fix reset_true and diagnostic comment --- esmvaltool/diag_scripts/seaborn_diag.py | 4 +--- esmvaltool/recipes/recipe_seaborn.yml | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/esmvaltool/diag_scripts/seaborn_diag.py b/esmvaltool/diag_scripts/seaborn_diag.py index b02ec6c10d..e55cb1cda7 100644 --- a/esmvaltool/diag_scripts/seaborn_diag.py +++ b/esmvaltool/diag_scripts/seaborn_diag.py @@ -148,8 +148,6 @@ def _create_plot( plot_func_str, _get_str_from_kwargs(plot_kwargs), ) - if plot_func_str in ['jointplot']: - data_frame = data_frame.reset_index() plot_obj = plot_func(data=data_frame, **plot_kwargs) @@ -449,7 +447,7 @@ 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 workaround + 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: diff --git a/esmvaltool/recipes/recipe_seaborn.yml b/esmvaltool/recipes/recipe_seaborn.yml index 08f90f7501..1e6967fb27 100644 --- a/esmvaltool/recipes/recipe_seaborn.yml +++ b/esmvaltool/recipes/recipe_seaborn.yml @@ -160,6 +160,7 @@ diagnostics: marker: . hue: dataset add_aux_coords: true + reset_index: true legend_title: Model plot_object_methods: set_axis_labels: @@ -197,6 +198,7 @@ diagnostics: marker: . hue: dataset add_aux_coords: true + reset_index: true legend_title: Model plot_object_methods: set_axis_labels: