Exemplo n.º 1
0
"""Test CDAT conservative regridding"""
from vcmq import N, meshbounds, bounds1d, cdms2, MV2, rc, P, add_grid, rcdefaults, \
    create_lon, create_lat, savefigs, code_file_name

# Input grid
x0, y0, nx, ny, dx, dy = 0., 0., 20, 15, 5., 5.
x = x0 + N.arange(0, nx * dx, dx)
y = y0 + N.arange(0, ny * dy, dy)
xxbi, yybi = meshbounds(x, y)
xb = bounds1d(x)
yb = bounds1d(y)
lon = create_lon(x)
lat = create_lat(y)
lon.setBounds(xb)
lat.setBounds(yb)
gridi = cdms2.createRectGrid(lat, lon)

# Input data
vari = MV2.ones(gridi.shape) * 50
vari[5:10, 7:13] = -10
#vari[:, -1] = MV2.masked # <<< THIS MAKES IT WORK!

vari.setAxisList([gridi.getLatitude(), gridi.getLongitude()])
vari.setGrid(gridi)

# Output grid
grido, xxbo, yybo = gridi, xxbi, yybi

# Regrid
diag = {'dstAreaFractions': None}
varo = vari.regrid(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)
lono = cdms2.createAxis(xo)
lono.designateLongitude() ; lono.units= 'degrees_east'
lato = cdms2.createAxis(yo)
lato.designateLatitude() ; lato.units = 'degrees_north'
xob = bounds1d(lono) ; lono.setBounds(xob)
yob = bounds1d(lato) ; lato.setBounds(yob)
grido = cdms2.createRectGrid(lato, lono)
xmin, xmax = minmax(loni.asma(),lono)
ymin, ymax = minmax(lati.asma(), lato)
nyo,nxo = grido.shape
#print 'rank',rank
basefile = code_file_name(ext=False)
repfile = basefile+'.nt%(nt)s-nz%(nz)s-nyi%(nyi)s-nxi%(nxi)s.log'%locals()
if rank==0: 
    if os.path.exists(repfile): os.remove(repfile)
    f = open(repfile, 'w')
    if size:
#        print 'MPI', size
        print >>f, 'MPI: NPROC=%i'%size
    print >>f, 'NT=%(nt)i, NZ=%(nz)i'%locals()
Exemplo n.º 3
0
"""Test the traditionnal CDAT regrid2 regridder"""

from vcmq import MV2, create_grid, meshbounds, P, add_grid, N, bounds1d, plot2d, savefigs,code_file_name
from regrid2 import Horizontal

# Input
nx, ny = 6, 4
vari = MV2.array(N.arange(nx*ny*1.).reshape(ny, nx), fill_value=1e20)
xi = vari.getAxis(-1)
xi[:] *= 2
yi = vari.getAxis(-2)
yi[:] *= 3
xi.designateLongitude()
yi.designateLatitude()
xi.setBounds(bounds1d(xi))
yi.setBounds(bounds1d(yi))
vari[1:2, 2:4] = MV2.masked
gridi = vari.getGrid()


# Output
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)
Exemplo n.º 4
0
"""Test CDAT conservative regridding"""
from vcmq import N, meshbounds, bounds1d, cdms2, MV2, rc, P, add_grid, rcdefaults, \
    create_lon, create_lat, savefigs, code_file_name
    
# Input grid
x0, y0, nx, ny, dx, dy = 0., 0., 20, 15, 5., 5.
x = x0+N.arange(0, nx*dx, dx)
y = y0+N.arange(0, ny*dy, dy)
xxbi, yybi = meshbounds(x, y)
xb = bounds1d(x)
yb = bounds1d(y)
lon = create_lon(x)
lat = create_lat(y)
lon.setBounds(xb)
lat.setBounds(yb)
gridi = cdms2.createRectGrid(lat, lon)

# Input data
vari = MV2.ones(gridi.shape)*50
vari[5:10, 7:13] = -10
#vari[:, -1] = MV2.masked # <<< THIS MAKES IT WORK!

vari.setAxisList([gridi.getLatitude(), gridi.getLongitude()])
vari.setGrid(gridi)

# Output grid
grido, xxbo, yybo = gridi, xxbi, yybi

# Regrid
diag = {'dstAreaFractions':None}
varo = vari.regrid(grido, tool='esmf', method='conservative', 
Exemplo n.º 5
0
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)
lono = cdms2.createAxis(xo)
lono.designateLongitude()
lono.units = 'degrees_east'
lato = cdms2.createAxis(yo)
lato.designateLatitude()
lato.units = 'degrees_north'
xob = bounds1d(lono)
lono.setBounds(xob)
yob = bounds1d(lato)
lato.setBounds(yob)
grido = cdms2.createRectGrid(lato, lono)
xmin, xmax = minmax(loni.asma(), lono)
ymin, ymax = minmax(lati.asma(), lato)
nyo, nxo = grido.shape
#print 'rank',rank
basefile = code_file_name(ext=False)
repfile = basefile + '.nt%(nt)s-nz%(nz)s-nyi%(nyi)s-nxi%(nxi)s.log' % locals()
if rank == 0:
    if os.path.exists(repfile): os.remove(repfile)
    f = open(repfile, 'w')
    if size:
        #        print 'MPI', size
Exemplo n.º 6
0
"""Test the traditionnal CDAT regrid2 regridder"""

from vcmq import MV2, create_grid, meshbounds, P, add_grid, N, bounds1d, plot2d, savefigs, code_file_name
from regrid2 import Horizontal

# Input
nx, ny = 6, 4
vari = MV2.array(N.arange(nx * ny * 1.).reshape(ny, nx), fill_value=1e20)
xi = vari.getAxis(-1)
xi[:] *= 2
yi = vari.getAxis(-2)
yi[:] *= 3
xi.designateLongitude()
yi.designateLatitude()
xi.setBounds(bounds1d(xi))
yi.setBounds(bounds1d(yi))
vari[1:2, 2:4] = MV2.masked
gridi = vari.getGrid()

# Output
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