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_function(self): """ :return: """ chameleon = Chameleon() triplechameleon = TripleChameleon() 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 = { '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 = {'amp': amp1, 'w_c': .5, 'w_t': 1., 'e1': e1, 'e2': e2} kwargs_2 = {'amp': amp2, 'w_c': .1, 'w_t': .5, 'e1': e1, 'e2': e2} kwargs_3 = {'amp': amp3, 'w_c': .1, 'w_t': .5, 'e1': e1, 'e2': e2} flux = triplechameleon.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) flux3 = chameleon.function(x=x, y=1., **kwargs_3) npt.assert_almost_equal(flux, flux1 + flux2 + flux3, decimal=8)
def __init__(self, light_model_list, smoothing=0.001): """ :param light_model_list: list of light models :param smoothing: smoothing factor for certain models (deprecated) """ self.profile_type_list = light_model_list self.func_list = [] for profile_type in light_model_list: if profile_type == 'GAUSSIAN': from lenstronomy.LightModel.Profiles.gaussian import Gaussian self.func_list.append(Gaussian()) elif profile_type == 'GAUSSIAN_ELLIPSE': from lenstronomy.LightModel.Profiles.gaussian import GaussianEllipse self.func_list.append(GaussianEllipse()) elif profile_type == 'ELLIPSOID': from lenstronomy.LightModel.Profiles.ellipsoid import Ellipsoid self.func_list.append(Ellipsoid()) elif profile_type == 'MULTI_GAUSSIAN': from lenstronomy.LightModel.Profiles.gaussian import MultiGaussian self.func_list.append(MultiGaussian()) elif profile_type == 'MULTI_GAUSSIAN_ELLIPSE': from lenstronomy.LightModel.Profiles.gaussian import MultiGaussianEllipse self.func_list.append(MultiGaussianEllipse()) elif profile_type == 'SERSIC': from lenstronomy.LightModel.Profiles.sersic import Sersic self.func_list.append(Sersic(smoothing=smoothing)) elif profile_type == 'SERSIC_ELLIPSE': from lenstronomy.LightModel.Profiles.sersic import SersicElliptic self.func_list.append( SersicElliptic(smoothing=smoothing, sersic_major_axis=sersic_major_axis_conf)) elif profile_type == 'CORE_SERSIC': from lenstronomy.LightModel.Profiles.sersic import CoreSersic self.func_list.append(CoreSersic(smoothing=smoothing)) elif profile_type == 'SHAPELETS': from lenstronomy.LightModel.Profiles.shapelets import ShapeletSet self.func_list.append(ShapeletSet()) elif profile_type == 'SHAPELETS_POLAR': from lenstronomy.LightModel.Profiles.shapelets_polar import ShapeletSetPolar self.func_list.append(ShapeletSetPolar(exponential=False)) elif profile_type == 'SHAPELETS_POLAR_EXP': from lenstronomy.LightModel.Profiles.shapelets_polar import ShapeletSetPolar self.func_list.append(ShapeletSetPolar(exponential=True)) elif profile_type == 'HERNQUIST': from lenstronomy.LightModel.Profiles.hernquist import Hernquist self.func_list.append(Hernquist()) elif profile_type == 'HERNQUIST_ELLIPSE': from lenstronomy.LightModel.Profiles.hernquist import HernquistEllipse self.func_list.append(HernquistEllipse()) elif profile_type == 'PJAFFE': from lenstronomy.LightModel.Profiles.p_jaffe import PJaffe self.func_list.append(PJaffe()) elif profile_type == 'PJAFFE_ELLIPSE': from lenstronomy.LightModel.Profiles.p_jaffe import PJaffe_Ellipse self.func_list.append(PJaffe_Ellipse()) elif profile_type == 'UNIFORM': from lenstronomy.LightModel.Profiles.uniform import Uniform self.func_list.append(Uniform()) elif profile_type == 'POWER_LAW': from lenstronomy.LightModel.Profiles.power_law import PowerLaw self.func_list.append(PowerLaw()) elif profile_type == 'NIE': from lenstronomy.LightModel.Profiles.nie import NIE self.func_list.append(NIE()) elif profile_type == 'CHAMELEON': from lenstronomy.LightModel.Profiles.chameleon import Chameleon self.func_list.append(Chameleon()) elif profile_type == 'DOUBLE_CHAMELEON': from lenstronomy.LightModel.Profiles.chameleon import DoubleChameleon self.func_list.append(DoubleChameleon()) elif profile_type == 'TRIPLE_CHAMELEON': from lenstronomy.LightModel.Profiles.chameleon import TripleChameleon self.func_list.append(TripleChameleon()) elif profile_type == 'INTERPOL': from lenstronomy.LightModel.Profiles.interpolation import Interpol self.func_list.append(Interpol()) elif profile_type == 'SLIT_STARLETS': from lenstronomy.LightModel.Profiles.starlets import SLIT_Starlets self.func_list.append( SLIT_Starlets(fast_inverse=True, second_gen=False)) elif profile_type == 'SLIT_STARLETS_GEN2': from lenstronomy.LightModel.Profiles.starlets import SLIT_Starlets self.func_list.append(SLIT_Starlets(second_gen=True)) else: raise ValueError( 'No light model of type %s found! Supported are the following models: %s' % (profile_type, _MODELS_SUPPORTED)) self._num_func = len(self.func_list)
def __init__(self, light_model_list, smoothing=0.0000001): """ :param light_model_list: list of light models :param deflection_scaling_list: list of floats, rescales the original reduced deflection angles from the lens model to enable different models to be placed at different optical (redshift) distances. None means they are all :param source_redshift_list: list of redshifts of the model components :param smoothing: smoothing factor for certain models (deprecated) """ self.profile_type_list = light_model_list self.func_list = [] for profile_type in light_model_list: if profile_type == 'GAUSSIAN': from lenstronomy.LightModel.Profiles.gaussian import Gaussian self.func_list.append(Gaussian()) elif profile_type == 'GAUSSIAN_ELLIPSE': from lenstronomy.LightModel.Profiles.gaussian import GaussianEllipse self.func_list.append(GaussianEllipse()) elif profile_type == 'MULTI_GAUSSIAN': from lenstronomy.LightModel.Profiles.gaussian import MultiGaussian self.func_list.append(MultiGaussian()) elif profile_type == 'MULTI_GAUSSIAN_ELLIPSE': from lenstronomy.LightModel.Profiles.gaussian import MultiGaussianEllipse self.func_list.append(MultiGaussianEllipse()) elif profile_type == 'SERSIC': from lenstronomy.LightModel.Profiles.sersic import Sersic self.func_list.append(Sersic(smoothing=smoothing)) elif profile_type == 'SERSIC_ELLIPSE': from lenstronomy.LightModel.Profiles.sersic import SersicElliptic self.func_list.append(SersicElliptic(smoothing=smoothing)) elif profile_type == 'CORE_SERSIC': from lenstronomy.LightModel.Profiles.sersic import CoreSersic self.func_list.append(CoreSersic(smoothing=smoothing)) elif profile_type == 'SHAPELETS': from lenstronomy.LightModel.Profiles.shapelets import ShapeletSet self.func_list.append(ShapeletSet()) elif profile_type == 'SHAPELETS_POLAR': from lenstronomy.LightModel.Profiles.shapelets_polar import ShapeletSetPolar self.func_list.append(ShapeletSetPolar(exponential=False)) elif profile_type == 'SHAPELETS_POLAR_EXP': from lenstronomy.LightModel.Profiles.shapelets_polar import ShapeletSetPolar self.func_list.append(ShapeletSetPolar(exponential=True)) elif profile_type == 'HERNQUIST': from lenstronomy.LightModel.Profiles.hernquist import Hernquist self.func_list.append(Hernquist()) elif profile_type == 'HERNQUIST_ELLIPSE': from lenstronomy.LightModel.Profiles.hernquist import HernquistEllipse self.func_list.append(HernquistEllipse()) elif profile_type == 'PJAFFE': from lenstronomy.LightModel.Profiles.p_jaffe import PJaffe self.func_list.append(PJaffe()) elif profile_type == 'PJAFFE_ELLIPSE': from lenstronomy.LightModel.Profiles.p_jaffe import PJaffe_Ellipse self.func_list.append(PJaffe_Ellipse()) elif profile_type == 'UNIFORM': from lenstronomy.LightModel.Profiles.uniform import Uniform self.func_list.append(Uniform()) elif profile_type == 'POWER_LAW': from lenstronomy.LightModel.Profiles.power_law import PowerLaw self.func_list.append(PowerLaw()) elif profile_type == 'NIE': from lenstronomy.LightModel.Profiles.nie import NIE self.func_list.append(NIE()) elif profile_type == 'CHAMELEON': from lenstronomy.LightModel.Profiles.chameleon import Chameleon self.func_list.append(Chameleon()) elif profile_type == 'DOUBLE_CHAMELEON': from lenstronomy.LightModel.Profiles.chameleon import DoubleChameleon self.func_list.append(DoubleChameleon()) elif profile_type == 'TRIPLE_CHAMELEON': from lenstronomy.LightModel.Profiles.chameleon import TripleChameleon self.func_list.append(TripleChameleon()) elif profile_type == 'INTERPOL': from lenstronomy.LightModel.Profiles.interpolation import Interpol self.func_list.append(Interpol()) else: raise ValueError('Warning! No light model of type', profile_type, ' found!')