def single_qvp(site, fpath, sw_ang=10.): # open radar file radar = read_nexrad_archive(fpath) radlat = radar.latitude['data'][0] radlon = radar.longitude['data'][0] nyvel = radar.get_nyquist_vel(1) # get sweeps fixed_angles = radar.fixed_angle['data'] nang = len(fixed_angles) sw05 = np.arange(nang)[np.abs(fixed_angles - sw_ang) < 1.] sw_inds = sw05[::2] # loop over sweeps for sw in sw_inds: azi = 90. - radar.get_azimuth(sw) elev = radar.get_elevation(sw) ran = radar.range['data'] sweep = radar.extract_sweeps([sw]) fixed_angle = fixed_angles[sw] # calculate sweep time vol_time = sweep.time['units'] sw_toffs = sweep.time['data'][0] sw_time = datetime.fromtimestamp( time.mktime( time.strptime(vol_time, 'seconds since %Y-%m-%dT%H:%M:%SZ'))) sw_time = sw_time + timedelta(seconds=sw_toffs) sw_ts_utc = calendar.timegm(sw_time.utctimetuple()) # get time strings yyyy = '{:04d}'.format(sw_time.year) mm = '{:02d}'.format(sw_time.month) dd = '{:02d}'.format(sw_time.day) hh = '{:02d}'.format(sw_time.hour) mn = '{:02d}'.format(sw_time.minute) ss = '{:02d}'.format(sw_time.second) print(yyyy, mm, dd, hh, mn, ss) ref = sweep.fields['reflectivity']['data'] zdr = sweep.fields['differential_reflectivity']['data'] rhohv = sweep.fields['cross_correlation_ratio']['data'] phidp = sweep.fields['differential_phase']['data'] dims = ref.shape numradials = dims[0] + 1 numgates = dims[1] angle = np.mean(elev) # mask data by rhohv and threshold #----------------------------------------------- ref = np.ma.masked_where(rhohv < 0.4, ref) zdr = np.ma.masked_where(rhohv < 0.4, zdr) phidp = np.ma.masked_where(rhohv < 0.4, phidp) rhohv = np.ma.masked_where(rhohv < 0.4, rhohv) zdr = np.ma.masked_where(ref < -15., zdr) phidp = np.ma.masked_where(ref < -15., phidp) rhohv = np.ma.masked_where(ref < -15., rhohv) ref = np.ma.masked_where(ref < -15., ref) # calculate kdp #----------------------------------------------- print('Calculating KDP...') phidp = dealiasPhiDP(phidp) kdp_alt, delta, phidp_alt = calc_kdp(phidp, 0.25) kdp_alt = np.ma.masked_where(ref < -5., kdp_alt) # calculate beam height #----------------------------------------------------------- radz = 10. erad = np.pi * angle / 180. ke = 4. / 3. a = 6378137. zcor = np.sqrt(ran**2. + (ke * a)**2. + 2. * ran * ke * a * np.sin(erad)) - ke * a + radz # generate qvp #--------------------- ref_qvp = np.ma.mean(ref, axis=0) zdr_qvp = np.ma.mean(zdr, axis=0) kdp_qvp = np.ma.mean(kdp_alt, axis=0) rhv_qvp = np.ma.mean(rhohv, axis=0) print(rhv_qvp.shape, zcor.shape) # write to text file fqvp = open(f'{yyyy}{mm}{dd}_{hh}{mn}_{site}.txt', 'w') fqvp.write(f'time:{sw_ts_utc:d}\n') fqvp.write(f'z\tzh\tzdr\tkdp\trhv\n') # limit to 15 km ARL nz = np.argmin(np.abs(zcor - 15000.)) ref_qvp[ref_qvp.mask] = -999. zdr_qvp[zdr_qvp.mask] = -999. kdp_qvp[kdp_qvp.mask] = -999. rhv_qvp[rhv_qvp.mask] = -999. for i in range(nz): fqvp.write( f'{zcor[i]:.1f}\t{ref_qvp[i]:.1f}\t{zdr_qvp[i]:.2f}\t{kdp_qvp[i]:.2f}\t{rhv_qvp[i]:.3f}\n' ) fqvp.close()
def plot_low_sweeps(site, fpath, ds_set=150., xcen_set=150., ycen_set=70., sw_ang=0.5): # open radar file radar = read_nexrad_archive(fpath) radlat = radar.latitude['data'][0] radlon = radar.longitude['data'][0] nyvel = radar.get_nyquist_vel(1) # plot stuff mpl.rc('font', **{'family': 'sans-serif', 'sans-serif': ['Helvetica']}) mpl.rc('text', usetex=True) figcnt = 0 # get lat lon corners of data domain ds = ds_set xcen = xcen_set ycen = ycen_set minlat, minlon = xy2latlon(xcen - ds, ycen - ds, radlat, radlon) maxlat, maxlon = xy2latlon(xcen + ds, ycen + ds, radlat, radlon) xlabel = 'X-distance (km)' ylabel = 'Y-distance (km)' # color map stuff zh_map = createCmap('zh2_map') zdr_map = createCmap('zdr_map') vel_map = createCmap('vel2_map') phv_map = createCmap('phv_map') kdp_map = createCmap('kdp_map') numcolors = 33 numlevs = numcolors - 1 cinds = np.linspace(0., 254., numcolors).astype(int) zh_cols = zh_map.colors[cinds] zdr_cols = zdr_map.colors[cinds] vel_cols = vel_map.colors[cinds] phv_cols = phv_map.colors[cinds] kdp_cols = kdp_map.colors[cinds] zh_levs = np.linspace(-10., 70., numlevs) sw_levs = np.linspace(0., 8., numlevs) zdr_levs = np.linspace(-2.4, 6.9, numlevs) phidp_levs = np.linspace(50., 100., numlevs) phv_levs = np.linspace(0.71, 1.06, numlevs) kdp_levs = np.linspace(-0.8, 2.3, numlevs) vel_levs = np.linspace(-35., 35., numlevs) zh_mapn, zh_norm = cm.from_levels_and_colors(zh_levs, zh_cols, extend='both') zdr_mapn, zdr_norm = cm.from_levels_and_colors(zdr_levs, zdr_cols, extend='both') phidp_mapn, phidp_norm = cm.from_levels_and_colors(phidp_levs, zh_cols, extend='both') phv_mapn, phv_norm = cm.from_levels_and_colors(phv_levs, phv_cols, extend='both') kdp_mapn, kdp_norm = cm.from_levels_and_colors(kdp_levs, kdp_cols, extend='both') vel_mapn, vel_norm = cm.from_levels_and_colors(vel_levs, vel_cols, extend='both') sw_mapn, sw_norm = cm.from_levels_and_colors(sw_levs, zh_cols, extend='both') # set common font sizes cblb_fsize = 18 cbti_fsize = 16 axtl_fsize = 20 axlb_fsize = 20 axti_fsize = 18 # cartopy features coast = cfeature.GSHHSFeature(scale='high', levels=[1], edgecolor='gray') states = cfeature.STATES.with_scale('50m') shapename = 'admin_1_states_provinces_lakes_shp' states_shp = shpreader.natural_earth(resolution='50m', category='cultural', name=shapename) # create basemap #m = Basemap(llcrnrlon=minlon, llcrnrlat=minlat, urcrnrlon=maxlon, urcrnrlat=maxlat, # projection='merc', lat_1=15., lat_2=35., lon_0=-80., # resolution='h', area_thresh=1000.) # get sweeps fixed_angles = radar.fixed_angle['data'] nang = len(fixed_angles) sw05 = np.arange(nang)[np.abs(fixed_angles - sw_ang) < 0.2] print(fixed_angles) # seperate out z and mdv sweeps sw_inds = sw05[::2] swv_inds = sw05[1::2] # loop over sweeps for sw in sw_inds: azi_p = 90. - radar.get_azimuth(sw) elev_p = radar.get_elevation(sw) ran = radar.range['data'] sweep = radar.extract_sweeps([sw]) fixed_angle = fixed_angles[sw] if fixed_angle < 2.: sweep_v = radar.extract_sweeps([sw + 1]) else: sweep_v = sweep # calculate sweep time vol_time = sweep.time['units'] sw_toffs = sweep.time['data'][0] sw_time = datetime.fromtimestamp( time.mktime( time.strptime(vol_time, 'seconds since %Y-%m-%dT%H:%M:%SZ'))) sw_time = sw_time + timedelta(seconds=sw_toffs) # get time strings yyyy = '{:04d}'.format(sw_time.year) mm = '{:02d}'.format(sw_time.month) dd = '{:02d}'.format(sw_time.day) hh = '{:02d}'.format(sw_time.hour) mn = '{:02d}'.format(sw_time.minute) ss = '{:02d}'.format(sw_time.second) print(yyyy, mm, dd, hh, mn, ss) ref_p = sweep.fields['reflectivity']['data'] zdr_p = sweep.fields['differential_reflectivity']['data'] rhohv_p = sweep.fields['cross_correlation_ratio']['data'] vel_p = sweep_v.fields['velocity']['data'] phidp_p = sweep.fields['differential_phase']['data'] sw_p = sweep_v.fields['spectrum_width']['data'] azi_v_p = 90. - radar.get_azimuth(sw + 1) elev_v_p = radar.get_elevation(sw + 1) dims = ref_p.shape numradials = dims[0] + 1 numgates = dims[1] # expand radially to remove no data spike elev = np.empty([numradials]) elev_v = np.empty([numradials]) azi = np.empty([numradials]) azi_v = np.empty([numradials]) ref = np.empty([numradials, numgates]) zdr = np.empty([numradials, numgates]) phidp = np.empty([numradials, numgates]) rhohv = np.empty([numradials, numgates]) vel = np.empty([numradials, numgates]) sw = np.empty([numradials, numgates]) elev[0:numradials - 1] = elev_p elev[numradials - 1] = elev_p[0] elev_v[0:numradials - 1] = elev_v_p elev_v[numradials - 1] = elev_v_p[0] azi[0:numradials - 1] = azi_p azi[numradials - 1] = azi_p[0] azi_v[0:numradials - 1] = azi_v_p azi_v[numradials - 1] = azi_v_p[0] ref[0:numradials - 1, :] = ref_p ref[numradials - 1, :] = ref_p[0] zdr[0:numradials - 1, :] = zdr_p zdr[numradials - 1, :] = zdr_p[0] phidp[0:numradials - 1, :] = phidp_p phidp[numradials - 1, :] = phidp_p[0] rhohv[0:numradials - 1, :] = rhohv_p rhohv[numradials - 1, :] = rhohv_p[0] vel[0:numradials - 1, :] = vel_p vel[numradials - 1, :] = vel_p[0] sw[0:numradials - 1, :] = sw_p sw[numradials - 1, :] = sw_p[0] # get stats on velocity vcount = Counter(vel.flatten()) angle = np.mean(elev) angle_v = np.mean(elev_v) # mask data by rhohv and threshold #----------------------------------------------- ref = np.ma.masked_where(rhohv < 0.4, ref) zdr = np.ma.masked_where(rhohv < 0.4, zdr) phidp = np.ma.masked_where(rhohv < 0.4, phidp) vel = np.ma.masked_where(rhohv < 0.4, vel) sw = np.ma.masked_where(rhohv < 0.4, sw) rhohv = np.ma.masked_where(rhohv < 0.4, rhohv) zdr = np.ma.masked_where(ref < -15., zdr) phidp = np.ma.masked_where(ref < -15., phidp) rhohv = np.ma.masked_where(ref < -15., rhohv) vel = np.ma.masked_where(ref < -15., vel) sw = np.ma.masked_where(ref < -15., sw) ref = np.ma.masked_where(ref < -15., ref) # calculate kdp #----------------------------------------------- print('Calculating KDP...') phidp = dealiasPhiDP(phidp) kdp_alt, delta, phidp_alt = calc_kdp(phidp) kdp_alt = np.ma.masked_where(ref < -5., kdp_alt) # calculate x and y coordinates (wrt beampath) for plotting #----------------------------------------------------------- ran_2d = np.tile(ran, (numradials, 1)) azi.shape = (azi.shape[0], 1) azi_v.shape = (azi_v.shape[0], 1) azi_2d = np.tile(azi, (1, numgates)) azi_v_2d = np.tile(azi_v, (1, numgates)) radz = 10. erad = np.pi * angle / 180. erad_v = np.pi * angle_v / 180. ke = 4. / 3. a = 6378137. # beam height and beam distance zcor = np.sqrt(ran_2d**2. + (ke * a)**2. + 2. * ran_2d * ke * a * np.sin(erad)) - ke * a + radz scor = ke * a * np.arcsin(ran_2d * np.cos(erad) / (ke * a + zcor)) / 1000. xcor = scor * np.cos(np.pi * azi_2d / 180.) ycor = scor * np.sin(np.pi * azi_2d / 180.) # for velocity zcor_v = np.sqrt(ran_2d**2. + (ke * a)**2. + 2. * ran_2d * ke * a * np.sin(erad_v)) - ke * a + radz scor_v = ke * a * np.arcsin(ran_2d * np.cos(erad_v) / (ke * a + zcor)) / 1000. xcor_v = scor_v * np.cos(np.pi * azi_v_2d / 180.) ycor_v = scor_v * np.sin(np.pi * azi_v_2d / 180.) # convert to lon,lat for basemap plotting lat, lon = xy2latlon(xcor, ycor, radlat, radlon) lat_v, lon_v = xy2latlon(xcor_v, ycor_v, radlat, radlon) # plot #--------------------- print('Plotting...') plt.figure(figcnt) figcnt = figcnt + 1 #x, y = m(lon, lat) #x_v, y_v = m(lon_v, lat_v) #rx, ry = m(radlon, radlat) # ZH plot #------------------------------ ax1 = plt.subplot(2, 2, 1, projection=ccrs.PlateCarree()) plt.pcolormesh(lon, lat, ref, cmap=zh_map, vmin=-10., vmax=80., transform=ccrs.PlateCarree()) cb1 = plt.colorbar(fraction=0.04) cb1.set_label('(dBZ)', fontsize=cblb_fsize) cb1_la = [f'{ti:.0f}' for ti in cb1.get_ticks()] cb1.ax.set_yticklabels(cb1_la, fontsize=cbti_fsize) ax1.set_title('Z$\sf{_H}$', x=0.0, y=1.02, horizontalalignment='left', fontsize=axtl_fsize) #ax1.add_feature(coast) #ax1.add_feature(states, edgecolor='k') ax1.add_geometries(shpreader.Reader(states_shp).geometries(), ccrs.PlateCarree(), edgecolor='k', facecolor='none', linewidth=0.5) ax1.add_feature(USCOUNTIES.with_scale('20m'), edgecolor='k', linewidth=0.2) ax1.set_extent([minlon, maxlon, minlat, maxlat]) # ZDR plot #------------------------------ ax2 = plt.subplot(2, 2, 2, projection=ccrs.PlateCarree()) plt.pcolormesh(lon, lat, zdr, cmap=zdr_map, vmin=-2.4, vmax=6.9, transform=ccrs.PlateCarree()) cb2 = plt.colorbar(fraction=0.04) cb2.set_label('(dB)', fontsize=cblb_fsize) cb2_la = [f'{ti:.1f}' for ti in cb2.get_ticks()] cb2.ax.set_yticklabels(cb2_la, fontsize=cbti_fsize) ax2.set_title('Z$_{\sf{DR}}$', x=0.0, y=1.02, horizontalalignment='left', fontsize=axtl_fsize) ax2.add_geometries(shpreader.Reader(states_shp).geometries(), ccrs.PlateCarree(), edgecolor='k', facecolor='none', linewidth=0.5) ax2.add_feature(USCOUNTIES.with_scale('20m'), edgecolor='k', linewidth=0.2) ax2.set_extent([minlon, maxlon, minlat, maxlat]) # KDP plot #------------------------------ ax3 = plt.subplot(2, 2, 3, projection=ccrs.PlateCarree()) plt.pcolormesh(lon, lat, kdp_alt, cmap=kdp_map, vmin=-1.6, vmax=4.3, transform=ccrs.PlateCarree()) cb3 = plt.colorbar(fraction=0.04) cb3.set_label('(deg./km)', fontsize=cblb_fsize) cb3_la = [f'{ti:.1f}' for ti in cb3.get_ticks()] cb3.ax.set_yticklabels(cb3_la, fontsize=cbti_fsize) ax3.set_title('$\sf{K_{DP}}$', x=0.0, y=1.02, horizontalalignment='left', fontsize=axtl_fsize) ax3.add_geometries(shpreader.Reader(states_shp).geometries(), ccrs.PlateCarree(), edgecolor='k', facecolor='none', linewidth=0.5) ax3.add_feature(USCOUNTIES.with_scale('20m'), edgecolor='k', linewidth=0.2) ax3.set_extent([minlon, maxlon, minlat, maxlat]) # RhoHV plot #------------------------------ ax4 = plt.subplot(2, 2, 4, projection=ccrs.PlateCarree()) plt.pcolormesh(lon, lat, rhohv, cmap=phv_map, vmin=0.695, vmax=1.045, transform=ccrs.PlateCarree()) cb4 = plt.colorbar(fraction=0.04) cb4.set_label('', fontsize=20) cb4_la = [f'{ti:.2f}' for ti in cb4.get_ticks()] cb4.ax.set_yticklabels(cb4_la, fontsize=cbti_fsize) ax4.set_title('$\\rho\sf{_{HV}}$', x=0.0, y=1.02, horizontalalignment='left', fontsize=axtl_fsize) ax4.add_geometries(shpreader.Reader(states_shp).geometries(), ccrs.PlateCarree(), edgecolor='k', facecolor='none', linewidth=0.5) ax4.add_feature(USCOUNTIES.with_scale('20m'), edgecolor='k', linewidth=0.2) ax4.set_extent([minlon, maxlon, minlat, maxlat]) # save image as .png #------------------------------- title = '{} - {}/{}/{} - {}:{} UTC - {:.1f} deg. PPI'.format( site, yyyy, mm, dd, hh, mn, float(angle)) plt.suptitle(title, fontsize=24) plt.subplots_adjust(top=0.95, hspace=-0.1, wspace=0.2) imgname = yyyy + mm + dd + '_' + hh + mn + '_' + site.lower() + '.png' plt.savefig(imgname, format='png', dpi=120) plt.close() # crop out white space from figure os.system('convert -trim ' + imgname + ' ' + imgname)
# open file #----------------------------------- print 'Opening file...' yyyy = '2016' mm = '10' dd = '07' hh = '12' mn = '29' ss = '01' site = 'KMLB' filename = '{}{}{}{}_{}{}{}_V06'.format(site, yyyy, mm, dd, hh, mn, ss) rad = read_nexrad_archive(filename) rad_sw = rad.extract_sweeps([0]) # get variables #----------------------------------- elev_p = rad_sw.elevation['data'] azi_p = 90. - rad_sw.azimuth['data'] ran = rad_sw.range['data'] ref_p = rad_sw.fields['reflectivity']['data'] zdr_p = rad_sw.fields['differential_reflectivity']['data'] phidp_p = rad_sw.fields['differential_phase']['data'] rhohv_p = rad_sw.fields['cross_correlation_ratio']['data'] radlat = rad_sw.latitude['data'][0] radlon = rad_sw.longitude['data'][0] dims = ref_p.shape
def kdp_compare(site, fpath, ds_set=150., xcen_set=150., ycen_set=70., sw_ang=0.5, range_rings=False, mode='severe'): t1 = time.time() # open radar file radar = read_nexrad_archive(fpath) radlat = radar.latitude['data'][0] radlon = radar.longitude['data'][0] nyvel = radar.get_nyquist_vel(1) t2 = time.time() print(f'opening time, {t2-t1:.4f}') # plot stuff mpl.rc('font', **{'family': 'sans-serif', 'sans-serif': ['Helvetica']}) mpl.rc('text', usetex=True) facecolor = 'white' edgecolor = 'black' mpl.rcParams['axes.facecolor'] = facecolor mpl.rcParams['savefig.facecolor'] = facecolor mpl.rcParams['axes.edgecolor'] = edgecolor mpl.rcParams['figure.edgecolor'] = edgecolor mpl.rcParams['savefig.edgecolor'] = edgecolor mpl.rcParams['text.color'] = edgecolor mpl.rcParams['axes.labelcolor'] = edgecolor mpl.rcParams['xtick.color'] = edgecolor mpl.rcParams['ytick.color'] = edgecolor figcnt = 0 # get lat lon corners of data domain ds = ds_set xcen = xcen_set ycen = ycen_set #minlat, minlon = xy2latlon(xcen-ds, ycen-ds, radlat, radlon) #maxlat, maxlon = xy2latlon(xcen+ds, ycen+ds, radlat, radlon) minx = xcen - ds maxx = xcen + ds miny = ycen - ds maxy = ycen + ds xlabel = 'X-distance (km)' ylabel = 'Y-distance (km)' # colormaps kdp_map = createCmap('kdp_map') # set ranges of colormaps based on mode if mode == 'winter': zh_min = -10. zh_max = 60. kdp_min = -1.6 kdp_max = 4.3 if mode == 'severe': zh_min = 10. zh_max = 80. kdp_min = -3.2 kdp_max = 8.6 # set common font sizes cblb_fsize = 18 cbti_fsize = 16 axtl_fsize = 20 axlb_fsize = 20 axti_fsize = 18 # height contours clevs = [3., 6., 9., 12.] fmt_dict = {} for cl in clevs: fmt_dict[cl] = f'{cl:.0f} km' # cartopy features t2 = time.time() cfile = Dataset(f'site_geom/{site}_counties.nc', 'r') cnt_verts = cfile.variables['vertex'][:] cnt_codes = cfile.variables['vertex_code'][:] sfile = Dataset(f'site_geom/{site}_states.nc', 'r') st_verts = sfile.variables['vertex'][:] st_codes = sfile.variables['vertex_code'][:] cnt_path = Path(cnt_verts, cnt_codes) st_path = Path(st_verts, st_codes) t3 = time.time() print(f'cartopy features time, {t3-t2:.4f}') # get sweeps fixed_angles = radar.fixed_angle['data'] print(fixed_angles) nang = len(fixed_angles) sw05 = np.arange(nang)[np.abs(fixed_angles - sw_ang) < 0.2] # seperate out z and mdv sweeps sw_inds = sw05[::2] swv_inds = sw05[1::2] #sw_inds = [sw_inds[0]] # loop over sweeps for sw in sw_inds: t2 = time.time() rd1 = time.time() azi = 90. - radar.get_azimuth(sw) elev = radar.get_elevation(sw) ran = radar.range['data'] sweep = radar.extract_sweeps([sw]) fixed_angle = fixed_angles[sw] # calculate sweep time vol_time = sweep.time['units'] sw_toffs = sweep.time['data'][0] sw_time = datetime.strptime(vol_time, 'seconds since %Y-%m-%dT%H:%M:%SZ') sw_time = sw_time + timedelta(seconds=sw_toffs) sw_time = datetime(year=sw_time.year, month=sw_time.month, day=sw_time.day, hour=sw_time.hour, minute=sw_time.minute, second=sw_time.second, tzinfo=timezone.utc) # get time strings yyyy = '{:04d}'.format(sw_time.year) mm = '{:02d}'.format(sw_time.month) dd = '{:02d}'.format(sw_time.day) hh = '{:02d}'.format(sw_time.hour) mn = '{:02d}'.format(sw_time.minute) ss = '{:02d}'.format(sw_time.second) print(yyyy, mm, dd, hh, mn, ss) ref = sweep.fields['reflectivity']['data'] rhohv = sweep.fields['cross_correlation_ratio']['data'] phidp = sweep.fields['differential_phase']['data'] dims = ref.shape numradials = dims[0] numgates = dims[1] angle = np.mean(elev) # extend azimuth by one azi_ext = np.empty([numradials + 1]) azi_ext[0:numradials] = azi azi_ext[numradials] = azi[0] azi = azi_ext[:] ref = extend_azi(ref) phidp = extend_azi(phidp) rhohv = extend_azi(rhohv) # mask data by rhohv and threshold #----------------------------------------------- ref = np.ma.masked_where(rhohv < 0.4, ref) phidp = np.ma.masked_where(rhohv < 0.4, phidp) rhohv = np.ma.masked_where(rhohv < 0.4, rhohv) phidp = np.ma.masked_where(ref < zh_min, phidp) rhohv = np.ma.masked_where(ref < zh_min, rhohv) ref = np.ma.masked_where(ref < zh_min, ref) rd2 = time.time() print('read data time', rd2 - rd1) # calculate x and y coordinates (wrt beampath) for plotting #----------------------------------------------------------- ct1 = time.time() ran_2d = np.tile(ran, (numradials + 1, 1)) azi.shape = (azi.shape[0], 1) azi_2d = np.tile(azi, (1, numgates)) radz = 10. erad = np.pi * angle / 180. ke = 4. / 3. a = 6378137. # beam height and beam distance zcor = np.sqrt(ran_2d**2. + (ke * a)**2. + 2. * ran_2d * ke * a * np.sin(erad)) - ke * a + radz scor = ke * a * np.arcsin(ran_2d * np.cos(erad) / (ke * a + zcor)) / 1000. xcor = ran_2d * np.cos(np.pi * azi_2d / 180.) / 1.e3 ycor = ran_2d * np.sin(np.pi * azi_2d / 180.) / 1.e3 # convert to lon,lat for map plotting lat, lon = xy2latlon(xcor, ycor, radlat, radlon) ct2 = time.time() print('make coordinates time', ct2 - ct1) t3 = time.time() print(f'data prep time, {t3-t2:.4f}') # calculate kdp #----------------------------------------------- print('Calculating KDP...') kd1 = time.time() phidp = dealiasPhiDP(phidp) kdp, delta, phidp_alt = calc_kdp(phidp, 0.25) kdp = np.ma.masked_where(ref < -15., kdp) kd2 = time.time() print('kdp calc time', kd2 - kd1) kdp_dict, _, _ = ret.kdp_maesaka(sweep) kdp_maesaka = kdp_dict['data'] kdp_maesaka = np.ma.masked_where(ref[:-1, :] < -15., kdp_maesaka) kdp_dict, _ = ret.kdp_vulpiani(sweep) kdp_vulpiani = kdp_dict['data'] kdp_vulpiani = np.ma.masked_where(ref[:-1, :] < -15., kdp_vulpiani) kdp_brin, _, _ = calc_kdp_bringi(phidp, ref, ran_2d / 1.e3) kdp_brin = np.ma.masked_where(ref < -15., kdp_brin) kdp_brin = np.ma.masked_where(kdp_brin == np.min(kdp_brin), kdp_brin) # plot #--------------------- print('Plotting...') fig = plt.figure(figcnt, figsize=(12, 10)) figcnt = figcnt + 1 # KDP plot #------------------------------ t2 = time.time() ax = plt.subplot(2, 2, 1) plt.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False) plt.tick_params(axis='y', which='both', left=False, right=False, labelleft=False) #plt.pcolormesh(xcor, ycor, kdp, cmap=kdp_map, vmin=-1.6, vmax=4.3) plt.pcolormesh(xcor, ycor, kdp_maesaka, cmap=kdp_map, vmin=kdp_min, vmax=kdp_max) cb = plt.colorbar(format='%.1f', fraction=0.045) if range_rings: cs = plt.contour(xcor, ycor, zcor / 1.e3, levels=clevs, linewidths=2., colors='k', linestyles='--') ax.clabel(cs, inline=1, fmt=fmt_dict, fontsize=axti_fsize) ax.set_title('$\sf{K_{DP}}$ ($^{\circ}$ km$^{-1}$)', x=0.0, y=1.02, horizontalalignment='left', fontsize=axtl_fsize) cnt_patch = patches.PathPatch(cnt_path, edgecolor=edgecolor, fill=False, lw=0.3) st_patch = patches.PathPatch(st_path, edgecolor=edgecolor, fill=False, lw=0.6) ax.add_patch(cnt_patch) ax.add_patch(st_patch) ax.set_aspect(1.) ax.set_facecolor(facecolor) ax.set_xlim([minx, maxx]) ax.set_ylim([miny, maxy]) t3 = time.time() print(f'kdp time, {t3-t2:.4f}') # KDP plot #------------------------------ t2 = time.time() ax = plt.subplot(2, 2, 2) plt.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False) plt.tick_params(axis='y', which='both', left=False, right=False, labelleft=False) #plt.pcolormesh(xcor, ycor, kdp, cmap=kdp_map, vmin=-1.6, vmax=4.3) plt.pcolormesh(xcor, ycor, kdp_vulpiani, cmap=kdp_map, vmin=kdp_min, vmax=kdp_max) cb = plt.colorbar(format='%.1f', fraction=0.045) if range_rings: cs = plt.contour(xcor, ycor, zcor / 1.e3, levels=clevs, linewidths=2., colors='k', linestyles='--') ax.clabel(cs, inline=1, fmt=fmt_dict, fontsize=axti_fsize) ax.set_title('$\sf{K_{DP}}$ ($^{\circ}$ km$^{-1}$)', x=0.0, y=1.02, horizontalalignment='left', fontsize=axtl_fsize) cnt_patch = patches.PathPatch(cnt_path, edgecolor=edgecolor, fill=False, lw=0.3) st_patch = patches.PathPatch(st_path, edgecolor=edgecolor, fill=False, lw=0.6) ax.add_patch(cnt_patch) ax.add_patch(st_patch) ax.set_aspect(1.) ax.set_facecolor(facecolor) ax.set_xlim([minx, maxx]) ax.set_ylim([miny, maxy]) t3 = time.time() print(f'kdp time, {t3-t2:.4f}') # KDP plot #------------------------------ t2 = time.time() ax = plt.subplot(2, 2, 3) plt.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False) plt.tick_params(axis='y', which='both', left=False, right=False, labelleft=False) #plt.pcolormesh(xcor, ycor, kdp, cmap=kdp_map, vmin=-1.6, vmax=4.3) plt.pcolormesh(xcor, ycor, kdp, cmap=kdp_map, vmin=kdp_min, vmax=kdp_max) cb = plt.colorbar(format='%.1f', fraction=0.045) if range_rings: cs = plt.contour(xcor, ycor, zcor / 1.e3, levels=clevs, linewidths=2., colors='k', linestyles='--') ax.clabel(cs, inline=1, fmt=fmt_dict, fontsize=axti_fsize) ax.set_title('$\sf{K_{DP}}$ ($^{\circ}$ km$^{-1}$)', x=0.0, y=1.02, horizontalalignment='left', fontsize=axtl_fsize) cnt_patch = patches.PathPatch(cnt_path, edgecolor=edgecolor, fill=False, lw=0.3) st_patch = patches.PathPatch(st_path, edgecolor=edgecolor, fill=False, lw=0.6) ax.add_patch(cnt_patch) ax.add_patch(st_patch) ax.set_aspect(1.) ax.set_facecolor(facecolor) ax.set_xlim([minx, maxx]) ax.set_ylim([miny, maxy]) t3 = time.time() print(f'kdp time, {t3-t2:.4f}') # KDP plot #------------------------------ t2 = time.time() ax = plt.subplot(2, 2, 4) plt.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False) plt.tick_params(axis='y', which='both', left=False, right=False, labelleft=False) #plt.pcolormesh(xcor, ycor, kdp, cmap=kdp_map, vmin=-1.6, vmax=4.3) plt.pcolormesh(xcor, ycor, kdp_brin, cmap=kdp_map, vmin=kdp_min, vmax=kdp_max) cb = plt.colorbar(format='%.1f', fraction=0.045) if range_rings: cs = plt.contour(xcor, ycor, zcor / 1.e3, levels=clevs, linewidths=2., colors='k', linestyles='--') ax.clabel(cs, inline=1, fmt=fmt_dict, fontsize=axti_fsize) ax.set_title('$\sf{K_{DP}}$ ($^{\circ}$ km$^{-1}$)', x=0.0, y=1.02, horizontalalignment='left', fontsize=axtl_fsize) cnt_patch = patches.PathPatch(cnt_path, edgecolor=edgecolor, fill=False, lw=0.3) st_patch = patches.PathPatch(st_path, edgecolor=edgecolor, fill=False, lw=0.6) ax.add_patch(cnt_patch) ax.add_patch(st_patch) ax.set_aspect(1.) ax.set_facecolor(facecolor) ax.set_xlim([minx, maxx]) ax.set_ylim([miny, maxy]) t3 = time.time() print(f'kdp time, {t3-t2:.4f}') # save image as .png #------------------------------- title = '{} - {}/{}/{} - {}:{} UTC - {:.1f} deg. PPI'.format( site, yyyy, mm, dd, hh, mn, float(angle)) plt.suptitle(title, fontsize=24, y=1.) plt.subplots_adjust(top=0.96, hspace=0., wspace=0.2) imgname = yyyy + mm + dd + '_' + hh + mn + '_' + site.lower() + '.png' t2 = time.time() plt.savefig(imgname, format='png', dpi=150, bbox_inches='tight') plt.close() t3 = time.time() print(f'render time, {t3-t2:.4f}')
def plot_single(site, fpath, ds_set=150., xcen_set=150., ycen_set=70., sw_ang=0.5, range_rings=False, mode='severe', npanel=4): t1 = time.time() # open radar file radar = read_nexrad_archive(fpath) radlat = radar.latitude['data'][0] radlon = radar.longitude['data'][0] nyvel = radar.get_nyquist_vel(1) t2 = time.time() print(f'opening time, {t2-t1:.4f}') # plot stuff mpl.rc('font', **{'family': 'sans-serif', 'sans-serif': ['Helvetica']}) mpl.rc('text', usetex=True) facecolor = 'white' edgecolor = 'black' mpl.rcParams['axes.facecolor'] = facecolor mpl.rcParams['savefig.facecolor'] = facecolor mpl.rcParams['axes.edgecolor'] = edgecolor mpl.rcParams['figure.edgecolor'] = edgecolor mpl.rcParams['savefig.edgecolor'] = edgecolor mpl.rcParams['text.color'] = edgecolor mpl.rcParams['axes.labelcolor'] = edgecolor mpl.rcParams['xtick.color'] = edgecolor mpl.rcParams['ytick.color'] = edgecolor figcnt = 0 # get lat lon corners of data domain ds = ds_set xcen = xcen_set ycen = ycen_set #minlat, minlon = xy2latlon(xcen-ds, ycen-ds, radlat, radlon) #maxlat, maxlon = xy2latlon(xcen+ds, ycen+ds, radlat, radlon) minx = xcen - ds maxx = xcen + ds miny = ycen - ds maxy = ycen + ds xlabel = 'X-distance (km)' ylabel = 'Y-distance (km)' # colormaps zh_map = createCmap('zh2_map') zdr_map = createCmap('zdr_map') vel_map = createCmap('vel2_map') phv_map = createCmap('phv_map') kdp_map = createCmap('kdp_map') # set ranges of colormaps based on mode if mode == 'winter': zh_mask = -10. zh_min = -10. zh_max = 60. zdr_min = -2.4 zdr_max = 6.9 kdp_min = -1.6 kdp_max = 4.3 #rhohv_min = 0.695 #rhohv_max = 1.045 rhohv_min = 0.81 rhohv_max = 1.01 if mode == 'severe': zh_mask = 10. zh_min = -10. zh_max = 80. zdr_min = -2.4 zdr_max = 6.9 kdp_min = -3.2 kdp_max = 8.6 #rhohv_min = 0.695 #rhohv_max = 1.045 rhohv_min = 0.6 rhohv_max = 1.0 # set common font sizes cblb_fsize = 18 cbti_fsize = 16 axtl_fsize = 20 axlb_fsize = 20 axti_fsize = 18 # height contours clevs = [1., 2., 3., 4., 5., 6.] fmt_dict = {} for cl in clevs: fmt_dict[cl] = f'{cl:.0f} km' # cartopy features t2 = time.time() cfile = Dataset(f'site_geom/{site}_counties.nc', 'r') cnt_verts = cfile.variables['vertex'][:] cnt_codes = cfile.variables['vertex_code'][:] sfile = Dataset(f'site_geom/{site}_states.nc', 'r') st_verts = sfile.variables['vertex'][:] st_codes = sfile.variables['vertex_code'][:] cnt_path = Path(cnt_verts, cnt_codes) st_path = Path(st_verts, st_codes) t3 = time.time() print(f'cartopy features time, {t3-t2:.4f}') # get sweeps fixed_angles = radar.fixed_angle['data'] print(fixed_angles) nang = len(fixed_angles) sw05 = np.arange(nang)[np.abs(fixed_angles - sw_ang) < 0.2] # seperate out z and mdv sweeps sw_inds = sw05[::2] swv_inds = sw05[1::2] #sw_inds = [sw_inds[0]] # loop over sweeps for sw in sw_inds: t2 = time.time() rd1 = time.time() azi = 90. - radar.get_azimuth(sw) elev = radar.get_elevation(sw) ran = radar.range['data'] sweep = radar.extract_sweeps([sw]) fixed_angle = fixed_angles[sw] if fixed_angle < 2.: sweep_v = radar.extract_sweeps([sw + 1]) else: sweep_v = sweep # calculate sweep time vol_time = sweep.time['units'] sw_toffs = sweep.time['data'][0] sw_time = datetime.strptime(vol_time, 'seconds since %Y-%m-%dT%H:%M:%SZ') sw_time = sw_time + timedelta(seconds=sw_toffs) sw_time = datetime(year=sw_time.year, month=sw_time.month, day=sw_time.day, hour=sw_time.hour, minute=sw_time.minute, second=sw_time.second, tzinfo=timezone.utc) # get time strings yyyy = '{:04d}'.format(sw_time.year) mm = '{:02d}'.format(sw_time.month) dd = '{:02d}'.format(sw_time.day) hh = '{:02d}'.format(sw_time.hour) mn = '{:02d}'.format(sw_time.minute) ss = '{:02d}'.format(sw_time.second) print(yyyy, mm, dd, hh, mn, ss) ref = sweep.fields['reflectivity']['data'] zdr = sweep.fields['differential_reflectivity']['data'] rhohv = sweep.fields['cross_correlation_ratio']['data'] vel = sweep_v.fields['velocity']['data'] phidp = sweep.fields['differential_phase']['data'] swd = sweep_v.fields['spectrum_width']['data'] if fixed_angle < 2.: azi_v = 90. - radar.get_azimuth(sw + 1) elev_v = radar.get_elevation(sw + 1) else: azi_v = 90. - radar.get_azimuth(sw) elev_v = radar.get_elevation(sw) dims = ref.shape numradials = dims[0] numgates = dims[1] angle = np.mean(elev) angle_v = np.mean(elev_v) # extend azimuth by one azi_ext = np.empty([numradials + 1]) azi_ext[0:numradials] = azi azi_ext[numradials] = azi[0] azi = azi_ext[:] azi_ext = np.empty([numradials + 1]) azi_ext[0:numradials] = azi_v azi_ext[numradials] = azi_v[0] azi_v = azi_ext[:] ref = extend_azi(ref) zdr = extend_azi(zdr) phidp = extend_azi(phidp) rhohv = extend_azi(rhohv) swd = extend_azi(swd) vel = extend_azi(vel) # get the correct masking variables for mdv and sw az_diff_ind = np.argmin(np.abs(azi[0] - azi_v)) rhohv_v = np.ma.masked_all(rhohv.shape) ref_v = np.ma.masked_all(ref.shape) az1 = numradials - az_diff_ind rhohv_v[az_diff_ind:numradials, :] = rhohv[0:az1, :] rhohv_v[0:az_diff_ind, :] = rhohv[az1:numradials, :] ref_v[az_diff_ind:numradials, :] = ref[0:az1, :] ref_v[0:az_diff_ind, :] = ref[az1:numradials, :] # mask data by rhohv and threshold #----------------------------------------------- ref = np.ma.masked_where(rhohv < 0.4, ref) zdr = np.ma.masked_where(rhohv < 0.4, zdr) phidp = np.ma.masked_where(rhohv < 0.4, phidp) vel = np.ma.masked_where(rhohv_v < 0.4, vel) swd = np.ma.masked_where(rhohv_v < 0.4, swd) rhohv = np.ma.masked_where(rhohv < 0.4, rhohv) zdr = np.ma.masked_where(ref < zh_mask, zdr) phidp = np.ma.masked_where(ref < 15., phidp) rhohv = np.ma.masked_where(ref < zh_mask, rhohv) vel = np.ma.masked_where(ref_v < zh_mask, vel) swd = np.ma.masked_where(ref_v < zh_mask, swd) ref = np.ma.masked_where(ref < zh_mask, ref) rd2 = time.time() print('read data time', rd2 - rd1) # calculate kdp #----------------------------------------------- print('Calculating KDP...') kd1 = time.time() phidp = dealiasPhiDP(phidp) kdp, delta, phidp_alt = calc_kdp(phidp, 0.25) kdp = np.ma.masked_where((ref < zh_mask) | (rhohv < 0.4), kdp) kd2 = time.time() print('kdp calc time', kd2 - kd1) # calculate x and y coordinates (wrt beampath) for plotting #----------------------------------------------------------- ct1 = time.time() ran_2d = np.tile(ran, (numradials + 1, 1)) azi.shape = (azi.shape[0], 1) azi_v.shape = (azi_v.shape[0], 1) azi_2d = np.tile(azi, (1, numgates)) azi_v_2d = np.tile(azi_v, (1, numgates)) radz = 10. erad = np.pi * angle / 180. erad_v = np.pi * angle_v / 180. ke = 4. / 3. a = 6378137. # beam height and beam distance zcor = np.sqrt(ran_2d**2. + (ke * a)**2. + 2. * ran_2d * ke * a * np.sin(erad)) - ke * a + radz scor = ke * a * np.arcsin(ran_2d * np.cos(erad) / (ke * a + zcor)) / 1000. xcor = ran_2d * np.cos(np.pi * azi_2d / 180.) / 1.e3 ycor = ran_2d * np.sin(np.pi * azi_2d / 180.) / 1.e3 # for velocity zcor_v = np.sqrt(ran_2d**2. + (ke * a)**2. + 2. * ran_2d * ke * a * np.sin(erad_v)) - ke * a + radz scor_v = ke * a * np.arcsin(ran_2d * np.cos(erad_v) / (ke * a + zcor)) / 1000. xcor_v = scor_v * np.cos(np.pi * azi_v_2d / 180.) ycor_v = scor_v * np.sin(np.pi * azi_v_2d / 180.) # convert to lon,lat for map plotting lat, lon = xy2latlon(xcor, ycor, radlat, radlon) lat_v, lon_v = xy2latlon(xcor_v, ycor_v, radlat, radlon) ct2 = time.time() print('make coordinates time', ct2 - ct1) t3 = time.time() print(f'data prep time, {t3-t2:.4f}') # plot #--------------------- print('Plotting...') if npanel == 6: fig = plt.figure(figcnt, figsize=(16, 10)) ncol = 3 else: fig = plt.figure(figcnt, figsize=(12, 10)) ncol = 2 figcnt = figcnt + 1 # ZH plot #------------------------------ t2 = time.time() ax = fig.add_subplot(2, ncol, 1) plt.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False) plt.tick_params(axis='y', which='both', left=False, right=False, labelleft=False) #plt.pcolormesh(xcor, ycor, ref, cmap=zh_map, vmin=-10., vmax=80.) plt.pcolormesh(xcor, ycor, ref, cmap=zh_map, vmin=zh_min, vmax=zh_max) cb = plt.colorbar(format='%.0f', fraction=0.045) if range_rings: cs = plt.contour(xcor, ycor, zcor / 1.e3, levels=clevs, linewidths=2., colors='k', linestyles='--') ax.clabel(cs, inline=1, fmt=fmt_dict, fontsize=axti_fsize) ax.set_title('Z$\sf{_H}$ (dBZ)', x=0.0, y=1.02, horizontalalignment='left', fontsize=axtl_fsize) cnt_patch = patches.PathPatch(cnt_path, edgecolor=edgecolor, fill=False, lw=0.3) st_patch = patches.PathPatch(st_path, edgecolor=edgecolor, fill=False, lw=0.6) ax.add_patch(cnt_patch) ax.add_patch(st_patch) ax.set_aspect(1.) ax.set_facecolor(facecolor) ax.set_xlim([minx, maxx]) ax.set_ylim([miny, maxy]) t3 = time.time() print(f'zh time, {t3-t2:.4f}') # ZDR plot #------------------------------ t2 = time.time() ax = fig.add_subplot(2, ncol, 2) plt.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False) plt.tick_params(axis='y', which='both', left=False, right=False, labelleft=False) #plt.pcolormesh(xcor, ycor, zdr, cmap=zdr_map, vmin=-2.4, vmax=6.9) plt.pcolormesh(xcor, ycor, zdr, cmap=zdr_map, vmin=zdr_min, vmax=zdr_max) cb = plt.colorbar(format='%.1f', fraction=0.045) if range_rings: cs = plt.contour(xcor, ycor, zcor / 1.e3, levels=clevs, linewidths=2., colors='k', linestyles='--') ax.clabel(cs, inline=1, fmt=fmt_dict, fontsize=axti_fsize) ax.set_title('Z$\sf{_{DR}}$ (dB)', x=0.0, y=1.02, horizontalalignment='left', fontsize=axtl_fsize) cnt_patch = patches.PathPatch(cnt_path, edgecolor=edgecolor, fill=False, lw=0.3) st_patch = patches.PathPatch(st_path, edgecolor=edgecolor, fill=False, lw=0.6) ax.add_patch(cnt_patch) ax.add_patch(st_patch) ax.set_aspect(1.) ax.set_facecolor(facecolor) ax.set_xlim([minx, maxx]) ax.set_ylim([miny, maxy]) t3 = time.time() print(f'zdr time, {t3-t2:.4f}') # KDP plot #------------------------------ t2 = time.time() ax = plt.subplot(2, ncol, 3) plt.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False) plt.tick_params(axis='y', which='both', left=False, right=False, labelleft=False) #plt.pcolormesh(xcor, ycor, kdp, cmap=kdp_map, vmin=-1.6, vmax=4.3) plt.pcolormesh(xcor, ycor, kdp, cmap=kdp_map, vmin=kdp_min, vmax=kdp_max) cb = plt.colorbar(format='%.1f', fraction=0.045) if range_rings: cs = plt.contour(xcor, ycor, zcor / 1.e3, levels=clevs, linewidths=2., colors='k', linestyles='--') ax.clabel(cs, inline=1, fmt=fmt_dict, fontsize=axti_fsize) ax.set_title('$\sf{K_{DP}}$ ($^{\circ}$ km$^{-1}$)', x=0.0, y=1.02, horizontalalignment='left', fontsize=axtl_fsize) cnt_patch = patches.PathPatch(cnt_path, edgecolor=edgecolor, fill=False, lw=0.3) st_patch = patches.PathPatch(st_path, edgecolor=edgecolor, fill=False, lw=0.6) ax.add_patch(cnt_patch) ax.add_patch(st_patch) ax.set_aspect(1.) ax.set_facecolor(facecolor) ax.set_xlim([minx, maxx]) ax.set_ylim([miny, maxy]) t3 = time.time() print(f'kdp time, {t3-t2:.4f}') # RhoHV plot #------------------------------ t2 = time.time() ax = plt.subplot(2, ncol, 4) plt.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False) plt.tick_params(axis='y', which='both', left=False, right=False, labelleft=False) #plt.pcolormesh(xcor, ycor, rhohv, cmap=phv_map, vmin=0.695, vmax=1.045) #plt.pcolormesh(xcor, ycor, rhohv, cmap=phv_map, vmin=rhohv_min, vmax=rhohv_max) plt.pcolormesh(xcor, ycor, rhohv, cmap='Spectral_r', vmin=rhohv_min, vmax=rhohv_max) cb = plt.colorbar(format='%.2f', fraction=0.045) if range_rings: cs = plt.contour(xcor, ycor, zcor / 1.e3, levels=clevs, linewidths=2., colors='k', linestyles='--') ax.clabel(cs, inline=1, fmt=fmt_dict, fontsize=axti_fsize) ax.set_title('$\\rho\sf{_{HV}}$', x=0.0, y=1.02, horizontalalignment='left', fontsize=axtl_fsize) cnt_patch = patches.PathPatch(cnt_path, edgecolor=edgecolor, fill=False, lw=0.3) st_patch = patches.PathPatch(st_path, edgecolor=edgecolor, fill=False, lw=0.6) ax.add_patch(cnt_patch) ax.add_patch(st_patch) ax.set_aspect(1.) ax.set_facecolor(facecolor) ax.set_xlim([minx, maxx]) ax.set_ylim([miny, maxy]) t3 = time.time() print(f'rhohv time, {t3-t2:.4f}') if npanel == 6: # MDV plot #------------------------------ t2 = time.time() ax = plt.subplot(2, ncol, 5) plt.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False) plt.tick_params(axis='y', which='both', left=False, right=False, labelleft=False) plt.pcolormesh(xcor_v, ycor_v, vel, cmap=vel_map, vmin=-nyvel, vmax=nyvel) cb = plt.colorbar(format='%.0f', fraction=0.045) if range_rings: cs = plt.contour(xcor_v, ycor_v, zcor_v / 1.e3, levels=clevs, linewidths=2., colors='k', linestyles='--') ax.clabel(cs, inline=1, fmt=fmt_dict, fontsize=axti_fsize) ax.set_title('$\sf{MDV}$ (m s$^{-1}$)', x=0.0, y=1.02, horizontalalignment='left', fontsize=axtl_fsize) cnt_patch = patches.PathPatch(cnt_path, edgecolor=edgecolor, fill=False, lw=0.3) st_patch = patches.PathPatch(st_path, edgecolor=edgecolor, fill=False, lw=0.6) ax.add_patch(cnt_patch) ax.add_patch(st_patch) ax.set_aspect(1.) ax.set_facecolor(facecolor) ax.set_xlim([minx, maxx]) ax.set_ylim([miny, maxy]) t3 = time.time() print(f'vel time, {t3-t2:.4f}') # SW plot #------------------------------ t2 = time.time() ax = plt.subplot(2, ncol, 6) plt.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False) plt.tick_params(axis='y', which='both', left=False, right=False, labelleft=False) plt.pcolormesh(xcor_v, ycor_v, swd, cmap='magma', vmin=0., vmax=10.) cb = plt.colorbar(format='%.1f', fraction=0.045) if range_rings: cs = plt.contour(xcor_v, ycor_v, zcor_v / 1.e3, levels=clevs, linewidths=2., colors='k', linestyles='--') ax.clabel(cs, inline=1, fmt=fmt_dict, fontsize=axti_fsize) ax.set_title('$\\sigma\sf{_v}$ (m s$^{-1}$)', x=0.0, y=1.02, horizontalalignment='left', fontsize=axtl_fsize) cnt_patch = patches.PathPatch(cnt_path, edgecolor=edgecolor, fill=False, lw=0.3) st_patch = patches.PathPatch(st_path, edgecolor=edgecolor, fill=False, lw=0.6) ax.add_patch(cnt_patch) ax.add_patch(st_patch) ax.set_aspect(1.) ax.set_facecolor(facecolor) ax.set_xlim([minx, maxx]) ax.set_ylim([miny, maxy]) t3 = time.time() print(f'sw time, {t3-t2:.4f}') # save image as .png #------------------------------- title = '{} - {}/{}/{} - {}:{} UTC - {:.1f} deg. PPI'.format( site, yyyy, mm, dd, hh, mn, float(angle)) plt.suptitle(title, fontsize=24, y=1.04) plt.subplots_adjust(top=0.96, hspace=0., wspace=0.2) imgname = yyyy + mm + dd + '_' + hh + mn + '_' + site.lower() + '.png' t2 = time.time() plt.savefig(imgname, format='png', dpi=150, bbox_inches='tight') plt.close() t3 = time.time() print(f'render time, {t3-t2:.4f}')
#----------------------------------- print 'Opening file...' yyyy = '2018' mm = '09' dd = '14' hh = '12' mn = '03' ss = '46' site = 'KLTX' direc = 'aws_nexrad/' filename = '{}{}{}{}_{}{}{}_V06'.format(site, yyyy, mm, dd, hh, mn, ss) rad = read_nexrad_archive(direc+filename) rad_sw = rad.extract_sweeps([1]) # get variables #----------------------------------- elev_p = rad_sw.elevation['data'] azi_p = 90.-rad_sw.azimuth['data'] ran = rad_sw.range['data'] vel_p = rad_sw.fields['velocity']['data'] nyvel = rad.get_nyquist_vel(1) azi_p[azi_p<0.] = azi_p[azi_p<0.]+360. dims = vel_p.shape numradials = dims[0]+1 numgates = dims[1]