本文整理汇总了Python中vcmq.N.arange方法的典型用法代码示例。如果您正苦于以下问题:Python N.arange方法的具体用法?Python N.arange怎么用?Python N.arange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vcmq.N
的用法示例。
在下文中一共展示了N.arange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import arange [as 别名]
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: create_lon
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import arange [as 别名]
#!/usr/bin/env python
# -*- coding: utf8 -*-
"""Axes et grilles avec VACUMM"""
from vcmq import N, MV2, create_lon, create_lat, create_grid, isgrid, isrect, islon, set_grid, get_grid, get_axis, varsel, resol, curv2rect, get_xy, meshgrid, meshcells, create_dep, isregular, P, rotate_grid, shiftgrid, extendgrid, create_axes2d, isdepthup, coord2slice, monotonic, xshift, depth2dz, get_closest
# Créer
# - axes
lon = create_lon((2., 11, 2.)) # -> SPECIFIEZ LE LONG_NAME
lat = create_lat(N.arange(43, 50.))
dep = create_dep((0., 10))
# -> AFFICHEZ LES INFOS
xx, yy = N.meshgrid(N.arange(5.), N.arange(4.))
lon2d, lat2d = create_axes2d(xx, yy)
ii = lon2d.getAxis(1)
# - grille
grid = create_grid(lon, lat) # -> ESSAYEZ AVEC LON EXPLICITE
gridc = create_grid(lon2d, lat2d)
# Verifier
print islon(lon)
print isgrid(grid) # -> TEST PARAM CURV=...
print isrect(gridc) # -> CREEZ GRILLE NON RECT ET RETESTER
print isdepthup(dep) # -> TESTEZ EN CHANGEANT ATTRIBUT POSITIVE ET VALEURS
print isregular(lon)
# Affecter
示例3: create_lon
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import arange [as 别名]
"""Test :func:`~vacumm.misc.plot.section2` in quiver mode"""
# Imports
from vcmq import create_lon, N, MV2, create_dep, os, code_file_name, section2
from vacumm.misc.phys.units import deg2m
# Init data with z 1D
nz = 11
nx = 11
x = create_lon(N.arange(nx))
xm = deg2m(x[:],lat=45.) # meters
dx = xm[:].ptp()
z = create_dep((-nz+1, 1.), units='m', long_name='Depth')
dz = z[:].ptp()
scale = dz/dx
u = MV2.ones((nz,nx)) # 1 m/s
w = u*scale # 1 m/s * scale
for var in u,w:
var.setAxis(0, z)
var.setAxis(1, x)
var.units = 'm/s'
# Plot
figfile = code_file_name(ext='png')
if os.path.exists(figfile): os.remove(figfile)
s = section2((u,w), quiver_norm=1, fill=False, show=False,
savefig=figfile, close=False, axes_aspect=1)
# Result
result = dict(files=figfile)
示例4: create_time
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import arange [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)
示例5: int
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import arange [as 别名]
"""Test fortran function :f:func:`nearest2dto1d`"""
from vcmq import P, N, code_file_name, os, add_grid
from vacumm.misc.grid._interp_ import nearest2dto1d
# Input grid and data
nxy = 15
xi = N.arange(nxy*1.)
yi = N.arange(nxy*1.)
xxi, yyi = N.meshgrid(xi, yi)
zi = N.ma.array(yyi)
zi[int(nxy*0.3):int(nxy*0.8), int(nxy*0.3):int(nxy*0.8)] = N.ma.masked
zi.shape = 1, nxy, nxy
# Output positions
no = 1000
xo = N.random.uniform(-nxy/4., nxy+nxy/4., no)
yo = N.random.uniform(-nxy/4., nxy+nxy/4., no)
# Interpolate
mv = zi.get_fill_value()
zo = nearest2dto1d(xi,yi,zi.filled(mv),xo,yo,mv)
zo = N.ma.masked_values(zo, mv)
# Plot
kw = dict(vmin=zi.min(), vmax=zi.max())
P.figure(figsize=(6, 6))
P.subplot(111, aspect=1)
P.contourf(xxi, yyi, zi[0], **kw)
add_grid((xi, yi), edges=False, centers=True, marker='o')
示例6: create_dep
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import arange [as 别名]
ax = P.subplot(131)
P.pcolormesh(xbi, ybi, vi, **kw)
P.title('Original')
P.subplot(132, sharex=ax, sharey=ax)
P.pcolormesh(xbo, ybo, vol, **kw)
P.title('Linear')
P.subplot(133, sharex=ax, sharey=ax)
P.pcolormesh(xbo, ybo, voc, **kw)
P.ylim(ymin=min(ybi.min(), ybo.min()), ymax=max(ybi.max(), ybo.max()))
P.title('Cellave')
P.tight_layout()
P.savefig(figfile)
# 1d->1d
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))
示例7: int
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import arange [as 别名]
"""Test the :func:`~vacumm.misc.grid.regridding.regrid2d` function"""
from vcmq import P, N, MV2, code_file_name, os, add_grid, rotate_grid, set_grid, \
create_grid, rc, rcdefaults, plot2d
from vacumm.misc.grid.regridding import regrid2d
# Input grid and data
nxi = 20
nyi = 15
# - rect
xi = N.arange(nxi*1.)
yi = N.arange(nyi*1.)
gridri = create_grid(xi, yi)
xxri, yyri = N.meshgrid(xi, yi)
zzri = N.ma.array(yyri)
zzri[int(nyi*0.3):int(nyi*0.6), int(nxi*0.3):int(nxi*0.6)] = N.ma.masked
varri = MV2.asarray(zzri)
set_grid(varri, gridri)
# - curv
gridci = rotate_grid(gridri, 30)
xxci = gridci.getLongitude().getValue()
yyci = gridci.getLatitude().getValue()
zzci = N.ma.array(yyci)
zzci[int(nyi*0.3):int(nyi*0.6), int(nxi*0.3):int(nxi*0.6)] = N.ma.masked
varci = MV2.asarray(zzci)
set_grid(varci, gridci)
# Output positions
nxo = 25
nyo = 18
# - rect
示例8: f
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import arange [as 别名]
sp = f("speed")
spe = f("speed_error")
f.close()
# Create hourly time axis
taxi = sp.getTime()
taxi.toRelativeTime("hours since 2000")
ctimesi = taxi.asComponentTime()
ct0 = round_date(ctimesi[0], "hour")
ct1 = round_date(ctimesi[-1], "hour")
taxo = create_time(lindates(ct0, ct1, 1, "hour"), taxi.units)
# Lag error
# - estimation
els = []
lags = N.arange(1, 6)
for lag in lags:
els.append(N.sqrt(((sp[lag:] - sp[:-lag]) ** 2).mean()))
els = N.array(els)
a, b, _, _, _ = linregress(lags, els)
# - plot
P.figure(figsize=(6, 6))
P.subplot(211)
P.plot(lags, els, "o")
P.plot([0, lags[-1]], [b, a * lags[-1] + b], "g")
P.axhline(b, color="0.8", ls="--")
P.ylim(ymin=0)
P.xlabel("Lag [hour]")
P.ylabel("Error [m s-1]")
add_key(1)
P.title("Linear lag error model")
示例9: range
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import arange [as 别名]
"""Test the fortran function :f:func:`curv2rel_single`"""
from vcmq import N, P, code_file_name, P, os, meshbounds
from vacumm.misc.grid._interp_ import curv2rel_single
# Input grid
x0, y0 = 0., 2.
nxi = 3
nyi = 3
dxi = (2., 2.)
dyi = (-2., 2.)
xxi = N.zeros((nyi, nxi))
xxi[0] = x0 + N.arange(nxi) * dxi[0]
for j in range(1, nyi):
xxi[j] = xxi[j-1] + dyi[0]
yyi = N.zeros((nyi, nxi))
yyi[:, 0] = y0 + N.arange(nyi) * dyi[1]
for j in range(1, nyi):
yyi[:, j] = yyi[:, j-1] + dxi[1]
xxbi, yybi = meshbounds(xxi, yyi)
relpos2index = lambda fi, fj, nyi: fj * nyi + fi
ii, jj = N.meshgrid(N.arange(nxi)+.5, N.arange(nyi)+.5)
iib, jjb = meshbounds(ii, jj)
zzi = relpos2index(ii, jj, nyi)
zzbi = relpos2index(iib, jjb, nyi)
# Input random points
N.random.seed(0)
np = 100
xxo = N.random.random(np)*(xxbi.max()-xxbi.min()) + xxbi.min()
yyo = N.random.random(np)*(yybi.max()-yybi.min()) + yybi.min()
示例10: create_dep
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import arange [as 别名]
"""Test :func:`~vacumm.misc.plot.section2` with a Z- variable"""
# 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)
示例11: zip
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import arange [as 别名]
"""Test the fortran function :f:func:`curv2rect`"""
from vcmq import N, P, code_file_name, P, os
from vacumm.misc.grid._interp_ import curv2rect
# Input
x1, y1 = 0., 0.
x2, y2 = 3., 1.
x3, y3 = 2., 4.
x4, y4 = -1., 2.
# Format and convert
xx, yy = N.meshgrid(N.arange(-2, 4, 0.25), N.arange(-1, 5, 0.25))
nxy = xx.shape
xx.shape = -1
yy.shape = -1
pp, qq = [], []
for x, y in zip(xx, yy):
p, q = curv2rect(x1,x2,x3,x4,y1,y2,y3,y4,x,y)
pp.append(p)
qq.append(q)
pp = N.array(pp)
qq = N.array(qq)
# Plot
xp = [x1, x2, x3, x4, x1]
yp = [y1, y2, y3, y4, y1]
P.subplot(211)
levels = N.array([-10, 0, 1, 10.])
o = P.contourf(xx.reshape(nxy), yy.reshape(nxy), pp.reshape(nxy), levels=levels)
P.colorbar(o)
P.plot(xp, yp, 'k')
示例12: open
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import arange [as 别名]
"""Compare CDAT regridding speed with rectangular and rectangular grids"""
config = {
'esmf':['linear', 'patch', 'conserv'],
'libcf':['linear'],
}
# Imports
from vcmq import MV2, create_grid2d, code_file_name, os, CDATRegridder, N, set_grid, psinfo
from vacumm.misc.grid import rotate_grid
from time import time
# Input
nx = ny = 300
vari = MV2.array(N.arange(nx*ny*1.).reshape(ny, nx))
gridi = create_grid2d(vari.getAxis(1)[:]*50/nx, vari.getAxis(0)[:]*50/nx)
set_grid(vari, gridi)
# Output grid
gridor = create_grid2d(vari.getAxis(1)[:]*0.09*50/nx,
vari.getAxis(0)[:]*0.09*50/nx)
gridoc = rotate_grid(gridi, 30)
# Log
logfile = code_file_name(ext='log')
if os.path.exists(logfile): os.remove(logfile)
f = open(logfile, 'w')
print >>f, 'NY=%(ny)i, NX=%(nx)i'%locals()
# Loop on methods
for tool, methods in config.items():
示例13: rotate_grid
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import arange [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)
示例14: meshbounds
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import arange [as 别名]
"""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',
示例15: rotate_grid
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import arange [as 别名]
"""Test the class :class:`~vacumm.misc.grid.regridding.CurvedInterpolator`"""
from vacumm.misc.grid.misc import rotate_grid
from vacumm.misc.grid.regridding import CurvedInterpolator
from vcmq import P, N, set_grid, plot2d, MV2, add_grid, code_file_name, os
# Curved grid
nxy = 10
lon = N.arange(nxy*1.)
lat = N.arange(nxy*1.)
gridi = rotate_grid((lon, lat), 30)
xxi = gridi.getLongitude()[:].filled()
yyi = gridi.getLatitude()[:].filled()
vari = MV2.array(yyi)
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.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)
P.subplot(132, aspect=1)