예제 #1
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)
# - bilin c2c / vacumm
varo = regrid2d(varci, gridco, method='bilinear', tool='vacumm')
plot2d(varo, title='VACUMM / Bilinear', subplot=(4,3,ip), **kw);ip+=1
add_grid(gridci, **kwg)
# - bilin c2c / emsf
varo = regrid2d(varci, gridco, method='bilinear', tool='esmf')
예제 #2
0
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,
           subplot=(2, 2, i + 3),
           title='interp1d: axis=%s\next=%s, mode=%s' % (axis, ext, mode),
           **kw)
varo = extend2d(vari, iext=2, jext=2, mode='linear')
plot2d(varo,
       subplot=(2, 2, 2),
       title='interp2d: mode=linear\niext=2, jext=2',
       **kw)
P.tight_layout()
savefigs(code_file_name(), verbose=False)
예제 #3
0
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
add_grid(gridri, **kwg)
# - bilin c2c / vacumm
varo = regrid2d(varci, gridco, method='bilinear', tool='vacumm')
plot2d(varo[0], title='VACUMM / Bilinear', subplot=(4,3,ip), **kw);ip+=1
add_grid(gridci, **kwg)
# - bilin c2c / emsf
varo = regrid2d(varci, gridco, method='bilinear', tool='esmf')
예제 #4
0
"""Test :func:`~vacumm.misc.plot.plot2d` with specified cell bounds"""

# Imports
from vcmq import MV2, N, code_file_name, plot2d, os

# Init
var = MV2.reshape(MV2.arange(4*3), (3, 4))
var.units = 'Count'
var.long_name = 'Navets'
x = var.getAxis(1)
x.units = 'km'
x.long_name = 'Distance'
y = var.getAxis(0)
y.units = 'm'
y.long_name = 'Height'
y.designateLevel()

# Bounds
y[:] = [1.5, 3.5, 4.5]
y2db = N.array([0., 3, 4, 5])

# Plot
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
plot2d(var, savefig=figfile, show=False, close=True, y2db=y2db, fill='pcolor',
    xmin=-.5, xmax=3.5, ymin=0, ymax=5, cmap='jet')

# Unittest
result = {"files":figfile}
예제 #5
0
"""Test :func:`~vacumm.misc.plot.plot2d` with arbitrary axes"""

# %% Imports
from vcmq import MV2, code_file_name, plot2d, os

# %% Init
var = MV2.reshape(MV2.arange(10 * 8), (8, 10))
var.units = 'Count'
var.long_name = 'Navets'
x = var.getAxis(1)
x.units = 'km'
x.long_name = 'Distance'
y = var.getAxis(0)
y.units = 'Hz'
y.long_name = 'Frequency'

# %% Plot
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
plot2d(var, savefig=figfile, show=False, close=True)
예제 #6
0
"""Test :func:`~vacumm.misc.plot.plot2d` with a time axis"""

# Imports
from vcmq import MV2, code_file_name, plot2d, os

# Init
var = MV2.reshape(MV2.arange(10*8), (8,10))
var.units = 'Count'
var.long_name = 'Carottes'
x = var.getAxis(1)
x.units = 'months since 2000'
x.long_name = 'Time'
y = var.getAxis(0)
y.units = 'Hz'
y.long_name = 'Frequency'

# Plot
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
plot2d(var, savefig=figfile, show=False, close=True, fill='pcolor', order='t-')

# Unittest
result = {"files":figfile}
예제 #7
0
"""Test :func:`~vacumm.misc.plot.plot2d` with a time axis"""

# Imports
from vcmq import MV2, code_file_name, plot2d, os

# Init
var = MV2.reshape(MV2.arange(10 * 8), (8, 10))
var.units = 'Count'
var.long_name = 'Carottes'
x = var.getAxis(1)
x.units = 'months since 2000'
x.long_name = 'Time'
y = var.getAxis(0)
y.units = 'Hz'
y.long_name = 'Frequency'

# Plot
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
plot2d(var, savefig=figfile, show=False, close=True, fill='pcolor', order='t-')

# Unittest
result = {"files": figfile}
예제 #8
0
grido = create_grid(xi[:]+2*2.5, yi[:]+3*1.5)
xo = grido.getLongitude()
yo = grido.getLatitude()
xo.setBounds(bounds1d(xo))
yo.setBounds(bounds1d(yo))
xxob, yyob = meshbounds(xo, yo)

# Regridding
varo, wo = vari.regrid(grido, tool='regrid2', returnTuple=1)

# Plot
kw = dict(fill='pcolor', contour=False, xhide=True, yhide=True,
    xticks=[], yticks=[], cmap='jet',
    colorbar=False, show=False)
P.figure(figsize=(6, 3))
p = plot2d(vari, subplot=131, title='Original', **kw)
add_grid(gridi)
add_grid(grido)
P.axis('image')
p = plot2d(varo, subplot=132, title='Regridded',  **kw)
add_grid(gridi)
add_grid(grido)
P.axis('image')
P.subplot(133)
P.pcolor(xxob, yyob, wo)
add_grid(grido)
P.title("Output weights")
P.tight_layout()
savefigs(code_file_name(),pdf=True, verbose=False)
P.close()
예제 #9
0
파일: showvar.py 프로젝트: jfleroux/vacumm
    kwplot[att] = getattr(args, att)
for att in ('color', 'linewidth'):
    val = getattr(args, att)
    if val is not None:
        kwplot[att] = val
kwplot['quiver_norm'] = args.qnorm
if len(vv)==2 and args.qonly:
    kwplot['contour'] = kwplot['fill'] = False
if args.figsize:
    kwplot['figsize'] = tuple([float(v) for v in args.figsize.split(',')])
if args.res=='off':
    args.res = None
kwplot['res'] = args.res

#del kwplot['color']
#kwplot = {'color':None}

# Adaptative plot
if ndim==2:
    if order in ['yx', 'xy']:
        map2(vv, **kwplot)
    elif 't' in order:
        hov2(vv, **kwplot)
    else:
        plot2d(vv, **kwplot)
else:
    if len(vv)>1:
        stick2(*vv, **kwplot)
    else:
        curve2(vv, **kwplot)
예제 #10
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")
plot2d(varo, title="VACUMM / Bilinear", subplot=(4, 3, ip), **kw)
ip += 1
add_grid(gridri, **kwg)
# - bilin c2c / vacumm
varo = regrid2d(varci, gridco, method="bilinear", tool="vacumm")
예제 #11
0
    kwplot[att] = getattr(args, att)
for att in ('color', 'linewidth'):
    val = getattr(args, att)
    if val is not None:
        kwplot[att] = val
kwplot['quiver_norm'] = args.qnorm
if len(vv) == 2 and args.qonly:
    kwplot['contour'] = kwplot['fill'] = False
if args.figsize:
    kwplot['figsize'] = tuple([float(v) for v in args.figsize.split(',')])
if args.res == 'off':
    args.res = None
kwplot['res'] = args.res

#del kwplot['color']
#kwplot = {'color':None}

# Adaptative plot
if ndim == 2:
    if order in ['yx', 'xy']:
        map2(vv, **kwplot)
    elif 't' in order:
        hov2(vv, **kwplot)
    else:
        plot2d(vv, **kwplot)
else:
    if len(vv) > 1:
        stick2(*vv, **kwplot)
    else:
        curve2(vv, **kwplot)
예제 #12
0
# Imports
from vcmq import MV2, code_file_name, plot2d, os

# Init
var = MV2.reshape(MV2.arange(10 * 8), (8, 10))
var.id = 'navets'
var.getAxis(0).id = 'frequency'
var.getAxis(1).id = 'distance'

# Plot
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
# - positive
plot2d(var,
       subplot=326,
       show=False,
       figsize=(6, 8),
       cmap='auto',
       title='Positive?')
# - negative
var[:] *= -1
plot2d(var, subplot=325, show=False, cmap='auto', title='Negative?')
# - force normal
var[:] *= -1
plot2d(var,
       subplot=322,
       show=False,
       cmap='auto',
       levels_mode='normal',
       title='Force normal')
# - force cmap
plot2d(var, subplot=323, show=False, cmap='turbid', title='Force cmap: turbid')
예제 #13
0
# 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, subplot=(2, 2, i+3), 
        title='interp1d: axis=%s\next=%s, mode=%s'%(axis, ext, mode), **kw)
varo = extend2d(vari, iext=2, jext=2, mode='linear')
plot2d(varo, subplot=(2, 2, 2), 
    title='interp2d: mode=linear\niext=2, jext=2', **kw)
P.tight_layout()
savefigs(code_file_name(), verbose=False)
P.close()
예제 #14
0
# Regridding
varo, wo = vari.regrid(grido, tool='regrid2', returnTuple=1)

# Plot
kw = dict(fill='pcolor',
          contour=False,
          xhide=True,
          yhide=True,
          xticks=[],
          yticks=[],
          cmap='jet',
          colorbar=False,
          show=False)
P.figure(figsize=(6, 3))
p = plot2d(vari, subplot=131, title='Original', **kw)
add_grid(gridi)
add_grid(grido)
P.axis('image')
p = plot2d(varo, subplot=132, title='Regridded', **kw)
add_grid(gridi)
add_grid(grido)
P.axis('image')
P.subplot(133)
P.pcolor(xxob, yyob, wo)
add_grid(grido)
P.title("Output weights")
P.tight_layout()
savefigs(code_file_name(), pdf=True, verbose=False)
P.close()
예제 #15
0
"""Test :func:`~vacumm.misc.plot.plot2d` with arbitrary axes"""

# Imports
from vcmq import MV2, code_file_name, plot2d, os

# Init
var = MV2.reshape(MV2.arange(10*8), (8,10))
var.units = 'Count'
var.long_name = 'Navets'
x = var.getAxis(1)
x.units = 'km'
x.long_name = 'Distance'
y = var.getAxis(0)
y.units = 'Hz'
y.long_name = 'Frequency'

# Plot
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
plot2d(var, savefig=figfile, show=True, close=True)

# Unittest
result = {"files":figfile}