def plot_precip(): print(" PRECIP") # Set Figure Size (1000 x 800) plt.figure(figsize=(width,height),frameon=False) rainc = nc.variables['RAINC'] rainnc = nc.variables['RAINNC'] # First, find out if this is first time or not # Based on skip. This should be total from each output time if time == 0: prev_total = rainc[time] + rainnc[time] else: prev_total = rainc[time-1] + rainnc[time-1] total_accum = rainc[time] + rainnc[time] precip_tend = total_accum - prev_total # Convert from mm to in precip_tend = precip_tend * .0393700787 units = 'in' PCP_LEVELS = [0.01,0.03,0.05,0.10,0.15,0.20,0.25,0.30,0.40,0.50,0.60,0.70,0.80,0.90,1.00,1.25,1.50,1.75,2.00,2.50] PRECIP=plt.contourf(x,y,precip_tend,PCP_LEVELS,cmap=coltbls.precip1()) #plt.jet() title = '%s Hour Precip' % skip prodid = 'precip' drawmap(PRECIP, title, prodid, units)
def plot_precip(): print(" PRECIP") # Set Figure Size (1000 x 800) pylab.figure(figsize=(width,height),frameon=False) rainc = nc.variables['RAINC'] rainnc = nc.variables['RAINNC'] # First, find out if this is first time or not if time == 0: prev_total = rainc[time] + rainnc[time] else: prev_total = rainc[time-1] + rainnc[time-1] total_accum = rainc[time] + rainnc[time] precip_tend = total_accum - prev_total # Convert from mm to in precip_tend = precip_tend * .0393700787 units = 'in' PCP_LEVELS = [0.01,0.03,0.05,0.10,0.15,0.20,0.25,0.30,0.40,0.50,0.60,0.70,0.80,0.90,1.00,1.25,1.50,1.75,2.00,2.50] PRECIP=pylab.contourf(x,y,precip_tend,PCP_LEVELS,cmap=coltbls.precip1()) #pylab.jet() title = '%s Hour Precip' % skip prodid = 'precip' drawmap(PRECIP, title, prodid, units)
def plot_pwat(): print(" PRECIP. WATER") # Set Figure Size (1000 x 800) plt.figure(figsize=(width, height), frameon=False) g = 9.81 P = nc.variables['P'] PB = nc.variables['PB'] Qv = nc.variables['QVAPOR'] # First we need an array of pressures Pr = P[time] + PB[time] print "SHAPE Pr: ", np.shape(Pr) Qvap = Qv[time, :, :, :] print "SHAPE Qvap: ", np.shape(Qvap) # Now go through each point for j in range(len(Pr[0])): currow_pwat = [] for i in range(len(Pr[0, 0])): curcol_pwat = [] for k in range(len(Pr) - 1): curdp = (Pr[k, j, i] - Pr[k + 1, j, i]) * 0.01 curpwat = curdp * Qvap[k, j, i] curcol_pwat.append(curpwat) np_curcol_pwat = np.array(curcol_pwat) point_pwat = np.sum(curcol_pwat) currow_pwat.append(point_pwat) np_currow_pwat = np.array(currow_pwat) if j == 0: total_pwat = np_currow_pwat else: total_pwat = np.row_stack((np_currow_pwat, total_pwat)) pwat = np.divide(total_pwat, g) print "Len j: ", len(Pr) print "Len i: ", len(Pr[0]) print "SHAPE: ", np.shape(pwat) print "MAX: ", np.max(pwat) PCP_LEVELS = [ 0.01, 0.03, 0.05, 0.10, 0.15, 0.20, 0.25, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90, 1.00, 1.25, 1.50, 1.75, 2.00, 2.50 ] PWAT_LEVS = [ 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.1, 2.3, 2.4, 2.5 ] PWAT = plt.contourf(x, y, pwat, PCP_LEVELS, cmap=coltbls.precip1()) units = 'mm' title = 'Precipitable Water (in)' prodid = 'pwat' drawmap(PWAT, title, prodid, units)
def plot_pwat(): print(" PRECIP. WATER") # Set Figure Size (1000 x 800) plt.figure(figsize=(width,height),frameon=False) g = 9.81 P = nc.variables['P'] PB = nc.variables['PB'] Qv = nc.variables['QVAPOR'] # First we need an array of pressures Pr = P[time] + PB[time] print "SHAPE Pr: ", np.shape(Pr) Qvap = Qv[time,:,:,:] print "SHAPE Qvap: ", np.shape(Qvap) # Now go through each point for j in range(len(Pr[0])): currow_pwat = [] for i in range(len(Pr[0,0])): curcol_pwat = [] for k in range(len(Pr)-1): curdp = (Pr[k,j,i] - Pr[k+1,j,i]) * 0.01 curpwat = curdp * Qvap[k,j,i] curcol_pwat.append(curpwat) np_curcol_pwat = np.array(curcol_pwat) point_pwat = np.sum(curcol_pwat) currow_pwat.append(point_pwat) np_currow_pwat = np.array(currow_pwat) if j == 0: total_pwat = np_currow_pwat else: total_pwat = np.row_stack((np_currow_pwat, total_pwat)) pwat = np.divide(total_pwat,g) print "Len j: ", len(Pr) print "Len i: ", len(Pr[0]) print "SHAPE: ", np.shape(pwat) print "MAX: ", np.max(pwat) PCP_LEVELS = [0.01,0.03,0.05,0.10,0.15,0.20,0.25,0.30,0.40,0.50,0.60,0.70,0.80,0.90,1.00,1.25,1.50,1.75,2.00,2.50] PWAT_LEVS = [0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.1,2.3,2.4,2.5] PWAT=plt.contourf(x,y,pwat,PCP_LEVELS,cmap=coltbls.precip1()) units = 'mm' title = 'Precipitable Water (in)' prodid = 'pwat' drawmap(PWAT, title, prodid, units)
def plot_precip(self,imagename='precip.png', title='',timestep=0): """plot accumulated precipitation Optional input: -------- imagename = 'your file name.png', defaults to vapor.png' title = 'your title' defaults to none timestep = integer. If there are multiple time periods per file then choose your timestep, defaults to 0' Returns: -------- contour plot of accumulated precipitaiton """ pl.figure(6) pl.clf() try: rainnc_full=self.variable_dict['RAINNC'] except ValueError: print 'you do not have any non-convective rain data' rainnc_full = None except KeyError: rainnc_full=self.get_var('RAINNC') try: rainc_full=self.variable_dict['RAINC'] except KeyError: rainc_full=self.get_var('RAINC') except ValueError: print 'you do not have any convective rain data' rainc_full = None times=self.get_var('Times') if (timestep == 0): start_time =0 end_time = len(times) else: start_time=timestep end_time=timestep+1 try: m=self.map_proj x=self.map_x y=self.map_y except: self.bmap() m=self.map_proj x=self.map_x y=self.map_y for the_time in range(start_time,end_time): time=times[the_time] pl.clf() if (rainnc_full == None) & (rainc_full == None): print 'you have no precipitation data at all, quitting' return None if (rainnc_full == None) & (rainc_full != None): rain_total = rainc_full[the_time,:,:] if (rainc_full == None) & (rainnc_full != None): rain_total = rainnc_full[the_time,:,:] if (rainc_full != None) & (rainnc_full != None): rain_total=rainnc_full[the_time,:,:] + rainc_full[the_time,:,:] custom_map=pl.get_cmap('jet',lut=22) PCP_LEVELS = [0.01,0.03,0.05,0.10,0.15,0.20,0.25,0.30,0.40,0.50,0.60,0.70,0.80,0.90,1.00,1.25,1.50,1.75,2.00,2.50] max_precip = n.max(rain_total) scaling_factor = n.ceil(max_precip/PCP_LEVELS[-1]) if scaling_factor > 0.0: for cont in range(len(PCP_LEVELS)): PCP_LEVELS[cont]=PCP_LEVELS[cont]*scaling_factor m.contourf(x,y,rain_total[:,:],PCP_LEVELS,cmap = coltbls.precip1()) self.map_lines() pl.colorbar(orientation='horizontal') pl.title(title) pl.savefig(self.plot_directory+'/'+imagename)