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)
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)
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)