我的问题是,当我运行下面的代码时,出现以下令人费解的错误
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)
该定义指出:
"shift : 浮点数或序列,可选
沿轴的偏移。如果是浮点数,则每个轴的移位都是相同的。如果是一个序列,则 shift 应该为每个轴包含一个值。”
错误明确指出值应该是 int,而定义明确要求浮点值。我尝试为“shift”插入整数值,代码运行良好。我也尝试将数据移动到 ndarray 中,但仍然发生错误。
所以我想要做的是根据“坐标”数组中的浮点值移动图像,具有亚像素分辨率。我要么不正确理解定义或错误消息,并且想知道为什么我的函数实现不起作用。
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)