def test_lens_model_correspondence(self): """ here we test the proportionality of the convergence of the lens model with the surface brightness of the light model """ chameleon_lens = ChameleonLens() chameleon = Chameleon() x, y = util.make_grid(numPix=100, deltapix=0.1) e1, e2 = 0., 0 w_c, w_t = 0.5, 1. kwargs_light = {'amp': 1., 'w_c': w_c, 'w_t': w_t, 'e1': e1, 'e2': e2} kwargs_lens = { 'alpha_1': 1., 'w_c': w_c, 'w_t': w_t, 'e1': e1, 'e2': e2 } flux = chameleon.function(x=x, y=y, **kwargs_light) f_xx, f_xy, f_yx, f_yy = chameleon_lens.hessian(x=x, y=y, **kwargs_lens) kappa = 1 / 2. * (f_xx + f_yy) # flux2d = util.array2image(flux) # kappa2d = util.array2image(kappa) npt.assert_almost_equal(flux / np.mean(flux), kappa / np.mean(kappa), decimal=3)
def test_derivatives(self): """ :return: """ triplechameleon = TripleChameleon() chameleon = Chameleon() x = np.linspace(0.1, 10, 10) phi_G, q = 0.3, 0.8 ratio12 = 2. ratio13 = 3 e1, e2 = param_util.phi_q2_ellipticity(phi_G, q) kwargs_light = {'alpha_1': 1., 'ratio12': ratio12, 'ratio13': ratio13, 'w_c1': .5, 'w_t1': 1., 'e11': e1, 'e21': e2, 'w_c2': .1, 'w_t2': .5, 'e12': e1, 'e22': e2, 'w_c3': .1, 'w_t3': .5, 'e13': e1, 'e23': e2 } amp1 = 1. / (1. + 1. / ratio12 + 1. / ratio13) amp2 = amp1 / ratio12 amp3 = amp1 / ratio13 kwargs_1 = {'alpha_1': amp1, 'w_c': .5, 'w_t': 1., 'e1': e1, 'e2': e2} kwargs_2 = {'alpha_1': amp2, 'w_c': .1, 'w_t': .5, 'e1': e1, 'e2': e2} kwargs_3 = {'alpha_1': amp3, 'w_c': .1, 'w_t': .5, 'e1': e1, 'e2': e2} f_x, f_y = triplechameleon.derivatives(x=x, y=1., **kwargs_light) f_x1, f_y1 = chameleon.derivatives(x=x, y=1., **kwargs_1) f_x2, f_y2 = chameleon.derivatives(x=x, y=1., **kwargs_2) f_x3, f_y3 = chameleon.derivatives(x=x, y=1., **kwargs_3) npt.assert_almost_equal(f_x, f_x1 + f_x2 + f_x3, decimal=8) npt.assert_almost_equal(f_y, f_y1 + f_y2 + f_y3, decimal=8)
def test_hessian(self): """ :return: """ doublechameleon = DoubleChameleon() chameleon = Chameleon() x = np.linspace(0.1, 10, 10) phi_G, q = 0.3, 0.8 theta_E = 1. ratio = 2. e1, e2 = param_util.phi_q2_ellipticity(phi_G, q) kwargs_lens = {'alpha_1': theta_E, 'ratio': ratio, 'w_c1': .5, 'w_t1': 1., 'e11': e1, 'e21': e2, 'w_c2': .1, 'w_t2': .5, 'e12': e1, 'e22': e2} kwargs_light = {'amp': theta_E, 'ratio': ratio, 'w_c1': .5, 'w_t1': 1., 'e11': e1, 'e21': e2, 'w_c2': .1, 'w_t2': .5, 'e12': e1, 'e22': e2} kwargs_1 = {'alpha_1': theta_E / (1 + 1./ratio), 'w_c': .5, 'w_t': 1., 'e1': e1, 'e2': e2} kwargs_2 = {'alpha_1': theta_E / (1 + ratio), 'w_c': .1, 'w_t': .5, 'e1': e1, 'e2': e2} f_xx, f_yy, f_xy = doublechameleon.hessian(x=x, y=1., **kwargs_lens) f_xx1, f_yy1, f_xy1 = chameleon.hessian(x=x, y=1., **kwargs_1) f_xx2, f_yy2, f_xy2 = chameleon.hessian(x=x, y=1., **kwargs_2) npt.assert_almost_equal(f_xx, f_xx1 + f_xx2, decimal=8) npt.assert_almost_equal(f_yy, f_yy1 + f_yy2, decimal=8) npt.assert_almost_equal(f_xy, f_xy1 + f_xy2, decimal=8) light = DoubleChameleonLight() f_xx, f_yy, f_xy = doublechameleon.hessian(x=np.linspace(0, 1, 10), y=np.zeros(10), **kwargs_lens) kappa = 1./2 * (f_xx + f_yy) kappa_norm = kappa / np.mean(kappa) flux = light.function(x=np.linspace(0, 1, 10), y=np.zeros(10), **kwargs_light) flux_norm = flux / np.mean(flux) npt.assert_almost_equal(kappa_norm, flux_norm, decimal=5)
class Chameleon(object): """ class of the Chameleon model (See Dutton+ 2011, Suyu+2014) an elliptical truncated double isothermal profile """ param_names = ['amp', 'w_c', 'w_t', 'e1', 'e2', 'center_x', 'center_y'] lower_limit_default = {'amp': 0, 'w_c': 0, 'w_t': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} upper_limit_default = {'amp': 100, 'w_c': 100, 'w_t': 100, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100} def __init__(self): self.nie = NIE() self._chameleonLens = ChameleonLens() def function(self, x, y, amp, w_c, w_t, e1, e2, center_x=0, center_y=0): """ :param x: ra-coordinate :param y: dec-coordinate :param w_c: :param w_t: :param amp: amplitude of first power-law flux :param e1: eccentricity parameter :param e2: eccentricity parameter :param center_x: center :param center_y: center :return: flux of chameleon profile """ amp_new, w_c, w_t, s_scale_1, s_scale_2 = self._chameleonLens.param_convert(amp, w_c, w_t, e1, e2) flux1 = self.nie.function(x, y, 1, e1, e2, s_scale_1, center_x, center_y) flux2 = self.nie.function(x, y, 1, e1, e2, s_scale_2, center_x, center_y) flux = amp_new * (flux1 - flux2) return flux def light_3d(self, r, amp, w_c, w_t, e1, e2, center_x=0, center_y=0): """ :param r: 3d radius :param w_c: :param w_t: :param amp: amplitude of first power-law flux :param e1: eccentricity parameter :param e2: eccentricity parameter :param center_x: center :param center_y: center :return: 3d flux of chameleon profile at radius r """ amp_new, w_c, w_t, s_scale_1, s_scale_2 = self._chameleonLens.param_convert(amp, w_c, w_t, e1, e2) flux1 = self.nie.light_3d(r, 1, e1, e2, s_scale_1, center_x, center_y) flux2 = self.nie.light_3d(r, 1, e1, e2, s_scale_2, center_x, center_y) flux = amp_new * (flux1 - flux2) return flux
def test_hessian(self): """ :return: """ triplechameleon = TripleChameleon() chameleon = Chameleon() x = np.linspace(0.1, 10, 10) phi_G, q = 0.3, 0.8 ratio12 = 2. ratio13 = 3 e1, e2 = param_util.phi_q2_ellipticity(phi_G, q) kwargs_lens = {'alpha_1': 1., 'ratio12': ratio12, 'ratio13': ratio13, 'w_c1': .5, 'w_t1': 1., 'e11': e1, 'e21': e2, 'w_c2': .1, 'w_t2': .5, 'e12': e1, 'e22': e2, 'w_c3': .1, 'w_t3': .5, 'e13': e1, 'e23': e2 } kwargs_light = {'amp': 1., 'ratio12': ratio12, 'ratio13': ratio13, 'w_c1': .5, 'w_t1': 1., 'e11': e1, 'e21': e2, 'w_c2': .1, 'w_t2': .5, 'e12': e1, 'e22': e2, 'w_c3': .1, 'w_t3': .5, 'e13': e1, 'e23': e2 } amp1 = 1. / (1. + 1. / ratio12 + 1. / ratio13) amp2 = amp1 / ratio12 amp3 = amp1 / ratio13 kwargs_1 = {'alpha_1': amp1, 'w_c': .5, 'w_t': 1., 'e1': e1, 'e2': e2} kwargs_2 = {'alpha_1': amp2, 'w_c': .1, 'w_t': .5, 'e1': e1, 'e2': e2} kwargs_3 = {'alpha_1': amp3, 'w_c': .1, 'w_t': .5, 'e1': e1, 'e2': e2} f_xx, f_yy, f_xy = triplechameleon.hessian(x=x, y=1., **kwargs_lens) f_xx1, f_yy1, f_xy1 = chameleon.hessian(x=x, y=1., **kwargs_1) f_xx2, f_yy2, f_xy2 = chameleon.hessian(x=x, y=1., **kwargs_2) f_xx3, f_yy3, f_xy3 = chameleon.hessian(x=x, y=1., **kwargs_3) npt.assert_almost_equal(f_xx, f_xx1 + f_xx2 + f_xx3, decimal=8) npt.assert_almost_equal(f_yy, f_yy1 + f_yy2 + f_yy3, decimal=8) npt.assert_almost_equal(f_xy, f_xy1 + f_xy2 + f_xy3, decimal=8) light = TripleChameleonLight() f_xx, f_yy, f_xy = triplechameleon.hessian(x=np.linspace(0, 1, 10), y=np.zeros(10), **kwargs_lens) kappa = 1./2 * (f_xx + f_yy) kappa_norm = kappa / np.mean(kappa) flux = light.function(x=np.linspace(0, 1, 10), y=np.zeros(10), **kwargs_light) flux_norm = flux / np.mean(flux) npt.assert_almost_equal(kappa_norm, flux_norm, decimal=5)
def test_derivatives(self): """ :return: """ doublechameleon = DoubleChameleon() chameleon = Chameleon() x = np.linspace(0.1, 10, 10) phi_G, q = 0.3, 0.8 theta_E = 1. ratio = 2. e1, e2 = param_util.phi_q2_ellipticity(phi_G, q) kwargs_light = { 'theta_E': 1., 'ratio': 2, 'w_c1': .5, 'w_t1': 1., 'e11': e1, 'e21': e2, 'w_c2': .1, 'w_t2': .5, 'e12': e1, 'e22': e2 } kwargs_1 = { 'theta_E': theta_E / (1 + 1. / ratio), 'w_c': .5, 'w_t': 1., 'e1': e1, 'e2': e2 } kwargs_2 = { 'theta_E': theta_E / (1 + ratio), 'w_c': .1, 'w_t': .5, 'e1': e1, 'e2': e2 } f_x, f_y = doublechameleon.derivatives(x=x, y=1., **kwargs_light) f_x1, f_y1 = chameleon.derivatives(x=x, y=1., **kwargs_1) f_x2, f_y2 = chameleon.derivatives(x=x, y=1., **kwargs_2) npt.assert_almost_equal(f_x, f_x1 + f_x2, decimal=8) npt.assert_almost_equal(f_y, f_y1 + f_y2, decimal=8)
def test_function(self): """ :return: """ doublechameleon = DoubleChameleon() chameleon = Chameleon() x = np.linspace(0.1, 10, 10) phi_G, q = 0.3, 0.8 theta_E = 1. ratio = 2. e1, e2 = param_util.phi_q2_ellipticity(phi_G, q) kwargs_light = { 'alpha_1': 1., 'ratio': 2, 'w_c1': .5, 'w_t1': 1., 'e11': e1, 'e21': e2, 'w_c2': .1, 'w_t2': .5, 'e12': e1, 'e22': e2 } kwargs_1 = { 'alpha_1': theta_E / (1 + 1. / ratio), 'w_c': .5, 'w_t': 1., 'e1': e1, 'e2': e2 } kwargs_2 = { 'alpha_1': theta_E / (1 + ratio), 'w_c': .1, 'w_t': .5, 'e1': e1, 'e2': e2 } flux = doublechameleon.function(x=x, y=1., **kwargs_light) flux1 = chameleon.function(x=x, y=1., **kwargs_1) flux2 = chameleon.function(x=x, y=1., **kwargs_2) npt.assert_almost_equal(flux, flux1 + flux2, decimal=8)
class Chameleon(object): """ class of the Chameleon model (See Suyu+2014) an elliptical truncated double isothermal profile """ param_names = ['amp', 'w_c', 'w_t', 'e1', 'e2', 'center_x', 'center_y'] lower_limit_default = { 'amp': 0, 'w_c': 0, 'w_t': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100 } upper_limit_default = { 'amp': 100, 'w_c': 100, 'w_t': 100, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100 } def __init__(self): self.nie = NIE() self._chameleonLens = ChameleonLens() def function(self, x, y, amp, w_c, w_t, e1, e2, center_x=0, center_y=0): """ :param x: ra-coordinate :param y: dec-coordinate :param amp: amplitude of first power-law flux :param flux_ratio: ratio of amplitudes of first to second power-law profile :param gamma1: power-law slope :param gamma2: power-law slope :param e1: ellipticity parameter :param e2: ellipticity parameter :param center_x: center :param center_y: center :return: flux of chameleon profile """ amp_new, w_c, w_t = self._chameleonLens._theta_convert(amp, w_c, w_t) phi_G, q = param_util.ellipticity2phi_q(e1, e2) s_scale_1 = np.sqrt(4 * w_c**2 / (1. + q)**2) s_scale_2 = np.sqrt(4 * w_t**2 / (1. + q)**2) flux1 = self.nie.function(x, y, 1, e1, e2, s_scale_1, center_x, center_y) flux2 = self.nie.function(x, y, 1, e1, e2, s_scale_2, center_x, center_y) flux = amp_new / (1. + q) * (flux1 - flux2) return flux
class TestChameleon(object): """ class to test the Moffat profile """ def setup(self): self.chameleon = Chameleon() self.nie = NIE() def test_theta_E_convert(self): w_c, w_t = 2, 1 theta_E_convert, w_c, w_t = self.chameleon._theta_E_convert(theta_E=1, w_c=w_c, w_t=w_t) assert w_c == 1 assert w_t == 2 def test_function(self): """ :return: """ x = np.linspace(0.1, 10, 10) w_c, w_t = 0.5, 1. phi_G, q = 0.3, 0.8 e1, e2 = param_util.phi_q2_ellipticity(phi_G, q) kwargs_light = { 'theta_E': 1., 'w_c': .5, 'w_t': 1., 'e1': e1, 'e2': e2 } theta_E_convert, w_c, w_t = self.chameleon._theta_E_convert(theta_E=1, w_c=0.5, w_t=1.) s_scale_1 = np.sqrt(4 * w_c**2 / (1. + q)**2) s_scale_2 = np.sqrt(4 * w_t**2 / (1. + q)**2) kwargs_1 = { 'theta_E': theta_E_convert, 's_scale': s_scale_1, 'e1': e1, 'e2': e2 } kwargs_2 = { 'theta_E': theta_E_convert, 's_scale': s_scale_2, 'e1': e1, 'e2': e2 } f_ = self.chameleon.function(x=x, y=1., **kwargs_light) f_1 = self.nie.function(x=x, y=1., **kwargs_1) f_2 = self.nie.function(x=x, y=1., **kwargs_2) npt.assert_almost_equal(f_, (f_1 - f_2), decimal=5) def test_derivatives(self): """ :return: """ x = np.linspace(0.1, 10, 10) w_c, w_t = 0.5, 1. phi_G, q = 0.3, 0.8 e1, e2 = param_util.phi_q2_ellipticity(phi_G, q) kwargs_light = { 'theta_E': 1., 'w_c': .5, 'w_t': 1., 'e1': e1, 'e2': e2 } theta_E_convert, w_c, w_t = self.chameleon._theta_E_convert(theta_E=1, w_c=0.5, w_t=1.) s_scale_1 = np.sqrt(4 * w_c**2 / (1. + q)**2) s_scale_2 = np.sqrt(4 * w_t**2 / (1. + q)**2) kwargs_1 = { 'theta_E': theta_E_convert, 's_scale': s_scale_1, 'e1': e1, 'e2': e2 } kwargs_2 = { 'theta_E': theta_E_convert, 's_scale': s_scale_2, 'e1': e1, 'e2': e2 } f_x, f_y = self.chameleon.derivatives(x=x, y=1., **kwargs_light) f_x_1, f_y_1 = self.nie.derivatives(x=x, y=1., **kwargs_1) f_x_2, f_y_2 = self.nie.derivatives(x=x, y=1., **kwargs_2) npt.assert_almost_equal(f_x, (f_x_1 - f_x_2), decimal=5) npt.assert_almost_equal(f_y, (f_y_1 - f_y_2), decimal=5) f_x, f_y = self.chameleon.derivatives(x=1, y=0., **kwargs_light) npt.assert_almost_equal(f_x, 1, decimal=1) def test_hessian(self): """ :return: """ x = np.linspace(0.1, 10, 10) w_c, w_t = 0.5, 1. phi_G, q = 0.3, 0.8 e1, e2 = param_util.phi_q2_ellipticity(phi_G, q) kwargs_light = { 'theta_E': 1., 'w_c': .5, 'w_t': 1., 'e1': e1, 'e2': e2 } theta_E_convert, w_c, w_t = self.chameleon._theta_E_convert(theta_E=1, w_c=0.5, w_t=1.) s_scale_1 = np.sqrt(4 * w_c**2 / (1. + q)**2) s_scale_2 = np.sqrt(4 * w_t**2 / (1. + q)**2) kwargs_1 = { 'theta_E': theta_E_convert, 's_scale': s_scale_1, 'e1': e1, 'e2': e2 } kwargs_2 = { 'theta_E': theta_E_convert, 's_scale': s_scale_2, 'e1': e1, 'e2': e2 } f_xx, f_yy, f_xy = self.chameleon.hessian(x=x, y=1., **kwargs_light) f_xx_1, f_yy_1, f_xy_1 = self.nie.hessian(x=x, y=1., **kwargs_1) f_xx_2, f_yy_2, f_xy_2 = self.nie.hessian(x=x, y=1., **kwargs_2) npt.assert_almost_equal(f_xx, (f_xx_1 - f_xx_2), decimal=5) npt.assert_almost_equal(f_yy, (f_yy_1 - f_yy_2), decimal=5) npt.assert_almost_equal(f_xy, (f_xy_1 - f_xy_2), decimal=5)
def setup(self): self.chameleon = Chameleon() self.nie = NIE()
def _import_class(lens_type, custom_class, z_lens=None, z_source=None): """ :param lens_type: string, lens model type :param custom_class: custom class :param z_lens: lens redshift # currently only used in NFW_MC model as this is redshift dependent :param z_source: source redshift # currently only used in NFW_MC model as this is redshift dependent :return: class instance of the lens model type """ if lens_type == 'SHIFT': from lenstronomy.LensModel.Profiles.alpha_shift import Shift return Shift() elif lens_type == 'SHEAR': from lenstronomy.LensModel.Profiles.shear import Shear return Shear() elif lens_type == 'SHEAR_GAMMA_PSI': from lenstronomy.LensModel.Profiles.shear import ShearGammaPsi return ShearGammaPsi() elif lens_type == 'CONVERGENCE': from lenstronomy.LensModel.Profiles.convergence import Convergence return Convergence() elif lens_type == 'FLEXION': from lenstronomy.LensModel.Profiles.flexion import Flexion return Flexion() elif lens_type == 'FLEXIONFG': from lenstronomy.LensModel.Profiles.flexionfg import Flexionfg return Flexionfg() elif lens_type == 'POINT_MASS': from lenstronomy.LensModel.Profiles.point_mass import PointMass return PointMass() elif lens_type == 'SIS': from lenstronomy.LensModel.Profiles.sis import SIS return SIS() elif lens_type == 'SIS_TRUNCATED': from lenstronomy.LensModel.Profiles.sis_truncate import SIS_truncate return SIS_truncate() elif lens_type == 'SIE': from lenstronomy.LensModel.Profiles.sie import SIE return SIE() elif lens_type == 'SPP': from lenstronomy.LensModel.Profiles.spp import SPP return SPP() elif lens_type == 'NIE': from lenstronomy.LensModel.Profiles.nie import NIE return NIE() elif lens_type == 'NIE_SIMPLE': from lenstronomy.LensModel.Profiles.nie import NIEMajorAxis return NIEMajorAxis() elif lens_type == 'CHAMELEON': from lenstronomy.LensModel.Profiles.chameleon import Chameleon return Chameleon() elif lens_type == 'DOUBLE_CHAMELEON': from lenstronomy.LensModel.Profiles.chameleon import DoubleChameleon return DoubleChameleon() elif lens_type == 'TRIPLE_CHAMELEON': from lenstronomy.LensModel.Profiles.chameleon import TripleChameleon return TripleChameleon() elif lens_type == 'SPEP': from lenstronomy.LensModel.Profiles.spep import SPEP return SPEP() elif lens_type == 'SPEMD': from lenstronomy.LensModel.Profiles.spemd import SPEMD return SPEMD() elif lens_type == 'SPEMD_SMOOTH': from lenstronomy.LensModel.Profiles.spemd_smooth import SPEMD_SMOOTH return SPEMD_SMOOTH() elif lens_type == 'NFW': from lenstronomy.LensModel.Profiles.nfw import NFW return NFW() elif lens_type == 'NFW_ELLIPSE': from lenstronomy.LensModel.Profiles.nfw_ellipse import NFW_ELLIPSE return NFW_ELLIPSE() elif lens_type == 'NFW_ELLIPSE_GAUSS_DEC': from lenstronomy.LensModel.Profiles.gauss_decomposition import NFWEllipseGaussDec return NFWEllipseGaussDec() elif lens_type == 'TNFW': from lenstronomy.LensModel.Profiles.tnfw import TNFW return TNFW() elif lens_type == 'CNFW': from lenstronomy.LensModel.Profiles.cnfw import CNFW return CNFW() elif lens_type == 'CNFW_ELLIPSE': from lenstronomy.LensModel.Profiles.cnfw_ellipse import CNFW_ELLIPSE return CNFW_ELLIPSE() elif lens_type == 'CTNFW_GAUSS_DEC': from lenstronomy.LensModel.Profiles.gauss_decomposition import CTNFWGaussDec return CTNFWGaussDec() elif lens_type == 'NFW_MC': from lenstronomy.LensModel.Profiles.nfw_mass_concentration import NFWMC return NFWMC(z_lens=z_lens, z_source=z_source) elif lens_type == 'SERSIC': from lenstronomy.LensModel.Profiles.sersic import Sersic return Sersic() elif lens_type == 'SERSIC_ELLIPSE_POTENTIAL': from lenstronomy.LensModel.Profiles.sersic_ellipse_potential import SersicEllipse return SersicEllipse() elif lens_type == 'SERSIC_ELLIPSE_KAPPA': from lenstronomy.LensModel.Profiles.sersic_ellipse_kappa import SersicEllipseKappa return SersicEllipseKappa() elif lens_type == 'SERSIC_ELLIPSE_GAUSS_DEC': from lenstronomy.LensModel.Profiles.gauss_decomposition \ import SersicEllipseGaussDec return SersicEllipseGaussDec() elif lens_type == 'PJAFFE': from lenstronomy.LensModel.Profiles.p_jaffe import PJaffe return PJaffe() elif lens_type == 'PJAFFE_ELLIPSE': from lenstronomy.LensModel.Profiles.p_jaffe_ellipse import PJaffe_Ellipse return PJaffe_Ellipse() elif lens_type == 'HERNQUIST': from lenstronomy.LensModel.Profiles.hernquist import Hernquist return Hernquist() elif lens_type == 'HERNQUIST_ELLIPSE': from lenstronomy.LensModel.Profiles.hernquist_ellipse import Hernquist_Ellipse return Hernquist_Ellipse() elif lens_type == 'GAUSSIAN': from lenstronomy.LensModel.Profiles.gaussian_potential import Gaussian return Gaussian() elif lens_type == 'GAUSSIAN_KAPPA': from lenstronomy.LensModel.Profiles.gaussian_kappa import GaussianKappa return GaussianKappa() elif lens_type == 'GAUSSIAN_ELLIPSE_KAPPA': from lenstronomy.LensModel.Profiles.gaussian_ellipse_kappa import GaussianEllipseKappa return GaussianEllipseKappa() elif lens_type == 'GAUSSIAN_ELLIPSE_POTENTIAL': from lenstronomy.LensModel.Profiles.gaussian_ellipse_potential import GaussianEllipsePotential return GaussianEllipsePotential() elif lens_type == 'MULTI_GAUSSIAN_KAPPA': from lenstronomy.LensModel.Profiles.multi_gaussian_kappa import MultiGaussianKappa return MultiGaussianKappa() elif lens_type == 'MULTI_GAUSSIAN_KAPPA_ELLIPSE': from lenstronomy.LensModel.Profiles.multi_gaussian_kappa import MultiGaussianKappaEllipse return MultiGaussianKappaEllipse() elif lens_type == 'INTERPOL': from lenstronomy.LensModel.Profiles.interpol import Interpol return Interpol() elif lens_type == 'INTERPOL_SCALED': from lenstronomy.LensModel.Profiles.interpol import InterpolScaled return InterpolScaled() elif lens_type == 'SHAPELETS_POLAR': from lenstronomy.LensModel.Profiles.shapelet_pot_polar import PolarShapelets return PolarShapelets() elif lens_type == 'SHAPELETS_CART': from lenstronomy.LensModel.Profiles.shapelet_pot_cartesian import CartShapelets return CartShapelets() elif lens_type == 'DIPOLE': from lenstronomy.LensModel.Profiles.dipole import Dipole return Dipole() elif lens_type == 'CURVED_ARC': from lenstronomy.LensModel.Profiles.curved_arc import CurvedArc return CurvedArc() elif lens_type == 'ARC_PERT': from lenstronomy.LensModel.Profiles.arc_perturbations import ArcPerturbations return ArcPerturbations() elif lens_type == 'coreBURKERT': from lenstronomy.LensModel.Profiles.coreBurkert import CoreBurkert return CoreBurkert() elif lens_type == 'CORED_DENSITY': from lenstronomy.LensModel.Profiles.cored_density import CoredDensity return CoredDensity() elif lens_type == 'CORED_DENSITY_2': from lenstronomy.LensModel.Profiles.cored_density_2 import CoredDensity2 return CoredDensity2() elif lens_type == 'CORED_DENSITY_MST': from lenstronomy.LensModel.Profiles.cored_density_mst import CoredDensityMST return CoredDensityMST(profile_type='CORED_DENSITY') elif lens_type == 'CORED_DENSITY_2_MST': from lenstronomy.LensModel.Profiles.cored_density_mst import CoredDensityMST return CoredDensityMST(profile_type='CORED_DENSITY_2') elif lens_type == 'NumericalAlpha': from lenstronomy.LensModel.Profiles.numerical_deflections import NumericalAlpha return NumericalAlpha(custom_class) else: raise ValueError('%s is not a valid lens model' % lens_type)
def __init__(self, lens_model_list, **kwargs): """ :param lens_model_list: list of strings with lens model names :param foreground_shear: bool, when True, models a foreground non-linear shear distortion """ self.func_list = [] self._foreground_shear = False for i, lens_type in enumerate(lens_model_list): if lens_type == 'SHEAR': from lenstronomy.LensModel.Profiles.external_shear import ExternalShear self.func_list.append(ExternalShear()) elif lens_type == 'CONVERGENCE': from lenstronomy.LensModel.Profiles.mass_sheet import MassSheet self.func_list.append(MassSheet()) elif lens_type == 'FLEXION': from lenstronomy.LensModel.Profiles.flexion import Flexion self.func_list.append(Flexion()) elif lens_type == 'POINT_MASS': from lenstronomy.LensModel.Profiles.point_mass import PointMass self.func_list.append(PointMass()) elif lens_type == 'SIS': from lenstronomy.LensModel.Profiles.sis import SIS self.func_list.append(SIS()) elif lens_type == 'SIS_TRUNCATED': from lenstronomy.LensModel.Profiles.sis_truncate import SIS_truncate self.func_list.append(SIS_truncate()) elif lens_type == 'SIE': from lenstronomy.LensModel.Profiles.sie import SIE self.func_list.append(SIE()) elif lens_type == 'SPP': from lenstronomy.LensModel.Profiles.spp import SPP self.func_list.append(SPP()) elif lens_type == 'NIE': from lenstronomy.LensModel.Profiles.nie import NIE self.func_list.append(NIE()) elif lens_type == 'NIE_SIMPLE': from lenstronomy.LensModel.Profiles.nie import NIE_simple self.func_list.append(NIE_simple()) elif lens_type == 'CHAMELEON': from lenstronomy.LensModel.Profiles.chameleon import Chameleon self.func_list.append(Chameleon()) elif lens_type == 'DOUBLE_CHAMELEON': from lenstronomy.LensModel.Profiles.chameleon import DoubleChameleon self.func_list.append(DoubleChameleon()) elif lens_type == 'SPEP': from lenstronomy.LensModel.Profiles.spep import SPEP self.func_list.append(SPEP()) elif lens_type == 'SPEMD': from lenstronomy.LensModel.Profiles.spemd import SPEMD self.func_list.append(SPEMD()) elif lens_type == 'SPEMD_SMOOTH': from lenstronomy.LensModel.Profiles.spemd_smooth import SPEMD_SMOOTH self.func_list.append(SPEMD_SMOOTH()) elif lens_type == 'NFW': from lenstronomy.LensModel.Profiles.nfw import NFW self.func_list.append(NFW(**kwargs)) elif lens_type == 'NFW_ELLIPSE': from lenstronomy.LensModel.Profiles.nfw_ellipse import NFW_ELLIPSE self.func_list.append( NFW_ELLIPSE(interpol=False, num_interp_X=1000, max_interp_X=100)) elif lens_type == 'TNFW': from lenstronomy.LensModel.Profiles.tnfw import TNFW self.func_list.append(TNFW()) elif lens_type == 'SERSIC': from lenstronomy.LensModel.Profiles.sersic import Sersic self.func_list.append(Sersic()) elif lens_type == 'SERSIC_ELLIPSE': from lenstronomy.LensModel.Profiles.sersic_ellipse import SersicEllipse self.func_list.append(SersicEllipse()) elif lens_type == 'PJAFFE': from lenstronomy.LensModel.Profiles.p_jaffe import PJaffe self.func_list.append(PJaffe()) elif lens_type == 'PJAFFE_ELLIPSE': from lenstronomy.LensModel.Profiles.p_jaffe_ellipse import PJaffe_Ellipse self.func_list.append(PJaffe_Ellipse()) elif lens_type == 'HERNQUIST': from lenstronomy.LensModel.Profiles.hernquist import Hernquist self.func_list.append(Hernquist()) elif lens_type == 'HERNQUIST_ELLIPSE': from lenstronomy.LensModel.Profiles.hernquist_ellipse import Hernquist_Ellipse self.func_list.append(Hernquist_Ellipse()) elif lens_type == 'GAUSSIAN': from lenstronomy.LensModel.Profiles.gaussian_potential import Gaussian self.func_list.append(Gaussian()) elif lens_type == 'GAUSSIAN_KAPPA': from lenstronomy.LensModel.Profiles.gaussian_kappa import GaussianKappa self.func_list.append(GaussianKappa()) elif lens_type == 'GAUSSIAN_KAPPA_ELLIPSE': from lenstronomy.LensModel.Profiles.gaussian_kappa_ellipse import GaussianKappaEllipse self.func_list.append(GaussianKappaEllipse()) elif lens_type == 'MULTI_GAUSSIAN_KAPPA': from lenstronomy.LensModel.Profiles.multi_gaussian_kappa import MultiGaussianKappa self.func_list.append(MultiGaussianKappa()) elif lens_type == 'MULTI_GAUSSIAN_KAPPA_ELLIPSE': from lenstronomy.LensModel.Profiles.multi_gaussian_kappa import MultiGaussianKappaEllipse self.func_list.append(MultiGaussianKappaEllipse()) elif lens_type == 'INTERPOL': from lenstronomy.LensModel.Profiles.interpol import Interpol_func self.func_list.append( Interpol_func(grid=False, min_grid_number=100)) elif lens_type == 'INTERPOL_SCALED': from lenstronomy.LensModel.Profiles.interpol import Interpol_func_scaled self.func_list.append( Interpol_func_scaled(grid=False, min_grid_number=100)) elif lens_type == 'SHAPELETS_POLAR': from lenstronomy.LensModel.Profiles.shapelet_pot_polar import PolarShapelets self.func_list.append(PolarShapelets()) elif lens_type == 'SHAPELETS_CART': from lenstronomy.LensModel.Profiles.shapelet_pot_cartesian import CartShapelets self.func_list.append(CartShapelets()) elif lens_type == 'DIPOLE': from lenstronomy.LensModel.Profiles.dipole import Dipole self.func_list.append(Dipole()) elif lens_type == 'FOREGROUND_SHEAR': from lenstronomy.LensModel.Profiles.external_shear import ExternalShear self.func_list.append(ExternalShear()) self._foreground_shear = True self._foreground_shear_idex = i else: raise ValueError('%s is not a valid lens model' % lens_type) self._model_list = lens_model_list
def _import_class(self, lens_type, i, custom_class): if lens_type == 'SHIFT': from lenstronomy.LensModel.Profiles.alpha_shift import Shift return Shift() elif lens_type == 'SHEAR': from lenstronomy.LensModel.Profiles.shear import Shear return Shear() elif lens_type == 'CONVERGENCE': from lenstronomy.LensModel.Profiles.convergence import Convergence return Convergence() elif lens_type == 'FLEXION': from lenstronomy.LensModel.Profiles.flexion import Flexion return Flexion() elif lens_type == 'POINT_MASS': from lenstronomy.LensModel.Profiles.point_mass import PointMass return PointMass() elif lens_type == 'SIS': from lenstronomy.LensModel.Profiles.sis import SIS return SIS() elif lens_type == 'SIS_TRUNCATED': from lenstronomy.LensModel.Profiles.sis_truncate import SIS_truncate return SIS_truncate() elif lens_type == 'SIE': from lenstronomy.LensModel.Profiles.sie import SIE return SIE() elif lens_type == 'SPP': from lenstronomy.LensModel.Profiles.spp import SPP return SPP() elif lens_type == 'NIE': from lenstronomy.LensModel.Profiles.nie import NIE return NIE() elif lens_type == 'NIE_SIMPLE': from lenstronomy.LensModel.Profiles.nie import NIE_simple return NIE_simple() elif lens_type == 'CHAMELEON': from lenstronomy.LensModel.Profiles.chameleon import Chameleon return Chameleon() elif lens_type == 'DOUBLE_CHAMELEON': from lenstronomy.LensModel.Profiles.chameleon import DoubleChameleon return DoubleChameleon() elif lens_type == 'SPEP': from lenstronomy.LensModel.Profiles.spep import SPEP return SPEP() elif lens_type == 'SPEMD': from lenstronomy.LensModel.Profiles.spemd import SPEMD return SPEMD() elif lens_type == 'SPEMD_SMOOTH': from lenstronomy.LensModel.Profiles.spemd_smooth import SPEMD_SMOOTH return SPEMD_SMOOTH() elif lens_type == 'NFW': from lenstronomy.LensModel.Profiles.nfw import NFW return NFW() elif lens_type == 'NFW_ELLIPSE': from lenstronomy.LensModel.Profiles.nfw_ellipse import NFW_ELLIPSE return NFW_ELLIPSE() elif lens_type == 'TNFW': from lenstronomy.LensModel.Profiles.tnfw import TNFW return TNFW() elif lens_type == 'CNFW': from lenstronomy.LensModel.Profiles.cnfw import CNFW return CNFW() elif lens_type == 'SERSIC': from lenstronomy.LensModel.Profiles.sersic import Sersic return Sersic() elif lens_type == 'SERSIC_ELLIPSE': from lenstronomy.LensModel.Profiles.sersic_ellipse import SersicEllipse return SersicEllipse() elif lens_type == 'PJAFFE': from lenstronomy.LensModel.Profiles.p_jaffe import PJaffe return PJaffe() elif lens_type == 'PJAFFE_ELLIPSE': from lenstronomy.LensModel.Profiles.p_jaffe_ellipse import PJaffe_Ellipse return PJaffe_Ellipse() elif lens_type == 'HERNQUIST': from lenstronomy.LensModel.Profiles.hernquist import Hernquist return Hernquist() elif lens_type == 'HERNQUIST_ELLIPSE': from lenstronomy.LensModel.Profiles.hernquist_ellipse import Hernquist_Ellipse return Hernquist_Ellipse() elif lens_type == 'GAUSSIAN': from lenstronomy.LensModel.Profiles.gaussian_potential import Gaussian return Gaussian() elif lens_type == 'GAUSSIAN_KAPPA': from lenstronomy.LensModel.Profiles.gaussian_kappa import GaussianKappa return GaussianKappa() elif lens_type == 'GAUSSIAN_KAPPA_ELLIPSE': from lenstronomy.LensModel.Profiles.gaussian_kappa_ellipse import GaussianKappaEllipse return GaussianKappaEllipse() elif lens_type == 'MULTI_GAUSSIAN_KAPPA': from lenstronomy.LensModel.Profiles.multi_gaussian_kappa import MultiGaussianKappa return MultiGaussianKappa() elif lens_type == 'MULTI_GAUSSIAN_KAPPA_ELLIPSE': from lenstronomy.LensModel.Profiles.multi_gaussian_kappa import MultiGaussianKappaEllipse return MultiGaussianKappaEllipse() elif lens_type == 'INTERPOL': from lenstronomy.LensModel.Profiles.interpol import Interpol return Interpol(grid=False, min_grid_number=100) elif lens_type == 'INTERPOL_SCALED': from lenstronomy.LensModel.Profiles.interpol import InterpolScaled return InterpolScaled() elif lens_type == 'SHAPELETS_POLAR': from lenstronomy.LensModel.Profiles.shapelet_pot_polar import PolarShapelets return PolarShapelets() elif lens_type == 'SHAPELETS_CART': from lenstronomy.LensModel.Profiles.shapelet_pot_cartesian import CartShapelets return CartShapelets() elif lens_type == 'DIPOLE': from lenstronomy.LensModel.Profiles.dipole import Dipole return Dipole() elif lens_type == 'FOREGROUND_SHEAR': from lenstronomy.LensModel.Profiles.shear import Shear self._foreground_shear = True self._foreground_shear_idex = i return Shear() elif lens_type == 'coreBURKERT': from lenstronomy.LensModel.Profiles.coreBurkert import coreBurkert return coreBurkert() elif lens_type == 'NumericalAlpha': from lenstronomy.LensModel.Profiles.numerical_deflections import NumericalAlpha return NumericalAlpha(custom_class[i]) else: raise ValueError('%s is not a valid lens model' % lens_type)
def _import_class(lens_type, custom_class, kwargs_interp, z_lens=None, z_source=None): """ :param lens_type: string, lens model type :param custom_class: custom class :param z_lens: lens redshift # currently only used in NFW_MC model as this is redshift dependent :param z_source: source redshift # currently only used in NFW_MC model as this is redshift dependent :param kwargs_interp: interpolation keyword arguments specifying the numerics. See description in the Interpolate() class. Only applicable for 'INTERPOL' and 'INTERPOL_SCALED' models. :return: class instance of the lens model type """ if lens_type == 'SHIFT': from lenstronomy.LensModel.Profiles.constant_shift import Shift return Shift() elif lens_type == 'NIE_POTENTIAL': from lenstronomy.LensModel.Profiles.nie_potential import NIE_POTENTIAL return NIE_POTENTIAL() elif lens_type == 'CONST_MAG': from lenstronomy.LensModel.Profiles.const_mag import ConstMag return ConstMag() elif lens_type == 'SHEAR': from lenstronomy.LensModel.Profiles.shear import Shear return Shear() elif lens_type == 'SHEAR_GAMMA_PSI': from lenstronomy.LensModel.Profiles.shear import ShearGammaPsi return ShearGammaPsi() elif lens_type == 'SHEAR_REDUCED': from lenstronomy.LensModel.Profiles.shear import ShearReduced return ShearReduced() elif lens_type == 'CONVERGENCE': from lenstronomy.LensModel.Profiles.convergence import Convergence return Convergence() elif lens_type == 'HESSIAN': from lenstronomy.LensModel.Profiles.hessian import Hessian return Hessian() elif lens_type == 'FLEXION': from lenstronomy.LensModel.Profiles.flexion import Flexion return Flexion() elif lens_type == 'FLEXIONFG': from lenstronomy.LensModel.Profiles.flexionfg import Flexionfg return Flexionfg() elif lens_type == 'POINT_MASS': from lenstronomy.LensModel.Profiles.point_mass import PointMass return PointMass() elif lens_type == 'SIS': from lenstronomy.LensModel.Profiles.sis import SIS return SIS() elif lens_type == 'SIS_TRUNCATED': from lenstronomy.LensModel.Profiles.sis_truncate import SIS_truncate return SIS_truncate() elif lens_type == 'SIE': from lenstronomy.LensModel.Profiles.sie import SIE return SIE() elif lens_type == 'SPP': from lenstronomy.LensModel.Profiles.spp import SPP return SPP() elif lens_type == 'NIE': from lenstronomy.LensModel.Profiles.nie import NIE return NIE() elif lens_type == 'NIE_SIMPLE': from lenstronomy.LensModel.Profiles.nie import NIEMajorAxis return NIEMajorAxis() elif lens_type == 'CHAMELEON': from lenstronomy.LensModel.Profiles.chameleon import Chameleon return Chameleon() elif lens_type == 'DOUBLE_CHAMELEON': from lenstronomy.LensModel.Profiles.chameleon import DoubleChameleon return DoubleChameleon() elif lens_type == 'TRIPLE_CHAMELEON': from lenstronomy.LensModel.Profiles.chameleon import TripleChameleon return TripleChameleon() elif lens_type == 'SPEP': from lenstronomy.LensModel.Profiles.spep import SPEP return SPEP() elif lens_type == 'PEMD': from lenstronomy.LensModel.Profiles.pemd import PEMD return PEMD() elif lens_type == 'SPEMD': from lenstronomy.LensModel.Profiles.spemd import SPEMD return SPEMD() elif lens_type == 'EPL': from lenstronomy.LensModel.Profiles.epl import EPL return EPL() elif lens_type == 'EPL_NUMBA': from lenstronomy.LensModel.Profiles.epl_numba import EPL_numba return EPL_numba() elif lens_type == 'SPL_CORE': from lenstronomy.LensModel.Profiles.splcore import SPLCORE return SPLCORE() elif lens_type == 'NFW': from lenstronomy.LensModel.Profiles.nfw import NFW return NFW() elif lens_type == 'NFW_ELLIPSE': from lenstronomy.LensModel.Profiles.nfw_ellipse import NFW_ELLIPSE return NFW_ELLIPSE() elif lens_type == 'NFW_ELLIPSE_GAUSS_DEC': from lenstronomy.LensModel.Profiles.gauss_decomposition import NFWEllipseGaussDec return NFWEllipseGaussDec() elif lens_type == 'NFW_ELLIPSE_CSE': from lenstronomy.LensModel.Profiles.nfw_ellipse_cse import NFW_ELLIPSE_CSE return NFW_ELLIPSE_CSE() elif lens_type == 'TNFW': from lenstronomy.LensModel.Profiles.tnfw import TNFW return TNFW() elif lens_type == 'TNFW_ELLIPSE': from lenstronomy.LensModel.Profiles.tnfw_ellipse import TNFW_ELLIPSE return TNFW_ELLIPSE() elif lens_type == 'CNFW': from lenstronomy.LensModel.Profiles.cnfw import CNFW return CNFW() elif lens_type == 'CNFW_ELLIPSE': from lenstronomy.LensModel.Profiles.cnfw_ellipse import CNFW_ELLIPSE return CNFW_ELLIPSE() elif lens_type == 'CTNFW_GAUSS_DEC': from lenstronomy.LensModel.Profiles.gauss_decomposition import CTNFWGaussDec return CTNFWGaussDec() elif lens_type == 'NFW_MC': from lenstronomy.LensModel.Profiles.nfw_mass_concentration import NFWMC return NFWMC(z_lens=z_lens, z_source=z_source) elif lens_type == 'SERSIC': from lenstronomy.LensModel.Profiles.sersic import Sersic return Sersic() elif lens_type == 'SERSIC_ELLIPSE_POTENTIAL': from lenstronomy.LensModel.Profiles.sersic_ellipse_potential import SersicEllipse return SersicEllipse() elif lens_type == 'SERSIC_ELLIPSE_KAPPA': from lenstronomy.LensModel.Profiles.sersic_ellipse_kappa import SersicEllipseKappa return SersicEllipseKappa() elif lens_type == 'SERSIC_ELLIPSE_GAUSS_DEC': from lenstronomy.LensModel.Profiles.gauss_decomposition import SersicEllipseGaussDec return SersicEllipseGaussDec() elif lens_type == 'PJAFFE': from lenstronomy.LensModel.Profiles.p_jaffe import PJaffe return PJaffe() elif lens_type == 'PJAFFE_ELLIPSE': from lenstronomy.LensModel.Profiles.p_jaffe_ellipse import PJaffe_Ellipse return PJaffe_Ellipse() elif lens_type == 'HERNQUIST': from lenstronomy.LensModel.Profiles.hernquist import Hernquist return Hernquist() elif lens_type == 'HERNQUIST_ELLIPSE': from lenstronomy.LensModel.Profiles.hernquist_ellipse import Hernquist_Ellipse return Hernquist_Ellipse() elif lens_type == 'HERNQUIST_ELLIPSE_CSE': from lenstronomy.LensModel.Profiles.hernquist_ellipse_cse import HernquistEllipseCSE return HernquistEllipseCSE() elif lens_type == 'GAUSSIAN': from lenstronomy.LensModel.Profiles.gaussian_potential import Gaussian return Gaussian() elif lens_type == 'GAUSSIAN_KAPPA': from lenstronomy.LensModel.Profiles.gaussian_kappa import GaussianKappa return GaussianKappa() elif lens_type == 'GAUSSIAN_ELLIPSE_KAPPA': from lenstronomy.LensModel.Profiles.gaussian_ellipse_kappa import GaussianEllipseKappa return GaussianEllipseKappa() elif lens_type == 'GAUSSIAN_ELLIPSE_POTENTIAL': from lenstronomy.LensModel.Profiles.gaussian_ellipse_potential import GaussianEllipsePotential return GaussianEllipsePotential() elif lens_type == 'MULTI_GAUSSIAN_KAPPA': from lenstronomy.LensModel.Profiles.multi_gaussian_kappa import MultiGaussianKappa return MultiGaussianKappa() elif lens_type == 'MULTI_GAUSSIAN_KAPPA_ELLIPSE': from lenstronomy.LensModel.Profiles.multi_gaussian_kappa import MultiGaussianKappaEllipse return MultiGaussianKappaEllipse() elif lens_type == 'INTERPOL': from lenstronomy.LensModel.Profiles.interpol import Interpol return Interpol(**kwargs_interp) elif lens_type == 'INTERPOL_SCALED': from lenstronomy.LensModel.Profiles.interpol import InterpolScaled return InterpolScaled(**kwargs_interp) elif lens_type == 'SHAPELETS_POLAR': from lenstronomy.LensModel.Profiles.shapelet_pot_polar import PolarShapelets return PolarShapelets() elif lens_type == 'SHAPELETS_CART': from lenstronomy.LensModel.Profiles.shapelet_pot_cartesian import CartShapelets return CartShapelets() elif lens_type == 'DIPOLE': from lenstronomy.LensModel.Profiles.dipole import Dipole return Dipole() elif lens_type == 'CURVED_ARC_CONST': from lenstronomy.LensModel.Profiles.curved_arc_const import CurvedArcConst return CurvedArcConst() elif lens_type == 'CURVED_ARC_CONST_MST': from lenstronomy.LensModel.Profiles.curved_arc_const import CurvedArcConstMST return CurvedArcConstMST() elif lens_type == 'CURVED_ARC_SPP': from lenstronomy.LensModel.Profiles.curved_arc_spp import CurvedArcSPP return CurvedArcSPP() elif lens_type == 'CURVED_ARC_SIS_MST': from lenstronomy.LensModel.Profiles.curved_arc_sis_mst import CurvedArcSISMST return CurvedArcSISMST() elif lens_type == 'CURVED_ARC_SPT': from lenstronomy.LensModel.Profiles.curved_arc_spt import CurvedArcSPT return CurvedArcSPT() elif lens_type == 'CURVED_ARC_TAN_DIFF': from lenstronomy.LensModel.Profiles.curved_arc_tan_diff import CurvedArcTanDiff return CurvedArcTanDiff() elif lens_type == 'ARC_PERT': from lenstronomy.LensModel.Profiles.arc_perturbations import ArcPerturbations return ArcPerturbations() elif lens_type == 'coreBURKERT': from lenstronomy.LensModel.Profiles.coreBurkert import CoreBurkert return CoreBurkert() elif lens_type == 'CORED_DENSITY': from lenstronomy.LensModel.Profiles.cored_density import CoredDensity return CoredDensity() elif lens_type == 'CORED_DENSITY_2': from lenstronomy.LensModel.Profiles.cored_density_2 import CoredDensity2 return CoredDensity2() elif lens_type == 'CORED_DENSITY_EXP': from lenstronomy.LensModel.Profiles.cored_density_exp import CoredDensityExp return CoredDensityExp() elif lens_type == 'CORED_DENSITY_MST': from lenstronomy.LensModel.Profiles.cored_density_mst import CoredDensityMST return CoredDensityMST(profile_type='CORED_DENSITY') elif lens_type == 'CORED_DENSITY_2_MST': from lenstronomy.LensModel.Profiles.cored_density_mst import CoredDensityMST return CoredDensityMST(profile_type='CORED_DENSITY_2') elif lens_type == 'CORED_DENSITY_EXP_MST': from lenstronomy.LensModel.Profiles.cored_density_mst import CoredDensityMST return CoredDensityMST(profile_type='CORED_DENSITY_EXP') elif lens_type == 'NumericalAlpha': from lenstronomy.LensModel.Profiles.numerical_deflections import NumericalAlpha return NumericalAlpha(custom_class) elif lens_type == 'MULTIPOLE': from lenstronomy.LensModel.Profiles.multipole import Multipole return Multipole() elif lens_type == 'CSE': from lenstronomy.LensModel.Profiles.cored_steep_ellipsoid import CSE return CSE() elif lens_type == 'ElliSLICE': from lenstronomy.LensModel.Profiles.elliptical_density_slice import ElliSLICE return ElliSLICE() elif lens_type == 'ULDM': from lenstronomy.LensModel.Profiles.uldm import Uldm return Uldm() elif lens_type == 'CORED_DENSITY_ULDM_MST': from lenstronomy.LensModel.Profiles.cored_density_mst import CoredDensityMST return CoredDensityMST(profile_type='CORED_DENSITY_ULDM') else: raise ValueError( '%s is not a valid lens model. Supported are: %s.' % (lens_type, _SUPPORTED_MODELS))
class TestChameleon(object): """ class to test the Moffat profile """ def setup(self): self.chameleon = Chameleon() self.nie = NIE() def test_theta_E_convert(self): w_c, w_t = 2, 1 theta_E_convert, w_c, w_t, s_scale_1, s_scale_2 = self.chameleon.param_convert( alpha_1=1, w_c=w_c, w_t=w_t, e1=0, e2=0) assert w_c == 1 assert w_t == 2 assert theta_E_convert == 0 def test_function(self): """ :return: """ x = np.linspace(0.1, 10, 10) w_c, w_t = 0.5, 1. phi_G, q = 0.3, 0.8 e1, e2 = param_util.phi_q2_ellipticity(phi_G, q) kwargs_light = { 'alpha_1': 1., 'w_c': .5, 'w_t': 1., 'e1': e1, 'e2': e2 } theta_E_convert, w_c, w_t, s_scale_1, s_scale_2 = self.chameleon.param_convert( alpha_1=1, w_c=0.5, w_t=1., e1=e1, e2=e2) kwargs_1 = { 'theta_E': theta_E_convert, 's_scale': s_scale_1, 'e1': e1, 'e2': e2 } kwargs_2 = { 'theta_E': theta_E_convert, 's_scale': s_scale_2, 'e1': e1, 'e2': e2 } f_ = self.chameleon.function(x=x, y=1., **kwargs_light) f_1 = self.nie.function(x=x, y=1., **kwargs_1) f_2 = self.nie.function(x=x, y=1., **kwargs_2) npt.assert_almost_equal(f_, (f_1 - f_2), decimal=5) def test_derivatives(self): """ :return: """ x = np.linspace(0.1, 10, 10) w_c, w_t = 0.5, 1. phi_G, q = 0.3, 0.8 e1, e2 = param_util.phi_q2_ellipticity(phi_G, q) kwargs_light = { 'alpha_1': 1., 'w_c': .5, 'w_t': 1., 'e1': e1, 'e2': e2 } theta_E_convert, w_c, w_t, s_scale_1, s_scale_2 = self.chameleon.param_convert( alpha_1=1, w_c=0.5, w_t=1., e1=e1, e2=e2) kwargs_1 = { 'theta_E': theta_E_convert, 's_scale': s_scale_1, 'e1': e1, 'e2': e2 } kwargs_2 = { 'theta_E': theta_E_convert, 's_scale': s_scale_2, 'e1': e1, 'e2': e2 } f_x, f_y = self.chameleon.derivatives(x=x, y=1., **kwargs_light) f_x_1, f_y_1 = self.nie.derivatives(x=x, y=1., **kwargs_1) f_x_2, f_y_2 = self.nie.derivatives(x=x, y=1., **kwargs_2) npt.assert_almost_equal(f_x, (f_x_1 - f_x_2), decimal=5) npt.assert_almost_equal(f_y, (f_y_1 - f_y_2), decimal=5) f_x, f_y = self.chameleon.derivatives(x=1, y=0., **kwargs_light) npt.assert_almost_equal(f_x, 1, decimal=1) def test_hessian(self): """ :return: """ x = np.linspace(0.1, 10, 10) w_c, w_t = 0.5, 1. phi_G, q = 0.3, 0.8 e1, e2 = param_util.phi_q2_ellipticity(phi_G, q) kwargs_light = { 'alpha_1': 1., 'w_c': .5, 'w_t': 1., 'e1': e1, 'e2': e2 } theta_E_convert, w_c, w_t, s_scale_1, s_scale_2 = self.chameleon.param_convert( alpha_1=1, w_c=0.5, w_t=1., e1=e1, e2=e2) kwargs_1 = { 'theta_E': theta_E_convert, 's_scale': s_scale_1, 'e1': e1, 'e2': e2 } kwargs_2 = { 'theta_E': theta_E_convert, 's_scale': s_scale_2, 'e1': e1, 'e2': e2 } f_xx, f_xy, f_yx, f_yy = self.chameleon.hessian(x=x, y=1., **kwargs_light) f_xx_1, f_xy_1, f_yx_1, f_yy_1 = self.nie.hessian(x=x, y=1., **kwargs_1) f_xx_2, f_xy_2, f_yx_2, f_yy_2 = self.nie.hessian(x=x, y=1., **kwargs_2) npt.assert_almost_equal(f_xx, (f_xx_1 - f_xx_2), decimal=5) npt.assert_almost_equal(f_yy, (f_yy_1 - f_yy_2), decimal=5) npt.assert_almost_equal(f_xy, (f_xy_1 - f_xy_2), decimal=5) npt.assert_almost_equal(f_yx, (f_yx_1 - f_yx_2), decimal=5) def test_static(self): x, y = 1., 1. phi_G, q = 0.3, 0.8 e1, e2 = param_util.phi_q2_ellipticity(phi_G, q) kwargs_light = { 'alpha_1': 1., 'w_c': .5, 'w_t': 1., 'e1': e1, 'e2': e2 } f_ = self.chameleon.function(x, y, **kwargs_light) self.chameleon.set_static(**kwargs_light) f_static = self.chameleon.function(x, y, **kwargs_light) npt.assert_almost_equal(f_, f_static, decimal=8) self.chameleon.set_dynamic() kwargs_light = { 'alpha_1': 2., 'w_c': .5, 'w_t': 1., 'e1': e1, 'e2': e2 } f_dyn = self.chameleon.function(x, y, **kwargs_light) assert f_dyn != f_static
def __init__(self): self.nie = NIE() self._chameleonLens = ChameleonLens()