Пример #1
0
def test_radar_view():
	lats=linspace(-13.0, -11.5, 40)
	lons=linspace(130., 132., 40)
	ber_loc=[-12.4, 130.85] #location of Berrimah radar
	gp_loc=[-12.2492,  131.0444]#location of CPOL at Gunn Point
	h=2.5*1000.0
	t0=systime()
	i_a, j_a, k_a=propigation.unit_vector_grid(lats, lons, h, gp_loc)
	print "unit_vector_compute took ", systime()-t0, " seconds"
	fw=0.1#degrees
	m_bump=5.0
	#b1=simul_winds.speed_bump(lats, lons, [-12.0, 131.0], fw)*m_bump
	#b2=-1.0*simul_winds.speed_bump(lats, lons, [-12.0, 131.1], fw)*m_bump
	u,v=simul_winds.unif_wind(lats, lons, 5.0, 75.0)
	up,vp=array(simul_winds.vortex(lats, lons,  [-12.5, 131.1], fw))*m_bump
	#up=u+(b1-b2)
	#vp=v-(b1-b2)
	w=v*0.0
	v_r=i_a*(up+u)+j_a*(vp+v)+k_a*w
	f=figure()
	mapobj=pres.generate_darwin_plot()
	pres.contour_vr(mapobj,lats, lons, v_r)
	savefig(os.getenv('HOME')+'/bom_mds/output/test_radar_view_gp.png')
	close(f)
	f=figure()
	mapobj=pres.generate_darwin_plot()
	pres.quiver_contour_winds(mapobj, lats, lons, (up+u),(vp+v))
	savefig(os.getenv('HOME')+'/bom_mds/output/test_pert2.png')
	close(f)
Пример #2
0
def test_gracon():
	#setup
	noise_level=0.0#m/s
	nx=40
	ny=40
	fw=0.1
	m_bump=10.00
	t0=systime()
	lats=linspace(-13.5, -12.0, 40)
	lons=linspace(130.5, 131.5, 40)
	ber_loc=[-12.4, 130.85] #location of Berrimah radar
	gp_loc=[-12.2492,  131.0444]#location of CPOL at Gunn Point
	h=2.5*1000.0
	print 'calculating berimah UV', systime()-t0
	i_ber, j_ber, k_ber=propigation.unit_vector_grid(lats, lons, h, ber_loc)
	print 'calculating gp UV', systime()-t0
	i_gp, j_gp, k_gp=propigation.unit_vector_grid(lats, lons, h, gp_loc)
	#make winds
	u,v=simul_winds.unif_wind(lats, lons, 10.0, 75.0)
	up,vp=array(simul_winds.vortex(lats, lons,  [-12.5, 131.1], fw))*m_bump
	#make V_r measurements
	vr_ber=i_ber*(up+u)+j_ber*(vp+v) + (random.random([nx,ny])-0.5)*(noise_level*2.0)
	vr_gp=i_gp*(up+u)+j_gp*(vp+v)+ (random.random([nx,ny])-0.5)*(noise_level*2.0)
	#try to reconstruct the wind field
	igu, igv= simul_winds.unif_wind(lats, lons, 0.0, 90.0)
	gv_u=zeros(u.shape)
	gv_v=zeros(v.shape)
	f=0.0
	print igu.mean()
	
	angs=array(propigation.make_lobe_grid(ber_loc, gp_loc, lats,lons))
	wts=zeros(angs.shape, dtype=float)+1.0
	#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[i,j]=1.0
	print 'Into fortran'
	gv_u,gv_v,f,u_array,v_array = gracon_vel2d.gracon_vel2d(gv_u,gv_v,f,igu,igv,i_ber,j_ber,i_gp,j_gp,vr_ber,vr_gp,wts, nx=nx,ny=ny)
	print u_array.mean()
	print f
	bnds=[0.,20.]
	f=figure()
	mapobj=pres.generate_darwin_plot()
	pres.quiver_contour_winds(mapobj, lats, lons, (up+u),(vp+v), bounds=bnds)
	savefig(os.getenv('HOME')+'/bom_mds/output/orig_winds_clean.png')
	close(f)
	f=figure()
	mapobj=pres.generate_darwin_plot()
	pres.quiver_contour_winds(mapobj, lats, lons, (wts*u_array +0.001),(wts*v_array +0.001), bounds=bnds)
	savefig(os.getenv('HOME')+'/bom_mds/output/recon_winds_clean.png')
	close(f)
	f=figure()
	mapobj=pres.generate_darwin_plot()
	pres.quiver_contour_winds(mapobj, lats, lons, (wts*u_array - (up+u)),(wts*v_array -(vp+v)))
	savefig(os.getenv('HOME')+'/bom_mds/output/errors_clean.png')
	close(f)
Пример #3
0
def simple_reconstruction_3d_pytest(tim, lvl_str, use_guess):
	lvl=int(lvl_str)
	ber, gp=netcdf_utis.load_cube('/bm/gdata/scollis/cube_data/20060122_'+tim+'_ver_hr_big.nc')
	print gp['levs'][lvl]
	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
	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']
	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	
	f=0.0
	gv_u=zeros(ber['CZ'].shape, dtype=float)
	gv_v=zeros(ber['CZ'].shape, dtype=float)
	wts=mask*mask_vel_ber*wts_ang
	gu,gv,f= grad_conj_solver_plus_plus.meas_cost(gv_u, gv_v, f, igu, igv, ber['i_comp'], ber['j_comp'], gp['i_comp'], gp['j_comp'],  ber['VR'], gp['VR'], mywts)
	print "Mean U gradient", gu.mean(), "gv mean", gv.mean(), "F ", f
	for i in range(len(gp['levs'])):
		print "U,V ", (igu[:,:,i]).sum()/mywts[:,:,i].sum(), (igv[:,:,i]).sum()/mywts[:,:,i].sum()
		#gv_u,gv_v,cost = vel_2d_cost(gv_u,gv_v,cost,u_array,v_array,i_cmpt_r1,j_cmpt_r1,i_cmpt_r2,j_cmpt_r2,vr1,vr2,weights,nx=shape(gv_u,0),ny=shape(gv_u,1))
      		print gracon_vel2d.vel_2d_cost(gv_u[:,:,i]*0.0,gv_v[:,:,i]*0.0,0.0,igu[:,:,i],igv[:,:,i],ber['i_comp'][:,:,i], ber['j_comp'][:,:,i], gp['i_comp'][:,:,i], gp['j_comp'][:,:,i],  ber['VR'][:,:,i], gp['VR'][:,:,i],mywts[:,:,i])[2]
	gv_u,gv_v,f,u_array,v_array = grad_conj_solver_plus_plus.gracon_vel2d_3d( gv_u, gv_v, f, igu, igv, ber['i_comp'], ber['j_comp'], gp['i_comp'], gp['j_comp'], ber['VR'], gp['VR'], mywts)#, nx=nx, ny=ny, nz=nz)
	gp.update({'u_array': u_array, 'v_array':v_array})
	netcdf_utis.save_data_cube(ber, gp, '/bm/gdata/scollis/cube_data/20060122_'+tim+'_winds_ver1.nc', gp['zero_loc'])
	plotit=True
	if plotit:
		for lvl in range(len(gp['levs'])):
			print lvl
			f=figure()
			mapobj=pres.generate_darwin_plot(box=[130.8, 131.2, -12.4, -12.0])
			diff=gp['VR']-(u_array*gp['i_comp']+ v_array*gp['j_comp'])
			gp.update({'diff':diff})
			pres.reconstruction_plot(mapobj, lats, lons, gp, lvl, 'diff',u_array[:,:,lvl],v_array[:,:,lvl], angs, mywts[:,:,lvl])
			#pres.quiver_contour_winds(mapobj, lats, lons, (wts*u_array).clip(min=-50, max=50),(wts*v_array).clip(min=-50, max=50))
			t1='Gunn Point CAPPI (dBZ) and reconstructed winds (m/s) at %(lev)05dm \n 22/01/06 ' %{'lev':gp['levs'][lvl]}
			title(t1+tim) 
			ff=os.getenv('HOME')+'/bom_mds/output/recons_22012006/real_%(lev)05d_' %{'lev':gp['levs'][lvl]}
			savefig(ff+tim+'_2d_3d.png')
			close(f)	
Пример #4
0
def test_uniform_winds():
	f=figure()
	lats=linspace(-13.0, -11.5, 20)
	lons=linspace(130., 132., 20)
	u,v=simul_winds.unif_wind(lats, lons, 10.0, 45.0)
	mapobj=pres.generate_darwin_plot()
	pres.quiver_winds(mapobj, lats, lons, u,v)
	savefig(os.getenv('HOME')+'/bom_mds/output/test_uniform.png')
	close(f)
Пример #5
0
def test_pert_winds():
	f=figure()
	lats=linspace(-13.0, -11.5, 20)
	lons=linspace(130., 132., 20)
	u,v=simul_winds.unif_wind(lats, lons, 5.0, 45.0)
	mapobj=pres.generate_darwin_plot()
	fw=0.2#degrees
	m_bump=15.0
	b1=simul_winds.speed_bump(lats, lons, [-12.0, 131.0], fw)*m_bump
	b2=-1.0*simul_winds.speed_bump(lats, lons, [-12.0, 131.2], fw)*m_bump
	pres.quiver_contour_winds(mapobj, lats, lons, u+(b1+b2),v-(b1+b2))
	savefig(os.getenv('HOME')+'/bom_mds/output/test_pert.png')
	close(f)
Пример #6
0
def test_angle_grid2():
	lats=linspace(-13.0, -11.5, 100)
	lons=linspace(130., 132., 100)
	ber_loc=[-12.4, 130.85] #location of Berrimah radar
	gp_loc=[-12.2492,  131.0444]#location of CPOL at Gunn Point
	h=10.0*1000.0
	t0=systime()
	i_a, j_a, k_a=propigation.unit_vector_grid(lats, lons, h, ber_loc)
	print "compute took ", systime()-t0, " seconds"
	f=figure()
	mapobj=pres.generate_darwin_plot()
	pres.contour_comp(mapobj,lats, lons, k_a)
	savefig(os.getenv('HOME')+'/bom_mds/output/test_angs.png')
	close(f)
Пример #7
0
def simple_reconstruction(tim, lvl_str):
	#load data
	srm=array([15.0, 5.0])/sqrt(2.0)
	ber, gp=netcdf_utis.load_cube('/bm/gdata/scollis/cube_data/20060122_'+tim+'_ver1.nc')
	lvl=int(lvl_str)
	print gp['levs'][lvl]
	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]
	
	angs=array(propigation.make_lobe_grid(ber_loc, gp_loc, lats,lons))
	wts_ang=zeros(angs.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
	
	
	#create a weighting grid
	mask_reflect=10.0#dBZ	
	mask=(gp['CZ'][:,:,lvl]/mask_reflect).round().clip(min=0., max=1.0) 
	mask_vel_ber=(ber['VR'][:,:,lvl]+100.).clip(min=0., max=1.)
	#run gracon
	print 'Into fortran'
	nx,ny=ber['CZ'][:,:,lvl].shape
	f=0.0
	gv_u=zeros(ber['CZ'][:,:,lvl].shape, dtype=float)
	gv_v=zeros(ber['CZ'][:,:,lvl].shape, dtype=float)
	igu=ones(ber['CZ'][:,:,lvl].shape, dtype=float)*srm[0]
	igv=ones(ber['CZ'][:,:,lvl].shape, dtype=float)*srm[1]
	gv_u,gv_v,f,u_array,v_array = gracon_vel2d.gracon_vel2d(gv_u,gv_v,f,igu,igv,ber['i_comp'][:,:,lvl],ber['j_comp'][:,:,lvl],gp['i_comp'][:,:,lvl],gp['j_comp'][:,:,lvl], ber['VR'][:,:,lvl],gp['VR'][:,:,lvl],mask*mask_vel_ber*wts_ang, nx=nx,ny=ny)
	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)	
	wts=mask*mask_vel_ber*wts_ang
	f=figure()
	mapobj=pres.generate_darwin_plot(box=[130.8, 131.2, -12.4, -12.0])
	pres.reconstruction_plot(mapobj, lats, lons, gp, lvl, 'CZ',u_array,v_array, angs, wts)
	#pres.quiver_contour_winds(mapobj, lats, lons, (wts*u_array).clip(min=-50, max=50),(wts*v_array).clip(min=-50, max=50))
	t1='Gunn Point CAPPI (dBZ) and reconstructed winds (m/s) at %(lev)05dm \n 22/01/06 ' %{'lev':gp['levs'][lvl]}
	title(t1+tim) 
	ff=os.getenv('HOME')+'/bom_mds/output/recons_22012006/real_%(lev)05d_' %{'lev':gp['levs'][lvl]}
	savefig(ff+tim+'_2d.png')
	close(f)	
Пример #8
0
def test_mapping():
	f=figure()
	mapobj=pres.generate_darwin_plot()
	savefig(os.getenv('HOME')+'/bom_mds/output/test_mapping.png')
	close(f)
Пример #9
0
def simple_reconstruction_3d(tim, lvl_str):
	#load data
	u=0
	l=10
	ui=zeros([l],dtype=float)
	vi=zeros([l],dtype=float)
	#srm=0.0*array([1.0, 5.0])/sqrt(2.0)
	ber, gp=netcdf_utis.load_cube('/bm/gdata/scollis/cube_data/20060122_'+tim+'_ver1.nc')
	for i in range(l):
		ui[i], vi[i]=simple_reco(ber,gp,i)
	lvl=int(lvl_str)
	print gp['levs'][lvl]
	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]
	
	angs=array(propigation.make_lobe_grid(ber_loc, gp_loc, lats,lons))
	wts_ang=zeros(gp['CZ'][:,:,u:l].shape, dtype=float)
	for i in range(wts_ang.shape[0]):
		for j in range(wts_ang.shape[1]):
			for k in range(wts_ang.shape[2]):
				if (angs[i,j] < 150.0) and (angs[i,j] > 30.0): wts_ang[i,j,k]=1.0
	
	
	#create a weighting grid
	mask_reflect=12.0#dBZ	
	mask=(ber['CZ'][:,:,u:l]/mask_reflect).round().clip(min=0., max=1.0) 
	mask_vel_ber=(ber['VR'][:,:,u:l]+100.).clip(min=0., max=1.)
	#run gracon
	print 'Into fortran'
	nx,ny,nz=ber['CZ'][:,:,u:l].shape
	print nx,ny,nz
	f=0.0
	gv_u=zeros(ber['CZ'][:,:,u:l].shape, dtype=float)
	gv_v=zeros(ber['CZ'][:,:,u:l].shape, dtype=float)
	igu=ones(ber['CZ'][:,:,u:l].shape, dtype=float)
	igv=ones(ber['CZ'][:,:,u:l].shape, dtype=float)
	for i in range(len(ui)):
		igu[:,:,i]=igu[:,:,i]*ui[i]
		igv[:,:,i]=igu[:,:,i]*vi[i]
	
	
	wts=mask*mask_vel_ber*wts_ang
	#gv_u,gv_v,f,u_array,v_array = gracon_vel2d_3d(gv_u,gv_v,f,u_array,v_array,i_cmpt_r1,j_cmpt_r1,i_cmpt_r2,j_cmpt_r2,vr1,vr2,weights,nx=shape(gv_u,0),ny=shape(gv_u,1),nz=shape(gv_u,2))
	gv_u,gv_v,f,u_array,v_array = gracon_vel2d_3d.gracon_vel2d_3d( gv_u, gv_v, f, igu, igv, ber['i_comp'][:,:,u:l], ber['j_comp'][:,:,u:l], gp['i_comp'][:,:,u:l], gp['j_comp'][:,:,u:l], ber['VR'][:,:,u:l], gp['VR'][:,:,u:l], mywts)#, nx=nx, ny=ny, nz=nz)
	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)	
	f=figure()
	mapobj=pres.generate_darwin_plot(box=[130.8, 131.2, -12.4, -12.0])
	diff=gp['VR'][:,:,u:l]-(u_array*gp['i_comp'][:,:,u:l]+ v_array*gp['j_comp'][:,:,u:l])
	gp.update({'diff':diff})
	pres.reconstruction_plot(mapobj, lats, lons, gp, lvl, 'diff',u_array[:,:,lvl],v_array[:,:,lvl], angs, wts[:,:,lvl])
	#pres.quiver_contour_winds(mapobj, lats, lons, (wts*u_array).clip(min=-50, max=50),(wts*v_array).clip(min=-50, max=50))
	t1='Gunn Point CAPPI (dBZ) and reconstructed winds (m/s) at %(lev)05dm \n 22/01/06 ' %{'lev':gp['levs'][lvl]}
	title(t1+tim) 
	ff=os.getenv('HOME')+'/bom_mds/output/recons_22012006/real_%(lev)05d_' %{'lev':gp['levs'][lvl]}
	savefig(ff+tim+'_2d_3d.png')
	close(f)