根据Most efficient way to calculate radial profile,我想计算相同的值,但不是平均值,我想为每个径向bin使用中位数。我写了这些函数:
def radial_median(background,rs = None,is_fft_shifted = True):
if rs is None :
i = np.fft.fftfreq(background.shape[0]) * background.shape[0]
j = np.fft.fftfreq(background.shape[1]) * background.shape[1]
k = np.fft.fftfreq(background.shape[2]) * background.shape[2]
i,j,k = np.meshgrid(i,k,indexing='ij')
rs = np.sqrt(i**2 + j**2 + k**2).astype(np.int16)
if is_fft_shifted is False :
rs = np.fft.fftshift(rs)
rs = rs.ravel()
ind = np.argsort(rs.flat) # get sorted indices
sr = rs.flat[ind] # sorted radii
ri = sr.astype(np.int32) # integer part of radii (bin size = 1)
ri = np.array(list(set(ri)))
# calculate the median
f = lambda r: np.nanmedian(background[(rs >= r - .5) & (rs < r + .5)])
# vectorize median function
radial_median_profile = np.vectorize(f)(ri)
background = radial_median_profile[rs].reshape(background.shape)
return background,rs,radial_median_provile
def av_radial_median_profile(x,y,data):
Int,median_profile = radial_median(data,rs=np.rint(np.sqrt(x**2+y**2)).astype(np.int))
return Int
但是我遇到了这个问题:
Traceback (most recent call last):
File "maskMakerGUI.py",line 1211,in radial_median_substraction
m_background = av_radial_median_profile(self.x_map,self.y_map,dist,self.cspad.copy(),self.mask_clicked.copy(),pol_bool)
File "maskMakerGUI.py",line 317,in av_radial_median_profile
Int,median_profile = radial_median(Int.reshape(data.shape),rs=np.rint(np.sqrt(x**2+y**2)).astype(np.int))
File "maskMakerGUI.py",line 284,in radial_median
background = radial_median_profile[rs].reshape(background.shape)
IndexError: index 1145 is out of bounds for axis 0 with size 1145
我不明白为什么会出现此错误。
data.shape,x.shape和y.shape =(1480,1552) 我不得不使用Python 3.6。 我将非常感谢您的任何建议或更正。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。