0

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

 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上给出的函数的定义,这让我感到困惑-插值移位

该定义指出:

"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)
4

1 回答 1

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
于 2017-02-25T11:42:01.213 回答