-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_multiple_COSMO_domains.py
200 lines (189 loc) · 7.07 KB
/
plot_multiple_COSMO_domains.py
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# Description: Plot multiple COSMO domains with high-resolution background
# data from Natural Earth (https://www.naturalearthdata.com)
#
# Author: Christian R. Steger, October 2023
# Load modules
import os
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.gridspec as gridspec
import cartopy.crs as ccrs
from shapely.ops import transform
from shapely.ops import unary_union
from pyproj import CRS, Transformer
from utilities.plot import polygon2patch
from utilities.grid import polygon_rectangular
from utilities.plot import naturalearth_background
mpl.style.use("classic")
# Paths to folders
path_plot = "/Users/csteger/Desktop/"
###############################################################################
# Domain specifications and plot settings
###############################################################################
# COSMO domains
domains = {
# -------------------------------------------------------------------------
"Europe": {
"EURO":
{"name_plot": "EURO",
"startlat_tot": -14.86,
"startlon_tot": -18.86,
"pollat": 43.0,
"pollon": -170.0,
"polgam": 0.0,
"dlon": 0.02,
"dlat": 0.02,
"ie_tot": 1542,
"je_tot": 1542},
"EURO-CORDEX":
{"name_plot": "EURO-\nCORDEX",
"startlat_tot": -24.805,
"startlon_tot": -29.805,
"pollat": 39.25,
"pollon": -162.00,
"polgam": 0.0,
"dlon": 0.11,
"dlat": 0.11,
"ie_tot": 450,
"je_tot": 438},
"ALP":
{"name_plot": "ALP",
"startlat_tot": -6.6,
"startlon_tot": -6.2,
"pollat": 43.0,
"pollon": -170.0,
"polgam": 0.0,
"dlon": 0.02,
"dlat": 0.02,
"ie_tot": 800,
"je_tot": 600},
},
# -------------------------------------------------------------------------
"Atlantic": {
"T_ATL":
{"name_plot": "T-ATL",
"startlat_tot": -7.77,
"startlon_tot": -65.625,
"pollat": 90.0,
"pollon": -180.0,
"polgam": 0.0,
"dlon": 0.02,
"dlat": 0.02,
"ie_tot": 2310,
"je_tot": 1542},
"L_ATL":
{"name_plot": "L-ATL",
"startlat_tot": -37.45,
"startlon_tot": -54.54,
"pollat": 90.0,
"pollon": -180.0,
"polgam": 0.0,
"dlon": 0.03,
"dlat": 0.03,
"ie_tot": 2750,
"je_tot": 2065},
},
# -------------------------------------------------------------------------
"East_Asia": {
"EAS-CORDEX":
{"name_plot": "EAS-CORDEX",
"startlat_tot": -23.53,
"startlon_tot": -44.66,
"pollat": 61.0,
"pollon": -63.7,
"polgam": 0.0,
"dlon": 0.11,
"dlat": 0.11,
"ie_tot": 818,
"je_tot": 530},
"BECCY":
{"name_plot": "BECCY",
"startlat_tot": -12.67,
"startlon_tot": -28.24,
"pollat": 61.00,
"pollon": -63.70,
"polgam": 0.0,
"dlon": 0.04,
"dlat": 0.04,
"ie_tot": 650,
"je_tot": 650}
}
# -------------------------------------------------------------------------
}
###############################################################################
# Plot
###############################################################################
# Plot maps
fig = plt.figure(figsize=(18.0, 5.0)) # width, height
gs = gridspec.GridSpec(1, 3, left=0.02, bottom=0.02, right=0.98,
top=0.98, hspace=0.1, wspace=-0.2,
width_ratios=[1.0, 1.0, 1.0])
for ind_i, i in enumerate(domains.keys()):
# Compute domain boundaries and map centre
domains_rot = []
for ind_j, j in enumerate(domains[i].keys()):
crs_rot = ccrs.RotatedPole(
pole_latitude=domains[i][j]["pollat"],
pole_longitude=domains[i][j]["pollon"],
central_rotated_longitude=domains[i][j]["polgam"])
rlon_llc = domains[i][j]["startlon_tot"] \
- (domains[i][j]["dlon"] / 2.0)
rlat_llc = domains[i][j]["startlat_tot"] \
- (domains[i][j]["dlat"] / 2.0)
box = (rlon_llc,
rlat_llc,
rlon_llc + domains[i][j]["ie_tot"] * domains[i][j]["dlon"],
rlat_llc + domains[i][j]["je_tot"] * domains[i][j]["dlat"])
poly = polygon_rectangular(box, spacing=0.01)
if ind_j == 0:
domains_rot.append(poly)
crs_rot_ref = crs_rot
else:
project = Transformer.from_crs(
CRS.from_user_input(crs_rot),
CRS.from_user_input(crs_rot_ref),
always_xy=True).transform
domains_rot.append(transform(project, poly))
domains_union = unary_union(domains_rot)
cen_lon, cen_lat = ccrs.PlateCarree().transform_point(
*domains_union.centroid.xy, crs_rot)
crs_map = ccrs.Orthographic(central_longitude=cen_lon,
central_latitude=cen_lat)
# Domain labels (-> have to be set manually)
label_pos = {
# ---------------------------------------------------------------------
"Europe": {
"EURO": (-1_900_000, -2_400_000),
"EURO-CORDEX": (1_200_000, -3_400_000),
"ALP": (200_000, -100_000)},
# ---------------------------------------------------------------------
"Atlantic": {
"T_ATL": (-1_500_000, -750_000),
"L_ATL": (2_800_000, 2_550_000)},
# ---------------------------------------------------------------------
"East_Asia": {
"EAS-CORDEX": (-3_400_000, 3_400_000),
"BECCY": (-2_800_000, 1_100_000)
}
# ---------------------------------------------------------------------
}
# Plot
ax = plt.subplot(gs[ind_i], projection=crs_map)
ax.set_global()
image_name = "cross_blended_hypso_with_relief_water_drains_" \
+ "and_ocean_bottom"
naturalearth_background(ax, image_name=image_name, image_res="medium",
interp_res=(3000, 3000))
ax.coastlines("50m", linewidth=0.5)
for ind_j, j in enumerate(domains_rot):
poly = polygon2patch(domains_rot[ind_j], facecolor="none",
edgecolor="black", alpha=1.0, linewidth=2.0,
transform=crs_rot_ref)
ax.add_collection(poly)
dom_name = list(domains[i].keys())[ind_j]
plt.text(*label_pos[i][dom_name], domains[i][dom_name]["name_plot"],
fontsize=10, fontweight="bold", transform=crs_map)
print("Region " + i + " plotted")
fig.savefig(path_plot + "COSMO_domains.png", dpi=300, bbox_inches="tight")
plt.close(fig)