Exemplo n.º 1
0
    def test_compare_power_law(self):
        """
        compare power-law profiles analytical vs. numerical
        :return:
        """
        # light profile
        light_profile_list = ['HERNQUIST']
        r_eff = 1.5
        kwargs_light = [{'Rs':  0.551 * r_eff, 'amp': 1.}]  # effective half light radius (2d projected) in arcsec
        # 0.551 *
        # mass profile
        mass_profile_list = ['SPP']
        theta_E = 1.2
        gamma = 2.
        kwargs_profile = [{'theta_E': theta_E, 'gamma': gamma}]  # Einstein radius (arcsec) and power-law slope

        # anisotropy profile
        anisotropy_type = 'OM'
        r_ani = 2.
        kwargs_anisotropy = {'r_ani': r_ani}  # anisotropy radius [arcsec]

        # aperture as slit
        aperture_type = 'slit'
        length = 1.
        width = 0.3
        kwargs_aperture = {'aperture_type': aperture_type, 'length': length, 'width': width, 'center_ra': 0, 'center_dec': 0, 'angle': 0}

        psf_fwhm = 1.  # Gaussian FWHM psf
        kwargs_cosmo = {'d_d': 1000, 'd_s': 1500, 'd_ds': 800}
        kwargs_numerics = {'interpol_grid_num': 500, 'log_integration': True,
                           'max_integrate': 100}
        kwargs_model = {'mass_profile_list': mass_profile_list,
                        'light_profile_list': light_profile_list,
                        'anisotropy_model': anisotropy_type}
        kwargs_psf = {'psf_type': 'GAUSSIAN', 'fwhm': psf_fwhm}
        galkin = Galkin(kwargs_model=kwargs_model, kwargs_aperture=kwargs_aperture, kwargs_psf=kwargs_psf,
                        kwargs_cosmo=kwargs_cosmo, kwargs_numerics=kwargs_numerics)
        sigma_v = galkin.dispersion(kwargs_profile, kwargs_light, kwargs_anisotropy, sampling_number=1000)

        kwargs_numerics = {'interpol_grid_num': 500, 'log_integration': False, 'max_integrate': 10}

        galkin = Galkin(kwargs_model=kwargs_model, kwargs_aperture=kwargs_aperture, kwargs_psf=kwargs_psf,
                        kwargs_cosmo=kwargs_cosmo, kwargs_numerics=kwargs_numerics, analytic_kinematics=False)
        sigma_v_lin = galkin.dispersion(kwargs_profile, kwargs_light, kwargs_anisotropy, sampling_number=1000)

        los_disp = Galkin(kwargs_model=kwargs_model, kwargs_aperture=kwargs_aperture, kwargs_psf=kwargs_psf,
                        kwargs_cosmo=kwargs_cosmo, kwargs_numerics=kwargs_numerics, analytic_kinematics=True)
        sigma_v2 = los_disp.dispersion(kwargs_mass={'gamma': gamma, 'theta_E': theta_E}, kwargs_light={'r_eff': r_eff},
                                       kwargs_anisotropy={'r_ani':r_ani}, sampling_number=1000)
        print(sigma_v, sigma_v_lin, sigma_v2, 'sigma_v Galkin (log and linear), sigma_v los dispersion')
        npt.assert_almost_equal(sigma_v2/sigma_v, 1, decimal=2)
Exemplo n.º 2
0
    def velocity_dispersion_analytical(self,
                                       theta_E,
                                       gamma,
                                       r_eff,
                                       r_ani,
                                       kappa_ext=0):
        """
        computes the LOS velocity dispersion of the lens within a slit of size R_slit x dR_slit and seeing psf_fwhm.
        The assumptions are a Hernquist light profile and the spherical power-law lens model at the first position and
        an Osipkov and Merritt ('OM') stellar anisotropy distribution.

        Further information can be found in the AnalyticKinematics() class.

        :param theta_E: Einstein radius
        :param gamma: power-low slope of the mass profile (=2 corresponds to isothermal)
        :param r_ani: anisotropy radius in units of angles
        :param r_eff: projected half-light radius
        :param kappa_ext: external convergence not accounted in the lens models
        :return: velocity dispersion in units [km/s]
        """
        galkin = Galkin(kwargs_model={'anisotropy_model': 'OM'},
                        kwargs_aperture=self._kwargs_aperture_kin,
                        kwargs_psf=self._kwargs_psf_kin,
                        kwargs_cosmo=self._kwargs_cosmo,
                        kwargs_numerics={},
                        analytic_kinematics=True)
        kwargs_profile = {'theta_E': theta_E, 'gamma': gamma}
        kwargs_light = {'r_eff': r_eff}
        kwargs_anisotropy = {'r_ani': r_ani}
        sigma_v = galkin.dispersion(kwargs_profile,
                                    kwargs_light,
                                    kwargs_anisotropy,
                                    sampling_number=self._sampling_number)
        sigma_v = self.transform_kappa_ext(sigma_v, kappa_ext=kappa_ext)
        return sigma_v
Exemplo n.º 3
0
    def test_log_vs_linear_integral(self):
        # light profile
        light_profile_list = ['HERNQUIST']
        Rs = .5
        kwargs_light = [{'Rs':  Rs, 'amp': 1.}]  # effective half light radius (2d projected) in arcsec
        # 0.551 *
        # mass profile
        mass_profile_list = ['SPP']
        theta_E = 1.2
        gamma = 2.
        kwargs_profile = [{'theta_E': theta_E, 'gamma': gamma}]  # Einstein radius (arcsec) and power-law slope

        # anisotropy profile
        anisotropy_type = 'OM'
        r_ani = 2.
        kwargs_anisotropy = {'r_ani': r_ani}  # anisotropy radius [arcsec]

        # aperture as slit
        aperture_type = 'slit'
        length = 3.8
        width = 0.9
        kwargs_aperture = {'aperture_type': aperture_type, 'length': length, 'width': width, 'center_ra': 0, 'center_dec': 0, 'angle': 0}

        psf_fwhm = 0.7  # Gaussian FWHM psf
        kwargs_cosmo = {'d_d': 1000, 'd_s': 1500, 'd_ds': 800}
        kwargs_numerics_log = {'interpol_grid_num': 500, 'log_integration': True,
                           'max_integrate': 10}
        kwargs_numerics_linear = {'interpol_grid_num': 500, 'log_integration': False,
                           'max_integrate': 10}
        kwargs_psf = {'psf_type': 'GAUSSIAN', 'fwhm': psf_fwhm}
        kwargs_model = {'mass_profile_list': mass_profile_list,
                        'light_profile_list': light_profile_list,
                        'anisotropy_model': anisotropy_type}
        galkin_linear = Galkin(kwargs_model=kwargs_model, kwargs_aperture=kwargs_aperture, kwargs_psf=kwargs_psf,
                               kwargs_cosmo=kwargs_cosmo, kwargs_numerics=kwargs_numerics_linear)

        sigma_v = galkin_linear.dispersion(kwargs_profile, kwargs_light, kwargs_anisotropy, sampling_number=1000)
        galkin_log = Galkin(kwargs_model=kwargs_model, kwargs_aperture=kwargs_aperture, kwargs_psf=kwargs_psf,
                            kwargs_cosmo=kwargs_cosmo, kwargs_numerics=kwargs_numerics_log)
        sigma_v2 = galkin_log.dispersion(kwargs_profile, kwargs_light, kwargs_anisotropy, sampling_number=1000)
        print(sigma_v, sigma_v2, 'sigma_v linear, sigma_v log')
        print((sigma_v/sigma_v2)**2)

        npt.assert_almost_equal(sigma_v/sigma_v2, 1, decimal=1)
Exemplo n.º 4
0
    def test_dispersion_map(self):
        """
        tests whether the old and new version provide the same answer
        """
        # light profile
        light_profile_list = ['HERNQUIST']
        r_eff = 1.5
        kwargs_light = [{'Rs': r_eff, 'amp': 1.}]  # effective half light radius (2d projected) in arcsec
        # 0.551 *
        # mass profile
        mass_profile_list = ['SPP']
        theta_E = 1.2
        gamma = 2.
        kwargs_mass = [{'theta_E': theta_E, 'gamma': gamma}]  # Einstein radius (arcsec) and power-law slope

        # anisotropy profile
        anisotropy_type = 'OM'
        r_ani = 2.
        kwargs_anisotropy = {'r_ani': r_ani}  # anisotropy radius [arcsec]

        # aperture as shell
        #aperture_type = 'shell'
        #kwargs_aperture_inner = {'r_in': 0., 'r_out': 0.2, 'center_dec': 0, 'center_ra': 0}

        #kwargs_aperture_outer = {'r_in': 0., 'r_out': 1.5, 'center_dec': 0, 'center_ra': 0}

        # aperture as slit
        r_bins = np.linspace(0, 2, 3)
        kwargs_ifu = {'r_bins': r_bins, 'center_ra': 0, 'center_dec': 0, 'aperture_type': 'IFU_shells'}
        kwargs_aperture = {'aperture_type': 'shell', 'r_in': r_bins[0], 'r_out': r_bins[1], 'center_ra': 0,
                           'center_dec': 0}

        psf_fwhm = 1.  # Gaussian FWHM psf
        kwargs_cosmo = {'d_d': 1000, 'd_s': 1500, 'd_ds': 800}
        kwargs_numerics = {'interpol_grid_num': 500, 'log_integration': True,
                           'max_integrate': 100}
        kwargs_model = {'mass_profile_list': mass_profile_list,
                        'light_profile_list': light_profile_list,
                        'anisotropy_model': anisotropy_type}
        kwargs_psf = {'psf_type': 'GAUSSIAN', 'fwhm': psf_fwhm}

        galkinIFU = Galkin(kwargs_aperture=kwargs_ifu, kwargs_psf=kwargs_psf, kwargs_cosmo=kwargs_cosmo,
                           kwargs_model=kwargs_model, kwargs_numerics=kwargs_numerics, analytic_kinematics=True)
        sigma_v_ifu = galkinIFU.dispersion_map(kwargs_mass={'theta_E': theta_E, 'gamma': gamma}, kwargs_light={'r_eff': r_eff},
                                               kwargs_anisotropy=kwargs_anisotropy, num_kin_sampling=1000)
        galkin = Galkin(kwargs_model, kwargs_aperture, kwargs_psf, kwargs_cosmo, kwargs_numerics,
                        analytic_kinematics=True)
        sigma_v = galkin.dispersion(kwargs_mass={'theta_E': theta_E, 'gamma': gamma}, kwargs_light={'r_eff': r_eff},
                                    kwargs_anisotropy=kwargs_anisotropy, sampling_number=1000)
        npt.assert_almost_equal(sigma_v, sigma_v_ifu[0], decimal=-1)
Exemplo n.º 5
0
    def test_OMvsGOM(self):
        """
        test OsivkopMerrit vs generalized OM model
        :return:
        """
        light_profile_list = ['HERNQUIST']
        r_eff = 1.5
        kwargs_light = [{
            'Rs': r_eff,
            'amp': 1.
        }]  # effective half light radius (2d projected) in arcsec
        # 0.551 *
        # mass profile
        mass_profile_list = ['SPP']
        theta_E = 1.2
        gamma = 2.
        kwargs_profile = [{
            'theta_E': theta_E,
            'gamma': gamma
        }]  # Einstein radius (arcsec) and power-law slope

        # aperture as slit
        aperture_type = 'slit'
        length = 1.
        width = 0.3
        kwargs_aperture = {
            'aperture_type': aperture_type,
            'length': length,
            'width': width,
            'center_ra': 0,
            'center_dec': 0,
            'angle': 0
        }

        psf_fwhm = 1.  # Gaussian FWHM psf
        kwargs_cosmo = {'d_d': 1000, 'd_s': 1500, 'd_ds': 800}
        kwargs_numerics = {
            'interpol_grid_num': 100,
            'log_integration': True,
            'max_integrate': 100,
            'min_integrate': 0.001
        }

        # anisotropy profile
        anisotropy_type = 'OM'
        r_ani = 0.2
        kwargs_anisotropy = {'r_ani': r_ani}  # anisotropy radius [arcsec]

        kwargs_model = {
            'mass_profile_list': mass_profile_list,
            'light_profile_list': light_profile_list,
            'anisotropy_model': anisotropy_type
        }
        kwargs_psf = {'psf_type': 'GAUSSIAN', 'fwhm': psf_fwhm}
        galkin = Galkin(kwargs_model=kwargs_model,
                        kwargs_aperture=kwargs_aperture,
                        kwargs_psf=kwargs_psf,
                        kwargs_cosmo=kwargs_cosmo,
                        kwargs_numerics=kwargs_numerics)
        sigma_v_om = galkin.dispersion(kwargs_profile,
                                       kwargs_light,
                                       kwargs_anisotropy,
                                       sampling_number=5000)

        # anisotropy profile
        anisotropy_type = 'GOM'

        kwargs_anisotropy = {
            'r_ani': r_ani,
            'beta_inf': 1
        }  # anisotropy radius [arcsec]

        kwargs_model = {
            'mass_profile_list': mass_profile_list,
            'light_profile_list': light_profile_list,
            'anisotropy_model': anisotropy_type
        }
        kwargs_psf = {'psf_type': 'GAUSSIAN', 'fwhm': psf_fwhm}
        galkin_gom = Galkin(kwargs_model=kwargs_model,
                            kwargs_aperture=kwargs_aperture,
                            kwargs_psf=kwargs_psf,
                            kwargs_cosmo=kwargs_cosmo,
                            kwargs_numerics=kwargs_numerics)
        sigma_v_gom = galkin_gom.dispersion(kwargs_profile,
                                            kwargs_light,
                                            kwargs_anisotropy,
                                            sampling_number=5000)
        # warning: this tests does not work to this precision for every random seed. To increase precision, increase
        # sampling_number
        npt.assert_almost_equal(sigma_v_gom, sigma_v_om, decimal=0)
Exemplo n.º 6
0
    def test_2d_vs_3d_power_law(self):
        # set up power-law light profile
        light_model = ['POWER_LAW']
        kwargs_light = [{'gamma': 2, 'amp': 1, 'e1': 0, 'e2': 0}]

        lens_model = ['SIS']
        kwargs_mass = [{'theta_E': 1}]

        anisotropy_type = 'isotropic'
        kwargs_anisotropy = {}
        kwargs_model = {
            'mass_profile_list': lens_model,
            'light_profile_list': light_model,
            'anisotropy_model': anisotropy_type
        }
        kwargs_numerics = {
            'interpol_grid_num': 2000,
            'log_integration': True,
            'max_integrate': 50,
            'min_integrate': 0.0001
        }

        kwargs_numerics_3d = copy.deepcopy(kwargs_numerics)
        kwargs_numerics_3d['lum_weight_int_method'] = False

        kwargs_numerics_2d = copy.deepcopy(kwargs_numerics)
        kwargs_numerics_2d['lum_weight_int_method'] = True

        kwargs_cosmo = {'d_d': 1000, 'd_s': 1500, 'd_ds': 800}

        # compute analytic velocity dispersion of SIS profile

        v_sigma_c2 = kwargs_mass[0]['theta_E'] * const.arcsec / (
            4 * np.pi) * kwargs_cosmo['d_s'] / kwargs_cosmo['d_ds']
        v_sigma_true = np.sqrt(v_sigma_c2) * const.c / 1000

        # aperture as slit
        aperture_type = 'slit'
        length = 1.
        width = 0.3
        kwargs_aperture = {
            'aperture_type': aperture_type,
            'length': length,
            'width': width,
            'center_ra': 0,
            'center_dec': 0,
            'angle': 0
        }
        kwargs_psf = {'psf_type': 'GAUSSIAN', 'fwhm': 0.5}

        galkin3d = Galkin(kwargs_model=kwargs_model,
                          kwargs_aperture=kwargs_aperture,
                          kwargs_psf=kwargs_psf,
                          kwargs_cosmo=kwargs_cosmo,
                          kwargs_numerics=kwargs_numerics_3d)

        galkin2d = Galkin(kwargs_model=kwargs_model,
                          kwargs_aperture=kwargs_aperture,
                          kwargs_psf=kwargs_psf,
                          kwargs_cosmo=kwargs_cosmo,
                          kwargs_numerics=kwargs_numerics_2d)

        sigma_draw_list = []
        for i in range(100):
            sigma_v_draw = galkin3d._draw_one_sigma2(kwargs_mass, kwargs_light,
                                                     kwargs_anisotropy)
            sigma_draw_list.append(sigma_v_draw)
            # print(np.sqrt(sigma_v_draw)/ 1000)

        #import matplotlib.pyplot as plt
        #plt.plot(np.sqrt(sigma_draw_list) / 1000 / v_sigma_true)
        #plt.show()

        print(np.sqrt(np.mean(sigma_draw_list)) / 1000, 'mean draw')
        print('truth = ', v_sigma_true)
        #assert 1 == 0

        sigma_v_2d = galkin2d.dispersion(kwargs_mass,
                                         kwargs_light,
                                         kwargs_anisotropy,
                                         sampling_number=1000)
        sigma_v_3d = galkin3d.dispersion(kwargs_mass,
                                         kwargs_light,
                                         kwargs_anisotropy,
                                         sampling_number=1000)
        npt.assert_almost_equal(sigma_v_2d / v_sigma_true, 1, decimal=2)
        npt.assert_almost_equal(sigma_v_3d / v_sigma_true, 1, decimal=2)
Exemplo n.º 7
0
    def test_projected_integral_vs_3d_rendering(self):

        lum_weight_int_method = True

        # light profile
        light_profile_list = ['HERNQUIST']
        r_eff = 1.5
        kwargs_light = [{
            'Rs': 0.551 * r_eff,
            'amp': 1.
        }]  # effective half light radius (2d projected) in arcsec
        # 0.551 *
        # mass profile
        mass_profile_list = ['SPP']
        theta_E = 1.2
        gamma = 2.
        kwargs_profile = [{
            'theta_E': theta_E,
            'gamma': gamma
        }]  # Einstein radius (arcsec) and power-law slope

        # anisotropy profile
        anisotropy_type = 'OM'
        r_ani = 2.
        kwargs_anisotropy = {'r_ani': r_ani}  # anisotropy radius [arcsec]

        # aperture as slit
        aperture_type = 'slit'
        length = 1.
        width = 0.3
        kwargs_aperture = {
            'aperture_type': aperture_type,
            'length': length,
            'width': width,
            'center_ra': 0,
            'center_dec': 0,
            'angle': 0
        }

        psf_fwhm = 1.  # Gaussian FWHM psf
        kwargs_cosmo = {'d_d': 1000, 'd_s': 1500, 'd_ds': 800}
        kwargs_numerics_3d = {
            'interpol_grid_num': 2000,
            'log_integration': True,
            'max_integrate': 1000,
            'min_integrate': 0.00001,
            'lum_weight_int_method': False
        }
        kwargs_model = {
            'mass_profile_list': mass_profile_list,
            'light_profile_list': light_profile_list,
            'anisotropy_model': anisotropy_type
        }
        kwargs_psf = {'psf_type': 'GAUSSIAN', 'fwhm': psf_fwhm}
        galkin = Galkin(kwargs_model=kwargs_model,
                        kwargs_aperture=kwargs_aperture,
                        kwargs_psf=kwargs_psf,
                        kwargs_cosmo=kwargs_cosmo,
                        kwargs_numerics=kwargs_numerics_3d)
        sigma_v = galkin.dispersion(kwargs_profile,
                                    kwargs_light,
                                    kwargs_anisotropy,
                                    sampling_number=1000)

        kwargs_numerics_2d = {
            'interpol_grid_num': 2000,
            'log_integration': True,
            'max_integrate': 1000,
            'min_integrate': 0.00001,
            'lum_weight_int_method': True
        }

        galkin = Galkin(kwargs_model=kwargs_model,
                        kwargs_aperture=kwargs_aperture,
                        kwargs_psf=kwargs_psf,
                        kwargs_cosmo=kwargs_cosmo,
                        kwargs_numerics=kwargs_numerics_2d,
                        analytic_kinematics=False)
        sigma_v_int_method = galkin.dispersion(kwargs_profile,
                                               kwargs_light,
                                               kwargs_anisotropy,
                                               sampling_number=1000)
        npt.assert_almost_equal(sigma_v_int_method / sigma_v, 1, decimal=2)
Exemplo n.º 8
0
    def test_log_vs_linear_integral(self):
        """
        here we test logarithmic vs linear integral in an end-to-end fashion.
        We do not demand the highest level of precisions here!!!
        We are using the luminosity-weighted velocity dispersion integration calculation in this test.
        """

        # light profile
        light_profile_list = ['HERNQUIST']
        Rs = .5
        kwargs_light = [{
            'Rs': Rs,
            'amp': 1.
        }]  # effective half light radius (2d projected) in arcsec
        # 0.551 *
        # mass profile
        mass_profile_list = ['SPP']
        theta_E = 1.2
        gamma = 2.
        kwargs_profile = [{
            'theta_E': theta_E,
            'gamma': gamma
        }]  # Einstein radius (arcsec) and power-law slope

        # anisotropy profile
        anisotropy_type = 'OM'
        r_ani = 2.
        kwargs_anisotropy = {'r_ani': r_ani}  # anisotropy radius [arcsec]

        # aperture as slit
        aperture_type = 'slit'
        length = 3.8
        width = 0.9
        kwargs_aperture = {
            'aperture_type': aperture_type,
            'length': length,
            'width': width,
            'center_ra': 0,
            'center_dec': 0,
            'angle': 0
        }

        psf_fwhm = 0.7  # Gaussian FWHM psf
        kwargs_cosmo = {'d_d': 1000, 'd_s': 1500, 'd_ds': 800}
        kwargs_numerics_log = {
            'interpol_grid_num': 1000,
            'log_integration': True,
            'max_integrate': 10,
            'min_integrate': 0.001,
            'lum_weight_int_method': True
        }
        kwargs_numerics_linear = {
            'interpol_grid_num': 1000,
            'log_integration': False,
            'max_integrate': 10,
            'min_integrate': 0.001,
            'lum_weight_int_method': True
        }
        kwargs_psf = {'psf_type': 'GAUSSIAN', 'fwhm': psf_fwhm}
        kwargs_model = {
            'mass_profile_list': mass_profile_list,
            'light_profile_list': light_profile_list,
            'anisotropy_model': anisotropy_type
        }
        galkin_linear = Galkin(kwargs_model=kwargs_model,
                               kwargs_aperture=kwargs_aperture,
                               kwargs_psf=kwargs_psf,
                               kwargs_cosmo=kwargs_cosmo,
                               kwargs_numerics=kwargs_numerics_linear)

        sigma_v_lin = galkin_linear.dispersion(kwargs_profile,
                                               kwargs_light,
                                               kwargs_anisotropy,
                                               sampling_number=1000)
        galkin_log = Galkin(kwargs_model=kwargs_model,
                            kwargs_aperture=kwargs_aperture,
                            kwargs_psf=kwargs_psf,
                            kwargs_cosmo=kwargs_cosmo,
                            kwargs_numerics=kwargs_numerics_log)
        sigma_v_log = galkin_log.dispersion(kwargs_profile,
                                            kwargs_light,
                                            kwargs_anisotropy,
                                            sampling_number=1000)
        print(sigma_v_lin, sigma_v_log, 'sigma_v linear, sigma_v log')
        print((sigma_v_lin / sigma_v_log)**2)

        npt.assert_almost_equal(sigma_v_lin / sigma_v_log, 1, decimal=2)
Exemplo n.º 9
0
    def test_sersic_vs_hernquist_kinematics(self):
        """
        attention: this test only works for Sersic indices > \approx 2!
        Lower n_sersic will result in different predictions with the Hernquist assumptions
        replacing the correct Light model!
        :return:
        """
        # anisotropy profile
        anisotropy_type = 'OM'
        r_ani = 2.
        kwargs_anisotropy = {'r_ani': r_ani}  # anisotropy radius [arcsec]

        # aperture as slit
        aperture_type = 'slit'
        length = 3.8
        width = 0.9
        kwargs_aperture = {
            'length': length,
            'width': width,
            'center_ra': 0,
            'center_dec': 0,
            'angle': 0,
            'aperture_type': aperture_type
        }

        psf_fwhm = 0.7  # Gaussian FWHM psf
        kwargs_cosmo = {'d_d': 1000, 'd_s': 1500, 'd_ds': 800}

        # light profile
        light_profile_list = ['SERSIC']
        r_sersic = .3
        n_sersic = 2.8
        kwargs_light = [{
            'amp': 1.,
            'R_sersic': r_sersic,
            'n_sersic': n_sersic,
            'center_x': 0,
            'center_y': 0
        }]  # effective half light radius (2d projected) in arcsec

        # mass profile
        mass_profile_list = ['SPP']
        theta_E = 1.2
        gamma = 2.
        kwargs_profile = [{
            'theta_E': theta_E,
            'gamma': gamma
        }]  # Einstein radius (arcsec) and power-law slope

        # Hernquist fit to Sersic profile
        profile_analysis = LightProfileAnalysis(LightModel(['SERSIC']))
        r_eff = profile_analysis.half_light_radius(kwargs_light,
                                                   grid_spacing=0.1,
                                                   grid_num=100)
        print(r_eff)
        light_profile_list_hernquist = ['HERNQUIST']
        kwargs_light_hernquist = [{'Rs': r_eff * 0.551, 'amp': 1.}]

        # mge of light profile
        lightModel = LightModel(light_profile_list)
        r_array = np.logspace(-3, 2, 100) * r_eff * 2
        print(r_sersic / r_eff, 'r_sersic/r_eff')
        flux_r = lightModel.surface_brightness(r_array, 0, kwargs_light)
        amps, sigmas, norm = mge.mge_1d(r_array, flux_r, N=20)
        light_profile_list_mge = ['MULTI_GAUSSIAN']
        kwargs_light_mge = [{'amp': amps, 'sigma': sigmas}]
        print(amps, sigmas, 'amp', 'sigma')
        kwargs_psf = {'psf_type': 'GAUSSIAN', 'fwhm': psf_fwhm}

        kwargs_model = {
            'mass_profile_list': mass_profile_list,
            'light_profile_list': light_profile_list_hernquist,
            'anisotropy_model': anisotropy_type
        }

        galkin = Galkin(kwargs_model=kwargs_model,
                        kwargs_psf=kwargs_psf,
                        kwargs_cosmo=kwargs_cosmo,
                        kwargs_aperture=kwargs_aperture,
                        kwargs_numerics={})
        sigma_v = galkin.dispersion(kwargs_profile, kwargs_light_hernquist,
                                    kwargs_anisotropy)

        kwargs_model = {
            'mass_profile_list': mass_profile_list,
            'light_profile_list': light_profile_list_mge,
            'anisotropy_model': anisotropy_type
        }
        galkin = Galkin(kwargs_model=kwargs_model,
                        kwargs_psf=kwargs_psf,
                        kwargs_cosmo=kwargs_cosmo,
                        kwargs_aperture=kwargs_aperture,
                        kwargs_numerics={})
        sigma_v2 = galkin.dispersion(kwargs_profile, kwargs_light_mge,
                                     kwargs_anisotropy)

        print(sigma_v, sigma_v2, 'sigma_v Galkin, sigma_v MGEn')
        print((sigma_v / sigma_v2)**2)

        npt.assert_almost_equal((sigma_v - sigma_v2) / sigma_v2, 0, decimal=1)
Exemplo n.º 10
0
    def test_mge_light_and_mass(self):
        # anisotropy profile
        anisotropy_model = 'OM'
        r_ani = 2.
        kwargs_anisotropy = {'r_ani': r_ani}  # anisotropy radius [arcsec]

        # aperture as slit
        aperture_type = 'slit'
        length = 3.8
        width = 0.9
        kwargs_aperture = {
            'length': length,
            'width': width,
            'center_ra': 0,
            'center_dec': 0,
            'angle': 0,
            'aperture_type': aperture_type
        }

        psf_fwhm = 0.7  # Gaussian FWHM psf
        kwargs_cosmo = {'d_d': 1000, 'd_s': 1500, 'd_ds': 800}

        # light profile
        light_profile_list = ['HERNQUIST']
        r_eff = 1.8
        kwargs_light = [{
            'Rs': r_eff,
            'amp': 1.
        }]  # effective half light radius (2d projected) in arcsec

        # mass profile
        mass_profile_list = ['SPP']
        theta_E = 1.2
        gamma = 2.
        kwargs_profile = [{
            'theta_E': theta_E,
            'gamma': gamma
        }]  # Einstein radius (arcsec) and power-law slope

        # mge of light profile
        lightModel = LightModel(light_profile_list)
        r_array = np.logspace(-2, 2, 200) * r_eff * 2
        flux_r = lightModel.surface_brightness(r_array, 0, kwargs_light)
        amps, sigmas, norm = mge.mge_1d(r_array, flux_r, N=20)
        light_profile_list_mge = ['MULTI_GAUSSIAN']
        kwargs_light_mge = [{'amp': amps, 'sigma': sigmas}]

        # mge of lens profile
        lensModel = LensModel(mass_profile_list)
        r_array = np.logspace(-2, 2, 200)
        kappa_r = lensModel.kappa(r_array, 0, kwargs_profile)
        amps, sigmas, norm = mge.mge_1d(r_array, kappa_r, N=20)
        mass_profile_list_mge = ['MULTI_GAUSSIAN_KAPPA']
        kwargs_profile_mge = [{'amp': amps, 'sigma': sigmas}]
        kwargs_psf = {'psf_type': 'GAUSSIAN', 'fwhm': psf_fwhm}
        kwargs_model = {
            'mass_profile_list': mass_profile_list,
            'light_profile_list': light_profile_list,
            'anisotropy_model': anisotropy_model
        }
        kwargs_numerics = {
            'interpol_grid_num': 100,
            'log_integration': True,
            'max_integrate': 100,
            'min_integrate': 0.01
        }
        galkin = Galkin(kwargs_model=kwargs_model,
                        kwargs_psf=kwargs_psf,
                        kwargs_cosmo=kwargs_cosmo,
                        kwargs_aperture=kwargs_aperture,
                        kwargs_numerics=kwargs_numerics)
        sigma_v = galkin.dispersion(kwargs_profile, kwargs_light,
                                    kwargs_anisotropy)

        kwargs_model_mge = {
            'mass_profile_list': mass_profile_list_mge,
            'light_profile_list': light_profile_list_mge,
            'anisotropy_model': anisotropy_model
        }

        galkin = Galkin(kwargs_model=kwargs_model_mge,
                        kwargs_psf=kwargs_psf,
                        kwargs_cosmo=kwargs_cosmo,
                        kwargs_aperture=kwargs_aperture,
                        kwargs_numerics=kwargs_numerics)
        sigma_v2 = galkin.dispersion(kwargs_profile_mge, kwargs_light_mge,
                                     kwargs_anisotropy)

        print(sigma_v, sigma_v2, 'sigma_v Galkin, sigma_v MGEn')
        print((sigma_v / sigma_v2)**2)
        npt.assert_almost_equal((sigma_v - sigma_v2) / sigma_v2, 0, decimal=2)