示例#1
0
from vacumm.misc.grid.regridding import extend1d, extend2d

# Input data
nxi = 4
nyi = 3
xxi, yyi = N.meshgrid(N.arange(nxi) + .25, N.arange(nyi) - .25)
for j in xrange(nyi):
    xxi[j, :] -= j * 0.5
for i in xrange(nxi):
    yyi[:, i] += i * 0.5
gridi = create_grid2d(xxi, yyi)  # input cdms grid
vari = MV2.array(N.arange(nyi * nxi).reshape(nyi, nxi)) + 10.
set_grid(vari, gridi)  # set grid and axes

# Extend and plot
rc('font', size=9)
P.figure(figsize=(6, 6))
kw = dict(xmin=xxi.min() - 3,
          xmax=xxi.max() + 3,
          ymin=yyi.min() - 3,
          ymax=yyi.max() + 3,
          show=False,
          xhide='auto',
          yhide='auto')
# - original
plot2d(vari, title='Original', subplot=(2, 2, 1), **kw)
# - extend1d
for i, (axis, ext, mode) in enumerate([(-1, (2, 2), 'same'),
                                       (-2, 2, 'linear')]):
    varo = extend1d(vari, ext=ext, axis=axis, mode=mode)
    plot2d(varo,
示例#2
0
# Imports
from vcmq import DS, data_sample, mixed_layer_depth, rc, map2, os, code_file_name

# Read data
ds = DS(data_sample(ncfile),'mars', logger_level='critical')
temp = ds.get_temp(squeeze=True)
sal = ds.get_sal(squeeze=True)
depth = ds.get_depth(squeeze=True)
kz = ds.get_kz(squeeze=True)

# Compute MLD
kw = dict(depth=depth, format_axes=True)
mld = {}
mld['deltatemp'] = mixed_layer_depth(temp, mode='deltatemp',**kw)
mld['deltadens'] = mixed_layer_depth((temp,sal), mode='deltadens', **kw)
mld['kz'] = mixed_layer_depth(kz, mode='kz', **kw)
vmin = min([v.min() for v in mld.values()])
vmax = max([v.max() for v in mld.values()])

# Plot it
rc('font', size=8)
for i,(mode, var) in enumerate(mld.items()):
    m = map2(var, fill='pcolormesh', nmax=20, vmin=vmin, vmax=vmax,
        subplot=(len(mld),1,i+1), figsize=(4.1,8),
        contour_linewidths=0.7, cmap='vacumm_rnb2_hymex', hspace=0.25, bottom=0.08,
        title='%%(long_name)s: mode = "%s"'%mode, show=False)
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
m.savefig(figfile)

示例#3
0
nxo = 25
nyo = 18
# - rect
dxi = xi[-1]-xi[0]
dyi = yi[-1]-yi[0]
xro = N.linspace(xi[0]+dxi*0.2, xi[-1]+dxi*0.2, nxo)
yro = N.linspace(yi[0]-dyi*0.2, yi[-1]-dyi*0.2, nyo)
gridro = create_grid(xro, yro)
# - curv
xco = N.linspace(xi[0], xi[-1], nxo)
yco = N.linspace(yi[0], yi[-1], nyo)
gridco = rotate_grid((xco, yco), -20)

# Interpolate and Plot
# - original
rc('font', size=8)
rc('axes', labelsize=7)
kw = dict(show=False, axes_aspect=1, colorbar=False, grid=False)
kwg = dict(edges=False, centers=True, markersize=2, alpha=1)
ip = 1
plot2d(varri, title='Original rectangular', figure=10,
    figsize=(7, 7), subplot=(4,3,ip), **kw);ip+=1
plot2d(varci, title='Original curvilinear', subplot=(4,3,ip), **kw);ip+=1
# - nearest
varo = regrid2d(varci, gridco, method='nearest', tool='vacumm')
plot2d(varo, title='VACUMM / Nearest', subplot=(4,3,ip), **kw);ip+=1
add_grid(gridci, **kwg)
# - bilin r2r / vacumm
varo = regrid2d(varri, gridro, method='bilinear', tool='vacumm')
plot2d(varo, title='VACUMM / Bilinear', subplot=(4,3,ip), **kw);ip+=1
add_grid(gridri, **kwg)
示例#4
0
nxo = 25
nyo = 18
# - rect
dxi = xi[-1]-xi[0]
dyi = yi[-1]-yi[0]
xro = N.linspace(xi[0]+dxi*0.2, xi[-1]+dxi*0.2, nxo)
yro = N.linspace(yi[0]-dyi*0.2, yi[-1]-dyi*0.2, nyo)
gridro = create_grid(xro, yro)
# - curv
xco = N.linspace(xi[0], xi[-1], nxo)
yco = N.linspace(yi[0], yi[-1], nyo)
gridco = rotate_grid((xco, yco), -20)

# Interpolate and Plot
# - original
rc('font', size=6)
rc('axes', labelsize=7)
kw = dict(show=False, axes_aspect=1, colorbar=False, grid=False, linewidth=.3,
          cmap='viridis')
kwg = dict(edges=False, centers=True, markersize=2, alpha=1)
ip = 1
plot2d(varri[0], title='Original rectangular', figure=10,
    figsize=(7, 7), subplot=(4,3,ip), **kw);ip+=1
plot2d(varci[0], title='Original curvilinear', subplot=(4,3,ip), **kw);ip+=1
# - nearest
varo = regrid2d(varci, gridco, method='nearest', tool='vacumm')
plot2d(varo[0], title='VACUMM / Nearest', subplot=(4,3,ip), **kw);ip+=1
add_grid(gridci, **kwg)
# - bilin r2r / vacumm
varo = regrid2d(varri, gridro, method='bilinear', tool='vacumm')
plot2d(varo[0], title='VACUMM / Bilinear', subplot=(4,3,ip), **kw);ip+=1
示例#5
0
nxo = 25
nyo = 18
# - rect
dxi = xi[-1] - xi[0]
dyi = yi[-1] - yi[0]
xro = N.linspace(xi[0] + dxi * 0.2, xi[-1] + dxi * 0.2, nxo)
yro = N.linspace(yi[0] - dyi * 0.2, yi[-1] - dyi * 0.2, nyo)
gridro = create_grid(xro, yro)
# - curv
xco = N.linspace(xi[0], xi[-1], nxo)
yco = N.linspace(yi[0], yi[-1], nyo)
gridco = rotate_grid((xco, yco), -20)

# Interpolate and Plot
# - original
rc("font", size=8)
rc("axes", labelsize=7)
kw = dict(show=False, axes_aspect=1, colorbar=False, grid=False, linewidth=0.3)
kwg = dict(edges=False, centers=True, markersize=2, alpha=1)
ip = 1
plot2d(varri, title="Original rectangular", figure=10, figsize=(7, 7), subplot=(4, 3, ip), **kw)
ip += 1
plot2d(varci, title="Original curvilinear", subplot=(4, 3, ip), **kw)
ip += 1
# - nearest
varo = regrid2d(varci, gridco, method="nearest", tool="vacumm")
plot2d(varo, title="VACUMM / Nearest", subplot=(4, 3, ip), **kw)
ip += 1
add_grid(gridci, **kwg)
# - bilin r2r / vacumm
varo = regrid2d(varri, gridro, method="bilinear", tool="vacumm")
grido, xxbo, yybo = gridi, xxbi, yybi

# Regrid
diag = {'dstAreaFractions':None}
varo = vari.regrid(grido, tool='esmf', method='conservative', 
    diag=diag, coordSys='cart')
    
# Norm
frac = diag['dstAreaFractions']
mask = frac==0.
frac[mask]=1.
varo[:] /= frac
varo[:] = MV2.masked_where(mask, varo, copy=0)

# Plot
rc('font', size=9)
kw = dict(vmin=vari.min(), vmax=vari.max())
axis = [xxbi.min(), xxbi.max(), yybo.min(), yybo.max()]
P.figure(figsize=(7, 3))
P.subplot(121, aspect=1)
P.pcolormesh(xxbi, yybi, vari, **kw)
P.colorbar(shrink=0.7)
add_grid(gridi, color='0.5')
add_grid(grido)
P.axis(axis)
P.title('Original: max=%g min=%g'%(vari.max(), vari.min()))
P.subplot(122, aspect=1)
P.pcolormesh(xxbo, yybo, varo, **kw)
P.colorbar(shrink=0.7)
add_grid(gridi)
add_grid(grido, color='0.5')