-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap_topo.py
More file actions
204 lines (161 loc) · 5.38 KB
/
map_topo.py
File metadata and controls
204 lines (161 loc) · 5.38 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
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
201
202
203
204
#!/usr/bin/env python3
"""
@author: tylunel
Creation : 07/01/2021
Script for plotting simple colormaps
"""
import matplotlib.pyplot as plt
import xarray as xr
import tools
import shapefile
import pandas as pd
import global_variables as gv
###############################################
# model = '1_planier_0105/02_1km'
# model = '1_planier_0105/021_200m'
model = '1_planier_0105/022_40m'
color_map = 'YlOrBr' # jet, seismic, BuPu, coolwarm, viridis, RdYlGn,
# BuPu, coolwarm, viridis, RdYlGn, jet,... (add _r to reverse)
# YlOrBr for orography
var_name = 'ZS' #LAI_ISBA, ZO_ISBA, PATCHP7, ALBNIR_S, MSLP, TG1_ISBA, RAINF_ISBA, CLDFR
vmin=0
vmax=800
# level, only useful if var 3D
ilevel = 1 #0 is Halo, 1:2m, 2:6.12m, 3:10.49m, 10:49.3m, 20:141m, 30:304m, 40:600m, 50:1126m, 60:2070m
sea_in_cyan = True
france_borders = False
points_to_plot = [
'planier',
'marseille',
'carry',
]
zoom_on = 'planier_40m'
prop = gv.zoom_domain_prop[zoom_on]
lat_range = prop['lat_range']
lon_range = prop['lon_range']
figsize = prop['figsize'] # if None automatic scaling
save_plot = True
save_folder = f'./figures/topo_map/{model}'
plot_title = 'Topography'
##############################################
#%% LOAD DATA
pgd_filename = f'{gv.global_simu_folder}/{model}/{gv.pgd_filename_dict[model]}'
pgd = xr.open_dataset(pgd_filename)
# pgd = xr.open_dataset(
# '/home/lunelt/Data/mnh_run/' + \
# 'PGD_1KM.nc')
#%% DATA SELECTION and ZOOM
varNd = pgd[var_name]
#remove single dimensions
varNd = varNd.squeeze()
if len(varNd.shape) == 2:
var2d = varNd
elif len(varNd.shape) == 3:
var2d = varNd[ilevel,:,:]
# remove 999 values, and replace by nan
var2d = var2d.where(~(var2d == 999))
# filter the outliers
#var2d = var2d.where(var2d <= vmax)
if figsize is None: # not working well /!\
xaxis_dist = float(pgd.ni.max() - pgd.ni.min()) # in km
yaxis_dist = float(pgd.nj.max() - pgd.nj.min()) # in km
scale = 1/20000
figsize = (xaxis_dist*scale*1.2, yaxis_dist*scale)
#%%
fig = plt.figure(figsize=figsize)
#%% Sea borders
if sea_in_cyan:
cmap = plt.cm.get_cmap(color_map).copy()
if var_name == 'ZS':
vmin=0.1
cmap.set_under('c') # for plotting the sea in cyan
else: # plot the contours
sea_covers = pgd.COVER001.data
plt.contour(pgd.longitude.data,
pgd.latitude.data,
sea_covers,
levels=0, #+1 -> number of contour to plot
linestyles='solid',
linewidths=1.,
colors='k'
# colors=['None'],
# hatches='-'
)
pgd1 = var2d
plt.pcolormesh(pgd1.longitude.data,
pgd1.latitude.data,
pgd1,
cmap=cmap,
vmin=vmin, vmax=vmax,
)
cbar = plt.colorbar()
cbar.set_label('altitude [m]')
#plt.title(plot_title)
plt.xlabel('longitude', fontsize=12)
plt.ylabel('latitude', fontsize=12)
# plt.ylim([pgd1.latitude.min(), pgd1.latitude.max()])
# plt.xlim([pgd1.longitude.min(), pgd1.longitude.max()])
#%% TOPO
#%% France borders
if france_borders:
sf = shapefile.Reader("../TM-WORLD-BORDERS/TM_WORLD_BORDERS-0.3.sph")
shapes = sf.shapes()
france = shapes[64].points
france_df = pd.DataFrame(france, columns=['lon', 'lat'])
france_S = france_df[france_df.lat < 43.8]
france_SE = france_S[france_S.lon > 4]
plt.plot(france_SE.lon, france_SE.lat,
color='k',
linewidth=1)
# Rivers
# rivers = shapefile.Reader("/home/lunelt/postproc_python/rivers_europe_37253/rivers_europe_37253.shp")
# # Check here to find ID of river: https://data.apps.fao.org/catalog/dataset/e0243940-e5d9-487c-8102-45180cf1a99f/resource/59557e5b-c852-4974-8576-8d954587b102
# ebro = rivers.shapes()[39555].points
# ebro_df = pd.DataFrame(ebro, columns=['lon', 'lat'])
# plt.plot(ebro_df.lon, ebro_df.lat,
# color='b',
# linewidth=1)
# segre = rivers.shapes()[38572].points
# segre_df = pd.DataFrame(segre, columns=['lon', 'lat'])
# plt.plot(segre_df.lon, segre_df.lat,
# color='b',
# linewidth=1)
#%% POINTS SITES
sites = {key:gv.whole[key] for key in points_to_plot}
for site in sites:
plt.scatter(sites[site]['lon'],
sites[site]['lat'],
color='r',
s=10 #size of markers
)
# print site name on fig:
try:
sitename = sites[site]['longname']
except KeyError:
sitename = site
if site == 'lleida':
plt.text(sites[site]['lon']-0.45,
sites[site]['lat']+0.02,
sitename,
fontsize=10)
else:
plt.text(sites[site]['lon']+0.02,
sites[site]['lat']+0.02,
sitename,
fontsize=10)
#%% FIGURE OPTIONS and ZOOM
#if len(varNd.shape) == 2:
# plot_title = '{0} - {1} diff between {2} and {3}'.format(
# wanted_date, var_name, models[0], models[1])
#elif len(varNd.shape) == 3:
# plot_title = '{0} - {1} diff between {2} and {3} at {4}m'.format(
# wanted_date, var_name, models[0], models[1], var2d.level.round())
#plot_title = 'diff between pgd400m1.11 and pgd400m1.15'
#
#plt.title(plot_title)
#
if zoom_on is not None:
plt.ylim(lat_range)
plt.xlim(lon_range)
if save_plot:
tools.save_figure(plot_title, save_folder)