def plot_T2(loc,timetuple,lats,lons,dom): fig = plt.figure() for i,ens in enumerate(ensnames): # Load data from nc file time = convert_time(dom,timetuple) x,y,exactlat,exactlon = gridded_data.getXY(lats,lons,loc[0],loc[1]) ncpath = ncdir+ens+'/'+ncfname nc = Dataset(ncpath,'r') ens_T2 = nc.variables['T2'][time,y,x] - 273.15 plt.bar(i,ens_T2) # if obs == 1: # # Include observed shear # D = load_sounding_data(obspath) # obs_T2 = D['thta'][0] # plt.bar(len(ensnames),obs_T2,color='black') # xlabelnames = ensnames + ['OBS'] # xticklocs = [0.5+n for n in range(len(ensnames)+1)] # else: xlabelnames = ensnames xticklocs = [0.5+n for n in range(len(ensnames))] fname = '_'.join(('T2',nicetime)) plt.gca().autoscale(enable=True,axis='y',tight=True) plt.xticks(xticklocs,xlabelnames) plt.ylabel('2m potential temperature (C)') fig.savefig(outdir+fname, bbox_inches='tight', pad_inches=0.5) fig.clf()
def return_shear(lev1,lev2,ncpath,ens,loc,timetuple,lats,lons,dom): nc = Dataset(ncpath,'r') time = convert_time(dom,timetuple) x,y,exactlat,exactlon = gridded_data.getXY(lats,lons,loc[0],loc[1]) u = nc.variables['U'][time,:,y,x][:] v = nc.variables['V'][time,:,y,x][:] #wind = N.sqrt(u**2 + v**2) geopot = nc.variables['PH'][time,:,y,x][:] + nc.variables['PHB'][time,:,y,x][:] Z = geopot/9.81 zAGL = Z - nc.variables['HGT'][time,y,x] # Height AGL # Compute the height, AGL, of the u/v surfaces zAGL_wind = N.array([(z0+z1)/2.0 for z0,z1 in zip(zAGL[:-1],zAGL[1:])]) # Find wind at lev2 via interpolation lev2 *= 1000 # get into metres u2 = N.interp(lev2,zAGL_wind,u) v2 = N.interp(lev2,zAGL_wind,v) if lev1 == 0: u1 = nc.variables['U10'][time,y,x] v1 = nc.variables['V10'][time,y,x] else: # Find wind at lev1 via interpolation pass shear = N.sqrt((u2-u1)**2 + (v2-v1)**2) return shear
def plot_Q2(loc,timetuple,lats,lons,dom): fig = plt.figure() for i,ens in enumerate(ensnames): # Load data from nc file time = convert_time(dom,timetuple) x,y,exactlat,exactlon = gridded_data.getXY(lats,lons,loc[0],loc[1]) ncpath = ncdir+ens+'/'+ncfname nc = Dataset(ncpath,'r') ens_Q2 = nc.variables['Q2'][time,y,x]*1000 plt.bar(i,ens_Q2) if obs == 1: # Include observed shear D = load_sounding_data(obspath) obs_Q2 = D['mixr'][0] plt.bar(len(ensnames),obs_Q2,color='black') xlabelnames = ensnames + ['OBS'] xticklocs = [0.5+n for n in range(len(ensnames)+1)] else: xlabelnames = ensnames xticklocs = [0.5+n for n in range(len(ensnames))] fname = '_'.join(('Q2',nicetime)) plt.xticks(xticklocs,xlabelnames) plt.ylabel('Mixing ratio at surface (g kg$^{-1}$)') fig.savefig(outdir+fname, bbox_inches='tight', pad_inches=0.5) fig.clf()
def skewTPlot(nest, timetuple): """ This is the method to use from the outside nest: The nesting level of the nc-file from WRF time: The time for which to plot """ nc = openWRF(nest) time = convert_time(nest, timetuple) _Nx, _Ny, _Nz, _longs, _lats, _dx, _dy, x, y = getDimensions(nc) plt.figure() _isotherms() _isobars() _dry_adiabats() _moist_adiabats() P = nc.variables["P"][time, :, y, x] + nc.variables["PB"][time, :, y, x] _windbarbs(nc, time, y, x, P) _temperature(nc, time, y, x, P) _dewpoint(nc, time, y, x, P) plt.axis([-40, 50, P_b, P_t]) plt.xlabel("Temperature ($^{\circ}\! C$) at 1000hPa") xticks = np.arange(-40, 51, 5) plt.xticks(xticks, ["" if tick % 10 != 0 else str(tick) for tick in xticks]) plt.ylabel("Pressure (hPa)") yticks = np.arange(P_bot, P_t - 1, -10 ** 4) plt.yticks(yticks, yticks / 100) sfcT = nc.variables["T2"][time, y, x] - T_zero sfcP = nc.variables["PSFC"][time, y, x] sfcW = nc.variables["Q2"][time, y, x] sfcTd = td(e(sfcW, sfcP)) plt.suptitle( "Drybulb: %4.1f$^{\circ}\! C$ Dewpoint: %3.1f$^{\circ}\! C$ Pressure: %5.1f hPa" % (sfcT, sfcTd, 0.01 * sfcP), fontsize=10, x=0.5, y=0.03, ) # plt.show() plt.savefig(outdir + naming + str(nest) + "_skewT.png") plt.title("Skew-T plot for (location)") plt.close()
def gettime(): t = convert_time(dom, timetuple) return t