Пример #1
0
def get_two_best_sondes(date_str, **kwargs):
	sonde_file=kwargs.get('sonde_file', '/bm/gdata/scollis/twpice/darwin.txt')
	#outdir=kwargs.get('outdir', '/flurry/home/scollis/bom_mds/dealias/')
	sonde_file=kwargs.get('sonde_file', '/bm/gdata/scollis/twpice/darwin.txt')
	outdir=kwargs.get('outdir', '/flurry/home/scollis/bom_mds/dealias/')
	tim_date=num2date(datestr2num(date_str))
	sonde_list=read_sounding.read_sounding_within_a_day(sonde_file, tim_date)
	launch_dates=[sonde['date_list'][0] for sonde in sonde_list]
	#print launch_dates
	launch_date_offset=[date2num(sonde['date_list'][0])- date2num(tim_date)  for sonde in sonde_list]
	sonde_made_it=False
	candidate=0
	while not(sonde_made_it):
		best_sonde=sonde_list[argsort(abs(array(launch_date_offset)))[candidate]]
		candidate=candidate+1
		sonde_made_it=best_sonde['alt(m)'][-1] > 18000.
		if not sonde_made_it: print "Sonde Burst at ", best_sonde['alt(m)'][-1], "m rejecting"
	print "Sonde Burst at ", best_sonde['alt(m)'][-1], "m Accepting"
	sonde_made_it=False
	while not(sonde_made_it):
		sec_best_sonde=sonde_list[argsort(abs(array(launch_date_offset)))[candidate]]
		candidate=candidate+1
		sonde_made_it=sec_best_sonde['alt(m)'][-1] > 18000.
		if not sonde_made_it: print "Sonde Burst at ", sec_best_sonde['alt(m)'][-1], "m rejecting"
	print "Sonde Burst at ", sec_best_sonde['alt(m)'][-1], "m Accepting"
	print 'Time of radar: ', tim_date, ' Time of  best sonde_launch: ', best_sonde['date_list'][0], ' Time of sonde_termination: ', best_sonde['date_list'][-1]
	print 'Time of radar: ', tim_date, ' Time of second sonde_launch: ', sec_best_sonde['date_list'][0], ' Time of sonde_termination: ', best_sonde['date_list'][-1]
	for i in range(len(sonde_list)):
		best_sonde=sonde_list[argsort(abs(array(launch_date_offset)))[i]]
		print 'Time of radar: ', tim_date, ' Time of  best sonde_launch: ', best_sonde['date_list'][0], ' Offset', abs(date2num(best_sonde['date_list'][0])-date2num(tim_date))*24.0
	return best_sonde, sec_best_sonde
Пример #2
0
def recon(date_str, latstr, lonstr):
     use_guess='sonde'
     sonde_file='/bm/gdata/scollis/twpice/darwin.txt'
     #tim='1350'
     tim_date=num2date(datestr2num(date_str)) 
     ber, gp=netcdf_utis.load_cube('/bm/gdata/scollis/cube_data/'+std_datestr(tim_date)+'_deal.nc')
     sonde_list=read_sounding.read_sounding_within_a_day(sonde_file, tim_date)
     #launch_dates=[sonde['date_list'][0] for sonde in sonde_list]
     #launch_date_offset=[date2num(sonde['date_list'][0])- date2num(tim_date)  for sonde in sonde_list]
     #best_sonde=sonde_list[argsort(abs(array(launch_date_offset)))[0]]
     #print 'Time of radar: ', tim_date, ' Time of sonde_launch: ', best_sonde['date_list'][0], ' Time of sonde_termination: ', best_sonde['date_list'][-1]
     req=[ 'alt(m)',  'wspd(m/s)', 'tdry(degs)',  'wdir(degs)']	
     first_sonde, second_sonde=read_sounding.get_two_best_conc_sondes(date_str, req_vars=req)
     interp_sonde=read_sounding.interp_sonde_time(first_sonde, second_sonde, tim_date, gp['levs'])
     u_sonde=ones(gp['CZ'].shape, dtype=float)
     v_sonde=ones(gp['CZ'].shape, dtype=float)
     w_sonde=zeros(gp['CZ'].shape, dtype=float)
     for k in range(len(gp['levs'])):
	     u_sonde[:,:,k]=-1.0*u_sonde[:,:,k]*interp_sonde['wspd(m/s)'][k]*sin(pi*interp_sonde['wdir(degs)'][k]/180.0)
	     v_sonde[:,:,k]=-1.0*v_sonde[:,:,k]*interp_sonde['wspd(m/s)'][k]*cos(pi*interp_sonde['wdir(degs)'][k]/180.0)
     Re=6371.0*1000.0
     rad_at_radar=Re*sin(pi/2.0 -abs(gp['zero_loc'][0]*pi/180.0))#ax_radius(float(lat_cpol), units='degrees')
     lons=gp['zero_loc'][1]+360.0*gp['xar']/(rad_at_radar*2.0*pi)
     lats=gp['zero_loc'][0] + 360.0*gp['yar']/(Re*2.0*pi)	
     ber_loc=[-12.457, 130.925]
     gp_loc= [-12.2492,  131.0444]
     
     if use_guess=='none':
	  igu=ones(ber['CZ'].shape, dtype=float)*0.0
	  igv=ones(ber['CZ'].shape, dtype=float)*0.0
	  igw=ones(ber['CZ'].shape, dtype=float)*0.0
     elif use_guess=='sonde':
	  igu=u_sonde
	  igv=v_sonde
	  igw=w_sonde
     else:
	  ber_ig, gp_ig=netcdf_utis.load_cube(use_guess)
	  print gp_ig.keys()
	  igu=gp_ig['u_array']
	  igv=gp_ig['v_array']
	  igw=ones(ber['CZ'].shape, dtype=float)*0.0
     
     #mywts=ones(ber['CZ'].shape, dtype=float)
     angs=array(propigation.make_lobe_grid(ber_loc, gp_loc, lats,lons))
     #wts_ang=zeros(gp['CZ'][:,:,0].shape, dtype=float)
     #for i in range(angs.shape[0]):
     #    for j in range(angs.shape[1]):
     #		 if (angs[i,j] < 150.0) and (angs[i,j] > 30.0): wts_ang[i,j]=1.0
     #for lvl_num in range(len(gp['levs'])):
     #	  #create a weighting grid
     #	  mask_reflect=10.0#dBZ	
     #	  mask=(gp['CZ'][:,:,lvl_num]/mask_reflect).round().clip(min=0., max=1.0) 
     #	  mask_vel_ber=(ber['VR'][:,:,lvl_num]+100.).clip(min=0., max=1.)
     #	  mywts[:,:,lvl_num]=mask*mask_vel_ber*wts_ang	
     mywts=met.make_mask(ber, gp, angs, 1.0, 80.0)
     print "Mean gp masked Velocity ", (gp['VE']*mywts).mean()
     print "min gp masked Velocity ", (gp['VE']*mywts).min()
     print "max gp masked Velocity ", (gp['VE']*mywts).max()
     print "Mean Berrimah masked Velocity ", (ber['VE']*mywts).mean()
     print "min Berrimah masked Velocity ", (ber['VE']*mywts).min()
     print "max Berrimah masked Velocity ", (ber['VE']*mywts).max()
     print "Mean gp masked CZ ", (gp['CZ']*mywts).mean()
     print "min gp masked CZ ", (gp['CZ']*mywts).min()
     print "max gp masked CZ ", (gp['CZ']*mywts).max()
     print "Mean Berrimah masked CZ ", (ber['CZ']*mywts).mean()
     print "min Berrimah masked CZ ", (ber['CZ']*mywts).min()
     print "max Berrimah masked CZ ", (ber['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(gp['CZ']*mywts, tdry, gp['levs'], display=True)
     print "**********************FALLSPEED INFO****************************"
     #print 
     
     
     f=0.0
     X=[igu,igv,igw]
     G,F,X=grad_conj_solver_3d.gracon_3d_packaged(X ,ber, gp, mywts, interp_sonde)
     u_array,v_array,w_array=X 
     lvl=2500.0
     lvl_num=argsort(abs(gp['levs']-lvl))[0]
     print "Level_num=", lvl_num
     if latstr=='max' or lonstr=='max':
	     maskedcz=gp['CZ'][:,:,lvl_num]*mywts[:,:,lvl_num]
	     i,j=mathematics.where_closest_2d(maskedcz.max(), maskedcz)
	     print i,j
	     lat=lats[j[0]]
	     lon=lons[i[0]]
	     print "Max CZ at ", lat, lon 
     else:
	     lon=float(lonstr)
	     lat=float(latstr)
     f=figure()
     #(lat_sl, lon_sl, lvl, data_cube, lats, lons, levs, u, v, w, angs, mask, par='CZ', w_mag=2.0, **kwargs)
     alat, alon, alvl=pres.plot_slices(lat, lon, lvl, gp, lats, lons, gp['levs'], u_array, v_array, w_array, angs, mywts, par='CZ', w_mag=2.0,box=[130.5, 131.5, -12.7, -12.0], bquiver=[0.05, 0.75], ksp=0.05)
     t1='Gunn Point reflectivity (dBZ) and reconstructed winds (m/s, *2.0 for w)\n sliced at %(alat)2.2fS and %(alon)3.2fE and %(alvl)d Metres on 22/01/06 at ' %{'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}
     print ff
     savefig(ff+t2+'.png', dpi=200)
     gp.update({'u_array':u_array, 'v_array':v_array, 'w_array':w_array})
     netcdf_utis.save_data_cube(ber, gp, '/bm/gdata/scollis/cube_data/'+std_datestr(tim_date)+'_winds.nc', gp_loc)
     close(f)
Пример #3
0
def get_two_best_conc_sondes(date_str, **kwargs):
	req_vars=kwargs.get('req_vars', [ 'alt(m)', 'press(hPa)',  'wspd(m/s)', 'tdry(degs)',  'wdir(degs)'])
	min_ht=kwargs.get('min_ht', 17000.)
	sonde_file=kwargs.get('sonde_file', '/bm/gdata/scollis/twpice/darwin.txt')
	#outdir=kwargs.get('outdir', '/flurry/home/scollis/bom_mds/dealias/')
	sonde_file=kwargs.get('sonde_file', '/bm/gdata/scollis/twpice/darwin.txt')
	outdir=kwargs.get('outdir', '/flurry/home/scollis/bom_mds/dealias/')
	tim_date=num2date(datestr2num(date_str))
	sonde_list=read_sounding.read_sounding_within_a_day(sonde_file, tim_date)
	launch_dates=[sonde['date_list'][0] for sonde in sonde_list]
	#print launch_dates
	launch_date_offset=[date2num(sonde['date_list'][0])- date2num(tim_date)  for sonde in sonde_list]
	sonde_made_it=False
	candidate=0
	while not(sonde_made_it):
		sonde_num=argsort(abs(array(launch_date_offset)))[candidate]
		best_sonde=sonde_list[sonde_num]
		candidate=candidate+1
		sonde_made_it=is_sonde_good(best_sonde, min_ht, req_vars)
		#sonde_made_it=best_sonde['alt(m)'][-1] > min_ht
		#if not sonde_made_it: print "Sonde Burst at ", best_sonde['alt(m)'][-1], "m rejecting"
	#print "Sonde Burst at ", best_sonde['alt(m)'][-1], "m Accepting"
	if launch_date_offset[sonde_num] < 0.:
		print "Best Sonde flight is before the radar scan"
		first_sonde=best_sonde
		candidate=sonde_num +1
		sonde_made_it=False
		while not(sonde_made_it):
			second_sonde=sonde_list[candidate]
			candidate=candidate+1
			sonde_made_it=is_sonde_good(second_sonde, min_ht, req_vars)
			#sonde_made_it=second_sonde['alt(m)'][-1] > min_ht
			#if not sonde_made_it: print "Sonde Burst at ", second_sonde['alt(m)'][-1], "m rejecting"
			if (candidate==len(sonde_list)) and not(sonde_made_it):
				print "I'm running off the end of the list, Bailing"
				second_sonde=first_sonde
				sonde_made_it=True
	elif launch_date_offset[sonde_num] > 0.:
		print "Best Sonde flight is after the radar scan"
		second_sonde=best_sonde
		candidate=sonde_num -1
		sonde_made_it=False
		while not(sonde_made_it):
			first_sonde=sonde_list[candidate]
			candidate=candidate-1
			sonde_made_it=is_sonde_good(first_sonde, min_ht, req_vars)
			#sonde_made_it=first_sonde['alt(m)'][-1] > min_ht
			#if not sonde_made_it: print "Sonde Burst at ", first_sonde['alt(m)'][-1], "m rejecting"
			if candidate==-1 and not(sonde_made_it):
				print "I'm running off the start of the list, Bailing"
				first_sonde=second_sonde
				sonde_made_it=True
	elif launch_date_offset[sonde_num]==0.:
		print "Sonde launched at exactly the same time of the scan... Huey be praised"
		first_sonde=second_sonde=best_sonde
	print 'Time of radar: ', tim_date
	print  ' Time of  first sonde_launch: ', first_sonde['date_list'][0], ' Time of first sonde_termination: ', first_sonde['date_list'][-1]
	print "Sonde Burst at ", first_sonde['alt(m)'][-1], "m Accepting"
	print  ' Time of second sonde_launch: ', second_sonde['date_list'][0], ' Time of second sonde_termination: ', second_sonde['date_list'][-1]
	print "Sonde Burst at ", second_sonde['alt(m)'][-1], "m Accepting"
	
	for i in range(len(sonde_list)):
		best_sonde=sonde_list[argsort(abs(array(launch_date_offset)))[i]]
		print 'Time of radar: ', tim_date, ' Time of  best sonde_launch: ', best_sonde['date_list'][0], ' Offset', abs(date2num(best_sonde['date_list'][0])-date2num(tim_date))*24.0
	
	return first_sonde, second_sonde