Untitled5: Warnings
Untitled5: Warnings
Untitled5: Warnings
September 5, 2020
[2]: '1.8.0'
# conda environments:
#
base C:\Users\Usuario\anaconda3
myenv C:\Users\Usuario\anaconda3\envs\myenv
pyart_env C:\Users\Usuario\anaconda3\envs\pyart_env
wradlib * C:\Users\Usuario\anaconda3\envs\wradlib
C:\Users\Usuario\miniconda3
Note: you may need to restart the kernel to use updated packages.
1
Archivo GPM 2A-CS-Ku
trmm_2a25_file = wrl.util.get_wradlib_data_file('trmm/2A-CS-151E24S154E30S.TRMM.
,→PR.2A25.20100206-S111425-E111526.069662.7.HDF')
2
gr_data = wrl.io.read_generic_netcdf(filename)
dat = gr_data['what']['date']
tim = gr_data['what']['time']
date = dt.datetime.strptime(dat + tim, "%Y%d%m%H%M%S")
source = gr_data['what']['source']
lon = gr_data['where']['lon']
lat = gr_data['where']['lat']
alt = gr_data['where']['height']
if gr_data['what']['object'] == 'PVOL':
ntilt = _get_tilts(gr_data)
else:
raise ValueError('GR file is no PPI/Volume File')
if ((len(np.unique(r0)) != 1) |
(len(np.unique(dr)) != 1) |
(len(np.unique(a0)) != 1) |
(len(np.unique(nbeam)) != 1) |
(nbeam[0] != 360)):
raise ValueError('GroundRadar Data layout dos not match')
gr_dict = {}
gr_dict.update({'source': source, 'date': date, 'lon': lon, 'lat': lat,
'alt': alt, 'ngate': ngate, 'nbeam': nbeam, 'ntilt': ntilt,
'r0': r0, 'dr': dr, 'a0': a0, 'elang': elang})
if not loaddata:
return gr_dict
sdate = []
refl = []
3
for i in range(0, ntilt):
dset = gr_data['dataset{0}'.format(i+1)]
dat = dset['what']['startdate']
tim = dset['what']['starttime']
date = dt.datetime.strptime(dat + tim, "%Y%d%m%H%M%S")
sdate.append(date)
data = dset['data1']
quantity = data['what']['quantity']
factor = data['what']['gain']
offset = data['what']['offset']
if quantity == 'DBZH':
dat = data['variables']['data']['data'] * factor + offset
refl.append(dat)
sdate = np.array(sdate)
refl = np.array(refl)
return gr_dict
4
alt0_gr = gr_data['alt']
# Beam width of GR (degree)
bw_gr = 1.
print(elev_gr, lon0_gr)
1.2999999523162842 153.24000549316406
[[[-- -- -- … -- -- --]
[-- -- -- … -- -- --]
[-- -- -- … -- -- --]
…
[-- -- -- … -- -- --]
[-- -- -- … -- -- --]
[-- -- -- … -- -- --]]
[[-- -- -- … -- -- --]
[-- -- -- … -- -- --]
[-- -- -- … -- -- --]
…
[-- -- -- … -- -- --]
5
[-- -- -- … -- -- --]
[-- -- -- … -- -- --]]
[[-- -- -- … -- -- --]
[-- -- -- … -- -- --]
[-- -- -- … -- -- --]
…
[-- -- -- … -- -- --]
[-- -- -- … -- -- --]
[-- -- -- … -- -- --]]
[[-- -- -- … -- -- --]
[-- -- -- … -- -- --]
[-- -- -- … -- -- --]
…
[-- -- -- … -- -- --]
[15.90999984741211 15.930000305175781 15.920000076293945 … -- -- --]
[-- 15.0 15.020000457763672 … -- -- --]]
[[-- -- -- … -- -- --]
[-- -- -- … -- -- --]
[-- -- -- … -- -- --]
…
[-- -- -- … -- -- --]
[-- -- -- … -- -- --]
[-- -- -- … -- -- --]]
[[-- -- -- … -- -- --]
[-- -- -- … -- -- --]
[-- -- -- … -- -- --]
…
[-- -- -- … -- -- --]
[-- -- -- … -- -- --]
[-- -- -- … -- -- --]]]
6
# Number of gates in one SR ray
ngate_sr = sr_data['nbin']
[16]: print(sr_lon.shape)
(82, 49)
squeeze=True)
print("XYZ-Grid-Shape:", gr_xyz.shape)
7
# get radar domain (outer ring)
gr_domain = gr_xyz[:,-1,0:2]
gr_domain = np.vstack((gr_domain, gr_domain[0]))
print("Domain-Shape:", gr_domain.shape)
(82, 49, 2)
(82, 49)
(82, 49) (82, 49, 2)
(82, 49) (4018, 2)
8
[21]: print("NRAY", nray_sr)
print("NBIN", ngate_sr)
NRAY 49
NBIN 176
(82, 49, 176, 2) (176,) (82, 49, 176)
(82, 49, 2)
SR_XYP: (82, 49, 176, 2) (82, 49, 176, 3) (176,) (82, 49, 176)
9
[22]: r_sr, az_sr, elev_sr = wrl.georef.xyz_to_spherical(xyzp_sr, alt0_gr, proj=rad)
#TODO: hardcoded 1.0
mask = (elev_sr > (1.0 - bw_gr/2.)) & (elev_sr < (1.0 + bw_gr/2.))
pl.figure()
pl.pcolormesh(mask[40,:,:].T)
10
[25]: # GR pulse volumes
# along one beam
vol_gr = wrl.qual.pulse_volume(r_gr, dr_gr, bw_gr)
# with shape (nray_gr, ngate_gr)
vol_gr = np.repeat(vol_gr, nray_gr).reshape((nray_gr, ngate_gr), order="F")
Ds = dr_sr / np.cos(np.radians(alpha))
Ds = np.broadcast_to(Ds[..., np.newaxis], Rs.shape)
[27]: print(z_sr.shape)
print(sr_data['zbb'].shape, sr_data['bbwidth'].shape, sr_data['quality'].shape)
ratio, ibb = wrl.qual.get_bb_ratio(sr_data['zbb'], sr_data['bbwidth'],␣
,→sr_data['quality'], z_sr)
print(ratio.shape)
zbb = sr_data['zbb'].copy()
zbb[~ibb] = np.nan
print(np.nanmin(ratio[..., 9]), np.nanmax(ratio[..., 9]))
#pl.imshow(ratio, vmin=-10, vmax=30)
ia = (ratio >= 1)
ref_sr_ss[ia] = ref_sr[ia] + wrl.util.calculate_polynomial(ref_sr[ia], a_s[:
,→,10])
ib = (ratio <= 0)
ref_sr_ss[ib] = ref_sr[ib] + wrl.util.calculate_polynomial(ref_sr[ib], a_s[:,0])
ref_sr_sh[ib] = ref_sr[ib] + wrl.util.calculate_polynomial(ref_sr[ib], a_h[:,0])
im = (ratio > 0) & (ratio < 1)
ind = np.round(ratio[im] * 10).astype(np.int)
ref_sr_ss[im] = ref_sr[im] + wrl.util.calculate_polynomial(ref_sr[im], a_s[:
,→,ind])
11
# Jackson Tan's fix for C-band
is_cband = False
if (is_cband):
deltas = (ref_sr_ss - ref_sr) * 5.3 / 10.0
ref_sr_ss = outref_sr + deltas
deltah = (ref_sr_sh - ref_sr) * 5.3 / 10.0
ref_sr_sh = ref_sr + deltah
# Snow
ia = ( gr_xyz[...,2] >= np.nanmean(zbb) )
#ref_gr_ku[ia] = wrl.trafo.KuBandToS.snow[0] + wrl.trafo.KuBandToS.
,→snow[1]*ref_gr[ia] + wrl.trafo.KuBandToS.snow[2]*ref_gr[ia]**2
# Rain
ib = ( gr_xyz[...,2] < np.nanmean(zbb) )
#ref_gr_ku[ib] = wrl.trafo.KuBandToS.rain[0] + wrl.trafo.KuBandToS.
,→rain[1]*ref_gr[ia] + wrl.trafo.KuBandToS.rain[2]*ref_gr[ia]**2
12
# SR bins intersect with GR sweep
valid = valid & (elev_sr >= (elev_gr-bw_gr/2.)) & (elev_sr <= (elev_gr+bw_gr/2.
,→))
# approximate Rs
rs_v1 = Rs.copy()
rs_v1[~valid] = np.nan
rs_m1 = np.nanmax(rs_v1, axis=2)
rs_prof = rs_m1[vscan, vray]
ds = rs_prof
# approximate Ds
ds_v1 = Ds.copy()
ds_v1[~valid] = np.nan
ds_m1 = np.nansum(ds_v1, axis=2)
ds_prof = ds_m1[vscan, vray]
dz = ds_prof
# approximate Vs
vs_v1 = vol_sr.copy()
vs_v1[~valid] = np.nan
vs_m1 = np.nansum(vs_v1, axis=2)
vs_prof = vs_m1[vscan, vray]
13
volsr1 = vs_prof
ref_sr_2 = wrl.trafo.idecibel(ref_sr_ss)
ref_sr_2[~valid] = np.nan
refsr2a = np.nanmean(ref_sr_2, axis=2)[vscan,vray]
refsr2a = wrl.trafo.decibel(refsr2a)
ref_sr_3 = wrl.trafo.idecibel(ref_sr_sh)
ref_sr_3[~valid] = np.nan
14
refsr3a = np.nanmean(ref_sr_3, axis=2)[vscan,vray]
refsr3a = wrl.trafo.decibel(refsr3a)
print(refsr1a.shape)
(1218,)
1218
[36]: #%%time
print("creating")
zdp = wrl.zonalstats.ZonalDataPoly(gr_poly[..., 0:2].reshape(-1, 5, 2),␣
,→trg_poly, srs=rad)
zdp.dump_vector('m3d_zonal_poly_{0}'.format(platf))
creating
[37]: #%%time
print("loading")
obj3 = wrl.zonalstats.ZonalStatsPoly('m3d_zonal_poly_{0}'.format(platf))
loading
[38]: #%%time
print(obj3.ix.shape)
volgr1 = np.array([np.sum(vol_gr.ravel()[obj3.ix[i]])
for i in np.arange(len(obj3.ix))[~obj3.check_empty()]])
print(volgr1.shape)
ref_gr_i = wrl.trafo.idecibel(ref_gr.ravel())
ref_gr_ku_i = wrl.trafo.idecibel(ref_gr_ku.ravel())
refgr1a = np.array([np.nanmean(ref_gr_i[obj3.ix[i]])
for i in np.arange(len(obj3.ix))[~obj3.check_empty()]])
refgr1a = wrl.trafo.decibel(refgr1a)
refgr2a = np.array([np.nanmean(ref_gr_ku_i[obj3.ix[i]])
for i in np.arange(len(obj3.ix))[~obj3.check_empty()]])
refgr2a = wrl.trafo.decibel(refgr2a)
15
(1218,)
(1218,)
pl.xlabel("Reflectivity (dBZ)")
pl.legend()
fig.suptitle("uncorrected GR vs uncorrected SR")
16
pl.xlabel("GR reflectivity (dBZ)")
pl.ylabel("SR reflectivity (dBZ)")
ax = fig.add_subplot(122)
pl.hist(refgr1a[refsr1a>10], bins=np.arange(-10,50,5), edgecolor="None",␣
,→label="GR")
pl.xlabel("Reflectivity (dBZ)")
pl.legend()
fig.suptitle("corrected GR vs uncorrected SR")
pl.xlabel("Reflectivity (dBZ)")
pl.legend()
17
fig.suptitle("corrected GR vs corrected SR snow")
pl.title("SR reflectivity")
pl.xlim(-100000, 150000)
pl.ylim(-150000, 150000)
pl.grid()
ax = fig.add_subplot(122, aspect="equal")
pl.scatter(xyz[..., 0], xyz[...,1], c=refgr1a, cmap=pl.cm.viridis, vmin=10,␣
,→vmax=50, edgecolor="None")
pl.title("GR reflectivity")
pl.xlim(-100000, 150000)
pl.ylim(-150000, 150000)
pl.grid()
fig.suptitle("uncorrected GR vs uncorrected SR")
pl.tight_layout()
18
[43]: # Lots of containers to store samples (only for one GR sweep angle!)
x = np.zeros(nprof)*np.nan # x coordinate of sample
y = np.zeros(nprof)*np.nan # y coordinate of sample
z = np.zeros(nprof)*np.nan # z coordinate of sample
dz = np.zeros(nprof)*np.nan # depth of sample
ds = np.zeros(nprof)*np.nan # width of sample
rs = np.zeros(nprof)*np.nan # range of sample from GR
refsr1 = np.zeros(nprof)*np.nan # SR reflectivity
refsr2 = np.zeros(nprof)*np.nan # SR reflectivity (S-band, snow)
refsr3 = np.zeros(nprof)*np.nan # SR reflectivity (S-band, hail)
refgr1 = np.zeros(nprof)*np.nan # GR reflectivity
refgr2 = np.zeros(nprof)*np.nan # GR reflectivity (Ku-band)
ntotpr = np.zeros(nprof,dtype="i4")# total number of SR bins in sample
nrej1 = np.zeros(nprof,dtype="i4")# number of rejected SR bins in sample
ntotgr = np.zeros(nprof,dtype="i4")# total number of GR bins in sample
nrej2 = np.zeros(nprof,dtype="i4")# number of rejected GR bins in sample
iref1 = np.zeros(nprof)*np.nan # path-integrated SR reflectivity
iref2 = np.zeros(nprof)*np.nan # path-integrated GR reflectivity
stdv1 = np.zeros(nprof)*np.nan # std. dev. of SR reflectivity in sample
stdv2 = np.zeros(nprof)*np.nan # std. dev. of GR reflectivity in sample
volsr = np.zeros(nprof)*np.nan # total volume of SR bins in sample
volgr = np.zeros(nprof)*np.nan # total volume of GR bins in sample
[44]: #%%time
# Loop over relevant SR profiles
19
for ii, (ss, rr) in enumerate(zip(vscan,vray)):
# Index and count valid bins in each profile
ip = np.where(valid[ss,rr])[0]
numbins = len(ip)
ntotpr[ii]=numbins
if numbins == 0:
continue
# Compute the mean position of these bins
x[ii]=np.mean(xyzp_sr[ss,rr,ip,0])
y[ii]=np.mean(xyzp_sr[ss,rr,ip,1])
z[ii]=np.mean(xyzp_sr[ss,rr,ip,2])
# SR averaging volume
volsr[ii]=np.sum(vol_sr[ss, rr, ip])
refsr1[ii]=np.nanmean(ref_sr[ss,rr,ip])
refsr2[ii]=np.nanmean(ref_sr_ss[ss,rr,ip])
refsr3[ii]=np.nanmean(ref_sr_sh[ss,rr,ip])
20
# SHOULD WE USE ZONALDATA INSTEAD? COULD BE MORE ACCURATE, BUT ALSO SLOWER
# WE COULD BASICALLY START A NEW LOOP HERE AND RUN ZONALDATA BEFORE
if len(aa) == 0:
continue
pl.xlabel("Reflectivity (dBZ)")
pl.legend()
fig.suptitle("uncorrected GR vs uncorrected SR")
21
[45]: fig = pl.figure(figsize=(12,5))
ax = fig.add_subplot(121, aspect="equal")
pl.scatter(refgr2, refsr1, marker="+", c="black")
pl.plot([0,60],[0,60], linestyle="solid", color="black")
pl.xlim(10,50)
pl.ylim(10,50)
pl.xlabel("GR reflectivity (dBZ)")
pl.ylabel("SR reflectivity (dBZ)")
ax = fig.add_subplot(122)
pl.hist(refgr1[refsr1>10], bins=np.arange(-10,50,5), edgecolor="None",␣
,→label="GR")
pl.xlabel("Reflectivity (dBZ)")
pl.legend()
fig.suptitle("corrected GR vs uncorrected SR")
22
[46]: fig = pl.figure(figsize=(12,5))
ax = fig.add_subplot(121, aspect="equal")
pl.scatter(refgr2, refsr2, marker="+", c="black")
pl.plot([0,60],[0,60], linestyle="solid", color="black")
pl.xlim(10,50)
pl.ylim(10,50)
pl.xlabel("GR reflectivity (dBZ)")
pl.ylabel("SR reflectivity (dBZ)")
ax = fig.add_subplot(122)
pl.hist(refgr2[refsr2>10], bins=np.arange(-10,50,5), edgecolor="None",␣
,→label="GR")
pl.xlabel("Reflectivity (dBZ)")
pl.legend()
fig.suptitle("corrected GR vs corrected SR snow")
23
[47]: fig = pl.figure(figsize=(12,5))
ax = fig.add_subplot(121, aspect="equal")
pl.scatter(refgr2, refsr3, marker="+", c="black")
pl.plot([0,60],[0,60], linestyle="solid", color="black")
pl.xlim(10,50)
pl.ylim(10,50)
pl.xlabel("GR reflectivity (dBZ)")
pl.ylabel("SR reflectivity (dBZ)")
ax = fig.add_subplot(122)
pl.hist(refgr2[refsr3>10], bins=np.arange(-10,50,5), edgecolor="None",␣
,→label="GR")
pl.xlabel("Reflectivity (dBZ)")
pl.legend()
fig.suptitle("corrected GR vs corrected SR hail")
24
[48]: fig = pl.figure(figsize=(12,8))
ax = fig.add_subplot(121, aspect="equal")
pl.scatter(x, y, c=refsr1, cmap=pl.cm.viridis, vmin=10, vmax=50,␣
,→edgecolor="None")
pl.title("SR reflectivity")
pl.xlim(-100000, 150000)
pl.ylim(-150000, 150000)
pl.grid()
ax = fig.add_subplot(122, aspect="equal")
pl.scatter(x, y, c=refgr1, cmap=pl.cm.viridis, vmin=10, vmax=50,␣
,→edgecolor="None")
pl.title("GR reflectivity")
pl.xlim(-100000, 150000)
pl.ylim(-150000, 150000)
pl.grid()
fig.suptitle("uncorrected GR vs uncorrected SR")
pl.tight_layout()
25
[ ]:
26