Skip to content

Commit

Permalink
add reference datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
lukruh committed Sep 5, 2023
1 parent bdb9b62 commit db69135
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 100 deletions.
50 changes: 23 additions & 27 deletions esmvaltool/diag_scripts/monitor/multi_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ def _plot_zonal_mean_profile_without_ref(self, plot_func, dataset):
return (plot_path, {netcdf_path: cube})

def _plot_hovmoeller_time_vs_lat_or_lon_with_ref(self, plot_func, dataset,
ref_dataset):
ref_dataset):
"""Plot the hovmoeller profile for single dataset with reference."""
plot_type = 'hovmoeller_time_vs_lat_or_lon'
logger.info("Plotting zonal mean profile with reference dataset"
Expand Down Expand Up @@ -1236,18 +1236,18 @@ def _plot_hovmoeller_time_vs_lat_or_lon_with_ref(self, plot_func, dataset,
plot_kwargs['axes'] = axes_data
plot_data = plot_func(cube, **plot_kwargs)
axes_data.set_title(self._get_label(dataset), pad=3.0)
z_coord = cube.coord(axis='Z')
axes_data.set_ylabel(f'{z_coord.long_name} [{z_coord.units}]')
if self.plots[plot_type]['log_y']:
axes_data.set_yscale('log')
axes_data.get_yaxis().set_major_formatter(
FormatStrFormatter('%.1f'))
if self.plots[plot_type]['show_y_minor_ticklabels']:
axes_data.get_yaxis().set_minor_formatter(
FormatStrFormatter('%.1f'))
else:
axes_data.get_yaxis().set_minor_formatter(NullFormatter())
self._add_stats(plot_type, axes_data, dim_coords_dat, dataset)
axes_data.set_ylabel('Time / Year')
if "latitude" in dim_coords_dat:
axes_data.set_xlabel('Latitude / °N')
elif "longitude" in dim_coords_dat:
axes_data.set_xlabel('Longitude / °E')
plt.gca().yaxis.set_major_locator(mdates.YearLocator())
plt.gca().yaxis.set_major_formatter(mdates.DateFormatter("%Y"))
if self.plots[plot_type]['show_y_minor_ticks']:
plt.gca().yaxis.set_minor_locator(mdates.MonthLocator())
if self.plots[plot_type]['show_x_minor_ticks']:
plt.gca().xaxis.set_minor_locator(AutoMinorLocator())
# self._add_stats(plot_type, axes_data, dim_coords_dat, dataset)

# Plot reference dataset (top right)
# Note: make sure to use the same vmin and vmax than the top left
Expand All @@ -1261,7 +1261,7 @@ def _plot_hovmoeller_time_vs_lat_or_lon_with_ref(self, plot_func, dataset,
plot_ref = plot_func(ref_cube, **plot_kwargs)
axes_ref.set_title(self._get_label(ref_dataset), pad=3.0)
plt.setp(axes_ref.get_yticklabels(), visible=False)
self._add_stats(plot_type, axes_ref, dim_coords_ref, ref_dataset)
# self._add_stats(plot_type, axes_ref, dim_coords_ref, ref_dataset)

# Add colorbar(s)
self._add_colorbar(plot_type, plot_data, plot_ref, axes_data,
Expand All @@ -1279,8 +1279,11 @@ def _plot_hovmoeller_time_vs_lat_or_lon_with_ref(self, plot_func, dataset,
f"{self._get_label(dataset)} - {self._get_label(ref_dataset)}",
pad=3.0,
)
axes_bias.set_xlabel('latitude [°N]')
axes_bias.set_ylabel(f'{z_coord.long_name} [{z_coord.units}]')
axes_bias.set_ylabel('Time / Year')
if "latitude" in dim_coords_dat:
axes_bias.set_xlabel('Latitude / °N')
elif "longitude" in dim_coords_dat:
axes_bias.set_xlabel('Longitude / °E')
cbar_kwargs_bias = self._get_cbar_kwargs(plot_type, bias=True)
cbar_bias = fig.colorbar(plot_bias, ax=axes_bias,
**cbar_kwargs_bias)
Expand All @@ -1289,16 +1292,14 @@ def _plot_hovmoeller_time_vs_lat_or_lon_with_ref(self, plot_func, dataset,
fontsize=fontsize,
)
cbar_bias.ax.tick_params(labelsize=fontsize)
self._add_stats(plot_type, axes_bias, dim_coords_dat, dataset,
ref_dataset)

# Customize plot
fig.suptitle(f"{dataset['long_name']} ({dataset['start_year']}-"
f"{dataset['end_year']})")
self._process_pyplot_kwargs(plot_type, dataset)

# Rasterization
if self.plots[plot_type]['rasterize']:
if self.plots[plot_type]['rasterize']: # TODO: not working?
self._set_rasterized([axes_data, axes_ref, axes_bias])

# File paths
Expand Down Expand Up @@ -1441,6 +1442,8 @@ def _get_multi_dataset_facets(datasets):
@staticmethod
def _get_reference_dataset(datasets, short_name):
"""Extract reference dataset."""
print("MEMEMME")
print(datasets)
ref_datasets = [d for d in datasets if
d.get('reference_for_monitor_diags', False)]
if len(ref_datasets) > 1:
Expand Down Expand Up @@ -1915,13 +1918,6 @@ def create_hovmoeller_time_vs_lat_or_lon_plot(self, datasets, short_name):
)
ancestors.append(ref_dataset['filename'])

# If statistics are shown add a brief description to the caption
# TODO: update caption
if self.plots[plot_type]['show_stats']:
caption += (
" The number in the top left corner corresponds to the "
"spatial mean (weighted by grid cell areas).")

# Save plot
plt.savefig(plot_path, **self.cfg['savefig_kwargs'])
logger.info("Wrote %s", plot_path)
Expand Down Expand Up @@ -1955,7 +1951,7 @@ def compute(self):
self.create_zonal_mean_profile_plot(datasets, short_name)
self.create_1d_profile_plot(datasets, short_name)
self.create_hovmoeller_time_vs_lat_or_lon_plot(
datasets,
datasets,
short_name
)

Expand Down
128 changes: 55 additions & 73 deletions esmvaltool/recipes/monitor/recipe_hovmoeller_time_vs_lat_or_lon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,6 @@ preprocessors:

diagnostics:

# Specific instructions:
#
# The following 4 diagnostic blocks need to produce sensible plots with the
# same code. We recommend to comment them in one-by-one so only one is active
# at a time. You can use tip (6) from above to only run one diagnostic.
# Remember to re-run the entire recipe if you change the recipe file.
#
# You can copy the method 'create_zonal_mean_profile_plot' to a new method
# 'create_hovmoeller_time_vs_lat_or_lon_plot' in the diagnostic script and
# relevant other methods to get started.
#
# Remember to also add some documentation on the new plot type to the top of
# the diagnostic file.

time_vs_lat_without_ref: # this is an arbitrary name
# Should create a single panel with a time vs. latitude contour plot
variables:
Expand All @@ -77,67 +63,63 @@ diagnostics:
plot_filename: '{plot_type}_{real_name}_{dataset}_{mip}'
plots:
hovmoeller_time_vs_lat_or_lon:
common_cbar: true
# plot_func: contourf
# common_cbar: true
# show_x_minor_ticks: true
# show_y_minor_ticks: true
# rasterize: true
plot_func: contourf
# plot_kwargs:
# levels: 20

# time_vs_lat_with_ref: # this is an arbitrary name
# # Should create a three-panel time vs. latitude contour plot for the two
# # datasets and the corresponding bias
# # see https://esmvaltool.dkrz.de/shared/esmvaltool/stable_release/recipe_monitor_with_refs_20230704_163457/plots/plot_zonal_mean_profiles_with_references/plot/zonal_mean_profile_ta_EC-Earth3_Amon.png
# variables:
# tas:
# preprocessor: zonal_mean
# mip: Amon
# timerange: '20000101/20030101'
# additional_datasets:
# - {project: ICON, dataset: ICON, exp: icon-2.6.1_atm_amip_R2B5_r1v1i1p1l1f1}
# - {project: native6, dataset: ERA5, type: reanaly, version: v1, tier: 3}
# scripts:
# plot: # this is an arbitrary name
# script: /work/bd1179/esmvaltool_hackathon/diag_scripts/multi_datasets.py # MODIFY!!!
# plot_folder: '{plot_dir}'
# plot_filename: '{plot_type}_{real_name}_{dataset}_{mip}'
# plots:
# hovmoeller_time_vs_lat_or_lon:
# common_cbar: true
time_vs_lat_with_ref:
variables:
tas:
preprocessor: zonal_mean
mip: Amon
timerange: '20000101/20030101'
additional_datasets:
- {project: ICON, dataset: ICON, exp: icon-2.6.1_atm_amip_R2B5_r1v1i1p1l1f1}
- {project: native6, dataset: ERA5, type: reanaly, version: v1, tier: 3, reference_for_monitor_diags: true}
scripts:
plot:
script: monitor/multi_datasets.py
plot_folder: '{plot_dir}'
plot_filename: '{plot_type}_{real_name}_{dataset}_{mip}'
plots:
hovmoeller_time_vs_lat_or_lon:
common_cbar: true

# time_vs_lon_without_ref: # this is an arbitrary name
# # Should create a single panel with a time vs. longitude contour plot
# variables:
# tas:
# preprocessor: meridional_mean
# mip: Amon
# timerange: '20000101/20030101'
# additional_datasets:
# - {project: ICON, dataset: ICON, exp: icon-2.6.1_atm_amip_R2B5_r1v1i1p1l1f1}
# scripts:
# plot: # this is an arbitrary name
# script: /work/bd1179/esmvaltool_hackathon/diag_scripts/multi_datasets.py # MODIFY!!!
# plot_folder: '{plot_dir}'
# plot_filename: '{plot_type}_{real_name}_{dataset}_{mip}'
# plots:
# hovmoeller_time_vs_lat_or_lon:
# common_cbar: true
time_vs_lon_without_ref:
variables:
tas:
preprocessor: meridional_mean
mip: Amon
timerange: '20000101/20030101'
additional_datasets:
- {project: ICON, dataset: ICON, exp: icon-2.6.1_atm_amip_R2B5_r1v1i1p1l1f1}
scripts:
plot:
script: monitor/multi_datasets.py
plot_folder: '{plot_dir}'
plot_filename: '{plot_type}_{real_name}_{dataset}_{mip}'
plots:
hovmoeller_time_vs_lat_or_lon:
common_cbar: true

# time_vs_lon_with_ref: # this is an arbitrary name
# # Should create a three-panel time vs. longitude contour plot for the two
# # datasets and the corresponding bias
# # see https://esmvaltool.dkrz.de/shared/esmvaltool/stable_release/recipe_monitor_with_refs_20230704_163457/plots/plot_zonal_mean_profiles_with_references/plot/zonal_mean_profile_ta_EC-Earth3_Amon.png
# variables:
# tas:
# preprocessor: meridional_mean
# mip: Amon
# timerange: '20000101/20030101'
# additional_datasets:
# - {project: ICON, dataset: ICON, exp: icon-2.6.1_atm_amip_R2B5_r1v1i1p1l1f1}
# - {project: native6, dataset: ERA5, type: reanaly, version: v1, tier: 3}
# scripts:
# plot: # this is an arbitrary name
# script: /work/bd1179/esmvaltool_hackathon/diag_scripts/multi_datasets.py # MODIFY!!!
# plot_folder: '{plot_dir}'
# plot_filename: '{plot_type}_{real_name}_{dataset}_{mip}'
# plots:
# hovmoeller_time_vs_lat_or_lon:
# common_cbar: true
time_vs_lon_with_ref:
variables:
tas:
preprocessor: meridional_mean
mip: Amon
timerange: '20000101/20030101'
additional_datasets:
- {project: ICON, dataset: ICON, exp: icon-2.6.1_atm_amip_R2B5_r1v1i1p1l1f1}
- {project: native6, dataset: ERA5, type: reanaly, version: v1, tier: 3, reference_for_monitor_diags: true}
scripts:
plot:
script: monitor/multi_datasets.py
plot_folder: '{plot_dir}'
plot_filename: '{plot_type}_{real_name}_{dataset}_{mip}'
plots:
hovmoeller_time_vs_lat_or_lon:
common_cbar: true

0 comments on commit db69135

Please sign in to comment.