当前位置: 首页>>代码示例>>Python>>正文


Python N.resize方法代码示例

本文整理汇总了Python中vcmq.N.resize方法的典型用法代码示例。如果您正苦于以下问题:Python N.resize方法的具体用法?Python N.resize怎么用?Python N.resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vcmq.N的用法示例。


在下文中一共展示了N.resize方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: slice

# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import resize [as 别名]
result.append(('AssertEqual', (coord2slice(lon1d, lon=slice(3, 6)), slice(3, 6, None))))
result.append(('AssertEqual', (coord2slice(lon1d, lat=(6, 8)), slice(0, 10, 1))))
result.append(('AssertEqual', (coord2slice(lon1d, lon=(60, 70)), None)))

# Rect grid
grid = create_grid((0, 10.), (20, 30.))
result.append(('AssertEqual', (coord2slice(grid, lon=(0., 3.5), lat=slice(3, 5)), 
    (slice(0, 4, 1), slice(3, 5, None), None))))
result.append(('AssertEqual', (coord2slice(grid, lat=(21,21, 'ccb')),
    (slice(0, 10, 1), slice(1, 2, 1), None))))

# 2D axis
lon2d = N.empty((10, 10.))
for i in xrange(10): 
    lon2d[i] = lon1d[:]+i
lat2d = N.resize((N.arange(10)+20), (10, 10)).T
lon2d, lat2d = create_axes2d(lon2d, lat2d)
kw = dict(show=False)
plot(lon2d, lat2d, lon2d, 'lon2d', figfiles, figfile, lon=(2, 4), **kw)
plot(lon2d, lat2d, lon2d, 'lon2d', figfiles, figfile, lon=(2, 4), lat=slice(0, 2), **kw)
plot(lon2d, lat2d, lat2d,  'lat2d', figfiles, figfile, lat=(22, 26.6,'ccb'), **kw)

# Curv grid
grid = create_grid(lon2d, lat2d)
plot(lon2d, lat2d, grid, 'grid', figfiles, figfile, lon=(8, 11, 'cc'), lat=(21.9, 26., 'cc'), **kw)
plot(lon2d, lat2d, grid, 'grid', figfiles, figfile, lon=slice(2, 5), lat=(23.4, 23.6, 'ccb'), **kw)
res = coord2slice(grid,lon=(8,8,'ccb'),lat=(24,24,'ccb'))
result.append(('AssertEqual', (res[:2], (slice(3, 6, 1), slice(4, 5, 1)))))
result.append(('AssertEqual', (coord2slice(grid,lon=(8,8,'ccb'),lat=(24,24,'ccb'), mode='a').tolist(), 
    [[4, 4, 4], [3, 4, 5]])))
开发者ID:jfleroux,项目名称:vacumm,代码行数:32,代码来源:test_grid_coord2slice_acad.py

示例2: len

# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import resize [as 别名]
from vcmq import N, P,meshcells, minmax, code_file_name, os
from vacumm.misc.grid._interp_ import interp1dxx


nx = nyi = 10
mv = 1.e20
u, v = N.mgrid[-3:3:nx*1j, -3:3:10j]-2
vari = N.ma.asarray(u**2+v**2)
vari.set_fill_value(mv)
yi = N.linspace(-1000.,0., nyi)
yo = N.linspace(-1200, 100, 30.)
vari[nx/3:2*nx/3, nyi/3:2*nyi/3] = N.ma.masked
x = N.arange(nx)
dyi = (yi[1]-yi[0])*0.49
dyo = (yo[1]-yo[0])*0.49
yyi = N.resize(yi, vari.shape)+N.random.uniform(-dyi, dyi, vari.shape)
yyo = N.resize(yo, (nx, len(yo)))+N.random.uniform(-dyo, dyo, (nx, len(yo)))
yyib, xxib  = meshcells(yyi, x)
yyob, xxob  = meshcells(yyo, x)

varon = N.ma.masked_values(interp1dxx(vari.filled(), yyi, yyo, mv, 0, extrap=0), mv)
varol = N.ma.masked_values(interp1dxx(vari.filled(), yyi, yyo, mv, 1, extrap=0), mv)
varoh = N.ma.masked_values(interp1dxx(vari.filled(), yyi, yyo, mv, 3, extrap=0), mv)

kw = dict(vmin=vari.min(), vmax=vari.max())
axlims = [x[0], x[-1], yo[0], yo[-1]]
P.figure(figsize=(8, 8))
P.subplot(221)
P.pcolor(xxib, yyib, vari)
P.axis(axlims)
P.title('Original')
开发者ID:jfleroux,项目名称:vacumm,代码行数:33,代码来源:test_regrid_fortran_interp1dxx.py

示例3: format_exc

# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import resize [as 别名]
        else: diag = None
        try:
            varo = vari.regrid(grido, tool=tool, method=method, diag=diag)
            if rank==0: print >>f, ' ok'
        except:
            if rank==0: 
                print >>f, ' failed'
                print >>f, format_exc()
            continue
        if rank==0: 
            print >>f, tool.upper(), method, ':', '%5.1f'%(time()-t0), 'seconds', psinfo()
            frac = diag['dstAreaFractions']
            if frac is not None:
                mask = frac<=1.e-3
                frac[mask] = 1.
                frac = N.resize(frac, varo.shape)
                mask = N.resize(mask, varo.shape)
                varo[:] /= frac
                varo[:] = MV2.masked_where(mask, varo, copy=0)
#        del r
        gc.collect()
        if rank==0: 
            print >>f, ' plot'
            P.figure(figsize=(12, 6))
            P.subplots_adjust(right=0.9)
            P.subplot(121)
            P.pcolormesh(xi, yi, vari[0,0].asma(),vmin=vmin,vmax=vmax)
            P.axis([xmin, xmax, ymin, ymax])
            P.colorbar()
            P.title('Original')
            P.subplot(122)
开发者ID:jfleroux,项目名称:vacumm,代码行数:33,代码来源:test_cdat_regrid_curv2rect.py

示例4: create_time

# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import resize [as 别名]
"""Test :func:`~vacumm.misc.plot.hov2` with a TZ variable"""

# Imports
from vcmq import N, MV2, create_dep, create_time, hov2, os, rc, code_file_name

# Init data with z 1D
nt = 10
nz = 8
var = N.dot(N.hanning(nt).reshape(nt, 1), N.hanning(nz).reshape(1, nz))
var = MV2.array(var)
time = create_time((0., nt), units="days since 2000")
z1d = create_dep((-nz+1, 1.))
var.setAxis(0, time)
var.setAxis(1, z1d)
z2d = N.resize(z1d, var.shape)
z2d *= N.resize((N.arange(1., nt+1)/nt).reshape(1, nt), (nz, nt)).T

# Plot with z 1D
rc('font', size=8)
kw = dict(show=False, bgcolor='0.5', date_fmt="%a")
hov2(var, subplot=211, **kw)

# Plot with z 2D
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
hov2(var, xaxis=z2d, subplot=212, twin='x', savefig=figfile, close=True, **kw)

# Unittest
result = dict(files=figfile)

开发者ID:jfleroux,项目名称:vacumm,代码行数:31,代码来源:test_plot_hov_tz.py

示例5: create_dep

# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import resize [as 别名]
# Imports
from vcmq import N, MV2, cdms2, create_dep, rc, section2, code_file_name, os

# Init data with z 1D
nz = 8
nd = 10
var = N.dot(N.hanning(nz).reshape(nz, 1), N.hanning(nd).reshape(1, nd))
var = MV2.array(var)
d = cdms2.createAxis(N.arange(nd))
d.units='km'
d.long_name='Distance'
z1d = create_dep((-nz+1, 1.))
var.setAxis(0, z1d)
var.setAxis(1, d)
z2d = N.resize(z1d[:].reshape(1, nz), (nd, nz)).T
z2d *= N.arange(1., nd+1)/nd

# Plot with z 1D
rc('font', size=8)
kw = dict(show=False, bgcolor='0.5')
section2(var, subplot=211, **kw)

# Plot with z 2D
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
section2(var, yaxis=z2d, subplot=212, savefig=figfile, close=True, **kw)

# Result
result = dict(files=figfile)
开发者ID:jfleroux,项目名称:vacumm,代码行数:31,代码来源:test_plot_section_zo.py

示例6: rotate_grid

# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import resize [as 别名]
"""Test the fortran function :f:func:`nearest2d`"""
from vcmq import N, P, code_file_name, P, os, rotate_grid, add_grid, meshbounds
from vacumm.misc.grid._interp_ import nearest2d


# Input grid
gridi = rotate_grid((N.arange(5), N.arange(4)), 30)
xxi = gridi.getLongitude()[:].filled()
yyi = gridi.getLatitude()[:].filled()
vari = N.resize(yyi, (20, )+ yyi.shape)
nb = 10
xxbi, yybi = meshbounds(xxi, yyi)

# Output grid
grido = rotate_grid((N.linspace(0, 6, 50)-1, N.linspace(0, 4, 35)+1.), -20)
xxo = grido.getLongitude()[:].filled()
yyo = grido.getLatitude()[:].filled()
xxbo, yybo = meshbounds(xxo, yyo)

# Nearest
varo = nearest2d(vari, xxi, yyi, xxo, yyo, nb)

# Plot
vmin = varo.min()
vmax = varo.max()
P.figure(figsize=(8, 4))
P.subplot(121, aspect=1)
P.pcolor(xxbi, yybi, vari[0], vmin=vmin, vmax=vmax)
add_grid(grido)
P.title('original')
P.subplot(122, aspect=1)
开发者ID:VACUMM,项目名称:vacumm,代码行数:33,代码来源:test_regrid_fortran_nearest2d.py

示例7: meshcells

# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import resize [as 别名]
"""Test the fortran function :f:func:`interp1dx`"""
from vcmq import N, P,meshcells, minmax, code_file_name, os
from vacumm.misc.grid._interp_ import interp1dx


nx = nyi = 10
mv = 1.e20
u, v = N.mgrid[-3:3:nx*1j, -3:3:10j]-2
vari = N.ma.asarray(u**2+v**2)
vari.set_fill_value(mv)
yi = N.linspace(-1000.,0., nyi)
yo = N.linspace(-1200, 100, 30.)
vari[nx/3:2*nx/3, nyi/3:2*nyi/3] = N.ma.masked
x = N.arange(nx)
dyi = (yi[1]-yi[0])*0.49
yyi = N.resize(yi, vari.shape)+N.random.uniform(-dyi, dyi, vari.shape)
yyib, xxib  = meshcells(yyi, x)
yyob, xxob  = meshcells(yo, x)

varon = N.ma.masked_values(interp1dx(vari.filled(), yyi, yo, mv, 0, extrap=0), mv)
varol = N.ma.masked_values(interp1dx(vari.filled(), yyi, yo, mv, 1, extrap=0), mv)
varoh = N.ma.masked_values(interp1dx(vari.filled(), yyi, yo, mv, 3, extrap=0), mv)

kw = dict(vmin=vari.min(), vmax=vari.max())
axlims = [x[0], x[-1], yo[0], yo[-1]]
P.figure(figsize=(8, 8))
P.subplot(221)
P.pcolor(xxib, yyib, vari)
P.axis(axlims)
P.title('Original')
P.subplot(222)
开发者ID:jfleroux,项目名称:vacumm,代码行数:33,代码来源:test_regrid_fortran_interp1dx.py

示例8: create_dep

# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import resize [as 别名]
depi1d = create_dep(N.arange(-4500., 1, 500))
depo1d = create_dep(N.arange(-4000., 1, 333.33))
nzi = depi1d.shape[0]
vari = MV2.asarray(N.ma.resize(depi1d[:], (nt, ny, nx, nzi)).transpose([0, 3, 1, 2]))
vari.setAxis(1, depi1d)
varol1 = regrid1d(vari, depo1d, method='linear')
varol2 = regrid1d(vari, depo1d, method='linear', iaxi=0, iaxo=0, axi=depi1d)
result.append(('assertEqual', [(varol1-varol2).std(), 0]))
varoc = regrid1d(vari, depo1d, method='cellave')
myplot(vari, depi1d, varol1, varoc, depo1d, code_file_name(ext='_0.png'))


# 4d->1d
depi1d = N.arange(-4500., 1, 500)
nzi = depi1d.shape[0]
depi4d = N.resize(N.resize(depi1d, (nx, ny, nzi)).T, (nt, nzi, ny, nx))
depi4d += 500*(N.random.random(depi4d.shape)-0.5)
depo1d = create_dep(N.arange(-4000., 1, 333.33))
vari = MV2.array(depi4d, fill_value=1e20)
vari.getAxis(1).designateLevel()
depi4d = MV2.asarray(depi4d)
depi4d.getAxis(1).designateLevel()
varol1 = regrid1d(vari, depo1d, method='linear', axi=depi4d)
varol2 = regrid1d(vari, depo1d, method='linear', iaxi=1, axi=depi4d)
result.append(('assertEqual', [(varol1-varol2).std(), 0]))
varoc = regrid1d(vari, depo1d, method='cellave', iaxi=1, axi=depi4d)
myplot(vari, depi4d, varol1, varoc, depo1d, code_file_name(ext='_1.png'))


# 4d->4d
depi1d = N.arange(-4500., 1, 500)
开发者ID:jfleroux,项目名称:vacumm,代码行数:33,代码来源:test_regrid_regrid1d.py

示例9: dict

# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import resize [as 别名]
"""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'], 
开发者ID:jfleroux,项目名称:vacumm,代码行数:33,代码来源:test_plot_taylor.py


注:本文中的vcmq.N.resize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。