-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfigure2.py
More file actions
81 lines (64 loc) · 2.99 KB
/
figure2.py
File metadata and controls
81 lines (64 loc) · 2.99 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
import datetime as dt
import pandas as pd
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from pathlib import Path
from inca import plot_inca, sum_binary_inca
from tawes import read_json_data
# FIG2: 5 subplots, left big: Main event, right small: four next-largest events (sorted by max 2h RR)
def figure2():
# main event
time0 = dt.datetime(2024, 8, 17, 14, 0)
time1 = time0 + dt.timedelta(hours=2)
inca_ds = get_data(time0, time1)
station_data = read_json_data(f"data/{time0:%Y%m%d}/tawes.json")
station_data = pd.DataFrame.from_dict(station_data, orient='index')
fig = plt.figure(layout='constrained', figsize=(12, 6))
subfigs = fig.subfigures(1, 2, wspace=0.07, width_ratios=[1, 1.2])
ax1 = subfigs[0].subplots(1, 1, subplot_kw=dict(projection=ccrs.epsg(31287)))
pm = plot_inca(
inca_ds, time0, time1, "", filename=None, ax=ax1, add_colorbar=True,
station_data=station_data,
cbar_kwargs={'extend': 'both', 'label': '2-hour precipitation [mm]',
'location': 'bottom', 'drawedges': True})
pm.colorbar.ax.tick_params(labelsize=15)
ax1.text(0, 1, f"(a) {time1:%Y-%m-%d %H:%M}", fontweight='bold',
transform=ax1.transAxes, verticalalignment='top', fontsize=17,
zorder=15, horizontalalignment='left',
bbox={'facecolor': 'w', 'pad': 1, 'zorder': 14})
ax1.text(16.09, 48.15, 'V i e n n a w o o d s', fontsize=15, rotation=64,
ha='left', style='italic', transform=ccrs.PlateCarree())
ax1.axis('off')
old_events = [
dt.datetime(2014, 5, 24, 13, 0), # 62,1 mm
dt.datetime(2021, 7, 17, 18, 0), # 57,8 mm
dt.datetime(2010, 5, 13, 14, 0), # 55,2 mm
dt.datetime(2008, 5, 18, 13, 0) # 51,6 mm
]
# next-ranking smaller events (same colorbar!)
axs2 = subfigs[1].subplots(
2, 2, subplot_kw=dict(projection=ccrs.epsg(31287)))
label = ["(b)", "(c)", "(d)", "(e)"]
for i, ax in enumerate(axs2.flatten()):
time0 = old_events[i]
time1 = time0 + dt.timedelta(hours=2)
inca_ds = get_data(time0, time1)
station_data = read_json_data(f"data/{time0:%Y%m%d}/tawes.json")
station_data = pd.DataFrame.from_dict(station_data, orient='index')
plot_inca(inca_ds, time0, time1, "", filename=None, ax=ax,
add_colorbar=False, y=(460000, 503000),
station_data=station_data)
ax.text(0.01, 1, f"{label[i]} {time1:%Y-%m-%d %H:%M}", fontweight='bold',
transform=ax.transAxes, verticalalignment='top', fontsize=17,
horizontalalignment='left', zorder=15,
bbox={'facecolor': 'w', 'pad': 1, 'zorder': 14})
Path("output").mkdir(exist_ok=True)
plt.savefig("output/figure2.png", dpi=300, bbox_inches='tight')
plt.close()
return
def get_data(time0, time1):
ds = sum_binary_inca(
f"data/{time0:%Y%m%d}", time0 + dt.timedelta(minutes=15), time1)
return ds
if __name__ == '__main__':
figure2()