Radial Median Substraction Python 3.6

в продолжении данного поста Радиальный бэкграунд (radial mean, radial median) Python, хочу приложить последующие попытки решения данной проблемы за счёт ниже написанного куска кода.

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, j, 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, rs, 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, rs, 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 and y.shape = (1480, 1552)

Буду благодарен любым наводкам и объяснениям.


Ответы (0 шт):