from windspharm.cdms import VectorWind from windspharm.examples import example_data_path # Read zonal and meridional wind components from file using the cdms2 module # from CDAT. The components are in separate files. ncu = cdms2.open(example_data_path('uwnd_mean.nc'), 'r') uwnd = ncu('uwnd') ncu.close() ncv = cdms2.open(example_data_path('vwnd_mean.nc'), 'r') vwnd = ncv('vwnd') ncv.close() # Create a VectorWind instance to handle the computation of streamfunction and # velocity potential. w = VectorWind(uwnd, vwnd) # Compute the streamfunction and velocity potential. sf, vp = w.sfvp() # Pick out the field for December and add a cyclic point (the cyclic point is # for plotting purposes). sf_dec = sf(time=slice(11, 12), longitude=(0, 360), squeeze=True) vp_dec = vp(time=slice(11, 12), longitude=(0, 360), squeeze=True) # Plot streamfunction. m = Basemap(projection='cyl', resolution='c', llcrnrlon=0, llcrnrlat=-90, urcrnrlon=360.01,
mpl.rcParams['mathtext.default'] = 'regular' # Read zonal and meridional wind components from file using the cdms2 module # from CDAT. The components are in separate files. ncu = cdms2.open(example_data_path('uwnd_mean.nc'), 'r') uwnd = ncu('uwnd') ncu.close() ncv = cdms2.open(example_data_path('vwnd_mean.nc'), 'r') vwnd = ncv('vwnd') ncv.close() # Create a VectorWind instance to handle the computation of streamfunction and # velocity potential. w = VectorWind(uwnd, vwnd) # Compute the streamfunction and velocity potential. sf, vp = w.sfvp() # Pick out the field for December and add a cyclic point (the cyclic point is # for plotting purposes). sf_dec = sf(time=slice(11, 12), longitude=(0, 360), squeeze=True) vp_dec = vp(time=slice(11, 12), longitude=(0, 360), squeeze=True) # Plot streamfunction. ax1 = plt.axes(projection=ccrs.PlateCarree(central_longitude=180)) lons, lats = sf_dec.getLongitude()[:], sf_dec.getLatitude()[:] clevs = [-120, -100, -80, -60, -40, -20, 0, 20, 40, 60, 80, 100, 120] fill_sf = ax1.contourf(lons, lats, sf_dec.asma() * 1e-06, clevs, transform=ccrs.PlateCarree(), cmap=plt.cm.RdBu_r,
from windspharm.cdms import VectorWind # Read zonal and meridional wind components from file using the cdms2 module # from CDAT. The components are defined on pressure levels and are in separate # files. ncu = cdms2.open('../../example_data/uwnd_mean.nc', 'r') uwnd = ncu('uwnd') ncu.close() ncv = cdms2.open('../../example_data/vwnd_mean.nc', 'r') vwnd = ncv('vwnd') ncv.close() # Create a VectorWind instance to handle the computations. w = VectorWind(uwnd, vwnd) # Compute components of rossby wave source: absolute vorticity, divergence, # irrotational (divergent) wind components, gradients of absolute vorticity. eta = w.absolutevorticity() div = w.divergence() uchi, vchi = w.irrotationalcomponent() etax, etay = w.gradient(eta) # Combine the components to form the Rossby wave source term. S = -eta * div - uchi * etax + vchi * etay # Pick out the field for December at 200 hPa and add a cyclic point (the # cyclic point is for plotting purposes). S_200 = S(time=slice(11,12), level=200, longitude=(0,360), squeeze=True)
#----------------Read in global u,v---------------- abpath_in = '/home/guangzhi/datasets/erai/uv_p900_6_2007_Jan.nc' print('\n### <helmholtz>: Read in file:\n', abpath_in) fin = cdms.open(abpath_in, 'r') uall = fin('u', time=slice(0, 1)) vall = fin('v', time=slice(0, 1)) fin.close() uall = uall(squeeze=1) vall = vall(squeeze=1) print('uall.shape = ', uall.shape) print('vall.shape = ', vall.shape) # global wind harmonics wf = VectorWind(uall, vall) sf0, vp0 = wf.sfvp() #-----------------Get a region box----------------- ubox = uall(latitude=(5, 50), longitude=(100, 180)) vbox = vall(latitude=(5, 50), longitude=(100, 180)) sf0 = sf0(latitude=(5, 50), longitude=(100, 180)) vp0 = vp0(latitude=(5, 50), longitude=(100, 180)) # create an wind obj, optimization will use gradient descent w2 = Wind2D(ubox, vbox, 'optimize') sf2, vp2 = w2.getSFVP() uchi2, vchi2, upsi2, vpsi2 = w2.helmholtz() uhat2 = uchi2 + upsi2 vhat2 = vchi2 + vpsi2
import cdms2 from windspharm.cdms import VectorWind from windspharm.examples import example_data_path # Read zonal and meridional wind components from file using the cdms2 module # from CDAT. The components are in separate files. ncu = cdms2.open(example_data_path('uwnd_mean.nc'), 'r') uwnd = ncu('uwnd') ncu.close() ncv = cdms2.open(example_data_path('vwnd_mean.nc'), 'r') vwnd = ncv('vwnd') ncv.close() # Create a VectorWind instance to handle the computations. w = VectorWind(uwnd, vwnd) # Compute components of rossby wave source: absolute vorticity, divergence, # irrotational (divergent) wind components, gradients of absolute vorticity. eta = w.absolutevorticity() div = w.divergence() uchi, vchi = w.irrotationalcomponent() etax, etay = w.gradient(eta) # Combine the components to form the Rossby wave source term. S = -eta * div - (uchi * etax + vchi * etay) # Pick out the field for December and add a cyclic point (the cyclic point is # for plotting purposes). S_dec = S(time=slice(11, 12), longitude=(0, 360), squeeze=True)