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)
上给出的函数定义如下:
“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)