2017-02-24 417 views
0

我的问题是,当我运行下面的代码,我收到以下错误令人费解使用scipy.ndimage.interpolation.shift(),IndexError:只有整数,切片(`:`)

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices 

出现由于函数:scipy.ndimage.interpolation.shift(输入,移位,输出=无,顺序= 3,模式='常量',cval = 0.0,prefilter = True)

这令我感到困惑,因为在“https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.ndimage.interpolation.shift.html#scipy-ndimage-interpolation-shift

上给出的函数定义如下:

“shift:浮动或顺序,可选

沿轴移动。如果浮动,每个轴的换档都相同。 “

该错误明确指出,值应该是int,而定义明确要求浮点值。我尝试插入'shift'和代码的整数值我也尝试将数据移动到一个ndarray中,但仍然发生错误

所以我想要做的就是根据“coords”数组中的浮点值以亚像素分辨率移动图像。我要么不正确地理解定义或错误消息,并且想知道为什么我的功能实现不起作用。

pa_float = [float(x) for x in pa_list] 
dist_float =[float(x) for x in dist_list] 
pa_rad_list = np.radians(pa_float) 

x_coord = np.multiply(np.cos(pa_rad_list), dist_float)*(-1)*(512) 
y_coord = np.multiply(np.sin(pa_rad_list), dist_float)*(512) 
# The first number in x_coord and the first number in y_coord represent the first coordinate pair.... and so on for the second..n th 
coords = np.column_stack((x_coord,y_coord)) # shape (72,12) 

for data in glob.glob(ImageFolderPath+'/*icn.rest_avg.fits'): 
    scidata0 = fits.getdata(data,0) 
    scidata0[0,0,:,:] = ndimage.interpolation.shift(scidata0[0,0,:,:], coords[data,:], order=3,mode='nearest',prefilter=True) 
    finalarray.append(scidata0) 

回答

0

所以我想出了问题。 'data'参数不像for循环中的典型计数器,而是包含文件名的字符串。 在for循环中添加一个计数器并将“数据”更改为函数中的该计数器将解决该问题。

for data in glob.glob(ImageFolderPath+'/*icn.rest_avg.fits'): 
scidata0 = fits.getdata(data,0) 
scidata0[0,0,:,:] = ndimage.interpolation.shift(scidata0[0,0,:,:], coords[i,:], order=3, mode='nearest', prefilter=True) 
finalarray.append(scidata0) 
i+=1 
相关问题