Exemplo n.º 1
0
# 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,
                       extend='both')
ax1.coastlines()
ax1.gridlines()
Exemplo n.º 2
0
# 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,
            urcrnrlat=90)
lons, lats = sf_dec.getLongitude()[:], sf_dec.getLatitude()[:]
x, y = m(*np.meshgrid(lons, lats))
Exemplo n.º 3
0
    #----------------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

    #-------------------Plot------------------------