def test_radial_profile(): from lenstronomy.LightModel.Profiles.gaussian import Gaussian gauss = Gaussian() x, y = util.make_grid(11, 1) flux = gauss.function(x, y, sigma=10, amp=1) data = util.array2image(flux) profile_r = image_util.radial_profile(data, center=[5, 5]) profile_r_true = gauss.function(np.linspace(0, stop=7, num=8), 0, sigma=10, amp=1) npt.assert_almost_equal(profile_r, profile_r_true, decimal=3)
def mge_kernel(kernel, order=5): """ azimutal Multi-Gaussian expansion of a pixelized kernel :param kernel: 2d numpy array :return: """ # radial average n = len(kernel) center = (n - 1) / 2. psf_r = image_util.radial_profile(kernel, center=[center, center]) # MGE of radial average n_r = len(psf_r) r_array = np.linspace(start=0., stop=n_r - 1, num=n_r) amps, sigmas, norm = mge.mge_1d(r_array, psf_r, N=order, linspace=True) return amps, sigmas, norm
def fwhm_kernel(kernel): """ :param kernel: :return: """ n = len(kernel) center = (n - 1) / 2. I_r = image_util.radial_profile(kernel, center=[center, center]) if n % 2 == 0: raise ValueError('only works with odd number of pixels in kernel!') max_flux = kernel[int((n-1)/2), int((n-1)/2)] I_2 = max_flux / 2. r = np.linspace(0, (n - 1) / 2, int((n + 1) / 2)) + 0.33 for i in range(1, len(I_r)): if I_r[i] < I_2: fwhm_2 = (I_2 - I_r[i - 1]) / (I_r[i] - I_r[i - 1]) + r[i - 1] return fwhm_2 * 2 raise ValueError('The kernel did not drop to half the max value - fwhm not determined!')