Scipy Cookbook 関数をコピーしようとしています:
from scipy import ogrid, sin, mgrid, ndimage, array
x,y = ogrid[-1:1:5j,-1:1:5j]
fvals = sin(x)*sin(y)
newx,newy = mgrid[-1:1:100j,-1:1:100j]
x0 = x[0,0]
y0 = y[0,0]
dx = x[1,0] - x0
dy = y[0,1] - y0
ivals = (newx - x0)/dx
jvals = (newy - y0)/dy
coords = array([ivals, jvals])
newf = ndimage.map_coordinates(fvals, coords)
多くのシナリオで機能する必要がある独自の関数を使用する
import scipy
import numpy as np
"""N-D interpolation for equally-spaced data"""
x = np.c_[plist['modx']]
y = np.transpose(np.c_[plist['mody']])
pdb.set_trace()
#newx,newy = np.meshgrid(plist['newx'],plist['newy'])
newx,newy = scipy.mgrid[plist['modx'][0]:plist['modx'][-1]:-plist['remapto'],
plist['mody'][0]:plist['mody'][-1]:-plist['remapto']]
x0 = x[0,0]
y0 = y[0,0]
dx = x[1,0] - x0
dy = y[0,1] - y0
ivals = (newx - x0)/dx
jvals = (newy - y0)/dy
coords = scipy.array([ivals, jvals])
for i in np.arange(ivals.shape[0]):
nvals[i] = scipy.ndimage.map_coordinates(ivals[i], coords)
このコードを正しく動作させるのに苦労しています。問題の領域は次のとおりです。 1.) 次の行を再作成します: newx,newy = mgrid[-1:1:100j,-1:1:100j]。私の場合、ベクトル形式のグリッドを持つ辞書があります。np.meshgrid を使用してこの行を再作成しようとしましたが、行 coords = scipy.array([ivals, jvals]) でエラーが発生します。このクックブック関数を再作成し、より動的にするための助けを探しています。どんな助けも大歓迎です。
/M