本文整理汇总了Python中vcmq.N.meshgrid方法的典型用法代码示例。如果您正苦于以下问题:Python N.meshgrid方法的具体用法?Python N.meshgrid怎么用?Python N.meshgrid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vcmq.N
的用法示例。
在下文中一共展示了N.meshgrid方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SimpleCloudKriger
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import meshgrid [as 别名]
# Input
xi = [20., 26., 50., 70]
yi = [20, 26., 70., 20]
zi = [15., 6., 2., 4.]
# Output positions
nx = ny = 101
xg = N.linspace(1, 100, 101)
yg = N.linspace(1, 100, 101)
# Some inits
xi = N.array(xi)
yi = N.array(yi)
zi = N.array(zi)
xxg, yyg = N.meshgrid(xg, yg)
xo = xxg.ravel()
yo = yyg.ravel()
vgm = variogram_model('linear', n=0, s=sill, r=range)
# Setup the kriger
sck = SimpleCloudKriger(xi, yi, zi, vgf=vgm, farvalue=farvalue)
# Interpolate
zo = sck(xo, yo)
# Check a far value
zzg = zo.reshape(ny, nx)
N.testing.assert_allclose(zzg[-1, -1],farvalue)
# Plot
示例2: create_lon
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import meshgrid [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_grid
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import meshgrid [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
示例4: int
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import meshgrid [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')
示例5: gridded_gauss3
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import meshgrid [as 别名]
"""Test function :func:`~vacumm.misc.grid.kriging.krig` for grid refinement"""
nxi = 15
nyi = 10
r = 3
from vcmq import P, savefigs, code_file_name, N, auto_scale, add_grid
from vacumm.misc.grid.kriging import gridded_gauss3, random_gauss3, random_points, krig
# Generate random gridded field
xi, yi, zzi = gridded_gauss3(nx=nxi, ny=nyi)
xxi, yyi = N.meshgrid(xi, yi)
# Refined grid
xo = N.linspace(xi[0], xi[-1], (nxi-1)*r+1)
yo = N.linspace(yi[0], yi[-1], (nyi-1)*r+1)
xxo, yyo = N.meshgrid(xo, yo)
# Interpolate
zzo = krig(xxi.ravel(), yyi.ravel(), zzi.ravel(), xxo.ravel(), yyo.ravel())
zzo.shape = xxo.shape
# Section
P.figure(figsize=(8, 4))
iyis = [3, 4]
for iyi in iyis:
label = iyi==iyis[0]
P.plot(xi, zzi[iyi], 'ob-', markersize=8, label='Original' if label else None)
P.plot(xo, zzo[iyi*r], 'or-', markersize=5, lw=.8, label='Interpolated' if label else None)
P.legend(loc='best', framealpha=0.5)
P.grid()
示例6: range
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import meshgrid [as 别名]
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()
xxo = N.concatenate((xxo, xxi.ravel()))
yyo = N.concatenate((yyo, yyi.ravel()))
np = xxo.size
# Convert to relative indices
zzo = N.zeros(np)-1
示例7: zip
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import meshgrid [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')
示例8: rotate_grid
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import meshgrid [as 别名]
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)
P.scatter(xg, yg, c=varog.asma(), s=120, linewidth=0, **kw)
add_grid(gridi, edges=False, centers=-1)
xylims = (xxi.min(), xxi.max(), yyi.min(), yyi.max())
P.axis(xylims)
P.title('Interp to grid')
# Interpolate to grid
nr = 40
xr = P.random(nr)*nxy
yr = P.random(nr)*nxy
cir = CurvedInterpolator(gridi, (xr, yr))
示例9: OrderedDict
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import meshgrid [as 别名]
from vcmq import create_grid2d, meshbounds, set_grid, code_file_name, P, N, MV2, rc, add_grid
from collections import OrderedDict
configs = OrderedDict(
libcf=['linear'],
esmf=[
'linear',
'patch',
'conservative',
]
)
# Input curved grid
nxi = 5
nyi = 4
xxi, yyi = N.meshgrid(N.arange(nxi)+.25, N.arange(nyi)-.25)
for j in xrange(nyi):
xxi[j,:] -= j*0.5
#yyi[j,:] += j
for i in xrange(nxi):
yyi[:,i] += i*0.5
gridi = create_grid2d(xxi,yyi) # input cdms grid
xxib,yyib = meshbounds(xxi,yyi) # coordinates of cell corners
# Output curved grid
nxo = 7
nyo = 7
xxo, yyo = N.meshgrid(N.arange(nxo)+.5, N.arange(nyo)-.5)
grido = create_grid2d(xxo, yyo) # output cdms grid
xxob,yyob = meshbounds(xxo,yyo) # coordinates of cell corners
示例10: xrange
# 需要导入模块: from vcmq import N [as 别名]
# 或者: from vcmq.N import meshgrid [as 别名]
"""Test :func:`~vacumm.misc.grid.regridding.extend1d` and :func:`~vacumm.misc.grid.regridding.extend2d`"""
from vcmq import N, create_grid2d, P, rc, plot2d, MV2, set_grid, savefigs, code_file_name
from vacumm.misc.grid.regridding import extend1d, extend2d
# Input data
nxi = 4
nyi = 3
xxi, yyi = N.meshgrid(N.arange(nxi)+.25, N.arange(nyi)-.25)
for j in xrange(nyi):
xxi[j,:] -= j*0.5
for i in xrange(nxi):
yyi[:,i] += i*0.5
gridi = create_grid2d(xxi,yyi) # input cdms grid
vari = MV2.array(N.arange(nyi*nxi).reshape(nyi,nxi))+10.
set_grid(vari, gridi) # set grid and axes
# Extend and plot
rc('font', size=9)
P.figure(figsize=(6, 6))
kw = dict(xmin=xxi.min()-3, xmax=xxi.max()+3, ymin=yyi.min()-3,
ymax=yyi.max()+3, show=False, xhide='auto', yhide='auto')
# - original
plot2d(vari, title='Original', subplot=(2, 2, 1), **kw)
# - extend1d
for i, (axis, ext, mode) in enumerate([(-1, (2, 2), 'same'), (-2, 2, 'linear')]):
varo = extend1d(vari, ext=ext, axis=axis, mode=mode)
plot2d(varo, subplot=(2, 2, i+3),
title='interp1d: axis=%s\next=%s, mode=%s'%(axis, ext, mode), **kw)
varo = extend2d(vari, iext=2, jext=2, mode='linear')
plot2d(varo, subplot=(2, 2, 2),