Example #1
0
    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)
Example #2
0
 def __init__(self, light_model_list, smoothing=0.0000001):
     self.profile_type_list = light_model_list
     self.func_list = []
     for profile_type in light_model_list:
         valid = True
         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 Sersic_elliptic
             self.func_list.append(Sersic_elliptic(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 == 'HERNQUIST':
             from lenstronomy.LightModel.Profiles.hernquist import Hernquist
             self.func_list.append(Hernquist())
         elif profile_type == 'HERNQUIST_ELLIPSE':
             from lenstronomy.LightModel.Profiles.hernquist import Hernquist_Ellipse
             self.func_list.append(Hernquist_Ellipse())
         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())
         else:
             raise ValueError('Warning! No light model of type', profile_type, ' found!')
Example #3
0
    def test_function(self):
        """

        :return:
        """
        chameleon = Chameleon()
        doublechameleon = DoubleChameleon()

        x = np.linspace(0.1, 10, 10)
        w_c, w_t = 0.5, 1.
        phi_G, q = 0.3, 0.8
        theta_E = 1.
        ratio = 2.
        e1, e2 = param_util.phi_q2_ellipticity(phi_G, q)
        kwargs_light = {
            'amp': 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 = {
            'amp': 1. / (1 + 1. / ratio),
            'w_c': .5,
            'w_t': 1.,
            'e1': e1,
            'e2': e2
        }
        kwargs_2 = {
            'amp': 1. / (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)
Example #4
0
    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)
Example #5
0
 def test_param_name(self):
     chameleon = DoubleChameleon()
     names = chameleon.param_names
     assert names[0] == 'amp'
Example #6
0
    def __init__(self,
                 light_model_list,
                 deflection_scaling_list=None,
                 source_redshift_list=None,
                 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.deflection_scaling_list = deflection_scaling_list
        self.redshift_list = source_redshift_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 == '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 == '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!')