コード例 #1
0
def plot(xx, yy, target, label, figfiles, figfile, lon=None, lat=None, show=False):
    xs, ys, mask = coord2slice(target, lon=lon, lat=lat)
    P.figure(figsize=(6, 3.5))
    P.title('Target=%(label)s / select: lon=%(lon)s, lat=%(lat)s'%locals())
    add_grid((xx, yy))
    xx = xx.asma()
    yy = yy.asma()
    if isinstance(lon, tuple): 
        P.axvline(lon[0], color='m', ls='--', lw=2)
        P.axvline(lon[1], color='m', ls='--', lw=2)
    elif isinstance(lon, slice):
        i, j, k = lon.indices(xx.shape[1])
        P.plot(xx[:, i], yy[:, i], 'c--', lw=2)
        P.plot(xx[:, j-1], yy[:, j-1], 'c--', lw=2)
    if isinstance(lat, tuple): 
        P.axhline(lat[0], color='m', ls='--', lw=2)
        P.axhline(lat[1], color='m', ls='--', lw=2)
    elif isinstance(lat, slice):
        i, j, k = lat.indices(yy.shape[0])
        P.plot(xx[i], yy[i], 'c--', lw=2)
        P.plot(xx[j-1], yy[j-1], 'c--', lw=2)
    P.xticks(N.arange(xx.min()-1, xx.max()+1))
    P.yticks(N.arange(yy.min()-1, yy.max()+1))
    xxi, yyi = xx, yy
    xx = xx[ys, xs]
    yy = yy[ys, xs]
#    mask = mask[ys, xs]
    xxb, yyb = meshbounds(xx, yy)
    P.pcolor(xxb, yyb, mask, shading='faceted')
    P.scatter(xx.ravel(), yy.ravel(), c=(0, 1, 0))
    P.grid('on')
    P.axis('image')
    P.tight_layout()
    i = len(figfiles)
    savefig = figfile%i
    if os.path.exists(savefig): os.remove(savefig)
    P.savefig(savefig)
    figfiles.append(savefig)
    if show: P.show()
    else: P.close()
コード例 #2
0
# On ajoute un traît de côte pour le masquage
from vacumm.bathy.bathy import GriddedBathy, GriddedBathyMerger
bathy_large = GriddedBathy(var_large, shoreline='i')
bathy_small = var_small

# Création de la grille finale de résolution intermédiaire
final_grid = create_grid((-6., .5, xr * 2.5), (45, 47., yr * 2.5))

# On crée maintenant le merger
merger = GriddedBathyMerger(final_grid)
# - ajout de la bathy basse resolution en premier (en dessous)
merger += bathy_large
# - puis ajout de celle haute résolution
merger += bathy_small

# On définit le traît de côte pour le masquage
merger.set_shoreline('h')

# Fusion vers la grille finale
bathy = merger.merge()

# Plot
merger.plot(show=False)
from vacumm.misc.plot import savefigs, add_grid
kwgrid = dict(linewidth=.5, alpha=.5, samp=2)
add_grid(grid_large, color='r', **kwgrid)
add_grid(var_small.getGrid(), color='#00ff00', **kwgrid)
savefigs(__file__)
P.close()
コード例 #3
0
varob = interp2d(vari, (xo, yo), method='bilinear')
# - nearest
varon = interp2d(vari, (xo, yo), method='nearest')

# Plot
import pylab as P
from vacumm.misc.plot import savefigs, add_grid
xob, yob = meshbounds(xo[:], yo[:])
lims = [xob.min(), xob.max(), yob.min(), yob.max()]
# -
P.figure(figsize=(5.5, 7))
P.subplots_adjust(bottom=.07, hspace=.35)
P.subplot(311)
P.pcolor(xib, yib, vari, **vminmax)
P.axis(lims)
add_grid((xo, yo), linewidth=.3)
P.title('Original')
# -
P.subplot(312)
P.pcolor(xob, yob, varob, **vminmax)
P.axis(lims)
add_grid((xi, yi), linewidth=.3)
P.title('Bilinear')
# -
P.subplot(313)
P.pcolor(xob, yob, varon, **vminmax)
P.axis(lims)
add_grid((xi, yi), linewidth=.3)
P.title('Nearest')
# -
savefigs(__file__)
コード例 #4
0
cgrido = rotate_grid(hs.getGrid(), -30)


print 'Regrillage'
from vacumm.misc.grid.regridding import regrid2d
print ' - par natgrid'
hs_nat = regrid2d(hs, cgrido, 'nat')
print ' - par SCRIP/conservative'
hs_scripcons = regrid2d(hs, cgrido, 'conservative')
print ' - par SCRIP/bilineaire'
hs_scripbilin = regrid2d(hs, cgrido, 'bilinear')


print 'Plots'
from matplotlib import rcParams ; rcParams['font.size'] = 10
import pylab as P
from vacumm.misc.plot import map2, savefigs, xhide, yhide, add_grid
P.figure(figsize=(6.5, 5))
P.subplots_adjust(hspace=.28, bottom=.07, left=.08, right=.98)
kwplot = dict(show=False, colorbar=False, vmin=hs.min(), vmax=hs.max(), 
    drawparallels_size=8, drawmeridians_size=8, drawmeridians_rotation=45.)
m = map2(hs, title='Original', subplot=221, xhide=1,**kwplot)
add_grid(cgrido, lw=.7, alpha=.3)
map2(hs_nat, title='Natgrid', subplot=222, xhide=1,yhide=1,m=m, **kwplot)
add_grid(cgridi, lw=.7, alpha=.3)
map2(hs_scripcons, title='SCRIP : remapping', subplot=223, m=m, **kwplot)
add_grid(cgridi, lw=.7, alpha=.3)
map2(hs_scripbilin, title=u'SCRIP : bilinéaire',subplot=224,yhide=1,m=m, **kwplot)
add_grid(cgridi, lw=.7, alpha=.3)
savefigs(__file__)
コード例 #5
0
# Creation d'un axe de profondeur
from vacumm.misc.axes import create_dep
ddep = 5.
dep = create_dep((-h0.max(), 0. + ddep, ddep))

# Creation de l'axe etendu (taille (ndep,nx))
depths = -N.outer(t.getAxis(0)[::-1], h0)
dep[-1] = depths[-1].max()

# Regrillage lineaire
from vacumm.misc.grid.regridding import regrid1d
tr = regrid1d(t, dep, 'linear', axi=depths, axis=0)
tr.long_name = 'Interpolated'
t.getAxis(0).designateLevel()

# Plot
from vacumm.misc.plot import savefigs, yscale, add_grid, section2
import pylab as P
P.figure(figsize=(5.5, 6))
kwplot = dict(show=False, bgcolor='.5', ylim=(-80, 0))
# - original
section2(t, yaxis=depths, subplot=211, hspace=.3, **kwplot)
add_grid((t.getLongitude(), depths[:]), linewidth=.3)

# - regridded
section2(tr, subplot=212, **kwplot)
add_grid((tr.getLongitude(), dep[:]), linewidth=.3)
savefigs(__file__)
P.close()
コード例 #6
0
from vacumm.misc.grid import rotate_grid
import numpy as N
cgrido = rotate_grid(hs.getGrid(), -30)


print 'Regrillage'
from vacumm.misc.grid.regridding import regrid2d
print ' - par SCRIP/conservative'
hs_scripcons = regrid2d(hs, cgrido, 'conservative')
print ' - par SCRIP/bilineaire'
hs_scripbilin = regrid2d(hs, cgrido, 'bilinear')


print 'Plots'
from matplotlib import rcParams ; rcParams['font.size'] = 10
import pylab as P
from vacumm.misc.plot import map2, savefigs, xhide, yhide, add_grid
P.figure(figsize=(4, 7))
P.subplots_adjust(hspace=.28, bottom=.07, left=.08, right=.98)
kwplot = dict(show=False, colorbar=False, vmin=hs.min(), vmax=hs.max(),
    drawparallels_size=8, drawmeridians_size=8, drawmeridians_rotation=45.,
    xhide='auto',  yhide='auto')
m = map2(hs, title='Original', subplot=311, **kwplot)
add_grid(cgrido, lw=.7, alpha=.3)
map2(hs_scripcons, title='SCRIP : remapping', subplot=312, m=m, **kwplot)
add_grid(cgridi, lw=.7, alpha=.3)
map2(hs_scripbilin, title=u'SCRIP : bilinéaire', subplot=313, m=m, **kwplot)
add_grid(cgridi, lw=.7, alpha=.3)
savefigs(__file__)
P.close()
コード例 #7
0
ファイル: showgrid.py プロジェクト: acoat/vacumm
# Plot
if options.plot or options.out:

    xmin, ymin, xmax, ymax = scalebox(grid, 1 / options.zoom)
    for att in 'xmin', 'xmax', 'ymin', 'ymax':
        if getattr(options, att) is not None:
            exec att + " = %s" % getattr(options, att)
    if options.figsize is not None:
        try:
            options.figsize = eval(options.figsize)
            if not isinstance(options.figsize, tuple):
                options.figsize = options.figsize, options.figsize
        except:
            options.figsize = None
    if options.proj.lower() == 'none': options.proj = None
    m = map2(lon=(xmin, xmax),
             lat=(ymin, ymax),
             show=False,
             res=options.shoreline,
             title='Grid from ' + os.path.basename(ncfile),
             figsize=options.figsize,
             proj=options.proj)
    add_grid(grid, m=m, centers=True, borders=True, color='b', markersize=5)
    m.legend(zorder=200, alpha=.7, title='Grid: %ix%i' % grid.shape[::-1])
    if options.out:
        m.savefig(options.out)
        print 'Plot saved to ' + options.out
    if options.plot: m.show()
f.close()
コード例 #8
0
# Creation d'un axe de profondeur
from vacumm.misc.axes import create_dep
ddep = 5.
dep = create_dep((-h0.max(),0.+ddep , ddep))

# Creation de l'axe etendu (taille (ndep,nx))
depths = -N.outer(t.getAxis(0)[::-1], h0)
dep[-1] = depths[-1].max()

# Regrillage lineaire
from vacumm.misc.grid.regridding import regrid1d
tr = regrid1d(t, dep, 'linear', axi=depths, axis=0)
tr.long_name = 'Interpolated'
t.getAxis(0).designateLevel()

# Plot
from vacumm.misc.plot import savefigs,yscale, add_grid, section2
import pylab as P
P.figure(figsize=(5.5, 6))
kwplot = dict(show=False, bgcolor='.5', ylim=(-80, 0))
# - original
section2(t, yaxis=depths, subplot=211, hspace=.3, **kwplot)
add_grid((t.getLongitude(), depths[:]), linewidth=.3)

# - regridded
section2(tr, subplot=212, **kwplot)
add_grid((tr.getLongitude(), dep[:]), linewidth=.3)
savefigs(__file__)

コード例 #9
0
ファイル: showgrid.py プロジェクト: jfleroux/vacumm
xres, yres = resol(gg, proj=True)
xres /= 1000.
yres /= 1000.
print 'Zonal resolution     : %g° / %gkm'%(lonres, xres)
print 'Meridional resolution: %g° / %gkm'%(latres, yres)

# Plot
if options.plot or options.out:

    xmin, ymin, xmax, ymax = scalebox(grid, 1/options.zoom)
    for att in 'xmin', 'xmax', 'ymin', 'ymax':
        if getattr(options, att) is not None: exec att+" = %s"%getattr(options, att)
    if options.figsize is not None:
        try:
            options.figsize = eval(options.figsize)
            if not isinstance(options.figsize, tuple):
                options.figsize = options.figsize, options.figsize
        except:
            options.figsize = None
    if options.proj.lower() == 'none': options.proj = None
    m = map2(lon=(xmin, xmax), lat=(ymin, ymax), show=False, res=options.shoreline,
        title='Grid from '+os.path.basename(ncfile), figsize=options.figsize,
        proj = options.proj)
    add_grid(grid, m=m, centers=True, borders=True, color='b', markersize=5)
    m.legend(zorder=200, alpha=.7, title='Grid: %ix%i'%grid.shape[::-1])
    if options.out:
        m.savefig(options.out)
        print 'Plot saved to '+ options.out
    if options.plot: m.show()
f.close()
コード例 #10
0
# On ajoute un traît de côte pour le masquage
from vacumm.bathy.bathy import GriddedBathy, GriddedBathyMerger
bathy_large = GriddedBathy(var_large, shoreline='i')
bathy_small = var_small

# Création de la grille finale de résolution intermédiaire
final_grid = create_grid((-6., .5, xr*2.5), (45, 47., yr*2.5))

# On crée maintenant le merger
merger = GriddedBathyMerger(final_grid)
# - ajout de la bathy basse resolution en premier (en dessous)
merger += bathy_large
# - puis ajout de celle haute résolution
merger += bathy_small

# On définit le traît de côte pour le masquage
merger.set_shoreline('h')

# Fusion vers la grille finale
bathy = merger.merge()

# Plot
merger.plot(show=False)
from vacumm.misc.plot import savefigs, add_grid
kwgrid = dict(linewidth=.5, alpha=.5, samp=2)
add_grid(grid_large, color='r', **kwgrid)
add_grid(var_small.getGrid(), color='#00ff00', **kwgrid)
savefigs(__file__)