cradarfile ='CPOL20060101_040009.00000_all_calb_2kmres.cdf'
radarc = Dataset(cradarfile)
print radarc.variables.keys()
dzc = radarc.variables['DZ']
drc = radarc.variables['DR']
kdc = radarc.variables['KD']
rhc = radarc.variables['RH']
radar_z= np.arange(np.array(np.shape(radarc.variables['z'])))*radarc.zdelta+radarc.zfirst
radar_x= np.arange(np.array(np.shape(radarc.variables['x'])))*radarc.xdelta+radarc.xfirst
radar_y= np.arange(np.array(np.shape(radarc.variables['y'])))*radarc.ydelta+radarc.yfirst
#### Set up some colorbar stuff
lowdbz = 0.
highdbz = 68.
deldbz = 4.
rangedbz = highdbz-lowdbz
levels_dbz = range(0,68,4) # dbz contour levels
fig, ax = plt.subplots(1,1,figsize=(16,16))
#Plot the 'background' reflectivity with a transparancy of 0.4
dbz_hand=plt.contourf(radar_x,radar_y,dzc[2,:,:],levels_dbz,interpolation='none', cmap='RdYlBu_r',alpha=0.4)
#Define the locations of the two radars in the gridded coodrinate system
rad1=[0.0,0.0]
rad2=[-13.47,-27.99]
#Select a beam-crossling angle
beamang=30
rad1x,rad1y,rad2x,rad2y,midpoint,radius=dualdopp(rad1,rad2,beamang)
#Over plot the outline of the dual-doppler rings and the locations of the radars
plt.plot(rad1x,rad1y,color='r')
plt.plot(rad2x,rad2y,color='r')
plt.plot(rad1[0],rad1[1],marker='o',color='k')
plt.plot(rad2[0],rad2[1],marker='o',color='k')
#Find the indices of the location of the dual-Doppler lobes in our x, y from the dual-Doppler output
myx1=np.argmin(np.abs(radar_x-midpoint[0][0]))
myy1=np.argmin(np.abs(radar_y-midpoint[0][1]))
myx2=np.argmin(np.abs(radar_x-midpoint[1][0]))
myy2=np.argmin(np.abs(radar_y-midpoint[1][1]))
center_x=[myx1,myx2]
center_y=[myy1,myy2]
#Now mask out everything outside of the lobes
mynewdata=mask_dualdop(dzc[2,:,:],center_x,center_y,radius/2.)
#Over plot the masked data in 'full' opacity
plt.contourf(radar_x,radar_y,mynewdata,levels_dbz,interpolation='none',cmap='RdYlBu_r')
#Add some lables
plt.xlabel('E-W Distance (km)')
plt.ylabel('N-S Distance (km)')
plt.title('CPOL 20060101 0400 UTC dual-Doppler lobes beamcrossing: {:2.1f}'.format(beamang))
plt.savefig('CPOL_dualDop_gridplot_{}.png'.format(beamang),dpi=200)