0

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

4

1 に答える 1

1

のドキュメントを参照してくださいmap_coordinates。補間しようとしている実際のデータがコードのどこにあるかわかりません。私が言いたいのは、おそらくあなたは と の関数であるデータを持っているということinputです。つまり、補間したいということです。最初に示した例では、これは arrayです。これは への最初の引数である必要があります。xyinput = f(x,y)fvalsmap_coordinates

たとえば、補間しようとしているデータが である場合input、これは shape の 2 次元配列である必要があり(len(x),len(y))、補間されたデータは次のようになります。

interpolated_data = map_coordinates(input, coords)
于 2012-07-09T22:39:57.623 に答える