comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()


#if rank==0: print 'read'
f = cdms2.open(data_sample(ncfile))
vari2d = f(ncvar)[0,yslice,xslice]
f.close()
gridi = vari2d.getGrid()
vari2d[:] += 3*vari2d.mean()
vari2d[:, -1] = MV2.masked
nyi,nxi = vari2d.shape

#if rank==0: print 'expand in time and depth'
vari = MV2.resize(vari2d, (nt, nz)+vari2d.shape)
cp_props(vari2d, vari)


#if rank==0: print 'grido'
loni = gridi.getLongitude()
lati = gridi.getLatitude()
xib, yib = bounds2d(loni, lati)
loni.setBounds(xib)
lati.setBounds(yib)
xi = loni.getValue()
yi = lati.getValue()
dx = N.diff(xi[0]).mean()
dy = N.diff(yi[:, 0]).mean()
xo = N.arange(xi.min()+10*dx, -30*dx+xi.max(), dx)
yo = N.arange(yi.min()-20*dy, yi.max()-20*dy, dy)
Ejemplo n.º 2
0
"""Test function :func:`~vacumm.misc.plot.taylor` in different configurations"""
from vcmq import taylor, rc, code_file_name, MV2, N

# Make some data
nt = 50
nens = 50
# - references
ref1 = MV2.sin(MV2.arange(nt, dtype='f')) * 10.
ref2 = ref1 * 1.2
# - ensemble 1
dat1 = MV2.resize(ref1, (nens, nt)) + N.resize(N.random.rand(nt * nens),
                                               (nens, nt)) * 20.
dat1.long_name = 'Set 1'
dat1.units = 'meters'
# - modele 2
dat2 = MV2.resize(ref2, (nens, nt)) + N.resize(N.random.rand(nt * nens),
                                               (nens, nt)) * 40.
dat2.long_name = 'Set 2'

# Plot
rc('font', size=8)
kwplot = dict(figsize=(5, 5),
              savefigs_pdf=False,
              show=False,
              close=True,
              savefigs_verbose=False)
basename = code_file_name(ext=False) + '_%i'
# - single variable
taylor(dat1[0],
       ref1,
       savefigs=basename % 0,
Ejemplo n.º 3
0
"""Test the class :class:`~vacumm.misc.grid.regridding.CurvedInterpolator`"""

from vcmq import (P, N, set_grid, plot2d, MV2, add_grid, code_file_name, os,
                  create_time, CurvedInterpolator, rotate_grid)

# Curved grid
nxy = 10
nt = 5
lon = N.arange(nxy * 1.)
lat = N.arange(nxy * 1.)
time = create_time((nt, ), 'years since 2000')
gridi = rotate_grid((lon, lat), 30)
xxi = gridi.getLongitude()[:].filled()
yyi = gridi.getLatitude()[:].filled()
vari = MV2.resize(yyi, (nt, nxy, nxy))
vari.setAxis(0, time)
set_grid(vari, gridi)
kw = dict(vmin=vari.min(), vmax=vari.max())
P.figure(figsize=(10, 3.5))
P.subplot(131, aspect=1)
P.contourf(xxi, yyi, vari[0].asma(), **kw)
add_grid(gridi, edges=False, centers=-1)
xylims = (xxi.min(), xxi.max(), yyi.min(), yyi.max())
P.axis(xylims)
P.title('Curved grid')

# Interpolate to grid
xg, yg = N.meshgrid(N.arange(-3.5, 14.5), N.arange(-3.5, 14.5))
nxyg = xg.shape
cig = CurvedInterpolator(gridi, (xg, yg), g2g=True)
varog = cig(vari)
Ejemplo n.º 4
0
from vcmq import N, MV2, create_grid, rotate_grid, GriddedSelector

# %% Rectangular grid
rgrid = create_grid((-14., -4, .25), (43., 52, .25), 'rect')
var = MV2.reshape(MV2.arange(2 * rgrid.shape[0] * rgrid.shape[1]),
                  (2, ) + rgrid.shape)
gs = GriddedSelector(rgrid, lon=(-9, -6, 'co'), lat=(44.1, 48.2))
rvar = gs(var)
assert rvar.shape == (2, 16, 12)
assert rvar.getLongitude()[-1] == -6.25
assert rvar.getLatitude()[-1] == 48

# %% Curvilinear
cgrid = rotate_grid(rgrid, 30.)
gs = GriddedSelector(cgrid, lon=(-9, -6, 'co'), lat=(44.1, 48.2))
cvar = gs(var)
assert cvar.shape == (2, 20, 18)
assert cvar.getLongitude().asma()[~gs.mask].min() == -9
assert cvar.getLatitude().asma()[~gs.mask].max() <= 48.2

# %% Unstructured
N.random.seed(0)
ugrid = create_grid(N.random.uniform(-14, -4, 100),
                    N.random.uniform(43, 52, 100), 'unstruct')
var = MV2.resize(ugrid.getLatitude().asma(), (2, ) + ugrid.shape)
gs = GriddedSelector(ugrid, lon=(-9, -6, 'co'), lat=(44.1, 48.2))
uvar = gs(var)
assert uvar.getGrid().shape == (34, )
assert uvar.getLongitude().min() >= -9
assert uvar.getLatitude().max() < 52
Ejemplo n.º 5
0
"""Test function :func:`~vacumm.misc.plot.taylor` in different configurations"""
from vcmq import taylor, rc, code_file_name, MV2, N

# Make some data
nt = 50
nens = 50
# - references
ref1 = MV2.sin(MV2.arange(nt, dtype='f'))*10.
ref2 = ref1*1.2
# - ensemble 1
dat1 = MV2.resize(ref1, (nens, nt))+N.resize(N.random.rand(nt*nens), (nens, nt))*20.
dat1.long_name = 'Set 1'
dat1.units = 'meters'
# - modele 2
dat2 = MV2.resize(ref2, (nens, nt))+N.resize(N.random.rand(nt*nens), (nens, nt))*40.
dat2.long_name = 'Set 2'

# Plot
rc('font', size=8)
kwplot = dict(figsize=(5,5), savefigs_pdf=False, show=False, close=True, savefigs_verbose=False)
basename = code_file_name(ext=False)+'_%i'
# - single variable
taylor(dat1[0], ref1, savefigs=basename%0, colors='cyan', title='Basic', **kwplot)
# - single variable without normalization
taylor(dat1[0], ref1, savefigs=basename%1, normalize=False, reflabel='Reference', 
    title='No normalization', **kwplot)
# - several variables with same ref
taylor([d for d in dat1], ref1, colors='cyan', savefigs=basename%2, 
    title='Several variables', **kwplot)
# - several variables with same ref with specified colors
taylor([d for d in dat1[:3]], ref1, colors = ['r', 'g', 'b'],