avg   = netCDF4.Dataset(roms.rundir + roms.run_name + '_avg.nc')
lm, km, im, jm = avg.variables['temp'].shape


print "\n\n      Computing run average .... may take a while.......\n\n"

if zlev == 0:
    print "Computing average for AVG 1\n\n" 
    umean = avg.variables['u'][1800::10,-1,...].mean(axis=0)
    vmean = avg.variables['v'][1800::10,-1,...].mean(axis=0)

    umean = griddata(lonu.ravel(), latu.ravel(), umean.ravel(), lon, lat)
    vmean = griddata(lonv.ravel(), latv.ravel(), vmean.ravel(), lon, lat) 

else:
    zu = get_depths(avg, grd, 0, 'u')
    zv = get_depths(avg, grd, 0, 'v')
    u = np.zeros( (km, im, jm-1) )
    v = np.zeros( (km, im-1, jm) )
    umean  = np.zeros( (im, jm-1) )
    vmean  = np.zeros( (im-1, jm) )
    count = 0

    print "\nComputing average for AVG 1" 
    for l in np.arange(1800, lm, 10):
        print "    Day %s of %s" %(l, lm)
        count += 1
        u += avg.variables['u'][l,...]
        v += avg.variables['v'][l,...]

    u = u / count
Exemple #2
0
latv  = grdfile.variables['lat_v'][:]
lonu  = grdfile.variables['lon_u'][:]
lonv  = grdfile.variables['lon_v'][:]
h     = grdfile.variables['h'][:]

print ' \n' + '==> ' + '  READING CHOSEN ROMS OUTPUT NETCDF FILE ...\n' + ' '
outfile  = netCDF4.Dataset(roms.rundir + roms.run_name + '_' + filetype + '.nc')

TSbc = []; TSnbuc = []; TN = []; TE = [];

for l in days:
    U    = outfile.variables['u'][l,...]
    V    = outfile.variables['v'][l,...]
    print " DAY = " + str(l+1)
    #km, im, jm = T.shape
    zu   = get_depths(outfile,grdfile,l,'u')
    zv   = get_depths(outfile,grdfile,l,'v')

    f    = latv[:,0]    
    fsec = near(f,niN)
    xN   = lonv[0,:]
    zN   = np.squeeze( zv[:, fsec, :] )
    vN   = np.squeeze( V[: ,fsec , :] ) 
    
    fsec = near(f,niS)
    xS   = lonv[0,:]
    zS   = np.squeeze( zv[:, fsec, :] )
    vS   = np.squeeze( V[: ,fsec , :] ) 
 
    f = lonu[0, :]
    fsec = near(f,njE)
Exemple #3
0
print ' \n' + '==> ' + '  READING CHOSEN ROMS OUTPUT NETCDF FILE ...\n' + ' '
outfile = netCDF4.Dataset(roms.rundir + roms.run_name + '_' + filetype + '.nc')

# assigning some variables from ROMS output file
if PLOT == 4:
    ZETA = outfile.variables['zeta'][l, ...]
    UBAR = outfile.variables['ubar'][l, ...]
    VBAR = outfile.variables['vbar'][l, ...]
else:
    T = outfile.variables['temp'][l, ...]
    S = outfile.variables['salt'][l, ...]
    U = outfile.variables['u'][l, ...]
    V = outfile.variables['v'][l, ...]
    print ' \n' + '==> ' + '  GETTING DEPTHS OF S-LEVELS ...\n' + ' '
    km, im, jm = T.shape
    zt = get_depths(outfile, grdfile, l, 'temp')
    zu = get_depths(outfile, grdfile, l, 'u')
    zv = get_depths(outfile, grdfile, l, 'v')

if PLOT == 1 or PLOT == 4:

    # setting up map projection
    m = Basemap(projection='cyl',
                llcrnrlat=latplot[0],
                urcrnrlat=latplot[1],
                llcrnrlon=lonplot[0],
                urcrnrlon=lonplot[1],
                lat_ts=0,
                resolution='i')

    if PLOT == 1:
Exemple #4
0
zmax    = -1000         # treshold depth to compute volume transport
lonlim  = (-40, -36)    # 
latlim  = (-17, -14)    # NBUC's flow is going to be an average of these meridians

# OE2 data - from ROMS diag RUN ###################################################
# I'm doing time-average too (4 days)

oe2file = '/Users/rsoutelino/rsoutelino/myroms/leste2_run/leste2geo_avg.nc'
stabday = 4   # day in which mean KE stabilized
ncfile = nc.Dataset(oe2file)
grd   = nc.Dataset(oe2file[:-6] + 'grd.nc')
lon   = ncfile.variables['lon_v'][:]
lat   = ncfile.variables['lat_v'][:]
v     = ncfile.variables['v'][1:stabday,...];  v = v.mean(axis=0)
v     = np.ma.masked_where(v > 10, v)
z     = get_depths(ncfile, grd, stabday-1, 'v')
k, i, j = v.shape

# slicing sections and computing transports

i1, i2, j1, j2 = slice(lon, lat, lonlim, latlim)
v   = np.squeeze(   v[:, j1:j2, i1:i2] ); v = v.mean(axis=1)
lon = np.squeeze(    lon[j1:j2, i1:i2] ); lon = lon.mean(axis=0)
z   = np.squeeze(   z[:, j1:j2, i1:i2] ); z = z.mean(axis=1)
lon.shape = ( 1, np.size(lon) )
lon = lon.repeat(k, axis=0)
v  = np.ma.masked_where(z < zmax, v)

Tv = transp(lon, z, v)

if Tv > 0:
Exemple #5
0
    print "Computing average for AVG 2\n\n"
    umean2 = avg2.variables['u'][::10, -1, ...].mean(axis=0)
    vmean2 = avg2.variables['v'][::10, -1, ...].mean(axis=0)

    print "Computing average for AVG 3\n\n"
    umean3 = avg3.variables['u'][::10, -1, ...].mean(axis=0)
    vmean3 = avg3.variables['v'][::10, -1, ...].mean(axis=0)

    umean = (umean1 + umean2 + umean3) / 3
    vmean = (vmean1 + vmean2 + vmean3) / 3

    umean = griddata(lonu.ravel(), latu.ravel(), umean.ravel(), lon, lat)
    vmean = griddata(lonv.ravel(), latv.ravel(), vmean.ravel(), lon, lat)

else:
    zu = get_depths(avg1, grd, 0, 'u')
    zv = get_depths(avg1, grd, 0, 'v')
    umean1 = np.zeros((km, im, jm - 1))
    vmean1 = np.zeros((km, im - 1, jm))
    umean2 = np.zeros((km, im, jm - 1))
    vmean2 = np.zeros((km, im - 1, jm))
    umean3 = np.zeros((km, im, jm - 1))
    vmean3 = np.zeros((km, im - 1, jm))
    umean = np.zeros((im, jm - 1))
    vmean = np.zeros((im - 1, jm))
    count = 0

    print "\nComputing average for AVG 1"
    for l in np.arange(1800, lm1, 10):
        print "    Day %s of %s" % (l, lm1)
        count += 1
Exemple #6
0
print ' \n' + '==> ' + '  COMPUTING TIME-AVERAGE ...\n' + ' '
T=0; U=0; V=0; W=0;
for l in days: 
    T    = T + outfile.variables['temp'][l,...]
    U    = U + outfile.variables['u'][l,...]
    V    = V + outfile.variables['v'][l,...]
    #W    = W + outfile.variables['w'][l,:-1,...]

T = T / len(days); U = U / len(days); V = V / len(days); 
W = W / len(days);

km, im, jm = T.shape

print ' \n' + '==> ' + '  GETTING DEPTHS OF S-LEVELS ...\n' + ' '
zt   = get_depths(outfile,grdfile,0,'temp')
zu   = get_depths(outfile,grdfile,0,'u')
zv   = get_depths(outfile,grdfile,0,'v')

# horizontal ==========================================

print ' \n' + '==> ' + '  INTERPOLATING FROM S --> Z ...\n' + ' '
u = 0*lonu; v = 0*lonv; t = 0*lon; s = 0*lon; w = 0*lon

for a in range (0, im):
    for b in range(0, jm):
        t[a,b] = np.interp(-nk, zt[:, a, b], T[:, a, b] )
        #s[a,b] = np.interp(-nk, zt[:, a, b], S[:, a, b] )
        #w[a,b] = np.interp(-nk, zt[:, a, b], W[:, a, b] )

for a in range (0, im):
Exemple #7
0
lonlim = (-40, -36)  #
latlim = (-17, -14)  # NBUC's flow is going to be an average of these meridians

# OE2 data - from ROMS diag RUN ###################################################
# I'm doing time-average too (4 days)

oe2file = '/Users/rsoutelino/rsoutelino/myroms/leste2_run/leste2geo_avg.nc'
stabday = 4  # day in which mean KE stabilized
ncfile = nc.Dataset(oe2file)
grd = nc.Dataset(oe2file[:-6] + 'grd.nc')
lon = ncfile.variables['lon_v'][:]
lat = ncfile.variables['lat_v'][:]
v = ncfile.variables['v'][1:stabday, ...]
v = v.mean(axis=0)
v = np.ma.masked_where(v > 10, v)
z = get_depths(ncfile, grd, stabday - 1, 'v')
k, i, j = v.shape

# slicing sections and computing transports

i1, i2, j1, j2 = slice(lon, lat, lonlim, latlim)
v = np.squeeze(v[:, j1:j2, i1:i2])
v = v.mean(axis=1)
lon = np.squeeze(lon[j1:j2, i1:i2])
lon = lon.mean(axis=0)
z = np.squeeze(z[:, j1:j2, i1:i2])
z = z.mean(axis=1)
lon.shape = (1, np.size(lon))
lon = lon.repeat(k, axis=0)
v = np.ma.masked_where(z < zmax, v)
lonu  = oe2nc.variables['lon_u'][:]
latu  = oe2nc.variables['lat_u'][:]
lonv  = oe2nc.variables['lon_v'][:]
latv  = oe2nc.variables['lat_v'][:]

u   = oe2nc.variables['u'][stabday-1,]
v   = oe2nc.variables['v'][stabday-1,...]

# masking the arrays
u = np.ma.masked_where(u > 10, u)
v = np.ma.masked_where(v > 10, v)

ku, iu, ju = u.shape
kv, iv, jv = v.shape

zu   = get_depths(oe2nc, grd, stabday-1, 'u')
zv   = get_depths(oe2nc, grd, stabday-1, 'v')

# SLICING THE SECTIONS and COMPUTING TRANSPORTS

# South boundary
vS   = np.squeeze(   v[:, 2, :] )
lonS = np.squeeze(   lonv[2, :] )
zS   = np.squeeze(  zv[:, 2, :] )
lonS.shape = ( 1, np.size(lonS) )
lonS = lonS.repeat(ku, axis=0)
vSt  = np.ma.masked_where(zS < zmax, vS)

dx = np.diff(lonS, axis=1) * 111 * 1000
aux  = dx[:,0]; aux.shape = (np.size(aux), 1)
dx = np.concatenate( (dx, aux), axis=1) 
Exemple #9
0
lonu = grd.variables['lon_u'][:]
lonv = grd.variables['lon_v'][:]
h = grd.variables['h'][:]

print ' \n' + '==> ' + '  READING CHOSEN ROMS OUTPUT NETCDF FILE ...\n' + ' '
avg = netCDF4.Dataset(roms.rundir + roms.run_name + '_avg.nc')

lm, km, im, jm = avg.variables['temp'].shape

tmp = avg.variables['temp'][0, 0, ...]

lon, lat, tmp = subset(lonr, latr, tmp, lims[0], lims[1], lims[2], lims[3])

# AVG  ===============================================================

zu = get_depths(avg, grd, 0, 'u')
zv = get_depths(avg, grd, 0, 'v')
zt = get_depths(avg, grd, 0, 't')

times = np.arange(1800, lm, 10)
U = np.zeros((times.size, lon.shape[0], lon.shape[1]), dtype=np.float64)
V = np.zeros((times.size, lon.shape[0], lon.shape[1]), dtype=np.float64)
T = np.zeros((times.size, lon.shape[0], lon.shape[1]), dtype=np.float64)

print "\n\n      Slicing %s eddy, at %s m, in AVG.... may take a while.......\n\n" % (
    eddy, zlev)

if zlev == 0:
    count = 0
    for l in times:
        print "AVG - step %s of %s, at %s m" % (l, times[-1], zlev)
Exemple #10
0
lonu = oe2nc.variables['lon_u'][:]
latu = oe2nc.variables['lat_u'][:]
lonv = oe2nc.variables['lon_v'][:]
latv = oe2nc.variables['lat_v'][:]

u = oe2nc.variables['u'][stabday - 1, ]
v = oe2nc.variables['v'][stabday - 1, ...]

# masking the arrays
u = np.ma.masked_where(u > 10, u)
v = np.ma.masked_where(v > 10, v)

ku, iu, ju = u.shape
kv, iv, jv = v.shape

zu = get_depths(oe2nc, grd, stabday - 1, 'u')
zv = get_depths(oe2nc, grd, stabday - 1, 'v')

# SLICING THE SECTIONS and COMPUTING TRANSPORTS

# South boundary
vS = np.squeeze(v[:, 2, :])
lonS = np.squeeze(lonv[2, :])
zS = np.squeeze(zv[:, 2, :])
lonS.shape = (1, np.size(lonS))
lonS = lonS.repeat(ku, axis=0)
vSt = np.ma.masked_where(zS < zmax, vS)

dx = np.diff(lonS, axis=1) * 111 * 1000
aux = dx[:, 0]
aux.shape = (np.size(aux), 1)
Exemple #11
0
avg3   = netCDF4.Dataset(roms.rundir + roms.run_name + '_avg-3.nc')

lm1, km, im, jm = avg1.variables['temp'].shape
lm2, km, im, jm = avg2.variables['temp'].shape
lm3, km, im, jm = avg3.variables['temp'].shape



tmp = avg1.variables['temp'][0,0,...]

lon, lat, tmp = subset(lonr, latr, tmp, lims[0], lims[1], lims[2], lims[3])


# AVG1 output ===============================================================

zu = get_depths(avg1, grd, 0, 'u')
zv = get_depths(avg1, grd, 0, 'v')
zt = get_depths(avg1, grd, 0, 't')

times = np.arange(1800, lm1, 10)
U1 = np.zeros((times.size, lon.shape[0], lon.shape[1]), dtype=np.float64)
V1 = np.zeros((times.size, lon.shape[0], lon.shape[1]), dtype=np.float64)
T1 = np.zeros((times.size, lon.shape[0], lon.shape[1]), dtype=np.float64)


print "\n\n      Slicing %s eddy, at %s m, in AVG-1.... may take a while.......\n\n" %(eddy, zlev)

if zlev == 0:
    count = 0
    for l in times:
        print "AVG-1 - step %s of %s, at %s m" %(l, times[-1], zlev)
Exemple #12
0
print ' \n' + '==> ' + '  COMPUTING TIME-AVERAGE ...\n' + ' '
T=0; S=0; U=0; V=0; W=0;
for l in days:
    T    = T + outfile.variables['temp'][l,...]
    S    = S + outfile.variables['salt'][l,...]
    U    = U + outfile.variables['u'][l,...]
    V    = V + outfile.variables['v'][l,...]

T = T / len(days); S = S / len(days); 
U = U / len(days); V = V / len(days); 

km, im, jm = T.shape

print ' \n' + '==> ' + '  GETTING DEPTHS OF S-LEVELS ...\n' + ' '
zt   = get_depths(outfile,grdfile,days[0],'temp')
zu   = get_depths(outfile,grdfile,days[0],'u')
zv   = get_depths(outfile,grdfile,days[0],'v')


# vertical ==============================================

f    = latv[:,0]    
fsec = near(f,niN)
xN   = lonv[0,:]
zN   = np.squeeze( zv[:, fsec, :] )
vN   = np.squeeze( V[: ,fsec , :] ) 
tN   = np.squeeze( T[: ,fsec , :] )
sN   = np.squeeze( S[: ,fsec , :] )
ztN  = np.squeeze( zt[: ,fsec , :] )