Exemplo n.º 1
0
 def test_mge_lens_light_elliptical(self):
     e1, e2 = 0.3, 0.
     kwargs_profile = [{
         'amp': 1.,
         'sigma': 2,
         'center_x': 0.,
         'center_y': 0,
         'e1': e1,
         'e2': e2
     }]
     kwargs_options = {'lens_light_model_list': ['GAUSSIAN_ELLIPSE']}
     lensAnalysis = LensAnalysis(kwargs_options)
     amplitudes, sigma, center_x, center_y = lensAnalysis.multi_gaussian_lens_light(
         kwargs_profile, n_comp=20, e1=e1, e2=e2, deltaPix=0.05, numPix=400)
     mge = MultiGaussianEllipse()
     flux = mge.function(1.,
                         1,
                         amp=amplitudes,
                         sigma=sigma,
                         center_x=center_x,
                         center_y=center_y,
                         e1=e1,
                         e2=e2)
     flux_true = lensAnalysis.LensLightModel.surface_brightness(
         1., 1., kwargs_profile)
     npt.assert_almost_equal(flux / flux_true, 1, decimal=1)
Exemplo n.º 2
0
    def test_function_split(self):
        """

        :return:
        """
        multiGaussian = MultiGaussian()
        multiGaussianEllipse = MultiGaussianEllipse()
        output = multiGaussian.function_split(x=1., y=1., amp=[1., 2], sigma=[1, 2], center_x=0, center_y=0)
        output_2 = multiGaussianEllipse.function_split(x=1., y=1., amp=[1., 2], sigma=[1, 2], e1=0, e2=0, center_x=0, center_y=0)
        npt.assert_almost_equal(output[0], output_2[0], decimal=8)
        npt.assert_almost_equal(output[1], output_2[1], decimal=8)
Exemplo n.º 3
0
    def test_light2mass_mge(self):
        from lenstronomy.LightModel.Profiles.gaussian import MultiGaussianEllipse
        multiGaussianEllipse = MultiGaussianEllipse()
        x_grid, y_grid = util.make_grid(numPix=100, deltapix=0.05)
        kwargs_light = [{
            'amp': [2, 1],
            'sigma': [0.1, 1],
            'center_x': 0,
            'center_y': 0,
            'e1': 0.1,
            'e2': 0
        }]
        light_model_list = ['MULTI_GAUSSIAN_ELLIPSE']
        lensAnalysis = LensAnalysis(
            kwargs_model={'lens_light_model_list': light_model_list})
        kwargs_mge = lensAnalysis.light2mass_mge(
            kwargs_lens_light=kwargs_light,
            numPix=100,
            deltaPix=0.05,
            elliptical=True)
        npt.assert_almost_equal(kwargs_mge['e1'],
                                kwargs_light[0]['e1'],
                                decimal=2)

        del kwargs_light[0]['center_x']
        del kwargs_light[0]['center_y']
        kwargs_mge = lensAnalysis.light2mass_mge(
            kwargs_lens_light=kwargs_light,
            numPix=100,
            deltaPix=0.05,
            elliptical=False)
        npt.assert_almost_equal(kwargs_mge['center_x'], 0, decimal=2)
Exemplo n.º 4
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!')
Exemplo n.º 5
0
    def test_light_3d(self):
        gaussianEllipse = GaussianEllipse()
        gaussian = Gaussian()

        sigma = 1
        r = 1.
        amp = 1.
        flux_spherical = gaussian.light_3d(r, amp, sigma)
        flux = gaussianEllipse.light_3d(r, amp, sigma)
        npt.assert_almost_equal(flux, flux_spherical, decimal=8)

        multiGaussian = MultiGaussian()
        multiGaussianEllipse = MultiGaussianEllipse()
        amp = [1, 2]
        sigma = [1., 2]
        flux_spherical = multiGaussian.light_3d(r, amp, sigma)
        flux = multiGaussianEllipse.light_3d(r, amp, sigma)
        npt.assert_almost_equal(flux, flux_spherical, decimal=8)
Exemplo n.º 6
0
    def test_multi_gaussian_decomposition_ellipse(self):
        Rs = 1.
        kwargs_light = [{'Rs': Rs, 'amp': 1., 'center_x': 0, 'center_y': 0}]
        kwargs_options = {'light_model_list': ['HERNQUIST']}
        lightModel = LightModel(**kwargs_options)
        profile = LightProfileAnalysis(light_model=lightModel)

        kwargs_mge = profile.multi_gaussian_decomposition_ellipse(
            kwargs_light,
            grid_spacing=0.01,
            grid_num=100,
            model_bool_list=None,
            n_comp=20,
            center_x=None,
            center_y=None)
        mge = MultiGaussianEllipse()
        r_array = np.logspace(start=-2, stop=0.5, num=10)
        flux = mge.function(r_array, 0, **kwargs_mge)
        flux_true = lightModel.surface_brightness(r_array, 0, kwargs_light)
        npt.assert_almost_equal(flux / flux_true, 1, decimal=2)

        # elliptic

        Rs = 1.
        kwargs_light = [{
            'Rs': Rs,
            'amp': 1.,
            'e1': 0.1,
            'e2': 0,
            'center_x': 0,
            'center_y': 0
        }]
        kwargs_options = {'light_model_list': ['HERNQUIST_ELLIPSE']}
        lightModel = LightModel(**kwargs_options)
        profile = LightProfileAnalysis(light_model=lightModel)

        kwargs_mge = profile.multi_gaussian_decomposition_ellipse(
            kwargs_light,
            grid_spacing=0.1,
            grid_num=400,
            model_bool_list=None,
            n_comp=20,
            center_x=None,
            center_y=None)

        print(kwargs_mge['e1'])
        mge = MultiGaussianEllipse()
        r_array = np.logspace(start=-2, stop=0.5, num=10)
        flux = mge.function(r_array, 0, **kwargs_mge)
        flux_true = lightModel.surface_brightness(r_array, 0, kwargs_light)

        npt.assert_almost_equal(flux / flux_true, 1, decimal=1)
Exemplo n.º 7
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)
Exemplo n.º 8
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!')