wolfhece 2.1.112__py3-none-any.whl → 2.1.113__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wolfhece/PyDraw.py +1 -1
- wolfhece/apps/version.py +1 -1
- wolfhece/irm_qdf.py +34 -7
- wolfhece/mar/commontools.py +203 -196
- wolfhece/wolf_array.py +53 -14
- {wolfhece-2.1.112.dist-info → wolfhece-2.1.113.dist-info}/METADATA +1 -2
- {wolfhece-2.1.112.dist-info → wolfhece-2.1.113.dist-info}/RECORD +10 -10
- {wolfhece-2.1.112.dist-info → wolfhece-2.1.113.dist-info}/WHEEL +0 -0
- {wolfhece-2.1.112.dist-info → wolfhece-2.1.113.dist-info}/entry_points.txt +0 -0
- {wolfhece-2.1.112.dist-info → wolfhece-2.1.113.dist-info}/top_level.txt +0 -0
wolfhece/mar/commontools.py
CHANGED
@@ -10,7 +10,6 @@ Created on Mon Dec 5 09:03:34 2022
|
|
10
10
|
import numpy as np
|
11
11
|
import matplotlib.pyplot as plt
|
12
12
|
import commontools as ct
|
13
|
-
from mpl_toolkits.basemap import Basemap
|
14
13
|
import xarray as xr
|
15
14
|
import matplotlib as mpl
|
16
15
|
import pandas as pd
|
@@ -47,7 +46,7 @@ def openfileh(fileloc,col):
|
|
47
46
|
columns=lines.split()
|
48
47
|
V=np.append(V,float(columns[col]))
|
49
48
|
r=r+1
|
50
|
-
return(V)
|
49
|
+
return(V)
|
51
50
|
|
52
51
|
def isbis(year):
|
53
52
|
if((year%4==0 and year%100!=0)or(year%4==0 and year%400==0 and year%100==0)):
|
@@ -63,27 +62,27 @@ def seasonalmeans(fileloc,col,start_year,end_year,mod,season):
|
|
63
62
|
# T=np.zeros(end_year-start_year+1)
|
64
63
|
|
65
64
|
|
66
|
-
for y in range(start_year,end_year+1):
|
65
|
+
for y in range(start_year,end_year+1):
|
67
66
|
beg_summer=np.array([173,173,170]);end_summer=np.array([264,264,259])
|
68
67
|
beg_falls=end_summer+1;end_falls=np.array([355,355,359])
|
69
68
|
beg_winter=end_falls+1;end_winter=np.array([80,80,69])
|
70
69
|
beg_spring=end_winter+1;end_spring=beg_summer-1
|
71
|
-
end_year=np.array([365,365,360])
|
72
|
-
|
70
|
+
end_year=np.array([365,365,360])
|
71
|
+
|
73
72
|
if(isbis(y)==1 and mod==0):
|
74
73
|
beg_summer=beg_summer+1;end_summer=end_summer+1
|
75
74
|
beg_falls=beg_falls+1;end_falls=end_falls+1
|
76
75
|
beg_winter=beg_winter+1;end_winter=end_winter+1
|
77
76
|
beg_spring=beg_spring+1;end_spring=beg_summer-1
|
78
|
-
end_year=end_year+1
|
79
|
-
# ind=y-start_year
|
80
|
-
if season=="Summer":
|
77
|
+
end_year=end_year+1
|
78
|
+
# ind=y-start_year
|
79
|
+
if season=="Summer":
|
81
80
|
MASK=years==y
|
82
81
|
T=np.append(T,np.mean(var[MASK][beg_summer[mod]-1:end_summer[mod]-1]))
|
83
82
|
# T[ind]=np.mean(var[MASK][beg_summer[mod]-1:end_summer[mod]-1])
|
84
83
|
elif season=="Falls":
|
85
84
|
MASK=years==y
|
86
|
-
T=np.append(T,np.mean(var[MASK][beg_falls[mod]-1:end_falls[mod]-1]))
|
85
|
+
T=np.append(T,np.mean(var[MASK][beg_falls[mod]-1:end_falls[mod]-1]))
|
87
86
|
# T[ind]=np.mean(var[MASK][beg_falls[mod]-1:end_falls[mod]-1])
|
88
87
|
elif season=="Winter":
|
89
88
|
MASK1=years==y;MASK2=years==y+1
|
@@ -97,7 +96,7 @@ def seasonalmeans(fileloc,col,start_year,end_year,mod,season):
|
|
97
96
|
# T[ind]=np.mean(var[MASK][beg_spring[mod]-1:end_spring[mod]-1])
|
98
97
|
elif season=="year":
|
99
98
|
MASK=years==y
|
100
|
-
T=np.append(T,np.mean(var[MASK][0:end_year[mod]-1]))
|
99
|
+
T=np.append(T,np.mean(var[MASK][0:end_year[mod]-1]))
|
101
100
|
# T[ind]=np.mean(var[MASK][0:end_year[mod]-1])
|
102
101
|
return(T)
|
103
102
|
|
@@ -109,27 +108,27 @@ def seasonalsums(fileloc,col,start_year,end_year,mod,season):
|
|
109
108
|
# T=np.zeros(end_year-start_year+1)
|
110
109
|
|
111
110
|
|
112
|
-
for y in range(start_year,end_year+1):
|
111
|
+
for y in range(start_year,end_year+1):
|
113
112
|
beg_summer=np.array([173,173,170]);end_summer=np.array([264,264,259])
|
114
113
|
beg_falls=end_summer+1;end_falls=np.array([355,355,359])
|
115
114
|
beg_winter=end_falls+1;end_winter=np.array([80,80,69])
|
116
115
|
beg_spring=end_winter+1;end_spring=beg_summer-1
|
117
|
-
end_year=np.array([365,365,360])
|
118
|
-
|
116
|
+
end_year=np.array([365,365,360])
|
117
|
+
|
119
118
|
if(isbis(y)==1 and mod==0):
|
120
119
|
beg_summer=beg_summer+1;end_summer=end_summer+1
|
121
120
|
beg_falls=beg_falls+1;end_falls=end_falls+1
|
122
121
|
beg_winter=beg_winter+1;end_winter=end_winter+1
|
123
122
|
beg_spring=beg_spring+1;end_spring=beg_summer-1
|
124
|
-
end_year=end_year+1
|
125
|
-
# ind=y-start_year
|
126
|
-
if season=="Summer":
|
123
|
+
end_year=end_year+1
|
124
|
+
# ind=y-start_year
|
125
|
+
if season=="Summer":
|
127
126
|
MASK=years==y
|
128
127
|
T=np.append(T,np.sum(var[MASK][beg_summer[mod]-1:end_summer[mod]-1]))
|
129
128
|
# T[ind]=np.mean(var[MASK][beg_summer[mod]-1:end_summer[mod]-1])
|
130
129
|
elif season=="Falls":
|
131
130
|
MASK=years==y
|
132
|
-
T=np.append(T,np.sum(var[MASK][beg_falls[mod]-1:end_falls[mod]-1]))
|
131
|
+
T=np.append(T,np.sum(var[MASK][beg_falls[mod]-1:end_falls[mod]-1]))
|
133
132
|
# T[ind]=np.mean(var[MASK][beg_falls[mod]-1:end_falls[mod]-1])
|
134
133
|
elif season=="Winter":
|
135
134
|
MASK1=years==y;MASK2=years==y+1
|
@@ -143,18 +142,18 @@ def seasonalsums(fileloc,col,start_year,end_year,mod,season):
|
|
143
142
|
# T[ind]=np.mean(var[MASK][beg_spring[mod]-1:end_spring[mod]-1])
|
144
143
|
elif season=="year":
|
145
144
|
MASK=years==y
|
146
|
-
T=np.append(T,np.sum(var[MASK][0:end_year[mod]-1]))
|
145
|
+
T=np.append(T,np.sum(var[MASK][0:end_year[mod]-1]))
|
147
146
|
# T[ind]=np.mean(var[MASK][0:end_year[mod]-1])
|
148
147
|
return(T)
|
149
148
|
|
150
149
|
def text_into_matrix(model_name,scenario,mx,my,sy,ey):
|
151
150
|
"""
|
152
151
|
This function reads precipitation
|
153
|
-
text files to put all of it in a
|
152
|
+
text files to put all of it in a
|
154
153
|
3D matrix of yearly precipitation
|
155
154
|
"""
|
156
155
|
directory='/srv7_tmp1/jbrajkovic/These/TS_ppp2/'
|
157
|
-
|
156
|
+
|
158
157
|
mat_ret=np.zeros([mx,my,1])
|
159
158
|
if scenario=='ssp585':
|
160
159
|
y1=1980;y2=2100
|
@@ -168,21 +167,21 @@ def text_into_matrix(model_name,scenario,mx,my,sy,ey):
|
|
168
167
|
isuiv+=1
|
169
168
|
# print('File doesn\'t exist',fn)
|
170
169
|
continue
|
171
|
-
else:
|
170
|
+
else:
|
172
171
|
isuiv2+=1
|
173
|
-
|
172
|
+
|
174
173
|
if isuiv<=my:
|
175
174
|
ii=0;jj=isuiv
|
176
175
|
else:
|
177
176
|
jj=int(isuiv%my)-1
|
178
177
|
ii=int((isuiv-jj)/my)
|
179
|
-
|
178
|
+
|
180
179
|
if jj==0:j=my-1;ii=ii-1
|
181
180
|
else:jj=jj-1
|
182
181
|
if isuiv2==1:
|
183
182
|
with open (fn, 'r') as f:
|
184
183
|
yys = [float(row[0]) for row in csv.reader(f,delimiter='\t')]
|
185
|
-
with open (fn, 'r') as f:
|
184
|
+
with open (fn, 'r') as f:
|
186
185
|
pr= [float(row[2]) for row in csv.reader(f,delimiter='\t')]
|
187
186
|
else:
|
188
187
|
with open (fn, 'r') as f:
|
@@ -197,11 +196,11 @@ def text_into_matrix(model_name,scenario,mx,my,sy,ey):
|
|
197
196
|
if isuiv2%200==0:print(isuiv2, mat_ret[ii,jj,0])
|
198
197
|
isuiv+=1
|
199
198
|
return(mat_ret)
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
199
|
+
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
|
205
204
|
|
206
205
|
|
207
206
|
def slidingmeans(TS,interval,std_or_mean=1):
|
@@ -220,10 +219,10 @@ def slidingmeans(TS,interval,std_or_mean=1):
|
|
220
219
|
else:newTS[i]=np.std(TS[i-int2:i+int2])
|
221
220
|
return(newTS)
|
222
221
|
|
223
|
-
|
222
|
+
|
224
223
|
def RGPD(vec,shape,scale,pu,teta,th):
|
225
224
|
# print(th)
|
226
|
-
r=th+(scale/shape)*((vec*pu*teta)**shape-1)
|
225
|
+
r=th+(scale/shape)*((vec*pu*teta)**shape-1)
|
227
226
|
return (r)
|
228
227
|
|
229
228
|
def GPD_frequency(valu,shape,scale,pu,teta,th,events_per_year):
|
@@ -232,7 +231,7 @@ def GPD_frequency(valu,shape,scale,pu,teta,th,events_per_year):
|
|
232
231
|
return(ret_p)
|
233
232
|
|
234
233
|
def RGPDI_values(vec,shape,scale,th):
|
235
|
-
|
234
|
+
|
236
235
|
vals=((((1-vec)**(-shape))-1)*scale)/shape+th
|
237
236
|
return (vals)
|
238
237
|
|
@@ -240,7 +239,7 @@ def RGPD_values(vec,shape,scale):
|
|
240
239
|
vals=1-(1+shape*vec/scale)**(-1/shape)
|
241
240
|
return (vals)
|
242
241
|
|
243
|
-
|
242
|
+
|
244
243
|
def CIGPD(vec,shape,scale,pu,teta,th,varsc,varsh,cov):
|
245
244
|
T1=(((vec*pu*teta)**shape-1)/shape)**2*varsc
|
246
245
|
T2=((scale*(-(vec*teta*pu)**shape+shape*(vec*teta*pu)**shape*np.log(vec*teta*pu)+1)/shape**2))**2*varsh
|
@@ -248,7 +247,7 @@ def CIGPD(vec,shape,scale,pu,teta,th,varsc,varsh,cov):
|
|
248
247
|
((scale*(-(vec*teta*pu)**shape+shape*(vec*teta*pu)**shape*np.log(vec*teta*pu)+1)/shape**2))*cov
|
249
248
|
CI=np.sqrt(T1+T2+T3)*1.645
|
250
249
|
return(CI)
|
251
|
-
|
250
|
+
|
252
251
|
|
253
252
|
|
254
253
|
def JJ2date(day,year):
|
@@ -261,7 +260,7 @@ def JJ2date(day,year):
|
|
261
260
|
|
262
261
|
for i in range(1,12):
|
263
262
|
end_monthcum[i]=end_monthcum[i-1]+end_month[i]
|
264
|
-
|
263
|
+
|
265
264
|
for i in range(0,12):
|
266
265
|
if i > 0:
|
267
266
|
if (day<=end_monthcum[i] and day>end_monthcum[i-1]):
|
@@ -271,20 +270,20 @@ def JJ2date(day,year):
|
|
271
270
|
if (day<=end_monthcum[i] and day>0):
|
272
271
|
m=monthlab[i]
|
273
272
|
jj=day
|
274
|
-
# jj+=1
|
273
|
+
# jj+=1
|
275
274
|
date=np.array([jj,m,year]);date.astype(int)
|
276
275
|
return(date)
|
277
276
|
|
278
277
|
def date2JJ(day,month,year,fn1='__',type_mod=2):
|
279
|
-
end_month=[31,28,31,30,31,30,31,31,30,31,30,31]
|
278
|
+
end_month=[31,28,31,30,31,30,31,31,30,31,30,31]
|
280
279
|
end_monthcum=np.zeros(12);
|
281
280
|
if type_mod==1:
|
282
281
|
if (ct.isbis(year)==1):end_month[1]=29
|
283
|
-
|
282
|
+
|
284
283
|
|
285
284
|
for i in range(1,12):
|
286
285
|
end_monthcum[i]=end_monthcum[i-1]+end_month[i]
|
287
|
-
|
286
|
+
|
288
287
|
jj=int(end_monthcum[int(month-1)])+day
|
289
288
|
# print(day,month,year,jj)
|
290
289
|
return(jj)
|
@@ -299,6 +298,8 @@ def makebounds(mat,step):
|
|
299
298
|
return(bounds)
|
300
299
|
|
301
300
|
def map_belgium(ax,lons,lats):
|
301
|
+
from mpl_toolkits.basemap import Basemap
|
302
|
+
|
302
303
|
lat_0=50.6;lon_0=4.73
|
303
304
|
m = Basemap(width=55000,height=50000,
|
304
305
|
rsphere=(649328.00,665262.0),\
|
@@ -309,6 +310,7 @@ def map_belgium(ax,lons,lats):
|
|
309
310
|
return(m)
|
310
311
|
|
311
312
|
def map_belgium_J21(ax,lons,lats):
|
313
|
+
from mpl_toolkits.basemap import Basemap
|
312
314
|
lat_0=50.15;lon_0=5.83
|
313
315
|
m = Basemap(width=15000,height=18000,
|
314
316
|
rsphere=(649328.00,665262.0),\
|
@@ -320,6 +322,7 @@ def map_belgium_J21(ax,lons,lats):
|
|
320
322
|
|
321
323
|
|
322
324
|
def map_Vesdre(ax,lons,lats):
|
325
|
+
from mpl_toolkits.basemap import Basemap
|
323
326
|
lat_0=50.55;lon_0=5.93
|
324
327
|
m = Basemap(width=6000,height=3800,
|
325
328
|
rsphere=(649328.00,665262.0),\
|
@@ -328,14 +331,15 @@ def map_Vesdre(ax,lons,lats):
|
|
328
331
|
m.drawcountries()
|
329
332
|
m.drawcoastlines()
|
330
333
|
return(m)
|
331
|
-
|
332
334
|
|
333
335
|
|
334
336
|
|
335
|
-
|
337
|
+
|
338
|
+
|
336
339
|
def map_belgium_zoom(ax,lons,lats):
|
340
|
+
from mpl_toolkits.basemap import Basemap
|
337
341
|
lat_0=50.6;lon_0=4.73
|
338
|
-
|
342
|
+
|
339
343
|
m = Basemap(width=34000,height=30000,
|
340
344
|
rsphere=(649328.00,665262.0),\
|
341
345
|
area_thresh=1000.,projection='lcc',\
|
@@ -350,7 +354,8 @@ def map_belgium_zoom(ax,lons,lats):
|
|
350
354
|
return(m)
|
351
355
|
|
352
356
|
def map_Europe(ax,lons,lats):
|
353
|
-
|
357
|
+
from mpl_toolkits.basemap import Basemap
|
358
|
+
|
354
359
|
print(np.mean(lats))
|
355
360
|
m = Basemap(width=6000,height=150000,
|
356
361
|
rsphere=(649328.00,665262.0),\
|
@@ -368,7 +373,7 @@ def mean_netcdf_alldomain(start_year,end_year,direct,var):
|
|
368
373
|
for y in range(start_year,end_year+1):
|
369
374
|
# print(y)
|
370
375
|
fn=glob.glob(direct+'*'+str(y)+'**nc*')[0]
|
371
|
-
|
376
|
+
|
372
377
|
if y==start_year:
|
373
378
|
matrice=np.average(np.transpose((np.array(xr.open_dataset(fn)[var]))),axis=2)
|
374
379
|
else:
|
@@ -386,18 +391,19 @@ def mean_netcdf_alldomain(start_year,end_year,direct,var):
|
|
386
391
|
# for k in range(dimt):
|
387
392
|
# mat2add[i,j,k]=np.mean(matrice[i,j,:,k])
|
388
393
|
# matdaily=np.append(matdaily,mat2add,axis=2)
|
389
|
-
|
390
|
-
|
394
|
+
|
395
|
+
|
391
396
|
return(meant)
|
392
397
|
|
393
398
|
def quick_map_plot(lons,lats,mat,bounds,cmap,MSK=np.zeros(0),nticks=4):
|
399
|
+
from mpl_toolkits.basemap import Basemap
|
394
400
|
# filemask="/srv7_tmp1/jbrajkovic/These/EU-7.5km.nc"
|
395
401
|
# ds_mask=xr.open_dataset(filemask)
|
396
402
|
# mask=np.transpose(np.array(ds_mask.MASK[:,:]))
|
397
403
|
# MSK=mask==1
|
398
404
|
if MSK.shape[0]==0:
|
399
405
|
MSK=np.zeros_like(mat)==0
|
400
|
-
|
406
|
+
|
401
407
|
lon_center=4.96
|
402
408
|
# lon_center=np.mean(lats)
|
403
409
|
lat_center=50.56
|
@@ -414,13 +420,13 @@ def quick_map_plot(lons,lats,mat,bounds,cmap,MSK=np.zeros(0),nticks=4):
|
|
414
420
|
step=vmax/10.
|
415
421
|
# bounds = bounds=np.arange(0,105,5)
|
416
422
|
# cmap=cm.jet
|
417
|
-
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
|
423
|
+
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
|
418
424
|
x,y=m(lons,lats)
|
419
425
|
# print(x,y)
|
420
426
|
mapa=m.pcolormesh(x,y,mat,norm=norm,cmap=cmap)
|
421
427
|
# mapa=m.contourf(x,y,mat,norm=norm,cmap=cmap)
|
422
|
-
# m.contour(x,y,MSK,levels=0,linewidth=3.0)
|
423
|
-
|
428
|
+
# m.contour(x,y,MSK,levels=0,linewidth=3.0)
|
429
|
+
|
424
430
|
# ds_mask=xr.open_dataset(filemask)
|
425
431
|
# mask=np.transpose(np.array(ds_mask.MASK[:,:]))
|
426
432
|
# MSK=mask==1
|
@@ -433,7 +439,7 @@ def quick_map_plot(lons,lats,mat,bounds,cmap,MSK=np.zeros(0),nticks=4):
|
|
433
439
|
# color='black',
|
434
440
|
# arrowprops=dict(arrowstyle='Simple', color='black'),
|
435
441
|
# fontsize=24,weight='bold')
|
436
|
-
# plt.annotate(text1, xy=(0.9, 0.1), xycoords='axes fraction',
|
442
|
+
# plt.annotate(text1, xy=(0.9, 0.1), xycoords='axes fraction',
|
437
443
|
# color='black',
|
438
444
|
# fontsize=24,weight='bold')
|
439
445
|
# m.contourf(x,y,mat,norm=norm,cmap=cmap)
|
@@ -452,7 +458,7 @@ def quick_map_plot(lons,lats,mat,bounds,cmap,MSK=np.zeros(0),nticks=4):
|
|
452
458
|
# ha=ps1[i],va=pos[i],color='k')
|
453
459
|
# else:
|
454
460
|
# plt.text(xv[i], yv[i]-decalage[i], cities[i],fontsize=10,
|
455
|
-
# ha=ps1[i],va=pos[i],color='k',weight='bold')
|
461
|
+
# ha=ps1[i],va=pos[i],color='k',weight='bold')
|
456
462
|
# if i<=4:plt.scatter(xv[i], yv[i],marker='+',color='black',s=8)
|
457
463
|
# for item in [fig, ax]:
|
458
464
|
# item.patch.set_visible(False)
|
@@ -463,8 +469,9 @@ def quick_map_plot(lons,lats,mat,bounds,cmap,MSK=np.zeros(0),nticks=4):
|
|
463
469
|
cbar.ax.tick_params(labelsize=10)
|
464
470
|
# cbar.set_label('Height (m)',fontsize=14,labelpad=10)
|
465
471
|
# cbar.solids.set_edgecolor("face")
|
466
|
-
|
472
|
+
|
467
473
|
def quick_map_plot2(lons,lats,mat,bounds,cmap,ax):
|
474
|
+
from mpl_toolkits.basemap import Basemap
|
468
475
|
lat_0=50.6;lon_0=4.73
|
469
476
|
lon_center=lon_0
|
470
477
|
# lon_center=np.mean(lats)
|
@@ -481,11 +488,11 @@ def quick_map_plot2(lons,lats,mat,bounds,cmap,ax):
|
|
481
488
|
step=vmax/10.
|
482
489
|
# bounds = bounds=np.arange(0,105,5)
|
483
490
|
# cmap=cm.jet
|
484
|
-
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
|
491
|
+
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
|
485
492
|
x,y=m(lons,lats)
|
486
493
|
mapa=m.pcolormesh(x,y,mat,norm=norm,cmap=cmap )
|
487
494
|
return(mapa)
|
488
|
-
|
495
|
+
|
489
496
|
# def get_coordinates(path_to_file):
|
490
497
|
|
491
498
|
# with fiona.open(path_to_file) as shapefile:
|
@@ -495,62 +502,62 @@ def quick_map_plot2(lons,lats,mat,bounds,cmap,ax):
|
|
495
502
|
# print(record)
|
496
503
|
# # Read the shapefile
|
497
504
|
# gdf = gpd.read_file(path_to_file)
|
498
|
-
|
505
|
+
|
499
506
|
# # Print the first few rows of the GeoDataFrame
|
500
507
|
# print(gdf.head())
|
501
|
-
|
508
|
+
|
502
509
|
def mask_belgium(lon,lat,path_in,path_out,center_or_all=2):
|
503
|
-
|
504
|
-
"""This routine takes as arguments:
|
510
|
+
|
511
|
+
"""This routine takes as arguments:
|
505
512
|
-The longitudes and latitudes of the netcdf (gridded)
|
506
513
|
-a .tif file of the mask we want to create (tif must be in epsg:31370 lambbert 72)
|
507
514
|
and creates a mask at the resolution of the input netcdf which is saved as netcdf in path_out
|
508
|
-
|
509
|
-
L'option center_or_all precise si l'on souhaite qu'un des 4 coins des pixels chosisis soient à l'intérieur
|
515
|
+
|
516
|
+
L'option center_or_all precise si l'on souhaite qu'un des 4 coins des pixels chosisis soient à l'intérieur
|
510
517
|
de la zone ou si on regarde uniquement le centre.
|
511
518
|
Si center_or_all vaut 1, on ragarde uniquement le centre et donc le masque sera plus petit
|
512
|
-
|
519
|
+
|
513
520
|
conseil : raster d'une résolution 100 mètres en input'
|
514
521
|
"""
|
515
|
-
|
522
|
+
|
516
523
|
"Projecting lon lat to Lambert"
|
517
524
|
discheck=300000
|
518
525
|
lb=pyproj.Proj(projparams='epsg:31370')
|
519
526
|
xlb,ylb=lb(lon,lat)
|
520
527
|
if center_or_all!=0:
|
521
528
|
xlb_ur=np.zeros([xlb.shape[0],xlb.shape[1]])
|
522
|
-
ylb_ur=np.zeros([xlb.shape[0],xlb.shape[1]])
|
523
|
-
|
529
|
+
ylb_ur=np.zeros([xlb.shape[0],xlb.shape[1]])
|
530
|
+
|
524
531
|
xlb_ul=np.zeros([xlb.shape[0],xlb.shape[1]])
|
525
532
|
ylb_ul=np.zeros([xlb.shape[0],xlb.shape[1]])
|
526
|
-
|
527
|
-
|
533
|
+
|
534
|
+
|
528
535
|
xlb_bl=np.zeros([xlb.shape[0],xlb.shape[1]])
|
529
536
|
ylb_bl=np.zeros([xlb.shape[0],xlb.shape[1]])
|
530
|
-
|
531
|
-
xlb_br=np.zeros([xlb.shape[0],xlb.shape[1]])
|
532
|
-
ylb_br=np.zeros([xlb.shape[0],xlb.shape[1]])
|
533
|
-
|
537
|
+
|
538
|
+
xlb_br=np.zeros([xlb.shape[0],xlb.shape[1]])
|
539
|
+
ylb_br=np.zeros([xlb.shape[0],xlb.shape[1]])
|
540
|
+
|
534
541
|
"Calcul des sommets des pixels"
|
535
|
-
|
542
|
+
|
536
543
|
for i in range(1,xlb.shape[0]-1):
|
537
544
|
for j in range(1,xlb.shape[1]-1):
|
538
545
|
xlb_ur[i,j]=np.mean(lon[i-1:i+1,j:j+2]);ylb_ur[i,j]=np.mean(lat[i-1:i+1,j:j+2])
|
539
546
|
xlb_ul[i,j]=np.mean(lon[i-1:i+1,j-1:j+1]);ylb_ul[i,j]=np.mean(lat[i-1:i,j-1:j+1])
|
540
547
|
xlb_bl[i,j]=np.mean(lon[i:i+2,j-1:j+1]);ylb_bl[i,j]=np.mean(lat[i:i+2,j-1:j+1])
|
541
548
|
xlb_br[i,j]=np.mean(lon[i:i+2,j:j+2]);ylb_br[i,j]=np.mean(lat[i:i+2,j:j+2])
|
542
|
-
|
549
|
+
|
543
550
|
xlb_ur,ylb_ur=lb(xlb_ur,ylb_ur)
|
544
551
|
xlb_ul,ylb_ul=lb(xlb_ul,ylb_ul)
|
545
552
|
xlb_bl,ylb_bl=lb(xlb_bl,ylb_bl)
|
546
553
|
xlb_br,ylb_br=lb(xlb_br,ylb_br)
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
554
|
+
|
555
|
+
|
556
|
+
|
557
|
+
|
551
558
|
# print (ylb_ur[1:]-ylb[1:])
|
552
559
|
"Opening the raster file"
|
553
|
-
|
560
|
+
|
554
561
|
im = Image.open(path_in)
|
555
562
|
imarray = np.array(im)
|
556
563
|
|
@@ -570,11 +577,11 @@ def mask_belgium(lon,lat,path_in,path_out,center_or_all=2):
|
|
570
577
|
lons=lons[imarray!=0]
|
571
578
|
print(lats)
|
572
579
|
MSK=np.zeros(xlb.shape)
|
573
|
-
|
580
|
+
|
574
581
|
print(np.max(xs),np.max(ys))
|
575
|
-
|
582
|
+
|
576
583
|
"Finding the pixels which are in the zone"
|
577
|
-
|
584
|
+
|
578
585
|
"perimetre de recherche"
|
579
586
|
maxi_lat=np.max(lats)
|
580
587
|
mini_lat=np.min(lats)
|
@@ -592,7 +599,7 @@ def mask_belgium(lon,lat,path_in,path_out,center_or_all=2):
|
|
592
599
|
if abs(ylb[i,j]-maxi_lat)<disu and ylb[i,j]-maxi_lat>=0 :
|
593
600
|
iu=i
|
594
601
|
disu=abs(ylb[i,j]-maxi_lat)
|
595
|
-
|
602
|
+
|
596
603
|
if abs( ylb[i,j]-mini_lat)<disb and ylb[i,j]-mini_lat<=0:
|
597
604
|
ib=i
|
598
605
|
disb=abs( ylb[i,j]-mini_lat)
|
@@ -604,8 +611,8 @@ def mask_belgium(lon,lat,path_in,path_out,center_or_all=2):
|
|
604
611
|
if abs(xlb[i,j]-maxi_lon)<disr and xlb[i,j]-maxi_lon >=0 :
|
605
612
|
jr=j
|
606
613
|
disr=abs(xlb[i,j]-maxi_lon)
|
607
|
-
|
608
|
-
print(disu,disr,disb,disl)
|
614
|
+
|
615
|
+
print(disu,disr,disb,disl)
|
609
616
|
print(iu,ib,jl,jr)
|
610
617
|
# if iu==ib or jl==jr:
|
611
618
|
# iu=1;ib=xlb.shape[0]-1
|
@@ -626,7 +633,7 @@ def mask_belgium(lon,lat,path_in,path_out,center_or_all=2):
|
|
626
633
|
|
627
634
|
else:
|
628
635
|
msk_stp=lons[((abs(lons-xlb[i,j])<discheck)&(abs(lats-ylb[i,j])<discheck))]
|
629
|
-
|
636
|
+
|
630
637
|
# print(i,j)
|
631
638
|
# if i%10==0 and j==jl:
|
632
639
|
# print(i,j)
|
@@ -639,7 +646,7 @@ def mask_belgium(lon,lat,path_in,path_out,center_or_all=2):
|
|
639
646
|
|
640
647
|
# MSK
|
641
648
|
# time=[1]
|
642
|
-
|
649
|
+
|
643
650
|
"writing the output netcdf with the mask"
|
644
651
|
|
645
652
|
coords=dict(
|
@@ -650,7 +657,7 @@ def mask_belgium(lon,lat,path_in,path_out,center_or_all=2):
|
|
650
657
|
data=np.transpose(np.zeros([xlb.shape[0],xlb.shape[1]])),
|
651
658
|
dims=["y","x"],
|
652
659
|
coords=coords,
|
653
|
-
)
|
660
|
+
)
|
654
661
|
Mar_rain=xr.DataArray(
|
655
662
|
data=np.transpose(MSK),
|
656
663
|
dims=["y","x"],
|
@@ -665,54 +672,54 @@ def mask_belgium(lon,lat,path_in,path_out,center_or_all=2):
|
|
665
672
|
MSK=[MSK==1]
|
666
673
|
return (ylb)
|
667
674
|
# return(coords)
|
668
|
-
|
675
|
+
|
669
676
|
def mask_belgiumV2(lon,lat,path_in,path_out,center_or_all=2,discheck=300000,buffer=2):
|
670
|
-
"""This routine takes as arguments:
|
677
|
+
"""This routine takes as arguments:
|
671
678
|
-The longitudes and latitudes of the netcdf (gridded)
|
672
679
|
-a .tif file of the mask we want to create (tif must be in epsg:31370 lambbert 72)
|
673
680
|
and creates a mask at the resolution of the input netcdf which is saved as netcdf in path_out
|
674
|
-
|
675
|
-
L'option center_or_all precise si l'on souhaite qu'un des 4 coins des pixels chosisis soient à l'intérieur
|
681
|
+
|
682
|
+
L'option center_or_all precise si l'on souhaite qu'un des 4 coins des pixels chosisis soient à l'intérieur
|
676
683
|
de la zone ou si on regarde uniquement le centre.
|
677
684
|
Si center_or_all vaut 1, on ragarde uniquement le centre et donc le masque sera plus petit
|
678
|
-
|
685
|
+
|
679
686
|
conseil : raster d'une résolution 100 mètres en input'
|
680
687
|
"""
|
681
|
-
|
688
|
+
|
682
689
|
"Projecting lon lat to Lambert"
|
683
690
|
# discheck=300000
|
684
691
|
print('Check distance = '+str(discheck) + 'meters')
|
685
692
|
lb=pyproj.Proj(projparams='epsg:31370')
|
686
|
-
|
693
|
+
|
687
694
|
if center_or_all!=0:
|
688
695
|
xlb_ur=np.zeros_like(lon)
|
689
696
|
ylb_ur=np.zeros_like(lon)
|
690
|
-
|
697
|
+
|
691
698
|
xlb_ul=np.zeros_like(lon)
|
692
699
|
ylb_ul=np.zeros_like(lon)
|
693
|
-
|
694
|
-
|
700
|
+
|
701
|
+
|
695
702
|
xlb_bl=np.zeros_like(lon)
|
696
703
|
ylb_bl=np.zeros_like(lon)
|
697
|
-
|
704
|
+
|
698
705
|
xlb_br=np.zeros_like(lon)
|
699
706
|
ylb_br=np.zeros_like(lon)
|
700
|
-
|
707
|
+
|
701
708
|
"Calcul des sommets des pixels"
|
702
|
-
|
709
|
+
|
703
710
|
for i in range(1,lon.shape[0]-1):
|
704
711
|
for j in range(1,lon.shape[1]-1):
|
705
712
|
xlb_ur[i,j]=np.mean(lon[i-1:i+1,j:j+2]);ylb_ur[i,j]=np.mean(lat[i-1:i+1,j:j+2])
|
706
713
|
xlb_ul[i,j]=np.mean(lon[i-1:i+1,j-1:j+1]);ylb_ul[i,j]=np.mean(lat[i-1:i,j-1:j+1])
|
707
714
|
xlb_bl[i,j]=np.mean(lon[i:i+2,j-1:j+1]);ylb_bl[i,j]=np.mean(lat[i:i+2,j-1:j+1])
|
708
715
|
xlb_br[i,j]=np.mean(lon[i:i+2,j:j+2]);ylb_br[i,j]=np.mean(lat[i:i+2,j:j+2])
|
709
|
-
|
710
|
-
|
711
|
-
|
716
|
+
|
717
|
+
|
718
|
+
|
712
719
|
|
713
720
|
# print (ylb_ur[1:]-ylb[1:])
|
714
721
|
"Opening the raster file"
|
715
|
-
|
722
|
+
|
716
723
|
im = Image.open(path_in)
|
717
724
|
imarray = np.array(im)
|
718
725
|
|
@@ -727,25 +734,25 @@ def mask_belgiumV2(lon,lat,path_in,path_out,center_or_all=2,discheck=300000,buff
|
|
727
734
|
lons= np.array(xs)
|
728
735
|
lats = np.array(ys)
|
729
736
|
print('lons shape', lons.shape)
|
730
|
-
|
737
|
+
|
731
738
|
inProj=Proj(init='epsg:31370')
|
732
739
|
outProj = Proj(init='epsg:4326')
|
733
740
|
|
734
|
-
lons,lats=transform(inProj,outProj,lons,lats)
|
735
|
-
|
741
|
+
lons,lats=transform(inProj,outProj,lons,lats)
|
742
|
+
|
736
743
|
# print(ys,ylb)
|
737
744
|
# plt.imshow(imarray);plt.colorbar()
|
738
745
|
# plt.show()
|
739
746
|
lats=lats[imarray>0]
|
740
747
|
lons=lons[imarray>0]
|
741
|
-
|
748
|
+
|
742
749
|
print(lats)
|
743
750
|
MSK=np.zeros(lon.shape)
|
744
|
-
|
751
|
+
|
745
752
|
print(np.max(xs),np.max(ys))
|
746
|
-
|
753
|
+
|
747
754
|
"Finding the pixels which are in the zone"
|
748
|
-
|
755
|
+
|
749
756
|
"perimetre de recherche"
|
750
757
|
maxi_lat=np.max(lats)
|
751
758
|
mini_lat=np.min(lats)
|
@@ -758,7 +765,7 @@ def mask_belgiumV2(lon,lat,path_in,path_out,center_or_all=2,discheck=300000,buff
|
|
758
765
|
disb=disrech
|
759
766
|
disl=disrech
|
760
767
|
disr=disrech
|
761
|
-
|
768
|
+
|
762
769
|
print('lon max ',maxi_lon,mini_lon,me_lat,maxi_lat,mini_lat)
|
763
770
|
for i in range(lon.shape[0]):
|
764
771
|
# print(i)
|
@@ -766,27 +773,27 @@ def mask_belgiumV2(lon,lat,path_in,path_out,center_or_all=2,discheck=300000,buff
|
|
766
773
|
if ct.dis2pix(lat[i,j], lon[i,j], maxi_lat, lon[i,j])<disu and lat[i,j]>=maxi_lat:
|
767
774
|
iu=i
|
768
775
|
disu=ct.dis2pix(lat[i,j], lon[i,j], maxi_lat, lon[i,j])
|
769
|
-
|
770
|
-
if ct.dis2pix(lat[i,j], lon[i,j], mini_lat, lon[i,j])<disb and lat[i,j]<=mini_lat:
|
776
|
+
|
777
|
+
if ct.dis2pix(lat[i,j], lon[i,j], mini_lat, lon[i,j])<disb and lat[i,j]<=mini_lat:
|
771
778
|
ib=i
|
772
779
|
disb=ct.dis2pix(lat[i,j], lon[i,j], mini_lat, lon[i,j])
|
773
|
-
|
780
|
+
|
774
781
|
if ct.dis2pix(lat[i,j], lon[i,j], me_lat, mini_lon)<disl and lon[i,j]<=mini_lon:
|
775
782
|
jl=j
|
776
783
|
disl=ct.dis2pix(lat[i,j], lon[i,j], me_lat, mini_lon)
|
777
|
-
|
778
|
-
if ct.dis2pix(lat[i,j], lon[i,j], me_lat, maxi_lon)<disr and lon[i,j]>=maxi_lon:
|
779
|
-
|
784
|
+
|
785
|
+
if ct.dis2pix(lat[i,j], lon[i,j], me_lat, maxi_lon)<disr and lon[i,j]>=maxi_lon:
|
786
|
+
|
780
787
|
jr=j
|
781
788
|
disr=ct.dis2pix(lat[i,j], lon[i,j], me_lat, maxi_lon)
|
782
|
-
|
783
|
-
print(disu,disr,disb,disl)
|
789
|
+
|
790
|
+
print(disu,disr,disb,disl)
|
784
791
|
print(iu,ib,jl,jr)
|
785
792
|
print('aire latitudinale de recherche : '+"{:.0f}".format(lat[int(ib),int(jl)])+' '+"{:.0f}".format(lat[int(iu),int(jl)]))
|
786
793
|
ide=iu-2;ifi=ib+2
|
787
794
|
if ide<0:ide=0;
|
788
795
|
if ifi>lon.shape[0]:ifi=lon.shape[0]
|
789
|
-
|
796
|
+
|
790
797
|
jde=jl-2;jfi=jr+2
|
791
798
|
if jde<0:jde=0
|
792
799
|
if jr>lon.shape[0]:jfi=lon.shape[1]
|
@@ -800,36 +807,36 @@ def mask_belgiumV2(lon,lat,path_in,path_out,center_or_all=2,discheck=300000,buff
|
|
800
807
|
# msk_stp=lons[((abs(lons-xlb_ur[i,j])<100)&(abs(lats-ylb_ur[i,j])<100))]
|
801
808
|
if center_or_all !=2:
|
802
809
|
if center_or_all==1:
|
803
|
-
|
804
|
-
msk_stp=lons[((ct.dis2pix(lats, lons, lat[i,j], lon[i,j])<discheck)|
|
810
|
+
|
811
|
+
msk_stp=lons[((ct.dis2pix(lats, lons, lat[i,j], lon[i,j])<discheck)|
|
805
812
|
((ct.dis2pix(lats, lons, ylb_ur[i,j], xlb_ur[i,j]))<discheck)|
|
806
813
|
((ct.dis2pix(lats, lons, ylb_ul[i,j], xlb_ul[i,j]))<discheck)|
|
807
814
|
(ct.dis2pix(lats, lons, ylb_bl[i,j], xlb_bl[i,j])<discheck)|
|
808
815
|
((ct.dis2pix(lats, lons, ylb_br[i,j], xlb_br[i,j]))<discheck))]
|
809
|
-
|
810
|
-
|
816
|
+
|
817
|
+
|
811
818
|
else:
|
812
|
-
msk_stp=lons[(ct.dis2pix(lats, lons, lat[i,j], lon[i,j])<discheck)]
|
813
|
-
|
819
|
+
msk_stp=lons[(ct.dis2pix(lats, lons, lat[i,j], lon[i,j])<discheck)]
|
820
|
+
|
814
821
|
if np.size(msk_stp)!=0:#print('ok');
|
815
822
|
print(i,j)
|
816
823
|
MSK[i,j]=1
|
817
|
-
|
824
|
+
|
818
825
|
else:
|
819
|
-
dists=np.matrix([ct.dis2pix(center_pixel_lat, center_pixel_lon, lat[i,j], lon[i,j]),
|
826
|
+
dists=np.matrix([ct.dis2pix(center_pixel_lat, center_pixel_lon, lat[i,j], lon[i,j]),
|
820
827
|
ct.dis2pix(center_pixel_lat, center_pixel_lon, ylb_ur[i,j], xlb_ur[i,j]),
|
821
828
|
ct.dis2pix(center_pixel_lat, center_pixel_lon, ylb_ul[i,j], xlb_ul[i,j]),
|
822
829
|
ct.dis2pix(center_pixel_lat, center_pixel_lon, ylb_bl[i,j], xlb_bl[i,j]),
|
823
830
|
ct.dis2pix(center_pixel_lat, center_pixel_lon, ylb_br[i,j], xlb_br[i,j])])
|
824
831
|
min_dist=np.min(dists)
|
825
|
-
|
832
|
+
|
826
833
|
if min_dist<min_dist1:
|
827
834
|
min_dist1=min_dist
|
828
835
|
iic=i;jjc=j
|
829
836
|
if center_or_all==2:
|
830
837
|
MSK[iic-buffer:iic+buffer+1,jjc-buffer:jjc+buffer+1]=1
|
831
|
-
|
832
|
-
|
838
|
+
|
839
|
+
|
833
840
|
"writing the output netcdf with the mask"
|
834
841
|
|
835
842
|
coords=dict(
|
@@ -840,7 +847,7 @@ def mask_belgiumV2(lon,lat,path_in,path_out,center_or_all=2,discheck=300000,buff
|
|
840
847
|
data=np.transpose(np.zeros([lon.shape[0],lat.shape[1]])),
|
841
848
|
dims=["y","x"],
|
842
849
|
coords=coords,
|
843
|
-
)
|
850
|
+
)
|
844
851
|
Mar_rain=xr.DataArray(
|
845
852
|
data=np.transpose(MSK),
|
846
853
|
dims=["y","x"],
|
@@ -854,7 +861,7 @@ def mask_belgiumV2(lon,lat,path_in,path_out,center_or_all=2,discheck=300000,buff
|
|
854
861
|
Mar_ds.to_netcdf(path_out,mode='w',format=format1)
|
855
862
|
MSK=[MSK==1]
|
856
863
|
return (MSK)
|
857
|
-
|
864
|
+
|
858
865
|
def dis2pix(lat1,lon1,lat2,lon2):
|
859
866
|
lat1,lon1,lat2,lon2=np.deg2rad(lat1),np.deg2rad(lon1),np.deg2rad(lat2),np.deg2rad(lon2)
|
860
867
|
dis=np.arccos(np.sin(lat1)*np.sin(lat2)+np.cos(lat1)*np.cos(lat2)*np.cos(abs(lon1-lon2)))*6371000
|
@@ -873,7 +880,7 @@ def grid_mean(folder,year,var,season,sum_or_mean=0,nts=24,lev=0,nf=0,fn1='__'):
|
|
873
880
|
# print(fn)
|
874
881
|
seasons_names=['SP','SU','F','W','DJF','MAM','JJA','SON']
|
875
882
|
if season!='Y':
|
876
|
-
|
883
|
+
|
877
884
|
beg_seas=[81,173,265,356,335,60,152,244]
|
878
885
|
end_seas=[172,264,355,80,59,151,243,334]
|
879
886
|
for i in range(8):
|
@@ -911,7 +918,7 @@ def grid_mean(folder,year,var,season,sum_or_mean=0,nts=24,lev=0,nf=0,fn1='__'):
|
|
911
918
|
[:,:,0:es*nts+nts])
|
912
919
|
Ds=np.append(Ds,np.transpose(np.array(xr.open_dataset(fn1)['MBRR'])+\
|
913
920
|
np.array(xr.open_dataset(fn1)['MBSF']))\
|
914
|
-
[:,:,(bs-1)*nts+1:],axis=2)
|
921
|
+
[:,:,(bs-1)*nts+1:],axis=2)
|
915
922
|
Ds=np.average(Ds,axis=2)
|
916
923
|
else:
|
917
924
|
mat=np.array(xr.open_dataset(fn)[var])
|
@@ -937,23 +944,23 @@ def grid_mean(folder,year,var,season,sum_or_mean=0,nts=24,lev=0,nf=0,fn1='__'):
|
|
937
944
|
elif season=='Y' :
|
938
945
|
mat=np.transpose(mat)\
|
939
946
|
[:,:,:]
|
940
|
-
|
947
|
+
|
941
948
|
else:
|
942
949
|
mat=np.transpose(mat)\
|
943
950
|
[:,:,(bs-1)*nts+1: es*nts+nts]
|
944
|
-
|
945
|
-
|
951
|
+
|
952
|
+
|
946
953
|
if sum_or_mean:
|
947
|
-
|
954
|
+
|
948
955
|
Ds=np.sum(mat,axis=2)
|
949
|
-
|
956
|
+
|
950
957
|
else:
|
951
958
|
print(axis)
|
952
959
|
Ds=np.average(mat,axis=2)
|
953
960
|
|
954
|
-
|
961
|
+
|
955
962
|
return(Ds)
|
956
|
-
|
963
|
+
|
957
964
|
def find_pix_be(lon_p,lat_p,lons,lats):
|
958
965
|
Lb72=pyproj.Proj(projparams='epsg:31370')
|
959
966
|
xl,yl=Lb72(lon_p,lat_p)
|
@@ -990,18 +997,18 @@ def find_MARs_closest_pixel(lonsm,latsm,lonsi,latsi,neighbours=1):
|
|
990
997
|
else:
|
991
998
|
if dis2pixels[i,j,k,l]<dists[n] and\
|
992
999
|
dis2pixels[i,j,k,l]>dists[n-1]:
|
993
|
-
dists[n]=dis2pixels[i,j,k,l]
|
1000
|
+
dists[n]=dis2pixels[i,j,k,l]
|
994
1001
|
output[i,j,n,0]=k
|
995
1002
|
output[i,j,n,1]=l
|
996
1003
|
output[i,j,n,2]=1/(dists[n]/1000)
|
997
1004
|
return(output)
|
998
|
-
|
1005
|
+
|
999
1006
|
def IPCC_cmap():
|
1000
1007
|
cmap = mpl.colors.LinearSegmentedColormap.from_list("", [(84/256, 48/256, 5/256),
|
1001
1008
|
(245/256,245/256,245/256),
|
1002
1009
|
(0/256,60/256,48/256)])
|
1003
1010
|
return(cmap)
|
1004
|
-
|
1011
|
+
|
1005
1012
|
def draw_cities(m,fs_c=14,fs_C=16):
|
1006
1013
|
fs=10
|
1007
1014
|
cities=np.array(['Bruxelles','Charleroi','Liège',
|
@@ -1024,16 +1031,16 @@ def draw_cities(m,fs_c=14,fs_C=16):
|
|
1024
1031
|
plt.text(xv[i], yv[i]-decalage[i], cities[i],fontsize=fs_c,
|
1025
1032
|
ha=ps1[i],va=pos[i],color='k',weight='bold',
|
1026
1033
|
path_effects=[pe.withStroke(linewidth=4, foreground="white")])
|
1027
|
-
|
1034
|
+
|
1028
1035
|
else:
|
1029
1036
|
plt.text(xv[i], yv[i]-decalage[i], cities[i],fontsize=fs_C,
|
1030
|
-
ha=ps1[i],va=pos[i],color='k',weight='bold')
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1037
|
+
ha=ps1[i],va=pos[i],color='k',weight='bold')
|
1038
|
+
|
1039
|
+
|
1040
|
+
|
1034
1041
|
def draw_stations(m,n_id=1,fs=8):
|
1035
1042
|
|
1036
|
-
|
1043
|
+
|
1037
1044
|
stations_lons=[6.07960,5.912,6.228,
|
1038
1045
|
5.594,5.405,5.255,
|
1039
1046
|
4.591,4.653,4.471,
|
@@ -1043,7 +1050,7 @@ def draw_stations(m,n_id=1,fs=8):
|
|
1043
1050
|
4.539,5.470,5.072,
|
1044
1051
|
4.470,4.381,3.208,
|
1045
1052
|
2.856,2.668 ]
|
1046
|
-
|
1053
|
+
|
1047
1054
|
stations_lats=[50.511,50.478,50.459,
|
1048
1055
|
49.647,50.037,50.207,
|
1049
1056
|
50.094,50.226,50.478,
|
@@ -1053,7 +1060,7 @@ def draw_stations(m,n_id=1,fs=8):
|
|
1053
1060
|
51.064,51.170,51.270,
|
1054
1061
|
51.219,51.322
|
1055
1062
|
,51.322,51.200,51.126]
|
1056
|
-
|
1063
|
+
|
1057
1064
|
stations_names=['Mont-Rigi','Spa','Elsenborn',
|
1058
1065
|
'Buzenol','Saint-Hubert','Humain',
|
1059
1066
|
'Dourbes','Florennes','Gosselies',
|
@@ -1063,7 +1070,7 @@ def draw_stations(m,n_id=1,fs=8):
|
|
1063
1070
|
'Sint-Katelijne','Kleine-Brogel','Retie',
|
1064
1071
|
'Deurne','Stabroek','Zeebrugge',
|
1065
1072
|
'Middelkerke','Koksijde']
|
1066
|
-
|
1073
|
+
|
1067
1074
|
stations_index=['06494','06490','06496',
|
1068
1075
|
'06484','06476','06472',
|
1069
1076
|
'06455','06456','06449',
|
@@ -1079,18 +1086,18 @@ def draw_stations(m,n_id=1,fs=8):
|
|
1079
1086
|
# m.drawmapscale(5.5,49.2,5.5, 49)
|
1080
1087
|
for i in range(np.size(stations_lons)):
|
1081
1088
|
plt.text(xv[i], yv[i], te[i],fontsize=fs,
|
1082
|
-
color='k',weight='bold')
|
1083
|
-
|
1084
|
-
|
1089
|
+
color='k',weight='bold')
|
1090
|
+
|
1091
|
+
|
1085
1092
|
def box_plot(data, edge_color, fill_color,ax):
|
1086
1093
|
bp = ax.boxplot(data, patch_artist=True)
|
1087
|
-
|
1094
|
+
|
1088
1095
|
for element in ['boxes', 'whiskers', 'fliers', 'means', 'medians', 'caps']:
|
1089
1096
|
plt.setp(bp[element], color=edge_color)
|
1090
1097
|
|
1091
1098
|
for patch in bp['boxes']:
|
1092
|
-
patch.set(facecolor=fill_color)
|
1093
|
-
|
1099
|
+
patch.set(facecolor=fill_color)
|
1100
|
+
|
1094
1101
|
return bp
|
1095
1102
|
|
1096
1103
|
|
@@ -1102,7 +1109,7 @@ def endmonth(year):
|
|
1102
1109
|
return(em)
|
1103
1110
|
|
1104
1111
|
def radar_coord():
|
1105
|
-
|
1112
|
+
|
1106
1113
|
radar='/srv5_tmp3/RADCLIM/2021/20210714230000.radclim.accum1h.hdf'
|
1107
1114
|
f = h5py.File(radar, "r")
|
1108
1115
|
|
@@ -1116,12 +1123,12 @@ def radar_coord():
|
|
1116
1123
|
lr_x = ul_x + (xsize*xscale)
|
1117
1124
|
lr_x = ul_x + (xsize*xscale)
|
1118
1125
|
lr_y = ul_y - (ysize*yscale)
|
1119
|
-
|
1126
|
+
|
1120
1127
|
x=np.arange(ul_x, lr_x, xscale) + xscale/2
|
1121
1128
|
y=np.arange(lr_y, ul_y, yscale) - yscale/2
|
1122
|
-
|
1129
|
+
|
1123
1130
|
xx,yy = np.meshgrid(x,y)
|
1124
|
-
|
1131
|
+
|
1125
1132
|
yy= np.flip(yy)
|
1126
1133
|
|
1127
1134
|
inProj=Proj(r'+proj=lcc +lat_1=49.83333333333334 +lat_2=51.16666666666666 +lat_0=50.797815 +lon_0=4.359215833333333 +x_0=649328 +y_0=665262 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs ')
|
@@ -1144,7 +1151,7 @@ def RGEV(retp,nyears,loc,sca,sha):
|
|
1144
1151
|
|
1145
1152
|
def GEV_frequency(value,loc,sca,sha):
|
1146
1153
|
prob=1-np.exp(-(1-(((loc-value)*sha)/sca))**(-1/sha))
|
1147
|
-
|
1154
|
+
|
1148
1155
|
ret=(1/prob)
|
1149
1156
|
return(ret)
|
1150
1157
|
|
@@ -1161,8 +1168,8 @@ def GEVCI(retp,loc,sc,sh,
|
|
1161
1168
|
return(CI)
|
1162
1169
|
|
1163
1170
|
|
1164
|
-
|
1165
|
-
|
1171
|
+
|
1172
|
+
|
1166
1173
|
|
1167
1174
|
def gumCI(retp,loc,sc,
|
1168
1175
|
varloc,varsc,
|
@@ -1173,7 +1180,7 @@ def gumCI(retp,loc,sc,
|
|
1173
1180
|
S2T=derloc**2*varloc+dersc**2*varsc+2*derloc*dersc*covlocsc
|
1174
1181
|
CI=S2T**0.5*1.645
|
1175
1182
|
return(CI)
|
1176
|
-
|
1183
|
+
|
1177
1184
|
|
1178
1185
|
def RGum(retp,nyears,loc,sca):
|
1179
1186
|
prob=1/(retp)#*nyears)
|
@@ -1190,7 +1197,7 @@ def extreme_matrix(fn,ret_per=20,value=50,mx=80,my=50,abs_or_retour=1,ydays=365,
|
|
1190
1197
|
|
1191
1198
|
f=open(fn,'r')
|
1192
1199
|
indice_suivi=0
|
1193
|
-
|
1200
|
+
|
1194
1201
|
mat=np.zeros([mx,my])*float('nan')
|
1195
1202
|
mv=np.array(ret_per*ydays)
|
1196
1203
|
for line in f:
|
@@ -1216,10 +1223,10 @@ def extreme_matrix(fn,ret_per=20,value=50,mx=80,my=50,abs_or_retour=1,ydays=365,
|
|
1216
1223
|
th=float(columns[9])
|
1217
1224
|
varsh=float(columns[4])
|
1218
1225
|
varsc=float(columns[3])
|
1219
|
-
cov=float(columns[5])
|
1226
|
+
cov=float(columns[5])
|
1220
1227
|
pu=ne/(ydays*(end_year-start_year+1));teta=ncl/ne
|
1221
|
-
if abs_or_retour:
|
1222
|
-
|
1228
|
+
if abs_or_retour:
|
1229
|
+
|
1223
1230
|
if sha==0:
|
1224
1231
|
continue
|
1225
1232
|
mat[i,j]=ct.RGPD(mv,sha,sca,pu,teta,th)
|
@@ -1238,7 +1245,7 @@ def extreme_matrix(fn,ret_per=20,value=50,mx=80,my=50,abs_or_retour=1,ydays=365,
|
|
1238
1245
|
nye=end_year-start_year+1
|
1239
1246
|
if abs_or_retour: mat[i,j]=ct.RGEV(ret_per,nye,loc,sca,sha)
|
1240
1247
|
else:mat[i,j]=ct.GEV_frequency(value[i,j],loc,sca, sha)
|
1241
|
-
|
1248
|
+
|
1242
1249
|
elif gpd_gev_gum==2:
|
1243
1250
|
nye=end_year-start_year+1
|
1244
1251
|
loc=float(columns[13])
|
@@ -1255,14 +1262,14 @@ def extreme_matrix_V2(fn,ret_per=20,value=50,mx=80,my=50,
|
|
1255
1262
|
gpd_gev_gum=0,unst_st=0,var_unst='MKam',y_unst=2021):
|
1256
1263
|
# print('ok')
|
1257
1264
|
|
1258
|
-
|
1265
|
+
|
1259
1266
|
data=ct.df_from_file(fn)
|
1260
1267
|
mat=np.zeros([mx,my])*float('nan')
|
1261
1268
|
mv=np.array(ret_per*ydays)
|
1262
|
-
|
1269
|
+
|
1263
1270
|
for p in range(data.shape[0]):
|
1264
1271
|
# for line in f:
|
1265
|
-
|
1272
|
+
|
1266
1273
|
ind_pix=data['indice'][p]
|
1267
1274
|
if ind_pix<=my:
|
1268
1275
|
i=0;j=ind_pix
|
@@ -1274,7 +1281,7 @@ def extreme_matrix_V2(fn,ret_per=20,value=50,mx=80,my=50,
|
|
1274
1281
|
if j==0:j=my-1;i=i-1
|
1275
1282
|
else:j=j-1
|
1276
1283
|
if unst_st==0:
|
1277
|
-
|
1284
|
+
|
1278
1285
|
if gpd_gev_gum==0:
|
1279
1286
|
sca=data['sc'][p]
|
1280
1287
|
sha=data['sh'][p]
|
@@ -1285,7 +1292,7 @@ def extreme_matrix_V2(fn,ret_per=20,value=50,mx=80,my=50,
|
|
1285
1292
|
varsc=data['varsc'][p]
|
1286
1293
|
cov=data['cov'][p]
|
1287
1294
|
pu=ne/(ydays*(end_year-start_year+1));teta=ncl/ne
|
1288
|
-
if abs_or_retour:
|
1295
|
+
if abs_or_retour:
|
1289
1296
|
if sha==0:
|
1290
1297
|
continue
|
1291
1298
|
mat[i,j]=ct.RGPD(mv,sha,sca,pu,teta,th)
|
@@ -1304,7 +1311,7 @@ def extreme_matrix_V2(fn,ret_per=20,value=50,mx=80,my=50,
|
|
1304
1311
|
nye=end_year-start_year+1
|
1305
1312
|
if abs_or_retour: mat[i,j]=ct.RGEV(ret_per,nye,loc,sca,sha)
|
1306
1313
|
else:mat[i,j]=ct.GEV_frequency(value[i,j],loc,sca, sha)
|
1307
|
-
|
1314
|
+
|
1308
1315
|
elif gpd_gev_gum==2:
|
1309
1316
|
nye=end_year-start_year+1
|
1310
1317
|
loc=data['GUMshape'][p]
|
@@ -1326,7 +1333,7 @@ def extreme_matrix_V2(fn,ret_per=20,value=50,mx=80,my=50,
|
|
1326
1333
|
slam=data['slam'][p]
|
1327
1334
|
th=th+(y_unst-start_year)*slam
|
1328
1335
|
sca=sca+(y_unst-start_year)*slam
|
1329
|
-
if abs_or_retour:
|
1336
|
+
if abs_or_retour:
|
1330
1337
|
if sha==0:
|
1331
1338
|
continue
|
1332
1339
|
mat[i,j]=ct.RGPD(mv,sha,sca,pu,teta,th)
|
@@ -1348,19 +1355,19 @@ def extreme_matrix_V2(fn,ret_per=20,value=50,mx=80,my=50,
|
|
1348
1355
|
nye=end_year-start_year+1
|
1349
1356
|
if abs_or_retour: mat[i,j]=ct.RGEV(ret_per,nye,loc,sca,sha)
|
1350
1357
|
else:mat[i,j]=ct.GEV_frequency(value[i,j],loc,sca, sha)
|
1351
|
-
|
1358
|
+
|
1352
1359
|
elif gpd_gev_gum==2:
|
1353
1360
|
nye=end_year-start_year+1
|
1354
1361
|
loc=data['GUMshape'][p]
|
1355
1362
|
sca=data['GUMscale'][p]
|
1356
1363
|
if abs_or_retour: mat[i,j]=ct.RGum(ret_per,nye,loc,sca)
|
1357
1364
|
else:mat[i,j]=ct.Gum_frequency(value[i,j],loc,sca)
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1365
|
+
|
1366
|
+
|
1367
|
+
|
1368
|
+
|
1369
|
+
|
1370
|
+
|
1364
1371
|
return(mat)
|
1365
1372
|
|
1366
1373
|
def find_clusters(TS1):
|
@@ -1380,7 +1387,7 @@ def find_clusters(TS1):
|
|
1380
1387
|
cl_ind=t
|
1381
1388
|
while suiv<r and t1<np.size(TS):
|
1382
1389
|
suiv+=1
|
1383
|
-
|
1390
|
+
|
1384
1391
|
# print(t1)
|
1385
1392
|
if pd.isna(TS[t1])==False:
|
1386
1393
|
# print('ok')
|
@@ -1388,13 +1395,13 @@ def find_clusters(TS1):
|
|
1388
1395
|
if TS[t1]>cl_maxima:cl_maxima=TS[t1];cl_ind=t1
|
1389
1396
|
# print(suiv)
|
1390
1397
|
t1+=1
|
1391
|
-
|
1398
|
+
|
1392
1399
|
clss=np.append(clss,cl_maxima)
|
1393
1400
|
indexes=np.append(indexes,cl_ind)
|
1394
1401
|
# print(cls_dates.shape)
|
1395
|
-
|
1402
|
+
|
1396
1403
|
t=t1
|
1397
|
-
|
1404
|
+
|
1398
1405
|
t+=1
|
1399
1406
|
return(clss,indexes)
|
1400
1407
|
|
@@ -1407,21 +1414,21 @@ def df_from_file(fn):
|
|
1407
1414
|
lines=line.strip()
|
1408
1415
|
lines=lines.split()
|
1409
1416
|
if suiv>0:
|
1410
|
-
|
1411
|
-
|
1417
|
+
|
1418
|
+
|
1412
1419
|
dat=lines[0]
|
1413
1420
|
vappend=np.zeros([1,np.size(lines[:])])
|
1414
1421
|
# dates=np.append(dates,dat[1:-1])
|
1415
1422
|
for i in range(vappend.shape[1]):
|
1416
1423
|
vappend[0,i]=float(lines[i])
|
1417
|
-
|
1424
|
+
|
1418
1425
|
if suiv==1:
|
1419
1426
|
data=vappend
|
1420
1427
|
else:
|
1421
1428
|
data=np.append(data,vappend,axis=0)
|
1422
1429
|
else:
|
1423
1430
|
vnames=lines
|
1424
|
-
|
1431
|
+
|
1425
1432
|
data=pd.DataFrame(data)
|
1426
1433
|
data.columns=vnames
|
1427
1434
|
return(data)
|