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
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)
def test_raise(self): with self.assertRaises(ValueError): kwargs_model = {'anisotropy_model': 'const'} kwargs_aperture = {'center_ra': 0, 'width': 1, 'length': 1, 'angle': 0, 'center_dec': 0, 'aperture_type': 'slit'} kwargs_cosmo = {'d_d': 1000, 'd_s': 1500, 'd_ds': 800} kwargs_psf = {'psf_type': 'GAUSSIAN', 'fwhm': 1} Galkin(kwargs_model, kwargs_aperture, kwargs_psf, kwargs_cosmo, kwargs_numerics={}, analytic_kinematics=True)
def test_log_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' psf_fwhm = 0.7 # Gaussian FWHM psf kwargs_cosmo = {'d_d': 1000, 'd_s': 1500, 'd_ds': 800} kwargs_numerics_linear = {'interpol_grid_num': 500, 'log_integration': False, 'max_integrate': 10, 'min_integrate': 0.001} kwargs_numerics_log = {'interpol_grid_num': 500, 'log_integration': True, 'max_integrate': 10, 'min_integrate': 0.001} kwargs_aperture = {'width': 1, 'length': 1., 'aperture_type': aperture_type} 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) galkin_log = Galkin(kwargs_model=kwargs_model, kwargs_aperture=kwargs_aperture, kwargs_psf=kwargs_psf, kwargs_cosmo=kwargs_cosmo, kwargs_numerics=kwargs_numerics_log) R = np.linspace(0.05, 1, 100) lin_I_R = np.zeros_like(R) log_I_R = np.zeros_like(R) for i in range(len(R)): lin_I_R[i] = galkin_linear.numerics._I_R_sigma2(R[i], kwargs_profile, kwargs_light, kwargs_anisotropy) log_I_R[i] = galkin_log.numerics._I_R_sigma2(R[i], kwargs_profile, kwargs_light, kwargs_anisotropy) print(log_I_R/lin_I_R) for i in range(len(R)): npt.assert_almost_equal(log_I_R[i] / lin_I_R[i], 1, decimal=2)
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 = 'OsipkovMerritt' 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} 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}] # 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 lens_analysis = LensAnalysis({'lens_light_model_list': ['SERSIC'], 'lens_model_list': []}) r_eff = lens_analysis.half_light_radius_lens(kwargs_light, deltaPix=0.1, numPix=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') galkin = Galkin(mass_profile_list, light_profile_list_hernquist, aperture_type=aperture_type, anisotropy_model=anisotropy_type, fwhm=psf_fwhm, kwargs_cosmo=kwargs_cosmo) sigma_v = galkin.vel_disp(kwargs_profile, kwargs_light_hernquist, kwargs_anisotropy, kwargs_aperture) galkin = Galkin(mass_profile_list, light_profile_list_mge, aperture_type=aperture_type, anisotropy_model=anisotropy_type, fwhm=psf_fwhm, kwargs_cosmo=kwargs_cosmo) sigma_v2 = galkin.vel_disp(kwargs_profile, kwargs_light_mge, kwargs_anisotropy, kwargs_aperture) 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)
def galkin_settings(self, kwargs_lens, kwargs_lens_light, r_eff=None, theta_E=None, gamma=None): """ :param kwargs_lens: lens model keyword argument list :param kwargs_lens_light: deflector light keyword argument list :param r_eff: half-light radius (optional) :param theta_E: Einstein radius (optional) :param gamma: local power-law slope at the Einstein radius (optional) :return: Galkin() instance and mass and light profiles configured for the Galkin module """ if r_eff is None: r_eff = self._lensLightProfile.half_light_radius(kwargs_lens_light, grid_spacing=0.05, grid_num=200, center_x=None, center_y=None, model_bool_list=self._light_model_kinematics_bool) if theta_E is None: theta_E = self._lensMassProfile.effective_einstein_radius(kwargs_lens, center_x=None, center_y=None, model_bool_list=self._lens_model_kinematics_bool, grid_num=200, grid_spacing=0.05, get_precision=False, verbose=True) if gamma is None and self._analytic_kinematics is True: gamma = self._lensMassProfile.profile_slope(kwargs_lens, theta_E, center_x=None, center_y=None, model_list_bool=self._lens_model_kinematics_bool, num_points=10) mass_profile_list, kwargs_profile = self.kinematic_lens_profiles(kwargs_lens, MGE_fit=self._MGE_mass, theta_E=theta_E, model_kinematics_bool=self._lens_model_kinematics_bool, kwargs_mge=self._kwargs_mge_mass, gamma=gamma, analytic_kinematics=self._analytic_kinematics) light_profile_list, kwargs_light = self.kinematic_light_profile(kwargs_lens_light, r_eff=r_eff, MGE_fit=self._MGE_light, kwargs_mge=self._kwargs_mge_light, model_kinematics_bool=self._light_model_kinematics_bool, Hernquist_approx=self._Hernquist_approx, analytic_kinematics=self._analytic_kinematics) kwargs_model = {'mass_profile_list': mass_profile_list, 'light_profile_list': light_profile_list, 'anisotropy_model': self._anisotropy_model} if self._multi_observations is True: galkin = GalkinMultiObservation(kwargs_model=kwargs_model, kwargs_aperture_list=self._kwargs_aperture_kin, kwargs_psf_list=self._kwargs_psf_kin, kwargs_cosmo=self._kwargs_cosmo, kwargs_numerics=self._kwargs_numerics_kin, analytic_kinematics=self._analytic_kinematics) else: galkin = Galkin(kwargs_model=kwargs_model, kwargs_aperture=self._kwargs_aperture_kin, kwargs_psf=self._kwargs_psf_kin, kwargs_cosmo=self._kwargs_cosmo, kwargs_numerics=self._kwargs_numerics_kin, analytic_kinematics=self._analytic_kinematics) return galkin, kwargs_profile, kwargs_light
def test_mge_light_and_mass(self): # anisotropy profile anisotropy_type = 'OsipkovMerritt' 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} 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}] galkin = Galkin(mass_profile_list, light_profile_list, aperture_type=aperture_type, anisotropy_model=anisotropy_type, fwhm=psf_fwhm, kwargs_cosmo=kwargs_cosmo) sigma_v = galkin.vel_disp(kwargs_profile, kwargs_light, kwargs_anisotropy, kwargs_aperture) galkin = Galkin(mass_profile_list_mge, light_profile_list_mge, aperture_type=aperture_type, anisotropy_model=anisotropy_type, fwhm=psf_fwhm, kwargs_cosmo=kwargs_cosmo) sigma_v2 = galkin.vel_disp(kwargs_profile_mge, kwargs_light_mge, kwargs_anisotropy, kwargs_aperture) 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)
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)
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)
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': r_eff, 'sigma0': 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 = 'OsipkovMerritt' 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 = {'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 = {'sampling_number': 1000, 'interpol_grid_num': 500, 'log_integration': True, 'max_integrate': 100} galkin = Galkin(mass_profile_list, light_profile_list, aperture_type=aperture_type, anisotropy_model=anisotropy_type, fwhm=psf_fwhm, kwargs_cosmo=kwargs_cosmo, kwargs_numerics=kwargs_numerics) sigma_v = galkin.vel_disp(kwargs_profile, kwargs_light, kwargs_anisotropy, kwargs_aperture) kwargs_numerics = {'sampling_number': 1000, 'interpol_grid_num': 500, 'log_integration': False, 'max_integrate': 10} galkin = Galkin(mass_profile_list, light_profile_list, aperture_type=aperture_type, anisotropy_model=anisotropy_type, fwhm=psf_fwhm, kwargs_cosmo=kwargs_cosmo, kwargs_numerics=kwargs_numerics) sigma_v_lin = galkin.vel_disp(kwargs_profile, kwargs_light, kwargs_anisotropy, kwargs_aperture) los_disp = Velocity_dispersion(beta_const=False, b_prior=False, kwargs_cosmo=kwargs_cosmo) sigma_v2 = los_disp.vel_disp(gamma, theta_E, r_eff/0.551, aniso_param=r_ani, R_slit=length, dR_slit=width, FWHM=psf_fwhm, num=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)
def test_log_vs_linear_integral(self): # light profile light_profile_list = ['HERNQUIST'] r_eff = .5 kwargs_light = [{'Rs': r_eff, 'sigma0': 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 = 'OsipkovMerritt' 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} psf_fwhm = 0.7 # Gaussian FWHM psf kwargs_cosmo = {'D_d': 1000, 'D_s': 1500, 'D_ds': 800} kwargs_numerics_log = {'sampling_number': 1000, 'interpol_grid_num': 500, 'log_integration': True, 'max_integrate': 10} kwargs_numerics_linear = {'sampling_number': 1000, 'interpol_grid_num': 500, 'log_integration': False, 'max_integrate': 10} galkin_linear = Galkin(mass_profile_list, light_profile_list, aperture_type=aperture_type, anisotropy_model=anisotropy_type, fwhm=psf_fwhm, kwargs_cosmo=kwargs_cosmo, kwargs_numerics=kwargs_numerics_linear) sigma_v = galkin_linear.vel_disp(kwargs_profile, kwargs_light, kwargs_anisotropy, kwargs_aperture) galkin_log = Galkin(mass_profile_list, light_profile_list, aperture_type=aperture_type, anisotropy_model=anisotropy_type, fwhm=psf_fwhm, kwargs_cosmo=kwargs_cosmo, kwargs_numerics=kwargs_numerics_log) sigma_v2 = galkin_log.vel_disp(kwargs_profile, kwargs_light, kwargs_anisotropy, kwargs_aperture) 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=2)
def test_log_linear_integral(self): # light profile light_profile_list = ['HERNQUIST'] r_eff = .5 kwargs_light = [{'Rs': r_eff, 'sigma0': 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 = 'OsipkovMerritt' r_ani = 2. kwargs_anisotropy = {'r_ani': r_ani} # anisotropy radius [arcsec] # aperture as slit aperture_type = 'slit' psf_fwhm = 0.7 # Gaussian FWHM psf kwargs_cosmo = {'D_d': 1000, 'D_s': 1500, 'D_ds': 800} kwargs_numerics_linear = {'sampling_number': 1000, 'interpol_grid_num': 500, 'log_integration': False, 'max_integrate': 10, 'min_integrate': 0.001} kwargs_numerics_log = {'sampling_number': 1000, 'interpol_grid_num': 500, 'log_integration': True, 'max_integrate': 10, 'min_integrate': 0.001} galkin_linear = Galkin(mass_profile_list, light_profile_list, aperture_type=aperture_type, anisotropy_model=anisotropy_type, fwhm=psf_fwhm, kwargs_cosmo=kwargs_cosmo, kwargs_numerics=kwargs_numerics_linear) galkin_log = Galkin(mass_profile_list, light_profile_list, aperture_type=aperture_type, anisotropy_model=anisotropy_type, fwhm=psf_fwhm, kwargs_cosmo=kwargs_cosmo, kwargs_numerics=kwargs_numerics_log) R = np.linspace(0.05, 1, 100) lin_I_R = np.zeros_like(R) log_I_R = np.zeros_like(R) for i in range(len(R)): lin_I_R[i] = galkin_linear.I_R_simga2(R[i], kwargs_profile, kwargs_light, kwargs_anisotropy) log_I_R[i] = galkin_log.I_R_simga2(R[i], kwargs_profile, kwargs_light, kwargs_anisotropy) print(log_I_R/lin_I_R) for i in range(len(R)): npt.assert_almost_equal(log_I_R[i] / lin_I_R[i], 1, decimal=2)
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)
def test_mge_power_law_lens(self): """ compare power-law profiles analytical vs. numerical :return: """ # anisotropy profile anisotropy_type = 'OsipkovMerritt' 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 lens profile lensModel = LensModel(mass_profile_list) r_array = np.logspace(-2, 1, 100) * theta_E 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} galkin = Galkin(mass_profile_list, light_profile_list, anisotropy_model=anisotropy_type, kwargs_psf=kwargs_psf, kwargs_cosmo=kwargs_cosmo, kwargs_aperture=kwargs_aperture) sigma_v = galkin.vel_disp(kwargs_profile, kwargs_light, kwargs_anisotropy) galkin = Galkin(mass_profile_list_mge, light_profile_list, anisotropy_model=anisotropy_type, kwargs_psf=kwargs_psf, kwargs_cosmo=kwargs_cosmo, kwargs_aperture=kwargs_aperture) sigma_v2 = galkin.vel_disp(kwargs_profile_mge, kwargs_light, 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)
def velocity_disperson_numerical(self, kwargs_lens, kwargs_lens_light, kwargs_anisotropy, kwargs_aperture, psf_fwhm, aperture_type, anisotropy_model, r_eff=1., kwargs_numerics={}, MGE_light=False, MGE_mass=False): """ :param kwargs_lens: :param kwargs_lens_light: :param kwargs_anisotropy: :param kwargs_aperature: :return: """ kwargs_cosmo = { 'D_d': self.lensCosmo.D_d, 'D_s': self.lensCosmo.D_s, 'D_ds': self.lensCosmo.D_ds } mass_profile_list = [] kwargs_profile = [] lens_model_internal_bool = self.kwargs_options.get( 'lens_model_deflector_bool', [True] * len(kwargs_lens)) for i, lens_model in enumerate(self.kwargs_options['lens_model_list']): if lens_model_internal_bool[i]: mass_profile_list.append(lens_model) kwargs_lens_i = { k: v for k, v in kwargs_lens[i].items() if not k in ['center_x', 'center_y'] } kwargs_profile.append(kwargs_lens_i) if MGE_mass is True: massModel = LensModelExtensions(lens_model_list=mass_profile_list) theta_E = massModel.effective_einstein_radius(kwargs_lens) r_array = np.logspace(-4, 2, 200) * theta_E mass_r = massModel.kappa(r_array, 0, kwargs_profile) amps, sigmas, norm = mge.mge_1d(r_array, mass_r, N=20) mass_profile_list = ['MULTI_GAUSSIAN_KAPPA'] kwargs_profile = [{'amp': amps, 'sigma': sigmas}] light_profile_list = [] kwargs_light = [] lens_light_model_internal_bool = self.kwargs_options.get( 'light_model_deflector_bool', [True] * len(kwargs_lens_light)) for i, light_model in enumerate( self.kwargs_options['lens_light_model_list']): if lens_light_model_internal_bool[i]: light_profile_list.append(light_model) kwargs_Lens_light_i = { k: v for k, v in kwargs_lens_light[i].items() if not k in ['center_x', 'center_y'] } if 'q' in kwargs_Lens_light_i: kwargs_Lens_light_i['q'] = 1 kwargs_light.append(kwargs_Lens_light_i) if MGE_light is True: lightModel = LightModel(light_profile_list) r_array = np.logspace(-3, 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 = ['MULTI_GAUSSIAN'] kwargs_light = [{'amp': amps, 'sigma': sigmas}] galkin = Galkin(mass_profile_list, light_profile_list, aperture_type=aperture_type, anisotropy_model=anisotropy_model, fwhm=psf_fwhm, kwargs_cosmo=kwargs_cosmo, kwargs_numerics=kwargs_numerics) sigma_v = galkin.vel_disp(kwargs_profile, kwargs_light, kwargs_anisotropy, kwargs_aperture, r_eff=r_eff) return sigma_v
def velocity_dispersion_numerical(self, kwargs_lens, kwargs_lens_light, kwargs_anisotropy, kwargs_aperture, kwargs_psf, anisotropy_model, r_eff=None, theta_E=None, kwargs_numerics={}, MGE_light=False, kwargs_mge_light=None, MGE_mass=False, kwargs_mge_mass=None, Hernquist_approx=False, kappa_ext=0): """ Computes the LOS velocity dispersion of the deflector galaxy with arbitrary combinations of light and mass models. For a detailed description, visit the description of the Galkin() class. Additionally to executing the GalKin routine, it has an optional Multi-Gaussian-Expansion decomposition of lens and light models that do not have a three-dimensional distribution built in, such as Sersic profiles etc. The center of all the lens and lens light models that are part of the kinematic estimate must be centered on the same point. :param kwargs_lens: lens model parameters :param kwargs_lens_light: lens light parameters :param kwargs_anisotropy: anisotropy parameters (see Galkin module) :param kwargs_aperture: aperture parameters (see Galkin module) :param kwargs_psf: seeing conditions and model (see GalKin module) :param anisotropy_model: stellar anisotropy model (see Galkin module) :param r_eff: a rough estimate of the half light radius of the lens light in case of computing the MGE of the light profile :param theta_E: a rough estimate of the Einstein radius when performing the MGE of the deflector :param kwargs_numerics: keyword arguments that contain numerical options (see Galkin module) :param MGE_light: bool, if true performs the MGE for the light distribution :param MGE_mass: bool, if true performs the MGE for the mass distribution :param Hernquist_approx: bool, if True, uses a Hernquist light profile matched to the half light radius of the deflector light profile to compute the kinematics :param kappa_ext: external convergence not accounted in the lens models :param kwargs_mge_light: keyword arguments that go into the MGE decomposition routine :param kwargs_mge_mass: keyword arguments that go into the MGE decomposition routine :return: LOS velocity dispersion [km/s] """ mass_profile_list, kwargs_profile = self.kinematic_lens_profiles( kwargs_lens, MGE_fit=MGE_mass, theta_E=theta_E, model_kinematics_bool=self._lens_model_kinematics_bool, kwargs_mge=kwargs_mge_mass) light_profile_list, kwargs_light = self.kinematic_light_profile( kwargs_lens_light, r_eff=r_eff, MGE_fit=MGE_light, kwargs_mge=kwargs_mge_light, model_kinematics_bool=self._light_model_kinematics_bool, Hernquist_approx=Hernquist_approx) galkin = Galkin(mass_profile_list, light_profile_list, kwargs_aperture=kwargs_aperture, kwargs_psf=kwargs_psf, anisotropy_model=anisotropy_model, kwargs_cosmo=self._kwargs_cosmo, **kwargs_numerics) sigma = galkin.vel_disp(kwargs_profile, kwargs_light, kwargs_anisotropy) sigma *= np.sqrt(1 - kappa_ext) return sigma
def velocity_dispersion_numerical(self, kwargs_lens, kwargs_lens_light, kwargs_anisotropy, kwargs_aperture, psf_fwhm, aperture_type, anisotropy_model, r_eff=None, kwargs_numerics={}, MGE_light=False, MGE_mass=False, lens_model_kinematics_bool=None, light_model_kinematics_bool=None, Hernquist_approx=False): """ Computes the LOS velocity dispersion of the deflector galaxy with arbitrary combinations of light and mass models. For a detailed description, visit the description of the Galkin() class. Additionaly to executing the Galkin routine, it has an optional Multi-Gaussian-Expansion decomposition of lens and light models that do not have a three-dimensional distribution built in, such as Sersic profiles etc. The center of all the lens and lens light models that are part of the kinematic estimate must be centered on the same point. :param kwargs_lens: lens model parameters :param kwargs_lens_light: lens light parameters :param kwargs_anisotropy: anisotropy parameters (see Galkin module) :param kwargs_aperture: aperture parameters (see Galkin module) :param psf_fwhm: full width at half maximum of the seeing (Gaussian form) :param aperture_type: type of aperture (see Galkin module :param anisotropy_model: stellar anisotropy model (see Galkin module) :param r_eff: a rough estimate of the half light radius of the lens light in case of computing the MGE of the light profile :param kwargs_numerics: keyword arguments that contain numerical options (see Galkin module) :param MGE_light: bool, if true performs the MGE for the light distribution :param MGE_mass: bool, if true performs the MGE for the mass distribution :param lens_model_kinematics_bool: bool list of length of the lens model. Only takes a subset of all the models as part of the kinematics computation (can be used to ignore substructure, shear etc that do not describe the main deflector potential :param light_model_kinematics_bool: bool list of length of the light model. Only takes a subset of all the models as part of the kinematics computation (can be used to ignore light components that do not describe the main deflector :return: LOS velocity dispersion [km/s] """ kwargs_cosmo = { 'D_d': self.lensCosmo.D_d, 'D_s': self.lensCosmo.D_s, 'D_ds': self.lensCosmo.D_ds } mass_profile_list = [] kwargs_profile = [] if lens_model_kinematics_bool is None: lens_model_kinematics_bool = [True] * len(kwargs_lens) for i, lens_model in enumerate(self.kwargs_options['lens_model_list']): if lens_model_kinematics_bool[i] is True: mass_profile_list.append(lens_model) if lens_model in ['INTERPOL', 'INTERPOL_SCLAED']: center_x, center_y = self._lensModelExt.lens_center( kwargs_lens, k=i) kwargs_lens_i = copy.deepcopy(kwargs_lens[i]) kwargs_lens_i['grid_interp_x'] -= center_x kwargs_lens_i['grid_interp_y'] -= center_y else: kwargs_lens_i = { k: v for k, v in kwargs_lens[i].items() if not k in ['center_x', 'center_y'] } kwargs_profile.append(kwargs_lens_i) if MGE_mass is True: lensModel = LensModel(lens_model_list=mass_profile_list) massModel = LensModelExtensions(lensModel) theta_E = massModel.effective_einstein_radius(kwargs_profile) r_array = np.logspace(-4, 2, 200) * theta_E mass_r = lensModel.kappa(r_array, np.zeros_like(r_array), kwargs_profile) amps, sigmas, norm = mge.mge_1d(r_array, mass_r, N=20) mass_profile_list = ['MULTI_GAUSSIAN_KAPPA'] kwargs_profile = [{'amp': amps, 'sigma': sigmas}] light_profile_list = [] kwargs_light = [] if light_model_kinematics_bool is None: light_model_kinematics_bool = [True] * len(kwargs_lens_light) for i, light_model in enumerate( self.kwargs_options['lens_light_model_list']): if light_model_kinematics_bool[i]: light_profile_list.append(light_model) kwargs_lens_light_i = { k: v for k, v in kwargs_lens_light[i].items() if not k in ['center_x', 'center_y'] } if 'q' in kwargs_lens_light_i: kwargs_lens_light_i['q'] = 1 kwargs_light.append(kwargs_lens_light_i) if r_eff is None: lensAnalysis = LensAnalysis( {'lens_light_model_list': light_profile_list}) r_eff = lensAnalysis.half_light_radius_lens( kwargs_light, model_bool_list=light_model_kinematics_bool) if Hernquist_approx is True: light_profile_list = ['HERNQUIST'] kwargs_light = [{'Rs': r_eff, 'amp': 1.}] else: if MGE_light is True: lightModel = LightModel(light_profile_list) r_array = np.logspace(-3, 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 = ['MULTI_GAUSSIAN'] kwargs_light = [{'amp': amps, 'sigma': sigmas}] galkin = Galkin(mass_profile_list, light_profile_list, aperture_type=aperture_type, anisotropy_model=anisotropy_model, fwhm=psf_fwhm, kwargs_cosmo=kwargs_cosmo, **kwargs_numerics) sigma2 = galkin.vel_disp(kwargs_profile, kwargs_light, kwargs_anisotropy, kwargs_aperture) return sigma2
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)
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)
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)
def velocity_dispersion_numerical(self, kwargs_lens, kwargs_lens_light, kwargs_anisotropy, kwargs_aperture, psf_fwhm, aperture_type, anisotropy_model, r_eff, psf_type='GAUSSIAN', moffat_beta=2.6, kwargs_numerics={}, MGE_light=False, MGE_mass=False, lens_model_kinematics_bool=None, light_model_kinematics_bool=None, Hernquist_approx=False, kappa_ext=0): """ Computes the LOS velocity dispersion of the deflector galaxy with arbitrary combinations of light and mass models. For a detailed description, visit the description of the Galkin() class. Additionaly to executing the Galkin routine, it has an optional Multi-Gaussian-Expansion decomposition of lens and light models that do not have a three-dimensional distribution built in, such as Sersic profiles etc. The center of all the lens and lens light models that are part of the kinematic estimate must be centered on the same point. :param kwargs_lens: lens model parameters :param kwargs_lens_light: lens light parameters :param kwargs_anisotropy: anisotropy parameters (see Galkin module) :param kwargs_aperture: aperture parameters (see Galkin module) :param psf_fwhm: full width at half maximum of the seeing (Gaussian form) :param psf_type: string, point spread functino type, current support for 'GAUSSIAN' and 'MOFFAT' :param moffat_beta: float, beta parameter of Moffat profile :param aperture_type: type of aperture (see Galkin module :param anisotropy_model: stellar anisotropy model (see Galkin module) :param r_eff: a rough estimate of the half light radius of the lens light in case of computing the MGE of the light profile :param kwargs_numerics: keyword arguments that contain numerical options (see Galkin module) :param MGE_light: bool, if true performs the MGE for the light distribution :param MGE_mass: bool, if true performs the MGE for the mass distribution :param lens_model_kinematics_bool: bool list of length of the lens model. Only takes a subset of all the models as part of the kinematics computation (can be used to ignore substructure, shear etc that do not describe the main deflector potential :param light_model_kinematics_bool: bool list of length of the light model. Only takes a subset of all the models as part of the kinematics computation (can be used to ignore light components that do not describe the main deflector :param Hernquist_approx: bool, if True, uses a Hernquist light profile matched to the half light radius of the deflector light profile to compute the kinematics :param kappa_ext: external convergence not accounted in the lens models :return: LOS velocity dispersion [km/s] """ kwargs_cosmo = { 'D_d': self.lensCosmo.D_d, 'D_s': self.lensCosmo.D_s, 'D_ds': self.lensCosmo.D_ds } mass_profile_list, kwargs_profile, light_profile_list, kwargs_light = self.kinematic_profiles( kwargs_lens, kwargs_lens_light, r_eff=r_eff, MGE_light=MGE_light, MGE_mass=MGE_mass, lens_model_kinematics_bool=lens_model_kinematics_bool, light_model_kinematics_bool=light_model_kinematics_bool, Hernquist_approx=Hernquist_approx) galkin = Galkin(mass_profile_list, light_profile_list, aperture_type=aperture_type, anisotropy_model=anisotropy_model, fwhm=psf_fwhm, psf_type=psf_type, moffat_beta=moffat_beta, kwargs_cosmo=kwargs_cosmo, **kwargs_numerics) sigma = galkin.vel_disp(kwargs_profile, kwargs_light, kwargs_anisotropy, kwargs_aperture) sigma *= np.sqrt(1 - kappa_ext) return sigma
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)