-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plot_irr_withdrawl_map_OBS_CTL_IRR.py
258 lines (216 loc) · 12.1 KB
/
Plot_irr_withdrawl_map_OBS_CTL_IRR.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
import geopandas as gp
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import matplotlib as mpl
from matplotlib import colors
import cartopy.crs as ccrs
import shapefile
import cartopy.feature as cfeature
listx1 = []
listy1 = []
listx2 = []
listy2 = []
listx3 = []
listy3 = []
listx4 = []
listy4 = []
listx5 = []
listy5 = []
#IPCC = gp.GeoDataFrame.from_file('E:\Data_Evaluation\ATLAS-master\\reference-regions\IPCC-WGI-reference-regions-v4_shapefile\IPCC-WGI-reference-regions-v4.shp', encoding = 'gb18030')
IPCC_shapes = shapefile.Reader('E:\Data_Evaluation\ATLAS-master\\reference-regions\IPCC-WGI-reference-regions-v4_shapefile\IPCC-WGI-reference-regions-v4.shp')
IPCC_border = IPCC_shapes.shapes()
border_points = IPCC_border[6].points
for xNew, yNew in border_points:
listx1.append(xNew)
listy1.append(yNew)
border_points = IPCC_border[19].points
for xNew, yNew in border_points:
listx2.append(xNew)
listy2.append(yNew)
border_points = IPCC_border[35].points
for xNew, yNew in border_points:
listx3.append(xNew)
listy3.append(yNew)
border_points = IPCC_border[37].points
for xNew, yNew in border_points:
listx4.append(xNew)
listy4.append(yNew)
border_points = IPCC_border[38].points
for xNew, yNew in border_points:
listx5.append(xNew)
listy5.append(yNew)
border_points = IPCC_border[6].points
for xNew, yNew in border_points:
listx1.append(xNew)
listy1.append(yNew)
border_points = IPCC_border[6].points
for xNew, yNew in border_points:
listx1.append(xNew)
listy1.append(yNew)
border_points = IPCC_border[6].points
for xNew, yNew in border_points:
listx1.append(xNew)
listy1.append(yNew)
border_points = IPCC_border[6].points
for xNew, yNew in border_points:
listx1.append(xNew)
listy1.append(yNew)
#xpoint = [8.7175, 127.2506, 140.0269, -96.4701, 121.2653]
#ypoint = [45.0700, 38.2013, 36.0539, 41.1649, 14.1412]
xpoint = [8.7175, 140.0269, -96.4701]
ypoint = [45.0700, 36.0539, 41.1649]
# function definition
def subplotdefi(row, col, num, title,fontsize):
ax = plt.subplot(row, col, num)
plt.title(title,fontsize=fontsize)
right_side1 = ax.spines['right'] # right_side1.set_visible(False)
left_side1 = ax.spines['left'] # left_side1.set_visible(False)
top_side1 = ax.spines['top'] # top_side1.set_visible(False)
bottom_side1 = ax.spines['bottom'] # bottom_side1.set_visible(False)
ax.set_xticks([])
ax.set_yticks([])
return ax
def plotmap(boundary, ax, colomn, cmap, norm, legend_kwds):
base = boundary.boundary.plot(ax=ax, edgecolor='lightgrey', linewidth=0.1)
divider = make_axes_locatable(ax)
cax = divider.append_axes("bottom", size="3%", pad=0.1)
h = data_geod.plot(column=colomn, cmap=cmap, ax=base, norm=norm, alpha=10, legend=True, cax=cax,
legend_kwds=legend_kwds,
missing_kwds={"color": "lightgray", "label": "Missing values"}) #missing_kwds={"color": "lightgrey", "edgecolor": "white", "label": "Missing values"})
return h
def plotmap2(boundary, ax, colomn, cmap, norm, legend_kwds):
base = boundary.boundary.plot(ax=ax, edgecolor='lightgrey', linewidth=0.1)
divider = make_axes_locatable(ax)
cax = divider.append_axes("bottom", size="3%", pad=0.1)
h = data_geod.plot(column=colomn, cmap=cmap, ax=base, norm=norm, alpha=10, legend=True, cax=cax,
legend_kwds=legend_kwds,
missing_kwds={"color": "white", "label": "Missing values"}) #missing_kwds={"color": "lightgrey", "edgecolor": "white", "label": "Missing values"})
return h
def set_plot_param():
"""Set my own customized plotting parameters"""
mpl.rc('axes', edgecolor='lightgrey')
mpl.rc('axes', labelcolor='dimgrey')
mpl.rc('xtick', color='dimgrey')
mpl.rc('xtick', labelsize=12)
mpl.rc('ytick', color='dimgrey')
mpl.rc('ytick', labelsize=12)
mpl.rc('axes', titlesize=14)
mpl.rc('axes', labelsize=12)
mpl.rc('legend', fontsize='large')
mpl.rc('text', color='dimgrey')
projection = ccrs.PlateCarree()
boundary = gp.GeoDataFrame.from_file('E:\Data_Evaluation\Data_for_evaluation\Irrigation_amount\\Example_final_final_final.shp', encoding = 'gb18030')
data_geod = gp.GeoDataFrame.from_file('E:\Data_Evaluation\Data_for_evaluation\Irrigation_amount\\Example_final_final_final.shp', encoding = 'gb18030')
# plot 1
f = plt.figure(figsize = (12, 7), dpi=100) # initiate the figure
f.subplots_adjust(hspace=0.1, wspace=0.1, left = 0.05, right = 0.95, top = 0.95, bottom = 0.05)
set_plot_param()
ax = subplotdefi(1,1,1,'Observed irrigation water withdrawal',18)
# plot water withdrawal
vmax = data_geod.Obs.max()
vmin = data_geod.Obs.min()
norm_withd = colors.DivergingNorm(vmin=vmin,
vcenter=0.01,
vmax=vmax)
cmap_withd='Blues'
bounds_Blues = [0, 0.5, 1, 2, 5, 10, 15, 30]
Blues = mpl.cm.get_cmap('Blues')
colors_Blues = [Blues(0.125), Blues(0.25), Blues(0.375), Blues(0.5), Blues(0.625), Blues(0.75), Blues(0.875), Blues(0.99)]
print(colors_Blues)
cmap_Blues = mpl.colors.ListedColormap(colors_Blues)
norm_Blues = mpl.colors.BoundaryNorm(bounds_Blues,cmap_Blues.N,extend='max')
h = plotmap(boundary, ax, 'Obs', cmap_Blues, norm_Blues,legend_kwds={'label': r"water withdrawal ($km^3$/yr)",'orientation': "horizontal"})
plt.savefig('E:\Data_Evaluation\Data_for_evaluation\Irrigation_amount\Fig\\ObsIWW.png')
#plt.show()
#plot 2
f2 = plt.figure(figsize = (6, 7), dpi=100) # initiate the figure
f2.subplots_adjust(hspace=0.1, wspace=0.1, left = 0.05, right = 0.95, top = 0.95, bottom = 0.05)
ax = subplotdefi(2,1,1,'Simulated irrigation water withdrawal (CTL)',14)
ax.text(0.01,0.92,'a',color='dimgrey',fontsize=12, transform=ax.transAxes, weight = 'bold')
plt.plot(listx1,listy1, color='black')
ax.text(-136,16,'NCA',color='black',fontsize=10, weight = 'bold')
plt.plot(listx2,listy2, color='black')
ax.text(-38,30,'MED',color='black',fontsize=10, weight = 'bold')
plt.plot(listx3,listy3, color='black')
ax.text(50,7,'SAS',color='black',fontsize=10, weight = 'bold')
plt.plot(listx4,listy4, color='black')
ax.text(142,25.5,'EAS',color='black',fontsize=10, weight = 'bold')
plt.plot(listx5,listy5, color='black')
ax.text(93,-20,'SEA',color='black',fontsize=10, weight = 'bold')
ax1 = subplotdefi(2,1,2,'Bias (CTL - OBS)',14)
ax1.text(0.01,0.92,'b',color='dimgrey',fontsize=12, transform=ax1.transAxes, weight = 'bold')
plt.scatter(xpoint,ypoint, color='black', s=5, marker='^' ,zorder=10)
ax1.text(-96,41,'NEB',color='black',fontsize=8, weight = 'bold')
#ax1.text(127,39,'CHE',color='black',fontsize=8, weight = 'bold')
ax1.text(141.5,29.5,'MAS',color='black',fontsize=8, weight = 'bold')
ax1.text(8.7,46,'CAS',color='black',fontsize=8, weight = 'bold')
#ax1.text(122,14,'RIF',color='black',fontsize=8, weight = 'bold')
h2 = plotmap2(boundary, ax, 'Ctl', cmap_Blues, norm_Blues,legend_kwds={'label': r"water withdrawal ($km^3$/yr)",'orientation': "horizontal"})
PRGn = mpl.cm.get_cmap('PRGn_r')
colors = [PRGn(0.01),PRGn(0.1),PRGn(0.2),PRGn(0.3),PRGn(0.5),PRGn(0.7),PRGn(0.8),PRGn(0.9),PRGn(0.99)]
colors = [PRGn(0.01),PRGn(0.1),PRGn(0.2),PRGn(0.3),'whitesmoke',PRGn(0.7),PRGn(0.8),PRGn(0.9),PRGn(0.99)]
#colors = ['darkgreen', 'forestgreen', 'limegreen', 'lime', 'white', 'plum', 'violet', 'fuchsia', 'purple']
cmap_bias = mpl.colors.ListedColormap(colors)
bounds = [-15, -10, -5, -0.001, 0.001, 5, 10, 15]
bounds = [-5, -3, -1, -0.1, 0.1, 1, 3, 5]
norm_bias = mpl.colors.BoundaryNorm(bounds,cmap_bias.N,extend='both')
bwr = mpl.cm.get_cmap('bwr_r')
colors = [bwr(0.1),bwr(0.2),bwr(0.3),bwr(0.4),bwr(0.5),bwr(0.6),bwr(0.7),bwr(0.8),bwr(0.9)]
colors = [bwr(0.1),bwr(0.2),bwr(0.3),bwr(0.4),'whitesmoke',bwr(0.6),bwr(0.7),bwr(0.8),bwr(0.9)]
#colors = ['darkgoldenrod', 'goldenrod', 'gold', 'yellow', 'white', 'aqua', 'dodgerblue', 'blue', 'darkblue']
cmap_bias1 = mpl.colors.ListedColormap(colors)
bounds = [-15, -10, -5, -0.001, 0.001, 5, 10, 15]
bounds = [-10, -5, -2, -0.5, 0.5, 2, 5, 10]
norm_bias1 = mpl.colors.BoundaryNorm(bounds,cmap_bias1.N,extend='both')
h2 = plotmap(boundary, ax1, 'Bias_ctl', cmap_bias1, norm_bias1,legend_kwds={'label': r"mean bias ($km^3$/yr)",'orientation': "horizontal"})
plt.savefig('E:\Data_Evaluation\Data_for_evaluation\Irrigation_amount\Fig\\CTL_Obs.png')
#plot 3
f2 = plt.figure(figsize = (12, 7), dpi=100) # initiate the figure
f2.subplots_adjust(hspace=0.1, wspace=0.1, left = 0.05, right = 0.95, top = 0.95, bottom = 0.05)
#ax1 = subplotdefi(2,2,1,'Mean error (IRR_meth - OBS)',14)
ax1 = subplotdefi(2,2,1,'',14)
ax1.set_title('IRR_0 - OBS',loc='right',fontsize = 12)
ax1.text(0.01,0.92,'a',color='dimgrey',fontsize=12, transform=ax1.transAxes, weight = 'bold')
#ax2 = subplotdefi(2,2,2,'Mean error (IRR_drai - OBS)',14)
ax2 = subplotdefi(2,2,2,'',14)
ax2.set_title('IRR_1 - OBS',loc='right',fontsize = 12)
ax2.text(0.01,0.92,'b',color='dimgrey',fontsize=12, transform=ax2.transAxes, weight = 'bold')
#ax3 = subplotdefi(2,2,3,'Mean error (IRR_pool - OBS)',14)
ax3 = subplotdefi(2,2,3,'',14)
ax3.set_title('IRR_2 - OBS',loc='right',fontsize = 12)
ax3.text(0.01,0.92,'c',color='dimgrey',fontsize=12, transform=ax3.transAxes, weight = 'bold')
#ax4 = subplotdefi(2,2,4,'Mean error (IRR_satu - OBS)',14)
ax4 = subplotdefi(2,2,4,'',14)
ax4.set_title('IRR_3 - OBS',loc='right',fontsize = 12)
ax4.text(0.01,0.92,'d',color='dimgrey',fontsize=12, transform=ax4.transAxes, weight = 'bold')
h1 = plotmap(boundary, ax1, 'Bias_irr', cmap_bias1, norm_bias1,legend_kwds={'label': r"mean bias ($km^3$/yr)",'orientation': "horizontal"})
h2 = plotmap(boundary, ax2, 'Bias_drai', cmap_bias1, norm_bias1,legend_kwds={'label': r"mean bias ($km^3$/yr)",'orientation': "horizontal"})
h3 = plotmap(boundary, ax3, 'Bias_pool', cmap_bias1, norm_bias1,legend_kwds={'label': r"mean bias ($km^3$/yr)",'orientation': "horizontal"})
h4 = plotmap(boundary, ax4, 'Bias_satu', cmap_bias1, norm_bias1,legend_kwds={'label': r"mean bias ($km^3$/yr)",'orientation': "horizontal"})
plt.savefig('E:\Data_Evaluation\Data_for_evaluation\Irrigation_amount\Fig\\IRR_CTL.png')
#plt.show()
#plot 4
f2 = plt.figure(figsize = (12, 7), dpi=100) # initiate the figure
f2.subplots_adjust(hspace=0.1, wspace=0.1, left = 0.05, right = 0.95, top = 0.95, bottom = 0.05)
#ax1 = subplotdefi(2,2,1,'Mean absolute error (MAE) change (IRR_meth - CTL)',14)
ax1 = subplotdefi(2,2,1,'',14)
ax1.set_title('MAE(IRR_0) - MAE(CTL)',loc='right',fontsize = 12)
ax1.text(0.01,0.92,'a',color='dimgrey',fontsize=12, transform=ax1.transAxes, weight = 'bold')
#ax2 = subplotdefi(2,2,2,'Mean absolute error (MAE) change (IRR_drai - CTL)',14)
ax2 = subplotdefi(2,2,2,'',14)
ax2.set_title('MAE(IRR_1) - MAE(CTL)',loc='right',fontsize = 12)
ax2.text(0.01,0.92,'b',color='dimgrey',fontsize=12, transform=ax2.transAxes, weight = 'bold')
#ax3 = subplotdefi(2,2,3,'Mean absolute error (MAE) change (IRR_pool - CTL)',14)
ax3 = subplotdefi(2,2,3,'',14)
ax3.set_title('MAE(IRR_2) - MAE(CTL)',loc='right',fontsize = 12)
ax3.text(0.01,0.92,'c',color='dimgrey',fontsize=12, transform=ax3.transAxes, weight = 'bold')
#ax4 = subplotdefi(2,2,4,'Mean absolute error (MAE) change (IRR_satu - CTL)',14)
ax4 = subplotdefi(2,2,4,'',14)
ax4.set_title('MAE(IRR_3) - MAE(CTL)',loc='right',fontsize = 12)
ax4.text(0.01,0.92,'d',color='dimgrey',fontsize=12, transform=ax4.transAxes, weight = 'bold')
h1 = plotmap(boundary, ax1, 'AbBias_1', cmap_bias, norm_bias,legend_kwds={'label': r"MAE change ($km^3$/yr)",'orientation': "horizontal"})
h2 = plotmap(boundary, ax2, 'AbBias_2', cmap_bias, norm_bias,legend_kwds={'label': r"MAE change ($km^3$/yr)",'orientation': "horizontal"})
h3 = plotmap(boundary, ax3, 'AbBias_3', cmap_bias, norm_bias,legend_kwds={'label': r"MAE change ($km^3$/yr)",'orientation': "horizontal"})
h4 = plotmap(boundary, ax4, 'AbBias_4', cmap_bias, norm_bias,legend_kwds={'label': r"MAE change ($km^3$/yr)",'orientation': "horizontal"})
plt.savefig('E:\Data_Evaluation\Data_for_evaluation\Irrigation_amount\Fig\\4.png')
#plt.show()