- 积分
- 723
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2012-2-7
- 最后登录
- 1970-1-1
|
发表于 2013-9-28 10:25:25
|
显示全部楼层
Interp2d 主要针对不规则的散点资料,对于格点资料用scipy.ndimage或map_coordinates
ndimage的zoom可以放大一个数组:
“Zooming" an array (scipy.ndimage.zoom)
As a quick example (This will use cubic interpolation. Use order=1 for bilinear, order=0 for nearest, etc.):
import numpy as np
import scipy.ndimage as ndimage
data = np.arange(9).reshape(3,3)
print 'Original:\n', data
print 'Zoomed by 2x:\n', ndimage.zoom(data, 2)
This yields:
Original:
[[0 1 2]
[3 4 5]
[6 7 8]]
Zoomed by 2x:
[[0 0 1 1 2 2]
[1 1 1 2 2 3]
[2 2 3 3 4 4]
[4 4 5 5 6 6]
[5 6 6 7 7 7]
[6 6 7 7 8 8]]
基于这两个函数,JohannesBuchner做了一个regulargrid包,用于插值规则格点资料(下载地址见regulargrid)
用法:
插值函数一:
Cartesian grid regulargrid.cartesiangrid.CartesianGrid (equal spacing between points)
Uses very fast implementation based on scipy.ndimage.map_coordinates
Example:
- # create a 3-dimensional cartesian grid:
- limits = [(0, 1), (0, 1), (0, 1)]
- x = numpy.linspace(0, 1, 8)
- y = numpy.linspace(0, 1, 9)
- z = numpy.linspace(0, 1, 10)
- Z, Y = numpy.meshgrid(z, y)
- X = numpy.array([[x]]).transpose()
- # our grid values
- values = X**2 + Y - Z
- from regulargrid.cartesiangrid import CartesianGrid
- # does linear interpolation
- grid = CartesianGrid(limits, values)
- # interpolate for one point
- print grid([0.1], [0.5], [0.3])
- # interpolate many
- print grid([0.1, 0.3], [0.5, 0.5], [0.3, 0.2])
插值函数二:
Regular grid regulargrid.regulargrid.RegularGrid (unequal spacing between points)
该函数作者没给例程,估计用法跟上述用法一致 |
|