Skip to content

Commit 0bd4a5b

Browse files
refactor: increase font sizes of alphas plots
also relabel E_coal -> E_coll
1 parent e1e5289 commit 0bd4a5b

1 file changed

Lines changed: 142 additions & 3 deletions

File tree

scripts_for_plotting/compare_alphas.py

Lines changed: 142 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@
6161
assert args.pysdm_path2build.is_dir(), f"pysdm_path2build: {args.pysdm_path2build}"
6262
assert args.path4figs.is_dir(), f"path4figs: {args.path4figs}"
6363

64+
# %% font sizes for beautifying plots
65+
SMALL_SIZE = 15
66+
MEDIUM_SIZE = 16
67+
BIG_SIZE = 18.5
68+
69+
plt.rc("font", size=SMALL_SIZE) # controls default text sizes
70+
plt.rc("axes", titlesize=BIG_SIZE) # fontsize of the axes title
71+
plt.rc("axes", labelsize=BIG_SIZE) # fontsize of the x and y labels
72+
plt.rc("xtick", labelsize=MEDIUM_SIZE) # fontsize of the tick labels
73+
plt.rc("ytick", labelsize=MEDIUM_SIZE) # fontsize of the tick labels
74+
plt.rc("legend", fontsize=BIG_SIZE) # legend fontsize
75+
plt.rc("figure", titlesize=BIG_SIZE) # fontsize of the figure title
6476

6577
# %% Load CLEO ensembles
6678
setups = { # (numconc, fixed_coaleffs) : (nsupers_per_gbxs, alphas)
@@ -111,7 +123,7 @@
111123
print(key, f"members={value.ensemble.size}")
112124
print("-------------------------------- ")
113125
# %% Plot Hill figure 4 (top 2 rows only)
114-
fig, axes = plt.subplots(nrows=2, ncols=4, figsize=(16, 5), width_ratios=[5, 5, 5, 4])
126+
fig, axes = plt.subplots(nrows=2, ncols=4, figsize=(21, 5), width_ratios=[5, 5, 5, 4])
115127
gs = axes[0, -1].get_gridspec()
116128
for ax in axes[:, -1]:
117129
ax.remove()
@@ -143,9 +155,10 @@ def get_style(model, fixed_coaleff, alpha):
143155
mdl = "PySDM"
144156
elif model == "cleo":
145157
mdl = "CLEO"
146-
lbl = f"{mdl}, \u03B1={alpha}"
147158
if not fixed_coaleff:
148-
lbl += ", with $E_{coal}$"
159+
lbl = f"{mdl}" + " with $E_{coll}$, " + f"\u03B1={alpha}"
160+
else:
161+
lbl = f"{mdl}, \u03B1={alpha}"
149162

150163
return {"color": c, "linestyle": line, "label": lbl}
151164

@@ -248,4 +261,130 @@ def get_style(model, fixed_coaleff, alpha):
248261
plt.savefig(args.path4figs / "fig4_alphas.pdf", format="pdf", bbox_inches="tight")
249262
plt.show()
250263

264+
# %% Plot different version of Hill figure 4 (top 2 rows only)
265+
fig, axes = plt.subplots(
266+
nrows=5, ncols=2, figsize=(10, 10), height_ratios=[5, 5, 1, 5, 5]
267+
)
268+
gs = axes[2, 1].get_gridspec()
269+
axes[2, 0].remove() # padding axes
270+
for ax in axes[2:, -1]:
271+
ax.remove() # legend axes
272+
axes = [[axes[0, 0], axes[1, 0]], [axes[0, 1], axes[1, 1]], [axes[3, 0], axes[4, 0]]]
273+
legax = fig.add_subplot(gs[2:, -1])
274+
legax.spines[["right", "top", "left", "bottom"]].set_visible(False)
275+
legax.set_xticks([])
276+
legax.set_yticks([])
277+
278+
axes_setups = {
279+
0: {
280+
"numconc": 50,
281+
"nsupers": 256,
282+
"alpha": [0.0, 0.5, 1.0],
283+
"fixed_coaleff": [True, False],
284+
},
285+
1: {
286+
"numconc": 150,
287+
"nsupers": 256,
288+
"alpha": [0.0, 0.5, 1.0],
289+
"fixed_coaleff": [True, False],
290+
},
291+
2: {
292+
"numconc": 300,
293+
"nsupers": 256,
294+
"alpha": [0.0, 0.5, 1.0],
295+
"fixed_coaleff": [True, False],
296+
},
297+
}
298+
299+
handles, labels = [], []
300+
for a in range(len(axes_setups)):
301+
axs = axes[a] # axes for given numconc
302+
numconc = axes_setups[a]["numconc"]
303+
nsupers = axes_setups[a]["nsupers"]
304+
305+
for alpha in axes_setups[a]["alpha"]:
306+
for fixed_coaleff in axes_setups[a]["fixed_coaleff"]:
307+
label = led.get_label(is_precip, fixed_coaleff, numconc, nsupers, alpha)
308+
if label not in pysdm_datasets.keys():
309+
print(f"skipping PySDM {label}")
310+
else:
311+
# print(f"{label} found for PySDM")
312+
ds = pysdm_datasets[label]
313+
style = get_style("pysdm", fixed_coaleff, alpha)
314+
axs[0].plot(ds.time, ds.lwp.mean(dim="ensemble"), **style)
315+
axs[1].plot(
316+
ds.time, ds.surfprecip_rolling.mean(dim="ensemble"), **style
317+
)
318+
319+
style["label"] = None
320+
style["alpha"] = 0.15
321+
lower, upper = calcs.mean_pm_stddev(ds.lwp, dim="ensemble")
322+
axs[0].fill_between(ds.time, lower, upper, **style)
323+
lower, upper = calcs.mean_pm_stddev_surfprecip_rolling(
324+
ds, precip_rolling_window, dim="ensemble"
325+
)
326+
axs[1].fill_between(ds.time, lower, upper, **style)
327+
328+
if label not in cleo_datasets.keys():
329+
print(f"skipping CLEO {label}")
330+
else:
331+
# print(f"{label} found for CLEO")
332+
ds = cleo_datasets[label]
333+
style = get_style("cleo", fixed_coaleff, alpha)
334+
axs[0].plot(ds.time, ds.lwp.mean(dim="ensemble"), **style)
335+
axs[1].plot(
336+
ds.time, ds.surfprecip_rolling.mean(dim="ensemble"), **style
337+
)
338+
339+
style["label"] = None
340+
style["alpha"] = 0.15
341+
lower, upper = calcs.mean_pm_stddev(ds.lwp, dim="ensemble")
342+
axs[0].fill_between(ds.time, lower, upper, **style)
343+
lower, upper = calcs.mean_pm_stddev_surfprecip_rolling(
344+
ds, precip_rolling_window, dim="ensemble"
345+
)
346+
axs[1].fill_between(ds.time, lower, upper, **style)
347+
348+
hands, labs = axs[0].get_legend_handles_labels()
349+
for lab in labs:
350+
if lab not in labels:
351+
labels.append(lab)
352+
handles.append(hands[labs.index(lab)])
353+
354+
legax.legend(handles, labels, loc="lower center")
355+
356+
for axs in axes:
357+
for ax in axs:
358+
ax.spines[["right", "top"]].set_visible(False)
359+
ax.set_xlim([0, 3000])
360+
361+
for ax in [axes[0][1], axes[1][1], axes[2][1]]:
362+
ax.set_xlabel("time [s]")
363+
364+
ylims1 = [0.0, 1.6]
365+
yticks1 = np.arange(ylims1[0], ylims1[1] + 0.5, 0.5)
366+
for ax in [axes[0][0], axes[1][0], axes[2][0]]:
367+
ax.set_ylabel("LWP / kg m$^{-2}$")
368+
ax.set_yticks(yticks1)
369+
ax.set_ylim(ylims1)
370+
371+
ylims2 = [0.0, 3.25]
372+
yticks2 = np.arange(ylims2[0], ylims2[1] + 1.0, 1.0)
373+
for ax in [axes[0][1], axes[1][1], axes[2][1]]:
374+
ax.set_ylabel("P / mm $h^{-1}$")
375+
ax.set_yticks(yticks2)
376+
ax.set_ylim(ylims2)
377+
378+
panels = ["a)", "b)", "c)"]
379+
for a in range(len(axes_setups)):
380+
numconc = axes_setups[a]["numconc"]
381+
axes[a][0].set_title(f"{panels[a]}" + " N$_c$ = " + f"{numconc}" + " cm$^{{-3}}$")
382+
383+
fig.tight_layout()
384+
plt.subplots_adjust(hspace=0.5)
385+
386+
plt.savefig(args.path4figs / "fig4_alphas_v2.pdf", format="pdf", bbox_inches="tight")
387+
plt.show()
388+
389+
251390
# %%

0 commit comments

Comments
 (0)