def test_spemd(self): from lenstronomy.LensModel.Profiles.spep import SPEP from lenstronomy.LensModel.Profiles.multi_gaussian_kappa import MultiGaussianKappa spep = SPEP() mge_kappa = MultiGaussianKappa() n_comp = 8 theta_E = 1.41 kwargs = {'theta_E': theta_E, 'e1': 0, 'e2': 0, 'gamma': 1.61} rs = np.logspace(-2., 1., 100) * theta_E f_xx, f_yy, f_xy = spep.hessian(rs, 0, **kwargs) kappa = 1 / 2. * (f_xx + f_yy) amplitudes, sigmas, norm = mge.mge_1d(rs, kappa, N=n_comp) kappa_mge = self.multiGaussian.function(rs, np.zeros_like(rs), amp=amplitudes, sigma=sigmas) f_xx_mge, f_yy_mge, f_xy_mge = mge_kappa.hessian(rs, np.zeros_like(rs), amp=amplitudes, sigma=sigmas) for i in range(0, 80): npt.assert_almost_equal(kappa_mge[i], 1. / 2 * (f_xx_mge[i] + f_yy_mge[i]), decimal=1) npt.assert_almost_equal((kappa[i] - kappa_mge[i]) / kappa[i], 0, decimal=1) f_ = spep.function(theta_E, 0, **kwargs) f_mge = mge_kappa.function(theta_E, 0, sigma=sigmas, amp=amplitudes) npt.assert_almost_equal(f_mge / f_, 1, decimal=2)
def test_nfw_sersic(self): kwargs_lens_nfw = {'alpha_Rs': 1.4129647849966354, 'Rs': 7.0991113634274736} kwargs_lens_sersic = {'k_eff': 0.24100561407593576, 'n_sersic': 1.8058507329346063, 'R_sersic': 1.0371803141813705} from lenstronomy.LensModel.Profiles.nfw import NFW from lenstronomy.LensModel.Profiles.sersic import Sersic nfw = NFW() sersic = Sersic() theta_E = 1.5 n_comp = 10 rs = np.logspace(-2., 1., 100) * theta_E f_xx_nfw, f_xy_nfw, f_yx_nfw, f_yy_nfw = nfw.hessian(rs, 0, **kwargs_lens_nfw) f_xx_s, f_xy_s, f_yx_s, f_yy_s = sersic.hessian(rs, 0, **kwargs_lens_sersic) kappa = 1 / 2. * (f_xx_nfw + f_xx_s + f_yy_nfw + f_yy_s) amplitudes, sigmas, norm = mge.mge_1d(rs, kappa, N=n_comp) kappa_mge = self.multiGaussian.function(rs, np.zeros_like(rs), amp=amplitudes, sigma=sigmas) from lenstronomy.LensModel.Profiles.multi_gaussian_kappa import MultiGaussianKappa mge_kappa = MultiGaussianKappa() f_xx_mge, f_xy_mge, f_yx_mge, f_yy_mge = mge_kappa.hessian(rs, np.zeros_like(rs), amp=amplitudes, sigma=sigmas) for i in range(0, 80): npt.assert_almost_equal(kappa_mge[i], 1. / 2 * (f_xx_mge[i] + f_yy_mge[i]), decimal=1) npt.assert_almost_equal((kappa[i] - kappa_mge[i]) / kappa[i], 0, decimal=1) f_nfw = nfw.function(theta_E, 0, **kwargs_lens_nfw) f_s = sersic.function(theta_E, 0, **kwargs_lens_sersic) f_mge = mge_kappa.function(theta_E, 0, sigma=sigmas, amp=amplitudes) npt.assert_almost_equal(f_mge / (f_nfw + f_s), 1, decimal=2)