-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpcc_ckx_stat.py
350 lines (257 loc) · 12.3 KB
/
pcc_ckx_stat.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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#!/usr/bin/env python
import h5py
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import glob
import math
import pandas as pd
import wradlib
from scipy import stats
import matplotlib.cm as cm
my_cmap = cm.get_cmap('jet',40)
my_cmap.set_under('lightgrey')
my_cmap.set_over('darkred')
from pcc import get_miub_cmap as my_cmap
from pcc import plot_radar
from pcc import boxpol_pos
from pcc import plot_borders
import wradlib as wrl
from osgeo import osr
from satlib import ipoli_radi_stat
from satlib import corcor
Pos = boxpol_pos()
blon0, blat0 = Pos['lon_ppi'], Pos['lat_ppi']
bbx, bby = Pos['gkx_ppi'], Pos['gky_ppi']
from time import *
from pcc import cut_the_swath
from satlib import good_overpasses_dpr_boxpol as overpasses_dpr_boxpol
print ("_")
tstart = clock()
#print (overpasses_dpr_boxpol)
for ii in overpasses_dpr_boxpol.keys()[0]:
ZP = overpasses_dpr_boxpol[ii][0],
pfadnr = overpasses_dpr_boxpol[ii][1]
enigma = overpasses_dpr_boxpol[ii][2]
offset = overpasses_dpr_boxpol[ii][3]
ZP = ZP[0]
print type(ZP), type(pfadnr), type(enigma), type(offset)
print ZP, pfadnr, enigma, offset
#ZP = '20180125170330'; pfadnr=0; enigma='neu'; offset=1
# Pfade zu den Dateien festlegen
#-----------------------------#
year = ZP[0:4]; ye = ZP[2:4]; m = ZP[4:6]; d = ZP[6:8]; ht = ZP[8:10]; mt = ZP[10:12]; st = ZP[12:14]
print('/automount/ags/velibor/gpmdata/dprV7/2A.GPM.DPR.V7-20170308.' + year + m + d + '*.HDF5')
#pfad_radar = glob.glob('/automount/ags/velibor/gpmdata/dpr/2A.GPM.DPR.V6-20160118.' + year + m + d + '*.HDF5')
pfad_radar = glob.glob('/automount/ags/velibor/gpmdata/dprV7/2A.GPM.DPR.V7-20170308.' + year + m + d + '*.HDF5')
print ('GPM:',pfad_radar)
pfad_radar = pfad_radar[pfadnr]
#pfad_radar_Ku = pfad_radar[0]
deg_scan = ["/ppi_1p5deg/","/ppi_2p4deg/","/ppi_3p4deg/",
"/n_ppi_010deg/","/n_ppi_045deg/",
"/n_ppi_082deg/","/n_ppi_110deg/","/n_ppi_140deg/",
"/n_ppi_180deg/","/n_ppi_280deg/","/n_vertical_scan/"][0]
if enigma=='neu':
print ('New enigma')
deg_scan = ["/n_ppi_010deg/"][0]
boxpolpath = '/automount/radar/scans/' + year+ "/" +year +"-"+ m + "/" + year+ "-" + m +"-"+ d +\
deg_scan+"*"+year+m+d+ht+mt+st+"*.h5"
print (boxpolpath)
ppi_datapath=glob.glob(boxpolpath)
print ('Boxpol: ',ppi_datapath)
ppi_datapath = ppi_datapath[0]
else:
try:
ppi_datapath=glob.glob('/automount/radar-archiv/scans/' + year+ "/" +
year +"-"+ m + "/" + year+ "-" + m +"-"+ d +
deg_scan+ year + "-" + m +"-"+ d + "--" +ht +
":"+mt+":"+st+",*.mvol")
print ppi_datapath
ppi_datapath = ppi_datapath[0]
except:
ppi_datapath=glob.glob('/automount/radar/scans/' + year+ "/" +
year +"-"+ m + "/" + year+ "-" + m +"-"+
d + deg_scan+ year + "-" + m +"-"+ d +
"--" +ht +":"+mt+":"+st+",*.mvol")
print ('Old enigma')
print ('Boxpol: ',ppi_datapath)
ppi_datapath = ppi_datapath[0]
# Wichtige Parameter festlegen
TH = 15 #Threshold um Nullen fuer Niederschlag raus zu filtern
#################################################### PPI BoxPol Daten einlesen
#------------------------------------------------------------------------------
ppi=h5py.File(ppi_datapath,'r')
data, attrs = wradlib.io.read_GAMIC_hdf5(ppi_datapath)
ZH0 = data['SCAN0']['ZH']['data']
PHIDP = data['SCAN0']['PHIDP']['data']
r = attrs['SCAN0']['r']
az = attrs['SCAN0']['az']
elevation=attrs['SCAN0']['elevation']
lon_ppi = attrs['VOL']['Longitude']
lat_ppi = attrs['VOL']['Latitude']
alt_ppi = attrs['VOL']['Height']
rho = data['SCAN0']['RHOHV']['data']
R = ZH0
print ("________Beam Blockage______")
R[151:165]=np.nan
print (np.nanmax(R))
print ("________CLUTTER______")
rho_th = 0.85
R[rho<= rho_th] = np.nan
print (np.nanmax(R))
print ("________offset______")
R = R + offset
print (np.nanmax(R))
#?
print ("________ATTCORR______")
"""pia = wrl.atten.correctAttenuationHB(
R,
coefficients = dict(a=4.57e-5, b=0.731, gate_length=1.0),
mode="warn",
thrs=59.)
pia[pia > 4.8] = 4.8
print ("________ATTCORR2______")
R = R + pia
print (np.nanmax([R,pia]))"""
print ("________DPR Threshold______")
Z_boxpol = R
### Threshold for DPR sensitivity
Z_boxpol[Z_boxpol<TH]=np.nan
################################################################# DPR Einlesen
# -----------------------------------------------------------------------------
scan = 'MS'
gpmku = h5py.File(pfad_radar, 'r')
gpmku_HS = gpmku[scan]['SLV']
dpr_lat_1 = np.array(gpmku[scan]['Latitude'])
dpr_lon_1 = np.array(gpmku[scan]['Longitude'])
Z_dpr = np.array(gpmku_HS['zFactorCorrectedNearSurface'])
Z_dpr[Z_dpr < TH] = np.nan
## Einlesen von Phase un Raintype
dpr_raintype = np.array(gpmku[scan]['CSF']['typePrecip'], dtype=float)
dpr_phase = np.array(gpmku_HS['phaseNearSurface'], dtype=float)
############################################################## RADOLAN einlesen
# -----------------------------------------------------------------------------
mtt = mt
mtt = str(int(round(float(mtt)/5.0)*5.0))
if mtt == '0':
mtt = '00'
if mtt == '5':
mtt = '05'
if mtt == '60':
mtt = '55'
r_pro = 'rx'
pfad = ('/automount/radar/dwd/'+ r_pro +'/'+str(year)+'/'+str(year)+'-'+
str(m)+'/'+ str(year)+'-'+str(m)+'-'+str(d)+'/raa01-'+r_pro+'_10000-'+
str(ye)+str(m)+ str(d)+str(ht)+str(mtt)+'-dwd---bin.gz')
print ('RADOLANPFAD: ', pfad)
pfad_radolan = pfad[:-3]
try:
rw_filename = wradlib.util.get_wradlib_data_file(pfad)
except EnvironmentError:
rw_filename = wradlib.util.get_wradlib_data_file(pfad_radolan)
rwdata, rwattrs = wradlib.io.read_RADOLAN_composite(rw_filename)
radolan_zeit = rwattrs['datetime'].strftime("%Y.%m.%d -- %H:%M:%S")
radolan_grid_xy = wradlib.georef.get_radolan_grid(900,900)
x = radolan_grid_xy[:,:,0]
y = radolan_grid_xy[:,:,1]
rwdata = np.ma.masked_equal(rwdata, -9999) / 2 - 32.5
### Threshold for DPR sensitivity
rwdata[rwdata<TH]=np.nan
Z_radolan = rwdata
######################################################## Cut the Swath for Bonn
# -----------------------------------------------------------------------------
dpr_lon, dpr_lat, Z_dpr = cut_the_swath(dpr_lon_1,dpr_lat_1,Z_dpr, eu=0)
dpr_lon, dpr_lat, dpr_raintype = cut_the_swath(dpr_lon_1,dpr_lat_1,dpr_raintype, eu=0)
dpr_lon, dpr_lat, dpr_phase = cut_the_swath(dpr_lon_1,dpr_lat_1,dpr_phase, eu=0)
######################################################## Koordinaten Projektion
# -----------------------------------------------------------------------------
proj_stereo = wrl.georef.create_osr("dwd-radolan")
proj_wgs = osr.SpatialReference()
proj_wgs.ImportFromEPSG(4326)
dpr_lon, dpr_lat = wradlib.georef.reproject(dpr_lon, dpr_lat,
projection_target=proj_stereo ,
projection_source=proj_wgs)
blon, blat = wradlib.georef.reproject(blon0, blat0,
projection_target=proj_stereo ,
projection_source=proj_wgs)
############################################################### Dpr zuschneiden
#------------------------------------------------------------------------------
print ('Max --------------------------------------->', r[-1]/1000.)
inner_r = 15. # in km!!!!
print ('Min --------------------------------------->', inner_r)
lon0, lat0, radius = blon, blat, r[-1]/1000.
rr = np.sqrt((dpr_lat - lat0)**2 + (dpr_lon - lon0)**2)
position = rr < radius
# Maximum Range
Z_dpr[np.where(rr > radius)] = np.nan
dpr_raintype[np.where(rr > radius)] = np.nan
dpr_phase[np.where(rr > radius)] = np.nan
# Minimum Range
Z_dpr[np.where(rr < inner_r)] = np.nan
dpr_raintype[np.where(rr < inner_r)] = np.nan
dpr_phase[np.where(rr < inner_r)] = np.nan
########################################################### RADOLAN zuschneiden
#------------------------------------------------------------------------------
rr2 = np.sqrt((y - lat0)**2 + (x - lon0)**2)
position2 = rr2 < radius
# Maximum Range
Z_radolan[np.where(rr2 > radius)] = np.nan
# Minimum Range
Z_radolan[np.where(rr2 < inner_r)] = np.nan
########################################################### BoXPol zuschneiden
#------------------------------------------------------------------------------
# Minimum Range
a = (inner_r*1000.)/(r[1]-r[0])# inner_r in m!!!!
a = a.astype(int) # bin bis zu welchem radius alles NaN gesetzt wird
Z_boxpol[:,0:a]=np.nan
print (a)
############################################################### Inverse Dezibel
#------------------------------------------------------------------------------
Z_boxpol = wradlib.trafo.idecibel(Z_boxpol)
Z_dpr = wradlib.trafo.idecibel(Z_dpr)
Z_radolan = wradlib.trafo.idecibel(Z_radolan)
################################################## BoXPol interpolieren auf DPR
#------------------------------------------------------------------------------
t1 = clock()
radar_location = (lon_ppi, lat_ppi, alt_ppi)
#elevation = 1.5
azimuths = az
ranges = r
polargrid = np.meshgrid(ranges, azimuths)
lon, lat, alt = wradlib.georef.polar2lonlatalt_n(polargrid[0], polargrid[1],
elevation, radar_location)
lon, lat = wradlib.georef.reproject(lon, lat, projection_target=proj_stereo ,
projection_source=proj_wgs)
grid_xy = np.vstack((dpr_lon.ravel(), dpr_lat.ravel())).transpose()
xy=np.concatenate([lon.ravel()[:,None],lat.ravel()[:,None]], axis=1)
Z_boxpol_ipoli, Z_boxpol_ipoli_std, Z_boxpol_ipoli_median, Z_boxpol_ipoli_max, Z_boxpol_ipoli_min = ipoli_radi_stat(xy,Z_boxpol.ravel(),grid_xy,2.5)
Z_boxpol_ipoli = Z_boxpol_ipoli.reshape(dpr_lon.shape)
Z_boxpol_ipoli_std = Z_boxpol_ipoli_std.reshape(dpr_lon.shape)
Z_boxpol_ipoli_median = Z_boxpol_ipoli_median.reshape(dpr_lon.shape)
Z_boxpol_ipoli_max = Z_boxpol_ipoli_max.reshape(dpr_lon.shape)
Z_boxpol_ipoli_min = Z_boxpol_ipoli_min.reshape(dpr_lon.shape)
t2 = clock()
print ('Interpolationsdauer Boxpol auf DPR:', t2 - t1)
################################################# RADOLAN interpolieren auf DPR
#------------------------------------------------------------------------------
xy_rado = np.vstack((x.ravel(), y.ravel())).transpose()
Z_radolan_ipoli, Z_radolan_ipoli_std, Z_radolan_ipoli_median, Z_radolan_ipoli_max, Z_radolan_ipoli_min = ipoli_radi_stat(xy_rado,Z_radolan.ravel().filled(np.nan),grid_xy,2.5)
Z_radolan_ipoli = Z_radolan_ipoli.reshape(dpr_lon.shape)
Z_radolan_ipoli_std = Z_radolan_ipoli_std.reshape(dpr_lon.shape)
Z_radolan_ipoli_median = Z_radolan_ipoli_median.reshape(dpr_lon.shape)
Z_radolan_ipoli_max = Z_radolan_ipoli_max.reshape(dpr_lon.shape)
Z_radolan_ipoli_min = Z_radolan_ipoli_min.reshape(dpr_lon.shape)
t3 = clock()
print ('Interpolationsdauer RADOLAN auf DPR:', t3 - t2)
################################################################### in Dezibel
#------------------------------------------------------------------------------
Z_boxpol = wradlib.trafo.decibel(Z_boxpol)
Z_dpr = wradlib.trafo.decibel(Z_dpr)
Z_radolan = wradlib.trafo.decibel(Z_radolan)
Z_boxpol_ipoli = wradlib.trafo.decibel(Z_boxpol_ipoli)
Z_radolan_ipoli = wradlib.trafo.decibel(Z_radolan_ipoli)
#zwischenspeichern
#np.save('/automount/ags/velibor/data/dpr_boxpol_radolan/test/median/'+ZP+'.npy',
# [Z_dpr, Z_boxpol, Z_boxpol_ipoli, Z_radolan, Z_radolan_ipoli, dpr_phase, dpr_raintype, dpr_lon, dpr_lat])
tend = clock()
print ('Gesamtlaufzeit: ',(tend-tstart)/60., 'min')