-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfigures_intercomparison_5.py
More file actions
129 lines (118 loc) · 3.9 KB
/
Copy pathfigures_intercomparison_5.py
File metadata and controls
129 lines (118 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Script to compare GLEAM4 to alternative datasets
# Author: Olivier Bonte, Ghent University, olivier.bonte@ugent.be
# October 2025
# %% Imports and paths
import importlib
import matplotlib.pyplot as plt
import numpy as np
import xarray as xr
import conf
import functions
importlib.reload(conf)
importlib.reload(functions)
from conf import (
E_plot_dict,
color_dict_pattern,
folder_figures,
folder_processed,
model_list_pattern,
model_version,
ocean_color,
yearly_averages_file_comparison,
)
from functions import make_custom_cmap
# %%
da_comp = xr.open_dataarray(folder_processed / yearly_averages_file_comparison)
# da_comp = xr.open_dataarray(folder_processed / "comparison_temp.nc")
# GLEAM4 - other products
model_list_others = [p for p in model_list_pattern if p != "GLEAM4"]
# other_products_list = list(da_comp.product.to_pandas().drop("GLEAM4"))
da_comp_diff = da_comp.sel(product="GLEAM4") - da_comp.sel(product=model_list_others)
#
# %% Figure 5: global comparison plot
font_settings = {"size": 6}
plt.rc("font", **font_settings)
fig = plt.figure(
figsize=(7, 1 / 2 * 11.69), layout="constrained"
) # , layout="constrained") # tight_layout=True)
ax = fig.subplot_mosaic(
"""
AADDG
BBEEG
CCFFG
""",
)
# A -> C: the other products
cmap_E = make_custom_cmap(E_plot_dict["vmin"], E_plot_dict["vmax"])
for letter, product in zip(["A", "B", "C"], model_list_others):
img_E = da_comp.sel(product=product).plot.imshow(
ax=ax[letter],
add_colorbar=False,
cmap=cmap_E,
vmin=E_plot_dict["vmin"],
vmax=E_plot_dict["vmax"],
)
# Only longitude for bottom plot
if letter != "C":
ax[letter].tick_params(labelbottom=False)
ax[letter].set_xlabel("")
# ax[letter].label_outer()
else:
ax[letter].set_xlabel("Longitude")
# Always latitude set
ax[letter].set_ylabel("Latitude")
ax[letter].set_title("")
# Add model name as text
ax[letter].text(-170, -65, product, color=color_dict_pattern[product])
# Set ocean color
ax[letter].set_facecolor(ocean_color)
# D -> F: GLEAM4 - other products
for letter, product in zip(["D", "E", "F"], model_list_others):
img_diff = da_comp_diff.sel(product=product).plot.imshow(
ax=ax[letter], add_colorbar=False, cmap="RdBu", vmin=-300, vmax=300
)
if letter != "F":
ax[letter].tick_params(labelbottom=False)
ax[letter].set_xlabel("")
else:
ax[letter].set_xlabel("Longitude")
ax[letter].set_ylabel("")
ax[letter].tick_params(labelleft=False)
ax[letter].set_title("")
# Add models name as text
ax[letter].text(-170, -65, "GLEAM4 -", color=color_dict_pattern["GLEAM4"])
ax[letter].text(-108, -65, product, color=color_dict_pattern[product])
# Set ocean color
ax[letter].set_facecolor(ocean_color)
# Adding colorbars
# Key tip: use "constrained layout"
# https://matplotlib.org/stable/users/explain/axes/colorbar_placement.html
fig.colorbar(img_E, ax=ax["C"], location="bottom", shrink=0.8, label="[mm/year]")
fig.colorbar(img_diff, ax=ax["F"], location="bottom", shrink=0.8, label="[mm/year]")
# G: mean over longitudes
for product in model_list_pattern:
da_comp.sel(product=product).mean(dim="lon").plot(
y="lat",
ax=ax["G"],
color=color_dict_pattern[product],
label=product,
linewidth=1,
)
legend = ax["G"].legend(frameon=False, handlelength=0)
for text, product in zip(legend.get_texts(), model_list_pattern):
text.set_color(color_dict_pattern[product])
ax["G"].set_title("")
ax["G"].set_ylabel("Latitude")
ax["G"].set_xlabel("[mm/year]")
# Set title for entire figure
fig.suptitle(f"{model_version}: {da_comp.attrs['years_considered']}")
# Save to high quality png
fig.savefig(
folder_figures
/ (
f"{model_version}_global_product_intercomparison_fig_5_"
f"{da_comp.attrs['years_considered']}.png"
),
dpi=900,
)
# %%