def radar_to_cappi(radar1_filename, radar2_filename,**kwargs): ini_fname=kwargs.get('ini_fname', os.getenv('HOME')+'/bom_mds/bom_mds.ini') loud=kwargs.get('loud', False) ini_dict=parse_ini.parse_ini(ini_fname) if loud: print "Loading radar file 1" if 'radar1_path' in ini_dict.keys(): radar1=read_radar.load_radar(ini_dict['radar1_path']+radar1_filename) else: radar1=pyradar.load_radar(radar1_filename) if loud: print "Loading radar file 2" if 'radar2_path' in ini_dict.keys(): radar2=read_radar.load_radar(ini_dict['radar2_path']+radar2_filename) else: radar2=pyradar.load_radar(radar2_filename) cappi_z_bounds=ini_dict.get('cappi_z_bounds', [500,15000]) cappi_xy_bounds=ini_dict.get('cappi_xy_bounds', [-50000, 50000]) cappi_resolution=ini_dict.get('cappi_resolution', [100, 40]) levs=linspace(cappi_z_bounds[0], cappi_z_bounds[1], cappi_resolution[1]) xar=linspace(cappi_xy_bounds[0], cappi_xy_bounds[1], cappi_resolution[0]) yar=linspace(cappi_xy_bounds[0], cappi_xy_bounds[1], cappi_resolution[0]) displace=mathematics.corner_to_point(radar1[0]['radar_loc'], radar2[0]['radar_loc']) if loud: print "Cappi-ing radar 1" radar1_cube=radar_to_cart.make_cube(radar1, xar, yar, levs) if loud: print "Cappi-ing radar 2" radar2_cube=radar_to_cart.make_cube(radar2, xar, yar, levs, displacement=displace) cube_fname=ini_dict['cube_path']+'cappi_'+std_datestr(radar1_cube['date'])+'.nc' netcdf_utis.save_data_cube(radar1_cube, radar2_cube, cube_fname)
def process_scan(scan, **kwargs): ini_fname=kwargs.get('ini_fname', os.getenv('HOME')+'/bom_mds/bom_mds.ini') ini_dict=parse_ini.parse_ini(ini_fname) gated_vars=['VE', 'VR', 'CZ', 'RH', 'PH', 'ZD', 'SW','KD'] filtered_scan={} for item in set(scan.keys())&set(gated_vars): if ini_dict[item+'_bins'] !=0: rec_array=numpy.zeros(scan[item].shape, dtype=float) for az_num in range(scan[item].shape[0]): rec_array[az_num, :]=filter_ray(scan[item][az_num,:], scan['RH'][az_num,:], npts=ini_dict[item+'_bins'], ftype=ini_dict[item+'_window'], RH_thresh=ini_dict['RH_thresh']) filtered_scan.update({item:rec_array}) else: filtered_scan.update({item:scan[item]}) rec_array=numpy.zeros(scan[item].shape, dtype=float) for az_num in range(scan['PH'].shape[0]): rec_array[az_num, :]=generate_kdp(scan['PH'][az_num,:], scan['range'][az_num,:] ,scan['RH'][az_num,:] ,npts=ini_dict['KD_bins'], ftype=ini_dict['KD_window'], RH_thresh=ini_dict['RH_thresh']) filtered_scan.update({'KD':rec_array}) return filtered_scan
def pres_winds(datestr, **kwargs): #latstr, lonstr, ini_fname=kwargs.get('ini_fname', os.getenv('HOME')+'/bom_mds/bom_mds.ini') ini_dict=parse_ini.parse_ini(ini_fname) parm=kwargs.get('parm','CZ') dateobj=num2date(datestr2num(datestr)) tim_date=num2date(datestr2num(datestr)) radar1, radar2=netcdf_utis.load_cube('/data/cube_data/'+std_datestr(tim_date)+'_winds.nc') print radar1['radar_name'] print radar2['radar_name'] lvl=kwargs.get('lvl',3000.0) lvl_num=argsort(abs(radar1['levs']-lvl))[0] print "Level_num=", lvl_num Re=6371.0*1000.0 rad_at_radar=Re*sin(pi/2.0 -abs(radar1['radar_loc'][0]*pi/180.0)) lons=radar1['radar_loc'][1]+360.0*radar1['xar']/(rad_at_radar*2.0*pi) lats=radar1['radar_loc'][0] + 360.0*radar1['yar']/(Re*2.0*pi) ber_loc=[-12.457, 130.925] gp_loc=[-12.2492, 131.0444] angs=array(propigation.make_lobe_grid(radar2['radar_loc'], radar1['radar_loc'], lats,lons)) mywts=met.make_mask_bad1(radar2, radar1, angs, 1.0, 80.0) if ini_dict['cross'][0]=='max' or ini_dict['cross'][1]=='max': #maskedcz=radar1['CZ'][:,:,lvl_num]*mywts[:,:,lvl_num] #i,j=mathematics.where_closest_2d(maskedcz.max(), maskedcz) maskedw=radar1['w_array'][:,:,7]*mywts[:,:,7] i,j=mathematics.where_closest_2d(maskedw.max(), maskedw) print i,j lat=lats[j[0]] lon=lons[i[0]] print "Max w at ", lat, lon else: lon=ini_dict['cross'][1]#float(lonstr) lat=ini_dict['cross'][0]#float(latstr) f=figure() alat, alon, alvl=pres.plot_slices(lat, lon, lvl, radar1, lats, lons, radar1['levs'], radar1['u_array'], radar1['v_array'], radar1['w_array'], angs, mywts, par=parm, w_mag=1.0,box=ini_dict['pres_box'], bquiver=[0.05, 0.75], ksp=0.05,qscale=ini_dict['qscale']) t1='Gunn Point reflectivity (dBZ) and reconstructed winds (m/s)\n sliced at %(alat)2.2fS and %(alon)3.2fE and %(alvl)d Metres on %(day)02d/%(mon)02d/%(yr)04d at ' %{'day':tim_date.day, 'mon':tim_date.month, 'yr':tim_date.year,'alat':abs(alat), 'alon':alon, 'alvl':alvl} t2=" %(HH)02d%(MM)02dZ" %{'HH':tim_date.hour, 'MM':tim_date.minute} f.text( .1, .92, t1+t2) inte_part=1000*(float(int(lat))-lat) print {'alat':abs(alat), 'alon':alon, 'alvl':alvl} #ff=os.getenv('HOME')+'/bom_mds/output/recons_'+std_datestr(tim_date)[0:-5]+'/slicer3_%(alat)2.02f_%(alon)3.02f_%(alvl)05d_' %{'alat':abs(alat), 'alon':alon, 'alvl':alvl} ff=os.getenv('HOME')+'/bom_mds/output/tests/slicer_'+std_datestr(tim_date)+'_%(alat)2.02f_%(alon)3.02f_%(alvl)05d_' %{'alat':abs(alat), 'alon':alon, 'alvl':alvl} print ff savefig(ff+t2+'.png', dpi=200) close(f)
def radar_to_winds(datestr, **kwargs): #check to see if we have the radar files #check to see if there are deailased files #kwargs={} loud=kwargs.get('loud', False) #datestr='200601220700' ini_fname=kwargs.get('ini_fname', os.getenv('HOME')+'/bom_mds/bom_mds.ini') dateobj=num2date(datestr2num(datestr)) ini_fname=kwargs.get('ini_fname', os.getenv('HOME')+'/bom_mds/bom_mds.ini') ini_dict=parse_ini.parse_ini(ini_fname) radar1_deal_list=os.listdir(ini_dict['radar1_path']) radar2_deal_list=os.listdir(ini_dict['radar2_path']) radar1_raw_list=os.listdir(ini_dict['radar1_raw_path']) radar2_raw_list=os.listdir(ini_dict['radar2_raw_path']) radar1_target=ini_dict['radar1_prefix']+std_datestr(dateobj, ini_dict['radar1_type']) radar2_target=ini_dict['radar2_prefix']+std_datestr(dateobj, ini_dict['radar2_type']) poss_deal_files1=[] for item in radar1_deal_list: if radar1_target in item: poss_deal_files1.append(item) if len(poss_deal_files1)==0: poss_raw_files1=[] print "No dealiased files found... Dealiasing" for item in radar1_raw_list: if radar1_target in item: poss_raw_files1.append(item) if len(poss_raw_files1)==0: #print "no files found" raise IOError, 'Radar 2 File not there' #return else: print "Dealiasing "+poss_raw_files1[0] radar1_filename=dealias.dealias_arb(poss_raw_files1[0], ini_dict['radar1_type'], ini_dict['radar1_raw_path'], ini_dict['radar1_path'], ini_dict['radar1_prefix']) else: radar1_filename=poss_deal_files1[0] poss_deal_files2=[] for item in radar2_deal_list: if radar2_target in item: poss_deal_files2.append(item) if len(poss_deal_files2)==0: poss_raw_files2=[] print "No dealiased files found... Dealiasing" for item in radar2_raw_list: if radar2_target in item: poss_raw_files2.append(item) if len(poss_raw_files2)==0: #print "no files found" raise IOError, 'Radar 2 File not there' else: radar2_filename=dealias.dealias_arb(poss_raw_files2[0], ini_dict['radar2_type'], ini_dict['radar2_raw_path'], ini_dict['radar2_path'], ini_dict['radar2_prefix']) else: radar2_filename=poss_deal_files2[0] if loud: print "Loading radar file 1" if 'radar1_path' in ini_dict.keys(): radar1=read_radar.load_radar(ini_dict['radar1_path']+radar1_filename) else: radar1=read_radar.load_radar(radar1_filename) if loud: print "Loading radar file 2" if 'radar2_path' in ini_dict.keys(): radar2=read_radar.load_radar(ini_dict['radar2_path']+radar2_filename) else: radar2=read_radar.load_radar(radar2_filename) pres.plot_ppi(radar2[2],'VE', fig_path='/scratch/bom_mds_dumps/', fig_name='radar2_ve.png') pres.plot_ppi(radar2[2],'CZ', fig_path='/scratch/bom_mds_dumps/', fig_name='radar2_cz.png') cappi_z_bounds=ini_dict.get('cappi_z_bounds', [500,15000]) cappi_xy_bounds=ini_dict.get('cappi_xy_bounds', [-50000, 50000]) cappi_resolution=ini_dict.get('cappi_resolution', [100, 40]) levs=linspace(cappi_z_bounds[0], cappi_z_bounds[1], cappi_resolution[1]) xar=linspace(cappi_xy_bounds[0], cappi_xy_bounds[1], cappi_resolution[0]) yar=linspace(cappi_xy_bounds[0], cappi_xy_bounds[1], cappi_resolution[0]) displace=mathematics.corner_to_point(radar1[0]['radar_loc'], radar2[0]['radar_loc']) if loud: print "Cappi-ing radar 1" #radar1_cube_=radar_to_cart.make_cube(radar1, xar, yar, levs) radar1_cube=cappi_v2.make_cube_all(radar1,xar, yar,levs) #max_el=array([scan['Elev'][0] for scan in radar1]).max() #radar1_cube=cappi_v2.blend(radar1_cube_v,radar1_cube_h, max_el,loud=True) if loud: print "Cappi-ing radar 2" #radar2_cube_v=radar_to_cart.make_cube(radar2, xar, yar, levs, displacement=displace) radar2_cube=cappi_v2.make_cube_all(radar2,xar, yar,levs, displacement=displace) #max_el=array([scan['Elev'][0] for scan in radar2]).max() #radar2_cube=cappi_v2.blend(radar2_cube_v,radar2_cube_h, max_el,loud=True) #radar2_cube_v=radar_to_cart.make_cube(radar2, xar, yar, levs, displacement=displace) cube_fname=ini_dict['cube_path']+'cappi_'+std_datestr(radar1_cube['date'], "uf")+'.nc' #netcdf_utis.save_data_cube(radar1_cube, radar2_cube, cube_fname) #Initial Guess req=[ 'alt(m)', 'wspd(m/s)', 'wdir(degs)', 'tdry(degs)','press(hPa)' ] first_sonde,second_sonde = read_sounding.get_two_best_conc_sondes(datestr, req_vars=req) interp_sonde=read_sounding.interp_sonde_time(first_sonde, second_sonde, dateobj, levs) if ini_dict['initial_guess']=='sonde': #using a sonde for out initial gues u_ig=ones(radar1_cube['CZ'].shape, dtype=float) v_ig=ones(radar1_cube['CZ'].shape, dtype=float) w_ig=zeros(radar1_cube['CZ'].shape, dtype=float) for k in range(len(levs)): u_ig[:,:,k]=1.0*u_ig[:,:,k]*interp_sonde['wspd(m/s)'][k]*sin(pi*interp_sonde['wdir(degs)'][k]/180.0) v_ig[:,:,k]=1.0*v_ig[:,:,k]*interp_sonde['wspd(m/s)'][k]*cos(pi*interp_sonde['wdir(degs)'][k]/180.0) else: u_ig=zeros(radar1_cube['CZ'].shape, dtype=float) v_ig=zeros(radar1_cube['CZ'].shape, dtype=float) w_ig=zeros(radar1_cube['CZ'].shape, dtype=float) Re=6371.0*1000.0 rad_at_radar=Re*sin(pi/2.0 -abs(radar1[0]['radar_loc'][0]*pi/180.0))#ax_radius(float(lat_cpol), units='degrees') lons=radar1[0]['radar_loc'][1]+360.0*xar/(rad_at_radar*2.0*pi) lats=radar1[0]['radar_loc'][0] + 360.0*yar/(Re*2.0*pi) #Masking angs=array(propigation.make_lobe_grid(radar2[0]['radar_loc'], radar1[0]['radar_loc'], lats,lons)) mywts=met.make_mask_bad1(radar2_cube, radar1_cube, angs, 1.0, 80.0) print "Mean gp masked Velocity ", (radar1_cube['VE']*mywts).mean() print "min gp masked Velocity ", (radar1_cube['VE']*mywts).min() print "max gp masked Velocity ", (radar1_cube['VE']*mywts).max() print "Mean Berrimah masked Velocity ", (radar2_cube['VE']*mywts).mean() print "min Berrimah masked Velocity ", (radar2_cube['VE']*mywts).min() print "max Berrimah masked Velocity ", (radar2_cube['VE']*mywts).max() print "Mean gp masked CZ ", (radar1_cube['CZ']*mywts).mean() print "min gp masked CZ ", (radar1_cube['CZ']*mywts).min() print "max gp masked CZ ", (radar1_cube['CZ']*mywts).max() print "Mean Berrimah masked CZ ", (radar2_cube['CZ']*mywts).mean() print "min Berrimah masked CZ ", (radar2_cube['CZ']*mywts).min() print "max Berrimah masked CZ ", (radar2_cube['CZ']*mywts).max() print "Number of masked points", (mywts.shape[0]*mywts.shape[1]*mywts.shape[2])-mywts.sum() print "Number of unmasked points ", mywts.sum() print "**********************FALLSPEED INFO****************************" #def terminal_velocity(refl, temps, levs, display=False): tdry=interp_sonde['tdry(degs)'] pressure=interp_sonde['press(hPa)'] dummy=met.terminal_velocity(radar1_cube['CZ']*mywts, tdry, radar1_cube['levs'], display=True) print "**********************FALLSPEED INFO****************************" f=0.0 X=[u_ig,v_ig,w_ig] G,F,X=grad_conj_solver_3d.gracon_3d_packaged(X ,radar2_cube, radar1_cube, mywts, interp_sonde) u_array,v_array,w_array=X radar1_cube.update({'u_array':u_array, 'v_array':v_array, 'w_array':w_array}) netcdf_utis.save_data_cube(radar1_cube, radar2_cube, '/data/cube_data/'+std_datestr(dateobj, "uf") +'_winds.nc')
def read_class(date_obj, **kwargs): hydro_filename = "/data/cpol_hyrdo_class/" + dt + "_" + tm + ".ascii" hydro_file = open(hydro_filename, "r") hydro_ascii = hydro_file.readlines() hydro_file.close() hydro_dateobj = num2date(datestr2num(hydro_ascii[0])) data_list = [float(item) for item in hydro_ascii[1].split()] data_dict = { "zero_loc": [data_list[0], data_list[1]], "xrng": [data_list[2], data_list[3]], "yrng": [data_list[5], data_list[6]], "zrng": [data_list[8], data_list[9]], "res": [data_list[4], data_list[7], data_list[10]], } float_list = [] for item in hydro_ascii[2 : len(hydro_ascii)]: for number in item.split(): float_list.append(float(number)) classifyT = zeros(data_dict["res"], dtype="float") reflT = zeros(data_dict["res"], dtype="float") # i+nx*(j-1)+nx*ny*(k-1) classify = zeros(data_dict["res"], dtype="float") refl = zeros(data_dict["res"], dtype="float") for i in range(data_dict["res"][0]): for j in range(data_dict["res"][1]): for k in range(data_dict["res"][2]): classifyT[i, j, k] = float_list[ int(i + j * data_dict["res"][0] + data_dict["res"][1] * data_dict["res"][0] * k) * 2 + 1 ] reflT[i, j, k] = float_list[ int(i + j * data_dict["res"][0] + data_dict["res"][1] * data_dict["res"][0] * k) * 2 ] for k in range(data_dict["res"][2]): classify[:, :, k] = transpose(classifyT[:, :, k]) refl[:, :, k] = transpose(reflT[:, :, k]) xar = linspace(data_dict["xrng"][0], data_dict["xrng"][1], data_dict["res"][0]) * 1000.0 yar = linspace(data_dict["yrng"][0], data_dict["yrng"][1], data_dict["res"][1]) * 1000.0 zar = linspace(data_dict["zrng"][0], data_dict["zrng"][1], data_dict["res"][2]) * 1000.0 Re = 6371.0 * 1000.0 rad_at_radar = Re * sin( pi / 2.0 - abs(data_dict["zero_loc"][0] * pi / 180.0) ) # ax_radius(float(lat_cpol), units='degrees') lons = data_dict["zero_loc"][1] + 360.0 * xar / (rad_at_radar * 2.0 * pi) lats = data_dict["zero_loc"][0] + 360.0 * yar / (Re * 2.0 * pi) data_dict.update({"xar": xar, "yar": yar, "zar": zar, "CZ": refl, "classify": classify, "lats": lats, "lons": lons}) datestr = dt + " " + tm kwargs = {} ini_fname = kwargs.get("ini_fname", os.getenv("HOME") + "/bom_mds/bom_mds.ini") ini_dict = parse_ini.parse_ini(ini_fname) dateobj = num2date(datestr2num(datestr)) tim_date = num2date(datestr2num(datestr)) radar1, radar2 = netcdf_utis.load_cube("/data/cube_data/" + std_datestr(tim_date) + "_winds.nc") Re = 6371.0 * 1000.0 rad_at_radar = Re * sin(pi / 2.0 - abs(radar1["radar_loc"][0] * pi / 180.0)) lons = radar1["radar_loc"][1] + 360.0 * radar1["xar"] / (rad_at_radar * 2.0 * pi) lats = radar1["radar_loc"][0] + 360.0 * radar1["yar"] / (Re * 2.0 * pi) ber_loc = [-12.457, 130.925] gp_loc = [-12.2492, 131.0444]
date_dict={'y':date_obj.year,'m':date_obj.month,'d':date_obj.day,'HH':date_obj.hour, 'MM':date_obj.minute} return "%(y)04d%(m)02d%(d)02d%(HH)02d%(MM)02d" %date_dict kwargs={} datestr='200601220700' #check to see if we have the radar files #check to see if there are deailased files #kwargs={} loud=kwargs.get('loud', False) ini_fname=kwargs.get('ini_fname', os.getenv('HOME')+'/bom_mds/bom_mds.ini') dateobj=num2date(datestr2num(datestr)) ini_fname=kwargs.get('ini_fname', os.getenv('HOME')+'/bom_mds/bom_mds.ini') ini_dict=parse_ini.parse_ini(ini_fname) radar1_deal_list=os.listdir(ini_dict['radar1_path']) radar2_deal_list=os.listdir(ini_dict['radar2_path']) radar1_raw_list=os.listdir(ini_dict['radar1_raw_path']) radar2_raw_list=os.listdir(ini_dict['radar2_raw_path']) radar1_target=ini_dict['radar1_prefix']+std_datestr(dateobj, ini_dict['radar1_type']) radar2_target=ini_dict['radar2_prefix']+std_datestr(dateobj, ini_dict['radar2_type']) poss_deal_files1=[] for item in radar1_deal_list: if radar1_target in item: poss_deal_files1.append(item) if len(poss_deal_files1)==0: poss_raw_files1=[] print "No dealiased files found... Dealiasing"