Using scipy.ndimage.interpolation.shift(), IndexError: only integers, slices (`:`)

Using scipy.ndimage.interpolation.shift(), IndexError: only integers, slices (`:`)

我的问题是,当我 运行 下面的代码时,我得到以下令人费解的错误

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

由于函数而出现:scipy.ndimage.interpolation.shift(input, shift, output=None, order=3, mode='constant', 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 : float or sequence, optional

沿轴的偏移。如果是浮动,则每个轴的移位相同。如果是一个序列,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)

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

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