diff --git a/.gitignore b/.gitignore index f86ba58df..efe8d1f9a 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ develop-eggs .installed.cfg lib lib64 +docs/_build # Installer logs pip-log.txt diff --git a/HISTORY.rst b/HISTORY.rst index 5c1281a61..baaaa9441 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -298,4 +298,7 @@ History +++++++++++++++++++ * Zeus sampler implemented * Nautilus sampler implemented -* Roman telescope configuration added \ No newline at end of file +* Roman telescope configuration added +* double power-law mass profile +* generalized NFW profile +* enabled to turn off linear solver in fitting \ No newline at end of file diff --git a/docs/_build/doctrees/environment.pickle b/docs/_build/doctrees/environment.pickle deleted file mode 100644 index 5bbfaf1c3..000000000 Binary files a/docs/_build/doctrees/environment.pickle and /dev/null differ diff --git a/docs/_build/doctrees/history.doctree b/docs/_build/doctrees/history.doctree deleted file mode 100644 index 1692cdda3..000000000 Binary files a/docs/_build/doctrees/history.doctree and /dev/null differ diff --git a/docs/_build/doctrees/index.doctree b/docs/_build/doctrees/index.doctree deleted file mode 100644 index 3d3d7921f..000000000 Binary files a/docs/_build/doctrees/index.doctree and /dev/null differ diff --git a/docs/_build/doctrees/installation.doctree b/docs/_build/doctrees/installation.doctree deleted file mode 100644 index e69dc90ca..000000000 Binary files a/docs/_build/doctrees/installation.doctree and /dev/null differ diff --git a/docs/_build/doctrees/lenstronomy.LensModel.Profiles.doctree b/docs/_build/doctrees/lenstronomy.LensModel.Profiles.doctree deleted file mode 100644 index bae92a281..000000000 Binary files a/docs/_build/doctrees/lenstronomy.LensModel.Profiles.doctree and /dev/null differ diff --git a/docs/_build/doctrees/lenstronomy.Plots.doctree b/docs/_build/doctrees/lenstronomy.Plots.doctree deleted file mode 100644 index 922d94e51..000000000 Binary files a/docs/_build/doctrees/lenstronomy.Plots.doctree and /dev/null differ diff --git a/docs/_build/doctrees/lenstronomy.SimulationAPI.doctree b/docs/_build/doctrees/lenstronomy.SimulationAPI.doctree deleted file mode 100644 index 0682af306..000000000 Binary files a/docs/_build/doctrees/lenstronomy.SimulationAPI.doctree and /dev/null differ diff --git a/docs/_build/doctrees/lenstronomy.Util.doctree b/docs/_build/doctrees/lenstronomy.Util.doctree deleted file mode 100644 index dbf5f5732..000000000 Binary files a/docs/_build/doctrees/lenstronomy.Util.doctree and /dev/null differ diff --git a/docs/_build/doctrees/lenstronomy.Workflow.doctree b/docs/_build/doctrees/lenstronomy.Workflow.doctree deleted file mode 100644 index eb15d6e90..000000000 Binary files a/docs/_build/doctrees/lenstronomy.Workflow.doctree and /dev/null differ diff --git a/docs/_build/doctrees/published.doctree b/docs/_build/doctrees/published.doctree deleted file mode 100644 index 71245f2c3..000000000 Binary files a/docs/_build/doctrees/published.doctree and /dev/null differ diff --git a/docs/_build/html/.buildinfo b/docs/_build/html/.buildinfo deleted file mode 100644 index 86bfd2bc1..000000000 --- a/docs/_build/html/.buildinfo +++ /dev/null @@ -1,4 +0,0 @@ -# Sphinx build info version 1 -# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. -config: c989bb26a7c346f7dba133cfc4f72e88 -tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/docs/_build/html/_modules/index.html b/docs/_build/html/_modules/index.html deleted file mode 100644 index 3e2e43d71..000000000 --- a/docs/_build/html/_modules/index.html +++ /dev/null @@ -1,273 +0,0 @@ - - - - - - - - Overview: module code — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

All modules for which code is available

- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Analysis/kinematics_api.html b/docs/_build/html/_modules/lenstronomy/Analysis/kinematics_api.html deleted file mode 100644 index f5ef0100f..000000000 --- a/docs/_build/html/_modules/lenstronomy/Analysis/kinematics_api.html +++ /dev/null @@ -1,470 +0,0 @@ - - - - - - - - lenstronomy.Analysis.kinematics_api — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Analysis.kinematics_api

-__author__ = 'sibirrer'
-
-import numpy as np
-import copy
-from lenstronomy.GalKin.galkin_multiobservation import GalkinMultiObservation
-from lenstronomy.GalKin.galkin import Galkin
-from lenstronomy.Cosmo.lens_cosmo import LensCosmo
-from lenstronomy.Util import class_creator
-from lenstronomy.Analysis.lens_profile import LensProfileAnalysis
-from lenstronomy.Analysis.light_profile import LightProfileAnalysis
-import lenstronomy.Util.multi_gauss_expansion as mge
-
-__all__ = ['KinematicsAPI']
-
-
-
[docs]class KinematicsAPI(object): - """ - this class contains routines to compute time delays, magnification ratios, line of sight velocity dispersions etc - for a given lens model - """ - - def __init__(self, z_lens, z_source, kwargs_model, kwargs_aperture, kwargs_seeing, anisotropy_model, cosmo=None, - lens_model_kinematics_bool=None, light_model_kinematics_bool=None, multi_observations=False, - kwargs_numerics_galkin=None, analytic_kinematics=False, Hernquist_approx=False, MGE_light=False, - MGE_mass=False, kwargs_mge_light=None, kwargs_mge_mass=None, sampling_number=1000, - num_kin_sampling=1000, num_psf_sampling=100): - """ - - :param z_lens: redshift of lens - :param z_source: redshift of source - :param kwargs_model: model keyword arguments, needs 'lens_model_list', 'lens_light_model_list' - :param kwargs_aperture: spectroscopic aperture keyword arguments, see lenstronomy.Galkin.aperture for options - :param kwargs_seeing: seeing condition of spectroscopic observation, corresponds to kwargs_psf in the GalKin module specified in lenstronomy.GalKin.psf - :param cosmo: astropy.cosmology instance, if None then will be set to the default cosmology - :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 multi_observations: bool, if True uses multi-observation to predict a set of different observations with - the GalkinMultiObservation() class. kwargs_aperture and kwargs_seeing require to be lists of the individual - observations. - :param anisotropy_model: type of stellar anisotropy model. See details in MamonLokasAnisotropy() class of lenstronomy.GalKin.anisotropy - :param analytic_kinematics: boolean, if True, used the analytic JAM modeling for a power-law profile on top of a Hernquist light profile - ATTENTION: This may not be accurate for your specific problem! - :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 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 kwargs_numerics_galkin: numerical settings for the integrated line-of-sight velocity dispersion - :param kwargs_mge_mass: keyword arguments that go into the MGE decomposition routine - :param kwargs_mge_light: keyword arguments that go into the MGE decomposition routine - :param sampling_number: int, number of spectral rendering to compute the light weighted integrated LOS - dispersion within the aperture. This keyword should be chosen high enough to result in converged results within the tolerance. - :param num_kin_sampling: number of kinematic renderings on a total IFU - :param num_psf_sampling: number of PSF displacements for each kinematic rendering on the IFU - """ - self.z_d = z_lens - self.z_s = z_source - self._kwargs_aperture_kin = kwargs_aperture - self._kwargs_psf_kin = kwargs_seeing - self.lensCosmo = LensCosmo(z_lens, z_source, cosmo=cosmo) - self.LensModel, self.SourceModel, self.LensLightModel, self.PointSource, extinction_class = class_creator.create_class_instances( - all_models=True, **kwargs_model) - self._lensLightProfile = LightProfileAnalysis(light_model=self.LensLightModel) - self._lensMassProfile = LensProfileAnalysis(lens_model=self.LensModel) - self._lens_light_model_list = self.LensLightModel.profile_type_list - self._lens_model_list = self.LensModel.lens_model_list - self._kwargs_cosmo = {'d_d': self.lensCosmo.dd, 'd_s': self.lensCosmo.ds, 'd_ds': self.lensCosmo.dds} - self._lens_model_kinematics_bool = lens_model_kinematics_bool - self._light_model_kinematics_bool = light_model_kinematics_bool - self._sampling_number = sampling_number - self._num_kin_sampling = num_kin_sampling - self._num_psf_sampling = num_psf_sampling - - if kwargs_mge_mass is None: - self._kwargs_mge_mass = {'n_comp': 20} - else : - self._kwargs_mge_mass = kwargs_mge_mass - - if kwargs_mge_light is None: - self._kwargs_mge_light = {'grid_spacing': 0.01, 'grid_num': 100, 'n_comp': 20, 'center_x': None, - 'center_y': None} - else: - self._kwargs_mge_light = kwargs_mge_light - if kwargs_numerics_galkin is None: - kwargs_numerics_galkin = {'interpol_grid_num': 1000, # numerical interpolation, should converge -> infinity - 'log_integration': True, # log or linear interpolation of surface brightness and mass models - 'max_integrate': 100, - 'min_integrate': 0.001} # lower/upper bound of numerical integrals - self._kwargs_numerics_kin = kwargs_numerics_galkin - self._anisotropy_model = anisotropy_model - self._analytic_kinematics = analytic_kinematics - self._Hernquist_approx = Hernquist_approx - self._MGE_light = MGE_light - self._MGE_mass = MGE_mass - self._multi_observations = multi_observations - -
[docs] def velocity_dispersion(self, kwargs_lens, kwargs_lens_light, kwargs_anisotropy, r_eff=None, theta_E=None, - gamma=None, kappa_ext=0): - """ - API for both, analytic and numerical JAM to compute the velocity dispersion [km/s] - This routine uses the galkin_setting() routine for the Galkin configurations (see there what options and input - is relevant. - - :param kwargs_lens: lens model keyword arguments - :param kwargs_lens_light: lens light model keyword arguments - :param kwargs_anisotropy: stellar anisotropy keyword arguments - :param r_eff: projected half-light radius of the stellar light associated with the deflector galaxy, optional, - if set to None will be computed in this function with default settings that may not be accurate. - :param theta_E: Einstein radius (optional) - :param gamma: power-law slope (optional) - :param kappa_ext: external convergence (optional) - :return: velocity dispersion [km/s] - """ - galkin, kwargs_profile, kwargs_light = self.galkin_settings(kwargs_lens, kwargs_lens_light, r_eff=r_eff, - theta_E=theta_E, gamma=gamma) - 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
- -
[docs] def velocity_dispersion_map(self, kwargs_lens, kwargs_lens_light, kwargs_anisotropy, r_eff=None, theta_E=None, - gamma=None, kappa_ext=0): - """ - API for both, analytic and numerical JAM to compute the velocity dispersion map with IFU data [km/s] - - :param kwargs_lens: lens model keyword arguments - :param kwargs_lens_light: lens light model keyword arguments - :param kwargs_anisotropy: stellar anisotropy keyword arguments - :param r_eff: projected half-light radius of the stellar light associated with the deflector galaxy, optional, - if set to None will be computed in this function with default settings that may not be accurate. - :param theta_E: circularized Einstein radius, optional, if not provided will either be computed in this - function with default settings or not required - :param gamma: power-law slope at the Einstein radius, optional - :param kappa_ext: external convergence - :return: velocity dispersion [km/s] - """ - galkin, kwargs_profile, kwargs_light = self.galkin_settings(kwargs_lens, kwargs_lens_light, r_eff=r_eff, - theta_E=theta_E, gamma=gamma) - sigma_v_map = galkin.dispersion_map(kwargs_profile, kwargs_light, kwargs_anisotropy, - num_kin_sampling=self._num_kin_sampling, num_psf_sampling=self._num_psf_sampling) - sigma_v_map = self.transform_kappa_ext(sigma_v_map, kappa_ext=kappa_ext) - return sigma_v_map
- -
[docs] 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
- -
[docs] 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
- -
[docs] def kinematic_lens_profiles(self, kwargs_lens, MGE_fit=False, model_kinematics_bool=None, theta_E=None, gamma=None, - kwargs_mge=None, analytic_kinematics=False): - """ - translates the lenstronomy lens and mass profiles into a (sub) set of profiles that are compatible with the - GalKin module to compute the kinematics thereof. - The requirement is that the - profiles are centered at (0, 0) and that for all profile types there exists a 3d de-projected analytical - representation. - - :param kwargs_lens: lens model parameters - :param MGE_fit: bool, if true performs the MGE for the mass distribution - :param 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 theta_E: (optional float) estimate of the Einstein radius. If present, does not numerically compute this - quantity in this routine numerically - :param gamma: local power-law slope at the Einstein radius (optional) - :param kwargs_mge: keyword arguments that go into the MGE decomposition routine - :param analytic_kinematics: bool, if True, solves the Jeans equation analytically for the - power-law mass profile with Hernquist light profile - :return: mass_profile_list, keyword argument list - """ - if analytic_kinematics is True: - if gamma is None or theta_E is None: - raise ValueError('power-law slope and Einstein radius must be set to allow for analytic kinematics to ' - 'be computed!') - return None, {'theta_E': theta_E, 'gamma': gamma} - mass_profile_list = [] - kwargs_profile = [] - if model_kinematics_bool is None: - model_kinematics_bool = [True] * len(kwargs_lens) - for i, lens_model in enumerate(self._lens_model_list): - if model_kinematics_bool[i] is True: - mass_profile_list.append(lens_model) - if lens_model in ['INTERPOL', 'INTERPOL_SCLAED']: - center_x_i, center_y_i = self._lensMassProfile.convergence_peak(kwargs_lens, model_bool_list=i, - grid_num=200, grid_spacing=0.01, - center_x_init=0, center_y_init=0) - kwargs_lens_i = copy.deepcopy(kwargs_lens[i]) - kwargs_lens_i['grid_interp_x'] -= center_x_i - kwargs_lens_i['grid_interp_y'] -= center_y_i - 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_fit is True: - if kwargs_mge is None: - raise ValueError('kwargs_mge needs to be specified!') - if theta_E is None: - raise ValueError('rough estimate of the Einstein radius needs to be provided to compute the MGE!') - r_array = np.logspace(-4, 2, 200) * theta_E - if self._lens_model_list[0] in ['INTERPOL', 'INTERPOL_SCLAED']: - center_x, center_y = self._lensMassProfile.convergence_peak(kwargs_lens, model_bool_list=model_kinematics_bool, - grid_num=200, grid_spacing=0.01, - center_x_init=0, center_y_init=0) - else: - center_x, center_y = None, None - mass_r = self._lensMassProfile.radial_lens_profile(r_array, kwargs_lens, center_x=center_x, - center_y=center_y, model_bool_list=model_kinematics_bool) - amps, sigmas, norm = mge.mge_1d(r_array, mass_r, N=kwargs_mge.get('n_comp', 20)) - mass_profile_list = ['MULTI_GAUSSIAN_KAPPA'] - kwargs_profile = [{'amp': amps, 'sigma': sigmas}] - - return mass_profile_list, kwargs_profile
- -
[docs] def kinematic_light_profile(self, kwargs_lens_light, r_eff=None, MGE_fit=False, model_kinematics_bool=None, - Hernquist_approx=False, kwargs_mge=None, analytic_kinematics=False): - """ - setting up of the light profile to compute the kinematics in the GalKin module. The requirement is that the - profiles are centered at (0, 0) and that for all profile types there exists a 3d de-projected analytical - representation. - - :param kwargs_lens_light: deflector light model keyword argument list - :param r_eff: (optional float, else=None) Pre-calculated projected half-light radius of the deflector profile. - If not provided, numerical calculation is done in this routine if required. - :param MGE_fit: boolean, if True performs a Multi-Gaussian expansion of the radial light profile and returns - this solution. - :param model_kinematics_bool: list of booleans to indicate a subset of light profiles to be part of the physical - deflector light. - :param Hernquist_approx: boolean, if True replaces the actual light profile(s) with a Hernquist model with - matched half-light radius. - :param kwargs_mge: keyword arguments that go into the MGE decomposition routine - :param analytic_kinematics: bool, if True, solves the Jeans equation analytically for the - power-law mass profile with Hernquist light profile and adjust the settings accordingly - :return: deflector type list, keyword arguments list - """ - if analytic_kinematics is True: - if r_eff is None: - raise ValueError('half light radius "r_eff" needs to be set to allow for analytic kinematics to be ' - 'computed!') - return None, {'r_eff': r_eff} - light_profile_list = [] - kwargs_light = [] - if model_kinematics_bool is None: - model_kinematics_bool = [True] * len(kwargs_lens_light) - for i, light_model in enumerate(self._lens_light_model_list): - if model_kinematics_bool[i] is True: - 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 'e1' in kwargs_lens_light_i: - kwargs_lens_light_i['e1'] = 0 - kwargs_lens_light_i['e2'] = 0 - kwargs_light.append(kwargs_lens_light_i) - if Hernquist_approx is True: - if r_eff is None: - raise ValueError('r_eff needs to be pre-computed and specified when using the Hernquist approximation') - light_profile_list = ['HERNQUIST'] - kwargs_light = [{'Rs': r_eff * 0.551, 'amp': 1.}] - else: - if MGE_fit is True: - if kwargs_mge is None: - raise ValueError('kwargs_mge must be provided to compute the MGE') - amps, sigmas, center_x, center_y = self._lensLightProfile.multi_gaussian_decomposition( - kwargs_lens_light, model_bool_list=model_kinematics_bool, r_h=r_eff, **kwargs_mge) - light_profile_list = ['MULTI_GAUSSIAN'] - kwargs_light = [{'amp': amps, 'sigma': sigmas}] - return light_profile_list, kwargs_light
- -
[docs] def kinematics_modeling_settings(self, anisotropy_model, kwargs_numerics_galkin, analytic_kinematics=False, - Hernquist_approx=False, MGE_light=False, MGE_mass=False, kwargs_mge_light=None, - kwargs_mge_mass=None, sampling_number=1000, num_kin_sampling=1000, - num_psf_sampling=100): - """ - - :param anisotropy_model: type of stellar anisotropy model. See details in MamonLokasAnisotropy() class of lenstronomy.GalKin.anisotropy - :param analytic_kinematics: boolean, if True, used the analytic JAM modeling for a power-law profile on top of a Hernquist light profile - ATTENTION: This may not be accurate for your specific problem! - :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 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 kwargs_numerics_galkin: numerical settings for the integrated line-of-sight velocity dispersion - :param kwargs_mge_mass: keyword arguments that go into the MGE decomposition routine - :param kwargs_mge_light: keyword arguments that go into the MGE decomposition routine - :param sampling_number: number of spectral rendering on a single slit - :param num_kin_sampling: number of kinematic renderings on a total IFU - :param num_psf_sampling: number of PSF displacements for each kinematic rendering on the IFU - :return: - """ - if kwargs_mge_mass is None: - self._kwargs_mge_mass = {'n_comp': 20} - else : - self._kwargs_mge_mass = kwargs_mge_mass - - if kwargs_mge_light is None: - self._kwargs_mge_light = {'grid_spacing': 0.01, 'grid_num': 100, 'n_comp': 20, 'center_x': None, - 'center_y': None} - else: - self._kwargs_mge_light = kwargs_mge_light - self._kwargs_numerics_kin = kwargs_numerics_galkin - self._anisotropy_model = anisotropy_model - self._analytic_kinematics = analytic_kinematics - self._Hernquist_approx = Hernquist_approx - self._MGE_light = MGE_light - self._MGE_mass = MGE_mass - self._sampling_number = sampling_number - self._num_kin_sampling = num_kin_sampling - self._num_psf_sampling = num_psf_sampling
- -
[docs] @staticmethod - def transform_kappa_ext(sigma_v, kappa_ext=0): - """ - - :param sigma_v: velocity dispersion estimate of the lensing deflector without considering external convergence - :param kappa_ext: external convergence to be used in the mass-sheet degeneracy - :return: transformed velocity dispersion - """ - sigma_v_mst = sigma_v * np.sqrt(1 - kappa_ext) - return sigma_v_mst
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Analysis/lens_profile.html b/docs/_build/html/_modules/lenstronomy/Analysis/lens_profile.html deleted file mode 100644 index 7754f30de..000000000 --- a/docs/_build/html/_modules/lenstronomy/Analysis/lens_profile.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - - lenstronomy.Analysis.lens_profile — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Analysis.lens_profile

-import numpy as np
-from lenstronomy.Util import util
-from lenstronomy.Util import mask_util as mask_util
-import lenstronomy.Util.multi_gauss_expansion as mge
-from lenstronomy.Util import analysis_util
-from lenstronomy.LensModel.lens_model_extensions import LensModelExtensions
-
-__all__ = ['LensProfileAnalysis']
-
-
-
[docs]class LensProfileAnalysis(object): - """ - class with analysis routines to compute derived properties of the lens model - """ - def __init__(self, lens_model): - """ - - :param lens_model: LensModel instance - """ - self._lens_model = lens_model - -
[docs] def effective_einstein_radius(self, kwargs_lens, center_x=None, center_y=None, model_bool_list=None, grid_num=200, - grid_spacing=0.05, get_precision=False, verbose=True): - """ - computes the radius with mean convergence=1 - - :param kwargs_lens: list of lens model keyword arguments - :param center_x: position of the center (if not set, is attempting to find it from the parameters kwargs_lens) - :param center_y: position of the center (if not set, is attempting to find it from the parameters kwargs_lens) - :param model_bool_list: list of booleans indicating the addition (=True) of a model component in computing the - Einstein radius - :param grid_num: integer, number of grid points to numerically evaluate the convergence and estimate the - Einstein radius - :param grid_spacing: spacing in angular units of the grid - :param get_precision: If `True`, return the precision of estimated Einstein radius - :param verbose: boolean, if True prints warning if indication of insufficient result - :return: estimate of the Einstein radius - """ - center_x, center_y = analysis_util.profile_center(kwargs_lens, center_x, center_y) - - x_grid, y_grid = util.make_grid(numPix=grid_num, deltapix=grid_spacing) - x_grid += center_x - y_grid += center_y - kappa = self._lens_model.kappa(x_grid, y_grid, kwargs_lens, k=model_bool_list) - if self._lens_model.lens_model_list[0] in ['INTERPOL', 'INTERPOL_SCALED']: - center_x = x_grid[kappa == np.max(kappa)][0] - center_y = y_grid[kappa == np.max(kappa)][0] - - r_array = np.linspace(0, grid_num*grid_spacing/2., grid_num*2) - inner_most_bin = True - for r in r_array: - mask = np.array(1 - mask_util.mask_center_2d(center_x, center_y, r, x_grid, y_grid)) - sum_mask = np.sum(mask) - if sum_mask > 0: - kappa_mean = np.sum(kappa*mask)/np.sum(mask) - if inner_most_bin: - if kappa_mean < 1: - Warning( - "Central convergence value is subcritical <1 and hence an Einstein radius is ill defined.") - if get_precision: - return np.nan, 0 - else: - return np.nan - inner_most_bin = False - if kappa_mean < 1: - if get_precision: - return r, r_array[1] - r_array[0] - else: - return r - if verbose: - Warning("No Einstein radius computed for the following model!", kwargs_lens) - return np.nan
- -
[docs] def local_lensing_effect(self, kwargs_lens, ra_pos=0, dec_pos=0, model_list_bool=None): - """ - computes deflection, shear and convergence at (ra_pos,dec_pos) for those part of the lens model not included - in the main deflector. - - :param kwargs_lens: lens model keyword argument list - :param ra_pos: RA position where to compute the external effect - :param dec_pos: DEC position where to compute the external effect - :param model_list_bool: boolean list indicating which models effect to be added to the estimate - :return: alpha_x, alpha_y, kappa, shear1, shear2 - """ - f_x, f_y = self._lens_model.alpha(ra_pos, dec_pos, kwargs_lens, k=model_list_bool) - f_xx, f_xy, f_yx, f_yy = self._lens_model.hessian(ra_pos, dec_pos, kwargs_lens, k=model_list_bool) - kappa = (f_xx + f_yy)/2. - shear1 = 1./2 * (f_xx - f_yy) - shear2 = f_xy - return f_x, f_y, kappa, shear1, shear2
- -
[docs] def profile_slope(self, kwargs_lens, radius, center_x=None, center_y=None, model_list_bool=None, num_points=10): - """ - computes the logarithmic power-law slope of a profile. ATTENTION: this is not an observable! - - :param kwargs_lens: lens model keyword argument list - :param radius: radius from the center where to compute the logarithmic slope (angular units - :param center_x: center of profile from where to compute the slope - :param center_y: center of profile from where to compute the slope - :param model_list_bool: bool list, indicate which part of the model to consider - :param num_points: number of estimates around the Einstein radius - :return: logarithmic power-law slope - """ - center_x, center_y = analysis_util.profile_center(kwargs_lens, center_x, center_y) - x, y = util.points_on_circle(radius, num_points) - dr = 0.01 - x_dr, y_dr = util.points_on_circle(radius + dr, num_points) - - alpha_E_x_i, alpha_E_y_i = self._lens_model.alpha(center_x + x, center_y + y, kwargs_lens, k=model_list_bool) - alpha_E_r = np.sqrt(alpha_E_x_i**2 + alpha_E_y_i**2) - alpha_E_dr_x_i, alpha_E_dr_y_i = self._lens_model.alpha(center_x + x_dr, center_y + y_dr, kwargs_lens, - k=model_list_bool) - alpha_E_dr = np.sqrt(alpha_E_dr_x_i ** 2 + alpha_E_dr_y_i ** 2) - slope = np.mean(np.log(alpha_E_dr / alpha_E_r) / np.log((radius + dr) / radius)) - gamma = -slope + 2 - return gamma
- -
[docs] def mst_invariant_differential(self, kwargs_lens, radius, center_x=None, center_y=None, model_list_bool=None, - num_points=10): - """ - Average of the radial stretch differential in radial direction, divided by the radial stretch factor. - - .. math:: - \\xi = \\frac{\\partial \\lambda_{\\rm rad}}{\\partial r} \\frac{1}{\\lambda_{\\rm rad}} - - This quantity is invariant under the MST. - The specific definition is provided by Birrer 2021. Equivalent (proportional) definitions are provided by e.g. - Kochanek 2020, Sonnenfeld 2018. - - :param kwargs_lens: lens model keyword argument list - :param radius: radius from the center where to compute the MST invariant differential - :param center_x: center position - :param center_y: center position - :param model_list_bool: indicate which part of the model to consider - :param num_points: number of estimates around the radius - :return: xi - """ - center_x, center_y = analysis_util.profile_center(kwargs_lens, center_x, center_y) - x, y = util.points_on_circle(radius, num_points) - ext = LensModelExtensions(lensModel=self._lens_model) - lambda_rad, lambda_tan, orientation_angle, dlambda_tan_dtan, dlambda_tan_drad, dlambda_rad_drad, dlambda_rad_dtan, dphi_tan_dtan, dphi_tan_drad, dphi_rad_drad, dphi_rad_dtan = ext.radial_tangential_differentials(x, y, kwargs_lens, center_x=center_x, center_y=center_y) - xi = np.mean(dlambda_rad_drad/lambda_rad) - return xi
- -
[docs] def radial_lens_profile(self, r_list, kwargs_lens, center_x=None, center_y=None, model_bool_list=None): - """ - - :param r_list: list of radii to compute the spherically averaged lens light profile - :param center_x: center of the profile - :param center_y: center of the profile - :param kwargs_lens: lens parameter keyword argument list - :param model_bool_list: bool list or None, indicating which profiles to sum over - :return: flux amplitudes at r_list radii azimuthally averaged - """ - center_x, center_y = analysis_util.profile_center(kwargs_lens, center_x, center_y) - kappa_list = [] - for r in r_list: - x, y = util.points_on_circle(r, num_points=20) - f_r = self._lens_model.kappa(x + center_x, y + center_y, kwargs=kwargs_lens, k=model_bool_list) - kappa_list.append(np.average(f_r)) - return kappa_list
- -
[docs] def multi_gaussian_lens(self, kwargs_lens, center_x=None, center_y=None, model_bool_list=None, n_comp=20): - """ - multi-gaussian lens model in convergence space - - :param kwargs_lens: - :param n_comp: - :return: - """ - center_x, center_y = analysis_util.profile_center(kwargs_lens, center_x, center_y) - theta_E = self.effective_einstein_radius(kwargs_lens) - r_array = np.logspace(-4, 2, 200) * theta_E - kappa_s = self.radial_lens_profile(r_array, kwargs_lens, center_x=center_x, center_y=center_y, - model_bool_list=model_bool_list) - amplitudes, sigmas, norm = mge.mge_1d(r_array, kappa_s, N=n_comp) - return amplitudes, sigmas, center_x, center_y
- -
[docs] def mass_fraction_within_radius(self, kwargs_lens, center_x, center_y, theta_E, numPix=100): - """ - computes the mean convergence of all the different lens model components within a spherical aperture - - :param kwargs_lens: lens model keyword argument list - :param center_x: center of the aperture - :param center_y: center of the aperture - :param theta_E: radius of aperture - :return: list of average convergences for all the model components - """ - x_grid, y_grid = util.make_grid(numPix=numPix, deltapix=2.*theta_E / numPix) - x_grid += center_x - y_grid += center_y - mask = mask_util.mask_azimuthal(x_grid, y_grid, center_x, center_y, theta_E) - kappa_list = [] - for i in range(len(kwargs_lens)): - kappa = self._lens_model.kappa(x_grid, y_grid, kwargs_lens, k=i) - kappa_mean = np.sum(kappa * mask) / np.sum(mask) - kappa_list.append(kappa_mean) - return kappa_list
- -
[docs] def convergence_peak(self, kwargs_lens, model_bool_list=None, grid_num=200, grid_spacing=0.01, center_x_init=0, - center_y_init=0): - """ - computes the maximal convergence position on a grid and returns its coordinate - - :param kwargs_lens: lens model keyword argument list - :param model_bool_list: bool list (optional) to include certain models or not - :return: center_x, center_y - """ - x_grid, y_grid = util.make_grid(numPix=grid_num, deltapix=grid_spacing) - x_grid += center_x_init - y_grid += center_y_init - - kappa = self._lens_model.kappa(x_grid, y_grid, kwargs_lens, k=model_bool_list) - - center_x = x_grid[kappa == np.max(kappa)] - center_y = y_grid[kappa == np.max(kappa)] - return center_x, center_y
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Analysis/light2mass.html b/docs/_build/html/_modules/lenstronomy/Analysis/light2mass.html deleted file mode 100644 index 603741c3c..000000000 --- a/docs/_build/html/_modules/lenstronomy/Analysis/light2mass.html +++ /dev/null @@ -1,138 +0,0 @@ - - - - - - - - lenstronomy.Analysis.light2mass — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Analysis.light2mass

-import numpy as np
-from lenstronomy.Util import util
-from lenstronomy.LightModel.light_model import LightModel
-
-__all__ = ['light2mass_interpol']
-
-
-
[docs]def light2mass_interpol(lens_light_model_list, kwargs_lens_light, numPix=100, deltaPix=0.05, subgrid_res=5, - center_x=0, center_y=0): - """ - takes a lens light model and turns it numerically in a lens model - (with all lensmodel quantities computed on a grid). Then provides an interpolated grid for the quantities. - - :param kwargs_lens_light: lens light keyword argument list - :param numPix: number of pixels per axis for the return interpolation - :param deltaPix: interpolation/pixel size - :param center_x: center of the grid - :param center_y: center of the grid - :param subgrid_res: subgrid for the numerical integrals - :return: keyword arguments for 'INTERPOL' lens model - """ - # make super-sampled grid - x_grid_sub, y_grid_sub = util.make_grid(numPix=numPix * 5, deltapix=deltaPix, subgrid_res=subgrid_res) - import lenstronomy.Util.mask_util as mask_util - mask = mask_util.mask_azimuthal(x_grid_sub, y_grid_sub, center_x, center_y, r=1) - x_grid, y_grid = util.make_grid(numPix=numPix, deltapix=deltaPix) - # compute light on the subgrid - lightModel = LightModel(light_model_list=lens_light_model_list) - flux = lightModel.surface_brightness(x_grid_sub, y_grid_sub, kwargs_lens_light) - flux_norm = np.sum(flux[mask == 1]) / np.sum(mask) - flux /= flux_norm - from lenstronomy.LensModel import convergence_integrals as integral - - # compute lensing quantities with subgrid - convergence_sub = util.array2image(flux) - f_x_sub, f_y_sub = integral.deflection_from_kappa_grid(convergence_sub, grid_spacing=deltaPix / float(subgrid_res)) - f_sub = integral.potential_from_kappa_grid(convergence_sub, grid_spacing=deltaPix / float(subgrid_res)) - # interpolation function on lensing quantities - x_axes_sub, y_axes_sub = util.get_axes(x_grid_sub, y_grid_sub) - from lenstronomy.LensModel.Profiles.interpol import Interpol - interp_func = Interpol() - interp_func.do_interp(x_axes_sub, y_axes_sub, f_sub, f_x_sub, f_y_sub) - # compute lensing quantities on sparser grid - x_axes, y_axes = util.get_axes(x_grid, y_grid) - f_ = interp_func.function(x_grid, y_grid) - f_x, f_y = interp_func.derivatives(x_grid, y_grid) - # numerical differentials for second order differentials - from lenstronomy.LensModel.lens_model import LensModel - lens_model = LensModel(lens_model_list=['INTERPOL']) - kwargs = [{'grid_interp_x': x_axes_sub, 'grid_interp_y': y_axes_sub, 'f_': f_sub, - 'f_x': f_x_sub, 'f_y': f_y_sub}] - f_xx, f_xy, f_yx, f_yy = lens_model.hessian(x_grid, y_grid, kwargs, diff=0.00001) - kwargs_interpol = {'grid_interp_x': x_axes, 'grid_interp_y': y_axes, 'f_': util.array2image(f_), - 'f_x': util.array2image(f_x), 'f_y': util.array2image(f_y), 'f_xx': util.array2image(f_xx), - 'f_xy': util.array2image(f_xy), 'f_yy': util.array2image(f_yy)} - return kwargs_interpol
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Analysis/light_profile.html b/docs/_build/html/_modules/lenstronomy/Analysis/light_profile.html deleted file mode 100644 index 2e78b1ed7..000000000 --- a/docs/_build/html/_modules/lenstronomy/Analysis/light_profile.html +++ /dev/null @@ -1,246 +0,0 @@ - - - - - - - - lenstronomy.Analysis.light_profile — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Analysis.light_profile

-import copy
-import numpy as np
-import lenstronomy.Util.util as util
-import lenstronomy.Util.analysis_util as analysis_util
-import lenstronomy.Util.multi_gauss_expansion as mge
-
-__all__ = ['LightProfileAnalysis']
-
-
-
[docs]class LightProfileAnalysis(object): - """ - class with analysis routines to compute derived properties of the lens model - """ - def __init__(self, light_model): - """ - - :param light_model: LightModel instance - """ - self._light_model = light_model - -
[docs] def ellipticity(self, kwargs_light, grid_spacing, grid_num, center_x=None, center_y=None, model_bool_list=None): - """ - make sure that the window covers all the light, otherwise the moments may give a too low answers. - - :param kwargs_light: keyword argument list of profiles - :param center_x: center of profile, if None takes it from the first profile in kwargs_light - :param center_y: center of profile, if None takes it from the first profile in kwargs_light - :param model_bool_list: list of booleans to select subsets of the profile - :param grid_spacing: grid spacing over which the moments are computed - :param grid_num: grid size over which the moments are computed - :return: eccentricities e1, e2 - """ - center_x, center_y = analysis_util.profile_center(kwargs_light, center_x, center_y) - if model_bool_list is None: - model_bool_list = [True] * len(kwargs_light) - x_grid, y_grid = util.make_grid(numPix=grid_num, deltapix=grid_spacing) - x_grid += center_x - y_grid += center_y - I_xy = self._light_model.surface_brightness(x_grid, y_grid, kwargs_light, k=model_bool_list) - e1, e2 = analysis_util.ellipticities(I_xy, x_grid-center_x, y_grid-center_y) - return e1, e2
- -
[docs] def half_light_radius(self, kwargs_light, grid_spacing, grid_num, center_x=None, center_y=None, model_bool_list=None): - """ - computes numerically the half-light-radius of the deflector light and the total photon flux - - :param kwargs_light: keyword argument list of profiles - :param center_x: center of profile, if None takes it from the first profile in kwargs_light - :param center_y: center of profile, if None takes it from the first profile in kwargs_light - :param model_bool_list: list of booleans to select subsets of the profile - :param grid_spacing: grid spacing over which the moments are computed - :param grid_num: grid size over which the moments are computed - :return: half-light radius - """ - center_x, center_y = analysis_util.profile_center(kwargs_light, center_x, center_y) - if model_bool_list is None: - model_bool_list = [True] * len(kwargs_light) - x_grid, y_grid = util.make_grid(numPix=grid_num, deltapix=grid_spacing) - x_grid += center_x - y_grid += center_y - lens_light = self._light_model.surface_brightness(x_grid, y_grid, kwargs_light, k=model_bool_list) - R_h = analysis_util.half_light_radius(lens_light, x_grid, y_grid, center_x, center_y) - return R_h
- -
[docs] def radial_light_profile(self, r_list, kwargs_light, center_x=None, center_y=None, model_bool_list=None): - """ - - :param r_list: list of radii to compute the spherically averaged lens light profile - :param center_x: center of the profile - :param center_y: center of the profile - :param kwargs_light: lens light parameter keyword argument list - :param model_bool_list: bool list or None, indicating which profiles to sum over - :return: flux amplitudes at r_list radii spherically averaged - """ - center_x, center_y = analysis_util.profile_center(kwargs_light, center_x, center_y) - f_list = [] - for r in r_list: - x, y = util.points_on_circle(r, num_points=20) - f_r = self._light_model.surface_brightness(x + center_x, y + center_y, kwargs_list=kwargs_light, k=model_bool_list) - f_list.append(np.average(f_r)) - return f_list
- -
[docs] def multi_gaussian_decomposition(self, kwargs_light, model_bool_list=None, n_comp=20, center_x=None, center_y=None, - r_h=None, grid_spacing=0.02, grid_num=200): - """ - multi-gaussian decomposition of the lens light profile (in 1-dimension) - - :param kwargs_light: keyword argument list of profiles - :param center_x: center of profile, if None takes it from the first profile in kwargs_light - :param center_y: center of profile, if None takes it from the first profile in kwargs_light - :param model_bool_list: list of booleans to select subsets of the profile - :param grid_spacing: grid spacing over which the moments are computed for the half-light radius - :param grid_num: grid size over which the moments are computed - :param n_comp: maximum number of Gaussian's in the MGE - :param r_h: float, half light radius to be used for MGE (optional, otherwise using a numerical grid) - :return: amplitudes, sigmas, center_x, center_y - """ - - center_x, center_y = analysis_util.profile_center(kwargs_light, center_x, center_y) - if r_h is None: - r_h = self.half_light_radius(kwargs_light, center_x=center_x, center_y=center_y, - model_bool_list=model_bool_list, grid_spacing=grid_spacing, grid_num=grid_num) - r_array = np.logspace(-3, 2, 200) * r_h * 2 - flux_r = self.radial_light_profile(r_array, kwargs_light, center_x=center_x, center_y=center_y, - model_bool_list=model_bool_list) - - amplitudes, sigmas, norm = mge.mge_1d(r_array, flux_r, N=n_comp) - return amplitudes, sigmas, center_x, center_y
- -
[docs] def multi_gaussian_decomposition_ellipse(self, kwargs_light, model_bool_list=None, - center_x=None, center_y=None, grid_num=100, grid_spacing=0.05, n_comp=20): - """ - MGE with ellipticity estimate. - Attention: numerical grid settings for ellipticity estimate and radial MGE may not necessarily be the same! - - :param kwargs_light: keyword argument list of profiles - :param center_x: center of profile, if None takes it from the first profile in kwargs_light - :param center_y: center of profile, if None takes it from the first profile in kwargs_light - :param model_bool_list: list of booleans to select subsets of the profile - :param grid_spacing: grid spacing over which the moments are computed - :param grid_num: grid size over which the moments are computed - :param n_comp: maximum number of Gaussians in the MGE - :return: keyword arguments of the elliptical multi Gaussian profile in lenstronomy conventions - """ - # estimate center - center_x, center_y = analysis_util.profile_center(kwargs_light, center_x, center_y) - - e1, e2 = self.ellipticity(kwargs_light, center_x=center_x, center_y=center_y, - model_bool_list=model_bool_list, grid_spacing=grid_spacing * 2, grid_num=grid_num) - - # MGE around major axis - amplitudes, sigmas, center_x, center_y = self.multi_gaussian_decomposition(kwargs_light, - model_bool_list=model_bool_list, - n_comp=n_comp, grid_spacing=grid_spacing, - grid_num=grid_num, center_x=center_x, - center_y=center_y) - kwargs_mge = {'amp': amplitudes, 'sigma': sigmas, 'center_x': center_x, 'center_y': center_y} - kwargs_mge['e1'] = e1 - kwargs_mge['e2'] = e2 - return kwargs_mge
- -
[docs] def flux_components(self, kwargs_light, grid_num=400, grid_spacing=0.01): - """ - computes the total flux in each component of the model - - :param kwargs_light: - :param grid_num: - :param grid_spacing: - :return: - """ - flux_list = [] - R_h_list = [] - x_grid, y_grid = util.make_grid(numPix=grid_num, deltapix=grid_spacing) - kwargs_copy = copy.deepcopy(kwargs_light) - for k, kwargs in enumerate(kwargs_light): - if 'center_x' in kwargs_copy[k]: - kwargs_copy[k]['center_x'] = 0 - kwargs_copy[k]['center_y'] = 0 - light = self._light_model.surface_brightness(x_grid, y_grid, kwargs_copy, k=k) - flux = np.sum(light) * grid_spacing ** 2 - R_h = analysis_util.half_light_radius(light, x_grid, y_grid) - flux_list.append(flux) - R_h_list.append(R_h) - return flux_list, R_h_list
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Analysis/td_cosmography.html b/docs/_build/html/_modules/lenstronomy/Analysis/td_cosmography.html deleted file mode 100644 index e094db82b..000000000 --- a/docs/_build/html/_modules/lenstronomy/Analysis/td_cosmography.html +++ /dev/null @@ -1,278 +0,0 @@ - - - - - - - - lenstronomy.Analysis.td_cosmography — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Analysis.td_cosmography

-__author__ = 'sibirrer'
-
-
-import numpy as np
-from astropy.cosmology import default_cosmology
-from lenstronomy.Util import class_creator
-from lenstronomy.Util import constants as const
-from lenstronomy.Cosmo.lens_cosmo import LensCosmo
-from lenstronomy.Analysis.kinematics_api import KinematicsAPI
-
-__all__ = ['TDCosmography']
-
-
-
[docs]class TDCosmography(KinematicsAPI): - """ - class equipped to perform a cosmographic analysis from a lens model with added measurements of time delays and - kinematics. - This class does not require any cosmological knowledge and can return angular diameter distance estimates - self-consistently integrating the kinematics routines and time delay estimates in the lens modeling. - This description follows Birrer et al. 2016, 2019. - - - """ - def __init__(self, z_lens, z_source, kwargs_model, cosmo_fiducial=None, lens_model_kinematics_bool=None, - light_model_kinematics_bool=None, kwargs_seeing=None, kwargs_aperture=None, anisotropy_model=None, - **kwargs_kin_api): - """ - - :param z_lens: redshift of deflector - :param z_source: redshift of source - :param kwargs_model: model configurations (according to FittingSequence) - :param cosmo_fiducial: fiducial cosmology used to compute angular diameter distances where required - :param lens_model_kinematics_bool: (optional) bool list, corresponding to lens models being included into the - kinematics modeling - :param light_model_kinematics_bool: (optional) bool list, corresponding to lens light models being included - into the kinematics modeling - :param kwargs_seeing: seeing conditions (see observation class in Galkin) - :param kwargs_aperture: aperture keyword arguments (see aperture class in Galkin) - :param anisotropy_model: string, anisotropy model type - :param kwargs_kin_api: additional keyword arguments for KinematicsAPI class instance - """ - - if cosmo_fiducial is None: - cosmo_fiducial = default_cosmology.get() - if kwargs_seeing is None: - kwargs_seeing = {} - if kwargs_aperture is None: - kwargs_aperture = {} - self._z_lens = z_lens - self._z_source = z_source - self._cosmo_fiducial = cosmo_fiducial - self._lens_cosmo = LensCosmo(z_lens=z_lens, z_source=z_source, cosmo=self._cosmo_fiducial) - self.LensModel, self.SourceModel, self.LensLightModel, self.PointSource, extinction_class = class_creator.create_class_instances(all_models=True, **kwargs_model) - super(TDCosmography, self).__init__(z_lens=z_lens, z_source=z_source, kwargs_model=kwargs_model, - cosmo=cosmo_fiducial, lens_model_kinematics_bool=lens_model_kinematics_bool, - light_model_kinematics_bool=light_model_kinematics_bool, - kwargs_seeing=kwargs_seeing, kwargs_aperture=kwargs_aperture, - anisotropy_model=anisotropy_model, **kwargs_kin_api) - -
[docs] def time_delays(self, kwargs_lens, kwargs_ps, kappa_ext=0, original_ps_position=False): - """ - predicts the time delays of the image positions given the fiducial cosmology relative to a straight line - without lensing. - Negative values correspond to images arriving earlier, and positive signs correspond to images arriving later. - - :param kwargs_lens: lens model parameters - :param kwargs_ps: point source parameters - :param kappa_ext: external convergence (optional) - :param original_ps_position: boolean (only applies when first point source model is of type 'LENSED_POSITION'), - uses the image positions in the model parameters and does not re-compute images (which might be differently ordered) - in case of the lens equation solver - :return: time delays at image positions for the fixed cosmology in units of days - """ - fermat_pot = self.fermat_potential(kwargs_lens, kwargs_ps, original_ps_position=original_ps_position) - time_delay = self._lens_cosmo.time_delay_units(fermat_pot, kappa_ext) - return time_delay
- -
[docs] def fermat_potential(self, kwargs_lens, kwargs_ps, original_ps_position=False): - """ - Fermat potential (negative sign means earlier arrival time) - - :param kwargs_lens: lens model keyword argument list - :param kwargs_ps: point source keyword argument list - :param original_ps_position: boolean (only applies when first point source model is of type 'LENSED_POSITION'), - uses the image positions in the model parameters and does not re-compute images (which might be differently ordered) - in case of the lens equation solver - :return: Fermat potential of all the image positions in the first point source list entry - """ - ra_pos, dec_pos = self.PointSource.image_position(kwargs_ps, kwargs_lens, original_position=original_ps_position) - ra_pos = ra_pos[0] - dec_pos = dec_pos[0] - ra_source, dec_source = self.LensModel.ray_shooting(ra_pos, dec_pos, kwargs_lens) - sigma_source = np.sqrt(np.var(ra_source) + np.var(dec_source)) - if sigma_source > 0.001: - Warning('Source position computed from the different image positions do not trace back to the same position! ' - 'The error is %s mas and may be larger than what is required for an accurate relative time delay estimate!' - 'See e.g. Birrer & Treu 2019.' % sigma_source * 1000) - ra_source = np.mean(ra_source) - dec_source = np.mean(dec_source) - fermat_pot = self.LensModel.fermat_potential(ra_pos, dec_pos, kwargs_lens, ra_source, dec_source) - return fermat_pot
- -
[docs] def velocity_dispersion_dimension_less(self, kwargs_lens, kwargs_lens_light, kwargs_anisotropy, r_eff=None, - theta_E=None, gamma=None): - """ - sigma**2 = Dd/Dds * c**2 * J(kwargs_lens, kwargs_light, anisotropy) - (Equation 4.11 in Birrer et al. 2016 or Equation 6 in Birrer et al. 2019) J() is a dimensionless and - cosmological independent quantity only depending on angular units. This function returns J given the lens - and light parameters and the anisotropy choice without an external mass sheet correction. - - :param kwargs_lens: lens model keyword arguments - :param kwargs_lens_light: lens light model keyword arguments - :param kwargs_anisotropy: stellar anisotropy keyword arguments - :param r_eff: projected half-light radius of the stellar light associated with the deflector galaxy, optional, - if set to None will be computed in this function with default settings that may not be accurate. - :param theta_E: pre-computed Einstein radius (optional) - :param gamma: pre-computed power-law slope of mass profile - :return: dimensionless velocity dispersion (see e.g. Birrer et al. 2016, 2019) - """ - sigma_v = self.velocity_dispersion(kwargs_lens=kwargs_lens, kwargs_lens_light=kwargs_lens_light, - kwargs_anisotropy=kwargs_anisotropy, r_eff=r_eff, theta_E=theta_E, - gamma=gamma) - sigma_v *= 1000 # convert from [km/s] to [m/s] - J = sigma_v ** 2 * self._lens_cosmo.dds / self._lens_cosmo.ds / const.c ** 2 - return J
- -
[docs] def velocity_dispersion_map_dimension_less(self, kwargs_lens, kwargs_lens_light, kwargs_anisotropy, r_eff=None, - theta_E=None, gamma=None): - """ - sigma**2 = Dd/Dds * c**2 * J(kwargs_lens, kwargs_light, anisotropy) - (Equation 4.11 in Birrer et al. 2016 or Equation 6 in Birrer et al. 2019) J() is a dimensionless and - cosmological independent quantity only depending on angular units. This function returns J given the lens - and light parameters and the anisotropy choice without an external mass sheet correction. - This routine computes the IFU map of the kinematic quantities. - - :param kwargs_lens: lens model keyword arguments - :param kwargs_lens_light: lens light model keyword arguments - :param kwargs_anisotropy: stellar anisotropy keyword arguments - :param r_eff: projected half-light radius of the stellar light associated with the deflector galaxy, optional, - if set to None will be computed in this function with default settings that may not be accurate. - :return: dimensionless velocity dispersion (see e.g. Birrer et al. 2016, 2019) - """ - sigma_v_map = self.velocity_dispersion_map(kwargs_lens=kwargs_lens, kwargs_lens_light=kwargs_lens_light, - kwargs_anisotropy=kwargs_anisotropy, r_eff=r_eff, theta_E=theta_E, - gamma=gamma) - sigma_v_map *= 1000 # convert from [km/s] to [m/s] - J_map = sigma_v_map ** 2 * self._lens_cosmo.dds / self._lens_cosmo.ds / const.c ** 2 - return J_map
- -
[docs] @staticmethod - def ddt_from_time_delay(d_fermat_model, dt_measured, kappa_s=0, kappa_ds=0, kappa_d=0): - """ - Time-delay distance in units of Mpc from the modeled Fermat potential and measured time delay from an image pair. - - :param d_fermat_model: relative Fermat potential between two images from the same source in units arcsec^2 - :param dt_measured: measured time delay between the same image pair in units of days - :param kappa_s: external convergence from observer to source - :param kappa_ds: external convergence from lens to source - :param kappa_d: external convergence form observer to lens - :return: D_dt, time-delay distance - """ - D_dt_model = dt_measured * const.day_s * const.c / const.Mpc / d_fermat_model / const.arcsec ** 2 - D_dt = D_dt_model * (1-kappa_ds) / (1 - kappa_s) / (1 - kappa_d) - return D_dt
- -
[docs] @staticmethod - def ds_dds_from_kinematics(sigma_v, J, kappa_s=0, kappa_ds=0): - """ - computes the estimate of the ratio of angular diameter distances Ds/Dds from the kinematic estimate of the lens - and the measured dispersion. - - :param sigma_v: velocity dispersion [km/s] - :param J: dimensionless kinematic constraint (see Birrer et al. 2016, 2019) - :return: Ds/Dds - """ - ds_dds_model = (sigma_v * 1000) ** 2 / const.c ** 2 / J - ds_dds = ds_dds_model * (1 - kappa_ds) / (1 - kappa_s) - return ds_dds
- -
[docs] def ddt_dd_from_time_delay_and_kinematics(self, d_fermat_model, dt_measured, sigma_v_measured, J, kappa_s=0, - kappa_ds=0, kappa_d=0): - """ - - :param d_fermat_model: relative Fermat potential in units arcsec^2 - :param dt_measured: measured relative time delay [days] - :param sigma_v_measured: 1-sigma Gaussian uncertainty in the measured velocity dispersion - :param J: modeled dimensionless kinematic estimate - :param kappa_s: LOS convergence from observer to source - :param kappa_ds: LOS convergence from deflector to source - :param kappa_d: LOS convergence from observer to deflector - :return: D_dt, D_d - """ - ddt = self.ddt_from_time_delay(d_fermat_model, dt_measured, kappa_s=kappa_s, kappa_ds=kappa_ds, kappa_d=kappa_d) - ds_dds = self.ds_dds_from_kinematics(sigma_v_measured, J, kappa_s=kappa_s, kappa_ds=kappa_ds) - dd = ddt / ds_dds / (1 + self._z_lens) - return ddt, dd
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Cosmo/background.html b/docs/_build/html/_modules/lenstronomy/Cosmo/background.html deleted file mode 100644 index 462606c2a..000000000 --- a/docs/_build/html/_modules/lenstronomy/Cosmo/background.html +++ /dev/null @@ -1,160 +0,0 @@ - - - - - - - - lenstronomy.Cosmo.background — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Cosmo.background

-__author__ = 'sibirrer'
-
-import numpy as np
-import lenstronomy.Util.constants as const
-from lenstronomy.Cosmo.cosmo_interp import CosmoInterp
-
-__all__ = ['Background']
-
-
-
[docs]class Background(object): - """ - class to compute cosmological distances - """ - def __init__(self, cosmo=None, interp=False, **kwargs_interp): - """ - - :param cosmo: instance of astropy.cosmology - :param interp: boolean, if True, uses interpolated cosmology to evaluate specific redshifts - :param kwargs_interp: keyword arguments of CosmoInterp specifying the interpolation interval and maximum - redshift - :return: Background class with instance of astropy.cosmology - """ - - if cosmo is None: - from astropy.cosmology import default_cosmology - cosmo = default_cosmology.get() - if interp: - self.cosmo = CosmoInterp(cosmo, **kwargs_interp) - else: - self.cosmo = cosmo - -
[docs] def a_z(self, z): - """ - returns scale factor (a_0 = 1) for given redshift - :param z: redshift - :return: scale factor - """ - return 1./(1+z)
- -
[docs] def d_xy(self, z_observer, z_source): - """ - - :param z_observer: observer redshift - :param z_source: source redshift - :return: angular diameter distance in units of Mpc - """ - D_xy = self.cosmo.angular_diameter_distance_z1z2(z_observer, z_source) - return D_xy.value
- -
[docs] def ddt(self, z_lens, z_source): - """ - time-delay distance - - :param z_lens: redshift of lens - :param z_source: redshift of source - :return: time-delay distance in units of proper Mpc - """ - return self.d_xy(0, z_lens) * self.d_xy(0, z_source) / self.d_xy(z_lens, z_source) * (1 + z_lens)
- -
[docs] def T_xy(self, z_observer, z_source): - """ - - :param z_observer: observer - :param z_source: source - :return: transverse comoving distance in units of Mpc - """ - D_xy = self.d_xy(z_observer, z_source) - T_xy = D_xy * (1 + z_source) - return T_xy
- - @property - def rho_crit(self): - """ - critical density - :return: value in M_sol/Mpc^3 - """ - h = self.cosmo.H(0).value / 100. - return 3 * h ** 2 / (8 * np.pi * const.G) * 10 ** 10 * const.Mpc / const.M_sun
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Cosmo/cosmo_solver.html b/docs/_build/html/_modules/lenstronomy/Cosmo/cosmo_solver.html deleted file mode 100644 index 1686d406a..000000000 --- a/docs/_build/html/_modules/lenstronomy/Cosmo/cosmo_solver.html +++ /dev/null @@ -1,211 +0,0 @@ - - - - - - - - lenstronomy.Cosmo.cosmo_solver — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Cosmo.cosmo_solver

-__author__ = 'sibirrer'
-
-import scipy.optimize
-import scipy.interpolate as interpolate
-import numpy as np
-
-from astropy.cosmology import FlatLambdaCDM
-from lenstronomy.Cosmo.lens_cosmo import LensCosmo
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -def cosmo2angular_diameter_distances(H_0, omega_m, z_lens, z_source): - """ - - :param H_0: Hubble constant [km/s/Mpc] - :param omega_m: dimensionless matter density at z=0 - :param z_lens: deflector redshift - :param z_source: source redshift - :return: angular diameter distances Dd and Ds/Dds - """ - cosmo = FlatLambdaCDM(H0=H_0, Om0=omega_m, Ob0=0.) - lensCosmo = LensCosmo(z_lens=z_lens, z_source=z_source, cosmo=cosmo) - Dd = lensCosmo.dd - Ds = lensCosmo.ds - Dds = lensCosmo.dds - return Dd, Ds/Dds
- - -
[docs]@export -def ddt2h0(ddt, z_lens, z_source, cosmo): - """ - converts time-delay distance to H0 for a given expansion history - - :param ddt: time-delay distance in Mpc - :param z_lens: deflector redshift - :param z_source: source redshift - :param cosmo: astropy.cosmology class instance - :return: h0 value which matches the cosmology class effectively replacing the h0 value used in the creation of this class - """ - h0_fiducial = cosmo.H0.value - lens_cosmo = LensCosmo(z_lens=z_lens, z_source=z_source, cosmo=cosmo) - ddt_fiducial = lens_cosmo.ddt - h0 = h0_fiducial * ddt_fiducial / ddt - return h0
- - -
[docs]@export -class SolverFlatLCDM(object): - """ - class to solve multidimensional non-linear equations to determine the cosmological parameters H0 and omega_m given - the angular diameter distance relations - """ - def __init__(self, z_d, z_s): - self.z_d = z_d - self.z_s = z_s - -
[docs] def F(self, x, Dd, Ds_Dds): - """ - - :param x: array of parameters (H_0, omega_m) - :return: - """ - [H_0, omega_m] = x - omega_m = abs(omega_m)%1 - Dd_new, Ds_Dds_new = cosmo2angular_diameter_distances(H_0, omega_m, self.z_d, self.z_s) - y = np.zeros(2) - y[0] = Dd - Dd_new - y[1] = Ds_Dds - Ds_Dds_new - return y
- -
[docs] def solve(self, init, dd, ds_dds): - x = scipy.optimize.fsolve(self.F, init, args=(dd, ds_dds), xtol=1.49012e-08, factor=0.1) - x[1] = abs(x[1]) % 1 - y = self.F(x, dd, ds_dds) - if abs(y[0]) >= 0.1 or abs(y[1]) > 0.1: - x = np.array([-1, -1]) - return x
- - -
[docs]@export -class InvertCosmo(object): - """ - class to do an interpolation and call the inverse of this interpolation to get H_0 and omega_m - """ - def __init__(self, z_d, z_s, H0_range=np.linspace(10, 100, 90), omega_m_range=np.linspace(0.05, 1, 95)): - self.z_d = z_d - self.z_s = z_s - self._H0_range = H0_range - self._omega_m_range = omega_m_range - - def _make_interpolation(self): - """ - creates an interpolation grid in H_0, omega_m and computes quantities in Dd and Ds_Dds - :return: - """ - grid2d = np.dstack(np.meshgrid(self._H0_range, self._omega_m_range)).reshape(-1, 2) - H0_grid = grid2d[:, 0] - omega_m_grid = grid2d[:, 1] - Dd_grid = np.zeros_like(H0_grid) - Ds_Dds_grid = np.zeros_like(H0_grid) - for i in range(len(H0_grid)): - Dd, Ds_Dds = cosmo2angular_diameter_distances(H0_grid[i], omega_m_grid[i], self.z_d, self.z_s) - Dd_grid[i] = Dd - Ds_Dds_grid[i] = Ds_Dds - self._f_H0 = interpolate.interp2d(Dd_grid, Ds_Dds_grid, H0_grid, kind='linear', copy=False, bounds_error=False, fill_value=-1) - print("H0 interpolation done") - self._f_omega_m = interpolate.interp2d(Dd_grid, Ds_Dds_grid, omega_m_grid, kind='linear', copy=False, bounds_error=False, fill_value=0) - print("omega_m interpolation done") - -
[docs] def get_cosmo(self, Dd, Ds_Dds): - """ - return the values of H0 and omega_m computed with an interpolation - :param Dd: flat - :param Ds_Dds: float - :return: - """ - if not hasattr(self, '_f_H0') or not hasattr(self, '_f_omega_m'): - self._make_interpolation() - H0 = self._f_H0(Dd, Ds_Dds) - print(H0, 'H0') - omega_m = self._f_omega_m(Dd, Ds_Dds) - Dd_new, Ds_Dds_new = cosmo2angular_diameter_distances(H0[0], omega_m[0], self.z_d, self.z_s) - if abs(Dd - Dd_new)/Dd > 0.01 or abs(Ds_Dds - Ds_Dds_new)/Ds_Dds > 0.01: - return -1, -1 - else: - return H0[0], omega_m[0]
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Cosmo/kde_likelihood.html b/docs/_build/html/_modules/lenstronomy/Cosmo/kde_likelihood.html deleted file mode 100644 index 9305ee606..000000000 --- a/docs/_build/html/_modules/lenstronomy/Cosmo/kde_likelihood.html +++ /dev/null @@ -1,131 +0,0 @@ - - - - - - - - lenstronomy.Cosmo.kde_likelihood — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Cosmo.kde_likelihood

-import numpy as np
-from scipy import stats
-
-__all__ = ['KDELikelihood']
-
-
-
[docs]class KDELikelihood(object): - """ - class that samples the cosmographic likelihood given a distribution of points in the 2-dimensional distribution - of D_d and D_delta_t - """ - def __init__(self, D_d_sample, D_delta_t_sample, kde_type='scipy_gaussian', bandwidth=1): - """ - - :param D_d_sample: 1-d numpy array of angular diameter distances to the lens plane - :param D_delta_t_sample: 1-d numpy array of time-delay distances - kde_type : string - The kernel to use. Valid kernels are - 'scipy_gaussian' or - ['gaussian'|'tophat'|'epanechnikov'|'exponential'|'linear'|'cosine'] - Default is 'gaussian'. - :param bandwidth: width of kernel (in same units as the angular diameter quantities) - """ - values = np.vstack([D_d_sample, D_delta_t_sample]) - if kde_type == 'scipy_gaussian': - self._PDF_kernel = stats.gaussian_kde(values) - else: - from sklearn.neighbors import KernelDensity - self._kde = KernelDensity(bandwidth=bandwidth, kernel=kde_type) - values = np.vstack([D_d_sample, D_delta_t_sample]) - self._kde.fit(values.T) - self._kde_type = kde_type - -
[docs] def logLikelihood(self, D_d, D_delta_t): - """ - likelihood of the data (represented in the distribution of this class) given a model with predicted angular - diameter distances. - - :param D_d: model predicted angular diameter distance - :param D_delta_t: model predicted time-delay distance - :return: loglikelihood (log of KDE value) - """ - if self._kde_type == 'scipy_gaussian': - density = self._PDF_kernel([D_d, D_delta_t]) - logL = np.log(density) - else: - x = np.array([[D_d], [D_delta_t]]) - logL = self._kde.score_samples(x.T) - return logL
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Cosmo/lcdm.html b/docs/_build/html/_modules/lenstronomy/Cosmo/lcdm.html deleted file mode 100644 index a8f33fb78..000000000 --- a/docs/_build/html/_modules/lenstronomy/Cosmo/lcdm.html +++ /dev/null @@ -1,160 +0,0 @@ - - - - - - - - lenstronomy.Cosmo.lcdm — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Cosmo.lcdm

-__author__ = 'sibirrer'
-
-from astropy.cosmology import FlatLambdaCDM, LambdaCDM
-from lenstronomy.Cosmo.lens_cosmo import LensCosmo
-
-__all__ = ['LCDM']
-
-
-
[docs]class LCDM(object): - """ - Flat LCDM cosmology background with free Hubble parameter and Omega_m at fixed lens redshift configuration - """ - - def __init__(self, z_lens, z_source, flat=True): - """ - - :param z_lens: redshift of lens - :param z_source: redshift of source - :param flat: bool, if True, flat universe is assumed - """ - self.z_lens = z_lens - self.z_source = z_source - self._flat = flat - - def _get_cosom(self, H_0, Om0, Ode0=None): - """ - - :param H_0: - :param Om0: - :param Ode0: - :return: - """ - if self._flat is True: - cosmo = FlatLambdaCDM(H0=H_0, Om0=Om0) - else: - cosmo = LambdaCDM(H0=H_0, Om0=Om0, Ode0=Ode0) - lensCosmo = LensCosmo(z_lens=self.z_lens, z_source=self.z_source, cosmo=cosmo) - return lensCosmo - -
[docs] def D_d(self, H_0, Om0, Ode0=None): - """ - angular diameter to deflector - :param H_0: Hubble parameter [km/s/Mpc] - :param Om0: normalized matter density at present time - :return: float [Mpc] - """ - lensCosmo = self._get_cosom(H_0, Om0, Ode0) - return lensCosmo.dd
- -
[docs] def D_s(self, H_0, Om0, Ode0=None): - """ - angular diameter to source - :param H_0: Hubble parameter [km/s/Mpc] - :param Om0: normalized matter density at present time - :return: float [Mpc] - """ - lensCosmo = self._get_cosom(H_0, Om0, Ode0) - return lensCosmo.ds
- -
[docs] def D_ds(self, H_0, Om0, Ode0=None): - """ - angular diameter from deflector to source - :param H_0: Hubble parameter [km/s/Mpc] - :param Om0: normalized matter density at present time - :return: float [Mpc] - """ - lensCosmo = self._get_cosom(H_0, Om0, Ode0) - return lensCosmo.dds
- -
[docs] def D_dt(self, H_0, Om0, Ode0=None): - """ - time delay distance - :param H_0: Hubble parameter [km/s/Mpc] - :param Om0: normalized matter density at present time - :return: float [Mpc] - """ - lensCosmo = self._get_cosom(H_0, Om0, Ode0) - return lensCosmo.ddt
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Cosmo/lens_cosmo.html b/docs/_build/html/_modules/lenstronomy/Cosmo/lens_cosmo.html deleted file mode 100644 index 74f552622..000000000 --- a/docs/_build/html/_modules/lenstronomy/Cosmo/lens_cosmo.html +++ /dev/null @@ -1,359 +0,0 @@ - - - - - - - - lenstronomy.Cosmo.lens_cosmo — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Cosmo.lens_cosmo

-__author__ = 'sibirrer'
-
-# this file contains a class to convert lensing and physical units
-
-import numpy as np
-import lenstronomy.Util.constants as const
-from lenstronomy.Cosmo.background import Background
-from lenstronomy.Cosmo.nfw_param import NFWParam
-
-__all__ = ['LensCosmo']
-
-
-
[docs]class LensCosmo(object): - """ - class to manage the physical units and distances present in a single plane lens with fixed input cosmology - """ - def __init__(self, z_lens, z_source, cosmo=None): - """ - - :param z_lens: redshift of lens - :param z_source: redshift of source - :param cosmo: astropy.cosmology instance - """ - - self.z_lens = z_lens - self.z_source = z_source - self.background = Background(cosmo=cosmo) - self.nfw_param = NFWParam(cosmo=cosmo) - -
[docs] def a_z(self, z): - """ - convert redshift into scale factor - :param z: redshift - :return: scale factor - """ - return 1. / (1. + z)
- - @property - def h(self): - return self.background.cosmo.H(0).value / 100. - - @property - def dd(self): - """ - - :return: angular diameter distance to the deflector [Mpc] - """ - return self.background.d_xy(0, self.z_lens) - - @property - def ds(self): - """ - - :return: angular diameter distance to the source [Mpc] - """ - return self.background.d_xy(0, self.z_source) - - @property - def dds(self): - """ - - :return: angular diameter distance from deflector to source [Mpc] - """ - return self.background.d_xy(self.z_lens, self.z_source) - - @property - def ddt(self): - """ - - :return: time delay distance [Mpc] - """ - return (1 + self.z_lens) * self.dd * self.ds / self.dds - - @property - def sigma_crit(self): - """ - returns the critical projected lensing mass density in units of M_sun/Mpc^2 - :return: critical projected lensing mass density - """ - if not hasattr(self, '_sigma_crit_mpc'): - const_SI = const.c ** 2 / (4 * np.pi * const.G) # c^2/(4*pi*G) in units of [kg/m] - conversion = const.Mpc / const.M_sun # converts [kg/m] to [M_sun/Mpc] - factor = const_SI*conversion # c^2/(4*pi*G) in units of [M_sun/Mpc] - self._sigma_crit_mpc = self.ds / (self.dd * self.dds) * factor # [M_sun/Mpc^2] - return self._sigma_crit_mpc - - @property - def sigma_crit_angle(self): - """ - returns the critical surface density in units of M_sun/arcsec^2 (in physical solar mass units) - when provided a physical mass per physical Mpc^2 - :return: critical projected mass density - """ - if not hasattr(self, '_sigma_crit_arcsec'): - const_SI = const.c ** 2 / (4 * np.pi * const.G) # c^2/(4*pi*G) in units of [kg/m] - conversion = const.Mpc / const.M_sun # converts [kg/m] to [M_sun/Mpc] - factor = const_SI * conversion # c^2/(4*pi*G) in units of [M_sun/Mpc] - self._sigma_crit_arcsec = self.ds / (self.dd * self.dds) * factor * (self.dd * const.arcsec) ** 2 # [M_sun/arcsec^2] - return self._sigma_crit_arcsec - -
[docs] def phys2arcsec_lens(self, phys): - """ - convert physical Mpc into arc seconds - :param phys: physical distance [Mpc] - :return: angular diameter [arcsec] - """ - return phys / self.dd / const.arcsec
- -
[docs] def arcsec2phys_lens(self, arcsec): - """ - convert angular to physical quantities for lens plane - :param arcsec: angular size at lens plane [arcsec] - :return: physical size at lens plane [Mpc] - """ - return arcsec * const.arcsec * self.dd
- -
[docs] def arcsec2phys_source(self, arcsec): - """ - convert angular to physical quantities for source plane - :param arcsec: angular size at source plane [arcsec] - :return: physical size at source plane [Mpc] - """ - return arcsec * const.arcsec * self.ds
- -
[docs] def kappa2proj_mass(self, kappa): - """ - convert convergence to projected mass M_sun/Mpc^2 - :param kappa: lensing convergence - :return: projected mass [M_sun/Mpc^2] - """ - return kappa * self.sigma_crit
- -
[docs] def mass_in_theta_E(self, theta_E): - """ - mass within Einstein radius (area * epsilon crit) [M_sun] - :param theta_E: Einstein radius [arcsec] - :return: mass within Einstein radius [M_sun] - """ - mass = self.arcsec2phys_lens(theta_E) ** 2 * np.pi * self.sigma_crit - return mass
- -
[docs] def mass_in_coin(self, theta_E): - """ - - :param theta_E: Einstein radius [arcsec] - :return: mass in coin calculated in mean density of the universe - """ - chi_L = self.background.T_xy(0, self.z_lens) - chi_S = self.background.T_xy(0, self.z_source) - return 1./3 * np.pi * (chi_L * theta_E * const.arcsec) ** 2 * chi_S * self.background.rho_crit #[M_sun/Mpc**3]
- -
[docs] def time_delay_units(self, fermat_pot, kappa_ext=0): - """ - - :param fermat_pot: in units of arcsec^2 (e.g. Fermat potential) - :param kappa_ext: unit-less external shear not accounted for in the Fermat potential - :return: time delay in days - """ - D_dt = self.ddt * (1. - kappa_ext) * const.Mpc # eqn 7 in Suyu et al. - return D_dt / const.c * fermat_pot / const.day_s * const.arcsec ** 2 # * self.arcsec2phys_lens(1.)**2
- -
[docs] def time_delay2fermat_pot(self, dt): - """ - - :param dt: time delay in units of days - :return: Fermat potential in units arcsec**2 for a given cosmology - """ - D_dt = self.ddt * const.Mpc - return dt * const.c * const.day_s / D_dt / const.arcsec ** 2
- -
[docs] def nfw_angle2physical(self, Rs_angle, alpha_Rs): - """ - converts the angular parameters into the physical ones for an NFW profile - - :param alpha_Rs: observed bending angle at the scale radius in units of arcsec - :param Rs_angle: scale radius in units of arcsec - :return: rho0 [Msun/Mpc^3], Rs [Mpc], c, r200 [Mpc], M200 [Msun] - """ - Rs = Rs_angle * const.arcsec * self.dd - theta_scaled = alpha_Rs * self.sigma_crit * self.dd * const.arcsec - rho0 = theta_scaled / (4 * Rs ** 2 * (1 + np.log(1. / 2.))) - rho0_com = rho0 / self.h**2 - c = self.nfw_param.c_rho0(rho0_com, self.z_lens) - r200 = c * Rs - M200 = self.nfw_param.M_r200(r200 * self.h, self.z_lens) / self.h - return rho0, Rs, c, r200, M200
- -
[docs] def nfw_physical2angle(self, M, c): - """ - converts the physical mass and concentration parameter of an NFW profile into the lensing quantities - - :param M: mass enclosed 200 rho_crit in units of M_sun (physical units, meaning no little h) - :param c: NFW concentration parameter (r200/r_s) - :return: Rs_angle (angle at scale radius) (in units of arcsec), alpha_Rs (observed bending angle at the scale radius - """ - rho0, Rs, r200 = self.nfwParam_physical(M, c) - Rs_angle = Rs / self.dd / const.arcsec # Rs in arcsec - alpha_Rs = rho0 * (4 * Rs ** 2 * (1 + np.log(1. / 2.))) - return Rs_angle, alpha_Rs / self.sigma_crit / self.dd / const.arcsec
- -
[docs] def nfwParam_physical(self, M, c): - """ - returns the NFW parameters in physical units - - :param M: physical mass in M_sun - :param c: concentration - :return: rho0 [Msun/Mpc^3], Rs [Mpc], r200 [Mpc] - """ - r200 = self.nfw_param.r200_M(M * self.h, self.z_lens) / self.h # physical radius r200 - rho0 = self.nfw_param.rho0_c(c, self.z_lens) * self.h**2 # physical density in M_sun/Mpc**3 - Rs = r200/c - return rho0, Rs, r200
- -
[docs] def nfw_M_theta_r200(self, M): - """ - returns r200 radius in angular units of arc seconds on the sky - - :param M: physical mass in M_sun - :return: angle (in arc seconds) of the r200 radius - """ - r200 = self.nfw_param.r200_M(M * self.h, self.z_lens) / self.h # physical radius r200 - theta_r200 = r200 / self.dd / const.arcsec - return theta_r200
- -
[docs] def sis_theta_E2sigma_v(self, theta_E): - """ - converts the lensing Einstein radius into a physical velocity dispersion - :param theta_E: Einstein radius (in arcsec) - :return: velocity dispersion in units (km/s) - """ - v_sigma_c2 = theta_E * const.arcsec / (4*np.pi) * self.ds / self.dds - return np.sqrt(v_sigma_c2)*const.c / 1000
- -
[docs] def sis_sigma_v2theta_E(self, v_sigma): - """ - converts the velocity dispersion into an Einstein radius for a SIS profile - :param v_sigma: velocity dispersion (km/s) - :return: theta_E (arcsec) - """ - theta_E = 4 * np.pi * (v_sigma * 1000./const.c) ** 2 * self.dds / self.ds / const.arcsec - return theta_E
- -
[docs] def uldm_angular2phys(self, kappa_0, theta_c): - """ - converts the anguar parameters entering the LensModel Uldm() (Ultra Light - Dark Matter) class in physical masses, i.e. the total soliton mass and the - mass of the particle - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcseconds) - :return: m_eV_log10, M_sol_log10, the log10 of the masses, m in eV and M in M_sun - """ - D_Lens = self.dd * 10**6 # in parsec - Sigma_c = self.sigma_crit * 10**(-12) # in M_sun / parsec^2 - r_c = theta_c * const.arcsec * D_Lens - rho0 = 2048 * np.sqrt(0.091) * kappa_0 * Sigma_c / (429 * np.pi * r_c) - m_log10 = -22 + 0.5*np.log10(190 / rho0 * (r_c / 100)**(-4)) - M_log10 = 9 + np.log10(160 * 1.4 / r_c) - 2 * (m_log10 + 22) - return m_log10, M_log10
- -
[docs] def uldm_mphys2angular(self, m_log10, M_log10): - """ - converts physical ULDM mass in the ones, in angular units, that enter - the LensModel Uldm() class - :param m_log10: exponent of ULDM mass in eV - :param M_log10: exponent of soliton mass in M_sun - :return: kappa_0, theta_c, the central convergence and core radius (in arcseconds) - """ - D_Lens = self.dd * 10**6 # in parsec - Sigma_c = self.sigma_crit * 10**(-12) # in M_sun/parsec^2 - m22 = 10**(m_log10 + 22) - M9 = 10**(M_log10 -9) - r_c = 160 * 1.4 * m22**(-2) * M9**(-1) # core radius in parsec - rho0 = 190 * m22**(-2) * (r_c / 100)**(-4) # central density in M_sun/parsec^3 - kappa_0 = 429 * np.pi * rho0 * r_c / (2048 * np.sqrt(0.091) * Sigma_c) - theta_c = r_c / D_Lens / const.arcsec - return kappa_0, theta_c
- -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Cosmo/nfw_param.html b/docs/_build/html/_modules/lenstronomy/Cosmo/nfw_param.html deleted file mode 100644 index 93f899a4a..000000000 --- a/docs/_build/html/_modules/lenstronomy/Cosmo/nfw_param.html +++ /dev/null @@ -1,207 +0,0 @@ - - - - - - - - lenstronomy.Cosmo.nfw_param — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Cosmo.nfw_param

-import numpy as np
-
-__all__ = ['NFWParam']
-
-
-
[docs]class NFWParam(object): - """ - class which contains a halo model parameters dependent on cosmology for NFW profile - All distances are given in physical units. Mass definitions are relative to 200 crit including redshift evolution. - The redshift evolution is cosmology dependent (dark energy). - The H0 dependence is propagated into the input and return units. - """ - - rhoc = 2.77536627e11 # critical density [h^2 M_sun Mpc^-3] - - def __init__(self, cosmo=None): - """ - - :param cosmo: astropy.cosmology instance - """ - from astropy.cosmology import default_cosmology - - if cosmo is None: - cosmo = default_cosmology.get() - self.cosmo = cosmo - -
[docs] def rhoc_z(self, z): - """ - - :param z: redshift - :return: critical density of the universe at redshift z in physical units [h^2 M_sun Mpc^-3] - """ - return self.rhoc * (self.cosmo.efunc(z)) ** 2
- #return self.rhoc*(1+z)**3 - -
[docs] def M200(self, rs, rho0, c): - """ - M(R_200) calculation for NFW profile - - :param rs: scale radius - :type rs: float - :param rho0: density normalization (characteristic density) - :type rho0: float - :param c: concentration - :type c: float [4,40] - :return: M(R_200) density - """ - return 4 * np.pi * rho0 * rs ** 3 * (np.log(1. + c) - c / (1. + c))
- -
[docs] def r200_M(self, M, z): - """ - computes the radius R_200 crit of a halo of mass M in physical distances M/h - - :param M: halo mass in M_sun/h - :type M: float or numpy array - :param z: redshift - :type z: float - :return: radius R_200 in physical Mpc/h - """ - return (3*M/(4*np.pi*self.rhoc_z(z)*200))**(1./3.)
- -
[docs] def M_r200(self, r200, z): - """ - - :param r200: r200 in physical Mpc/h - :param z: redshift - :return: M200 in M_sun/h - """ - return self.rhoc_z(z)*200 * r200**3 * 4*np.pi/3.
- -
[docs] def rho0_c(self, c, z): - """ - computes density normalization as a function of concentration parameter - - :param c: concentration - :param z: redshift - :return: density normalization in h^2/Mpc^3 (physical) - """ - return 200./3*self.rhoc_z(z)*c**3/(np.log(1.+c)-c/(1.+c))
- -
[docs] def c_rho0(self, rho0, z): - """ - computes the concentration given density normalization rho_0 in h^2/Mpc^3 (physical) (inverse of function rho0_c) - :param rho0: density normalization in h^2/Mpc^3 (physical) - :param z: redshift - :return: concentration parameter c - """ - if not hasattr(self, '_c_rho0_interp'): - c_array = np.linspace(0.1, 10, 100) - rho0_array = self.rho0_c(c_array, z) - from scipy import interpolate - self._c_rho0_interp = interpolate.InterpolatedUnivariateSpline(rho0_array, c_array, w=None, bbox=[None, None], k=3) - return self._c_rho0_interp(rho0)
- -
[docs] def c_M_z(self, M, z): - """ - fitting function of http://moriond.in2p3.fr/J08/proceedings/duffy.pdf for the mass and redshift dependence of - the concentration parameter - - :param M: halo mass in M_sun/h - :type M: float or numpy array - :param z: redshift - :type z: float >0 - :return: concentration parameter as float - """ - # fitted parameter values - A = 5.22 - B = -0.072 - C = -0.42 - M_pivot = 2.*10**12 - return A*(M/M_pivot)**B*(1+z)**C
- -
[docs] def nfw_Mz(self, M, z): - """ - returns all needed parameter (in physical units modulo h) to draw the profile of the main halo - r200 in physical Mpc/h - rho_s in h^2/Mpc^3 (physical) - Rs in Mpc/h physical - c unit less - """ - c = self.c_M_z(M, z) - r200 = self.r200_M(M, z) - rho0 = self.rho0_c(c, z) - Rs = r200/c - return r200, rho0, c, Rs
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Data/coord_transforms.html b/docs/_build/html/_modules/lenstronomy/Data/coord_transforms.html deleted file mode 100644 index 4ee9482e8..000000000 --- a/docs/_build/html/_modules/lenstronomy/Data/coord_transforms.html +++ /dev/null @@ -1,238 +0,0 @@ - - - - - - - - lenstronomy.Data.coord_transforms — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Data.coord_transforms

-import numpy.linalg as linalg
-import numpy as np
-import lenstronomy.Util.util as util
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -class Coordinates(object): - """ - class to handle linear coordinate transformations of a square pixel image - """ - def __init__(self, transform_pix2angle, ra_at_xy_0, dec_at_xy_0): - """ - initialize the coordinate-to-pixel transform and their inverse - :param transform_pix2angle: 2x2 matrix, mapping of pixel to coordinate - :param ra_at_xy_0: ra coordinate at pixel (0,0) - :param dec_at_xy_0: dec coordinate at pixel (0,0) - """ - self._Mpix2a = transform_pix2angle - self._Ma2pix = linalg.inv(self._Mpix2a) - self._ra_at_xy_0 = ra_at_xy_0 - self._dec_at_xy_0 = dec_at_xy_0 - self._x_at_radec_0, self._y_at_radec_0 = util.map_coord2pix(-self._ra_at_xy_0, -self._dec_at_xy_0, 0, 0, - self._Ma2pix) - - @property - def transform_angle2pix(self): - """ - - :return: transformation matrix from angular to pixel coordinates - """ - return self._Ma2pix - - @property - def transform_pix2angle(self): - """ - - :return: transformation matrix from pixel to angular coordinates - """ - return self._Mpix2a - - @property - def xy_at_radec_0(self): - """ - - :return: pixel coordinate at angular (0,0) point - """ - return self._x_at_radec_0, self._y_at_radec_0 - - @property - def radec_at_xy_0(self): - """ - - :return: RA, DEC coordinate at (0,0) pixel coordinate - """ - return self._ra_at_xy_0, self._dec_at_xy_0 - -
[docs] def map_coord2pix(self, ra, dec): - """ - maps the (ra,dec) coordinates of the system into the pixel coordinate of the image - - :param ra: relative RA coordinate as defined by the coordinate frame - :param dec: relative DEC coordinate as defined by the coordinate frame - :return: (x, y) pixel coordinates - """ - - return util.map_coord2pix(ra, dec, self._x_at_radec_0, self._y_at_radec_0, self._Ma2pix)
- -
[docs] def map_pix2coord(self, x, y): - """ - maps the (x,y) pixel coordinates of the image into the system coordinates - - :param x: pixel coordinate (can be 1d numpy array), defined in the center of the pixel - :param y: pixel coordinate (can be 1d numpy array), defined in the center of the pixel - :return: relative (RA, DEC) coordinates of the system - """ - return util.map_coord2pix(x, y, self._ra_at_xy_0, self._dec_at_xy_0, self._Mpix2a)
- - @property - def pixel_area(self): - """ - angular area of a pixel in the image - :return: area [arcsec^2] - """ - return np.abs(linalg.det(self._Mpix2a)) - - @property - def pixel_width(self): - """ - size of pixel - :return: sqrt(pixel_area) - """ - return np.sqrt(self.pixel_area) - -
[docs] def coordinate_grid(self, nx, ny): - """ - - :param nx: number of pixels in x-direction - :param ny: number of pixels in y-direction - :return: 2d arrays with coordinates in RA/DEC with ra_coord[y-axis, x-axis] - """ - ra_coords, dec_coords = util.grid_from_coordinate_transform(nx, ny, self._Mpix2a, self._ra_at_xy_0, - self._dec_at_xy_0) - ra_coords = util.array2image(ra_coords, nx, ny) # new - dec_coords = util.array2image(dec_coords, nx, ny) # new - return ra_coords, dec_coords
- -
[docs] def shift_coordinate_system(self, x_shift, y_shift, pixel_unit=False): - """ - shifts the coordinate system - :param x_shift: shift in x (or RA) - :param y_shift: shift in y (or DEC) - :param pixel_unit: bool, if True, units of pixels in input, otherwise RA/DEC - :return: updated data class with change in coordinate system - """ - self._shift_coordinates(x_shift, y_shift, pixel_unit)
- - def _shift_coordinates(self, x_shift, y_shift, pixel_unit=False): - """ - - shifts the coordinate system - :param x_shift: shift in x (or RA) - :param y_shift: shift in y (or DEC) - :param pixel_unit: bool, if True, units of pixels in input, otherwise RA/DEC - :return: updated data class with change in coordinate system - """ - if pixel_unit is True: - ra_shift, dec_shift = self.map_pix2coord(x_shift, y_shift) - ra_shift -= self._ra_at_xy_0 - dec_shift -= self._dec_at_xy_0 - print(ra_shift, dec_shift, 'test') - else: - ra_shift, dec_shift = x_shift, y_shift - self._ra_at_xy_0 += ra_shift - self._dec_at_xy_0 += dec_shift - self._x_at_radec_0, self._y_at_radec_0 = util.map_coord2pix(-self._ra_at_xy_0, -self._dec_at_xy_0, 0, 0, - self._Ma2pix)
- - -
[docs]@export -class Coordinates1D(Coordinates): - """ - coordinate grid described in 1-d arrays - """ -
[docs] def coordinate_grid(self, nx, ny): - """ - - :param nx: number of pixels in x-direction - :param ny: number of pixels in y-direction - :return: 2d arrays with coordinates in RA/DEC with ra_coord[y-axis, x-axis] - """ - ra_coords, dec_coords = util.grid_from_coordinate_transform(nx, ny, self._Mpix2a, self._ra_at_xy_0, - self._dec_at_xy_0) - return ra_coords, dec_coords
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Data/imaging_data.html b/docs/_build/html/_modules/lenstronomy/Data/imaging_data.html deleted file mode 100644 index 8c094148b..000000000 --- a/docs/_build/html/_modules/lenstronomy/Data/imaging_data.html +++ /dev/null @@ -1,186 +0,0 @@ - - - - - - - - lenstronomy.Data.imaging_data — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Data.imaging_data

-import numpy as np
-
-from lenstronomy.Data.pixel_grid import PixelGrid
-from lenstronomy.Data.image_noise import ImageNoise
-
-__all__ = ['ImageData']
-
-
-
[docs]class ImageData(PixelGrid, ImageNoise): - """ - class to handle the data, coordinate system and masking, including convolution with various numerical precisions - - The Data() class is initialized with keyword arguments: - - - 'image_data': 2d numpy array of the image data - - 'transform_pix2angle' 2x2 transformation matrix (linear) to transform a pixel shift into a coordinate shift (x, y) -> (ra, dec) - - 'ra_at_xy_0' RA coordinate of pixel (0,0) - - 'dec_at_xy_0' DEC coordinate of pixel (0,0) - - optional keywords for shifts in the coordinate system: - - 'ra_shift': shifts the coordinate system with respect to 'ra_at_xy_0' - - 'dec_shift': shifts the coordinate system with respect to 'dec_at_xy_0' - - optional keywords for noise properties: - - 'background_rms': rms value of the background noise - - 'exp_time': float, exposure time to compute the Poisson noise contribution - - 'exposure_map': 2d numpy array, effective exposure time for each pixel. If set, will replace 'exp_time' - - 'noise_map': Gaussian noise (1-sigma) for each individual pixel. - If this keyword is set, the other noise properties will be ignored. - - - Notes: - ------ - the likelihood for the data given model P(data|model) is defined in the function below. Please make sure that - your definitions and units of 'exposure_map', 'background_rms' and 'image_data' are in accordance with the - likelihood function. In particular, make sure that the Poisson noise contribution is defined in the count rate. - - - """ - def __init__(self, image_data, exposure_time=None, background_rms=None, noise_map=None, gradient_boost_factor=None, - ra_at_xy_0=0, dec_at_xy_0=0, transform_pix2angle=None, ra_shift=0, dec_shift=0): - """ - - :param image_data: 2d numpy array of the image data - :param exposure_time: int or array of size the data; exposure time - (common for all pixels or individually for each individual pixel) - :param background_rms: root-mean-square value of Gaussian background noise in units counts per second - :param noise_map: int or array of size the data; joint noise sqrt(variance) of each individual pixel. - :param gradient_boost_factor: None or float, variance terms added in quadrature scaling with - gradient^2 * gradient_boost_factor - :param transform_pix2angle: 2x2 matrix, mapping of pixel to coordinate - :param ra_at_xy_0: ra coordinate at pixel (0,0) - :param dec_at_xy_0: dec coordinate at pixel (0,0) - :param ra_shift: RA shift of pixel grid - :param dec_shift: DEC shift of pixel grid - """ - nx, ny = np.shape(image_data) - if transform_pix2angle is None: - transform_pix2angle = np.array([[1, 0], [0, 1]]) - PixelGrid.__init__(self, nx, ny, transform_pix2angle, ra_at_xy_0 + ra_shift, dec_at_xy_0 + dec_shift) - ImageNoise.__init__(self, image_data, exposure_time=exposure_time, background_rms=background_rms, - noise_map=noise_map, gradient_boost_factor=gradient_boost_factor, verbose=False) - -
[docs] def update_data(self, image_data): - """ - - update the data as well as the error matrix estimated from it when done so using the data - - :param image_data: 2d numpy array of same size as nx, ny - :return: None - """ - nx, ny = np.shape(image_data) - if not self._nx == nx and not self._ny == ny: - raise ValueError("shape of new data %s %s must equal old data %s %s!" % (nx, ny, self._nx, self._ny)) - self._data = image_data - if hasattr(self, '_C_D') and self._noise_map is None: - del self._C_D
- - @property - def data(self): - """ - - :return: 2d numpy array of data - """ - return self._data - -
[docs] def log_likelihood(self, model, mask, additional_error_map=0): - """ - - computes the likelihood of the data given the model p(data|model) - The Gaussian errors are estimated with the covariance matrix, based on the model image. The errors include the - background rms value and the exposure time to compute the Poisson noise level (in Gaussian approximation). - - :param model: the model (same dimensions and units as data) - :param mask: bool (1, 0) values per pixel. If =0, the pixel is ignored in the likelihood - :param additional_error_map: additional error term (in same units as covariance matrix). - This can e.g. come from model errors in the PSF estimation. - :return: the natural logarithm of the likelihood p(data|model) - """ - C_D = self.C_D_model(model) - X2 = (model - self._data) ** 2 / (C_D + np.abs(additional_error_map)) * mask - X2 = np.array(X2) - logL = - np.sum(X2) / 2 - return logL
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Data/psf.html b/docs/_build/html/_modules/lenstronomy/Data/psf.html deleted file mode 100644 index ca3d105d2..000000000 --- a/docs/_build/html/_modules/lenstronomy/Data/psf.html +++ /dev/null @@ -1,244 +0,0 @@ - - - - - - - - lenstronomy.Data.psf — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Data.psf

-import numpy as np
-import lenstronomy.Util.kernel_util as kernel_util
-import lenstronomy.Util.util as util
-import warnings
-
-__all__ = ['PSF']
-
-
-
[docs]class PSF(object): - """ - Point Spread Function class. - This class describes and manages products used to perform the PSF modeling (convolution for extended surface - brightness and painting of PSF's for point sources). - """ - - def __init__(self, psf_type='NONE', fwhm=None, truncation=5, pixel_size=None, kernel_point_source=None, - psf_error_map=None, point_source_supersampling_factor=1, kernel_point_source_init=None): - """ - - :param psf_type: string, type of PSF: options are 'NONE', 'PIXEL', 'GAUSSIAN' - :param fwhm: float, full width at half maximum, only required for 'GAUSSIAN' model - :param truncation: float, Gaussian truncation (in units of sigma), only required for 'GAUSSIAN' model - :param pixel_size: width of pixel (required for Gaussian model, not required when using in combination with ImageModel modules) - :param kernel_point_source: 2d numpy array, odd length, centered PSF of a point source - (if not normalized, will be normalized) - :param psf_error_map: uncertainty in the PSF model per pixel (size of data, not super-sampled). 2d numpy array. - Size can be larger or smaller than the pixel-sized PSF model and if so, will be matched. - This error will be added to the pixel error around the position of point sources as follows: - sigma^2_i += 'psf_error_map'_j * (point_source_flux_i)**2 - :param point_source_supersampling_factor: int, supersampling factor of kernel_point_source - :param kernel_point_source_init: memory of an initial point source kernel that gets passed through the psf iteration - """ - self.psf_type = psf_type - self._pixel_size = pixel_size - self.kernel_point_source_init = kernel_point_source_init - if self.psf_type == 'GAUSSIAN': - if fwhm is None: - raise ValueError('fwhm must be set for GAUSSIAN psf type!') - self._fwhm = fwhm - self._sigma_gaussian = util.fwhm2sigma(self._fwhm) - self._truncation = truncation - self._point_source_supersampling_factor = 0 - elif self.psf_type == 'PIXEL': - if kernel_point_source is None: - raise ValueError('kernel_point_source needs to be specified for PIXEL PSF type!') - if len(kernel_point_source) % 2 == 0: - raise ValueError('kernel needs to have odd axis number, not ', np.shape(kernel_point_source)) - if point_source_supersampling_factor > 1: - self._kernel_point_source_supersampled = kernel_point_source - self._point_source_supersampling_factor = point_source_supersampling_factor - kernel_point_source = kernel_util.degrade_kernel(self._kernel_point_source_supersampled, self._point_source_supersampling_factor) - self._kernel_point_source = kernel_point_source / np.sum(kernel_point_source) - - elif self.psf_type == 'NONE': - self._kernel_point_source = np.zeros((3, 3)) - self._kernel_point_source[1, 1] = 1 - else: - raise ValueError("psf_type %s not supported!" % self.psf_type) - if psf_error_map is not None: - n_kernel = len(self.kernel_point_source) - self._psf_error_map = kernel_util.match_kernel_size(psf_error_map, n_kernel) - if self.psf_type == 'PIXEL' and point_source_supersampling_factor > 1: - if len(psf_error_map) == len(self._kernel_point_source_supersampled): - Warning('psf_error_map has the same size as the super-sampled kernel. Make sure the units in the' - 'psf_error_map are on the down-sampled pixel scale.') - self.psf_error_map_bool = True - else: - self.psf_error_map_bool = False - - @property - def kernel_point_source(self): - if not hasattr(self, '_kernel_point_source'): - if self.psf_type == 'GAUSSIAN': - kernel_num_pix = min(round(self._truncation * self._fwhm / self._pixel_size), 201) - if kernel_num_pix % 2 == 0: - kernel_num_pix += 1 - self._kernel_point_source = kernel_util.kernel_gaussian(kernel_num_pix, self._pixel_size, self._fwhm) - return self._kernel_point_source - - @property - def kernel_pixel(self): - """ - returns the convolution kernel for a uniform surface brightness on a pixel size - - :return: 2d numpy array - """ - if not hasattr(self, '_kernel_pixel'): - self._kernel_pixel = kernel_util.pixel_kernel(self.kernel_point_source, subgrid_res=1) - return self._kernel_pixel - -
[docs] def kernel_point_source_supersampled(self, supersampling_factor, updata_cache=True): - """ - generates (if not already available) a supersampled PSF with ood numbers of pixels centered - - :param supersampling_factor: int >=1, supersampling factor relative to pixel resolution - :param updata_cache: boolean, if True, updates the cached supersampling PSF if generated. - Attention, this will overwrite a previously used supersampled PSF if the resolution is changing. - :return: super-sampled PSF as 2d numpy array - """ - if hasattr(self, '_kernel_point_source_supersampled') and self._point_source_supersampling_factor == supersampling_factor: - kernel_point_source_supersampled = self._kernel_point_source_supersampled - else: - if self.psf_type == 'GAUSSIAN': - kernel_numPix = self._truncation / self._pixel_size * supersampling_factor - kernel_numPix = int(round(kernel_numPix)) - if kernel_numPix > 10000: - raise ValueError('The pixelized Gaussian kernel has a grid of %s pixels with a truncation at ' - '%s times the sigma of the Gaussian, exceeding the limit allowed.' % (kernel_numPix, self._truncation)) - if kernel_numPix % 2 == 0: - kernel_numPix += 1 - kernel_point_source_supersampled = kernel_util.kernel_gaussian(kernel_numPix, self._pixel_size / supersampling_factor, self._fwhm) - - elif self.psf_type == 'PIXEL': - - kernel = kernel_util.subgrid_kernel(self.kernel_point_source, supersampling_factor, odd=True, num_iter=5) - n = len(self.kernel_point_source) - n_new = n * supersampling_factor - if n_new % 2 == 0: - n_new -= 1 - if hasattr(self, '_kernel_point_source_supersampled'): - warnings.warn("Super-sampled point source kernel over-written due to different subsampling" - " size requested.", Warning) - kernel_point_source_supersampled = kernel_util.cut_psf(kernel, psf_size=n_new) - elif self.psf_type == 'NONE': - kernel_point_source_supersampled = self._kernel_point_source - else: - raise ValueError('psf_type %s not valid!' % self.psf_type) - if updata_cache is True: - self._kernel_point_source_supersampled = kernel_point_source_supersampled - self._point_source_supersampling_factor = supersampling_factor - return kernel_point_source_supersampled
- -
[docs] def set_pixel_size(self, deltaPix): - """ - update pixel size - - :param deltaPix: pixel size in angular units (arc seconds) - :return: None - """ - self._pixel_size = deltaPix - if self.psf_type == 'GAUSSIAN': - try: - del self._kernel_point_source - except: - pass
- - @property - def psf_error_map(self): - if not hasattr(self, '_psf_error_map'): - self._psf_error_map = np.zeros_like(self.kernel_point_source) - return self._psf_error_map - - @property - def fwhm(self): - """ - - :return: full width at half maximum of kernel (in units of pixel) - """ - if self.psf_type == 'GAUSSIAN': - return self._fwhm - else: - return kernel_util.fwhm_kernel(self.kernel_point_source) * self._pixel_size
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/GalKin/analytic_kinematics.html b/docs/_build/html/_modules/lenstronomy/GalKin/analytic_kinematics.html deleted file mode 100644 index 4baa95e16..000000000 --- a/docs/_build/html/_modules/lenstronomy/GalKin/analytic_kinematics.html +++ /dev/null @@ -1,271 +0,0 @@ - - - - - - - - lenstronomy.GalKin.analytic_kinematics — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.GalKin.analytic_kinematics

-__author__ = 'sibirrer'
-
-import numpy as np
-from scipy.interpolate import interp1d
-import lenstronomy.GalKin.velocity_util as vel_util
-from lenstronomy.GalKin.cosmo import Cosmo
-from lenstronomy.GalKin.anisotropy import Anisotropy
-from lenstronomy.LensModel.Profiles.spp import SPP
-import lenstronomy.Util.constants as const
-import math
-
-__all__ = ['AnalyticKinematics']
-
-
-
[docs]class AnalyticKinematics(Anisotropy): - """ - class to compute eqn 20 in Suyu+2010 with a Monte-Carlo from rendering from the - light profile distribution and displacing them with a Gaussian seeing convolution - - This class assumes spherical symmetry in light and mass distribution and - - a Hernquist light profile (parameterised by the half-light radius) - - a power-law mass profile (parameterized by the Einstein radius and logarithmic slop) - - The analytic equations for the kinematics in this approximation are presented e.g. in Suyu et al. 2010 and - the spectral rendering approach to compute the seeing convolved slit measurement is presented in Birrer et al. 2016. - The stellar anisotropy is parameterised based on Osipkov 1979; Merritt 1985. - - Units - ----- - all units are meant to be in angular arc seconds. The physical units are fold in through the angular diameter - distances - - """ - def __init__(self, kwargs_cosmo, interpol_grid_num=100, log_integration=False, max_integrate=100, - min_integrate=0.001): - """ - - :param kwargs_cosmo: keyword argument with angular diameter distances - """ - - self._interp_grid_num = interpol_grid_num - self._log_int = log_integration - self._max_integrate = max_integrate # maximal integration (and interpolation) in units of arcsecs - self._min_integrate = min_integrate # min integration (and interpolation) in units of arcsecs - self._max_interpolate = max_integrate # we chose to set the interpolation range to the integration range - self._min_interpolate = min_integrate # we chose to set the interpolation range to the integration range - - self._cosmo = Cosmo(**kwargs_cosmo) - self._spp = SPP() - Anisotropy.__init__(self, anisotropy_type='OM') - - def _rho0_r0_gamma(self, theta_E, gamma): - # equation (14) in Suyu+ 2010 - return -1 * math.gamma(gamma/2) / (np.sqrt(np.pi)*math.gamma((gamma-3)/2.)) * theta_E ** gamma / \ - self._cosmo.arcsec2phys_lens(theta_E) * self._cosmo.epsilon_crit * const.M_sun / const.Mpc ** 3 - -
[docs] @staticmethod - def draw_light(kwargs_light): - """ - - :param kwargs_light: keyword argument (list) of the light model - :return: 3d radius (if possible), 2d projected radius, x-projected coordinate, y-projected coordinate - """ - if 'a' not in kwargs_light: - kwargs_light['a'] = 0.551 * kwargs_light['r_eff'] - a = kwargs_light['a'] - r = vel_util.draw_hernquist(a) - R, x, y = vel_util.project2d_random(r) - return r, R, x, y
- - def _sigma_s2(self, r, R, r_ani, a, gamma, rho0_r0_gamma): - """ - projected velocity dispersion - :param r: 3d radius of the light tracer particle - :param R: 2d projected radius of the light tracer particle - :param r_ani: anisotropy radius - :param a: scale of the Hernquist light profile - :param gamma: power-law slope of the mass profile - :param rho0_r0_gamma: combination of Einstein radius and power-law slope as equation (14) in Suyu+ 2010 - :return: projected velocity dispersion - """ - beta = self.beta_r(r, **{'r_ani': r_ani}) - return (1 - beta * R**2/r**2) * self._sigma_r2_interp(r, a, gamma, rho0_r0_gamma, r_ani) - -
[docs] def sigma_s2(self, r, R, kwargs_mass, kwargs_light, kwargs_anisotropy): - """ - returns unweighted los velocity dispersion for a specified projected radius, with weight 1 - - :param r: 3d radius (not needed for this calculation) - :param R: 2d projected radius (in angular units of arcsec) - :param kwargs_mass: mass model parameters (following lenstronomy lens model conventions) - :param kwargs_light: deflector light parameters (following lenstronomy light model conventions) - :param kwargs_anisotropy: anisotropy parameters, may vary according to anisotropy type chosen. - We refer to the Anisotropy() class for details on the parameters. - :return: line-of-sight projected velocity dispersion at projected radius R from 3d radius r - """ - a, gamma, rho0_r0_gamma, r_ani = self._read_out_params(kwargs_mass, kwargs_light, kwargs_anisotropy) - return self._sigma_s2(r, R, r_ani, a, gamma, rho0_r0_gamma), 1
- -
[docs] def sigma_r2(self, r, kwargs_mass, kwargs_light, kwargs_anisotropy): - """ - equation (19) in Suyu+ 2010 - - :param r: 3d radius - :param kwargs_mass: mass profile keyword arguments - :param kwargs_light: light profile keyword arguments - :param kwargs_anisotropy: anisotropy keyword arguments - :return: velocity dispersion in [m/s] - """ - a, gamma, rho0_r0_gamma, r_ani = self._read_out_params(kwargs_mass, kwargs_light, kwargs_anisotropy) - return self._sigma_r2(r, a, gamma, rho0_r0_gamma, r_ani)
- - def _read_out_params(self, kwargs_mass, kwargs_light, kwargs_anisotropy): - """ - reads the relevant parameters out of the keyword arguments and transforms them to the conventions used in this - class - - :param kwargs_mass: mass profile keyword arguments - :param kwargs_light: light profile keyword arguments - :param kwargs_anisotropy: anisotropy keyword arguments - :return: a (Rs of Hernquist profile), gamma, rho0_r0_gamma, r_ani - """ - if 'a' not in kwargs_light: - kwargs_light['a'] = 0.551 * kwargs_light['r_eff'] - if 'rho0_r0_gamma' not in kwargs_mass: - kwargs_mass['rho0_r0_gamma'] = self._rho0_r0_gamma(kwargs_mass['theta_E'], kwargs_mass['gamma']) - a = kwargs_light['a'] - gamma = kwargs_mass['gamma'] - rho0_r0_gamma = kwargs_mass['rho0_r0_gamma'] - r_ani = kwargs_anisotropy['r_ani'] - return a, gamma, rho0_r0_gamma, r_ani - - def _sigma_r2(self, r, a, gamma, rho0_r0_gamma, r_ani): - """ - equation (19) in Suyu+ 2010 - """ - # first term - prefac1 = 4*np.pi * const.G * a**(-gamma) * rho0_r0_gamma / (3-gamma) - prefac2 = r * (r + a)**3/(r**2 + r_ani**2) - # TODO check whether interpolation functions can speed this up - hyp1 = vel_util.hyp_2F1(a=2+gamma, b=gamma, c=3+gamma, z=1./(1+r/a)) - hyp2 = vel_util.hyp_2F1(a=3, b=gamma, c=1+gamma, z=-a/r) - fac = r_ani**2/a**2 * hyp1 / ((2+gamma) * (r/a + 1)**(2+gamma)) + hyp2 / (gamma*(r/a)**gamma) - return prefac1 * prefac2 * fac * (const.arcsec * self._cosmo.dd * const.Mpc) ** 2 - - def _sigma_r2_interp(self, r, a, gamma, rho0_r0_gamma, r_ani): - """ - - :param r: - :param a: - :param gamma: - :param rho0_r0_gamma: - :param r_ani: - :return: - """ - if not hasattr(self, '_interp_sigma_r2'): - min_log = np.log10(self._min_integrate) - max_log = np.log10(self._max_integrate) - r_array = np.logspace(min_log, max_log, self._interp_grid_num) - I_R_sigma2_array = [] - for r_i in r_array: - I_R_sigma2_array.append(self._sigma_r2(r_i, a, gamma, rho0_r0_gamma, r_ani)) - self._interp_sigma_r2 = interp1d(np.log(r_array), np.array(I_R_sigma2_array), fill_value="extrapolate") - return self._interp_sigma_r2(np.log(r)) - -
[docs] def grav_potential(self, r, kwargs_mass): - """ - Gravitational potential in SI units - - :param r: radius (arc seconds) - :param kwargs_mass: - :return: gravitational potential - """ - theta_E = kwargs_mass['theta_E'] - gamma = kwargs_mass['gamma'] - mass_dimless = self._spp.mass_3d_lens(r, theta_E, gamma) - mass_dim = mass_dimless * const.arcsec ** 2 * self._cosmo.dd * self._cosmo.ds / self._cosmo.dds * const.Mpc * \ - const.c ** 2 / (4 * np.pi * const.G) - grav_pot = -const.G * mass_dim / (r * const.arcsec * self._cosmo.dd * const.Mpc) - return grav_pot
- -
[docs] def delete_cache(self): - """ - deletes temporary cache tight to a specific model - - :return: - """ - if hasattr(self, '_interp_sigma_r2'): - del self._interp_sigma_r2
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/GalKin/anisotropy.html b/docs/_build/html/_modules/lenstronomy/GalKin/anisotropy.html deleted file mode 100644 index 63b8e4b89..000000000 --- a/docs/_build/html/_modules/lenstronomy/GalKin/anisotropy.html +++ /dev/null @@ -1,519 +0,0 @@ - - - - - - - - lenstronomy.GalKin.anisotropy — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.GalKin.anisotropy

-import numpy as np
-import scipy.special as special
-from lenstronomy.GalKin import velocity_util
-from scipy.interpolate import interp1d
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -class Anisotropy(object): - """ - class that handles the kinematic anisotropy - sources: Mamon & Lokas 2005 - https://arxiv.org/pdf/astro-ph/0405491.pdf - - Agnello et al. 2014 - https://arxiv.org/pdf/1401.4462.pdf - """ - - def __init__(self, anisotropy_type): - """ - - :param anisotropy_type: string, anisotropy model type - """ - self._type = anisotropy_type - if self._type == 'const': - self._model = Const() - elif self._type == 'radial': - self._model = Radial() - elif self._type == 'isotropic': - self._model = Isotropic() - elif self._type == 'OM': - self._model = OsipkovMerritt() - elif self._type == 'GOM': - self._model = GeneralizedOM() - elif self._type == 'Colin': - self._model = Colin() - else: - raise ValueError('anisotropy type %s not supported!' % self._type) - -
[docs] def beta_r(self, r, **kwargs): - """ - returns the anisotropy parameter at a given radius - :param r: 3d radius - :param kwargs: parameters of the specified anisotropy model - :return: beta(r) - """ - return self._model.beta_r(r, **kwargs)
- -
[docs] def K(self, r, R, **kwargs): - """ - equation A16 im Mamon & Lokas for Osipkov&Merrit anisotropy - - :param r: 3d radius - :param R: projected 2d radius - :param kwargs: parameters of the specified anisotropy model - :return: K(r, R) - """ - return self._model.K(r, R, **kwargs)
- -
[docs] def anisotropy_solution(self, r, **kwargs): - """ - the solution to - d ln(f)/ d ln(r) = 2 beta(r) - - :param r: 3d radius - :param kwargs: parameters of the specified anisotropy model - :return: f(r) - """ - return self._model.anisotropy_solution(r, **kwargs)
- -
[docs] def delete_anisotropy_cache(self): - """ - deletes cached interpolations for a fixed anisotropy model - :return: - """ - if hasattr(self._model, 'delete_cache'): - self._model.delete_cache()
- - -
[docs]@export -class Const(object): - """ - constant anisotropy model class - See Mamon & Lokas 2005 for details - """ - def __init__(self): - pass - -
[docs] @staticmethod - def K(r, R, beta): - """ - equation A16 im Mamon & Lokas for constant anisotropy - - :param r: 3d radius - :param R: projected 2d radius - :param beta: anisotropy - :return: K(r, R, beta) - """ - u = r / R - k = np.sqrt(1 - 1. / u ** 2) / (1. - 2 * beta) + np.sqrt(np.pi) / 2 * special.gamma( - beta - 1. / 2) / special.gamma(beta) \ - * (3. / 2 - beta) * u ** (2 * beta - 1.) * (1 - special.betainc(beta + 1. / 2, 1. / 2, 1. / u ** 2)) - return k
- -
[docs] @staticmethod - def beta_r(r, beta): - """ - anisotropy as a function of radius - - :param r: 3d radius - :param beta: anisotropy - :return: beta - """ - return beta
- -
[docs] def anisotropy_solution(self, r, **kwargs): - """ - the solution to - d ln(f)/ d ln(r) = 2 beta(r) - - :param r: 3d radius - :param kwargs: parameters of the specified anisotropy model - :return: f(r) - """ - raise ValueError('routine not supported yet for constant anisotropy model!')
- - -
[docs]@export -class Isotropic(object): - """ - class for isotropic (beta=0) stellar orbits - See Mamon & Lokas 2005 for details - """ - def __init__(self): - pass - -
[docs] @staticmethod - def K(r, R): - """ - equation A16 im Mamon & Lokas for constant anisotropy - - :param r: 3d radius - :param R: projected 2d radius - :return: K(r, R) - """ - u = r / R - k = np.sqrt(1 - 1. / u ** 2) - return k
- -
[docs] @staticmethod - def beta_r(r): - """ - anisotropy as a function of radius - - :param r: 3d radius - :return: beta - """ - return 0.
- -
[docs] def anisotropy_solution(self, r, **kwargs): - """ - the solution to - d ln(f)/ d ln(r) = 2 beta(r) - See e.g. A3 in Mamon & Lokas - - :param r: 3d radius - :param kwargs: parameters of the specified anisotropy model - :return: f(r) - """ - return 1
- - -
[docs]@export -class Radial(object): - """ - class for radial (beta=1) stellar orbits - See Mamon & Lokas 2005 for details - """ - def __init__(self): - pass - -
[docs] def K(self, r, R): - """ - equation A16 im Mamon & Lokas for constant anisotropy - - :param r: 3d radius - :param R: projected 2d radius - :return: K(r, R) - """ - u = r / R - k = np.pi / 4 * u - 1. / 2 * np.sqrt(1 - 1. / u ** 2) - u / 2. * np.arcsin(1. / u) - return k
- -
[docs] @staticmethod - def beta_r(r): - """ - anisotropy as a function of radius - - :param r: 3d radius - :return: beta - """ - return 1.
- -
[docs] def anisotropy_solution(self, r): - """ - the solution to - d ln(f)/ d ln(r) = 2 beta(r) - See e.g. A4 in Mamon & Lokas - - :param r: 3d radius - :return: f(r) - """ - return r**2
- - -
[docs]@export -class OsipkovMerritt(object): - """ - class for Osipkov&Merrit stellar orbits - See Mamon & Lokas 2005 for details - """ - def __init__(self): - pass - -
[docs] def K(self, r, R, r_ani): - """ - equation A16 im Mamon & Lokas 2005 for Osipkov&Merrit anisotropy - - :param r: 3d radius - :param R: projected 2d radius - :param r_ani: anisotropy radius - :return: K(r, R) - """ - u = r / R - ua = r_ani / R - k = (ua ** 2 + 1. / 2) / (ua ** 2 + 1) ** (3. / 2) * (u ** 2 + ua ** 2) / u * np.arctan( - np.sqrt((u ** 2 - 1) / (ua ** 2 + 1))) - 1. / 2 / (ua ** 2 + 1) * np.sqrt(1 - 1. / u ** 2) - return k
- -
[docs] @staticmethod - def beta_r(r, r_ani): - """ - anisotropy as a function of radius - - :param r: 3d radius - :param r_ani: anisotropy radius - :return: beta - """ - return r**2/(r_ani**2 + r**2)
- -
[docs] @staticmethod - def anisotropy_solution(r, r_ani): - """ - the solution to - d ln(f)/ d ln(r) = 2 beta(r) - See e.g. A5 in Mamon & Lokas - - :param r: 3d radius - :param r_ani: anisotropy radius - :return: f(r) - """ - return r**2 + r_ani**2
- - -
[docs]@export -class GeneralizedOM(object): - """ - generalized Osipkov&Merrit profile - see Agnello et al. 2014 https://arxiv.org/pdf/1401.4462.pdf - b(r) = beta_inf * r^2 / (r^2 + r_ani^2) - """ - def __init__(self): - self._z_interp = np.append(-np.flip(np.logspace(-1, 3, 200)**2), 0) - #self._z_interp = -np.linspace(-200, 0, 200)**2 # z = (R**2 - r**2) / (r_ani**2 + R**2) - -
[docs] @staticmethod - def beta_r(r, r_ani, beta_inf): - """ - anisotropy as a function of radius - - :param r: 3d radius - :param r_ani: anisotropy radius - :param beta_inf: anisotropy at infinity - :return: beta - """ - return beta_inf * r**2/(r_ani**2 + r**2)
- -
[docs] def K(self, r, R, r_ani, beta_inf): - """ - equation19 in Agnello et al. 2014 for k_beta(R, r) such that - K(R, r) = (sqrt(r^2 - R^2) + k_beta(R, r)) / r - - :param r: 3d radius - :param R: projected 2d radius - :param r_ani: anisotropy radius - :param beta_inf: anisotropy at infinity - :return: K(r, R) - """ - return (np.sqrt(r**2 - R**2) + self._k_beta(r, R, r_ani, beta_inf)) / r
- -
[docs] def anisotropy_solution(self, r, r_ani, beta_inf): - """ - the solution to - d ln(f)/ d ln(r) = 2 beta(r) - See e.g. A5 in Mamon & Lokas with a scaling (nominator of Agnello et al. 2014 Equation (12) - - :param r: 3d radius - :param r_ani: anisotropy radius - :param beta_inf: anisotropy at infinity - :return: f(r) - """ - return (r**2 + r_ani**2) ** beta_inf
- -
[docs] def delete_cache(self): - """ - deletes the interpolation function of the hypergeometic function for a specific beta_inf - - :return: deleted self variables - """ - if hasattr(self, '_f_12_interp'): - del self._f_12_interp - if hasattr(self, '_f_32_interp'): - del self._f_32_interp
- - def _k_beta(self, r, R, r_ani, beta_inf): - """ - equation19 in Agnello et al. 2014 for k_beta(R, r) such that - K(R, r) = (sqrt(r^2 - R^2) + k_beta(R, r)) / r - - :param r: 3d radius - :param R: projected 2d radius - :param r_ani: anisotropy radius - :param beta_inf: anisotropy at infinity - :return: k_beta(r, R) - """ - z = (R**2 - r**2) / (r_ani**2 + R**2) - # ((r**2 + r_ani**2) / (R**2 + r_ani**2)) ** beta_inf - return - self.beta_r(R, r_ani, beta_inf) * self._j_beta(R, r, r_ani, beta_inf) *\ - np.sqrt(r**2 - R**2) * (self._F_12(z, beta_inf) + 2. * (1 - r**2/R**2) / 3 * self._F_32(z, beta_inf)) - - def _F_12(self, z, beta_inf): - """ - - :param z: (R**2 - r**2) / (r_ani**2 + R**2) - :param beta_inf: anisotropy at infinity - :return: _F(1/2, z, beta_inf) - """ - if not hasattr(self, '_f_12_interp'): - f_12_interp = self._F(1 / 2., self._z_interp, beta_inf) - self._f_12_interp = interp1d(self._z_interp, f_12_interp, kind='cubic', fill_value="extrapolate") - return self._f_12_interp(z) - - def _F_32(self, z, beta_inf): - """ - - :param z: (R**2 - r**2) / (r_ani**2 + R**2) - :param beta_inf: anisotropy at infinity - :return: _F(3/2, z, beta_inf) - """ - if not hasattr(self, '_f_32_interp'): - f_32_interp = self._F(3 / 2., self._z_interp, beta_inf) - self._f_32_interp = interp1d(self._z_interp, f_32_interp, kind='cubic', fill_value="extrapolate") - return self._f_32_interp(z) - - def _j_beta(self, r, s, r_ani, beta_inf): - """ - equation (12) in Agnello et al. 2014 - - :param r: - :param s: - :param r_ani: - :param beta_inf - :return: - """ - return ((s**2 + r_ani**2) / (r**2 + r_ani**2)) ** beta_inf - - def _F(self, a, z, beta_inf): - """ - the hypergeometric function 2F1 (a, 1 +beta_inf, a + 1, z) - - :param a: - :param z: - :return: - """ - if isinstance(z, int) or isinstance(z, float): - return velocity_util.hyp_2F1(a=a, b=1+beta_inf, c=a+1, z=z) - else: - _F_array = [] - for z_i in z: - _F_array.append(velocity_util.hyp_2F1(a=a, b=1+beta_inf, c=a+1, z=z_i)) - return np.array(_F_array, dtype=float)
- - -
[docs]@export -class Colin(object): - """ - class for stellar orbits anisotropy parameter based on Colin et al. (2000) - See Mamon & Lokas 2005 for details - """ - def __init__(self): - pass - -
[docs] def K(self, r, R, r_ani): - """ - equation A16 im Mamon & Lokas for Osipkov&Merrit anisotropy - - :param r: 3d radius - :param R: projected 2d radius - :param r_ani: anisotropy radius - :return: K(r, R) - """ - u = r / R - if np.min(u) < 1: - raise ValueError("3d radius is smaller than projected radius! Does not make sense.") - ua = r_ani / R - if ua == 1: - k = (1 + 1. / u) * np.arccosh(u) - 1. / 6 * (8. / u + 7) * np.sqrt((u - 1.) / (u + 1.)) - elif ua > 1: - k = 0.5 / (ua ** 2 - 1) * np.sqrt(1 - 1. / u ** 2) + (1. + ua / u) * np.arccosh(u) - np.sign(ua - 1) * ua * \ - (ua ** 2 - 0.5) / np.abs(ua ** 2 - 1) ** (3. / 2) * (1. + ua / u) * np.arccosh((ua * u + 1) / (u + ua)) - else: # ua < 1 - k = 0.5 / (ua ** 2 - 1) * np.sqrt(1 - 1. / u ** 2) + (1. + ua / u) * np.arccosh(u) - np.sign(ua - 1) * ua * \ - (ua ** 2 - 0.5) / np.abs(ua ** 2 - 1) ** (3. / 2) * (1. + ua / u) * np.arccos((ua * u + 1) / (u + ua)) - return k
- -
[docs] @staticmethod - def beta_r(r, r_ani): - """ - anisotropy as a function of radius - - :param r: 3d radius - :param r_ani: anisotropy radius - :return: beta - """ - return 1./2 * r / (r + r_ani)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/GalKin/aperture.html b/docs/_build/html/_modules/lenstronomy/GalKin/aperture.html deleted file mode 100644 index 69a69070b..000000000 --- a/docs/_build/html/_modules/lenstronomy/GalKin/aperture.html +++ /dev/null @@ -1,136 +0,0 @@ - - - - - - - - lenstronomy.GalKin.aperture — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.GalKin.aperture

-__author__ = 'sibirrer'
-
-from lenstronomy.GalKin.aperture_types import Shell, Slit, IFUShells, Frame
-
-__all__ = ['Aperture']
-
-
-"""
-class that defines the aperture of the measurement (e.g. slit, integral field spectroscopy regions etc)
-
-Available aperture types:
--------------------------
-
-'slit': length, width, center_ra, center_dec, angle
-'shell': r_in, r_out, center_ra, center_dec
-
-"""
-
-
-
[docs]class Aperture(object): - """ - defines mask(s) of spectra, can handle IFU and single slit/box type data. - """ - def __init__(self, aperture_type, **kwargs_aperture): - """ - - :param aperture_type: string - :param kwargs_aperture: keyword arguments reflecting the aperture type chosen. - We refer to the specific class instances for documentation. - """ - if aperture_type == 'slit': - self._aperture = Slit(**kwargs_aperture) - elif aperture_type == 'shell': - self._aperture = Shell(**kwargs_aperture) - elif aperture_type == 'IFU_shells': - self._aperture = IFUShells(**kwargs_aperture) - elif aperture_type == 'frame': - self._aperture = Frame(**kwargs_aperture) - else: - raise ValueError("aperture type %s not implemented! Available are 'slit', 'shell', 'IFU_shells'. " - % aperture_type) - -
[docs] def aperture_select(self, ra, dec): - """ - - :param ra: angular coordinate of photon/ray - :param dec: angular coordinate of photon/ray - :return: bool, True if photon/ray is within the slit, False otherwise, int of the segment of the IFU - """ - return self._aperture.aperture_select(ra, dec)
- - @property - def num_segments(self): - return self._aperture.num_segments
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/GalKin/aperture_types.html b/docs/_build/html/_modules/lenstronomy/GalKin/aperture_types.html deleted file mode 100644 index 86827f2a9..000000000 --- a/docs/_build/html/_modules/lenstronomy/GalKin/aperture_types.html +++ /dev/null @@ -1,324 +0,0 @@ - - - - - - - - lenstronomy.GalKin.aperture_types — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.GalKin.aperture_types

-__author__ = 'sibirrer'
-
-import numpy as np
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -class Slit(object): - """ - Slit aperture description - """ - - def __init__(self, length, width, center_ra=0, center_dec=0, angle=0): - """ - - :param length: length of slit - :param width: width of slit - :param center_ra: center of slit - :param center_dec: center of slit - :param angle: orientation angle of slit, angle=0 corresponds length in RA direction - """ - self._length = length - self._width = width - self._center_ra, self._center_dec = center_ra, center_dec - self._angle = angle - -
[docs] def aperture_select(self, ra, dec): - """ - - :param ra: angular coordinate of photon/ray - :param dec: angular coordinate of photon/ray - :return: bool, True if photon/ray is within the slit, False otherwise - """ - return slit_select(ra, dec, self._length, self._width, self._center_ra, self._center_dec, self._angle), 0
- - @property - def num_segments(self): - """ - number of segments with separate measurements of the velocity dispersion - :return: int - """ - return 1
- - -
[docs]@export -def slit_select(ra, dec, length, width, center_ra=0, center_dec=0, angle=0): - """ - - :param ra: angular coordinate of photon/ray - :param dec: angular coordinate of photon/ray - :param length: length of slit - :param width: width of slit - :param center_ra: center of slit - :param center_dec: center of slit - :param angle: orientation angle of slit, angle=0 corresponds length in RA direction - :return: bool, True if photon/ray is within the slit, False otherwise - """ - ra_ = ra - center_ra - dec_ = dec - center_dec - x = np.cos(angle) * ra_ + np.sin(angle) * dec_ - y = - np.sin(angle) * ra_ + np.cos(angle) * dec_ - - if abs(x) < length / 2. and abs(y) < width / 2.: - return True - else: - return False
- - -
[docs]@export -class Frame(object): - """ - rectangular box with a hole in the middle (also rectangular), effectively a frame - """ - - def __init__(self, width_outer, width_inner, center_ra=0, center_dec=0, angle=0): - """ - - :param width_outer: width of box to the outer parts - :param width_inner: width of inner removed box - :param center_ra: center of slit - :param center_dec: center of slit - :param angle: orientation angle of slit, angle=0 corresponds length in RA direction - """ - self._width_outer = width_outer - self._width_inner = width_inner - self._center_ra, self._center_dec = center_ra, center_dec - self._angle = angle - -
[docs] def aperture_select(self, ra, dec): - """ - - :param ra: angular coordinate of photon/ray - :param dec: angular coordinate of photon/ray - :return: bool, True if photon/ray is within the slit, False otherwise - """ - return frame_select(ra, dec, self._width_outer, self._width_inner, self._center_ra, self._center_dec, self._angle), 0
- - @property - def num_segments(self): - """ - number of segments with separate measurements of the velocity dispersion - :return: int - """ - return 1
- - -
[docs]@export -def frame_select(ra, dec, width_outer, width_inner, center_ra=0, center_dec=0, angle=0): - """ - - :param ra: angular coordinate of photon/ray - :param dec: angular coordinate of photon/ray - :param width_outer: width of box to the outer parts - :param width_inner: width of inner removed box - :param center_ra: center of slit - :param center_dec: center of slit - :param angle: orientation angle of slit, angle=0 corresponds length in RA direction - :return: bool, True if photon/ray is within the box with a hole, False otherwise - """ - ra_ = ra - center_ra - dec_ = dec - center_dec - x = np.cos(angle) * ra_ + np.sin(angle) * dec_ - y = - np.sin(angle) * ra_ + np.cos(angle) * dec_ - if abs(x) < width_outer / 2. and abs(y) < width_outer / 2.: - if abs(x) < width_inner / 2. and abs(y) < width_inner / 2.: - return False - else: - return True - return False
- - -
[docs]@export -class Shell(object): - """ - Shell aperture - """ - - def __init__(self, r_in, r_out, center_ra=0, center_dec=0): - """ - - :param r_in: innermost radius to be selected - :param r_out: outermost radius to be selected - :param center_ra: center of the sphere - :param center_dec: center of the sphere - """ - self._r_in, self._r_out = r_in, r_out - self._center_ra, self._center_dec = center_ra, center_dec - -
[docs] def aperture_select(self, ra, dec): - """ - - :param ra: angular coordinate of photon/ray - :param dec: angular coordinate of photon/ray - :return: bool, True if photon/ray is within the slit, False otherwise - """ - return shell_select(ra, dec, self._r_in, self._r_out, self._center_ra, self._center_dec), 0
- - @property - def num_segments(self): - """ - number of segments with separate measurements of the velocity dispersion - :return: int - """ - return 1
- - -
[docs]@export -def shell_select(ra, dec, r_in, r_out, center_ra=0, center_dec=0): - """ - - :param ra: angular coordinate of photon/ray - :param dec: angular coordinate of photon/ray - :param r_in: innermost radius to be selected - :param r_out: outermost radius to be selected - :param center_ra: center of the sphere - :param center_dec: center of the sphere - :return: boolean, True if within the radial range, False otherwise - """ - x = ra - center_ra - y = dec - center_dec - R = np.sqrt(x ** 2 + y ** 2) - if (R >= r_in) and (R < r_out): - return True - else: - return False
- - -
[docs]@export -class IFUShells(object): - """ - class for an Integral Field Unit spectrograph with azimuthal shells where the kinematics are measured - """ - def __init__(self, r_bins, center_ra=0, center_dec=0): - """ - - :param r_bins: array of radial bins to average the dispersion spectra in ascending order. - It starts with the inner-most edge to the outermost edge. - :param center_ra: center of the sphere - :param center_dec: center of the sphere - """ - self._r_bins = r_bins - self._center_ra, self._center_dec = center_ra, center_dec - -
[docs] def aperture_select(self, ra, dec): - """ - - :param ra: angular coordinate of photon/ray - :param dec: angular coordinate of photon/ray - :return: bool, True if photon/ray is within the slit, False otherwise, index of shell - """ - return shell_ifu_select(ra, dec, self._r_bins, self._center_ra, self._center_dec)
- - @property - def num_segments(self): - """ - number of segments with separate measurements of the velocity dispersion - :return: int - """ - return len(self._r_bins) - 1
- - -
[docs]@export -def shell_ifu_select(ra, dec, r_bin, center_ra=0, center_dec=0): - """ - - :param ra: angular coordinate of photon/ray - :param dec: angular coordinate of photon/ray - :param r_bin: array of radial bins to average the dispersion spectra in ascending order. - It starts with the inner-most edge to the outermost edge. - :param center_ra: center of the sphere - :param center_dec: center of the sphere - :return: boolean, True if within the radial range, False otherwise - """ - x = ra - center_ra - y = dec - center_dec - R = np.sqrt(x ** 2 + y ** 2) - for i in range(0, len(r_bin) - 1): - if (R >= r_bin[i]) and (R < r_bin[i+1]): - return True, i - return False, None
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/GalKin/cosmo.html b/docs/_build/html/_modules/lenstronomy/GalKin/cosmo.html deleted file mode 100644 index a4c1f0c00..000000000 --- a/docs/_build/html/_modules/lenstronomy/GalKin/cosmo.html +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - lenstronomy.GalKin.cosmo — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.GalKin.cosmo

-import lenstronomy.Util.constants as const
-import numpy as np
-
-__all__ = ['Cosmo']
-
-
-
[docs]class Cosmo(object): - """ - cosmological quantities - """ - def __init__(self, d_d, d_s, d_ds): - """ - - :param d_d: angular diameter distance to the deflector - :param d_s: angular diameter distance to the source - :param d_ds: angular diameter distance between deflector and source - """ - if d_ds <= 0 or d_s <= 0 or d_d <= 0: - raise ValueError('input angular diameter distances Dd: %s, Ds: %s, Dds: %s are not suppored for a lens' - ' model!' % (d_d, d_s, d_ds)) - self.dd = float(d_d) # angular diameter distance from observer to deflector in physical Mpc - self.ds = float(d_s) # angular diameter distance from observer to source in physical Mpc - self.dds = float(d_ds) # angular diameter distance from deflector to source in physical Mpc - -
[docs] def arcsec2phys_lens(self, theta): - """ - converts are seconds to physical units on the deflector - :param theta: angle observed on the sky in units of arc seconds - :return: pyhsical distance of the angle in units of Mpc - """ - return theta * const.arcsec * self.dd
- - @property - def epsilon_crit(self): - """ - returns the critical projected mass density in units of M_sun/Mpc^2 (physical units) - """ - const_si = const.c**2 / (4*np.pi * const.G) # c^2/(4*pi*G) in units of [kg/m] - conversion = const.Mpc / const.M_sun # converts [kg/m] to [M_sun/Mpc] - pre_const = const_si * conversion # c^2/(4*pi*G) in units of [M_sun/Mpc] - epsilon_crit = self.ds / (self.dd * self.dds) * pre_const # [M_sun/Mpc^2] - return epsilon_crit
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/GalKin/galkin.html b/docs/_build/html/_modules/lenstronomy/GalKin/galkin.html deleted file mode 100644 index 269b9db07..000000000 --- a/docs/_build/html/_modules/lenstronomy/GalKin/galkin.html +++ /dev/null @@ -1,222 +0,0 @@ - - - - - - - - lenstronomy.GalKin.galkin — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.GalKin.galkin

-from lenstronomy.GalKin.observation import GalkinObservation
-from lenstronomy.GalKin.galkin_model import GalkinModel
-
-import numpy as np
-
-__all__ = ['Galkin']
-
-
-
[docs]class Galkin(GalkinModel, GalkinObservation): - """ - Major class to compute velocity dispersion measurements given light and mass models - - The class supports any mass and light distribution (and superposition thereof) that has a 3d correspondance in their - 2d lens model distribution. For models that do not have this correspondance, you may want to apply a - Multi-Gaussian Expansion (MGE) on their models and use the MGE to be de-projected to 3d. - - The computation follows Mamon&Lokas 2005 and performs the spectral rendering of the seeing convolved apperture with - the method introduced by Birrer et al. 2016. - - The class supports various types of anisotropy models (see Anisotropy class) and aperture types (see Aperture class). - - Solving the Jeans Equation requires a numerical integral over the 3d light and mass profile (see Mamon&Lokas 2005). - This class (as well as the dedicated LightModel and MassModel classes) perform those integral numerically with an - interpolated grid. - - The seeing convolved integral over the aperture is computed by rendering spectra (light weighted LOS kinematics) - from the light distribution. - - The cosmology assumed to compute the physical mass and distances are set via the kwargs_cosmo keyword arguments. - d_d: Angular diameter distance to the deflector (in Mpc) - d_s: Angular diameter distance to the source (in Mpc) - d_ds: Angular diameter distance from the deflector to the source (in Mpc) - - The numerical options can be chosen through the kwargs_numerics keywords - - interpol_grid_num: number of interpolation points in the light and mass profile (radially). This number should - be chosen high enough to accurately describe the true light profile underneath. - log_integration: bool, if True, performs the interpolation and numerical integration in log-scale. - - max_integrate: maximum 3d radius to where the numerical integration of the Jeans Equation solver is made. - This value should be large enough to contain most of the light and to lead to a converged result. - min_integrate: minimal integration value. This value should be very close to zero but some mass and light - profiles are diverging and a numerically stabel value should be chosen. - - These numerical options should be chosen to allow for a converged result (within your tolerance) but not too - conservative to impact too much the computational cost. Reasonable values might depend on the specific problem. - - """ - def __init__(self, kwargs_model, kwargs_aperture, kwargs_psf, kwargs_cosmo, kwargs_numerics=None, - analytic_kinematics=False): - """ - - :param kwargs_model: keyword arguments describing the model components - :param kwargs_aperture: keyword arguments describing the spectroscopic aperture, see Aperture() class - :param kwargs_psf: keyword argument specifying the PSF of the observation - :param kwargs_cosmo: keyword arguments that define the cosmology in terms of the angular diameter distances - involved - :param kwargs_numerics: numerics keyword arguments - :param analytic_kinematics: bool, if True uses the analytic kinematic model - """ - GalkinModel.__init__(self, kwargs_model, kwargs_cosmo, kwargs_numerics=kwargs_numerics, - analytic_kinematics=analytic_kinematics) - GalkinObservation.__init__(self, kwargs_aperture=kwargs_aperture, kwargs_psf=kwargs_psf) - -
[docs] def dispersion(self, kwargs_mass, kwargs_light, kwargs_anisotropy, sampling_number=1000): - """ - computes the averaged LOS velocity dispersion in the slit (convolved) - - :param kwargs_mass: mass model parameters (following lenstronomy lens model conventions) - :param kwargs_light: deflector light parameters (following lenstronomy light model conventions) - :param kwargs_anisotropy: anisotropy parameters, may vary according to anisotropy type chosen. - We refer to the Anisotropy() class for details on the parameters. - :param sampling_number: int, number of spectral sampling of the light distribution - :return: integrated LOS velocity dispersion in units [km/s] - """ - sigma2_IR_sum = 0 - IR_sum = 0 - for i in range(0, sampling_number): - sigma2_IR, IR = self._draw_one_sigma2(kwargs_mass, kwargs_light, kwargs_anisotropy) - sigma2_IR_sum += sigma2_IR - IR_sum += IR - sigma_s2_average = sigma2_IR_sum / IR_sum - # apply unit conversion from arc seconds and deflections to physical velocity dispersion in (km/s) - self.numerics.delete_cache() - return np.sqrt(sigma_s2_average) / 1000. # in units of km/s
- -
[docs] def dispersion_map(self, kwargs_mass, kwargs_light, kwargs_anisotropy, num_kin_sampling=1000, num_psf_sampling=100): - """ - computes the velocity dispersion in each Integral Field Unit - - :param kwargs_mass: keyword arguments of the mass model - :param kwargs_light: keyword argument of the light model - :param kwargs_anisotropy: anisotropy keyword arguments - :param num_kin_sampling: int, number of draws from a kinematic prediction of a LOS - :param num_psf_sampling: int, number of displacements/render from a spectra to be displaced on the IFU - :return: ordered array of velocity dispersions [km/s] for each unit - """ - # draw from light profile (3d and 2d option) - # compute kinematics of it (analytic or numerical) - # displace it n-times - # add it and keep track of how many draws are added on each segment - # compute average in each segment - # return value per segment - num_segments = self.num_segments - sigma2_IR_sum = np.zeros(num_segments) - count_draws = np.zeros(num_segments) - - for i in range(0, num_kin_sampling): - r, R, x, y = self.numerics.draw_light(kwargs_light) - sigma2_IR, IR = self.numerics.sigma_s2(r, R, kwargs_mass, kwargs_light, kwargs_anisotropy) - for k in range(0, num_psf_sampling): - x_, y_ = self.displace_psf(x, y) - bool_ap, ifu_index = self.aperture_select(x_, y_) - if bool_ap is True: - sigma2_IR_sum[ifu_index] += sigma2_IR - count_draws[ifu_index] += IR - - sigma_s2_average = sigma2_IR_sum / count_draws - # apply unit conversion from arc seconds and deflections to physical velocity dispersion in (km/s) - self.numerics.delete_cache() - return np.sqrt(sigma_s2_average) / 1000. # in units of km/s
- - def _draw_one_sigma2(self, kwargs_mass, kwargs_light, kwargs_anisotropy): - """ - - :param kwargs_mass: mass model parameters (following lenstronomy lens model conventions) - :param kwargs_light: deflector light parameters (following lenstronomy light model conventions) - :param kwargs_anisotropy: anisotropy parameters, may vary according to anisotropy type chosen. - We refer to the Anisotropy() class for details on the parameters. - :return: integrated LOS velocity dispersion in angular units for a single draw of the light distribution that - falls in the aperture after displacing with the seeing - """ - while True: - r, R, x, y = self.numerics.draw_light(kwargs_light) - x_, y_ = self.displace_psf(x, y) - bool_ap, _ = self.aperture_select(x_, y_) - if bool_ap is True: - break - sigma2_IR, IR = self.numerics.sigma_s2(r, R, kwargs_mass, kwargs_light, kwargs_anisotropy) - return sigma2_IR, IR
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/GalKin/galkin_model.html b/docs/_build/html/_modules/lenstronomy/GalKin/galkin_model.html deleted file mode 100644 index a1cc8f250..000000000 --- a/docs/_build/html/_modules/lenstronomy/GalKin/galkin_model.html +++ /dev/null @@ -1,170 +0,0 @@ - - - - - - - - lenstronomy.GalKin.galkin_model — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.GalKin.galkin_model

-from lenstronomy.GalKin.numeric_kinematics import NumericKinematics
-from lenstronomy.GalKin.analytic_kinematics import AnalyticKinematics
-
-__all__ = ['GalkinModel']
-
-
-
[docs]class GalkinModel(object): - """ - this class handles all the kinematic modeling aspects of Galkin - Excluded are observational conditions (seeing, aperture etc) - Major class to compute velocity dispersion measurements given light and mass models - - The class supports any mass and light distribution (and superposition thereof) that has a 3d correspondance in their - 2d lens model distribution. For models that do not have this correspondence, you may want to apply a - Multi-Gaussian Expansion (MGE) on their models and use the MGE to be de-projected to 3d. - - The computation follows Mamon&Lokas 2005. - - The class supports various types of anisotropy models (see Anisotropy class). - Solving the Jeans Equation requires a numerical integral over the 3d light and mass profile (see Mamon&Lokas 2005). - This class (as well as the dedicated LightModel and MassModel classes) perform those integral numerically with an - interpolated grid. - - The cosmology assumed to compute the physical mass and distances are set via the kwargs_cosmo keyword arguments. - d_d: Angular diameter distance to the deflector (in Mpc) - d_s: Angular diameter distance to the source (in Mpc) - d_ds: Angular diameter distance from the deflector to the source (in Mpc) - - The numerical options can be chosen through the kwargs_numerics keywords - - interpol_grid_num: number of interpolation points in the light and mass profile (radially). This number should - be chosen high enough to accurately describe the true light profile underneath. - log_integration: bool, if True, performs the interpolation and numerical integration in log-scale. - - max_integrate: maximum 3d radius to where the numerical integration of the Jeans Equation solver is made. - This value should be large enough to contain most of the light and to lead to a converged result. - min_integrate: minimal integration value. This value should be very close to zero but some mass and light - profiles are diverging and a numerically stable value should be chosen. - - These numerical options should be chosen to allow for a converged result (within your tolerance) but not too - conservative to impact too much the computational cost. Reasonable values might depend on the specific problem. - - """ - def __init__(self, kwargs_model, kwargs_cosmo, kwargs_numerics=None, analytic_kinematics=False): - """ - - :param kwargs_model: keyword arguments describing the model components - :param kwargs_cosmo: keyword arguments that define the cosmology in terms of the angular diameter distances - involved - :param kwargs_numerics: numerics keyword arguments - :param analytic_kinematics: bool, if True uses the analytic kinematic model - """ - if kwargs_numerics is None: - kwargs_numerics = {'interpol_grid_num': 200, # numerical interpolation, should converge -> infinity - 'log_integration': True, - # log or linear interpolation of surface brightness and mass models - 'max_integrate': 100, - 'min_integrate': 0.001} # lower/upper bound of numerical integrals - if analytic_kinematics is True: - anisotropy_model = kwargs_model.get('anisotropy_model') - if not anisotropy_model == 'OM': - raise ValueError('analytic kinematics only available for OsipkovMerritt ("OM") anisotropy model.') - self.numerics = AnalyticKinematics(kwargs_cosmo=kwargs_cosmo, **kwargs_numerics) - else: - self.numerics = NumericKinematics(kwargs_model=kwargs_model, kwargs_cosmo=kwargs_cosmo, **kwargs_numerics) - self._analytic_kinematics = analytic_kinematics - -
[docs] def check_df(self, r, kwargs_mass, kwargs_light, kwargs_anisotropy): - """ - checks whether the phase space distribution function of a given anisotropy model is positive. - Currently this is implemented by the relation provided by Ciotti and Morganti 2010 equation (10) - https://arxiv.org/pdf/1006.2344.pdf - - :param r: 3d radius to check slope-anisotropy constraint - :param kwargs_mass: keyword arguments for mass (lens) profile - :param kwargs_light: keyword arguments for light profile - :param kwargs_anisotropy: keyword arguments for stellar anisotropy distribution - :return: equation (10) >= 0 for physical interpretation - """ - dr = 0.01 # finite differential in radial direction - r_dr = r + dr - - sigmar2 = self.numerics.sigma_r2(r, kwargs_mass, kwargs_light, kwargs_anisotropy) - sigmar2_dr = self.numerics.sigma_r2(r_dr, kwargs_mass, kwargs_light, kwargs_anisotropy) - grav_pot = self.numerics.grav_potential(r, kwargs_mass) - grav_pot_dr = self.numerics.grav_potential(r_dr, kwargs_mass) - self.numerics.delete_cache() - return r * (sigmar2_dr - sigmar2 - grav_pot + grav_pot_dr) / dr
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/GalKin/light_profile.html b/docs/_build/html/_modules/lenstronomy/GalKin/light_profile.html deleted file mode 100644 index 97abfd722..000000000 --- a/docs/_build/html/_modules/lenstronomy/GalKin/light_profile.html +++ /dev/null @@ -1,333 +0,0 @@ - - - - - - - - lenstronomy.GalKin.light_profile — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.GalKin.light_profile

-import numpy as np
-import copy
-from scipy.interpolate import interp1d
-from lenstronomy.LightModel.light_model import LightModel
-
-__all__ = ['LightProfile']
-
-
-
[docs]class LightProfile(object): - """ - class to deal with the light distribution for GalKin - - In particular, this class allows for: - - (faster) interpolated calculation for a given profile (for a range that the Jeans equation is computed) - - drawing 3d and 2d distributions from a given (spherical) profile - (within bounds where the Jeans equation is expected to be accurate) - - 2d projected profiles within the 3d integration range (truncated) - - """ - def __init__(self, profile_list, interpol_grid_num=2000, max_interpolate=1000, min_interpolate=0.001, - max_draw=None): - """ - - :param profile_list: list of light profiles for LightModel module (must support light_3d() functionalities) - :param interpol_grid_num: int; number of interpolation steps (logarithmically between min and max value) - :param max_interpolate: float; maximum interpolation of 3d light profile - :param min_interpolate: float; minimum interpolate (and also drawing of light profile) - :param max_draw: float; (optional) if set, draws up to this radius, else uses max_interpolate value - """ - - self.light_model = LightModel(light_model_list=profile_list) - self._interp_grid_num = interpol_grid_num - self._max_interpolate = max_interpolate - self._min_interpolate = min_interpolate - if max_draw is None: - max_draw = max_interpolate - self._max_draw = max_draw - -
[docs] def light_3d(self, r, kwargs_list): - """ - three-dimensional light profile - - :param r: 3d radius - :param kwargs_list: list of keyword arguments of light profiles (see LightModule) - :return: flux per 3d volume at radius r - """ - light_3d = self.light_model.light_3d(r, kwargs_list) - return light_3d
- -
[docs] def light_3d_interp(self, r, kwargs_list, new_compute=False): - """ - interpolated three-dimensional light profile within bounds [min_interpolate, max_interpolate] - in logarithmic units with interpol_grid_num numbers of interpolation steps - - :param r: 3d radius - :param kwargs_list: list of keyword arguments of light profiles (see LightModule) - :param new_compute: boolean, if True, re-computes the interpolation - (becomes valid with updated kwargs_list argument) - :return: flux per 3d volume at radius r - """ - if not hasattr(self, '_f_light_3d') or new_compute is True: - r_array = np.logspace(np.log10(self._min_interpolate), np.log10(self._max_interpolate), self._interp_grid_num) - light_3d_array = self.light_model.light_3d(r_array, kwargs_list) - light_3d_array[light_3d_array < 10 ** (-1000)] = 10 ** (-1000) - f = interp1d(np.log(r_array), np.log(light_3d_array), fill_value=(np.log(light_3d_array[0]), -1000), - bounds_error=False) # "extrapolate" - self._f_light_3d = f - return np.exp(self._f_light_3d(np.log(r)))
- -
[docs] def light_2d(self, R, kwargs_list): - """ - projected light profile (integrated to infinity in the projected axis) - - :param R: projected 2d radius - :param kwargs_list: list of keyword arguments of light profiles (see LightModule) - :return: projected surface brightness - """ - kwargs_light_circularized = self._circularize_kwargs(kwargs_list) - return self.light_model.surface_brightness(R, 0, kwargs_light_circularized)
- - def _circularize_kwargs(self, kwargs_list): - """ - - :param kwargs_list: list of keyword arguments of light profiles (see LightModule) - :return: circularized arguments - """ - # TODO make sure averaging is done azimuthally - if not hasattr(self, '_kwargs_light_circularized'): - kwargs_list_copy = copy.deepcopy(kwargs_list) - kwargs_list_new = [] - for kwargs in kwargs_list_copy: - if 'e1' in kwargs: - kwargs['e1'] = 0 - if 'e2' in kwargs: - kwargs['e2'] = 0 - kwargs_list_new.append({k: v for k, v in kwargs.items() if k not in ['center_x', 'center_y']}) - self._kwargs_light_circularized = kwargs_list_new - return self._kwargs_light_circularized - - def _light_2d_finite_single(self, R, kwargs_list): - """ - projected light profile (integrated to FINITE 3d boundaries from the max_interpolate) - for a single float number of R - - :param R: projected 2d radius (between min_interpolate and max_interpolate) - :param kwargs_list: list of keyword arguments of light profiles (see LightModule) - :return: projected surface brightness - """ - - # here we perform a logarithmic integral - stop = np.log10(np.maximum(np.sqrt(self._max_interpolate**2 - R**2), self._min_interpolate + 0.00001)) - x = np.logspace(start=np.log10(self._min_interpolate), stop=stop, num=self._interp_grid_num) - r_array = np.sqrt(x**2 + R**2) - flux_r = self.light_3d(r_array, kwargs_list) - dlog_r = (np.log10(x[2]) - np.log10(x[1])) * np.log(10) - flux_r *= dlog_r * x - - # linear integral - # x = np.linspace(start=self._min_interpolate, stop=np.sqrt(self._max_interpolate ** 2 - R ** 2), - # num=self._interp_grid_num) - # r_array = np.sqrt(x ** 2 + R ** 2) - # dr = x[1] - x[0] - # flux_r = self.light_3d(r_array + dr / 2, kwargs_circ) - # dr = x[1] - x[0] - # flux_r *= dr - - flux_R = np.sum(flux_r) - # perform finite integral - - # out = integrate.quad(lambda x: self.light_3d(np.sqrt(R ** 2 + x ** 2), kwargs_circ), self._min_interpolate, - # np.sqrt(self._max_interpolate**2 - R**2)) - # print(out_1, out, 'test') - # flux_R = out[0] - return flux_R * 2 # integral in both directions - -
[docs] def light_2d_finite(self, R, kwargs_list): - """ - projected light profile (integrated to FINITE 3d boundaries from the max_interpolate) - - :param R: projected 2d radius (between min_interpolate and max_interpolate - :param kwargs_list: list of keyword arguments of light profiles (see LightModule) - :return: projected surface brightness - """ - - kwargs_circ = self._circularize_kwargs(kwargs_list) - n = len(np.atleast_1d(R)) - if n <= 1: - return self._light_2d_finite_single(R, kwargs_circ) - else: - light_2d = np.zeros(n) - for i, R_i in enumerate(R): - light_2d[i] = self._light_2d_finite_single(R_i, kwargs_circ) - return light_2d
- -
[docs] def draw_light_2d_linear(self, kwargs_list, n=1, new_compute=False): - """ - constructs the CDF and draws from it random realizations of projected radii R - The interpolation of the CDF is done in linear projected radius space - - :param kwargs_list: list of keyword arguments of light profiles (see LightModule) - :param n: int; number of draws - :param new_compute: boolean, if True, re-computes the interpolation - (becomes valid with updated kwargs_list argument) - :return: draw of projected radius for the given light profile distribution - """ - if not hasattr(self, '_light_cdf') or new_compute is True: - r_array = np.linspace(self._min_interpolate, self._max_draw, self._interp_grid_num) - cum_sum = np.zeros_like(r_array) - sum_light = 0 - for i, r in enumerate(r_array): - if i == 0: - cum_sum[i] = 0 - else: - sum_light += self.light_2d(r, kwargs_list) * r - cum_sum[i] = copy.deepcopy(sum_light) - cum_sum_norm = cum_sum/cum_sum[-1] - f = interp1d(cum_sum_norm, r_array) - self._light_cdf = f - cdf_draw = np.random.uniform(0., 1, n) - r_draw = self._light_cdf(cdf_draw) - return r_draw
- -
[docs] def draw_light_2d(self, kwargs_list, n=1, new_compute=False): - """ - constructs the CDF and draws from it random realizations of projected radii R - CDF is constructed in logarithmic projected radius spacing - - :param kwargs_list: light model keyword argument list - :param n: int, number of draws per functino call - :param new_compute: re-computes the interpolated CDF - :return: realization of projected radius following the distribution of the light model - """ - if not hasattr(self, '_light_cdf_log') or new_compute is True: - r_array = np.logspace(np.log10(self._min_interpolate), np.log10(self._max_draw), self._interp_grid_num) - cum_sum = np.zeros_like(r_array) - sum_light = 0 - for i, r in enumerate(r_array): - if i == 0: - cum_sum[i] = 0 - else: - sum_light += self.light_2d(r, kwargs_list) * r * r - cum_sum[i] = copy.deepcopy(sum_light) - cum_sum_norm = cum_sum/cum_sum[-1] - f = interp1d(cum_sum_norm, np.log(r_array)) - self._light_cdf_log = f - cdf_draw = np.random.uniform(0., 1, n) - r_log_draw = self._light_cdf_log(cdf_draw) - return np.exp(r_log_draw)
- -
[docs] def draw_light_3d(self, kwargs_list, n=1, new_compute=False): - """ - constructs the CDF and draws from it random realizations of 3D radii r - - :param kwargs_list: light model keyword argument list - :param n: int, number of draws per function call - :param new_compute: re-computes the interpolated CDF - :return: realization of projected radius following the distribution of the light model - """ - if not hasattr(self, '_light_3d_cdf_log') or new_compute is True: - r_array = np.logspace(np.log10(self._min_interpolate), np.log10(self._max_draw), self._interp_grid_num) - dlog_r = np.log10(r_array[1]) - np.log10(r_array[0]) - r_array_int = np.logspace(np.log10(self._min_interpolate) + dlog_r / 2, np.log10(self._max_draw) + dlog_r / 2, self._interp_grid_num) - cum_sum = np.zeros_like(r_array) - sum_light = 0 - for i, r in enumerate(r_array_int[:-1]): - # if i == 0: - # cum_sum[i] = 0 - # else: - sum_light += self.light_3d(r, kwargs_list) * r**2 * (r_array[i+1] - r_array[i]) # * r - cum_sum[i+1] = copy.deepcopy(sum_light) - cum_sum_norm = cum_sum/cum_sum[-1] - f = interp1d(cum_sum_norm, np.log(r_array)) - self._light_3d_cdf_log = f - cdf_draw = np.random.uniform(0., 1, n) - r_log_draw = self._light_3d_cdf_log(cdf_draw) - return np.exp(r_log_draw)
- -
[docs] def delete_cache(self): - """ - deletes cached interpolation function of the CDF for a specific light profile - - :return: None - """ - if hasattr(self, '_light_cdf_log'): - del self._light_cdf_log - if hasattr(self, '_light_cdf'): - del self._light_cdf - if hasattr(self, '_f_light_3d'): - del self._f_light_3d - if hasattr(self, '_kwargs_light_circularized'): - del self._kwargs_light_circularized
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/GalKin/numeric_kinematics.html b/docs/_build/html/_modules/lenstronomy/GalKin/numeric_kinematics.html deleted file mode 100644 index 70fe913fe..000000000 --- a/docs/_build/html/_modules/lenstronomy/GalKin/numeric_kinematics.html +++ /dev/null @@ -1,414 +0,0 @@ - - - - - - - - lenstronomy.GalKin.numeric_kinematics — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.GalKin.numeric_kinematics

-import numpy as np
-from scipy.interpolate import interp1d
-
-import lenstronomy.Util.constants as const
-from lenstronomy.GalKin.light_profile import LightProfile
-from lenstronomy.GalKin.anisotropy import Anisotropy
-from lenstronomy.GalKin.cosmo import Cosmo
-from lenstronomy.LensModel.single_plane import SinglePlane
-import lenstronomy.GalKin.velocity_util as util
-
-__all__ = ['NumericKinematics']
-
-
-
[docs]class NumericKinematics(Anisotropy): - - def __init__(self, kwargs_model, kwargs_cosmo, interpol_grid_num=1000, log_integration=True, max_integrate=1000, - min_integrate=0.0001, max_light_draw=None, lum_weight_int_method=True): - """ - What we need: - - max projected R to have ACCURATE I_R_sigma values - - make sure everything outside cancels out (or is not rendered) - - :param interpol_grid_num: number of interpolation bins for integrand and interpolated functions - :param log_integration: bool, if True, performs the numerical integral in log space distance (adviced) - (only applies for lum_weight_int_method=True) - :param max_integrate: maximum radius (in arc seconds) of the Jeans equation integral - (assumes zero tracer particles outside this radius) - :param max_light_draw: float; (optional) if set, draws up to this radius, else uses max_interpolate value - :param lum_weight_int_method: bool, luminosity weighted dispersion integral to calculate LOS projected Jean's - solution. ATTENTION: currently less accurate than 3d solution - :param min_integrate: - """ - mass_profile_list = kwargs_model.get('mass_profile_list') - light_profile_list = kwargs_model.get('light_profile_list') - anisotropy_model = kwargs_model.get('anisotropy_model') - self._interp_grid_num = interpol_grid_num - self._log_int = log_integration - self._max_integrate = max_integrate # maximal integration (and interpolation) in units of arcsecs - self._min_integrate = min_integrate # min integration (and interpolation) in units of arcsecs - self._max_interpolate = max_integrate # we chose to set the interpolation range to the integration range - self._min_interpolate = min_integrate # we chose to set the interpolation range to the integration range - if max_light_draw is None: - max_light_draw = max_integrate # make sure the actual solution for the kinematics is only computed way inside the integral - self.lightProfile = LightProfile(light_profile_list, interpol_grid_num=interpol_grid_num, - max_interpolate=max_integrate, min_interpolate=min_integrate, - max_draw=max_light_draw) - Anisotropy.__init__(self, anisotropy_type=anisotropy_model) - self.cosmo = Cosmo(**kwargs_cosmo) - self._mass_profile = SinglePlane(mass_profile_list) - self._lum_weight_int_method = lum_weight_int_method - -
[docs] def sigma_s2(self, r, R, kwargs_mass, kwargs_light, kwargs_anisotropy): - """ - returns unweighted los velocity dispersion for a specified 3d and projected radius - (if lum_weight_int_method=True then the 3d radius is not required and the function directly performs the - luminosity weighted integral in projection at R) - - :param r: 3d radius (not needed for this calculation) - :param R: 2d projected radius (in angular units of arcsec) - :param kwargs_mass: mass model parameters (following lenstronomy lens model conventions) - :param kwargs_light: deflector light parameters (following lenstronomy light model conventions) - :param kwargs_anisotropy: anisotropy parameters, may vary according to anisotropy type chosen. - We refer to the Anisotropy() class for details on the parameters. - :return: weighted line-of-sight projected velocity dispersion at projected radius R with weights I - """ - if self._lum_weight_int_method is True: - return self.sigma_s2_project(R, kwargs_mass, kwargs_light, kwargs_anisotropy) - else: - return self.sigma_s2_r(r, R, kwargs_mass, kwargs_light, kwargs_anisotropy), 1
- -
[docs] def sigma_s2_project(self, R, kwargs_mass, kwargs_light, kwargs_anisotropy): - """ - returns luminosity-weighted los velocity dispersion for a specified projected radius R and weight - - :param R: 2d projected radius (in angular units of arcsec) - :param kwargs_mass: mass model parameters (following lenstronomy lens model conventions) - :param kwargs_light: deflector light parameters (following lenstronomy light model conventions) - :param kwargs_anisotropy: anisotropy parameters, may vary according to anisotropy type chosen. - We refer to the Anisotropy() class for details on the parameters. - :return: line-of-sight projected velocity dispersion at projected radius R - """ - # nominator is numerically to a finite distance, so luminosity weighting might be off - # this could lead to an under-prediction of the velocity dispersion - # so we ask the function _I_R_sigma2() to also return the numerical l(r) - # I_R_sigma2, I_R = self._I_R_sigma2_interp(R, kwargs_mass, kwargs_light, kwargs_anisotropy) - I_R_sigma2, I_R = self._I_R_sigma2_interp(R, kwargs_mass, kwargs_light, kwargs_anisotropy) - # I_R = self.lightProfile.light_2d(R, kwargs_light) - return I_R_sigma2 / I_R, 1
- -
[docs] def sigma_s2_r(self, r, R, kwargs_mass, kwargs_light, kwargs_anisotropy): - """ - returns unweighted los velocity dispersion for a specified 3d radius r at projected radius R - - :param r: 3d radius (not needed for this calculation) - :param R: 2d projected radius (in angular units of arcsec) - :param kwargs_mass: mass model parameters (following lenstronomy lens model conventions) - :param kwargs_light: deflector light parameters (following lenstronomy light model conventions) - :param kwargs_anisotropy: anisotropy parameters, may vary according to anisotropy type chosen. - We refer to the Anisotropy() class for details on the parameters. - :return: line-of-sight projected velocity dispersion at projected radius R from 3d radius r - """ - beta = self.beta_r(r, **kwargs_anisotropy) - return (1 - beta * R ** 2 / r ** 2) * self.sigma_r2(r, kwargs_mass, kwargs_light, kwargs_anisotropy)
- -
[docs] def sigma_r2(self, r, kwargs_mass, kwargs_light, kwargs_anisotropy): - """ - computes numerically the solution of the Jeans equation for a specific 3d radius - E.g. Equation (A1) of Mamon & Lokas https://arxiv.org/pdf/astro-ph/0405491.pdf - - .. math:: - l(r) \\sigma_r(r) ^ 2 = 1/f(r) \\int_r^{\\infty} f(s) l(s) G M(s) / s^2 ds - - where l(r) is the 3d light profile - M(s) is the enclosed 3d mass - f is the solution to - d ln(f)/ d ln(r) = 2 beta(r) - - :param r: 3d radius - :param kwargs_mass: mass model parameters (following lenstronomy lens model conventions) - :param kwargs_light: deflector light parameters (following lenstronomy light model conventions) - :param kwargs_anisotropy: anisotropy parameters, may vary according to anisotropy type chosen. - We refer to the Anisotropy() class for details on the parameters. - :return: sigma_r**2 - """ - # l_r = self.lightProfile.light_3d_interp(r, kwargs_light) - l_r = self.lightProfile.light_3d(r, kwargs_light) - f_r = self.anisotropy_solution(r, **kwargs_anisotropy) - return 1 / f_r / l_r * self._jeans_solution_integral(r, kwargs_mass, kwargs_light, kwargs_anisotropy) * const.G / (const.arcsec * self.cosmo.dd * const.Mpc)
- -
[docs] def mass_3d(self, r, kwargs): - """ - mass enclosed a 3d radius - - :param r: in arc seconds - :param kwargs: lens model parameters in arc seconds - :return: mass enclosed physical radius in kg - """ - mass_dimless = self._mass_profile.mass_3d(r, kwargs) - mass_dim = mass_dimless * const.arcsec ** 2 * self.cosmo.dd * self.cosmo.ds / self.cosmo.dds * const.Mpc * \ - const.c ** 2 / (4 * np.pi * const.G) - return mass_dim
- -
[docs] def grav_potential(self, r, kwargs_mass): - """ - Gravitational potential in SI units - - :param r: radius (arc seconds) - :param kwargs_mass: - :return: gravitational potential - """ - mass_dim = self.mass_3d(r, kwargs_mass) - grav_pot = -const.G * mass_dim / (r * const.arcsec * self.cosmo.dd * const.Mpc) - return grav_pot
- -
[docs] def draw_light(self, kwargs_light): - """ - - :param kwargs_light: keyword argument (list) of the light model - :return: 3d radius (if possible), 2d projected radius, x-projected coordinate, y-projected coordinate - """ - r = self.lightProfile.draw_light_3d(kwargs_light, n=1)[0] - R, x, y = util.project2d_random(r) - return r, R, x, y
- -
[docs] def delete_cache(self): - """ - delete interpolation function for a specific mass and light profile as well as for a specific anisotropy model - - :return: - """ - if hasattr(self, '_log_mass_3d'): - del self._log_mass_3d - if hasattr(self, '_interp_jeans_integral'): - del self._interp_jeans_integral - if hasattr(self, '_interp_I_R_sigma2'): - del self._interp_I_R_sigma2 - self.lightProfile.delete_cache() - self.delete_anisotropy_cache()
- - def _I_R_sigma2(self, R, kwargs_mass, kwargs_light, kwargs_anisotropy): - """ - equation A15 in Mamon&Lokas 2005 as a logarithmic numerical integral (if option is chosen) - - :param R: 2d projected radius (in angular units) - :param kwargs_mass: mass model parameters (following lenstronomy lens model conventions) - :param kwargs_light: deflector light parameters (following lenstronomy light model conventions) - :param kwargs_anisotropy: anisotropy parameters, may vary according to anisotropy type chosen. - We refer to the Anisotropy() class for details on the parameters. - :return: integral of A15 in Mamon&Lokas 2005 - """ - R = max(R, self._min_integrate) - max_integrate = self._max_integrate # make sure the integration of the Jeans equation is performed further out than the interpolation - # if False: - # # linear integral near R - # lin_max = min(2 * R_, self._max_interpolate) - # lin_max = min(lin_max, R_+1) - # r_array = np.linspace(start=R, stop=lin_max, num=int(self._interp_grid_num / 2)) - # dr = r_array[2] - r_array[1] - # IR_sigma2_ = self._integrand_A15(r_array[1:] - dr/2, R, kwargs_mass, kwargs_light, kwargs_anisotropy) - # IR_sigma2_dr_lin = IR_sigma2_ * dr - # # logarithmic integral for larger extent - # max_log = np.log10(max_integrate) - # r_array = np.logspace(np.log10(lin_max), max_log, int(self._interp_grid_num / 2)) - # dlog_r = (np.log10(r_array[2]) - np.log10(r_array[1])) * np.log(10) - # IR_sigma2_ = self._integrand_A15(r_array, R_, kwargs_mass, kwargs_light, kwargs_anisotropy) - # IR_sigma2_dr_log = IR_sigma2_ * dlog_r * r_array - # IR_sigma2_dr = np.append(IR_sigma2_dr_lin, IR_sigma2_dr_log) - if self._log_int is True: - min_log = np.log10(R) - max_log = np.log10(max_integrate) - dlogr = (max_log - min_log) / (self._interp_grid_num - 1) - r_array = np.logspace(min_log + dlogr / 2., max_log + dlogr / 2., self._interp_grid_num) - dlog_r = (np.log10(r_array[2]) - np.log10(r_array[1])) * np.log(10) - IR_sigma2_ = self._integrand_A15(r_array, R, kwargs_mass, kwargs_light, kwargs_anisotropy) - IR_sigma2_dr = IR_sigma2_ * dlog_r * r_array - else: - r_array = np.linspace(start=R, stop=self._max_interpolate, num=self._interp_grid_num) - dr = r_array[2] - r_array[1] - IR_sigma2_ = self._integrand_A15(r_array + dr / 2., R, kwargs_mass, kwargs_light, kwargs_anisotropy) - IR_sigma2_dr = IR_sigma2_ * dr - - IR_sigma2 = np.sum(IR_sigma2_dr) # integral from angle to physical scales - IR = self.lightProfile.light_2d_finite(R, kwargs_light) - return IR_sigma2 * 2 * const.G / (const.arcsec * self.cosmo.dd * const.Mpc), IR - - def _I_R_sigma2_interp(self, R, kwargs_mass, kwargs_light, kwargs_anisotropy): - """ - equation A15 in Mamon&Lokas 2005 as interpolation in log space - - :param R: projected radius - :param kwargs_mass: mass profile keyword arguments - :param kwargs_light: light model keyword arguments - :param kwargs_anisotropy: stellar anisotropy keyword arguments - :return: - """ - R = np.maximum(R, self._min_integrate) - if not hasattr(self, '_interp_I_R_sigma2'): - min_log = np.log10(self._min_integrate) - max_log = np.log10(self._max_integrate) - R_array = np.logspace(min_log, max_log, self._interp_grid_num) # self._interp_grid_num - I_R_sigma2_array = [] - I_R_array = [] - for R_i in R_array: - I_R_sigma2_, IR_ = self._I_R_sigma2(R_i, kwargs_mass, kwargs_light, kwargs_anisotropy) - I_R_sigma2_array.append(I_R_sigma2_) - I_R_array.append(IR_) - self._interp_I_R_sigma2 = interp1d(np.log(R_array), np.array(I_R_sigma2_array), fill_value="extrapolate") - self._interp_I_R = interp1d(np.log(R_array), np.array(I_R_array), fill_value="extrapolate") - return self._interp_I_R_sigma2(np.log(R)), self._interp_I_R(np.log(R)) - - def _integrand_A15(self, r, R, kwargs_mass, kwargs_light, kwargs_anisotropy): - """ - integrand of A15 (in log space) in Mamon&Lokas 2005 - - :param r: 3d radius in arc seconds - :param R: 2d projected radius - :param kwargs_mass: mass model parameters (following lenstronomy lens model conventions) - :param kwargs_light: deflector light parameters (following lenstronomy light model conventions) - :param kwargs_anisotropy: anisotropy parameters, may vary according to anisotropy type chosen. - We refer to the Anisotropy() class for details on the parameters. - :return: integrand - """ - k_r = self.K(r, R, **kwargs_anisotropy) - # l_r = self.lightProfile.light_3d_interp(r, kwargs_light) - # m_r = self._mass_3d_interp(r, kwargs_mass) - l_r = self.lightProfile.light_3d(r, kwargs_light) - m_r = self.mass_3d(r, kwargs_mass) - out = k_r * l_r * m_r / r - return out - - def _jeans_solution_integral(self, r, kwargs_mass, kwargs_light, kwargs_anisotropy): - """ - interpolated solution of the integral - - .. math:: - \\int_r^{\\infty} f(s) l(s) G M(s) / s^2 ds - - :param r: 3d radius - :param kwargs_mass: mass profile keyword arguments - :param kwargs_light: light profile keyword arguments - :param kwargs_anisotropy: anisotropy keyword arguments - :return: interpolated solution of the Jeans integral - (copped values at large radius as they become numerically inaccurate) - """ - if not hasattr(self, '_interp_jeans_integral'): - min_log = np.log10(self._min_integrate) - max_log = np.log10(self._max_integrate) # we extend the integral but ignore these outer solutions in the interpolation - r_array = np.logspace(min_log, max_log, self._interp_grid_num) - dlog_r = (np.log10(r_array[2]) - np.log10(r_array[1])) * np.log(10) - integrand_jeans = self._integrand_jeans_solution(r_array, kwargs_mass, kwargs_light, kwargs_anisotropy) * dlog_r * r_array - # flip array from inf to finite - integral_jeans_r = np.cumsum(np.flip(integrand_jeans)) - # flip array back - integral_jeans_r = np.flip(integral_jeans_r) - # call 1d interpolation function - self._interp_jeans_integral = interp1d(np.log(r_array[r_array <= self._max_integrate]), - integral_jeans_r[r_array <= self._max_integrate], - fill_value="extrapolate") - return self._interp_jeans_integral(np.log(r)) - - def _integrand_jeans_solution(self, r, kwargs_mass, kwargs_light, kwargs_anisotropy): - """ - integrand of A1 (in log space) in Mamon&Lokas 2005 to calculate the Jeans equation numerically - f(s) l(s) M(s) / s^2 - - :param r: 3d radius - :param kwargs_mass: mass model keyword arguments - :param kwargs_light: light model keyword arguments - :param kwargs_anisotropy: anisotropy model keyword argument - :return: integrand value - """ - f_r = self.anisotropy_solution(r, **kwargs_anisotropy) - l_r = self.lightProfile.light_3d(r, kwargs_light) - m_r = self._mass_3d_interp(r, kwargs_mass) - out = f_r * l_r * m_r / r**2 - return out - - def _mass_3d_interp(self, r, kwargs, new_compute=False): - """ - - :param r: in arc seconds - :param kwargs: lens model parameters in arc seconds - :param new_compute: bool, if True, recomputes the interpolation - :return: mass enclosed physical radius in kg - """ - if not hasattr(self, '_log_mass_3d') or new_compute is True: - r_array = np.logspace(np.log10(self._min_interpolate), np.log10(self._max_interpolate), self._interp_grid_num) - mass_3d_array = self.mass_3d(r_array, kwargs) - mass_3d_array[mass_3d_array < 10. ** (-100)] = 10. ** (-100) - self._log_mass_3d = interp1d(np.log(r_array), np.log(mass_3d_array/r_array), - fill_value=(np.log(mass_3d_array[0] / r_array[0]), -1000), bounds_error=False) - return np.exp(self._log_mass_3d(np.log(r))) * np.minimum(r, self._max_interpolate)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/GalKin/observation.html b/docs/_build/html/_modules/lenstronomy/GalKin/observation.html deleted file mode 100644 index 8a8219f06..000000000 --- a/docs/_build/html/_modules/lenstronomy/GalKin/observation.html +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - lenstronomy.GalKin.observation — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.GalKin.observation

-from lenstronomy.GalKin.aperture import Aperture
-from lenstronomy.GalKin.psf import PSF
-
-__all__ = ['GalkinObservation']
-
-
-
[docs]class GalkinObservation(PSF, Aperture): - """ - this class sets the base for the observational properties (aperture and seeing condition) - """ - def __init__(self, kwargs_aperture, kwargs_psf): - Aperture.__init__(self, **kwargs_aperture) - PSF.__init__(self, **kwargs_psf)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/GalKin/psf.html b/docs/_build/html/_modules/lenstronomy/GalKin/psf.html deleted file mode 100644 index ee70a8b3d..000000000 --- a/docs/_build/html/_modules/lenstronomy/GalKin/psf.html +++ /dev/null @@ -1,161 +0,0 @@ - - - - - - - - lenstronomy.GalKin.psf — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.GalKin.psf

-from lenstronomy.GalKin import velocity_util as util
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -class PSF(object): - """ - general class to handle the PSF in the GalKin module for rendering the displacement of photons/spectro - """ - def __init__(self, psf_type, **kwargs_psf): - """ - - :param psf_type: string, point spread function type, current support for 'GAUSSIAN' and 'MOFFAT' - :param kwargs_psf: keyword argument describing the relevant parameters of the PSF. - """ - if psf_type == 'GAUSSIAN': - self._psf = PSFGaussian(**kwargs_psf) - elif psf_type == 'MOFFAT': - self._psf = PSFMoffat(**kwargs_psf) - else: - raise ValueError('psf_type %s not supported for convolution!' % psf_type) - -
[docs] def displace_psf(self, x, y): - """ - - :param x: x-coordinate of light ray - :param y: y-coordinate of light ray - :return: x', y' displaced by the two dimensional PSF distribution function - """ - return self._psf.displace_psf(x, y)
- - -
[docs]@export -class PSFGaussian(object): - """ - Gaussian PSF - """ - def __init__(self, fwhm): - """ - - :param fwhm: full width at half maximum seeing condition - """ - self._fwhm = fwhm - -
[docs] def displace_psf(self, x, y): - """ - - :param x: x-coordinate of light ray - :param y: y-coordinate of light ray - :return: x', y' displaced by the two dimensional PSF distribution function - """ - return util.displace_PSF_gaussian(x, y, self._fwhm)
- - -
[docs]@export -class PSFMoffat(object): - """ - Moffat PSF - """ - - def __init__(self, fwhm, moffat_beta): - """ - - :param fwhm: full width at half maximum seeing condition - :param moffat_beta: float, beta parameter of Moffat profile - """ - self._fwhm = fwhm - self._moffat_beta = moffat_beta - -
[docs] def displace_psf(self, x, y): - """ - - :param x: x-coordinate of light ray - :param y: y-coordinate of light ray - :return: x', y' displaced by the two dimensional PSF distribution function - """ - return util.displace_PSF_moffat(x, y, self._fwhm, self._moffat_beta)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/GalKin/velocity_util.html b/docs/_build/html/_modules/lenstronomy/GalKin/velocity_util.html deleted file mode 100644 index 2e475f6f5..000000000 --- a/docs/_build/html/_modules/lenstronomy/GalKin/velocity_util.html +++ /dev/null @@ -1,227 +0,0 @@ - - - - - - - - lenstronomy.GalKin.velocity_util — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.GalKin.velocity_util

-__author__ = 'sibirrer'
-
-import numpy as np
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -def hyp_2F1(a, b, c, z): - """ - http://docs.sympy.org/0.7.1/modules/mpmath/functions/hypergeometric.html - """ - import mpmath as mp - - return mp.hyp2f1(a, b, c, z)
- - -
[docs]@export -def displace_PSF_gaussian(x, y, FWHM): - """ - - :param x: x-coord (arc sec) - :param y: y-coord (arc sec) - :param FWHM: psf size (arc sec) - :return: x', y' random displaced according to psf - """ - sigma = FWHM / (2 * np.sqrt(2 * np.log(2))) - sigma_one_direction = sigma - x_ = x + np.random.normal() * sigma_one_direction - y_ = y + np.random.normal() * sigma_one_direction - return x_, y_
- - -
[docs]@export -def moffat_r(r, alpha, beta): - """ - Moffat profile - - :param r: radial coordinate - :param alpha: Moffat parameter - :param beta: exponent - :return: Moffat profile - """ - return 2. * (beta - 1) / alpha ** 2 * (1 + (r/alpha) ** 2) ** (-beta)
- - -
[docs]@export -def moffat_fwhm_alpha(FWHM, beta): - """ - computes alpha parameter from FWHM and beta for a Moffat profile - - :param FWHM: full width at half maximum - :param beta: beta parameter of Moffat profile - :return: alpha parameter of Moffat profile - """ - return FWHM / (2 * np.sqrt(2 ** (1. / beta) - 1))
- - -
[docs]@export -def draw_moffat_r(FWHM, beta): - """ - - :param FWHM: full width at half maximum - :param beta: Moffat beta parameter - :return: draw from radial Moffat distribution - """ - alpha = moffat_fwhm_alpha(FWHM, beta) - y = draw_cdf_Y(beta) - # equation B3 in Berge et al. paper - X = alpha * np.sqrt((y - 1)) - return X
- - -
[docs]@export -def displace_PSF_moffat(x, y, FWHM, beta): - """ - - :param x: x-coordinate of light ray - :param y: y-coordinate of light ray - :param FWHM: full width at half maximum - :param beta: Moffat beta parameter - :return: displaced ray by PSF - """ - X = draw_moffat_r(FWHM, beta) - dx, dy = draw_xy(X) - return x + dx, y + dy
- - -
[docs]@export -def draw_cdf_Y(beta): - """ - Draw c.d.f for Moffat function according to Berge et al. Ufig paper, equation B2 - cdf(Y) = 1-Y**(1-beta) - - :return: - """ - x = np.random.uniform(0, 1) - return (1-x) ** (1./(1-beta))
- - -
[docs]@export -def project2d_random(r): - """ - draws a random projection from radius r in 2d and 1d - :param r: 3d radius - :return: R, x, y - """ - size = len(np.atleast_1d(r)) - if size == 1: - size = None - u1 = np.random.uniform(0, 1, size=size) - u2 = np.random.uniform(0, 1, size=size) - l = np.arccos(2*u1 - 1) - np.pi / 2 - phi = 2 * np.pi * u2 - x = r * np.cos(l) * np.cos(phi) - y = r * np.cos(l) * np.sin(phi) - # z = r * np.sin(l) - R = np.sqrt(x**2 + y**2) - return R, x, y
- - -
[docs]@export -def draw_xy(R): - """ - - :param R: projected radius - :return: - """ - phi = np.random.uniform(0, 2 * np.pi) - x = R * np.cos(phi) - y = R * np.sin(phi) - return x, y
- - -
[docs]@export -def draw_hernquist(a): - """ - - :param a: 0.551*r_eff - :return: realisation of radius of Hernquist luminosity weighting in 3d - """ - P = np.random.uniform() # draws uniform between [0,1) - r = a*np.sqrt(P)*(np.sqrt(P)+1)/(1-P) # solves analytically to r from P(r) - return r
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/ImSim/MultiBand/joint_linear.html b/docs/_build/html/_modules/lenstronomy/ImSim/MultiBand/joint_linear.html deleted file mode 100644 index 7df88c23d..000000000 --- a/docs/_build/html/_modules/lenstronomy/ImSim/MultiBand/joint_linear.html +++ /dev/null @@ -1,238 +0,0 @@ - - - - - - - - lenstronomy.ImSim.MultiBand.joint_linear — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.ImSim.MultiBand.joint_linear

-from lenstronomy.ImSim.MultiBand.multi_linear import MultiLinear
-import lenstronomy.ImSim.de_lens as de_lens
-
-import numpy as np
-
-__all__ = ['JointLinear']
-
-
-
[docs]class JointLinear(MultiLinear): - """ - class to model multiple exposures in the same band and makes a constraint fit to all bands simultaneously - with joint constraints on the surface brightness of the model. This model setting require the same surface - brightness models to be called in all available images/bands - - """ - def __init__(self, multi_band_list, kwargs_model, compute_bool=None, likelihood_mask_list=None): - # TODO: make this raise statement valid - # if kwargs_model.get('index_source_light_model_list', None) is not None or \ - # kwargs_model.get('index_lens_light_model_list', None) is not None or \ - # kwargs_model.get('index_point_source_model_list', None) is not None: - # raise ValueError('You are not allowed to set partial surface brightness models to individual bands in the ' - # 'joint-linear mode. Your settings are: ', kwargs_model) - super(JointLinear, self).__init__(multi_band_list, kwargs_model=kwargs_model, compute_bool=compute_bool, - likelihood_mask_list=likelihood_mask_list) - self.type = 'joint-linear' - -
[docs] def image_linear_solve(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - kwargs_extinction=None, kwargs_special=None, inv_bool=False): - """ - computes the image (lens and source surface brightness with a given lens model). - The linear parameters are computed with a weighted linear least square optimization - (i.e. flux normalization of the brightness profiles) - - :param kwargs_lens: list of keyword arguments corresponding to the superposition of different lens profiles - :param kwargs_source: list of keyword arguments corresponding to the superposition of different source light profiles - :param kwargs_lens_light: list of keyword arguments corresponding to different lens light surface brightness profiles - :param kwargs_ps: keyword arguments corresponding to "other" parameters, such as external shear and point source image positions - :param inv_bool: if True, invert the full linear solver Matrix Ax = y for the purpose of the covariance matrix. - :return: 1d array of surface brightness pixels of the optimal solution of the linear parameters to match the data - """ - A = self.linear_response_matrix(kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, kwargs_extinction, kwargs_special) - C_D_response, model_error_list = self.error_response(kwargs_lens, kwargs_ps) - d = self.data_response - param, cov_param, wls_model = de_lens.get_param_WLS(A.T, 1 / C_D_response, d, inv_bool=inv_bool) - wls_list = self._array2image_list(wls_model) - return wls_list, model_error_list, cov_param, param
- -
[docs] def linear_response_matrix(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - kwargs_extinction=None, kwargs_special=None): - """ - computes the linear response matrix (m x n), with n being the data size and m being the coefficients - - :param kwargs_lens: - :param kwargs_source: - :param kwargs_lens_light: - :param kwargs_ps: - :return: - """ - A = [] - for i in range(self._num_bands): - if self._compute_bool[i] is True: - A_i = self._imageModel_list[i].linear_response_matrix(kwargs_lens, kwargs_source, kwargs_lens_light, - kwargs_ps, kwargs_extinction, kwargs_special) - if len(A) == 0: - A = A_i - else: - A = np.append(A, A_i, axis=1) - return A
- - @property - def data_response(self): - """ - returns the 1d array of the data element that is fitted for (including masking) - - :return: 1d numpy array - """ - d = [] - for i in range(self._num_bands): - if self._compute_bool[i] is True: - d_i = self._imageModel_list[i].data_response - if len(d) == 0: - d = d_i - else: - d = np.append(d, d_i) - return d - - def _array2image_list(self, array): - """ - maps 1d vector of joint exposures in list of 2d images of single exposures - - :param array: 1d numpy array - :return: list of 2d numpy arrays of size of exposures - """ - image_list = [] - k = 0 - for i in range(self._num_bands): - if self._compute_bool[i] is True: - num_data = self.num_response_list[i] - array_i = array[k:k + num_data] - image_i = self._imageModel_list[i].array_masked2image(array_i) - image_list.append(image_i) - k += num_data - return image_list - -
[docs] def error_response(self, kwargs_lens, kwargs_ps, kwargs_special=None): - """ - returns the 1d array of the error estimate corresponding to the data response - - :return: 1d numpy array of response, 2d array of additonal errors (e.g. point source uncertainties) - """ - C_D_response, model_error = [], [] - for i in range(self._num_bands): - if self._compute_bool[i] is True: - C_D_response_i, model_error_i = self._imageModel_list[i].error_response(kwargs_lens, kwargs_ps, kwargs_special=kwargs_special) - model_error.append(model_error_i) - if len(C_D_response) == 0: - C_D_response = C_D_response_i - else: - C_D_response = np.append(C_D_response, C_D_response_i) - return C_D_response, model_error
- -
[docs] def likelihood_data_given_model(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - kwargs_extinction=None, kwargs_special=None, source_marg=False, linear_prior=None, - check_positive_flux=False): - """ - computes the likelihood of the data given a model - This is specified with the non-linear parameters and a linear inversion and prior marginalisation. - - :param kwargs_lens: - :param kwargs_source: - :param kwargs_lens_light: - :param kwargs_ps: - :param check_positive_flux: bool, if True, checks whether the linear inversion resulted in non-negative flux - components and applies a punishment in the likelihood if so. - :return: log likelihood (natural logarithm) (sum of the log likelihoods of the individual images) - """ - # generate image - im_sim_list, model_error_list, cov_matrix, param = self.image_linear_solve(kwargs_lens, kwargs_source, - kwargs_lens_light, kwargs_ps, - kwargs_extinction, kwargs_special, - inv_bool=source_marg) - # compute X^2 - logL = 0 - index = 0 - for i in range(self._num_bands): - if self._compute_bool[i] is True: - logL += self._imageModel_list[i].Data.log_likelihood(im_sim_list[index], self._imageModel_list[i].likelihood_mask, model_error_list[index]) - index += 1 - if cov_matrix is not None and source_marg: - marg_const = de_lens.marginalization_new(cov_matrix, d_prior=linear_prior) - logL += marg_const - if check_positive_flux is True and self._num_bands > 0: - bool_ = self._imageModel_list[0].check_positive_flux(kwargs_source, kwargs_lens_light, kwargs_ps) - if bool_ is False: - logL -= 10 ** 5 - return logL
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/ImSim/MultiBand/multi_data_base.html b/docs/_build/html/_modules/lenstronomy/ImSim/MultiBand/multi_data_base.html deleted file mode 100644 index 5797ec7ab..000000000 --- a/docs/_build/html/_modules/lenstronomy/ImSim/MultiBand/multi_data_base.html +++ /dev/null @@ -1,167 +0,0 @@ - - - - - - - - lenstronomy.ImSim.MultiBand.multi_data_base — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.ImSim.MultiBand.multi_data_base

-__all__ = ['MultiDataBase']
-
-
-
[docs]class MultiDataBase(object): - """ - Base class with definitions that are shared among all variations of modelling multiple data sets - """ - - def __init__(self, image_model_list, compute_bool=None): - """ - - :param image_model_list: list of ImageModel instances (supporting linear inversions) - :param compute_bool: list of booleans for each imaging band indicating whether to model it or not. - """ - self._num_bands = len(image_model_list) - if compute_bool is None: - compute_bool = [True] * self._num_bands - else: - if not len(compute_bool) == self._num_bands: - raise ValueError('compute_bool statement has not the same range as number of bands available!') - self._compute_bool = compute_bool - self._imageModel_list = image_model_list - self._num_response_list = [] - for imageModel in image_model_list: - self._num_response_list.append(imageModel.num_data_evaluate) - - @property - def num_bands(self): - return self._num_bands - - @property - def num_response_list(self): - """ - list of number of data elements that are used in the minimization - - :return: list of integers - """ - return self._num_response_list - -
[docs] def reset_point_source_cache(self, cache=True): - """ - deletes all the cache in the point source class and saves it from then on - - :return: - """ - for imageModel in self._imageModel_list: - imageModel.reset_point_source_cache(cache=cache)
- - @property - def num_data_evaluate(self): - num = 0 - for i in range(self._num_bands): - if self._compute_bool[i] is True: - num += self._imageModel_list[i].num_data_evaluate - return num - -
[docs] def num_param_linear(self, kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps): - """ - - :return: number of linear coefficients to be solved for in the linear inversion - """ - num = 0 - for i in range(self._num_bands): - if self._compute_bool[i] is True: - num += self._imageModel_list[i].num_param_linear(kwargs_lens, kwargs_source, kwargs_lens_light, - kwargs_ps) - return num
- -
[docs] def reduced_residuals(self, model_list, error_map_list=None): - """ - - :param model_list: list of models - :param error_map_list: list of error maps - :return: - """ - residual_list = [] - if error_map_list is None: - error_map_list = [[] for _ in range(self._num_bands)] - index = 0 - for i in range(self._num_bands): - if self._compute_bool[i] is True: - residual_list.append(self._imageModel_list[i].reduced_residuals(model_list[index], - error_map=error_map_list[index])) - index += 1 - return residual_list
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/ImSim/MultiBand/multi_linear.html b/docs/_build/html/_modules/lenstronomy/ImSim/MultiBand/multi_linear.html deleted file mode 100644 index db56246c5..000000000 --- a/docs/_build/html/_modules/lenstronomy/ImSim/MultiBand/multi_linear.html +++ /dev/null @@ -1,183 +0,0 @@ - - - - - - - - lenstronomy.ImSim.MultiBand.multi_linear — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.ImSim.MultiBand.multi_linear

-from lenstronomy.ImSim.MultiBand.multi_data_base import MultiDataBase
-from lenstronomy.ImSim.MultiBand.single_band_multi_model import SingleBandMultiModel
-
-__all__ = ['MultiLinear']
-
-
-
[docs]class MultiLinear(MultiDataBase): - """ - class to simulate/reconstruct images in multi-band option. - This class calls functions of image_model.py with different bands with - joint non-linear parameters and decoupled linear parameters. - - the class supports keyword arguments 'index_lens_model_list', 'index_source_light_model_list', - 'index_lens_light_model_list', 'index_point_source_model_list', 'index_optical_depth_model_list' in kwargs_model - These arguments should be lists of length the number of imaging bands available and each entry in the list - is a list of integers specifying the model components being evaluated for the specific band. - - E.g. there are two bands and you want to different light profiles being modeled. - - you define two different light profiles lens_light_model_list = ['SERSIC', 'SERSIC'] - - set index_lens_light_model_list = [[0], [1]] - - (optional) for now all the parameters between the two light profiles are independent in the model. You have - the possibility to join a subset of model parameters (e.g. joint centroid). See the Param() class for documentation. - - """ - - def __init__(self, multi_band_list, kwargs_model, likelihood_mask_list=None, compute_bool=None, kwargs_pixelbased=None): - """ - - :param multi_band_list: list of imaging band configurations [[kwargs_data, kwargs_psf, kwargs_numerics],[...], ...] - :param kwargs_model: model option keyword arguments - :param likelihood_mask_list: list of likelihood masks (booleans with size of the individual images) - :param compute_bool: (optional), bool list to indicate which band to be included in the modeling - """ - self.type = 'multi-linear' - imageModel_list = [] - for band_index in range(len(multi_band_list)): - imageModel = SingleBandMultiModel(multi_band_list, kwargs_model, likelihood_mask_list=likelihood_mask_list, - band_index=band_index, kwargs_pixelbased=kwargs_pixelbased) - imageModel_list.append(imageModel) - super(MultiLinear, self).__init__(imageModel_list, compute_bool=compute_bool) - -
[docs] def image_linear_solve(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - kwargs_extinction=None, kwargs_special=None, inv_bool=False): - """ - computes the image (lens and source surface brightness with a given lens model). - The linear parameters are computed with a weighted linear least square optimization - (i.e. flux normalization of the brightness profiles) - - :param kwargs_lens: list of keyword arguments corresponding to the superposition of different lens profiles - :param kwargs_source: list of keyword arguments corresponding to the superposition of different source light profiles - :param kwargs_lens_light: list of keyword arguments corresponding to different lens light surface brightness profiles - :param kwargs_ps: keyword arguments corresponding to "other" parameters, such as external shear and point source image positions - :param inv_bool: if True, invert the full linear solver Matrix Ax = y for the purpose of the covariance matrix. - :return: 1d array of surface brightness pixels of the optimal solution of the linear parameters to match the data - """ - wls_list, error_map_list, cov_param_list, param_list = [], [], [], [] - for i in range(self._num_bands): - if self._compute_bool[i] is True: - wls_model, error_map, cov_param, param = self._imageModel_list[i].image_linear_solve(kwargs_lens, - kwargs_source, - kwargs_lens_light, - kwargs_ps, - kwargs_extinction, - kwargs_special, - inv_bool=inv_bool) - else: - wls_model, error_map, cov_param, param = None, None, None, None - wls_list.append(wls_model) - error_map_list.append(error_map) - cov_param_list.append(cov_param) - param_list.append(param) - return wls_list, error_map_list, cov_param_list, param_list
- -
[docs] def likelihood_data_given_model(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - kwargs_extinction=None, kwargs_special=None, source_marg=False, linear_prior=None, - check_positive_flux=False): - """ - computes the likelihood of the data given a model - This is specified with the non-linear parameters and a linear inversion and prior marginalisation. - - :param kwargs_lens: - :param kwargs_source: - :param kwargs_lens_light: - :param kwargs_ps: - :param check_positive_flux: bool, if True, checks whether the linear inversion resulted in non-negative flux - components and applies a punishment in the likelihood if so. - :return: log likelihood (natural logarithm) (sum of the log likelihoods of the individual images) - """ - # generate image - logL = 0 - if linear_prior is None: - linear_prior = [None for i in range(self._num_bands)] - for i in range(self._num_bands): - if self._compute_bool[i] is True: - logL += self._imageModel_list[i].likelihood_data_given_model(kwargs_lens, kwargs_source, - kwargs_lens_light, kwargs_ps, - kwargs_extinction, kwargs_special, - source_marg=source_marg, - linear_prior=linear_prior[i], - check_positive_flux=check_positive_flux) - return logL
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/ImSim/MultiBand/single_band_multi_model.html b/docs/_build/html/_modules/lenstronomy/ImSim/MultiBand/single_band_multi_model.html deleted file mode 100644 index 15f2714b0..000000000 --- a/docs/_build/html/_modules/lenstronomy/ImSim/MultiBand/single_band_multi_model.html +++ /dev/null @@ -1,274 +0,0 @@ - - - - - - - - lenstronomy.ImSim.MultiBand.single_band_multi_model — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.ImSim.MultiBand.single_band_multi_model

-from lenstronomy.ImSim.image_linear_solve import ImageLinearFit
-from lenstronomy.Data.imaging_data import ImageData
-from lenstronomy.Data.psf import PSF
-from lenstronomy.Util import class_creator
-
-__all__ = ['SingleBandMultiModel']
-
-
-
[docs]class SingleBandMultiModel(ImageLinearFit): - """ - class to simulate/reconstruct images in multi-band option. - This class calls functions of image_model.py with different bands with - decoupled linear parameters and the option to pass/select different light models for the different bands - - the class supports keyword arguments 'index_lens_model_list', 'index_source_light_model_list', - 'index_lens_light_model_list', 'index_point_source_model_list', 'index_optical_depth_model_list' in kwargs_model - These arguments should be lists of length the number of imaging bands available and each entry in the list - is a list of integers specifying the model components being evaluated for the specific band. - - E.g. there are two bands and you want to different light profiles being modeled. - - you define two different light profiles lens_light_model_list = ['SERSIC', 'SERSIC'] - - set index_lens_light_model_list = [[0], [1]] - - (optional) for now all the parameters between the two light profiles are independent in the model. You have - the possibility to join a subset of model parameters (e.g. joint centroid). See the Param() class for documentation. - - """ - - def __init__(self, multi_band_list, kwargs_model, likelihood_mask_list=None, band_index=0, kwargs_pixelbased=None): - """ - - :param multi_band_list: list of imaging band configurations [[kwargs_data, kwargs_psf, kwargs_numerics],[...], ...] - :param kwargs_model: model option keyword arguments - :param likelihood_mask_list: list of likelihood masks (booleans with size of the individual images - :param band_index: integer, index of the imaging band to model - :param kwargs_pixelbased: keyword arguments with various settings related to the pixel-based solver (see SLITronomy documentation) - """ - self.type = 'single-band-multi-model' - if likelihood_mask_list is None: - likelihood_mask_list = [None for i in range(len(multi_band_list))] - lens_model_class, source_model_class, lens_light_model_class, point_source_class, extinction_class = class_creator.create_class_instances(band_index=band_index, **kwargs_model) - kwargs_data = multi_band_list[band_index][0] - kwargs_psf = multi_band_list[band_index][1] - kwargs_numerics = multi_band_list[band_index][2] - data_i = ImageData(**kwargs_data) - psf_i = PSF(**kwargs_psf) - - index_lens_model_list = kwargs_model.get('index_lens_model_list', [None for i in range(len(multi_band_list))]) - self._index_lens_model = index_lens_model_list[band_index] - index_source_list = kwargs_model.get('index_source_light_model_list', [None for i in range(len(multi_band_list))]) - self._index_source = index_source_list[band_index] - index_lens_light_list = kwargs_model.get('index_lens_light_model_list', [None for i in range(len(multi_band_list))]) - self._index_lens_light = index_lens_light_list[band_index] - index_point_source_list = kwargs_model.get('index_point_source_model_list', [None for i in range(len(multi_band_list))]) - self._index_point_source = index_point_source_list[band_index] - index_optical_depth = kwargs_model.get('index_optical_depth_model_list', - [None for i in range(len(multi_band_list))]) - self._index_optical_depth = index_optical_depth[band_index] - - super(SingleBandMultiModel, self).__init__(data_i, psf_i, lens_model_class, source_model_class, - lens_light_model_class, point_source_class, extinction_class, - kwargs_numerics=kwargs_numerics, likelihood_mask=likelihood_mask_list[band_index], - kwargs_pixelbased=kwargs_pixelbased) - -
[docs] def image_linear_solve(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - kwargs_extinction=None, kwargs_special=None, inv_bool=False): - """ - computes the image (lens and source surface brightness with a given lens model). - The linear parameters are computed with a weighted linear least square optimization (i.e. flux normalization of the brightness profiles) - :param kwargs_lens: list of keyword arguments corresponding to the superposition of different lens profiles - :param kwargs_source: list of keyword arguments corresponding to the superposition of different source light profiles - :param kwargs_lens_light: list of keyword arguments corresponding to different lens light surface brightness profiles - :param kwargs_ps: keyword arguments corresponding to "other" parameters, such as external shear and point source image positions - :param inv_bool: if True, invert the full linear solver Matrix Ax = y for the purpose of the covariance matrix. - :return: 1d array of surface brightness pixels of the optimal solution of the linear parameters to match the data - """ - kwargs_lens_i, kwargs_source_i, kwargs_lens_light_i, kwargs_ps_i, kwargs_extinction_i = self.select_kwargs(kwargs_lens, - kwargs_source, - kwargs_lens_light, - kwargs_ps, - kwargs_extinction) - wls_model, error_map, cov_param, param = self._image_linear_solve(kwargs_lens_i, kwargs_source_i, - kwargs_lens_light_i, kwargs_ps_i, - kwargs_extinction_i, kwargs_special, inv_bool=inv_bool) - return wls_model, error_map, cov_param, param
- -
[docs] def likelihood_data_given_model(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - kwargs_extinction=None, kwargs_special=None, source_marg=False, linear_prior=None, - check_positive_flux=False): - """ - computes the likelihood of the data given a model - This is specified with the non-linear parameters and a linear inversion and prior marginalisation. - - :param kwargs_lens: - :param kwargs_source: - :param kwargs_lens_light: - :param kwargs_ps: - :param check_positive_flux: bool, if True, checks whether the linear inversion resulted in non-negative flux - components and applies a punishment in the likelihood if so. - :return: log likelihood (natural logarithm) (sum of the log likelihoods of the individual images) - """ - # generate image - kwargs_lens_i, kwargs_source_i, kwargs_lens_light_i, kwargs_ps_i, kwargs_extinction_i = self.select_kwargs(kwargs_lens, - kwargs_source, - kwargs_lens_light, - kwargs_ps, - kwargs_extinction) - logL = self._likelihood_data_given_model(kwargs_lens_i, kwargs_source_i, kwargs_lens_light_i, kwargs_ps_i, - kwargs_extinction_i, kwargs_special, source_marg=source_marg, - linear_prior=linear_prior, check_positive_flux=check_positive_flux) - return logL
- -
[docs] def num_param_linear(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None): - """ - - :return: number of linear coefficients to be solved for in the linear inversion - """ - kwargs_lens_i, kwargs_source_i, kwargs_lens_light_i, kwargs_ps_i, kwargs_extinction_i = self.select_kwargs(kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps) - num = self._num_param_linear(kwargs_lens_i, kwargs_source_i, kwargs_lens_light_i, kwargs_ps_i) - return num
- -
[docs] def linear_response_matrix(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - kwargs_extinction=None, kwargs_special=None): - """ - computes the linear response matrix (m x n), with n beeing the data size and m being the coefficients - - :param kwargs_lens: - :param kwargs_source: - :param kwargs_lens_light: - :param kwargs_ps: - :return: - """ - kwargs_lens_i, kwargs_source_i, kwargs_lens_light_i, kwargs_ps_i, kwargs_extinction_i = self.select_kwargs(kwargs_lens, - kwargs_source, - kwargs_lens_light, - kwargs_ps, - kwargs_extinction) - A = self._linear_response_matrix(kwargs_lens_i, kwargs_source_i, kwargs_lens_light_i, kwargs_ps_i, - kwargs_extinction_i, kwargs_special) - return A
- -
[docs] def error_map_source(self, kwargs_source, x_grid, y_grid, cov_param, model_index_select=True): - """ - variance of the linear source reconstruction in the source plane coordinates, - computed by the diagonal elements of the covariance matrix of the source reconstruction as a sum of the errors - of the basis set. - - :param kwargs_source: keyword arguments of source model - :param x_grid: x-axis of positions to compute error map - :param y_grid: y-axis of positions to compute error map - :param cov_param: covariance matrix of liner inversion parameters - :param model_index_select: boolean, if True, selects the model components of this band (default). If False, - assumes input kwargs_source is already selected list. - :return: diagonal covariance errors at the positions (x_grid, y_grid) - """ - if self._index_source is None or model_index_select is False: - kwargs_source_i = kwargs_source - else: - kwargs_source_i = [kwargs_source[k] for k in self._index_source] - return self._error_map_source(kwargs_source_i, x_grid, y_grid, cov_param)
- -
[docs] def select_kwargs(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - kwargs_extinction=None, kwargs_special=None): - """ - select subset of kwargs lists referenced to this imaging band - - :param kwargs_lens: - :param kwargs_source: - :param kwargs_lens_light: - :param kwargs_ps: - :return: - """ - if self._index_lens_model is None: - kwargs_lens_i = kwargs_lens - else: - kwargs_lens_i = [kwargs_lens[k] for k in self._index_lens_model] - if self._index_source is None: - kwargs_source_i = kwargs_source - else: - kwargs_source_i = [kwargs_source[k] for k in self._index_source] - if self._index_lens_light is None: - kwargs_lens_light_i = kwargs_lens_light - else: - kwargs_lens_light_i = [kwargs_lens_light[k] for k in self._index_lens_light] - if self._index_point_source is None: - kwargs_ps_i = kwargs_ps - else: - kwargs_ps_i = [kwargs_ps[k] for k in self._index_point_source] - if self._index_optical_depth is None or kwargs_extinction is None: - kwargs_extinction_i = kwargs_extinction - else: - kwargs_extinction_i = [kwargs_extinction[k] for k in self._index_optical_depth] - return kwargs_lens_i, kwargs_source_i, kwargs_lens_light_i, kwargs_ps_i, kwargs_extinction_i
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/adaptive_numerics.html b/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/adaptive_numerics.html deleted file mode 100644 index 87250ea49..000000000 --- a/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/adaptive_numerics.html +++ /dev/null @@ -1,155 +0,0 @@ - - - - - - - - lenstronomy.ImSim.Numerics.adaptive_numerics — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.ImSim.Numerics.adaptive_numerics

-from lenstronomy.ImSim.Numerics.numba_convolution import SubgridNumbaConvolution, NumbaConvolution
-from lenstronomy.ImSim.Numerics.convolution import PixelKernelConvolution
-from lenstronomy.Util import kernel_util
-from lenstronomy.Util import image_util
-
-__all__ = ['AdaptiveConvolution']
-
-
-
[docs]class AdaptiveConvolution(object): - """ - This class performs convolutions of a subset of pixels at higher supersampled resolution - Goal: speed up relative to higher resolution FFT when only considering a (small) subset of pixels to be convolved - on the higher resolution grid. - - strategy: - 1. lower resolution convolution over full image with FFT - 2. subset of pixels with higher resolution Numba convolution (with smaller kernel) - 3. the same subset of pixels with low resolution Numba convolution (with same kernel as step 2) - adaptive solution is 1 + 2 - 3 - - """ - def __init__(self, kernel_super, supersampling_factor, conv_supersample_pixels, supersampling_kernel_size=None, - compute_pixels=None, nopython=True, cache=True, parallel=False): - """ - - :param kernel_super: convolution kernel in units of super sampled pixels provided, odd length per axis - :param supersampling_factor: factor of supersampling relative to pixel grid - :param conv_supersample_pixels: bool array same size as data, pixels to be convolved and their light to be blurred - :param supersampling_kernel_size: number of pixels (in units of the image pixels) that are convolved with the - supersampled kernel - :param compute_pixels: bool array of size of image, these pixels (if True) will get blurred light from other pixels - :param nopython: bool, numba jit setting to use python or compiled. - :param cache: bool, numba jit setting to use cache - :param parallel: bool, numba jit setting to use parallel mode - """ - kernel = kernel_util.degrade_kernel(kernel_super, degrading_factor=supersampling_factor) - self._low_res_conv = PixelKernelConvolution(kernel, convolution_type='fft') - if supersampling_kernel_size is None: - supersampling_kernel_size = len(kernel) - - n_cut_super = supersampling_kernel_size * supersampling_factor - if n_cut_super % 2 == 0: - n_cut_super += 1 - kernel_super_cut = image_util.cut_edges(kernel_super, n_cut_super) - kernel_cut = kernel_util.degrade_kernel(kernel_super_cut, degrading_factor=supersampling_factor) - - self._low_res_partial = NumbaConvolution(kernel_cut, conv_supersample_pixels, compute_pixels=compute_pixels, - nopython=nopython, cache=cache, parallel=parallel, memory_raise=True) - self._hig_res_partial = SubgridNumbaConvolution(kernel_super_cut, supersampling_factor, conv_supersample_pixels, - compute_pixels=compute_pixels, nopython=nopython, cache=cache, - parallel=parallel) # , kernel_size=len(kernel_cut)) - self._supersampling_factor = supersampling_factor - -
[docs] def re_size_convolve(self, image_low_res, image_high_res): - """ - - :param image_low_res: regular sampled image/model - :param image_high_res: supersampled image/model to be convolved on a regular pixel grid - :return: convolved and re-sized image - """ - image_low_res_conv = self._low_res_conv.convolution2d(image_low_res) - image_low_res_partial_conv = self._low_res_partial.convolve2d(image_low_res) - image_high_res_partial_conv = self._hig_res_partial.convolve2d(image_high_res) - return image_low_res_conv + image_high_res_partial_conv - image_low_res_partial_conv
- -
[docs] def convolve2d(self, image_high_res): - """ - - :param image_high_res: supersampled image/model to be convolved on a regular pixel grid - :return: convolved and re-sized image - """ - image_low_res = image_util.re_size(image_high_res, factor=self._supersampling_factor) - return self.re_size_convolve(image_low_res, image_high_res)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/convolution.html b/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/convolution.html deleted file mode 100644 index c52907f57..000000000 --- a/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/convolution.html +++ /dev/null @@ -1,455 +0,0 @@ - - - - - - - - lenstronomy.ImSim.Numerics.convolution — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.ImSim.Numerics.convolution

-from scipy import fftpack, ndimage, signal
-import numpy as np
-import threading
-import lenstronomy.Util.kernel_util as kernel_util
-import lenstronomy.Util.util as util
-import lenstronomy.Util.image_util as image_util
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-_rfft_mt_safe = True  # (NumpyVersion(np.__version__) >= '1.9.0.dev-e24486e')
-_rfft_lock = threading.Lock()
-
-
-
-
-def _centered(arr, newshape):
-    # Return the center newshape portion of the array.
-    newshape = np.asarray(newshape)
-    currshape = np.array(arr.shape)
-    startind = (currshape - newshape) // 2
-    endind = startind + newshape
-    myslice = [slice(startind[k], endind[k]) for k in range(len(endind))]
-    return arr[tuple(myslice)]
-
-
-
[docs]@export -class PixelKernelConvolution(object): - """ - class to compute convolutions for a given pixelized kernel (fft, grid) - """ - def __init__(self, kernel, convolution_type='fft_static'): - """ - - :param kernel: 2d array, convolution kernel - :param convolution_type: string, 'fft', 'grid', 'fft_static' mode of 2d convolution - """ - self._kernel = kernel - if convolution_type not in ['fft', 'grid', 'fft_static']: - raise ValueError('convolution_type %s not supported!' % convolution_type) - self._type = convolution_type - self._pre_computed = False - -
[docs] def pixel_kernel(self, num_pix=None): - """ - access pixelated kernel - - :param num_pix: size of returned kernel (odd number per axis). If None, return the original kernel. - :return: pixel kernel centered - """ - if num_pix is not None: - return kernel_util.cut_psf(self._kernel, num_pix) - return self._kernel
- -
[docs] def copy_transpose(self): - """ - - :return: copy of the class with kernel set to the transpose of original one - """ - return PixelKernelConvolution(self._kernel.T, convolution_type=self._type)
- -
[docs] def convolution2d(self, image): - """ - - :param image: 2d array (image) to be convolved - :return: fft convolution - """ - if self._type == 'fft': - image_conv = signal.fftconvolve(image, self._kernel, mode='same') - elif self._type == 'fft_static': - image_conv = self._static_fft(image, mode='same') - elif self._type == 'grid': - image_conv = signal.convolve2d(image, self._kernel, mode='same') - else: - raise ValueError('convolution_type %s not supported!' % self._type) - return image_conv
- - def _static_fft(self, image, mode='same'): - """ - scipy fft convolution with saved static fft kernel - - :param image: 2d numpy array to be convolved - :return: - """ - in1 = image - in1 = np.asarray(in1) - if self._pre_computed is False: - self._s1, self._s2, self._complex_result, self._shape, self._fshape, self._fslice, self._sp2 = self._static_pre_compute(image) - self._pre_computed = True - s1, s2, complex_result, shape, fshape, fslice, sp2 = self._s1, self._s2, self._complex_result, self._shape, self._fshape, self._fslice, self._sp2 - # if in1.ndim == in2.ndim == 0: # scalar inputs - # return in1 * in2 - # elif not in1.ndim == in2.ndim: - # raise ValueError("in1 and in2 should have the same dimensionality") - # elif in1.size == 0 or in2.size == 0: # empty arrays - # return np.array([]) - - # Check that input sizes are compatible with 'valid' mode - # if _inputs_swap_needed(mode, s1, s2): - # Convolution is commutative; order doesn't have any effect on output - # only applicable for 'valid' mode - # in1, s1, in2, s2 = in2, s2, in1, s1 - - # Pre-1.9 NumPy FFT routines are not threadsafe. For older NumPys, make - # sure we only call rfftn/irfftn from one thread at a time. - if not complex_result and (_rfft_mt_safe or _rfft_lock.acquire(False)): - try: - sp1 = np.fft.rfftn(in1, fshape) - ret = (np.fft.irfftn(sp1 * sp2, fshape)[fslice].copy()) - finally: - if not _rfft_mt_safe: - _rfft_lock.release() - else: - # If we're here, it's either because we need a complex result, or we - # failed to acquire _rfft_lock (meaning rfftn isn't threadsafe and - # is already in use by another thread). In either case, use the - # (threadsafe but slower) SciPy complex-FFT routines instead. - sp1 = fftpack.fftn(in1, fshape) - ret = fftpack.ifftn(sp1 * sp2)[fslice].copy() - if not complex_result: - ret = ret.real - - if mode == "full": - return ret - elif mode == "same": - return _centered(ret, s1) - elif mode == "valid": - return _centered(ret, s1 - s2 + 1) - else: - raise ValueError("Acceptable mode flags are 'valid'," - " 'same', or 'full'.") - - def _static_pre_compute(self, image): - """ - pre-compute Fourier transformed kernel and shape quantities to speed up convolution - - :param image: 2d numpy array - :return: - """ - in1 = image - in2 = self._kernel - s1 = np.array(in1.shape) - s2 = np.array(in2.shape) - complex_result = (np.issubdtype(in1.dtype, np.complexfloating) or - np.issubdtype(in2.dtype, np.complexfloating)) - shape = s1 + s2 - 1 - - # Check that input sizes are compatible with 'valid' mode - # if _inputs_swap_needed(mode, s1, s2): - # Convolution is commutative; order doesn't have any effect on output - # only applicable for 'valid' mode - # in1, s1, in2, s2 = in2, s2, in1, s1 - - # Speed up FFT by padding to optimal size for FFTPACK - fshape = [fftpack.helper.next_fast_len(int(d)) for d in shape] - fslice = tuple([slice(0, int(sz)) for sz in shape]) - # Pre-1.9 NumPy FFT routines are not threadsafe. For older NumPys, make - # sure we only call rfftn/irfftn from one thread at a time. - if not complex_result and (_rfft_mt_safe or _rfft_lock.acquire(False)): - try: - sp2 = np.fft.rfftn(in2, fshape) - finally: - if not _rfft_mt_safe: - _rfft_lock.release() - else: - # If we're here, it's either because we need a complex result, or we - # failed to acquire _rfft_lock (meaning rfftn isn't threadsafe and - # is already in use by another thread). In either case, use the - # (threadsafe but slower) SciPy complex-FFT routines instead. - sp2 = fftpack.fftn(in2, fshape) - return s1, s2, complex_result, shape, fshape, fslice, sp2 - -
[docs] def re_size_convolve(self, image_low_res, image_high_res=None): - """ - - :param image_low_res: regular sampled image/model - :param image_high_res: supersampled image/model to be convolved on a regular pixel grid - :return: convolved and re-sized image - """ - return self.convolution2d(image_low_res)
- - -
[docs]@export -class SubgridKernelConvolution(object): - """ - class to compute the convolution on a supersampled grid with partial convolution computed on the regular grid - """ - def __init__(self, kernel_supersampled, supersampling_factor, supersampling_kernel_size=None, convolution_type='fft_static'): - """ - - :param kernel_supersampled: kernel in supersampled pixels - :param supersampling_factor: supersampling factor relative to the image pixel grid - :param supersampling_kernel_size: number of pixels (in units of the image pixels) that are convolved with the - supersampled kernel - """ - # n_high = len(kernel_supersampled) - self._supersampling_factor = supersampling_factor - # numPix = int(n_high / self._supersampling_factor) - # if self._supersampling_factor % 2 == 0: - # self._kernel = kernel_util.averaging_even_kernel(kernel_supersampled, self._supersampling_factor) - # else: - # self._kernel = util.averaging(kernel_supersampled, numGrid=n_high, numPix=numPix) - if supersampling_kernel_size is None: - kernel_low_res, kernel_high_res = np.zeros((3, 3)), kernel_supersampled - self._low_res_convolution = False - else: - kernel_low_res, kernel_high_res = kernel_util.split_kernel(kernel_supersampled, supersampling_kernel_size, - self._supersampling_factor) - self._low_res_convolution = True - self._low_res_conv = PixelKernelConvolution(kernel_low_res, convolution_type=convolution_type) - self._high_res_conv = PixelKernelConvolution(kernel_high_res, convolution_type=convolution_type) - -
[docs] def convolution2d(self, image): - """ - - :param image: 2d array (high resoluton image) to be convolved and re-sized - :return: convolved image - """ - - image_high_res_conv = self._high_res_conv.convolution2d(image) - image_resized_conv = image_util.re_size(image_high_res_conv, self._supersampling_factor) - if self._low_res_convolution is True: - image_resized = image_util.re_size(image, self._supersampling_factor) - image_resized_conv += self._low_res_conv.convolution2d(image_resized) - return image_resized_conv
- -
[docs] def re_size_convolve(self, image_low_res, image_high_res): - """ - - :param image_high_res: supersampled image/model to be convolved on a regular pixel grid - :return: convolved and re-sized image - """ - image_high_res_conv = self._high_res_conv.convolution2d(image_high_res) - image_resized_conv = image_util.re_size(image_high_res_conv, self._supersampling_factor) - if self._low_res_convolution is True: - image_resized_conv += self._low_res_conv.convolution2d(image_low_res) - return image_resized_conv
- - -
[docs]@export -class MultiGaussianConvolution(object): - """ - class to perform a convolution consisting of multiple 2d Gaussians - This is aimed to lead to a speed-up without significant loss of accuracy do to the simplified convolution kernel - relative to a pixelized kernel. - """ - - def __init__(self, sigma_list, fraction_list, pixel_scale, supersampling_factor=1, supersampling_convolution=False, - truncation=2): - """ - - :param sigma_list: list of std value of Gaussian kernel - :param fraction_list: fraction of flux to be convoled with each Gaussian kernel - :param pixel_scale: scale of pixel width (to convert sigmas into units of pixels) - :param truncation: float. Truncate the filter at this many standard deviations. - Default is 4.0. - """ - self._num_gaussians = len(sigma_list) - self._sigmas_scaled = np.array(sigma_list) / pixel_scale - if supersampling_convolution is True: - self._sigmas_scaled *= supersampling_factor - self._fraction_list = fraction_list / np.sum(fraction_list) - assert len(self._sigmas_scaled) == len(self._fraction_list) - self._truncation = truncation - self._pixel_scale = pixel_scale - self._supersampling_factor = supersampling_factor - self._supersampling_convolution = supersampling_convolution - -
[docs] def convolution2d(self, image): - """ - 2d convolution - - :param image: 2d numpy array, image to be convolved - :return: convolved image, 2d numpy array - """ - image_conv = None - for i in range(self._num_gaussians): - if image_conv is None: - image_conv = ndimage.filters.gaussian_filter(image, self._sigmas_scaled[i], mode='nearest', - truncate=self._truncation) * self._fraction_list[i] - else: - image_conv += ndimage.filters.gaussian_filter(image, self._sigmas_scaled[i], mode='nearest', - truncate=self._truncation) * self._fraction_list[i] - return image_conv
- -
[docs] def re_size_convolve(self, image_low_res, image_high_res): - """ - - :param image_high_res: supersampled image/model to be convolved on a regular pixel grid - :return: convolved and re-sized image - """ - if self._supersampling_convolution is True: - image_high_res_conv = self.convolution2d(image_high_res) - image_resized_conv = image_util.re_size(image_high_res_conv, self._supersampling_factor) - else: - image_resized_conv = self.convolution2d(image_low_res) - return image_resized_conv
- -
[docs] def pixel_kernel(self, num_pix): - """ - computes a pixelized kernel from the MGE parameters - - :param num_pix: int, size of kernel (odd number per axis) - :return: pixel kernel centered - """ - from lenstronomy.LightModel.Profiles.gaussian import MultiGaussian - mg = MultiGaussian() - x, y = util.make_grid(numPix=num_pix, deltapix=self._pixel_scale) - kernel = mg.function(x, y, amp=self._fraction_list, sigma=self._sigmas_scaled) - kernel = util.array2image(kernel) - return kernel / np.sum(kernel)
- - -
[docs]@export -class FWHMGaussianConvolution(object): - """ - uses a two-dimensional Gaussian function with same FWHM of given kernel as approximation - """ - def __init__(self, kernel, truncation=4): - """ - - :param kernel: 2d kernel - :param truncation: sigma scaling of kernel truncation - """ - fwhm = kernel_util.fwhm_kernel(kernel) - self._sigma = util.fwhm2sigma(fwhm) - self._truncation = truncation - -
[docs] def convolution2d(self, image): - """ - 2d convolution - - :param image: 2d numpy array, image to be convolved - :return: convolved image, 2d numpy array - """ - - image_conv = ndimage.filters.gaussian_filter(image, self._sigma, mode='nearest', truncate=self._truncation) - return image_conv
- - -
[docs]@export -class MGEConvolution(object): - """ - approximates a 2d kernel with an azimuthal Multi-Gaussian expansion - """ - def __init__(self, kernel, pixel_scale, order=1): - """ - - :param kernel: 2d convolution kernel (centered, odd axis number) - :param order: order of Multi-Gaussian Expansion - """ - amps, sigmas, norm = kernel_util.mge_kernel(kernel, order=order) - # make instance o MultiGaussian convolution kernel - self._mge_conv = MultiGaussianConvolution(sigma_list=sigmas*pixel_scale, fraction_list=np.array(amps) / np.sum(amps), - pixel_scale=pixel_scale, truncation=4) - self._kernel = kernel - # store difference between MGE approximation and real kernel - -
[docs] def convolution2d(self, image): - """ - - :param image: - :return: - """ - return self._mge_conv.convolution2d(image)
- -
[docs] def kernel_difference(self): - """ - - :return: difference between true kernel and MGE approximation - """ - kernel_mge = self._mge_conv.pixel_kernel(num_pix=len(self._kernel)) - return self._kernel - kernel_mge
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/grid.html b/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/grid.html deleted file mode 100644 index ab7fcab39..000000000 --- a/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/grid.html +++ /dev/null @@ -1,344 +0,0 @@ - - - - - - - - lenstronomy.ImSim.Numerics.grid — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.ImSim.Numerics.grid

-import numpy as np
-from lenstronomy.Util import util
-from lenstronomy.Util import image_util
-from lenstronomy.Data.coord_transforms import Coordinates1D
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -class AdaptiveGrid(Coordinates1D): - """ - manages a super-sampled grid on the partial image - """ - def __init__(self, nx, ny, transform_pix2angle, ra_at_xy_0, dec_at_xy_0, supersampling_indexes, - supersampling_factor, flux_evaluate_indexes=None): - """ - - :param nx: number of pixels in x-axis - :param ny: number of pixels in y-axis - :param transform_pix2angle: 2x2 matrix, mapping of pixel to coordinate - :param ra_at_xy_0: ra coordinate at pixel (0,0) - :param dec_at_xy_0: dec coordinate at pixel (0,0) - :param supersampling_indexes: bool array of shape nx x ny, corresponding to pixels being super_sampled - :param supersampling_factor: int, factor (per axis) of super-sampling - :param flux_evaluate_indexes: bool array of shape nx x ny, corresponding to pixels being evaluated - (for both low and high res). Default is None, replaced by setting all pixels to being evaluated. - """ - super(AdaptiveGrid, self).__init__(transform_pix2angle, ra_at_xy_0, dec_at_xy_0) - self._nx = nx - self._ny = ny - self._x_grid, self._y_grid = self.coordinate_grid(nx, ny) - if flux_evaluate_indexes is None: - flux_evaluate_indexes = np.ones_like(self._x_grid, dtype=bool) - supersampled_indexes1d = util.image2array(supersampling_indexes) - self._high_res_indexes1d = (supersampled_indexes1d) & (flux_evaluate_indexes) - self._low_res_indexes1d = (np.invert(supersampled_indexes1d)) & (flux_evaluate_indexes) - self._supersampling_factor = supersampling_factor - self._num_sub = supersampling_factor * supersampling_factor - self._x_low_res = self._x_grid[self._low_res_indexes1d] - self._y_low_res = self._y_grid[self._low_res_indexes1d] - self._num_low_res = len(self._x_low_res) - - @property - def coordinates_evaluate(self): - """ - - :return: 1d array of all coordinates being evaluated to perform the image computation - """ - ra_low, dec_low = self._x_low_res, self._y_low_res - ra_high, dec_high = self._high_res_coordinates - ra_joint = np.append(ra_low, ra_high) - dec_joint = np.append(dec_low, dec_high) - return ra_joint, dec_joint - -
[docs] def flux_array2image_low_high(self, flux_array, high_res_return=True): - """ - - :param flux_array: 1d array of low and high resolution flux values corresponding to the coordinates_evaluate order - :param high_res_return: bool, if True also returns the high resolution image - (needs more computation and is only needed when convolution is performed on the supersampling level) - :return: 2d array, 2d array, corresponding to (partial) images in low and high resolution (to be convolved) - """ - low_res_values = flux_array[0:self._num_low_res] - high_res_values = flux_array[self._num_low_res:] - image_low_res = self._merge_low_high_res(low_res_values, high_res_values) - if high_res_return is True: - image_high_res_partial = self._high_res_image(high_res_values) - else: - image_high_res_partial = None - return image_low_res, image_high_res_partial
- - @property - def _high_res_coordinates(self): - """ - - :return: 1d arrays of subpixel grid coordinates - """ - if not hasattr(self, '_x_sub_grid'): - self._subpixel_coordinates() - return self._x_high_res, self._y_high_res - - def _merge_low_high_res(self, low_res_values, supersampled_values): - """ - adds/overwrites the supersampled values on the image - - :param low_res_values: 1d array of image with low resolution - :param supersampled_values: values of the supersampled sub-pixels - :return: 2d image - """ - - array = np.zeros_like(self._x_grid) - array[self._low_res_indexes1d] = low_res_values - array_low_res_partial = self._average_subgrid(supersampled_values) - array[self._high_res_indexes1d] = array_low_res_partial - return util.array2image(array) - - def _high_res_image(self, supersampled_values): - """ - - :param supersampled_values: 1d array of supersampled values corresponding to coordinates - :return: 2d array of supersampled image (zeros outside supersampled frame) - """ - high_res = np.zeros((self._nx * self._supersampling_factor, self._ny * self._supersampling_factor)) - count = 0 - for i in range(self._supersampling_factor): - for j in range(self._supersampling_factor): - selected = supersampled_values[count::self._num_sub] - high_res[i::self._supersampling_factor, j::self._supersampling_factor] = self._array2image_subset( - selected) - count += 1 - return high_res - - def _subpixel_coordinates(self): - """ - - :return: 1d arrays of subpixel grid coordinates - """ - x_grid_select = self._x_grid[self._high_res_indexes1d] - y_grid_select = self._y_grid[self._high_res_indexes1d] - x_sub_grid = np.zeros(len(x_grid_select) * self._num_sub) - y_sub_grid = np.zeros(len(x_grid_select) * self._num_sub) - count = 0 - for i in range(self._supersampling_factor): - for j in range(self._supersampling_factor): - x_ij = 1. / self._supersampling_factor / 2. + j / float(self._supersampling_factor) - 1. / 2 - y_ij = 1. / self._supersampling_factor / 2. + i / float(self._supersampling_factor) - 1. / 2 - delta_ra, delta_dec = self.map_pix2coord(x_ij, y_ij) - delta_ra0, delta_dec_0 = self.map_pix2coord(0, 0) - x_sub_grid[count::self._num_sub] = x_grid_select + delta_ra - delta_ra0 - y_sub_grid[count::self._num_sub] = y_grid_select + delta_dec - delta_dec_0 - count += 1 - self._x_high_res = x_sub_grid - self._y_high_res = y_sub_grid - - def _average_subgrid(self, subgrid_values): - """ - averages the values over a pixel - - :param subgrid_values: values (e.g. flux) of subgrid coordinates - :return: 1d array of size of the supersampled pixels - """ - values_2d = np.reshape(subgrid_values, (-1, self._num_sub)) - return np.mean(values_2d, axis=1) - - def _array2image_subset(self, array): - """ - maps a 1d array into a (nx, ny) 2d grid with array populating the idex_mask indices - :param array: 1d array - :return: 2d array - """ - grid1d = np.zeros(self._nx * self._ny) - grid1d[self._high_res_indexes1d] = array - grid2d = util.array2image(grid1d, self._nx, self._ny) - return grid2d
- - -
[docs]@export -class RegularGrid(Coordinates1D): - """ - manages a super-sampled grid on the partial image - """ - def __init__(self, nx, ny, transform_pix2angle, ra_at_xy_0, dec_at_xy_0, supersampling_factor=1, - flux_evaluate_indexes=None): - """ - - :param nx: number of pixels in x-axis - :param ny: number of pixels in y-axis - :param transform_pix2angle: 2x2 matrix, mapping of pixel to coordinate - :param ra_at_xy_0: ra coordinate at pixel (0,0) - :param dec_at_xy_0: dec coordinate at pixel (0,0) - :param supersampling_factor: int, factor (per axis) of super-sampling - :param flux_evaluate_indexes: bool array of shape nx x ny, corresponding to pixels being evaluated - (for both low and high res). Default is None, replaced by setting all pixels to being evaluated. - """ - super(RegularGrid, self).__init__(transform_pix2angle, ra_at_xy_0, dec_at_xy_0) - self._supersampling_factor = supersampling_factor - self._nx = nx - self._ny = ny - self._x_grid, self._y_grid = self.coordinate_grid(nx, ny) - if flux_evaluate_indexes is None: - flux_evaluate_indexes = np.ones_like(self._x_grid, dtype=bool) - else: - flux_evaluate_indexes = util.image2array(flux_evaluate_indexes) - self._compute_indexes = self._subgrid_index(flux_evaluate_indexes, self._supersampling_factor, self._nx, self._ny) - - x_grid_sub, y_grid_sub = util.make_subgrid(self._x_grid, self._y_grid, self._supersampling_factor) - self._ra_subgrid = x_grid_sub[self._compute_indexes] - self._dec_subgrid = y_grid_sub[self._compute_indexes] - - @property - def coordinates_evaluate(self): - """ - - :return: 1d array of all coordinates being evaluated to perform the image computation - """ - return self._ra_subgrid, self._dec_subgrid - - @property - def grid_points_spacing(self): - """ - effective spacing between coordinate points, after supersampling - :return: sqrt(pixel_area)/supersampling_factor - """ - return self.pixel_width / self._supersampling_factor - - @property - def num_grid_points_axes(self): - """ - effective number of points along each axes, after supersampling - :return: number of pixels per axis, nx*supersampling_factor ny*supersampling_factor - """ - return self._nx * self._supersampling_factor, self._ny * self._supersampling_factor - - @property - def supersampling_factor(self): - """ - :return: factor (per axis) of super-sampling relative to a pixel - """ - return self._supersampling_factor - -
[docs] def flux_array2image_low_high(self, flux_array, **kwargs): - """ - - :param flux_array: 1d array of low and high resolution flux values corresponding to the coordinates_evaluate order - :return: 2d array, 2d array, corresponding to (partial) images in low and high resolution (to be convolved) - """ - image = self._array2image(flux_array) - if self._supersampling_factor > 1: - image_high_res = image - image_low_res = image_util.re_size(image, self._supersampling_factor) - else: - image_high_res = None - image_low_res = image - return image_low_res, image_high_res
- - @staticmethod - def _subgrid_index(idex_mask, subgrid_res, nx, ny): - """ - - :param idex_mask: 1d array of mask of data - :param subgrid_res: subgrid resolution - :return: 1d array of equivalent mask in subgrid resolution - """ - idex_sub = np.repeat(idex_mask, subgrid_res, axis=0) - idex_sub = util.array2image(idex_sub, nx=nx, ny=ny*subgrid_res) - idex_sub = np.repeat(idex_sub, subgrid_res, axis=0) - idex_sub = util.image2array(idex_sub) - return idex_sub - - def _array2image(self, array): - """ - maps a 1d array into a (nx, ny) 2d grid with array populating the idex_mask indices - - :param array: 1d array - :return: - """ - nx, ny = self._nx * self._supersampling_factor, self._ny * self._supersampling_factor - grid1d = np.zeros((nx * ny)) - grid1d[self._compute_indexes] = array - grid2d = util.array2image(grid1d, nx, ny) - return grid2d
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/numba_convolution.html b/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/numba_convolution.html deleted file mode 100644 index 3718219a0..000000000 --- a/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/numba_convolution.html +++ /dev/null @@ -1,305 +0,0 @@ - - - - - - - - lenstronomy.ImSim.Numerics.numba_convolution — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.ImSim.Numerics.numba_convolution

-import numpy as np
-
-from lenstronomy.Util import numba_util
-from lenstronomy.ImSim.Numerics.partial_image import PartialImage
-from lenstronomy.Util import image_util
-
-__all__ = ['NumbaConvolution']
-
-
-
[docs]class NumbaConvolution(object): - """ - class to convolve explicit pixels only - - the convolution is inspired by pyautolens: https://github.com/Jammy2211/PyAutoLens - """ - def __init__(self, kernel, conv_pixels, compute_pixels=None, nopython=True, cache=True, parallel=False, - memory_raise=True): - """ - - :param kernel: convolution kernel in units of the image pixels provided, odd length per axis - :param conv_pixels: bool array same size as data, pixels to be convolved and their light to be blurred - :param compute_pixels: bool array of size of image, these pixels (if True) will get blurred light from other - pixels - :param nopython: bool, numba jit setting to use python or compiled. - :param cache: bool, numba jit setting to use cache - :param parallel: bool, numba jit setting to use parallel mode - :param memory_raise: bool, if True, checks whether memory required to store the convolution kernel is within - certain bounds - """ - # numba_util.nopython = nopython - # numba_util.cache = cache - # numba_util.parallel = parallel - self._memory_raise = memory_raise - self._kernel = kernel - self._conv_pixels = conv_pixels - self._nx, self._ny = np.shape(conv_pixels) - if compute_pixels is None: - compute_pixels = np.ones_like(conv_pixels) - compute_pixels = np.array(compute_pixels, dtype=bool) - assert np.shape(conv_pixels) == np.shape(compute_pixels) - self._mask = compute_pixels - self._partialInput = PartialImage(partial_read_bools=conv_pixels) - self._partialOutput = PartialImage(partial_read_bools=compute_pixels) - index_array_out = self._partialOutput.index_array - index_array_input = self._partialInput.index_array - kernel_shape = kernel.shape - self.kernel_max_size = kernel_shape[0] * kernel_shape[1] - - image_index = 0 - if self._partialInput.num_partial * self.kernel_max_size > 10 ** 9 and self._memory_raise is True: - raise ValueError("kernel length %s combined with data size %s requires %s memory elements, which might" - "exceed the memory limit and thus gives a raise. If you wish to ignore this raise, set" - " memory_raise=False" % (self.kernel_max_size, self._partialInput.num_partial, self._partialInput.num_partial * self.kernel_max_size)) - self._image_frame_indexes = np.zeros((self._partialInput.num_partial, self.kernel_max_size), dtype='int') - self._image_frame_psfs = np.zeros((self._partialInput.num_partial, self.kernel_max_size)) - self._image_frame_lengths = np.zeros((self._partialInput.num_partial), dtype='int') - for x in range(index_array_input.shape[0]): - for y in range(index_array_input.shape[1]): - if conv_pixels[x][y]: - image_frame_psfs, image_frame_indexes, frame_length = self._pre_compute_frame_kernel((x, y), - self._kernel[:, :], - compute_pixels, - index_array_out) - - self._image_frame_indexes[image_index, :] = image_frame_indexes - self._image_frame_psfs[image_index, :] = image_frame_psfs - self._image_frame_lengths[image_index] = frame_length - image_index += 1 - -
[docs] def convolve2d(self, image): - """ - 2d convolution - - :param image: 2d numpy array, image to be convolved - :return: convolved image, 2d numpy array - """ - image_array_partial = self._partialInput.partial_array(image) - conv_array = self._convolve_jit(image_array_partial, num_data=self._partialOutput.num_partial, - image_frame_kernels=self._image_frame_psfs, - image_frame_indexes=self._image_frame_indexes, - image_frame_lengths=self._image_frame_lengths) - conv_image = self._partialOutput.image_from_partial(conv_array) - return conv_image
- - @staticmethod - @numba_util.jit() - def _pre_compute_frame_kernel(image_index, kernel, mask, index_array): - """ - - :param image_index: (int, int) index of pixels - :param kernel: kernel, 2d rectangular array - :param mask: mask (size of full image) - :return: - frame_kernels: values of kernel - frame_indexes: (int) 1d index corresponding to the pixel receiving the kernel value - frame_counter: number of pixels with non-zero addition due to kernel convolution - """ - kernel_shape = kernel.shape - i0, j0 = image_index - kx, ky = kernel_shape[0], kernel_shape[1] - mask_shape = index_array.shape - nx, ny = mask_shape[0], mask_shape[1] - kx2 = int((kx - 1) / 2) - ky2 = int((ky - 1) / 2) - frame_counter = 0 - frame_kernels = np.zeros(kx*ky) - frame_indexes = np.zeros(kx*ky) - - for i in range(kx): - for j in range(ky): - x = i0 + i - kx2 - y = j0 + j - ky2 - if 0 <= x < nx and 0 <= y < ny: - if mask[x, y]: - frame_indexes[frame_counter] = index_array[x, y] - frame_kernels[frame_counter] = kernel[i, j] - frame_counter += 1 - return frame_kernels, frame_indexes, frame_counter - - @staticmethod - @numba_util.jit() - def _convolve_jit(image_array, num_data, image_frame_kernels, image_frame_indexes, image_frame_lengths): - """ - - :param image_array: selected subset of image in 1d array conventions - :param num_data: number of 1d data that get convolved light and are output - :param image_frame_kernels: list of indexes that have a response for certain pixel (as a list - :param image_frame_lengths: length of image_frame_kernels - :return: - """ - conv_array = np.zeros(num_data) - for image_index in range(len(image_array)): # loop through pixels that are to be blurred - value = image_array[image_index] # value of pixel that gets blurred - frame_length = image_frame_lengths[image_index] # number of pixels that gets assigned a fraction of the convolution - frame_indexes = image_frame_indexes[image_index] # list of 1d indexes that get added flux from the blurred image - frame_kernels = image_frame_kernels[image_index] # values of kernel for each frame indexes - for kernel_index in range(frame_length): # loop through all pixels that are impacted by the kernel of the pixel being blurred - vector_index = frame_indexes[kernel_index] # 1d coordinate of pixel to be added value - kernel = frame_kernels[kernel_index] # kernel response of pixel - conv_array[vector_index] += value * kernel # ad value to pixel - return conv_array
- - -class SubgridNumbaConvolution(object): - """ - class that inputs a supersampled grid and convolution kernel and computes the response on the regular grid - This makes use of the regualr NumbaConvolution class as a loop through the different sub-pixel positions - """ - - def __init__(self, kernel_super, supersampling_factor, conv_pixels, compute_pixels=None, kernel_size=None, nopython=True, cache=True, parallel=False): - """ - - :param kernel_super: convolution kernel in units of super sampled pixels provided, odd length per axis - :param supersampling_factor: factor of supersampling relative to pixel grid - :param conv_pixels: bool array same size as data, pixels to be convolved and their light to be blurred - :param compute_pixels: bool array of size of image, these pixels (if True) will get blurred light from other pixels - :param nopython: bool, numba jit setting to use python or compiled. - :param cache: bool, numba jit setting to use cache - :param parallel: bool, numba jit setting to use parallel mode - """ - self._nx, self._ny = conv_pixels.shape - self._supersampling_factor = supersampling_factor - # loop through the different supersampling sectors - self._numba_conv_list = [] - if compute_pixels is None: - compute_pixels = np.ones_like(conv_pixels) - compute_pixels = np.array(compute_pixels, dtype=bool) - - for i in range(supersampling_factor): - for j in range(supersampling_factor): - # compute shifted psf kernel - kernel = self._partial_kernel(kernel_super, i, j) - if kernel_size is not None: - kernel = image_util.cut_edges(kernel, kernel_size) - numba_conv = NumbaConvolution(kernel, conv_pixels, compute_pixels=compute_pixels, nopython=nopython, cache=cache, parallel=parallel) - self._numba_conv_list.append(numba_conv) - - def convolve2d(self, image_high_res): - """ - - :param image_high_res: supersampled image/model to be convolved and re-bined to regular resolution - :return: convolved and re-bind image - """ - conv_image = np.zeros((self._nx, self._ny)) - count = 0 - for i in range(self._supersampling_factor): - for j in range(self._supersampling_factor): - image_select = self._partial_image(image_high_res, i, j) - conv_image += self._numba_conv_list[count].convolve2d(image_select) - count += 1 - return conv_image - - def _partial_image(self, image_high_res, i, j): - """ - - :param image_high_res: 2d array supersampled - :param i: index of super-sampled position in first axis - :param j: index of super-sampled position in second axis - :return: 2d array only selected the specific supersampled position within a regular pixel - """ - return image_high_res[i::self._supersampling_factor, j::self._supersampling_factor] - - def _partial_kernel(self, kernel_super, i, j): - """ - - :param kernel_super: supersampled kernel - :param i: index of super-sampled position in first axis - :param j: index of super-sampled position in second axis - :return: effective kernel rebinned to regular grid resulting from the subpersampled position (i,j) - """ - n = len(kernel_super) - kernel_size = int(round(n / float(self._supersampling_factor) + 1.5)) - if kernel_size % 2 == 0: - kernel_size += 1 - n_match = kernel_size * self._supersampling_factor - kernel_super_match = np.zeros((n_match, n_match)) - delta = int((n_match - n - self._supersampling_factor) / 2) + 1 - i0 = delta # index where to start kernel for i=0 - j0 = delta # index where to start kernel for j=0 (should be symmetric) - kernel_super_match[i0 + i:i0 + i + n, j0 + j:j0 + j + n] = kernel_super - #kernel_super_match = image_util.cut_edges(kernel_super_match, numPix=n) - kernel = image_util.re_size(kernel_super_match, factor=self._supersampling_factor) - return kernel -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/numerics.html b/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/numerics.html deleted file mode 100644 index a54a644f5..000000000 --- a/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/numerics.html +++ /dev/null @@ -1,255 +0,0 @@ - - - - - - - - lenstronomy.ImSim.Numerics.numerics — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.ImSim.Numerics.numerics

-from lenstronomy.ImSim.Numerics.grid import RegularGrid, AdaptiveGrid
-from lenstronomy.ImSim.Numerics.convolution import SubgridKernelConvolution, PixelKernelConvolution, MultiGaussianConvolution
-from lenstronomy.ImSim.Numerics.point_source_rendering import PointSourceRendering
-from lenstronomy.Util import util
-from lenstronomy.Util import kernel_util
-import numpy as np
-
-__all__ = ['Numerics']
-
-
-
[docs]class Numerics(PointSourceRendering): - """ - this classes manages the numerical options and computations of an image. - The class has two main functions, re_size_convolve() and coordinates_evaluate() - """ - def __init__(self, pixel_grid, psf, supersampling_factor=1, compute_mode='regular', supersampling_convolution=False, - supersampling_kernel_size=5, flux_evaluate_indexes=None, supersampled_indexes=None, - compute_indexes=None, point_source_supersampling_factor=1, convolution_kernel_size=None, - convolution_type='fft_static', truncation=4): - """ - - :param pixel_grid: PixelGrid() class instance - :param psf: PSF() class instance - :param compute_mode: options are: 'regular', 'adaptive' - :param supersampling_factor: int, factor of higher resolution sub-pixel sampling of surface brightness - :param supersampling_convolution: bool, if True, performs (part of) the convolution on the super-sampled - grid/pixels - :param supersampling_kernel_size: int (odd number), size (in regular pixel units) of the super-sampled - convolution - :param flux_evaluate_indexes: boolean 2d array of size of image (or None, then initiated as gird of True's). - Pixels indicated with True will be used to perform the surface brightness computation (and possible lensing - ray-shooting). Pixels marked as False will be assigned a flux value of zero (or ignored in the adaptive - convolution) - :param supersampled_indexes: 2d boolean array (only used in mode='adaptive') of pixels to be supersampled (in - surface brightness and if supersampling_convolution=True also in convolution). All other pixels not set to =True - will not be super-sampled. - :param compute_indexes: 2d boolean array (only used in compute_mode='adaptive'), marks pixel that the response after - convolution is computed (all others =0). This can be set to likelihood_mask in the Likelihood module for - consistency. - :param point_source_supersampling_factor: super-sampling resolution of the point source placing - :param convolution_kernel_size: int, odd number, size of convolution kernel. If None, takes size of point_source_kernel - :param convolution_type: string, 'fft', 'grid', 'fft_static' mode of 2d convolution - """ - if compute_mode not in ['regular', 'adaptive']: - raise ValueError('compute_mode specified as %s not valid. Options are "adaptive", "regular"') - # if no super sampling, turn the supersampling convolution off - self._psf_type = psf.psf_type - if not isinstance(supersampling_factor, int): - raise TypeError('supersampling_factor needs to be an integer! Current type is %s' % type(supersampling_factor)) - if supersampling_factor == 1: - supersampling_convolution = False - self._pixel_width = pixel_grid.pixel_width - nx, ny = pixel_grid.num_pixel_axes - transform_pix2angle = pixel_grid.transform_pix2angle - ra_at_xy_0, dec_at_xy_0 = pixel_grid.radec_at_xy_0 - if supersampled_indexes is None: - supersampled_indexes = np.zeros((nx, ny), dtype=bool) - if compute_mode == 'adaptive': # or (compute_mode == 'regular' and supersampling_convolution is False and supersampling_factor > 1): - self._grid = AdaptiveGrid(nx, ny, transform_pix2angle, ra_at_xy_0, dec_at_xy_0, supersampled_indexes, - supersampling_factor, flux_evaluate_indexes) - else: - self._grid = RegularGrid(nx, ny, transform_pix2angle, ra_at_xy_0, dec_at_xy_0, supersampling_factor, - flux_evaluate_indexes) - if self._psf_type == 'PIXEL': - if compute_mode == 'adaptive' and supersampling_convolution is True: - from lenstronomy.ImSim.Numerics.adaptive_numerics import AdaptiveConvolution - kernel_super = psf.kernel_point_source_supersampled(supersampling_factor) - kernel_super = self._supersampling_cut_kernel(kernel_super, convolution_kernel_size, supersampling_factor) - self._conv = AdaptiveConvolution(kernel_super, supersampling_factor, - conv_supersample_pixels=supersampled_indexes, - supersampling_kernel_size=supersampling_kernel_size, - compute_pixels=compute_indexes, nopython=True, cache=True, parallel=False) - - elif compute_mode == 'regular' and supersampling_convolution is True: - kernel_super = psf.kernel_point_source_supersampled(supersampling_factor) - if convolution_kernel_size is not None: - kernel_super = psf.kernel_point_source_supersampled(supersampling_factor) - kernel_super = self._supersampling_cut_kernel(kernel_super, convolution_kernel_size, - supersampling_factor) - self._conv = SubgridKernelConvolution(kernel_super, supersampling_factor, - supersampling_kernel_size=supersampling_kernel_size, - convolution_type=convolution_type) - else: - kernel = psf.kernel_point_source - kernel = self._supersampling_cut_kernel(kernel, convolution_kernel_size, - supersampling_factor=1) - self._conv = PixelKernelConvolution(kernel, convolution_type=convolution_type) - - elif self._psf_type == 'GAUSSIAN': - pixel_scale = pixel_grid.pixel_width - fwhm = psf.fwhm # FWHM in units of angle - sigma = util.fwhm2sigma(fwhm) - sigma_list = [sigma] - fraction_list = [1] - self._conv = MultiGaussianConvolution(sigma_list, fraction_list, pixel_scale, supersampling_factor, - supersampling_convolution, truncation=truncation) - elif self._psf_type == 'NONE': - self._conv = None - else: - raise ValueError('psf_type %s not valid! Chose either NONE, GAUSSIAN or PIXEL.' % self._psf_type) - super(Numerics, self).__init__(pixel_grid=pixel_grid, supersampling_factor=point_source_supersampling_factor, - psf=psf) - if supersampling_convolution is True: - self._high_res_return = True - else: - self._high_res_return = False - -
[docs] def re_size_convolve(self, flux_array, unconvolved=False): - """ - - :param flux_array: 1d array, flux values corresponding to coordinates_evaluate - :param unconvolved: boolean, if True, does not apply a convolution - :return: convolved image on regular pixel grid, 2d array - """ - # add supersampled region to lower resolution on - image_low_res, image_high_res_partial = self._grid.flux_array2image_low_high(flux_array, - high_res_return=self._high_res_return) - if unconvolved is True or self._psf_type == 'NONE': - image_conv = image_low_res - else: - # convolve low res grid and high res grid - image_conv = self._conv.re_size_convolve(image_low_res, image_high_res_partial) - return image_conv * self._pixel_width ** 2
- - @property - def grid_supersampling_factor(self): - """ - - :return: supersampling factor set for higher resolution sub-pixel sampling of surface brightness - """ - return self._grid.supersampling_factor - - @property - def coordinates_evaluate(self): - """ - - :return: 1d array of all coordinates being evaluated to perform the image computation - """ - return self._grid.coordinates_evaluate - - @staticmethod - def _supersampling_cut_kernel(kernel_super, convolution_kernel_size, supersampling_factor): - """ - - :param kernel_super: super-sampled kernel - :param convolution_kernel_size: size of convolution kernel in units of regular pixels (odd) - :param supersampling_factor: super-sampling factor of convolution kernel - :return: cut out kernel in super-sampling size - """ - if convolution_kernel_size is not None: - size = convolution_kernel_size * supersampling_factor - if size % 2 == 0: - size += 1 - kernel_cut = kernel_util.cut_psf(kernel_super, size) - return kernel_cut - else: - return kernel_super - - @property - def convolution_class(self): - """ - - :return: convolution class (can be SubgridKernelConvolution, PixelKernelConvolution, MultiGaussianConvolution, ...) - """ - return self._conv - - @property - def grid_class(self): - """ - - :return: grid class (can be RegularGrid, AdaptiveGrid) - """ - return self._grid
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/partial_image.html b/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/partial_image.html deleted file mode 100644 index 46bffcc51..000000000 --- a/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/partial_image.html +++ /dev/null @@ -1,151 +0,0 @@ - - - - - - - - lenstronomy.ImSim.Numerics.partial_image — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.ImSim.Numerics.partial_image

-import numpy as np
-import lenstronomy.Util.util as util
-
-__all__ = ['PartialImage']
-
-
-
[docs]class PartialImage(object): - """ - class to deal with the use of partial slicing of a 2d data array, to be used for various computations where only - a subset of pixels need to be know. - """ - def __init__(self, partial_read_bools): - """ - - :param partial_read_bools: 2d numpy array of bools indicating which indexes to be processed - """ - self._partial_read_bools = np.array(partial_read_bools, dtype=bool) - self._nx, self._ny = np.shape(partial_read_bools) - self._partial_read_bools_array = util.image2array(partial_read_bools) - self._num_partial = int(np.sum(self._partial_read_bools_array)) - -
[docs] def partial_array(self, image): - """ - - :param image: 2d array - :return: 1d array of partial list - """ - array = util.image2array(image) - return array[self._partial_read_bools_array]
- - @property - def index_array(self): - """ - - :return: 2d array with indexes (integers) corresponding to the 1d array, -1 when masked - """ - if not hasattr(self, '_index_array'): - full_array = -1 * np.ones(len(self._partial_read_bools_array)) - num_array = np.linspace(start=0, stop=self.num_partial-1, num=self.num_partial) - full_array[self._partial_read_bools_array] = num_array - self._index_array = util.array2image(full_array, nx=self._nx, ny=self._ny) - return self._index_array - -
[docs] def array_from_partial(self, partial_array): - """ - - :param partial_array: 1d array of the partial indexes - :return: full 1d array - """ - full_array = np.zeros(len(self._partial_read_bools_array)) - full_array[self._partial_read_bools_array] = partial_array - return full_array
- -
[docs] def image_from_partial(self, partial_array): - """ - - :param partial_array: 1d array corresponding to the indexes of the partial read - :return: full image with zeros elsewhere - """ - array = self.array_from_partial(partial_array) - return util.array2image(array, nx=self._nx, ny=self._ny)
- - @property - def num_partial(self): - """ - - :return: number of indexes handled in the partial section - """ - return self._num_partial
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/point_source_rendering.html b/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/point_source_rendering.html deleted file mode 100644 index 634af08a5..000000000 --- a/docs/_build/html/_modules/lenstronomy/ImSim/Numerics/point_source_rendering.html +++ /dev/null @@ -1,157 +0,0 @@ - - - - - - - - lenstronomy.ImSim.Numerics.point_source_rendering — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.ImSim.Numerics.point_source_rendering

-from lenstronomy.Util import image_util
-from lenstronomy.Util import kernel_util
-import numpy as np
-
-__all__ = ['PointSourceRendering']
-
-
-
[docs]class PointSourceRendering(object): - """ - numerics to compute the point source response on an image - """ - def __init__(self, pixel_grid, supersampling_factor, psf): - """ - - :param pixel_grid: PixelGrid() instance - :param supersampling_factor: int, factor of supersampling of point source - :param psf: PSF() instance - """ - self._pixel_grid = pixel_grid - self._nx, self._ny = self._pixel_grid.num_pixel_axes - self._supersampling_factor = supersampling_factor - self._psf = psf - -
[docs] def point_source_rendering(self, ra_pos, dec_pos, amp): - """ - - :param ra_pos: list of RA positions of point source(s) - :param dec_pos: list of DEC positions of point source(s) - :param amp: list of amplitudes of point source(s) - :return: 2d numpy array of size of the image with the point source(s) rendered - """ - subgrid = self._supersampling_factor - x_pos, y_pos = self._pixel_grid.map_coord2pix(ra_pos, dec_pos) - # translate coordinates to higher resolution grid - x_pos_subgird = x_pos * subgrid + (subgrid - 1) / 2. - y_pos_subgrid = y_pos * subgrid + (subgrid - 1) / 2. - kernel_point_source_subgrid = self._kernel_supersampled - # initialize grid with higher resolution - subgrid2d = np.zeros((self._nx*subgrid, self._ny*subgrid)) - # add_layer2image - if len(x_pos) > len(amp): - raise ValueError('there are %s images appearing but only %s amplitudes provided!' % (len(x_pos), len(amp))) - for i in range(len(x_pos)): - subgrid2d = image_util.add_layer2image(subgrid2d, x_pos_subgird[i], y_pos_subgrid[i], amp[i] * kernel_point_source_subgrid) - # re-size grid to data resolution - grid2d = image_util.re_size(subgrid2d, factor=subgrid) - return grid2d*subgrid**2
- - @property - def _kernel_supersampled(self): - if not hasattr(self, '_kernel_supersampled_instance'): - self._kernel_supersampled_instance = self._psf.kernel_point_source_supersampled(self._supersampling_factor, updata_cache=False) - return self._kernel_supersampled_instance - -
[docs] def psf_error_map(self, ra_pos, dec_pos, amp, data, fix_psf_error_map=False): - """ - - :param ra_pos: image positions of point sources - :param dec_pos: image positions of point sources - :param amp: amplitude of modeled point sources - :param data: 2d numpy array of the data - :param fix_psf_error_map: bool, if True, estimates the error based on the imput (modeled) amplitude, else uses the data to do so. - :return: 2d array of size of the image with error terms (sigma**2) expected from inaccuracies in the PSF modeling - """ - x_pos, y_pos = self._pixel_grid.map_coord2pix(ra_pos, dec_pos) - psf_kernel = self._psf.kernel_point_source - psf_error_map = self._psf.psf_error_map - error_map = np.zeros_like(data) - for i in range(len(x_pos)): - if fix_psf_error_map is True: - amp_estimated = amp - else: - amp_estimated = kernel_util.estimate_amp(data, x_pos[i], y_pos[i], psf_kernel) - error_map = image_util.add_layer2image(error_map, x_pos[i], y_pos[i], psf_error_map * (psf_kernel * amp_estimated) ** 2) - return error_map
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/ImSim/de_lens.html b/docs/_build/html/_modules/lenstronomy/ImSim/de_lens.html deleted file mode 100644 index 1b0e8894e..000000000 --- a/docs/_build/html/_modules/lenstronomy/ImSim/de_lens.html +++ /dev/null @@ -1,187 +0,0 @@ - - - - - - - - lenstronomy.ImSim.de_lens — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.ImSim.de_lens

-__author__ = 'sibirrer'
-
-import numpy as np
-import sys
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -def get_param_WLS(A, C_D_inv, d, inv_bool=True): - """ - returns the parameter values given - :param A: response matrix Nd x Ns (Nd = # data points, Ns = # parameters) - :param C_D_inv: inverse covariance matrix of the data, Nd x Nd, diagonal form - :param d: data array, 1-d Nd - :param inv_bool: boolean, wheter returning also the inverse matrix or just solve the linear system - :return: 1-d array of parameter values - """ - M = A.T.dot(np.multiply(C_D_inv, A.T).T) - if inv_bool: - if np.linalg.cond(M) < 5/sys.float_info.epsilon: - M_inv = _stable_inv(M) - else: - M_inv = np.zeros_like(M) - R = A.T.dot(np.multiply(C_D_inv, d)) - B = M_inv.dot(R) - else: - if np.linalg.cond(M) < 5/sys.float_info.epsilon: - R = A.T.dot(np.multiply(C_D_inv, d)) - B = _solve_stable(M, R) - # try: - # B = np.linalg.solve(M, R).T - # except: - # B = np.zeros(len(A.T)) - else: - B = np.zeros(len(A.T)) - M_inv = None - image = A.dot(B) - return B, M_inv, image
- - -
[docs]@export -def marginalisation_const(M_inv): - """ - get marginalisation constant 1/2 log(M_beta) for flat priors - :param M_inv: 2D covariance matrix - :return: float - """ - - sign, log_det = np.linalg.slogdet(M_inv) - if sign == 0: - return -10**15 - return sign * log_det/2
- - -
[docs]@export -def marginalization_new(M_inv, d_prior=None): - """ - - :param M_inv: 2D covariance matrix - :param d_prior: maximum prior length of linear parameters - :return: log determinant with eigenvalues to be smaller or equal d_prior - """ - if d_prior is None: - return marginalisation_const(M_inv) - v, w = np.linalg.eig(M_inv) - sign_v = np.sign(v) - v_abs = np.abs(v) - - v_abs[v_abs > d_prior**2] = d_prior**2 - log_det = np.sum(np.log(v_abs)) * np.prod(sign_v) - if np.isnan(log_det): - return -10**15 - m = len(v) - return log_det / 2 + m/2. * np.log(np.pi/2.) - m * np.log(d_prior)
- - -def _stable_inv(m): - """ - stable linear inversion - - :param m: square matrix to be inverted - :return: inverse of M (or zeros) - """ - try: - m_inv = np.linalg.inv(m) - except: - m_inv = np.zeros_like(m) - return m_inv - - -def _solve_stable(m, r): - """ - - :param m: matrix - :param r: vector - :return: solution for B = M x R - """ - try: - b = np.linalg.solve(m, r).T - except: - n = np.shape(m)[0] - b = np.zeros(n) - return b -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/ImSim/image2source_mapping.html b/docs/_build/html/_modules/lenstronomy/ImSim/image2source_mapping.html deleted file mode 100644 index 2abc6e953..000000000 --- a/docs/_build/html/_modules/lenstronomy/ImSim/image2source_mapping.html +++ /dev/null @@ -1,320 +0,0 @@ - - - - - - - - lenstronomy.ImSim.image2source_mapping — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.ImSim.image2source_mapping

-import numpy as np
-from lenstronomy.Cosmo.background import Background
-
-__all__ = ['Image2SourceMapping']
-
-
-
[docs]class Image2SourceMapping(object): - """ - this class handles multiple source planes and performs the computation of predicted surface brightness at given - image positions. - The class is enable to deal with an arbitrary number of different source planes. There are two different settings: - - Single lens plane modelling: - In case of a single deflector, lenstronomy models the reduced deflection angles - (matched to the source plane in single source plane mode). Each source light model can be added a number - (scale_factor) that rescales the reduced deflection angle to the specific source plane. - - Multiple lens plane modelling: - The multi-plane lens modelling requires the assumption of a cosmology and the redshifts of the multiple lens and - source planes. The backwards ray-tracing is performed and stopped at the different source plane redshift to compute - the mapping between source to image plane. - """ - - def __init__(self, lensModel, sourceModel): - """ - - :param lensModel: lenstronomy LensModel() class instance - :param sourceModel: LightModel () class instance - The lightModel includes: - - source_scale_factor_list: list of floats corresponding to the rescaled deflection angles to the specific source - components. None indicates that the list will be set to 1, meaning a single source plane model (in single lens plane mode). - - source_redshift_list: list of redshifts of the light components (in multi lens plane mode) - """ - self._lightModel = sourceModel - self._lensModel = lensModel - light_model_list = sourceModel.profile_type_list - self._multi_lens_plane = lensModel.multi_plane - self._source_redshift_list = sourceModel.redshift_list - self._deflection_scaling_list = sourceModel.deflection_scaling_list - self._multi_source_plane = True - if self._multi_lens_plane is True: - if self._deflection_scaling_list is not None: - raise ValueError('deflection scaling for different source planes not possible in combination of ' - 'multi-lens plane modeling. You have to specify the redshifts of the sources instead.') - self._bkg_cosmo = Background(lensModel.cosmo) - if self._source_redshift_list is None: - self._multi_source_plane = False - elif len(self._source_redshift_list) != len(light_model_list): - raise ValueError("length of redshift_list must correspond to length of light_model_list") - elif np.max(self._source_redshift_list) > self._lensModel.z_source: - raise ValueError("redshift of source_redshift_list have to be smaler or equal to the one specified in " - "the lens model.") - else: - self._sorted_source_redshift_index = self._index_ordering(self._source_redshift_list) - self._T0z_list = [] - for z_stop in self._source_redshift_list: - self._T0z_list.append(self._bkg_cosmo.T_xy(0, z_stop)) - z_start = 0 - self._T_ij_start_list = [] - self._T_ij_end_list = [] - for i, index_source in enumerate(self._sorted_source_redshift_index): - z_stop = self._source_redshift_list[index_source] - T_ij_start, T_ij_end = self._lensModel.lens_model.transverse_distance_start_stop(z_start, z_stop, include_z_start=False) - self._T_ij_start_list.append(T_ij_start) - self._T_ij_end_list.append(T_ij_end) - z_start = z_stop - else: - if self._deflection_scaling_list is None: - self._multi_source_plane = False - elif len(self._deflection_scaling_list) != len(light_model_list): - raise ValueError('length of scale_factor_list must correspond to length of light_model_list!') - -
[docs] def image2source(self, x, y, kwargs_lens, index_source): - """ - mapping of image plane to source plane coordinates - WARNING: for multi lens plane computations and multi source planes, this computation can be slow and should be - used as rarely as possible. - - :param x: image plane coordinate (angle) - :param y: image plane coordinate (angle) - :param kwargs_lens: lens model kwargs list - :param index_source: int, index of source model - :return: source plane coordinate corresponding to the source model of index idex_source - """ - if self._multi_source_plane is False: - x_source, y_source = self._lensModel.ray_shooting(x, y, kwargs_lens) - else: - if self._multi_lens_plane is False: - x_alpha, y_alpha = self._lensModel.alpha(x, y, kwargs_lens) - scale_factor = self._deflection_scaling_list[index_source] - x_source = x - x_alpha * scale_factor - y_source = y - y_alpha * scale_factor - else: - z_stop = self._source_redshift_list[index_source] - x_ = np.zeros_like(x) - y_ = np.zeros_like(y) - x_comov, y_comov, alpha_x, alpha_y = self._lensModel.lens_model.ray_shooting_partial(x_, y_, x, y, - 0, z_stop, - kwargs_lens, - include_z_start=False) - - T_z = self._T0z_list[index_source] - x_source = x_comov / T_z - y_source = y_comov / T_z - return x_source, y_source
- -
[docs] def image_flux_joint(self, x, y, kwargs_lens, kwargs_source, k=None): - """ - - :param x: coordinate in image plane - :param y: coordinate in image plane - :param kwargs_lens: lens model kwargs list - :param kwargs_source: source model kwargs list - :param k: None or int or list of int for partial evaluation of light models - :return: surface brightness of all joint light components at image position (x, y) - """ - if self._multi_source_plane is False: - x_source, y_source = self._lensModel.ray_shooting(x, y, kwargs_lens) - return self._lightModel.surface_brightness(x_source, y_source, kwargs_source, k=k) - else: - flux = np.zeros_like(x) - if self._multi_lens_plane is False: - x_alpha, y_alpha = self._lensModel.alpha(x, y, kwargs_lens) - for i in range(len(self._deflection_scaling_list)): - scale_factor = self._deflection_scaling_list[i] - x_source = x - x_alpha * scale_factor - y_source = y - y_alpha * scale_factor - if k is None or k ==i: - flux += self._lightModel.surface_brightness(x_source, y_source, kwargs_source, k=i) - else: - x_comov = np.zeros_like(x) - y_comov = np.zeros_like(y) - alpha_x, alpha_y = x, y - x_source, y_source = alpha_x, alpha_y - z_start = 0 - for i, index_source in enumerate(self._sorted_source_redshift_index): - z_stop = self._source_redshift_list[index_source] - if z_stop > z_start: - T_ij_start = self._T_ij_start_list[i] - T_ij_end = self._T_ij_end_list[i] - x_comov, y_comov, alpha_x, alpha_y = self._lensModel.lens_model.ray_shooting_partial(x_comov, y_comov, alpha_x, alpha_y, z_start, z_stop, - kwargs_lens, include_z_start=False, - T_ij_start=T_ij_start, T_ij_end=T_ij_end) - - T_z = self._T0z_list[index_source] - x_source = x_comov / T_z - y_source = y_comov / T_z - if k is None or k == i: - flux += self._lightModel.surface_brightness(x_source, y_source, kwargs_source, k=index_source) - z_start = z_stop - return flux
- -
[docs] def image_flux_split(self, x, y, kwargs_lens, kwargs_source): - """ - - :param x: coordinate in image plane - :param y: coordinate in image plane - :param kwargs_lens: lens model kwargs list - :param kwargs_source: source model kwargs list - :return: list of responses of every single basis component with default amplitude amp=1, in the same order as the light_model_list - """ - if self._multi_source_plane is False: - x_source, y_source = self._lensModel.ray_shooting(x, y, kwargs_lens) - return self._lightModel.functions_split(x_source, y_source, kwargs_source) - else: - response = [] - n = 0 - if self._multi_lens_plane is False: - x_alpha, y_alpha = self._lensModel.alpha(x, y, kwargs_lens) - for i in range(len(self._deflection_scaling_list)): - scale_factor = self._deflection_scaling_list[i] - x_source = x - x_alpha * scale_factor - y_source = y - y_alpha * scale_factor - response_i, n_i = self._lightModel.functions_split(x_source, y_source, kwargs_source, k=i) - response += response_i - n += n_i - else: - n_i_list = [] - x_comov = np.zeros_like(x) - y_comov = np.zeros_like(y) - alpha_x, alpha_y = x, y - x_source, y_source = alpha_x, alpha_y - z_start = 0 - for i, index_source in enumerate(self._sorted_source_redshift_index): - z_stop = self._source_redshift_list[index_source] - if z_stop > z_start: - T_ij_start = self._T_ij_start_list[i] - T_ij_end = self._T_ij_end_list[i] - x_comov, y_comov, alpha_x, alpha_y = self._lensModel.lens_model.ray_shooting_partial(x_comov, - y_comov, alpha_x, alpha_y, z_start, z_stop, kwargs_lens, - include_z_start=False, T_ij_start=T_ij_start, - T_ij_end=T_ij_end) - T_z = self._T0z_list[index_source] - x_source = x_comov / T_z - y_source = y_comov / T_z - response_i, n_i = self._lightModel.functions_split(x_source, y_source, kwargs_source, k=index_source) - n_i_list.append(n_i) - response += response_i - n += n_i - z_start = z_stop - n_list = self._lightModel.num_param_linear_list(kwargs_source) - response = self._re_order_split(response, n_list) - - return response, n
- - @staticmethod - def _index_ordering(redshift_list): - """ - - :param redshift_list: list of redshifts - :return: indexes in ascending order to be evaluated (from z=0 to z=z_source) - """ - redshift_list = np.array(redshift_list) - sort_index = np.argsort(redshift_list) - return sort_index - - def _re_order_split(self, response, n_list): - """ - - :param response: splitted functions in order of redshifts - :param n_list: list of number of response vectors per model in order of the model list (not redshift ordered) - :return: reshuffled array in order of the function definition - """ - counter_regular = 0 - n_sum_list_regular = [] - - for i in range(len(self._source_redshift_list)): - n_sum_list_regular += [counter_regular] - counter_regular += n_list[i] - - reshuffled = np.zeros_like(response) - n_sum_sorted = 0 - for i, index in enumerate(self._sorted_source_redshift_index): - n_i = n_list[index] - n_sum = n_sum_list_regular[index] - reshuffled[n_sum:n_sum + n_i] = response[n_sum_sorted:n_sum_sorted + n_i] - n_sum_sorted += n_i - return reshuffled
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/ImSim/image_linear_solve.html b/docs/_build/html/_modules/lenstronomy/ImSim/image_linear_solve.html deleted file mode 100644 index dad825f33..000000000 --- a/docs/_build/html/_modules/lenstronomy/ImSim/image_linear_solve.html +++ /dev/null @@ -1,579 +0,0 @@ - - - - - - - - lenstronomy.ImSim.image_linear_solve — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.ImSim.image_linear_solve

-from lenstronomy.ImSim.image_model import ImageModel
-import lenstronomy.ImSim.de_lens as de_lens
-from lenstronomy.Util import util
-import numpy as np
-
-__all__ = ['ImageLinearFit']
-
-
-
[docs]class ImageLinearFit(ImageModel): - """ - linear version class, inherits ImageModel. - - When light models use pixel-based profile types, such as 'SLIT_STARLETS', - the WLS linear inversion is replaced by the regularized inversion performed by an external solver. - The current pixel-based solver is provided by the SLITronomy plug-in. - """ - def __init__(self, data_class, psf_class=None, lens_model_class=None, source_model_class=None, - lens_light_model_class=None, point_source_class=None, extinction_class=None, - kwargs_numerics=None, likelihood_mask=None, - psf_error_map_bool_list=None, kwargs_pixelbased=None): - """ - - :param data_class: ImageData() instance - :param psf_class: PSF() instance - :param lens_model_class: LensModel() instance - :param source_model_class: LightModel() instance - :param lens_light_model_class: LightModel() instance - :param point_source_class: PointSource() instance - :param kwargs_numerics: keyword arguments passed to the Numerics module - :param likelihood_mask: 2d boolean array of pixels to be counted in the likelihood calculation/linear optimization - :param psf_error_map_bool_list: list of boolean of length of point source models. Indicates whether PSF error map - :param kwargs_pixelbased: keyword arguments with various settings related to the pixel-based solver (see SLITronomy documentation) - being applied to the point sources. - """ - if likelihood_mask is None: - likelihood_mask = np.ones_like(data_class.data) - self.likelihood_mask = np.array(likelihood_mask, dtype=bool) - self._mask1d = util.image2array(self.likelihood_mask) - # kwargs_numerics['compute_indexes'] = self.likelihood_mask # here we overwrite the indexes to be computed with the likelihood mask - super(ImageLinearFit, self).__init__(data_class, psf_class=psf_class, lens_model_class=lens_model_class, - source_model_class=source_model_class, - lens_light_model_class=lens_light_model_class, - point_source_class=point_source_class, extinction_class=extinction_class, - kwargs_numerics=kwargs_numerics, kwargs_pixelbased=kwargs_pixelbased) - if psf_error_map_bool_list is None: - psf_error_map_bool_list = [True] * len(self.PointSource.point_source_type_list) - self._psf_error_map_bool_list = psf_error_map_bool_list - if self._pixelbased_bool is True: - # update the pixel-based solver with the likelihood mask - self.PixelSolver.set_likelihood_mask(self.likelihood_mask) - -
[docs] def image_linear_solve(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - kwargs_extinction=None, kwargs_special=None, inv_bool=False): - """ - - computes the image (lens and source surface brightness with a given lens model). - The linear parameters are computed with a weighted linear least square optimization (i.e. flux normalization of the brightness profiles) - However in case of pixel-based modelling, pixel values are constrained by an external solver (e.g. SLITronomy). - - :param kwargs_lens: list of keyword arguments corresponding to the superposition of different lens profiles - :param kwargs_source: list of keyword arguments corresponding to the superposition of different source light profiles - :param kwargs_lens_light: list of keyword arguments corresponding to different lens light surface brightness profiles - :param kwargs_ps: keyword arguments corresponding to "other" parameters, such as external shear and point source image positions - :param inv_bool: if True, invert the full linear solver Matrix Ax = y for the purpose of the covariance matrix. - :return: 2d array of surface brightness pixels of the optimal solution of the linear parameters to match the data - """ - return self._image_linear_solve(kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, kwargs_extinction, - kwargs_special, inv_bool=inv_bool)
- - def _image_linear_solve(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - kwargs_extinction=None, kwargs_special=None, inv_bool=False): - """ - - computes the image (lens and source surface brightness with a given lens model). - By default, the linear parameters are computed with a weighted linear least square optimization (i.e. flux normalization of the brightness profiles) - However in case of pixel-based modelling, pixel values are constrained by an external solver (e.g. SLITronomy). - - :param kwargs_lens: list of keyword arguments corresponding to the superposition of different lens profiles - :param kwargs_source: list of keyword arguments corresponding to the superposition of different source light profiles - :param kwargs_lens_light: list of keyword arguments corresponding to different lens light surface brightness profiles - :param kwargs_ps: keyword arguments corresponding to "other" parameters, such as external shear and point source image positions - :param inv_bool: if True, invert the full linear solver Matrix Ax = y for the purpose of the covariance matrix. - This has no impact in case of pixel-based modelling. - :return: 2d array of surface brightness pixels of the optimal solution of the linear parameters to match the data - """ - if self._pixelbased_bool is True: - model, model_error, cov_param, param = self.image_pixelbased_solve(kwargs_lens, kwargs_source, - kwargs_lens_light, kwargs_ps, - kwargs_extinction, kwargs_special) - else: - A = self._linear_response_matrix(kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, kwargs_extinction, kwargs_special) - C_D_response, model_error = self._error_response(kwargs_lens, kwargs_ps, kwargs_special=kwargs_special) - d = self.data_response - param, cov_param, wls_model = de_lens.get_param_WLS(A.T, 1 / C_D_response, d, inv_bool=inv_bool) - model = self.array_masked2image(wls_model) - _, _, _, _ = self.update_linear_kwargs(param, kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps) - return model, model_error, cov_param, param - -
[docs] def image_pixelbased_solve(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, - kwargs_ps=None, kwargs_extinction=None, kwargs_special=None, - init_lens_light_model=None): - """ - computes the image (lens and source surface brightness with a given lens model) using the pixel-based solver. - - :param kwargs_lens: list of keyword arguments corresponding to the superposition of different lens profiles - :param kwargs_source: list of keyword arguments corresponding to the superposition of different source light profiles - :param kwargs_lens_light: list of keyword arguments corresponding to different lens light surface brightness profiles - :param kwargs_ps: keyword arguments corresponding to point sources - :param kwargs_extinction: keyword arguments corresponding to dust extinction - :param kwargs_special: keyword arguments corresponding to "special" parameters - :param init_lens_light_model: optional initial guess for the lens surface brightness - :return: 2d array of surface brightness pixels of the optimal solution of the linear parameters to match the data - """ - _, model_error = self._error_response(kwargs_lens, kwargs_ps, kwargs_special=kwargs_special) - model, param, _ = self.PixelSolver.solve(kwargs_lens, kwargs_source, kwargs_lens_light=kwargs_lens_light, - kwargs_ps=kwargs_ps, kwargs_special=kwargs_special, - init_lens_light_model=init_lens_light_model) - cov_param = None - _, _ = self.update_pixel_kwargs(kwargs_source, kwargs_lens_light) - _, _, _, _ = self.update_linear_kwargs(param, kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps) - return model, model_error, cov_param, param
- -
[docs] def linear_response_matrix(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - kwargs_extinction=None, kwargs_special=None): - """ - computes the linear response matrix (m x n), with n being the data size and m being the coefficients - - :param kwargs_lens: lens model keyword argument list - :param kwargs_source: extended source model keyword argument list - :param kwargs_lens_light: lens light model keyword argument list - :param kwargs_ps: point source model keyword argument list - :param kwargs_extinction: extinction model keyword argument list - :param kwargs_special: special keyword argument list - :return: linear response matrix - """ - A = self._linear_response_matrix(kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, kwargs_extinction, - kwargs_special) - return A
- - @property - def data_response(self): - """ - returns the 1d array of the data element that is fitted for (including masking) - - :return: 1d numpy array - """ - d = self.image2array_masked(self.Data.data) - return d - -
[docs] def error_response(self, kwargs_lens, kwargs_ps, kwargs_special): - """ - returns the 1d array of the error estimate corresponding to the data response - - :return: 1d numpy array of response, 2d array of additonal errors (e.g. point source uncertainties) - """ - return self._error_response(kwargs_lens, kwargs_ps, kwargs_special=kwargs_special)
- - def _error_response(self, kwargs_lens, kwargs_ps, kwargs_special): - """ - returns the 1d array of the error estimate corresponding to the data response - - :return: 1d numpy array of response, 2d array of additonal errors (e.g. point source uncertainties) - """ - psf_model_error = self._error_map_psf(kwargs_lens, kwargs_ps, kwargs_special=kwargs_special) - C_D_response = self.image2array_masked(self.Data.C_D + psf_model_error) - return C_D_response, psf_model_error - -
[docs] def likelihood_data_given_model(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - kwargs_extinction=None, kwargs_special=None, source_marg=False, linear_prior=None, - check_positive_flux=False): - """ - - computes the likelihood of the data given a model - This is specified with the non-linear parameters and a linear inversion and prior marginalisation. - - :param kwargs_lens: list of keyword arguments corresponding to the superposition of different lens profiles - :param kwargs_source: list of keyword arguments corresponding to the superposition of different source light profiles - :param kwargs_lens_light: list of keyword arguments corresponding to different lens light surface brightness profiles - :param kwargs_ps: keyword arguments corresponding to "other" parameters, such as external shear and point source image positions - :param kwargs_extinction: - :param kwargs_special: - :param source_marg: bool, performs a marginalization over the linear parameters - :param linear_prior: linear prior width in eigenvalues - :param check_positive_flux: bool, if True, checks whether the linear inversion resulted in non-negative flux - components and applies a punishment in the likelihood if so. - :return: log likelihood (natural logarithm) - """ - return self._likelihood_data_given_model(kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, - kwargs_extinction, kwargs_special, source_marg, - linear_prior=linear_prior, check_positive_flux=check_positive_flux)
- - def _likelihood_data_given_model(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - kwargs_extinction=None, kwargs_special=None, source_marg=False, linear_prior=None, - check_positive_flux=False): - """ - - computes the likelihood of the data given a model - This is specified with the non-linear parameters and a linear inversion and prior marginalisation. - - :param kwargs_lens: list of keyword arguments corresponding to the superposition of different lens profiles - :param kwargs_source: list of keyword arguments corresponding to the superposition of different source light profiles - :param kwargs_lens_light: list of keyword arguments corresponding to different lens light surface brightness profiles - :param kwargs_ps: keyword arguments corresponding to "other" parameters, such as external shear and point source image positions - :param source_marg: bool, performs a marginalization over the linear parameters - :param linear_prior: linear prior width in eigenvalues - :param check_positive_flux: bool, if True, checks whether the linear inversion resulted in non-negative flux - components and applies a punishment in the likelihood if so. - :return: log likelihood (natural logarithm) - """ - # generate image - im_sim, model_error, cov_matrix, param = self._image_linear_solve(kwargs_lens, kwargs_source, kwargs_lens_light, - kwargs_ps, kwargs_extinction, kwargs_special, - inv_bool=source_marg) - # compute X^2 - logL = self.Data.log_likelihood(im_sim, self.likelihood_mask, model_error) - - if self._pixelbased_bool is False: - if cov_matrix is not None and source_marg: - marg_const = de_lens.marginalization_new(cov_matrix, d_prior=linear_prior) - logL += marg_const - if check_positive_flux is True: - bool_ = self.check_positive_flux(kwargs_source, kwargs_lens_light, kwargs_ps) - if bool_ is False: - logL -= 10**8 - return logL - -
[docs] def num_param_linear(self, kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps): - """ - - :return: number of linear coefficients to be solved for in the linear inversion - """ - return self._num_param_linear(kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps)
- - def _num_param_linear(self, kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps): - """ - - :return: number of linear coefficients to be solved for in the linear inversion - """ - num = 0 - if self._pixelbased_bool is False: - num += self.SourceModel.num_param_linear(kwargs_source) - num += self.LensLightModel.num_param_linear(kwargs_lens_light) - num += self.PointSource.num_basis(kwargs_ps, kwargs_lens) - return num - - def _linear_response_matrix(self, kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, - kwargs_extinction=None, kwargs_special=None, unconvolved=False): - """ - - computes the linear response matrix (m x n), with n being the data size and m being the coefficients - The calculation is done by - - first (optional) computing differential extinctions) - - adding linear components of the lensed source(s) - - adding linear components of the unlensed components (i.e. deflector) - - adding point sources (can be multiply lensed or stars in the field) - - :param kwargs_lens: list of keyword arguments corresponding to the superposition of different lens profiles - :param kwargs_source: list of keyword arguments corresponding to the superposition of different source light profiles - :param kwargs_lens_light: list of keyword arguments corresponding to different lens light surface brightness profiles - :param kwargs_ps: keyword arguments corresponding to "other" parameters, such as external shear and point source image positions - :param unconvolved: bool, if True, computes components without convolution kernel (will not work for point sources) - :return: response matrix (m x n) - """ - x_grid, y_grid = self.ImageNumerics.coordinates_evaluate - source_light_response, n_source = self.source_mapping.image_flux_split(x_grid, y_grid, kwargs_lens, - kwargs_source) - extinction = self._extinction.extinction(x_grid, y_grid, kwargs_extinction=kwargs_extinction, - kwargs_special=kwargs_special) - lens_light_response, n_lens_light = self.LensLightModel.functions_split(x_grid, y_grid, kwargs_lens_light) - - ra_pos, dec_pos, amp, n_points = self.point_source_linear_response_set(kwargs_ps, kwargs_lens, kwargs_special, with_amp=False) - num_param = n_points + n_lens_light + n_source - - num_response = self.num_data_evaluate - A = np.zeros((num_param, num_response)) - n = 0 - # response of lensed source profile - for i in range(0, n_source): - image = source_light_response[i] - image *= extinction - image = self.ImageNumerics.re_size_convolve(image, unconvolved=unconvolved) - A[n, :] = np.nan_to_num(self.image2array_masked(image), copy=False) - n += 1 - # response of deflector light profile (or any other un-lensed extended components) - for i in range(0, n_lens_light): - image = lens_light_response[i] - image = self.ImageNumerics.re_size_convolve(image, unconvolved=unconvolved) - A[n, :] = np.nan_to_num(self.image2array_masked(image), copy=False) - n += 1 - # response of point sources - for i in range(0, n_points): - image = self.ImageNumerics.point_source_rendering(ra_pos[i], dec_pos[i], amp[i]) - A[n, :] = np.nan_to_num(self.image2array_masked(image), copy=False) - n += 1 - return A - -
[docs] def update_linear_kwargs(self, param, kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps): - """ - - links linear parameters to kwargs arguments - - :param param: linear parameter vector corresponding to the response matrix - :return: updated list of kwargs with linear parameter values - """ - i = 0 - kwargs_source, i = self.SourceModel.update_linear(param, i, kwargs_list=kwargs_source) - kwargs_lens_light, i = self.LensLightModel.update_linear(param, i, kwargs_list=kwargs_lens_light) - kwargs_ps, i = self.PointSource.update_linear(param, i, kwargs_ps, kwargs_lens) - return kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps
- -
[docs] def update_pixel_kwargs(self, kwargs_source, kwargs_lens_light): - """ - - Update kwargs arguments for pixel-based profiles with fixed properties - such as their number of pixels, scale, and center coordinates (fixed to the origin). - - :param kwargs_source: list of keyword arguments corresponding to the superposition of different source light profiles - :param kwargs_lens_light: list of keyword arguments corresponding to the superposition of different lens light profiles - :return: updated kwargs_source and kwargs_lens_light - """ - # in case the source plane grid size has changed, update the kwargs accordingly - ss_factor_source = self.SourceNumerics.grid_supersampling_factor - kwargs_source[0]['n_pixels'] = int(self.Data.num_pixel * ss_factor_source**2) #  effective number of pixels in source plane - kwargs_source[0]['scale'] = self.Data.pixel_width / ss_factor_source # effective pixel size of source plane grid - # pixelated reconstructions have no well-defined center, we put it arbitrarily at (0, 0), center of the image - kwargs_source[0]['center_x'] = 0 - kwargs_source[0]['center_y'] = 0 - # do the same if the lens light has been reconstructed - if kwargs_lens_light is not None and len(kwargs_lens_light) > 0: - kwargs_lens_light[0]['n_pixels'] = self.Data.num_pixel - kwargs_lens_light[0]['scale'] = self.Data.pixel_width - kwargs_lens_light[0]['center_x'] = 0 - kwargs_lens_light[0]['center_y'] = 0 - return kwargs_source, kwargs_lens_light
- -
[docs] def reduced_residuals(self, model, error_map=0): - """ - - :param model: 2d numpy array of the modeled image - :param error_map: 2d numpy array of additional noise/error terms from model components (such as PSF model uncertainties) - :return: 2d numpy array of reduced residuals per pixel - """ - mask = self.likelihood_mask - C_D = self.Data.C_D_model(model) - residual = (model - self.Data.data)/np.sqrt(C_D+np.abs(error_map))*mask - return residual
- -
[docs] def reduced_chi2(self, model, error_map=0): - """ - returns reduced chi2 - :param model: 2d numpy array of a model predicted image - :param error_map: same format as model, additional error component (such as PSF errors) - :return: reduced chi2 - """ - norm_res = self.reduced_residuals(model, error_map) - return np.sum(norm_res**2) / self.num_data_evaluate
- - @property - def num_data_evaluate(self): - """ - number of data points to be used in the linear solver - :return: - """ - return int(np.sum(self.likelihood_mask)) - -
[docs] def update_data(self, data_class): - """ - - :param data_class: instance of Data() class - :return: no return. Class is updated. - """ - self.Data = data_class - self.ImageNumerics._PixelGrid = data_class
- -
[docs] def image2array_masked(self, image): - """ - returns 1d array of values in image that are not masked out for the likelihood computation/linear minimization - :param image: 2d numpy array of full image - :return: 1d array - """ - array = util.image2array(image) - return array[self._mask1d]
- -
[docs] def array_masked2image(self, array): - """ - - :param array: 1d array of values not masked out (part of linear fitting) - :return: 2d array of full image - """ - nx, ny = self.Data.num_pixel_axes - grid1d = np.zeros(nx * ny) - grid1d[self._mask1d] = array - grid2d = util.array2image(grid1d, nx, ny) - return grid2d
- - def _error_map_psf(self, kwargs_lens, kwargs_ps, kwargs_special=None): - """ - - :param kwargs_lens: - :param kwargs_ps: - :return: - """ - error_map = np.zeros(self.Data.num_pixel_axes) - if self._psf_error_map is True: - for k, bool_ in enumerate(self._psf_error_map_bool_list): - if bool_ is True: - ra_pos, dec_pos, _ = self.PointSource.point_source_list(kwargs_ps, kwargs_lens=kwargs_lens, k=k, - with_amp=False) - if len(ra_pos) > 0: - ra_pos, dec_pos = self._displace_astrometry(ra_pos, dec_pos, kwargs_special=kwargs_special) - error_map += self.ImageNumerics.psf_error_map(ra_pos, dec_pos, None, self.Data.data, - fix_psf_error_map=False) - return error_map - -
[docs] def error_map_source(self, kwargs_source, x_grid, y_grid, cov_param): - """ - variance of the linear source reconstruction in the source plane coordinates, - computed by the diagonal elements of the covariance matrix of the source reconstruction as a sum of the errors - of the basis set. - - :param kwargs_source: keyword arguments of source model - :param x_grid: x-axis of positions to compute error map - :param y_grid: y-axis of positions to compute error map - :param cov_param: covariance matrix of liner inversion parameters - :return: diagonal covariance errors at the positions (x_grid, y_grid) - """ - return self._error_map_source(kwargs_source, x_grid, y_grid, cov_param)
- - def _error_map_source(self, kwargs_source, x_grid, y_grid, cov_param): - """ - variance of the linear source reconstruction in the source plane coordinates, - computed by the diagonal elements of the covariance matrix of the source reconstruction as a sum of the errors - of the basis set. - - :param kwargs_source: keyword arguments of source model - :param x_grid: x-axis of positions to compute error map - :param y_grid: y-axis of positions to compute error map - :param cov_param: covariance matrix of liner inversion parameters - :return: diagonal covariance errors at the positions (x_grid, y_grid) - """ - - error_map = np.zeros_like(x_grid) - basis_functions, n_source = self.SourceModel.functions_split(x_grid, y_grid, kwargs_source) - basis_functions = np.array(basis_functions) - - if cov_param is not None: - for i in range(len(error_map)): - error_map[i] = basis_functions[:, i].T.dot(cov_param[:n_source, :n_source]).dot(basis_functions[:, i]) - return error_map - -
[docs] def point_source_linear_response_set(self, kwargs_ps, kwargs_lens, kwargs_special, with_amp=True): - """ - - :param kwargs_ps: point source keyword argument list - :param kwargs_lens: lens model keyword argument list - :param kwargs_special: special keyword argument list, may include 'delta_x_image' and 'delta_y_image' - :param with_amp: bool, if True, relative magnification between multiply imaged point sources are held fixed. - :return: list of positions and amplitudes split in different basis components with applied astrometric corrections - """ - - ra_pos, dec_pos, amp, n_points = self.PointSource.linear_response_set(kwargs_ps, kwargs_lens, with_amp=with_amp) - - if kwargs_special is not None: - if 'delta_x_image' in kwargs_special: - delta_x, delta_y = kwargs_special['delta_x_image'], kwargs_special['delta_y_image'] - k = 0 - n = len(delta_x) - for i in range(n_points): - for j in range(len(ra_pos[i])): - if k >= n: - break - ra_pos[i][j] = ra_pos[i][j] + delta_x[k] - dec_pos[i][j] = dec_pos[i][j] + delta_y[k] - k += 1 - return ra_pos, dec_pos, amp, n_points
- -
[docs] def check_positive_flux(self, kwargs_source, kwargs_lens_light, kwargs_ps): - """ - checks whether the surface brightness profiles contain positive fluxes and returns bool if True - - :param kwargs_source: source surface brightness keyword argument list - :param kwargs_lens_light: lens surface brightness keyword argument list - :param kwargs_ps: point source keyword argument list - :return: boolean - """ - pos_bool_ps = self.PointSource.check_positive_flux(kwargs_ps) - if self._pixelbased_bool is True: - # this constraint must be handled by the pixel-based solver - pos_bool_source = True - pos_bool_lens_light = True - else: - pos_bool_source = self.SourceModel.check_positive_flux_profile(kwargs_source) - pos_bool_lens_light = self.LensLightModel.check_positive_flux_profile(kwargs_lens_light) - if pos_bool_ps is True and pos_bool_source is True and pos_bool_lens_light is True: - return True - else: - return False
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/ImSim/image_model.html b/docs/_build/html/_modules/lenstronomy/ImSim/image_model.html deleted file mode 100644 index 77e141c78..000000000 --- a/docs/_build/html/_modules/lenstronomy/ImSim/image_model.html +++ /dev/null @@ -1,425 +0,0 @@ - - - - - - - - lenstronomy.ImSim.image_model — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.ImSim.image_model

-__author__ = 'sibirrer'
-
-from lenstronomy.ImSim.Numerics.numerics_subframe import NumericsSubFrame
-from lenstronomy.ImSim.image2source_mapping import Image2SourceMapping
-from lenstronomy.LensModel.lens_model import LensModel
-from lenstronomy.LightModel.light_model import LightModel
-from lenstronomy.PointSource.point_source import PointSource
-from lenstronomy.ImSim.differential_extinction import DifferentialExtinction
-from lenstronomy.Util import util
-
-import numpy as np
-
-__all__ = ['ImageModel']
-
-
-
[docs]class ImageModel(object): - """ - this class uses functions of lens_model and source_model to make a lensed image - """ - def __init__(self, data_class, psf_class, lens_model_class=None, source_model_class=None, - lens_light_model_class=None, point_source_class=None, extinction_class=None, kwargs_numerics=None, - kwargs_pixelbased=None): - """ - :param data_class: instance of ImageData() or PixelGrid() class - :param psf_class: instance of PSF() class - :param lens_model_class: instance of LensModel() class - :param source_model_class: instance of LightModel() class describing the source parameters - :param lens_light_model_class: instance of LightModel() class describing the lens light parameters - :param point_source_class: instance of PointSource() class describing the point sources - :param kwargs_numerics: keyword arguments with various numeric description (see ImageNumerics class for options) - :param kwargs_pixelbased: keyword arguments with various settings related to the pixel-based solver (see SLITronomy documentation) - """ - self.type = 'single-band' - self.num_bands = 1 - self.PSF = psf_class - self.Data = data_class - self.PSF.set_pixel_size(self.Data.pixel_width) - if kwargs_numerics is None: - kwargs_numerics = {} - self.ImageNumerics = NumericsSubFrame(pixel_grid=self.Data, psf=self.PSF, **kwargs_numerics) - if lens_model_class is None: - lens_model_class = LensModel(lens_model_list=[]) - self.LensModel = lens_model_class - if point_source_class is None: - point_source_class = PointSource(point_source_type_list=[]) - self.PointSource = point_source_class - self.PointSource.update_lens_model(lens_model_class=lens_model_class) - x_center, y_center = self.Data.center - self.PointSource.update_search_window(search_window=np.max(self.Data.width), x_center=x_center, - y_center=y_center, min_distance=self.Data.pixel_width, - only_from_unspecified=True) - self._psf_error_map = self.PSF.psf_error_map_bool - - if source_model_class is None: - source_model_class = LightModel(light_model_list=[]) - self.SourceModel = source_model_class - if lens_light_model_class is None: - lens_light_model_class = LightModel(light_model_list=[]) - self.LensLightModel = lens_light_model_class - self._kwargs_numerics = kwargs_numerics - if extinction_class is None: - extinction_class = DifferentialExtinction(optical_depth_model=[]) - self._extinction = extinction_class - if kwargs_pixelbased is None: - kwargs_pixelbased = {} - else: - kwargs_pixelbased = kwargs_pixelbased.copy() - self._pixelbased_bool = self._detect_pixelbased_models() - if self._pixelbased_bool is True: - from slitronomy.Util.class_util import create_solver_class # requirement on SLITronomy is exclusively here - self.SourceNumerics = self._setup_pixelbased_source_numerics(kwargs_numerics, kwargs_pixelbased) - self.PixelSolver = create_solver_class(self.Data, self.PSF, self.ImageNumerics, self.SourceNumerics, - self.LensModel, self.SourceModel, self.LensLightModel, self.PointSource, - self._extinction, kwargs_pixelbased) - self.source_mapping = None # handled with pixelated operator - else: - self.source_mapping = Image2SourceMapping(lensModel=lens_model_class, sourceModel=source_model_class) - -
[docs] def reset_point_source_cache(self, cache=True): - """ - deletes all the cache in the point source class and saves it from then on - - :param cache: boolean, if True, saves the next occuring point source positions in the cache - :return: None - """ - self.PointSource.delete_lens_model_cache() - self.PointSource.set_save_cache(cache)
- -
[docs] def update_psf(self, psf_class): - """ - - update the instance of the class with a new instance of PSF() with a potentially different point spread function - - :param psf_class: - :return: no return. Class is updated. - """ - self.PSF = psf_class - self.PSF.set_pixel_size(self.Data.pixel_width) - self.ImageNumerics = NumericsSubFrame(pixel_grid=self.Data, psf=self.PSF, **self._kwargs_numerics)
- -
[docs] def source_surface_brightness(self, kwargs_source, kwargs_lens=None, kwargs_extinction=None, kwargs_special=None, - unconvolved=False, de_lensed=False, k=None, update_pixelbased_mapping=True): - """ - - computes the source surface brightness distribution - - :param kwargs_source: list of keyword arguments corresponding to the superposition of different source light profiles - :param kwargs_lens: list of keyword arguments corresponding to the superposition of different lens profiles - :param kwargs_extinction: list of keyword arguments of extinction model - :param unconvolved: if True: returns the unconvolved light distribution (prefect seeing) - :param de_lensed: if True: returns the un-lensed source surface brightness profile, otherwise the lensed. - :param k: integer, if set, will only return the model of the specific index - :return: 2d array of surface brightness pixels - """ - if len(self.SourceModel.profile_type_list) == 0: - return np.zeros(self.Data.num_pixel_axes) - if self._pixelbased_bool is True: - return self._source_surface_brightness_pixelbased(kwargs_source, kwargs_lens=kwargs_lens, - kwargs_extinction=kwargs_extinction, - kwargs_special=kwargs_special, - unconvolved=unconvolved, de_lensed=de_lensed, k=k, - update_mapping=update_pixelbased_mapping) - else: - return self._source_surface_brightness_analytical(kwargs_source, kwargs_lens=kwargs_lens, - kwargs_extinction=kwargs_extinction, - kwargs_special=kwargs_special, - unconvolved=unconvolved, de_lensed=de_lensed, k=k)
- - def _source_surface_brightness_analytical(self, kwargs_source, kwargs_lens=None, kwargs_extinction=None, kwargs_special=None, - unconvolved=False, de_lensed=False, k=None): - """ - - computes the source surface brightness distribution - - :param kwargs_source: list of keyword arguments corresponding to the superposition of different source light profiles - :param kwargs_lens: list of keyword arguments corresponding to the superposition of different lens profiles - :param kwargs_extinction: list of keyword arguments of extinction model - :param unconvolved: if True: returns the unconvolved light distribution (prefect seeing) - :param de_lensed: if True: returns the un-lensed source surface brightness profile, otherwise the lensed. - :param k: integer, if set, will only return the model of the specific index - :return: 2d array of surface brightness pixels - """ - ra_grid, dec_grid = self.ImageNumerics.coordinates_evaluate - if de_lensed is True: - source_light = self.SourceModel.surface_brightness(ra_grid, dec_grid, kwargs_source, k=k) - else: - source_light = self.source_mapping.image_flux_joint(ra_grid, dec_grid, kwargs_lens, kwargs_source, k=k) - source_light *= self._extinction.extinction(ra_grid, dec_grid, kwargs_extinction=kwargs_extinction, - kwargs_special=kwargs_special) - source_light_final = self.ImageNumerics.re_size_convolve(source_light, unconvolved=unconvolved) - return source_light_final - - def _source_surface_brightness_pixelbased(self, kwargs_source, kwargs_lens=None, kwargs_extinction=None, kwargs_special=None, - unconvolved=False, de_lensed=False, k=None, update_mapping=True): - """ - computes the source surface brightness distribution, using pixel-based solver for light profiles (from SLITronomy) - - :param kwargs_source: list of keyword arguments corresponding to the superposition of different source light profiles - :param kwargs_lens: list of keyword arguments corresponding to the superposition of different lens profiles - :param kwargs_extinction: list of keyword arguments of extinction model - :param unconvolved: if True: returns the unconvolved light distribution (prefect seeing) - :param de_lensed: if True: returns the un-lensed source surface brightness profile, otherwise the lensed. - :param k: integer, if set, will only return the model of the specific index - :param update_mapping: if False, prevent the pixelated lensing mapping to be updated (saves computation time if previously computed). - :return: 2d array of surface brightness pixels - """ - ra_grid, dec_grid = self.SourceNumerics.coordinates_evaluate - source_light = self.SourceModel.surface_brightness(ra_grid, dec_grid, kwargs_source, k=k) - if de_lensed is True: - source_light = self.SourceNumerics.re_size_convolve(source_light, unconvolved=unconvolved) - else: - source_mapping = self.PixelSolver.lensingOperator - source_light = source_mapping.source2image(source_light, kwargs_lens=kwargs_lens, kwargs_special=kwargs_special, - update_mapping=update_mapping, original_source_grid=True) - source_light = self.ImageNumerics.re_size_convolve(source_light, unconvolved=unconvolved) - # undo flux normalization performed by re_size_convolve (already handled in SLITronomy) - source_light_final = source_light / self.Data.pixel_width**2 - return source_light_final - -
[docs] def lens_surface_brightness(self, kwargs_lens_light, unconvolved=False, k=None): - """ - - computes the lens surface brightness distribution - - :param kwargs_lens_light: list of keyword arguments corresponding to different lens light surface brightness profiles - :param unconvolved: if True, returns unconvolved surface brightness (perfect seeing), otherwise convolved with PSF kernel - :return: 2d array of surface brightness pixels - """ - if self._pixelbased_bool is True: - if unconvolved is True: - raise ValueError("Lens light pixel-based modelling does not perform deconvolution") - return self._lens_surface_brightness_pixelbased(kwargs_lens_light, k=k) - else: - return self._lens_surface_brightness_analytical(kwargs_lens_light, unconvolved=unconvolved, k=k)
- - def _lens_surface_brightness_analytical(self, kwargs_lens_light, unconvolved=False, k=None): - """ - - computes the lens surface brightness distribution - - :param kwargs_lens_light: list of keyword arguments corresponding to different lens light surface brightness profiles - :param unconvolved: if True, returns unconvolved surface brightness (perfect seeing), otherwise convolved with PSF kernel - :return: 2d array of surface brightness pixels - """ - ra_grid, dec_grid = self.ImageNumerics.coordinates_evaluate - lens_light = self.LensLightModel.surface_brightness(ra_grid, dec_grid, kwargs_lens_light, k=k) - lens_light_final = self.ImageNumerics.re_size_convolve(lens_light, unconvolved=unconvolved) - return lens_light_final - - def _lens_surface_brightness_pixelbased(self, kwargs_lens_light, k=None): - """ - - computes the lens surface brightness distribution , using pixel-based solver for light profiles (from SLITronomy) - Important: SLITronomy does not solve for deconvolved lens light, hence the returned map is convolved with the PSF. - - :param kwargs_lens_light: list of keyword arguments corresponding to different lens light surface brightness profiles - :return: 2d array of surface brightness pixels - """ - ra_grid, dec_grid = self.ImageNumerics.coordinates_evaluate - lens_light = self.LensLightModel.surface_brightness(ra_grid, dec_grid, kwargs_lens_light, k=k) - lens_light_final = util.array2image(lens_light) - return lens_light_final - -
[docs] def point_source(self, kwargs_ps, kwargs_lens=None, kwargs_special=None, unconvolved=False, k=None): - """ - - computes the point source positions and paints PSF convolutions on them - - :param kwargs_ps: - :param k: - :return: - """ - point_source_image = np.zeros((self.Data.num_pixel_axes)) - if unconvolved or self.PointSource is None: - return point_source_image - ra_pos, dec_pos, amp = self.PointSource.point_source_list(kwargs_ps, kwargs_lens=kwargs_lens, k=k) - ra_pos, dec_pos = self._displace_astrometry(ra_pos, dec_pos, kwargs_special=kwargs_special) - point_source_image += self.ImageNumerics.point_source_rendering(ra_pos, dec_pos, amp) - return point_source_image
- -
[docs] def image(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - kwargs_extinction=None, kwargs_special=None, unconvolved=False, source_add=True, lens_light_add=True, point_source_add=True): - """ - - make an image with a realisation of linear parameter values "param" - - :param kwargs_lens: list of keyword arguments corresponding to the superposition of different lens profiles - :param kwargs_source: list of keyword arguments corresponding to the superposition of different source light profiles - :param kwargs_lens_light: list of keyword arguments corresponding to different lens light surface brightness profiles - :param kwargs_ps: keyword arguments corresponding to "other" parameters, such as external shear and point source image positions - :param unconvolved: if True: returns the unconvolved light distribution (prefect seeing) - :param source_add: if True, compute source, otherwise without - :param lens_light_add: if True, compute lens light, otherwise without - :param point_source_add: if True, add point sources, otherwise without - :return: 2d array of surface brightness pixels of the simulation - """ - model = np.zeros((self.Data.num_pixel_axes)) - if source_add is True: - model += self.source_surface_brightness(kwargs_source, kwargs_lens, kwargs_extinction=kwargs_extinction, - kwargs_special=kwargs_special, unconvolved=unconvolved) - if lens_light_add is True: - model += self.lens_surface_brightness(kwargs_lens_light, unconvolved=unconvolved) - if point_source_add is True: - model += self.point_source(kwargs_ps, kwargs_lens, kwargs_special=kwargs_special, unconvolved=unconvolved) - return model
- -
[docs] def extinction_map(self, kwargs_extinction=None, kwargs_special=None): - """ - differential extinction per pixel - - :param kwargs_extinction: list of keyword arguments corresponding to the optical depth models tau, such that extinction is exp(-tau) - :param kwargs_special: keyword arguments, additional parameter to the extinction - :return: 2d array of size of the image - """ - ra_grid, dec_grid = self.ImageNumerics.coordinates_evaluate - extinction = self._extinction.extinction(ra_grid, dec_grid, kwargs_extinction=kwargs_extinction, - kwargs_special=kwargs_special) - extinction_array = np.ones_like(ra_grid) * extinction - extinction = self.ImageNumerics.re_size_convolve(extinction_array, unconvolved=True) - return extinction
- - def _displace_astrometry(self, x_pos, y_pos, kwargs_special=None): - """ - displaces point sources by shifts specified in kwargs_special - - :param x_pos: list of point source positions according to point source model list - :param y_pos: list of point source positions according to point source model list - :param kwargs_special: keyword arguments, can contain 'delta_x_image' and 'delta_y_image' - The list is defined in order of the image positions - :return: shifted image positions in same format as input - """ - if kwargs_special is not None: - if 'delta_x_image' in kwargs_special: - delta_x, delta_y = kwargs_special['delta_x_image'], kwargs_special['delta_y_image'] - delta_x_new = np.zeros(len(x_pos)) - delta_x_new[0:len(delta_x)] = delta_x[:] - delta_y_new = np.zeros(len(y_pos)) - delta_y_new[0:len(delta_y)] = delta_y - x_pos = x_pos + delta_x_new - y_pos = y_pos + delta_y_new - return x_pos, y_pos - - def _detect_pixelbased_models(self): - """ - Returns True if light profiles specific to pixel-based modelling are present in source model list. - Otherwise returns False. - - Currently, pixel-based light profiles are: 'SLIT_STARLETS', 'SLIT_STARLETS_GEN2'. - """ - source_model_list = self.SourceModel.profile_type_list - if 'SLIT_STARLETS' in source_model_list or 'SLIT_STARLETS_GEN2' in source_model_list: - if len(source_model_list) > 1: - raise ValueError("'SLIT_STARLETS' or 'SLIT_STARLETS_GEN2' must be the only source model list for pixel-based modelling") - return True - return False - - def _setup_pixelbased_source_numerics(self, kwargs_numerics, kwargs_pixelbased): - """ - Check if model requirement are compatible with support pixel-based solver, - and creates a new numerics class specifically for source plane. - - :param kwargs_numerics: keyword argument with various numeric description (see ImageNumerics class for options) - :param kwargs_pixelbased: keyword argument with various settings related to the pixel-based solver (see SLITronomy documentation) - """ - # check that the required convolution type is compatible with pixel-based modelling (in current implementation) - psf_type = self.PSF.psf_type - supersampling_convolution = kwargs_numerics.get('supersampling_convolution', False) - supersampling_factor = kwargs_numerics.get('supersampling_factor', 1) - compute_mode = kwargs_numerics.get('compute_mode', 'regular') - if psf_type not in ['PIXEL', 'NONE']: - raise ValueError("Only convolution using a pixelated kernel is supported for pixel-based modelling") - if compute_mode != 'regular': - raise ValueError("Only regular coordinate grid is supported for pixel-based modelling") - if (supersampling_convolution is True and supersampling_factor > 1): - raise ValueError("Only non-supersampled convolution is supported for pixel-based modelling") - - # setup the source numerics with a (possibily) different supersampling resolution - supersampling_factor_source = kwargs_pixelbased.pop('supersampling_factor_source', 1) - kwargs_numerics_source = kwargs_numerics.copy() - kwargs_numerics_source['supersampling_factor'] = supersampling_factor_source - kwargs_numerics_source['compute_mode'] = 'regular' - source_numerics_class = NumericsSubFrame(pixel_grid=self.Data, psf=self.PSF, **kwargs_numerics_source) - return source_numerics_class
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/LightConeSim/light_cone.html b/docs/_build/html/_modules/lenstronomy/LensModel/LightConeSim/light_cone.html deleted file mode 100644 index aae474240..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/LightConeSim/light_cone.html +++ /dev/null @@ -1,185 +0,0 @@ - - - - - - - - lenstronomy.LensModel.LightConeSim.light_cone — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.LightConeSim.light_cone

-from lenstronomy.Util import util
-from lenstronomy.LensModel import convergence_integrals
-import numpy as np
-from lenstronomy.Util import constants as const
-from lenstronomy.Cosmo.lens_cosmo import LensCosmo
-from lenstronomy.LensModel.lens_model import LensModel
-
-__all__ = ['LightCone', 'MassSlice']
-
-
-
[docs]class LightCone(object): - """ - class to perform multi-plane ray-tracing from convergence maps at different redshifts - From the convergence maps the deflection angles and lensing potential are computed (from different settings) - and then an interpolated grid of all those quantities generate an instance of the lenstronomy LensModel multi-plane - instance. All features of the LensModel module are supported. - - Improvements that can be made for accuracy and speed: - 1. adaptive mesh integral for the convergence map - 2. Interpolated deflection map on different scales than the mass map. - - The design principles should allow those implementations 'under the hook' of this class. - """ - - def __init__(self, mass_map_list, grid_spacing_list, redshift_list): - """ - - :param mass_map_list: 2d numpy array of mass map (in units Msol) - :param grid_spacing_list: list of grid spacing of the individual mass maps - :param redshift_list: list of redshifts of the mass maps - - """ - self._mass_slice_list = [] - for i in range(len(mass_map_list)): - self._mass_slice_list.append(MassSlice(mass_map_list[i], grid_spacing_list[i], redshift_list[i])) - self._mass_map_list = mass_map_list - self._grid_spacing_list = grid_spacing_list - self._redshift_list = redshift_list - -
[docs] def cone_instance(self, z_source, cosmo, multi_plane=True, kwargs_interp=None): - """ - - :param z_source: redshift to where lensing quantities are computed - :param cosmo: astropy.cosmology class - :param multi_plane: boolean, if True, computes multi-plane ray-tracing - :param kwargs_interp: interpolation keyword arguments specifying the numerics. - See description in the Interpolate() class. Only applicable for 'INTERPOL' and 'INTERPOL_SCALED' models. - :return: LensModel instance, keyword argument list of lens model - """ - lens_model = LensModel(lens_model_list=['INTERPOL'] * len(self._mass_map_list), - lens_redshift_list=self._redshift_list, multi_plane=multi_plane, - z_source_convention=z_source, cosmo=cosmo, z_source=z_source, - kwargs_interp=kwargs_interp) - kwargs_lens = [] - for mass_slice in self._mass_slice_list: - kwargs_lens.append(mass_slice.interpol_instance(z_source, cosmo)) - return lens_model, kwargs_lens
- - -
[docs]class MassSlice(object): - """ - class to describe a single mass slice - """ - def __init__(self, mass_map, grid_spacing, redshift): - """ - - :param mass_map: 2d numpy array of mass map (in units physical Msol) - :param grid_spacing: grid spacing of the mass map (in units physical Mpc) - :param redshift: redshift - """ - nx, ny = np.shape(mass_map) - if nx != ny: - raise ValueError('Shape of mass map needs to be square!, set as %s %s' % (nx, ny)) - self._mass_map = mass_map - self._grid_spacing = grid_spacing - self._redshift = redshift - self._f_x_mass, self._f_y_mass = convergence_integrals.deflection_from_kappa_grid(self._mass_map, - self._grid_spacing) - self._f_mass = convergence_integrals.potential_from_kappa_grid(self._mass_map, self._grid_spacing) - x_grid, y_grid = util.make_grid(numPix=len(self._mass_map), deltapix=self._grid_spacing) - self._x_axes_mpc, self._y_axes_mpc = util.get_axes(x_grid, y_grid) - -
[docs] def interpol_instance(self, z_source, cosmo): - """ - scales the mass map integrals (with units of mass not convergence) into a convergence map for the given - cosmology and source redshift and returns the keyword arguments of the interpolated reduced deflection and - lensing potential. - - :param z_source: redshift of the source - :param cosmo: astropy.cosmology instance - :return: keyword arguments of the interpolation instance with numerically computed deflection angles and lensing - potential - """ - lens_cosmo = LensCosmo(z_lens=self._redshift, z_source=z_source, cosmo=cosmo) - mpc2arcsec = lens_cosmo.dd * const.arcsec - x_axes = self._x_axes_mpc / mpc2arcsec # units of arc seconds in grid spacing - y_axes = self._y_axes_mpc / mpc2arcsec # units of arc seconds in grid spacing - - f_ = self._f_mass / lens_cosmo.sigma_crit_angle / self._grid_spacing ** 2 - f_x = self._f_x_mass / lens_cosmo.sigma_crit_angle / self._grid_spacing ** 2 * mpc2arcsec - f_y = self._f_y_mass / lens_cosmo.sigma_crit_angle / self._grid_spacing ** 2 * mpc2arcsec - kwargs_interp = {'grid_interp_x': x_axes, 'grid_interp_y': y_axes, 'f_': f_, 'f_x': f_x, 'f_y': f_y} - return kwargs_interp
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/arc_perturbations.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/arc_perturbations.html deleted file mode 100644 index 1a30a51b8..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/arc_perturbations.html +++ /dev/null @@ -1,243 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.arc_perturbations — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.arc_perturbations

-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-from lenstronomy.Util import param_util
-from lenstronomy.Util import derivative_util
-import numpy as np
-
-__all__ = ['ArcPerturbations']
-
-
-
[docs]class ArcPerturbations(LensProfileBase): - """ - uses radial and tangential fourier modes within a specific range in both directions to perturb a lensing potential - """ - def __init__(self): - super(ArcPerturbations, self).__init__() - self._2_pi = np.pi * 2 - -
[docs] def function(self, x, y, coeff, d_r, d_phi, center_x, center_y): - """ - - :param x: x-coordinate - :param y: y-coordinate - :param coeff: float, amplitude of basis - :param d_r: period of radial sinusoidal in units of angle - :param d_phi: period of tangential sinusoidal in radian - :param center_x: center of rotation for tangential basis - :param center_y: center of rotation for tangential basis - :return: - """ - r, phi = param_util.cart2polar(x, y, center_x=center_x, center_y=center_y) - dphi_ = d_phi / self._2_pi - phi_r = self._phi_r(r, d_r) - phi_theta = self._phi_theta(phi, dphi_) - return phi_r * phi_theta * coeff
- -
[docs] def derivatives(self, x, y, coeff, d_r, d_phi, center_x, center_y): - """ - - :param x: x-coordinate - :param y: y-coordinate - :param coeff: float, amplitude of basis - :param d_r: period of radial sinusoidal in units of angle - :param d_phi: period of tangential sinusoidal in radian - :param center_x: center of rotation for tangential basis - :param center_y: center of rotation for tangential basis - :return: f_x, f_y - """ - r, theta = param_util.cart2polar(x, y, center_x=center_x, center_y=center_y) - dphi_ = d_phi / self._2_pi - d_phi_dr = self._d_phi_r(r, d_r) * self._phi_theta(theta, dphi_) - d_phi_d_theta = self._d_phi_theta(theta, dphi_) * self._phi_r(r, d_r) - x_ = x - center_x - y_ = y - center_y - dr_dx = derivative_util.d_r_dx(x_, y_) - dr_dy = derivative_util.d_r_dy(x_, y_) - d_theta_dx = derivative_util.d_phi_dx(x_, y_) - d_theta_dy = derivative_util.d_phi_dy(x_, y_) - f_x = d_phi_dr * dr_dx + d_phi_d_theta * d_theta_dx - f_y = d_phi_dr * dr_dy + d_phi_d_theta * d_theta_dy - return f_x * coeff, f_y * coeff
- -
[docs] def hessian(self, x, y, coeff, d_r, d_phi, center_x, center_y): - """ - - :param x: x-coordinate - :param y: y-coordinate - :param coeff: float, amplitude of basis - :param d_r: period of radial sinusoidal in units of angle - :param d_phi: period of tangential sinusoidal in radian - :param center_x: center of rotation for tangential basis - :param center_y: center of rotation for tangential basis - :return: f_xx, f_yy, f_xy - """ - r, theta = param_util.cart2polar(x, y, center_x=center_x, center_y=center_y) - dphi_ = d_phi / self._2_pi - - d_phi_dr = self._d_phi_r(r, d_r) * self._phi_theta(theta, dphi_) - d_phi_dr2 = self._d_phi_r2(r, d_r) * self._phi_theta(theta, dphi_) - d_phi_d_theta = self._d_phi_theta(theta, dphi_) * self._phi_r(r, d_r) - d_phi_d_theta2 = self._d_phi_theta2(theta, dphi_) * self._phi_r(r, d_r) - d_phi_dr_dtheta = self._d_phi_r(r, d_r) * self._d_phi_theta(theta, dphi_) - x_ = x - center_x - y_ = y - center_y - dr_dx = derivative_util.d_r_dx(x_, y_) - dr_dy = derivative_util.d_r_dy(x_, y_) - d_theta_dx = derivative_util.d_phi_dx(x_, y_) - d_theta_dy = derivative_util.d_phi_dy(x_, y_) - dr_dxx = derivative_util.d_x_diffr_dx(x_, y_) - dr_dxy = derivative_util.d_x_diffr_dy(x_, y_) - dr_dyy = derivative_util.d_y_diffr_dy(x_, y_) - d_theta_dxx = derivative_util.d_phi_dxx(x_, y_) - d_theta_dyy = derivative_util.d_phi_dyy(x_, y_) - d_theta_dxy = derivative_util.d_phi_dxy(x_, y_) - - f_xx = d_phi_dr2 * dr_dx**2 + d_phi_dr * dr_dxx + d_phi_d_theta2 * d_theta_dx**2 + d_phi_d_theta * d_theta_dxx + 2 * d_phi_dr_dtheta * dr_dx * d_theta_dx - f_yy = d_phi_dr2 * dr_dy**2 + d_phi_dr * dr_dyy + d_phi_d_theta2 * d_theta_dy**2 + d_phi_d_theta * d_theta_dyy + 2 * d_phi_dr_dtheta * dr_dy * d_theta_dy - f_xy = d_phi_dr2 * dr_dx * dr_dy + d_phi_dr * dr_dxy + d_phi_d_theta2 * d_theta_dx * d_theta_dy + d_phi_d_theta * d_theta_dxy + d_phi_dr_dtheta * dr_dx * d_theta_dy + d_phi_dr_dtheta * dr_dy * d_theta_dx - return f_xx * coeff, f_xy * coeff, f_xy * coeff, f_yy * coeff
- - @staticmethod - def _phi_r(r, d_r): - """ - - :param r: numpy array, radius - :param d_r: period of radial sinusoidal in units of angle - :return: radial component of the potential - """ - return np.cos(r/d_r) - - @staticmethod - def _d_phi_r(r, d_r): - """ - radial derivatives - - :param r: numpy array, radius - :param d_r: period of radial sinusoidal in units of angle - :return: radial component of the potential - """ - return -np.sin(r / d_r) / d_r - - @staticmethod - def _d_phi_r2(r, d_r): - """ - radial second derivatives - - :param r: numpy array, radius - :param d_r: period of radial sinusoidal in units of angle - :return: radial component of the potential - """ - return -np.cos(r / d_r) / d_r**2 - - @staticmethod - def _phi_theta(theta, d_theta): - """ - - :param theta: numpy array, orientation angle in 2pi convention - :param d_theta: period of tangential sinusoidal in radian - :return: tangential component of the potential - """ - return np.cos(theta / d_theta) - - @staticmethod - def _d_phi_theta(theta, d_theta): - """ - tangential derivatives - - :param theta: numpy array, angle - :param d_theta: period of tangential sinusoidal in radian - :return: tangential component of the potential - """ - return -np.sin(theta / d_theta) / d_theta - - @staticmethod - def _d_phi_theta2(r, d_theta): - """ - tangential derivatives - - :param r: numpy array, radius - :param d_theta: period of tangential sinusoidal in radian - :return: tangential component of the potential - """ - return -np.cos(r / d_theta) / d_theta**2
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/base_profile.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/base_profile.html deleted file mode 100644 index 2f91d030b..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/base_profile.html +++ /dev/null @@ -1,157 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.base_profile — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.base_profile

-__all__ = ['LensProfileBase']
-
-
-
[docs]class LensProfileBase(object): - """ - this class acts as the base class of all lens model functions and indicates raise statements and default outputs - if these functions are not defined in the specific lens model class - """ - - def __init__(self, *args, **kwargs): - self._static = False - -
[docs] def function(self, *args, **kwargs): - """ - lensing potential - - :param kwargs: keywords of the profile - :return: raise as definition is not defined - """ - raise ValueError('function definition is not defined in the profile you want to execute.')
- -
[docs] def derivatives(self, *args, **kwargs): - """ - deflection angles - - :param kwargs: keywords of the profile - :return: raise as definition is not defined - """ - raise ValueError('derivatives definition is not defined in the profile you want to execute.')
- -
[docs] def hessian(self, *args, **kwargs): - """ - returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - - :param kwargs: keywords of the profile - :return: raise as definition is not defined - """ - raise ValueError('hessian definition is not defined in the profile you want to execute.')
- -
[docs] def density_lens(self, *args, **kwargs): - """ - computes the density at 3d radius r given lens model parameterization. - The integral in the LOS projection of this quantity results in the convergence quantity. - - :param kwargs: keywords of the profile - :return: raise as definition is not defined - """ - raise ValueError('density_lens definition is not defined in the profile you want to execute.')
- -
[docs] def mass_3d_lens(self, *args, **kwargs): - """ - mass enclosed a 3d sphere or radius r given a lens parameterization with angular units - For this profile those are identical. - - :param kwargs: keywords of the profile - :return: raise as definition is not defined - """ - raise ValueError('mass_3d_lens definition is not defined in the profile you want to execute.')
- -
[docs] def set_static(self, **kwargs): - """ - pre-computes certain computations that do only relate to the lens model parameters and not to the specific - position where to evaluate the lens model - - :param kwargs: lens model parameters - :return: no return, for certain lens model some private self variables are initiated - """ - pass
- -
[docs] def set_dynamic(self): - """ - - :return: no return, deletes pre-computed variables for certain lens models - """ - pass
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/chameleon.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/chameleon.html deleted file mode 100644 index d1bea936b..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/chameleon.html +++ /dev/null @@ -1,693 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.chameleon — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.chameleon

-from lenstronomy.LensModel.Profiles.nie import NIE
-from lenstronomy.LensModel.Profiles.point_mass import PointMass
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-import lenstronomy.Util.param_util as param_util
-import numpy as np
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -class Chameleon(LensProfileBase): - """ - class of the Chameleon model (See Suyu+2014) an elliptical truncated double isothermal profile - - """ - param_names = ['alpha_1', 'w_c', 'w_t', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'alpha_1': 0, 'w_c': 0, 'w_t': 0, 'e1': -0.8, 'e2': -0.8, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'alpha_1': 100, 'w_c': 100, 'w_t': 100, 'e1': 0.8, 'e2': 0.8, 'center_x': 100, 'center_y': 100} - - def __init__(self, static=False): - self._nie_1 = NIE() - self._nie_2 = NIE() - super(Chameleon, self).__init__() - self._static = static - -
[docs] def function(self, x, y, alpha_1, w_c, w_t, e1, e2, center_x=0, center_y=0): - """ - - :param x: ra-coordinate - :param y: dec-coordinate - :param alpha_1: deflection angle at 1 (arcseconds) from the center - :param w_c: see Suyu+2014 - :param w_t: see Suyu+2014 - :param e1: ellipticity parameter - :param e2: ellipticity parameter - :param center_x: ra center - :param center_y: dec center - :return: lensing potential - """ - - theta_E_conv, w_c, w_t, s_scale_1, s_scale_2 = self.param_convert(alpha_1, w_c, w_t, e1, e2) - f_1 = self._nie_1.function(x, y, theta_E_conv, e1, e2, s_scale_1, center_x, center_y) - f_2 = self._nie_2.function(x, y, theta_E_conv, e1, e2, s_scale_2, center_x, center_y) - f_ = f_1 - f_2 - return f_
- -
[docs] def derivatives(self, x, y, alpha_1, w_c, w_t, e1, e2, center_x=0, center_y=0): - """ - - :param x: ra-coordinate - :param y: dec-coordinate - :param alpha_1: deflection angle at 1 (arcseconds) from the center - :param w_c: see Suyu+2014 - :param w_t: see Suyu+2014 - :param e1: ellipticity parameter - :param e2: ellipticity parameter - :param center_x: ra center - :param center_y: dec center - :return: deflection angles (RA, DEC) - """ - theta_E_conv, w_c, w_t, s_scale_1, s_scale_2 = self.param_convert(alpha_1, w_c, w_t, e1, e2) - f_x_1, f_y_1 = self._nie_1.derivatives(x, y, theta_E_conv, e1, e2, s_scale_1, center_x, center_y) - f_x_2, f_y_2 = self._nie_2.derivatives(x, y, theta_E_conv, e1, e2, s_scale_2, center_x, center_y) - f_x = f_x_1 - f_x_2 - f_y = f_y_1 - f_y_2 - return f_x, f_y
- -
[docs] def hessian(self, x, y, alpha_1, w_c, w_t, e1, e2, center_x=0, center_y=0): - """ - - :param x: ra-coordinate - :param y: dec-coordinate - :param alpha_1: deflection angle at 1 (arcseconds) from the center - :param w_c: see Suyu+2014 - :param w_t: see Suyu+2014 - :param e1: ellipticity parameter - :param e2: ellipticity parameter - :param center_x: ra center - :param center_y: dec center - :return: second derivatives of the lensing potential (Hessian: f_xx, f_xy, f_yx, f_yy) - """ - theta_E_conv, w_c, w_t, s_scale_1, s_scale_2 = self.param_convert(alpha_1, w_c, w_t, e1, e2) - f_xx_1, f_xy_1, f_yx_1, f_yy_1 = self._nie_1.hessian(x, y, theta_E_conv, e1, e2, s_scale_1, center_x, center_y) - f_xx_2, f_xy_2, f_yx_2, f_yy_2 = self._nie_2.hessian(x, y, theta_E_conv, e1, e2, s_scale_2, center_x, center_y) - f_xx = f_xx_1 - f_xx_2 - f_yy = f_yy_1 - f_yy_2 - f_xy = f_xy_1 - f_xy_2 - f_yx = f_yx_1 - f_yx_2 - return f_xx, f_xy, f_yx, f_yy
- -
[docs] def density_lens(self, r, alpha_1, w_c, w_t, e1=0, e2=0, center_x=0, center_y=0): - """ - spherical average density as a function of 3d radius - - :param r: 3d radius - :param alpha_1: deflection angle at 1 (arcseconds) from the center - :param w_c: see Suyu+2014 - :param w_t: see Suyu+2014 - :param e1: ellipticity parameter - :param e2: ellipticity parameter - :param center_x: ra center - :param center_y: dec center - :return: matter density at 3d radius r - """ - theta_E_conv, w_c, w_t, s_scale_1, s_scale_2 = self.param_convert(alpha_1, w_c, w_t, e1, e2) - f_1 = self._nie_1.density_lens(r, theta_E_conv, e1, e2, s_scale_1, center_x, center_y) - f_2 = self._nie_2.density_lens(r, theta_E_conv, e1, e2, s_scale_2, center_x, center_y) - f_ = f_1 - f_2 - return f_
- -
[docs] def mass_3d_lens(self, r, alpha_1, w_c, w_t, e1=0, e2=0, center_x=0, center_y=0): - """ - mass enclosed 3d radius - - :param r: 3d radius - :param alpha_1: deflection angle at 1 (arcseconds) from the center - :param w_c: see Suyu+2014 - :param w_t: see Suyu+2014 - :param e1: ellipticity parameter - :param e2: ellipticity parameter - :param center_x: ra center - :param center_y: dec center - :return: mass enclosed 3d radius r - """ - theta_E_conv, w_c, w_t, s_scale_1, s_scale_2 = self.param_convert(alpha_1, w_c, w_t, e1, e2) - m_1 = self._nie_1.mass_3d_lens(r, theta_E_conv, e1, e2, s_scale_1, center_x, center_y) - m_2 = self._nie_2.mass_3d_lens(r, theta_E_conv, e1, e2, s_scale_2, center_x, center_y) - m_ = m_1 - m_2 - return m_
- -
[docs] def param_convert(self, alpha_1, w_c, w_t, e1, e2): - """ - convert the parameter alpha_1 (deflection angle one arcsecond from the center) into the - "Einstein radius" scale parameter of the two NIE profiles - - :param alpha_1: deflection angle at 1 (arcseconds) from the center - :param w_c: see Suyu+2014 - :param w_t: see Suyu+2014 - :param e1: eccentricity modulus - :param e2: eccentricity modulus - :return: - """ - if self._static is True: - return self._theta_convert_static, self._w_c_static, self._w_t_stactic, self._s_scale_1_static, self._s_scale_2_static - return self._param_convert(alpha_1, w_c, w_t, e1, e2)
- - def _param_convert(self, alpha_1, w_c, w_t, e1, e2): - if not w_t >= w_c: - return 0, w_t, w_c, 1, 1 - s_scale_1 = w_c - s_scale_2 = w_t - f_x_1, f_y_1 = self._nie_1.derivatives(1, 0, theta_E=1, e1=0, e2=0, s_scale=s_scale_1) - f_x_2, f_y_2 = self._nie_2.derivatives(1, 0, theta_E=1, e1=0, e2=0, s_scale=s_scale_2) - f_x = f_x_1 - f_x_2 - theta_E_convert = alpha_1 / f_x - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - s_scale_1 = np.sqrt(4 * w_c ** 2 / (1. + q) ** 2) - s_scale_2 = np.sqrt(4 * w_t ** 2 / (1. + q) ** 2) - return theta_E_convert, w_c, w_t, s_scale_1, s_scale_2 - -
[docs] def set_static(self, alpha_1, w_c, w_t, e1, e2, center_x=0, center_y=0): - """ - - :param alpha_1: - :param w_c: - :param w_t: - :param e1: - :param e2: - :param center_x: - :param center_y: - :return: - """ - self._static = True - self._theta_convert_static, self._w_c_static, self._w_t_stactic, self._s_scale_1_static, self._s_scale_2_static = self._param_convert(alpha_1, w_c, w_t, e1, e2) - self._nie_1.set_static(self._theta_convert_static, e1, e2, self._s_scale_1_static, center_x, center_y) - self._nie_2.set_static(self._theta_convert_static, e1, e2, self._s_scale_2_static, center_x, center_y)
- -
[docs] def set_dynamic(self): - """ - - :return: - """ - self._static = False - if hasattr(self, '_theta_convert_static'): - del self._theta_convert_static - if hasattr(self, '_w_c_static'): - del self._w_c_static - if hasattr(self, '_w_t_stactic'): - del self._w_t_stactic - if hasattr(self, '_s_scale_1_static'): - del self._s_scale_1_static - if hasattr(self, '_s_scale_2_static'): - del self._s_scale_2_static - self._nie_1.set_dynamic() - self._nie_2.set_dynamic()
- - -
[docs]@export -class DoubleChameleon(LensProfileBase): - """ - class of the Chameleon model (See Suyu+2014) an elliptical truncated double isothermal profile - - """ - param_names = ['alpha_1', 'ratio', 'w_c1', 'w_t1', 'e11', 'e21', 'w_c2', 'w_t2', 'e12', 'e22', 'center_x', 'center_y'] - lower_limit_default = {'alpha_1': 0, 'ratio': 0, 'w_c1': 0, 'w_t1': 0, 'e11': -0.8, 'e21': -0.8, - 'w_c2': 0, 'w_t2': 0, 'e12': -0.8, 'e22': -0.8, - 'center_x': -100, 'center_y': -100} - upper_limit_default = {'alpha_1': 100, 'ratio': 100, 'w_c1': 100, 'w_t1': 100, 'e11': 0.8, 'e21': 0.8, - 'w_c2': 100, 'w_t2': 100, 'e12': 0.8, 'e22': 0.8, - 'center_x': 100, 'center_y': 100} - - def __init__(self): - self._chameleon_1 = Chameleon() - self._chameleon_2 = Chameleon() - super(DoubleChameleon, self).__init__() - -
[docs] def function(self, x, y, alpha_1, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0): - """ - :param x: ra-coordinate - :param y: dec-coordinate - :param alpha_1: deflection angle at 1 (arcseconds) from the center - :param ratio: ratio of deflection amplitude at radius = 1 of the first to second Chameleon profile - :param w_c1: Suyu+2014 for first profile - :param w_t1: Suyu+2014 for first profile - :param e11: ellipticity parameter for first profile - :param e21: ellipticity parameter for first profile - :param w_c2: Suyu+2014 for second profile - :param w_t2: Suyu+2014 for second profile - :param e12: ellipticity parameter for second profile - :param e22: ellipticity parameter for second profile - :param center_x: ra center - :param center_y: dec center - :return: lensing potential - """ - - f_1 = self._chameleon_1.function(x, y, alpha_1 / (1. + 1. / ratio), w_c1, w_t1, e11, e21, center_x, center_y) - f_2 = self._chameleon_2.function(x, y, alpha_1 / (1. + ratio), w_c2, w_t2, e12, e22, center_x, center_y) - return f_1 + f_2
- -
[docs] def derivatives(self, x, y, alpha_1, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0): - """ - :param x: ra-coordinate - :param y: dec-coordinate - :param alpha_1: deflection angle at 1 (arcseconds) from the center - :param ratio: ratio of deflection amplitude at radius = 1 of the first to second Chameleon profile - :param w_c1: Suyu+2014 for first profile - :param w_t1: Suyu+2014 for first profile - :param e11: ellipticity parameter for first profile - :param e21: ellipticity parameter for first profile - :param w_c2: Suyu+2014 for second profile - :param w_t2: Suyu+2014 for second profile - :param e12: ellipticity parameter for second profile - :param e22: ellipticity parameter for second profile^V - :param center_x: ra center - :param center_y: dec center - :return: deflection angles (RA, DEC) - """ - f_x1, f_y1 = self._chameleon_1.derivatives(x, y, alpha_1 / (1. + 1. / ratio), w_c1, w_t1, e11, e21, center_x, center_y) - f_x2, f_y2 = self._chameleon_2.derivatives(x, y, alpha_1 / (1. + ratio), w_c2, w_t2, e12, e22, center_x, center_y) - return f_x1 + f_x2, f_y1 + f_y2
- -
[docs] def hessian(self, x, y, alpha_1, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0): - """ - :param x: ra-coordinate - :param y: dec-coordinate - :param alpha_1: deflection angle at 1 (arcseconds) from the center - :param ratio: ratio of deflection amplitude at radius = 1 of the first to second Chameleon profile - :param w_c1: Suyu+2014 for first profile - :param w_t1: Suyu+2014 for first profile - :param e11: ellipticity parameter for first profile - :param e21: ellipticity parameter for first profile - :param w_c2: Suyu+2014 for second profile - :param w_t2: Suyu+2014 for second profile - :param e12: ellipticity parameter for second profile - :param e22: ellipticity parameter for second profile - :param center_x: ra center - :param center_y: dec center - :return: second derivatives of the lensing potential (Hessian: f_xx, f_yy, f_xy) - """ - f_xx1, f_xy1, f_yx1, f_yy1, = self._chameleon_1.hessian(x, y, alpha_1 / (1. + 1. / ratio), w_c1, w_t1, e11, e21, center_x, center_y) - f_xx2, f_xy2, f_yx2, f_yy2 = self._chameleon_2.hessian(x, y, alpha_1 / (1. + ratio), w_c2, w_t2, e12, e22, center_x, center_y) - return f_xx1 + f_xx2, f_xy1 + f_xy2, f_xy1 + f_xy2, f_yy1 + f_yy2
- -
[docs] def density_lens(self, r, alpha_1, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0): - """ - :param r: 3d radius - :param alpha_1: deflection angle at 1 (arcseconds) from the center - :param ratio: ratio of deflection amplitude at radius = 1 of the first to second Chameleon profile - :param w_c1: Suyu+2014 for first profile - :param w_t1: Suyu+2014 for first profile - :param e11: ellipticity parameter for first profile - :param e21: ellipticity parameter for first profile - :param w_c2: Suyu+2014 for second profile - :param w_t2: Suyu+2014 for second profile - :param e12: ellipticity parameter for second profile - :param e22: ellipticity parameter for second profile - :param center_x: ra center - :param center_y: dec center - :return: 3d density at radius r - """ - - f_1 = self._chameleon_1.density_lens(r, alpha_1 / (1. + 1. / ratio), w_c1, w_t1, e11, e21, center_x, center_y) - f_2 = self._chameleon_2.density_lens(r, alpha_1 / (1. + ratio), w_c2, w_t2, e12, e22, center_x, center_y) - return f_1 + f_2
- -
[docs] def mass_3d_lens(self, r, alpha_1, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0): - """ - :param r: 3d radius - :param alpha_1: deflection angle at 1 (arcseconds) from the center - :param ratio: ratio of deflection amplitude at radius = 1 of the first to second Chameleon profile - :param w_c1: Suyu+2014 for first profile - :param w_t1: Suyu+2014 for first profile - :param e11: ellipticity parameter for first profile - :param e21: ellipticity parameter for first profile - :param w_c2: Suyu+2014 for second profile - :param w_t2: Suyu+2014 for second profile - :param e12: ellipticity parameter for second profile - :param e22: ellipticity parameter for second profile - :param center_x: ra center - :param center_y: dec center - :return: mass enclosed 3d radius - """ - - m_1 = self._chameleon_1.mass_3d_lens(r, alpha_1 / (1. + 1. / ratio), w_c1, w_t1, e11, e21, center_x, center_y) - m_2 = self._chameleon_2.mass_3d_lens(r, alpha_1 / (1. + ratio), w_c2, w_t2, e12, e22, center_x, center_y) - return m_1 + m_2
- -
[docs] def set_static(self, alpha_1, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0): - self._chameleon_1.set_static(alpha_1 / (1. + 1. / ratio), w_c1, w_t1, e11, e21, center_x, center_y) - self._chameleon_2.set_static(alpha_1 / (1. + ratio), w_c2, w_t2, e12, e22, center_x, center_y)
- -
[docs] def set_dynamic(self): - self._chameleon_1.set_dynamic() - self._chameleon_2.set_dynamic()
- - -
[docs]@export -class TripleChameleon(LensProfileBase): - """ - class of the Chameleon model (See Suyu+2014) an elliptical truncated double isothermal profile - - """ - param_names = ['alpha_1', 'ratio12', 'ratio13', 'w_c1', 'w_t1', 'e11', 'e21', 'w_c2', 'w_t2', 'e12', 'e22', 'w_c3', 'w_t3', 'e13', - 'e23', 'center_x', 'center_y'] - lower_limit_default = {'alpha_1': 0, 'ratio12': 0, 'ratio13': 0, 'w_c1': 0, 'w_t1': 0, 'e11': -0.8, 'e21': -0.8, - 'w_c2': 0, 'w_t2': 0, 'e12': -0.8, 'e22': -0.8, - 'w_c3': 0, 'w_t3': 0, 'e13': -0.8, 'e23': -0.8, - 'center_x': -100, 'center_y': -100} - upper_limit_default = {'alpha_1': 100, 'ratio12': 100, 'ratio13': 100, 'w_c1': 100, 'w_t1': 100, 'e11': 0.8, 'e21': 0.8, - 'w_c2': 100, 'w_t2': 100, 'e12': 0.8, 'e22': 0.8, - 'w_c3': 100, 'w_t3': 100, 'e13': 0.8, 'e23': 0.8, - 'center_x': 100, 'center_y': 100} - - def __init__(self): - self._chameleon_1 = Chameleon() - self._chameleon_2 = Chameleon() - self._chameleon_3 = Chameleon() - super(TripleChameleon, self).__init__() - - @staticmethod - def _ratio_definition(alpha_1, ratio12, ratio13): - """ - - :param alpha_1: deflection angle at 1 arcsecond - :param ratio12: ratio of first to second amplitude - :param ratio13: ratio of first to third amplitude - :return: amplitudes of individual chameleon profiles - """ - amp1 = alpha_1 / (1. + 1. / ratio12 + 1. / ratio13) - amp2 = amp1 / ratio12 - amp3 = amp1 / ratio13 - return amp1, amp2, amp3 - -
[docs] def function(self, x, y, alpha_1, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, - center_x=0, center_y=0): - """ - - :param alpha_1: - :param ratio12: ratio of first to second amplitude - :param ratio13: ratio of first to third amplitude - :param w_c1: - :param w_t1: - :param e11: - :param e21: - :param w_c2: - :param w_t2: - :param e12: - :param e22: - :param center_x: - :param center_y: - :return: - """ - amp1, amp2, amp3 = self._ratio_definition(alpha_1, ratio12, ratio13) - f_1 = self._chameleon_1.function(x, y, amp1, w_c1, w_t1, e11, e21, center_x, center_y) - f_2 = self._chameleon_2.function(x, y, amp2, w_c2, w_t2, e12, e22, center_x, center_y) - f_3 = self._chameleon_3.function(x, y, amp3, w_c3, w_t3, e13, e23, center_x, center_y) - return f_1 + f_2 + f_3
- -
[docs] def derivatives(self, x, y, alpha_1, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, - e23, center_x=0, center_y=0): - """ - - :param alpha_1: - :param ratio12: ratio of first to second amplitude - :param ratio13: ratio of first to third amplidute - :param w_c1: - :param w_t1: - :param e11: - :param e21: - :param w_c2: - :param w_t2: - :param e12: - :param e22: - :param center_x: - :param center_y: - :return: - """ - amp1, amp2, amp3 = self._ratio_definition(alpha_1, ratio12, ratio13) - f_x1, f_y1 = self._chameleon_1.derivatives(x, y, amp1, w_c1, w_t1, e11, e21, center_x, center_y) - f_x2, f_y2 = self._chameleon_2.derivatives(x, y, amp2, w_c2, w_t2, e12, e22, center_x, center_y) - f_x3, f_y3 = self._chameleon_3.derivatives(x, y, amp3, w_c3, w_t3, e13, e23, center_x, center_y) - return f_x1 + f_x2 + f_x3, f_y1 + f_y2 + f_y3
- -
[docs] def hessian(self, x, y, alpha_1, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, - center_x=0, center_y=0): - """ - - :param alpha_1: - :param ratio12: ratio of first to second amplitude - :param ratio13: ratio of first to third amplidute - :param w_c1: - :param w_t1: - :param e11: - :param e21: - :param w_c2: - :param w_t2: - :param e12: - :param e22: - :param center_x: - :param center_y: - :return: - """ - amp1, amp2, amp3 = self._ratio_definition(alpha_1, ratio12, ratio13) - f_xx1, f_xy1, f_yx1, f_yy1 = self._chameleon_1.hessian(x, y, amp1, w_c1, w_t1, e11, e21, center_x, center_y) - f_xx2, f_xy2, f_yx2, f_yy2 = self._chameleon_2.hessian(x, y, amp2, w_c2, w_t2, e12, e22, center_x, center_y) - f_xx3, f_xy3, f_yx3, f_yy3 = self._chameleon_3.hessian(x, y, amp3, w_c3, w_t3, e13, e23, center_x, center_y) - return f_xx1 + f_xx2 + f_xx3, f_xy1 + f_xy2 + f_xy3, f_yx1 + f_yx2 + f_yx3, f_yy1 + f_yy2 + f_yy3
- -
[docs] def density_lens(self, r, alpha_1, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, - center_x=0, center_y=0): - """ - - :param r: 3d radius - :param alpha_1: - :param ratio12: ratio of first to second amplitude - :param ratio13: ratio of first to third amplitude - :param w_c1: - :param w_t1: - :param e11: - :param e21: - :param w_c2: - :param w_t2: - :param e12: - :param e22: - :param center_x: - :param center_y: - :return: density at radius r (spherical average) - """ - amp1, amp2, amp3 = self._ratio_definition(alpha_1, ratio12, ratio13) - f_1 = self._chameleon_1.density_lens(r, amp1, w_c1, w_t1, e11, e21, center_x, center_y) - f_2 = self._chameleon_2.density_lens(r, amp2, w_c2, w_t2, e12, e22, center_x, center_y) - f_3 = self._chameleon_3.density_lens(r, amp3, w_c3, w_t3, e13, e23, center_x, center_y) - return f_1 + f_2 + f_3
- -
[docs] def mass_3d_lens(self, r, alpha_1, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, - center_x=0, center_y=0): - """ - - :param r: 3d radius - :param alpha_1: - :param ratio12: ratio of first to second amplitude - :param ratio13: ratio of first to third amplitude - :param w_c1: - :param w_t1: - :param e11: - :param e21: - :param w_c2: - :param w_t2: - :param e12: - :param e22: - :param center_x: - :param center_y: - :return: mass enclosed 3d radius - """ - amp1, amp2, amp3 = self._ratio_definition(alpha_1, ratio12, ratio13) - m_1 = self._chameleon_1.mass_3d_lens(r, amp1, w_c1, w_t1, e11, e21, center_x, center_y) - m_2 = self._chameleon_2.mass_3d_lens(r, amp2, w_c2, w_t2, e12, e22, center_x, center_y) - m_3 = self._chameleon_3.mass_3d_lens(r, amp3, w_c3, w_t3, e13, e23, center_x, center_y) - return m_1 + m_2 + m_3
- -
[docs] def set_static(self, alpha_1, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, - center_x=0, center_y=0): - amp1, amp2, amp3 = self._ratio_definition(alpha_1, ratio12, ratio13) - self._chameleon_1.set_static(amp1, w_c1, w_t1, e11, e21, center_x, center_y) - self._chameleon_2.set_static(amp2, w_c2, w_t2, e12, e22, center_x, center_y) - self._chameleon_3.set_static(amp3, w_c3, w_t3, e13, e23, center_x, center_y)
- -
[docs] def set_dynamic(self): - self._chameleon_1.set_dynamic() - self._chameleon_2.set_dynamic() - self._chameleon_3.set_dynamic()
- - -
[docs]@export -class DoubleChameleonPointMass(LensProfileBase): - """ - class of the Chameleon model (See Suyu+2014) an elliptical truncated double isothermal profile - - """ - param_names = ['alpha_1', 'ratio_chameleon', 'ratio_pointmass', 'w_c1', 'w_t1', 'e11', 'e21', 'w_c2', 'w_t2', - 'e12', 'e22', 'center_x', 'center_y'] - lower_limit_default = {'alpha_1': 0, 'ratio_chameleon': 0, 'ratio_pointmass': 0, 'w_c1': 0, 'w_t1': 0, 'e11': -0.8, - 'e21': -0.8, 'w_c2': 0, 'w_t2': 0, 'e12': -0.8, 'e22': -0.8, - 'center_x': -100, 'center_y': -100} - upper_limit_default = {'alpha_1': 100, 'ratio_chameleon': 100, 'ratio_pointmass': 100, 'w_c1': 100, 'w_t1': 100, 'e11': 0.8, 'e21': 0.8, - 'w_c2': 100, 'w_t2': 100, 'e12': 0.8, 'e22': 0.8, - 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.chameleon = DoubleChameleon() - self.pointMass = PointMass() - super(DoubleChameleonPointMass, self).__init__() - -
[docs] def function(self, x, y, alpha_1, ratio_pointmass, ratio_chameleon, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, - center_x=0, center_y=0): - """ - #TODO chose better parameterization for combining point mass and Chameleon profiles - :param x: ra-coordinate - :param y: dec-coordinate - :param alpha_1: deflection angle at 1 (arcseconds) from the center - :param ratio_pointmass: ratio of point source Einstein radius to combined Chameleon deflection angle at r=1 - :param ratio_chameleon: ratio in deflection angles at r=1 for the two Chameleon profiles - :param w_c1: Suyu+2014 for first profile - :param w_t1: Suyu+2014 for first profile - :param e11: ellipticity parameter for first profile - :param e21: ellipticity parameter for first profile - :param w_c2: Suyu+2014 for second profile - :param w_t2: Suyu+2014 for second profile - :param e12: ellipticity parameter for second profile - :param e22: ellipticity parameter for second profile - :param center_x: ra center - :param center_y: dec center - :return: - """ - f_1 = self.pointMass.function(x, y, alpha_1 / (1. + 1. / ratio_pointmass), center_x, center_y) - f_2 = self.chameleon.function(x, y, alpha_1 / (1. + ratio_pointmass), ratio_chameleon, w_c1, w_t1, e11, e21, - w_c2, w_t2, e12, e22, center_x, center_y) - return f_1 + f_2
- -
[docs] def derivatives(self, x, y, alpha_1, ratio_pointmass, ratio_chameleon, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, - center_x=0, center_y=0): - """ - - :param x: - :param y: - :param alpha_1: - :param ratio_pointmass: ratio of point source Einstein radius to combined Chameleon deflection angle at r=1 - :param ratio_chameleon: ratio in deflection angles at r=1 for the two Chameleon profiles - :param w_c1: Suyu+2014 for first profile - :param w_t1: Suyu+2014 for first profile - :param e11: ellipticity parameter for first profile - :param e21: ellipticity parameter for first profile - :param w_c2: Suyu+2014 for second profile - :param w_t2: Suyu+2014 for second profile - :param e12: ellipticity parameter for second profile - :param e22: ellipticity parameter for second profile - :param center_x: ra center - :param center_y: dec center - :return: - """ - f_x1, f_y1 = self.pointMass.derivatives(x, y, alpha_1 / (1. + 1. / ratio_pointmass), center_x, center_y) - f_x2, f_y2 = self.chameleon.derivatives(x, y, alpha_1 / (1. + ratio_pointmass), ratio_chameleon, w_c1, w_t1, - e11, e21, w_c2, w_t2, e12, e22, center_x, center_y) - return f_x1 + f_x2, f_y1 + f_y2
- -
[docs] def hessian(self, x, y, alpha_1, ratio_pointmass, ratio_chameleon, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, - center_x=0, center_y=0): - """ - - :param x: - :param y: - :param alpha_1: - :param ratio_pointmass: ratio of point source Einstein radius to combined Chameleon deflection angle at r=1 - :param ratio_chameleon: ratio in deflection angles at r=1 for the two Chameleon profiles - :param w_c1: Suyu+2014 for first profile - :param w_t1: Suyu+2014 for first profile - :param e11: ellipticity parameter for first profile - :param e21: ellipticity parameter for first profile - :param w_c2: Suyu+2014 for second profile - :param w_t2: Suyu+2014 for second profile - :param e12: ellipticity parameter for second profile - :param e22: ellipticity parameter for second profile - :param center_x: ra center - :param center_y: dec center - :return: - """ - f_xx1, f_xy1, f_yx1, f_yy1 = self.pointMass.hessian(x, y, alpha_1 / (1. + 1. / ratio_pointmass), center_x, center_y) - f_xx2, f_xy2, f_yx2, f_yy2 = self.chameleon.hessian(x, y, alpha_1 / (1. + ratio_pointmass), ratio_chameleon, w_c1, w_t1, - e11, e21, w_c2, w_t2, e12, e22, center_x, center_y) - return f_xx1 + f_xx2, f_xy1 + f_xy2, f_yx1 + f_yx2, f_yy1 + f_yy2
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/cnfw.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/cnfw.html deleted file mode 100644 index 5831ef4d2..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/cnfw.html +++ /dev/null @@ -1,448 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.cnfw — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.cnfw

-__author__ = 'dgilman', 'sibirrer'
-
-import numpy as np
-from scipy.integrate import quad
-from lenstronomy.LensModel.Profiles.nfw import NFW
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['CNFW']
-
-
-
[docs]class CNFW(LensProfileBase): - """ - this class computes the lensing quantities of a cored NFW profile: - rho = rho0 * (r + r_core)^-1 * (r + rs)^-2 - alpha_Rs is the normalization equivalent to the deflection angle at rs in the absence of a core - - """ - model_name = 'CNFW' - _s = 0.001 # numerical limit for minimal radius - param_names = ['Rs', 'alpha_Rs', 'r_core', 'center_x', 'center_y'] - lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'r_core': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'r_core': 100, 'center_x': 100, 'center_y': 100} - - def __init__(self): - """ - - """ - self._nfw = NFW() - super(CNFW, self).__init__() - -
[docs] def function(self, x, y, Rs, alpha_Rs, r_core, center_x=0, center_y=0): - """ - - :param x: angular position - :param y: angular position - :param Rs: angular turn over point - :param alpha_Rs: deflection at Rs (in the absence of a core - :param r_core: core radius - :param center_x: center of halo - :param center_y: center of halo - :return: - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_ ** 2 + y_ ** 2) - r = np.maximum(r, self._s) - rho0 = self._alpha2rho0(alpha_Rs=alpha_Rs, Rs=Rs, r_core=r_core) - if isinstance(r, int) or isinstance(r, float): - return self._num_integral_potential(r, Rs, rho0, r_core) - else: - #TODO: currently the numerical integral is done one by one. More efficient is sorting the radial list and - # then perform one numerical integral reading out to the radial points - f_ = [] - for i in range(len(r)): - f_.append(self._num_integral_potential(r[i], Rs, rho0, r_core)) - return np.array(f_)
- - def _num_integral_potential(self, r, Rs, rho0, r_core): - """ - - :param r: - :param r_core: - :return: - """ - def _integrand(x): - return self.alpha_r(x, Rs, rho0, r_core) - f_ = quad(_integrand, 0, r)[0] - return f_ - -
[docs] def derivatives(self, x, y, Rs, alpha_Rs, r_core, center_x=0, center_y=0): - - rho0 = self._alpha2rho0(alpha_Rs=alpha_Rs, Rs=Rs, r_core=r_core) - if Rs < 0.0000001: - Rs = 0.0000001 - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_ ** 2 + y_ ** 2) - R = np.maximum(R, self._s) - f_r = self.alpha_r(R, Rs, rho0, r_core) - f_x = f_r * x_ / R - f_y = f_r * y_ / R - return f_x, f_y
- -
[docs] def hessian(self, x, y, Rs, alpha_Rs, r_core, center_x=0, center_y=0): - - #raise Exception('Hessian for truncated nfw profile not yet implemented.') - - """ - returns Hessian matrix of function d^2f/dx^2, d^f/dy^2, d^2/dxdy - """ - rho0 = self._alpha2rho0(alpha_Rs=alpha_Rs, Rs=Rs, r_core=r_core) - if Rs < 0.0001: - Rs = 0.0001 - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_ ** 2 + y_ ** 2) - - kappa = self.density_2d(x_, y_, Rs, rho0, r_core) - gamma1, gamma2 = self.cnfwGamma(R, Rs, rho0, r_core, x_, y_) - f_xx = kappa + gamma1 - f_yy = kappa - gamma1 - f_xy = gamma2 - return f_xx, f_xy, f_xy, f_yy
- -
[docs] def density(self, R, Rs, rho0, r_core): - """ - three dimensional truncated NFW profile - - :param R: radius of interest - :type R: float/numpy array - :param Rs: scale radius - :type Rs: float - :param rho0: density normalization (central core density) - :type rho0: float - :return: rho(R) density - """ - - M0 = 4*np.pi*rho0 * Rs ** 3 - return (M0/4/np.pi) * ((r_core + R)*(R + Rs)**2) ** -1
- -
[docs] def density_lens(self, R, Rs, alpha_Rs, r_core): - """ - computes the density at 3d radius r given lens model parameterization. - The integral in the LOS projection of this quantity results in the convergence quantity. - - """ - rho0 = self._alpha2rho0(alpha_Rs=alpha_Rs, Rs=Rs, r_core=r_core) - return self.density(R, Rs, rho0, r_core)
- -
[docs] def density_2d(self, x, y, Rs, rho0, r_core, center_x=0, center_y=0): - """ - projected two dimenstional NFW profile (kappa*Sigma_crit) - - :param x: radius of interest - :type x: float/numpy array - :param Rs: scale radius - :type Rs: float - :param rho0: density normalization (characteristic density) - :type rho0: float - :return: Epsilon(R) projected density at radius R - """ - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_ ** 2 + y_ ** 2) - b = r_core * Rs ** -1 - x = R * Rs ** -1 - Fx = self._F(x, b) - - return 2 * rho0 * Rs * Fx
- -
[docs] def mass_3d(self, R, Rs, rho0, r_core): - """ - mass enclosed a 3d sphere or radius r - - :param R: - :param Rs: - :param rho0: - :param r_core: - :return: - """ - b = r_core * Rs ** -1 - x = R * Rs ** -1 - - M_0 = 4 * np.pi * Rs**3 * rho0 - - return M_0 * (x * (1+x) ** -1 * (-1+b) ** -1 + (-1+b) ** -2 * - ((2*b-1)*np.log(1/(1+x)) + b **2 * np.log(x / b + 1)))
- -
[docs] def mass_3d_lens(self, R, Rs, alpha_Rs, r_core): - """ - mass enclosed a 3d sphere or radius r given a lens parameterization with angular units - - :return: - """ - rho0 = self._alpha2rho0(alpha_Rs=alpha_Rs, Rs=Rs, r_core=r_core) - return self.mass_3d(R, Rs, rho0, r_core)
- -
[docs] def alpha_r(self, R, Rs, rho0, r_core): - """ - deflection angel of NFW profile along the radial direction - - :param R: radius of interest - :type R: float/numpy array - :param Rs: scale radius - :type Rs: float - :return: Epsilon(R) projected density at radius R - """ - #R = np.maximum(R, self._s) - x = R / Rs - x = np.maximum(x, self._s) - b = r_core * Rs ** -1 - #b = max(b, 0.000001) - gx = self._G(x, b) - a = 4*rho0*Rs**2*gx/x - return a
- -
[docs] def cnfwGamma(self, R, Rs, rho0, r_core, ax_x, ax_y): - """ - - shear gamma of NFW profile (times Sigma_crit) along the projection to coordinate 'axis' - - :param R: radius of interest - :type R: float/numpy array - :param Rs: scale radius - :type Rs: float - :param rho0: density normalization (characteristic density) - :type rho0: float - :return: Epsilon(R) projected density at radius R - """ - c = 0.000001 - if isinstance(R, int) or isinstance(R, float): - R = max(R, c) - else: - R[R <= c] = c - x = R * Rs ** -1 - b = r_core * Rs ** -1 - b = max(b, c) - gx = self._G(x, b) - Fx = self._F(x, b) - a = 2 * rho0 * Rs * (2 * gx / x ** 2 - Fx) # /x #2*rho0*Rs*(2*gx/x**2 - Fx)*axis/x - return a * (ax_y ** 2 - ax_x ** 2) / R ** 2, -a * 2 * (ax_x * ax_y) / R ** 2
- -
[docs] def mass_2d(self, R, Rs, rho0, r_core): - - """ - analytic solution of the projection integral - (convergence) - - """ - - x = R / Rs - b = r_core / Rs - b = max(b, 0.000001) - gx = self._G(x, b) - - m_2d = 4*np.pi*rho0*Rs*R**2*gx/x**2 - - return m_2d
- - def _alpha2rho0(self, alpha_Rs, Rs, r_core): - - b = r_core * Rs ** -1 - gx = self._G(1., b) - rho0 = alpha_Rs * (4 * Rs ** 2 * gx) ** -1 - return rho0 - - def _rho2alpha(self, rho0, Rs, r_core): - - b = r_core * Rs ** -1 - gx = self._G(1., b) - alpha = 4*Rs ** 2*gx*rho0 - return alpha - - def _nfw_func(self, x): - """ - Classic NFW function in terms of arctanh and arctan - :param x: r/Rs - :return: - """ - - #c = 0.000000001 - - if isinstance(x, np.ndarray): - #x[np.where(x<c)] = c - nfwvals = np.ones_like(x) - inds1 = np.where(x < 1) - inds2 = np.where(x > 1) - - nfwvals[inds1] = (1 - x[inds1] ** 2) ** -.5 * np.arctanh((1 - x[inds1] ** 2) ** .5) - nfwvals[inds2] = (x[inds2] ** 2 - 1) ** -.5 * np.arctan((x[inds2] ** 2 - 1) ** .5) - - return nfwvals - - elif isinstance(x, float) or isinstance(x, int): - #x = max(x, c) - if x == 1: - return 1 - if x < 1: - return (1 - x ** 2) ** -.5 * np.arctanh((1 - x ** 2) ** .5) - else: - return (x ** 2 - 1) ** -.5 * np.arctan((x ** 2 - 1) ** .5) - - def _F(self, X, b, c = 0.001): - """ - analytic solution of the projection integral - - :param X: a dimensionless quantity, either r/rs or r/rc - :type X: float >0 - """ - - if b == 1: - b = 1 + c - - prefac = (b - 1) ** -2 - - if isinstance(X, np.ndarray): - - X[np.where(X == 1)] = 1 - c - - output = np.empty_like(X) - - inds1 = np.where(np.absolute(X - b)<c) - output[inds1] = prefac*(-2 - b + (1 + b + b ** 2) * self._nfw_func(b)) * (1 + b) ** -1 - - inds2 = np.where(np.absolute(X - b)>=c) - - output[inds2] = prefac * ((X[inds2] ** 2 - 1) ** -1 * (1 - b - - (1 - b * X[inds2] ** 2) * self._nfw_func(X[inds2])) - - self._nfw_func(X[inds2] * b ** -1)) - - else: - - if X == 1: - X = 1-c - - if np.absolute(X - b)<c: - output = prefac * (-2 - b + (1 + b + b ** 2) * self._nfw_func(b)) * (1 + b) ** -1 - - else: - output = prefac * ((X ** 2 - 1) ** -1 * (1 - b - - (1 - b * X ** 2) * self._nfw_func(X)) - self._nfw_func(X * b ** -1)) - - return output - - def _G(self, X, b, c=0.000001): - """ - - analytic solution of integral for NFW profile to compute deflection angel and gamma - - :param X: R/Rs - :type X: float >0 - """ - if b == 1: - b = 1+c - - b2 = b ** 2 - x2 = X**2 - - fac = (1 - b) ** 2 - prefac = fac ** -1 - - if isinstance(X, np.ndarray): - - output = np.ones_like(X) - - inds1 = np.where(np.absolute(X - b) <= c) - inds2 = np.where(np.absolute(X - b) > c) - - output[inds1] = prefac * (2*(1-2*b+b**3)*self._nfw_func(b) + fac * (-1.38692 + np.log(b2)) - b2*np.log(b2)) - - output[inds2] = prefac * (fac * np.log(0.25 * x2[inds2]) - b2 * np.log(b2) + - 2 * (b2 - x2[inds2]) * self._nfw_func(X[inds2] * b**-1) + - 2 * (1+b*(x2[inds2] - 2)) * self._nfw_func(X[inds2])) - return 0.5*output - - else: - - if np.absolute(X - b) <= c: - output = prefac * (2*(1-2*b+b**3)*self._nfw_func(b) + - fac * (-1.38692 + np.log(b2)) - b2*np.log(b2)) - else: - output = prefac * (fac * np.log(0.25 * x2) - b2 * np.log(b2) + - 2 * (b2 - x2) * self._nfw_func(X * b**-1) + 2 * (1+b*(x2 - 2))* - self._nfw_func(X)) - - return 0.5 * output
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/cnfw_ellipse.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/cnfw_ellipse.html deleted file mode 100644 index bd4d385e7..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/cnfw_ellipse.html +++ /dev/null @@ -1,183 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.cnfw_ellipse — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.cnfw_ellipse

-__author__ = 'sibirrer'
-
-# this file contains a class to compute the Navaro-Frank-White function in mass/kappa space
-# the potential therefore is its integral
-
-import numpy as np
-from lenstronomy.LensModel.Profiles.cnfw import CNFW
-import lenstronomy.Util.param_util as param_util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['CNFW_ELLIPSE']
-
-
-
[docs]class CNFW_ELLIPSE(LensProfileBase): - """ - this class contains functions concerning the NFW profile - - relation are: R_200 = c * Rs - """ - param_names = ['Rs', 'alpha_Rs', 'r_core', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'r_core': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'r_core': 100, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.cnfw = CNFW() - self._diff = 0.0000000001 - super(CNFW_ELLIPSE, self).__init__() - -
[docs] def function(self, x, y, Rs, alpha_Rs, r_core, e1, e2, center_x=0, center_y=0): - """ - returns double integral of NFW profile - """ - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - x_shift = x - center_x - y_shift = y - center_y - cos_phi = np.cos(phi_G) - sin_phi = np.sin(phi_G) - e = min(abs(1. - q), 0.99) - xt1 = (cos_phi*x_shift+sin_phi*y_shift)*np.sqrt(1 - e) - xt2 = (-sin_phi*x_shift+cos_phi*y_shift)*np.sqrt(1 + e) - R_ = np.sqrt(xt1**2 + xt2**2) - f_ = self.cnfw.function(R_, 0, Rs, alpha_Rs, r_core, center_x=0, center_y=0) - return f_
- -
[docs] def derivatives(self, x, y, Rs, alpha_Rs, r_core, e1, e2, center_x=0, center_y=0): - """ - returns df/dx and df/dy of the function (integral of NFW) - """ - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - x_shift = x - center_x - y_shift = y - center_y - cos_phi = np.cos(phi_G) - sin_phi = np.sin(phi_G) - e = min(abs(1. - q), 0.99) - xt1 = (cos_phi*x_shift+sin_phi*y_shift)*np.sqrt(1 - e) - xt2 = (-sin_phi*x_shift+cos_phi*y_shift)*np.sqrt(1 + e) - - f_x_prim, f_y_prim = self.cnfw.derivatives(xt1, xt2, Rs, alpha_Rs, r_core, center_x=0, center_y=0) - f_x_prim *= np.sqrt(1 - e) - f_y_prim *= np.sqrt(1 + e) - f_x = cos_phi*f_x_prim-sin_phi*f_y_prim - f_y = sin_phi*f_x_prim+cos_phi*f_y_prim - return f_x, f_y
- -
[docs] def hessian(self, x, y, Rs, alpha_Rs, r_core, e1, e2, center_x=0, center_y=0): - """ - returns Hessian matrix of function d^2f/dx^2, d^f/dy^2, d^2/dxdy - """ - diff = 0.0000001 - alpha_ra_dx, alpha_dec_dx = self.derivatives(x + diff, y, Rs, alpha_Rs, r_core, e1, e2, center_x, center_y) - alpha_ra_dy, alpha_dec_dy = self.derivatives(x, y + diff, Rs, alpha_Rs, r_core, e1, e2, center_x, center_y) - - alpha_ra_dx_, alpha_dec_dx_ = self.derivatives(x - diff, y, Rs, alpha_Rs, r_core, e1, e2, center_x, center_y) - alpha_ra_dy_, alpha_dec_dy_ = self.derivatives(x, y - diff, Rs, alpha_Rs, r_core, e1, e2, center_x, center_y) - - dalpha_rara = (alpha_ra_dx - alpha_ra_dx_) / diff / 2 - dalpha_radec = (alpha_ra_dy - alpha_ra_dy_) / diff / 2 - dalpha_decra = (alpha_dec_dx - alpha_dec_dx_) / diff / 2 - dalpha_decdec = (alpha_dec_dy - alpha_dec_dy_) / diff / 2 - - f_xx = dalpha_rara - f_yy = dalpha_decdec - f_xy = dalpha_radec - f_yx = dalpha_decra - return f_xx, f_xy, f_yx, f_yy
- -
[docs] def mass_3d_lens(self, R, Rs, alpha_Rs, r_core, e1=0, e2=0): - """ - mass enclosed a 3d sphere or radius r given a lens parameterization with angular units - - :return: - """ - return self.cnfw.mass_3d_lens(R, Rs, alpha_Rs, r_core)
- -
[docs] def density_lens(self, R, Rs, alpha_Rs, r_core, e1=0, e2=0): - """ - computes the density at 3d radius r given lens model parameterization. - The integral in the LOS projection of this quantity results in the convergence quantity. - - """ - return self.cnfw.density_lens(R, Rs, alpha_Rs, r_core)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/const_mag.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/const_mag.html deleted file mode 100644 index 3d3457e2b..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/const_mag.html +++ /dev/null @@ -1,199 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.const_mag — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.const_mag

-__author__ = 'gipagano'
-
-import numpy as np
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['ConstMag']
-
-
-
[docs]class ConstMag(LensProfileBase): - """ - this class implements the macromodel potential of `Diego et al. <https://www.aanda.org/articles/aa/pdf/2019/07/aa35490-19.pdf>`_ - Convergence and shear are computed according to `Diego2018 <arXiv:1706.10281v2>`_ - """ - - param_names = ['center_x', 'center_y','mu_r', 'mu_t', 'parity', 'phi_G'] - lower_limit_default = {'center_x': -100, 'center_y': -100, 'mu_r':1, 'mu_t': 1000, 'parity': -1, 'phi_G':0.0} - upper_limit_default = {'center_x': 100, 'center_y': 100, 'mu_r':1, 'mu_t': 1000, 'parity': 1, 'phi_G':np.pi} - -
[docs] def function(self, x, y, mu_r, mu_t, parity, phi_G, center_x=0, center_y=0): - """ - - :param x: x-coord (in angles) - :param y: y-coord (in angles) - :param mu_r: radial magnification - :param mu_t: tangential magnification - :param parity: parity side of the macromodel. Either +1 (positive parity) or -1 (negative parity) - :param phi_G: shear orientation angle (relative to the x-axis) - :return: lensing potential - """ - - # positive parity case - if parity == 1: - gamma = (1./mu_t-1./mu_r)*0.5 - kappa = 1 -gamma-1./mu_r - - # negative parity case - elif parity == -1: - gamma = (1./mu_t+1./mu_r)*0.5 - kappa = 1 -gamma+1./mu_r - else: - raise ValueError('%f is not a valid value for the parity of the macromodel. Choose either +1 or -1.' % parity) - - # compute the shear along the x and y directions, rotate the vector in the opposite direction than the reference frame (compare with util.rotate) - gamma1, gamma2 = gamma*np.cos(2*phi_G), -gamma*np.sin(2*phi_G) - - x_shift = x - center_x - y_shift = y - center_y - f_ = 1./2. * kappa * (x_shift*x_shift + y_shift*y_shift) + 1./2. * gamma1 * (x_shift*x_shift - y_shift*y_shift)-gamma2*x_shift*y_shift - - return f_
- -
[docs] def derivatives(self, x, y, mu_r, mu_t, parity, phi_G, center_x=0, center_y=0): - """ - - :param x: x-coord (in angles) - :param y: y-coord (in angles) - :param mu_r: radial magnification - :param mu_t: tangential magnification - :param parity: parity of the side of the macromodel. Either +1 (positive parity) or -1 (negative parity) - :param phi_G: shear orientation angle (relative to the x-axis) - :return: deflection angle (in angles) - """ - - # positive parity case - if (parity== 1): - gamma = (1./mu_t-1./mu_r)*0.5 - kappa = 1 -gamma-1./mu_r - - # negative parity case - elif (parity== -1): - gamma = (1./mu_t+1./mu_r)*0.5 - kappa = 1 -gamma+1./mu_r - else: - raise ValueError('%f is not a valid value for the parity of the macromodel. Choose either +1 or -1.' % parity) - - # compute the shear along the x and y directions, rotate the vector in the opposite direction than the reference frame (compare with util.rotate) - gamma1, gamma2 = gamma*np.cos(2*phi_G), -gamma*np.sin(2*phi_G) - - x_shift = x - center_x - y_shift = y - center_y - f_x = (kappa+gamma1)*x_shift - gamma2*y_shift - f_y = (kappa-gamma1)*y_shift - gamma2*x_shift - - return f_x, f_y
- -
[docs] def hessian(self, x, y, mu_r, mu_t, parity, phi_G, center_x=0, center_y=0): - """ - - :param x: x-coord (in angles) - :param y: y-coord (in angles) - :param mu_r: radial magnification - :param mu_t: tangential magnification - :param parity: parity of the side of the macromodel. Either +1 (positive parity) or -1 (negative parity) - :param phi_G: shear orientation angle (relative to the x-axis) - :return: hessian matrix (in angles) - """ - - # positive parity case - if (parity== 1): - gamma = (1./mu_t-1./mu_r)*0.5 - kappa = 1 -gamma-1./mu_r - - # negative parity case - elif (parity== -1): - gamma = (1./mu_t+1./mu_r)*0.5 - kappa = 1 -gamma+1./mu_r - else: - raise ValueError('%f is not a valid value for the parity of the macromodel. Choose either +1 or -1.' % parity) - - # compute the shear along the x and y directions, rotate the vector in the opposite direction than the reference frame (compare with util.rotate) - gamma1, gamma2 = gamma*np.cos(2*phi_G), -gamma*np.sin(2*phi_G) - - f_xx = kappa + gamma1 - f_yy = kappa - gamma1 - f_xy = -gamma2 - - return f_xx, f_xy, f_xy, f_yy
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/constant_shift.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/constant_shift.html deleted file mode 100644 index 03a8ee489..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/constant_shift.html +++ /dev/null @@ -1,134 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.constant_shift — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.constant_shift

-__author__ = 'sibirrer'
-
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-import numpy as np
-
-__all__ = ['Shift']
-
-
-
[docs]class Shift(LensProfileBase): - """ - Lens model with a constant shift of the deflection field - """ - param_names = ['alpha_x', 'alpha_y'] - lower_limit_default = {'alpha_x': -1000, 'alpha_y': -1000} - upper_limit_default = {'alpha_x': 1000, 'alpha_y': 1000} - -
[docs] def function(self, x, y, alpha_x, alpha_y): - """ - - :param x: coordinate in image plane (angle) - :param y: coordinate in image plane (angle) - :param alpha_x: shift in x-direction (angle) - :param alpha_y: shift in y-direction (angle) - :return: lensing potential - """ - - return np.zeros_like(x)
- -
[docs] def derivatives(self, x, y, alpha_x, alpha_y): - """ - - :param x: coordinate in image plane (angle) - :param y: coordinate in image plane (angle) - :param alpha_x: shift in x-direction (angle) - :param alpha_y: shift in y-direction (angle) - :return: deflection in x- and y-direction - """ - f_x = np.ones_like(x) * alpha_x - f_y = np.ones_like(x) * alpha_y - return f_x, f_y
- -
[docs] def hessian(self, x, y, alpha_x, alpha_y): - """ - - :param x: coordinate in image plane (angle) - :param y: coordinate in image plane (angle) - :param alpha_x: shift in x-direction (angle) - :param alpha_y: shift in y-direction (angle) - :return: hessian elements f_xx, f_xy, f_yx, f_yy - """ - f_xx, f_xy, f_yx, f_yy = 0, 0, 0, 0 - return f_xx, f_xy, f_yx, f_yy
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/convergence.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/convergence.html deleted file mode 100644 index 8b88cd388..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/convergence.html +++ /dev/null @@ -1,145 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.convergence — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.convergence

-__author__ = 'sibirrer'
-
-import lenstronomy.Util.param_util as param_util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['Convergence']
-
-
-
[docs]class Convergence(LensProfileBase): - """ - a single mass sheet (external convergence) - """ - model_name = 'CONVERGENCE' - param_names = ['kappa', 'ra_0', 'dec_0'] - lower_limit_default = {'kappa': -10, 'ra_0': -100, 'dec_0': -100} - upper_limit_default = {'kappa': 10, 'ra_0': 100, 'dec_0': 100} - -
[docs] def function(self, x, y, kappa, ra_0=0, dec_0=0): - """ - lensing potential - - :param x: x-coordinate - :param y: y-coordinate - :param kappa: (external) convergence - :return: lensing potential - """ - theta, phi = param_util.cart2polar(x - ra_0, y - dec_0) - f_ = 1. / 2 * kappa * theta ** 2 - return f_
- -
[docs] def derivatives(self, x, y, kappa, ra_0=0, dec_0=0): - """ - deflection angle - - :param x: x-coordinate - :param y: y-coordinate - :param kappa: (external) convergence - :return: deflection angles (first order derivatives) - """ - x_ = x - ra_0 - y_ = y - dec_0 - f_x = kappa * x_ - f_y = kappa * y_ - return f_x, f_y
- -
[docs] def hessian(self, x, y, kappa, ra_0=0, dec_0=0): - """ - Hessian matrix - - :param x: x-coordinate - :param y: y-coordinate - :param kappa: external convergence - :param ra_0: zero point of polynomial expansion (no deflection added) - :param dec_0: zero point of polynomial expansion (no deflection added) - :return: second order derivatives f_xx, f_xy, f_yx, f_yy - """ - gamma1 = 0 - gamma2 = 0 - kappa = kappa - f_xx = kappa + gamma1 - f_yy = kappa - gamma1 - f_xy = gamma2 - return f_xx, f_xy, f_xy, f_yy
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/coreBurkert.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/coreBurkert.html deleted file mode 100644 index ab02c44a5..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/coreBurkert.html +++ /dev/null @@ -1,514 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.coreBurkert — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.coreBurkert

-__author__ = 'dgilman'
-
-import numpy as np
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['CoreBurkert']
-
-
-
[docs]class CoreBurkert(LensProfileBase): - """ - lensing properties of a modified Burkert profile with variable core size - normalized by rho0, the central core density - - """ - - param_names = ['Rs', 'alpha_Rs', 'r_core', 'center_x', 'center_y'] - lower_limit_default = {'Rs': 1, 'alpha_Rs': 0, 'r_core': 0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'Rs': 100, 'alpha_Rs': 100, 'r_core': 50, 'center_x': 100, 'center_y': 100} - -
[docs] def function(self, x, y, Rs, alpha_Rs, r_core, center_x=0, center_y=0): - """ - - :param x: angular position - :param y: angular position - :param Rs: angular turn over point - :param alpha_Rs: deflection angle at Rs - :param center_x: center of halo - :param center_y: center of halo - :return: - """ - - rho0 = self._alpha2rho0(alpha_Rs=alpha_Rs, Rs=Rs, r_core=r_core) - - if Rs < 0.0000001: - Rs = 0.0000001 - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_ ** 2 + y_ ** 2) - f_ = self.cBurkPot(R, Rs, rho0, r_core) - return f_
- -
[docs] def derivatives(self, x, y, Rs, alpha_Rs, r_core, center_x=0, center_y=0): - """ - deflection angles - :param x: x coordinate - :param y: y coordinate - :param Rs: scale radius - :param alpha_Rs: deflection angle at Rs - :param r_core: core radius - :param center_x: - :param center_y: - :return: - """ - - rho0 = self._alpha2rho0(alpha_Rs=alpha_Rs, Rs=Rs, r_core=r_core) - - if Rs < 0.0000001: - Rs = 0.0000001 - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_ ** 2 + y_ ** 2) - - dx, dy = self.coreBurkAlpha(R, Rs, rho0, r_core, x_, y_) - - return dx, dy
- -
[docs] def hessian(self, x, y, Rs, alpha_Rs, r_core, center_x=0, center_y=0): - - """ - :param x: x coordinate - :param y: y coordinate - :param Rs: scale radius - :param alpha_Rs: deflection angle at Rs - :param r_core: core radius - :param center_x: - :param center_y: - :return: - """ - - if Rs < 0.0001: - Rs = 0.0001 - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_ ** 2 + y_ ** 2) - - rho0 = self._alpha2rho0(alpha_Rs=alpha_Rs, Rs=Rs, r_core=r_core) - - kappa = self.density_2d(x_, y_, Rs, rho0, r_core) - - gamma1, gamma2 = self.cBurkGamma(R, Rs, rho0, r_core, x_, y_) - f_xx = kappa + gamma1 - f_yy = kappa - gamma1 - f_xy = gamma2 - return f_xx, f_xy, f_xy, f_yy
- -
[docs] def mass_2d(self, R, Rs, rho0, r_core): - - """ - analytic solution of the projection integral - (convergence) - - :param R: projected distance - :param Rs: scale radius - :param rho0: central core density - :param r_core: core radius - """ - - x = R * Rs ** -1 - p = Rs * r_core ** -1 - gx = self._G(x, p) - - m_2d = 2 * np.pi * rho0 * Rs ** 3 * gx - - return m_2d
- -
[docs] def coreBurkAlpha(self, R, Rs, rho0, r_core, ax_x, ax_y): - """ - deflection angle - - :param R: - :param Rs: - :param rho0: - :param r_core: - :param ax_x: - :param ax_y: - :return: - """ - x = R * Rs ** -1 - p = Rs * r_core ** -1 - - gx = self._G(x, p) - - a = 2 * rho0 * Rs ** 2 * gx / x - - return a * ax_x / R, a * ax_y / R
- -
[docs] def density(self, R, Rs, rho0, r_core): - """ - three dimensional cored Burkert profile - - :param R: radius of interest - :type R: float/numpy array - :param Rs: scale radius - :type Rs: float - :param rho0: characteristic density - :type rho0: float - :return: rho(R) density - """ - - M0 = 4*np.pi * Rs ** 3 * rho0 - - return (M0 / (4*np.pi)) * ((r_core + R) * (Rs ** 2 + R ** 2)) ** -1
- -
[docs] def density_2d(self, x, y, Rs, rho0, r_core, center_x=0, center_y=0): - """ - projected two dimenstional core Burkert profile (kappa*Sigma_crit) - - :param x: x coordinate - :param y: y coordinate - :param Rs: scale radius - :param rho0: central core density - :param r_core: core radius - """ - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_ ** 2 + y_ ** 2) - x = R * Rs ** -1 - p = Rs * r_core ** -1 - Fx = self._F(x, p) - - return 2 * rho0 * Rs * Fx
- -
[docs] def mass_3d(self, R, Rs, rho0, r_core): - """ - :param R: projected distance - :param Rs: scale radius - :param rho0: central core density - :param r_core: core radius - """ - - Rs = float(Rs) - b = r_core * Rs ** -1 - c = R * Rs ** -1 - - M0 = 4*np.pi*Rs**3 * rho0 - - return M0 * (1+b**2) ** -1 * (0.5*np.log(1+c**2) + b**2*np.log(c*b**-1 + 1) - b*np.arctan(c))
- -
[docs] def cBurkPot(self, R, Rs, rho0, r_core): - - """ - :param R: projected distance - :param Rs: scale radius - :param rho0: central core density - :param r_core: core radius - """ - x = R * Rs ** -1 - p = Rs * r_core ** -1 - hx = self._H(x, p) - - return 2 * rho0 * Rs ** 3 * hx
- -
[docs] def cBurkGamma(self, R, Rs, rho0, r_core, ax_x, ax_y): - """ - - :param R: projected distance - :param Rs: scale radius - :param rho0: central core density - :param r_core: core radius - :param ax_x: x coordinate - :param ax_y: y coordinate - :return: - """ - c = 0.000001 - - if isinstance(R, int) or isinstance(R, float): - R = max(R, c) - else: - R[R <= c] = c - - x = R * Rs ** -1 - p = Rs * r_core ** -1 - - gx = self._G(x, p) - fx = self._F(x, p) - - m_x = 2 * rho0 * Rs ** 3 * gx - kappa = 2 * rho0 * Rs * fx - - a = 2 * (m_x * R ** -2 - kappa) - - return 0.5 * a * (ax_y ** 2 - ax_x ** 2) / R ** 2, -a * (ax_x * ax_y) / R ** 2
- - @staticmethod - def _u(x): - - return np.sqrt(1 + x ** 2) - - @staticmethod - def _g(x, p): - - return np.sqrt(1 - x ** 2 * p ** 2) - - @staticmethod - def _f(x, p): - - return np.sqrt(x ** 2 * p ** 2 - 1) - - def _H(self, x, p): - - prefactor = (p + p ** 3) ** -1 * p - - if isinstance(x, np.ndarray): - - inds0 = np.where(x * p == 1) - inds1 = np.where(x * p < 1) - inds2 = np.where(x * p > 1) - func = np.ones_like(x) - - func[inds1] = 0.9058413472016891 + (-0.9640065632861909 + np.pi * self._u(x[inds1]) - - 0.9058413472016892 * p) * p + 2 * p ** 2 * ( - self._u(x[inds1]) - 0.5 * np.arctanh(self._u(x[inds1]) ** -1)) * np.arctanh( - self._u(x[inds1]) ** -1) + \ - 2 * (self._g(x[inds1], p) - 0.5 * np.arctanh(self._g(x[inds1], p))) * \ - np.arctanh(self._g(x[inds1], p)) + (1 + p ** 2) * np.log(x[inds1]) ** 2 - np.pi * p * \ - np.log(1 + self._u(x[inds1])) + (0.3068528194400547 + 0.25 * np.log(p ** 2)) * \ - np.log(p ** 2) + np.log(x[inds1]) * ( - 0.6137056388801094 + 0.6137056388801094 * p ** 2 + np.log(p ** 2)) - - func[inds2] = 0.9058413472016891 + (-0.9640065632861909 + np.pi * self._u(x[inds2]) - - 0.9058413472016892 * p) * p + 2 * p ** 2 * ( - self._u(x[inds2]) - 0.5 * np.arctanh(self._u(x[inds2]) ** -1)) * np.arctanh( - self._u(x[inds2]) ** -1) + \ - -2 * (self._f(x[inds2], p) - 0.5 * np.arctan(self._f(x[inds2], p))) * \ - np.arctan(self._f(x[inds2], p)) + (1 + p ** 2) * np.log(x[inds2]) ** 2 - np.pi * p * \ - np.log(1 + self._u(x[inds2])) + (0.3068528194400547 + 0.25 * np.log(p ** 2)) * \ - np.log(p ** 2) + np.log(x[inds2]) * ( - 0.6137056388801094 + 0.6137056388801094 * p ** 2 + np.log(p ** 2)) - - func[inds0] = 0.9058413472016891 + (-0.9640065632861909 + np.pi * self._u(x[inds0]) - - 0.9058413472016892 * p) * p + 2 * p ** 2 * ( - self._u(x[inds0]) - 0.5 * np.arctanh(self._u(x[inds0]) ** -1)) * np.arctanh( - self._u(x[inds0]) ** -1) \ - + (1 + p ** 2) * np.log(x[inds0]) ** 2 - np.pi * p * \ - np.log(1 + self._u(x[inds0])) + (0.3068528194400547 + 0.25 * np.log(p ** 2)) * \ - np.log(p ** 2) + np.log(x[inds0]) * ( - 0.6137056388801094 + 0.6137056388801094 * p ** 2 + np.log(p ** 2)) - - else: - if x * p < 1: - func = 0.9058413472016891 + (-0.9640065632861909 + np.pi * self._u(x) - - 0.9058413472016892 * p) * p + 2 * p ** 2 * ( - self._u(x) - 0.5 * np.arctanh(self._u(x) ** -1)) * np.arctanh(self._u(x) ** -1) + \ - 2 * (self._g(x, p) - 0.5 * np.arctanh(self._g(x, p))) * \ - np.arctanh(self._g(x, p)) + (1 + p ** 2) * np.log(x) ** 2 - np.pi * p * \ - np.log(1 + self._u(x)) + (0.3068528194400547 + 0.25 * np.log(p ** 2)) * \ - np.log(p ** 2) + np.log(x) * (0.6137056388801094 + 0.6137056388801094 * p ** 2 + np.log(p ** 2)) - elif x * p > 1: - func = 0.9058413472016891 + (-0.9640065632861909 + np.pi * self._u(x) - - 0.9058413472016892 * p) * p + 2 * p ** 2 * ( - self._u(x) - 0.5 * np.arctanh(self._u(x) ** -1)) * np.arctanh( - self._u(x) ** -1) + \ - -2 * (self._f(x, p) - 0.5 * np.arctan(self._f(x, p))) * \ - np.arctan(self._f(x, p)) + (1 + p ** 2) * np.log(x) ** 2 - np.pi * p * \ - np.log(1 + self._u(x)) + (0.3068528194400547 + 0.25 * np.log(p ** 2)) * \ - np.log(p ** 2) + np.log(x) * ( - 0.6137056388801094 + 0.6137056388801094 * p ** 2 + np.log(p ** 2)) - else: - func = 0.9058413472016891 + (-0.9640065632861909 + np.pi * self._u(x) - - 0.9058413472016892 * p) * p + 2 * p ** 2 * ( - self._u(x) - 0.5 * np.arctanh(self._u(x) ** -1)) * np.arctanh(self._u(x) ** -1) \ - + (1 + p ** 2) * np.log(x) ** 2 - np.pi * p * \ - np.log(1 + self._u(x)) + (0.3068528194400547 + 0.25 * np.log(p ** 2)) * \ - np.log(p ** 2) + np.log(x) * (0.6137056388801094 + 0.6137056388801094 * p ** 2 + np.log(p ** 2)) - - return prefactor * func - - def _F(self, x, p): - - """ - solution of the projection integal (kappa) - arctanh / arctan function - :param x: r/Rs - :param p: r_core / Rs - :return: - """ - prefactor = 0.5 * (1 + p ** 2) ** -1 * p - - if isinstance(x, np.ndarray): - - inds0 = np.where(x * p == 1) - inds1 = np.where(x * p < 1) - inds2 = np.where(x * p > 1) - - func = np.ones_like(x) - - func[inds0] = self._u(x[inds0]) ** -1 * (np.pi + 2 * p * np.arctanh(self._u(x[inds0]) ** -1)) - - func[inds1] = self._u(x[inds1]) ** -1 * (np.pi + 2 * p * np.arctanh(self._u(x[inds1]) ** -1)) - \ - (2 * p * self._g(x[inds1], p) ** -1 * np.arctanh(self._g(x[inds1], p))) - - func[inds2] = self._u(x[inds2]) ** -1 * (np.pi + 2 * p * np.arctanh(self._u(x[inds2]) ** -1)) - \ - (2 * p * self._f(x[inds2], p) ** -1 * np.arctan(self._f(x[inds2], p))) - - return prefactor * func - - else: - - if x * p == 1: - func = self._u(x) ** -1 * (np.pi + 2 * p * np.arctanh(self._u(x) ** -1)) - elif x * p < 1: - func = self._u(x) ** -1 * (np.pi + 2 * p * np.arctanh(self._u(x) ** -1)) - \ - (2 * p * self._g(x, p) ** -1 * np.arctanh(self._g(x, p))) - else: - func = self._u(x) ** -1 * (np.pi + 2 * p * np.arctanh(self._u(x) ** -1)) - \ - (2 * p * self._f(x, p) ** -1 * np.arctan(self._f(x, p))) - - return prefactor * func - - def _G(self, x, p): - """ - analytic solution of the 2d projected mass integral - integral: 2 * pi * x * kappa * dx - :param x: - :param p: - :return: - """ - - prefactor = (p + p ** 3) ** -1 * p - - if isinstance(x, np.ndarray): - - inds0 = np.where(x * p == 1) - inds1 = np.where(x * p < 1) - inds2 = np.where(x * p > 1) - - func = np.ones_like(x) - - func[inds0] = np.log(0.25 * x[inds0] ** 2 * p ** 2) + np.pi * p * (self._u(x[inds0]) - 1) + \ - 2 * p ** 2 * (self._u(x[inds0]) * np.arctanh(self._u(x[inds0]) ** -1) + - np.log(0.5 * x[inds0])) - - func[inds1] = np.log(0.25 * x[inds1] ** 2 * p ** 2) + np.pi * p * (self._u(x[inds1]) - 1) + \ - 2 * p ** 2 * (self._u(x[inds1]) * np.arctanh(self._u(x[inds1]) ** -1) + - np.log(0.5 * x[inds1])) + 2 * self._g(x[inds1], p) * np.arctanh( - self._g(x[inds1], p)) - - func[inds2] = np.log(0.25 * x[inds2] ** 2 * p ** 2) + np.pi * p * (self._u(x[inds2]) - 1) + \ - 2 * p ** 2 * (self._u(x[inds2]) * np.arctanh(self._u(x[inds2]) ** -1) + - np.log(0.5 * x[inds2])) - 2 * self._f(x[inds2], p) * np.arctan( - self._f(x[inds2], p)) - - - else: - - if x * p == 1: - - func = np.log(0.25 * x ** 2 * p ** 2) + np.pi * p * (self._u(x) - 1) + \ - 2 * p ** 2 * (self._u(x) * np.arctanh(self._u(x) ** -1) + - np.log(0.5 * x)) - - elif x * p < 1: - - func = np.log(0.25 * x ** 2 * p ** 2) + np.pi * p * (self._u(x) - 1) + \ - 2 * p ** 2 * (self._u(x) * np.arctanh(self._u(x) ** -1) + - np.log(0.5 * x)) + 2 * self._g(x, p) * np.arctanh(self._g(x, p)) - - else: - - func = np.log(0.25 * x ** 2 * p ** 2) + np.pi * p * (self._u(x) - 1) + \ - 2 * p ** 2 * (self._u(x) * np.arctanh(self._u(x) ** -1) + - np.log(0.5 * x)) - 2 * self._f(x, p) * np.arctan(self._f(x, p)) - - return func * prefactor - - def _alpha2rho0(self, alpha_Rs=None, Rs=None, r_core=None): - - p = Rs * r_core ** -1 - - gx = self._G(1, p) - - rho0 = alpha_Rs / (2 * Rs ** 2 * gx) - - return rho0 - - def _rho2alpha(self, rho0=None, Rs=None, r_core=None): - - p = Rs / r_core - gx = self._G(1, p) - alpha = 2 * Rs ** 2 * gx * rho0 - - return alpha
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/cored_density.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/cored_density.html deleted file mode 100644 index d6a386764..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/cored_density.html +++ /dev/null @@ -1,278 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.cored_density — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.cored_density

-__author__ = 'sibirrer'
-
-import numpy as np
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-from lenstronomy.Util import derivative_util as calc_util
-
-__all__ = ['CoredDensity']
-
-
-
[docs]class CoredDensity(LensProfileBase): - """ - class for a uniform cored density dropping steep in the outskirts - This profile is e.g. featured in Blum et al. 2020 https://arxiv.org/abs/2001.07182v1 - 3d rho(r) = 2/pi * Sigma_crit R_c**3 * (R_c**2 + r**2)**(-2) - - """ - _s = 0.000001 # numerical limit for minimal radius - param_names = ['sigma0', 'r_core', 'center_x', 'center_y'] - lower_limit_default = {'sigma0': -1, 'r_core': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'sigma0': 10, 'r_core': 100, 'center_x': 100, 'center_y': 100} - -
[docs] def function(self, x, y, sigma0, r_core, center_x=0, center_y=0): - """ - potential of cored density profile - - :param x: x-coordinate in angular units - :param y: y-coordinate in angular units - :param sigma0: convergence in the core - :param r_core: core radius - :param center_x: center of the profile - :param center_y: center of the profile - :return: lensing potential at (x, y) - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_ ** 2 + y_ ** 2) - r = np.maximum(r, self._s) - return 2 * sigma0 * r_core ** 2 * (2 * np.log(r) - np.log(np.sqrt(r**2 + r_core**2) - r_core))
- -
[docs] def derivatives(self, x, y, sigma0, r_core, center_x=0, center_y=0): - """ - deflection angle of cored density profile - - :param x: x-coordinate in angular units - :param y: y-coordinate in angular units - :param sigma0: convergence in the core - :param r_core: core radius - :param center_x: center of the profile - :param center_y: center of the profile - :return: alpha_x, alpha_y at (x, y) - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - r = np.maximum(r, self._s) - alpha_r = self.alpha_r(r, sigma0, r_core) - f_x = alpha_r * x_ / r - f_y = alpha_r * y_ / r - return f_x, f_y
- -
[docs] def hessian(self, x, y, sigma0, r_core, center_x=0, center_y=0): - """ - - :param x: x-coordinate in angular units - :param y: y-coordinate in angular units - :param sigma0: convergence in the core - :param r_core: core radius - :param center_x: center of the profile - :param center_y: center of the profile - :return: Hessian df/dxdx, df/dxdy, df/dydx, df/dydy at position (x, y) - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_ ** 2 + y_ ** 2) - r = np.maximum(r, self._s) - d_alpha_dr = self.d_alpha_dr(r, sigma0, r_core) - alpha = self.alpha_r(r, sigma0, r_core) - dr_dx = calc_util.d_r_dx(x_, y_) - dr_dy = calc_util.d_r_dy(x_, y_) - f_xx = d_alpha_dr * dr_dx * x_ / r + alpha * calc_util.d_x_diffr_dx(x_, y_) - f_yy = d_alpha_dr * dr_dy * y_ / r + alpha * calc_util.d_y_diffr_dy(x_, y_) - f_xy = d_alpha_dr * dr_dy * x_ / r + alpha * calc_util.d_x_diffr_dy(x_, y_) - return f_xx, f_xy, f_xy, f_yy
- -
[docs] @staticmethod - def alpha_r(r, sigma0, r_core): - """ - radial deflection angle of the cored density profile - - :param r: radius (angular scale) - :param sigma0: convergence in the core - :param r_core: core radius - :return: deflection angle - """ - return 2 * sigma0 * r_core ** 2 / r * (1 - (1 + (r/r_core)**2) ** (-1./2))
- -
[docs] @staticmethod - def d_alpha_dr(r, sigma0, r_core): - """ - radial derivatives of the radial deflection angle - - :param r: radius (angular scale) - :param sigma0: convergence in the core - :param r_core: core radius - :return: dalpha/dr - """ - return 2 * sigma0 * (((1 + (r/r_core) ** 2) ** (-3./2)) - (r_core/r) ** 2 * (1 - (1+(r/r_core)**2) ** (-1./2)))
- -
[docs] @staticmethod - def kappa_r(r, sigma0, r_core): - """ - convergence of the cored density profile. This routine is also for testing - - :param r: radius (angular scale) - :param sigma0: convergence in the core - :param r_core: core radius - :return: convergence at r - """ - return sigma0 * (1 + (r/r_core)**2) ** (-3./2)
- -
[docs] @staticmethod - def density(r, sigma0, r_core): - """ - rho(r) = 2/pi * Sigma_crit R_c**3 * (R_c**2 + r**2)**(-2) - - :param r: radius (angular scale) - :param sigma0: convergence in the core - :param r_core: core radius - :return: density at radius r - """ - return 2/np.pi * sigma0 * r_core**3 * (r_core**2 + r**2) ** (-2)
- -
[docs] def density_lens(self, r, sigma0, r_core): - """ - computes the density at 3d radius r given lens model parameterization. - The integral in the LOS projection of this quantity results in the convergence quantity. - - :param r: radius (angular scale) - :param sigma0: convergence in the core - :param r_core: core radius - :return: desnity at radius r - """ - return self.density(r, sigma0, r_core)
- -
[docs] def density_2d(self, x, y, sigma0, r_core, center_x=0, center_y=0): - """ - projected density at projected radius r - - :param x: x-coordinate in angular units - :param y: y-coordinate in angular units - :param sigma0: convergence in the core - :param r_core: core radius - :param center_x: center of the profile - :param center_y: center of the profile - :return: projected density - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_ ** 2 + y_ ** 2) - r = np.maximum(r, self._s) - return self.kappa_r(r, sigma0, r_core)
- -
[docs] def mass_2d(self, r, sigma0, r_core): - """ - mass enclosed in cylinder of radius r - - :param r: radius (angular scale) - :param sigma0: convergence in the core - :param r_core: core radius - :return: mass enclosed in cylinder of radius r - """ - return self.alpha_r(r, sigma0, r_core) * np.pi * r
- -
[docs] @staticmethod - def mass_3d(r, sigma0, r_core): - """ - mass enclosed 3d radius - - :param r: radius (angular scale) - :param sigma0: convergence in the core - :param r_core: core radius - :return: mass enclosed 3d radius - """ - return 8 * sigma0 * r_core**3 * (np.arctan(r/r_core)/(2*r_core) - r / (2 * (r**2 + r_core**2)))
- -
[docs] def mass_3d_lens(self, r, sigma0, r_core): - """ - mass enclosed a 3d sphere or radius r given a lens parameterization with angular units - For this profile those are identical. - - :param r: radius (angular scale) - :param sigma0: convergence in the core - :param r_core: core radius - :return: mass enclosed 3d radius - """ - return self.mass_3d(r, sigma0, r_core)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/cored_density_2.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/cored_density_2.html deleted file mode 100644 index 5ae5251a0..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/cored_density_2.html +++ /dev/null @@ -1,306 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.cored_density_2 — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.cored_density_2

-__author__ = 'sibirrer'
-
-import numpy as np
-from scipy.integrate import quad
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-from lenstronomy.Util import derivative_util as calc_util
-
-__all__ = ['CoredDensity2']
-
-
-
[docs]class CoredDensity2(LensProfileBase): - """ - class for a uniform cored density dropping steep in the outskirts - credits for suggesting this profile goes to Kfir Blum - - .. math:: - \\rho(r) = 2/\\pi * \\Sigma_{\\rm crit} R_c^2 * (R_c^2 + r^2)^{-3/2} - - This profile drops like an NFW profile as math:`\\rho(r)^{-3}`. - - """ - - model_name = 'CORED_DENSITY_2' - _s = 0.000001 # numerical limit for minimal radius - param_names = ['sigma0', 'r_core', 'center_x', 'center_y'] - lower_limit_default = {'sigma0': -1, 'r_core': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'sigma0': 10, 'r_core': 100, 'center_x': 100, 'center_y': 100} - -
[docs] def function(self, x, y, sigma0, r_core, center_x=0, center_y=0): - """ - potential of cored density profile - - :param x: x-coordinate in angular units - :param y: y-coordinate in angular units - :param sigma0: convergence in the core - :param r_core: core radius - :param center_x: center of the profile - :param center_y: center of the profile - :return: lensing potential at (x, y) - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_ ** 2 + y_ ** 2) - r = np.maximum(r, self._s) - if isinstance(r, int) or isinstance(r, float): - return self._num_integral_potential(r, sigma0, r_core) - else: - f_ = [] - for i in range(len(r)): - f_.append(self._num_integral_potential(r[i], sigma0, r_core)) - return np.array(f_)
- - def _num_integral_potential(self, r, sigma0, r_core): - """ - - :param r: - :param r_core: - :return: - """ - def _integrand(x): - return self.alpha_r(x, sigma0=sigma0, r_core=r_core) - f_ = quad(_integrand, 0, r)[0] - return f_ - -
[docs] def derivatives(self, x, y, sigma0, r_core, center_x=0, center_y=0): - """ - deflection angle of cored density profile - - :param x: x-coordinate in angular units - :param y: y-coordinate in angular units - :param sigma0: convergence in the core - :param r_core: core radius - :param center_x: center of the profile - :param center_y: center of the profile - :return: alpha_x, alpha_y at (x, y) - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - r = np.maximum(r, self._s) - alpha_r = self.alpha_r(r, sigma0, r_core) - f_x = alpha_r * x_ / r - f_y = alpha_r * y_ / r - return f_x, f_y
- -
[docs] def hessian(self, x, y, sigma0, r_core, center_x=0, center_y=0): - """ - - :param x: x-coordinate in angular units - :param y: y-coordinate in angular units - :param sigma0: convergence in the core - :param r_core: core radius - :param center_x: center of the profile - :param center_y: center of the profile - :return: Hessian df/dxdx, df/dxdy, df/dydx, df/dydy at position (x, y) - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_ ** 2 + y_ ** 2) - r = np.maximum(r, self._s) - d_alpha_dr = self.d_alpha_dr(r, sigma0, r_core) - alpha = self.alpha_r(r, sigma0, r_core) - dr_dx = calc_util.d_r_dx(x_, y_) - dr_dy = calc_util.d_r_dy(x_, y_) - f_xx = d_alpha_dr * dr_dx * x_ / r + alpha * calc_util.d_x_diffr_dx(x_, y_) - f_yy = d_alpha_dr * dr_dy * y_ / r + alpha * calc_util.d_y_diffr_dy(x_, y_) - f_xy = d_alpha_dr * dr_dy * x_ / r + alpha * calc_util.d_x_diffr_dy(x_, y_) - return f_xx, f_xy, f_xy, f_yy
- -
[docs] @staticmethod - def alpha_r(r, sigma0, r_core): - """ - radial deflection angle of the cored density profile - - :param r: radius (angular scale) - :param sigma0: convergence in the core - :param r_core: core radius - :return: deflection angle - """ - return sigma0 * r_core ** 2 * np.log((r_core**2 + r**2) / r_core**2) / r # this is mass_2d / (r * pi)
- -
[docs] @staticmethod - def d_alpha_dr(r, sigma0, r_core): - """ - radial derivatives of the radial deflection angle - - :param r: radius (angular scale) - :param sigma0: convergence in the core - :param r_core: core radius - :return: dalpha/dr - """ - return sigma0 * r_core ** 2 * (-1./r**2 * np.log((r_core**2 + r**2) / r_core**2) + 1/r * r_core**2 / - (r**2 + r_core**2) * 2 * r/r_core**2)
- -
[docs] @staticmethod - def kappa_r(r, sigma0, r_core): - """ - convergence of the cored density profile. This routine is also for testing - - :param r: radius (angular scale) - :param sigma0: convergence in the core - :param r_core: core radius - :return: convergence at r - """ - return sigma0 * r_core ** 2 / (r_core ** 2 + r ** 2)
- -
[docs] @staticmethod - def density(r, sigma0, r_core): - """ - rho(r) = 2/pi * Sigma_crit R_c**3 * (R_c**2 + r**2)**(-3/2) - - :param r: radius (angular scale) - :param sigma0: convergence in the core - :param r_core: core radius - :return: density at radius r - """ - return 1./2 * sigma0 * r_core**2 * (r_core**2 + r**2) ** (-3./2)
- -
[docs] def density_lens(self, r, sigma0, r_core): - """ - computes the density at 3d radius r given lens model parameterization. - The integral in the LOS projection of this quantity results in the convergence quantity. - - :param r: radius (angular scale) - :param sigma0: convergence in the core - :param r_core: core radius - :return: density at radius r - """ - return self.density(r, sigma0, r_core)
- -
[docs] def density_2d(self, x, y, sigma0, r_core, center_x=0, center_y=0): - """ - projected density at projected radius r - - :param x: x-coordinate in angular units - :param y: y-coordinate in angular units - :param sigma0: convergence in the core - :param r_core: core radius - :param center_x: center of the profile - :param center_y: center of the profile - :return: projected density - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_ ** 2 + y_ ** 2) - r = np.maximum(r, self._s) - return self.kappa_r(r, sigma0, r_core)
- -
[docs] @staticmethod - def mass_2d(r, sigma0, r_core): - """ - mass enclosed in cylinder of radius r - - :param r: radius (angular scale) - :param sigma0: convergence in the core - :param r_core: core radius - :return: mass enclosed in cylinder of radius r - """ - return sigma0 * r_core ** 2 * np.pi * np.log((r_core**2 + r**2) / r_core**2)
- -
[docs] @staticmethod - def mass_3d(r, sigma0, r_core): - """ - mass enclosed 3d radius - - :param r: radius (angular scale) - :param sigma0: convergence in the core - :param r_core: core radius - :return: mass enclosed 3d radius - """ - r_ = np.sqrt(r**2 + r_core**2) - return 2 * np.pi * sigma0 * r_core**2 * (r_ * np.log(r_ + r) - np.log(r_core) * r_ - r) / r_
- -
[docs] def mass_3d_lens(self, r, sigma0, r_core): - """ - mass enclosed a 3d sphere or radius r given a lens parameterization with angular units - For this profile those are identical. - - :param r: radius (angular scale) - :param sigma0: convergence in the core - :param r_core: core radius - :return: mass enclosed 3d radius - """ - return self.mass_3d(r, sigma0, r_core)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/cored_density_exp.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/cored_density_exp.html deleted file mode 100644 index 04c06b182..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/cored_density_exp.html +++ /dev/null @@ -1,279 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.cored_density_exp — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.cored_density_exp

-__author__ = 'lucateo'
-
-import numpy as np
-from scipy.special import exp1, erf
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['CoredDensityExp']
-
-
-
[docs]class CoredDensityExp(LensProfileBase): - """ - this class contains functions concerning an exponential cored density profile, - namely - - ..math:: - \\rho(r) = \\rho_0 \\exp(- (\\theta / \\theta_c)^2) - - """ - _s = 0.000001 # numerical limit for minimal radius - param_names = ['kappa_0', 'theta_c', 'center_x', 'center_y'] - lower_limit_default = {'kappa_0': 0, 'theta_c': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'kappa_0': 10, 'theta_c': 100, 'center_x': 100, 'center_y': 100} - -
[docs] @staticmethod - def rhotilde(kappa_0, theta_c): - """ - Computes the central density in angular units - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :return: central density in 1/arcsec - """ - return kappa_0 / (np.sqrt(np.pi) * theta_c)
- -
[docs] def function(self, x, y, kappa_0, theta_c, center_x=0, center_y=0): - """ - :param x: angular position (normally in units of arc seconds) - :param y: angular position (normally in units of arc seconds) - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :param center_x: center of halo (in angular units) - :param center_y: center of halo (in angular units) - :return: lensing potential (in arcsec^2) - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_ ** 2 + y_ ** 2) - r = np.maximum(r, self._s) - Integral_factor = 0.5 * exp1((r/theta_c)**2) + np.log((r/theta_c)) - function = kappa_0 * theta_c**2 * Integral_factor - return function
- -
[docs] @staticmethod - def alpha_radial(r, kappa_0, theta_c): - """ - returns the radial part of the deflection angle - :param r: angular position (normally in units of arc seconds) - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :return: radial deflection angle - """ - prefactor = kappa_0 * theta_c**2 / r - return prefactor * (1 - np.exp(- (r/theta_c)**2))
- -
[docs] def derivatives(self, x, y, kappa_0, theta_c, center_x=0, center_y=0): - """ - returns df/dx and df/dy of the function (lensing potential), which are - the deflection angles - - :param x: angular position (normally in units of arc seconds) - :param y: angular position (normally in units of arc seconds) - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :param center_x: center of halo (in angular units) - :param center_y: center of halo (in angular units) - :return: deflection angle in x, deflection angle in y - """ - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_**2 + y_**2) - R = np.maximum(R, 0.00000001) - f_x = self.alpha_radial(R, kappa_0, theta_c) * x_ / R - f_y = self.alpha_radial(R, kappa_0, theta_c) * y_ / R - return f_x, f_y
- -
[docs] def hessian(self, x, y, kappa_0, theta_c, center_x=0, center_y=0): - """ - :param x: angular position (normally in units of arc seconds) - :param y: angular position (normally in units of arc seconds) - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :param center_x: center of halo (in angular units) - :param center_y: center of halo (in angular units) - :return: Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_**2 + y_**2) - R = np.maximum(R, 0.00000001) - prefactor = kappa_0 * theta_c**2 - expFactor = np.exp(- (R/theta_c)**2) - factor1 = (1 - expFactor)/R**4 - factor2 = 2/(R**2 * theta_c**2) * expFactor - f_xx = prefactor * (factor1 * (y_**2 - x_**2) + factor2 * x_**2) - f_yy = prefactor * (factor1 * (x_**2 - y_**2) + factor2 * y_**2) - f_xy = prefactor * (- factor1 * 2 * x_ * y_ + factor2 * x_*y_) - return f_xx, f_xy, f_xy, f_yy
- -
[docs] def density(self, R, kappa_0, theta_c): - """ - three dimensional density profile in angular units - (rho0_physical = rho0_angular Sigma_crit / D_lens) - - :param R: projected angular position (normally in units of arc seconds) - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :return: rho(R) density - """ - rhotilde = self.rhotilde(kappa_0, theta_c) - return rhotilde * np.exp(-(R/theta_c)**2)
- -
[docs] def density_lens(self, r, kappa_0, theta_c): - """ - computes the density at 3d radius r given lens model parameterization. - The integral in the LOS projection of this quantity results in the convergence quantity. - - :param r: angular position (normally in units of arc seconds) - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :return: density rho(r) - """ - return self.density(r, kappa_0, theta_c)
- -
[docs] @staticmethod - def kappa_r(R, kappa_0, theta_c): - """ - convergence of the cored density profile. This routine is also for testing - - :param R: radius (angular scale) - :param kappa_0: convergence in the core - :param theta_c: core radius - :return: convergence at r - """ - expFactor = np.exp(- (R/theta_c)**2) - return kappa_0 * expFactor
- -
[docs] def density_2d(self, x, y, kappa_0, theta_c, center_x=0, center_y=0): - """ - projected two dimensional ULDM profile (convergence * Sigma_crit), but given our - units convention for rho0, it is basically the convergence - - :param x: angular position (normally in units of arc seconds) - :param y: angular position (normally in units of arc seconds) - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :return: Epsilon(R) projected density at radius R - """ - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_**2 + y_**2) - return self.kappa_r(R, kappa_0, theta_c)
- -
[docs] @staticmethod - def mass_3d(R, kappa_0, theta_c): - """ - mass enclosed a 3d sphere or radius r - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :param R: radius in arcseconds - :return: mass of soliton in angular units - """ - integral_factor = np.sqrt(np.pi) * erf(R/theta_c)/2 - R/theta_c * np.exp(-(R/theta_c)**2) - m_3d = 2 * np.sqrt(np.pi) * kappa_0 * theta_c**2 * integral_factor - return m_3d
- -
[docs] def mass_3d_lens(self, r, kappa_0, theta_c): - """ - mass enclosed a 3d sphere or radius r - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :return: mass - """ - m_3d = self.mass_3d(r, kappa_0, theta_c) - return m_3d
- -
[docs] def mass_2d(self, R, kappa_0, theta_c): - """ - mass enclosed a 2d sphere of radius r - returns - - .. math:: - M_{2D} = 2 \\pi \\int_0^r dr' r' \\int dz \\rho(\\sqrt(r'^2 + z^2)) - - :param kappa_0: central convergence of soliton - :param theta_c: core radius (in arcsec) - :return: M_2D (ULDM only) - """ - return self.alpha_radial(R, kappa_0, theta_c) * np.pi * R
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/cored_density_mst.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/cored_density_mst.html deleted file mode 100644 index 7d25f877c..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/cored_density_mst.html +++ /dev/null @@ -1,175 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.cored_density_mst — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.cored_density_mst

-__author__ = 'sibirrer'
-
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-from lenstronomy.LensModel.Profiles.cored_density import CoredDensity
-from lenstronomy.LensModel.Profiles.cored_density_2 import CoredDensity2
-from lenstronomy.LensModel.Profiles.cored_density_exp import CoredDensityExp
-from lenstronomy.LensModel.Profiles.uldm import Uldm
-from lenstronomy.LensModel.Profiles.convergence import Convergence
-
-__all__ = ['CoredDensityMST']
-
-
-
[docs]class CoredDensityMST(LensProfileBase): - """ - approximate mass-sheet transform of a density core. This routine takes the parameters of the density core and - subtracts a mass-sheet that approximates the cored profile in it's center to counter-act (in approximation) this - model. This allows for better sampling of the mass-sheet transformed quantities that do not have strong covariances. - The subtraction of the mass-sheet is done such that the sampler returns the real central convergence of the original - model (but be careful, the output of quantities like the Einstein angle of the main deflector are still the - not-scaled one). - Attention!!! The interpretation of the result is that the mass sheet as 'CONVERGENCE' that is present needs to be - subtracted in post-processing. - """ - param_names = ['lambda_approx', 'r_core', 'center_x', 'center_y'] - lower_limit_default = {'lambda_approx': -1, 'r_core': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'lambda_approx': 10, 'r_core': 100, 'center_x': 100, 'center_y': 100} - - def __init__(self, profile_type='CORED_DENSITY'): - if profile_type == 'CORED_DENSITY': - self._profile = CoredDensity() - elif profile_type == 'CORED_DENSITY_2': - self._profile = CoredDensity2() - elif profile_type == 'CORED_DENSITY_EXP': - self._profile = CoredDensityExp() - # Due to parameters name conventions/positioning, right now only the free soliton with - # the default value of slope = 8 is supported - elif profile_type == 'CORED_DENSITY_ULDM': - self._profile = Uldm() - else: - raise ValueError('profile_type %s not supported for CoredDensityMST instance.' % profile_type) - self._convergence = Convergence() - super(CoredDensityMST, self).__init__() - -
[docs] def function(self, x, y, lambda_approx, r_core, center_x=0, center_y=0): - """ - lensing potential of approximate mass-sheet correction - - :param x: x-coordinate - :param y: y-coordinate - :param lambda_approx: approximate mass sheet transform - :param r_core: core radius of the cored density profile - :param center_x: x-center of the profile - :param center_y: y-center of the profile - :return: lensing potential correction - """ - kappa_ext = (1 - lambda_approx)/lambda_approx - f_cored_density = self._profile.function(x, y, kappa_ext, r_core, center_x, center_y) - f_ms = self._convergence.function(x, y, kappa_ext, center_x, center_y) - return f_cored_density - f_ms
- -
[docs] def derivatives(self, x, y, lambda_approx, r_core, center_x=0, center_y=0): - """ - deflection angles of approximate mass-sheet correction - - :param x: x-coordinate - :param y: y-coordinate - :param lambda_approx: approximate mass sheet transform - :param r_core: core radius of the cored density profile - :param center_x: x-center of the profile - :param center_y: y-center of the profile - :return: alpha_x, alpha_y - """ - kappa_ext = (1 - lambda_approx)/lambda_approx - f_x_cd, f_y_cd = self._profile.derivatives(x, y, kappa_ext, r_core, center_x, center_y) - f_x_ms, f_y_ms = self._convergence.derivatives(x, y, kappa_ext, center_x, center_y) - return f_x_cd - f_x_ms, f_y_cd - f_y_ms
- -
[docs] def hessian(self, x, y, lambda_approx, r_core, center_x=0, center_y=0): - """ - Hessian terms of approximate mass-sheet correction - - :param x: x-coordinate - :param y: y-coordinate - :param lambda_approx: approximate mass sheet transform - :param r_core: core radius of the cored density profile - :param center_x: x-center of the profile - :param center_y: y-center of the profile - :return: df/dxx, df/dxy, df/dyx, df/dyy - """ - kappa_ext = (1 - lambda_approx)/lambda_approx - f_xx_cd, f_xy_cd, f_yx_cd, f_yy_cd = self._profile.hessian(x, y, kappa_ext, r_core, center_x, center_y) - f_xx_ms, f_xy_ms, f_yx_ms, f_yy_ms = self._convergence.hessian(x, y, kappa_ext, center_x, center_y) - return f_xx_cd - f_xx_ms, f_xy_cd - f_xy_ms, f_yx_cd - f_yx_ms, f_yy_cd - f_yy_ms
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/curved_arc_const.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/curved_arc_const.html deleted file mode 100644 index b3f7bda47..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/curved_arc_const.html +++ /dev/null @@ -1,325 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.curved_arc_const — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.curved_arc_const

-import numpy as np
-from lenstronomy.LensModel.Profiles.convergence import Convergence
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-from lenstronomy.Util import util
-
-__all__ = ['CurvedArcConstMST', 'CurvedArcConst']
-
-
-
[docs]class CurvedArcConstMST(LensProfileBase): - """ - lens model that describes a section of a highly magnified deflector region. - The parameterization is chosen to describe local observables efficient. - - Observables are: - - curvature radius (basically bending relative to the center of the profile) - - radial stretch (plus sign) thickness of arc with parity (more generalized than the power-law slope) - - tangential stretch (plus sign). Infinity means at critical curve - - direction of curvature - - position of arc - - Requirements: - - Should work with other perturbative models without breaking its meaning (say when adding additional shear terms) - - Must best reflect the observables in lensing - - minimal covariances between the parameters, intuitive parameterization. - - """ - param_names = ['tangential_stretch', 'radial_stretch', 'curvature', 'direction', 'center_x', 'center_y'] - lower_limit_default = {'tangential_stretch': -100, 'radial_stretch': -5, 'curvature': 0.000001, 'direction': -np.pi, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'tangential_stretch': 100, 'radial_stretch': 5, 'curvature': 100, 'direction': np.pi, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self._mst = Convergence() - self._curve = CurvedArcConst() - super(CurvedArcConstMST, self).__init__() - -
[docs] def function(self, x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y): - """ - ATTENTION: there may not be a global lensing potential! - - :param x: - :param y: - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: - """ - raise NotImplemented('lensing potential for regularly curved arc is not implemented')
- -
[docs] def derivatives(self, x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y): - """ - - :param x: - :param y: - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: - """ - lambda_mst = 1. / radial_stretch - kappa_ext = 1 - lambda_mst - curve_stretch = tangential_stretch / radial_stretch - - f_x_curve, f_y_curve = self._curve.derivatives(x, y, curve_stretch, curvature, direction, center_x, center_y) - f_x_mst, f_y_mst = self._mst.derivatives(x, y, kappa_ext, ra_0=center_x, dec_0=center_y) - f_x = lambda_mst * f_x_curve + f_x_mst - f_y = lambda_mst * f_y_curve + f_y_mst - return f_x, f_y
- -
[docs] def hessian(self, x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y): - """ - - :param x: - :param y: - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: - """ - lambda_mst = 1. / radial_stretch - kappa_ext = 1 - lambda_mst - curve_stretch = tangential_stretch / radial_stretch - f_xx_c, f_xy_c, f_yx_c, f_yy_c = self._curve.hessian(x, y, curve_stretch, curvature, direction, center_x, center_y) - f_xx_mst, f_xy_mst, f_yx_mst, f_yy_mst = self._mst.hessian(x, y, kappa_ext, ra_0=center_x, dec_0=center_y) - f_xx = lambda_mst * f_xx_c + f_xx_mst - f_xy = lambda_mst * f_xy_c + f_xy_mst - f_yx = lambda_mst * f_yx_c + f_yx_mst - f_yy = lambda_mst * f_yy_c + f_yy_mst - return f_xx, f_xy, f_yx, f_yy
- - -
[docs]class CurvedArcConst(LensProfileBase): - """ - curved arc lensing with orientation of curvature perpendicular to the x-axis with unity radial stretch - - """ - param_names = ['tangential_stretch', 'curvature', 'direction', 'center_x', 'center_y'] - lower_limit_default = {'tangential_stretch': -100, 'curvature': 0.000001, 'direction': -np.pi, - 'center_x': -100, 'center_y': -100} - upper_limit_default = {'tangential_stretch': 100, 'curvature': 100, 'direction': np.pi, - 'center_x': 100, 'center_y': 100} - -
[docs] def function(self, x, y, tangential_stretch, curvature, direction, center_x, center_y): - """ - ATTENTION: there may not be a global lensing potential! - - :param x: - :param y: - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: - """ - raise NotImplemented('lensing potential for regularly curved arc is not implemented')
- -
[docs] def derivatives(self, x, y, tangential_stretch, curvature, direction, center_x, center_y): - """ - - :param x: - :param y: - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: - """ - - r = 1 / curvature - # deflection angle to allow for tangential stretch - # (ratio of source position around zero point relative to radius is tangential stretch) - alpha = r * (1/tangential_stretch + 1) - - # shift - x_ = x - center_x - y_ = y - center_y - # rotate - x__, y__ = util.rotate(x_, y_, direction) - # evaluate - - # move x-coordinate to circle intercept with x-axis - if isinstance(x, int) or isinstance(x, float): - if abs(y__) > r: - f__x, f__y = 0, 0 - else: - f__x, f__y = self._deflection(y__, r, tangential_stretch) - - else: - f__x, f__y = np.zeros_like(x__), np.zeros_like(y__) - _y__ = y__[y__ <= r] - _f__x, _f__y = self._deflection(_y__, r, tangential_stretch) - f__x[y__ <= r] = _f__x - f__y[y__ <= r] = _f__y - - # rotate back - f_x, f_y = util.rotate(f__x, f__y, -direction) - return f_x, f_y
- -
[docs] def hessian(self, x, y, tangential_stretch, curvature, direction, center_x, center_y): - """ - - :param x: - :param y: - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: - """ - alpha_ra, alpha_dec = self.derivatives(x, y, tangential_stretch, curvature, direction, center_x, center_y) - diff = 0.0000001 - alpha_ra_dx, alpha_dec_dx = self.derivatives(x + diff, y, tangential_stretch, curvature, direction, center_x, center_y) - alpha_ra_dy, alpha_dec_dy = self.derivatives(x, y + diff, tangential_stretch, curvature, direction, center_x, center_y) - - f_xx = (alpha_ra_dx - alpha_ra) / diff - f_xy = (alpha_ra_dy - alpha_ra) / diff - f_yx = (alpha_dec_dx - alpha_dec) / diff - f_yy = (alpha_dec_dy - alpha_dec) / diff - - """ - #TODO make rotational invariances of double derivates with curl - r = 1 / curvature - # deflection angle to allow for tangential stretch - # (ratio of source position around zero point relative to radius is tangential stretch) - alpha = r * (1 / tangential_stretch + 1) - - # shift - x_ = x - center_x - y_ = y - center_y - # rotate - x__, y__ = util.rotate(x_, y_, direction) - f__xx = 0 - f__xy = -alpha * curvature * np.sin(y__ * curvature) - f__yx = 0 - f__yy = alpha * curvature * np.cos(y__ * curvature) - # transform back - phi_G = direction - kappa = 1. / 2 * (f__xx + f__yy) - gamma1__ = 1. / 2 * (f__xx - f__yy) - gamma2__ = f__xy - gamma1 = np.cos(2 * phi_G) * gamma1__ - np.sin(2 * phi_G) * gamma2__ - gamma2 = +np.sin(2 * phi_G) * gamma1__ + np.cos(2 * phi_G) * gamma2__ - f_xx = kappa + gamma1 - f_yy = kappa - gamma1 - - #f_xx = np.cos(2*direction) * f__xx - np.sin(2*direction) * f__yy - #f_yy = -np.sin(2*direction) * f__xx + np.cos(2*direction) * f__yy - - f_xy = np.cos(2 * direction) * f__xy - np.sin(2 * direction) * f__yx - f_yx = -np.sin(2 * direction) * f__xy + np.cos(2 * direction) * f__yx - return f_xx, f_xy, f_yx, f_yy - """ - return f_xx, f_xy, f_yx, f_yy
- - @staticmethod - def _deflection(y, r, tangential_stretch): - """ - - :param y: off-axis coordinate, require all entries to be <=r ! - :param r: curvature radius - :param tangential_stretch: tangential stretch - :return: deflections f_x, f_y - """ - - x_r = np.sqrt(r ** 2 - y ** 2) - f_x = x_r - r - # move y-coordinate circle length / tangential stretch up from x-axis - phi = np.arcsin(y / r) - l = phi * r - beta_y = l / tangential_stretch - f_y = y - beta_y - return f_x, f_y
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/curved_arc_sis_mst.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/curved_arc_sis_mst.html deleted file mode 100644 index 6b169b9d1..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/curved_arc_sis_mst.html +++ /dev/null @@ -1,238 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.curved_arc_sis_mst — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.curved_arc_sis_mst

-import numpy as np
-from lenstronomy.LensModel.Profiles.sis import SIS
-from lenstronomy.LensModel.Profiles.convergence import Convergence
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['CurvedArcSISMST']
-
-
-
[docs]class CurvedArcSISMST(LensProfileBase): - """ - lens model that describes a section of a highly magnified deflector region. - The parameterization is chosen to describe local observables efficient. - - Observables are: - - curvature radius (basically bending relative to the center of the profile) - - radial stretch (plus sign) thickness of arc with parity (more generalized than the power-law slope) - - tangential stretch (plus sign). Infinity means at critical curve - - direction of curvature - - position of arc - - Requirements: - - Should work with other perturbative models without breaking its meaning (say when adding additional shear terms) - - Must best reflect the observables in lensing - - minimal covariances between the parameters, intuitive parameterization. - - """ - param_names = ['tangential_stretch', 'radial_stretch', 'curvature', 'direction', 'center_x', 'center_y'] - lower_limit_default = {'tangential_stretch': -100, 'radial_stretch': -5, 'curvature': 0.000001, 'direction': -np.pi, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'tangential_stretch': 100, 'radial_stretch': 5, 'curvature': 100, 'direction': np.pi, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self._sis = SIS() - self._mst = Convergence() - super(CurvedArcSISMST, self).__init__() - -
[docs] @staticmethod - def stretch2sis_mst(tangential_stretch, radial_stretch, curvature, direction, center_x, center_y): - """ - - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: parameters in terms of a spherical SIS + MST resulting in the same observables - """ - center_x_sis, center_y_sis = center_deflector(curvature, direction, center_x, center_y) - r_curvature = 1. / curvature - lambda_mst = 1./radial_stretch - kappa_ext = 1 - lambda_mst - theta_E = r_curvature * (1. - radial_stretch / tangential_stretch) - return theta_E, kappa_ext, center_x_sis, center_y_sis
- -
[docs] @staticmethod - def sis_mst2stretch(theta_E, kappa_ext, center_x_sis, center_y_sis, center_x, center_y): - """ - turn Singular power-law lens model into stretch parameterization at position (center_x, center_y) - This is the inverse function of stretch2spp() - - :param theta_E: Einstein radius of SIS profile - :param kappa_ext: external convergence (MST factor 1 - kappa_ext) - :param center_x_sis: center of SPP model - :param center_y_sis: center of SPP model - :param center_x: center of curved model definition - :param center_y: center of curved model definition - :return: tangential_stretch, radial_stretch, curvature, direction - :return: - """ - r_curvature = np.sqrt((center_x_sis - center_x) ** 2 + (center_y_sis - center_y) ** 2) - direction = np.arctan2(center_y - center_y_sis, center_x - center_x_sis) - radial_stretch = 1. / (1 - kappa_ext) - tangential_stretch = 1 / (1 - (theta_E/r_curvature)) * radial_stretch - curvature = 1./r_curvature - return tangential_stretch, radial_stretch, curvature, direction
- -
[docs] def function(self, x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y): - """ - ATTENTION: there may not be a global lensing potential! - - :param x: - :param y: - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: - """ - lambda_mst = 1. / radial_stretch - theta_E, kappa_ext, center_x_sis, center_y_sis = self.stretch2sis_mst(tangential_stretch, radial_stretch, curvature, direction, center_x, center_y) - f_sis = self._sis.function(x, y, theta_E, center_x_sis, center_y_sis) # - self._sis.function(center_x, center_y, theta_E, center_x_sis, center_y_sis) - alpha_x, alpha_y = self._sis.derivatives(center_x, center_y, theta_E, center_x_sis, center_y_sis) - f_sis_0 = alpha_x * (x - center_x) + alpha_y * (y - center_y) - f_mst = self._mst.function(x, y, kappa_ext, ra_0=center_x, dec_0=center_y) - return lambda_mst * (f_sis - f_sis_0) + f_mst
- -
[docs] def derivatives(self, x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y): - """ - - :param x: - :param y: - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: - """ - lambda_mst = 1. / radial_stretch - theta_E, kappa_ext, center_x_sis, center_y_sis = self.stretch2sis_mst(tangential_stretch, - radial_stretch, curvature, - direction, center_x, center_y) - f_x_sis, f_y_sis = self._sis.derivatives(x, y, theta_E, center_x_sis, center_y_sis) - f_x0, f_y0 = self._sis.derivatives(center_x, center_y, theta_E, center_x_sis, center_y_sis) - f_x_mst, f_y_mst = self._mst.derivatives(x, y, kappa_ext, ra_0=center_x, dec_0=center_y) - f_x = lambda_mst * (f_x_sis - f_x0) + f_x_mst - f_y = lambda_mst * (f_y_sis - f_y0) + f_y_mst - return f_x, f_y
- -
[docs] def hessian(self, x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y): - """ - - :param x: - :param y: - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: - """ - lambda_mst = 1. / radial_stretch - theta_E, kappa_ext, center_x_sis, center_y_sis = self.stretch2sis_mst(tangential_stretch, - radial_stretch, curvature, - direction, center_x, center_y) - f_xx_sis, f_xy_sis, f_yx_sis, f_yy_sis = self._sis.hessian(x, y, theta_E, center_x_sis, center_y_sis) - f_xx_mst, f_xy_mst, f_yx_mst, f_yy_mst = self._mst.hessian(x, y, kappa_ext, ra_0=center_x, dec_0=center_y) - return lambda_mst * f_xx_sis + f_xx_mst, lambda_mst * f_xy_sis + f_xy_mst, lambda_mst * f_yx_sis + f_yx_mst, lambda_mst * f_yy_sis + f_yy_mst
- - -def center_deflector(curvature, direction, center_x, center_y): - """ - - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: center_sis_x, center_sis_y - """ - center_x_sis = center_x - np.cos(direction) / curvature - center_y_sis = center_y - np.sin(direction) / curvature - return center_x_sis, center_y_sis -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/curved_arc_spp.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/curved_arc_spp.html deleted file mode 100644 index b9db9e109..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/curved_arc_spp.html +++ /dev/null @@ -1,225 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.curved_arc_spp — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.curved_arc_spp

-import numpy as np
-from lenstronomy.LensModel.Profiles.spp import SPP
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['CurvedArcSPP', 'center_deflector']
-
-
-
[docs]class CurvedArcSPP(LensProfileBase): - """ - lens model that describes a section of a highly magnified deflector region. - The parameterization is chosen to describe local observables efficient. - - Observables are: - - curvature radius (basically bending relative to the center of the profile) - - radial stretch (plus sign) thickness of arc with parity (more generalized than the power-law slope) - - tangential stretch (plus sign). Infinity means at critical curve - - direction of curvature - - position of arc - - Requirements: - - Should work with other perturbative models without breaking its meaning (say when adding additional shear terms) - - Must best reflect the observables in lensing - - minimal covariances between the parameters, intuitive parameterization. - - """ - param_names = ['tangential_stretch', 'radial_stretch', 'curvature', 'direction', 'center_x', 'center_y'] - lower_limit_default = {'tangential_stretch': -100, 'radial_stretch': -5, 'curvature': 0.000001, 'direction': -np.pi, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'tangential_stretch': 100, 'radial_stretch': 5, 'curvature': 100, 'direction': np.pi, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self._spp = SPP() - super(CurvedArcSPP, self).__init__() - -
[docs] @staticmethod - def stretch2spp(tangential_stretch, radial_stretch, curvature, direction, center_x, center_y): - """ - - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: parameters in terms of a spherical power-law profile resulting in the same observables - """ - center_x_spp, center_y_spp = center_deflector(curvature, direction, center_x, center_y) - r_curvature = 1. / curvature - gamma = (1./radial_stretch - 1) / (1 - 1./tangential_stretch) + 2 - theta_E = abs(1 - 1./tangential_stretch)**(1./(gamma - 1)) * r_curvature - return theta_E, gamma, center_x_spp, center_y_spp
- -
[docs] @staticmethod - def spp2stretch(theta_E, gamma, center_x_spp, center_y_spp, center_x, center_y): - """ - turn Singular power-law lens model into stretch parameterization at position (center_x, center_y) - This is the inverse function of stretch2spp() - - :param theta_E: Einstein radius of SPP model - :param gamma: power-law slope - :param center_x_spp: center of SPP model - :param center_y_spp: center of SPP model - :param center_x: center of curved model definition - :param center_y: center of curved model definition - :return: tangential_stretch, radial_stretch, curvature, direction - """ - r_curvature = np.sqrt((center_x_spp - center_x)**2 + (center_y_spp - center_y)**2) - direction = np.arctan2(center_y - center_y_spp, center_x - center_x_spp) - tangential_stretch = 1 / (1 - (theta_E/r_curvature) ** (gamma - 1)) - radial_stretch = 1 / (1 + (gamma - 2) * (theta_E/r_curvature) ** (gamma - 1)) - curvature = 1./r_curvature - return tangential_stretch, radial_stretch, curvature, direction
- -
[docs] def function(self, x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y): - """ - ATTENTION: there may not be a global lensing potential! - - :param x: - :param y: - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: - """ - theta_E, gamma, center_x_spp, center_y_spp = self.stretch2spp(tangential_stretch, radial_stretch, curvature, direction, center_x, center_y) - f_ = self._spp.function(x, y, theta_E, gamma, center_x_spp, center_y_spp) - alpha_x, alpha_y = self._spp.derivatives(center_x, center_y, theta_E, gamma, center_x_spp, center_y_spp) - f_0 = alpha_x * (x - center_x) + alpha_y * (y - center_y) - return f_ - f_0
- -
[docs] def derivatives(self, x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y): - """ - - :param x: - :param y: - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: - """ - theta_E, gamma, center_x_spp, center_y_spp = self.stretch2spp(tangential_stretch, - radial_stretch, curvature, - direction, center_x, center_y) - f_x, f_y = self._spp.derivatives(x, y, theta_E, gamma, center_x_spp, center_y_spp) - f_x0, f_y0 = self._spp.derivatives(center_x, center_y, theta_E, gamma, center_x_spp, center_y_spp) - return f_x - f_x0, f_y - f_y0
- -
[docs] def hessian(self, x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y): - """ - - :param x: - :param y: - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: - """ - theta_E, gamma, center_x_spp, center_y_spp = self.stretch2spp(tangential_stretch, - radial_stretch, curvature, - direction, center_x, center_y) - return self._spp.hessian(x, y, theta_E, gamma, center_x_spp, center_y_spp)
- - -
[docs]def center_deflector(curvature, direction, center_x, center_y): - """ - - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: center_spp_x, center_spp_y - """ - center_x_spp = center_x - np.cos(direction) / curvature - center_y_spp = center_y - np.sin(direction) / curvature - return center_x_spp, center_y_spp
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/curved_arc_spt.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/curved_arc_spt.html deleted file mode 100644 index 9a9020c75..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/curved_arc_spt.html +++ /dev/null @@ -1,186 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.curved_arc_spt — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.curved_arc_spt

-import numpy as np
-from lenstronomy.LensModel.Profiles.shear import ShearReduced
-from lenstronomy.LensModel.Profiles.curved_arc_sis_mst import CurvedArcSISMST
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['CurvedArcSPT']
-
-
-
[docs]class CurvedArcSPT(LensProfileBase): - """ - Curved arc model based on SIS+MST with an additional non-linear shear distortions applied on the source coordinates - around the center. - This profile is effectively a Source Position Transform of a curved arc and a shear distortion. - - """ - param_names = ['tangential_stretch', 'radial_stretch', 'curvature', 'direction', 'gamma1', 'gamma2', 'center_x', - 'center_y'] - lower_limit_default = {'tangential_stretch': -100, 'radial_stretch': -5, 'curvature': 0.000001, 'direction': -np.pi, - 'gamma1': -0.5, 'gamma2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'tangential_stretch': 100, 'radial_stretch': 5, 'curvature': 100, 'direction': np.pi, - 'gamma1': 0.5, 'gamma2': 0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self._curve = CurvedArcSISMST() - self._distort = ShearReduced() - super(CurvedArcSPT, self).__init__() - -
[docs] def function(self, x, y, tangential_stretch, radial_stretch, curvature, direction, gamma1, gamma2, center_x, - center_y): - """ - ATTENTION: there may not be a global lensing potential! - - :param x: - :param y: - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param gamma1: non-linear reduced shear distortion in the source plane - :param gamma2: non-linear reduced shear distortion in the source plane - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: - """ - raise NotImplemented('lensing potential for regularly curved arc is not implemented')
- -
[docs] def derivatives(self, x, y, tangential_stretch, radial_stretch, curvature, direction, gamma1, gamma2, center_x, - center_y): - """ - - :param x: - :param y: - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param gamma1: non-linear reduced shear distortion in the source plane - :param gamma2: non-linear reduced shear distortion in the source plane - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: - """ - # computed regular curved arc deflection - f_x_c, f_y_c = self._curve.derivatives(x, y, tangential_stretch, radial_stretch, curvature, direction, - center_x, center_y) - # map to source plane coordinate system - beta_x, beta_y = x - f_x_c, y - f_y_c - # distort source plane coordinate system around (center_x, center_y) - f_x_b, f_y_b = self._distort.derivatives(beta_x, beta_y, gamma1, gamma2, ra_0=center_x, dec_0=center_y) - beta_x_, beta_y_ = beta_x - f_x_b, beta_y - f_y_b - # compute total deflection between initial coordinate and final source coordinate to match lens equation - # beta = theta - alpha - f_x, f_y = x - beta_x_, y - beta_y_ - return f_x, f_y
- -
[docs] def hessian(self, x, y, tangential_stretch, radial_stretch, curvature, direction, gamma1, gamma2, center_x, - center_y): - """ - - :param x: - :param y: - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param gamma1: non-linear reduced shear distortion in the source plane - :param gamma2: non-linear reduced shear distortion in the source plane - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: - """ - alpha_ra, alpha_dec = self.derivatives(x, y, tangential_stretch, radial_stretch, curvature, direction, gamma1, - gamma2, center_x, center_y) - diff = 0.0000001 - alpha_ra_dx, alpha_dec_dx = self.derivatives(x + diff, y, tangential_stretch, radial_stretch, curvature, - direction, gamma1, gamma2, center_x, center_y) - alpha_ra_dy, alpha_dec_dy = self.derivatives(x, y + diff, tangential_stretch, radial_stretch, curvature, - direction, gamma1, gamma2, center_x, center_y) - - f_xx = (alpha_ra_dx - alpha_ra) / diff - f_xy = (alpha_ra_dy - alpha_ra) / diff - f_yx = (alpha_dec_dx - alpha_dec) / diff - f_yy = (alpha_dec_dy - alpha_dec) / diff - return f_xx, f_xy, f_yx, f_yy
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/curved_arc_tan_diff.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/curved_arc_tan_diff.html deleted file mode 100644 index 2d07e7553..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/curved_arc_tan_diff.html +++ /dev/null @@ -1,239 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.curved_arc_tan_diff — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.curved_arc_tan_diff

-import numpy as np
-from lenstronomy.LensModel.Profiles.sie import SIE
-from lenstronomy.LensModel.Profiles.convergence import Convergence
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-from lenstronomy.Util import param_util
-
-__all__ = ['CurvedArcTanDiff']
-
-
-
[docs]class CurvedArcTanDiff(LensProfileBase): - """ - Curved arc model with an additional non-zero tangential stretch differential in tangential direction component - - Observables are: - - curvature radius (basically bending relative to the center of the profile) - - radial stretch (plus sign) thickness of arc with parity (more generalized than the power-law slope) - - tangential stretch (plus sign). Infinity means at critical curve - - direction of curvature - - position of arc - - Requirements: - - Should work with other perturbative models without breaking its meaning (say when adding additional shear terms) - - Must best reflect the observables in lensing - - minimal covariances between the parameters, intuitive parameterization. - - """ - param_names = ['tangential_stretch', 'radial_stretch', 'curvature', 'dtan_dtan', 'direction', 'center_x', 'center_y'] - lower_limit_default = {'tangential_stretch': -100, 'radial_stretch': -5, 'curvature': 0.000001, 'dtan_dtan': -10, 'direction': -np.pi, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'tangential_stretch': 100, 'radial_stretch': 5, 'curvature': 100, 'dtan_dtab': 10, 'direction': np.pi, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self._sie = SIE(NIE=True) - self._mst = Convergence() - super(CurvedArcTanDiff, self).__init__() - -
[docs] @staticmethod - def stretch2sie_mst(tangential_stretch, radial_stretch, curvature, dtan_dtan, direction, center_x, center_y): - """ - - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param dtan_dtan: d(tangential_stretch) / d(tangential direction) / tangential stretch - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: parameters in terms of a spherical SIS + MST resulting in the same observables - """ - center_x_sis, center_y_sis = center_deflector(curvature, direction, center_x, center_y) - r_curvature = 1. / curvature - lambda_mst = 1./radial_stretch - kappa_ext = 1 - lambda_mst - theta_E = r_curvature * (1. - radial_stretch / tangential_stretch) - # analytic relation (see Birrer 2021) - dlambda_tan_dr = tangential_stretch / r_curvature * (1 - tangential_stretch / radial_stretch) - - # translate tangential eigenvalue gradient in lens ellipticity - dtan_dtan_ = dtan_dtan * tangential_stretch - epsilon = np.abs(dtan_dtan_ / dlambda_tan_dr) - # bound epsilon by (-1, 1) - epsilon = np.minimum(epsilon, 0.99999) - q = np.sqrt((1 - epsilon) / (1 + epsilon)) - - if dtan_dtan_ < 0: - phi = direction - np.pi / 4 - else: - phi = direction + np.pi / 4 - e1_sie, e2_sie = param_util.phi_q2_ellipticity(phi, q) - - # ellipticity adopted Einstein radius to match local tangential and radial stretch - factor = np.sqrt(1 + q ** 2) / np.sqrt(2 * q) - theta_E_sie = theta_E * factor - return theta_E_sie, e1_sie, e2_sie, kappa_ext, center_x_sis, center_y_sis
- -
[docs] def function(self, x, y, tangential_stretch, radial_stretch, curvature, dtan_dtan, direction, center_x, center_y): - """ - ATTENTION: there may not be a global lensing potential! - - :param x: - :param y: - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param dtan_dtan: d(tangential_stretch) / d(tangential direction) / tangential stretch - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: - """ - lambda_mst = 1. / radial_stretch - theta_E_sie, e1_sie, e2_sie, kappa_ext, center_x_sis, center_y_sis = self.stretch2sie_mst(tangential_stretch, radial_stretch, curvature, dtan_dtan, direction, center_x, center_y) - f_sis = self._sie.function(x, y, theta_E_sie, e1_sie, e2_sie, center_x_sis, center_y_sis) # - self._sis.function(center_x, center_y, theta_E, center_x_sis, center_y_sis) - alpha_x, alpha_y = self._sie.derivatives(center_x, center_y, theta_E_sie, e1_sie, e2_sie, center_x_sis, center_y_sis) - f_sis_0 = alpha_x * (x - center_x) + alpha_y * (y - center_y) - f_mst = self._mst.function(x, y, kappa_ext, ra_0=center_x, dec_0=center_y) - return lambda_mst * (f_sis - f_sis_0) + f_mst
- -
[docs] def derivatives(self, x, y, tangential_stretch, radial_stretch, curvature, dtan_dtan, direction, center_x, center_y): - """ - - :param x: - :param y: - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param dtan_dtan: d(tangential_stretch) / d(tangential direction) / tangential stretch - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: - """ - lambda_mst = 1. / radial_stretch - theta_E_sie, e1_sie, e2_sie, kappa_ext, center_x_sis, center_y_sis = self.stretch2sie_mst(tangential_stretch, - radial_stretch, curvature, dtan_dtan, - direction, center_x, center_y) - f_x_sis, f_y_sis = self._sie.derivatives(x, y, theta_E_sie, e1_sie, e2_sie, center_x_sis, center_y_sis) - f_x0, f_y0 = self._sie.derivatives(center_x, center_y, theta_E_sie, e1_sie, e2_sie, center_x_sis, center_y_sis) - f_x_mst, f_y_mst = self._mst.derivatives(x, y, kappa_ext, ra_0=center_x, dec_0=center_y) - f_x = lambda_mst * (f_x_sis - f_x0) + f_x_mst - f_y = lambda_mst * (f_y_sis - f_y0) + f_y_mst - return f_x, f_y
- -
[docs] def hessian(self, x, y, tangential_stretch, radial_stretch, curvature, dtan_dtan, direction, center_x, center_y): - """ - - :param x: - :param y: - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param dtan_dtan: d(tangential_stretch) / d(tangential direction) / tangential stretch - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: - """ - lambda_mst = 1. / radial_stretch - theta_E_sie, e1_sie, e2_sie, kappa_ext, center_x_sis, center_y_sis = self.stretch2sie_mst(tangential_stretch, - radial_stretch, curvature, dtan_dtan, - direction, center_x, center_y) - f_xx_sis, f_xy_sis, f_yx_sis, f_yy_sis = self._sie.hessian(x, y, theta_E_sie, e1_sie, e2_sie, center_x_sis, center_y_sis) - f_xx_mst, f_xy_mst, f_yx_mst, f_yy_mst = self._mst.hessian(x, y, kappa_ext, ra_0=center_x, dec_0=center_y) - return lambda_mst * f_xx_sis + f_xx_mst, lambda_mst * f_xy_sis + f_xy_mst, lambda_mst * f_yx_sis + f_yx_mst, lambda_mst * f_yy_sis + f_yy_mst
- - -def center_deflector(curvature, direction, center_x, center_y): - """ - - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :return: center_sis_x, center_sis_y - """ - center_x_sis = center_x - np.cos(direction) / curvature - center_y_sis = center_y - np.sin(direction) / curvature - return center_x_sis, center_y_sis -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/dipole.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/dipole.html deleted file mode 100644 index 93307d724..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/dipole.html +++ /dev/null @@ -1,197 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.dipole — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.dipole

-__author__ = 'sibirrer'
-
-
-import numpy as np
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['Dipole', 'DipoleUtil']
-
-
-
[docs]class Dipole(LensProfileBase): - """ - class for dipole response of two massive bodies (experimental) - """ - param_names = ['com_x', 'com_y', 'phi_dipole', 'coupling'] - lower_limit_default = {'com_x': -100, 'com_y': -100, 'phi_dipole': -10, 'coupling': -10} - upper_limit_default = {'com_x': 100, 'com_y': 100, 'phi_dipole': 10, 'coupling': 10} - -
[docs] def function(self, x, y, com_x, com_y, phi_dipole, coupling): - # coordinate shift - x_shift = x - com_x - y_shift = y - com_y - - # rotation angle - sin_phi = np.sin(phi_dipole) - cos_phi = np.cos(phi_dipole) - x_ = cos_phi*x_shift + sin_phi*y_shift - # y_ = -sin_phi*x_shift + cos_phi*y_shift - # r = np.sqrt(x_**2 + y_**2) - - # f_ = coupling**2 * (x_/y_)**2 # np.sqrt(np.abs(y_)/r) * np.abs(y_) - # f_ = coupling * np.abs(x_) - f_ = np.zeros_like(x_) - return f_
- -
[docs] def derivatives(self, x, y, com_x, com_y, phi_dipole, coupling): - - # coordinate shift - x_shift = x - com_x - y_shift = y - com_y - - # rotation angle - sin_phi = np.sin(phi_dipole) - cos_phi = np.cos(phi_dipole) - x_ = cos_phi*x_shift + sin_phi*y_shift - y_ = -sin_phi*x_shift + cos_phi*y_shift - - f_x_prim = coupling * x_/np.sqrt(x_**2 + y_**2) - f_y_prim = np.zeros_like(x_) - # rotate back - f_x = cos_phi*f_x_prim-sin_phi*f_y_prim - f_y = sin_phi*f_x_prim+cos_phi*f_y_prim - return f_x, f_y
- -
[docs] def hessian(self, x, y, com_x, com_y, phi_dipole, coupling): - - # coordinate shift - x_shift = x - com_x - y_shift = y - com_y - - # rotation angle - sin_phi = np.sin(phi_dipole) - cos_phi = np.cos(phi_dipole) - x_ = cos_phi*x_shift + sin_phi*y_shift - y_ = -sin_phi*x_shift + cos_phi*y_shift - - r = np.sqrt(x_**2 + y_**2) - f_xx_prim = coupling*y_**2/r**3 - f_xy_prim = -coupling * x_ * y_ / r**3 - f_yy_prim = np.zeros_like(x_) - - kappa = 1./2 * (f_xx_prim + f_yy_prim) - gamma1_value = 1./2 * (f_xx_prim - f_yy_prim) - gamma2_value = f_xy_prim - # rotate back - gamma1 = np.cos(2*phi_dipole)*gamma1_value-np.sin(2*phi_dipole)*gamma2_value - gamma2 = +np.sin(2*phi_dipole)*gamma1_value+np.cos(2*phi_dipole)*gamma2_value - - f_xx = kappa + gamma1 - f_yy = kappa - gamma1 - f_xy = gamma2 - return f_xx, f_xy, f_xy, f_yy
- - -
[docs]class DipoleUtil(object): - """ - pre-calculation of dipole properties - """ - -
[docs] @staticmethod - def com(center1_x, center1_y, center2_x, center2_y, Fm): - """ - :return: center of mass - """ - com_x = (Fm * center1_x + center2_x)/(Fm + 1.) - com_y = (Fm * center1_y + center2_y)/(Fm + 1.) - return com_x, com_y
- -
[docs] @staticmethod - def mass_ratio(theta_E, theta_E_sub): - """ - computes mass ration of the two clumps with given Einstein radius and power law slope (clump1/sub-clump) - :param theta_E: - :param theta_E_sub: - :return: - """ - return (theta_E / theta_E_sub) ** 2
- -
[docs] @staticmethod - def angle(center1_x, center1_y, center2_x, center2_y): - """ - compute the rotation angle of the dipole - :return: - """ - phi_G = np.arctan2(center2_y - center1_y, center2_x - center1_x) - return phi_G
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/elliptical_density_slice.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/elliptical_density_slice.html deleted file mode 100644 index 20eb07607..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/elliptical_density_slice.html +++ /dev/null @@ -1,364 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.elliptical_density_slice — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.elliptical_density_slice

-__author__ = "lynevdv"
-
-import numpy as np
-import cmath as c
-from lenstronomy.Util import param_util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['ElliSLICE']
-
-
-
[docs]class ElliSLICE (LensProfileBase): - """ - This class computes the lensing quantities for an elliptical slice of constant density. - Based on Schramm 1994 https://ui.adsabs.harvard.edu/abs/1994A%26A...284...44S/abstract - - Computes the lensing quantities of an elliptical slice with semi major axis 'a' and - semi minor axis 'b', centered on 'center_x' and 'center_y', oriented with an angle 'psi' - in radian, and with constant surface mass density 'sigma_0'. - In other words, this lens model is characterized by the surface mass density : - - ..math:: - \\kappa(x,y) = \\left{ - \\begin{array}{ll} - \\sigma_0 & \\mbox{if } \\frac{x_{rot}^2}{a^2} + \\frac{y_{rot}^2}{b^2} \\leq 1 \\\ - 0 & \\mbox{else} - - \\end{array} - - \\right}. - - with - - ..math:: - x_{rot} = x_c \\cos \\psi + y_c \\sin \\psi \\ - y_{rot} = - x_c \\sin \\psi + y_c \\cos \\psi \\ - x_c = x - center_x \\ - y_c = y - center_y - - """ - param_names = ['a', 'b', 'psi', 'sigma_0', 'center_x', 'center_y'] - lower_limit_default = {'a': 0., 'b': 0., 'psi': -90./180.*np.pi, 'center_x': -100., 'center_y': -100.} - upper_limit_default = {'a': 100., 'b': 100., 'psi': 90. / 180. * np.pi, 'center_x': 100., 'center_y': 100.} - -
[docs] def function(self, x, y, a, b, psi, sigma_0, center_x=0., center_y=0.): - """ - lensing potential - - :param a: float, semi-major axis, must be positive - :param b: float, semi-minor axis, must be positive - :param psi: float, orientation in radian - :param sigma_0: float, surface mass density, must be positive - :param center_x: float, center on the x axis - :param center_y: float, center on the y axis - - """ - kwargs_slice = {'center_x': center_x, 'center_y': center_y, 'a': a, 'b': b, 'psi': psi, 'sigma_0': sigma_0} - x_ = x - center_x - y_ = y - center_y - x_rot = x_*np.cos(psi) + y_*np.sin(psi) - y_rot = -x_*np.sin(psi) + y_*np.cos(psi) - try: - len(x_) - except: - if (x_rot ** 2 / a ** 2) + (y_rot ** 2 / b ** 2) <= 1: - return self.pot_in(x_, y_, kwargs_slice) - else: - return self.pot_ext(x_, y_, kwargs_slice) - else: - f = np.array([self.pot_in(x_[i], y_[i], kwargs_slice) if (x_rot[i] ** 2 / a ** 2) + (y_rot[i] ** 2 / b ** 2) <= 1 - else self.pot_ext(x_[i], y_[i], kwargs_slice) for i in range(len(x_))]) - return f
- -
[docs] def derivatives(self, x, y, a, b, psi, sigma_0, center_x=0., center_y=0.): - """ - lensing deflection angle - - :param a: float, semi-major axis, must be positive - :param b: float, semi-minor axis, must be positive - :param psi: float, orientation in radian - :param sigma_0: float, surface mass density, must be positive - :param center_x: float, center on the x axis - :param center_y: float, center on the y axis - - """ - kwargs_slice = {'center_x': center_x, 'center_y': center_y, 'a': a, 'b': b, 'psi': psi, 'sigma_0': sigma_0} - x_ = x - center_x - y_ = y - center_y - x_rot = x_ * np.cos(psi) + y_ * np.sin(psi) - y_rot = -x_ * np.sin(psi) + y_ * np.cos(psi) - try: - len(x_) - except: - if (x_rot ** 2 / a ** 2) + (y_rot ** 2 / b ** 2) <= 1: - return self.alpha_in(x_, y_, kwargs_slice) - else: - return self.alpha_ext(x_, y_, kwargs_slice) - else: - defl = np.array([self.alpha_in(x_[i], y_[i], kwargs_slice) if (x_rot[i] ** 2 / a ** 2) + (y_rot[i] ** 2 / b ** 2) <= 1 - else self.alpha_ext(x_[i], y_[i], kwargs_slice) for i in range(len(x_))]) - return defl[:, 0], defl[:, 1]
- -
[docs] def hessian(self, x, y, a, b, psi, sigma_0, center_x=0., center_y=0.): - """ - lensing second derivatives - - :param a: float, semi-major axis, must be positive - :param b: float, semi-minor axis, must be positive - :param psi: float, orientation in radian - :param sigma_0: float, surface mass density, must be positive - :param center_x: float, center on the x axis - :param center_y: float, center on the y axis - - """ - - diff = 0.000000001 - alpha_ra, alpha_dec = self.derivatives(x, y, a, b, psi, sigma_0, center_x, center_y) - alpha_ra_dx, alpha_dec_dx = self.derivatives(x + diff, y, a, b, psi, sigma_0, center_x, center_y) - alpha_ra_dy, alpha_dec_dy = self.derivatives(x, y + diff, a, b, psi, sigma_0, center_x, center_y) - - f_xx = (alpha_ra_dx - alpha_ra) / diff - f_xy = (alpha_ra_dy - alpha_ra) / diff - f_yx = (alpha_dec_dx - alpha_dec) / diff - f_yy = (alpha_dec_dy - alpha_dec) / diff - return f_xx, f_xy, f_yx, f_yy
- -
[docs] @staticmethod - def sign(z): - """ - sign function - - :param z: complex - - """ - x = z.real - y = z.imag - if x > 0 or (x == 0 and y >= 0): - return 1 - else: - return -1
- -
[docs] def alpha_in(self, x, y, kwargs_slice): - """ - deflection angle for (x,y) inside the elliptical slice - - :param kwargs_slice: dict, dictionary with the slice definition (a,b,psi,sigma_0) - - """ - z = complex(x, y) - zb = z.conjugate() - psi = kwargs_slice['psi'] - e = (kwargs_slice['a'] - kwargs_slice['b']) / (kwargs_slice['a'] + kwargs_slice['b']) - sig_0 = kwargs_slice['sigma_0'] - e2ipsi = c.exp(2j * psi) - I_in = (z - e * zb * e2ipsi) * sig_0 - return I_in.real, I_in.imag
- -
[docs] def alpha_ext(self, x, y, kwargs_slice): - """ - deflection angle for (x,y) outside the elliptical slice - - :param kwargs_slice: dict, dictionary with the slice definition (a,b,psi,sigma_0) - - """ - z = complex(x, y) - r, phi = param_util.cart2polar(x, y) - zb = z.conjugate() - psi = kwargs_slice['psi'] - a = kwargs_slice['a'] - b = kwargs_slice['b'] - f2 = a ** 2 - b ** 2 - sig_0 = kwargs_slice['sigma_0'] - median_op = False - # when (x,y) is on one of the ellipse axis, there might be an issue when calculating the square root of - # zb ** 2 * e2ipsi - f2. When the argument has an imaginary part ==0, having 0. or -0. may return different - # answers. Therefore, for points (x,y) close to one axis, we take 3 points (one is x,y ; another one is a delta - # away from this position, perpendicularly to the axis ; another one is at -delta perpendicularly away from - # x,y). We calculate the function for each point and take the median. This avoids any singularity for points - # along the axis but it slows down the function. - if np.abs(np.sin(phi - psi)) <= 10 ** -10 \ - or np.abs(np.sin(phi - psi - np.pi / 2.)) <= 10 ** -10: # very close to one of the ellipse axis - median_op = True - e2ipsi = c.exp(2j * psi) - eipsi = c.exp(1j * psi) - if median_op is True: - eps = 10 ** -10 - z_minus_eps = complex(r * np.cos(phi - eps), r * np.sin(phi - eps)) - zb_minus_eps = z_minus_eps.conjugate() - z_plus_eps = complex(r * np.cos(phi + eps), r * np.sin(phi + eps)) - zb_plus_eps = z_plus_eps.conjugate() - I_out_minus = 2 * a * b / f2 * (zb_minus_eps * e2ipsi - eipsi * self.sign(zb_minus_eps * eipsi) - * c.sqrt(zb_minus_eps ** 2 * e2ipsi - f2)) * sig_0 - I_out_plus = 2 * a * b / f2 * (zb_plus_eps * e2ipsi - eipsi * self.sign(zb_plus_eps * eipsi) - * c.sqrt(zb_plus_eps ** 2 * e2ipsi - f2)) * sig_0 - I_out_mid = 2 * a * b / f2 * (zb * e2ipsi - eipsi * self.sign(zb * eipsi) - * c.sqrt(zb ** 2 * e2ipsi - f2)) * sig_0 - I_out_real = np.median([I_out_minus.real, I_out_plus.real, I_out_mid.real]) - I_out_imag = np.median([I_out_minus.imag, I_out_plus.imag, I_out_mid.imag]) - else: - I_out = 2 * a * b / f2 * ( - zb * e2ipsi - eipsi * self.sign(zb * eipsi) * c.sqrt(zb ** 2 * e2ipsi - f2)) * sig_0 - I_out_real = I_out.real - I_out_imag = I_out.imag - - # buf = zb ** 2 * e2ipsi - f2 ##problem with 0. and -0. giving different answers - # if buf.real == 0: - # buf = complex(0, buf.imag) - # if buf.imag == 0: - # buf = complex(buf.real, 0) - - return I_out_real, I_out_imag
- -
[docs] @staticmethod - def pot_in(x, y, kwargs_slice): - """ - lensing potential for (x,y) inside the elliptical slice - - :param kwargs_slice: dict, dictionary with the slice definition (a,b,psi,sigma_0) - - """ - psi = kwargs_slice['psi'] - a = kwargs_slice['a'] - b = kwargs_slice['b'] - sig_0 = kwargs_slice['sigma_0'] - e = (a - b) / (a + b) - rE = (a + b) / 2. - pot_in = 0.5 * ((1 - e) * (x * np.cos(psi) + y * np.sin(psi)) ** 2 + (1 + e) * ( - y * np.cos(psi) - x * np.sin(psi)) ** 2) * sig_0 - cst = sig_0 * rE ** 2 * (1 - e ** 2) * np.log(rE) - return pot_in + cst
- -
[docs] def pot_ext(self, x, y, kwargs_slice): - """ - lensing potential for (x,y) outside the elliptical slice - - :param kwargs_slice: dict, dictionary with the slice definition (a,b,psi,sigma_0) - - """ - z = complex(x, y) - # zb = z.conjugate() - psi = kwargs_slice['psi'] - a = kwargs_slice['a'] - b = kwargs_slice['b'] - sig_0 = kwargs_slice['sigma_0'] - r, phi = param_util.cart2polar(x, y) - median_op = False - # when (x,y) is on one of the ellipse axis, there might be an issue when calculating the square root of - # z ** 2 * em2ipsi - f2. When the argument has an imaginary part ==0, having 0. or -0. may return different - # answers. Therefore, for points (x,y) close to one axis, we take 3 points (one is x,y ; another one is a delta - # away from this position, perpendicularly to the axis ; another one is at -delta perpendicularly away from - # x,y). We calculate the function for each point and take the median. This avoids any singularity for points - # along the axis but it slows down the function. - if np.abs(np.sin(phi - psi)) <= 10 ** -10 \ - or np.abs(np.sin(phi - psi - np.pi / 2.)) <= 10 ** -10: # very close to one of the ellipse axis - median_op = True - e = (a - b) / (a + b) - f2 = a ** 2 - b ** 2 - emipsi = c.exp(-1j * psi) - em2ipsi = c.exp(-2j * psi) - if median_op is True: - eps = 10 ** -10 - z_minus_eps = complex(r * np.cos(phi - eps), r * np.sin(phi - eps)) - z_plus_eps = complex(r * np.cos(phi + eps), r * np.sin(phi + eps)) - - pot_ext_minus = (1 - e ** 2) / (4 * e) * (f2 * c.log( - (self.sign(z_minus_eps * emipsi) * z_minus_eps * emipsi + c.sqrt(z_minus_eps ** 2 * em2ipsi - f2)) / 2.) - - self.sign(z_minus_eps * emipsi) * z_minus_eps * emipsi * c.sqrt( - z_minus_eps ** 2 * em2ipsi - f2) + z_minus_eps ** 2 * em2ipsi) * sig_0 - pot_ext_plus = (1 - e ** 2) / (4 * e) * (f2 * c.log( - (self.sign(z_plus_eps * emipsi) * z_plus_eps * emipsi + c.sqrt(z_plus_eps ** 2 * em2ipsi - f2)) / 2.) - - self.sign(z_plus_eps * emipsi) * z_plus_eps * emipsi * c.sqrt( - z_plus_eps ** 2 * em2ipsi - f2) + z_plus_eps ** 2 * em2ipsi) * sig_0 - pot_ext_mid = (1 - e ** 2) / (4 * e) * ( - f2 * c.log((self.sign(z * emipsi) * z * emipsi + c.sqrt(z ** 2 * em2ipsi - f2)) / 2.) - - self.sign(z * emipsi) * z * emipsi * c.sqrt(z ** 2 * em2ipsi - f2) + z ** 2 * em2ipsi) * sig_0 - pot_ext = np.median([pot_ext_minus.real, pot_ext_plus.real, pot_ext_mid.real]) - else: - pot_ext = ((1 - e ** 2) / (4 * e) * ( - f2 * c.log((self.sign(z * emipsi) * z * emipsi + c.sqrt(z ** 2 * em2ipsi - f2)) / 2.) - - self.sign(z * emipsi) * z * emipsi * - c.sqrt(z ** 2 * em2ipsi - f2) + z ** 2 * em2ipsi) * sig_0).real - return pot_ext
- -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/epl.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/epl.html deleted file mode 100644 index db4288f1f..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/epl.html +++ /dev/null @@ -1,413 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.epl — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.epl

-__author__ = 'ntessore'
-
-import numpy as np
-import lenstronomy.Util.util as util
-import lenstronomy.Util.param_util as param_util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-from lenstronomy.LensModel.Profiles.spp import SPP
-from scipy.special import hyp2f1
-
-
-__all__ = ['EPL', 'EPLMajorAxis']
-
-
-
[docs]class EPL(LensProfileBase): - """" - Elliptical Power Law mass profile - - .. math:: - \\kappa(x, y) = \\frac{3-\\gamma}{2} \\left(\\frac{\\theta_{E}}{\\sqrt{q x^2 + y^2/q}} \\right)^{\\gamma-1} - - with :math:`\\theta_{E}` is the (circularized) Einstein radius, - :math:`\\gamma` is the negative power-law slope of the 3D mass distributions, - :math:`q` is the minor/major axis ratio, - and :math:`x` and :math:`y` are defined in a coordinate sys- tem aligned with the major and minor axis of the lens. - - In terms of eccentricities, this profile is defined as - - .. math:: - \\kappa(r) = \\frac{3-\\gamma}{2} \\left(\\frac{\\theta'_{E}}{r \\sqrt{1 − e*\\cos(2*\\phi)}} \\right)^{\\gamma-1} - - with :math:`\\epsilon` is the ellipticity defined as - - .. math:: - \\epsilon = \\frac{1-q^2}{1+q^2} - - And an Einstein radius :math:`\\theta'_{\\rm E}` related to the definition used is - - .. math:: - \\left(\\frac{\\theta'_{\\rm E}}{\\theta_{\\rm E}}\\right)^{2} = \\frac{2q}{1+q^2}. - - The mathematical form of the calculation is presented by Tessore & Metcalf (2015), https://arxiv.org/abs/1507.01819. - The current implementation is using hyperbolic functions. The paper presents an iterative calculation scheme, - converging in few iterations to high precision and accuracy. - - A (faster) implementation of the same model using numba is accessible as 'EPL_NUMBA' with the iterative calculation - scheme. - """ - param_names = ['theta_E', 'gamma', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'theta_E': 0, 'gamma': 1.5, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'theta_E': 100, 'gamma': 2.5, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.epl_major_axis = EPLMajorAxis() - self.spp = SPP() - super(EPL, self).__init__() - -
[docs] def param_conv(self, theta_E, gamma, e1, e2): - """ - converts parameters as defined in this class to the parameters used in the EPLMajorAxis() class - - :param theta_E: Einstein radius as defined in the profile class - :param gamma: negative power-law slope - :param e1: eccentricity modulus - :param e2: eccentricity modulus - - :return: b, t, q, phi_G - """ - if self._static is True: - return self._b_static, self._t_static, self._q_static, self._phi_G_static - return self._param_conv(theta_E, gamma, e1, e2)
- - @staticmethod - def _param_conv(theta_E, gamma, e1, e2): - """ - convert parameters from :math:`R = \\sqrt{q x^2 + y^2/q}` to - :math:`R = \\sqrt{q^2 x^2 + y^2}` - - :param gamma: power law slope - :param theta_E: Einstein radius - :param e1: eccentricity component - :param e2: eccentricity component - :return: critical radius b, slope t, axis ratio q, orientation angle phi_G - """ - t = gamma - 1 - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - b = theta_E * np.sqrt(q) - return b, t, q, phi_G - -
[docs] def set_static(self, theta_E, gamma, e1, e2, center_x=0, center_y=0): - """ - - :param theta_E: Einstein radius - :param gamma: power law slope - :param e1: eccentricity component - :param e2: eccentricity component - :param center_x: profile center - :param center_y: profile center - :return: self variables set - """ - self._static = True - self._b_static, self._t_static, self._q_static, self._phi_G_static = self._param_conv(theta_E, gamma, e1, e2)
- -
[docs] def set_dynamic(self): - """ - - :return: - """ - self._static = False - if hasattr(self, '_b_static'): - del self._b_static - if hasattr(self, '_t_static'): - del self._t_static - if hasattr(self, '_phi_G_static'): - del self._phi_G_static - if hasattr(self, '_q_static'): - del self._q_static
- -
[docs] def function(self, x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0): - """ - - :param x: x-coordinate in image plane - :param y: y-coordinate in image plane - :param theta_E: Einstein radius - :param gamma: power law slope - :param e1: eccentricity component - :param e2: eccentricity component - :param center_x: profile center - :param center_y: profile center - :return: lensing potential - """ - b, t, q, phi_G = self.param_conv(theta_E, gamma, e1, e2) - # shift - x_ = x - center_x - y_ = y - center_y - # rotate - x__, y__ = util.rotate(x_, y_, phi_G) - # evaluate - f_ = self.epl_major_axis.function(x__, y__, b, t, q) - # rotate back - return f_
- -
[docs] def derivatives(self, x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0): - """ - - :param x: x-coordinate in image plane - :param y: y-coordinate in image plane - :param theta_E: Einstein radius - :param gamma: power law slope - :param e1: eccentricity component - :param e2: eccentricity component - :param center_x: profile center - :param center_y: profile center - :return: alpha_x, alpha_y - """ - b, t, q, phi_G = self.param_conv(theta_E, gamma, e1, e2) - # shift - x_ = x - center_x - y_ = y - center_y - # rotate - x__, y__ = util.rotate(x_, y_, phi_G) - # evaluate - f__x, f__y = self.epl_major_axis.derivatives(x__, y__, b, t, q) - # rotate back - f_x, f_y = util.rotate(f__x, f__y, -phi_G) - return f_x, f_y
- -
[docs] def hessian(self, x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0): - """ - - :param x: x-coordinate in image plane - :param y: y-coordinate in image plane - :param theta_E: Einstein radius - :param gamma: power law slope - :param e1: eccentricity component - :param e2: eccentricity component - :param center_x: profile center - :param center_y: profile center - :return: f_xx, f_xy, f_yx, f_yy - """ - - b, t, q, phi_G = self.param_conv(theta_E, gamma, e1, e2) - # shift - x_ = x - center_x - y_ = y - center_y - # rotate - x__, y__ = util.rotate(x_, y_, phi_G) - # evaluate - f__xx, f__xy, f__yx, f__yy = self.epl_major_axis.hessian(x__, y__, b, t, q) - # rotate back - kappa = 1./2 * (f__xx + f__yy) - gamma1__ = 1./2 * (f__xx - f__yy) - gamma2__ = f__xy - gamma1 = np.cos(2 * phi_G) * gamma1__ - np.sin(2 * phi_G) * gamma2__ - gamma2 = +np.sin(2 * phi_G) * gamma1__ + np.cos(2 * phi_G) * gamma2__ - f_xx = kappa + gamma1 - f_yy = kappa - gamma1 - f_xy = gamma2 - return f_xx, f_xy, f_xy, f_yy
- -
[docs] def mass_3d_lens(self, r, theta_E, gamma, e1=None, e2=None): - """ - computes the spherical power-law mass enclosed (with SPP routine) - :param r: radius within the mass is computed - :param theta_E: Einstein radius - :param gamma: power-law slope - :param e1: eccentricity component (not used) - :param e2: eccentricity component (not used) - :return: mass enclosed a 3D radius r - """ - return self.spp.mass_3d_lens(r, theta_E, gamma)
- -
[docs] def density_lens(self, r, theta_E, gamma, e1=None, e2=None): - """ - computes the density at 3d radius r given lens model parameterization. - The integral in the LOS projection of this quantity results in the convergence quantity. - - :param r: radius within the mass is computed - :param theta_E: Einstein radius - :param gamma: power-law slope - :param e1: eccentricity component (not used) - :param e2: eccentricity component (not used) - :return: mass enclosed a 3D radius r - """ - return self.spp.density_lens(r, theta_E, gamma)
- - -
[docs]class EPLMajorAxis(LensProfileBase): - """ - This class contains the function and the derivatives of the - elliptical power law. - - .. math:: - \\kappa = (2-t)/2 * \\left[\\frac{b}{\\sqrt{q^2 x^2 + y^2}}\\right]^t - - where with :math:`t = \\gamma - 1` (from EPL class) being the projected power-law slope of the convergence profile, - critical radius b, axis ratio q. - - Tessore & Metcalf (2015), https://arxiv.org/abs/1507.01819 - """ - param_names = ['b', 't', 'q', 'center_x', 'center_y'] - - def __init__(self): - - super(EPLMajorAxis, self).__init__() - -
[docs] def function(self, x, y, b, t, q): - """ - returns the lensing potential - - :param x: x-coordinate in image plane relative to center (major axis) - :param y: y-coordinate in image plane relative to center (minor axis) - :param b: critical radius - :param t: projected power-law slope - :param q: axis ratio - :return: lensing potential - """ - # deflection from method - alpha_x, alpha_y = self.derivatives(x, y, b, t, q) - - # deflection potential, eq. (15) - psi = (x*alpha_x + y*alpha_y)/(2 - t) - - return psi
- -
[docs] def derivatives(self, x, y, b, t, q): - """ - returns the deflection angles - - :param x: x-coordinate in image plane relative to center (major axis) - :param y: y-coordinate in image plane relative to center (minor axis) - :param b: critical radius - :param t: projected power-law slope - :param q: axis ratio - :return: f_x, f_y - """ - # elliptical radius, eq. (5) - Z = np.empty(np.shape(x), dtype=complex) - Z.real = q*x - Z.imag = y - R = np.abs(Z) - R = np.maximum(R, 0.000000001) - - # angular dependency with extra factor of R, eq. (23) - R_omega = Z*hyp2f1(1, t/2, 2-t/2, -(1-q)/(1+q)*(Z/Z.conj())) - - # deflection, eq. (22) - alpha = 2/(1+q)*(b/R)**t*R_omega - - # return real and imaginary part - alpha_real = np.nan_to_num(alpha.real, posinf=10**10, neginf=-10**10) - alpha_imag = np.nan_to_num(alpha.imag, posinf=10**10, neginf=-10**10) - - return alpha_real, alpha_imag
- -
[docs] def hessian(self, x, y, b, t, q): - """ - Hessian matrix of the lensing potential - - :param x: x-coordinate in image plane relative to center (major axis) - :param y: y-coordinate in image plane relative to center (minor axis) - :param b: critical radius - :param t: projected power-law slope - :param q: axis ratio - :return: f_xx, f_yy, f_xy - """ - R = np.hypot(q*x, y) - R = np.maximum(R, 0.00000001) - r = np.hypot(x, y) - - cos, sin = x/r, y/r - cos2, sin2 = cos*cos*2 - 1, sin*cos*2 - - # convergence, eq. (2) - kappa = (2 - t)/2*(b/R)**t - kappa = np.nan_to_num(kappa, posinf=10**10, neginf=-10**10) - - # deflection via method - alpha_x, alpha_y = self.derivatives(x, y, b, t, q) - - # shear, eq. (17), corrected version from arXiv/corrigendum - gamma_1 = (1-t)*(alpha_x*cos - alpha_y*sin)/r - kappa*cos2 - gamma_2 = (1-t)*(alpha_y*cos + alpha_x*sin)/r - kappa*sin2 - gamma_1 = np.nan_to_num(gamma_1, posinf=10**10, neginf=-10**10) - gamma_2 = np.nan_to_num(gamma_2, posinf=10**10, neginf=-10**10) - - # second derivatives from convergence and shear - f_xx = kappa + gamma_1 - f_yy = kappa - gamma_1 - f_xy = gamma_2 - - return f_xx, f_xy, f_xy, f_yy
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/epl_numba.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/epl_numba.html deleted file mode 100644 index 3aaf3c388..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/epl_numba.html +++ /dev/null @@ -1,260 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.epl_numba — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.epl_numba

-__author__ = 'ewoudwempe'
-
-import numpy as np
-import lenstronomy.Util.param_util as param_util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-from lenstronomy.Util.numba_util import jit, nan_to_num
-
-__all__ = ['EPL_numba']
-
-
-
[docs]class EPL_numba(LensProfileBase): - """" - Elliptical Power Law mass profile - computation accelerated with numba - - .. math:: - \\kappa(x, y) = \\frac{3-\\gamma}{2} \\left(\\frac{\\theta_{E}}{\\sqrt{q x^2 + y^2/q}} \\right)^{\\gamma-1} - - with :math:`\\theta_{E}` is the (circularized) Einstein radius, - :math:`\\gamma` is the negative power-law slope of the 3D mass distributions, - :math:`q` is the minor/major axis ratio, - and :math:`x` and :math:`y` are defined in a coordinate system aligned with the major and minor axis of the lens. - - In terms of eccentricities, this profile is defined as - - .. math:: - \\kappa(r) = \\frac{3-\\gamma}{2} \\left(\\frac{\\theta'_{E}}{r \\sqrt{1 − e*\\cos(2*\\phi)}} \\right)^{\\gamma-1} - - with :math:`\\epsilon` is the ellipticity defined as - - .. math:: - \\epsilon = \\frac{1-q^2}{1+q^2} - - And an Einstein radius :math:`\\theta'_{\\rm E}` related to the definition used is - - .. math:: - \\left(\\frac{\\theta'_{\\rm E}}{\\theta_{\\rm E}}\\right)^{2} = \\frac{2q}{1+q^2}. - - - The mathematical form of the calculation is presented by Tessore & Metcalf (2015), https://arxiv.org/abs/1507.01819. - The current implementation is using hyperbolic functions. The paper presents an iterative calculation scheme, - converging in few iterations to high precision and accuracy. - - A (slower) implementation of the same model using hyperbolic functions without the iterative calculation - is accessible as 'EPL' not requiring numba. - """ - param_names = ['theta_E', 'gamma', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'theta_E': 0, 'gamma': 1.5, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'theta_E': 100, 'gamma': 2.5, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self): - super(EPL_numba).__init__() - -
[docs] @staticmethod - @jit() - def function(x, y, theta_E, gamma, e1, e2, center_x=0., center_y=0.): - """ - - :param x: x-coordinate (angle) - :param y: y-coordinate (angle) - :param theta_E: Einstein radius (angle), pay attention to specific definition! - :param gamma: logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal - :param e1: eccentricity component - :param e2: eccentricity component - :param center_x: x-position of lens center - :param center_y: y-position of lens center - :return: lensing potential - """ - z, b, t, q, ang = param_transform(x, y, theta_E, gamma, e1, e2, center_x, center_y) - alph = alpha(z.real, z.imag, b, q, t) - return 1/(2-t)*(z.real*alph.real+z.imag*alph.imag)
- -
[docs] @staticmethod - @jit() - def derivatives(x, y, theta_E, gamma, e1, e2, center_x=0., center_y=0.): - """ - - :param x: x-coordinate (angle) - :param y: y-coordinate (angle) - :param theta_E: Einstein radius (angle), pay attention to specific definition! - :param gamma: logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal - :param e1: eccentricity component - :param e2: eccentricity component - :param center_x: x-position of lens center - :param center_y: y-position of lens center - :return: deflection angles alpha_x, alpha_y - """ - z, b, t, q, ang = param_transform(x, y, theta_E, gamma, e1, e2, center_x, center_y) - alph = alpha(z.real, z.imag, b, q, t) * np.exp(1j*ang) - return alph.real, alph.imag
- -
[docs] @staticmethod - @jit() - def hessian(x, y, theta_E, gamma, e1, e2, center_x=0., center_y=0.): - """ - - :param x: x-coordinate (angle) - :param y: y-coordinate (angle) - :param theta_E: Einstein radius (angle), pay attention to specific definition! - :param gamma: logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal - :param e1: eccentricity component - :param e2: eccentricity component - :param center_x: x-position of lens center - :param center_y: y-position of lens center - :return: Hessian components f_xx, f_yy, f_xy - """ - z, b, t, q, ang_ell = param_transform(x, y, theta_E, gamma, e1, e2, center_x, center_y) - ang = np.angle(z) - # r = np.abs(z) - zz_ell = z.real*q+1j*z.imag - R = np.abs(zz_ell) - phi = np.angle(zz_ell) - - # u = np.minimum(nan_to_num((b/R)**t),1e100) - u = np.fmin((b/R)**t, 1e10) # I remove all factors of (b/R)**t to only have to remove nans once. - # The np.fmin is a regularisation near R=0, to avoid overflows - # in the magnification calculations - kappa = (2-t)/2 - Roverr = np.sqrt(np.cos(ang)**2*q**2+np.sin(ang)**2) - - Omega = omega(phi, t, q) - alph = (2*b)/(1+q)/b*Omega - gamma_shear = -np.exp(2j*(ang+ang_ell))*kappa + (1-t)*np.exp(1j*(ang+2*ang_ell)) * alph*Roverr - - f_xx = (kappa + gamma_shear.real)*u - f_yy = (kappa - gamma_shear.real)*u - f_xy = gamma_shear.imag*u - # Fix the nans if x=y=0 is filled in - - return f_xx, f_xy, f_xy, f_yy
- - -@jit() -def param_transform(x, y, theta_E, gamma, e1, e2, center_x=0., center_y=0.): - """Converts the parameters from lenstronomy definitions (as defined in PEMD) to the definitions of Tessore+ (2015)""" - t = gamma-1 - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - x_shift = x - center_x - y_shift = y - center_y - ang = phi_G - z = np.exp(-1j*phi_G) * (x_shift + y_shift*1j) - return z, theta_E*np.sqrt(q), t, q, ang - - -@jit() -def alpha(x, y, b, q, t, Omega=None): - """ - Calculates the complex deflection - - :param x: x-coordinate (angle) - :param y: y-coordinate (angle) - :param b: Einstein radius (angle), pay attention to specific definition! - :param q: axis ratio - :param t: logarithmic power-law slope. Is t=gamma-1 - :param Omega: If given, use this Omega (to avoid recalculations) - :return: complex deflection angle - """ - zz = x*q + 1j*y - R = np.abs(zz) - phi = np.angle(zz) - if Omega is None: - Omega = omega(phi, t, q) - # Omega = omega(phi, t, q) - alph = (2*b)/(1+q)*nan_to_num((b/R)**t*R/b)*Omega - return alph - - -@jit(fastmath=True) # Because of the reduction nature of this, relaxing commutativity actually matters a lot (4x speedup). -def omega(phi, t, q, niter_max=200, tol=1e-16): - f = (1-q)/(1+q) - omegas = np.zeros_like(phi, dtype=np.complex128) - niter = min(niter_max, int(np.log(tol)/np.log(f))+2) # The absolute value of each summand is always less than f, hence this limit for the number of iterations. - Omega = 1*np.exp(1j*phi) - fact = -f*np.exp(2j*phi) - for n in range(1, niter): - omegas += Omega - Omega *= (2*n-(2-t))/(2*n+(2-t)) * fact - omegas += Omega - return omegas -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/flexion.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/flexion.html deleted file mode 100644 index 864b4f02a..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/flexion.html +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.flexion — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.flexion

-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['Flexion']
-
-
-
[docs]class Flexion(LensProfileBase): - """ - class for flexion - """ - param_names = ['g1', 'g2', 'g3', 'g4', 'ra_0', 'dec_0'] - lower_limit_default = {'g1': -0.1, 'g2': -0.1, 'g3': -0.1, 'g4': -0.1, 'ra_0': -100, 'dec_0': -100} - upper_limit_default = {'g1': 0.1, 'g2': 0.1, 'g3': 0.1, 'g4': 0.1, 'ra_0': 100, 'dec_0': 100} - -
[docs] def function(self, x, y, g1, g2, g3, g4, ra_0=0, dec_0=0): - x_ = x - ra_0 - y_ = y - dec_0 - f_ = 1./6 * (g1 * x_**3 + 3*g2 * x_**2 * y_ + 3*g3 * x_ * y_**2 + g4 * y_**3) - return f_
- -
[docs] def derivatives(self, x, y, g1, g2, g3, g4, ra_0=0, dec_0=0): - x_ = x - ra_0 - y_ = y - dec_0 - f_x = 1./2.*g1*x_**2 + g2*x_*y_ + 1./2.*g3*y_**2 - f_y = 1./2.*g2*x_**2 + g3*x_*y_ + 1./2.*g4*y_**2 - return f_x, f_y
- -
[docs] def hessian(self, x, y, g1, g2, g3, g4, ra_0=0, dec_0=0): - x_ = x - ra_0 - y_ = y - dec_0 - f_xx = g1*x_ + g2*y_ - f_yy = g3*x_ + g4*y_ - f_xy = g2*x_ + g3*y_ - return f_xx, f_xy, f_xy, f_yy
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/flexionfg.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/flexionfg.html deleted file mode 100644 index 71334ff18..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/flexionfg.html +++ /dev/null @@ -1,165 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.flexionfg — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.flexionfg

-from lenstronomy.LensModel.Profiles.flexion import Flexion
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['Flexionfg']
-
-
-
[docs]class Flexionfg(LensProfileBase): - """ - Flexion consist of basis F flexion and G flexion (F1,F2,G1,G2), - see formulas 2.54, 2.55 in Massimo Meneghetti 2017 - "Introduction to Gravitational Lensing". - """ - param_names = ['F1', 'F2', 'G1', 'G2', 'ra_0', 'dec_0'] - lower_limit_default = {'F1': -0.1, 'F2': -0.1, 'G1': -0.1, 'G2': -0.1, 'ra_0': -100, 'dec_0': -100} - upper_limit_default = {'F1': 0.1, 'F2': 0.1, 'G1': 0.1, 'G2': 0.1, 'ra_0': 100, 'dec_0': 100} - - def __init__(self): - self.flexion_cart = Flexion() - super(Flexionfg, self).__init__() - -
[docs] def function(self, x, y, F1, F2, G1, G2, ra_0=0, dec_0=0): - """ - lensing potential - - :param x: x-coordinate - :param y: y-coordinate - :param F1: F1 flexion, derivative of kappa in x direction - :param F2: F2 flexion, derivative of kappa in y direction - :param G1: G1 flexion - :param G2: G2 flexion - :param ra_0: center x-coordinate - :param dec_0: center y-coordinate - :return: lensing potential - """ - _g1, _g2, _g3, _g4 = self.transform_fg(F1, F2, G1, G2) - return self.flexion_cart.function(x, y, _g1, _g2, _g3, _g4, ra_0, dec_0)
- -
[docs] def derivatives(self, x, y, F1, F2, G1, G2, ra_0=0, dec_0=0): - """ - deflection angle - :param x: x-coordinate - :param y: y-coordinate - :param F1: F1 flexion, derivative of kappa in x direction - :param F2: F2 flexion, derivative of kappa in y direction - :param G1: G1 flexion - :param G2: G2 flexion - :param ra_0: center x-coordinate - :param dec_0: center x-coordinate - :return: deflection angle - """ - _g1, _g2, _g3, _g4 = self.transform_fg(F1, F2, G1, G2) - return self.flexion_cart.derivatives(x, y, _g1, _g2, _g3, _g4, ra_0, dec_0)
- -
[docs] def hessian(self, x, y, F1, F2, G1, G2, ra_0=0, dec_0=0): - """ - Hessian matrix - :param x: x-coordinate - :param y: y-coordinate - :param F1: F1 flexion, derivative of kappa in x direction - :param F2: F2 flexion, derivative of kappa in y direction - :param G1: G1 flexion - :param G2: G2 flexion - :param ra_0: center x-coordinate - :param dec_0: center y-coordinate - :return: second order derivatives f_xx, f_yy, f_xy - """ - _g1, _g2, _g3, _g4 = self.transform_fg(F1, F2, G1, G2) - return self.flexion_cart.hessian(x, y, _g1, _g2, _g3, _g4, ra_0, dec_0)
- -
[docs] @staticmethod - def transform_fg(F1, F2, G1, G2): - """ - basis transform from (F1,F2,G1,G2) to (g1,g2,g3,g4) - :param F1: F1 flexion, derivative of kappa in x direction - :param F2: F2 flexion, derivative of kappa in y direction - :param G1: G1 flexion - :param G2: G2 flexion - :return: g1,g2,g3,g4 (phi_xxx, phi_xxy, phi_xyy, phi_yyy) - """ - g1 = (3*F1 + G1) * 0.5 - g2 = (3*F2 + G2) * 0.5 - g3 = (F1 - G1) * 0.5 - g4 = (F2 - G2) * 0.5 - return g1, g2, g3, g4
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/gauss_decomposition.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/gauss_decomposition.html deleted file mode 100644 index 25556bd39..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/gauss_decomposition.html +++ /dev/null @@ -1,776 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.gauss_decomposition — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.gauss_decomposition

-# -*- coding: utf-8 -*-
-"""
-This module contains the class to compute lensing properties of any
-elliptical profile using Shajib (2019)'s Gauss decomposition.
-"""
-
-__author__ = 'ajshajib'
-
-import numpy as np
-import abc
-from scipy.special import comb
-
-from lenstronomy.LensModel.Profiles.gaussian_ellipse_kappa import GaussianEllipseKappa
-from lenstronomy.LensModel.Profiles.sersic_utils import SersicUtil
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-_SQRT_2PI = np.sqrt(2*np.pi)
-
-
-
[docs]@export -class GaussianEllipseKappaSet(LensProfileBase): - """ - This class computes the lensing properties of a set of concentric - elliptical Gaussian convergences. - """ - param_names = ['amp', 'sigma', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'sigma': 0, 'e1': -0.5, 'e2': -0.5, - 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'sigma': 100, 'e1': 0.5, 'e2': 0.5, - 'center_x': 100, 'center_y': 100} - - def __init__(self, use_scipy_wofz=True, min_ellipticity=1e-5): - """ - - :param use_scipy_wofz: To initiate ``class GaussianEllipseKappa``. If ``True``, Gaussian lensing will use ``scipy.special.wofz`` function. Set ``False`` for lower precision, but faster speed. - :type use_scipy_wofz: ``bool`` - :param min_ellipticity: To be passed to ``class GaussianEllipseKappa``. Minimum ellipticity for Gaussian elliptical lensing calculation. For lower ellipticity than min_ellipticity the equations for the spherical case will be used. - :type min_ellipticity: ``float`` - """ - self.gaussian_ellipse_kappa = GaussianEllipseKappa( - use_scipy_wofz=use_scipy_wofz, - min_ellipticity=min_ellipticity) - super(GaussianEllipseKappaSet, self).__init__() - -
[docs] def function(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0): - """ - Compute the potential function for a set of concentric elliptical - Gaussian convergence profiles. - - :param x: x coordinate - :type x: ``float`` or ``numpy.array`` - :param y: y coordinate - :type y: ``float`` or ``numpy.array`` - :param amp: Amplitude of Gaussian, convention: :math:`A/(2 \\pi\\sigma^2) \\exp(-(x^2+y^2/q^2)/2\\sigma^2)` - :type amp: ``numpy.array`` with ``dtype=float`` - :param sigma: Standard deviation of Gaussian - :type sigma: ``numpy.array`` with ``dtype=float`` - :param e1: Ellipticity parameter 1 - :type e1: ``float`` - :param e2: Ellipticity parameter 2 - :type e2: ``float`` - :param center_x: x coordinate of centroid - :type center_x: ``float`` - :param center_y: y coordianate of centroid - :type center_y: ``float`` - :return: Potential for elliptical Gaussian convergence - :rtype: ``float``, or ``numpy.array`` with ``shape = x.shape`` - """ - function = np.zeros_like(x, dtype=float) - - for i in range(len(amp)): - function += self.gaussian_ellipse_kappa.function(x, y, - amp[i], - sigma[i], e1, - e2, - center_x, - center_y) - return function
- -
[docs] def derivatives(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0): - """ - Compute the derivatives of function angles :math:`\\partial - f/\\partial x`, :math:`\\partial f/\\partial y` at :math:`x,\\ y` for a - set of concentric elliptic Gaussian convergence profiles. - - :param x: x coordinate - :type x: ``float`` or ``numpy.array`` - :param y: y coordinate - :type y: ``float`` or ``numpy.array`` - :param amp: Amplitude of Gaussian, convention: :math:`A/(2 \\pi\\sigma^2) \\exp(-(x^2+y^2/q^2)/2\\sigma^2)` - :type amp: ``numpy.array`` with ``dtype=float`` - :param sigma: Standard deviation of Gaussian - :type sigma: ``numpy.array`` with ``dtype=float`` - :param e1: Ellipticity parameter 1 - :type e1: ``float`` - :param e2: Ellipticity parameter 2 - :type e2: ``float`` - :param center_x: x coordinate of centroid - :type center_x: ``float`` - :param center_y: y coordianate of centroid - :type center_y: ``float`` - :return: Deflection angle :math:`\\partial f/\\partial x`, :math:`\\partial f/\\partial y` for elliptical Gaussian convergence - :rtype: tuple ``(float, float)`` or ``(numpy.array, numpy.array)`` with each ``numpy`` array's shape equal to ``x.shape`` - """ - f_x = np.zeros_like(x, dtype=float) - f_y = np.zeros_like(x, dtype=float) - - for i in range(len(amp)): - f_x_i, f_y_i = self.gaussian_ellipse_kappa.derivatives(x, y, amp=amp[i], sigma=sigma[i], e1=e1, e2=e2, - center_x=center_x, center_y=center_y) - f_x += f_x_i - f_y += f_y_i - - return f_x, f_y
- -
[docs] def hessian(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0): - """ - Compute Hessian matrix of function :math:`\\partial^2f/\\partial x^2`, - :math:`\\partial^2 f/\\partial y^2`, :math:`\\partial^2 f/\\partial - x\\partial y` for a set of concentric elliptic Gaussian convergence - profiles. - - :param x: x coordinate - :type x: ``float`` or ``numpy.array`` - :param y: y coordinate - :type y: ``float`` or ``numpy.array`` - :param amp: Amplitude of Gaussian, convention: :math:`A/(2 \\pi\\sigma^2) \\exp(-(x^2+y^2/q^2)/2\\sigma^2)` - :type amp: ``numpy.array`` with ``dtype=float`` - :param sigma: Standard deviation of Gaussian - :type sigma: ``numpy.array`` with ``dtype=float`` - :param e1: Ellipticity parameter 1 - :type e1: ``float`` - :param e2: Ellipticity parameter 2 - :type e2: ``float`` - :param center_x: x coordinate of centroid - :type center_x: ``float`` - :param center_y: y coordianate of centroid - :type center_y: ``float`` - :return: Hessian :math:`\\partial^2f/\\partial x^2`, :math:`\\partial^2/\\partial x\\partial y`, - :math:`\\partial^2/\\partial y\\partial x`, :math:`\\partial^2 f/\\partial y^2` for elliptical Gaussian convergence. - :rtype: tuple ``(float, float, float)`` , or ``(numpy.array, numpy.array, numpy.array)`` - with each ``numpy`` array's shape equal to ``x.shape`` - """ - f_xx = np.zeros_like(x, dtype=float) - f_yy = np.zeros_like(x, dtype=float) - f_xy = np.zeros_like(x, dtype=float) - - for i in range(len(amp)): - f_xx_i, f_xy_i, _, f_yy_i = self.gaussian_ellipse_kappa.hessian(x, y, amp=amp[i], sigma=sigma[i], e1=e1, - e2=e2, center_x=center_x, center_y=center_y) - f_xx += f_xx_i - f_yy += f_yy_i - f_xy += f_xy_i - - return f_xx, f_xy, f_xy, f_yy
- -
[docs] def density_2d(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0): - """ - Compute the density of a set of concentric elliptical Gaussian - convergence profiles :math:`\\sum A/(2\\pi \\sigma^2) \\exp(-( - x^2+y^2/q^2)/2\\sigma^2)`. - - :param x: x coordinate - :type x: ``float`` or ``numpy.array`` - :param y: y coordinate - :type y: ``float`` or ``numpy.array`` - :param amp: Amplitude of Gaussian, convention: :math:`A/(2 \\pi\\sigma^2) \\exp(-(x^2+y^2/q^2)/2\\sigma^2)` - :type amp: ``numpy.array`` with ``dtype=float`` - :param sigma: Standard deviation of Gaussian - :type sigma: ``numpy.array`` with ``dtype=float`` - :param e1: Ellipticity parameter 1 - :type e1: ``float`` - :param e2: Ellipticity parameter 2 - :type e2: ``float`` - :param center_x: x coordinate of centroid - :type center_x: ``float`` - :param center_y: y coordianate of centroid - :type center_y: ``float`` - :return: Density :math:`\\kappa` for elliptical Gaussian convergence - :rtype: ``float``, or ``numpy.array`` with shape equal to ``x.shape`` - """ - density_2d = np.zeros_like(x, dtype=float) - - for i in range(len(amp)): - density_2d += self.gaussian_ellipse_kappa.density_2d(x, y, amp=amp[i], sigma=sigma[i], e1=e1, e2=e2, - center_x=center_x, center_y=center_y) - - return density_2d
- - -
[docs]@export -class GaussDecompositionAbstract(metaclass=abc.ABCMeta): - """ - This abstract class sets up a template for computing lensing properties of - an elliptical convergence through Shajib (2019)'s Gauss decomposition. - """ - def __init__(self, n_sigma=15, sigma_start_mult=0.02, sigma_end_mult=15., - precision=10, use_scipy_wofz=True, min_ellipticity=1e-5): - """ - Set up settings for the Gaussian decomposition. For more details about - the decomposition parameters, see Shajib (2019). - - :param n_sigma: Number of Gaussian components - :type n_sigma: ``int`` - :param sigma_start_mult: Lower range of logarithmically spaced sigmas - :type sigma_start_mult: ``float`` - :param sigma_end_mult: Upper range of logarithmically spaced sigmas - :type sigma_end_mult: ``float`` - :param precision: Numerical precision of Gaussian decomposition - :type precision: ``int`` - :param use_scipy_wofz: To be passed to ``class GaussianEllipseKappa``. If ``True``, Gaussian lensing will use ``scipy.special.wofz`` function. Set ``False`` for lower precision, but faster speed. - :type use_scipy_wofz: ``bool`` - :param min_ellipticity: To be passed to ``class GaussianEllipseKappa``. Minimum ellipticity for Gaussian elliptical lensing calculation. For lower ellipticity than min_ellipticity the equations for the spherical case will be used. - :type min_ellipticity: ``float`` - """ - self.gaussian_set = GaussianEllipseKappaSet( - use_scipy_wofz=use_scipy_wofz, - min_ellipticity=min_ellipticity) - - self.n_sigma = n_sigma - self.sigma_start_mult = sigma_start_mult - self.sigma_end_mult = sigma_end_mult - self.precision = precision - - p = self.precision - # nodes and weights based on Fourier-Euler method - # for details Abate & Whitt (2006) - kes = np.arange(2 * p + 1) - self.betas = np.sqrt(2 * p * np.log(10) / 3. + 2. * 1j * np.pi * kes) - epsilons = np.zeros(2 * p + 1) - - epsilons[0] = 0.5 - epsilons[1:p + 1] = 1. - epsilons[-1] = 1 / 2. ** p - - for k in range(1, p): - epsilons[2 * p - k] = epsilons[2 * p - k + 1] + 1 / 2. ** p * comb( - p, k) - - self.etas = (-1.) ** kes * epsilons * 10. ** (p / 3.) * 2. * _SQRT_2PI - -
[docs] def gauss_decompose(self, **kwargs): - r""" - Compute the amplitudes and sigmas of Gaussian components using the - integral transform with Gaussian kernel from Shajib (2019). The - returned values are in the convention of eq. (2.13). - - :param kwargs: Keyword arguments to send to ``func`` - :return: Amplitudes and standard deviations of the Gaussian components - :rtype: tuple ``(numpy.array, numpy.array)`` - """ - sigma_start = self.sigma_start_mult*self.get_scale(**kwargs) - sigma_end = self.sigma_end_mult*self.get_scale(**kwargs) - - sigmas = np.logspace(np.log10(sigma_start), np.log10(sigma_end), self.n_sigma) - - f_sigmas = np.sum(self.etas * self.get_kappa_1d(sigmas[:, np.newaxis]*self.betas[np.newaxis, :], **kwargs).real, - axis=1) - - del_log_sigma = np.abs(np.diff(np.log(sigmas)).mean()) - - amps = f_sigmas * del_log_sigma / _SQRT_2PI - - # weighting for trapezoid method integral - amps[0] *= 0.5 - amps[-1] *= 0.5 - - return amps, sigmas
- -
[docs] @abc.abstractmethod - def get_scale(self, **kwargs): - """ - Abstract method to identify the keyword argument for the scale size - among the profile parameters of the child class' convergence profile. - - :param kwargs: Keyword arguments - :return: Scale size - :rtype: ``float`` - """
- -
[docs] @abc.abstractmethod - def get_kappa_1d(self, y, **kwargs): - r""" - Abstract method to compute the spherical Sersic profile at y. - The concrete method has to defined by the child class. - - :param y: y coordinate - :type y: ``float`` or ``numpy.array`` - :param kwargs: Keyword arguments that are defined by the child class that are particular for the convergence profile - """
- -
[docs] def function(self, x, y, e1=0., e2=0., center_x=0., - center_y=0., **kwargs): - r""" - Compute the deflection potential of a Gauss-decomposed - elliptic convergence. - - :param x: x coordinate - :type x: ``float`` - :param y: y coordinate - :type y: ``float`` - :param e1: Ellipticity parameter 1 - :type e1: ``float`` - :param e2: Ellipticity parameter 2 - :type e2: ``float`` - :param center_x: x coordinate of centroid - :type center_x: ``float`` - :param center_y: y coordinate of centroid - :type center_y: ``float`` - :param kwargs: Keyword arguments that are defined by the child class that are particular for the convergence profile - :return: Deflection potential - :rtype: ``float`` - """ - amps, sigmas = self.gauss_decompose(**kwargs) - - # converting the amplitude convention A -> A/(2*pi*sigma^2) - amps *= 2.*np.pi * sigmas * sigmas - - return self.gaussian_set.function(x, y, amps, sigmas, e1, e2, center_x, center_y)
- -
[docs] def derivatives(self, x, y, e1=0., e2=0., center_x=0., - center_y=0., **kwargs): - r""" - Compute the derivatives of the deflection potential :math:`\partial - f/\partial x`, :math:`\partial f/\partial y` for a Gauss-decomposed - elliptic convergence. - - :param x: x coordinate - :type x: ``float`` or ``numpy.array`` - :param y: y coordinate - :type y: ``float`` or ``numpy.array`` - :param e1: Ellipticity parameter 1 - :type e1: ``float`` - :param e2: Ellipticity parameter 2 - :type e2: ``float`` - :param center_x: x coordinate of centroid - :type center_x: ``float`` - :param center_y: y coordinate of centroid - :type center_y: ``float`` - :param kwargs: Keyword arguments that are defined by the child class that are particular for the convergence profile - :return: Derivatives of deflection potential - :rtype: tuple ``(type(x), type(x))`` - """ - amps, sigmas = self.gauss_decompose(**kwargs) - - # converting the amplitude convention A -> A/(2*pi*sigma^2) - amps *= 2. * np.pi * sigmas * sigmas - - return self.gaussian_set.derivatives(x, y, amps, sigmas, e1, e2, center_x, center_y)
- -
[docs] def hessian(self, x, y, e1=0., e2=0., center_x=0., - center_y=0., **kwargs): - r""" - Compute the Hessian of the deflection potential - :math:`\partial^2f/\partial x^2`, :math:`\partial^2 f/ \partial - y^2`, :math:`\partial^2 f/\partial x\partial y` of a Gauss-decomposed - elliptic Sersic convergence. - - :param x: x coordinate - :type x: ``float`` or ``numpy.array`` - :param y: y coordinate - :type y: ``float`` or ``numpy.array`` - :param e1: Ellipticity parameter 1 - :type e1: ``float`` - :param e2: Ellipticity parameter 2 - :type e2: ``float`` - :param center_x: x coordinate of centroid - :type center_x: ``float`` - :param center_y: y coordinate of centroid - :type center_y: ``float`` - :param kwargs: Keyword arguments that are defined by the child class that are particular for the convergence profile - :return: Hessian of deflection potential - :rtype: tuple ``(type(x), type(x), type(x))`` - """ - amps, sigmas = self.gauss_decompose(**kwargs) - - # converting the amplitude convention A -> A/(2*pi*sigma^2) - amps *= 2. * np.pi * sigmas * sigmas - - return self.gaussian_set.hessian(x, y, amps, sigmas, e1, e2, center_x, center_y)
- -
[docs] def density_2d(self, x, y, e1=0., e2=0., center_x=0., - center_y=0., **kwargs): - r""" - Compute the convergence profile for Gauss-decomposed elliptic Sersic profile. - - :param x: x coordinate - :type x: ``float`` or ``numpy.array`` - :param y: y coordinate - :type y: ``float`` or ``numpy.array`` - :param e1: Ellipticity parameter 1 - :type e1: ``float`` - :param e2: Ellipticity parameter 2 - :type e2: ``float`` - :param center_x: x coordinate of centroid - :type center_x: ``float`` - :param center_y: y coordinate of centroid - :type center_y: ``float`` - :param kwargs: Keyword arguments that are defined by the child class that are particular for the convergence profile in the child class. - :return: Convergence profile - :rtype: ``type(x)`` - """ - amps, sigmas = self.gauss_decompose(**kwargs) - - # converting the amplitude convention A -> A/(2*pi*sigma^2) - amps *= 2. * np.pi * sigmas * sigmas - - return self.gaussian_set.density_2d(x, y, amps, sigmas, e1, e2, center_x, center_y)
- - -
[docs]@export -class SersicEllipseGaussDec(GaussDecompositionAbstract): - """ - This class computes the lensing properties of an elliptical Sersic - profile using the Shajib (2019)'s Gauss decomposition method. - """ - param_names = ['k_eff', 'R_sersic', 'n_sersic', 'e1', 'e2', 'center_x', - 'center_y'] - lower_limit_default = {'k_eff': 0., 'R_sersic': 0., 'n_sersic': 0.5, - 'e1': -0.5, 'e2': -0.5, 'center_x': -100., - 'center_y': -100.} - upper_limit_default = {'k_eff': 100., 'R_sersic': 100., 'n_sersic': 8., - 'e1': 0.5, 'e2': 0.5, 'center_x': 100., - 'center_y': 100.} - -
[docs] def get_kappa_1d(self, y, **kwargs): - r""" - Compute the spherical Sersic profile at y. - - :param y: y coordinate - :type y: ``float`` - :param kwargs: Keyword arguments - - :Keyword Arguments: - * **n_sersic** (``float``) -- - Sersic index - * **R_sersic** (``float``) -- - Sersic scale radius - * **k_eff** (``float``) -- - Sersic convergence at R_sersic - - :return: Sersic function at y - :rtype: ``type(y)`` - """ - n_sersic = kwargs['n_sersic'] - R_sersic = kwargs['R_sersic'] - k_eff = kwargs['k_eff'] - - bn = SersicUtil.b_n(n_sersic) - - return k_eff * np.exp(-bn * (y / R_sersic) ** (1. / n_sersic) + bn)
- -
[docs] def get_scale(self, **kwargs): - """ - Identify the scale size from the keyword arguments. - - :param kwargs: Keyword arguments - - :Keyword Arguments: - * **n_sersic** (``float``) -- - Sersic index - * **R_sersic** (``float``) -- - Sersic scale radius - * **k_eff** (``float``) -- - Sersic convergence at R_sersic - - :return: Sersic radius - :rtype: ``float`` - """ - return kwargs['R_sersic']
- - -
[docs]@export -class NFWEllipseGaussDec(GaussDecompositionAbstract): - """ - This class computes the lensing properties of an elliptical, projected NFW - profile using Shajib (2019)'s Gauss decomposition method. - """ - param_names = ['Rs', 'alpha_Rs', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'e1': -0.5, 'e2': -0.5, - 'center_x': -100, 'center_y': -100} - upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'e1': 0.5, 'e2': 0.5, - 'center_x': 100, 'center_y': 100} - - def __init__(self, n_sigma=15, sigma_start_mult=0.005, sigma_end_mult=50., - precision=10, use_scipy_wofz=True, min_ellipticity=1e-5): - """ - Set up settings for the Gaussian decomposition. For more details about - the decomposition parameters, see Shajib (2019). - - :param n_sigma: Number of Gaussian components - :type n_sigma: ``int`` - :param sigma_start_mult: Lower range of logarithmically spaced sigmas - :type sigma_start_mult: ``float`` - :param sigma_end_mult: Upper range of logarithmically spaced sigmas - :type sigma_end_mult: ``float`` - :param precision: Numerical precision of Gaussian decomposition - :type precision: ``int`` - :param use_scipy_wofz: To be passed to ``class GaussianEllipseKappa``. If ``True``, Gaussian lensing will use ``scipy.special.wofz`` function. Set ``False`` for lower precision, but faster speed. - :type use_scipy_wofz: ``bool`` - :param min_ellipticity: To be passed to ``class GaussianEllipseKappa``. Minimum ellipticity for Gaussian elliptical lensing calculation. For lower ellipticity than min_ellipticity the equations for the spherical case will be used. - :type min_ellipticity: ``float`` - """ - super(NFWEllipseGaussDec, self).__init__(n_sigma=n_sigma, - sigma_start_mult=sigma_start_mult, - sigma_end_mult=sigma_end_mult, - precision=precision, - use_scipy_wofz=use_scipy_wofz, - min_ellipticity=min_ellipticity) - -
[docs] def get_kappa_1d(self, y, **kwargs): - r""" - Compute the spherical projected NFW profile at y. - - :param y: y coordinate - :type y: ``float`` - :param kwargs: Keyword arguments - - :Keyword Arguments: - * **alpha_Rs** (``float``) -- - Deflection angle at ``Rs`` - * **R_s** (``float``) -- - NFW scale radius - - :return: projected NFW profile at y - :rtype: ``type(y)`` - """ - R_s = kwargs['Rs'] - alpha_Rs = kwargs['alpha_Rs'] - - kappa_s = alpha_Rs / (4 * R_s * (1 - 0.30102999566)) - # log2 = 0.30102999566 - - x = y/R_s - - f = np.empty(shape=x.shape, dtype=x.dtype) - - range1 = (x > 1.) - if np.any(range1): - s = x[range1] - f[range1] = (1 - np.arccos(1 / s) / np.sqrt(s * s - 1)) / ( - s * s - 1) - - range2 = (x < 1.) - if np.any(range2): - s = x[range2] - f[range2] = (1 - np.arccosh(1 / s) / np.sqrt(1 - s * s)) / ( - s * s - 1) - - range3 = np.logical_and(np.logical_not(range1), np.logical_not(range2)) - if np.any(range3): - f[range3] = 1. / 3. - - return 2 * kappa_s * f
- -
[docs] def get_scale(self, **kwargs): - """ - Identify the scale size from the keyword arguments. - - :param kwargs: Keyword arguments - - :Keyword Arguments: - * **alpha_Rs** (``float``) -- - Deflection angle at ``Rs`` - * **R_s** (``float``) -- - NFW scale radius - - :return: NFW scale radius - :rtype: ``float`` - """ - return kwargs['Rs']
- - -
[docs]@export -class GaussDecompositionAbstract3D(GaussDecompositionAbstract): - """ - This abstract class sets up a template for computing lensing properties of - a convergence from 3D spherical profile through Shajib (2019)'s Gauss - decomposition. - """ -
[docs] def gauss_decompose(self, **kwargs): - r""" - Compute the amplitudes and sigmas of Gaussian components using the - integral transform with Gaussian kernel from Shajib (2019). The - returned values are in the convention of eq. (2.13). - - :param kwargs: Keyword arguments to send to ``func`` - :return: Amplitudes and standard deviations of the Gaussian components - :rtype: tuple ``(numpy.array, numpy.array)`` - """ - - f_sigmas, sigmas = super(GaussDecompositionAbstract3D, - self).gauss_decompose(**kwargs) - - return f_sigmas * sigmas * _SQRT_2PI, sigmas
- - -
[docs]@export -class CTNFWGaussDec(GaussDecompositionAbstract3D): - """ - This class computes the lensing properties of an projection from a - spherical cored-truncated NFW profile using Shajib (2019)'s Gauss - decomposition method. - """ - param_names = ['r_s', 'r_core', 'r_trunc', 'a', 'rho_s', 'center_x' - 'center_y'] - lower_limit_default = {'r_s': 0, 'r_core': 0, 'r_trunc': 0, 'a': 0., - 'rho_s': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'r_s': 100, 'r_core': 100, 'r_trunc': 100, 'a': 10., - 'rho_s': 1000, 'center_x': 100, 'center_y': 100} - - def __init__(self, n_sigma=15, sigma_start_mult=0.01, sigma_end_mult=20., - precision=10, use_scipy_wofz=True): - """ - Set up settings for the Gaussian decomposition. For more details about - the decomposition parameters, see Shajib (2019). - - :param n_sigma: Number of Gaussian components - :type n_sigma: ``int`` - :param sigma_start_mult: Lower range of logarithmically spaced sigmas - :type sigma_start_mult: ``float`` - :param sigma_end_mult: Upper range of logarithmically spaced sigmas - :type sigma_end_mult: ``float`` - :param precision: Numerical precision of Gaussian decomposition - :type precision: ``int`` - :param use_scipy_wofz: To be passed to ``class GaussianEllipseKappa``. If ``True``, Gaussian lensing will use ``scipy.special.wofz`` function. Set ``False`` for lower precision, but faster speed. - :type use_scipy_wofz: ``bool`` - """ - super(CTNFWGaussDec, self).__init__(n_sigma=n_sigma, sigma_start_mult=sigma_start_mult, - sigma_end_mult=sigma_end_mult, precision=precision, - use_scipy_wofz=use_scipy_wofz) - -
[docs] def get_kappa_1d(self, y, **kwargs): - r""" - Compute the spherical cored-truncated NFW profile at y. - - :param y: y coordinate - :type y: ``float`` - :param kwargs: Keyword arguments - - :Keyword Arguments: - * **r_s** (``float``) -- - Scale radius - * **r_trunc** (``float``) -- - Truncation radius - * **r_core** (``float``) -- - Core radius - * **rho_s** (``float``) -- - Density normalization - * **a** (``float``) -- - Core regularization parameter - - :return: projected NFW profile at y - :rtype: ``type(y)`` - """ - r_s = kwargs['r_s'] - r_trunc = kwargs['r_trunc'] - r_core = kwargs['r_core'] - rho_s = kwargs['rho_s'] - a = kwargs['a'] - - beta = r_core/r_s - tau = r_trunc/r_s - - x = y/r_s - - return rho_s * (tau*tau / (tau*tau + x*x)) / (x**a + beta**a)**( - 1./a) / (1. + x)**2
- -
[docs] def get_scale(self, **kwargs): - """ - Identify the scale size from the keyword arguments. - - :param kwargs: Keyword arguments - - :Keyword Arguments: - * **r_s** (``float``) -- - Scale radius - * **r_trunc** (``float``) -- - Truncation radius - * **r_core** (``float``) -- - Core radius - * **rho_s** (``float``) -- - Density normalization - * **a** (``float``) -- - Core regularization parameter - - :return: NFW scale radius - :rtype: ``float`` - """ - return kwargs['r_s']
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/gaussian_ellipse_kappa.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/gaussian_ellipse_kappa.html deleted file mode 100644 index e33892572..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/gaussian_ellipse_kappa.html +++ /dev/null @@ -1,500 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.gaussian_ellipse_kappa — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.gaussian_ellipse_kappa

-# -*- coding: utf-8 -*-
-"""
-This module defines ``class GaussianEllipseKappa`` to compute the lensing
-properties of an elliptical Gaussian profile with ellipticity in the
-convergence using the formulae from Shajib (2019).
-"""
-
-__author__ = 'ajshajib'
-
-import numpy as np
-from scipy.special import wofz
-from scipy.integrate import quad
-from copy import deepcopy
-from lenstronomy.LensModel.Profiles.gaussian_kappa import GaussianKappa
-import lenstronomy.Util.param_util as param_util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['GaussianEllipseKappa']
-
-
-
[docs]class GaussianEllipseKappa(LensProfileBase): - """ - This class contains functions to evaluate the derivative and hessian matrix - of the deflection potential for an elliptical Gaussian convergence. - - The formulae are from Shajib (2019). - """ - param_names = ['amp', 'sigma', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'sigma': 0, 'e1': -0.5, 'e2': -0.5, - 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'sigma': 100, 'e1': 0.5, 'e2': 0.5, - 'center_x': 100, 'center_y': 100} - - def __init__(self, use_scipy_wofz=True, min_ellipticity=1e-5): - """ - Setup which method to use the Faddeeva function and the - ellipticity limit for spherical approximation. - - :param use_scipy_wofz: If ``True``, use ``scipy.special.wofz``. - :type use_scipy_wofz: ``bool`` - :param min_ellipticity: Minimum allowed ellipticity. For ``q > 1 - min_ellipticity``, values for spherical case will be returned. - :type min_ellipticity: ``float`` - """ - if use_scipy_wofz: - self.w_f = wofz - else: - self.w_f = self.w_f_approx - - self.min_ellipticity = min_ellipticity - self.spherical = GaussianKappa() - super(GaussianEllipseKappa, self).__init__() - -
[docs] def function(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0): - """ - Compute the potential function for elliptical Gaussian convergence. - - :param x: x coordinate - :type x: ``float`` or ``numpy.array`` - :param y: y coordinate - :type y: ``float`` or ``numpy.array`` - :param amp: Amplitude of Gaussian, convention: :math:`A/(2 \\pi\\sigma^2) \\exp(-(x^2+y^2/q^2)/2\\sigma^2)` - :type amp: ``float`` - :param sigma: Standard deviation of Gaussian - :type sigma: ``float`` - :param e1: Ellipticity parameter 1 - :type e1: ``float`` - :param e2: Ellipticity parameter 2 - :type e2: ``float`` - :param center_x: x coordinate of centroid - :type center_x: ``float`` - :param center_y: y coordianate of centroid - :type center_y: ``float`` - :return: Potential for elliptical Gaussian convergence - :rtype: ``float``, or ``numpy.array`` with shape equal to ``x.shape`` - """ - phi_g, q = param_util.ellipticity2phi_q(e1, e2) - - if q > 1 - self.min_ellipticity: - return self.spherical.function(x, y, amp, sigma, center_x, - center_y) - - # adjusting amplitude to make the notation compatible with the - # formulae given in Shajib (2019). - amp_ = amp / (2 * np.pi * sigma**2) - - # converting ellipticity definition from q*x^2 + y^2/q to q^2*x^2 + y^2 - sigma_ = sigma * np.sqrt(q) # * q - - x_shift = x - center_x - y_shift = y - center_y - cos_phi = np.cos(phi_g) - sin_phi = np.sin(phi_g) - - x_ = cos_phi * x_shift + sin_phi * y_shift - y_ = -sin_phi * x_shift + cos_phi * y_shift - - _b = 1. / 2. / sigma_ ** 2 - _p = np.sqrt(_b * q ** 2 / (1. - q ** 2)) - - if isinstance(x_, int) or isinstance(x_, float): - return self._num_integral(x_, y_, amp_, sigma_, _p, q) - else: - f_ = [] - for i in range(len(x_)): - f_.append(self._num_integral(x_[i], y_[i], amp_, sigma_, _p, q)) - return np.array(f_)
- - def _num_integral(self, x_, y_, amp_, sigma_, _p, q): - """ - - :param x_: - :param y_: - :param _p: - :param q: - :return: - """ - def pot_real_line_integrand(_x): - sig_func_re, sig_func_im = self.sigma_function(_p * _x, 0, q) - - alpha_x_ = amp_*sigma_ * self.sgn(_x) * np.sqrt(2*np.pi / ( - 1. - q ** 2)) * sig_func_re - - return alpha_x_ - - def pot_imag_line_integrand(_y): - sig_func_re, sig_func_im = self.sigma_function(_p * x_, _p * _y, q) - - alpha_y_ = -amp_*sigma_ * self.sgn(x_ + 1j*_y) * np.sqrt(2*np.pi / (1. - q ** 2)) * sig_func_im - - return alpha_y_ - - pot_on_real_line = quad(pot_real_line_integrand, 0, x_)[0] - pot_on_imag_parallel = quad(pot_imag_line_integrand, 0, y_)[0] - return pot_on_real_line + pot_on_imag_parallel - -
[docs] def derivatives(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0): - """ - Compute the derivatives of function angles :math:`\\partial - f/\\partial x`, :math:`\\partial f/\\partial y` at :math:`x,\\ y`. - - :param x: x coordinate - :type x: ``float`` or ``numpy.array`` - :param y: y coordinate - :type y: ``float`` or ``numpy.array`` - :param amp: Amplitude of Gaussian, convention: :math:`A/(2 \\pi\\sigma^2) \\exp(-(x^2+y^2/q^2)/2\\sigma^2)` - :type amp: ``float`` - :param sigma: Standard deviation of Gaussian - :type sigma: ``float`` - :param e1: Ellipticity parameter 1 - :type e1: ``float`` - :param e2: Ellipticity parameter 2 - :type e2: ``float`` - :param center_x: x coordinate of centroid - :type center_x: ``float`` - :param center_y: y coordianate of centroid - :type center_y: ``float`` - :return: Deflection angle :math:`\\partial f/\\partial x`, :math:`\\partial f/\\partial y` - for elliptical Gaussian convergence. - :rtype: tuple ``(float, float)`` or ``(numpy.array, numpy.array)`` with each ``numpy.array``'s shape equal - to ``x.shape``. - """ - phi_g, q = param_util.ellipticity2phi_q(e1, e2) - - if q > 1 - self.min_ellipticity: - return self.spherical.derivatives(x, y, amp, sigma, center_x, - center_y) - - # adjusting amplitude to make the notation compatible with the - # formulae given in Shajib (2019). - amp_ = amp / (2 * np.pi * sigma**2) - - # converting ellipticity definition from q*x^2 + y^2/q to q^2*x^2 + y^2 - sigma_ = sigma * np.sqrt(q) # * q - - x_shift = x - center_x - y_shift = y - center_y - cos_phi = np.cos(phi_g) - sin_phi = np.sin(phi_g) - - # rotated coordinates - x_ = cos_phi * x_shift + sin_phi * y_shift - y_ = -sin_phi * x_shift + cos_phi * y_shift - - _p = q / sigma_ / np.sqrt(2 * (1. - q**2)) - - sig_func_re, sig_func_im = self.sigma_function(_p * x_, _p * y_, q) - - alpha_x_ = amp_ * sigma_ * self.sgn(x_ + 1j*y_) * np.sqrt(2*np.pi/( - 1.-q**2)) * sig_func_re - alpha_y_ = - amp_ * sigma_ * self.sgn(x_ + 1j*y_) * np.sqrt( - 2 * np.pi / (1. - q ** 2)) * sig_func_im - - # rotate back to the original frame - f_x = alpha_x_ * cos_phi - alpha_y_ * sin_phi - f_y = alpha_x_ * sin_phi + alpha_y_ * cos_phi - - return f_x, f_y
- -
[docs] def hessian(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0): - """ - Compute Hessian matrix of function :math:`\\partial^2f/\\partial x^2`, - :math:`\\partial^2 f/\\partial y^2`, :math:`\\partial^2/\\partial - x\\partial y`. - - :param x: x coordinate - :type x: ``float`` or ``numpy.array`` - :param y: y coordinate - :type y: ``float`` or ``numpy.array`` - :param amp: Amplitude of Gaussian, convention: :math:`A/(2 \\pi\\sigma^2) \\exp(-(x^2+y^2/q^2)/2\\sigma^2)` - :type amp: ``float`` - :param sigma: Standard deviation of Gaussian - :type sigma: ``float`` - :param e1: Ellipticity parameter 1 - :type e1: ``float`` - :param e2: Ellipticity parameter 2 - :type e2: ``float`` - :param center_x: x coordinate of centroid - :type center_x: ``float`` - :param center_y: y coordianate of centroid - :type center_y: ``float`` - :return: Hessian :math:`A/(2 \\pi \\sigma^2) \\exp(-(x^2+y^2/q^2)/2\\sigma^2)` for elliptical Gaussian - convergence. - :rtype: tuple ``(float, float, float)`` , or ``(numpy.array, numpy.array, numpy.array)`` with each ``numpy.array``'s shape equal to ``x.shape``. - """ - phi_g, q = param_util.ellipticity2phi_q(e1, e2) - - if q > 1 - self.min_ellipticity: - return self.spherical.hessian(x, y, amp, sigma, center_x, center_y) - - # adjusting amplitude to make the notation compatible with the - # formulae given in Shajib (2019). - amp_ = amp / (2 * np.pi * sigma**2) - - # converting ellipticity definition from q*x^2 + y^2/q to q^2*x^2 + y^2 - sigma_ = sigma * np.sqrt(q) # * q - - x_shift = x - center_x - y_shift = y - center_y - cos_phi = np.cos(phi_g) - sin_phi = np.sin(phi_g) - - # rotated coordinates - x_ = cos_phi * x_shift + sin_phi * y_shift - y_ = -sin_phi * x_shift + cos_phi * y_shift - - _p = q / sigma_ / np.sqrt(2 * (1. - q**2)) - sig_func_re, sig_func_im = self.sigma_function(_p * x_, _p * y_, q) - - kappa = amp_ * np.exp(-(q**2 * x_**2 + y_**2) / 2 / sigma_**2) - - shear = - 1/(1-q*q) * ((1+q**2)*kappa - 2*q*amp_ + np.sqrt( - 2*np.pi) * q*q * amp_ * (x_ - 1j*y_) / sigma_ / np.sqrt(1-q*q) * ( - sig_func_re - 1j*sig_func_im)) - - # in rotated frame - f_xx_ = kappa + shear.real - f_yy_ = kappa - shear.real - f_xy_ = shear.imag - - # rotate back to the original frame - f_xx = f_xx_ * cos_phi**2 + f_yy_ * sin_phi**2 - 2 * sin_phi * cos_phi * f_xy_ - f_yy = f_xx_ * sin_phi**2 + f_yy_ * cos_phi**2 + 2 * sin_phi * cos_phi * f_xy_ - f_xy = sin_phi * cos_phi * (f_xx_ - f_yy_) + (cos_phi**2 - sin_phi**2) * f_xy_ - - return f_xx, f_xy, f_xy, f_yy
- -
[docs] def density_2d(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0): - """ - Compute the density of elliptical Gaussian :math:`A/(2 \\pi - \\sigma^2) \\exp(-(x^2+y^2/q^2)/2\\sigma^2)`. - - :param x: x coordinate. - :type x: ``float`` or ``numpy.array`` - :param y: y coordinate. - :type y: ``float`` or ``numpy.array`` - :param amp: Amplitude of Gaussian, convention: :math:`A/(2 \\pi\\sigma^2) \\exp(-(x^2+y^2/q^2)/2\\sigma^2)` - :type amp: ``float`` - :param sigma: Standard deviation of Gaussian. - :type sigma: ``float`` - :param e1: Ellipticity parameter 1. - :type e1: ``float`` - :param e2: Ellipticity parameter 2. - :type e2: ``float`` - :param center_x: x coordinate of centroid. - :type center_x: ``float`` - :param center_y: y coordianate of centroid. - :type center_y: ``float`` - :return: Density :math:`\\kappa` for elliptical Gaussian convergence. - :rtype: ``float``, or ``numpy.array`` with shape = ``x.shape``. - """ - f_xx, f_xy, f_yx, f_yy = self.hessian(x, y, amp, sigma, e1, e2, center_x, center_y) - return (f_xx + f_yy) / 2
- -
[docs] @staticmethod - def sgn(z): - """ - Compute the sign function :math:`\\mathrm{sgn}(z)` factor for - deflection as sugggested by Bray (1984). For current implementation, returning 1 is sufficient. - - :param z: Complex variable :math:`z = x + \\mathrm{i}y` - :type z: ``complex`` - :return: :math:`\\mathrm{sgn}(z)` - :rtype: ``float`` - """ - return 1.
- # np.sqrt(z*z)/z #np.sign(z.real*z.imag) - # return np.sign(z.real) - # if z.real != 0: - # return np.sign(z.real) - # else: - # return np.sign(z.imag) - # return np.where(z.real == 0, np.sign(z.real), np.sign(z.imag)) - -
[docs] def sigma_function(self, x, y, q): - r""" - Compute the function :math:`\varsigma (z; q)` from equation (4.12) - of Shajib (2019). - - :param x: Real part of complex variable, :math:`x = \mathrm{Re}(z)` - :type x: ``float`` or ``numpy.array`` - :param y: Imaginary part of complex variable, :math:`y = \mathrm{Im}(z)` - :type y: ``float`` or ``numpy.array`` - :param q: Axis ratio - :type q: ``float`` - :return: real and imaginary part of :math:`\varsigma(z; q)` function - :rtype: tuple ``(type(x), type(x))`` - """ - y_sign = np.sign(y) - y_ = deepcopy(y) * y_sign - z = x + 1j * y_ - zq = q * x + 1j * y_ / q - - w = self.w_f(z) - wq = self.w_f(zq) - - # exponential factor in the 2nd term of eqn. (4.15) of Shajib (2019) - exp_factor = np.exp(-x * x * (1 - q * q) - y_ * y_ * (1 / q / q - 1)) - - sigma_func_real = w.imag - exp_factor * wq.imag - sigma_func_imag = (- w.real + exp_factor * wq.real) * y_sign - - return sigma_func_real, sigma_func_imag
- -
[docs] @staticmethod - def w_f_approx(z): - """ - Compute the Faddeeva function :math:`w_{\\mathrm F}(z)` using the - approximation given in Zaghloul (2017). - - :param z: complex number - :type z: ``complex`` or ``numpy.array(dtype=complex)`` - :return: :math:`w_\\mathrm{F}(z)` - :rtype: ``complex`` - """ - sqrt_pi = 1 / np.sqrt(np.pi) - i_sqrt_pi = 1j * sqrt_pi - - wz = np.empty_like(z) - - z_imag2 = z.imag ** 2 - abs_z2 = z.real ** 2 + z_imag2 - - reg1 = (abs_z2 >= 38000.) - if np.any(reg1): - wz[reg1] = i_sqrt_pi / z[reg1] - - reg2 = (256. <= abs_z2) & (abs_z2 < 38000.) - if np.any(reg2): - t = z[reg2] - wz[reg2] = i_sqrt_pi * t / (t * t - 0.5) - - reg3 = (62. <= abs_z2) & (abs_z2 < 256.) - if np.any(reg3): - t = z[reg3] - wz[reg3] = (i_sqrt_pi / t) * (1 + 0.5 / (t * t - 1.5)) - - reg4 = (30. <= abs_z2) & (abs_z2 < 62.) & (z_imag2 >= 1e-13) - if np.any(reg4): - t = z[reg4] - tt = t * t - wz[reg4] = (i_sqrt_pi * t) * (tt - 2.5) / (tt * (tt - 3.) + 0.75) - - reg5 = (62. > abs_z2) & np.logical_not(reg4) & (abs_z2 > 2.5) & ( - z_imag2 < 0.072) - if np.any(reg5): - t = z[reg5] - u = -t * t - f1 = sqrt_pi - f2 = 1 - s1 = [1.320522, 35.7668, 219.031, 1540.787, 3321.99, 36183.31] - s2 = [1.841439, 61.57037, 364.2191, 2186.181, 9022.228, 24322.84, - 32066.6] - - for s in s1: - f1 = s - f1 * u - for s in s2: - f2 = s - f2 * u - - wz[reg5] = np.exp(u) + 1j * t * f1 / f2 - - reg6 = (30.0 > abs_z2) & np.logical_not(reg5) - if np.any(reg6): - t3 = - 1j * z[reg6] - - f1 = sqrt_pi - f2 = 1 - s1 = [5.9126262, 30.180142, 93.15558, 181.92853, 214.38239, - 122.60793] - s2 = [10.479857, 53.992907, 170.35400, 348.70392, 457.33448, - 352.73063, 122.60793] - - for s in s1: - f1 = f1 * t3 + s - for s in s2: - f2 = f2 * t3 + s - - wz[reg6] = f1 / f2 - return wz
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/gaussian_ellipse_potential.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/gaussian_ellipse_potential.html deleted file mode 100644 index 50943ce7d..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/gaussian_ellipse_potential.html +++ /dev/null @@ -1,233 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.gaussian_ellipse_potential — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.gaussian_ellipse_potential

-__author__ = 'sibirrer'
-#this file contains a class to make a gaussian
-
-import numpy as np
-from lenstronomy.LensModel.Profiles.gaussian_kappa import GaussianKappa
-import lenstronomy.Util.param_util as param_util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['GaussianEllipsePotential']
-
-
-
[docs]class GaussianEllipsePotential(LensProfileBase): - """ - this class contains functions to evaluate a Gaussian function and calculates its derivative and hessian matrix - with ellipticity in the convergence - - the calculation follows Glenn van de Ven et al. 2009 - - """ - param_names = ['amp', 'sigma', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'sigma': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'sigma': 100, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.spherical = GaussianKappa() - self._diff = 0.000001 - super(GaussianEllipsePotential, self).__init__() - -
[docs] def function(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0): - """ - returns Gaussian - """ - - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - x_shift = x - center_x - y_shift = y - center_y - cos_phi = np.cos(phi_G) - sin_phi = np.sin(phi_G) - e = abs(1 - q) - x_ = (cos_phi * x_shift + sin_phi * y_shift) * np.sqrt(1 - e) - y_ = (-sin_phi * x_shift + cos_phi * y_shift) * np.sqrt(1 + e) - f_ = self.spherical.function(x_, y_, amp=amp, sigma=sigma) - return f_
- -
[docs] def derivatives(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0): - """ - returns df/dx and df/dy of the function - """ - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - x_shift = x - center_x - y_shift = y - center_y - cos_phi = np.cos(phi_G) - sin_phi = np.sin(phi_G) - e = abs(1 - q) - x_ = (cos_phi * x_shift + sin_phi * y_shift) * np.sqrt(1 - e) - y_ = (-sin_phi * x_shift + cos_phi * y_shift) * np.sqrt(1 + e) - - f_x_prim, f_y_prim = self.spherical.derivatives(x_, y_, amp=amp, sigma=sigma) - f_x_prim *= np.sqrt(1 - e) - f_y_prim *= np.sqrt(1 + e) - f_x = cos_phi * f_x_prim - sin_phi * f_y_prim - f_y = sin_phi * f_x_prim + cos_phi * f_y_prim - return f_x, f_y
- -
[docs] def hessian(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0): - """ - returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - alpha_ra, alpha_dec = self.derivatives(x, y, amp, sigma, e1, e2, center_x, center_y) - diff = self._diff - alpha_ra_dx, alpha_dec_dx = self.derivatives(x + diff, y, amp, sigma, e1, e2, center_x, center_y) - alpha_ra_dy, alpha_dec_dy = self.derivatives(x, y + diff, amp, sigma, e1, e2, center_x, center_y) - - f_xx = (alpha_ra_dx - alpha_ra) / diff - f_xy = (alpha_ra_dy - alpha_ra) / diff - f_yx = (alpha_dec_dx - alpha_dec) / diff - f_yy = (alpha_dec_dy - alpha_dec) / diff - return f_xx, f_xy, f_yx, f_yy
- -
[docs] def density(self, r, amp, sigma, e1, e2): - """ - - :param r: - :param amp: - :param sigma: - :return: - """ - return self.spherical.density(r, amp, sigma)
- -
[docs] def density_2d(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0): - """ - - :param x: - :param y: - :param amp: - :param sigma: - :param e1: - :param e2: - :param center_x: - :param center_y: - :return: - """ - return self.spherical.density_2d(x, y, amp, sigma, center_x, center_y)
- -
[docs] def mass_2d(self, R, amp, sigma, e1, e2): - """ - - :param R: - :param amp: - :param sigma: - :param e1: - :param e2: - :return: - """ - return self.spherical.mass_2d(R, amp, sigma)
- -
[docs] def mass_3d(self, R, amp, sigma, e1, e2): - """ - - :param R: - :param amp: - :param sigma: - :param e1: - :param e2: - :return: - """ - return self.spherical.mass_3d(R, amp, sigma)
- -
[docs] def mass_3d_lens(self, R, amp, sigma, e1, e2): - """ - - :param R: - :param amp: - :param sigma: - :param e1: - :param e2: - :return: - """ - return self.spherical.mass_3d_lens(R, amp, sigma)
- -
[docs] def mass_2d_lens(self, R, amp, sigma, e1, e2): - """ - - :param R: - :param amp: - :param sigma: - :param e1: - :param e2: - :return: - """ - return self.spherical.mass_2d_lens(R, amp, sigma)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/gaussian_kappa.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/gaussian_kappa.html deleted file mode 100644 index ca3e63520..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/gaussian_kappa.html +++ /dev/null @@ -1,298 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.gaussian_kappa — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.gaussian_kappa

-__author__ = 'sibirrer'
-#this file contains a class to make a gaussian
-
-import numpy as np
-import scipy.special
-import scipy.integrate as integrate
-from lenstronomy.LensModel.Profiles.gaussian_potential import Gaussian
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['GaussianKappa']
-
-
-
[docs]class GaussianKappa(LensProfileBase): - """ - this class contains functions to evaluate a Gaussian function and calculates its derivative and hessian matrix - """ - param_names = ['amp', 'sigma', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'sigma': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'sigma': 100, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.gaussian = Gaussian() - self.ds = 0.00001 - super(LensProfileBase, self).__init__() - -
[docs] def function(self, x, y, amp, sigma, center_x=0, center_y=0): - """ - returns Gaussian - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - sigma_x, sigma_y = sigma, sigma - c = 1. / (2 * sigma_x * sigma_y) - if isinstance(x_, int) or isinstance(x_, float): - num_int = self._num_integral(r, c) - else: - num_int = [] - for i in range(len(x_)): - num_int.append(self._num_integral(r[i], c)) - num_int = np.array(num_int) - amp_density = self._amp2d_to_3d(amp, sigma_x, sigma_y) - amp2d = amp_density / (np.sqrt(np.pi) * np.sqrt(sigma_x * sigma_y * 2)) - amp2d *= 2 * 1. / (2 * c) - return num_int * amp2d
- - @staticmethod - def _num_integral(r, c): - """ - numerical integral (1-e^{-c*x^2})/x dx [0..r] - :param r: radius - :param c: 1/2sigma^2 - :return: - """ - out = integrate.quad(lambda x: (1-np.exp(-c*x**2))/x, 0, r) - return out[0] - -
[docs] def derivatives(self, x, y, amp, sigma, center_x=0, center_y=0): - """ - returns df/dx and df/dy of the function - """ - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_**2 + y_**2) - sigma_x, sigma_y = sigma, sigma - if isinstance(R, int) or isinstance(R, float): - R = max(R, self.ds) - else: - R[R <= self.ds] = self.ds - alpha = self.alpha_abs(R, amp, sigma) - return alpha / R * x_, alpha / R * y_
- -
[docs] def hessian(self, x, y, amp, sigma, center_x=0, center_y=0): - """ - returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - sigma_x, sigma_y = sigma, sigma - if isinstance(r, int) or isinstance(r, float): - r = max(r, self.ds) - else: - r[r <= self.ds] = self.ds - d_alpha_dr = -self.d_alpha_dr(r, amp, sigma_x, sigma_y) - alpha = self.alpha_abs(r, amp, sigma) - - f_xx = -(d_alpha_dr/r + alpha/r**2) * x_**2/r + alpha/r - f_yy = -(d_alpha_dr/r + alpha/r**2) * y_**2/r + alpha/r - f_xy = -(d_alpha_dr/r + alpha/r**2) * x_*y_/r - return f_xx, f_xy, f_xy, f_yy
- -
[docs] def density(self, r, amp, sigma): - """ - - :param r: - :param amp: - :param sigma: - :return: - """ - sigma_x, sigma_y = sigma, sigma - return self.gaussian.function(r, 0, amp, sigma_x, sigma_y)
- -
[docs] def density_2d(self, x, y, amp, sigma, center_x=0, center_y=0): - """ - - :param x: - :param y: - :param amp: - :param sigma: - :param center_x: - :param center_y: - :return: - """ - sigma_x, sigma_y = sigma, sigma - amp2d = self._amp3d_to_2d(amp, sigma_x, sigma_y) - return self.gaussian.function(x, y, amp2d, sigma_x, sigma_y, center_x, center_y)
- -
[docs] def mass_2d(self, R, amp, sigma): - """ - - :param R: - :param amp: - :param sigma: - :return: - """ - sigma_x, sigma_y = sigma, sigma - amp2d = amp / (np.sqrt(np.pi) * np.sqrt(sigma_x * sigma_y * 2)) - c = 1./(2 * sigma_x * sigma_y) - return amp2d * 2 * np.pi * 1./(2*c) * (1. - np.exp(-c * R**2))
- -
[docs] def mass_2d_lens(self, R, amp, sigma): - """ - - :param R: - :param amp: - :param sigma: - :return: - """ - sigma_x, sigma_y = sigma, sigma - amp_density = self._amp2d_to_3d(amp, sigma_x, sigma_y) - return self.mass_2d(R, amp_density, sigma)
- -
[docs] def alpha_abs(self, R, amp, sigma): - """ - absolute value of the deflection - :param R: - :param amp: - :param sigma: - :return: - """ - sigma_x, sigma_y = sigma, sigma - amp_density = self._amp2d_to_3d(amp, sigma_x, sigma_y) - alpha = self.mass_2d(R, amp_density, sigma) / np.pi / R - return alpha
- -
[docs] def d_alpha_dr(self, R, amp, sigma_x, sigma_y): - """ - - :param R: - :param amp: - :param sigma_x: - :param sigma_y: - :return: - """ - c = 1. / (2 * sigma_x * sigma_y) - A = self._amp2d_to_3d(amp, sigma_x, sigma_y) * np.sqrt(2/np.pi*sigma_x*sigma_y) - return 1./R**2 * (-1 + (1 + 2*c*R**2) * np.exp(-c*R**2)) * A
- -
[docs] def mass_3d(self, R, amp, sigma): - """ - - :param R: - :param amp: - :param sigma: - :return: - """ - sigma_x, sigma_y = sigma, sigma - A = amp / (2 * np.pi * sigma_x * sigma_y) - c = 1. / (2 * sigma_x * sigma_y) - result = 1. / (2*c) * (-R * np.exp(-c*R**2) + scipy.special.erf(np.sqrt(c) * R) * np.sqrt(np.pi/(4 * c))) - return result*A * 4 * np.pi
- -
[docs] def mass_3d_lens(self, R, amp, sigma): - """ - - :param R: - :param amp: - :param sigma: - :return: - """ - sigma_x, sigma_y = sigma, sigma - amp_density = self._amp2d_to_3d(amp, sigma_x, sigma_y) - return self.mass_3d(R, amp_density, sigma)
- - @staticmethod - def _amp3d_to_2d(amp, sigma_x, sigma_y): - """ - converts 3d density into 2d density parameter - :param amp: - :param sigma_x: - :param sigma_y: - :return: - """ - return amp * np.sqrt(np.pi) * np.sqrt(sigma_x * sigma_y * 2) - - @staticmethod - def _amp2d_to_3d(amp, sigma_x, sigma_y): - """ - converts 3d density into 2d density parameter - :param amp: - :param sigma_x: - :param sigma_y: - :return: - """ - return amp / (np.sqrt(np.pi) * np.sqrt(sigma_x * sigma_y * 2))
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/gaussian_potential.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/gaussian_potential.html deleted file mode 100644 index 809040236..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/gaussian_potential.html +++ /dev/null @@ -1,125 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.gaussian_potential — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.gaussian_potential

-__author__ = 'sibirrer'
-#this file contains a class to make a gaussian
-
-import numpy as np
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['Gaussian']
-
-
-
[docs]class Gaussian(LensProfileBase): - """ - this class contains functions to evaluate a Gaussian function and calculates its derivative and hessian matrix - """ - param_names = ['amp', 'sigma_x', 'sigma_y', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'sigma': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'sigma': 100, 'center_x': 100, 'center_y': 100} - -
[docs] def function(self, x, y, amp, sigma_x, sigma_y, center_x=0, center_y=0): - """ - returns Gaussian - """ - c = amp/(2*np.pi*sigma_x*sigma_y) - delta_x = x - center_x - delta_y = y - center_y - exponent = -((delta_x/sigma_x)**2+(delta_y/sigma_y)**2)/2. - return c * np.exp(exponent)
- -
[docs] def derivatives(self, x, y, amp, sigma_x, sigma_y, center_x=0, center_y=0): - """ - returns df/dx and df/dy of the function - """ - f_ = self.function(x, y, amp, sigma_x, sigma_y, center_x, center_y) - return f_ * (center_x-x)/sigma_x**2, f_ * (center_y-y)/sigma_y**2
- -
[docs] def hessian(self, x, y, amp, sigma_x, sigma_y, center_x = 0, center_y = 0): - """ - returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - f_ = self.function(x, y, amp, sigma_x, sigma_y, center_x, center_y) - f_xx = f_ * ( (-1./sigma_x**2) + (center_x-x)**2/sigma_x**4 ) - f_yy = f_ * ( (-1./sigma_y**2) + (center_y-y)**2/sigma_y**4 ) - f_xy = f_ * (center_x-x)/sigma_x**2 * (center_y-y)/sigma_y**2 - return f_xx, f_xy, f_xy, f_yy
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/hernquist.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/hernquist.html deleted file mode 100644 index 47e58b7fb..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/hernquist.html +++ /dev/null @@ -1,359 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.hernquist — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.hernquist

-import numpy as np
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['Hernquist']
-
-
-
[docs]class Hernquist(LensProfileBase): - """ - class to compute the Hernquist 1990 model, which is in 3d: - rho(r) = rho0 / (r/Rs * (1 + (r/Rs))**3) - - in lensing terms, the normalization parameter 'sigma0' is defined such that the deflection at projected RS leads to - alpha = 2./3 * Rs * sigma0 - - """ - _diff = 0.00000001 - _s = 0.00001 - param_names = ['sigma0', 'Rs', 'center_x', 'center_y'] - lower_limit_default = {'sigma0': 0, 'Rs': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'sigma0': 100, 'Rs': 100, 'center_x': 100, 'center_y': 100} - -
[docs] def density(self, r, rho0, Rs): - """ - computes the 3-d density - - :param r: 3-d radius - :param rho0: density normalization - :param Rs: Hernquist radius - :return: density at radius r - """ - rho = rho0 / (r/Rs * (1 + (r/Rs))**3) - return rho
- -
[docs] def density_lens(self, r, sigma0, Rs): - """ - Density as a function of 3d radius in lensing parameters - This function converts the lensing definition sigma0 into the 3d density - - :param r: 3d radius - :param sigma0: rho0 * Rs (units of projected density) - :param Rs: Hernquist radius - :return: enclosed mass in 3d - """ - rho0 = self.sigma2rho(sigma0, Rs) - return self.density(r, rho0, Rs)
- -
[docs] def density_2d(self, x, y, rho0, Rs, center_x=0, center_y=0): - """ - projected density along the line of sight at coordinate (x, y) - - :param x: x-coordinate - :param y: y-coordinate - :param rho0: density normalization - :param Rs: Hernquist radius - :param center_x: x-center of the profile - :param center_y: y-center of the profile - :return: projected density - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - X = r/Rs - sigma0 = self.rho2sigma(rho0, Rs) - if isinstance(X, int) or isinstance(X, float): - if X == 1: - X = 1.000001 - else: - X[X == 1] = 1.000001 - sigma = sigma0 / (X**2-1)**2 * (-3 + (2+X**2)*self._F(X)) - return sigma
- -
[docs] def mass_3d(self, r, rho0, Rs): - """ - mass enclosed a 3d sphere or radius r - - :param r: 3-d radius within the mass is integrated (same distance units as density definition) - :param rho0: density normalization - :param Rs: Hernquist radius - :return: enclosed mass - """ - mass_3d = 2*np.pi*Rs**3*rho0 * r**2/(r + Rs)**2 - return mass_3d
- -
[docs] def mass_3d_lens(self, r, sigma0, Rs): - """ - mass enclosed a 3d sphere or radius r for lens parameterisation - This function converts the lensing definition sigma0 into the 3d density - - :param sigma0: rho0 * Rs (units of projected density) - :param Rs: Hernquist radius - :return: enclosed mass in 3d - """ - rho0 = self.sigma2rho(sigma0, Rs) - return self.mass_3d(r, rho0, Rs)
- -
[docs] def mass_2d(self, r, rho0, Rs): - """ - mass enclosed projected 2d sphere of radius r - - :param r: projected radius - :param rho0: density normalization - :param Rs: Hernquist radius - :return: mass enclosed 2d projected radius - """ - - sigma0 = self.rho2sigma(rho0, Rs) - return self.mass_2d_lens(r, sigma0, Rs)
- -
[docs] def mass_2d_lens(self, r, sigma0, Rs): - """ - mass enclosed projected 2d sphere of radius r - Same as mass_2d but with input normalization in units of projected density - :param r: projected radius - :param sigma0: rho0 * Rs (units of projected density) - :param Rs: Hernquist radius - :return: mass enclosed 2d projected radius - """ - X = r/Rs - alpha_r = 2*sigma0 * Rs * X * (1-self._F(X)) / (X**2-1) - mass_2d = alpha_r * r * np.pi - return mass_2d
- -
[docs] def mass_tot(self, rho0, Rs): - """ - total mass within the profile - :param rho0: density normalization - :param Rs: Hernquist radius - :return: total mass within profile - """ - m_tot = 2*np.pi*rho0*Rs**3 - return m_tot
- -
[docs] def function(self, x, y, sigma0, Rs, center_x=0, center_y=0): - """ - lensing potential - - :param x: x-coordinate position (units of angle) - :param y: y-coordinate position (units of angle) - :param sigma0: normalization parameter defined such that the deflection at projected RS leads to alpha = 2./3 * Rs * sigma0 - :param Rs: Hernquist radius in units of angle - :param center_x: x-center of the profile (units of angle) - :param center_y: y-center of the profile (units of angle) - :return: lensing potential at (x,y) - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - r = np.maximum(r, self._s) - X = r / Rs - f_ = sigma0 * Rs ** 2 * (np.log(X ** 2 / 4.) + 2 * self._F(X)) - return f_
- -
[docs] def derivatives(self, x, y, sigma0, Rs, center_x=0, center_y=0): - """ - - :param x: x-coordinate position (units of angle) - :param y: y-coordinate position (units of angle) - :param sigma0: normalization parameter defined such that the deflection at projected RS leads to alpha = 2./3 * Rs * sigma0 - :param Rs: Hernquist radius in units of angle - :param center_x: x-center of the profile (units of angle) - :param center_y: y-center of the profile (units of angle) - :return: derivative of function (deflection angles in x- and y-direction) - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - r = np.maximum(r, self._s) - X = r/Rs - if isinstance(r, int) or isinstance(r, float): - #f = (1 - self._F(X)) / (X ** 2 - 1) # this expression is 1/3 for X=1 - if X == 1: - f = 1./3 - else: - f = (1 - self._F(X)) / (X ** 2 - 1) - else: - f = np.empty_like(X) - f[X == 1] = 1./3 - X_ = X[X != 1] - f[X != 1] = (1 - self._F(X_)) / (X_ ** 2 - 1) - alpha_r = 2 * sigma0 * Rs * f * X - f_x = alpha_r * x_/r - f_y = alpha_r * y_/r - return f_x, f_y
- -
[docs] def hessian(self, x, y, sigma0, Rs, center_x=0, center_y=0): - """ - Hessian terms of the function - - :param x: x-coordinate position (units of angle) - :param y: y-coordinate position (units of angle) - :param sigma0: normalization parameter defined such that the deflection at projected RS leads to alpha = 2./3 * Rs * sigma0 - :param Rs: Hernquist radius in units of angle - :param center_x: x-center of the profile (units of angle) - :param center_y: y-center of the profile (units of angle) - :return: df/dxdx, df/dxdy, df/dydx, df/dydy - """ - alpha_ra, alpha_dec = self.derivatives(x, y, sigma0, Rs, center_x, center_y) - diff = self._diff - alpha_ra_dx, alpha_dec_dx = self.derivatives(x + diff, y, sigma0, Rs, center_x, center_y) - alpha_ra_dy, alpha_dec_dy = self.derivatives(x, y + diff, sigma0, Rs, center_x, center_y) - - f_xx = (alpha_ra_dx - alpha_ra) / diff - f_xy = (alpha_ra_dy - alpha_ra) / diff - f_yx = (alpha_dec_dx - alpha_dec) / diff - f_yy = (alpha_dec_dy - alpha_dec) / diff - - return f_xx, f_xy, f_yx, f_yy
- -
[docs] def rho2sigma(self, rho0, Rs): - """ - converts 3d density into 2d projected density parameter - :param rho0: 3d density normalization of Hernquist model - :param Rs: Hernquist radius - :return: sigma0 defined quantity in projected units - """ - return rho0 * Rs
- -
[docs] def sigma2rho(self, sigma0, Rs): - """ - converts projected density parameter (in units of deflection) into 3d density parameter - :param sigma0: density defined quantity in projected units - :param Rs: Hernquist radius - :return: rho0 the 3d density normalization of Hernquist model - """ - return sigma0 / Rs
- - def _F(self, X): - """ - function 48 in https://arxiv.org/pdf/astro-ph/0102341.pdf - :param X: r/rs - :return: F(X) - """ - c = self._s - if isinstance(X, int) or isinstance(X, float): - X = max(X, c) - if X < 1 and X > 0: - a = 1. / np.sqrt(1 - X ** 2) * np.arctanh(np.sqrt(1 - X**2)) - elif X == 1: - a = 1. - elif X > 1: - a = 1. / np.sqrt(X ** 2 - 1) * np.arctan(np.sqrt(X**2 - 1)) - else: # X == 0: - a = 1. / np.sqrt(1 - c ** 2) * np.arctanh(np.sqrt((1 - c ** 2))) - - else: - a = np.empty_like(X) - X[X < c] = c - x = X[X < 1] - a[X < 1] = 1 / np.sqrt(1 - x ** 2) * np.arctanh(np.sqrt((1 - x**2))) - - x = X[X == 1] - a[X == 1] = 1. - - x = X[X > 1] - a[X > 1] = 1 / np.sqrt(x ** 2 - 1) * np.arctan(np.sqrt(x**2 - 1)) - # a[X>y] = 0 - return a - -
[docs] def grav_pot(self, x, y, rho0, Rs, center_x=0, center_y=0): - """ - #TODO decide whether these functions are needed or not - - gravitational potential (modulo 4 pi G and rho0 in appropriate units) - :param x: x-coordinate position (units of angle) - :param y: y-coordinate position (units of angle) - :param rho0: density normalization parameter of Hernquist profile - :param Rs: Hernquist radius in units of angle - :param center_x: x-center of the profile (units of angle) - :param center_y: y-center of the profile (units of angle) - :return: gravitational potential at projected radius - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - M = self.mass_tot(rho0, Rs) - pot = M / (r + Rs) - return pot
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/hernquist_ellipse.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/hernquist_ellipse.html deleted file mode 100644 index bc12190d8..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/hernquist_ellipse.html +++ /dev/null @@ -1,225 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.hernquist_ellipse — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.hernquist_ellipse

-from lenstronomy.LensModel.Profiles.hernquist import Hernquist
-import lenstronomy.Util.param_util as param_util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-import numpy as np
-
-__all__ = ['Hernquist_Ellipse']
-
-
-
[docs]class Hernquist_Ellipse(LensProfileBase): - """ - this class contains functions for the elliptical Hernquist profile. Ellipticity is defined in the potential. - - - """ - param_names = ['sigma0', 'Rs', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'sigma0': 0, 'Rs': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'sigma0': 100, 'Rs': 100, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.spherical = Hernquist() - self._diff = 0.00000001 - super(Hernquist_Ellipse, self).__init__() - -
[docs] def function(self, x, y, sigma0, Rs, e1, e2, center_x=0, center_y=0): - """ - returns double integral of NFW profile - """ - x_, y_ = param_util.transform_e1e2_square_average(x, y, e1, e2, center_x, center_y) - f_ = self.spherical.function(x_, y_, sigma0, Rs) - return f_
- -
[docs] def derivatives(self, x, y, sigma0, Rs, e1, e2, center_x=0, center_y=0): - """ - returns df/dx and df/dy of the function (integral of NFW) - """ - x_, y_ = param_util.transform_e1e2_square_average(x, y, e1, e2, center_x, center_y) - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - cos_phi = np.cos(phi_G) - sin_phi = np.sin(phi_G) - e = param_util.q2e(q) - - f_x_prim, f_y_prim = self.spherical.derivatives(x_, y_, sigma0, Rs) - f_x_prim *= np.sqrt(1 - e) - f_y_prim *= np.sqrt(1 + e) - f_x = cos_phi*f_x_prim-sin_phi*f_y_prim - f_y = sin_phi*f_x_prim+cos_phi*f_y_prim - return f_x, f_y
- -
[docs] def hessian(self, x, y, sigma0, Rs, e1, e2, center_x=0, center_y=0): - """ - returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - alpha_ra, alpha_dec = self.derivatives(x, y, sigma0, Rs, e1, e2, center_x, center_y) - diff = self._diff - alpha_ra_dx, alpha_dec_dx = self.derivatives(x + diff, y, sigma0, Rs, e1, e2, center_x, center_y) - alpha_ra_dy, alpha_dec_dy = self.derivatives(x, y + diff, sigma0, Rs, e1, e2, center_x, center_y) - - f_xx = (alpha_ra_dx - alpha_ra)/diff - f_xy = (alpha_ra_dy - alpha_ra)/diff - f_yx = (alpha_dec_dx - alpha_dec)/diff - f_yy = (alpha_dec_dy - alpha_dec)/diff - return f_xx, f_xy, f_yx, f_yy
- -
[docs] def density(self, r, rho0, Rs, e1=0, e2=0): - """ - computes the 3-d density - - :param r: 3-d radius - :param rho0: density normalization - :param Rs: Hernquist radius - :return: density at radius r - """ - return self.spherical.density(r, rho0, Rs)
- -
[docs] def density_lens(self, r, sigma0, Rs, e1=0, e2=0): - """ - Density as a function of 3d radius in lensing parameters - This function converts the lensing definition sigma0 into the 3d density - - :param r: 3d radius - :param sigma0: rho0 * Rs (units of projected density) - :param Rs: Hernquist radius - :return: enclosed mass in 3d - """ - return self.spherical.density_lens(r, sigma0, Rs)
- -
[docs] def density_2d(self, x, y, rho0, Rs, e1=0, e2=0, center_x=0, center_y=0): - """ - projected density along the line of sight at coordinate (x, y) - - :param x: x-coordinate - :param y: y-coordinate - :param rho0: density normalization - :param Rs: Hernquist radius - :param center_x: x-center of the profile - :param center_y: y-center of the profile - :return: projected density - """ - return self.spherical.density_2d(x, y, rho0, Rs, center_x, center_y)
- -
[docs] def mass_2d_lens(self, r, sigma0, Rs, e1=0, e2=0): - """ - mass enclosed projected 2d sphere of radius r - Same as mass_2d but with input normalization in units of projected density - :param r: projected radius - :param sigma0: rho0 * Rs (units of projected density) - :param Rs: Hernquist radius - :return: mass enclosed 2d projected radius - """ - return self.spherical.mass_2d_lens(r, sigma0, Rs)
- -
[docs] def mass_2d(self, r, rho0, Rs, e1=0, e2=0): - """ - mass enclosed projected 2d sphere of radius r - - :param r: projected radius - :param rho0: density normalization - :param Rs: Hernquist radius - :return: mass enclosed 2d projected radius - """ - return self.spherical.mass_2d(r, rho0, Rs)
- -
[docs] def mass_3d(self, r, rho0, Rs, e1=0, e2=0): - """ - mass enclosed a 3d sphere or radius r - - :param r: 3-d radius within the mass is integrated (same distance units as density definition) - :param rho0: density normalization - :param Rs: Hernquist radius - :return: enclosed mass - """ - return self.spherical.mass_3d(r, rho0, Rs)
- -
[docs] def mass_3d_lens(self, r, sigma0, Rs, e1=0, e2=0): - """ - mass enclosed a 3d sphere or radius r in lensing parameterization - - :param r: 3-d radius within the mass is integrated (same distance units as density definition) - :param sigma0: rho0 * Rs (units of projected density) - :param Rs: Hernquist radius - :return: enclosed mass - """ - return self.spherical.mass_3d_lens(r, sigma0, Rs)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/hessian.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/hessian.html deleted file mode 100644 index 4adf023dc..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/hessian.html +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.hessian — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.hessian

-__author__ = 'sibirrer'
-
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['Hessian']
-
-
-
[docs]class Hessian(LensProfileBase): - """ - class for constant Hessian distortion (second order) - The input is in the same convention as the LensModel.hessian() output. - """ - param_names = ['f_xx', 'f_yy', 'f_xy', 'f_yx', 'ra_0', 'dec_0'] - lower_limit_default = {'f_xx': -100, 'f_yy': -100, 'f_xy': -100, 'f_yx': -100, 'ra_0': -100, 'dec_0': -100} - upper_limit_default = {'f_xx': 100, 'f_yy': 100, 'f_xy': 100, 'f_yx': 100, 'ra_0': 100, 'dec_0': 100} - -
[docs] def function(self, x, y, f_xx, f_yy, f_xy, f_yx, ra_0=0, dec_0=0): - """ - - :param x: x-coordinate (angle) - :param y: y0-coordinate (angle) - :param f_xx: dalpha_x/dx - :param f_yy: dalpha_y/dy - :param f_xy: dalpha_x/dy - :param f_yx: dalpha_y/dx - :param ra_0: x/ra position where shear deflection is 0 - :param dec_0: y/dec position where shear deflection is 0 - :return: lensing potential - """ - x_ = x - ra_0 - y_ = y - dec_0 - f_ = 1/2. * (f_xx * x_ * x_ + (f_xy + f_yx) * x_ * y_ + f_yy * y_ * y_) - return f_
- -
[docs] def derivatives(self, x, y, f_xx, f_yy, f_xy, f_yx, ra_0=0, dec_0=0): - """ - - :param x: x-coordinate (angle) - :param y: y0-coordinate (angle) - :param f_xx: dalpha_x/dx - :param f_yy: dalpha_y/dy - :param f_xy: dalpha_x/dy - :param f_yx: dalpha_y/dx - :param ra_0: x/ra position where shear deflection is 0 - :param dec_0: y/dec position where shear deflection is 0 - :return: deflection angles - """ - x_ = x - ra_0 - y_ = y - dec_0 - f_x = f_xx * x_ + f_xy * y_ - f_y = f_yx * x_ + f_yy * y_ - return f_x, f_y
- -
[docs] def hessian(self, x, y, f_xx, f_yy, f_xy, f_yx, ra_0=0, dec_0=0): - """ - Hessian. Attention: If f_xy != f_yx then this function is not accurate! - - :param x: x-coordinate (angle) - :param y: y0-coordinate (angle) - :param f_xx: dalpha_x/dx - :param f_yy: dalpha_y/dy - :param f_xy: dalpha_x/dy - :param f_yx: dalpha_y/dx - :param ra_0: x/ra position where shear deflection is 0 - :param dec_0: y/dec position where shear deflection is 0 - :return: f_xx, f_yy, f_xy - """ - return f_xx, f_xy, f_yx, f_yy
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/interpol.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/interpol.html deleted file mode 100644 index 88eb6bb82..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/interpol.html +++ /dev/null @@ -1,378 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.interpol — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.interpol

-__author__ = 'sibirrer'
-
-import scipy.interpolate
-import numpy as np
-
-import lenstronomy.Util.util as util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['Interpol', 'InterpolScaled']
-
-
-
[docs]class Interpol(LensProfileBase): - """ - class which uses an interpolation of a lens model and its first and second order derivatives - - See also the tests in lenstronomy.test.test_LensModel.test_Profiles.test_interpol.py for example use cases - as checks against known analytic models. - - The deflection angle is in the same convention as the one in the LensModel module, meaning that: - source position = image position - deflection angle - """ - param_names = ['grid_interp_x', 'grid_interp_y', 'f_', 'f_x', 'f_y', 'f_xx', 'f_yy', 'f_xy'] - lower_limit_default = {} - upper_limit_default = {} - - def __init__(self, grid=False, min_grid_number=100, kwargs_spline=None): - """ - - :param grid: bool, if True, computes the calculation on a grid - :param min_grid_number: minimum numbers of positions to compute the interpolation on a grid, otherwise in a loop - :param kwargs_spline: keyword arguments for the scipy.interpolate.RectBivariateSpline() interpolation (optional) - if =None, a default linear interpolation is chosen. - """ - self._grid = grid - self._min_grid_number = min_grid_number - if kwargs_spline is None: - kwargs_spline = {'kx': 1, 'ky': 1, 's': 0} - self._kwargs_spline = kwargs_spline - super(Interpol, self).__init__() - -
[docs] def function(self, x, y, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None, f_xx=None, f_yy=None, - f_xy=None): - """ - - :param x: x-coordinate (angular position), float or numpy array - :param y: y-coordinate (angular position), float or numpy array - :param grid_interp_x: numpy array (ascending) to mark the x-direction of the interpolation grid - :param grid_interp_y: numpy array (ascending) to mark the y-direction of the interpolation grid - :param f_: 2d numpy array of lensing potential, matching the grids in grid_interp_x and grid_interp_y - :param f_x: 2d numpy array of deflection in x-direction, matching the grids in grid_interp_x and grid_interp_y - :param f_y: 2d numpy array of deflection in y-direction, matching the grids in grid_interp_x and grid_interp_y - :param f_xx: 2d numpy array of df/dxx, matching the grids in grid_interp_x and grid_interp_y - :param f_yy: 2d numpy array of df/dyy, matching the grids in grid_interp_x and grid_interp_y - :param f_xy: 2d numpy array of df/dxy, matching the grids in grid_interp_x and grid_interp_y - :return: potential at interpolated positions (x, y) - """ - #self._check_interp(grid_interp_x, grid_interp_y, f_, f_x, f_y, f_xx, f_yy, f_xy) - n = len(np.atleast_1d(x)) - if n <= 1 and np.shape(x) == (): - #if type(x) == float or type(x) == int or type(x) == type(np.float64(1)) or len(x) <= 1: - f_out = self.f_interp(x, y, grid_interp_x, grid_interp_y, f_) - return f_out - else: - if self._grid and n >= self._min_grid_number: - x_axes, y_axes = util.get_axes(x, y) - f_out = self.f_interp(x_axes, y_axes, grid_interp_x, grid_interp_y, f_, grid=self._grid) - f_out = util.image2array(f_out) - else: - #n = len(x) - f_out = np.zeros(n) - for i in range(n): - f_out[i] = self.f_interp(x[i], y[i], grid_interp_x, grid_interp_y, f_) - return f_out
- -
[docs] def derivatives(self, x, y, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None, f_xx=None, f_yy=None, f_xy=None): - """ - returns df/dx and df/dy of the function - - :param x: x-coordinate (angular position), float or numpy array - :param y: y-coordinate (angular position), float or numpy array - :param grid_interp_x: numpy array (ascending) to mark the x-direction of the interpolation grid - :param grid_interp_y: numpy array (ascending) to mark the y-direction of the interpolation grid - :param f_: 2d numpy array of lensing potential, matching the grids in grid_interp_x and grid_interp_y - :param f_x: 2d numpy array of deflection in x-direction, matching the grids in grid_interp_x and grid_interp_y - :param f_y: 2d numpy array of deflection in y-direction, matching the grids in grid_interp_x and grid_interp_y - :param f_xx: 2d numpy array of df/dxx, matching the grids in grid_interp_x and grid_interp_y - :param f_yy: 2d numpy array of df/dyy, matching the grids in grid_interp_x and grid_interp_y - :param f_xy: 2d numpy array of df/dxy, matching the grids in grid_interp_x and grid_interp_y - :return: f_x, f_y at interpolated positions (x, y) - """ - n = len(np.atleast_1d(x)) - if n <= 1 and np.shape(x) == (): - #if type(x) == float or type(x) == int or type(x) == type(np.float64(1)) or len(x) <= 1: - f_x_out = self.f_x_interp(x, y, grid_interp_x, grid_interp_y, f_x) - f_y_out = self.f_y_interp(x, y, grid_interp_x, grid_interp_y, f_y) - return f_x_out, f_y_out - else: - if self._grid and n >= self._min_grid_number: - x_, y_ = util.get_axes(x, y) - f_x_out = self.f_x_interp(x_, y_, grid_interp_x, grid_interp_y, f_x, grid=self._grid) - f_y_out = self.f_y_interp(x_, y_, grid_interp_x, grid_interp_y, f_y, grid=self._grid) - f_x_out = util.image2array(f_x_out) - f_y_out = util.image2array(f_y_out) - else: - #n = len(x) - f_x_out = self.f_x_interp(x, y, grid_interp_x, grid_interp_y, f_x) - f_y_out = self.f_y_interp(x, y, grid_interp_x, grid_interp_y, f_y) - return f_x_out, f_y_out
- -
[docs] def hessian(self, x, y, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None, f_xx=None, f_yy=None, f_xy=None): - """ - returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - - :param x: x-coordinate (angular position), float or numpy array - :param y: y-coordinate (angular position), float or numpy array - :param grid_interp_x: numpy array (ascending) to mark the x-direction of the interpolation grid - :param grid_interp_y: numpy array (ascending) to mark the y-direction of the interpolation grid - :param f_: 2d numpy array of lensing potential, matching the grids in grid_interp_x and grid_interp_y - :param f_x: 2d numpy array of deflection in x-direction, matching the grids in grid_interp_x and grid_interp_y - :param f_y: 2d numpy array of deflection in y-direction, matching the grids in grid_interp_x and grid_interp_y - :param f_xx: 2d numpy array of df/dxx, matching the grids in grid_interp_x and grid_interp_y - :param f_yy: 2d numpy array of df/dyy, matching the grids in grid_interp_x and grid_interp_y - :param f_xy: 2d numpy array of df/dxy, matching the grids in grid_interp_x and grid_interp_y - :return: f_xx, f_xy, f_yx, f_yy at interpolated positions (x, y) - """ - if not (hasattr(self, '_f_xx_interp')) and (f_xx is None or f_yy is None or f_xy is None): - diff = 0.000001 - alpha_ra_pp, alpha_dec_pp = self.derivatives(x + diff / 2, y + diff / 2, grid_interp_x=grid_interp_x, - grid_interp_y=grid_interp_y, f_=f_, f_x=f_x, f_y=f_y) - alpha_ra_pn, alpha_dec_pn = self.derivatives(x + diff / 2, y - diff / 2, grid_interp_x=grid_interp_x, - grid_interp_y=grid_interp_y, f_=f_, f_x=f_x, f_y=f_y) - - alpha_ra_np, alpha_dec_np = self.derivatives(x - diff / 2, y + diff / 2, grid_interp_x=grid_interp_x, - grid_interp_y=grid_interp_y, f_=f_, f_x=f_x, f_y=f_y) - alpha_ra_nn, alpha_dec_nn = self.derivatives(x - diff / 2, y - diff / 2, grid_interp_x=grid_interp_x, - grid_interp_y=grid_interp_y, f_=f_, f_x=f_x, f_y=f_y) - - f_xx_out = (alpha_ra_pp - alpha_ra_np + alpha_ra_pn - alpha_ra_nn) / diff / 2 - f_xy_out = (alpha_ra_pp - alpha_ra_pn + alpha_ra_np - alpha_ra_nn) / diff / 2 - f_yx_out = (alpha_dec_pp - alpha_dec_np + alpha_dec_pn - alpha_dec_nn) / diff / 2 - f_yy_out = (alpha_dec_pp - alpha_dec_pn + alpha_dec_np - alpha_dec_nn) / diff / 2 - return f_xx_out, f_xy_out, f_yx_out, f_yy_out - - n = len(np.atleast_1d(x)) - if n <= 1 and np.shape(x) == (): - #if type(x) == float or type(x) == int or type(x) == type(np.float64(1)) or len(x) <= 1: - f_xx_out = self.f_xx_interp(x, y, grid_interp_x, grid_interp_y, f_xx) - f_yy_out = self.f_yy_interp(x, y, grid_interp_x, grid_interp_y, f_yy) - f_xy_out = self.f_xy_interp(x, y, grid_interp_x, grid_interp_y, f_xy) - return f_xx_out, f_xy_out, f_xy_out, f_yy_out - else: - if self._grid and n >= self._min_grid_number: - x_, y_ = util.get_axes(x, y) - f_xx_out = self.f_xx_interp(x_, y_, grid_interp_x, grid_interp_y, f_xx, grid=self._grid) - f_yy_out = self.f_yy_interp(x_, y_, grid_interp_x, grid_interp_y, f_yy, grid=self._grid) - f_xy_out = self.f_xy_interp(x_, y_, grid_interp_x, grid_interp_y, f_xy, grid=self._grid) - f_xx_out = util.image2array(f_xx_out) - f_yy_out = util.image2array(f_yy_out) - f_xy_out = util.image2array(f_xy_out) - else: - #n = len(x) - f_xx_out, f_yy_out, f_xy_out = np.zeros(n), np.zeros(n), np.zeros(n) - for i in range(n): - f_xx_out[i] = self.f_xx_interp(x[i], y[i], grid_interp_x, grid_interp_y, f_xx) - f_yy_out[i] = self.f_yy_interp(x[i], y[i], grid_interp_x, grid_interp_y, f_yy) - f_xy_out[i] = self.f_xy_interp(x[i], y[i], grid_interp_x, grid_interp_y, f_xy) - return f_xx_out, f_xy_out, f_xy_out, f_yy_out
- -
[docs] def f_interp(self, x, y, x_grid=None, y_grid=None, f_=None, grid=False): - if not hasattr(self, '_f_interp'): - self._f_interp = scipy.interpolate.RectBivariateSpline(y_grid, x_grid, f_, **self._kwargs_spline) - return self._f_interp(y, x, grid=grid)
- -
[docs] def f_x_interp(self, x, y, x_grid=None, y_grid=None, f_x=None, grid=False): - if not hasattr(self, '_f_x_interp'): - self._f_x_interp = scipy.interpolate.RectBivariateSpline(y_grid, x_grid, f_x, **self._kwargs_spline) - return self._f_x_interp(y, x, grid=grid)
- -
[docs] def f_y_interp(self, x, y, x_grid=None, y_grid=None, f_y=None, grid=False): - if not hasattr(self, '_f_y_interp'): - self._f_y_interp = scipy.interpolate.RectBivariateSpline(y_grid, x_grid, f_y, **self._kwargs_spline) - return self._f_y_interp(y, x, grid=grid)
- -
[docs] def f_xx_interp(self, x, y, x_grid=None, y_grid=None, f_xx=None, grid=False): - if not hasattr(self, '_f_xx_interp'): - self._f_xx_interp = scipy.interpolate.RectBivariateSpline(y_grid, x_grid, f_xx, **self._kwargs_spline) - return self._f_xx_interp(y, x, grid=grid)
- -
[docs] def f_xy_interp(self, x, y, x_grid=None, y_grid=None, f_xy=None, grid=False): - if not hasattr(self, '_f_xy_interp'): - self._f_xy_interp = scipy.interpolate.RectBivariateSpline(y_grid, x_grid, f_xy, **self._kwargs_spline) - return self._f_xy_interp(y, x, grid=grid)
- -
[docs] def f_yy_interp(self, x, y, x_grid=None, y_grid=None, f_yy=None, grid=False): - if not hasattr(self, '_f_yy_interp'): - self._f_yy_interp = scipy.interpolate.RectBivariateSpline(y_grid, x_grid, f_yy, **self._kwargs_spline) - return self._f_yy_interp(y, x, grid=grid)
- -
[docs] def do_interp(self, x_grid, y_grid, f_, f_x, f_y, f_xx=None, f_yy=None, f_xy=None): - self._f_interp = scipy.interpolate.RectBivariateSpline(x_grid, y_grid, f_, **self._kwargs_spline) - self._f_x_interp = scipy.interpolate.RectBivariateSpline(x_grid, y_grid, f_x, **self._kwargs_spline) - self._f_y_interp = scipy.interpolate.RectBivariateSpline(x_grid, y_grid, f_y, **self._kwargs_spline) - if f_xx is not None: - self._f_xx_interp = scipy.interpolate.RectBivariateSpline(x_grid, y_grid, f_xx, **self._kwargs_spline) - if f_xy is not None: - self._f_xy_interp = scipy.interpolate.RectBivariateSpline(x_grid, y_grid, f_xy, **self._kwargs_spline) - if f_yy is not None: - self._f_yy_interp = scipy.interpolate.RectBivariateSpline(x_grid, y_grid, f_yy, **self._kwargs_spline)
- - -
[docs]class InterpolScaled(LensProfileBase): - """ - class for handling an interpolated lensing map and has the freedom to scale its lensing effect. - Applications are e.g. mass to light ratio. - """ - param_names = ['scale_factor', 'grid_interp_x', 'grid_interp_y', 'f_', 'f_x', 'f_y', 'f_xx', 'f_yy', 'f_xy'] - lower_limit_default = {'scale_factor': 0} - upper_limit_default = {'scale_factor': 100} - - def __init__(self, grid=True, min_grid_number=100, kwargs_spline=None): - """ - - :param grid: bool, if True, computes the calculation on a grid - :param min_grid_number: minimum numbers of positions to compute the interpolation on a grid - :param kwargs_spline: keyword arguments for the scipy.interpolate.RectBivariateSpline() interpolation (optional) - if =None, a default linear interpolation is chosen. - """ - self.interp_func = Interpol(grid, min_grid_number=min_grid_number, kwargs_spline=kwargs_spline) - super(InterpolScaled, self).__init__() - -
[docs] def function(self, x, y, scale_factor=1, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None, - f_xx=None, f_yy=None, f_xy=None): - """ - - :param x: x-coordinate (angular position), float or numpy array - :param y: y-coordinate (angular position), float or numpy array - :param scale_factor: float, overall scaling of the lens model relative to the input interpolation grid - :param grid_interp_x: numpy array (ascending) to mark the x-direction of the interpolation grid - :param grid_interp_y: numpy array (ascending) to mark the y-direction of the interpolation grid - :param f_: 2d numpy array of lensing potential, matching the grids in grid_interp_x and grid_interp_y - :param f_x: 2d numpy array of deflection in x-direction, matching the grids in grid_interp_x and grid_interp_y - :param f_y: 2d numpy array of deflection in y-direction, matching the grids in grid_interp_x and grid_interp_y - :param f_xx: 2d numpy array of df/dxx, matching the grids in grid_interp_x and grid_interp_y - :param f_yy: 2d numpy array of df/dyy, matching the grids in grid_interp_x and grid_interp_y - :param f_xy: 2d numpy array of df/dxy, matching the grids in grid_interp_x and grid_interp_y - :return: potential at interpolated positions (x, y) - """ - f_out = self.interp_func.function(x, y, grid_interp_x, grid_interp_y, f_, f_x, f_y, f_xx, f_yy, f_xy) - f_out *= scale_factor - return f_out
- -
[docs] def derivatives(self, x, y, scale_factor=1, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None, - f_xx=None, f_yy=None, f_xy=None): - """ - - :param x: x-coordinate (angular position), float or numpy array - :param y: y-coordinate (angular position), float or numpy array - :param scale_factor: float, overall scaling of the lens model relative to the input interpolation grid - :param grid_interp_x: numpy array (ascending) to mark the x-direction of the interpolation grid - :param grid_interp_y: numpy array (ascending) to mark the y-direction of the interpolation grid - :param f_: 2d numpy array of lensing potential, matching the grids in grid_interp_x and grid_interp_y - :param f_x: 2d numpy array of deflection in x-direction, matching the grids in grid_interp_x and grid_interp_y - :param f_y: 2d numpy array of deflection in y-direction, matching the grids in grid_interp_x and grid_interp_y - :param f_xx: 2d numpy array of df/dxx, matching the grids in grid_interp_x and grid_interp_y - :param f_yy: 2d numpy array of df/dyy, matching the grids in grid_interp_x and grid_interp_y - :param f_xy: 2d numpy array of df/dxy, matching the grids in grid_interp_x and grid_interp_y - :return: deflection angles in x- and y-direction at position (x, y) - """ - f_x_out, f_y_out = self.interp_func.derivatives(x, y, grid_interp_x, grid_interp_y, f_, f_x, f_y, f_xx, f_yy, f_xy) - f_x_out *= scale_factor - f_y_out *= scale_factor - return f_x_out, f_y_out
- -
[docs] def hessian(self, x, y, scale_factor=1, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None, - f_xx=None, f_yy=None, f_xy=None): - """ - - :param x: x-coordinate (angular position), float or numpy array - :param y: y-coordinate (angular position), float or numpy array - :param scale_factor: float, overall scaling of the lens model relative to the input interpolation grid - :param grid_interp_x: numpy array (ascending) to mark the x-direction of the interpolation grid - :param grid_interp_y: numpy array (ascending) to mark the y-direction of the interpolation grid - :param f_: 2d numpy array of lensing potential, matching the grids in grid_interp_x and grid_interp_y - :param f_x: 2d numpy array of deflection in x-direction, matching the grids in grid_interp_x and grid_interp_y - :param f_y: 2d numpy array of deflection in y-direction, matching the grids in grid_interp_x and grid_interp_y - :param f_xx: 2d numpy array of df/dxx, matching the grids in grid_interp_x and grid_interp_y - :param f_yy: 2d numpy array of df/dyy, matching the grids in grid_interp_x and grid_interp_y - :param f_xy: 2d numpy array of df/dxy, matching the grids in grid_interp_x and grid_interp_y - :return: second derivatives of the lensing potential f_xx, f_yy, f_xy at position (x, y) - """ - f_xx_out, f_xy_out, f_yx_out, f_yy_out = self.interp_func.hessian(x, y, grid_interp_x, grid_interp_y, f_, f_x, f_y, f_xx, f_yy, f_xy) - f_xx_out *= scale_factor - f_yy_out *= scale_factor - f_xy_out *= scale_factor - f_yx_out *= scale_factor - return f_xx_out, f_xy_out, f_yx_out, f_yy_out
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/multi_gaussian_kappa.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/multi_gaussian_kappa.html deleted file mode 100644 index 484868295..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/multi_gaussian_kappa.html +++ /dev/null @@ -1,307 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.multi_gaussian_kappa — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.multi_gaussian_kappa

-import numpy as np
-from lenstronomy.LensModel.Profiles.gaussian_kappa import GaussianKappa
-from lenstronomy.LensModel.Profiles.gaussian_ellipse_potential import GaussianEllipsePotential
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['MultiGaussianKappa', 'MultiGaussianKappaEllipse']
-
-
-
[docs]class MultiGaussianKappa(LensProfileBase): - """ - - """ - param_names = ['amp', 'sigma', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'sigma': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'sigma': 100, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.gaussian_kappa = GaussianKappa() - super(MultiGaussianKappa, self).__init__() - -
[docs] def function(self, x, y, amp, sigma, center_x=0, center_y=0, scale_factor=1): - """ - - :param x: - :param y: - :param amp: - :param sigma: - :param center_x: - :param center_y: - :return: - """ - f_ = np.zeros_like(x, dtype=float) - for i in range(len(amp)): - f_ += self.gaussian_kappa.function(x, y, amp=scale_factor*amp[i], sigma=sigma[i], - center_x=center_x, center_y=center_y) - return f_
- -
[docs] def derivatives(self, x, y, amp, sigma, center_x=0, center_y=0, scale_factor=1): - """ - - :param x: - :param y: - :param amp: - :param sigma: - :param center_x: - :param center_y: - :return: - """ - f_x, f_y = np.zeros_like(x, dtype=float), np.zeros_like(x, dtype=float) - for i in range(len(amp)): - f_x_i, f_y_i = self.gaussian_kappa.derivatives(x, y, amp=scale_factor*amp[i], sigma=sigma[i], - center_x=center_x, center_y=center_y) - f_x += f_x_i - f_y += f_y_i - return f_x, f_y
- -
[docs] def hessian(self, x, y, amp, sigma, center_x=0, center_y=0, scale_factor=1): - """ - - :param x: - :param y: - :param amp: - :param sigma: - :param center_x: - :param center_y: - :return: - """ - f_xx, f_yy, f_xy = np.zeros_like(x, dtype=float), np.zeros_like(x, dtype=float), np.zeros_like(x, dtype=float) - for i in range(len(amp)): - f_xx_i, f_xy_i, _, f_yy_i = self.gaussian_kappa.hessian(x, y, amp=scale_factor*amp[i], - sigma=sigma[i], center_x=center_x, - center_y=center_y) - f_xx += f_xx_i - f_yy += f_yy_i - f_xy += f_xy_i - return f_xx, f_xy, f_xy, f_yy
- -
[docs] def density(self, r, amp, sigma, scale_factor=1): - """ - - :param r: - :param amp: - :param sigma: - :return: - """ - d_ = np.zeros_like(r, dtype=float) - for i in range(len(amp)): - d_ += self.gaussian_kappa.density(r, scale_factor*amp[i], sigma[i]) - return d_
- -
[docs] def density_2d(self, x, y, amp, sigma, center_x=0, center_y=0, scale_factor=1): - """ - - :param R: - :param am: - :param sigma_x: - :param sigma_y: - :return: - """ - d_3d = np.zeros_like(x, dtype=float) - for i in range(len(amp)): - d_3d += self.gaussian_kappa.density_2d(x, y, scale_factor*amp[i], sigma[i], center_x, center_y) - return d_3d
- -
[docs] def mass_3d_lens(self, R, amp, sigma, scale_factor=1): - """ - - :param R: - :param amp: - :param sigma: - :return: - """ - mass_3d = np.zeros_like(R, dtype=float) - for i in range(len(amp)): - mass_3d += self.gaussian_kappa.mass_3d_lens(R, scale_factor*amp[i], sigma[i]) - return mass_3d
- - -
[docs]class MultiGaussianKappaEllipse(LensProfileBase): - """ - - """ - param_names = ['amp', 'sigma', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'sigma': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'sigma': 100, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.gaussian_kappa = GaussianEllipsePotential() - super(MultiGaussianKappaEllipse, self).__init__() - -
[docs] def function(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0, scale_factor=1): - """ - - :param x: - :param y: - :param amp: - :param sigma: - :param center_x: - :param center_y: - :return: - """ - f_ = np.zeros_like(x, dtype=float) - for i in range(len(amp)): - f_ += self.gaussian_kappa.function(x, y, amp=scale_factor*amp[i], sigma=sigma[i], e1=e1, e2=e2, - center_x=center_x, center_y=center_y) - return f_
- -
[docs] def derivatives(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0, scale_factor=1): - """ - - :param x: - :param y: - :param amp: - :param sigma: - :param center_x: - :param center_y: - :return: - """ - f_x, f_y = np.zeros_like(x, dtype=float), np.zeros_like(x, dtype=float) - for i in range(len(amp)): - f_x_i, f_y_i = self.gaussian_kappa.derivatives(x, y, amp=scale_factor*amp[i], sigma=sigma[i], e1=e1, e2=e2, - center_x=center_x, center_y=center_y) - f_x += f_x_i - f_y += f_y_i - return f_x, f_y
- -
[docs] def hessian(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0, scale_factor=1): - """ - - :param x: - :param y: - :param amp: - :param sigma: - :param center_x: - :param center_y: - :return: - """ - f_xx, f_yy, f_xy = np.zeros_like(x, dtype=float), np.zeros_like(x, dtype=float), np.zeros_like(x, dtype=float) - for i in range(len(amp)): - f_xx_i, f_xy_i, _, f_yy_i = self.gaussian_kappa.hessian(x, y, amp=scale_factor*amp[i], sigma=sigma[i], e1=e1, e2=e2, - center_x=center_x, center_y=center_y) - f_xx += f_xx_i - f_yy += f_yy_i - f_xy += f_xy_i - return f_xx, f_xy, f_xy, f_yy
- -
[docs] def density(self, r, amp, sigma, e1, e2, scale_factor=1): - """ - - :param r: - :param amp: - :param sigma: - :return: - """ - d_ = np.zeros_like(r, dtype=float) - for i in range(len(amp)): - d_ += self.gaussian_kappa.density(r, scale_factor*amp[i], sigma[i], e1, e2) - return d_
- -
[docs] def density_2d(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0, scale_factor=1): - """ - - :param R: - :param am: - :param sigma_x: - :param sigma_y: - :return: - """ - d_3d = np.zeros_like(x, dtype=float) - for i in range(len(amp)): - d_3d += self.gaussian_kappa.density_2d(x, y, scale_factor*amp[i], sigma[i], e1, e2, center_x, center_y) - return d_3d
- -
[docs] def mass_3d_lens(self, R, amp, sigma, e1, e2, scale_factor=1): - """ - - :param R: - :param amp: - :param sigma: - :return: - """ - mass_3d = np.zeros_like(R, dtype=float) - for i in range(len(amp)): - mass_3d += self.gaussian_kappa.mass_3d_lens(R, scale_factor*amp[i], sigma[i], e1, e2) - return mass_3d
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/multipole.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/multipole.html deleted file mode 100644 index 50588bc43..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/multipole.html +++ /dev/null @@ -1,155 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.multipole — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.multipole

-__author__ = 'lynevdv'
-
-import numpy as np
-
-import lenstronomy.Util.param_util as param_util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['Multipole']
-
-
-
[docs]class Multipole(LensProfileBase): - """ - This class contains a multipole contribution (for 1 component with m>=2) - This uses the same definitions as Xu et al.(2013) in Appendix B3 https://arxiv.org/pdf/1307.4220.pdf - m : int, multipole order, m>=2 - a_m : float, multipole strength - phi_m : float, multipole orientation in radian - """ - param_names = ['m', 'a_m', 'phi_m', 'center_x', 'center_y'] - lower_limit_default = {'m': 2,'a_m':0, 'phi_m':-np.pi, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'m': 100,'a_m':100, 'phi_m':np.pi, 'center_x': 100, 'center_y': 100} - -
[docs] def function(self, x, y, m, a_m, phi_m, center_x=0, center_y=0): - """ - Lensing potential of multipole contribution (for 1 component with m>=2) - This uses the same definitions as Xu et al.(2013) in Appendix B3 https://arxiv.org/pdf/1307.4220.pdf - - :param m: int, multipole order, m>=2 - :param a_m: float, multipole strength - :param phi_m: float, multipole orientation in radian - :param center_x: x-position - :param center_y: x-position - :return: lensing potential - """ - r, phi = param_util.cart2polar(x, y, center_x=center_x, center_y=center_y) - f_ = r*a_m /(1-m**2) * np.cos(m*(phi-phi_m)) - return f_
- -
[docs] def derivatives(self,x,y, m, a_m, phi_m, center_x=0, center_y=0): - """ - Deflection of a multipole contribution (for 1 component with m>=2) - This uses the same definitions as Xu et al.(2013) in Appendix B3 https://arxiv.org/pdf/1307.4220.pdf - - :param m: int, multipole order, m>=2 - :param a_m: float, multipole strength - :param phi_m: float, multipole orientation in radian - :param center_x: x-position - :param center_y: x-position - :return: deflection angles alpha_x, alpha_y - """ - r, phi = param_util.cart2polar(x, y, center_x=center_x, center_y=center_y) - f_x = np.cos(phi)*a_m/(1-m**2) * np.cos(m*(phi-phi_m)) + np.sin(phi)*m*a_m/(1-m**2)*np.sin(m*(phi-phi_m)) - f_y = np.sin(phi)*a_m/(1-m**2) * np.cos(m*(phi-phi_m)) - np.cos(phi)*m*a_m/(1-m**2)*np.sin(m*(phi-phi_m)) - return f_x, f_y
- -
[docs] def hessian(self, x, y, m, a_m, phi_m, center_x=0, center_y=0): - """ - Hessian of a multipole contribution (for 1 component with m>=2) - This uses the same definitions as Xu et al.(2013) in Appendix B3 https://arxiv.org/pdf/1307.4220.pdf - - :param m: int, multipole order, m>=2 - :param a_m: float, multipole strength - :param phi_m: float, multipole orientation in radian - :param center_x: x-position - :param center_y: x-position - :return: f_xx, f_xy, f_yx, f_yy - """ - r, phi = param_util.cart2polar(x, y, center_x=center_x, center_y=center_y) - r = np.maximum(r, 0.000001) - f_xx = 1./r * np.sin(phi)**2 * a_m *np.cos(m*(phi-phi_m)) - f_yy = 1./r * np.cos(phi)**2 * a_m *np.cos(m*(phi-phi_m)) - f_xy = -1./r * a_m * np.cos(phi) * np.sin(phi) * np.cos(m*(phi-phi_m)) - return f_xx, f_xy, f_xy, f_yy
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/nfw.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/nfw.html deleted file mode 100644 index 8a10afdcb..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/nfw.html +++ /dev/null @@ -1,529 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.nfw — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.nfw

-__author__ = 'sibirrer'
-
-# this file contains a class to compute the Navaro-Frenk-White profile
-import numpy as np
-import scipy.interpolate as interp
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['NFW']
-
-
-
[docs]class NFW(LensProfileBase): - """ - this class contains functions concerning the NFW profile - - relation are: R_200 = c * Rs - The definition of 'Rs' is in angular (arc second) units and the normalization is put in in regards to a deflection - angle at 'Rs' - 'alpha_Rs'. To convert a physical mass and concentration definition into those lensing quantities - for a specific redshift configuration and cosmological model, you can find routines in lenstronomy.Cosmo.lens_cosmo.py - - Examples for converting angular to physical mass units - ------------------------------------------------------ - >>> from lenstronomy.Cosmo.lens_cosmo import LensCosmo - >>> from astropy.cosmology import FlatLambdaCDM - >>> cosmo = FlatLambdaCDM(H0=70, Om0=0.3, Ob0=0.05) - >>> lens_cosmo = LensCosmo(z_lens=0.5, z_source=1.5, cosmo=cosmo) - - Here we compute the angular scale of Rs on the sky (in arc seconds) and the deflection angle at Rs (in arc seconds): - - >>> Rs_angle, alpha_Rs = lens_cosmo.nfw_physical2angle(M=10**13, c=6) - - And here we perform the inverse calculation given Rs_angle and alpha_Rs to return the physical halo properties. - - >>> rho0, Rs, c, r200, M200 = lens_cosmo.nfw_angle2physical(Rs_angle=Rs_angle, alpha_Rs=alpha_Rs) - - The lens model calculation uses angular units as arguments! So to execute a deflection angle calculation one uses - - >>> from lenstronomy.LensModel.Profiles.hernquist import NFW - >>> nfw = NFW() - >>> alpha_x, alpha_y = nfw.derivatives(x=1, y=1, Rs=Rs_angle, alpha_Rs=alpha_Rs, center_x=0, center_y=0) - - """ - profile_name = 'NFW' - param_names = ['Rs', 'alpha_Rs', 'center_x', 'center_y'] - lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'center_x': 100, 'center_y': 100} - - def __init__(self, interpol=False, num_interp_X=1000, max_interp_X=10): - """ - - :param interpol: bool, if True, interpolates the functions F(), g() and h() - :param num_interp_X: int (only considered if interpol=True), number of interpolation elements in units of r/r_s - :param max_interp_X: float (only considered if interpol=True), maximum r/r_s value to be interpolated - (returning zeros outside) - """ - self._interpol = interpol - self._max_interp_X = max_interp_X - self._num_interp_X = num_interp_X - super(NFW, self).__init__() - -
[docs] def function(self, x, y, Rs, alpha_Rs, center_x=0, center_y=0): - """ - - :param x: angular position (normally in units of arc seconds) - :param y: angular position (normally in units of arc seconds) - :param Rs: turn over point in the slope of the NFW profile in angular unit - :param alpha_Rs: deflection (angular units) at projected Rs - :param center_x: center of halo (in angular units) - :param center_y: center of halo (in angular units) - :return: lensing potential - """ - rho0_input = self.alpha2rho0(alpha_Rs=alpha_Rs, Rs=Rs) - if Rs < 0.0000001: - Rs = 0.0000001 - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_**2 + y_**2) - f_ = self.nfwPot(R, Rs, rho0_input) - return f_
- -
[docs] def derivatives(self, x, y, Rs, alpha_Rs, center_x=0, center_y=0): - """ - returns df/dx and df/dy of the function (integral of NFW), which are the deflection angles - - :param x: angular position (normally in units of arc seconds) - :param y: angular position (normally in units of arc seconds) - :param Rs: turn over point in the slope of the NFW profile in angular unit - :param alpha_Rs: deflection (angular units) at projected Rs - :param center_x: center of halo (in angular units) - :param center_y: center of halo (in angular units) - :return: deflection angle in x, deflection angle in y - """ - rho0_input = self.alpha2rho0(alpha_Rs=alpha_Rs, Rs=Rs) - if Rs < 0.0000001: - Rs = 0.0000001 - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_**2 + y_**2) - f_x, f_y = self.nfwAlpha(R, Rs, rho0_input, x_, y_) - return f_x, f_y
- -
[docs] def hessian(self, x, y, Rs, alpha_Rs, center_x=0, center_y=0): - """ - - :param x: angular position (normally in units of arc seconds) - :param y: angular position (normally in units of arc seconds) - :param Rs: turn over point in the slope of the NFW profile in angular unit - :param alpha_Rs: deflection (angular units) at projected Rs - :param center_x: center of halo (in angular units) - :param center_y: center of halo (in angular units) - :return: Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - rho0_input = self.alpha2rho0(alpha_Rs=alpha_Rs, Rs=Rs) - if Rs < 0.0000001: - Rs = 0.0000001 - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_**2 + y_**2) - kappa = self.density_2d(R, 0, Rs, rho0_input) - gamma1, gamma2 = self.nfwGamma(R, Rs, rho0_input, x_, y_) - f_xx = kappa + gamma1 - f_yy = kappa - gamma1 - f_xy = gamma2 - return f_xx, f_xy, f_xy, f_yy
- -
[docs] def density(self, R, Rs, rho0): - """ - three dimensional NFW profile - - :param R: radius of interest - :type R: float/numpy array - :param Rs: scale radius - :type Rs: float - :param rho0: density normalization (characteristic density) - :type rho0: float - :return: rho(R) density - """ - return rho0/(R/Rs*(1+R/Rs)**2)
- -
[docs] def density_lens(self, r, Rs, alpha_Rs): - """ - computes the density at 3d radius r given lens model parameterization. - The integral in the LOS projection of this quantity results in the convergence quantity. - - :param r: 3d radios - :param Rs: turn-over radius of NFW profile - :param alpha_Rs: deflection at Rs - :return: density rho(r) - """ - rho0 = self.alpha2rho0(alpha_Rs, Rs) - return self.density(r, Rs, rho0)
- -
[docs] def density_2d(self, x, y, Rs, rho0, center_x=0, center_y=0): - """ - projected two dimensional NFW profile (kappa*Sigma_crit) - - :param R: radius of interest - :type R: float/numpy array - :param Rs: scale radius - :type Rs: float - :param rho0: density normalization (characteristic density) - :type rho0: float - :param r200: radius of (sub)halo - :type r200: float>0 - :return: Epsilon(R) projected density at radius R - """ - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_**2 + y_**2) - x = R/Rs - Fx = self.F_(x) - return 2*rho0*Rs*Fx
- -
[docs] def mass_3d(self, r, Rs, rho0): - """ - mass enclosed a 3d sphere or radius r - - :param r: 3d radius - :param Rs: scale radius - :param rho0: density normalization (characteristic density) - :return: M(<r) - """ - Rs = float(Rs) - m_3d = 4. * np.pi * rho0 * Rs**3 * (np.log((Rs + r) / Rs) - r / (Rs + r)) - return m_3d
- -
[docs] def mass_3d_lens(self, r, Rs, alpha_Rs): - """ - mass enclosed a 3d sphere or radius r. - This function takes as input the lensing parameterization. - - :param r: 3d radius - :param Rs: scale radius - :param alpha_Rs: deflection (angular units) at projected Rs - :return: M(<r) - """ - rho0 = self.alpha2rho0(alpha_Rs, Rs) - m_3d = self.mass_3d(r, Rs, rho0) - return m_3d
- -
[docs] def mass_2d(self, R, Rs, rho0): - """ - mass enclosed a 2d cylinder or projected radius R - :param R: projected radius - :param Rs: scale radius - :param rho0: density normalization (characteristic density) - :return: mass in cylinder - """ - x = R/Rs - gx = self.g_(x) - m_2d = 4*rho0*Rs*R**2*gx/x**2 * np.pi - return m_2d
- -
[docs] def nfwPot(self, R, Rs, rho0): - """ - - lensing potential of NFW profile (Sigma_crit D_OL**2) - - :param R: radius of interest - :type R: float/numpy array - :param Rs: scale radius - :type Rs: float - :param rho0: density normalization (characteristic density) - :type rho0: float - :param r200: radius of (sub)halo - :type r200: float>0 - :return: Epsilon(R) projected density at radius R - """ - x = R/Rs - hx = self.h_(x) - return 2*rho0*Rs**3*hx
- -
[docs] def nfwAlpha(self, R, Rs, rho0, ax_x, ax_y): - """ - - deflection angel of NFW profile (times Sigma_crit D_OL) along the projection to coordinate 'axis' - - :param R: radius of interest - :type R: float/numpy array - :param Rs: scale radius - :type Rs: float - :param rho0: density normalization (characteristic density) - :type rho0: float - :param r200: radius of (sub)halo - :type r200: float>0 - :param axis: projection to either x- or y-axis - :type axis: same as R - :return: Epsilon(R) projected density at radius R - """ - R = np.maximum(R, 0.00000001) - x = R/Rs - gx = self.g_(x) - a = 4*rho0*Rs*R*gx/x**2/R - return a*ax_x, a*ax_y
- -
[docs] def nfwGamma(self, R, Rs, rho0, ax_x, ax_y): - """ - - shear gamma of NFW profile (times Sigma_crit) along the projection to coordinate 'axis' - - :param R: radius of interest - :type R: float/numpy array - :param Rs: scale radius - :type Rs: float - :param rho0: density normalization (characteristic density) - :type rho0: float - :param r200: radius of (sub)halo - :type r200: float>0 - :param axis: projection to either x- or y-axis - :type axis: same as R - :return: Epsilon(R) projected density at radius R - """ - c = 0.000001 - R = np.maximum(R, c) - x = R/Rs - gx = self.g_(x) - Fx = self.F_(x) - a = 2*rho0*Rs*(2*gx/x**2 - Fx)#/x #2*rho0*Rs*(2*gx/x**2 - Fx)*axis/x - return a*(ax_y**2-ax_x**2)/R**2, -a*2*(ax_x*ax_y)/R**2
- -
[docs] def F_(self, X): - """ - computes h() - - :param X: - :return: - """ - if self._interpol: - if not hasattr(self, '_F_interp'): - x = np.linspace(0, self._max_interp_X, self._num_interp_X) - F_x = self._F(x) - self._F_interp = interp.interp1d(x, F_x, kind='linear', axis=-1, copy=False, bounds_error=False, - fill_value=0, assume_sorted=True) - return self._F_interp(X) - else: - return self._F(X)
- - @staticmethod - def _F(X): - """ - analytic solution of the projection integral - - :param X: R/Rs - :type X: float >0 - """ - if isinstance(X, int) or isinstance(X, float): - if X < 1 and X > 0: - a = 1/(X**2-1)*(1-2/np.sqrt(1-X**2)*np.arctanh(np.sqrt((1-X)/(1+X)))) - elif X == 1: - a = 1./3 - elif X > 1: - a = 1/(X**2-1)*(1-2/np.sqrt(X**2-1)*np.arctan(np.sqrt((X-1)/(1+X)))) - else: # X == 0: - c = 0.0000001 - a = 1/(-1)*(1-2/np.sqrt(1)*np.arctanh(np.sqrt((1-c)/(1+c)))) - - else: - a = np.empty_like(X) - x = X[(X < 1) & (X > 0)] - a[(X < 1) & (X > 0)] = 1/(x**2-1)*(1-2/np.sqrt(1-x**2)*np.arctanh(np.sqrt((1-x)/(1+x)))) - - a[X == 1] = 1./3. - - x = X[X > 1] - a[X > 1] = 1/(x**2-1)*(1-2/np.sqrt(x**2-1)*np.arctan(np.sqrt((x-1)/(1+x)))) - # a[X>y] = 0 - - c = 0.0000001 - a[X == 0] = 1/(-1)*(1-2/np.sqrt(1)*np.arctanh(np.sqrt((1-c)/(1+c)))) - return a - -
[docs] def g_(self, X): - """ - computes h() - - :param X: R/Rs - :type X: float >0 - :return: - """ - if self._interpol: - if not hasattr(self, '_g_interp'): - x = np.linspace(0, self._max_interp_X, self._num_interp_X) - g_x = self._g(x) - self._g_interp = interp.interp1d(x, g_x, kind='linear', axis=-1, copy=False, bounds_error=False, - fill_value=0, assume_sorted=True) - return self._g_interp(X) - else: - return self._g(X)
- - @staticmethod - def _g(X): - """ - - analytic solution of integral for NFW profile to compute deflection angel and gamma - - :param X: R/Rs - :type X: float >0 - """ - c = 0.000001 - if isinstance(X, int) or isinstance(X, float): - if X < 1: - x = max(c, X) - a = np.log(x/2.) + 1/np.sqrt(1-x**2)*np.arccosh(1./x) - elif X == 1: - a = 1 + np.log(1./2.) - else: # X > 1: - a = np.log(X/2) + 1/np.sqrt(X**2-1)*np.arccos(1./X) - - else: - a = np.empty_like(X) - X[X <= c] = c - x = X[X < 1] - a[X < 1] = np.log(x/2.) + 1/np.sqrt(1-x**2)*np.arccosh(1./x) - a[X == 1] = 1 + np.log(1./2.) - x = X[X > 1] - a[X > 1] = np.log(x/2) + 1/np.sqrt(x**2-1)*np.arccos(1./x) - return a - -
[docs] def h_(self, X): - """ - computes h() - - :param X: R/Rs - :type X: float >0 - :return: h(X) - """ - if self._interpol: - if not hasattr(self, '_h_interp'): - x = np.linspace(0, self._max_interp_X, self._num_interp_X) - h_x = self._h(x) - self._h_interp = interp.interp1d(x, h_x, kind='linear', axis=-1, copy=False, bounds_error=False, - fill_value=0, assume_sorted=True) - return self._h_interp(X) - else: - return self._h(X)
- - @staticmethod - def _h(X): - """ - - analytic solution of integral for NFW profile to compute the potential - - :param X: R/Rs - :type X: float >0 - """ - c = 0.000001 - if isinstance(X, int) or isinstance(X, float): - if X < 1: - x = max(0.001, X) - a = np.log(x/2.)**2 - np.arccosh(1./x)**2 - else: # X >= 1: - a = np.log(X/2.)**2 + np.arccos(1./X)**2 - else: - a = np.empty_like(X) - X[X <= c] = 0.000001 - x = X[X < 1] - a[X < 1] = np.log(x/2.)**2 - np.arccosh(1./x)**2 - x = X[X >= 1] - a[X >= 1] = np.log(x/2.)**2 + np.arccos(1./x)**2 - return a - -
[docs] @staticmethod - def alpha2rho0(alpha_Rs, Rs): - - """ - convert angle at Rs into rho0 - - :param alpha_Rs: deflection angle at RS - :param Rs: scale radius - :return: density normalization (characteristic density) - """ - - rho0 = alpha_Rs / (4. * Rs ** 2 * (1. + np.log(1. / 2.))) - return rho0
- -
[docs] @staticmethod - def rho02alpha(rho0, Rs): - - """ - convert rho0 to angle at Rs - - :param rho0: density normalization (characteristic density) - :param Rs: scale radius - :return: deflection angle at RS - """ - - alpha_Rs = rho0 * (4 * Rs ** 2 * (1 + np.log(1. / 2.))) - return alpha_Rs
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/nfw_ellipse.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/nfw_ellipse.html deleted file mode 100644 index cb70c035a..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/nfw_ellipse.html +++ /dev/null @@ -1,223 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.nfw_ellipse — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.nfw_ellipse

-__author__ = 'sibirrer'
-
-import numpy as np
-from lenstronomy.LensModel.Profiles.nfw import NFW
-import lenstronomy.Util.param_util as param_util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['NFW_ELLIPSE']
-
-
-
[docs]class NFW_ELLIPSE(LensProfileBase): - """ - this class contains functions concerning the NFW profile with an ellipticity defined in the potential - parameterization of alpha_Rs and Rs is the same as for the spherical NFW profile - - from Glose & Kneib: https://cds.cern.ch/record/529584/files/0112138.pdf - - relation are: R_200 = c * Rs - """ - profile_name = 'NFW_ELLIPSE' - param_names = ['Rs', 'alpha_Rs', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self, interpol=False, num_interp_X=1000, max_interp_X=10): - """ - - :param interpol: bool, if True, interpolates the functions F(), g() and h() - :param num_interp_X: int (only considered if interpol=True), number of interpolation elements in units of r/r_s - :param max_interp_X: float (only considered if interpol=True), maximum r/r_s value to be interpolated - (returning zeros outside) - """ - self.nfw = NFW(interpol=interpol, num_interp_X=num_interp_X, max_interp_X=max_interp_X) - self._diff = 0.0000000001 - super(NFW_ELLIPSE, self).__init__() - -
[docs] def function(self, x, y, Rs, alpha_Rs, e1, e2, center_x=0, center_y=0): - """ - returns elliptically distorted NFW lensing potential - - :param x: angular position (normally in units of arc seconds) - :param y: angular position (normally in units of arc seconds) - :param Rs: turn over point in the slope of the NFW profile in angular unit - :param alpha_Rs: deflection (angular units) at projected Rs - :param e1: eccentricity component in x-direction - :param e2: eccentricity component in y-direction - :param center_x: center of halo (in angular units) - :param center_y: center of halo (in angular units) - :return: lensing potential - """ - x_, y_ = param_util.transform_e1e2_square_average(x, y, e1, e2, center_x, center_y) - R_ = np.sqrt(x_**2 + y_**2) - rho0_input = self.nfw.alpha2rho0(alpha_Rs=alpha_Rs, Rs=Rs) - if Rs < 0.0000001: - Rs = 0.0000001 - f_ = self.nfw.nfwPot(R_, Rs, rho0_input) - return f_
- -
[docs] def derivatives(self, x, y, Rs, alpha_Rs, e1, e2, center_x=0, center_y=0): - """ - returns df/dx and df/dy of the function, calculated as an elliptically distorted deflection angle of the - spherical NFW profile - - :param x: angular position (normally in units of arc seconds) - :param y: angular position (normally in units of arc seconds) - :param Rs: turn over point in the slope of the NFW profile in angular unit - :param alpha_Rs: deflection (angular units) at projected Rs - :param e1: eccentricity component in x-direction - :param e2: eccentricity component in y-direction - :param center_x: center of halo (in angular units) - :param center_y: center of halo (in angular units) - :return: deflection in x-direction, deflection in y-direction - """ - x_, y_ = param_util.transform_e1e2_square_average(x, y, e1, e2, center_x, center_y) - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - cos_phi = np.cos(phi_G) - sin_phi = np.sin(phi_G) - e = param_util.q2e(q) - # e = abs(1 - q) - R_ = np.sqrt(x_ ** 2 + y_ ** 2) - rho0_input = self.nfw.alpha2rho0(alpha_Rs=alpha_Rs, Rs=Rs) - if Rs < 0.0000001: - Rs = 0.0000001 - f_x_prim, f_y_prim = self.nfw.nfwAlpha(R_, Rs, rho0_input, x_, y_) - f_x_prim *= np.sqrt(1 - e) - f_y_prim *= np.sqrt(1 + e) - f_x = cos_phi*f_x_prim-sin_phi*f_y_prim - f_y = sin_phi*f_x_prim+cos_phi*f_y_prim - return f_x, f_y
- -
[docs] def hessian(self, x, y, Rs, alpha_Rs, e1, e2, center_x=0, center_y=0): - """ - returns Hessian matrix of function d^2f/dx^2, d^f/dy^2, d^2/dxdy - the calculation is performed as a numerical differential from the deflection field. Analytical relations are - possible - - :param x: angular position (normally in units of arc seconds) - :param y: angular position (normally in units of arc seconds) - :param Rs: turn over point in the slope of the NFW profile in angular unit - :param alpha_Rs: deflection (angular units) at projected Rs - :param e1: eccentricity component in x-direction - :param e2: eccentricity component in y-direction - :param center_x: center of halo (in angular units) - :param center_y: center of halo (in angular units) - :return: d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - alpha_ra, alpha_dec = self.derivatives(x, y, Rs, alpha_Rs, e1, e2, center_x, center_y) - diff = self._diff - alpha_ra_dx, alpha_dec_dx = self.derivatives(x + diff, y, Rs, alpha_Rs, e1, e2, center_x, center_y) - alpha_ra_dy, alpha_dec_dy = self.derivatives(x, y + diff, Rs, alpha_Rs, e1, e2, center_x, center_y) - - f_xx = (alpha_ra_dx - alpha_ra)/diff - f_xy = (alpha_ra_dy - alpha_ra)/diff - f_yx = (alpha_dec_dx - alpha_dec)/diff - f_yy = (alpha_dec_dy - alpha_dec)/diff - - return f_xx, f_xy, f_yx, f_yy
- -
[docs] def mass_3d_lens(self, R, Rs, alpha_Rs, e1=1, e2=0): - """ - - :param R: radius (in angular units) - :param Rs: - :param alpha_Rs: - :param e1: - :param e2: - :return: - """ - return self.nfw.mass_3d_lens(R, Rs, alpha_Rs)
- -
[docs] def density_lens(self, r, Rs, alpha_Rs, e1=1, e2=0): - """ - computes the density at 3d radius r given lens model parameterization. - The integral in the LOS projection of this quantity results in the convergence quantity. - - :param r: 3d radios - :param Rs: turn-over radius of NFW profile - :param alpha_Rs: deflection at Rs - :return: density rho(r) - """ - return self.nfw.density_lens(r, Rs, alpha_Rs)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/nfw_mass_concentration.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/nfw_mass_concentration.html deleted file mode 100644 index af1600bf5..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/nfw_mass_concentration.html +++ /dev/null @@ -1,188 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.nfw_mass_concentration — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.nfw_mass_concentration

-__author__ = 'sibirrer'
-
-# this file contains a class to compute the Navaro-Frank-White function in mass/kappa space
-from lenstronomy.LensModel.Profiles.nfw import NFW
-from lenstronomy.Cosmo.lens_cosmo import LensCosmo
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['NFWMC']
-
-
-
[docs]class NFWMC(LensProfileBase): - """ - this class contains functions parameterises the NFW profile with log10 M200 and the concentration rs/r200 - relation are: R_200 = c * Rs - - ATTENTION: the parameterization is cosmology and redshift dependent! - The cosmology to connect mass and deflection relations is fixed to default H0=70km/s Omega_m=0.3 flat LCDM. - It is recommended to keep a given cosmology definition in the lens modeling as the observable reduced deflection - angles are sensitive in this parameterization. If you do not want to impose a mass-concentration relation, it is - recommended to use the default NFW lensing profile parameterized in reduced deflection angles. - - """ - param_names = ['logM', 'concentration', 'center_x', 'center_y'] - lower_limit_default = {'logM': 0, 'concentration': 0.01, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'logM': 16, 'concentration': 1000, 'center_x': 100, 'center_y': 100} - - def __init__(self, z_lens, z_source, cosmo=None, static=False): - """ - - :param z_lens: redshift of lens - :param z_source: redshift of source - :param cosmo: astropy cosmology instance - :param static: boolean, if True, only operates with fixed parameter values - """ - self._nfw = NFW() - if cosmo is None: - from astropy.cosmology import FlatLambdaCDM - cosmo = FlatLambdaCDM(H0=70, Om0=0.3, Ob0=0.05) - self._lens_cosmo = LensCosmo(z_lens=z_lens, z_source=z_source, cosmo=cosmo) - self._static = static - super(NFWMC, self).__init__() - - def _m_c2deflections(self, logM, concentration): - """ - - :param logM: log10 mass in M200 stellar masses - :param concentration: halo concentration c = r_200 / r_s - :return: Rs (in arc seconds), alpha_Rs (in arc seconds) - """ - if self._static is True: - return self._Rs_static, self._alpha_Rs_static - M = 10 ** logM - Rs, alpha_Rs = self._lens_cosmo.nfw_physical2angle(M, concentration) - return Rs, alpha_Rs - -
[docs] def set_static(self, logM, concentration, center_x=0, center_y=0): - """ - - :param logM: - :param concentration: - :param center_x: - :param center_y: - :return: - """ - self._static = True - M = 10 ** logM - self._Rs_static, self._alpha_Rs_static = self._lens_cosmo.nfw_physical2angle(M, concentration)
- -
[docs] def set_dynamic(self): - """ - - :return: - """ - self._static = False - if hasattr(self, '_Rs_static'): - del self._Rs_static - if hasattr(self, '_alpha_Rs_static'): - del self._alpha_Rs_static
- -
[docs] def function(self, x, y, logM, concentration, center_x=0, center_y=0): - """ - - :param x: angular position - :param y: angular position - :param Rs: angular turn over point - :param alpha_Rs: deflection at Rs - :param center_x: center of halo - :param center_y: center of halo - :return: - """ - Rs, alpha_Rs = self._m_c2deflections(logM, concentration) - return self._nfw.function(x, y, alpha_Rs=alpha_Rs, Rs=Rs, center_x=center_x, center_y=center_y)
- -
[docs] def derivatives(self, x, y, logM, concentration, center_x=0, center_y=0): - """ - returns df/dx and df/dy of the function (integral of NFW) - """ - Rs, alpha_Rs = self._m_c2deflections(logM, concentration) - return self._nfw.derivatives(x, y, Rs, alpha_Rs, center_x, center_y)
- -
[docs] def hessian(self, x, y, logM, concentration, center_x=0, center_y=0): - """ - returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - Rs, alpha_Rs = self._m_c2deflections(logM, concentration) - return self._nfw.hessian(x, y, Rs, alpha_Rs, center_x, center_y)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/nfw_vir_trunc.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/nfw_vir_trunc.html deleted file mode 100644 index fad1fc4fd..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/nfw_vir_trunc.html +++ /dev/null @@ -1,176 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.nfw_vir_trunc — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.nfw_vir_trunc

-__author__ = 'sibirrer'
-
-# this file contains a class to compute the Navaro-Frank-White function in mass/kappa space
-# the potential therefore is its integral
-
-import numpy as np
-from lenstronomy.Util import  constants as const
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-from lenstronomy.Cosmo.lens_cosmo import LensCosmo
-
-__all__ = ['NFWVirTrunc']
-
-
-
[docs]class NFWVirTrunc(LensProfileBase): - """ - this class contains functions concerning the NFW profile that is sharply truncated at the virial radius - https://arxiv.org/pdf/astro-ph/0304034.pdf - - relation are: R_200 = c * Rs - """ - def __init__(self, z_lens, z_source, cosmo=None): - """ - - :param z_lens: redshift of lens - :param z_source: redshift of source - :param cosmo: astropy cosmology instance - """ - - if cosmo is None: - from astropy.cosmology import FlatLambdaCDM - cosmo = FlatLambdaCDM(H0=70, Om0=0.3, Ob0=0.05) - self._lens_cosmo = LensCosmo(z_lens=z_lens, z_source=z_source, cosmo=cosmo) - super(NFWVirTrunc, self).__init__() - -
[docs] def kappa(self, theta, logM, c): - """ - projected surface brightness - - :param theta: radial angle from the center of the profile - :param logM: log_10 halo mass in physical units of M_sun - :param c: concentration of the halo; r_200 = c * r_s - :return: convergence at theta - """ - M = 10. ** logM - theta_r200 = self._lens_cosmo.nfw_M_theta_r200(M) - #r_vir = theta_vir * self._lens_cosmo.D_d * const.arcsec # physical Mpc - #print(r_vir, 'r_vir') - x = c * theta / theta_r200 - f = self._f(c) - return M / self._lens_cosmo.sigma_crit_angle * c ** 2 * f / (2 * np.pi * theta_r200 ** 2) * self._G(x, c)
- - def _G(self, x, c): - """ - # G(x) https://arxiv.org/pdf/astro-ph/0209167.pdf equation 27 - - :param x: scaled projected radius with c * theta / theta_r200 - :param c: oncentration of the halo; r_200 = c * r_s - :return: G(x) - """ - s = 0.000001 - if isinstance(x, int) or isinstance(x, float): - if x < 1: - x = max(s, x) - a = - np.sqrt(c**2 - x**2) / (1 - x**2) / (1 + c) + 1 / (1 - x**2)**(3./2) * np.arccosh((x**2 + c) / (x * (1 + c))) - elif x == 1: - a = np.sqrt(c**2 - 1) / (3 * (1 + c)) * (1 + 1 / (c + 1.)) - elif x <= c: # X > 1: - a = - np.sqrt(c ** 2 - x ** 2) / (1 - x ** 2) / (1 + c) - 1 / (x ** 2 - 1) ** (3. / 2) * np.arccos( - (x ** 2 + c) / (x * (1 + c))) - else: - a = 0 - - else: - a = np.zeros_like(x) - x[x <= s] = s - x_ = x[x < 1] - a[x < 1] = - np.sqrt(c**2 - x_**2) / ((1 - x_**2) * (1 + c)) + 1 / (1 - x_**2)**(3./2) * np.arccosh((x_**2 + c) / (x_ * (1 + c))) - a[x == 1] = np.sqrt(c**2 - 1) / (3 * (1 + c)) * (1 + 1 / (c + 1.)) - x_ = x[(x > 1) & (x <= c)] - a[(x > 1) & (x <= c)] = - np.sqrt(c ** 2 - x_ ** 2) / (1 - x_ ** 2) / (1 + c) - 1 / (x_ ** 2 - 1) ** (3. / 2) * np.arccos( - (x_ ** 2 + c) / (x_ * (1 + c))) - #a[x > c] = 0 - return a - - def _f(self, c): - """ - - :param c: concentration - :return: dimensionless normalization of Halo mass - """ - return 1. / (np.log(1 + c) - c / (1 + c))
- -# https://arxiv.org/pdf/astro-ph/0304034.pdf equation 17 for shear - -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/nie.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/nie.html deleted file mode 100644 index ad31e3fc8..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/nie.html +++ /dev/null @@ -1,372 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.nie — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.nie

-__author__ = 'sibirrer'
-
-import numpy as np
-import lenstronomy.Util.util as util
-import lenstronomy.Util.param_util as param_util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['NIE', 'NIEMajorAxis']
-
-
-
[docs]class NIE(LensProfileBase): - """ - Non-singular isothermal ellipsoid (NIE) - - .. math:: - \\kappa = \\theta_E/2 \\left[s_{scale} + qx^2 + y^2/q]−1/2 - - """ - param_names = ['theta_E', 'e1', 'e2', 's_scale', 'center_x', 'center_y'] - lower_limit_default = {'theta_E': 0, 'e1': -0.5, 'e2': -0.5, 's_scale': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'theta_E': 10, 'e1': 0.5, 'e2': 0.5, 's_scale': 100, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.nie_major_axis = NIEMajorAxis() - super(NIE, self).__init__() - -
[docs] def function(self, x, y, theta_E, e1, e2, s_scale, center_x=0, center_y=0): - """ - - :param x: x-coordinate in image plane - :param y: y-coordinate in image plane - :param theta_E: Einstein radius - :param e1: eccentricity component - :param e2: eccentricity component - :param s_scale: smoothing scale - :param center_x: profile center - :param center_y: profile center - :return: lensing potential - """ - b, s, q, phi_G = self.param_conv(theta_E, e1, e2, s_scale) - # shift - x_ = x - center_x - y_ = y - center_y - # rotate - x__, y__ = util.rotate(x_, y_, phi_G) - # evaluate - f_ = self.nie_major_axis.function(x__, y__, b, s, q) - # rotate back - return f_
- -
[docs] def derivatives(self, x, y, theta_E, e1, e2, s_scale, center_x=0, center_y=0): - """ - - :param x: x-coordinate in image plane - :param y: y-coordinate in image plane - :param theta_E: Einstein radius - :param e1: eccentricity component - :param e2: eccentricity component - :param s_scale: smoothing scale - :param center_x: profile center - :param center_y: profile center - :return: alpha_x, alpha_y - """ - b, s, q, phi_G = self.param_conv(theta_E, e1, e2, s_scale) - # shift - x_ = x - center_x - y_ = y - center_y - # rotate - x__, y__ = util.rotate(x_, y_, phi_G) - # evaluate - f__x, f__y = self.nie_major_axis.derivatives(x__, y__, b, s, q) - # rotate back - f_x, f_y = util.rotate(f__x, f__y, -phi_G) - return f_x, f_y
- -
[docs] def hessian(self, x, y, theta_E, e1, e2, s_scale, center_x=0, center_y=0): - """ - - :param x: x-coordinate in image plane - :param y: y-coordinate in image plane - :param theta_E: Einstein radius - :param e1: eccentricity component - :param e2: eccentricity component - :param s_scale: smoothing scale - :param center_x: profile center - :param center_y: profile center - :return: f_xx, f_xy, f_yx, f_yy - """ - b, s, q, phi_G = self.param_conv(theta_E, e1, e2, s_scale) - # shift - x_ = x - center_x - y_ = y - center_y - # rotate - x__, y__ = util.rotate(x_, y_, phi_G) - # evaluate - f__xx, f__xy, _, f__yy = self.nie_major_axis.hessian(x__, y__, b, s, q) - # rotate back - kappa = 1./2 * (f__xx + f__yy) - gamma1__ = 1./2 * (f__xx - f__yy) - gamma2__ = f__xy - gamma1 = np.cos(2 * phi_G) * gamma1__ - np.sin(2 * phi_G) * gamma2__ - gamma2 = +np.sin(2 * phi_G) * gamma1__ + np.cos(2 * phi_G) * gamma2__ - f_xx = kappa + gamma1 - f_yy = kappa - gamma1 - f_xy = gamma2 - return f_xx, f_xy, f_xy, f_yy
- -
[docs] def density_lens(self, r, theta_E, e1, e2, s_scale, center_x=0, center_y=0): - """ - 3d mass density at 3d radius r. This function assumes spherical symmetry/ignoring the eccentricity. - - :param r: 3d radius - :param theta_E: Einstein radius - :param e1: eccentricity component - :param e2: eccentricity component - :param s_scale: smoothing scale - :param center_x: profile center - :param center_y: profile center - :return: 3d mass density at 3d radius r - """ - # kappa=1/2 at Einstein radius - rho0 = 1 / 2 * theta_E / np.pi - return rho0 / (r**2 + s_scale**2)
- -
[docs] def mass_3d_lens(self, r, theta_E, e1, e2, s_scale, center_x=0, center_y=0): - """ - mass enclosed a 3d radius r. This function assumes spherical symmetry/ignoring the eccentricity. - - :param r: 3d radius - :param theta_E: Einstein radius - :param e1: eccentricity component - :param e2: eccentricity component - :param s_scale: smoothing scale - :param center_x: profile center - :param center_y: profile center - :return: 3d mass density at 3d radius r - """ - rho0 = 1 / 2 * theta_E / np.pi - return rho0 * 4 * np.pi * (r - s_scale * np.arctan(r/s_scale))
- -
[docs] def param_conv(self, theta_E, e1, e2, s_scale): - if self._static is True: - return self._b_static, self._s_static, self._q_static, self._phi_G_static - return self._param_conv(theta_E, e1, e2, s_scale)
- - def _param_conv(self, theta_E, e1, e2, s_scale): - """ - convert parameters from 2*kappa = bIE [s2IE + r2(1 − e *cos(2*phi)]−1/2 to - 2*kappa= b *(q2(s2 + x2) + y2􏰉)−1/2 - see expressions after Equation 8 in Keeton and Kochanek 1998, https://arxiv.org/pdf/astro-ph/9705194.pdf - - :param theta_E: Einstein radius - :param e1: eccentricity component - :param e2: eccentricity component - :param s_scale: smoothing scale - :return: critical radius b, smoothing scale s, axis ratio q, orientation angle phi_G - """ - - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - theta_E_conv = self._theta_E_prod_average2major_axis(theta_E, q) - b = theta_E_conv * np.sqrt((1 + q**2)/2) - s = s_scale / np.sqrt(q) - #s = s_scale * np.sqrt((1 + q**2) / (2*q**2)) - return b, s, q, phi_G - -
[docs] def set_static(self, theta_E, e1, e2, s_scale, center_x=0, center_y=0): - """ - - :param x: x-coordinate in image plane - :param y: y-coordinate in image plane - :param theta_E: Einstein radius - :param e1: eccentricity component - :param e2: eccentricity component - :param s_scale: smoothing scale - :param center_x: profile center - :param center_y: profile center - :return: self variables set - """ - self._static = True - self._b_static, self._s_static, self._q_static, self._phi_G_static = self._param_conv(theta_E, e1, e2, s_scale)
- -
[docs] def set_dynamic(self): - """ - - :return: - """ - self._static = False - if hasattr(self, '_b_static'): - del self._b_static - if hasattr(self, '_s_static'): - del self._s_static - if hasattr(self, '_phi_G_static'): - del self._phi_G_static - if hasattr(self, '_q_static'): - del self._q_static
- - @staticmethod - def _theta_E_prod_average2major_axis(theta_E, q): - """ - Converts a product averaged Einstein radius (of semi-minor and semi-major axis) to a major axis Einstein radius - for an Isothermal ellipse. - The standard lenstronomy conventions are product averaged Einstein radii while other codes - (such as e.g. gravlens) use the semi-major axis convention. - - .. math:: - \\frac{\\theta_{E, prod ave}}{\\theta_{E, major}} = \\sqrt{(1+q^2) / (2 q) } - - :param theta_E: Einstein radius in lenstronomy conventions (product average of major and minor axes) - :param q: axis ratio minor/major - :return: theta_E in convention of kappa= b *(q^2(s^2 + x^2) + y^2􏰉)^{−1/2} (major axis) - """ - theta_E_major_axis = theta_E / (np.sqrt((1.+q**2) / (2. * q))) - return theta_E_major_axis
- - -
[docs]class NIEMajorAxis(LensProfileBase): - """ - This class contains the function and the derivatives of the non-singular isothermal ellipse. - See Keeton and Kochanek 1998, https://arxiv.org/pdf/astro-ph/9705194.pdf - - .. math:: - \\kappa = b * (q2(s2 + x2) + y2􏰉)^{−1/2}` - - """ - - param_names = ['b', 's', 'q', 'center_x', 'center_y'] - - def __init__(self, diff=0.0000000001): - self._diff = diff - super(NIEMajorAxis, self).__init__() - -
[docs] def function(self, x, y, b, s, q): - psi = self._psi(x, y, q, s) - alpha_x, alpha_y = self.derivatives(x, y, b, s, q) - f_ = x * alpha_x + y * alpha_y - b * s * 1. / 2. * np.log((psi + s) ** 2 + (1. - q ** 2) * x ** 2) - return f_
- -
[docs] def derivatives(self, x, y, b, s, q): - """ - returns df/dx and df/dy of the function - """ - if q >= 1: - q = 0.99999999 - psi = self._psi(x, y, q, s) - f_x = b / np.sqrt(1. - q ** 2) * np.arctan(np.sqrt(1. - q ** 2) * x / (psi + s)) - f_y = b / np.sqrt(1. - q ** 2) * np.arctanh(np.sqrt(1. - q ** 2) * y / (psi + q ** 2 * s)) - return f_x, f_y
- -
[docs] def hessian(self, x, y, b, s, q): - """ - returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - alpha_ra, alpha_dec = self.derivatives(x, y, b, s, q) - diff = self._diff - alpha_ra_dx, alpha_dec_dx = self.derivatives(x + diff, y, b, s, q) - alpha_ra_dy, alpha_dec_dy = self.derivatives(x, y + diff, b, s, q) - - f_xx = (alpha_ra_dx - alpha_ra) / diff - f_xy = (alpha_ra_dy - alpha_ra) / diff - f_yx = (alpha_dec_dx - alpha_dec) / diff - f_yy = (alpha_dec_dy - alpha_dec) / diff - return f_xx, f_xy, f_yx, f_yy
- -
[docs] @staticmethod - def kappa(x, y, b, s, q): - """ - convergence - - :param x: major axis coordinate - :param y: minor axis coordinate - :param b: normalization - :param s: smoothing scale - :param q: axis ratio - :return: convergence - """ - kappa = b/2. * (q**2 * (s**2 + x**2) + y**2)**(-1./2) - return kappa
- - @staticmethod - def _psi(x, y, q, s): - """ - expression after equation (8) in Keeton&Kochanek 1998 - - :param x: semi-major axis coordinate - :param y: semi-minor axis coordinate - :param q: axis ratio minor/major - :param s: smoothing scale in major axis direction - :return: phi - """ - return np.sqrt(q**2 * (s**2 + x**2) + y**2)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/nie_potential.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/nie_potential.html deleted file mode 100644 index 7d867e0a9..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/nie_potential.html +++ /dev/null @@ -1,300 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.nie_potential — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.nie_potential

-__author__ = 'gipagano'
-
-import numpy as np
-import lenstronomy.Util.util as util
-import lenstronomy.Util.param_util as param_util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['NIE_POTENTIAL', 'NIEPotentialMajorAxis']
-
-
-
[docs]class NIE_POTENTIAL(LensProfileBase): - """ - this class implements the elliptical potential of Eq. (67) of `LECTURES ON GRAVITATIONAL LENSING <https://arxiv.org/pdf/astro-ph/9606001.pdf>`_ - and Eq. (1) of `Blandford & Kochanek 1987 <http://adsabs.harvard.edu/full/1987ApJ...321..658B>`_, - mapped to Eq. (8) of `Barnaka1998 <https://iopscience.iop.org/article/10.1086/305950/fulltext/37798.text.html>`_ - to find the ellipticity bounds - """ - - param_names = ['center_x', 'center_y', 'theta_E', 'theta_c', 'e1', 'e2'] - lower_limit_default = {'center_x': -100, 'center_y': -100, 'theta_E': 0, 'theta_c': 0, 'e1': 0, 'e2': 0} - upper_limit_default = {'center_x': 100, 'center_y': 100, 'theta_E': 10, 'theta_c': 10, 'e1': 0.2, 'e2': 0.2} - - def __init__(self): - self.nie_potential_major_axis = NIEPotentialMajorAxis() - super(NIE_POTENTIAL, self).__init__() - -
[docs] def param_conv(self, theta_E, theta_c, e1, e2): - if self._static is True: - return self._thetaE_transf_static, self._thetac_static, self._eps_static, self._phi_G_static - return self._param_conv(theta_E, theta_c, e1, e2)
- - def _param_conv(self, theta_E, theta_c, e1, e2): - """ - convert the spherical averaged Einstein radius to an elliptical (major axis) Einstein radius and - the individual eccentricities to the modulus of the eccentricity - - :param theta_E: Einstein radius - :param theta_c: core radius - :param e1: eccentricity component - :param e2: eccentricity component - :return: transformed Einstein radius, core radius, ellipticity modulus, orientation angle phi_G - """ - - eps = np.sqrt(e1**2+e2**2) - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - theta_E_conv = self._theta_q_convert(theta_E, q) - theta_c_conv = self._theta_q_convert(theta_c, q) - return theta_E_conv, theta_c_conv, eps, phi_G - -
[docs] def set_static(self, theta_E, theta_c, e1, e2, center_x=0, center_y=0): - """ - - :param x: x-coordinate in image plane - :param y: y-coordinate in image plane - :param theta_E: Einstein radius - :param theta_c: core radius - :param e1: eccentricity component - :param e2: eccentricity component - :param center_x: profile center - :param center_y: profile center - :return: self variables set - """ - self._static = True - self._thetaE_transf_static, self._thetac_static, self._eps_static, self._phi_G_static = self._param_conv(theta_E, theta_c, e1, e2)
- -
[docs] def set_dynamic(self): - """ - - :return: - """ - self._static = False - if hasattr(self, '_thetaE_transf_static'): - del self._thetaE_transf_static - if hasattr(self, '_thetac_static'): - del self._thetac_static - if hasattr(self, '_eps_static'): - del self._eps_static - if hasattr(self, '_phi_G_static'): - del self._phi_G_static
- -
[docs] def function(self, x, y, theta_E, theta_c, e1, e2, center_x=0, center_y=0): - - """ - - :param x: x-coord (in angles) - :param y: y-coord (in angles) - :param theta_E: Einstein radius (in angles) - :param theta_c: core radius (in angles) - :param e1: eccentricity component, x direction(dimensionless) - :param e2: eccentricity component, y direction (dimensionless) - :return: lensing potential - """ - theta_E_conv, theta_c_conv, eps, phi_G = self.param_conv(theta_E, theta_c, e1, e2) - - # shift - x_ = x - center_x - y_ = y - center_y - - # rotate - x__, y__ = util.rotate(x_, y_, phi_G) - - # evaluate - f_ = self.nie_potential_major_axis.function(x__, y__, theta_E_conv, theta_c_conv, eps) - - # rotate back - return f_
- -
[docs] def derivatives(self, x, y, theta_E, theta_c, e1, e2, center_x=0, center_y=0): - """ - - :param x: x-coord (in angles) - :param y: y-coord (in angles) - :param theta_E: Einstein radius (in angles) - :param theta_c: core radius (in angles) - :param e1: eccentricity component, x direction(dimensionless) - :param e2: eccentricity component, y direction (dimensionless) - :return: deflection angle (in angles) - """ - theta_E_conv, theta_c_conv, eps, phi_G = self.param_conv(theta_E, theta_c, e1, e2) - - # shift - x_ = x - center_x - y_ = y - center_y - - # rotate - x__, y__ = util.rotate(x_, y_, phi_G) - - # evaluate - f__x, f__y = self.nie_potential_major_axis.derivatives(x__, y__, theta_E_conv, theta_c_conv, eps) - - # rotate back - f_x, f_y = util.rotate(f__x, f__y, -phi_G) - return f_x, f_y
- -
[docs] def hessian(self, x, y, theta_E, theta_c, e1, e2, center_x=0, center_y=0): - """ - - :param x: x-coord (in angles) - :param y: y-coord (in angles) - :param theta_E: Einstein radius (in angles) - :param theta_c: core radius (in angles) - :param e1: eccentricity component, x direction(dimensionless) - :param e2: eccentricity component, y direction (dimensionless) - :return: hessian matrix (in angles) - """ - theta_E_conv, theta_c_conv, eps, phi_G = self.param_conv(theta_E, theta_c, e1, e2) - - # shift - x_ = x - center_x - y_ = y - center_y - - # rotate - x__, y__ = util.rotate(x_, y_, phi_G) - - # evaluate - f__xx, f__xy, _, f__yy = self.nie_potential_major_axis.hessian(x__, y__, theta_E_conv, theta_c_conv, eps) - - # rotate back - kappa = 1./2 * (f__xx + f__yy) - gamma1__ = 1./2 * (f__xx - f__yy) - gamma2__ = f__xy - gamma1 = np.cos(2 * phi_G) * gamma1__ - np.sin(2 * phi_G) * gamma2__ - gamma2 = +np.sin(2 * phi_G) * gamma1__ + np.cos(2 * phi_G) * gamma2__ - f_xx = kappa + gamma1 - f_yy = kappa - gamma1 - f_xy = gamma2 - return f_xx, f_xy, f_xy, f_yy
- - def _theta_q_convert(self, theta_E, q): - """ - converts a spherical averaged Einstein radius/core radius to an elliptical (major axis) Einstein radius. - This then follows the convention of the SPEMD profile in lenstronomy. - (theta_E / theta_E_gravlens) = sqrt[ (1+q^2) / (2 q) ] - - :param theta_E: Einstein radius in lenstronomy conventions - :param q: axis ratio minor/major - :return: theta_E in convention of kappa= b *(q2(s2 + x2) + y2􏰉)−1/2 - """ - theta_E_new = theta_E / (np.sqrt((1.+q**2) / (2. * q))) #/ (1+(1-q)/2.) - return theta_E_new
- - -
[docs]class NIEPotentialMajorAxis(LensProfileBase): - """ - this class implements the elliptical potential of Eq. (67) of `LECTURES ON GRAVITATIONAL LENSING <https://arxiv.org/pdf/astro-ph/9606001.pdf>`_ - and Eq. (1) of `Blandford & Kochanek 1987 <http://adsabs.harvard.edu/full/1987ApJ...321..658B>`_, - mapped to Eq. (8) of `Barnaka1998 <https://iopscience.iop.org/article/10.1086/305950/fulltext/37798.text.html>`_ - to find the ellipticity bounds - """ - - param_names = ['theta_E', 'theta_c', 'eps', 'center_x', 'center_y'] - - def __init__(self, diff=0.0000000001): - self._diff = diff - super(NIEPotentialMajorAxis, self).__init__() - -
[docs] def function(self, x, y, theta_E, theta_c, eps): - f_ = theta_E*np.sqrt(theta_c**2+(1-eps)*x**2+(1+eps)*y**2) - return f_
- -
[docs] def derivatives(self, x, y, theta_E, theta_c, eps): - """ - returns df/dx and df/dy of the function - """ - factor = np.sqrt(theta_c**2+(1-eps)*x**2+(1+eps)*y**2) - f_x = (theta_E/factor)*(1-eps)*x - f_y = (theta_E/factor)*(1+eps)*y - return f_x, f_y
- -
[docs] def hessian(self, x, y, theta_E, theta_c, eps): - """ - returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - factor = np.sqrt(theta_c**2+(1-eps)*x**2+(1+eps)*y**2) - f_xx = (1-eps)*(theta_E/factor) -(theta_E/factor**3)*(1-eps)**2*x**2 - f_yy = (1+eps)*(theta_E/factor) -(theta_E/factor**3)*(1+eps)**2*y**2 - f_xy = -(theta_E/factor**3)*(1-eps**2)*x*y - return f_xx, f_xy, f_xy, f_yy
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/numerical_deflections.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/numerical_deflections.html deleted file mode 100644 index d4d02ed03..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/numerical_deflections.html +++ /dev/null @@ -1,171 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.numerical_deflections — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.numerical_deflections

-__author__ = 'dgilman'
-
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['NumericalAlpha']
-
-
-
[docs]class NumericalAlpha(LensProfileBase): - - """ - This class allows one to incorporate any lens profile into the usage framework of lenstronomy. When creating the - instance of LensModel with this lens profile, you must pass in numerical_alpha_class = CustomClass(), where - CustomClass is a class with a call method that returns the x/y deflection angles. This allows one to numerically - compute and interpolate deflection angles for potentially very complex mass profiles, and then use the results with - lenstronomy without having to heavily modify the existing structure of the software. - - """ - def __init__(self, custom_class): - - """ - :param custom_class: a user-defined class that has a __call___ method that returns deflection angles - - Code example: - - >>> custom_class = CustomLensingClass() - >>> alpha_x, alpha_y = custom_class(x, y, **kwargs) - - or equivalently: - - >>> from lenstronomy.LensModel.lens_model import LensModel - >>> lens_model_list = ['NumericalAlpha'] - >>> lens_model = LensModel(lens_model_list, numerical_alpha_class=custom_class) - >>>> alpha_x, alpha_y = lens_model.alpha(x, y, **kwargs) - """ - - self._custom_lens_class = custom_class - super(NumericalAlpha, self).__init__() - -
[docs] def function(self, x, y,center_x = 0, center_y = 0, **kwargs): - - raise Exception('no potential for this class.')
- -
[docs] def derivatives(self, x, y, center_x=0, center_y=0, **kwargs): - - """ - - :param x: x coordinate [arcsec] - :param y: x coordinate [arcsec] - :param center_x: deflector x center [arcsec] - :param center_y: deflector y center [arcsec] - :param kwargs: keyword arguments for the custom profile - :return: - """ - - x_ = x - center_x - y_ = y - center_y - f_x, f_y = self._custom_lens_class(x_, y_, **kwargs) - - return f_x, f_y
- -
[docs] def hessian(self, x, y, center_x=0, center_y=0, **kwargs): - """ - Returns the components of the hessian matrix - :param x: x coordinate [arcsec] - :param y: y coordinate [arcsec] - :param center_x: the deflector x coordinate - :param center_y: the deflector y coordinate - :param kwargs: keyword arguments for the profile - :return: the derivatives of the deflection angles that make up the hessian matrix - """ - - diff = 1e-6 - alpha_ra, alpha_dec = self.derivatives(x, y, center_x=center_x, center_y=center_y, **kwargs) - - alpha_ra_dx, alpha_dec_dx = self.derivatives(x + diff, y, center_x=center_x, center_y=center_y, **kwargs) - alpha_ra_dy, alpha_dec_dy = self.derivatives(x, y + diff, center_x=center_x, center_y=center_y, **kwargs) - - dalpha_rara = (alpha_ra_dx - alpha_ra) / diff - dalpha_radec = (alpha_ra_dy - alpha_ra) / diff - dalpha_decra = (alpha_dec_dx - alpha_dec) / diff - dalpha_decdec = (alpha_dec_dy - alpha_dec) / diff - - f_xx = dalpha_rara - f_yy = dalpha_decdec - f_xy = dalpha_radec - f_yx = dalpha_decra - - return f_xx, f_xy, f_yx, f_yy
- -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/p_jaffe.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/p_jaffe.html deleted file mode 100644 index 4a46bb123..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/p_jaffe.html +++ /dev/null @@ -1,365 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.p_jaffe — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.p_jaffe

-import numpy as np
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['PJaffe']
-
-
-
[docs]class PJaffe(LensProfileBase): - """ - class to compute the DUAL PSEUDO ISOTHERMAL ELLIPTICAL MASS DISTRIBUTION - based on Eliasdottir (2007) https://arxiv.org/pdf/0710.5636.pdf Appendix A - - Module name: 'PJAFFE'; - - An alternative name is dPIED. - - The 3D density distribution is - - .. math:: - \\rho(r) = \\frac{\\rho_0}{(1+r^2/Ra^2)(1+r^2/Rs^2)} - - with :math:`Rs > Ra`. - - The projected density is - - .. math:: - \\Sigma(R) = \\Sigma_0 \\frac{Ra Rs}{Rs-Ra}\\left(\\frac{1}{\\sqrt{Ra^2+R^2}} - \\frac{1}{\\sqrt{Rs^2+R^2}} \\right) - - with - - .. math:: - \\Sigma_0 = \\pi \\rho_0 \\frac{Ra Rs}{Rs + Ra} - - In the lensing parameterization, - - .. math:: - \\sigma_0 = \\frac{\\Sigma_0}{\\Sigma_{\\rm crit}} - - """ - - param_names = ['sigma0', 'Ra', 'Rs', 'center_x', 'center_y'] - lower_limit_default = {'sigma0': 0, 'Ra': 0, 'Rs': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'sigma0': 10, 'Ra': 100, 'Rs': 100, 'center_x': 100, 'center_y': 100} - - def __init__(self): - """ - - """ - LensProfileBase.__init__(self) - self._s = 0.0001 - -
[docs] def density(self, r, rho0, Ra, Rs): - """ - computes the density - - :param r: radial distance from the center (in 3D) - :param rho0: density normalization (see class documentation above) - :param Ra: core radius - :param Rs: transition radius from logarithmic slope -2 to -4 - :return: density at r - """ - Ra, Rs = self._sort_ra_rs(Ra, Rs) - rho = rho0 / ((1 + (r / Ra) ** 2) * (1 + (r / Rs) ** 2)) - return rho
- -
[docs] def density_2d(self, x, y, rho0, Ra, Rs, center_x=0, center_y=0): - """ - projected density - - :param x: projected coordinate on the sky - :param y: projected coordinate on the sky - :param rho0: density normalization (see class documentation above) - :param Ra: core radius - :param Rs: transition radius from logarithmic slope -2 to -4 - :param center_x: center of profile - :param center_y: center of profile - :return: projected density - """ - Ra, Rs = self._sort_ra_rs(Ra, Rs) - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - sigma0 = self.rho2sigma(rho0, Ra, Rs) - sigma = sigma0 * Ra * Rs / (Rs - Ra) * (1 / np.sqrt(Ra ** 2 + r ** 2) - 1 / np.sqrt(Rs ** 2 + r ** 2)) - return sigma
- -
[docs] def mass_3d(self, r, rho0, Ra, Rs): - """ - mass enclosed a 3d sphere or radius r - - :param r: radial distance from the center (in 3D) - :param rho0: density normalization (see class documentation above) - :param Ra: core radius - :param Rs: transition radius from logarithmic slope -2 to -4 - :return: M(<r) - """ - m_3d = 4 * np.pi * rho0 * Ra ** 2 * Rs ** 2 / (Rs ** 2 - Ra ** 2) * (Rs * np.arctan(r / Rs) - Ra * np.arctan(r / Ra)) - return m_3d
- -
[docs] def mass_3d_lens(self, r, sigma0, Ra, Rs): - """ - mass enclosed a 3d sphere or radius r given a lens parameterization with angular units - - :param r: radial distance from the center (in 3D) - :param sigma0: density normalization (see class documentation above) - :param Ra: core radius - :param Rs: transition radius from logarithmic slope -2 to -4 - :return: M(<r) in angular units (modulo critical mass density) - """ - rho0 = self.sigma2rho(sigma0, Ra, Rs) - return self.mass_3d(r, rho0, Ra, Rs)
- -
[docs] def mass_2d(self, r, rho0, Ra, Rs): - """ - mass enclosed projected 2d sphere of radius r - - :param r: radial distance from the center in projection - :param rho0: density normalization (see class documentation above) - :param Ra: core radius - :param Rs: transition radius from logarithmic slope -2 to -4 - :return: Sigma(<r) - """ - Ra, Rs = self._sort_ra_rs(Ra, Rs) - sigma0 = self.rho2sigma(rho0, Ra, Rs) - m_2d = 2 * np.pi * sigma0 * Ra * Rs / (Rs - Ra) * (np.sqrt(Ra ** 2 + r ** 2) - Ra - np.sqrt(Rs ** 2 + r ** 2) + Rs) - return m_2d
- -
[docs] def mass_tot(self, rho0, Ra, Rs): - """ - total mass within the profile - - :param rho0: density normalization (see class documentation above) - :param Ra: core radius - :param Rs: transition radius from logarithmic slope -2 to -4 - :return: total mass - """ - Ra, Rs = self._sort_ra_rs(Ra, Rs) - sigma0 = self.rho2sigma(rho0, Ra, Rs) - m_tot = 2 * np.pi * sigma0 * Ra * Rs - return m_tot
- -
[docs] def grav_pot(self, r, rho0, Ra, Rs): - """ - gravitational potential (modulo 4 pi G and rho0 in appropriate units) - - :param r: radial distance from the center (in 3D) - :param rho0: density normalization (see class documentation above) - :param Ra: core radius - :param Rs: transition radius from logarithmic slope -2 to -4 - :return: gravitational potential (modulo 4 pi G and rho0 in appropriate units) - """ - Ra, Rs = self._sort_ra_rs(Ra, Rs) - pot = 4 * np.pi * rho0 * Ra ** 2 * Rs ** 2 / (Rs ** 2 - Ra ** 2) * (Rs / r * np.arctan(r / Rs) - Ra / r * np.arctan(r / Ra) - + 1. / 2 * np.log((Rs ** 2 + r ** 2) / (Ra ** 2 + r ** 2))) - return pot
- -
[docs] def function(self, x, y, sigma0, Ra, Rs, center_x=0, center_y=0): - """ - lensing potential - - :param x: projected coordinate on the sky - :param y: projected coordinate on the sky - :param sigma0: sigma0/sigma_crit (see class documentation above) - :param Ra: core radius (see class documentation above) - :param Rs: transition radius from logarithmic slope -2 to -4 (see class documentation above) - :param center_x: center of profile - :param center_y: center of profile - :return: lensing potential - """ - Ra, Rs = self._sort_ra_rs(Ra, Rs) - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - f_ = -2*sigma0 * Ra * Rs / (Rs - Ra) * (np.sqrt(Rs ** 2 + r ** 2) - np.sqrt(Ra ** 2 + r ** 2) + Ra * np.log(Ra + np.sqrt(Ra ** 2 + r ** 2)) - Rs * np.log(Rs + np.sqrt(Rs ** 2 + r ** 2))) - return f_
- -
[docs] def derivatives(self, x, y, sigma0, Ra, Rs, center_x=0, center_y=0): - """ - deflection angles - - :param x: projected coordinate on the sky - :param y: projected coordinate on the sky - :param sigma0: sigma0/sigma_crit (see class documentation above) - :param Ra: core radius (see class documentation above) - :param Rs: transition radius from logarithmic slope -2 to -4 (see class documentation above) - :param center_x: center of profile - :param center_y: center of profile - :return: f_x, f_y - """ - Ra, Rs = self._sort_ra_rs(Ra, Rs) - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - if isinstance(r, int) or isinstance(r, float): - r = max(self._s, r) - else: - r[r < self._s] = self._s - alpha_r = 2*sigma0 * Ra * Rs / (Rs - Ra) * self._f_A20(r / Ra, r / Rs) - f_x = alpha_r * x_/r - f_y = alpha_r * y_/r - return f_x, f_y
- -
[docs] def hessian(self, x, y, sigma0, Ra, Rs, center_x=0, center_y=0): - """ - Hessian of lensing potential - - :param x: projected coordinate on the sky - :param y: projected coordinate on the sky - :param sigma0: sigma0/sigma_crit (see class documentation above) - :param Ra: core radius (see class documentation above) - :param Rs: transition radius from logarithmic slope -2 to -4 (see class documentation above) - :param center_x: center of profile - :param center_y: center of profile - :return: f_xx, f_xy, f_yx, f_yy - """ - Ra, Rs = self._sort_ra_rs(Ra, Rs) - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - if isinstance(r, int) or isinstance(r, float): - r = max(self._s, r) - else: - r[r < self._s] = self._s - gamma = sigma0 * Ra * Rs / (Rs - Ra) * (2 * (1. / (Ra + np.sqrt(Ra ** 2 + r ** 2)) - 1. / (Rs + np.sqrt(Rs ** 2 + r ** 2))) - - (1 / np.sqrt(Ra ** 2 + r ** 2) - 1 / np.sqrt(Rs ** 2 + r ** 2))) - kappa = sigma0 * Ra * Rs / (Rs - Ra) * (1 / np.sqrt(Ra ** 2 + r ** 2) - 1 / np.sqrt(Rs ** 2 + r ** 2)) - sin_2phi = -2*x_*y_/r**2 - cos_2phi = (y_**2 - x_**2)/r**2 - gamma1 = cos_2phi*gamma - gamma2 = sin_2phi*gamma - - f_xx = kappa + gamma1 - f_yy = kappa - gamma1 - f_xy = gamma2 - return f_xx, f_xy, f_xy, f_yy
- - def _f_A20(self, r_a, r_s): - """ - equation A20 in Eliasdottir (2007) - - :param r_a: r/Ra - :param r_s: r/Rs - :return: f(R/a, R/s) - """ - return r_a/(1+np.sqrt(1 + r_a**2)) - r_s/(1+np.sqrt(1 + r_s**2)) - -
[docs] def rho2sigma(self, rho0, Ra, Rs): - """ - converts 3d density into 2d projected density parameter, Equation A4 in Eliasdottir (2007) - - :param rho0: density normalization - :param Ra: core radius (see class documentation above) - :param Rs: transition radius from logarithmic slope -2 to -4 (see class documentation above) - :return: projected density normalization - """ - return np.pi * rho0 * Ra * Rs / (Rs + Ra)
- -
[docs] def sigma2rho(self, sigma0, Ra, Rs): - """ - inverse of rho2sigma() - - :param sigma0: projected density normalization - :param Ra: core radius (see class documentation above) - :param Rs: transition radius from logarithmic slope -2 to -4 (see class documentation above) - :return: 3D density normalization - """ - return (Rs + Ra) / Ra / Rs / np.pi * sigma0
- - @staticmethod - def _sort_ra_rs(Ra, Rs): - """ - sorts Ra and Rs to make sure Rs > Ra - - :param Ra: - :param Rs: - :return: Ra, Rs in conventions used - """ - if Ra >= Rs: - Ra, Rs = Rs, Ra - if Ra < 0.0001: - Ra = 0.0001 - if Rs < Ra + 0.0001: - Rs += 0.0001 - return Ra, Rs
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/p_jaffe_ellipse.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/p_jaffe_ellipse.html deleted file mode 100644 index df0bc1688..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/p_jaffe_ellipse.html +++ /dev/null @@ -1,184 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.p_jaffe_ellipse — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.p_jaffe_ellipse

-from lenstronomy.LensModel.Profiles.p_jaffe import PJaffe
-import lenstronomy.Util.param_util as param_util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-import numpy as np
-
-__all__ = ['PJaffe_Ellipse']
-
-
-
[docs]class PJaffe_Ellipse(LensProfileBase): - """ - class to compute the DUAL PSEUDO ISOTHERMAL ELLIPTICAL MASS DISTRIBUTION - based on Eliasdottir (2007) https://arxiv.org/pdf/0710.5636.pdf Appendix A - with the ellipticity implemented in the potential - - Module name: 'PJAFFE_ELLIPSE'; - - An alternative name is dPIED. - - The 3D density distribution is - - .. math:: - \\rho(r) = \\frac{\\rho_0}{(1+r^2/Ra^2)(1+r^2/Rs^2)} - - with :math:`Rs > Ra`. - - The projected density is - - .. math:: - \\Sigma(R) = \\Sigma_0 \\frac{Ra Rs}{Rs-Ra}\\left(\\frac{1}{\\sqrt{Ra^2+R^2}} - \\frac{1}{\\sqrt{Rs^2+R^2}} \\right) - - with - - .. math:: - \\Sigma_0 = \\pi \\rho_0 \\frac{Ra Rs}{Rs + Ra} - - In the lensing parameterization, - - .. math:: - \\sigma_0 = \\frac{\\Sigma_0}{\\Sigma_{\\rm crit}} - - """ - param_names = ['sigma0', 'Ra', 'Rs', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'sigma0': 0, 'Ra': 0, 'Rs': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'sigma0': 10, 'Ra': 100, 'Rs': 100, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.spherical = PJaffe() - self._diff = 0.000001 - super(PJaffe_Ellipse, self).__init__() - -
[docs] def function(self, x, y, sigma0, Ra, Rs, e1, e2, center_x=0, center_y=0): - """ - returns double integral of NFW profile - """ - x_, y_ = param_util.transform_e1e2_square_average(x, y, e1, e2, center_x, center_y) - f_ = self.spherical.function(x_, y_, sigma0, Ra, Rs) - return f_
- -
[docs] def derivatives(self, x, y, sigma0, Ra, Rs, e1, e2, center_x=0, center_y=0): - """ - returns df/dx and df/dy of the function (integral of NFW) - """ - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - x_, y_ = param_util.transform_e1e2_square_average(x, y, e1, e2, center_x, center_y) - e = param_util.q2e(q) - cos_phi = np.cos(phi_G) - sin_phi = np.sin(phi_G) - f_x_prim, f_y_prim = self.spherical.derivatives(x_, y_, sigma0, Ra, Rs, center_x=0, center_y=0) - f_x_prim *= np.sqrt(1 - e) - f_y_prim *= np.sqrt(1 + e) - f_x = cos_phi*f_x_prim-sin_phi*f_y_prim - f_y = sin_phi*f_x_prim+cos_phi*f_y_prim - return f_x, f_y
- -
[docs] def hessian(self, x, y, sigma0, Ra, Rs, e1, e2, center_x=0, center_y=0): - """ - returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - alpha_ra, alpha_dec = self.derivatives(x, y, sigma0, Ra, Rs, e1, e2, center_x, center_y) - diff = self._diff - alpha_ra_dx, alpha_dec_dx = self.derivatives(x + diff, y, sigma0, Ra, Rs, e1, e2, center_x, center_y) - alpha_ra_dy, alpha_dec_dy = self.derivatives(x, y + diff, sigma0, Ra, Rs, e1, e2, center_x, center_y) - - f_xx = (alpha_ra_dx - alpha_ra)/diff - f_xy = (alpha_ra_dy - alpha_ra)/diff - f_yx = (alpha_dec_dx - alpha_dec)/diff - f_yy = (alpha_dec_dy - alpha_dec)/diff - - return f_xx, f_xy, f_yx, f_yy
- -
[docs] def mass_3d_lens(self, r, sigma0, Ra, Rs, e1=0, e2=0): - """ - - :param r: - :param sigma0: - :param Ra: - :param Rs: - :param e1: - :param e2: - :return: - """ - return self.spherical.mass_3d_lens(r, sigma0, Ra, Rs)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/pemd.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/pemd.html deleted file mode 100644 index b75924da0..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/pemd.html +++ /dev/null @@ -1,206 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.pemd — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.pemd

-__author__ = 'sibirrer'
-
-from lenstronomy.LensModel.Profiles.spp import SPP
-from lenstronomy.LensModel.Profiles.spemd import SPEMD
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['PEMD']
-
-
-
[docs]class PEMD(LensProfileBase): - """ - class for power law ellipse mass density profile. - This class effectively calls the class SPEMD_SMOOTH with a fixed and very small central smoothing scale - to perform the numerical integral using the FASTELL code by Renan Barkana. - - .. math:: - \\kappa(x, y) = \\frac{3-\\gamma}{2} \\left(\\frac{\\theta_{E}}{\\sqrt{q x^2 + y^2/q}} \\right)^{\\gamma-1} - - with :math:`\\theta_{E}` is the (circularized) Einstein radius, - :math:`\\gamma` is the negative power-law slope of the 3D mass distributions, - :math:`q` is the minor/major axis ratio, - and :math:`x` and :math:`y` are defined in a coordinate system aligned with the major and minor axis of the lens. - - In terms of eccentricities, this profile is defined as - - .. math:: - \\kappa(r) = \\frac{3-\\gamma}{2} \\left(\\frac{\\theta'_{E}}{r \\sqrt{1 − e*\\cos(2*\\phi)}} \\right)^{\\gamma-1} - - with :math:`\\epsilon` is the ellipticity defined as - - .. math:: - \\epsilon = \\frac{1-q^2}{1+q^2} - - And an Einstein radius :math:`\\theta'_{\\rm E}` related to the definition used is - - .. math:: - \\left(\\frac{\\theta'_{\\rm E}}{\\theta_{\\rm E}}\\right)^{2} = \\frac{2q}{1+q^2}. - - - """ - param_names = ['theta_E', 'gamma', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'theta_E': 0, 'gamma': 1.5, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'theta_E': 100, 'gamma': 2.5, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self, suppress_fastell=False): - """ - - :param suppress_fastell: bool, if True, does not raise if fastell4py is not installed - """ - self._s_scale = 0.0000001 # smoothing scale as used to numerically compute a power-law profile - self.spp = SPP() - self.spemd_smooth = SPEMD(suppress_fastell=suppress_fastell) - super(PEMD, self).__init__() - -
[docs] def function(self, x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0): - """ - - :param x: x-coordinate (angle) - :param y: y-coordinate (angle) - :param theta_E: Einstein radius (angle), pay attention to specific definition! - :param gamma: logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal - :param e1: eccentricity component - :param e2: eccentricity component - :param center_x: x-position of lens center - :param center_y: y-position of lens center - :return: lensing potential - """ - return self.spemd_smooth.function(x, y, theta_E, gamma, e1, e2, self._s_scale, center_x, center_y)
- -
[docs] def derivatives(self, x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0): - """ - - :param x: x-coordinate (angle) - :param y: y-coordinate (angle) - :param theta_E: Einstein radius (angle), pay attention to specific definition! - :param gamma: logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal - :param e1: eccentricity component - :param e2: eccentricity component - :param center_x: x-position of lens center - :param center_y: y-position of lens center - :return: deflection angles alpha_x, alpha_y - """ - return self.spemd_smooth.derivatives(x, y, theta_E, gamma, e1, e2, self._s_scale, center_x, center_y)
- -
[docs] def hessian(self, x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0): - """ - - :param x: x-coordinate (angle) - :param y: y-coordinate (angle) - :param theta_E: Einstein radius (angle), pay attention to specific definition! - :param gamma: logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal - :param e1: eccentricity component - :param e2: eccentricity component - :param center_x: x-position of lens center - :param center_y: y-position of lens center - :return: Hessian components f_xx, f_xy, f_yx, f_yy - """ - return self.spemd_smooth.hessian(x, y, theta_E, gamma, e1, e2, self._s_scale, center_x, center_y)
- -
[docs] def mass_3d_lens(self, r, theta_E, gamma, e1=None, e2=None): - """ - computes the spherical power-law mass enclosed (with SPP routine) - :param r: radius within the mass is computed - :param theta_E: Einstein radius - :param gamma: power-law slope - :param e1: eccentricity component (not used) - :param e2: eccentricity component (not used) - :return: mass enclosed a 3D radius r - """ - return self.spp.mass_3d_lens(r, theta_E, gamma)
- -
[docs] def density_lens(self, r, theta_E, gamma, e1=None, e2=None): - """ - computes the density at 3d radius r given lens model parameterization. - The integral in the LOS projection of this quantity results in the convergence quantity. - - :param r: radius within the mass is computed - :param theta_E: Einstein radius - :param gamma: power-law slope - :param e1: eccentricity component (not used) - :param e2: eccentricity component (not used) - :return: mass enclosed a 3D radius r - """ - return self.spp.density_lens(r, theta_E, gamma)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/point_mass.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/point_mass.html deleted file mode 100644 index 1a684cd79..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/point_mass.html +++ /dev/null @@ -1,166 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.point_mass — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.point_mass

-__author__ = 'sibirrer'
-
-
-import numpy as np
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['PointMass']
-
-
-
[docs]class PointMass(LensProfileBase): - """ - class to compute the physical deflection angle of a point mass, given as an Einstein radius - """ - param_names = ['theta_E', 'center_x', 'center_y'] - lower_limit_default = {'theta_E': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'theta_E': 100, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.r_min = 10**(-25) - super(PointMass, self).__init__() - # alpha = 4*const.G * (mass*const.M_sun)/const.c**2/(r*const.Mpc) - -
[docs] def function(self, x, y, theta_E, center_x=0, center_y=0): - """ - - :param x: x-coord (in angles) - :param y: y-coord (in angles) - :param theta_E: Einstein radius (in angles) - :return: lensing potential - """ - x_ = x - center_x - y_ = y - center_y - a = np.sqrt(x_**2 + y_**2) - if isinstance(a, int) or isinstance(a, float): - r = max(self.r_min, a) - else: - r = np.empty_like(a) - r[a > self.r_min] = a[a > self.r_min] #in the SIS regime - r[a <= self.r_min] = self.r_min - phi = theta_E**2*np.log(r) - return phi
- -
[docs] def derivatives(self, x, y, theta_E, center_x=0, center_y=0): - """ - - :param x: x-coord (in angles) - :param y: y-coord (in angles) - :param theta_E: Einstein radius (in angles) - :return: deflection angle (in angles) - """ - x_ = x - center_x - y_ = y - center_y - a = np.sqrt(x_**2 + y_**2) - if isinstance(a, int) or isinstance(a, float): - r = max(self.r_min, a) - else: - r = np.empty_like(a) - r[a > self.r_min] = a[a > self.r_min] #in the SIS regime - r[a <= self.r_min] = self.r_min - alpha = theta_E**2/r - return alpha*x_/r, alpha*y_/r
- -
[docs] def hessian(self, x, y, theta_E, center_x=0, center_y=0): - """ - - :param x: x-coord (in angles) - :param y: y-coord (in angles) - :param theta_E: Einstein radius (in angles) - :return: hessian matrix (in angles) - """ - x_ = x - center_x - y_ = y - center_y - C = theta_E**2 - a = x_**2 + y_**2 - if isinstance(a, int) or isinstance(a, float): - r2 = max(self.r_min**2, a) - else: - r2 = np.empty_like(a) - r2[a > self.r_min**2] = a[a > self.r_min**2] #in the SIS regime - r2[a <= self.r_min**2] = self.r_min**2 - f_xx = C * (y_**2-x_**2)/r2**2 - f_yy = C * (x_**2-y_**2)/r2**2 - f_xy = -C * 2*x_*y_/r2**2 - return f_xx, f_xy, f_xy, f_yy
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sersic.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sersic.html deleted file mode 100644 index 3fedc8b48..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sersic.html +++ /dev/null @@ -1,162 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.sersic — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.sersic

-__author__ = 'sibirrer'
-#this file contains a class to make a gaussian
-
-import numpy as np
-import lenstronomy.Util.util as util
-from lenstronomy.LensModel.Profiles.sersic_utils import SersicUtil
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['Sersic']
-
-
-
[docs]class Sersic(SersicUtil, LensProfileBase): - """ - this class contains functions to evaluate a Sersic mass profile: https://arxiv.org/pdf/astro-ph/0311559.pdf - """ - param_names = ['k_eff', 'R_sersic', 'n_sersic', 'center_x', 'center_y'] - lower_limit_default = {'k_eff': 0, 'R_sersic': 0, 'n_sersic': 0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'k_eff': 10, 'R_sersic': 100, 'n_sersic': 8, 'center_x': 100, 'center_y': 100} - -
[docs] def function(self, x, y, n_sersic, R_sersic, k_eff, center_x=0, center_y=0): - """ - - :param x: x-coordinate - :param y: y-coordinate - :param n_sersic: Sersic index - :param R_sersic: half light radius - :param k_eff: convergence at half light radius - :param center_x: x-center - :param center_y: y-center - :return: - """ - - n = n_sersic - x_red = self._x_reduced(x, y, n, R_sersic, center_x, center_y) - b = self.b_n(n) - #hyper2f2_b = util.hyper2F2_array(2*n, 2*n, 1+2*n, 1+2*n, -b) - hyper2f2_bx = util.hyper2F2_array(2*n, 2*n, 1+2*n, 1+2*n, -b*x_red) - f_eff = np.exp(b) * R_sersic ** 2 / 2. * k_eff# * hyper2f2_b - f_ = f_eff * x_red**(2*n) * hyper2f2_bx# / hyper2f2_b - return f_
- -
[docs] def derivatives(self, x, y, n_sersic, R_sersic, k_eff, center_x=0, center_y=0): - """ - returns df/dx and df/dy of the function - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - if isinstance(r, int) or isinstance(r, float): - r = max(self._s, r) - else: - r[r < self._s] = self._s - alpha = -self.alpha_abs(x, y, n_sersic, R_sersic, k_eff, center_x, center_y) - f_x = alpha * x_ / r - f_y = alpha * y_ / r - return f_x, f_y
- -
[docs] def hessian(self, x, y, n_sersic, R_sersic, k_eff, center_x=0, center_y=0): - """ - returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - if isinstance(r, int) or isinstance(r, float): - r = max(self._s, r) - else: - r[r < self._s] = self._s - d_alpha_dr = self.d_alpha_dr(x, y, n_sersic, R_sersic, k_eff, center_x, center_y) - alpha = -self.alpha_abs(x, y, n_sersic, R_sersic, k_eff, center_x, center_y) - - #f_xx_ = d_alpha_dr * calc_util.d_r_dx(x_, y_) * x_/r + alpha * calc_util.d_x_diffr_dx(x_, y_) - #f_yy_ = d_alpha_dr * calc_util.d_r_dy(x_, y_) * y_/r + alpha * calc_util.d_y_diffr_dy(x_, y_) - #f_xy_ = d_alpha_dr * calc_util.d_r_dy(x_, y_) * x_/r + alpha * calc_util.d_x_diffr_dy(x_, y_) - - f_xx = -(d_alpha_dr/r + alpha/r**2) * x_**2/r + alpha/r - f_yy = -(d_alpha_dr/r + alpha/r**2) * y_**2/r + alpha/r - f_xy = -(d_alpha_dr/r + alpha/r**2) * x_*y_/r - - return f_xx, f_xy, f_xy, f_yy
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sersic_ellipse_kappa.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sersic_ellipse_kappa.html deleted file mode 100644 index 9ac665081..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sersic_ellipse_kappa.html +++ /dev/null @@ -1,255 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.sersic_ellipse_kappa — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.sersic_ellipse_kappa

-__author__ = 'dgilman'
-
-from scipy.integrate import quad
-import numpy as np
-from lenstronomy.LensModel.Profiles.sersic import Sersic
-from lenstronomy.Util import param_util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['SersicEllipseKappa']
-
-
-
[docs]class SersicEllipseKappa(LensProfileBase): - """ - this class contains the function and the derivatives of an elliptical sersic profile - with the ellipticity introduced in the convergence (not the potential). - - This requires the use of numerical integrals (Keeton 2004) - """ - param_names = ['k_eff', 'R_sersic', 'n_sersic', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'k_eff': 0, 'R_sersic': 0, 'n_sersic': 0.5, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, - 'center_y': -100} - upper_limit_default = {'k_eff': 10, 'R_sersic': 100, 'n_sersic': 8, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, - 'center_y': 100} - - def __init__(self): - - self._sersic = Sersic() - super(SersicEllipseKappa, self).__init__() - -
[docs] def function(self, x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y=0): - - raise Exception('not yet implemented')
- - # phi_G, q = param_util.ellipticity2phi_q(e1, e2) - # - # if isinstance(x, float) and isinstance(y, float): - # - # x_, y_ = self._coord_rotate(x, y, phi_G, center_x, center_y) - # integral = quad(self._integrand_I, 0, 1, args=(x_, y_, q, n_sersic, R_sersic, k_eff, center_x, center_y))[0] - # - # else: - # - # assert isinstance(x, np.ndarray) or isinstance(x, list) - # assert isinstance(y, np.ndarray) or isinstance(y, list) - # x = np.array(x) - # y = np.array(y) - # shape0 = x.shape - # assert shape0 == y.shape - # - # if isinstance(phi_G, float) or isinstance(phi_G, int): - # phiG = np.ones_like(x) * float(phi_G) - # q = np.ones_like(x) * float(q) - # integral = [] - # for i, (x_i, y_i, phi_i, q_i) in \ - # enumerate(zip(x.ravel(), y.ravel(), phiG.ravel(), q.ravel())): - # - # integral.append(quad(self._integrand_I, 0, 1, args=(x_, y_, q, n_sersic, - # R_sersic, k_eff, center_x, center_y))[0]) - # - # - # return 0.5 * q * integral - -
[docs] def derivatives(self, x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y = 0): - - phi_G, gam = param_util.shear_cartesian2polar(e1, e2) - q = max(1-gam, 0.00001) - - x, y = self._coord_rotate(x, y, phi_G, center_x, center_y) - - if isinstance(x, float) and isinstance(y, float): - - alpha_x, alpha_y = self._compute_derivative_atcoord(x, y, n_sersic, R_sersic, k_eff, - phi_G, q, center_x=center_x, center_y = center_y) - - else: - - assert isinstance(x, np.ndarray) or isinstance(x, list) - assert isinstance(y, np.ndarray) or isinstance(y, list) - x = np.array(x) - y = np.array(y) - shape0 = x.shape - assert shape0 == y.shape - - alpha_x, alpha_y = np.empty_like(x).ravel(), np.empty_like(y).ravel() - - if isinstance(phi_G, float) or isinstance(phi_G, int): - phiG = np.ones_like(alpha_x) * float(phi_G) - q = np.ones_like(alpha_x) * float(q) - - for i, (x_i, y_i, phi_i, q_i) in \ - enumerate(zip(x.ravel(), y.ravel(), phiG.ravel(), q.ravel())): - - fxi, fyi = self._compute_derivative_atcoord(x_i, y_i, n_sersic, R_sersic, k_eff, - phi_i, q_i, center_x=center_x, center_y = center_y) - - alpha_x[i], alpha_y[i] = fxi, fyi - - alpha_x = alpha_x.reshape(shape0) - alpha_y = alpha_y.reshape(shape0) - - alpha_x, alpha_y = self._coord_rotate(alpha_x, alpha_y, -phi_G, 0, 0) - - return alpha_x, alpha_y
- -
[docs] def hessian(self, x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y = 0): - """ - returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - alpha_ra, alpha_dec = self.derivatives(x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x, center_y) - diff = 0.000001 - alpha_ra_dx, alpha_dec_dx = self.derivatives(x + diff, y, n_sersic, R_sersic, k_eff, e1, e2, center_x, center_y) - alpha_ra_dy, alpha_dec_dy = self.derivatives(x, y + diff, n_sersic, R_sersic, k_eff, e1, e2, center_x, center_y) - - f_xx = (alpha_ra_dx - alpha_ra)/diff - f_xy = (alpha_ra_dy - alpha_ra)/diff - f_yx = (alpha_dec_dx - alpha_dec)/diff - f_yy = (alpha_dec_dy - alpha_dec)/diff - - return f_xx, f_xy, f_yx, f_yy
- -
[docs] def projected_mass(self, x, y, q, n_sersic, R_sersic, k_eff, u = 1, power = 1): - - b_n = self._sersic.b_n(n_sersic) - - elliptical_coord = self._elliptical_coord_u(x, y, u, q) ** power - elliptical_coord *= R_sersic ** -power - - exponent = -b_n * (elliptical_coord**(1./n_sersic) - 1) - - return k_eff * np.exp(exponent)
- - def _integrand_J(self, u, x, y, n_sersic, q, R_sersic, k_eff, n_integral): - - kappa = self.projected_mass(x, y, q, n_sersic, R_sersic, k_eff, u = u, power=1) - - power = -(n_integral + 0.5) - - return kappa * (1 - (1 - q**2)*u) ** power - - def _integrand_I(self, u, x, y, q, n_sersic, R_sersic, keff, centerx, centery): - - ellip_coord = self._elliptical_coord_u(x, y, u, q) - - def_angle_circular = self._sersic.alpha_abs(ellip_coord, 0, n_sersic, R_sersic, keff, centerx, centery) - - return ellip_coord * def_angle_circular * (1 - (1-q**2)*u) ** -0.5 * u ** -1 - - def _compute_derivative_atcoord(self, x, y, n_sersic, R_sersic, k_eff, phi_G, q, center_x=0, center_y = 0): - - alpha_x = x * q * quad(self._integrand_J, 0, 1, args=(x, y, n_sersic, q, R_sersic, k_eff, 0))[0] - alpha_y = y * q * quad(self._integrand_J, 0, 1, args=(x, y, n_sersic, q, R_sersic, k_eff, 1))[0] - - return alpha_x, alpha_y - - @staticmethod - def _elliptical_coord_u(x, y, u, q): - - fac = 1 - (1 - q**2) * u - - return (u * (x**2 + y**2 * fac**-1) )**0.5 - - @staticmethod - def _coord_rotate(x, y, phi_G, center_x, center_y): - - x_shift = x - center_x - y_shift = y - center_y - cos_phi = np.cos(phi_G) - sin_phi = np.sin(phi_G) - - x_ = cos_phi * x_shift + sin_phi * y_shift - y_ = -sin_phi * x_shift + cos_phi * y_shift - - return x_, y_
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sersic_ellipse_potential.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sersic_ellipse_potential.html deleted file mode 100644 index d0a611d69..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sersic_ellipse_potential.html +++ /dev/null @@ -1,149 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.sersic_ellipse_potential — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.sersic_ellipse_potential

-__author__ = 'sibirrer'
-#this file contains a class to make a gaussian
-
-import numpy as np
-from lenstronomy.LensModel.Profiles.sersic import Sersic
-import lenstronomy.Util.param_util as param_util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['SersicEllipse']
-
-
-
[docs]class SersicEllipse(LensProfileBase): - """ - this class contains functions to evaluate a Sersic mass profile: https://arxiv.org/pdf/astro-ph/0311559.pdf - """ - param_names = ['k_eff', 'R_sersic', 'n_sersic', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'k_eff': 0, 'R_sersic': 0, 'n_sersic': 0.5, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'k_eff': 10, 'R_sersic': 100, 'n_sersic': 8, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.sersic = Sersic() - self._diff = 0.000001 - super(SersicEllipse, self).__init__() - -
[docs] def function(self, x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y=0): - """ - returns Gaussian - """ - # phi_G, q = param_util.ellipticity2phi_q(e1, e2) - x_, y_ = param_util.transform_e1e2_square_average(x, y, e1, e2, center_x, center_y) - # x_, y_ = self._coord_transf(x, y, q, phi_G, center_x, center_y) - f_ = self.sersic.function(x_, y_, n_sersic, R_sersic, k_eff) - return f_
- -
[docs] def derivatives(self, x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y=0): - """ - returns df/dx and df/dy of the function - """ - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - e = param_util.q2e(q) - # e = abs(1. - q) - cos_phi = np.cos(phi_G) - sin_phi = np.sin(phi_G) - x_, y_ = param_util.transform_e1e2_square_average(x, y, e1, e2, center_x, center_y) - # x_, y_ = self._coord_transf(x, y, q, phi_G, center_x, center_y) - f_x_prim, f_y_prim = self.sersic.derivatives(x_, y_, n_sersic, R_sersic, k_eff) - f_x_prim *= np.sqrt(1 - e) - f_y_prim *= np.sqrt(1 + e) - f_x = cos_phi*f_x_prim-sin_phi*f_y_prim - f_y = sin_phi*f_x_prim+cos_phi*f_y_prim - return f_x, f_y
- -
[docs] def hessian(self, x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y=0): - """ - returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - alpha_ra, alpha_dec = self.derivatives(x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x, center_y) - diff = self._diff - alpha_ra_dx, alpha_dec_dx = self.derivatives(x + diff, y, n_sersic, R_sersic, k_eff, e1, e2, center_x, center_y) - alpha_ra_dy, alpha_dec_dy = self.derivatives(x, y + diff, n_sersic, R_sersic, k_eff, e1, e2, center_x, center_y) - - f_xx = (alpha_ra_dx - alpha_ra)/diff - f_xy = (alpha_ra_dy - alpha_ra)/diff - f_yx = (alpha_dec_dx - alpha_dec)/diff - f_yy = (alpha_dec_dy - alpha_dec)/diff - - return f_xx, f_xy, f_yx, f_yy
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sersic_utils.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sersic_utils.html deleted file mode 100644 index c25f681c1..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sersic_utils.html +++ /dev/null @@ -1,304 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.sersic_utils — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.sersic_utils

-import scipy.special as special
-import numpy as np
-import scipy
-from lenstronomy.Util import param_util
-
-__all__ = ['SersicUtil']
-
-
-
[docs]class SersicUtil(object): - - _s = 0.00001 - - def __init__(self, smoothing=_s, sersic_major_axis=False): - """ - - :param smoothing: smoothing scale of the innermost part of the profile (for numerical reasons) - :param sersic_major_axis: boolean; if True, defines the half-light radius of the Sersic light profile along - the semi-major axis (which is the Galfit convention) - if False, uses the product average of semi-major and semi-minor axis as the convention - (default definition for all light profiles in lenstronomy other than the Sersic profile) - """ - self._smoothing = smoothing - self._sersic_major_axis = sersic_major_axis - -
[docs] def k_bn(self, n, Re): - """ - returns normalisation of the sersic profile such that Re is the half light radius given n_sersic slope - """ - bn = self.b_n(n) - k = bn*Re**(-1./n) - return k, bn
- -
[docs] def k_Re(self, n, k): - """ - - """ - bn = self.b_n(n) - Re = (bn/k)**n - return Re
- -
[docs] @staticmethod - def b_n(n): - """ - b(n) computation. This is the approximation of the exact solution to the relation, 2*incomplete_gamma_function(2n; b_n) = Gamma_function(2*n). - :param n: the sersic index - :return: - """ - bn = 1.9992*n - 0.3271 - bn = np.maximum(bn, 0.00001) # make sure bn is strictly positive as a save guard for very low n_sersic - return bn
- -
[docs] def get_distance_from_center(self, x, y, e1, e2, center_x, center_y): - """ - Get the distance from the center of Sersic, accounting for orientation and axis ratio - :param x: - :param y: - :param e1: eccentricity - :param e2: eccentricity - :param center_x: center x of sersic - :param center_y: center y of sersic - """ - - if self._sersic_major_axis: - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - x_shift = x - center_x - y_shift = y - center_y - cos_phi = np.cos(phi_G) - sin_phi = np.sin(phi_G) - xt1 = cos_phi*x_shift+sin_phi*y_shift - xt2 = -sin_phi*x_shift+cos_phi*y_shift - xt2difq2 = xt2/(q*q) - r = np.sqrt(xt1*xt1+xt2*xt2difq2) - else: - x_, y_ = param_util.transform_e1e2_product_average(x, y, e1, e2, center_x, center_y) - r = np.sqrt(x_**2 + y_**2) - return r
- - def _x_reduced(self, x, y, n_sersic, r_eff, center_x, center_y): - """ - coordinate transform to normalized radius - :param x: - :param y: - :param center_x: - :param center_y: - :return: - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - if isinstance(r, int) or isinstance(r, float): - r = max(self._s, r) - else: - r[r < self._s] = self._s - x_reduced = (r/r_eff)**(1./n_sersic) - return x_reduced - - def _alpha_eff(self, r_eff, n_sersic, k_eff): - """ - deflection angle at r_eff - :param r_eff: - :param n_sersic: - :param k_eff: - :return: - """ - b = self.b_n(n_sersic) - alpha_eff = n_sersic * r_eff * k_eff * b**(-2*n_sersic) * np.exp(b) * special.gamma(2*n_sersic) - return -alpha_eff - -
[docs] def alpha_abs(self, x, y, n_sersic, r_eff, k_eff, center_x=0, center_y=0): - """ - - :param x: - :param y: - :param n_sersic: - :param r_eff: - :param k_eff: - :param center_x: - :param center_y: - :return: - """ - n = n_sersic - x_red = self._x_reduced(x, y, n_sersic, r_eff, center_x, center_y) - b = self.b_n(n_sersic) - a_eff = self._alpha_eff(r_eff, n_sersic, k_eff) - alpha = 2. * a_eff * x_red ** (-n) * (special.gammainc(2 * n, b * x_red)) - return alpha
- -
[docs] def d_alpha_dr(self, x, y, n_sersic, r_eff, k_eff, center_x=0, center_y=0): - """ - - :param x: - :param y: - :param n_sersic: - :param r_eff: - :param k_eff: - :param center_x: - :param center_y: - :return: - """ - _dr = 0.00001 - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - alpha = self.alpha_abs(r, 0, n_sersic, r_eff, k_eff) - alpha_dr = self.alpha_abs(r+_dr, 0, n_sersic, r_eff, k_eff) - d_alpha_dr = (alpha_dr - alpha)/_dr - return d_alpha_dr
- -
[docs] def density(self, x, y, n_sersic, r_eff, k_eff, center_x=0, center_y=0): - """ - de-projection of the Sersic profile based on - Prugniel & Simien (1997) - :return: - """ - raise ValueError("not implemented! Use a Multi-Gaussian-component decomposition.")
- - def _total_flux(self, r_eff, I_eff, n_sersic): - """ - computes total flux of a round Sersic profile - - :param r_eff: projected half light radius - :param I_eff: surface brightness at r_eff (in same units as r_eff) - :param n_sersic: Sersic index - :return: integrated flux to infinity - """ - bn = self.b_n(n_sersic) - return I_eff * r_eff**2 * 2 * np.pi * n_sersic * np.exp(bn) / bn**(2*n_sersic) * scipy.special.gamma(2*n_sersic) - -
[docs] def total_flux(self, amp, R_sersic, n_sersic, e1=0, e2=0, **kwargs): - """ - computes analytical integral to compute total flux of the Sersic profile - - :param amp: amplitude parameter in Sersic function (surface brightness at R_sersic - :param R_sersic: half-light radius in semi-major axis - :param n_sersic: Sersic index - :param e1: eccentricity - :param e2: eccentricity - :return: Analytic integral of the total flux of the Sersic profile - """ - # compute product average half-light radius - if self._sersic_major_axis: - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - r_eff = R_sersic * np.sqrt(q) # translate semi-major axis R_eff into product averaged definition for circularization - else: - r_eff = R_sersic - return self._total_flux(r_eff=r_eff, I_eff=amp, n_sersic=n_sersic)
- - def _R_stable(self, R): - """ - Floor R_ at self._smoothing for numerical stability - :param R: radius - :return: smoothed and stabilized radius - """ - return np.maximum(self._smoothing, R) - - def _r_sersic(self, R, R_sersic, n_sersic, max_R_frac=100.0, alpha=1.0, R_break=0.0): - """ - - :param R: radius (array or float) - :param R_sersic: Sersic radius (half-light radius) - :param n_sersic: Sersic index (float) - :param max_R_frac: maximum window outside of which the mass is zeroed, in units of R_sersic (float) - :return: kernel of the Sersic surface brightness at R - """ - - R_ = self._R_stable(R) - R_sersic_ = self._R_stable(R_sersic) - bn = self.b_n(n_sersic) - R_frac = R_ / R_sersic_ - #R_frac = R_frac.astype(np.float32) - if isinstance(R_, int) or isinstance(R_, float): - if R_frac > max_R_frac: - result = 0 - else: - exponent = -bn * (R_frac ** (1. / n_sersic) - 1.) - result = np.exp(exponent) - else: - R_frac_real = R_frac[R_frac <= max_R_frac] - exponent = -bn * (R_frac_real ** (1. / n_sersic) - 1.) - result = np.zeros_like(R_) - result[R_frac <= max_R_frac] = np.exp(exponent) - return np.nan_to_num(result)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/shapelet_pot_cartesian.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/shapelet_pot_cartesian.html deleted file mode 100644 index 42ab86bf2..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/shapelet_pot_cartesian.html +++ /dev/null @@ -1,330 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.shapelet_pot_cartesian — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.shapelet_pot_cartesian

-__author__ = 'sibirrer'
-
-# description of the polar shapelets in potential space
-
-import numpy as np
-import math
-import numpy.polynomial.hermite as hermite
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['CartShapelets']
-
-
-
[docs]class CartShapelets(LensProfileBase): - """ - this class contains the function and the derivatives of the cartesian shapelets - """ - param_names = ['coeffs', 'beta', 'center_x', 'center_y'] - lower_limit_default = {'coeffs': [0], 'beta': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'coeffs': [100], 'beta': 100, 'center_x': 100, 'center_y': 100} - -
[docs] def function(self, x, y, coeffs, beta, center_x=0, center_y=0): - shapelets = self._createShapelet(coeffs) - n_order = self._get_num_n(len(coeffs)) - n = len(np.atleast_1d(x)) - if n <= 1: - f_ = self._shapeletOutput(x, y, beta, shapelets, precalc=False) - else: - H_x, H_y = self.pre_calc(x, y, beta, n_order, center_x, center_y) - f_ = self._shapeletOutput(H_x, H_y, beta, shapelets) - return f_
- -
[docs] def derivatives(self, x, y, coeffs, beta, center_x=0, center_y=0): - """ - returns df/dx and df/dy of the function - """ - shapelets = self._createShapelet(coeffs) - n_order = self._get_num_n(len(coeffs)) - dx_shapelets = self._dx_shapelets(shapelets, beta) - dy_shapelets = self._dy_shapelets(shapelets, beta) - n = len(np.atleast_1d(x)) - if n <= 1: - f_x = self._shapeletOutput(x, y, beta, dx_shapelets, precalc=False) - f_y = self._shapeletOutput(x, y, beta, dy_shapelets, precalc=False) - else: - H_x, H_y = self.pre_calc(x, y, beta, n_order+1, center_x, center_y) - f_x = self._shapeletOutput(H_x, H_y, beta, dx_shapelets) - f_y = self._shapeletOutput(H_x, H_y, beta, dy_shapelets) - return f_x, f_y
- -
[docs] def hessian(self, x, y, coeffs, beta, center_x=0, center_y=0): - """ - returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - shapelets = self._createShapelet(coeffs) - n_order = self._get_num_n(len(coeffs)) - dxx_shapelets = self._dxx_shapelets(shapelets, beta) - dyy_shapelets = self._dyy_shapelets(shapelets, beta) - dxy_shapelets = self._dxy_shapelets(shapelets, beta) - n = len(np.atleast_1d(x)) - if n <= 1: - f_xx = self._shapeletOutput(x, y, beta, dxx_shapelets, precalc=False) - f_yy = self._shapeletOutput(x, y, beta, dyy_shapelets, precalc=False) - f_xy = self._shapeletOutput(x, y, beta, dxy_shapelets, precalc=False) - else: - H_x, H_y = self.pre_calc(x, y, beta, n_order+2, center_x, center_y) - f_xx = self._shapeletOutput(H_x, H_y, beta, dxx_shapelets) - f_yy = self._shapeletOutput(H_x, H_y, beta, dyy_shapelets) - f_xy = self._shapeletOutput(H_x, H_y, beta, dxy_shapelets) - return f_xx, f_xy, f_xy, f_yy
- - def _createShapelet(self, coeffs): - """ - returns a shapelet array out of the coefficients *a, up to order l - - :param num_l: order of shapelets - :type num_l: int. - :param coeff: shapelet coefficients - :type coeff: floats - :returns: complex array - :raises: AttributeError, KeyError - """ - n_coeffs = len(coeffs) - num_n = self._get_num_n(n_coeffs) - shapelets=np.zeros((num_n+1, num_n+1)) - n = 0 - k = 0 - for coeff in coeffs: - shapelets[n-k][k] = coeff - k += 1 - if k == n + 1: - n += 1 - k = 0 - return shapelets - - def _shapeletOutput(self, x, y, beta, shapelets, precalc=True): - """ - returns the the numerical values of a set of shapelets at polar coordinates - :param shapelets: set of shapelets [l=,r=,a_lr=] - :type shapelets: array of size (n,3) - :param coordPolar: set of coordinates in polar units - :type coordPolar: array of size (n,2) - :returns: array of same size with coords [r,phi] - :raises: AttributeError, KeyError - """ - n = len(np.atleast_1d(x)) - if n <= 1: - values = 0. - else: - values = np.zeros(len(x[0])) - n = 0 - k = 0 - i = 0 - num_n = len(shapelets) - while i < num_n * (num_n+1)/2: - values += self._function(x, y, shapelets[n-k][k], beta, n-k, k, precalc=precalc) - k += 1 - if k == n + 1: - n += 1 - k = 0 - i += 1 - return values - - def _function(self, x, y, amp, beta, n1, n2, center_x=0, center_y=0, precalc=False): - """ - - :param amp: amplitude of shapelet - :param beta: scale factor of shapelet - :param n1: x-order - :param n2: y-order - :param center_x: center in x - :param center_y: center in y - :return: - """ - if precalc: - return amp * x[n1] * y[n2] / beta - x_ = x - center_x - y_ = y - center_y - return amp * self.phi_n(n1, x_/beta) * self.phi_n(n2, y_/beta) /beta - - def _dx_shapelets(self, shapelets, beta): - """ - computes the derivative d/dx of the shapelet coeffs - :param shapelets: - :param beta: - :return: - """ - num_n = len(shapelets) - dx = np.zeros((num_n+1, num_n+1)) - for n1 in range(num_n): - for n2 in range(num_n): - amp = shapelets[n1][n2] - dx[n1+1][n2] -= np.sqrt((n1+1)/2.) * amp - if n1 > 0: - dx[n1-1][n2] += np.sqrt(n1/2.) * amp - return dx/beta - - def _dy_shapelets(self, shapelets, beta): - """ - computes the derivative d/dx of the shapelet coeffs - :param shapelets: - :param beta: - :return: - """ - num_n = len(shapelets) - dy = np.zeros((num_n+1, num_n+1)) - for n1 in range(num_n): - for n2 in range(num_n): - amp = shapelets[n1][n2] - dy[n1][n2+1] -= np.sqrt((n2+1)/2.) * amp - if n2 > 0: - dy[n1][n2-1] += np.sqrt(n2/2.) * amp - return dy/beta - - def _dxx_shapelets(self, shapelets, beta): - dx_shapelets = self._dx_shapelets(shapelets, beta) - return self._dx_shapelets(dx_shapelets, beta) - - def _dyy_shapelets(self, shapelets, beta): - dy_shapelets = self._dy_shapelets(shapelets, beta) - return self._dy_shapelets(dy_shapelets, beta) - - def _dxy_shapelets(self, shapelets, beta): - dy_shapelets = self._dy_shapelets(shapelets, beta) - return self._dx_shapelets(dy_shapelets, beta) - -
[docs] def H_n(self, n, x): - """ - constructs the Hermite polynomial of order n at position x (dimensionless) - - :param n: The n'the basis function. - :type name: int. - :param x: 1-dim position (dimensionless) - :type state: float or numpy array. - :returns: array-- H_n(x). - :raises: AttributeError, KeyError - """ - n_array = np.zeros(n+1) - n_array[n] = 1 - return hermite.hermval(x, n_array, tensor=False) #attention, this routine calculates every single hermite polynomial and multiplies it with zero (exept the right one)
- -
[docs] def phi_n(self,n,x): - """ - constructs the 1-dim basis function (formula (1) in Refregier et al. 2001) - - :param n: The n'the basis function. - :type name: int. - :param x: 1-dim position (dimensionless) - :type state: float or numpy array. - :returns: array-- phi_n(x). - :raises: AttributeError, KeyError - """ - prefactor = 1./np.sqrt(2**n*np.sqrt(np.pi)*math.factorial(n)) - return prefactor*self.H_n(n,x)*np.exp(-x**2/2.)
- -
[docs] def pre_calc(self, x, y, beta, n_order, center_x, center_y): - """ - calculates the H_n(x) and H_n(y) for a given x-array and y-array - :param x: - :param y: - :param amp: - :param beta: - :param n_order: - :param center_x: - :param center_y: - :return: list of H_n(x) and H_n(y) - """ - - n = len(np.atleast_1d(x)) - x_ = x - center_x - y_ = y - center_y - H_x = np.empty((n_order+1, n)) - H_y = np.empty((n_order+1, n)) - for n in range(0,n_order+1): - prefactor = 1./np.sqrt(2**n*np.sqrt(np.pi)*math.factorial(n)) - n_array = np.zeros(n+1) - n_array[n] = 1 - H_x[n] = hermite.hermval(x_/beta, n_array) * prefactor * np.exp(-(x_/beta)**2/2.) - H_y[n] = hermite.hermval(y_/beta, n_array) * prefactor * np.exp(-(y_/beta)**2/2.) - return H_x, H_y
- - def _get_num_n(self, n_coeffs): - """ - - :param n_coeffs: number of coeffs - :return: number of n_l of order of the shapelets - """ - num_n = round((math.sqrt(8*n_coeffs + 1) -1)/2. +0.499) - return int(num_n)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/shapelet_pot_polar.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/shapelet_pot_polar.html deleted file mode 100644 index bf932e752..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/shapelet_pot_polar.html +++ /dev/null @@ -1,317 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.shapelet_pot_polar — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.shapelet_pot_polar

-__author__ = 'sibirrer'
-
-# description of the polar shapelets in potential space
-
-import numpy as np
-import scipy.special
-import math
-
-import lenstronomy.Util.param_util as param_util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['PolarShapelets']
-
-
-
[docs]class PolarShapelets(LensProfileBase): - """ - this class contains the function and the derivatives of the Singular Isothermal Sphere - """ - param_names = ['coeffs', 'beta', 'center_x', 'center_y'] - lower_limit_default = {'coeffs': [0], 'beta': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'coeffs': [100], 'beta': 100, 'center_x': 100, 'center_y': 100} - - def __init__(self): - n = 10 - self.poly = [[[] for i in range(n)] for j in range(n)] - for i in range(0, n): - for j in range(0, n): - self.poly[i][j] = scipy.special.genlaguerre(i, j) - super(PolarShapelets, self).__init__() - -
[docs] def function(self, x, y, coeffs, beta, center_x=0, center_y=0): - shapelets = self._createShapelet(coeffs) - r, phi = param_util.cart2polar(x, y, center_x=center_x, center_y=center_y) - f_ = self._shapeletOutput(r, phi, beta, shapelets) - return f_
- -
[docs] def derivatives(self, x, y, coeffs, beta, center_x=0, center_y=0): - """ - returns df/dx and df/dy of the function - """ - shapelets = self._createShapelet(coeffs) - r, phi = param_util.cart2polar(x, y, center_x=center_x, center_y=center_y) - alpha1_shapelets, alpha2_shapelets = self._alphaShapelets(shapelets, beta) - f_x = self._shapeletOutput(r, phi, beta, alpha1_shapelets) - f_y = self._shapeletOutput(r, phi, beta, alpha2_shapelets) - return f_x, f_y
- -
[docs] def hessian(self, x, y, coeffs, beta, center_x=0, center_y=0): - """ - returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - shapelets = self._createShapelet(coeffs) - r, phi = param_util.cart2polar(x, y, center_x=center_x, center_y=center_y) - kappa_shapelets=self._kappaShapelets(shapelets, beta) - gamma1_shapelets, gamma2_shapelets=self._gammaShapelets(shapelets, beta) - kappa_value=self._shapeletOutput(r, phi, beta, kappa_shapelets) - gamma1_value=self._shapeletOutput(r, phi, beta, gamma1_shapelets) - gamma2_value=self._shapeletOutput(r, phi, beta, gamma2_shapelets) - f_xx = kappa_value + gamma1_value - f_xy = gamma2_value - f_yy = kappa_value - gamma1_value - return f_xx, f_xy, f_xy, f_yy
- - def _createShapelet(self,coeff): - """ - returns a shapelet array out of the coefficients *a, up to order l - - :param num_l: order of shapelets - :type num_l: int. - :param coeff: shapelet coefficients - :type coeff: floats - :returns: complex array - :raises: AttributeError, KeyError - """ - n_coeffs = len(coeff) - num_l = self._get_num_l(n_coeffs) - shapelets=np.zeros((num_l+1,num_l+1),'complex') - nl=0 - k=0 - i=0 - while i < len(coeff): - if i%2==0: - shapelets[nl][k]+=coeff[i]/2. - shapelets[k][nl]+=coeff[i]/2. - if k==nl: - nl+=1 - k=0 - i+=1 - continue - else: - k+=1 - i+=1 - continue - else: - shapelets[nl][k] += 1j*coeff[i]/2. - shapelets[k][nl] -= 1j*coeff[i]/2. - i+=1 - return shapelets - - def _shapeletOutput(self, r, phi, beta, shapelets): - """ - returns the the numerical values of a set of shapelets at polar coordinates - :param shapelets: set of shapelets [l=,r=,a_lr=] - :type shapelets: array of size (n,3) - :param coordPolar: set of coordinates in polar units - :type coordPolar: array of size (n,2) - :returns: array of same size with coords [r,phi] - :raises: AttributeError, KeyError - """ - if type(r) == float or type(r) == int or type(r) == type(np.float64(1)) or len(r) <= 1: - values = 0. - else: - values = np.zeros(len(r), 'complex') - for nl in range(0,len(shapelets)): #sum over different shapelets - for nr in range(0,len(shapelets)): - value = shapelets[nl][nr]*self._chi_lr(r, phi, nl, nr, beta) - values += value - return values.real - - def _chi_lr(self, r, phi, nl, nr, beta): - """ - computes the generalized polar basis function in the convention of Massey&Refregier eqn 8 - - :param nl: left basis - :type nl: int - :param nr: right basis - :type nr: int - :param beta: beta --the characteristic scale typically choosen to be close to the size of the object. - :type beta: float. - :param coord: coordinates [r,phi] - :type coord: array(n,2) - :returns: values at positions of coordinates. - :raises: AttributeError, KeyError - """ - m=int((nr-nl).real) - n=int((nr+nl).real) - p=int((n-abs(m))/2) - p2=int((n+abs(m))/2) - q=int(abs(m)) - if p % 2==0: #if p is even - prefac=1 - else: - prefac=-1 - prefactor=prefac/beta**(abs(m)+1)*np.sqrt(math.factorial(p)/(np.pi*math.factorial(p2))) - poly=self.poly[p][q] - return prefactor*r**q*poly((r/beta)**2)*np.exp(-(r/beta)**2/2)*np.exp(-1j*m*phi) - - def _kappaShapelets(self, shapelets, beta): - """ - calculates the convergence kappa given lensing potential shapelet coefficients (laplacian/2) - :param shapelets: set of shapelets [l=,r=,a_lr=] - :type shapelets: array of size (n,3) - :returns: set of kappa shapelets. - :raises: AttributeError, KeyError - """ - output=np.zeros((len(shapelets)+1,len(shapelets)+1),'complex') - for nl in range(0,len(shapelets)): - for nr in range(0,len(shapelets)): - a_lr=shapelets[nl][nr] - if nl>0: - output[nl-1][nr+1]+=a_lr*np.sqrt(nl*(nr+1))/2 - if nr>0: - output[nl-1][nr-1]+=a_lr*np.sqrt(nl*nr)/2 - output[nl+1][nr+1]+=a_lr*np.sqrt((nl+1)*(nr+1))/2 - if nr>0: - output[nl+1][nr-1]+=a_lr*np.sqrt((nl+1)*nr)/2 - return output/beta**2 - - def _alphaShapelets(self,shapelets, beta): - """ - calculates the deflection angles given lensing potential shapelet coefficients (laplacian/2) - :param shapelets: set of shapelets [l=,r=,a_lr=] - :type shapelets: array of size (n,3) - :returns: set of alpha shapelets. - :raises: AttributeError, KeyError - """ - output_x = np.zeros((len(shapelets)+1, len(shapelets)+1), 'complex') - output_y = np.zeros((len(shapelets)+1, len(shapelets)+1), 'complex') - for nl in range(0,len(shapelets)): - for nr in range(0,len(shapelets)): - a_lr=shapelets[nl][nr] - output_x[nl][nr+1]-=a_lr*np.sqrt(nr+1)/2 - output_y[nl][nr+1]-=a_lr*np.sqrt(nr+1)/2*1j - output_x[nl+1][nr]-=a_lr*np.sqrt(nl+1)/2 - output_y[nl+1][nr]+=a_lr*np.sqrt(nl+1)/2*1j - if nl>0: - output_x[nl-1][nr]+=a_lr*np.sqrt(nl)/2 - output_y[nl-1][nr]-=a_lr*np.sqrt(nl)/2*1j - if nr>0: - output_x[nl][nr-1]+=a_lr*np.sqrt(nr)/2 - output_y[nl][nr-1]+=a_lr*np.sqrt(nr)/2*1j - return output_x/beta,output_y/beta #attention complex numbers!!!! - - def _gammaShapelets(self,shapelets, beta): - """ - calculates the shear gamma given lensing potential shapelet coefficients - :param shapelets: set of shapelets [l=,r=,a_lr=] - :type shapelets: array of size (n,3) - :returns: set of alpha shapelets. - :raises: AttributeError, KeyError - """ - output_x = np.zeros((len(shapelets)+2,len(shapelets)+2),'complex') - output_y = np.zeros((len(shapelets)+2,len(shapelets)+2),'complex') - for nl in range(0, len(shapelets)): - for nr in range(0, len(shapelets)): - a_lr = shapelets[nl][nr] - output_x[nl+2][nr] += a_lr*np.sqrt((nl+1)*(nl+2))/2 - output_x[nl][nr+2] += a_lr*np.sqrt((nr+1)*(nr+2))/2 - output_x[nl][nr] += a_lr*(1-(nr+1)-(nl+1)) - if nl>1: - output_x[nl-2][nr] += a_lr*np.sqrt((nl)*(nl-1))/2 - if nr>1: - output_x[nl][nr-2] += a_lr*np.sqrt((nr)*(nr-1))/2 - - output_y[nl+2][nr] += a_lr*np.sqrt((nl+1)*(nl+2))*1j/4 - output_y[nl][nr+2] -= a_lr*np.sqrt((nr+1)*(nr+2))*1j/4 - if nl>0: - output_y[nl-1][nr+1] += a_lr*np.sqrt((nl)*(nr+1))*1j/2 - if nr>0: - output_y[nl+1][nr-1] -= a_lr*np.sqrt((nr)*(nl+1))*1j/2 - if nl>1: - output_y[nl-2][nr] -= a_lr*np.sqrt((nl)*(nl-1))*1j/4 - if nr>1: - output_y[nl][nr-2] += a_lr*np.sqrt((nr)*(nr-1))*1j/4 - return output_x/beta**2, output_y/beta**2 #attention complex numbers!!!! - - @staticmethod - def _get_num_l(n_coeffs): - """ - - :param n_coeffs: number of coeffs - :return: number of n_l of order of the shapelets - """ - num_l = int(round((math.sqrt(8*n_coeffs + 9)-3)/2 +0.499)) - return num_l
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/shear.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/shear.html deleted file mode 100644 index 55744049b..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/shear.html +++ /dev/null @@ -1,283 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.shear — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.shear

-__author__ = 'sibirrer'
-
-import lenstronomy.Util.param_util as param_util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-from lenstronomy.LensModel.Profiles.convergence import Convergence
-import numpy as np
-
-__all__ = ['Shear', 'ShearGammaPsi', 'ShearReduced']
-
-
-
[docs]class Shear(LensProfileBase): - """ - class for external shear gamma1, gamma2 expression - """ - param_names = ['gamma1', 'gamma2', 'ra_0', 'dec_0'] - lower_limit_default = {'gamma1': -0.5, 'gamma2': -0.5, 'ra_0': -100, 'dec_0': -100} - upper_limit_default = {'gamma1': 0.5, 'gamma2': 0.5, 'ra_0': 100, 'dec_0': 100} - -
[docs] def function(self, x, y, gamma1, gamma2, ra_0=0, dec_0=0): - """ - - :param x: x-coordinate (angle) - :param y: y0-coordinate (angle) - :param gamma1: shear component - :param gamma2: shear component - :param ra_0: x/ra position where shear deflection is 0 - :param dec_0: y/dec position where shear deflection is 0 - :return: lensing potential - """ - x_ = x - ra_0 - y_ = y - dec_0 - f_ = 1/2. * (gamma1 * x_ * x_ + 2 * gamma2 * x_ * y_ - gamma1 * y_ * y_) - return f_
- -
[docs] def derivatives(self, x, y, gamma1, gamma2, ra_0=0, dec_0=0): - """ - - :param x: x-coordinate (angle) - :param y: y0-coordinate (angle) - :param gamma1: shear component - :param gamma2: shear component - :param ra_0: x/ra position where shear deflection is 0 - :param dec_0: y/dec position where shear deflection is 0 - :return: deflection angles - """ - x_ = x - ra_0 - y_ = y - dec_0 - f_x = gamma1 * x_ + gamma2 * y_ - f_y = +gamma2 * x_ - gamma1 * y_ - return f_x, f_y
- -
[docs] def hessian(self, x, y, gamma1, gamma2, ra_0=0, dec_0=0): - """ - - :param x: x-coordinate (angle) - :param y: y0-coordinate (angle) - :param gamma1: shear component - :param gamma2: shear component - :param ra_0: x/ra position where shear deflection is 0 - :param dec_0: y/dec position where shear deflection is 0 - :return: f_xx, f_xy, f_yx, f_yy - """ - gamma1 = gamma1 - gamma2 = gamma2 - kappa = 0 - f_xx = kappa + gamma1 - f_yy = kappa - gamma1 - f_xy = gamma2 - return f_xx, f_xy, f_xy, f_yy
- - -
[docs]class ShearGammaPsi(LensProfileBase): - """ - class to model a shear field with shear strength and direction. The translation ot the cartesian shear distortions - is as follow: - - .. math:: - \\gamma_1 = \\gamma_{ext} \\cos(2 \\phi_{ext} - \\gamma_2 = \\gamma_{ext} \\sin(2 \\phi_{ext} - - """ - param_names = ['gamma_ext', 'psi_ext', 'ra_0', 'dec_0'] - lower_limit_default = {'gamma_ext': 0, 'psi_ext': -np.pi, 'ra_0': -100, 'dec_0': -100} - upper_limit_default = {'gamma_ext': 1, 'psi_ext': np.pi, 'ra_0': 100, 'dec_0': 100} - - def __init__(self): - self._shear_e1e2 = Shear() - super(ShearGammaPsi, self).__init__() - -
[docs] @staticmethod - def function(x, y, gamma_ext, psi_ext, ra_0=0, dec_0=0): - """ - - :param x: x-coordinate (angle) - :param y: y0-coordinate (angle) - :param gamma_ext: shear strength - :param psi_ext: shear angle (radian) - :param ra_0: x/ra position where shear deflection is 0 - :param dec_0: y/dec position where shear deflection is 0 - :return: - """ - # change to polar coordinate - r, phi = param_util.cart2polar(x-ra_0, y-dec_0) - f_ = 1. / 2 * gamma_ext * r ** 2 * np.cos(2 * (phi - psi_ext)) - return f_
- -
[docs] def derivatives(self, x, y, gamma_ext, psi_ext, ra_0=0, dec_0=0): - # rotation angle - gamma1, gamma2 = param_util.shear_polar2cartesian(psi_ext, gamma_ext) - return self._shear_e1e2.derivatives(x, y, gamma1, gamma2, ra_0, dec_0)
- -
[docs] def hessian(self, x, y, gamma_ext, psi_ext, ra_0=0, dec_0=0): - gamma1, gamma2 = param_util.shear_polar2cartesian(psi_ext, gamma_ext) - return self._shear_e1e2.hessian(x, y, gamma1, gamma2, ra_0, dec_0)
- - -
[docs]class ShearReduced(LensProfileBase): - """ - reduced shear distortions :math:`\\gamma' = \\gamma / (1-\\kappa)`. - This distortion keeps the magnification as unity and, thus, does not change the size of apparent objects. - To keep the magnification at unity, it requires - - .. math:: - (1-\\kappa)^2 - \\gamma_1^2 - \\gamma_2^ = 1 - - Thus, for given pair of reduced shear :math:`(\\gamma'_1, \\gamma'_2)`, an additional convergence term is calculated - and added to the lensing distortions. - """ - param_names = ['gamma1', 'gamma2', 'ra_0', 'dec_0'] - lower_limit_default = {'gamma1': -0.5, 'gamma2': -0.5, 'ra_0': -100, 'dec_0': -100} - upper_limit_default = {'gamma1': 0.5, 'gamma2': 0.5, 'ra_0': 100, 'dec_0': 100} - - def __init__(self): - self._shear = Shear() - self._convergence = Convergence() - super(ShearReduced, self).__init__() - - @staticmethod - def _kappa_reduced(gamma1, gamma2): - """ - compute convergence such that magnification is unity - - :param gamma1: reduced shear - :param gamma2: reduced shear - :return: kappa - """ - kappa = 1 - 1. / np.sqrt(1 - gamma1**2 - gamma2**2) - gamma1_ = (1-kappa) * gamma1 - gamma2_ = (1-kappa) * gamma2 - return kappa, gamma1_, gamma2_ - -
[docs] def function(self, x, y, gamma1, gamma2, ra_0=0, dec_0=0): - """ - - :param x: x-coordinate (angle) - :param y: y0-coordinate (angle) - :param gamma1: shear component - :param gamma2: shear component - :param ra_0: x/ra position where shear deflection is 0 - :param dec_0: y/dec position where shear deflection is 0 - :return: lensing potential - """ - kappa, gamma1_, gamma2_ = self._kappa_reduced(gamma1, gamma2) - f_shear = self._shear.function(x, y, gamma1_, gamma2_, ra_0, dec_0) - f_kappa = self._convergence.function(x, y, kappa, ra_0, dec_0) - return f_shear + f_kappa
- -
[docs] def derivatives(self, x, y, gamma1, gamma2, ra_0=0, dec_0=0): - """ - - :param x: x-coordinate (angle) - :param y: y0-coordinate (angle) - :param gamma1: shear component - :param gamma2: shear component - :param ra_0: x/ra position where shear deflection is 0 - :param dec_0: y/dec position where shear deflection is 0 - :return: deflection angles - """ - kappa, gamma1_, gamma2_ = self._kappa_reduced(gamma1, gamma2) - f_x_shear, f_y_shear = self._shear.derivatives(x, y, gamma1_, gamma2_, ra_0, dec_0) - f_x_kappa, f_y_kappa = self._convergence.derivatives(x, y, kappa, ra_0, dec_0) - return f_x_shear + f_x_kappa, f_y_shear + f_y_kappa
- -
[docs] def hessian(self, x, y, gamma1, gamma2, ra_0=0, dec_0=0): - """ - - :param x: x-coordinate (angle) - :param y: y0-coordinate (angle) - :param gamma1: shear component - :param gamma2: shear component - :param ra_0: x/ra position where shear deflection is 0 - :param dec_0: y/dec position where shear deflection is 0 - :return: f_xx, f_xy, f_yx, f_yy - """ - kappa, gamma1_, gamma2_ = self._kappa_reduced(gamma1, gamma2) - f_xx_g, f_xy_g, f_yx_g, f_yy_g = self._shear.hessian(x, y, gamma1_, gamma2_, ra_0, dec_0) - f_xx_k, f_xy_k, f_yx_k, f_yy_k = self._convergence.hessian(x, y, kappa, ra_0, dec_0) - f_xx = f_xx_g + f_xx_k - f_yy = f_yy_g + f_yy_k - f_xy = f_xy_g + f_xy_k - return f_xx, f_xy, f_xy, f_yy
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sie.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sie.html deleted file mode 100644 index 268a7f36f..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sie.html +++ /dev/null @@ -1,302 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.sie — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.sie

-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-import numpy as np
-
-__all__ = ['SIE']
-
-
-
[docs]class SIE(LensProfileBase): - """ - class for singular isothermal ellipsoid (SIS with ellipticity) - - .. math:: - \\kappa(x, y) = \\frac{1}{2} \\left(\\frac{\\theta_{E}}{\\sqrt{q x^2 + y^2/q}} \\right) - - with :math:`\\theta_{E}` is the (circularized) Einstein radius, - :math:`q` is the minor/major axis ratio, - and :math:`x` and :math:`y` are defined in a coordinate sys- tem aligned with the major and minor axis of the lens. - - In terms of eccentricities, this profile is defined as - - .. math:: - \\kappa(r) = \\frac{1}{2} \\left(\\frac{\\theta'_{E}}{r \\sqrt{1 − e*\\cos(2*\\phi)}} \\right) - - with :math:`\\epsilon` is the ellipticity defined as - - .. math:: - \\epsilon = \\frac{1-q^2}{1+q^2} - - And an Einstein radius :math:`\\theta'_{\\rm E}` related to the definition used is - - .. math:: - \\left(\\frac{\\theta'_{\\rm E}}{\\theta_{\\rm E}}\\right)^{2} = \\frac{2q}{1+q^2}. - - """ - param_names = ['theta_E', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'theta_E': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'theta_E': 100, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self, NIE=True): - """ - - :param NIE: bool, if True, is using the NIE analytic model. Otherwise it uses PEMD with gamma=2 from fastell4py - """ - self._nie = NIE - if NIE: - from lenstronomy.LensModel.Profiles.nie import NIE - self.profile = NIE() - else: - from lenstronomy.LensModel.Profiles.epl import EPL - self.profile = EPL() - self._s_scale = 0.0000000001 - self._gamma = 2 - super(SIE, self).__init__() - -
[docs] def function(self, x, y, theta_E, e1, e2, center_x=0, center_y=0): - """ - - :param x: - :param y: - :param theta_E: - :param q: - :param phi_G: - :param center_x: - :param center_y: - :return: - """ - if self._nie: - return self.profile.function(x, y, theta_E, e1, e2, self._s_scale, center_x, center_y) - else: - return self.profile.function(x, y, theta_E, self._gamma, e1, e2, center_x, center_y)
- -
[docs] def derivatives(self, x, y, theta_E, e1, e2, center_x=0, center_y=0): - """ - - :param x: - :param y: - :param theta_E: - :param q: - :param phi_G: - :param center_x: - :param center_y: - :return: - """ - if self._nie: - return self.profile.derivatives(x, y, theta_E, e1, e2, self._s_scale, center_x, center_y) - else: - return self.profile.derivatives(x, y, theta_E, self._gamma, e1, e2, center_x, center_y)
- -
[docs] def hessian(self, x, y, theta_E, e1, e2, center_x=0, center_y=0): - """ - - :param x: - :param y: - :param theta_E: - :param q: - :param phi_G: - :param center_x: - :param center_y: - :return: - """ - if self._nie: - return self.profile.hessian(x, y, theta_E, e1, e2, self._s_scale, center_x, center_y) - else: - return self.profile.hessian(x, y, theta_E, self._gamma, e1, e2, center_x, center_y)
- -
[docs] @staticmethod - def theta2rho(theta_E): - """ - converts projected density parameter (in units of deflection) into 3d density parameter - :param theta_E: - :return: - """ - fac1 = np.pi * 2 - rho0 = theta_E / fac1 - return rho0
- -
[docs] @staticmethod - def mass_3d(r, rho0, e1=0, e2=0): - """ - mass enclosed a 3d sphere or radius r - :param r: radius in angular units - :param rho0: density at angle=1 - :return: mass in angular units - """ - mass_3d = 4 * np.pi * rho0 * r - return mass_3d
- -
[docs] def mass_3d_lens(self, r, theta_E, e1=0, e2=0): - """ - mass enclosed a 3d sphere or radius r given a lens parameterization with angular units - - :param r: radius in angular units - :param theta_E: Einstein radius - :return: mass in angular units - """ - rho0 = self.theta2rho(theta_E) - return self.mass_3d(r, rho0)
- -
[docs] def mass_2d(self, r, rho0, e1=0, e2=0): - """ - mass enclosed projected 2d sphere of radius r - :param r: - :param rho0: - :param a: - :param s: - :return: - """ - alpha = np.pi * np.pi * 2 * rho0 - mass_2d = alpha*r - return mass_2d
- -
[docs] def mass_2d_lens(self, r, theta_E, e1=0, e2=0): - """ - - :param r: - :param theta_E: - :return: - """ - rho0 = self.theta2rho(theta_E) - return self.mass_2d(r, rho0)
- -
[docs] def grav_pot(self, x, y, rho0, e1=0, e2=0, center_x=0, center_y=0): - """ - gravitational potential (modulo 4 pi G and rho0 in appropriate units) - :param x: - :param y: - :param rho0: - :param a: - :param s: - :param center_x: - :param center_y: - :return: - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - mass_3d = self.mass_3d(r, rho0) - pot = mass_3d/r - return pot
- -
[docs] def density_lens(self, r, theta_E, e1=0, e2=0): - """ - computes the density at 3d radius r given lens model parameterization. - The integral in the LOS projection of this quantity results in the convergence quantity. - - :param r: radius in angles - :param theta_E: Einstein radius - :param e1: eccentricity component - :param e2: eccentricity component - :return: density - """ - rho0 = self.theta2rho(theta_E) - return self.density(r, rho0)
- -
[docs] @staticmethod - def density(r, rho0, e1=0, e2=0): - """ - computes the density - :param r: radius in angles - :param rho0: density at angle=1 - :return: density at r - """ - rho = rho0 / r**2 - return rho
- -
[docs] @staticmethod - def density_2d(x, y, rho0, e1=0, e2=0, center_x=0, center_y=0): - """ - projected density - :param x: - :param y: - :param rho0: - :param center_x: - :param center_y: - :return: - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - sigma = np.pi * rho0 / r - return sigma
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sis.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sis.html deleted file mode 100644 index f9d94e0ce..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sis.html +++ /dev/null @@ -1,271 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.sis — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.sis

-__author__ = 'sibirrer'
-
-import numpy as np
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['SIS']
-
-
-
[docs]class SIS(LensProfileBase): - """ - this class contains the function and the derivatives of the Singular Isothermal Sphere - - - .. math:: - \\kappa(x, y) = \\frac{1}{2} \\left(\\frac{\\theta_{E}}{\\sqrt{x^2 + y^2}} \\right) - - with :math:`\\theta_{E}` is the Einstein radius, - - - """ - param_names = ['theta_E', 'center_x', 'center_y'] - lower_limit_default = {'theta_E': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'theta_E': 100, 'center_x': 100, 'center_y': 100} - -
[docs] def function(self, x, y, theta_E, center_x=0, center_y=0): - x_shift = x - center_x - y_shift = y - center_y - f_ = theta_E * np.sqrt(x_shift*x_shift + y_shift*y_shift) - return f_
- -
[docs] def derivatives(self, x, y, theta_E, center_x=0, center_y=0): - """ - returns df/dx and df/dy of the function - """ - x_shift = x - center_x - y_shift = y - center_y - R = np.sqrt(x_shift*x_shift + y_shift*y_shift) - if isinstance(R, int) or isinstance(R, float): - a = theta_E / max(0.000001, R) - else: - a = np.empty_like(R) - r = R[R > 0] # in the SIS regime - a[R == 0] = 0 - a[R > 0] = theta_E / r - f_x = a * x_shift - f_y = a * y_shift - return f_x, f_y
- -
[docs] def hessian(self, x, y, theta_E, center_x=0, center_y=0): - """ - returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - x_shift = x - center_x - y_shift = y - center_y - R = (x_shift*x_shift + y_shift*y_shift)**(3./2) - if isinstance(R, int) or isinstance(R, float): - prefac = theta_E / max(0.000001, R) - else: - prefac = np.empty_like(R) - r = R[R > 0] # in the SIS regime - prefac[R == 0] = 0. - prefac[R > 0] = theta_E / r - - f_xx = y_shift*y_shift * prefac - f_yy = x_shift*x_shift * prefac - f_xy = -x_shift*y_shift * prefac - return f_xx, f_xy, f_xy, f_yy
- -
[docs] @staticmethod - def rho2theta(rho0): - """ - converts 3d density into 2d projected density parameter - :param rho0: - :return: - """ - theta_E = np.pi * 2 * rho0 - return theta_E
- -
[docs] @staticmethod - def theta2rho(theta_E): - """ - converts projected density parameter (in units of deflection) into 3d density parameter - :param theta_E: - :return: - """ - fac1 = np.pi * 2 - rho0 = theta_E / fac1 - return rho0
- -
[docs] @staticmethod - def mass_3d(r, rho0): - """ - mass enclosed a 3d sphere or radius r - :param r: radius in angular units - :param rho0: density at angle=1 - :return: mass in angular units - """ - mass_3d = 4 * np.pi * rho0 * r - return mass_3d
- -
[docs] def mass_3d_lens(self, r, theta_E): - """ - mass enclosed a 3d sphere or radius r given a lens parameterization with angular units - - :param r: radius in angular units - :param theta_E: Einstein radius - :return: mass in angular units - """ - rho0 = self.theta2rho(theta_E) - return self.mass_3d(r, rho0)
- -
[docs] @staticmethod - def mass_2d(r, rho0): - """ - mass enclosed projected 2d sphere of radius r - :param r: - :param rho0: - :return: - """ - alpha = np.pi * np.pi * 2 * rho0 - mass_2d = alpha*r - return mass_2d
- -
[docs] def mass_2d_lens(self, r, theta_E): - """ - - :param r: radius - :param theta_E: Einstein radius - :return: mass within a radius in projection - """ - rho0 = self.theta2rho(theta_E) - return self.mass_2d(r, rho0)
- -
[docs] def grav_pot(self, x, y, rho0, center_x=0, center_y=0): - """ - gravitational potential (modulo 4 pi G and rho0 in appropriate units) - :param x: - :param y: - :param rho0: - :param center_x: - :param center_y: - :return: - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - mass_3d = self.mass_3d(r, rho0) - pot = mass_3d/r - return pot
- -
[docs] @staticmethod - def density(r, rho0): - """ - computes the density - :param r: radius in angles - :param rho0: density at angle=1 - :return: density at r - """ - rho = rho0 / r**2 - return rho
- -
[docs] def density_lens(self, r, theta_E): - """ - computes the density at 3d radius r given lens model parameterization. - The integral in projected in units of angles (i.e. arc seconds) results in the convergence quantity. - - :param r: 3d radius - :param theta_E: Einstein radius - :return: density(r) - """ - rho0 = self.theta2rho(theta_E) - return self.density(r, rho0)
- -
[docs] @staticmethod - def density_2d(x, y, rho0, center_x=0, center_y=0): - """ - projected density - :param x: - :param y: - :param rho0: - :param center_x: - :param center_y: - :return: - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - sigma = np.pi * rho0 / r - return sigma
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sis_truncate.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sis_truncate.html deleted file mode 100644 index fdff831da..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/sis_truncate.html +++ /dev/null @@ -1,226 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.sis_truncate — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.sis_truncate

-__author__ = 'sibirrer'
-
-import numpy as np
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['SIS_truncate']
-
-
-
[docs]class SIS_truncate(LensProfileBase): - """ - this class contains the function and the derivatives of the Singular Isothermal Sphere - """ - param_names = ['theta_E', 'r_trunc', 'center_x', 'center_y'] - lower_limit_default = {'theta_E': 0, 'r_trunc': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'theta_E': 100, 'r_trunc': 100, 'center_x': 100, 'center_y': 100} - -
[docs] def function(self, x, y, theta_E, r_trunc, center_x=0, center_y=0): - x_shift = x - center_x - y_shift = y - center_y - r = np.sqrt(x_shift*x_shift + y_shift*y_shift) - if isinstance(r, int) or isinstance(r, float): - if r < r_trunc: - f_ = theta_E * r - elif r < 2*r_trunc: - f_ = theta_E * r_trunc + 1. / 2 * theta_E * (3 - r / r_trunc) * (r - r_trunc) - else: - f_ = 3./2 * theta_E * r_trunc - else: - f_ = np.zeros_like(r) - f_[r < r_trunc] = theta_E * r[r < r_trunc] - r_ = r[(r < 2*r_trunc) & (r > r_trunc)] - f_[(r < 2*r_trunc) & (r > r_trunc)] = theta_E * r_trunc + 1. / 2 * theta_E * (3 - r_ / r_trunc) * (r_ - r_trunc) - f_[r > 2*r_trunc] = 3./2 * theta_E * r_trunc - return f_
- -
[docs] def derivatives(self, x, y, theta_E, r_trunc, center_x=0, center_y=0): - """ - returns df/dx and df/dy of the function - """ - x_shift = x - center_x - y_shift = y - center_y - - dphi_dr = self._dphi_dr(x_shift, y_shift, theta_E, r_trunc) - dr_dx, dr_dy = self._dr_dx(x_shift, y_shift) - f_x = dphi_dr * dr_dx - f_y = dphi_dr * dr_dy - return f_x, f_y
- -
[docs] def hessian(self, x, y, theta_E, r_trunc, center_x=0, center_y=0): - """ - returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - x_shift = x - center_x - y_shift = y - center_y - dphi_dr = self._dphi_dr(x_shift, y_shift, theta_E, r_trunc) - d2phi_dr2 = self._d2phi_dr2(x_shift, y_shift, theta_E, r_trunc) - dr_dx, dr_dy = self._dr_dx(x, y) - d2r_dx2, d2r_dy2, d2r_dxy = self._d2r_dx2(x_shift, y_shift) - f_xx = d2r_dx2*dphi_dr + dr_dx**2*d2phi_dr2 - f_yy = d2r_dy2*dphi_dr + dr_dy**2*d2phi_dr2 - f_xy = d2r_dxy*dphi_dr + dr_dx*dr_dy*d2phi_dr2 - return f_xx, f_xy, f_xy, f_yy
- - def _dphi_dr(self, x, y, theta_E, r_trunc): - """ - - :param x: - :param y: - :param r_trunc: - :return: - """ - r = np.sqrt(x*x + y*y) - if isinstance(r, int) or isinstance(r, float): - if r == 0: - a = 0 - elif r < r_trunc: - a = theta_E - elif r < 2*r_trunc: - a = theta_E * (2 - r / r_trunc) - else: - a = 0 - else: - a = np.zeros_like(r) - a[(r < r_trunc) & (r > 0)] = theta_E - r_ = r[(r < 2*r_trunc) & (r >= r_trunc)] - a[(r < 2*r_trunc) & (r >= r_trunc)] = theta_E * (2 - r_ / r_trunc) - a[r >= 2*r_trunc] = 0 - return a - - def _d2phi_dr2(self, x, y, theta_E, r_trunc): - """ - second derivative of the potential in radial direction - :param x: - :param y: - :param theta_E: - :param r_trunc: - :return: - """ - r = np.sqrt(x*x + y*y) - if isinstance(r, int) or isinstance(r, float): - if r < r_trunc: - a = 0 - elif r < 2*r_trunc: - a = -theta_E / r_trunc - else: - a = 0 - else: - a = np.zeros_like(r) - a[r < r_trunc] = 0 - a[(r < 2*r_trunc) & (r > r_trunc)] = -theta_E / r_trunc - a[r > 2*r_trunc] = 0 - return a - - def _dr_dx(self, x, y): - """ - derivative of dr/dx, dr/dy - :param x: - :param y: - :return: - """ - - r = np.sqrt(x**2 + y**2) - if isinstance(r, int) or isinstance(r, float): - if r == 0: - r = 1 - else: - r[r == 0] = 1 - return x/r, y/r - - @staticmethod - def _d2r_dx2(x, y): - """ - second derivative - :param x: - :param y: - :return: - """ - r = np.sqrt(x**2 + y**2) - if isinstance(r, int) or isinstance(r, float): - if r == 0: - r = 1 - else: - r[r == 0] = 1 - return y**2/r**3, x**2/r**3, -x*y/r**3
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/spemd.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/spemd.html deleted file mode 100644 index a9fc71a18..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/spemd.html +++ /dev/null @@ -1,336 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.spemd — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.spemd

-__author__ = 'sibirrer'
-
-import numpy as np
-import lenstronomy.Util.param_util as param_util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['SPEMD']
-
-
-
[docs]class SPEMD(LensProfileBase): - """ - class for smooth power law ellipse mass density profile (SPEMD). This class effectively performs the FASTELL calculations - by Renan Barkana. The parameters are changed and represent a spherically averaged Einstein radius an a logarithmic - 3D mass profile slope. - - The SPEMD mass profile is defined as follow: - - .. math:: - \\kappa(x, y) = \\frac{3-\\gamma}{2} \\left(\\frac{\\theta_{E}}{\\sqrt{q x^2 + y^2/q + s^2}} \\right)^{\\gamma-1} - - with :math:`\\theta_{E}` is the (circularized) Einstein radius, - :math:`\\gamma` is the negative power-law slope of the 3D mass distributions, :math:`q` is the minor/major axis ratio, - and :math:`x` and :math:`y` are defined in a coordinate system aligned with the major and minor axis of the lens. - - the FASTELL definitions are as follows: - - The parameters are position :math:`(x1,x2)`, overall factor - (:math:`b`), power (gam), axis ratio (arat) which is <=1, core radius - squared (:math:`s2`), and the output potential (:math:`\\phi`). - The projected mass density distribution, in units of the - critical density, is - - .. math:: - \\kappa(x1,x2)=b_{fastell} \\left[u2+s2\\right]^{-gam}, - - with :math:`u2=\\left[x1^2+x2^2/(arat^2)\\right]`. - - The conversion from lenstronomy definitions of this class to FASTELL are: - - .. math:: - q_{fastell} \\equiv q_{lenstronomy} - - .. math:: - gam \\equiv (\\gamma-1)/2 - - .. math:: - b_{fastell} \\equiv (3-\\gamma)/2. * \\left(\\theta_{E}^2 / q\\right)^{gam} - - .. math:: - s2_{fastell} = s_{lenstronomy}^2 * q - - """ - param_names = ['theta_E', 'gamma', 'e1', 'e2', 's_scale', 'center_x', 'center_y'] - lower_limit_default = {'theta_E': 0, 'gamma': 0, 'e1': -0.5, 'e2': -0.5, 's_scale': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'theta_E': 100, 'gamma': 100, 'e1': 0.5, 'e2': 0.5, 's_scale': 100, 'center_x': 100, 'center_y': 100} - - def __init__(self, suppress_fastell=False): - """ - - """ - try: - from fastell4py import fastell4py - self._fastell4py_bool = True - self.fastell4py = fastell4py - except: - self._fastell4py_bool = False - if suppress_fastell: - ImportWarning("module fastell4py not installed. You can get it from here: " - "https://github.com/sibirrer/fastell4py " - "Make sure you have a fortran compiler such that the installation works properly.") - Warning("SPEMD model outputs are replaced by zeros as fastell4py package is not installed!") - else: - raise ImportError("module fastell4py not installed. You can get it from here: " - "https://github.com/sibirrer/fastell4py " - "Make sure you have a fortran compiler such that the installation works properly.") - super(SPEMD, self).__init__() - -
[docs] def function(self, x, y, theta_E, gamma, e1, e2, s_scale, center_x=0, center_y=0): - """ - - :param x: x-coordinate (angle) - :param y: y-coordinate (angle) - :param theta_E: Einstein radius (angle), pay attention to specific definition! - :param gamma: logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal - :param e1: eccentricity component - :param e2: eccentricity component - :param s_scale: smoothing scale in the center of the profile (angle) - :param center_x: x-position of lens center - :param center_y: y-position of lens center - :return: lensing potential - """ - x1, x2, q_fastell, gam, s2, q, phi_G = self.param_transform(x, y, theta_E, gamma, e1, e2, s_scale, center_x, - center_y) - compute_bool = self._parameter_constraints(q_fastell, gam, s2, q) - if self._fastell4py_bool and self.is_not_empty(x1, x2) and compute_bool: - potential = self.fastell4py.ellipphi(x1, x2, q_fastell, gam, arat=q, s2=s2) - n = len(np.atleast_1d(x)) - if n <= 1: - if np.shape(x) == (): - return np.array(potential[0]) - else: - potential = np.zeros_like(x1) - return potential
- -
[docs] def derivatives(self, x, y, theta_E, gamma, e1, e2, s_scale, center_x=0, center_y=0): - """ - - :param x: x-coordinate (angle) - :param y: y-coordinate (angle) - :param theta_E: Einstein radius (angle), pay attention to specific definition! - :param gamma: logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal - :param e1: eccentricity component - :param e2: eccentricity component - :param s_scale: smoothing scale in the center of the profile - :param center_x: x-position of lens center - :param center_y: y-position of lens center - :return: deflection angles alpha_x, alpha_y - """ - x1, x2, q_fastell, gam, s2, q, phi_G = self.param_transform(x, y, theta_E, gamma, e1, e2, s_scale, center_x, - center_y) - compute_bool = self._parameter_constraints(q_fastell, gam, s2, q) - if self._fastell4py_bool and self.is_not_empty(x1, x2) and compute_bool: - f_x_prim, f_y_prim = self.fastell4py.fastelldefl(x1, x2, q_fastell, gam, arat=q, s2=s2) - else: - f_x_prim, f_y_prim = np.zeros_like(x1), np.zeros_like(x1) - cos_phi = np.cos(phi_G) - sin_phi = np.sin(phi_G) - - f_x = cos_phi*f_x_prim - sin_phi*f_y_prim - f_y = sin_phi*f_x_prim + cos_phi*f_y_prim - return f_x, f_y
- -
[docs] def hessian(self, x, y, theta_E, gamma, e1, e2, s_scale, center_x=0, center_y=0): - """ - - :param x: x-coordinate (angle) - :param y: y-coordinate (angle) - :param theta_E: Einstein radius (angle), pay attention to specific definition! - :param gamma: logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal - :param e1: eccentricity component - :param e2: eccentricity component - :param s_scale: smoothing scale in the center of the profile - :param center_x: x-position of lens center - :param center_y: y-position of lens center - :return: Hessian components f_xx, f_xy, f_yx, f_yy - """ - x1, x2, q_fastell, gam, s2, q, phi_G = self.param_transform(x, y, theta_E, gamma, e1, e2, s_scale, center_x, center_y) - compute_bool = self._parameter_constraints(q_fastell, gam, s2, q) - if self._fastell4py_bool and self.is_not_empty(x1, x2) and compute_bool: - f_x_prim, f_y_prim, f_xx_prim, f_yy_prim, f_xy_prim = self.fastell4py.fastellmag(x1, x2, q_fastell, gam, - arat=q, s2=s2) - n = len(np.atleast_1d(x)) - if n <= 1: - if np.shape(x) == (): - f_xx_prim, f_yy_prim, f_xy_prim = np.array(f_xx_prim[0]), np.array(f_yy_prim[0]), np.array( - f_xy_prim[0]) - else: - f_xx_prim, f_yy_prim, f_xy_prim = np.zeros_like(x1), np.zeros_like(x1), np.zeros_like(x1) - kappa = (f_xx_prim + f_yy_prim)/2 - gamma1_value = (f_xx_prim - f_yy_prim)/2 - gamma2_value = f_xy_prim - - gamma1 = np.cos(2*phi_G)*gamma1_value-np.sin(2*phi_G)*gamma2_value - gamma2 = +np.sin(2*phi_G)*gamma1_value+np.cos(2*phi_G)*gamma2_value - - f_xx = kappa + gamma1 - f_yy = kappa - gamma1 - f_xy = gamma2 - return f_xx, f_xy, f_xy, f_yy
- -
[docs] def param_transform(self, x, y, theta_E, gamma, e1, e2, s_scale, center_x=0, center_y=0): - """ - transforms parameters in the format of fastell4py - - :param x: x-coordinate (angle) - :param y: y-coordinate (angle) - :param theta_E: Einstein radius (angle), pay attention to specific definition! - :param gamma: logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal - :param e1: eccentricity component - :param e2: eccentricity component - :param s_scale: smoothing scale in the center of the profile - :param center_x: x-position of lens center - :param center_y: y-position of lens center - :return: x-rotated, y-rotated, q_fastell, gam, s2, q, phi_G - """ - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - x = np.array(x) - y = np.array(y) - x_shift = x - center_x - y_shift = y - center_y - q_fastell, gam, s2 = self.convert_params(theta_E, gamma, q, s_scale) - cos_phi = np.cos(phi_G) - sin_phi = np.sin(phi_G) - - x1 = cos_phi * x_shift + sin_phi * y_shift - x2 = -sin_phi * x_shift + cos_phi * y_shift - return x1, x2, q_fastell, gam, s2, q, phi_G
- -
[docs] @staticmethod - def convert_params(theta_E, gamma, q, s_scale): - """ - converts parameter definitions into quantities used by the FASTELL fortran library - - :param theta_E: Einstein radius - :param gamma: 3D power-law slope of mass profile - :param q: axis ratio minor/major - :param s_scale: float, smoothing scale in the core - :return: pre-factors to SPEMP profile for FASTELL - """ - gam = (gamma-1)/2. - q_fastell = (3-gamma)/2. * (theta_E ** 2 / q) ** gam - s2 = s_scale ** 2 * q - return q_fastell, gam, s2
- -
[docs] @staticmethod - def is_not_empty(x1, x2): - """ - Check if float or not an empty array - :return: True if x1 and x2 are either floats/ints or an non-empty array, False if e.g. objects are [] - :rtype: bool - """ - assert type(x1) == type(x2) - - if isinstance(x1, (list, tuple, np.ndarray)): - if len(x1) != 0 and len(x2) != 0: - return True - else: - return False - else: - return True
- - @staticmethod - def _parameter_constraints(q_fastell, gam, s2, q): - """ - sets bounds to parameters due to numerical stability - - FASTELL has the following definitons: - The parameters are position (x1,x2), overall factor - (q), power (gam), axis ratio (arat) which is <=1, core radius - squared (s2), and the output potential (phi). - The projected mass density distribution, in units of the - critical density, is kappa(x1,x2)=q [u2+s2]^(-gam), where - u2=[x1^2+x2^2/(arat^2)]. - - :param q_fastell: float, normalization of lens model, q_fastell = (3-gamma)/2. * (theta_E ** 2 / q) ** gam - :param gam: float, slope parameter, gam = (gamma-1)/2. - :param q: axis ratio - :param s2: square of smoothing scale of the core - :return: bool of whether or not to let the fastell provide to be evaluated or instead return zero(s) - """ - if q_fastell <= 0 or q > 1 or q < 0.01 or gam > 0.999 or gam < 0.001 or \ - not np.isfinite(q_fastell): - return False - return True
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/spep.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/spep.html deleted file mode 100644 index e1b3df00d..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/spep.html +++ /dev/null @@ -1,252 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.spep — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.spep

-__author__ = 'sibirrer'
-
-
-import numpy as np
-import lenstronomy.Util.param_util as param_util
-from lenstronomy.Util import util
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-from lenstronomy.LensModel.Profiles.spp import SPP
-
-__all__ = ['SPEP']
-
-
-
[docs]class SPEP(LensProfileBase): - """ - class for Softened power-law elliptical potential (SPEP) - """ - param_names = ['theta_E', 'gamma', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'theta_E': 0, 'gamma': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'theta_E': 100, 'gamma': 100, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.spp = SPP() - super(SPEP, self).__init__() - -
[docs] def function(self, x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0): - """ - :param x: set of x-coordinates - :type x: array of size (n) - :param theta_E: Einstein radius of lense - :type theta_E: float. - :param gamma: power law slope of mass profifle - :type gamma: <2 float - :param q: Axis ratio - :type q: 0<q<1 - :param phi_G: position angel of SES - :type q: 0<phi_G<pi/2 - :returns: function - :raises: AttributeError, KeyError - """ - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - gamma, q = self._param_bounds(gamma, q) - theta_E *= q - x_shift = x - center_x - y_shift = y - center_y - E = theta_E / (((3 - gamma) / 2.) ** (1. / (1 - gamma)) * np.sqrt(q)) - #E = phi_E - eta = -gamma+3 - xt1 = np.cos(phi_G)*x_shift+np.sin(phi_G)*y_shift - xt2 = -np.sin(phi_G)*x_shift+np.cos(phi_G)*y_shift - p2 = xt1**2+xt2**2/q**2 - s2 = 0. # softening - return 2 * E**2/eta**2 * ((p2 + s2)/E**2)**(eta/2)
- -
[docs] def derivatives(self, x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0): - - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - gamma, q = self._param_bounds(gamma, q) - phi_E_new = theta_E * q - x_shift = x - center_x - y_shift = y - center_y - E = phi_E_new / (((3-gamma)/2.)**(1./(1-gamma))*np.sqrt(q)) - # E = phi_E - eta = float(-gamma+3) - cos_phi = np.cos(phi_G) - sin_phi = np.sin(phi_G) - - xt1=cos_phi*x_shift+sin_phi*y_shift - xt2=-sin_phi*x_shift+cos_phi*y_shift - xt2difq2 = xt2/(q*q) - P2=xt1*xt1+xt2*xt2difq2 - if isinstance(P2, int) or isinstance(P2, float): - a = max(0.000001,P2) - else: - a=np.empty_like(P2) - p2 = P2[P2 > 0] #in the SIS regime - a[P2 == 0] = 0.000001 - a[P2 > 0] = p2 - fac = 1./eta*(a/(E*E))**(eta/2-1)*2 - f_x_prim = fac*xt1 - f_y_prim = fac*xt2difq2 - - f_x = cos_phi*f_x_prim-sin_phi*f_y_prim - f_y = sin_phi*f_x_prim+cos_phi*f_y_prim - return f_x, f_y
- -
[docs] def hessian(self, x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0): - phi_G, q = param_util.ellipticity2phi_q(e1, e2) - gamma, q = self._param_bounds(gamma, q) - phi_E_new = theta_E * q - #x_shift = x - center_x - #y_shift = y - center_y - - # shift - x_ = x - center_x - y_ = y - center_y - # rotate - x__, y__ = util.rotate(x_, y_, phi_G) - - E = phi_E_new / (((3-gamma)/2.)**(1./(1-gamma))*np.sqrt(q)) - if E <= 0: - return np.zeros_like(x), np.zeros_like(x), np.zeros_like(x), np.zeros_like(x) - # E = phi_E - eta = float(-gamma+3) - #xt1 = np.cos(phi_G)*x_shift+np.sin(phi_G)*y_shift - #xt2 = -np.sin(phi_G)*x_shift+np.cos(phi_G)*y_shift - xt1, xt2 = x__, y__ - P2 = xt1**2+xt2**2/q**2 - - if isinstance(P2, int) or isinstance(P2, float): - a = max(0.000001, P2) - else: - a=np.empty_like(P2) - p2 = P2[P2>0] #in the SIS regime - a[P2==0] = 0.000001 - a[P2>0] = p2 - s2 = 0. # softening - - kappa=1./eta*(a/E**2)**(eta/2-1)*((eta-2)*(xt1**2+xt2**2/q**4)/a+(1+1/q**2)) - gamma1_value=1./eta*(a/E**2)**(eta/2-1)*(1-1/q**2+(eta/2-1)*(2*xt1**2-2*xt2**2/q**4)/a) - gamma2_value=4*xt1*xt2/q**2*(1./2-1/eta)*(a/E**2)**(eta/2-2)/E**2 - - gamma1 = np.cos(2*phi_G)*gamma1_value-np.sin(2*phi_G)*gamma2_value - gamma2 = +np.sin(2*phi_G)*gamma1_value+np.cos(2*phi_G)*gamma2_value - - f_xx = kappa + gamma1 - f_yy = kappa - gamma1 - f_xy = gamma2 - return f_xx, f_xy, f_xy, f_yy
- -
[docs] def mass_3d_lens(self, r, theta_E, gamma, e1=None, e2=None): - """ - computes the spherical power-law mass enclosed (with SPP routine) - :param r: radius within the mass is computed - :param theta_E: Einstein radius - :param gamma: power-law slope - :param e1: eccentricity component (not used) - :param e2: eccentricity component (not used) - :return: mass enclosed a 3D radius r - """ - return self.spp.mass_3d_lens(r, theta_E, gamma)
- -
[docs] def density_lens(self, r, theta_E, gamma, e1=None, e2=None): - """ - computes the density at 3d radius r given lens model parameterization. - The integral in the LOS projection of this quantity results in the convergence quantity. - - :param r: radius within the mass is computed - :param theta_E: Einstein radius - :param gamma: power-law slope - :param e1: eccentricity component (not used) - :param e2: eccentricity component (not used) - :return: mass enclosed a 3D radius r - """ - return self.spp.density_lens(r, theta_E, gamma)
- - def _param_bounds(self, gamma, q): - """ - bounds parameters - - :param gamma: - :param q: - :return: - """ - if gamma < 1.4: - gamma = 1.4 - if gamma > 2.9: - gamma = 2.9 - if q < 0.01: - q = 0.01 - return float(gamma), q
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/splcore.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/splcore.html deleted file mode 100644 index 55c0d506f..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/splcore.html +++ /dev/null @@ -1,379 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.splcore — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.splcore

-__author__ = 'dangilman'
-
-import numpy as np
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-from scipy.special import hyp2f1
-from scipy.special import gamma as gamma_func
-
-__all__ = ['SPLCORE']
-
-
-
[docs]class SPLCORE(LensProfileBase): - """ - This lens profile corresponds to a spherical power law (SPL) mass distribution with logarithmic slope gamma and - a 3D core radius r_core - - .. math:: - - \\rho\\left(r, \\rho_0, r_c, \\gamma\\right) = \\rho_0 - \\frac{{r_c}^\\gamma}{\\left(r^2 + r_c^2\\right)^{\\frac{\\gamma}{2}}} - - The difference between this and EPL is that this model contains a core radius, is circular, - and is also defined for gamma=3. - - With respect to SPEMD, this model is different in that it is also defined for gamma = 3, is circular, and is defined - in terms of a physical density parameter rho0, or the central density at r=0 divided by the critical density for - lensing such that rho0 has units 1/arcsec. - - This class is defined for all gamma > 1 - """ - - param_names = ['sigma0', 'center_x', 'center_y', 'r_core', 'gamma'] - lower_limit_default = {'sigma0': 0, 'center_x': -100, 'center_y': -100, 'r_core': 1e-6, 'gamma': 1.+1e-6} - upper_limit_default = {'sigma0': 1e+12, 'center_x': 100, 'center_y': 100, 'r_core': 100, 'gamma': 5.} - -
[docs] def function(self, x, y, sigma0, r_core, gamma, center_x=0, center_y=0): - - raise Exception('potential not implemented for this class')
- -
[docs] def derivatives(self, x, y, sigma0, r_core, gamma, center_x=0, center_y=0): - """ - :param x: projected x position at which to evaluate function [arcsec] - :param y: projected y position at which to evaluate function [arcsec] - :param sigma0: convergence at r = 0 - :param r_core: core radius [arcsec] - :param gamma: logarithmic slope at r -> infinity - :param center_x: x coordinate center of lens model [arcsec] - :param center_y: y coordinate center of lens model [arcsec] - :return: deflection angle alpha in x and y directions - """ - - x_ = x - center_x - y_ = y - center_y - r = np.hypot(x_, y_) - r = self._safe_r_division(r, r_core) - - alpha_r = self.alpha(r, sigma0, r_core, gamma) - cos = x_/r - sin = y_/r - return alpha_r * cos, alpha_r * sin
- -
[docs] def hessian(self, x, y, sigma0, r_core, gamma, center_x=0, center_y=0): - """ - :param x: projected x position at which to evaluate function [arcsec] - :param y: projected y position at which to evaluate function [arcsec] - :param sigma0: convergence at r = 0 - :param r_core: core radius [arcsec] - :param gamma: logarithmic slope at r -> infinity - :param center_x: x coordinate center of lens model [arcsec] - :param center_y: y coordinate center of lens model [arcsec] - :return: hessian elements - - alpha_(x/y) = alpha_r * cos/sin(x/y / r) - """ - x_ = x - center_x - y_ = y - center_y - r = np.hypot(x_, y_) - m2d = self.mass_2d_lens(r, sigma0, r_core, gamma) / np.pi - r = self._safe_r_division(r, r_core) - - rho0 = self._sigma2rho0(sigma0, r_core) - kappa = self.density_2d(x_, y_, rho0, r_core, gamma) - gamma_tot = m2d / r ** 2 - kappa - sin_2phi = -2*x_*y_/r**2 - cos_2phi = (y_**2 - x_**2)/r**2 - - gamma1 = cos_2phi * gamma_tot - gamma2 = sin_2phi * gamma_tot - - f_xx = kappa + gamma1 - f_yy = kappa - gamma1 - f_xy = gamma2 - return f_xx, f_xy, f_xy, f_yy
- -
[docs] def alpha(self, r, sigma0, r_core, gamma): - - """ - Returns the deflection angle at r - :param r: radius [arcsec] - :param sigma0: convergence at r=0 - :param r_core: core radius [arcsec] - :param gamma: logarithmic slope at r -> infinity - :return: deflection angle at r - """ - mass2d = self.mass_2d_lens(r, sigma0, r_core, gamma) - return mass2d / r / np.pi
- -
[docs] @staticmethod - def density(r, rho0, r_core, gamma): - """ - Returns the 3D density at r - :param r: radius [arcsec] - :param rho0: convergence at r=0 - :param r_core: core radius [arcsec] - :param gamma: logarithmic slope at r -> infinity - :return: density at r - """ - return rho0 * r_core ** gamma / (r_core**2 + r**2) ** (gamma/2)
- -
[docs] def density_lens(self, r, sigma0, r_core, gamma): - """ - Returns the 3D density at r - :param r: radius [arcsec] - :param sigma0: convergence at r=0 - :param r_core: core radius [arcsec] - :param gamma: logarithmic slope at r -> infinity - :return: density at r - """ - rho0 = self._sigma2rho0(sigma0, r_core) - return rho0 * r_core ** gamma / (r_core**2 + r**2) ** (gamma/2)
- - def _density_2d_r(self, r, rho0, r_core, gamma): - """ - Returns the convergence at radius r after applying _safe_r_division - :param r: position [arcsec] - :param rho0: convergence at r=0 - :param r_core: core radius [arcsec] - :param gamma: logarithmic slope at r -> infinity - :return: convergence at r - """ - sigma0 = self._rho02sigma(rho0, r_core) - if gamma == 3: - return 2 * r_core ** 2 * sigma0 / (r ** 2 + r_core ** 2) - elif gamma == 2: - return np.pi * r_core * sigma0 / (r_core ** 2 + r ** 2) ** 0.5 - else: - x = r / r_core - exponent = (1 - gamma) / 2 - return sigma0 * np.sqrt(np.pi) * gamma_func(0.5 * (gamma - 1)) / gamma_func(0.5 * gamma) * ( - 1 + x ** 2) ** exponent - -
[docs] def density_2d(self, x, y, rho0, r_core, gamma): - """ - Returns the convergence at radius r - :param x: x position [arcsec] - :param y: y position [arcsec] - :param rho0: convergence at r=0 - :param r_core: core radius [arcsec] - :param gamma: logarithmic slope at r -> infinity - :return: convergence at r - """ - - r = np.hypot(x, y) - r = self._safe_r_division(r, r_core) - return self._density_2d_r(r, rho0, r_core, gamma)
- -
[docs] def mass_3d(self, r, rho0, r_core, gamma): - """ - mass enclosed a 3d sphere or radius r - :param r: radius [arcsec] - :param rho0: density at r = 0 in units [rho_0_physical / sigma_crit] (which should be equal to [arcsec]) - where rho_0_physical is a physical density normalization and sigma_crit is the critical density for lensing - :param r_core: core radius [arcsec] - :param gamma: logarithmic slope at r -> infinity - :return: mass inside radius r - """ - return 4 * np.pi * r_core ** 3 * rho0 * self._g(r/r_core, gamma)
- -
[docs] def mass_3d_lens(self, r, sigma0, r_core, gamma): - """ - mass enclosed a 3d sphere or radius r - :param r: radius [arcsec] - :param sigma0: convergence at r = 0 - :param r_core: core radius [arcsec] - :param gamma: logarithmic slope at r -> infinity - :return: mass inside radius r - """ - rho0 = self._sigma2rho0(sigma0, r_core) - return self.mass_3d(r, rho0, r_core, gamma)
- -
[docs] def mass_2d(self, r, rho0, r_core, gamma): - """ - mass enclosed projected 2d disk of radius r - :param r: radius [arcsec] - :param rho0: density at r = 0 in units [rho_0_physical / sigma_crit] (which should be equal to [1/arcsec]) - where rho_0_physical is a physical density normalization and sigma_crit is the critical density for lensing - :param r_core: core radius [arcsec] - :param gamma: logarithmic slope at r -> infinity - :return: projected mass inside disk of radius r - """ - return 4 * np.pi * r_core ** 3 * rho0 * self._f(r/r_core, gamma)
- -
[docs] def mass_2d_lens(self, r, sigma0, r_core, gamma): - """ - mass enclosed projected 2d disk of radius r - :param r: radius [arcsec] - :param sigma0: convergence at r = 0 - where rho_0_physical is a physical density normalization and sigma_crit is the critical density for lensing - :param r_core: core radius [arcsec] - :param gamma: logarithmic slope at r -> infinity - :return: projected mass inside disk of radius r - """ - rho0 = self._sigma2rho0(sigma0, r_core) - return self.mass_2d(r, rho0, r_core, gamma)
- - @staticmethod - def _safe_r_division(r, r_core, x_min=1e-6): - """ - Avoids accidental division by 0 - :param r: radius in arcsec - :param r_core: core radius in arcsec - :return: a minimum value of r - """ - - if isinstance(r, float) or isinstance(r, int): - r = max(x_min * r_core, r) - else: - r[np.where(r < x_min * r_core)] = x_min * r_core - return r - - @staticmethod - def _sigma2rho0(sigma0, r_core): - """ - Converts the convergence normalization to the 3d normalization - :param sigma0: convergence at r=0 - :param r_core: core radius [arcsec] - :return: density normalization in units 1/arcsec, or rho_0_physical / sigma_crit - """ - return sigma0 / r_core - - @staticmethod - def _rho02sigma(rho0, r_core): - """ - Converts the convergence normalization to the 3d normalization - :param rho0: convergence at r=0 - :param r_core: core radius [arcsec] - :return: density normalization in units 1/arcsec, or rho_0_physical / sigma_crit - """ - return rho0 * r_core - - @staticmethod - def _f(x, gamma): - """ - Returns the solution of the 2D mass integral defined such that - - .. math:: - - m_{\\rm{2D}}\\left(R\\right) = 4 \\pi r_{\\rm{core}}^3 - \\rho_0 F\\left(\\frac{R}{r_{\\rm{core}}}, \\gamma\\right) - - :param x: dimensionless radius r/r_core - :param gamma: logarithmic slope at r -> infinity - :return: a number - """ - if gamma == 3: - return 0.5 * np.log(x ** 2 + 1) - elif gamma == 2: - return np.pi/2 * ((x**2 + 1)**0.5 - 1) - else: - gamma_func_term = gamma_func(0.5 * (gamma - 1)) / gamma_func(0.5 * gamma) - prefactor = np.sqrt(np.pi) * gamma_func_term / (2 * (gamma - 3)) - term = (1 - (1 + x ** 2) ** ((3 - gamma) / 2)) - return prefactor * term - - @staticmethod - def _g(x, gamma): - """ - Returns the solution of the 3D mass integral defined such that - Returns the solution of the 2D mass integral defined such that - - .. math:: - m_{\\rm{3D}}\\left(R\\right) = 4 \\pi r_{\\rm{core}}^3 - \\rho_0 G\\left(\\frac{R}{r_{\\rm{core}}}, \\gamma\\right) - - :param x: dimensionless radius r/r_core - :param gamma: logarithmic slope at r -> infinity - :return: a number - """ - - if gamma == 3: - return np.arcsinh(x) - x / (1 + x ** 2) ** 0.5 - elif gamma == 2: - return x - np.arctan(x) - else: - prefactor = 1 / ((gamma - 3) * (gamma - 1)) / x - term = hyp2f1(-0.5, gamma / 2, 0.5, -x ** 2) - (1 + x ** 2) ** ((2 - gamma) / 2) * ( - 1 + x ** 2 * (gamma - 1)) - return prefactor * term
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/spp.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/spp.html deleted file mode 100644 index f7cb832b6..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/spp.html +++ /dev/null @@ -1,309 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.spp — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.spp

-__author__ = 'sibirrer'
-
-
-import numpy as np
-import scipy.special as special
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-
-__all__ = ['SPP']
-
-
-
[docs]class SPP(LensProfileBase): - """ - class for circular power-law mass distribution - """ - param_names = ['theta_E', 'gamma', 'center_x', 'center_y'] - lower_limit_default = {'theta_E': 0, 'gamma': 1.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'theta_E': 100, 'gamma': 2.5, 'center_x': 100, 'center_y': 100} - -
[docs] def function(self, x, y, theta_E, gamma, center_x=0, center_y=0): - """ - :param x: set of x-coordinates - :type x: array of size (n) - :param theta_E: Einstein radius of lens - :type theta_E: float. - :param gamma: power law slope of mass profile - :type gamma: <2 float - :returns: function - :raises: AttributeError, KeyError - """ - gamma = self._gamma_limit(gamma) - - x_ = x - center_x - y_ = y - center_y - E = theta_E / ((3. - gamma) / 2.) ** (1. / (1. - gamma)) - # E = phi_E_spp - eta= -gamma + 3 - - p2 = x_**2+y_**2 - s2 = 0. # softening - return 2 * E**2/eta**2 * ((p2 + s2)/E**2)**(eta/2)
- -
[docs] def derivatives(self, x, y, theta_E, gamma, center_x=0., center_y=0.): - - gamma = self._gamma_limit(gamma) - - xt1 = x - center_x - xt2 = y - center_y - - r2 = xt1*xt1+xt2*xt2 - a = np.maximum(r2, 0.000001) - r = np.sqrt(a) - alpha = theta_E * (r2/theta_E**2) ** (1 - gamma/2.) - fac = alpha/r - f_x = fac*xt1 - f_y = fac*xt2 - return f_x, f_y
- -
[docs] def hessian(self, x, y, theta_E, gamma, center_x=0., center_y=0.): - gamma = self._gamma_limit(gamma) - xt1 = x - center_x - xt2 = y - center_y - E = theta_E / ((3. - gamma) / 2.) ** (1. / (1. - gamma)) - # E = phi_E_spp - eta = -gamma + 3. - - P2 = xt1**2+xt2**2 - if isinstance(P2, int) or isinstance(P2, float): - a = max(0.000001,P2) - else: - a=np.empty_like(P2) - p2 = P2[P2>0] #in the SIS regime - a[P2==0] = 0.000001 - a[P2>0] = p2 - - kappa = 1./eta*(a/E**2)**(eta/2-1)*((eta-2)*(xt1**2+xt2**2)/a+(1+1)) - gamma1 = 1./eta*(a/E**2)**(eta/2-1)*((eta/2-1)*(2*xt1**2-2*xt2**2)/a) - gamma2 = 4*xt1*xt2*(1./2-1/eta)*(a/E**2)**(eta/2-2)/E**2 - - f_xx = kappa + gamma1 - f_yy = kappa - gamma1 - f_xy = gamma2 - return f_xx, f_xy, f_xy, f_yy
- -
[docs] @staticmethod - def rho2theta(rho0, gamma): - """ - converts 3d density into 2d projected density parameter - :param rho0: - :param gamma: - :return: - """ - fac = np.sqrt(np.pi) * special.gamma(1. / 2 * (-1 + gamma)) / special.gamma(gamma / 2.) * 2 / (3 - gamma) * rho0 - - #fac = theta_E**(gamma - 1) - theta_E = fac**(1. / (gamma - 1)) - return theta_E
- -
[docs] @staticmethod - def theta2rho(theta_E, gamma): - """ - converts projected density parameter (in units of deflection) into 3d density parameter - :param theta_E: - :param gamma: - :return: - """ - fac1 = np.sqrt(np.pi) * special.gamma(1. / 2 * (-1 + gamma)) / special.gamma(gamma / 2.) * 2 / (3 - gamma) - fac2 = theta_E**(gamma - 1) - rho0 = fac2 / fac1 - return rho0
- -
[docs] @staticmethod - def mass_3d(r, rho0, gamma): - """ - mass enclosed a 3d sphere or radius r - :param r: - :param a: - :param s: - :return: - """ - mass_3d = 4 * np.pi * rho0 /(-gamma + 3) * r ** (-gamma + 3) - return mass_3d
- -
[docs] def mass_3d_lens(self, r, theta_E, gamma): - """ - - :param r: - :param theta_E: - :param gamma: - :return: - """ - rho0 = self.theta2rho(theta_E, gamma) - return self.mass_3d(r, rho0, gamma)
- -
[docs] def mass_2d(self, r, rho0, gamma): - """ - mass enclosed projected 2d sphere of radius r - :param r: - :param rho0: - :param a: - :param s: - :return: - """ - alpha = np.sqrt(np.pi) * special.gamma(1. / 2 * (-1 + gamma)) / special.gamma(gamma / 2.) * r ** (2 - gamma)/(3 - gamma) *np.pi * 2 * rho0 - mass_2d = alpha*r - return mass_2d
- -
[docs] def mass_2d_lens(self, r, theta_E, gamma): - """ - - :param r: projected radius - :param theta_E: Einstein radius - :param gamma: power-law slope - :return: 2d projected radius enclosed - """ - rho0 = self.theta2rho(theta_E, gamma) - return self.mass_2d(r, rho0, gamma)
- -
[docs] def grav_pot(self, x, y, rho0, gamma, center_x=0, center_y=0): - """ - gravitational potential (modulo 4 pi G and rho0 in appropriate units) - :param x: - :param y: - :param rho0: - :param a: - :param s: - :param center_x: - :param center_y: - :return: - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - mass_3d = self.mass_3d(r, rho0, gamma) - pot = mass_3d/r - return pot
- -
[docs] @staticmethod - def density(r, rho0, gamma): - """ - computes the density - :param x: - :param y: - :param rho0: - :param a: - :param s: - :return: - """ - rho = rho0 / r**gamma - return rho
- -
[docs] def density_lens(self, r, theta_E, gamma): - """ - computes the density at 3d radius r given lens model parameterization. - The integral in projected in units of angles (i.e. arc seconds) results in the convergence quantity. - - """ - rho0 = self.theta2rho(theta_E, gamma) - return self.density(r, rho0, gamma)
- -
[docs] @staticmethod - def density_2d(x, y, rho0, gamma, center_x=0, center_y=0): - """ - projected density - :param x: - :param y: - :param rho0: - :param a: - :param s: - :param center_x: - :param center_y: - :return: - """ - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_**2 + y_**2) - sigma = np.sqrt(np.pi) * special.gamma(1./2*(-1+gamma))/special.gamma(gamma/2.) * r**(1-gamma) * rho0 - return sigma
- - @staticmethod - def _gamma_limit(gamma): - """ - limits the power-law slope to certain bounds - - :param gamma: power-law slope - :return: bounded power-law slopte - """ - return gamma
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/tnfw.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/tnfw.html deleted file mode 100644 index 416ad0e15..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/tnfw.html +++ /dev/null @@ -1,496 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.tnfw — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.tnfw

-__author__ = 'sibirrer'
-
-# this file contains a class to compute the truncated Navaro-Frank-White function (Baltz et al 2009)in mass/kappa space
-# the potential therefore is its integral
-
-import numpy as np
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-from lenstronomy.LensModel.Profiles.nfw import NFW
-
-__all__ = ['TNFW']
-
-
-
[docs]class TNFW(LensProfileBase): - """ - this class contains functions concerning the truncated NFW profile with a truncation function (r_trunc^2)*(r^2+r_trunc^2) - - density equation is: - - .. math:: - \\rho(r) = \\frac{r_\\text{trunc}^2}{r^2+r_\\text{trunc}^2}\\frac{\\rho_0(\\alpha_{R_s})}{r/R_s(1+r/R_s)^2} - - relation are: R_200 = c * Rs - - """ - profile_name = 'TNFW' - param_names = ['Rs', 'alpha_Rs', 'r_trunc', 'center_x', 'center_y'] - lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'r_trunc': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'r_trunc': 100, 'center_x': 100, 'center_y': 100} - - def __init__(self): - """ - - """ - self._s = 0.001 - super(LensProfileBase, self).__init__() - -
[docs] def function(self, x, y, Rs, alpha_Rs, r_trunc, center_x=0, center_y=0): - """ - - :param x: angular position - :param y: angular position - :param Rs: angular turn over point - :param alpha_Rs: deflection at Rs - :param r_trunc: truncation radius - :param center_x: center of halo - :param center_y: center of halo - :return: lensing potential - """ - rho0_input = self.alpha2rho0(alpha_Rs=alpha_Rs, Rs=Rs) - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_ ** 2 + y_ ** 2) - R = np.maximum(R, self._s * Rs) - f_ = self.nfwPot(R, Rs, rho0_input, r_trunc) - - return f_
- - def _L(self, x, tau): - """ - Logarithm that appears frequently - :param x: r/Rs - :param tau: t/Rs - :return: - """ - x = np.maximum(x, self._s) - return np.log(x * (tau + np.sqrt(tau ** 2 + x ** 2)) ** -1) - -
[docs] def F(self, x): - """ - Classic NFW function in terms of arctanh and arctan - :param x: r/Rs - :return: - """ - - if isinstance(x, np.ndarray): - x = np.maximum(x, self._s) - nfwvals = np.zeros_like(x) - inds1 = np.where(x < 1) - inds2 = np.where(x > 1) - inds3 = np.where(x == 1) - nfwvals[inds1] = (1 - x[inds1] ** 2) ** -.5 * np.arctanh((1 - x[inds1] ** 2) ** .5) - nfwvals[inds2] = (x[inds2] ** 2 - 1) ** -.5 * np.arctan((x[inds2] ** 2 - 1) ** .5) - nfwvals[inds3] = 1 - return nfwvals - - elif isinstance(x, float) or isinstance(x, int): - x = np.maximum(x, 0) - if x == 1: - return 1 - elif x == 0: - return 0 - elif x < 1: - return (1 - x ** 2) ** -.5 * np.arctanh((1 - x ** 2) ** .5) - else: - return (x ** 2 - 1) ** -.5 * np.arctan((x ** 2 - 1) ** .5)
- -
[docs] def derivatives(self, x, y, Rs, alpha_Rs, r_trunc, center_x=0, center_y=0): - - """ - returns df/dx and df/dy of the function (integral of TNFW), which are the deflection angles - - :param x: angular position (normally in units of arc seconds) - :param y: angular position (normally in units of arc seconds) - :param Rs: turn over point in the slope of the NFW profile in angular unit - :param alpha_Rs: deflection (angular units) at projected Rs - :param r_trunc: truncation radius (angular units) - :param center_x: center of halo (in angular units) - :param center_y: center of halo (in angular units) - :return: deflection angle in x, deflection angle in y - """ - rho0_input = self.alpha2rho0(alpha_Rs=alpha_Rs, Rs=Rs) - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_ ** 2 + y_ ** 2) - R = np.maximum(R, self._s * Rs) - f_x, f_y = self.nfwAlpha(R, Rs, rho0_input, r_trunc, x_, y_) - return f_x, f_y
- -
[docs] def hessian(self, x, y, Rs, alpha_Rs, r_trunc, center_x=0, center_y=0): - - """ - returns d^2f/dx^2, d^2f/dxdy, d^2f/dydx, d^2f/dy^2 of the TNFW potential f - - :param x: angular position (normally in units of arc seconds) - :param y: angular position (normally in units of arc seconds) - :param Rs: turn over point in the slope of the NFW profile in angular unit - :param alpha_Rs: deflection (angular units) at projected Rs - :param r_trunc: truncation radius (angular units) - :param center_x: center of halo (in angular units) - :param center_y: center of halo (in angular units) - :return: Hessian matrix of function d^2f/dx^2, d^f/dy^2, d^2/dxdy - """ - - rho0_input = self.alpha2rho0(alpha_Rs=alpha_Rs, Rs=Rs) - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_ ** 2 + y_ ** 2) - R = np.maximum(R, self._s * Rs) - - kappa = self.density_2d(x_, y_, Rs, rho0_input, r_trunc) - gamma1, gamma2 = self.nfwGamma(R, Rs, rho0_input, r_trunc, x_, y_) - f_xx = kappa + gamma1 - f_yy = kappa - gamma1 - f_xy = gamma2 - return f_xx, f_xy, f_xy, f_yy
- -
[docs] @staticmethod - def density(r, Rs, rho0, r_trunc): - """ - three dimensional truncated NFW profile - - :param r: radius of interest - :type r: float/numpy array - :param Rs: scale radius - :type Rs: float > 0 - :param r_trunc: truncation radius (angular units) - :type r_trunc: float > 0 - :return: rho(r) density - """ - return (r_trunc ** 2 * (r_trunc ** 2 + r ** 2) ** -1) * rho0 / (r / Rs * (1 + r / Rs) ** 2)
- -
[docs] def density_2d(self, x, y, Rs, rho0, r_trunc, center_x=0, center_y=0): - """ - projected two dimensional NFW profile (kappa*Sigma_crit) - - :param R: projected radius of interest - :type R: float/numpy array - :param Rs: scale radius - :type Rs: float - :param rho0: density normalization (characteristic density) - :type rho0: float - :param r_trunc: truncation radius (angular units) - :type r_trunc: float > 0 - :return: Epsilon(R) projected density at radius R - """ - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_ ** 2 + y_ ** 2) - x = R * Rs ** -1 - tau = float(r_trunc) * Rs ** -1 - Fx = self._F(x, tau) - return 2 * rho0 * Rs * Fx
- -
[docs] def mass_3d(self, r, Rs, rho0, r_trunc): - """ - mass enclosed a 3d sphere or radius r - - :param r: 3d radius - :param Rs: scale radius - :param rho0: density normalization (characteristic density) - :param r_trunc: truncation radius (angular units) - :return: M(<r) - """ - - x = r * Rs ** -1 - x = np.maximum(x, self._s) - func = (r_trunc ** 2 * (-2 * x * (1 + r_trunc ** 2) + 4 * (1 + x) * r_trunc * np.arctan(x / r_trunc) - - 2 * (1 + x) * (-1 + r_trunc ** 2) * np.log(Rs) + 2 * (1 + x) * (-1 + r_trunc ** 2) * np.log(Rs * (1 + x)) + - 2 * (1 + x) * (-1 + r_trunc ** 2) * np.log(Rs * r_trunc) - - (1 + x) * (-1 + r_trunc ** 2) * np.log(Rs ** 2 * (x ** 2 + r_trunc ** 2)))) / (2. * (1 + x) * (1 + r_trunc ** 2) ** 2) - - m_3d = 4*np.pi*Rs ** 3 * rho0 * func - return m_3d
- -
[docs] def nfwPot(self, R, Rs, rho0, r_trunc): - """ - lensing potential of truncated NFW profile - - :param R: radius of interest - :type R: float/numpy array - :param Rs: scale radius - :type Rs: float - :param rho0: density normalization (characteristic density) - :type rho0: float - :param r_trunc: truncation radius (angular units) - :type r_trunc: float > 0 - :return: lensing potential - """ - x = R / Rs - x = np.maximum(x, self._s) - tau = float(r_trunc) / Rs - hx = self._h(x, tau) - return 2 * rho0 * Rs ** 3 * hx
- -
[docs] def nfwAlpha(self, R, Rs, rho0, r_trunc, ax_x, ax_y): - """ - deflection angel of NFW profile along the projection to coordinate axis - - :param R: radius of interest - :type R: float/numpy array - :param Rs: scale radius - :type Rs: float - :param rho0: density normalization (characteristic density) - :type rho0: float - :param r_trunc: truncation radius (angular units) - :type r_trunc: float > 0 - :param axis: projection to either x- or y-axis - :type axis: same as R - :return: - """ - R = np.maximum(R, self._s * Rs) - x = R / Rs - x = np.maximum(x, self._s) - tau = float(r_trunc) / Rs - gx = self._g(x, tau) - a = 4 * rho0 * Rs * gx / x ** 2 - return a * ax_x, a * ax_y
- -
[docs] def nfwGamma(self, R, Rs, rho0, r_trunc, ax_x, ax_y): - """ - - shear gamma of NFW profile (times Sigma_crit) along the projection to coordinate 'axis' - - :param R: radius of interest - :type R: float/numpy array - :param Rs: scale radius - :type Rs: float - :param rho0: density normalization (characteristic density) - :type rho0: float - :param r_trunc: truncation radius (angular units) - :type r_trunc: float > 0 - :param axis: projection to either x- or y-axis - :type axis: same as R - :return: - """ - R = np.maximum(R, self._s * Rs) - x = R / Rs - tau = float(r_trunc) * Rs ** -1 - gx = self._g(x, tau) - Fx = self._F(x, tau) - a = 2*rho0*Rs*(2*gx/x**2 - Fx) - return a * (ax_y ** 2 - ax_x ** 2) / R ** 2, -a * 2 * (ax_x * ax_y) / R ** 2
- -
[docs] def mass_2d(self, R, Rs, rho0, r_trunc): - """ - analytic solution of the projection integral (convergence) - - :param R: projected radius - :param Rs: scale radius - :param rho0: density normalization (characteristic density) - :param r_trunc: truncation radius (angular units) - :return: mass enclosed 2d projected cylinder - """ - - x = R / Rs - x = np.maximum(x, self._s) - tau = r_trunc / Rs - gx = self._g(x,tau) - m_2d = 4 * rho0 * Rs * R ** 2 * gx / x ** 2 * np.pi - return m_2d
- - def _F(self, X, tau): - """ - analytic solution of the projection integral - (convergence) - - :param X: R/Rs - :type X: float >0 - """ - t2 = tau ** 2 - X = np.maximum(X, self._s ) - _F = self.F(X) - a = t2*(t2+1)**-2 - if isinstance(X, np.ndarray): - #b = (t2 + 1) * (X ** 2 - 1) ** -1 * (1 - _F) - b = np.ones_like(X) - b[X == 1] = (t2+1) * 1./3 - b[X != 1] = (t2 + 1) * (X[X != 1] ** 2 - 1) ** -1 * (1 - _F[X != 1]) - - elif isinstance(X, float) or isinstance(X, int): - if X == 1: - b = (t2+1)* 1./3 - else: - b = (t2+1)*(X**2-1)**-1*(1-_F) - else: - raise ValueError("The variable type is not compatible with the function, please use float," - " int or ndarray's.") - - c = 2*_F - d = -np.pi*(t2+X**2)**-0.5 - e = (t2-1)*(tau*(t2+X**2)**0.5)**-1*self._L(X, tau) - result = a * (b + c + d + e) - - return result - - def _g(self, x, tau): - """ - analytic solution of integral for NFW profile to compute deflection angel and gamma - - :param x: R/Rs - :type x: float >0 - """ - x = np.maximum(x, self._s) - return tau ** 2 * (tau ** 2 + 1) ** -2 * ( - (tau ** 2 + 1 + 2 * (x ** 2 - 1)) * self.F(x) + tau * np.pi + (tau ** 2 - 1) * np.log(tau) + - np.sqrt(tau ** 2 + x ** 2) * (-np.pi + self._L(x, tau) * (tau ** 2 - 1) * tau ** -1)) - - @staticmethod - def _cos_function(x): - - if isinstance(x, np.ndarray) or isinstance(x, list): - out = np.empty_like(x) - inds1 = np.where(x < 1) - inds2 = np.where(x >= 1) - - out[inds1] = -np.arccosh(1 / x[inds1]) ** 2 - out[inds2] = np.arccos(1 / x[inds2]) ** 2 - - elif isinstance(x, float) or isinstance(x, int): - if x < 1: - out = -np.arccosh(1 / x) ** 2 - else: - out = np.arccos(1 / x) ** 2 - - else: - raise Exception('x data type %s not recognized.' % x) - - return out - - def _h(self, x, tau): - - """ - expression for the integral to compute potential - - :param x: R/Rs - :param tau: r_trunc/Rs - :type x: float >0 - """ - x = np.maximum(x, self._s) - - u = x ** 2 - t2 = tau ** 2 - Lx = self._L(x, tau) - Fx = self.F(x) - - return (t2 + 1) ** -2 * ( - 2 * t2 * np.pi * (tau - (t2 + u) ** .5 + tau * np.log(tau + (t2 + u) ** .5)) - + - 2 * (t2 - 1) * tau * (t2 + u) ** .5 * Lx - + - t2 * (t2 - 1) * Lx ** 2 - + - 4 * t2 * (u - 1) * Fx - + - t2 * (t2 - 1) * self._cos_function(x) - + - t2 * ((t2 - 1) * np.log(tau) - t2 - 1) * np.log(u) - - - t2 * ( - (t2 - 1) * np.log(tau) * np.log(4 * tau) + 2 * np.log(0.5 * tau) - 2 * tau * ( - tau - np.pi) * np.log( - tau * 2))) - -
[docs] @staticmethod - def alpha2rho0(alpha_Rs, Rs): - """ - convert angle at Rs into rho0; neglects the truncation - - :param alpha_Rs: deflection angle at RS - :param Rs: scale radius - :return: density normalization (characteristic density) - """ - return NFW.alpha2rho0(alpha_Rs, Rs)
- -
[docs] @staticmethod - def rho02alpha(rho0, Rs): - """ - convert rho0 to angle at Rs; neglects the truncation - - :param rho0: density normalization (characteristic density) - :param Rs: scale radius - :return: deflection angle at RS - """ - return NFW.rho02alpha(rho0, Rs)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/uldm.html b/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/uldm.html deleted file mode 100644 index dbe72281e..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Profiles/uldm.html +++ /dev/null @@ -1,328 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Profiles.uldm — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Profiles.uldm

-__author__ = 'lucateo'
-
-# this file contains a class to compute the Ultra Light Dark Matter soliton profile
-import numpy as np
-import scipy.interpolate as interp
-from scipy.special import gamma, hyp2f1
-from lenstronomy.LensModel.Profiles.base_profile import LensProfileBase
-import lenstronomy.Util.constants as const
-__all__ = ['Uldm']
-
-
-
[docs]class Uldm(LensProfileBase): - """ - This class contains functions concerning the ULDM soliton density profile, - whose good approximation is (see for example https://arxiv.org/pdf/1406.6586.pdf ) - - .. math:: - - \\rho = \\rho_0 (1 + a(\\theta/\\theta_c)^2)^{-\\beta} - - where :math:`\\theta_c` is the core radius, corresponding to the radius where the - density drops by half its central value, :math: `\\beta` is the slope (called just slope - in the parameters of this model), :math: `\\rho_0 = \\kappa_0 \\Sigma_c/D_lens`, - and :math: `a` is a parameter, dependent on :math: `\\beta`, chosen such - that :math: `\\theta_c` indeed corresponds to the radius where the density drops by half - (simple math gives :math: `a = 0.5^{-1/\\beta} - 1` ). - For an ULDM soliton profile without contributions to background potential, it - turns out that :math: `\\beta = 8, a = 0.091`. We allow :math: `\\beta` to be - different from 8 to model solitons which feel the influence of background - potential (see 2105.10873) - The profile has, as parameters: - :param kappa_0: central convergence - :param theta_c: core radius (in arcseconds) - :param slope: exponent entering the profile, default value is 8 - """ - _s = 0.000001 # numerical limit for minimal radius - param_names = ['kappa_0', 'theta_c', 'slope', 'center_x', 'center_y'] - lower_limit_default = {'kappa_0': 0, 'theta_c': 0, 'slope': 3.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'kappa_0': 1., 'theta_c': 100, 'slope': 10, 'center_x': 100, 'center_y': 100} - -
[docs] def rhotilde(self, kappa_0, theta_c, slope=8): - """ - Computes the central density in angular units - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :param slope: exponent entering the profile - :return: central density in 1/arcsec - """ - a_factor_sqrt = np.sqrt( (0.5)**(-1/slope) -1) - num_factor = gamma(slope) / gamma(slope - 1/2) * a_factor_sqrt / np.sqrt(np.pi) - return kappa_0 * num_factor / theta_c
- -
[docs] def function(self, x, y, kappa_0, theta_c, center_x=0, center_y=0, slope=8): - """ - :param x: angular position (normally in units of arc seconds) - :param y: angular position (normally in units of arc seconds) - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :param slope: exponent entering the profile - :param center_x: center of halo (in angular units) - :param center_y: center of halo (in angular units) - :return: lensing potential (in arcsec^2) - """ - from mpmath import hyp3f2 - - x_ = x - center_x - y_ = y - center_y - r = np.sqrt(x_** 2 + y_** 2) - r = np.maximum(r, self._s) - a_factor_sqrt = np.sqrt( (0.5)**(-1./slope) -1) - if np.isscalar(r) == True: - hypgeom = float(kappa_0 /2 * r**2 * - hyp3f2(1, 1, slope - 0.5, 2, 2, -(a_factor_sqrt * r /theta_c )**2)) - else: - hypgeom = np.array([ kappa_0 /2. * r_i**2. * - hyp3f2(1, 1, slope - 0.5, 2, 2, -(a_factor_sqrt * r_i / theta_c)**2.) for r_i in r], dtype=float) - return hypgeom
- -
[docs] def alpha_radial(self, r, kappa_0, theta_c, slope=8): - """ - returns the radial part of the deflection angle - - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :param slope: exponent entering the profile - :param r: radius where the deflection angle is computed - :return: radial deflection angle - """ - a_factor = (0.5)**(-1./slope) -1 - prefactor = 2./(2*slope -3) * kappa_0 * theta_c**2 / a_factor - denominator_factor = (1 + a_factor * r**2/theta_c**2)**(slope - 3./2) - return prefactor/r * (1 - 1/denominator_factor)
- -
[docs] def derivatives(self, x, y, kappa_0, theta_c, center_x=0, center_y=0, slope=8): - """ - returns df/dx and df/dy of the function (lensing potential), which are the deflection angles - - :param x: angular position (normally in units of arc seconds) - :param y: angular position (normally in units of arc seconds) - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :param slope: exponent entering the profile - :param center_x: center of halo (in angular units) - :param center_y: center of halo (in angular units) - :return: deflection angle in x, deflection angle in y - """ - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_**2 + y_**2) - R = np.maximum(R,0.00000001) - f_x = self.alpha_radial(R, kappa_0, theta_c, slope) * x_ / R - f_y = self.alpha_radial(R, kappa_0, theta_c, slope) * y_ / R - return f_x, f_y
- -
[docs] def hessian(self, x, y, kappa_0, theta_c, center_x=0, center_y=0, slope=8): - """ - :param x: angular position (normally in units of arc seconds) - :param y: angular position (normally in units of arc seconds) - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :param slope: exponent entering the profile - :param center_x: center of halo (in angular units) - :param center_y: center of halo (in angular units) - :return: Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2 - """ - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_**2 + y_**2) - R = np.maximum(R,0.00000001) - a_factor = (0.5)**(-1./slope) -1 - prefactor = 2./(2*slope -3) * kappa_0 * theta_c**2 / a_factor - # denominator factor - denominator = 1 + a_factor * R**2/theta_c**2 - factor1 = (2*slope - 3) * a_factor * denominator**(1./2 - slope) / (theta_c**2 * R**2) - factor2 = 1/R**4 * (1 - denominator**(3./2 - slope)) - f_xx = prefactor * (factor1 * x_**2 + factor2 * (y_**2 - x_**2)) - f_yy = prefactor * (factor1 * y_**2 + factor2 * (x_**2 - y_**2)) - f_xy = prefactor * (factor1 * x_ * y_ - factor2 * 2*x_*y_) - return f_xx, f_xy, f_xy, f_yy
- -
[docs] def density(self, R, kappa_0, theta_c, slope=8): - """ - three dimensional ULDM profile in angular units - (rho0_physical = rho0_angular Sigma_crit / D_lens) - :param R: radius of interest - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :param slope: exponent entering the profile - :return: rho(R) density in angular units - """ - rhotilde = self.rhotilde(kappa_0, theta_c, slope) - a_factor = (0.5)**(-1./slope) -1 - return rhotilde/(1 + a_factor* (R/theta_c)**2)**slope
- -
[docs] def density_lens(self, r, kappa_0, theta_c, slope=8): - """ - computes the density at 3d radius r given lens model parameterization. - The integral in the LOS projection of this quantity results in the - convergence quantity. - - :param r: 3d radius - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :param slope: exponent entering the profile - :return: density rho(r) - """ - return self.density(r, kappa_0, theta_c, slope)
- -
[docs] def kappa_r(self, R, kappa_0, theta_c, slope=8): - """ - convergence of the cored density profile. This routine is also for testing - - :param R: radius (angular scale) - :param kappa_0: convergence in the core - :param theta_c: core radius - :param slope: exponent entering the profile - :return: convergence at r - """ - a_factor = (0.5)**(-1./slope) -1 - return kappa_0 * (1 + a_factor * (R/theta_c)**2)**(1./2 - slope)
- - -
[docs] def density_2d(self, x, y, kappa_0, theta_c, center_x=0, center_y=0, slope=8): - """ - projected two dimensional ULDM profile (convergence * Sigma_crit), but - given our units convention for rho0, it is basically the convergence - - :param R: radius of interest - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :param slope: exponent entering the profile - :return: Epsilon(R) projected density at radius R - """ - x_ = x - center_x - y_ = y - center_y - R = np.sqrt(x_**2 + y_**2) - return self.kappa_r(R, kappa_0, theta_c, slope)
- - def _mass_integral(self, x, slope=8): - """ - Returns the analitic result of the integral appearing in mass expression - :param slope: exponent entering the profile - :return: integral result - """ - hypF = np.real(hyp2f1(3./2, slope, 5./2, - x**2)) - return 1./3 * x**3 * hypF - -
[docs] def mass_3d(self, R, kappa_0, theta_c, slope=8): - """ - mass enclosed a 3d sphere or radius r - :param R: radius in arcseconds - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :param slope: exponent entering the profile - :return: mass of soliton in angular units - """ - rhotilde = self.rhotilde(kappa_0, theta_c, slope) - a_factor = (0.5)**(-1./slope) -1 - prefactor = 4. * np.pi * rhotilde * theta_c**3 / (a_factor)**(1.5) - m_3d = prefactor * (self._mass_integral(R/theta_c * np.sqrt(a_factor), slope) - - self._mass_integral(0, slope) ) - return m_3d
- -
[docs] def mass_3d_lens(self, r, kappa_0, theta_c, slope=8): - """ - mass enclosed a 3d sphere or radius r - :param r: radius over which the mass is computed - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :param slope: exponent entering the profile - :return: mass enclosed in 3D ball - """ - m_3d = self.mass_3d(r, kappa_0, theta_c, slope) - return m_3d
- -
[docs] def mass_2d(self, R, kappa_0, theta_c, slope=8): - """ - mass enclosed a 2d sphere or radius r - :param R: radius over which the mass is computed - :param kappa_0: central convergence of profile - :param theta_c: core radius (in arcsec) - :param slope: exponent entering the profile - :return: mass enclosed in 2d sphere - """ - m_2d = np.pi * R * self.alpha_radial(R, kappa_0, theta_c, slope) - return m_2d
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/QuadOptimizer/multi_plane_fast.html b/docs/_build/html/_modules/lenstronomy/LensModel/QuadOptimizer/multi_plane_fast.html deleted file mode 100644 index e27cff4c6..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/QuadOptimizer/multi_plane_fast.html +++ /dev/null @@ -1,249 +0,0 @@ - - - - - - - - lenstronomy.LensModel.QuadOptimizer.multi_plane_fast — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.QuadOptimizer.multi_plane_fast

-__author__ = 'dgilman'
-
-from lenstronomy.LensModel.lens_model import LensModel
-import numpy as np
-
-
-
[docs]class MultiplaneFast(object): - - """ - This class accelerates ray tracing computations in multi plane lensing for quadruple image lenses by only - computing the deflection from objects in front of the main deflector at z_lens one time. The first ray tracing - computation through the foreground is saved and re-used, but it will always have the same shape as the initial - x_image, y_image arrays. - - """ - - def __init__(self, x_image, y_image, z_lens, z_source, lens_model_list, redshift_list, - astropy_instance, param_class, foreground_rays, - tol_source=1e-5, numerical_alpha_class=None): - - """ - - :param x_image: x_image to fit - :param y_image: y_image to fit - :param z_lens: lens redshift - :param z_source: source redshift - :param lens_model_list: list of lens models - :param redshift_list: list of lens redshifts - :param astropy_instance: instance of astropy to pass to lens model - :param param_class: an instance of ParamClass (see documentation in QuadOptimmizer.param_manager) - :param foreground_rays: (optional) pre-computed foreground rays from a previous iteration, if they are not specified - they will be re-computed - :param tol_source: source plane chi^2 sigma - :param numerical_alpha_class: class for computing numerically tabulated deflection angles - """ - - self.lensModel = LensModel(lens_model_list, z_lens, z_source, redshift_list, astropy_instance, - multi_plane=True, numerical_alpha_class=numerical_alpha_class) - - lensmodel_list_to_vary = lens_model_list[0:param_class.to_vary_index] - redshift_list_to_vary = redshift_list[0:param_class.to_vary_index] - lensmodel_list_fixed = lens_model_list[param_class.to_vary_index:] - redshift_list_fixed = redshift_list[param_class.to_vary_index:] - - self.lens_model_to_vary = LensModel(lensmodel_list_to_vary, z_lens, z_source, redshift_list_to_vary, - cosmo=astropy_instance, multi_plane=True, - numerical_alpha_class=numerical_alpha_class) - - self.lens_model_fixed = LensModel(lensmodel_list_fixed, z_lens, z_source, redshift_list_fixed, - cosmo=astropy_instance, multi_plane=True, - numerical_alpha_class=numerical_alpha_class) - - self._z_lens = z_lens - - self._z_source = z_source - - self._x_image = x_image - self._y_image = y_image - self._param_class = param_class - - self._tol_source = tol_source - - self._foreground_rays = foreground_rays - -
[docs] def chi_square(self, args_lens, *args, **kwargs): - - """ - - :param args_lens: array of lens model parameters being optimized, computed from kwargs_lens in a specified - param_class, see documentation in QuadOptimizer.param_manager - :return: total chi^2 penalty (source chi^2 + param chi^2), where param chi^2 is computed by the specified - param_class - """ - source_plane_penlty = self.source_plane_chi_square(args_lens) - - param_penalty = self._param_class.param_chi_square_penalty(args_lens) - - return source_plane_penlty + param_penalty
- -
[docs] def logL(self, args_lens, *args, **kwargs): - - """ - - :param args_lens: array of lens model parameters being optimized, computed from kwargs_lens in a specified - param_class, see documentation in QuadOptimizer.param_manager - :return: the log likelihood corresponding to the given chi^2 - """ - chi_square = self.chi_square(args_lens) - - return -0.5 * chi_square
- -
[docs] def source_plane_chi_square(self, args_lens, *args, **kwargs): - - """ - - :param args_lens: array of lens model parameters being optimized, computed from kwargs_lens in a specified - param_class, see documentation in QuadOptimizer.param_manager - :return: chi2 penalty for the source position (all images must map to the same source coordinate) - """ - - betax, betay = self.ray_shooting_fast(args_lens) - - dx_source = ((betax[0] - betax[1]) ** 2 + (betax[0] - betax[2]) ** 2 + ( - betax[0] - betax[3]) ** 2 + ( - betax[1] - betax[2]) ** 2 + - (betax[1] - betax[3]) ** 2 + (betax[2] - betax[3]) ** 2) - dy_source = ((betay[0] - betay[1]) ** 2 + (betay[0] - betay[2]) ** 2 + ( - betay[0] - betay[3]) ** 2 + ( - betay[1] - betay[2]) ** 2 + - (betay[1] - betay[3]) ** 2 + (betay[2] - betay[3]) ** 2) - - chi_square = 0.5 * (dx_source + dy_source) / self._tol_source ** 2 - - return chi_square
- -
[docs] def ray_shooting_fast(self, args_lens): - - """ - Performs a ray tracing computation through observed coordinates on the sky (self._x_image, self._y_image) - to the source plane, returning the final coordinates of each ray on the source plane - - :param args_lens: An array of parameters being optimized. The array is computed from a set of key word arguments - by an instance of ParamClass (see documentation in QuadOptimizer.param_manager) - :return: the xy coordinate of each ray traced back to the source plane - """ - - # these do not depend on kwargs_lens_array - x, y, alpha_x, alpha_y = self._ray_shooting_fast_foreground() - - # convert array into new kwargs dictionary - kw = self._param_class.args_to_kwargs(args_lens) - index = self._param_class.to_vary_index - kwargs_lens = kw[0:index] - # evaluate main deflector deflection angles - x, y, alpha_x, alpha_y = self.lens_model_to_vary.lens_model.ray_shooting_partial( - x, y, alpha_x, alpha_y, self._z_lens, self._z_lens, kwargs_lens, include_z_start=True) - - # ray trace through background halos - kwargs_lens = kw[index:] - x, y, _, _ = self.lens_model_fixed.lens_model.ray_shooting_partial( - x, y, alpha_x, alpha_y, self._z_lens, self._z_source, kwargs_lens, check_convention=False) - - beta_x, beta_y = self.lens_model_fixed.lens_model.co_moving2angle_source(x, y) - - return beta_x, beta_y
- - def _ray_shooting_fast_foreground(self): - - """ - Does the ray tracing through the foreground halos only once - """ - - if self._foreground_rays is None: - - # These do not depend on the kwargs being optimized for - kw = self._param_class.kwargs_lens - index = self._param_class.to_vary_index - kwargs_lens = kw[index:] - - x0, y0 = np.zeros_like(self._x_image), np.zeros_like(self._y_image) - x, y, alpha_x, alpha_y = self.lens_model_fixed.lens_model.ray_shooting_partial( - x0, y0, self._x_image, self._y_image, z_start=0., - z_stop=self._z_lens, kwargs_lens=kwargs_lens) - - self._foreground_rays = (x, y, alpha_x, alpha_y) - - return self._foreground_rays[0], self._foreground_rays[1], self._foreground_rays[2], self._foreground_rays[3]
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/QuadOptimizer/optimizer.html b/docs/_build/html/_modules/lenstronomy/LensModel/QuadOptimizer/optimizer.html deleted file mode 100644 index 06d49739b..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/QuadOptimizer/optimizer.html +++ /dev/null @@ -1,228 +0,0 @@ - - - - - - - - lenstronomy.LensModel.QuadOptimizer.optimizer — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.QuadOptimizer.optimizer

-__author__ = 'dgilman'
-
-from scipy.optimize import minimize
-import numpy as np
-from lenstronomy.Sampling.Samplers.pso import ParticleSwarmOptimizer
-from lenstronomy.LensModel.QuadOptimizer.multi_plane_fast import MultiplaneFast
-from lenstronomy.Sampling.Pool.pool import choose_pool
-
-__all__ = ['Optimizer']
-
-
-
[docs]class Optimizer(object): - """ - class which executes the optimization routines. Currently implemented as a particle swarm optimization followed by - a downhill simplex routine. - - Particle swarm optimizer is modified from the CosmoHammer particle swarm routine with different convergence criteria implemented. - """ - - def __init__(self, x_image, y_image, lens_model_list, redshift_list, z_lens, z_source, - parameter_class, astropy_instance=None, numerical_alpha_class=None, - particle_swarm=True, re_optimize=False, re_optimize_scale=1., - pso_convergence_mean=50000, foreground_rays=None, - tol_source=1e-5, tol_simplex_func=1e-3, simplex_n_iterations=400): - - """ - - :param x_image: x_image to fit (should be length 4) - :param y_image: y_image to fit (should be length 4) - :param lens_model_list: list of lens models for the system - :param redshift_list: list of lens redshifts for the system - :param z_lens: the main deflector redshift, the lens models being optimizer must be at this redshift - :param z_source: the source redshift - :param parameter_class: an instance of ParamClass (see documentation in QuadOptimizer.param_manager) - :param astropy_instance: an instance of astropy to pass to the lens model - :param numerical_alpha_class: a class to compute numerical deflection angles to pass to the lens model - :param particle_swarm: bool, whether or not to use a PSO fit first - :param re_optimize: bool, if True the initial spread of particles will be very tight - :param re_optimize_scale: float, controls how tight the initial spread of particles is - :param pso_convergence_mean: when to terminate the PSO fit - :param foreground_rays: (optional) can pass in pre-computed foreground light rays from a previous fit - so as to not waste time recomputing them - :param tol_source: sigma in the source plane chi^2 - :param tol_simplex_func: tolerance for the downhill simplex optimization - :param simplex_n_iterations: number of iterations per dimension for the downhill simplex optimization - """ - - self.fast_rayshooting = MultiplaneFast(x_image, y_image, z_lens, z_source, - lens_model_list, redshift_list, astropy_instance, parameter_class, - foreground_rays, tol_source, numerical_alpha_class) - - self._tol_source = tol_source - - self._pso_convergence_mean = pso_convergence_mean - - self._param_class = parameter_class - - self._tol_simplex_func = tol_simplex_func - - self._simplex_n_iterations = simplex_n_iterations - - self._particle_swarm = particle_swarm - - self._re_optimize = re_optimize - self._re_optimize_scale = re_optimize_scale - -
[docs] def optimize(self, n_particles=50, n_iterations=250, verbose=False, threadCount=1): - - """ - - :param n_particles: number of PSO particles, will be ignored if self._particle_swarm is False - :param n_iterations: number of PSO iterations, will be ignored if self._particle_swarm is False - :param verbose: whether to print stuff - :param threadCount: integer; number of threads in multi-threading mode - :return: keyword arguments that map (x_image, y_image) to the same source coordinate (source_x, source_y) - """ - - if self._particle_swarm: - - if threadCount > 1: - pool = choose_pool(mpi=False, processes=threadCount) - else: - pool = None - - kwargs = self._fit_pso(n_particles, n_iterations, pool, verbose) - - else: - kwargs = self._param_class.kwargs_lens - - kwargs_lens_final, source_penalty = self._fit_amoeba(kwargs, verbose) - - args_lens_final = self._param_class.kwargs_to_args(kwargs_lens_final) - source_x_array, source_y_array = self.fast_rayshooting.ray_shooting_fast(args_lens_final) - source_x, source_y = np.mean(source_x_array), np.mean(source_y_array) - - if verbose: - print('optimization done.') - print('Recovered source position: ', (source_x_array, source_y_array)) - - return kwargs_lens_final, [source_x, source_y]
- - def _fit_pso(self, n_particles, n_iterations, pool, verbose): - - """ - Executes the PSO - """ - - low_bounds, high_bounds = self._param_class.bounds(self._re_optimize, self._re_optimize_scale) - - pso = ParticleSwarmOptimizer(self.fast_rayshooting.logL, low_bounds, high_bounds, n_particles, - pool, args=[self._tol_source]) - - best, info = pso.optimize(n_iterations, verbose, early_stop_tolerance=self._pso_convergence_mean) - - if verbose: - print('PSO done... ') - print('source plane chi^2: ', self.fast_rayshooting.source_plane_chi_square(best)) - print('total chi^2: ', self.fast_rayshooting.chi_square(best)) - - kwargs = self._param_class.args_to_kwargs(best) - - return kwargs - - def _fit_amoeba(self, kwargs, verbose): - - """ - Executes the downhill simplex - """ - - args_init = self._param_class.kwargs_to_args(kwargs) - - options = {'adaptive': True, 'fatol': self._tol_simplex_func, - 'maxiter': self._simplex_n_iterations * len(args_init)} - - method = 'Nelder-Mead' - - if verbose: - print('starting amoeba... ') - - opt = minimize(self.fast_rayshooting.chi_square, x0=args_init, - method=method, options=options) - - kwargs = self._param_class.args_to_kwargs(opt['x']) - source_penalty = opt['fun'] - - return kwargs, source_penalty
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/QuadOptimizer/param_manager.html b/docs/_build/html/_modules/lenstronomy/LensModel/QuadOptimizer/param_manager.html deleted file mode 100644 index af31169ff..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/QuadOptimizer/param_manager.html +++ /dev/null @@ -1,376 +0,0 @@ - - - - - - - - lenstronomy.LensModel.QuadOptimizer.param_manager — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.QuadOptimizer.param_manager

-__author__ = 'dgilman'
-
-from lenstronomy.Util.param_util import shear_cartesian2polar, shear_polar2cartesian
-from lenstronomy.Util.param_util import ellipticity2phi_q
-import numpy as np
-
-# class ParamClass(object):
-#
-#     """
-#     This class handles converting a dict of parameter values into an array of parameter values to
-#     feed to the optimizer. This class can be user specified to implement any combination of lens models with arbitrary
-#     constraints on their parameters. Three examples are shown below for power law like mass models.
-#
-#     This class, if specified by user, must have the methods "kwargs_to_args" and "args_to_kwargs" (see below)
-#     """
-#     def __init__(self, kwargs_lens_init, **kwargs):
-#
-#         """
-#
-#         :param kwargs_lens_init: the initial kwargs_lens before optimizing
-#         :param args: any other args for the particular optimization routine corresponding to this class
-#         """
-#
-#         to_vary_index is the number of lens models with parameters that are being optimized. For power law + shear
-#         it equals 2, for example. The lens models being optimized should always come first in the lens_model_list
-#
-#         pass
-#
-#     @property
-#     def to_vary_index(self):
-#         return integer
-#
-#     def bounds(self, scale):
-#
-#         pass
-#
-#     @staticmethod
-#     def kwargs_to_args(kwargs):
-#
-#         pass
-#
-#     def args_to_kwargs(self, args):
-#
-#         pass
-
-
-
[docs]class PowerLawParamManager(object): - - """ - Base class for handling the translation between key word arguments and parameter arrays for - EPL mass models. This class is intended for use in modeling galaxy-scale lenses - """ - - def __init__(self, kwargs_lens_init): - - """ - - :param kwargs_lens_init: the initial kwargs_lens before optimizing - """ - - self.kwargs_lens = kwargs_lens_init - -
[docs] def param_chi_square_penalty(self, args): - - return 0.
- - @property - def to_vary_index(self): - - """ - The number of lens models being varied in this routine. This is set to 2 because the first three lens models - are EPL and SHEAR, and their parameters are being optimized. - - The kwargs_list is split at to to_vary_index with indicies < to_vary_index accessed in this class, - and lens models with indicies > to_vary_index kept fixed. - - Note that this requires a specific ordering of lens_model_list - :return: - """ - - return 2 - -
[docs] def bounds(self, re_optimize, scale=1.): - - """ - Sets the low/high parameter bounds for the particle swarm optimization - - NOTE: The low/high values specified here are intended for galaxy-scale lenses. If you want to use this - for a different size system you should create a new ParamClass with different settings - - :param re_optimize: keep a narrow window around each parameter - :param scale: scales the size of the uncertainty window - :return: - """ - - args = self.kwargs_to_args(self.kwargs_lens) - - if re_optimize: - thetaE_shift = 0.005 - center_shift = 0.01 - e_shift = 0.05 - g_shift = 0.025 - - else: - thetaE_shift = 0.25 - center_shift = 0.2 - e_shift = 0.2 - g_shift = 0.05 - - shifts = np.array([thetaE_shift, center_shift, center_shift, e_shift, e_shift, g_shift, g_shift]) - - low = np.array(args) - shifts * scale - high = np.array(args) + shifts * scale - return low, high
- -
[docs] @staticmethod - def kwargs_to_args(kwargs): - - """ - - :param kwargs: keyword arguments corresponding to the lens model parameters being optimized - :return: array of lens model parameters - """ - - thetaE = kwargs[0]['theta_E'] - center_x = kwargs[0]['center_x'] - center_y = kwargs[0]['center_y'] - e1 = kwargs[0]['e1'] - e2 = kwargs[0]['e2'] - g1 = kwargs[1]['gamma1'] - g2 = kwargs[1]['gamma2'] - - args = (thetaE, center_x, center_y, e1, e2, g1, g2) - return args
- - -
[docs]class PowerLawFreeShear(PowerLawParamManager): - - """ - This class implements a fit of EPL + external shear with every parameter except the power law slope allowed to vary - """ -
[docs] def args_to_kwargs(self, args): - - """ - - :param args: array of lens model parameters - :return: dictionary of lens model parameters - """ - - gamma = self.kwargs_lens[0]['gamma'] - kwargs_epl = {'theta_E': args[0], 'center_x': args[1], 'center_y': args[2], - 'e1': args[3], 'e2': args[4], 'gamma': gamma} - - kwargs_shear = {'gamma1': args[5], 'gamma2': args[6]} - - self.kwargs_lens[0] = kwargs_epl - self.kwargs_lens[1] = kwargs_shear - - return self.kwargs_lens
- - -
[docs]class PowerLawFixedShear(PowerLawParamManager): - - """ - This class implements a fit of EPL + external shear with every parameter except the power law slope AND the - shear strength allowed to vary. The user should specify shear_strengh in the args_param_class keyword when - creating the Optimizer class - """ - - def __init__(self, kwargs_lens_init, shear_strength): - - """ - - :param kwargs_lens_init: the initial kwargs_lens before optimizing - :param shear_strength: the strenght of the external shear to be kept fixed - """ - self._shear_strength = shear_strength - - super(PowerLawFixedShear, self).__init__(kwargs_lens_init) - -
[docs] def args_to_kwargs(self, args): - - """ - - :param args: array of lens model parameters - :return: dictionary of lens model parameters with fixed shear = shear_strength - """ - - (thetaE, center_x, center_y, e1, e2, g1, g2) = args - gamma = self.kwargs_lens[0]['gamma'] - - kwargs_epl = {'theta_E': thetaE, 'center_x': center_x, 'center_y': center_y, - 'e1': e1, 'e2': e2, 'gamma': gamma} - - phi, _ = shear_cartesian2polar(g1, g2) - gamma1, gamma2 = shear_polar2cartesian(phi, self._shear_strength) - kwargs_shear = {'gamma1': gamma1, 'gamma2': gamma2} - - self.kwargs_lens[0] = kwargs_epl - self.kwargs_lens[1] = kwargs_shear - - return self.kwargs_lens
- - -
[docs]class PowerLawFreeShearMultipole(PowerLawParamManager): - - """ - This class implements a fit of EPL + external shear + a multipole term with every parameter except the - power law slope and multipole moment free to vary. The mass centroid and orientation of the multipole term are - fixed to that of the EPL profile - - """ - - @property - def to_vary_index(self): - - """ - The number of lens models being varied in this routine. This is set to 3 because the first three lens models - are EPL, SHEAR, and MULTIPOLE, and their parameters are being optimized. - - The kwargs_list is split at to to_vary_index with indicies < to_vary_index accessed in this class, - and lens models with indicies > to_vary_index kept fixed. - - Note that this requires a specific ordering of lens_model_list - :return: - """ - - return 3 - -
[docs] def args_to_kwargs(self, args): - - (thetaE, center_x, center_y, e1, e2, g1, g2) = args - - gamma = self.kwargs_lens[0]['gamma'] - - kwargs_epl = {'theta_E': thetaE, 'center_x': center_x, 'center_y': center_y, - 'e1': e1, 'e2': e2, 'gamma': gamma} - kwargs_shear = {'gamma1': g1, 'gamma2': g2} - - self.kwargs_lens[0] = kwargs_epl - self.kwargs_lens[1] = kwargs_shear - - self.kwargs_lens[2]['center_x'] = center_x - self.kwargs_lens[2]['center_y'] = center_y - phi, _ = ellipticity2phi_q(e1, e2) - self.kwargs_lens[2]['phi_m'] = phi - - return self.kwargs_lens
- - -
[docs]class PowerLawFixedShearMultipole(PowerLawFixedShear): - """ - This class implements a fit of EPL + external shear + a multipole term with every parameter except the - power law slope, shear strength, and multipole moment free to vary. The mass centroid and orientation of the - multipole term are fixed to that of the EPL profile - """ - - @property - def to_vary_index(self): - - """ - The number of lens models being varied in this routine. This is set to 3 because the first three lens models - are EPL, SHEAR, and MULTIPOLE, and their parameters are being optimized. - - The kwargs_list is split at to to_vary_index with indicies < to_vary_index accessed in this class, - and lens models with indicies > to_vary_index kept fixed. - - Note that this requires a specific ordering of lens_model_list - :return: - """ - - return 3 - -
[docs] def args_to_kwargs(self, args): - - (thetaE, center_x, center_y, e1, e2, g1, g2) = args - gamma = self.kwargs_lens[0]['gamma'] - - kwargs_epl = {'theta_E': thetaE, 'center_x': center_x, 'center_y': center_y, - 'e1': e1, 'e2': e2, 'gamma': gamma} - - phi, _ = shear_cartesian2polar(g1, g2) - gamma1, gamma2 = shear_polar2cartesian(phi, self._shear_strength) - kwargs_shear = {'gamma1': gamma1, 'gamma2': gamma2} - - self.kwargs_lens[0] = kwargs_epl - self.kwargs_lens[1] = kwargs_shear - - self.kwargs_lens[2]['center_x'] = center_x - self.kwargs_lens[2]['center_y'] = center_y - phi, _ = ellipticity2phi_q(e1, e2) - self.kwargs_lens[2]['phi_m'] = phi - - return self.kwargs_lens
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Solver/lens_equation_solver.html b/docs/_build/html/_modules/lenstronomy/LensModel/Solver/lens_equation_solver.html deleted file mode 100644 index ee1e894b9..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Solver/lens_equation_solver.html +++ /dev/null @@ -1,485 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Solver.lens_equation_solver — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Solver.lens_equation_solver

-import numpy as np
-import lenstronomy.Util.util as util
-import lenstronomy.Util.image_util as image_util
-from scipy.optimize import minimize
-from lenstronomy.LensModel.Solver.epl_shear_solver import solve_lenseq_pemd
-
-__all__ = ['LensEquationSolver']
-
-
-
[docs]class LensEquationSolver(object): - """ - class to solve for image positions given lens model and source position - """ - def __init__(self, lensModel): - """ - This class must contain the following definitions (with same syntax as the standard LensModel() class: - def ray_shooting() - def hessian() - def magnification() - - :param lensModel: instance of a class according to lenstronomy.LensModel.lens_model - - """ - self.lensModel = lensModel - -
[docs] def image_position_stochastic(self, source_x, source_y, kwargs_lens, search_window=10, - precision_limit=10**(-10), arrival_time_sort=True, x_center=0, - y_center=0, num_random=1000): - """ - Solves the lens equation stochastic with the scipy minimization routine on the quadratic distance between - the backwards ray-shooted proposed image position and the source position. - Credits to Giulia Pagano - - :param source_x: source position - :param source_y: source position - :param kwargs_lens: lens model list of keyword arguments - :param search_window: angular size of search window - :param precision_limit: limit required on the precision in the source plane - :param arrival_time_sort: bool, if True sorts according to arrival time - :param x_center: center of search window - :param y_center: center of search window - :param num_random: number of random starting points of the non-linear solver in the search window - :return: x_image, y_image - """ - kwargs_lens = self.lensModel.set_static(kwargs_lens) - - x_solve, y_solve = [], [] - for i in range(num_random): - x_init = np.random.uniform(-search_window / 2., search_window / 2) + x_center - y_init = np.random.uniform(-search_window / 2., search_window / 2) + y_center - xinitial = np.array([x_init, y_init]) - result = minimize(self._root, xinitial, args=(kwargs_lens, source_x, source_y), tol=precision_limit ** 2, method='Nelder-Mead') - if self._root(result.x, kwargs_lens, source_x, source_y) < precision_limit**2: - x_solve.append(result.x[0]) - y_solve.append(result.x[1]) - - x_mins, y_mins = image_util.findOverlap(x_solve, y_solve, precision_limit) - if arrival_time_sort: - x_mins, y_mins = self.sort_arrival_times(x_mins, y_mins, kwargs_lens) - self.lensModel.set_dynamic() - return x_mins, y_mins
- - def _root(self, x, kwargs_lens, source_x, source_y): - """ - - :param x: parameters [x-coord, y-coord] - :param kwargs_lens: list of keyword arguments of the lens model - :param source_x: source position - :param source_y: source position - :return: square distance between ray-traced image position and given source position - """ - x_, y_ = x - beta_x, beta_y = self.lensModel.ray_shooting(x_, y_, kwargs_lens) - return (beta_x - source_x)**2 + (beta_y - source_y)**2 - -
[docs] def candidate_solutions(self, sourcePos_x, sourcePos_y, kwargs_lens, min_distance=0.1, search_window=10, - verbose=False, x_center=0, y_center=0): - """ - finds pixels in the image plane possibly hosting a solution of the lens equation, for the given source position and lens model - - :param sourcePos_x: source position in units of angle - :param sourcePos_y: source position in units of angle - :param kwargs_lens: lens model parameters as keyword arguments - :param min_distance: minimum separation to consider for two images in units of angle - :param search_window: window size to be considered by the solver. Will not find image position outside this window - :param verbose: bool, if True, prints some useful information for the user - :param x_center: float, center of the window to search for point sources - :param y_center: float, center of the window to search for point sources - :returns: (approximate) angular position of (multiple) images ra_pos, dec_pos in units of angles, related ray-traced source displacements and pixel width - :raises: AttributeError, KeyError - """ - kwargs_lens = self.lensModel.set_static(kwargs_lens) - # compute number of pixels to cover the search window with the required min_distance - numPix = int(round(search_window / min_distance) + 0.5) - x_grid, y_grid = util.make_grid(numPix, min_distance) - x_grid += x_center - y_grid += y_center - # ray-shoot to find the relative distance to the required source position for each grid point - x_mapped, y_mapped = self.lensModel.ray_shooting(x_grid, y_grid, kwargs_lens) - absmapped = util.displaceAbs(x_mapped, y_mapped, sourcePos_x, sourcePos_y) - # select minima in the grid points and select grid points that do not deviate more than the - # width of the grid point to a solution of the lens equation - x_mins, y_mins, delta_map = util.neighborSelect(absmapped, x_grid, y_grid) - # pixel width - pixel_width = x_grid[1]-x_grid[0] - - return x_mins, y_mins, delta_map, pixel_width
- -
[docs] def image_position_analytical(self, x, y, kwargs_lens, arrival_time_sort=True, magnification_limit=None, **kwargs_solver): - """ - Solves the lens equation. Only supports EPL-like (plus shear) models. Uses a specialized recipe that solves a - one-dimensional lens equation that is easier and more reliable to solve than the usual two-dimensional lens equation. - - :param x: source position in units of angle, an array of positions is also supported. - :param y: source position in units of angle, an array of positions is also supported. - :param kwargs_lens: lens model parameters as keyword arguments - :param arrival_time_sort: bool, if True, sorts image position in arrival time (first arrival photon first listed) - :param magnification_limit: None or float, if set will only return image positions that have an - abs(magnification) larger than this number - :param kwargs_solver: additional kwargs to be supplied to the solver. Particularly relevant are Nmeas and Nmeas_extra - :returns: (exact) angular position of (multiple) images ra_pos, dec_pos in units of angle - Note: in contrast to the other solvers, generally the (heavily demagnified) central image will also be included, so - setting a a proper magnification_limit is more important. To get similar behaviour, a limit of 1e-1 is acceptable - """ - lens_model_list = list(self.lensModel.lens_model_list) - if lens_model_list not in (['SIE', 'SHEAR'], ['SIE'], ['EPL_NUMBA', 'SHEAR'], ['EPL_NUMBA'], ['EPL', 'SHEAR'], ['EPL']): - raise ValueError("Only SIE or PEMD (+shear) supported in the analytical solver for now") - - x_mins, y_mins = solve_lenseq_pemd((x, y), kwargs_lens, **kwargs_solver) - if arrival_time_sort: - x_mins, y_mins = self.sort_arrival_times(x_mins, y_mins, kwargs_lens) - if magnification_limit is not None: - mag = np.abs(self.lensModel.magnification(x_mins, y_mins, kwargs_lens)) - x_mins = x_mins[mag >= magnification_limit] - y_mins = y_mins[mag >= magnification_limit] - return x_mins, y_mins
- -
[docs] def image_position_from_source(self, sourcePos_x, sourcePos_y, kwargs_lens, solver='lenstronomy', **kwargs): - """ - Solves the lens equation, i.e. finds the image positions in the lens plane that are mapped to a given source - position. - - :param sourcePos_x: source position in units of angle - :param sourcePos_y: source position in units of angle - :param kwargs_lens: lens model parameters as keyword arguments - :param solver: which solver to use, can be 'lenstronomy' (default), 'analytical' or 'stochastic'. - :param kwargs: Any additional kwargs are passed to the chosen solver, see the documentation of - image_position_lenstronomy, image_position_analytical and image_position_stochastic - :returns: (exact) angular position of (multiple) images ra_pos, dec_pos in units of angle - """ - if solver == 'lenstronomy': - return self.image_position_lenstronomy(sourcePos_x, sourcePos_y, kwargs_lens, **kwargs) - if solver == 'analytical': - return self.image_position_analytical(sourcePos_x, sourcePos_y, kwargs_lens, **kwargs) - if solver == 'stochastic': - return self.image_position_stochastic(sourcePos_x, sourcePos_y, kwargs_lens, **kwargs) - raise ValueError(f"{solver} is not a valid solver.")
- -
[docs] def image_position_lenstronomy(self, sourcePos_x, sourcePos_y, kwargs_lens, min_distance=0.1, search_window=10, - precision_limit=10**(-10), num_iter_max=100, arrival_time_sort=True, - initial_guess_cut=True, verbose=False, x_center=0, y_center=0, num_random=0, - non_linear=False, magnification_limit=None): - """ - Finds image position given source position and lens model. The solver first samples does a grid search in the - lens plane, and the grid points that are closest to the supplied source position are fed to a - specialized gradient-based root finder that finds the exact solutions. Works with all lens models. - - :param sourcePos_x: source position in units of angle - :param sourcePos_y: source position in units of angle - :param kwargs_lens: lens model parameters as keyword arguments - :param min_distance: minimum separation to consider for two images in units of angle - :param search_window: window size to be considered by the solver. Will not find image position outside this window - :param precision_limit: required precision in the lens equation solver (in units of angle in the source plane). - :param num_iter_max: maximum iteration of lens-source mapping conducted by solver to match the required precision - :param arrival_time_sort: bool, if True, sorts image position in arrival time (first arrival photon first listed) - :param initial_guess_cut: bool, if True, cuts initial local minima selected by the grid search based on distance criteria from the source position - :param verbose: bool, if True, prints some useful information for the user - :param x_center: float, center of the window to search for point sources - :param y_center: float, center of the window to search for point sources - :param num_random: int, number of random positions within the search window to be added to be starting - positions for the gradient decent solver - :param non_linear: bool, if True applies a non-linear solver not dependent on Hessian computation - :param magnification_limit: None or float, if set will only return image positions that have an - abs(magnification) larger than this number - :returns: (exact) angular position of (multiple) images ra_pos, dec_pos in units of angle - :raises: AttributeError, KeyError - """ - # find pixels in the image plane possibly hosting a solution of the lens equation, related source distances and - # pixel width - x_mins, y_mins, delta_map, pixel_width = self.candidate_solutions(sourcePos_x, sourcePos_y, kwargs_lens, min_distance, search_window, verbose, x_center, y_center) - if verbose: - print("There are %s regions identified that could contain a solution of the lens equation" % len(x_mins)) - if len(x_mins) < 1: - return x_mins, y_mins - if initial_guess_cut: - mag = np.abs(self.lensModel.magnification(x_mins, y_mins, kwargs_lens)) - mag[mag < 1] = 1 - x_mins = x_mins[delta_map <= min_distance*mag*5] - y_mins = y_mins[delta_map <= min_distance*mag*5] - if verbose: - print("The number of regions that meet the plausibility criteria are %s" % len(x_mins)) - x_mins = np.append(x_mins, np.random.uniform(low=-search_window/2+x_center, high=search_window/2+x_center, - size=num_random)) - y_mins = np.append(y_mins, np.random.uniform(low=-search_window / 2 + y_center, - high=search_window / 2 + y_center, size=num_random)) - # iterative solving of the lens equation for the selected grid points - # print("Candidates:", x_mins.shape, y_mins.shape) - x_mins, y_mins, solver_precision = self._find_gradient_decent(x_mins, y_mins, sourcePos_x, sourcePos_y, kwargs_lens, - precision_limit, num_iter_max, verbose=verbose, - min_distance=min_distance, non_linear=non_linear) - # only select iterative results that match the precision limit - x_mins = x_mins[solver_precision <= precision_limit] - y_mins = y_mins[solver_precision <= precision_limit] - # find redundant solutions within the min_distance criterion - x_mins, y_mins = image_util.findOverlap(x_mins, y_mins, min_distance) - if arrival_time_sort: - x_mins, y_mins = self.sort_arrival_times(x_mins, y_mins, kwargs_lens) - if magnification_limit is not None: - mag = np.abs(self.lensModel.magnification(x_mins, y_mins, kwargs_lens)) - x_mins = x_mins[mag >= magnification_limit] - y_mins = y_mins[mag >= magnification_limit] - self.lensModel.set_dynamic() - return x_mins, y_mins
- - def _find_gradient_decent(self, x_min, y_min, sourcePos_x, sourcePos_y, kwargs_lens, precision_limit=10 ** (-10), - num_iter_max=200, verbose=False, min_distance=0.01, non_linear=False): - """ - given a 'good guess' of a solution of the lens equation (expected image position given a fixed source position) - this routine iteratively performs a ray-tracing with second order correction (effectively gradient decent) to find - a precise solution to the lens equation. - - :param x_min: np.array, list of 'good guess' solutions of the lens equation - :param y_min: np.array, list of 'good guess' solutions of the lens equation - :param sourcePos_x: source position for which to solve the lens equation - :param sourcePos_y: source position for which to solve the lens equation - :param kwargs_lens: keyword argument list of the lens model - :param precision_limit: float, required match in the solution in the source plane - :param num_iter_max: int, maximum number of iterations before the algorithm stops - :param verbose: bool, if True inserts print statements about the behavior of the solver - :param min_distance: maximum correction applied per step (to avoid over-shooting in unstable regions) - :param non_linear: bool, if True, uses scipy.miminize instead of the directly implemented gradient decent approach. - :return: x_position array, y_position array, error in the source plane array - """ - num_candidates = len(x_min) - x_mins = np.zeros(num_candidates) - y_mins = np.zeros(num_candidates) - solver_precision = np.zeros(num_candidates) - for i in range(len(x_min)): - x_guess, y_guess, delta, l = self._solve_single_proposal(x_min[i], y_min[i], sourcePos_x, sourcePos_y, - kwargs_lens, precision_limit, num_iter_max, - max_step=min_distance, non_linear=non_linear) - if verbose: - print("Solution found for region %s with required precision at iteration %s" % (i, l)) - x_mins[i] = x_guess - y_mins[i] = y_guess - solver_precision[i] = delta - return x_mins, y_mins, solver_precision - - def _solve_single_proposal(self, x_guess, y_guess, source_x, source_y, kwargs_lens, precision_limit, num_iter_max, - max_step, non_linear=False): - """ - gradient decent solution of a single proposed starting point (close to a true solution) - - :param x_guess: starting guess position in the image plane - :param y_guess: starting guess position in the image plane - :param source_x: source position to solve for in the image plane - :param source_y: source position to solve for in the image plane - :param kwargs_lens: keyword argument list of the lens model - :param precision_limit: float, required match in the solution in the source plane - :param num_iter_max: int, maximum number of iterations before the algorithm stops - :param max_step: maximum correction applied per step (to avoid over-shooting in instable regions) - :param non_linear: bool, if True, uses scipy.miminize instead of the directly implemented gradient decent approach. - :return: x_position, y_position, error in the source plane, steps required (for gradient decent) - """ - l = 0 - if non_linear: - xinitial = np.array([x_guess, y_guess]) - result = minimize(self._root, xinitial, args=(kwargs_lens, source_x, source_y), tol=precision_limit ** 2, - method='Nelder-Mead') - delta = self._root(result.x, kwargs_lens, source_x, source_y) - x_guess, y_guess = result.x[0], result.x[1] - - else: - x_mapped, y_mapped = self.lensModel.ray_shooting(x_guess, y_guess, kwargs_lens) - delta = np.sqrt((x_mapped - source_x) ** 2 + (y_mapped - source_y) ** 2) - - while delta > precision_limit and l < num_iter_max: - x_mapped, y_mapped = self.lensModel.ray_shooting(x_guess, y_guess, kwargs_lens) - delta = np.sqrt((x_mapped - source_x) ** 2 + (y_mapped - source_y) ** 2) - f_xx, f_xy, f_yx, f_yy = self.lensModel.hessian(x_guess, y_guess, kwargs_lens) - DistMatrix = np.array([[1 - f_yy, f_yx], [f_xy, 1 - f_xx]]) - det = (1 - f_xx) * (1 - f_yy) - f_xy * f_yx - deltaVec = np.array([x_mapped - source_x, y_mapped - source_y]) - image_plane_vector = DistMatrix.dot(deltaVec) / det - dist = np.sqrt(image_plane_vector[0]**2 + image_plane_vector[1]**2) - if dist > max_step: - image_plane_vector *= max_step/dist - x_guess, y_guess, delta, l = self._gradient_step(x_guess, y_guess, source_x, source_y, delta, - image_plane_vector, kwargs_lens, l, num_iter_max) - return x_guess, y_guess, delta, l - - def _gradient_step(self, x_guess, y_guess, source_x, source_y, delta_init, image_plane_vector, kwargs_lens, - iter_num, num_iter_max): - """ - - :param x_guess: float, current best fit solution in the image plane - :param y_guess: float, current best fit solution in the image plane - :param source_x: float, source position to be matched - :param source_y: float, source position ot be matched - :param delta_init: current precision in the source plane of the mapped solution - :param image_plane_vector: correction vector in the image plane based on the Hessian operator and the deviation - in the source plane - :param kwargs_lens: lens model keyword argument list - :param iter_num: int, current iteration number - :param num_iter_max: int, maximum iteration number before aborting the process - :return: updated image position in x, updated image position in y, updated precision in the source plane, - total iterations done after this call - """ - x_new = x_guess - image_plane_vector[0] - y_new = y_guess - image_plane_vector[1] - x_mapped, y_mapped = self.lensModel.ray_shooting(x_new, y_new, kwargs_lens) - delta_new = np.sqrt((x_mapped - source_x) ** 2 + (y_mapped - source_y) ** 2) - iter_num += 1 - if delta_new > delta_init: - if num_iter_max < iter_num: - return x_guess, y_guess, delta_init, iter_num - else: - # if the new proposal is worse than the previous one, it randomly draws a new proposal in a different - # direction and tries again - image_plane_vector[0] *= np.random.normal(loc=0, scale=0.5) - image_plane_vector[1] *= np.random.normal(loc=0, scale=0.5) - return self._gradient_step(x_guess, y_guess, source_x, source_y, delta_init, image_plane_vector, kwargs_lens, iter_num, num_iter_max) - else: - return x_new, y_new, delta_new, iter_num - -
[docs] def findBrightImage(self, sourcePos_x, sourcePos_y, kwargs_lens, numImages=4, min_distance=0.01, search_window=5, - precision_limit=10**(-10), num_iter_max=10, arrival_time_sort=True, x_center=0, y_center=0, - num_random=0, non_linear=False, magnification_limit=None, initial_guess_cut=True, verbose=False): - """ - - :param sourcePos_x: source position in units of angle - :param sourcePos_y: source position in units of angle - :param kwargs_lens: lens model parameters as keyword arguments - :param min_distance: minimum separation to consider for two images in units of angle - :param search_window: window size to be considered by the solver. Will not find image position outside this window - :param precision_limit: required precision in the lens equation solver (in units of angle in the source plane). - :param num_iter_max: maximum iteration of lens-source mapping conducted by solver to match the required precision - :param arrival_time_sort: bool, if True, sorts image position in arrival time (first arrival photon first listed) - :param initial_guess_cut: bool, if True, cuts initial local minima selected by the grid search based on distance criteria from the source position - :param verbose: bool, if True, prints some useful information for the user - :param x_center: float, center of the window to search for point sources - :param y_center: float, center of the window to search for point sources - :param num_random: int, number of random positions within the search window to be added to be starting - positions for the gradient decent solver - :param non_linear: bool, if True applies a non-linear solver not dependent on Hessian computation - :param magnification_limit: None or float, if set will only return image positions that have an - abs(magnification) larger than this number - :returns: (exact) angular position of (multiple) images ra_pos, dec_pos in units of angle - """ - - x_mins, y_mins = self.image_position_from_source(sourcePos_x, sourcePos_y, kwargs_lens, - min_distance=min_distance, search_window=search_window, - precision_limit=precision_limit, num_iter_max=num_iter_max, - arrival_time_sort=arrival_time_sort, - initial_guess_cut=initial_guess_cut, verbose=verbose, - x_center=x_center, y_center=y_center, num_random=num_random, - non_linear=non_linear, magnification_limit=magnification_limit) - mag_list = [] - for i in range(len(x_mins)): - mag = self.lensModel.magnification(x_mins[i], y_mins[i], kwargs_lens) - mag_list.append(abs(mag)) - mag_list = np.array(mag_list) - x_mins_sorted = util.selectBest(x_mins, mag_list, numImages) - y_mins_sorted = util.selectBest(y_mins, mag_list, numImages) - if arrival_time_sort: - x_mins_sorted, y_mins_sorted = self.sort_arrival_times(x_mins_sorted, y_mins_sorted, kwargs_lens) - return x_mins_sorted, y_mins_sorted
- -
[docs] def sort_arrival_times(self, x_mins, y_mins, kwargs_lens): - """ - sort arrival times (fermat potential) of image positions in increasing order of light travel time - - :param x_mins: ra position of images - :param y_mins: dec position of images - :param kwargs_lens: keyword arguments of lens model - :return: sorted lists of x_mins and y_mins - """ - - if hasattr(self.lensModel, '_no_potential'): - raise Exception('Instance of lensModel passed to this class does not compute the lensing potential, ' - 'and therefore cannot compute time delays.') - - if len(x_mins) <= 1: - return x_mins, y_mins - if self.lensModel.multi_plane: - arrival_time = self.lensModel.arrival_time(x_mins, y_mins, kwargs_lens) - else: - fermat_pot = self.lensModel.fermat_potential(x_mins, y_mins, kwargs_lens) - arrival_time = fermat_pot - idx = np.argsort(arrival_time) - x_mins = np.array(x_mins)[idx] - y_mins = np.array(y_mins)[idx] - return x_mins, y_mins
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Solver/solver.html b/docs/_build/html/_modules/lenstronomy/LensModel/Solver/solver.html deleted file mode 100644 index 1493c6fd8..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Solver/solver.html +++ /dev/null @@ -1,163 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Solver.solver — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Solver.solver

-from lenstronomy.LensModel.Solver.solver2point import Solver2Point
-from lenstronomy.LensModel.Solver.solver4point import Solver4Point
-import numpy as np
-
-__all__ = ['Solver']
-
-
-
[docs]class Solver(object): - """ - joint solve class to manage with type of solver to be executed and checks whether the requirements are fulfilled. - - """ - - def __init__(self, solver_type, lensModel, num_images): - """ - - :param solver_type: string, option for specific solver type - see detailed instruction of the Solver4Point and Solver2Point classes - :param lensModel: instance of a LensModel() class - :param num_images: int, number of images to be solved for - """ - self._num_images = num_images - self._lensModel = lensModel - if self._num_images == 4: - self._solver = Solver4Point(lensModel, solver_type=solver_type) - elif self. _num_images == 2: - self._solver = Solver2Point(lensModel, solver_type=solver_type) - else: - raise ValueError("%s number of images is not valid. Use 2 or 4!" % self._num_images) - -
[docs] def constraint_lensmodel(self, x_pos, y_pos, kwargs_list, xtol=1.49012e-12): - """ - - :param x_pos: - :param y_pos: - :param kwargs_list: - :param xtol: - :return: - """ - return self._solver.constraint_lensmodel(x_pos, y_pos, kwargs_list, xtol=xtol)
- -
[docs] def update_solver(self, kwargs_lens, x_pos, y_pos): - """ - - - :param kwargs_lens: - :param x_pos: - :param y_pos: - :return: - """ - - if not len(x_pos) == self._num_images: - raise ValueError("Point source number %s must be as specified by the solver with number of images %s" % - (len(x_pos), self._num_images)) - kwargs_lens, precision = self.constraint_lensmodel(x_pos, y_pos, kwargs_lens) - return kwargs_lens
- -
[docs] def check_solver(self, image_x, image_y, kwargs_lens): - """ - returns the precision of the solver to match the image position - - :param kwargs_lens: full lens model (including solved parameters) - :param image_x: point source in image - :param image_y: point source in image - :return: precision of Euclidean distances between the different rays arriving at the image positions - """ - source_x, source_y = self._lensModel.ray_shooting(image_x, image_y, kwargs_lens) - dist = np.sqrt((source_x - source_x[0]) ** 2 + (source_y - source_y[0]) ** 2) - return dist
- -
[docs] def add_fixed_lens(self, kwargs_fixed_lens, kwargs_lens_init): - """ - returns kwargs that are kept fixed during run, depending on options - - :param kwargs_fixed_lens: keyword argument list of fixed parameters (indicated by fitting argument of the user) - :param kwargs_lens_init: Initial values of the full lens model keyword arguments - :return: updated kwargs_fixed_lens, added fixed parameters being added (and replaced later on) by the - non-linear solver. - """ - kwargs_fixed_lens = self._solver.add_fixed_lens(kwargs_fixed_lens, kwargs_lens_init) - return kwargs_fixed_lens
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Solver/solver2point.html b/docs/_build/html/_modules/lenstronomy/LensModel/Solver/solver2point.html deleted file mode 100644 index 11b514441..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Solver/solver2point.html +++ /dev/null @@ -1,282 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Solver.solver2point — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Solver.solver2point

-__author__ = 'sibirrer'
-
-import scipy.optimize
-import numpy as np
-import copy
-import lenstronomy.Util.param_util as param_util
-
-__all__ = ['Solver2Point']
-
-
-
[docs]class Solver2Point(object): - """ - class to solve a constraint lens model with two point source positions - - options are: - 'CENTER': solves for 'center_x', 'center_y' parameters of the first lens model - 'ELLIPSE': solves for 'e1', 'e2' of the first lens (can also be shear) - 'SHAPELETS': solves for shapelet coefficients c01, c10 - 'THETA_E_PHI: solves for Einstein radius of first lens model and shear angle of second model - - - """ - def __init__(self, lensModel, solver_type='CENTER', decoupling=True): - """ - - :param lensModel: instance of LensModel class - :param solver_type: string - :param decoupling: bool - """ - self.lensModel = lensModel - self._lens_mode_list = lensModel.lens_model_list - if solver_type not in ['CENTER', 'ELLIPSE', 'SHAPELETS', 'THETA_E_PHI', 'THETA_E_ELLIPSE']: - raise ValueError("solver_type %s is not a valid option!" % solver_type) - if solver_type == 'SHAPELETS': - if not self._lens_mode_list[0] in ['SHAPELETS_CART', 'SHAPELETS_POLAR']: - raise ValueError("solver_type %s needs the first lens model to be in ['SHAPELETS_CART', " - "'SHAPELETS_POLAR']" % solver_type) - if solver_type == 'THETA_E_PHI': - if not self._lens_mode_list[1] == 'SHEAR': - raise ValueError("solver_type %s needs the second lens model to be 'SHEAR" % solver_type) - self._solver_type = solver_type - if lensModel.multi_plane is True or 'FOREGROUND_SHEAR' in self._lens_mode_list or solver_type == 'THETA_E_PHI': - self._decoupling = False - else: - self._decoupling = decoupling - -
[docs] def constraint_lensmodel(self, x_pos, y_pos, kwargs_list, xtol=1.49012e-12): - """ - constrains lens model parameters by demanding the solution to match the image positions to a single source - position - - :param x_pos: list of image positions (x-axis) - :param y_pos: list of image position (y-axis) - :param kwargs_list: list of lens model kwargs - :param xtol: tolerance level of solution when to stop the non-linear solver - :return: updated lens model that satisfies the lens equation for the point sources - """ - kwargs = copy.deepcopy(kwargs_list) - init = self._extract_array(kwargs) - if self._decoupling: - alpha_0_x, alpha_0_y = self.lensModel.alpha(x_pos, y_pos, kwargs) - alpha_1_x, alpha_1_y = self.lensModel.alpha(x_pos, y_pos, kwargs, k=0) - x_sub = alpha_1_x - alpha_0_x - y_sub = alpha_1_y - alpha_0_y - else: - x_sub, y_sub = np.zeros(2), np.zeros(2) - a = self._subtract_constraint(x_sub, y_sub) - x = self.solve(x_pos, y_pos, init, kwargs, a, xtol=xtol) - kwargs = self._update_kwargs(x, kwargs) - y_end = self._F(x, x_pos, y_pos, kwargs, a) - accuracy = np.sum(y_end ** 2) - return kwargs, accuracy
- -
[docs] def solve(self, x_pos, y_pos, init, kwargs_list, a, xtol=1.49012e-12): - x = scipy.optimize.fsolve(self._F, init, args=(x_pos, y_pos, kwargs_list, a), xtol=xtol) # , factor=0.1) - return x
- - def _F(self, x, x_pos, y_pos, kwargs_list, a=np.zeros(2)): - kwargs_list = self._update_kwargs(x, kwargs_list) - if self._decoupling: - beta_x, beta_y = self.lensModel.ray_shooting(x_pos, y_pos, kwargs_list, k=0) - else: - beta_x, beta_y = self.lensModel.ray_shooting(x_pos, y_pos, kwargs_list) - y = np.zeros(2) - y[0] = beta_x[0] - beta_x[1] - y[1] = beta_y[0] - beta_y[1] - return y - a - - @staticmethod - def _subtract_constraint(x_sub, y_sub): - """ - - :param x_sub: - :param y_sub: - :return: - """ - a = np.zeros(2) - a[0] = - x_sub[0] + x_sub[1] - a[1] = - y_sub[0] + y_sub[1] - return a - - def _update_kwargs(self, x, kwargs_list): - """ - - :param x: list of parameters corresponding to the free parameter of the first lens model in the list - :param kwargs_list: list of lens model kwargs - :return: updated kwargs_list - """ - if self._solver_type == 'CENTER': - [center_x, center_y] = x - kwargs_list[0]['center_x'] = center_x - kwargs_list[0]['center_y'] = center_y - elif self._solver_type == 'ELLIPSE': - [e1, e2] = x - kwargs_list[0]['e1'] = e1 - kwargs_list[0]['e2'] = e2 - elif self._solver_type == 'SHAPELETS': - [c10, c01] = x - coeffs = list(kwargs_list[0]['coeffs']) - coeffs[1: 3] = [c10, c01] - kwargs_list[0]['coeffs'] = coeffs - elif self._solver_type == 'THETA_E_PHI': - [theta_E, phi_G] = x - kwargs_list[0]['theta_E'] = theta_E - phi_G_no_sense, gamma_ext = param_util.shear_cartesian2polar(kwargs_list[1]['gamma1'], kwargs_list[1]['gamma2']) - gamma1, gamma2 = param_util.shear_polar2cartesian(phi_G, gamma_ext) - kwargs_list[1]['gamma1'] = gamma1 - kwargs_list[1]['gamma2'] = gamma2 - elif self._solver_type == 'THETA_E_ELLIPSE': - [theta_E, phi_G] = x - kwargs_list[0]['theta_E'] = theta_E - phi_G_no_sense, q = param_util.ellipticity2phi_q(kwargs_list[0]['e1'], kwargs_list[0]['e2']) - e1, e2 = param_util.phi_q2_ellipticity(phi_G, q) - kwargs_list[0]['e1'] = e1 - kwargs_list[0]['e2'] = e2 - else: - raise ValueError("Solver type %s not supported for 2-point solver!" % self._solver_type) - return kwargs_list - - def _extract_array(self, kwargs_list): - """ - inverse of _update_kwargs - - :param kwargs_list: - :return: - """ - if self._solver_type == 'CENTER': - center_x = kwargs_list[0]['center_x'] - center_y = kwargs_list[0]['center_y'] - x = [center_x, center_y] - elif self._solver_type == 'ELLIPSE': - e1 = kwargs_list[0]['e1'] - e2 = kwargs_list[0]['e2'] - x = [e1, e2] - elif self._solver_type == 'SHAPELETS': - coeffs = list(kwargs_list[0]['coeffs']) - [c10, c01] = coeffs[1: 3] - x = [c10, c01] - elif self._solver_type == 'THETA_E_PHI': - theta_E = kwargs_list[0]['theta_E'] - gamma1 = kwargs_list[1]['gamma1'] - gamma2 = kwargs_list[1]['gamma2'] - phi_ext, gamma_ext = param_util.shear_cartesian2polar(gamma1, gamma2) - x = [theta_E, phi_ext] - elif self._solver_type == 'THETA_E_ELLIPSE': - theta_E = kwargs_list[0]['theta_E'] - e1 = kwargs_list[0]['e1'] - e2 = kwargs_list[0]['e2'] - phi_ext, gamma_ext = param_util.shear_cartesian2polar(e1, e2) - x = [theta_E, phi_ext] - else: - raise ValueError("Solver type %s not supported for 2-point solver!" % self._solver_type) - return x - -
[docs] def add_fixed_lens(self, kwargs_fixed_lens_list, kwargs_lens_init): - """ - - :param kwargs_fixed_lens_list: - :param kwargs_lens_init: - :return: - """ - kwargs_fixed = kwargs_fixed_lens_list[0] - kwargs_lens = kwargs_lens_init[0] - if self._solver_type in ['CENTER']: - kwargs_fixed['center_x'] = kwargs_lens['center_x'] - kwargs_fixed['center_y'] = kwargs_lens['center_y'] - elif self._solver_type in ['ELLIPSE']: - kwargs_fixed['e1'] = kwargs_lens['e1'] - kwargs_fixed['e2'] = kwargs_lens['e2'] - elif self._solver_type == 'SHAPELETS': - pass - elif self._solver_type == 'THETA_E_PHI': - kwargs_fixed['theta_E'] = kwargs_lens['theta_E'] - kwargs_fixed_lens_list[1]['gamma2'] = 0 - elif self._solver_type == 'THETA_E_ELLIPSE': - kwargs_fixed['theta_E'] = kwargs_lens['theta_E'] - kwargs_fixed_lens_list[0]['e2'] = 0 - else: - raise ValueError("Solver type %s not supported for 2-point solver!" % self._solver_type) - return kwargs_fixed_lens_list
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/Solver/solver4point.html b/docs/_build/html/_modules/lenstronomy/LensModel/Solver/solver4point.html deleted file mode 100644 index 4a8b28fde..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/Solver/solver4point.html +++ /dev/null @@ -1,308 +0,0 @@ - - - - - - - - lenstronomy.LensModel.Solver.solver4point — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.Solver.solver4point

-__author__ = 'sibirrer'
-
-import lenstronomy.Util.param_util as param_util
-
-import scipy.optimize
-import numpy as np
-import copy
-
-__all__ = ['Solver4Point']
-
-
-
[docs]class Solver4Point(object): - """ - class to make the constraints for the solver - """ - def __init__(self, lensModel, solver_type='PROFILE'): - self._solver_type = solver_type # supported: - if not lensModel.lens_model_list[0] in ['SPEP', 'SPEMD', 'PEMD', 'SIE', 'NIE', 'NFW_ELLIPSE', 'NFW_ELLIPSE_CSE', - 'SHAPELETS_CART', 'CNFW_ELLIPSE', 'EPL']: - raise ValueError("first lens model must be supported by the solver: 'SPEP', 'SPEMD', 'PEMD'," - " 'SIE', 'NIE', 'EPL', 'NFW_ELLIPSE', 'NFW_ELLIPSE_CSE', 'SHAPELETS_CART', 'CNFW_ELLIPSE'." - "Your choice was %s" % lensModel.lens_model_list[0]) - if solver_type not in ['PROFILE', 'PROFILE_SHEAR']: - raise ValueError("solver_type %s not supported! Choose from 'PROFILE', 'PROFILE_SHEAR'" - % solver_type) - if solver_type in ['PROFILE_SHEAR']: - if lensModel.lens_model_list[1] == 'SHEAR': - self._solver_type = 'PROFILE_SHEAR' - elif lensModel.lens_model_list[1] == 'SHEAR_GAMMA_PSI': - self._solver_type = 'PROFILE_SHEAR_GAMMA_PSI' - else: - raise ValueError("second lens model must be SHEAR_GAMMA_PSI or SHEAR to enable solver type %s!" % solver_type) - self.lensModel = lensModel - self._lens_mode_list = lensModel.lens_model_list - if lensModel.multi_plane is True or 'FOREGROUND_SHEAR' in self._lens_mode_list: - self._decoupling = False - else: - self._decoupling = True - -
[docs] def constraint_lensmodel(self, x_pos, y_pos, kwargs_list, xtol=1.49012e-12): - """ - - :param x_pos: list of image positions (x-axis) - :param y_pos: list of image position (y-axis) - :param xtol: numerical tolerance level - :param kwargs_list: list of lens model kwargs - :return: updated lens model that satisfies the lens equation for the point sources - """ - kwargs = copy.deepcopy(kwargs_list) - init = self._extract_array(kwargs) - if self._decoupling: - alpha_0_x, alpha_0_y = self.lensModel.alpha(x_pos, y_pos, kwargs) - alpha_1_x, alpha_1_y = self.lensModel.alpha(x_pos, y_pos, kwargs, k=0) - if self._solver_type in ['PROFILE_SHEAR', 'PROFILE_SHEAR_GAMMA_PSI']: - alpha_shear_x, alpha_shear_y = self.lensModel.alpha(x_pos, y_pos, kwargs, k=1) - alpha_1_x += alpha_shear_x - alpha_1_y += alpha_shear_y - x_sub = alpha_1_x - alpha_0_x - y_sub = alpha_1_y - alpha_0_y - else: - x_sub, y_sub = np.zeros(4), np.zeros(4) - a = self._subtract_constraint(x_sub, y_sub) - x = self.solve(x_pos, y_pos, init, kwargs, a, xtol) - kwargs = self._update_kwargs(x, kwargs) - y_end = self._F(x, x_pos, y_pos, kwargs, a) - accuracy = np.sum(y_end**2) - return kwargs, accuracy
- -
[docs] def solve(self, x_pos, y_pos, init, kwargs_list, a, xtol=1.49012e-10): - x = scipy.optimize.fsolve(self._F, init, args=(x_pos, y_pos, kwargs_list, a), xtol=xtol) # , factor=0.1) - return x
- - def _F(self, x, x_pos, y_pos, kwargs_list, a=np.zeros(6)): - kwargs_list = self._update_kwargs(x, kwargs_list) - if self._decoupling: - alpha_x, alpha_y = self.lensModel.alpha(x_pos, y_pos, kwargs_list, k=0) - if self._solver_type in ['PROFILE_SHEAR', 'PROFILE_SHEAR_GAMMA_PSI']: - alpha_x_shear, alpha_y_shear = self.lensModel.alpha(x_pos, y_pos, kwargs_list, k=1) - alpha_x += alpha_x_shear - alpha_y += alpha_y_shear - beta_x = x_pos - alpha_x - beta_y = y_pos - alpha_y - else: - beta_x, beta_y = self.lensModel.ray_shooting(x_pos, y_pos, kwargs_list) - y = np.zeros(6) - y[0] = beta_x[0] - beta_x[1] - y[1] = beta_x[0] - beta_x[2] - y[2] = beta_x[0] - beta_x[3] - y[3] = beta_y[0] - beta_y[1] - y[4] = beta_y[0] - beta_y[2] - y[5] = beta_y[0] - beta_y[3] - return y - a - - @staticmethod - def _subtract_constraint(x_sub, y_sub): - """ - - :param x_sub: - :param y_sub: - :return: - """ - a = np.zeros(6) - - a[0] = - x_sub[0] + x_sub[1] - a[1] = - x_sub[0] + x_sub[2] - a[2] = - x_sub[0] + x_sub[3] - a[3] = - y_sub[0] + y_sub[1] - a[4] = - y_sub[0] + y_sub[2] - a[5] = - y_sub[0] + y_sub[3] - return a - - def _update_kwargs(self, x, kwargs_list): - """ - - :param x: list of parameters corresponding to the free parameter of the first lens model in the list - :param kwargs_list: list of lens model kwargs - :return: updated kwargs_list - """ - if self._solver_type == 'PROFILE_SHEAR_GAMMA_PSI': - phi_G = x[5] # % (2 * np.pi) - kwargs_list[1]['psi_ext'] = phi_G - if self._solver_type == 'PROFILE_SHEAR': - phi_G = x[5] % np.pi - phi_G_no_sense, gamma_ext = param_util.shear_cartesian2polar(kwargs_list[1]['gamma1'], kwargs_list[1]['gamma2']) - gamma1, gamma2 = param_util.shear_polar2cartesian(phi_G, gamma_ext) - kwargs_list[1]['gamma1'] = gamma1 - kwargs_list[1]['gamma2'] = gamma2 - lens_model = self._lens_mode_list[0] - if lens_model in ['SPEP', 'SPEMD', 'SIE', 'NIE', 'PEMD', 'EPL']: - [theta_E, e1, e2, center_x, center_y, _] = x - kwargs_list[0]['theta_E'] = theta_E - kwargs_list[0]['e1'] = e1 - kwargs_list[0]['e2'] = e2 - kwargs_list[0]['center_x'] = center_x - kwargs_list[0]['center_y'] = center_y - elif lens_model in ['NFW_ELLIPSE', 'CNFW_ELLIPSE', 'NFW_ELLIPSE_CSE']: - [alpha_Rs, e1, e2, center_x, center_y, _] = x - kwargs_list[0]['alpha_Rs'] = alpha_Rs - kwargs_list[0]['e1'] = e1 - kwargs_list[0]['e2'] = e2 - kwargs_list[0]['center_x'] = center_x - kwargs_list[0]['center_y'] = center_y - elif lens_model in ['SHAPELETS_CART']: - [c10, c01, c20, c11, c02, _] = x - coeffs = list(kwargs_list[0]['coeffs']) - coeffs[1: 6] = [c10, c01, c20, c11, c02] - kwargs_list[0]['coeffs'] = coeffs - else: - raise ValueError("Lens model %s not supported for 4-point solver!" % lens_model) - return kwargs_list - - def _extract_array(self, kwargs_list): - """ - inverse of _update_kwargs - :param kwargs_list: - :return: - """ - if self._solver_type == 'PROFILE_SHEAR_GAMMA_PSI': - phi_ext = kwargs_list[1]['psi_ext'] # % (np.pi) - # e1 = kwargs_list[1]['e1'] - # e2 = kwargs_list[1]['e2'] - # phi_ext, gamma_ext = param_util.ellipticity2phi_gamma(e1, e2) - elif self._solver_type == 'PROFILE_SHEAR': - gamma1 = kwargs_list[1]['gamma1'] - gamma2 = kwargs_list[1]['gamma2'] - phi_ext, gamma_ext = param_util.shear_cartesian2polar(gamma1, gamma2) - # phi_G_no_sense, gamma_ext = param_util.ellipticity2phi_gamma(kwargs_list[1]['e1'], kwargs_list[1]['e2']) - # e1, e2 = param_util.phi_gamma_ellipticity(phi_G, gamma_ext) - # kwargs_list[1]['e1'] = e1 - else: - phi_ext = 0 - lens_model = self._lens_mode_list[0] - if lens_model in ['SPEP', 'SPEMD', 'SIE', 'NIE', 'PEMD', 'EPL']: - e1 = kwargs_list[0]['e1'] - e2 = kwargs_list[0]['e2'] - center_x = kwargs_list[0]['center_x'] - center_y = kwargs_list[0]['center_y'] - theta_E = kwargs_list[0]['theta_E'] - x = [theta_E, e1, e2, center_x, center_y, phi_ext] - elif lens_model in ['NFW_ELLIPSE', 'CNFW_ELLIPSE', 'NFW_ELLIPSE_CSE']: - e1 = kwargs_list[0]['e1'] - e2 = kwargs_list[0]['e2'] - center_x = kwargs_list[0]['center_x'] - center_y = kwargs_list[0]['center_y'] - alpha_Rs = kwargs_list[0]['alpha_Rs'] - x = [alpha_Rs, e1, e2, center_x, center_y, phi_ext] - elif lens_model in ['SHAPELETS_CART']: - coeffs = list(kwargs_list[0]['coeffs']) - [c10, c01, c20, c11, c02] = coeffs[1: 6] - x = [c10, c01, c20, c11, c02, phi_ext] - else: - raise ValueError("Lens model %s not supported for 4-point solver!" % lens_model) - return x - -
[docs] def add_fixed_lens(self, kwargs_fixed_lens_list, kwargs_lens_init): - """ - - :param kwargs_fixed_lens_list: - :param kwargs_lens_init: - :return: - """ - - lens_model = self.lensModel.lens_model_list[0] - kwargs_fixed = kwargs_fixed_lens_list[0] - kwargs_lens = kwargs_lens_init[0] - if self._solver_type in ['PROFILE_SHEAR', 'PROFILE_SHEAR_GAMMA_PSI']: - pass - # kwargs_fixed_lens_list[1]['psi_ext'] = kwargs_lens_init[1]['psi_ext'] - if lens_model in ['SPEP', 'SPEMD', 'SIE', 'NIE', 'PEMD', 'EPL']: - kwargs_fixed['theta_E'] = kwargs_lens['theta_E'] - kwargs_fixed['e1'] = kwargs_lens['e1'] - kwargs_fixed['e2'] = kwargs_lens['e2'] - kwargs_fixed['center_x'] = kwargs_lens['center_x'] - kwargs_fixed['center_y'] = kwargs_lens['center_y'] - elif lens_model in ['NFW_ELLIPSE', 'CNFW_ELLIPSE', 'NFW_ELLIPSE_CSE']: - kwargs_fixed['alpha_Rs'] = kwargs_lens['alpha_Rs'] - kwargs_fixed['e1'] = kwargs_lens['e1'] - kwargs_fixed['e2'] = kwargs_lens['e2'] - kwargs_fixed['center_x'] = kwargs_lens['center_x'] - kwargs_fixed['center_y'] = kwargs_lens['center_y'] - elif lens_model in ['SHAPELETS_CART']: - pass - else: - raise ValueError( - "%s is not a valid option. Choose from 'PROFILE', 'PROFILE_SHEAR', 'SHAPELETS'" % self._solver_type) - return kwargs_fixed_lens_list
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/convergence_integrals.html b/docs/_build/html/_modules/lenstronomy/LensModel/convergence_integrals.html deleted file mode 100644 index 77ec09a32..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/convergence_integrals.html +++ /dev/null @@ -1,232 +0,0 @@ - - - - - - - - lenstronomy.LensModel.convergence_integrals — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.convergence_integrals

-import numpy as np
-import scipy.signal as scp
-from lenstronomy.Util import util
-from lenstronomy.Util import image_util
-from lenstronomy.Util import kernel_util
-"""
-class to compute lensing potentials and deflection angles provided a convergence map
-"""
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -def potential_from_kappa_grid(kappa, grid_spacing): - """ - lensing potential on the convergence grid - the computation is performed as a convolution of the Green's function with the convergence map using FFT - - :param kappa: 2d grid of convergence values - :param grid_spacing: pixel size of grid - :return: lensing potential in a 2d grid at positions x_grid, y_grid - """ - num_pix = len(kappa) * 2 - if num_pix % 2 == 0: - num_pix += 1 - kernel = potential_kernel(num_pix, grid_spacing) - f_ = scp.fftconvolve(kappa, kernel, mode='same') / np.pi * grid_spacing ** 2 - return f_
- - -
[docs]@export -def potential_from_kappa_grid_adaptive(kappa_high_res, grid_spacing, low_res_factor, high_res_kernel_size): - """ - lensing potential on the convergence grid - the computation is performed as a convolution of the Green's function with the convergence map using FFT - - :param kappa_high_res: 2d grid of convergence values - :param grid_spacing: pixel size of grid - :param low_res_factor: lower resolution factor of larger scale kernel. - :param high_res_kernel_size: int, size of high resolution kernel in units of degraded pixels - :return: lensing potential in a 2d grid at positions x_grid, y_grid - """ - kappa_low_res = image_util.re_size(kappa_high_res, factor=low_res_factor) - num_pix = len(kappa_high_res) * 2 - if num_pix % 2 == 0: - num_pix += 1 - grid_spacing_low_res = grid_spacing * low_res_factor - kernel = potential_kernel(num_pix, grid_spacing) - kernel_low_res, kernel_high_res = kernel_util.split_kernel(kernel, high_res_kernel_size, low_res_factor, normalized=False) - - f_high_res = scp.fftconvolve(kappa_high_res, kernel_high_res, mode='same') / np.pi * grid_spacing ** 2 - f_high_res = image_util.re_size(f_high_res, low_res_factor) - f_low_res = scp.fftconvolve(kappa_low_res, kernel_low_res, mode='same') / np.pi * grid_spacing_low_res ** 2 - return f_high_res + f_low_res
- - -
[docs]@export -def deflection_from_kappa_grid(kappa, grid_spacing): - """ - deflection angles on the convergence grid - the computation is performed as a convolution of the Green's function with the convergence map using FFT - - :param kappa: convergence values for each pixel (2-d array) - :param grid_spacing: pixel size of grid - :return: numerical deflection angles in x- and y- direction - """ - num_pix = len(kappa) * 2 - if num_pix % 2 == 0: - num_pix += 1 - kernel_x, kernel_y = deflection_kernel(num_pix, grid_spacing) - f_x = scp.fftconvolve(kappa, kernel_x, mode='same') / np.pi * grid_spacing ** 2 - f_y = scp.fftconvolve(kappa, kernel_y, mode='same') / np.pi * grid_spacing ** 2 - return f_x, f_y
- - -
[docs]@export -def deflection_from_kappa_grid_adaptive(kappa_high_res, grid_spacing, low_res_factor, high_res_kernel_size): - """ - deflection angles on the convergence grid with adaptive FFT - the computation is performed as a convolution of the Green's function with the convergence map using FFT - The grid is returned in the lower resolution grid - - :param kappa_high_res: convergence values for each pixel (2-d array) - :param grid_spacing: pixel size of high resolution grid - :param low_res_factor: lower resolution factor of larger scale kernel. - :param high_res_kernel_size: int, size of high resolution kernel in units of degraded pixels - :return: numerical deflection angles in x- and y- direction - """ - kappa_low_res = image_util.re_size(kappa_high_res, factor=low_res_factor) - num_pix = len(kappa_high_res) * 2 - if num_pix % 2 == 0: - num_pix += 1 - - # if high_res_kernel_size % low_res_factor != 0: - # assert ValueError('fine grid kernel size needs to be a multiplicative factor of low_res_factor! Settings used: ' - # 'fine_grid_kernel_size=%s, low_res_factor=%s' % (high_res_kernel_size, low_res_factor)) - kernel_x, kernel_y = deflection_kernel(num_pix, grid_spacing) - grid_spacing_low_res = grid_spacing * low_res_factor - - kernel_low_res_x, kernel_high_res_x = kernel_util.split_kernel(kernel_x, high_res_kernel_size, low_res_factor, - normalized=False) - f_x_high_res = scp.fftconvolve(kappa_high_res, kernel_high_res_x, mode='same') / np.pi * grid_spacing ** 2 - f_x_high_res = image_util.re_size(f_x_high_res, low_res_factor) - f_x_low_res = scp.fftconvolve(kappa_low_res, kernel_low_res_x, mode='same') / np.pi * grid_spacing_low_res ** 2 - f_x = f_x_high_res + f_x_low_res - - kernel_low_res_y, kernel_high_res_y = kernel_util.split_kernel(kernel_y, high_res_kernel_size, low_res_factor, - normalized=False) - f_y_high_res = scp.fftconvolve(kappa_high_res, kernel_high_res_y, mode='same') / np.pi * grid_spacing ** 2 - f_y_high_res = image_util.re_size(f_y_high_res, low_res_factor) - f_y_low_res = scp.fftconvolve(kappa_low_res, kernel_low_res_y, mode='same') / np.pi * grid_spacing_low_res ** 2 - f_y = f_y_high_res + f_y_low_res - return f_x, f_y
- - -
[docs]@export -def potential_kernel(num_pix, delta_pix): - """ - numerical gridded integration kernel for convergence to lensing kernel with given pixel size - - :param num_pix: integer; number of pixels of kernel per axis - :param delta_pix: pixel size (per dimension in units of angle) - :return: kernel for lensing potential - """ - x_shift, y_shift = util.make_grid(numPix=num_pix, deltapix=delta_pix) - r2 = x_shift ** 2 + y_shift ** 2 - r2_max = np.max(r2) - r2[r2 < (delta_pix / 2) ** 2] = (delta_pix / 2) ** 2 - lnr = np.log(r2/r2_max) / 2. - kernel = util.array2image(lnr) - return kernel
- - -
[docs]@export -def deflection_kernel(num_pix, delta_pix): - """ - numerical gridded integration kernel for convergence to deflection angle with given pixel size - - :param num_pix: integer; number of pixels of kernel per axis, should be odd number to have a defined center - :param delta_pix: pixel size (per dimension in units of angle) - :return: kernel for x-direction and kernel of y-direction deflection angles - """ - x_shift, y_shift = util.make_grid(numPix=num_pix, deltapix=delta_pix) - r2 = x_shift**2 + y_shift**2 - r2[r2 < (delta_pix/2)**2] = (delta_pix/2) ** 2 - - kernel_x = util.array2image(x_shift / r2) - kernel_y = util.array2image(y_shift / r2) - return kernel_x, kernel_y
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/lens_model.html b/docs/_build/html/_modules/lenstronomy/LensModel/lens_model.html deleted file mode 100644 index 4b7a91edb..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/lens_model.html +++ /dev/null @@ -1,485 +0,0 @@ - - - - - - - - lenstronomy.LensModel.lens_model — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.lens_model

-__author__ = 'sibirrer'
-from lenstronomy.LensModel.single_plane import SinglePlane
-from lenstronomy.LensModel.MultiPlane.multi_plane import MultiPlane
-from lenstronomy.Cosmo.lens_cosmo import LensCosmo
-from lenstronomy.Util import constants as const
-
-__all__ = ['LensModel']
-
-
-
[docs]class LensModel(object): - """ - class to handle an arbitrary list of lens models. This is the main lenstronomy LensModel API for all other modules. - """ - - def __init__(self, lens_model_list, z_lens=None, z_source=None, lens_redshift_list=None, cosmo=None, - multi_plane=False, numerical_alpha_class=None, observed_convention_index=None, - z_source_convention=None, cosmo_interp=False, z_interp_stop=None, num_z_interp=100, - kwargs_interp=None): - """ - - :param lens_model_list: list of strings with lens model names - :param z_lens: redshift of the deflector (only considered when operating in single plane mode). - Is only needed for specific functions that require a cosmology. - :param z_source: redshift of the source: Needed in multi_plane option only, - not required for the core functionalities in the single plane mode. - :param lens_redshift_list: list of deflector redshift (corresponding to the lens model list), - only applicable in multi_plane mode. - :param cosmo: instance of the astropy cosmology class. If not specified, uses the default cosmology. - :param multi_plane: bool, if True, uses multi-plane mode. Default is False. - :param numerical_alpha_class: an instance of a custom class for use in NumericalAlpha() lens model - (see documentation in Profiles/numerical_alpha) - :param kwargs_interp: interpolation keyword arguments specifying the numerics. - See description in the Interpolate() class. Only applicable for 'INTERPOL' and 'INTERPOL_SCALED' models. - :param observed_convention_index: a list of indices, corresponding to the lens_model_list element with same - index, where the 'center_x' and 'center_y' kwargs correspond to observed (lensed) positions, not physical - positions. The code will compute the physical locations when performing computations - :param z_source_convention: float, redshift of a source to define the reduced deflection angles of the lens - models. If None, 'z_source' is used. - :param cosmo_interp: boolean (only employed in multi-plane mode), interpolates astropy.cosmology distances for - faster calls when accessing several lensing planes - :param z_interp_stop: (only in multi-plane with cosmo_interp=True); maximum redshift for distance interpolation - This number should be higher or equal the maximum of the source redshift and/or the z_source_convention - :param num_z_interp: (only in multi-plane with cosmo_interp=True); number of redshift bins for interpolating - distances - """ - self.lens_model_list = lens_model_list - self.z_lens = z_lens - self.z_source = z_source - self._z_source_convention = z_source_convention - self.redshift_list = lens_redshift_list - - if cosmo is None: - from astropy.cosmology import default_cosmology - cosmo = default_cosmology.get() - self.cosmo = cosmo - self.multi_plane = multi_plane - if multi_plane is True: - if z_source is None: - raise ValueError('z_source needs to be set for multi-plane lens modelling.') - - self.lens_model = MultiPlane(z_source, lens_model_list, lens_redshift_list, cosmo=cosmo, - numerical_alpha_class=numerical_alpha_class, - observed_convention_index=observed_convention_index, - z_source_convention=z_source_convention, cosmo_interp=cosmo_interp, - z_interp_stop=z_interp_stop, num_z_interp=num_z_interp, - kwargs_interp=kwargs_interp) - else: - self.lens_model = SinglePlane(lens_model_list, numerical_alpha_class=numerical_alpha_class, - lens_redshift_list=lens_redshift_list, - z_source_convention=z_source_convention, kwargs_interp=kwargs_interp) - if z_lens is not None and z_source is not None: - self._lensCosmo = LensCosmo(z_lens, z_source, cosmo=cosmo) - -
[docs] def ray_shooting(self, x, y, kwargs, k=None): - """ - maps image to source position (inverse deflection) - - :param x: x-position (preferentially arcsec) - :type x: numpy array - :param y: y-position (preferentially arcsec) - :type y: numpy array - :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes - :param k: only evaluate the k-th lens model - :return: source plane positions corresponding to (x, y) in the image plane - """ - return self.lens_model.ray_shooting(x, y, kwargs, k=k)
- -
[docs] def fermat_potential(self, x_image, y_image, kwargs_lens, x_source=None, y_source=None): - """ - Fermat potential (negative sign means earlier arrival time) - for Multi-plane lensing, it computes the effective Fermat potential (derived from the arrival time and - subtracted off the time-delay distance for the given cosmology). The units are given in arcsecond square. - - :param x_image: image position - :param y_image: image position - :param x_source: source position - :param y_source: source position - :param kwargs_lens: list of keyword arguments of lens model parameters matching the lens model classes - :return: fermat potential in arcsec**2 without geometry term (second part of Eqn 1 in Suyu et al. 2013) as a list - """ - if hasattr(self.lens_model, 'fermat_potential'): - return self.lens_model.fermat_potential(x_image, y_image, kwargs_lens, x_source, y_source) - elif hasattr(self.lens_model, 'arrival_time') and hasattr(self, '_lensCosmo'): - dt = self.lens_model.arrival_time(x_image, y_image, kwargs_lens) - fermat_pot_eff = dt * const.c / self._lensCosmo.ddt / const.Mpc * const.day_s / const.arcsec ** 2 - return fermat_pot_eff - else: - raise ValueError('In multi-plane lensing you need to provide a specific z_lens and z_source for which the ' - 'effective Fermat potential is evaluated')
- -
[docs] def arrival_time(self, x_image, y_image, kwargs_lens, kappa_ext=0, x_source=None, y_source=None): - """ - Arrival time of images relative to a straight line without lensing. - Negative values correspond to images arriving earlier, and positive signs correspond to images arriving later. - - :param x_image: image position - :param y_image: image position - :param kwargs_lens: lens model parameter keyword argument list - :param kappa_ext: external convergence contribution not accounted in the lens model that leads to the same - observables in position and relative fluxes but rescales the time delays - :param x_source: source position (optional), otherwise computed with ray-tracing - :param y_source: source position (optional), otherwise computed with ray-tracing - :return: arrival time of image positions in units of days - """ - if hasattr(self.lens_model, 'arrival_time'): - arrival_time = self.lens_model.arrival_time(x_image, y_image, kwargs_lens) - else: - fermat_pot = self.lens_model.fermat_potential(x_image, y_image, kwargs_lens, x_source=x_source, - y_source=y_source) - if not hasattr(self, '_lensCosmo'): - raise ValueError("LensModel class was not initialized with lens and source redshifts!") - arrival_time = self._lensCosmo.time_delay_units(fermat_pot) - arrival_time *= (1 - kappa_ext) - return arrival_time
- -
[docs] def potential(self, x, y, kwargs, k=None): - """ - lensing potential - - :param x: x-position (preferentially arcsec) - :type x: numpy array - :param y: y-position (preferentially arcsec) - :type y: numpy array - :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes - :param k: only evaluate the k-th lens model - :return: lensing potential in units of arcsec^2 - """ - return self.lens_model.potential(x, y, kwargs, k=k)
- -
[docs] def alpha(self, x, y, kwargs, k=None, diff=None): - """ - deflection angles - - :param x: x-position (preferentially arcsec) - :type x: numpy array - :param y: y-position (preferentially arcsec) - :type y: numpy array - :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes - :param k: only evaluate the k-th lens model - :param diff: None or float. If set, computes the deflection as a finite numerical differential of the lensing - potential. This differential is only applicable in the single lensing plane where the form of the lensing - potential is analytically known - :return: deflection angles in units of arcsec - """ - if diff is None: - return self.lens_model.alpha(x, y, kwargs, k=k) - elif self.multi_plane is False: - return self._deflection_differential(x, y, kwargs, k=k, diff=diff) - else: - raise ValueError('numerical differentiation of lensing potential is not available in the multi-plane ' - 'setting as analytical form of lensing potential is not available.')
- -
[docs] def hessian(self, x, y, kwargs, k=None, diff=None, diff_method='square'): - """ - hessian matrix - - :param x: x-position (preferentially arcsec) - :type x: numpy array - :param y: y-position (preferentially arcsec) - :type y: numpy array - :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes - :param k: only evaluate the k-th lens model - :param diff: float, scale over which the finite numerical differential is computed. If None, then using the - exact (if available) differentials. - :param diff_method: string, 'square' or 'cross', indicating whether finite differentials are computed from a - cross or a square of points around (x, y) - :return: f_xx, f_xy, f_yx, f_yy components - """ - if diff is None: - return self.lens_model.hessian(x, y, kwargs, k=k) - elif diff_method == 'square': - return self._hessian_differential_square(x, y, kwargs, k=k, diff=diff) - elif diff_method == 'cross': - return self._hessian_differential_cross(x, y, kwargs, k=k, diff=diff) - else: - raise ValueError('diff_method %s not supported. Chose among "square" or "cross".' % diff_method)
- -
[docs] def kappa(self, x, y, kwargs, k=None, diff=None, diff_method='square'): - """ - lensing convergence k = 1/2 laplacian(phi) - - :param x: x-position (preferentially arcsec) - :type x: numpy array - :param y: y-position (preferentially arcsec) - :type y: numpy array - :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes - :param k: only evaluate the k-th lens model - :param diff: float, scale over which the finite numerical differential is computed. If None, then using the - exact (if available) differentials. - :param diff_method: string, 'square' or 'cross', indicating whether finite differentials are computed from a - cross or a square of points around (x, y) - :return: lensing convergence - """ - - f_xx, f_xy, f_yx, f_yy = self.hessian(x, y, kwargs, k=k, diff=diff, diff_method=diff_method) - kappa = 1./2 * (f_xx + f_yy) - return kappa
- -
[docs] def curl(self, x, y, kwargs, k=None, diff=None, diff_method='square'): - """ - curl computation F_xy - F_yx - - :param x: x-position (preferentially arcsec) - :type x: numpy array - :param y: y-position (preferentially arcsec) - :type y: numpy array - :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes - :param k: only evaluate the k-th lens model - :param diff: float, scale over which the finite numerical differential is computed. If None, then using the - exact (if available) differentials. - :param diff_method: string, 'square' or 'cross', indicating whether finite differentials are computed from a - cross or a square of points around (x, y) - :return: curl at position (x, y) - """ - f_xx, f_xy, f_yx, f_yy = self.hessian(x, y, kwargs, k=k, diff=diff, diff_method=diff_method) - return f_xy - f_yx
- -
[docs] def gamma(self, x, y, kwargs, k=None, diff=None, diff_method='square'): - """ - shear computation - g1 = 1/2(d^2phi/dx^2 - d^2phi/dy^2) - g2 = d^2phi/dxdy - - :param x: x-position (preferentially arcsec) - :type x: numpy array - :param y: y-position (preferentially arcsec) - :type y: numpy array - :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes - :param k: only evaluate the k-th lens model - :param diff: float, scale over which the finite numerical differential is computed. If None, then using the - exact (if available) differentials. - :param diff_method: string, 'square' or 'cross', indicating whether finite differentials are computed from a - cross or a square of points around (x, y) - :return: gamma1, gamma2 - """ - - f_xx, f_xy, f_yx, f_yy = self.hessian(x, y, kwargs, k=k, diff=diff, diff_method=diff_method) - gamma1 = 1./2 * (f_xx - f_yy) - gamma2 = f_xy - return gamma1, gamma2
- -
[docs] def magnification(self, x, y, kwargs, k=None, diff=None, diff_method='square'): - """ - magnification - mag = 1/det(A) - A = 1 - d^2phi/d_ij - - :param x: x-position (preferentially arcsec) - :type x: numpy array - :param y: y-position (preferentially arcsec) - :type y: numpy array - :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes - :param k: only evaluate the k-th lens model - :param diff: float, scale over which the finite numerical differential is computed. If None, then using the - exact (if available) differentials. - :param diff_method: string, 'square' or 'cross', indicating whether finite differentials are computed from a - cross or a square of points around (x, y) - :return: magnification - """ - - f_xx, f_xy, f_yx, f_yy = self.hessian(x, y, kwargs, k=k, diff=diff, diff_method=diff_method) - det_A = (1 - f_xx) * (1 - f_yy) - f_xy*f_yx - return 1./det_A # attention, if dividing by zero
- -
[docs] def flexion(self, x, y, kwargs, k=None, diff=0.000001, hessian_diff=True): - """ - third derivatives (flexion) - - :param x: x-position (preferentially arcsec) - :type x: numpy array - :param y: y-position (preferentially arcsec) - :type y: numpy array - :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes - :param k: int or None, if set, only evaluates the differential from one model component - :param diff: numerical differential length of Flexion - :param hessian_diff: boolean, if true also computes the numerical differential length of Hessian (optional) - :return: f_xxx, f_xxy, f_xyy, f_yyy - """ - if hessian_diff is not True: - hessian_diff = None - f_xx_dx, f_xy_dx, f_yx_dx, f_yy_dx = self.hessian(x + diff/2, y, kwargs, k=k, diff=hessian_diff) - f_xx_dy, f_xy_dy, f_yx_dy, f_yy_dy = self.hessian(x, y + diff/2, kwargs, k=k, diff=hessian_diff) - - f_xx_dx_, f_xy_dx_, f_yx_dx_, f_yy_dx_ = self.hessian(x - diff/2, y, kwargs, k=k, diff=hessian_diff) - f_xx_dy_, f_xy_dy_, f_yx_dy_, f_yy_dy_ = self.hessian(x, y - diff/2, kwargs, k=k, diff=hessian_diff) - - f_xxx = (f_xx_dx - f_xx_dx_) / diff - f_xxy = (f_xx_dy - f_xx_dy_) / diff - f_xyy = (f_xy_dy - f_xy_dy_) / diff - f_yyy = (f_yy_dy - f_yy_dy_) / diff - return f_xxx, f_xxy, f_xyy, f_yyy
- -
[docs] def set_static(self, kwargs): - """ - set this instance to a static lens model. This can improve the speed in evaluating lensing quantities at - different positions but must not be used with different lens model parameters! - - :param kwargs: lens model keyword argument list - :return: kwargs_updated (in case of image position convention in multiplane lensing this is changed) - """ - return self.lens_model.set_static(kwargs)
- -
[docs] def set_dynamic(self): - """ - deletes cache for static setting and makes sure the observed convention in the position of lensing profiles in - the multi-plane setting is enabled. Dynamic is the default setting of this class enabling an accurate computation - of lensing quantities with different parameters in the lensing profiles. - - :return: None - """ - self.lens_model.set_dynamic()
- - def _deflection_differential(self, x, y, kwargs, k=None, diff=0.00001): - """ - - :param x: x-coordinate - :param y: y-coordinate - :param kwargs: keyword argument list - :param k: int or None, if set, only evaluates the differential from one model component - :param diff: finite differential length - :return: f_x, f_y - """ - phi_dx = self.lens_model.potential(x + diff/2, y, kwargs=kwargs, k=k) - phi_dy = self.lens_model.potential(x, y + diff/2, kwargs=kwargs, k=k) - phi_dx_ = self.lens_model.potential(x - diff/2, y, kwargs=kwargs, k=k) - phi_dy_ = self.lens_model.potential(x, y - diff/2, kwargs=kwargs, k=k) - f_x = (phi_dx - phi_dx_) / diff - f_y = (phi_dy - phi_dy_) / diff - return f_x, f_y - - def _hessian_differential_cross(self, x, y, kwargs, k=None, diff=0.00001): - """ - computes the numerical differentials over a finite range for f_xx, f_yy, f_xy from f_x and f_y - The differentials are computed along the cross centered at (x, y). - - :param x: x-coordinate - :param y: y-coordinate - :param kwargs: lens model keyword argument list - :param k: int, list of bools or None, indicating a subset of lens models to be evaluated - :param diff: float, scale of the finite differential (diff/2 in each direction used to compute the differential - :return: f_xx, f_xy, f_yx, f_yy - """ - alpha_ra_dx, alpha_dec_dx = self.alpha(x + diff/2, y, kwargs, k=k) - alpha_ra_dy, alpha_dec_dy = self.alpha(x, y + diff/2, kwargs, k=k) - - alpha_ra_dx_, alpha_dec_dx_ = self.alpha(x - diff/2, y, kwargs, k=k) - alpha_ra_dy_, alpha_dec_dy_ = self.alpha(x, y - diff/2, kwargs, k=k) - - dalpha_rara = (alpha_ra_dx - alpha_ra_dx_) / diff - dalpha_radec = (alpha_ra_dy - alpha_ra_dy_) / diff - dalpha_decra = (alpha_dec_dx - alpha_dec_dx_) / diff - dalpha_decdec = (alpha_dec_dy - alpha_dec_dy_) / diff - - f_xx = dalpha_rara - f_yy = dalpha_decdec - f_xy = dalpha_radec - f_yx = dalpha_decra - return f_xx, f_xy, f_yx, f_yy - - def _hessian_differential_square(self, x, y, kwargs, k=None, diff=0.00001): - """ - computes the numerical differentials over a finite range for f_xx, f_yy, f_xy from f_x and f_y - The differentials are computed on the square around (x, y). This minimizes curl. - - :param x: x-coordinate - :param y: y-coordinate - :param kwargs: lens model keyword argument list - :param k: int, list of booleans or None, indicating a subset of lens models to be evaluated - :param diff: float, scale of the finite differential (diff/2 in each direction used to compute the differential - :return: f_xx, f_xy, f_yx, f_yy - """ - alpha_ra_pp, alpha_dec_pp = self.alpha(x + diff/2, y + diff/2, kwargs, k=k) - alpha_ra_pn, alpha_dec_pn = self.alpha(x + diff/2, y - diff/2, kwargs, k=k) - - alpha_ra_np, alpha_dec_np = self.alpha(x - diff / 2, y + diff / 2, kwargs, k=k) - alpha_ra_nn, alpha_dec_nn = self.alpha(x - diff / 2, y - diff / 2, kwargs, k=k) - - f_xx = (alpha_ra_pp - alpha_ra_np + alpha_ra_pn - alpha_ra_nn) / diff / 2 - f_xy = (alpha_ra_pp - alpha_ra_pn + alpha_ra_np - alpha_ra_nn) / diff / 2 - f_yx = (alpha_dec_pp - alpha_dec_np + alpha_dec_pn - alpha_dec_nn) / diff / 2 - f_yy = (alpha_dec_pp - alpha_dec_pn + alpha_dec_np - alpha_dec_nn) / diff / 2 - - return f_xx, f_xy, f_yx, f_yy
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/lens_model_extensions.html b/docs/_build/html/_modules/lenstronomy/LensModel/lens_model_extensions.html deleted file mode 100644 index 0b19dc59f..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/lens_model_extensions.html +++ /dev/null @@ -1,761 +0,0 @@ - - - - - - - - lenstronomy.LensModel.lens_model_extensions — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.lens_model_extensions

-import numpy as np
-import lenstronomy.Util.util as util
-from lenstronomy.Util.magnification_finite_util import setup_mag_finite
-
-__all__ = ['LensModelExtensions']
-
-
-
[docs]class LensModelExtensions(object): - """ - class with extension routines not part of the LensModel core routines - """ - def __init__(self, lensModel): - - """ - :param lensModel: instance of the LensModel() class, or with same functionalities. - In particular, the following definitions are required to execute all functionalities presented in this class: - def ray_shooting() - def magnification() - def kappa() - def alpha() - def hessian() - - """ - self._lensModel = lensModel - -
[docs] def magnification_finite_adaptive(self, x_image, y_image, source_x, source_y, kwargs_lens, - source_fwhm_parsec, z_source, - cosmo=None, grid_resolution=None, - grid_radius_arcsec=None, axis_ratio=0.5, - tol=0.001, step_size=0.05, - use_largest_eigenvalue=True, - source_light_model='SINGLE_GAUSSIAN', - dx=None, dy=None, size_scale=None, amp_scale=None, - fixed_aperture_size=False): - """ - This method computes image magnifications with a finite-size background source assuming a Gaussian or a - double Gaussian source light profile. It can be much faster that magnification_finite for lens models with many - deflectors and a compact source. This is because most pixels in a rectangular window around a lensed - image of a compact source do not map onto the source, and therefore don't contribute to the integrated flux in - the image plane. - - Rather than ray tracing through a rectangular grid, this routine accelerates the computation of image - magnifications with finite-size sources by ray tracing through an elliptical region oriented such that - tracks the surface brightness of the lensed image. The aperture size is initially quite small, - and increases in size until the flux inside of it (and hence the magnification) converges. The orientation of - the elliptical aperture is computed from the magnification tensor evaluated at the image coordinate. - - If for whatever reason you prefer a circular aperture to the elliptical approximation using the hessian - eigenvectors, you can just set axis_ratio = 1. - - To use the eigenvalues of the hessian matrix to estimate the optimum axis ratio, set axis_ratio = 0. - - The default settings for the grid resolution and ray tracing window size work well for sources with fwhm between - 0.5 - 100 pc. - - :param x_image: a list or array of x coordinates [units arcsec] - :param y_image: a list or array of y coordinates [units arcsec] - :param source_x: float, source position - :param source_y: float, source position - :param kwargs_lens: keyword arguments for the lens model - :param source_fwhm_parsec: the size of the background source [units parsec] - :param z_source: the source redshift - :param cosmo: (optional) an instance of astropy.cosmology; if not specified, a default cosmology will be used - :param grid_resolution: the grid resolution in units arcsec/pixel; if not specified, an appropriate value will - be estimated from the source size - :param grid_radius_arcsec: (optional) the size of the ray tracing region in arcsec; if not specified, an appropriate value - will be estimated from the source size - :param axis_ratio: the axis ratio of the ellipse used for ray tracing; if axis_ratio = 0, then the eigenvalues - the hessian matrix will be used to estimate an appropriate axis ratio. Be warned: if the image is highly - magnified it will tend to curve out of the resulting ellipse - :param tol: tolerance for convergence in the magnification - :param step_size: sets the increment for the successively larger ray tracing windows - :param use_largest_eigenvalue: bool; if True, then the major axis of the ray tracing ellipse region - will be aligned with the eigenvector corresponding to the largest eigenvalue of the hessian matrix - :param source_light_model: the model for backgourn source light; currently implemented are 'SINGLE_GAUSSIAN' and - 'DOUBLE_GAUSSIAN'. - :param dx: used with source model 'DOUBLE_GAUSSIAN', the offset of the second source light profile from the first - [arcsec] - :param dy: used with source model 'DOUBLE_GAUSSIAN', the offset of the second source light profile from the first - [arcsec] - :param size_scale: used with source model 'DOUBLE_GAUSSIAN', the size of the second source light profile relative - to the first - :param amp_scale: used with source model 'DOUBLE_GAUSSIAN', the peak brightness of the second source light profile - relative to the first - :param fixed_aperture_size: bool, if True the flux is computed inside a fixed aperture size with radius - grid_radius_arcsec - :return: an array of image magnifications - """ - - grid_x_0, grid_y_0, source_model, kwargs_source, grid_resolution, grid_radius_arcsec = setup_mag_finite(cosmo, - self._lensModel, - grid_radius_arcsec, - grid_resolution, - source_fwhm_parsec, - source_light_model, - z_source, - source_x, - source_y, - dx, dy, - amp_scale, - size_scale) - grid_x_0, grid_y_0 = grid_x_0.ravel(), grid_y_0.ravel() - - minimum_magnification = 1e-5 - - magnifications = [] - - for xi, yi in zip(x_image, y_image): - - if axis_ratio == 1: - grid_r = np.hypot(grid_x_0, grid_y_0) - else: - w1, w2, v11, v12, v21, v22 = self.hessian_eigenvectors(xi, yi, kwargs_lens) - _v = [np.array([v11, v12]), np.array([v21, v22])] - _w = [abs(w1), abs(w2)] - if use_largest_eigenvalue: - idx = int(np.argmax(_w)) - else: - idx = int(np.argmin(_w)) - v = _v[idx] - - rotation_angle = np.arctan(v[1] / v[0]) - np.pi / 2 - grid_x, grid_y = util.rotate(grid_x_0, grid_y_0, rotation_angle) - - if axis_ratio == 0: - sort = np.argsort(_w) - q = _w[sort[0]] / _w[sort[1]] - grid_r = np.hypot(grid_x, grid_y / q).ravel() - else: - grid_r = np.hypot(grid_x, grid_y / axis_ratio).ravel() - - flux_array = np.zeros_like(grid_x_0) - step = step_size * grid_radius_arcsec - - r_min = 0 - if fixed_aperture_size: - r_max = grid_radius_arcsec - else: - r_max = step - magnification_current = 0. - - while True: - - flux_array = self._magnification_adaptive_iteration(flux_array, xi, yi, grid_x_0, grid_y_0, grid_r, - r_min, r_max, self._lensModel, kwargs_lens, - source_model, kwargs_source) - new_magnification = np.sum(flux_array) * grid_resolution ** 2 - diff = abs(new_magnification - magnification_current) / new_magnification - - if r_max >= grid_radius_arcsec: - break - elif diff < tol and new_magnification > minimum_magnification: - break - else: - r_min += step - r_max += step - magnification_current = new_magnification - - magnifications.append(new_magnification) - - return np.array(magnifications)
- - @staticmethod - def _magnification_adaptive_iteration(flux_array, x_image, y_image, grid_x, grid_y, grid_r, r_min, r_max, - lensModel, kwargs_lens, source_model, kwargs_source): - """ - This function computes the surface brightness of coordinates in 'flux_array' that satisfy r_min < grid_r < r_max, - where each coordinate in grid_r corresponds to a certain entry in flux_array. Likewise, grid_x, and grid_y - - :param flux_array: an array that contains the flux in each pixel - :param x_image: image x coordinate - :param y_image: image y coordinate - :param grid_x: an array of x coordinates - :param grid_y: an array of y coordinates - :param grid_r: an array of projected distances from the origin - :param r_min: sets the inner radius of the annulus where ray tracing happens - :param r_max: sets the outer radius of the annulus where ray tracing happens - :param lensModel: an instance of LensModel - :param kwargs_lens: keywords for the lens model - :param source_model: an instance of LightModel - :param kwargs_source: keywords for the light model - :return: the flux array where the surface brightness has been computed for all pixels - with r_min < grid_r < r_max. - """ - - condition1 = grid_r >= r_min - condition2 = grid_r < r_max - condition = np.logical_and(condition1, condition2) - - inds = np.where(condition)[0] - - xcoords = grid_x[inds] + x_image - ycoords = grid_y[inds] + y_image - beta_x, beta_y = lensModel.ray_shooting(xcoords, ycoords, kwargs_lens) - flux_in_pixels = source_model.surface_brightness(beta_x, beta_y, kwargs_source) - flux_array[inds] = flux_in_pixels - - return flux_array - -
[docs] def magnification_finite(self, x_pos, y_pos, kwargs_lens, source_sigma=0.003, window_size=0.1, grid_number=100, - polar_grid=False, aspect_ratio=0.5): - """ - returns the magnification of an extended source with Gaussian light profile - :param x_pos: x-axis positons of point sources - :param y_pos: y-axis position of point sources - :param kwargs_lens: lens model kwargs - :param source_sigma: Gaussian sigma in arc sec in source - :param window_size: size of window to compute the finite flux - :param grid_number: number of grid cells per axis in the window to numerically compute the flux - :return: numerically computed brightness of the sources - """ - - mag_finite = np.zeros_like(x_pos) - deltaPix = float(window_size)/grid_number - from lenstronomy.LightModel.Profiles.gaussian import Gaussian - quasar = Gaussian() - x_grid, y_grid = util.make_grid(numPix=grid_number, deltapix=deltaPix, subgrid_res=1) - - if polar_grid is True: - a = window_size*0.5 - b = window_size*0.5*aspect_ratio - ellipse_inds = (x_grid*a**-1) ** 2 + (y_grid*b**-1) ** 2 <= 1 - x_grid, y_grid = x_grid[ellipse_inds], y_grid[ellipse_inds] - - for i in range(len(x_pos)): - ra, dec = x_pos[i], y_pos[i] - - center_x, center_y = self._lensModel.ray_shooting(ra, dec, kwargs_lens) - - if polar_grid is True: - theta = np.arctan2(dec, ra) - xcoord, ycoord = util.rotate(x_grid, y_grid, theta) - else: - xcoord, ycoord = x_grid, y_grid - - betax, betay = self._lensModel.ray_shooting(xcoord + ra, ycoord + dec, kwargs_lens) - - I_image = quasar.function(betax, betay, 1., source_sigma, center_x, center_y) - mag_finite[i] = np.sum(I_image) * deltaPix**2 - return mag_finite
- -
[docs] def zoom_source(self, x_pos, y_pos, kwargs_lens, source_sigma=0.003, window_size=0.1, grid_number=100, - shape="GAUSSIAN"): - """ - computes the surface brightness on an image with a zoomed window - - :param x_pos: angular coordinate of center of image - :param y_pos: angular coordinate of center of image - :param kwargs_lens: lens model parameter list - :param source_sigma: source size (in angular units) - :param window_size: window size in angular units - :param grid_number: number of grid points per axis - :param shape: string, shape of source, supports 'GAUSSIAN' and 'TORUS - :return: 2d numpy array - """ - deltaPix = float(window_size) / grid_number - if shape == 'GAUSSIAN': - from lenstronomy.LightModel.Profiles.gaussian import Gaussian - quasar = Gaussian() - elif shape == 'TORUS': - import lenstronomy.LightModel.Profiles.ellipsoid as quasar - else: - raise ValueError("shape %s not valid for finite magnification computation!" % shape) - x_grid, y_grid = util.make_grid(numPix=grid_number, deltapix=deltaPix, subgrid_res=1) - center_x, center_y = self._lensModel.ray_shooting(x_pos, y_pos, kwargs_lens) - betax, betay = self._lensModel.ray_shooting(x_grid + x_pos, y_grid + y_pos, kwargs_lens) - image = quasar.function(betax, betay, 1., source_sigma, center_x, center_y) - return util.array2image(image)
- -
[docs] def critical_curve_tiling(self, kwargs_lens, compute_window=5, start_scale=0.5, max_order=10, center_x=0, - center_y=0): - """ - - :param kwargs_lens: lens model keyword argument list - :param compute_window: total window in the image plane where to search for critical curves - :param start_scale: float, angular scale on which to start the tiling from (if there are two distinct curves in - a region, it might only find one. - :param max_order: int, maximum order in the tiling to compute critical curve triangles - :param center_x: float, center of the window to compute critical curves and caustics - :param center_y: float, center of the window to compute critical curves and caustics - :return: list of positions representing coordinates of the critical curve (in RA and DEC) - """ - numPix = int(compute_window / start_scale) - x_grid_init, y_grid_init = util.make_grid(numPix, deltapix=start_scale, subgrid_res=1) - x_grid_init += center_x - y_grid_init += center_y - mag_init = util.array2image(self._lensModel.magnification(x_grid_init, y_grid_init, kwargs_lens)) - x_grid_init = util.array2image(x_grid_init) - y_grid_init = util.array2image(y_grid_init) - - ra_crit_list = [] - dec_crit_list = [] - # iterate through original triangles and return ra_crit, dec_crit list - for i in range(numPix-1): - for j in range(numPix-1): - edge1 = [x_grid_init[i, j], y_grid_init[i, j], mag_init[i, j]] - edge2 = [x_grid_init[i+1, j+1], y_grid_init[i+1, j+1], mag_init[i+1, j+1]] - edge_90_1 = [x_grid_init[i, j+1], y_grid_init[i, j+1], mag_init[i, j+1]] - edge_90_2 = [x_grid_init[i+1, j], y_grid_init[i+1, j], mag_init[i+1, j]] - ra_crit, dec_crit = self._tiling_crit(edge1, edge2, edge_90_1, max_order=max_order, - kwargs_lens=kwargs_lens) - ra_crit_list += ra_crit # list addition - dec_crit_list += dec_crit # list addition - ra_crit, dec_crit = self._tiling_crit(edge1, edge2, edge_90_2, max_order=max_order, - kwargs_lens=kwargs_lens) - ra_crit_list += ra_crit # list addition - dec_crit_list += dec_crit # list addition - return np.array(ra_crit_list), np.array(dec_crit_list)
- -
[docs] def caustic_area(self, kwargs_lens, kwargs_caustic_num, index_vertices=0): - """ - computes the area inside a connected caustic curve - - :param kwargs_lens: lens model keyword argument list - :param kwargs_caustic_num: keyword arguments for the numerical calculation of the caustics, as input of - self.critical_curve_caustics() - :param index_vertices: integer, index of connected vortex from the output of self.critical_curve_caustics() - of disconnected curves. - :return: area within the caustic curve selected - """ - - ra_crit_list, dec_crit_list, ra_caustic_list, dec_caustic_list = self.critical_curve_caustics(kwargs_lens, - **kwargs_caustic_num) - - # select specific vortex - ra_caustic_inner = ra_caustic_list[index_vertices] - dec_caustic_inner = dec_caustic_list[index_vertices] - - # merge RA DEC to vertices - C = np.dstack([ra_caustic_inner, dec_caustic_inner])[0] - - # compute area - a = util.area(C) - return a
- - def _tiling_crit(self, edge1, edge2, edge_90, max_order, kwargs_lens): - """ - tiles a rectangular triangle and compares the signs of the magnification - - :param edge1: [ra_coord, dec_coord, magnification] - :param edge2: [ra_coord, dec_coord, magnification] - :param edge_90: [ra_coord, dec_coord, magnification] - :param max_order: maximal order to fold triangle - :param kwargs_lens: lens model keyword argument list - :return: - """ - ra_1, dec_1, mag_1 = edge1 - ra_2, dec_2, mag_2 = edge2 - ra_3, dec_3, mag_3 = edge_90 - sign_list = np.sign([mag_1, mag_2, mag_3]) - if sign_list[0] == sign_list[1] and sign_list[0] == sign_list[2]: # if all signs are the same - return [], [] - else: - # split triangle along the long axis - # execute tiling twice - # add ra_crit and dec_crit together - # if max depth has been reached, return the mean value in the triangle - max_order -= 1 - if max_order <= 0: - return [(ra_1 + ra_2 + ra_3)/3], [(dec_1 + dec_2 + dec_3)/3] - else: - # split triangle - ra_90_ = (ra_1 + ra_2)/2 # find point in the middle of the long axis to split triangle - dec_90_ = (dec_1 + dec_2)/2 - mag_90_ = self._lensModel.magnification(ra_90_, dec_90_, kwargs_lens) - edge_90_ = [ra_90_, dec_90_, mag_90_] - ra_crit, dec_crit = self._tiling_crit(edge1=edge_90, edge2=edge1, edge_90=edge_90_, max_order=max_order, - kwargs_lens=kwargs_lens) - ra_crit_2, dec_crit_2 = self._tiling_crit(edge1=edge_90, edge2=edge2, edge_90=edge_90_, max_order=max_order, - kwargs_lens=kwargs_lens) - ra_crit += ra_crit_2 - dec_crit += dec_crit_2 - return ra_crit, dec_crit - -
[docs] def critical_curve_caustics(self, kwargs_lens, compute_window=5, grid_scale=0.01, center_x=0, center_y=0): - """ - - :param kwargs_lens: lens model kwargs - :param compute_window: window size in arcsec where the critical curve is computed - :param grid_scale: numerical grid spacing of the computation of the critical curves - :param center_x: float, center of the window to compute critical curves and caustics - :param center_y: float, center of the window to compute critical curves and caustics - :return: lists of ra and dec arrays corresponding to different disconnected critical curves and their caustic counterparts - - """ - numPix = int(compute_window / grid_scale) - x_grid_high_res, y_grid_high_res = util.make_grid(numPix, deltapix=grid_scale, subgrid_res=1) - x_grid_high_res += center_x - y_grid_high_res += center_y - mag_high_res = util.array2image(self._lensModel.magnification(x_grid_high_res, y_grid_high_res, kwargs_lens)) - - ra_crit_list = [] - dec_crit_list = [] - ra_caustic_list = [] - dec_caustic_list = [] - - # Import moved here to avoid import-time exception if skimage is missing - from skimage.measure import find_contours - paths = find_contours(1/mag_high_res, 0.) - - for i, v in enumerate(paths): - # x, y changed because of skimage conventions - ra_points = v[:, 1] * grid_scale - grid_scale * (numPix-1)/2 + center_x - dec_points = v[:, 0] * grid_scale - grid_scale * (numPix-1)/2 + center_y - ra_crit_list.append(ra_points) - dec_crit_list.append(dec_points) - ra_caustics, dec_caustics = self._lensModel.ray_shooting(ra_points, dec_points, kwargs_lens) - ra_caustic_list.append(ra_caustics) - dec_caustic_list.append(dec_caustics) - return ra_crit_list, dec_crit_list, ra_caustic_list, dec_caustic_list
- -
[docs] def hessian_eigenvectors(self, x, y, kwargs_lens, diff=None): - """ - computes magnification eigenvectors at position (x, y) - - :param x: x-position - :param y: y-position - :param kwargs_lens: lens model keyword arguments - :return: radial stretch, tangential stretch - """ - f_xx, f_xy, f_yx, f_yy = self._lensModel.hessian(x, y, kwargs_lens, diff=diff) - if isinstance(x, int) or isinstance(x, float): - A = np.array([[1-f_xx, f_xy], [f_yx, 1-f_yy]]) - w, v = np.linalg.eig(A) - v11, v12, v21, v22 = v[0, 0], v[0, 1], v[1, 0], v[1, 1] - w1, w2 = w[0], w[1] - else: - w1, w2, v11, v12, v21, v22 = np.empty(len(x), dtype=float), np.empty(len(x), dtype=float), np.empty_like(x), np.empty_like(x), np.empty_like(x), np.empty_like(x) - for i in range(len(x)): - A = np.array([[1 - f_xx[i], f_xy[i]], [f_yx[i], 1 - f_yy[i]]]) - w, v = np.linalg.eig(A) - w1[i], w2[i] = w[0], w[1] - v11[i], v12[i], v21[i], v22[i] = v[0, 0], v[0, 1], v[1, 0], v[1, 1] - return w1, w2, v11, v12, v21, v22
- -
[docs] def radial_tangential_stretch(self, x, y, kwargs_lens, diff=None, ra_0=0, dec_0=0, - coordinate_frame_definitions=False): - """ - computes the radial and tangential stretches at a given position - - :param x: x-position - :param y: y-position - :param kwargs_lens: lens model keyword arguments - :param diff: float or None, finite average differential scale - :return: radial stretch, tangential stretch - """ - w1, w2, v11, v12, v21, v22 = self.hessian_eigenvectors(x, y, kwargs_lens, diff=diff) - v_x, v_y = x - ra_0, y - dec_0 - - prod_v1 = v_x*v11 + v_y*v12 - prod_v2 = v_x*v21 + v_y*v22 - if isinstance(x, int) or isinstance(x, float): - if (coordinate_frame_definitions is True and abs(prod_v1) >= abs(prod_v2)) or (coordinate_frame_definitions is False and w1 >= w2): - lambda_rad = 1. / w1 - lambda_tan = 1. / w2 - v1_rad, v2_rad = v11, v12 - v1_tan, v2_tan = v21, v22 - prod_r = prod_v1 - else: - lambda_rad = 1. / w2 - lambda_tan = 1. / w1 - v1_rad, v2_rad = v21, v22 - v1_tan, v2_tan = v11, v12 - prod_r = prod_v2 - if prod_r < 0: # if radial eigenvector points towards the center - v1_rad, v2_rad = -v1_rad, -v2_rad - if v1_rad * v2_tan - v2_rad * v1_tan < 0: # cross product defines orientation of the tangential eigenvector - v1_tan *= -1 - v2_tan *= -1 - - else: - lambda_rad, lambda_tan, v1_rad, v2_rad, v1_tan, v2_tan = np.empty(len(x), dtype=float), np.empty(len(x), dtype=float), np.empty_like(x), np.empty_like(x), np.empty_like(x), np.empty_like(x) - for i in range(len(x)): - if (coordinate_frame_definitions is True and abs(prod_v1[i]) >= abs(prod_v2[i])) or ( - coordinate_frame_definitions is False and w1[i] >= w2[i]): - # if w1[i] > w2[i]: - lambda_rad[i] = 1. / w1[i] - lambda_tan[i] = 1. / w2[i] - v1_rad[i], v2_rad[i] = v11[i], v12[i] - v1_tan[i], v2_tan[i] = v21[i], v22[i] - prod_r = prod_v1[i] - else: - lambda_rad[i] = 1. / w2[i] - lambda_tan[i] = 1. / w1[i] - v1_rad[i], v2_rad[i] = v21[i], v22[i] - v1_tan[i], v2_tan[i] = v11[i], v12[i] - prod_r = prod_v2[i] - if prod_r < 0: # if radial eigenvector points towards the center - v1_rad[i], v2_rad[i] = -v1_rad[i], -v2_rad[i] - if v1_rad[i] * v2_tan[i] - v2_rad[i] * v1_tan[i] < 0: # cross product defines orientation of the tangential eigenvector - v1_tan[i] *= -1 - v2_tan[i] *= -1 - - return lambda_rad, lambda_tan, v1_rad, v2_rad, v1_tan, v2_tan
- -
[docs] def radial_tangential_differentials(self, x, y, kwargs_lens, center_x=0, center_y=0, smoothing_3rd=0.001, - smoothing_2nd=None): - """ - computes the differentials in stretches and directions - - :param x: x-position - :param y: y-position - :param kwargs_lens: lens model keyword arguments - :param center_x: x-coord of center towards which the rotation direction is defined - :param center_y: x-coord of center towards which the rotation direction is defined - :param smoothing_3rd: finite differential length of third order in units of angle - :param smoothing_2nd: float or None, finite average differential scale of Hessian - :return: - """ - lambda_rad, lambda_tan, v1_rad, v2_rad, v1_tan, v2_tan = self.radial_tangential_stretch(x, y, kwargs_lens, - diff=smoothing_2nd, - ra_0=center_x, dec_0=center_y, - coordinate_frame_definitions=True) - x0 = x - center_x - y0 = y - center_y - - # computing angle of tangential vector in regard to the defined coordinate center - cos_angle = (v1_tan * x0 + v2_tan * y0) / np.sqrt((x0 ** 2 + y0 ** 2) * (v1_tan ** 2 + v2_tan ** 2)) # * np.sign(v1_tan * y0 - v2_tan * x0) - orientation_angle = np.arccos(cos_angle) - np.pi / 2 - - # computing differentials in tangential and radial directions - dx_tan = x + smoothing_3rd * v1_tan - dy_tan = y + smoothing_3rd * v2_tan - lambda_rad_dtan, lambda_tan_dtan, v1_rad_dtan, v2_rad_dtan, v1_tan_dtan, v2_tan_dtan = self.radial_tangential_stretch(dx_tan, dy_tan, kwargs_lens, diff=smoothing_2nd, - ra_0=center_x, dec_0=center_y, coordinate_frame_definitions=True) - dx_rad = x + smoothing_3rd * v1_rad - dy_rad = y + smoothing_3rd * v2_rad - lambda_rad_drad, lambda_tan_drad, v1_rad_drad, v2_rad_drad, v1_tan_drad, v2_tan_drad = self.radial_tangential_stretch( - dx_rad, dy_rad, kwargs_lens, diff=smoothing_2nd, ra_0=center_x, dec_0=center_y, coordinate_frame_definitions=True) - - # eigenvalue differentials in tangential and radial direction - dlambda_tan_dtan = (lambda_tan_dtan - lambda_tan) / smoothing_3rd # * np.sign(v1_tan * y0 - v2_tan * x0) - dlambda_tan_drad = (lambda_tan_drad - lambda_tan) / smoothing_3rd # * np.sign(v1_rad * x0 + v2_rad * y0) - dlambda_rad_drad = (lambda_rad_drad - lambda_rad) / smoothing_3rd # * np.sign(v1_rad * x0 + v2_rad * y0) - dlambda_rad_dtan = (lambda_rad_dtan - lambda_rad) / smoothing_3rd # * np.sign(v1_rad * x0 + v2_rad * y0) - - # eigenvector direction differentials in tangential and radial direction - cos_dphi_tan_dtan = v1_tan * v1_tan_dtan + v2_tan * v2_tan_dtan # / (np.sqrt(v1_tan**2 + v2_tan**2) * np.sqrt(v1_tan_dtan**2 + v2_tan_dtan**2)) - norm = np.sqrt(v1_tan**2 + v2_tan**2) * np.sqrt(v1_tan_dtan**2 + v2_tan_dtan**2) - cos_dphi_tan_dtan /= norm - arc_cos_dphi_tan_dtan = np.arccos(np.abs(np.minimum(cos_dphi_tan_dtan, 1))) - dphi_tan_dtan = arc_cos_dphi_tan_dtan / smoothing_3rd - - cos_dphi_tan_drad = v1_tan * v1_tan_drad + v2_tan * v2_tan_drad # / (np.sqrt(v1_tan ** 2 + v2_tan ** 2) * np.sqrt(v1_tan_drad ** 2 + v2_tan_drad ** 2)) - norm = np.sqrt(v1_tan ** 2 + v2_tan ** 2) * np.sqrt(v1_tan_drad ** 2 + v2_tan_drad ** 2) - cos_dphi_tan_drad /= norm - arc_cos_dphi_tan_drad = np.arccos(np.abs(np.minimum(cos_dphi_tan_drad, 1))) - dphi_tan_drad = arc_cos_dphi_tan_drad / smoothing_3rd - - cos_dphi_rad_drad = v1_rad * v1_rad_drad + v2_rad * v2_rad_drad # / (np.sqrt(v1_rad**2 + v2_rad**2) * np.sqrt(v1_rad_drad**2 + v2_rad_drad**2)) - norm = np.sqrt(v1_rad**2 + v2_rad**2) * np.sqrt(v1_rad_drad**2 + v2_rad_drad**2) - cos_dphi_rad_drad /= norm - cos_dphi_rad_drad = np.minimum(cos_dphi_rad_drad, 1) - dphi_rad_drad = np.arccos(cos_dphi_rad_drad) / smoothing_3rd - - cos_dphi_rad_dtan = v1_rad * v1_rad_dtan + v2_rad * v2_rad_dtan # / (np.sqrt(v1_rad ** 2 + v2_rad ** 2) * np.sqrt(v1_rad_dtan ** 2 + v2_rad_dtan ** 2)) - norm = np.sqrt(v1_rad ** 2 + v2_rad ** 2) * np.sqrt(v1_rad_dtan ** 2 + v2_rad_dtan ** 2) - cos_dphi_rad_dtan /= norm - cos_dphi_rad_dtan = np.minimum(cos_dphi_rad_dtan, 1) - dphi_rad_dtan = np.arccos(cos_dphi_rad_dtan) / smoothing_3rd - - return lambda_rad, lambda_tan, orientation_angle, dlambda_tan_dtan, dlambda_tan_drad, dlambda_rad_drad, dlambda_rad_dtan, dphi_tan_dtan, dphi_tan_drad, dphi_rad_drad, dphi_rad_dtan
- -
[docs] def curved_arc_estimate(self, x, y, kwargs_lens, smoothing=None, smoothing_3rd=0.001, tan_diff=False): - """ - performs the estimation of the curved arc description at a particular position of an arbitrary lens profile - - :param x: float, x-position where the estimate is provided - :param y: float, y-position where the estimate is provided - :param kwargs_lens: lens model keyword arguments - :param smoothing: (optional) finite differential of second derivative (radial and tangential stretches) - :param smoothing_3rd: differential scale for third derivative to estimate the tangential curvature - :param tan_diff: boolean, if True, also returns the relative tangential stretch differential in tangential direction - :return: keyword argument list corresponding to a CURVED_ARC profile at (x, y) given the initial lens model - """ - radial_stretch, tangential_stretch, v_rad1, v_rad2, v_tang1, v_tang2 = self.radial_tangential_stretch(x, y, kwargs_lens, diff=smoothing) - dx_tang = x + smoothing_3rd * v_tang1 - dy_tang = y + smoothing_3rd * v_tang2 - _, _, _, _, v_tang1_dt, v_tang2_dt = self.radial_tangential_stretch(dx_tang, dy_tang, kwargs_lens, - diff=smoothing) - d_tang1 = v_tang1_dt - v_tang1 - d_tang2 = v_tang2_dt - v_tang2 - delta = np.sqrt(d_tang1**2 + d_tang2**2) - if delta > 1: - d_tang1 = v_tang1_dt + v_tang1 - d_tang2 = v_tang2_dt + v_tang2 - delta = np.sqrt(d_tang1 ** 2 + d_tang2 ** 2) - curvature = delta / smoothing_3rd - direction = np.arctan2(v_rad2 * np.sign(v_rad1 * x + v_rad2 * y), v_rad1 * np.sign(v_rad1 * x + v_rad2 * y)) - - kwargs_arc = {'radial_stretch': radial_stretch, - 'tangential_stretch': tangential_stretch, - 'curvature': curvature, - 'direction': direction, - 'center_x': x, 'center_y': y} - if tan_diff: - lambda_rad, lambda_tan, orientation_angle, dlambda_tan_dtan, dlambda_tan_drad, dlambda_rad_drad, dlambda_rad_dtan, dphi_tan_dtan, dphi_tan_drad, dphi_rad_drad, dphi_rad_dtan = self.radial_tangential_differentials(x, y, kwargs_lens, center_x=0, center_y=0, smoothing_3rd=smoothing_3rd) - kwargs_arc['dtan_dtan'] = dlambda_tan_dtan / lambda_tan - return kwargs_arc
- -
[docs] def tangential_average(self, x, y, kwargs_lens, dr, smoothing=None, num_average=9): - """ - computes average tangential stretch around position (x, y) within dr in radial direction - - :param x: x-position (float) - :param y: y-position (float) - :param kwargs_lens: lens model keyword argument list - :param dr: averaging scale in radial direction - :param smoothing: smoothing scale of derivative - :param num_average: integer, number of points averaged over within dr in the radial direction - :return: - """ - radial_stretch, tangential_stretch, v_rad1, v_rad2, v_tang1, v_tang2 = self.radial_tangential_stretch(x, y, - kwargs_lens, - diff=smoothing) - dr_array = np.linspace(start=-dr/2., stop=dr/2., num=num_average) - dx_r = x + dr_array * v_rad1 - dy_r = y + dr_array * v_rad2 - _, tangential_stretch_dr, _, _, _, _ = self.radial_tangential_stretch(dx_r, dy_r, kwargs_lens, diff=smoothing) - return np.average(tangential_stretch_dr)
- -
[docs] def curved_arc_finite_area(self, x, y, kwargs_lens, dr): - """ - computes an estimated curved arc over a finite extent mimicking the appearance of a finite source with radius dr - - :param x: x-position (float) - :param y: y-position (float) - :param kwargs_lens: lens model keyword argument list - :param dr: radius of finite source - :return: keyword arguments of curved arc - """ - - # estimate curvature centroid as the median around the circle - - # make circle of points around position of interest - x_c, y_c = util.points_on_circle(radius=dr, num_points=20, connect_ends=False) - - c_x_list, c_y_list = [], [] - # loop through curved arc estimate and compute curvature centroid - for x_, y_ in zip(x_c, y_c): - kwargs_arc_ = self.curved_arc_estimate(x_, y_, kwargs_lens) - direction = kwargs_arc_['direction'] - curvature = kwargs_arc_['curvature'] - center_x = x_ - np.cos(direction) / curvature - center_y = y_ - np.sin(direction) / curvature - c_x_list.append(center_x) - c_y_list.append(center_y) - center_x, center_y = np.median(c_x_list), np.median(c_y_list) - - # compute curvature and direction to the average centroid from the position of interest - r = np.sqrt((x - center_x) ** 2 + (y - center_y)**2) - curvature = 1 / r - direction = np.arctan2(y - center_y, x - center_x) - - # compute average radial stretch as the inverse difference in the source position - x_r = x + np.cos(direction) * dr - y_r = y + np.sin(direction) * dr - x_r_ = x - np.cos(direction) * dr - y_r_ = y - np.sin(direction) * dr - - xs_r, ys_r = self._lensModel.ray_shooting(x_r, y_r, kwargs_lens) - xs_r_, ys_r_ = self._lensModel.ray_shooting(x_r_, y_r_, kwargs_lens) - ds = np.sqrt((xs_r - xs_r_)**2 + (ys_r - ys_r_)**2) - radial_stretch = (2 * dr) / ds - - # compute average tangential stretch as the inverse difference in the sosurce position - x_t = x - np.sin(direction) * dr - y_t = y + np.cos(direction) * dr - x_t_ = x + np.sin(direction) * dr - y_t_ = y - np.cos(direction) * dr - - xs_t, ys_t = self._lensModel.ray_shooting(x_t, y_t, kwargs_lens) - xs_t_, ys_t_ = self._lensModel.ray_shooting(x_t_, y_t_, kwargs_lens) - ds = np.sqrt((xs_t - xs_t_) ** 2 + (ys_t - ys_t_) ** 2) - tangential_stretch = (2 * dr) / ds - kwargs_arc = {'direction': direction, 'radial_stretch': radial_stretch, - 'tangential_stretch': tangential_stretch, 'center_x': x, 'center_y': y, - 'curvature': curvature} - return kwargs_arc
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/lens_param.html b/docs/_build/html/_modules/lenstronomy/LensModel/lens_param.html deleted file mode 100644 index 654c006d9..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/lens_param.html +++ /dev/null @@ -1,266 +0,0 @@ - - - - - - - - lenstronomy.LensModel.lens_param — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.lens_param

-from lenstronomy.LensModel.single_plane import SinglePlane
-import numpy as np
-
-__all__ = ['LensParam']
-
-
-
[docs]class LensParam(object): - """ - class to handle the lens model parameter - """ - def __init__(self, lens_model_list, kwargs_fixed, kwargs_lower=None, kwargs_upper=None, kwargs_logsampling=None, - num_images=0, solver_type='NONE', num_shapelet_lens=0): - """ - - :param lens_model_list: list of strings of lens model names - :param kwargs_fixed: list of keyword arguments for model parameters to be held fixed - :param kwargs_lower: list of keyword arguments of the lower bounds of the model parameters - :param kwargs_upper: list of keyword arguments of the upper bounds of the model parameters - :param kwargs_logsampling: list of keyword arguments of parameters to be sampled in log10 space - :param num_images: number of images to be constrained by a non-linear solver - (only relevant when shapelet potential functions are used) - :param solver_type: string, type of non-linear solver - (only relevant in this class when 'SHAPELETS' is the solver type) - :param num_shapelet_lens: integer, number of shapelets in the lensing potential - (only relevant when 'SHAPELET' lens model is used) - """ - self.model_list = lens_model_list - self.kwargs_fixed = kwargs_fixed - self._num_images = num_images - self._solver_type = solver_type - self._num_shapelet_lens = num_shapelet_lens - lens_model = SinglePlane(lens_model_list=lens_model_list) - name_list = [] - for func in lens_model.func_list: - name_list.append(func.param_names) - self._param_name_list = name_list - if kwargs_lower is None: - kwargs_lower = [] - for func in lens_model.func_list: - kwargs_lower.append(func.lower_limit_default) - if kwargs_upper is None: - kwargs_upper = [] - for func in lens_model.func_list: - kwargs_upper.append(func.upper_limit_default) - - self.lower_limit = kwargs_lower - self.upper_limit = kwargs_upper - if kwargs_logsampling is None: - kwargs_logsampling = [[] for i in range(len(self.model_list))] - self.kwargs_logsampling = kwargs_logsampling - -
[docs] def get_params(self, args, i): - """ - - :param args: tuple of individual floats of sampling argument - :param i: integer, index at the beginning of the tuple for read out to keyword argument convention - :return: kwargs_list, index at the end of read out of this model component - """ - kwargs_list = [] - for k, model in enumerate(self.model_list): - kwargs = {} - kwargs_fixed = self.kwargs_fixed[k] - kwargs_logsampling = self.kwargs_logsampling[k] - param_names = self._param_name_list[k] - for name in param_names: - if name not in kwargs_fixed: - if model in ['SHAPELETS_POLAR', 'SHAPELETS_CART'] and name == 'coeffs': - num_coeffs = self._num_shapelet_lens - if self._solver_type == 'SHAPELETS' and k == 0: - if self._num_images == 4: - num_coeffs -= 6 - coeffs = args[i:i + num_coeffs] - coeffs = [0, 0, 0, 0, 0, 0] + list(coeffs[0:]) - elif self._num_images == 2: - num_coeffs -= 3 - coeffs = args[i:i + num_coeffs] - coeffs = [0, 0, 0] + list(coeffs[0:]) - else: - raise ValueError("Option for solver_type not valid!") - kwargs['coeffs'] = coeffs - else: - kwargs['coeffs'] = args[i:i + num_coeffs] - i += num_coeffs - elif model in ['MULTI_GAUSSIAN_KAPPA', 'MULTI_GAUSSIAN_KAPPA_ELLIPSE'] and name == 'amp': - if 'sigma' in kwargs_fixed: - num_param = len(kwargs_fixed['sigma']) - else: - num_param = len(kwargs['sigma']) - kwargs['amp'] = args[i:i + num_param] - i += num_param - elif model in ['MULTI_GAUSSIAN_KAPPA', 'MULTI_GAUSSIAN_KAPPA_ELLIPSE'] and name == 'sigma': - raise ValueError("%s must have fixed 'sigma' list!" % model) - elif model in ['INTERPOL', 'INTERPOL_SCALED'] and name in ['f_', 'f_xx', 'f_xy', 'f_yy']: - pass - else: - kwargs[name] = args[i] - i += 1 - else: - kwargs[name] = kwargs_fixed[name] - - if name in kwargs_logsampling and name not in kwargs_fixed: - kwargs[name] = 10**(kwargs[name]) - - kwargs_list.append(kwargs) - return kwargs_list, i
- -
[docs] def set_params(self, kwargs_list): - """ - - :param kwargs_list: keyword argument list of lens model components - :return: tuple of arguments (floats) that are being sampled - """ - args = [] - for k, model in enumerate(self.model_list): - kwargs = kwargs_list[k] - kwargs_fixed = self.kwargs_fixed[k] - kwargs_logsampling = self.kwargs_logsampling[k] - - param_names = self._param_name_list[k] - for name in param_names: - if name not in kwargs_fixed: - if model in ['SHAPELETS_POLAR', 'SHAPELETS_CART'] and name == 'coeffs': - coeffs = kwargs['coeffs'] - if self._solver_type == 'SHAPELETS' and k == 0: - if self._num_images == 4: - coeffs = coeffs[6:] - elif self._num_images == 2: - coeffs = coeffs[3:] - args += list(coeffs) - elif model in ['MULTI_GAUSSIAN_KAPPA', 'MULTI_GAUSSIAN_KAPPA_ELLIPSE'] and name == 'amp': - amp = kwargs['amp'] - args += list(amp) - elif model in ['MULTI_GAUSSIAN_KAPPA', 'MULTI_GAUSSIAN_KAPPA_ELLIPSE'] and name == 'sigma': - raise ValueError("%s must have fixed 'sigma' list!" % model) - elif model in ['INTERPOL', 'INTERPOL_SCALED'] and name in ['f_', 'f_xx', 'f_xy', 'f_yy']: - pass - # elif self._solver_type == 'PROFILE_SHEAR' and k == 1: - # if name == 'e1': - # _, gamma_ext = param_util.ellipticity2phi_gamma(kwargs['e1'], kwargs['e2']) - # args.append(gamma_ext) - # else: - # pass - else: - if name in kwargs_logsampling: - args.append(np.log10(kwargs[name])) - else: - args.append(kwargs[name]) - return args
- -
[docs] def num_param(self): - """ - - :return: integer, number of free parameters being sampled from the lens model components - """ - num = 0 - list = [] - type = 'lens' - for k, model in enumerate(self.model_list): - kwargs_fixed = self.kwargs_fixed[k] - param_names = self._param_name_list[k] - for name in param_names: - if name not in kwargs_fixed: - if model in ['SHAPELETS_POLAR', 'SHAPELETS_CART'] and name == 'coeffs': - num_coeffs = self._num_shapelet_lens - if self._solver_type == 'SHAPELETS' and k == 0: - if self._num_images == 4: - num_coeffs -= 6 - elif self._num_images == 2: - num_coeffs -= 3 - num += num_coeffs - list += [str(name + '_' + type + str(k))] * num_coeffs - elif model in ['MULTI_GAUSSIAN_KAPPA', 'MULTI_GAUSSIAN_KAPPA_ELLIPSE'] and name == 'amp': - num_param = len(kwargs_fixed['sigma']) - num += num_param - for i in range(num_param): - list.append(str(name + '_' + type + str(k))) - elif model in ['MULTI_GAUSSIAN_KAPPA', 'MULTI_GAUSSIAN_KAPPA_ELLIPSE'] and name == 'sigma': - raise ValueError("'sigma' must be a fixed keyword argument for MULTI_GAUSSIAN") - elif model in ['INTERPOL', 'INTERPOL_SCALED'] and name in ['f_', 'f_xx', 'f_xy', 'f_yy']: - pass - else: - num += 1 - list.append(str(name + '_' + type + str(k))) - return num, list
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/profile_integrals.html b/docs/_build/html/_modules/lenstronomy/LensModel/profile_integrals.html deleted file mode 100644 index b9f8e33fc..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/profile_integrals.html +++ /dev/null @@ -1,156 +0,0 @@ - - - - - - - - lenstronomy.LensModel.profile_integrals — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.profile_integrals

-import copy
-import scipy.integrate as integrate
-import numpy as np
-
-__all__ = ['ProfileIntegrals']
-
-
-
[docs]class ProfileIntegrals(object): - """ - class to perform integrals of spherical profiles to compute: - - projected densities - - enclosed densities - - projected enclosed densities - """ - def __init__(self, profile_class): - """ - - :param profile_class: list of lens models - """ - self._profile = profile_class - -
[docs] def mass_enclosed_3d(self, r, kwargs_profile, lens_param=False): - """ - computes the mass enclosed within a sphere of radius r - - :param r: radius (arcsec) - :param kwargs_profile: keyword argument list with lens model parameters - :param lens_param: boolean, if True uses the lens model parameterization in computing the 3d density convention - and the return is the convergence - :return: 3d mass enclosed of r - """ - kwargs = copy.deepcopy(kwargs_profile) - kwargs.pop('center_x', None) - kwargs.pop('center_y', None) - # integral of self._profile.density(x)* 4*np.pi * x^2 *dx, 0,r - if lens_param is True: - out = integrate.quad(lambda x: self._profile.density_lens(x, **kwargs) * 4 * np.pi * x ** 2, 0, r) - else: - out = integrate.quad(lambda x: self._profile.density(x, **kwargs)*4*np.pi*x**2, 0, r) - return out[0]
- -
[docs] def density_2d(self, r, kwargs_profile, lens_param=False): - """ - computes the projected density along the line-of-sight - - :param r: radius (arcsec) - :param kwargs_profile: keyword argument list with lens model parameters - :param lens_param: boolean, if True uses the lens model parameterization in computing the 3d density convention - and the return is the convergence - :return: 2d projected density at projected radius r - """ - kwargs = copy.deepcopy(kwargs_profile) - kwargs.pop('center_x', None) - kwargs.pop('center_y', None) - # integral of self._profile.density(np.sqrt(x^2+r^2))* dx, 0, infty - if lens_param is True: - out = integrate.quad(lambda x: 2 * self._profile.density_lens(np.sqrt(x ** 2 + r ** 2), **kwargs), 0, 100) - else: - out = integrate.quad(lambda x: 2*self._profile.density(np.sqrt(x**2+r**2), **kwargs), 0, 100) - return out[0]
- -
[docs] def mass_enclosed_2d(self, r, kwargs_profile): - """ - computes the mass enclosed the projected line-of-sight - :param r: radius (arcsec) - :param kwargs_profile: keyword argument list with lens model parameters - :return: projected mass enclosed radius r - """ - kwargs = copy.deepcopy(kwargs_profile) - kwargs.pop('center_x', None) - kwargs.pop('center_y', None) - # integral of self.density_2d(x)* 2*np.pi * x *dx, 0, r - out = integrate.quad(lambda x: self.density_2d(x, kwargs)*2*np.pi*x, 0, r) - return out[0]
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/profile_list_base.html b/docs/_build/html/_modules/lenstronomy/LensModel/profile_list_base.html deleted file mode 100644 index 260b30dfa..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/profile_list_base.html +++ /dev/null @@ -1,424 +0,0 @@ - - - - - - - - lenstronomy.LensModel.profile_list_base — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.profile_list_base

-from lenstronomy.Util.util import convert_bool_list
-
-__all__ = ['ProfileListBase']
-
-
-_SUPPORTED_MODELS = ['SHIFT', 'NIE_POTENTIAL', 'CONST_MAG', 'SHEAR', 'SHEAR_GAMMA_PSI', 'SHEAR_REDUCED', 'CONVERGENCE', 'FLEXION',
-                     'FLEXIONFG', 'POINT_MASS', 'SIS', 'SIS_TRUNCATED', 'SIE', 'SPP', 'NIE', 'NIE_SIMPLE', 'CHAMELEON',
-                     'DOUBLE_CHAMELEON', 'TRIPLE_CHAMELEON', 'SPEP', 'PEMD', 'SPEMD', 'EPL', 'EPL_NUMBA', 'SPL_CORE',
-                     'NFW', 'NFW_ELLIPSE', 'NFW_ELLIPSE_GAUSS_DEC', 'NFW_ELLIPSE_CSE', 'TNFW', 'TNFW_ELLIPSE',
-                     'CNFW', 'CNFW_ELLIPSE', 'CTNFW_GAUSS_DEC', 'NFW_MC', 'SERSIC',
-                     'SERSIC_ELLIPSE_POTENTIAL', 'SERSIC_ELLIPSE_KAPPA', 'SERSIC_ELLIPSE_GAUSS_DEC', 'PJAFFE',
-                     'PJAFFE_ELLIPSE', 'HERNQUIST', 'HERNQUIST_ELLIPSE', 'HERNQUIST_ELLIPSE_CSE', 'GAUSSIAN', 'GAUSSIAN_KAPPA',
-                     'GAUSSIAN_ELLIPSE_KAPPA', 'GAUSSIAN_ELLIPSE_POTENTIAL', 'MULTI_GAUSSIAN_KAPPA',
-                     'MULTI_GAUSSIAN_KAPPA_ELLIPSE', 'INTERPOL', 'INTERPOL_SCALED', 'SHAPELETS_POLAR', 'SHAPELETS_CART',
-                     'DIPOLE', 'CURVED_ARC_CONST', 'CURVED_ARC_SPP', 'CURVED_ARC_SIS_MST', 'CURVED_ARC_SPT',
-                     'CURVED_ARC_TAN_DIFF', 'ARC_PERT', 'coreBURKERT',
-                     'CORED_DENSITY', 'CORED_DENSITY_2', 'CORED_DENSITY_MST', 'CORED_DENSITY_2_MST', 'CORED_DENSITY_EXP',
-                     'CORED_DENSITY_EXP_MST', 'NumericalAlpha', 'MULTIPOLE', 'HESSIAN', 'ElliSLICE', 'ULDM',
-                     'CORED_DENSITY_ULDM_MST', 'CSE']
-
-
-
[docs]class ProfileListBase(object): - """ - class that manages the list of lens model class instances. This class is applicable for single plane and multi - plane lensing - """ - def __init__(self, lens_model_list, numerical_alpha_class=None, lens_redshift_list=None, z_source_convention=None, - kwargs_interp=None): - """ - - :param lens_model_list: list of strings with lens model names - :param numerical_alpha_class: an instance of a custom class for use in NumericalAlpha() lens model - deflection angles as a lens model. See the documentation in Profiles.numerical_deflections - :param kwargs_interp: interpolation keyword arguments specifying the numerics. - See description in the Interpolate() class. Only applicable for 'INTERPOL' and 'INTERPOL_SCALED' models. - """ - self.func_list = self._load_model_instances(lens_model_list, custom_class=numerical_alpha_class, - lens_redshift_list=lens_redshift_list, - z_source_convention=z_source_convention, - kwargs_interp=kwargs_interp) - self._num_func = len(self.func_list) - self._model_list = lens_model_list - - def _load_model_instances(self, lens_model_list, custom_class=None, lens_redshift_list=None, - z_source_convention=None, kwargs_interp=None): - if lens_redshift_list is None: - lens_redshift_list = [None] * len(lens_model_list) - if kwargs_interp is None: - kwargs_interp = {} - func_list = [] - imported_classes = {} - for i, lens_type in enumerate(lens_model_list): - # those models require a new instance per profile as certain pre-computations are relevant per individual profile - if lens_type in ['NFW_MC', 'CHAMELEON', 'DOUBLE_CHAMELEON', 'TRIPLE_CHAMELEON', 'NFW_ELLIPSE_GAUSS_DEC', - 'CTNFW_GAUSS_DEC', 'INTERPOL', 'INTERPOL_SCALED', 'NIE', 'NIE_SIMPLE']: - lensmodel_class = self._import_class(lens_type, custom_class, z_lens=lens_redshift_list[i], - z_source=z_source_convention, kwargs_interp=kwargs_interp) - else: - if lens_type not in imported_classes.keys(): - lensmodel_class = self._import_class(lens_type, custom_class, kwargs_interp=kwargs_interp) - imported_classes.update({lens_type: lensmodel_class}) - else: - lensmodel_class = imported_classes[lens_type] - func_list.append(lensmodel_class) - return func_list - - @staticmethod - def _import_class(lens_type, custom_class, kwargs_interp, z_lens=None, z_source=None): - """ - - :param lens_type: string, lens model type - :param custom_class: custom class - :param z_lens: lens redshift # currently only used in NFW_MC model as this is redshift dependent - :param z_source: source redshift # currently only used in NFW_MC model as this is redshift dependent - :param kwargs_interp: interpolation keyword arguments specifying the numerics. - See description in the Interpolate() class. Only applicable for 'INTERPOL' and 'INTERPOL_SCALED' models. - :return: class instance of the lens model type - """ - - if lens_type == 'SHIFT': - from lenstronomy.LensModel.Profiles.constant_shift import Shift - return Shift() - elif lens_type == 'NIE_POTENTIAL': - from lenstronomy.LensModel.Profiles.nie_potential import NIE_POTENTIAL - return NIE_POTENTIAL() - elif lens_type == 'CONST_MAG': - from lenstronomy.LensModel.Profiles.const_mag import ConstMag - return ConstMag() - elif lens_type == 'SHEAR': - from lenstronomy.LensModel.Profiles.shear import Shear - return Shear() - elif lens_type == 'SHEAR_GAMMA_PSI': - from lenstronomy.LensModel.Profiles.shear import ShearGammaPsi - return ShearGammaPsi() - elif lens_type == 'SHEAR_REDUCED': - from lenstronomy.LensModel.Profiles.shear import ShearReduced - return ShearReduced() - elif lens_type == 'CONVERGENCE': - from lenstronomy.LensModel.Profiles.convergence import Convergence - return Convergence() - elif lens_type == 'HESSIAN': - from lenstronomy.LensModel.Profiles.hessian import Hessian - return Hessian() - elif lens_type == 'FLEXION': - from lenstronomy.LensModel.Profiles.flexion import Flexion - return Flexion() - elif lens_type == 'FLEXIONFG': - from lenstronomy.LensModel.Profiles.flexionfg import Flexionfg - return Flexionfg() - elif lens_type == 'POINT_MASS': - from lenstronomy.LensModel.Profiles.point_mass import PointMass - return PointMass() - elif lens_type == 'SIS': - from lenstronomy.LensModel.Profiles.sis import SIS - return SIS() - elif lens_type == 'SIS_TRUNCATED': - from lenstronomy.LensModel.Profiles.sis_truncate import SIS_truncate - return SIS_truncate() - elif lens_type == 'SIE': - from lenstronomy.LensModel.Profiles.sie import SIE - return SIE() - elif lens_type == 'SPP': - from lenstronomy.LensModel.Profiles.spp import SPP - return SPP() - elif lens_type == 'NIE': - from lenstronomy.LensModel.Profiles.nie import NIE - return NIE() - elif lens_type == 'NIE_SIMPLE': - from lenstronomy.LensModel.Profiles.nie import NIEMajorAxis - return NIEMajorAxis() - elif lens_type == 'CHAMELEON': - from lenstronomy.LensModel.Profiles.chameleon import Chameleon - return Chameleon() - elif lens_type == 'DOUBLE_CHAMELEON': - from lenstronomy.LensModel.Profiles.chameleon import DoubleChameleon - return DoubleChameleon() - elif lens_type == 'TRIPLE_CHAMELEON': - from lenstronomy.LensModel.Profiles.chameleon import TripleChameleon - return TripleChameleon() - elif lens_type == 'SPEP': - from lenstronomy.LensModel.Profiles.spep import SPEP - return SPEP() - elif lens_type == 'PEMD': - from lenstronomy.LensModel.Profiles.pemd import PEMD - return PEMD() - elif lens_type == 'SPEMD': - from lenstronomy.LensModel.Profiles.spemd import SPEMD - return SPEMD() - elif lens_type == 'EPL': - from lenstronomy.LensModel.Profiles.epl import EPL - return EPL() - elif lens_type == 'EPL_NUMBA': - from lenstronomy.LensModel.Profiles.epl_numba import EPL_numba - return EPL_numba() - elif lens_type == 'SPL_CORE': - from lenstronomy.LensModel.Profiles.splcore import SPLCORE - return SPLCORE() - elif lens_type == 'NFW': - from lenstronomy.LensModel.Profiles.nfw import NFW - return NFW() - elif lens_type == 'NFW_ELLIPSE': - from lenstronomy.LensModel.Profiles.nfw_ellipse import NFW_ELLIPSE - return NFW_ELLIPSE() - elif lens_type == 'NFW_ELLIPSE_GAUSS_DEC': - from lenstronomy.LensModel.Profiles.gauss_decomposition import NFWEllipseGaussDec - return NFWEllipseGaussDec() - elif lens_type == 'NFW_ELLIPSE_CSE': - from lenstronomy.LensModel.Profiles.nfw_ellipse_cse import NFW_ELLIPSE_CSE - return NFW_ELLIPSE_CSE() - elif lens_type == 'TNFW': - from lenstronomy.LensModel.Profiles.tnfw import TNFW - return TNFW() - elif lens_type == 'TNFW_ELLIPSE': - from lenstronomy.LensModel.Profiles.tnfw_ellipse import TNFW_ELLIPSE - return TNFW_ELLIPSE() - elif lens_type == 'CNFW': - from lenstronomy.LensModel.Profiles.cnfw import CNFW - return CNFW() - elif lens_type == 'CNFW_ELLIPSE': - from lenstronomy.LensModel.Profiles.cnfw_ellipse import CNFW_ELLIPSE - return CNFW_ELLIPSE() - elif lens_type == 'CTNFW_GAUSS_DEC': - from lenstronomy.LensModel.Profiles.gauss_decomposition import CTNFWGaussDec - return CTNFWGaussDec() - elif lens_type == 'NFW_MC': - from lenstronomy.LensModel.Profiles.nfw_mass_concentration import NFWMC - return NFWMC(z_lens=z_lens, z_source=z_source) - elif lens_type == 'SERSIC': - from lenstronomy.LensModel.Profiles.sersic import Sersic - return Sersic() - elif lens_type == 'SERSIC_ELLIPSE_POTENTIAL': - from lenstronomy.LensModel.Profiles.sersic_ellipse_potential import SersicEllipse - return SersicEllipse() - elif lens_type == 'SERSIC_ELLIPSE_KAPPA': - from lenstronomy.LensModel.Profiles.sersic_ellipse_kappa import SersicEllipseKappa - return SersicEllipseKappa() - elif lens_type == 'SERSIC_ELLIPSE_GAUSS_DEC': - from lenstronomy.LensModel.Profiles.gauss_decomposition import SersicEllipseGaussDec - return SersicEllipseGaussDec() - elif lens_type == 'PJAFFE': - from lenstronomy.LensModel.Profiles.p_jaffe import PJaffe - return PJaffe() - elif lens_type == 'PJAFFE_ELLIPSE': - from lenstronomy.LensModel.Profiles.p_jaffe_ellipse import PJaffe_Ellipse - return PJaffe_Ellipse() - elif lens_type == 'HERNQUIST': - from lenstronomy.LensModel.Profiles.hernquist import Hernquist - return Hernquist() - elif lens_type == 'HERNQUIST_ELLIPSE': - from lenstronomy.LensModel.Profiles.hernquist_ellipse import Hernquist_Ellipse - return Hernquist_Ellipse() - elif lens_type =='HERNQUIST_ELLIPSE_CSE': - from lenstronomy.LensModel.Profiles.hernquist_ellipse_cse import HernquistEllipseCSE - return HernquistEllipseCSE() - elif lens_type == 'GAUSSIAN': - from lenstronomy.LensModel.Profiles.gaussian_potential import Gaussian - return Gaussian() - elif lens_type == 'GAUSSIAN_KAPPA': - from lenstronomy.LensModel.Profiles.gaussian_kappa import GaussianKappa - return GaussianKappa() - elif lens_type == 'GAUSSIAN_ELLIPSE_KAPPA': - from lenstronomy.LensModel.Profiles.gaussian_ellipse_kappa import GaussianEllipseKappa - return GaussianEllipseKappa() - elif lens_type == 'GAUSSIAN_ELLIPSE_POTENTIAL': - from lenstronomy.LensModel.Profiles.gaussian_ellipse_potential import GaussianEllipsePotential - return GaussianEllipsePotential() - elif lens_type == 'MULTI_GAUSSIAN_KAPPA': - from lenstronomy.LensModel.Profiles.multi_gaussian_kappa import MultiGaussianKappa - return MultiGaussianKappa() - elif lens_type == 'MULTI_GAUSSIAN_KAPPA_ELLIPSE': - from lenstronomy.LensModel.Profiles.multi_gaussian_kappa import MultiGaussianKappaEllipse - return MultiGaussianKappaEllipse() - elif lens_type == 'INTERPOL': - from lenstronomy.LensModel.Profiles.interpol import Interpol - return Interpol(**kwargs_interp) - elif lens_type == 'INTERPOL_SCALED': - from lenstronomy.LensModel.Profiles.interpol import InterpolScaled - return InterpolScaled(**kwargs_interp) - elif lens_type == 'SHAPELETS_POLAR': - from lenstronomy.LensModel.Profiles.shapelet_pot_polar import PolarShapelets - return PolarShapelets() - elif lens_type == 'SHAPELETS_CART': - from lenstronomy.LensModel.Profiles.shapelet_pot_cartesian import CartShapelets - return CartShapelets() - elif lens_type == 'DIPOLE': - from lenstronomy.LensModel.Profiles.dipole import Dipole - return Dipole() - elif lens_type == 'CURVED_ARC_CONST': - from lenstronomy.LensModel.Profiles.curved_arc_const import CurvedArcConst - return CurvedArcConst() - elif lens_type == 'CURVED_ARC_CONST_MST': - from lenstronomy.LensModel.Profiles.curved_arc_const import CurvedArcConstMST - return CurvedArcConstMST() - elif lens_type == 'CURVED_ARC_SPP': - from lenstronomy.LensModel.Profiles.curved_arc_spp import CurvedArcSPP - return CurvedArcSPP() - elif lens_type == 'CURVED_ARC_SIS_MST': - from lenstronomy.LensModel.Profiles.curved_arc_sis_mst import CurvedArcSISMST - return CurvedArcSISMST() - elif lens_type == 'CURVED_ARC_SPT': - from lenstronomy.LensModel.Profiles.curved_arc_spt import CurvedArcSPT - return CurvedArcSPT() - elif lens_type == 'CURVED_ARC_TAN_DIFF': - from lenstronomy.LensModel.Profiles.curved_arc_tan_diff import CurvedArcTanDiff - return CurvedArcTanDiff() - elif lens_type == 'ARC_PERT': - from lenstronomy.LensModel.Profiles.arc_perturbations import ArcPerturbations - return ArcPerturbations() - elif lens_type == 'coreBURKERT': - from lenstronomy.LensModel.Profiles.coreBurkert import CoreBurkert - return CoreBurkert() - elif lens_type == 'CORED_DENSITY': - from lenstronomy.LensModel.Profiles.cored_density import CoredDensity - return CoredDensity() - elif lens_type == 'CORED_DENSITY_2': - from lenstronomy.LensModel.Profiles.cored_density_2 import CoredDensity2 - return CoredDensity2() - elif lens_type == 'CORED_DENSITY_EXP': - from lenstronomy.LensModel.Profiles.cored_density_exp import CoredDensityExp - return CoredDensityExp() - elif lens_type == 'CORED_DENSITY_MST': - from lenstronomy.LensModel.Profiles.cored_density_mst import CoredDensityMST - return CoredDensityMST(profile_type='CORED_DENSITY') - elif lens_type == 'CORED_DENSITY_2_MST': - from lenstronomy.LensModel.Profiles.cored_density_mst import CoredDensityMST - return CoredDensityMST(profile_type='CORED_DENSITY_2') - elif lens_type == 'CORED_DENSITY_EXP_MST': - from lenstronomy.LensModel.Profiles.cored_density_mst import CoredDensityMST - return CoredDensityMST(profile_type='CORED_DENSITY_EXP') - elif lens_type == 'NumericalAlpha': - from lenstronomy.LensModel.Profiles.numerical_deflections import NumericalAlpha - return NumericalAlpha(custom_class) - elif lens_type == 'MULTIPOLE': - from lenstronomy.LensModel.Profiles.multipole import Multipole - return Multipole() - elif lens_type == 'CSE': - from lenstronomy.LensModel.Profiles.cored_steep_ellipsoid import CSE - return CSE() - elif lens_type == 'ElliSLICE': - from lenstronomy.LensModel.Profiles.elliptical_density_slice import ElliSLICE - return ElliSLICE() - elif lens_type == 'ULDM': - from lenstronomy.LensModel.Profiles.uldm import Uldm - return Uldm() - elif lens_type == 'CORED_DENSITY_ULDM_MST': - from lenstronomy.LensModel.Profiles.cored_density_mst import CoredDensityMST - return CoredDensityMST(profile_type='CORED_DENSITY_ULDM') - else: - raise ValueError('%s is not a valid lens model. Supported are: %s.' % (lens_type, _SUPPORTED_MODELS)) - - def _bool_list(self, k=None): - """ - returns a bool list of the length of the lens models - if k = None: returns bool list with True's - if k is int, returns bool list with False's but k'th is True - if k is a list of int, e.g. [0, 3, 5], returns a bool list with True's in the integers listed and False elsewhere - if k is a boolean list, checks for size to match the numbers of models and returns it - - :param k: None, int, or list of ints - :return: bool list - """ - return convert_bool_list(n=self._num_func, k=k) - -
[docs] def set_static(self, kwargs_list): - """ - - :param kwargs_list: list of keyword arguments for each profile - :return: kwargs_list - """ - for i, func in enumerate(self.func_list): - func.set_static(**kwargs_list[i]) - return kwargs_list
- -
[docs] def set_dynamic(self): - """ - frees cache set by static model (if exists) and re-computes all lensing quantities each time a definition is - called assuming different parameters are executed. This is the default mode if not specified as set_static() - - :return: None - """ - for i, func in enumerate(self.func_list): - func.set_dynamic()
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LensModel/single_plane.html b/docs/_build/html/_modules/lenstronomy/LensModel/single_plane.html deleted file mode 100644 index 840141638..000000000 --- a/docs/_build/html/_modules/lenstronomy/LensModel/single_plane.html +++ /dev/null @@ -1,261 +0,0 @@ - - - - - - - - lenstronomy.LensModel.single_plane — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LensModel.single_plane

-__author__ = 'sibirrer'
-
-import numpy as np
-from lenstronomy.LensModel.profile_list_base import ProfileListBase
-
-__all__ = ['SinglePlane']
-
-
-
[docs]class SinglePlane(ProfileListBase): - """ - class to handle an arbitrary list of lens models in a single lensing plane - """ - -
[docs] def ray_shooting(self, x, y, kwargs, k=None): - """ - maps image to source position (inverse deflection) - :param x: x-position (preferentially arcsec) - :type x: numpy array - :param y: y-position (preferentially arcsec) - :type y: numpy array - :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes - :param k: only evaluate the k-th lens model - :return: source plane positions corresponding to (x, y) in the image plane - """ - dx, dy = self.alpha(x, y, kwargs, k=k) - return x - dx, y - dy
- -
[docs] def fermat_potential(self, x_image, y_image, kwargs_lens, x_source=None, y_source=None, k=None): - """ - fermat potential (negative sign means earlier arrival time) - - :param x_image: image position - :param y_image: image position - :param x_source: source position - :param y_source: source position - :param kwargs_lens: list of keyword arguments of lens model parameters matching the lens model classes - :param k: - :return: fermat potential in arcsec**2 without geometry term (second part of Eqn 1 in Suyu et al. 2013) as a list - """ - - potential = self.potential(x_image, y_image, kwargs_lens, k=k) - if x_source is None or y_source is None: - x_source, y_source = self.ray_shooting(x_image, y_image, kwargs_lens, k=k) - geometry = ((x_image - x_source)**2 + (y_image - y_source)**2) / 2. - return geometry - potential
- -
[docs] def potential(self, x, y, kwargs, k=None): - """ - lensing potential - :param x: x-position (preferentially arcsec) - :type x: numpy array - :param y: y-position (preferentially arcsec) - :type y: numpy array - :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes - :param k: only evaluate the k-th lens model - :return: lensing potential in units of arcsec^2 - """ - x = np.array(x, dtype=float) - y = np.array(y, dtype=float) - if isinstance(k, int): - return self.func_list[k].function(x, y, **kwargs[k]) - bool_list = self._bool_list(k) - potential = np.zeros_like(x) - for i, func in enumerate(self.func_list): - if bool_list[i] is True: - potential += func.function(x, y, **kwargs[i]) - return potential
- -
[docs] def alpha(self, x, y, kwargs, k=None): - - """ - deflection angles - :param x: x-position (preferentially arcsec) - :type x: numpy array - :param y: y-position (preferentially arcsec) - :type y: numpy array - :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes - :param k: only evaluate the k-th lens model - :return: deflection angles in units of arcsec - """ - x = np.array(x, dtype=float) - y = np.array(y, dtype=float) - if isinstance(k, int): - return self.func_list[k].derivatives(x, y, **kwargs[k]) - bool_list = self._bool_list(k) - f_x, f_y = np.zeros_like(x), np.zeros_like(x) - for i, func in enumerate(self.func_list): - if bool_list[i] is True: - f_x_i, f_y_i = func.derivatives(x, y, **kwargs[i]) - f_x += f_x_i - f_y += f_y_i - return f_x, f_y
- -
[docs] def hessian(self, x, y, kwargs, k=None): - """ - hessian matrix - :param x: x-position (preferentially arcsec) - :type x: numpy array - :param y: y-position (preferentially arcsec) - :type y: numpy array - :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes - :param k: only evaluate the k-th lens model - :return: f_xx, f_xy, f_yx, f_yy components - """ - x = np.array(x, dtype=float) - y = np.array(y, dtype=float) - if isinstance(k, int): - f_xx, f_xy, f_yx, f_yy = self.func_list[k].hessian(x, y, **kwargs[k]) - return f_xx, f_xy, f_yx, f_yy - - bool_list = self._bool_list(k) - f_xx, f_xy, f_yx, f_yy = np.zeros_like(x), np.zeros_like(x), np.zeros_like(x), np.zeros_like(x) - for i, func in enumerate(self.func_list): - if bool_list[i] is True: - f_xx_i, f_xy_i, f_yx_i, f_yy_i = func.hessian(x, y, **kwargs[i]) - f_xx += f_xx_i - f_xy += f_xy_i - f_yx += f_yx_i - f_yy += f_yy_i - return f_xx, f_xy, f_yx, f_yy
- -
[docs] def mass_3d(self, r, kwargs, bool_list=None): - """ - computes the mass within a 3d sphere of radius r - - if you want to have physical units of kg, you need to multiply by this factor: - const.arcsec ** 2 * self._cosmo.dd * self._cosmo.ds / self._cosmo.dds * const.Mpc * const.c ** 2 / (4 * np.pi * const.G) - grav_pot = -const.G * mass_dim / (r * const.arcsec * self._cosmo.dd * const.Mpc) - - :param r: radius (in angular units) - :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes - :param bool_list: list of bools that are part of the output - :return: mass (in angular units, modulo epsilon_crit) - """ - bool_list = self._bool_list(bool_list) - mass_3d = 0 - for i, func in enumerate(self.func_list): - if bool_list[i] is True: - kwargs_i = {k: v for k, v in kwargs[i].items() if k not in ['center_x', 'center_y']} - mass_3d_i = func.mass_3d_lens(r, **kwargs_i) - mass_3d += mass_3d_i - return mass_3d
- -
[docs] def mass_2d(self, r, kwargs, bool_list=None): - """ - computes the mass enclosed a projected (2d) radius r - - :param r: radius (in angular units) - :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes - :param bool_list: list of bools that are part of the output - :return: projected mass (in angular units, modulo epsilon_crit) - """ - bool_list = self._bool_list(bool_list) - mass_2d = 0 - for i, func in enumerate(self.func_list): - if bool_list[i] is True: - kwargs_i = {k: v for k, v in kwargs[i].items() if k not in ['center_x', 'center_y']} - mass_2d_i = func.mass_2d_lens(r, **kwargs_i) - mass_2d += mass_2d_i - return mass_2d
- -
[docs] def density(self, r, kwargs, bool_list=None): - """ - 3d mass density at radius r - The integral in the LOS projection of this quantity results in the convergence quantity. - - :param r: radius (in angular units) - :param kwargs: list of keyword arguments of lens model parameters matching the lens model classes - :param bool_list: list of bools that are part of the output - :return: mass density at radius r (in angular units, modulo epsilon_crit) - """ - bool_list = self._bool_list(bool_list) - density = 0 - for i, func in enumerate(self.func_list): - if bool_list[i] is True: - kwargs_i = {k: v for k, v in kwargs[i].items() if k not in ['center_x', 'center_y']} - density_i = func.density_lens(r, **kwargs_i) - density += density_i - return density
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/chameleon.html b/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/chameleon.html deleted file mode 100644 index 11770a107..000000000 --- a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/chameleon.html +++ /dev/null @@ -1,292 +0,0 @@ - - - - - - - - lenstronomy.LightModel.Profiles.chameleon — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LightModel.Profiles.chameleon

-from lenstronomy.LightModel.Profiles.nie import NIE
-from lenstronomy.LensModel.Profiles.chameleon import Chameleon as ChameleonLens
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -class Chameleon(object): - """ - class of the Chameleon model (See Dutton+ 2011, Suyu+2014) an elliptical truncated double isothermal profile - - """ - param_names = ['amp', 'w_c', 'w_t', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'w_c': 0, 'w_t': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'w_c': 100, 'w_t': 100, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.nie = NIE() - self._chameleonLens = ChameleonLens() - -
[docs] def function(self, x, y, amp, w_c, w_t, e1, e2, center_x=0, center_y=0): - """ - - :param x: ra-coordinate - :param y: dec-coordinate - :param w_c: - :param w_t: - :param amp: amplitude of first power-law flux - :param e1: eccentricity parameter - :param e2: eccentricity parameter - :param center_x: center - :param center_y: center - :return: flux of chameleon profile - """ - amp_new, w_c, w_t, s_scale_1, s_scale_2 = self._chameleonLens.param_convert(amp, w_c, w_t, e1, e2) - flux1 = self.nie.function(x, y, 1, e1, e2, s_scale_1, center_x, center_y) - flux2 = self.nie.function(x, y, 1, e1, e2, s_scale_2, center_x, center_y) - flux = amp_new * (flux1 - flux2) - return flux
- -
[docs] def light_3d(self, r, amp, w_c, w_t, e1, e2, center_x=0, center_y=0): - """ - - :param r: 3d radius - :param w_c: - :param w_t: - :param amp: amplitude of first power-law flux - :param e1: eccentricity parameter - :param e2: eccentricity parameter - :param center_x: center - :param center_y: center - :return: 3d flux of chameleon profile at radius r - """ - amp_new, w_c, w_t, s_scale_1, s_scale_2 = self._chameleonLens.param_convert(amp, w_c, w_t, e1, e2) - flux1 = self.nie.light_3d(r, 1, e1, e2, s_scale_1, center_x, center_y) - flux2 = self.nie.light_3d(r, 1, e1, e2, s_scale_2, center_x, center_y) - flux = amp_new * (flux1 - flux2) - return flux
- - -
[docs]@export -class DoubleChameleon(object): - """ - class of the double Chameleon model. See Dutton+2011, Suyu+2014 for the single Chameleon model. - - """ - param_names = ['amp', 'ratio', 'w_c1', 'w_t1', 'e11', 'e21', 'w_c2', 'w_t2', 'e12', 'e22', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'ratio': 0, 'w_c1': 0, 'w_t1': 0, 'e11': -0.8, 'e21': -0.8, - 'w_c2': 0, 'w_t2': 0, 'e12': -0.8, 'e22': -0.8, - 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'ratio': 100, 'w_c1': 100, 'w_t1': 100, 'e11': 0.8, 'e21': 0.8, - 'w_c2': 100, 'w_t2': 100, 'e12': 0.8, 'e22': 0.8, - 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.chameleon = Chameleon() - -
[docs] def function(self, x, y, amp, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0): - """ - - :param x: - :param y: - :param amp: - :param ratio: - :param w_c1: - :param w_t1: - :param e11: - :param e21: - :param w_c2: - :param w_t2: - :param e12: - :param e22: - :param center_x: - :param center_y: - :return: - """ - f_1 = self.chameleon.function(x, y, amp / (1. + 1./ratio), w_c1, w_t1, e11, e21, center_x, center_y) - f_2 = self.chameleon.function(x, y, amp / (1. + ratio), w_c2, w_t2, e12, e22, center_x, center_y) - return f_1 + f_2
- -
[docs] def light_3d(self, r, amp, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0): - """ - - :param r: 3d radius - :param amp: - :param ratio: ratio of first to second amplitude of Chameleon surface brightness - :param w_c1: - :param w_t1: - :param e11: - :param e21: - :param w_c2: - :param w_t2: - :param e12: - :param e22: - :param center_x: - :param center_y: - :return: 3d light density at radius r - """ - f_1 = self.chameleon.light_3d(r, amp / (1. + 1./ratio), w_c1, w_t1, e11, e21, center_x, center_y) - f_2 = self.chameleon.light_3d(r, amp / (1. + ratio), w_c2, w_t2, e12, e22, center_x, center_y) - return f_1 + f_2
- - -
[docs]@export -class TripleChameleon(object): - """ - class of the Chameleon model (See Suyu+2014) an elliptical truncated double isothermal profile - - """ - param_names = ['amp', 'ratio12', 'ratio13', 'w_c1', 'w_t1', 'e11', 'e21', - 'w_c2', 'w_t2', 'e12', 'e22', 'w_c3', 'w_t3', 'e13', - 'e23', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'ratio12': 0, 'ratio13': 0., - 'w_c1': 0, 'w_t1': 0, 'e11': -0.8, 'e21': -0.8, - 'w_c2': 0, 'w_t2': 0, 'e12': -0.8, 'e22': -0.8, - 'w_c3': 0, 'w_t3': 0, 'e13': -0.8, 'e23': -0.8, - 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'ratio12': 100, 'ratio13': 100, - 'w_c1': 100, 'w_t1': 100, 'e11': 0.8, 'e21': 0.8, - 'w_c2': 100, 'w_t2': 100, 'e12': 0.8, 'e22': 0.8, - 'w_c3': 100, 'w_t3': 100, 'e13': 0.8, 'e23': 0.8, - 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.chameleon = Chameleon() - -
[docs] def function(self, x, y, amp, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, - center_x=0, center_y=0): - """ - - :param x: - :param y: - :param amp: - :param ratio12: ratio of first to second amplitude - :param ratio13: ratio of first to third amplitude - :param w_c1: - :param w_t1: - :param e11: - :param e21: - :param w_c2: - :param w_t2: - :param e12: - :param e22: - :param w_c3: - :param w_t3: - :param e13: - :param e23: - :param center_x: - :param center_y: - :return: - """ - amp1 = amp / (1. + 1./ratio12 + 1./ratio13) - amp2 = amp1 / ratio12 - amp3 = amp1 / ratio13 - f_1 = self.chameleon.function(x, y, amp1, w_c1, w_t1, e11, e21, center_x, center_y) - f_2 = self.chameleon.function(x, y, amp2, w_c2, w_t2, e12, e22, center_x, center_y) - f_3 = self.chameleon.function(x, y, amp3, w_c3, w_t3, e13, e23, center_x, center_y) - return f_1 + f_2 + f_3
- -
[docs] def light_3d(self, r, amp, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, - center_x=0, center_y=0): - """ - - :param r: 3d light radius - :param amp: - :param ratio12: ratio of first to second amplitude - :param ratio13: ratio of first to third amplitude - :param w_c1: - :param w_t1: - :param e11: - :param e21: - :param w_c2: - :param w_t2: - :param e12: - :param e22: - :param w_c3: - :param w_t3: - :param e13: - :param e23: - :param center_x: - :param center_y: - :return: - """ - amp1 = amp / (1. + 1./ratio12 + 1./ratio13) - amp2 = amp1 / ratio12 - amp3 = amp1 / ratio13 - f_1 = self.chameleon.light_3d(r, amp1, w_c1, w_t1, e11, e21, center_x, center_y) - f_2 = self.chameleon.light_3d(r, amp2, w_c2, w_t2, e12, e22, center_x, center_y) - f_3 = self.chameleon.light_3d(r, amp3, w_c3, w_t3, e13, e23, center_x, center_y) - return f_1 + f_2 + f_3
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/ellipsoid.html b/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/ellipsoid.html deleted file mode 100644 index 35dd1b873..000000000 --- a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/ellipsoid.html +++ /dev/null @@ -1,132 +0,0 @@ - - - - - - - - lenstronomy.LightModel.Profiles.ellipsoid — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LightModel.Profiles.ellipsoid

-__author__ = 'sibirrer'
-
-# this file contains a class to make an Ellipsoid
-import numpy as np
-from lenstronomy.Util import param_util
-
-__all__ = ['Ellipsoid']
-
-
-
[docs]class Ellipsoid(object): - """ - class for an universal surface brightness within an ellipsoid - """ - def __init__(self): - self.param_names = ['amp', 'radius', 'e1', 'e2', 'center_x', 'center_y'] - self.lower_limit_default = {'amp': 0, 'radius': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - self.upper_limit_default = {'amp': 1000, 'radius': 100, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100} - -
[docs] def function(self, x, y, amp, radius, e1, e2, center_x, center_y): - """ - - :param x: - :param y: - :param amp: surface brightness within the ellipsoid - :param radius: radius (product average of semi-major and semi-minor axis) of the ellipsoid - :param e1: eccentricity - :param e2: eccentricity - :param center_x: center - :param center_y: center - :return: surface brightness - """ - x_, y_ = param_util.transform_e1e2_product_average(x, y, e1, e2, center_x, center_y) - r2 = x_**2 + y_**2 - flux = np.zeros_like(x) - flux[r2 <= radius**2] = 1 - area = np.pi * radius ** 2 - return amp / area * flux
- - -def function(x, y, amp, sigma, center_x, center_y): - """ - returns torus (ellipse with constant surface brightness) profile - """ - x_shift = x - center_x - y_shift = y - center_y - area = np.pi * sigma**2 - dist = (x_shift / sigma) ** 2 + (y_shift / sigma) ** 2 - torus = np.zeros_like(x) - torus[dist <= 1] = 1 - return amp/area * torus -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/gaussian.html b/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/gaussian.html deleted file mode 100644 index 5c4039579..000000000 --- a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/gaussian.html +++ /dev/null @@ -1,367 +0,0 @@ - - - - - - - - lenstronomy.LightModel.Profiles.gaussian — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LightModel.Profiles.gaussian

-import numpy as np
-import lenstronomy.Util.param_util as param_util
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -class Gaussian(object): - """ - class for Gaussian light profile - The two-dimensional Gaussian profile amplitude is defined such that the 2D integral leads to the 'amp' value. - - profile name in LightModel module: 'GAUSSIAN' - """ - def __init__(self): - self.param_names = ['amp', 'sigma', 'center_x', 'center_y'] - self.lower_limit_default = {'amp': 0, 'sigma': 0, 'center_x': -100, 'center_y': -100} - self.upper_limit_default = {'amp': 1000, 'sigma': 100, 'center_x': 100, 'center_y': 100} - -
[docs] def function(self, x, y, amp, sigma, center_x=0, center_y=0): - """ - surface brightness per angular unit - - :param x: coordinate on the sky - :param y: coordinate on the sky - :param amp: amplitude, such that 2D integral leads to this value - :param sigma: sigma of Gaussian in each direction - :param center_x: center of profile - :param center_y: center of profile - :return: surface brightness at (x, y) - """ - c = amp / (2 * np.pi * sigma**2) - r2 = (x - center_x) ** 2 / sigma**2 + (y - center_y) ** 2 / sigma**2 - return c * np.exp(-r2 / 2.)
- -
[docs] def total_flux(self, amp, sigma, center_x=0, center_y=0): - """ - integrated flux of the profile - - :param amp: amplitude, such that 2D integral leads to this value - :param sigma: sigma of Gaussian in each direction - :param center_x: center of profile - :param center_y: center of profile - :return: total flux - """ - return amp
- -
[docs] def light_3d(self, r, amp, sigma): - """ - 3D brightness per angular volume element - - :param r: 3d distance from center of profile - :param amp: amplitude, such that 2D integral leads to this value - :param sigma: sigma of Gaussian in each direction - :return: 3D brightness per angular volume element - """ - amp3d = amp / np.sqrt(2 * sigma**2) / np.sqrt(np.pi) - sigma3d = sigma - return self.function(r, 0, amp3d, sigma3d)
- - -
[docs]@export -class GaussianEllipse(object): - """ - class for Gaussian light profile with ellipticity - - profile name in LightModel module: 'GAUSSIAN_ELLIPSE' - """ - param_names = ['amp', 'sigma', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'sigma': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 1000, 'sigma': 100, 'e1': -0.5, 'e2': -0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.gaussian = Gaussian() - -
[docs] def function(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0): - """ - - :param x: coordinate on the sky - :param y: coordinate on the sky - :param amp: amplitude, such that 2D integral leads to this value - :param sigma: sigma of Gaussian in each direction - :param e1: eccentricity modulus - :param e2: eccentricity modulus - :param center_x: center of profile - :param center_y: center of profile - :return: surface brightness at (x, y) - """ - x_, y_ = param_util.transform_e1e2_product_average(x, y, e1, e2, center_x, center_y) - return self.gaussian.function(x_, y_, amp, sigma, center_x=0, center_y=0)
- -
[docs] def total_flux(self, amp, sigma=None, e1=None, e2=None, center_x=None, center_y=None): - """ - total integrated flux of profile - - :param amp: amplitude, such that 2D integral leads to this value - :param sigma: sigma of Gaussian in each direction - :param e1: eccentricity modulus - :param e2: eccentricity modulus - :param center_x: center of profile - :param center_y: center of profile - :return: total flux - """ - return self.gaussian.total_flux(amp, sigma, center_x, center_y)
- -
[docs] def light_3d(self, r, amp, sigma, e1=0, e2=0): - """ - 3D brightness per angular volume element - - :param r: 3d distance from center of profile - :param amp: amplitude, such that 2D integral leads to this value - :param sigma: sigma of Gaussian in each direction - :param e1: eccentricity modulus - :param e2: eccentricity modulus - :return: 3D brightness per angular volume element - """ - return self.gaussian.light_3d(r, amp, sigma=sigma)
- - -
[docs]@export -class MultiGaussian(object): - """ - class for elliptical pseudo Jaffe lens light (2d projected light/mass distribution - - profile name in LightModel module: 'MULTI_GAUSSIAN' - """ - param_names = ['amp', 'sigma', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'sigma': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 1000, 'sigma': 100, 'e1': -0.5, 'e2': -0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.gaussian = Gaussian() - -
[docs] def function(self, x, y, amp, sigma, center_x=0, center_y=0): - """ - surface brightness per angular unit - - :param x: coordinate on the sky - :param y: coordinate on the sky - :param amp: list of amplitudes of individual Gaussian profiles - :param sigma: list of widths of individual Gaussian profiles - :param center_x: center of profile - :param center_y: center of profile - :return: surface brightness at (x, y) - """ - f_ = np.zeros_like(x) - for i in range(len(amp)): - f_ += self.gaussian.function(x, y, amp[i], sigma[i], center_x, center_y) - return f_
- -
[docs] def total_flux(self, amp, sigma, center_x=0, center_y=0): - """ - total integrated flux of profile - - :param amp: list of amplitudes of individual Gaussian profiles - :param sigma: list of widths of individual Gaussian profiles - :param center_x: center of profile - :param center_y: center of profile - :return: total flux - """ - flux = 0 - for i in range(len(amp)): - flux += self.gaussian.total_flux(amp[i], sigma[i], center_x, center_y) - return flux
- -
[docs] def function_split(self, x, y, amp, sigma, center_x=0, center_y=0): - """ - split surface brightness in individual components - - :param x: coordinate on the sky - :param y: coordinate on the sky - :param amp: list of amplitudes of individual Gaussian profiles - :param sigma: list of widths of individual Gaussian profiles - :param center_x: center of profile - :param center_y: center of profile - :return: list of arrays of surface brightness - """ - f_list = [] - for i in range(len(amp)): - f_list.append(self.gaussian.function(x, y, amp[i], sigma[i], center_x, center_y)) - return f_list
- -
[docs] def light_3d(self, r, amp, sigma): - """ - 3D brightness per angular volume element - - :param r: 3d distance from center of profile - :param amp: list of amplitudes of individual Gaussian profiles - :param sigma: list of widths of individual Gaussian profiles - :return: 3D brightness per angular volume element - """ - f_ = np.zeros_like(r) - for i in range(len(amp)): - f_ += self.gaussian.light_3d(r, amp[i], sigma[i]) - return f_
- - -
[docs]@export -class MultiGaussianEllipse(object): - """ - class for elliptical multi Gaussian profile - - profile name in LightModel module: 'MULTI_GAUSSIAN_ELLIPSE' - """ - param_names = ['amp', 'sigma', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'sigma': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 1000, 'sigma': 100, 'e1': -0.5, 'e2': -0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.gaussian = Gaussian() - -
[docs] def function(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0): - """ - surface brightness per angular unit - - :param x: coordinate on the sky - :param y: coordinate on the sky - :param amp: list of amplitudes of individual Gaussian profiles - :param sigma: list of widths of individual Gaussian profiles - :param e1: eccentricity modulus - :param e2: eccentricity modulus - :param center_x: center of profile - :param center_y: center of profile - :return: surface brightness at (x, y) - """ - x_, y_ = param_util.transform_e1e2_product_average(x, y, e1, e2, center_x, center_y) - - f_ = np.zeros_like(x) - for i in range(len(amp)): - f_ += self.gaussian.function(x_, y_, amp[i], sigma[i], center_x=0, center_y=0) - return f_
- -
[docs] def total_flux(self, amp, sigma, e1, e2, center_x=0, center_y=0): - """ - total integrated flux of profile - - :param amp: list of amplitudes of individual Gaussian profiles - :param sigma: list of widths of individual Gaussian profiles - :param e1: eccentricity modulus - :param e2: eccentricity modulus - :param center_x: center of profile - :param center_y: center of profile - :return: total flux - """ - flux = 0 - for i in range(len(amp)): - flux += self.gaussian.total_flux(amp[i], sigma[i], center_x, center_y) - return flux
- -
[docs] def function_split(self, x, y, amp, sigma, e1, e2, center_x=0, center_y=0): - """ - split surface brightness in individual components - - :param x: coordinate on the sky - :param y: coordinate on the sky - :param amp: list of amplitudes of individual Gaussian profiles - :param sigma: list of widths of individual Gaussian profiles - :param e1: eccentricity modulus - :param e2: eccentricity modulus - :param center_x: center of profile - :param center_y: center of profile - :return: list of arrays of surface brightness - """ - x_, y_ = param_util.transform_e1e2_product_average(x, y, e1, e2, center_x, center_y) - f_list = [] - for i in range(len(amp)): - f_list.append(self.gaussian.function(x_, y_, amp[i], sigma[i], center_x=0, center_y=0)) - return f_list
- -
[docs] def light_3d(self, r, amp, sigma, e1=0, e2=0): - """ - 3D brightness per angular volume element - - :param r: 3d distance from center of profile - :param amp: list of amplitudes of individual Gaussian profiles - :param sigma: list of widths of individual Gaussian profiles - :param e1: eccentricity modulus - :param e2: eccentricity modulus - :return: 3D brightness per angular volume element - """ - f_ = np.zeros_like(r) - for i in range(len(amp)): - f_ += self.gaussian.light_3d(r, amp[i], sigma[i]) - return f_
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/hernquist.html b/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/hernquist.html deleted file mode 100644 index 22d0c9567..000000000 --- a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/hernquist.html +++ /dev/null @@ -1,165 +0,0 @@ - - - - - - - - lenstronomy.LightModel.Profiles.hernquist — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LightModel.Profiles.hernquist

-import lenstronomy.Util.param_util as param_util
-
-__all__ = ['Hernquist', 'HernquistEllipse']
-
-
-
[docs]class Hernquist(object): - """ - class for pseudo Jaffe lens light (2d projected light/mass distribution - """ - def __init__(self): - from lenstronomy.LensModel.Profiles.hernquist import Hernquist as Hernquist_lens - self.lens = Hernquist_lens() - self.param_names = ['amp', 'Rs', 'center_x', 'center_y'] - self.lower_limit_default = {'amp': 0, 'Rs': 0, 'center_x': -100, 'center_y': -100} - self.upper_limit_default = {'amp': 100, 'Rs': 100, 'center_x': 100, 'center_y': 100} - -
[docs] def function(self, x, y, amp, Rs, center_x=0, center_y=0): - """ - - :param x: - :param y: - :param amp: - :param Rs: scale radius: half-light radius = Rs / 0.551 - :param center_x: - :param center_y: - :return: - """ - rho0 = self.lens.sigma2rho(amp, Rs) - return self.lens.density_2d(x, y, rho0, Rs, center_x, center_y)
- -
[docs] def light_3d(self, r, amp, Rs): - """ - - :param r: - :param amp: - :param Rs: - :return: - """ - rho0 = self.lens.sigma2rho(amp, Rs) - return self.lens.density(r, rho0, Rs)
- - -
[docs]class HernquistEllipse(object): - """ - class for elliptical pseudo Jaffe lens light (2d projected light/mass distribution - """ - param_names = ['amp', 'Rs', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'Rs': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'Rs': 100, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self): - from lenstronomy.LensModel.Profiles.hernquist import Hernquist as Hernquist_lens - self.lens = Hernquist_lens() - self.spherical = Hernquist() - -
[docs] def function(self, x, y, amp, Rs, e1, e2, center_x=0, center_y=0): - """ - - :param x: - :param y: - :param amp: - :param Rs: - :param e1: - :param e2: - :param center_x: - :param center_y: - :return: - """ - x_, y_ = param_util.transform_e1e2_square_average(x, y, e1, e2, center_x, center_y) - return self.spherical.function(x_, y_, amp, Rs)
- -
[docs] def light_3d(self, r, amp, Rs, e1=0, e2=0): - """ - - :param r: - :param amp: - :param Rs: - :param e1: - :param e2: - :return: - """ - rho0 = self.lens.sigma2rho(amp, Rs) - return self.lens.density(r, rho0, Rs)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/interpolation.html b/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/interpolation.html deleted file mode 100644 index c15f033d0..000000000 --- a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/interpolation.html +++ /dev/null @@ -1,182 +0,0 @@ - - - - - - - - lenstronomy.LightModel.Profiles.interpolation — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LightModel.Profiles.interpolation

-__author__ = 'sibirrer'
-
-import scipy.interpolate
-import numpy as np
-
-import lenstronomy.Util.util as util
-
-__all__ = ['Interpol']
-
-
-
[docs]class Interpol(object): - """ - class which uses an interpolation of an image to compute the surface brightness - - parameters are - 'image': 2d numpy array of surface brightness (not integrated flux per pixel!) - 'center_x': coordinate of center of image in angular units (i.e. arc seconds) - 'center_y': coordinate of center of image in angular units (i.e. arc seconds) - 'phi_G': rotation of image relative to the rectangular ra-to-dec orientation - 'scale': arcseconds per pixel of the image to be interpolated - - """ - param_names = ['image', 'amp', 'center_x', 'center_y', 'phi_G', 'scale'] - lower_limit_default = {'amp': 0, 'center_x': -1000, 'center_y': -1000, 'scale': 0.000000001, 'phi_G': -np.pi} - upper_limit_default = {'amp': 1000000, 'center_x': 1000, 'center_y': 1000, 'scale': 10000000000, 'phi_G': np.pi} - - def __init__(self): - pass - -
[docs] def function(self, x, y, image=None, amp=1, center_x=0, center_y=0, phi_G=0, scale=1): - """ - - :param x: x-coordinate to evaluate surface brightness - :param y: y-coordinate to evaluate surface brightness - :param image: 2d numpy array (image) to be used to interpolate - :param amp: amplitude of surface brightness scaling in respect of original image - :param center_x: center of interpolated image - :param center_y: center of interpolated image - :param phi_G: rotation angle of simulated image in respect to input gird - :param scale: pixel scale (in angular units) of the simulated image - :return: surface brightness from the model at coordinates (x, y) - """ - x_, y_ = self.coord2image_pixel(x, y, center_x, center_y, phi_G, scale) - return amp * self.image_interp(x_, y_, image)
- -
[docs] def image_interp(self, x, y, image): - if not hasattr(self, '_image_interp'): - # Setup the interpolator. - # Note that 'x' and 'y' in this block only refer to first and second - # image array axes. Outside this block it is more complicated. - nx, ny = np.shape(image) - image_bounds = np.zeros((nx + 2, ny + 2)) - nx0, ny0 = nx + 2, ny + 2 - image_bounds[1:-1, 1:-1] = image - x_grid = np.linspace(start=-(nx0 - 1) / 2, stop=(nx0 - 1) / 2, num=nx0) - y_grid = np.linspace(start=-(ny0 - 1) / 2, stop=(ny0 - 1) / 2, num=ny0) - self._image_interp = scipy.interpolate.RectBivariateSpline(x_grid, y_grid, image_bounds, kx=1, ky=1, s=0) - - # y and x must be flipped in call to interpolator - # (try reversing, the unit tests will fail) - return self._image_interp(y, x, grid=False)
- -
[docs] def total_flux(self, image, scale, amp=1, center_x=0, center_y=0, phi_G=0): - """ - sums up all the image surface brightness (image pixels defined in surface brightness at the coordinate of the pixel) - times pixel area - - :param image: pixelized surface brightness - :param scale: scale of the pixel in units of angle - :param amp: linear scaling parameter of the surface brightness multiplicative with the initial image - :param center_x: center of image in angular coordinates - :param center_y: center of image in angular coordinates - :param phi_G: rotation angle - :return: total flux of the image - """ - return np.sum(image) * scale**2 * amp
- -
[docs] @staticmethod - def coord2image_pixel(ra, dec, center_x, center_y, phi_G, scale): - """ - - :param ra: angular coordinate - :param dec: angular coordinate - :param center_x: center of image in angular coordinates - :param center_y: center of image in angular coordinates - :param phi_G: rotation angle - :param scale: pixel scale of image - :return: pixel coordinates - """ - ra_ = ra - center_x - dec_ = dec - center_y - x_ = ra_ / scale - y_ = dec_ / scale - x, y = util.rotate(x_, y_, phi_G) - return x, y
- -
[docs] def delete_cache(self): - """delete the cached interpolated image""" - if hasattr(self, '_image_interp'): - del self._image_interp
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/moffat.html b/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/moffat.html deleted file mode 100644 index ba37c89d5..000000000 --- a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/moffat.html +++ /dev/null @@ -1,122 +0,0 @@ - - - - - - - - lenstronomy.LightModel.Profiles.moffat — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LightModel.Profiles.moffat

-__author__ = 'sibirrer'
-
-# this file contains a class to make a Moffat profile
-
-__all__ = ['Moffat']
-
-
-
[docs]class Moffat(object): - """ - this class contains functions to evaluate a Moffat surface brightness profile - - .. math:: - - I(r) = I_0 * (1 + (r/\\alpha)^2)^{-\\beta} - - with :math:`I_0 = amp`. - - """ - def __init__(self): - self.param_names = ['amp', 'alpha', 'beta', 'center_x', 'center_y'] - self.lower_limit_default = {'amp': 0, 'alpha': 0, 'beta': 0, 'center_x': -100, 'center_y': -100} - self.upper_limit_default = {'amp': 100, 'alpha': 10, 'beta': 10, 'center_x': 100, 'center_y': 100} - -
[docs] def function(self, x, y, amp, alpha, beta, center_x=0, center_y=0): - """ - 2D Moffat profile - - :param x: x-position (angle) - :param y: y-position (angle) - :param amp: normalization - :param alpha: scale - :param beta: exponent - :param center_x: x-center - :param center_y: y-center - :return: surface brightness - """ - - x_shift = x - center_x - y_shift = y - center_y - return amp * (1. + (x_shift**2+y_shift**2)/alpha**2)**(-beta)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/nie.html b/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/nie.html deleted file mode 100644 index fc4e2431a..000000000 --- a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/nie.html +++ /dev/null @@ -1,144 +0,0 @@ - - - - - - - - lenstronomy.LightModel.Profiles.nie — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LightModel.Profiles.nie

-import numpy as np
-import lenstronomy.Util.param_util as param_util
-from lenstronomy.LightModel.Profiles.profile_base import LightProfileBase
-
-__all__ = ['NIE']
-
-
-
[docs]class NIE(LightProfileBase): - """ - non-divergent isothermal ellipse (projected) - This is effectively the convergence profile of the NIE lens model with an amplitude 'amp' rather than an Einstein - radius 'theta_E' - """ - param_names = ['amp', 'e1', 'e2', 's_scale', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'e1': -0.5, 'e2': -0.5, 's_scale': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'e1': 0.5, 'e2': 0.5, 's_scale': 100, 'center_x': 100, 'center_y': 100} - -
[docs] def function(self, x, y, amp, e1, e2, s_scale, center_x=0, center_y=0): - """ - - :param x: x-coordinate - :param y: y-coordinate - :param amp: surface brightness normalization - :param e1: eccentricity component - :param e2: eccentricity component - :param s_scale: smoothing scale (square averaged of minor and major axis) - :param center_x: center of profile - :param center_y: center of profile - :return: surface brightness of NIE profile - """ - # phi_G, q = param_util.ellipticity2phi_q(e1, e2) - # s = s_scale * np.sqrt((1 + q ** 2) / (2 * q ** 2)) - x__, y__ = param_util.transform_e1e2_product_average(x, y, e1, e2, center_x, center_y) - f_ = amp / 2. * (s_scale**2 + x__ ** 2 + y__ ** 2) ** (-1. / 2) - return f_
- -
[docs] def light_3d(self, r, amp, e1, e2, s_scale, center_x=0, center_y=0): - """ - 3d light distribution (in spherical regime) - - :param r: 3d radius - :param amp: surface brightness normalization - :param e1: eccentricity component - :param e2: eccentricity component - :param s_scale: smoothing scale (square averaged of minor and major axis) - :param center_x: center of profile - :param center_y: center of profile - :return: light density at 3d radius - """ - rho = self._amp2rho(amp) - return rho / (r**2 + s_scale**2)
- - @staticmethod - def _amp2rho(amp): - """ - converts surface brightness normalization 'amp' into 3d density normalization rho - - :param amp: - :return: rho - """ - factor = np.pi - return amp / 2 / factor
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/p_jaffe.html b/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/p_jaffe.html deleted file mode 100644 index fbd15c4c0..000000000 --- a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/p_jaffe.html +++ /dev/null @@ -1,165 +0,0 @@ - - - - - - - - lenstronomy.LightModel.Profiles.p_jaffe — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LightModel.Profiles.p_jaffe

-import lenstronomy.Util.param_util as param_util
-
-__all__ = ['PJaffe', 'PJaffeEllipse']
-
-
-
[docs]class PJaffe(object): - """ - class for pseudo Jaffe lens light (2d projected light/mass distribution) - """ - param_names = ['amp', 'Ra', 'Rs', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'Ra': 0, 'Rs': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'Ra': 100, 'Rs': 100, 'center_x': 100, 'center_y': 100} - - def __init__(self): - from lenstronomy.LensModel.Profiles.p_jaffe import PJaffe as PJaffe_lens - self.lens = PJaffe_lens() - -
[docs] def function(self, x, y, amp, Ra, Rs, center_x=0, center_y=0): - """ - - :param x: - :param y: - :param amp: - :param Ra: - :param Rs: - :param center_x: - :param center_y: - :return: - """ - rho0 = self.lens.sigma2rho(amp, Ra, Rs) - return self.lens.density_2d(x, y, rho0, Ra, Rs, center_x, center_y)
- -
[docs] def light_3d(self, r, amp, Ra, Rs): - """ - - :param r: - :param amp: - :param Rs: - :param Ra: - :return: - """ - rho0 = self.lens.sigma2rho(amp, Ra, Rs) - return self.lens.density(r, rho0, Ra, Rs)
- - -
[docs]class PJaffeEllipse(object): - """ - calss for elliptical pseudo Jaffe lens light - """ - param_names = ['amp', 'Ra', 'Rs', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'Ra': 0, 'Rs': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'Ra': 100, 'Rs': 100, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self): - from lenstronomy.LensModel.Profiles.p_jaffe import PJaffe as PJaffe_lens - self.lens = PJaffe_lens() - self.spherical = PJaffe() - -
[docs] def function(self, x, y, amp, Ra, Rs, e1, e2, center_x=0, center_y=0): - """ - - :param x: - :param y: - :param amp: - :param Ra: - :param Rs: - :param center_x: - :param center_y: - :return: - """ - x_, y_ = param_util.transform_e1e2_square_average(x, y, e1, e2, center_x, center_y) - return self.spherical.function(x_, y_, amp, Ra, Rs)
- -
[docs] def light_3d(self, r, amp, Ra, Rs, e1=0, e2=0): - """ - - :param r: - :param amp: - :param Ra: - :param Rs: - :return: - """ - return self.spherical.light_3d(r, amp, Ra, Rs)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/power_law.html b/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/power_law.html deleted file mode 100644 index d5982eb06..000000000 --- a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/power_law.html +++ /dev/null @@ -1,152 +0,0 @@ - - - - - - - - lenstronomy.LightModel.Profiles.power_law — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LightModel.Profiles.power_law

-import lenstronomy.Util.param_util as param_util
-from lenstronomy.LensModel.Profiles.spp import SPP
-import numpy as np
-import scipy.special as special
-
-__all__ = ['PowerLaw']
-
-
-
[docs]class PowerLaw(object): - """ - class for power-law elliptical light distribution - - """ - param_names = ['amp', 'gamma', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'gamma': 1, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'gamma': 3, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.lens = SPP() - -
[docs] def function(self, x, y, amp, gamma, e1, e2, center_x=0, center_y=0): - """ - - :param x: ra-coordinate - :param y: dec-coordinate - :param amp: amplitude of flux - :param gamma: projected power-law slope - :param e1: ellipticity - :param e2: ellipticity - :param center_x: center - :param center_y: center - :return: projected flux - """ - x_, y_ = param_util.transform_e1e2_product_average(x, y, e1, e2, center_x, center_y) - P2 = x_ ** 2 + y_ ** 2 - if isinstance(P2, int) or isinstance(P2, float): - a = max(0.00000001, P2) - else: - a = np.empty_like(P2) - p2 = P2[P2 > 0] # in the SIS regime - a[P2 == 0] = 0.00000001 - a[P2 > 0] = p2 - - sigma = amp * a ** ((1. - gamma)/2.) - return sigma
- -
[docs] def light_3d(self, r, amp, gamma, e1=0, e2=0): - """ - - :param r: - :param amp: - :param gamma: - :param e1: - :param e2: - :return: - """ - rho0 = self._amp2rho(amp, gamma) - rho = rho0 / r ** gamma - return rho
- - @staticmethod - def _amp2rho(amp, gamma): - """ - - :param amp: - :param gamma: - :return: - """ - factor = np.sqrt(np.pi) * special.gamma(1./2*(-1+gamma))/special.gamma(gamma/2.) - return amp / factor
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/sersic.html b/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/sersic.html deleted file mode 100644 index 22b55edfe..000000000 --- a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/sersic.html +++ /dev/null @@ -1,210 +0,0 @@ - - - - - - - - lenstronomy.LightModel.Profiles.sersic — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LightModel.Profiles.sersic

-__author__ = 'sibirrer'
-
-#  this file contains a class to make a Sersic profile
-
-import numpy as np
-from lenstronomy.LensModel.Profiles.sersic_utils import SersicUtil
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -class Sersic(SersicUtil): - """ - this class contains functions to evaluate an spherical Sersic function - - .. math:: - I(R) = I_0 \\exp \\left[ -b_n (R/R_{\\rm Sersic})^{\\frac{1}{n}}\\right] - - with :math:`I_0 = amp` - and - with :math:`b_{n}\\approx 1.999n-0.327` - - """ - - param_names = ['amp', 'R_sersic', 'n_sersic', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'R_sersic': 0, 'n_sersic': 0.5, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'R_sersic': 100, 'n_sersic': 8, 'center_x': 100, 'center_y': 100} - -
[docs] def function(self, x, y, amp, R_sersic, n_sersic, center_x=0, center_y=0, max_R_frac=100.0): - """ - - :param x: - :param y: - :param amp: surface brightness/amplitude value at the half light radius - :param R_sersic: semi-major axis half light radius - :param n_sersic: Sersic index - :param center_x: center in x-coordinate - :param center_y: center in y-coordinate - :param max_R_frac: maximum window outside of which the mass is zeroed, in units of R_sersic (float) - :return: Sersic profile value at (x, y) - """ - R = self.get_distance_from_center(x, y, e1=0, e2=0, center_x=center_x, center_y=center_y) - result = self._r_sersic(R, R_sersic, n_sersic, max_R_frac) - return amp * result
- - -
[docs]@export -class SersicElliptic(SersicUtil): - """ - this class contains functions to evaluate an elliptical Sersic function - """ - param_names = ['amp', 'R_sersic', 'n_sersic', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'R_sersic': 0, 'n_sersic': 0.5, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, - 'center_y': -100} - upper_limit_default = {'amp': 100, 'R_sersic': 100, 'n_sersic': 8, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, - 'center_y': 100} - -
[docs] def function(self, x, y, amp, R_sersic, n_sersic, e1, e2, center_x=0, center_y=0, max_R_frac=100.0): - """ - - :param x: - :param y: - :param amp: surface brightness/amplitude value at the half light radius - :param R_sersic: half light radius (either semi-major axis or product average of semi-major and semi-minor axis) - :param n_sersic: Sersic index - :param e1: eccentricity parameter - :param e2: eccentricity parameter - :param center_x: center in x-coordinate - :param center_y: center in y-coordinate - :param max_R_frac: maximum window outside of which the mass is zeroed, in units of R_sersic (float) - :return: Sersic profile value at (x, y) - """ - - R_sersic = np.maximum(0, R_sersic) - R = self.get_distance_from_center(x, y, e1, e2, center_x, center_y) - result = self._r_sersic(R, R_sersic, n_sersic, max_R_frac) - return amp * result
- - -
[docs]@export -class CoreSersic(SersicUtil): - """ - this class contains the Core-Sersic function introduced by e.g Trujillo et al. 2004 - - .. math:: - I(R) = I' \\left[1 + (R_b/R)^{\\alpha} \\right]^{\\gamma / \\alpha} - \\exp \\left{ -b_n \\left[(R^{\\alpha} + R_b^{\alpha})/R_e^{\\alpha} \\right]^{1 / (n\\alpha)} \\right} - - with - - .. math:: - I' = I_b 2^{-\\gamma/ \\alpha} \\exp \\left[b_n 2^{1 / (n\\alpha)} (R_b/R_e)^{1/n} \\right] - - where :math:`I_b` is the intensity at the break radius. - - """ - param_names = ['amp', 'R_sersic', 'Rb', 'n_sersic', 'gamma', 'e1', 'e2', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'Rb': 0, 'n_sersic': 0.5, 'gamma': 0, 'e1': -0.5, 'e2': -0.5, 'center_x': -100, - 'center_y': -100} - upper_limit_default = {'amp': 100, 'Rb': 100, 'n_sersic': 8, 'gamma': 10, 'e1': 0.5, 'e2': 0.5, 'center_x': 100, - 'center_y': 100} - -
[docs] def function(self, x, y, amp, R_sersic, Rb, n_sersic, gamma, e1, e2, center_x=0, center_y=0, alpha=3.0, - max_R_frac=100.0): - """ - :param x: - :param y: - :param amp: surface brightness/amplitude value at the half light radius - :param R_sersic: half light radius (either semi-major axis or product average of semi-major and semi-minor axis) - :param Rb: "break" core radius - :param n_sersic: Sersic index - :param gamma: inner power-law exponent - :param e1: eccentricity parameter - :param e2: eccentricity parameter - :param center_x: center in x-coordinate - :param center_y: center in y-coordinate - :param alpha: sharpness of the transition between the cusp and the outer Sersic profile (float) - :param max_R_frac: maximum window outside of which the mass is zeroed, in units of R_sersic (float) - :return: Cored Sersic profile value at (x, y) - """ - # TODO: max_R_frac not implemented - R_ = self.get_distance_from_center(x, y, e1, e2, center_x, center_y) - R = self._R_stable(R_) - bn = self.b_n(n_sersic) - result = amp * (1 + (Rb / R) ** alpha) ** (gamma / alpha) * \ - np.exp(-bn * (((R ** alpha + Rb ** alpha) / R_sersic ** alpha) ** (1. / (alpha * n_sersic)) - 1.)) - return np.nan_to_num(result)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/shapelets.html b/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/shapelets.html deleted file mode 100644 index 794e6db6e..000000000 --- a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/shapelets.html +++ /dev/null @@ -1,395 +0,0 @@ - - - - - - - - lenstronomy.LightModel.Profiles.shapelets — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LightModel.Profiles.shapelets

-__author__ = 'sibirrer'
-
-import numpy as np
-import numpy.polynomial.hermite as hermite
-import math
-
-import lenstronomy.Util.util as util
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -class Shapelets(object): - """ - class for 2d cartesian Shapelets. - - Sources: - Refregier 2003: Shapelets: I. A Method for Image Analysis https://arxiv.org/abs/astro-ph/0105178 - Refregier 2003: Shapelets: II. A Method for Weak Lensing Measurements https://arxiv.org/abs/astro-ph/0105179 - - For one dimension, the shapelets are defined as - - .. math:: - \\phi_n(x) \\equiv \\left[2^n \\pi^{1/2} n! \\right]]^{-1/2}H_n(x) e^{-\\frac{x^2}{2}} - - This basis is orthonormal. The dimensional basis function is - - .. math:: - B_n(x;\\beta) \\equiv \\beta^{-1/2} \\phi_n(\\beta^{-1}x) - - which are orthonormal as well. - - The two-dimensional basis function is - - .. math:: - \\phi_{\\bf n}({\bf x}) \\equiv \\phi_{n1}(x1) \\phi_{n2}(x2) - - where :math:`{\\bf n} \\equiv (n1, n2)` and :math:`{\\bf x} \\equiv (x1, x2)`. - - The dimensional two-dimentional basis function is - - .. math:: - B_{\\bf n}({\\bf x};\\beta) \\equiv \\beta^{-1/2} \\phi_{\\bf n}(\\beta^{-1}{\\bf x}). - - """ - param_names = ['amp', 'beta', 'n1', 'n2', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'beta': 0.01, 'n1': 0, 'n2': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'beta': 100, 'n1': 150, 'n2': 150, 'center_x': 100, 'center_y': 100} - - def __init__(self, interpolation=False, precalc=False, stable_cut=True, cut_scale=5): - """ - load interpolation of the Hermite polynomials in a range [-30,30] in order n<= 150 - - :param interpolation: boolean; if True, uses interpolated pre-calculated shapelets in the evaluation - :param precalc: boolean; if True interprets as input (x, y) as pre-calculated normalized shapelets - :param stable_cut: boolean; if True, sets the values outside of - :math:`\\sqrt\\left(n_{\\rm max} + 1 \\right) \\beta s_{\\rm cut scale} = 0`. - :param cut_scale: float, scaling parameter where to cut the shapelets. This is for numerical reasons such that - the polynomials in the Hermite function do not get unstable. - """ - - self._interpolation = interpolation - self._precalc = precalc - self._stable_cut = stable_cut - self._cut_scale = cut_scale - if interpolation: - n_order = 50 - self.H_interp = [[] for _ in range(0, n_order)] - self.x_grid = np.linspace(-50, 50, 6000) - for k in range(0, n_order): - n_array = np.zeros(k+1) - n_array[k] = 1 - values = self.hermval(self.x_grid, n_array) - self.H_interp[k] = values - -
[docs] def hermval(self, x, n_array, tensor=True): - """ - computes the Hermit polynomial as numpy.polynomial.hermite.hermval - difference: for values more than sqrt(n_max + 1) * cut_scale, the value is set to zero - this should be faster and numerically stable - - :param x: array of values - :param n_array: list of coeffs in H_n - :param tensor: see numpy.polynomial.hermite.hermval - :return: see numpy.polynomial.hermite.hermval - """ - if not self._stable_cut: - return hermite.hermval(x, n_array, tensor=tensor) - else: - n_max = len(n_array) - x_cut = np.sqrt(n_max + 1) * self._cut_scale - if isinstance(x, int) or isinstance(x, float): - if x >= x_cut: - return 0 - else: - return hermite.hermval(x, n_array) - else: - out = np.zeros_like(x) - out[x < x_cut] = hermite.hermval(x[x < x_cut], n_array, tensor=tensor) - return out
- -
[docs] def function(self, x, y, amp, beta, n1, n2, center_x, center_y): - """ - 2d cartesian shapelet - - :param x: x-coordinate - :param y: y-coordinate - :param amp: amplitude of shapelet - :param beta: scale factor of shapelet - :param n1: x-order of Hermite polynomial - :param n2: y-order of Hermite polynomial - :param center_x: center in x - :param center_y: center in y - :return: flux surface brighness at (x, y) - """ - - if self._precalc: - return amp * x[n1] * y[n2] # / beta - x_ = x - center_x - y_ = y - center_y - return np.nan_to_num(amp * self.phi_n(n1, x_/beta) * self.phi_n(n2, y_/beta)) # /beta
- -
[docs] def H_n(self, n, x): - """ - constructs the Hermite polynomial of order n at position x (dimensionless) - - :param n: The n'the basis function. - :param x: 1-dim position (dimensionless) - :type x: float or numpy array. - :returns: array-- H_n(x). - """ - if not self._interpolation: - n_array = np.zeros(n+1) - n_array[n] = 1 - return self.hermval(x, n_array, tensor=False) # attention, this routine calculates every single hermite polynomial and multiplies it with zero (exept the right one) - else: - return np.interp(x, self.x_grid, self.H_interp[n])
- -
[docs] def phi_n(self, n, x): - """ - constructs the 1-dim basis function (formula (1) in Refregier et al. 2001) - - :param n: The n'the basis function. - :type n: int. - :param x: 1-dim position (dimensionless) - :type x: float or numpy array. - :returns: array-- phi_n(x). - """ - prefactor = 1./np.sqrt(2**n*np.sqrt(np.pi)*math.factorial(n)) - return prefactor*self.H_n(n, x)*np.exp(-x**2/2.)
- -
[docs] def pre_calc(self, x, y, beta, n_order, center_x, center_y): - """ - calculates the H_n(x) and H_n(y) for a given x-array and y-array for the full order in the polynomials - - :param x: x-coordinates (numpy array) - :param y: 7-coordinates (numpy array) - :param beta: shapelet scale - :param n_order: order of shapelets - :param center_x: shapelet center - :param center_y: shapelet center - :return: list of H_n(x) and H_n(y) - """ - x_ = x - center_x - y_ = y - center_y - n = len(np.atleast_1d(x)) - H_x = np.empty((n_order+1, n)) - H_y = np.empty((n_order+1, n)) - exp_x = np.exp(-(x_ / beta) ** 2 / 2.) - exp_y = np.exp(-(y_ / beta) ** 2 / 2.) - if n_order > 170: - raise ValueError('polynomial order to large', n_order) - for n in range(0, n_order+1): - prefactor = 1./np.sqrt(2**n*np.sqrt(np.pi)*math.factorial(n)) - n_array = np.zeros(n+1) - n_array[n] = 1 - H_x[n] = self.hermval(x_/beta, n_array, tensor=False) * prefactor * exp_x - H_y[n] = self.hermval(y_/beta, n_array, tensor=False) * prefactor * exp_y - return H_x, H_y
- - -
[docs]@export -class ShapeletSet(object): - """ - class to operate on entire shapelet set limited by a maximal polynomial order n_max, such that n1 + n2 <= n_max - """ - param_names = ['amp', 'n_max', 'beta', 'center_x', 'center_y'] - lower_limit_default = {'beta': 0.01, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'beta': 100, 'center_x': 100, 'center_y': 100} - - def __init__(self): - self.shapelets = Shapelets(precalc=True) - -
[docs] def function(self, x, y, amp, n_max, beta, center_x=0, center_y=0): - """ - - :param x: x-coordinates - :param y: y-coordinates - :param amp: array of amplitudes in pre-defined order of shapelet basis functions - :param beta: shapelet scale - :param n_max: maximum polynomial order in Hermite polynomial - :param center_x: shapelet center - :param center_y: shapelet center - :return: surface brightness of combined shapelet set - """ - num_param = int((n_max+1)*(n_max+2)/2) - f_ = np.zeros(len(np.atleast_1d(x))) - n1 = 0 - n2 = 0 - H_x, H_y = self.shapelets.pre_calc(x, y, beta, n_max, center_x, center_y) - for i in range(num_param): - kwargs_source_shapelet = {'center_x': center_x, 'center_y': center_y, 'n1': n1, 'n2': n2, 'beta': beta, 'amp': amp[i]} - out = self.shapelets.function(H_x, H_y, **kwargs_source_shapelet) - f_ += out - if n1 == 0: - n1 = n2 + 1 - n2 = 0 - else: - n1 -= 1 - n2 += 1 - try: - len(x) - except: - f_ = f_[0] - return np.nan_to_num(f_)
- -
[docs] def function_split(self, x, y, amp, n_max, beta, center_x=0, center_y=0): - """ - splits shapelet set in list of individual shapelet basis function responses - - :param x: x-coordinates - :param y: y-coordinates - :param amp: array of amplitudes in pre-defined order of shapelet basis functions - :param beta: shapelet scale - :param n_max: maximum polynomial order in Hermite polynomial - :param center_x: shapelet center - :param center_y: shapelet center - :return: list of individual shapelet basis function responses - """ - num_param = int((n_max+1)*(n_max+2)/2) - A = [] - n1 = 0 - n2 = 0 - H_x, H_y = self.shapelets.pre_calc(x, y, beta, n_max, center_x, center_y) - for i in range(num_param): - kwargs_source_shapelet = {'center_x': center_x, 'center_y': center_y, 'n1': n1, 'n2': n2, 'beta': beta, 'amp': amp[i]} - A.append(self.shapelets.function(H_x, H_y, **kwargs_source_shapelet)) - if n1 == 0: - n1 = n2 + 1 - n2 = 0 - else: - n1 -= 1 - n2 += 1 - return A
- -
[docs] def shapelet_basis_2d(self, num_order, beta, numPix, deltaPix=1, center_x=0, center_y=0): - """ - - :param num_order: max shapelet order - :param beta: shapelet scale - :param numPix: number of pixel of the grid - :return: list of shapelets drawn on pixel grid, centered. - """ - num_param = int((num_order+2)*(num_order+1)/2) - kernel_list = [] - x_grid, y_grid = util.make_grid(numPix, deltapix=deltaPix, subgrid_res=1) - n1 = 0 - n2 = 0 - H_x, H_y = self.shapelets.pre_calc(x_grid, y_grid, beta, num_order, center_x=center_x, center_y=center_y) - for i in range(num_param): - kwargs_source_shapelet = {'center_x': 0, 'center_y': 0, 'n1': n1, 'n2': n2, 'beta': beta, 'amp': 1} - kernel = self.shapelets.function(H_x, H_y, **kwargs_source_shapelet) - kernel = util.array2image(kernel) - kernel_list.append(kernel) - if n1 == 0: - n1 = n2 + 1 - n2 = 0 - else: - n1 -= 1 - n2 += 1 - return kernel_list
- -
[docs] def decomposition(self, image, x, y, n_max, beta, deltaPix, center_x=0, center_y=0): - """ - decomposes an image into the shapelet coefficients in same order as for the function call - :param image: - :param x: - :param y: - :param n_max: - :param beta: - :param center_x: - :param center_y: - :return: - """ - num_param = int((n_max+1)*(n_max+2)/2) - param_list = np.zeros(num_param) - amp_norm = 1./beta**2*deltaPix**2 - n1 = 0 - n2 = 0 - H_x, H_y = self.shapelets.pre_calc(x, y, beta, n_max, center_x, center_y) - for i in range(num_param): - kwargs_source_shapelet = {'center_x': center_x, 'center_y': center_y, 'n1': n1, 'n2': n2, 'beta': beta, 'amp': amp_norm} - base = self.shapelets.function(H_x, H_y, **kwargs_source_shapelet) - param = np.sum(image*base) - param_list[i] = param - if n1 == 0: - n1 = n2 + 1 - n2 = 0 - else: - n1 -= 1 - n2 += 1 - return param_list
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/shapelets_polar.html b/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/shapelets_polar.html deleted file mode 100644 index 7438eaf91..000000000 --- a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/shapelets_polar.html +++ /dev/null @@ -1,488 +0,0 @@ - - - - - - - - lenstronomy.LightModel.Profiles.shapelets_polar — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LightModel.Profiles.shapelets_polar

-__author__ = 'sibirrer'
-
-import numpy as np
-import math
-import scipy.special
-
-import lenstronomy.Util.param_util as param_util
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -class ShapeletsPolar(object): - """ - 2D polar Shapelets, see Massey & Refregier 2005 - """ - param_names = ['amp', 'beta', 'n', 'm', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'beta': 0, 'n': 0, 'm': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'beta': 100, 'n': 150, 'm': 150, 'center_x': 100, 'center_y': 100} - - def __init__(self): - """ - load interpolation of the Hermite polynomials in a range [-30,30] in order n<= 150 - :return: - """ - pass - -
[docs] def function(self, x, y, amp, beta, n, m, complex_bool, center_x, center_y): - """ - - :param x: x-coordinate, numpy array - :param y: y-ccordinate, numpy array - :param amp: amplitude normalization - :param beta: shaplet scale - :param n: order of polynomial - :param m: rotational invariance - :param complex_bool: boolean; if True uses complex value of function _chi_n_m() - :param center_x: center of shapelet - :param center_y: center of shapelet - :return: amplitude of shapelet at possition (x, y) - """ - r, phi = param_util.cart2polar(x, y, center_x, center_y) - if complex_bool is True: - return amp * self._chi_n_m(r, beta, n, m) * np.exp(-1j * m * phi).imag - else: - return amp * self._chi_n_m(r, beta, n, m) * np.exp(-1j * m * phi).real
- - @staticmethod - def _chi_n_m(r, beta, n, m): - """ - - :param r: radius / beta - :param beta: shapelet scale - :param n: non-negative integer - :param m: integer, running from -n to n in steps of two - :return: value of function (8) in Massey & Refregier, complex numbers - """ - m_abs = int(abs(m)) - p = int((n - m_abs)/2) - p2 = int((n + m_abs)/2) - if p % 2 == 0: # if p is even - prefac = 1 - else: - prefac = -1 - prefactor = prefac/beta**(m_abs + 1)*np.sqrt(math.factorial(p)/(np.pi*math.factorial(p2))) - poly = scipy.special.genlaguerre(n=p, alpha=m_abs) # lower part, upper part of definition in Massey & Refregier - r_ = (r/beta)**2 - l_n_alpha = poly(r_) - return prefactor*r**m_abs*l_n_alpha*np.exp(-(r/beta)**2/2) - - @staticmethod - def _index2n(index): - """ - - :param index: index of convention - :return: n order of Laguerre - """ - n_float = (-3 + np.sqrt(9 + 8 * index)) / 2 - n_int = int(n_float) - if n_int == n_float: - n = n_int - else: - n = n_int + 1 - return n - -
[docs] def index2poly(self, index): - """ - manages the convention from an iterative index to the specific polynomial n, m, (real/imaginary part) - - :param index: int, index of list - :return: n, m bool - """ - - n = self._index2n(index) - - num_prev = n * (n + 1) / 2 - num = index + 1 - delta = int(num - num_prev - 1) - if n % 2 == 0: - if delta == 0: - m = delta - complex_bool = False - elif delta % 2 == 0: - complex_bool = True - m = delta - else: - complex_bool = False - m = delta + 1 - else: - if delta % 2 == 0: - complex_bool = False - m = delta + 1 - else: - complex_bool = True - m = delta - return n, m, complex_bool
- -
[docs] @staticmethod - def poly2index(n, m, complex_bool): - """ - - :param n: non-negative integer - :param m: integer, running from -n to n in steps of two - :param complex_bool: bool, if True, assigns complex part - :return: - """ - index = n * (n + 1) / 2 - if complex_bool is True: - if m == 0: - raise ValueError('m=0 can not have imaginary part!') - if n % 2 == 0: - if m % 2 == 0: - if m == 0: - index += 1 - else: - index += m - if complex_bool is True: - index += 1 - else: - raise ValueError('m needs to be even for even n!') - else: - if complex_bool is True: - index += m + 1 - else: - index += m - return int(index - 1)
- -
[docs] @staticmethod - def num_param(n_max): - """ - - :param n_max: maximal polynomial order - :return: number of basis components - """ - return int((n_max+1)*(n_max+2)/2)
- - -
[docs]@export -class ShapeletsPolarExp(object): - """ - 2D exponential shapelets, Berge et al. 2019 - """ - param_names = ['amp', 'beta', 'n', 'm', 'center_x', 'center_y'] - lower_limit_default = {'amp': 0, 'beta': 0, 'n': 0, 'm': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'amp': 100, 'beta': 100, 'n': 150, 'm': 150, 'center_x': 100, 'center_y': 100} - - def __init__(self): - """ - load interpolation of the Hermite polynomials in a range [-30,30] in order n<= 150 - :return: - """ - pass - -
[docs] def function(self, x, y, amp, beta, n, m, complex_bool, center_x, center_y): - """ - - :param x: x-coordinate, numpy array - :param y: y-ccordinate, numpy array - :param amp: amplitude normalization - :param beta: shaplet scale - :param n: order of polynomial - :param m: rotational invariance - :param complex_bool: boolean; if True uses complex value of function _chi_n_m() - :param center_x: center of shapelet - :param center_y: center of shapelet - :return: amplitude of shapelet at possition (x, y) - """ - r, phi = param_util.cart2polar(x, y, center_x, center_y) - if complex_bool is True: - return amp * self._chi_n_m(r, beta, n, m) * np.exp(-1j * m * phi).imag - else: - return amp * self._chi_n_m(r, beta, n, m) * np.exp(-1j * m * phi).real
- - @staticmethod - def _chi_n_m(r, beta, n, m): - """ - - :param r: radius - :param beta: shapelet scale - :param n: non-negative integer - :param m: integer, running from -n to n in steps of two - :return: value of function (20) in Berge et al. 2019 without complex coefficient - """ - m_abs = int(abs(m)) - p = int(n - m_abs) - p2 = int(n + m_abs) - if p % 2 == 0: # if p is even - prefac = 1 - else: - prefac = -1 - prefactor = prefac * np.sqrt(2./(beta*np.pi * (2*n + 1)**3) * math.factorial(p) / math.factorial(p2)) - poly = scipy.special.genlaguerre(n=p, alpha=2*m_abs) # lower part, upper part of definition in Massey & Refregier - x_ = 2. * r / (beta * (2*n + 1)) - l_n_alpha = poly(x_) - return prefactor * x_**m_abs * l_n_alpha * np.exp(-x_/2) / np.sqrt(beta) - -
[docs] @staticmethod - def num_param(n_max): - """ - - :param n_max: maximal polynomial order - :return: number of basis components - """ - return int((n_max + 1)**2)
- - @staticmethod - def _index2n(index): - """ - - :param index: index convention - :return: n - """ - n_float = np.sqrt(index + 1) - 1 - n_int = int(n_float) - if n_int == n_float: - n = n_int - else: - n = n_int + 1 - return n - -
[docs] def index2poly(self, index): - """ - - :param index: - :return: - """ - n = self._index2n(index) - num_prev = n**2 - delta = index + 1 - num_prev - if delta % 2 == 1: - m = int((delta - 1) / 2) - complex_bool = False - else: - m = int(delta/2) - complex_bool = True - return n, m, complex_bool
- -
[docs] @staticmethod - def poly2index(n, m, complex_bool): - """ - - :param n: - :param m: - :param complex_bool: - :return: index convention, integer - """ - index = n**2 - index += 2*m - if complex_bool is True: - index -= 1 - return int(index)
- - -
[docs]@export -class ShapeletSetPolar(object): - """ - class to operate on entire shapelet set - """ - param_names = ['amp', 'n_max', 'beta', 'center_x', 'center_y'] - lower_limit_default = {'beta': 0, 'center_x': -100, 'center_y': -100} - upper_limit_default = {'beta': 100, 'center_x': 100, 'center_y': 100} - - def __init__(self, exponential=False): - if exponential is True: - self.shapelets = ShapeletsPolarExp() - else: - self.shapelets = ShapeletsPolar() - self._exponential = exponential - -
[docs] def function(self, x, y, amp, n_max, beta, center_x=0, center_y=0): - """ - - :param x: - :param y: - :param amp: - :param n_max: - :param beta: - :param center_x: - :param center_y: - :return: - """ - num_param = self.shapelets.num_param(n_max) - f_ = np.zeros(len(np.atleast_1d(x))) - l_list = self._pre_calc(x, y, beta, n_max, center_x, center_y) - for i in range(num_param): - out = self._pre_calc_function(l_list, i) * amp[i] - f_ += out - try: - len(x) - except: - f_ = f_[0] - return np.nan_to_num(f_)
- -
[docs] def function_split(self, x, y, amp, n_max, beta, center_x=0, center_y=0): - num_param = self.shapelets.num_param(n_max) - A = [] - L_list = self._pre_calc(x, y, beta, n_max, center_x, center_y) - for i in range(num_param): - A.append(self._pre_calc_function(L_list, i) * amp[i]) - return A
- - def _pre_calc(self, x, y, beta, n_max, center_x, center_y): - """ - - :param x: - :param y: - :param beta: - :param n_max: - :param center_x: - :param center_y: - :return: - """ - L_list = [] - # polar coordinates - r, phi = param_util.cart2polar(x, y, center_x, center_y) - num_param = self.shapelets.num_param(n_max) - - # compute real and imaginary part of the complex angles in the range n_max - theta_m_real_list, theta_m_imag_list = [], [] - for i in range(n_max + 1): - m = i - exp_complex = np.exp(-1j * m * phi) - theta_m_real_list.append(exp_complex.real) - theta_m_imag_list.append(exp_complex.imag) - - # compute the Laguerre polynomials in n, m - chi_n_m_list = [[0 for _ in range(n_max + 1)] for _ in range(n_max + 1)] - for n in range(n_max+1): - for m in range(n+1): - if (n - m) % 2 == 0 or self._exponential is True: - chi_n_m_list[n][m] = self.shapelets._chi_n_m(r, beta, n, m) - - # combine together the pre-computed components - for index in range(num_param): - n, m, complex_bool = self.shapelets.index2poly(index) - if complex_bool is True: - L_i = chi_n_m_list[n][m] * theta_m_imag_list[m] - else: - L_i = chi_n_m_list[n][m] * theta_m_real_list[m] - L_list.append(L_i) - return L_list - - @staticmethod - def _pre_calc_function(L_list, i): - """ - evaluates the shapelet function based on the pre-calculated components in _pre_calc() - - :param L_list: pre-calculated components - :param i: index conventions of the sequence of basis components - :return: shaplet basis at the pre-calculated positions - """ - return L_list[i] - -
[docs] def decomposition(self, image, x, y, n_max, beta, deltaPix, center_x=0, center_y=0): - """ - decomposes an image into the shapelet coefficients in same order as for the function call - :param image: - :param x: - :param y: - :param n_max: - :param beta: - :param center_x: - :param center_y: - :return: - """ - num_param = self.shapelets.num_param(n_max) - param_list = np.zeros(num_param) - amp_norm = 1. * deltaPix**2 - L_list = self._pre_calc(x, y, beta, n_max, center_x, center_y) - for i in range(num_param): - base = self._pre_calc_function(L_list, i) * amp_norm - param = np.sum(image*base) - n, m, complex_bool = self.shapelets.index2poly(i) - if m != 0: - param *= 2 - param_list[i] = param - return param_list
- -
[docs] def index2poly(self, index): - """ - - :param index: index of coefficient in the convention here - :return: n, m, complex_bool - """ - return self.shapelets.index2poly(index)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/uniform.html b/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/uniform.html deleted file mode 100644 index e5941cb2b..000000000 --- a/docs/_build/html/_modules/lenstronomy/LightModel/Profiles/uniform.html +++ /dev/null @@ -1,108 +0,0 @@ - - - - - - - - lenstronomy.LightModel.Profiles.uniform — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LightModel.Profiles.uniform

-import numpy as np
-
-__all__ = ['Uniform']
-
-
-
[docs]class Uniform(object): - """ - uniform light profile. This profile can also compensate for an inaccurate background subtraction. - name for profile: 'UNIFORM' - """ - param_names = ['amp'] - lower_limit_default = {'amp': -100} - upper_limit_default = {'amp': 100} - - def __init__(self): - pass - -
[docs] def function(self, x, y, amp): - """ - - :param x: x-coordinate - :param y: y-coordinate - :param amp: surface brightness - :return: constant flux - """ - return np.ones_like(x) * amp
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LightModel/light_model.html b/docs/_build/html/_modules/lenstronomy/LightModel/light_model.html deleted file mode 100644 index e0c19fcf1..000000000 --- a/docs/_build/html/_modules/lenstronomy/LightModel/light_model.html +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - lenstronomy.LightModel.light_model — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LightModel.light_model

-__author__ = 'sibirrer'
-
-
-from lenstronomy.LightModel.linear_basis import LinearBasis
-
-__all__ = ['LightModel']
-
-
-
[docs]class LightModel(LinearBasis): - """ - class to handle extended surface brightness profiles (for e.g. source and lens light) - - all profiles come with a surface_brightness parameterization (in units per square angle and independent of - the pixel scale). - The parameter 'amp' is the linear scaling parameter of surface brightness. - Some functional forms come with a total_flux() definition that provide the integral of the surface brightness for a - given set of parameters. - - The SimulationAPI module allows to use astronomical magnitudes to be used and translated into the surface brightness - conventions of this module given a magnitude zero point. - - """ - - def __init__(self, light_model_list, deflection_scaling_list=None, source_redshift_list=None, - smoothing=0.001, sersic_major_axis=None): - """ - - :param light_model_list: list of light models - :param deflection_scaling_list: list of floats indicating a relative scaling of the deflection angle from the - reduced angles in the lens model definition (optional, only possible in single lens plane with multiple source - planes) - :param source_redshift_list: list of redshifts for the different light models - (optional and only used in multi-plane lensing in conjunction with a cosmology model) - :param smoothing: smoothing factor for certain models (deprecated) - :param sersic_major_axis: boolean or None, if True, uses the semi-major axis as the definition of the Sersic - half-light radius, if False, uses the product average of semi-major and semi-minor axis. If None, uses the - convention in the lenstronomy yaml setting (which by default is =False) - """ - super(LightModel, self).__init__(light_model_list=light_model_list, smoothing=smoothing, - sersic_major_axis=sersic_major_axis) - self.deflection_scaling_list = deflection_scaling_list - self.redshift_list = source_redshift_list
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/LightModel/light_param.html b/docs/_build/html/_modules/lenstronomy/LightModel/light_param.html deleted file mode 100644 index 29dcf4696..000000000 --- a/docs/_build/html/_modules/lenstronomy/LightModel/light_param.html +++ /dev/null @@ -1,274 +0,0 @@ - - - - - - - - lenstronomy.LightModel.light_param — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.LightModel.light_param

-from lenstronomy.LightModel.light_model import LightModel
-
-__all__ = ['LightParam']
-
-
-
[docs]class LightParam(object): - """ - class manages the parameters corresponding to the LightModel() module. Also manages linear parameter handling. - """ - - def __init__(self, light_model_list, kwargs_fixed, kwargs_lower=None, kwargs_upper=None, param_type='light', - linear_solver=True): - """ - - :param light_model_list: list of light models - :param kwargs_fixed: list of keyword arguments corresponding to parameters held fixed during sampling - :param kwargs_lower: list of keyword arguments indicating hard lower limit of the parameter space - :param kwargs_upper: list of keyword arguments indicating hard upper limit of the parameter space - :param param_type: string (optional), adding specifications in the output strings (such as lens light or - source light) - :param linear_solver: bool, if True fixes the linear amplitude parameters 'amp' (avoid sampling) such that they - get overwritten by the linear solver solution. - """ - self._lightModel = LightModel(light_model_list=light_model_list) - self._param_name_list = self._lightModel.param_name_list - self._type = param_type - self.model_list = light_model_list - self.kwargs_fixed = kwargs_fixed - if linear_solver: - self.kwargs_fixed = self._lightModel.add_fixed_linear(self.kwargs_fixed) - self._linear_solve = linear_solver - if kwargs_lower is None: - kwargs_lower = [] - for func in self._lightModel.func_list: - kwargs_lower.append(func.lower_limit_default) - if kwargs_upper is None: - kwargs_upper = [] - for func in self._lightModel.func_list: - kwargs_upper.append(func.upper_limit_default) - self.lower_limit = kwargs_lower - self.upper_limit = kwargs_upper - - @property - def param_name_list(self): - return self._param_name_list - -
[docs] def get_params(self, args, i): - """ - - :param args: list of floats corresponding ot the arguments being sampled - :param i: int, index of the first argument that is managed/read-out by this class - :return: keyword argument list of the light profile, index after reading out the arguments corresponding to - this class - """ - kwargs_list = [] - for k, model in enumerate(self.model_list): - kwargs = {} - kwargs_fixed = self.kwargs_fixed[k] - param_names = self._param_name_list[k] - for name in param_names: - if name not in kwargs_fixed: - if model in ['SHAPELETS', 'SHAPELETS_POLAR', 'SHAPELETS_POLAR_EXP'] and name == 'amp': - if 'n_max' in kwargs_fixed: - n_max = kwargs_fixed['n_max'] - else: - raise ValueError('n_max needs to be fixed in %s.' % model) - if model in ['SHAPELETS_POLAR_EXP']: - num_param = int((n_max + 1) ** 2) - else: - num_param = int((n_max + 1) * (n_max + 2) / 2) - kwargs['amp'] = args[i:i + num_param] - i += num_param - elif model in ['MULTI_GAUSSIAN', 'MULTI_GAUSSIAN_ELLIPSE'] and name == 'amp': - if 'sigma' in kwargs_fixed: - num_param = len(kwargs_fixed['sigma']) - else: - raise ValueError('sigma needs to be fixed in %s.' % model) - kwargs['amp'] = args[i:i + num_param] - i += num_param - elif model in ['SLIT_STARLETS', 'SLIT_STARLETS_GEN2'] and name == 'amp': - if 'n_scales' in kwargs_fixed and 'n_pixels' in kwargs_fixed: - n_scales = kwargs_fixed['n_scales'] - n_pixels = kwargs_fixed['n_pixels'] - else: - raise ValueError("'n_scales' and 'n_pixels' both need to be fixed in %s." % model) - num_param = n_scales * n_pixels - kwargs['amp'] = args[i:i + num_param] - i += num_param - else: - kwargs[name] = args[i] - i += 1 - else: - kwargs[name] = kwargs_fixed[name] - - kwargs_list.append(kwargs) - return kwargs_list, i
- -
[docs] def set_params(self, kwargs_list): - """ - - :param kwargs_list: list of keyword arguments of the light profile (free parameter as well as optionally the - fixed ones) - :return: list of floats corresponding to the free parameters - """ - args = [] - for k, model in enumerate(self.model_list): - kwargs = kwargs_list[k] - kwargs_fixed = self.kwargs_fixed[k] - - param_names = self._param_name_list[k] - for name in param_names: - if name not in kwargs_fixed: - if model in ['SHAPELETS', 'SHAPELETS_POLAR', 'SHAPELETS_POLAR_EXP'] and name == 'amp': - n_max = kwargs_fixed.get('n_max', kwargs['n_max']) - if model in ['SHAPELETS_POLAR_EXP']: - num_param = int((n_max + 1) ** 2) - else: - num_param = int((n_max + 1) * (n_max + 2) / 2) - for i in range(num_param): - args.append(kwargs[name][i]) - elif model in ['SLIT_STARLETS', 'SLIT_STARLETS_GEN2'] and name == 'amp': - if 'n_scales' in kwargs_fixed: - n_scales = kwargs_fixed['n_scales'] - else: - raise ValueError("'n_scales' for SLIT_STARLETS not found in kwargs_fixed") - if 'n_pixels' in kwargs_fixed: - n_pixels = kwargs_fixed['n_pixels'] - else: - raise ValueError("'n_pixels' for SLIT_STARLETS not found in kwargs_fixed") - num_param = n_scales * n_pixels - for i in range(num_param): - args.append(kwargs[name][i]) - elif model in ['SLIT_STARLETS', 'SLIT_STARLETS_GEN2'] and name in ['n_scales', 'n_pixels', 'scale', - 'center_x', 'center_y']: - raise ValueError("'{}' must be a fixed keyword argument for STARLETS-like models".format(name)) - elif model in ['MULTI_GAUSSIAN', 'MULTI_GAUSSIAN_ELLIPSE'] and name == 'amp': - num_param = len(kwargs['sigma']) - for i in range(num_param): - args.append(kwargs[name][i]) - elif model in ['MULTI_GAUSSIAN', 'MULTI_GAUSSIAN_ELLIPSE'] and name == 'sigma': - raise ValueError("'sigma' must be a fixed keyword argument for MULTI_GAUSSIAN") - else: - args.append(kwargs[name]) - return args
- -
[docs] def num_param(self): - """ - - :return: int, list of strings with param names - """ - num = 0 - name_list = [] - for k, model in enumerate(self.model_list): - kwargs_fixed = self.kwargs_fixed[k] - param_names = self._param_name_list[k] - for name in param_names: - if name not in kwargs_fixed: - if model in ['SHAPELETS', 'SHAPELETS_POLAR', 'SHAPELETS_POLAR_EXP'] and name == 'amp': - if 'n_max' not in kwargs_fixed: - raise ValueError("n_max needs to be fixed in this configuration!") - n_max = kwargs_fixed['n_max'] - if model in ['SHAPELETS_POLAR_EXP']: - num_param = int((n_max + 1) ** 2) - else: - num_param = int((n_max + 1) * (n_max + 2) / 2) - num += num_param - for i in range(num_param): - name_list.append(str(name + '_' + self._type + str(k))) - elif model in ['SLIT_STARLETS', 'SLIT_STARLETS_GEN2'] and name == 'amp': - if 'n_scales' not in kwargs_fixed or 'n_pixels' not in kwargs_fixed: - raise ValueError("n_scales and n_pixels need to be fixed when using STARLETS-like models!") - n_scales = kwargs_fixed['n_scales'] - n_pixels = kwargs_fixed['n_pixels'] - num_param = n_scales * n_pixels - num += num_param - for i in range(num_param): - name_list.append(str(name + '_' + self._type + str(k))) - elif model in ['MULTI_GAUSSIAN', 'MULTI_GAUSSIAN_ELLIPSE'] and name == 'amp': - num_param = len(kwargs_fixed['sigma']) - num += num_param - for i in range(num_param): - name_list.append(str(name + '_' + self._type + str(k))) - else: - num += 1 - name_list.append(str(name + '_' + self._type + str(k))) - return num, name_list
- -
[docs] def num_param_linear(self): - """ - :return: number of linear basis set coefficients - """ - return self._lightModel.num_param_linear(kwargs_list=self.kwargs_fixed)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Plots/chain_plot.html b/docs/_build/html/_modules/lenstronomy/Plots/chain_plot.html deleted file mode 100644 index 48f9809aa..000000000 --- a/docs/_build/html/_modules/lenstronomy/Plots/chain_plot.html +++ /dev/null @@ -1,250 +0,0 @@ - - - - - - - - lenstronomy.Plots.chain_plot — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Plots.chain_plot

-import copy
-
-import matplotlib.pyplot as plt
-import numpy as np
-from mpl_toolkits.axes_grid1 import make_axes_locatable
-
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -def plot_chain_list(chain_list, index=0, num_average=100): - """ - plots the output of a chain of samples (MCMC or PSO) with the some diagnostics of convergence. - This routine is an example and more tests might be appropriate to analyse a specific chain. - - :param chain_list: list of chains with arguments [type string, samples etc...] - :param index: index of chain to be plotted - :param num_average: in chains, number of steps to average over in plotting diagnostics - :return: plotting instance - """ - chain_i = chain_list[index] - chain_type = chain_i[0] - if chain_type == 'PSO': - chain, param = chain_i[1:] - f, axes = plot_chain(chain, param) - elif chain_type == 'EMCEE': - samples, param, dist = chain_i[1:] - f, ax = plt.subplots(1, 1, figsize=(6, 6)) - axes = plot_mcmc_behaviour(ax, samples, param, dist, num_average=num_average) - elif chain_type in ['MULTINEST', 'DYPOLYCHORD', 'DYNESTY']: - samples, param, dist = chain_i[1:4] - f, ax = plt.subplots(1, 1, figsize=(6, 6)) - axes = plot_mcmc_behaviour(ax, samples, param, dist, num_average=num_average) - else: - raise ValueError('chain_type %s not supported for plotting' % chain_type) - return f, axes
- - -
[docs]@export -def plot_chain(chain, param_list): - chi2_list, pos_list, vel_list = chain - - f, axes = plt.subplots(1, 3, figsize=(18, 6)) - ax = axes[0] - ax.plot(np.log10(-np.array(chi2_list))) - ax.set_title('-logL') - - ax = axes[1] - pos = np.array(pos_list) - vel = np.array(vel_list) - n_iter = len(pos) - plt.figure() - for i in range(0, len(pos[0])): - ax.plot((pos[:, i]-pos[n_iter-1, i]) / (pos[n_iter-1, i] + 1), label=param_list[i]) - ax.set_title('particle position') - ax.legend() - - ax = axes[2] - for i in range(0, len(vel[0])): - ax.plot(vel[:, i] / (pos[n_iter-1, i] + 1), label=param_list[i]) - ax.set_title('param velocity') - ax.legend() - return f, axes
- - -
[docs]@export -def plot_mcmc_behaviour(ax, samples_mcmc, param_mcmc, dist_mcmc=None, num_average=100): - """ - plots the MCMC behaviour and looks for convergence of the chain - - :param ax: matplotlib.axis instance - :param samples_mcmc: parameters sampled 2d numpy array - :param param_mcmc: list of parameters - :param dist_mcmc: log likelihood of the chain - :param num_average: number of samples to average (should coincide with the number of samples in the emcee process) - :return: - """ - num_samples = len(samples_mcmc[:, 0]) - num_average = int(num_average) - n_points = int((num_samples - num_samples % num_average) / num_average) - for i, param_name in enumerate(param_mcmc): - samples = samples_mcmc[:, i] - samples_averaged = np.average(samples[:int(n_points * num_average)].reshape(n_points, num_average), axis=1) - end_point = np.mean(samples_averaged) - samples_renormed = (samples_averaged - end_point) / np.std(samples_averaged) - ax.plot(samples_renormed, label=param_name) - - if dist_mcmc is not None: - dist_averaged = -np.max(dist_mcmc[:int(n_points * num_average)].reshape(n_points, num_average), axis=1) - dist_normed = (dist_averaged - np.max(dist_averaged)) / (np.max(dist_averaged) - np.min(dist_averaged)) - ax.plot(dist_normed, label="logL", color='k', linewidth=2) - ax.legend() - return ax
- - -
[docs]@export -def psf_iteration_compare(kwargs_psf, **kwargs): - """ - - :param kwargs_psf: - :param kwargs: kwargs to send to matplotlib.pyplot.matshow() - :return: - """ - psf_out = kwargs_psf['kernel_point_source'] - psf_in = kwargs_psf['kernel_point_source_init'] - psf_error_map = kwargs_psf.get('psf_error_map', None) - n_kernel = len(psf_in) - delta_x = n_kernel/20. - delta_y = n_kernel/10. - - if 'cmap' not in kwargs: - kwargs['cmap'] = 'seismic' - - n = 3 - if psf_error_map is not None: - n += 1 - f, axes = plt.subplots(1, n, figsize=(5*n, 5)) - ax = axes[0] - im = ax.matshow(np.log10(psf_in), origin='lower', **kwargs) - v_min, v_max = im.get_clim() - if 'vmin' not in kwargs: - kwargs['vmin'] = v_min - if 'vmax' not in kwargs: - kwargs['vmax'] = v_max - divider = make_axes_locatable(ax) - cax = divider.append_axes("right", size="5%", pad=0.05) - plt.colorbar(im, cax=cax) - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) - ax.text(delta_x, n_kernel-delta_y, "Initial PSF model", color="k", fontsize=20, backgroundcolor='w') - - ax = axes[1] - im = ax.matshow(np.log10(psf_out), origin='lower', **kwargs) - divider = make_axes_locatable(ax) - cax = divider.append_axes("right", size="5%", pad=0.05) - plt.colorbar(im, cax=cax) - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) - ax.text(delta_x, n_kernel-delta_y, "iterative reconstruction", color="k", fontsize=20, backgroundcolor='w') - - ax = axes[2] - kwargs_new = copy.deepcopy(kwargs) - - del kwargs_new['vmin'] - del kwargs_new['vmax'] - - im = ax.matshow(psf_out-psf_in, origin='lower', vmin=-10**-3, vmax=10**-3, **kwargs_new) - divider = make_axes_locatable(ax) - cax = divider.append_axes("right", size="5%", pad=0.05) - plt.colorbar(im, cax=cax) - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) - ax.text(delta_x, n_kernel-delta_y, "difference", color="k", fontsize=20, backgroundcolor='w') - - if psf_error_map is not None: - ax = axes[3] - im = ax.matshow(np.log10(psf_error_map*psf_out**2), origin='lower', **kwargs) - divider = make_axes_locatable(ax) - cax = divider.append_axes("right", size="5%", pad=0.05) - plt.colorbar(im, cax=cax) - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) - ax.text(delta_x, n_kernel - delta_y, "psf error map", color="k", fontsize=20, backgroundcolor='w') - - f.tight_layout() - return f, axes
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Plots/lens_plot.html b/docs/_build/html/_modules/lenstronomy/Plots/lens_plot.html deleted file mode 100644 index 45c0123b7..000000000 --- a/docs/_build/html/_modules/lenstronomy/Plots/lens_plot.html +++ /dev/null @@ -1,528 +0,0 @@ - - - - - - - - lenstronomy.Plots.lens_plot — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Plots.lens_plot

-
-import lenstronomy.Util.util as util
-import lenstronomy.Util.simulation_util as sim_util
-import matplotlib.pyplot as plt
-import numpy as np
-from mpl_toolkits.axes_grid1 import make_axes_locatable
-from lenstronomy.LensModel.lens_model_extensions import LensModelExtensions
-from lenstronomy.LensModel.Profiles.curved_arc_spp import center_deflector
-from lenstronomy.Data.imaging_data import ImageData
-from lenstronomy.Plots import plot_util
-import scipy.ndimage as ndimage
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-# TODO define coordinate grid beforehand, e.g. kwargs_data
-
-
[docs]@export -def lens_model_plot(ax, lensModel, kwargs_lens, numPix=500, deltaPix=0.01, sourcePos_x=0, sourcePos_y=0, - point_source=False, with_caustics=False, with_convergence=True, coord_center_ra=0, - coord_center_dec=0, coord_inverse=False, fast_caustic=True, **kwargs): - """ - plots a lens model (convergence) and the critical curves and caustics - - :param ax: matplotlib axis instance - :param lensModel: LensModel() class instance - :param kwargs_lens: lens model keyword argument list - :param numPix: total nnumber of pixels (for convergence map) - :param deltaPix: width of pixel (total frame size is deltaPix x numPix) - :param sourcePos_x: float, x-position of point source (image positions computed by the lens equation) - :param sourcePos_y: float, y-position of point source (image positions computed by the lens equation) - :param point_source: bool, if True, illustrates and computes the image positions of the point source - :param with_caustics: bool, if True, illustrates the critical curve and caustics of the system - :param with_convergence: bool, if True, illustrates the convergence map - :param coord_center_ra: float, x-coordinate of the center of the frame - :param coord_center_dec: float, y-coordinate of the center of the frame - :param coord_inverse: bool, if True, inverts the x-coordinates to go from right-to-left - (effectively the RA definition) - :param fast_caustic: boolean, if True, uses faster but less precise caustic calculation - (might have troubles for the outer caustic (inner critical curve) - :param with_convergence: boolean, if True, plots the convergence of the deflector - :return: - """ - kwargs_data = sim_util.data_configure_simple(numPix, deltaPix, center_ra=coord_center_ra, center_dec=coord_center_dec, - inverse=coord_inverse) - data = ImageData(**kwargs_data) - _coords = data - _frame_size = numPix * deltaPix - - ra0, dec0 = data.radec_at_xy_0 - if coord_inverse: - extent = [ra0, ra0 - _frame_size, dec0, dec0 + _frame_size] - else: - extent = [ra0, ra0 + _frame_size, dec0, dec0 + _frame_size] - - if with_convergence: - kwargs_convergence = kwargs.get('kwargs_convergence', {}) - convergence_plot(ax, pixel_grid=_coords, lens_model=lensModel, kwargs_lens=kwargs_lens, extent=extent, - **kwargs_convergence) - if with_caustics is True: - kwargs_caustics = kwargs.get('kwargs_caustics', {}) - caustics_plot(ax, pixel_grid=_coords, lens_model=lensModel, kwargs_lens=kwargs_lens, fast_caustic=fast_caustic, - coord_inverse=coord_inverse, pixel_offset=True, **kwargs_caustics) - if point_source: - kwargs_point_source = kwargs.get('kwargs_point_source', {}) - point_source_plot(ax, pixel_grid=_coords, lens_model=lensModel, kwargs_lens=kwargs_lens, - source_x=sourcePos_x, source_y=sourcePos_y, **kwargs_point_source) - if coord_inverse: - ax.set_xlim([ra0, ra0 - _frame_size]) - else: - ax.set_xlim([ra0, ra0 + _frame_size]) - ax.set_ylim([dec0, dec0 + _frame_size]) - # ax.get_xaxis().set_visible(False) - # ax.get_yaxis().set_visible(False) - ax.autoscale(False) - return ax
- - -def convergence_plot(ax, pixel_grid, lens_model, kwargs_lens, extent=None, vmin=-1, vmax=1, cmap='Greys', **kwargs): - """ - plot convergence - - :param ax: matplotlib axis instance - :param pixel_grid: lenstronomy PixelGrid() instance (or class with inheritance of PixelGrid() - :param lens_model: LensModel() class instance - :param kwargs_lens: lens model keyword argument list - :param extent: [[min, max] [min, max]] of frame - :param vmin: matplotlib vmin - :param vmax: matplotlib vmax - :param cmap: matplotlib cmap - :param kwargs: keyword arguments for matshow - :return: matplotlib axis instance with convergence plot - """ - x_grid, y_grid = pixel_grid.pixel_coordinates - x_grid1d = util.image2array(x_grid) - y_grid1d = util.image2array(y_grid) - kappa_result = lens_model.kappa(x_grid1d, y_grid1d, kwargs_lens) - kappa_result = util.array2image(kappa_result) - _ = ax.matshow(np.log10(kappa_result), origin='lower', extent=extent, cmap=cmap, vmin=vmin, vmax=vmax, **kwargs) - return ax - - -def caustics_plot(ax, pixel_grid, lens_model, kwargs_lens, fast_caustic=True, coord_inverse=False, color_crit='r', - color_caustic='g', pixel_offset=False, *args, **kwargs): - """ - - :param ax: matplotlib axis instance - :param pixel_grid: lenstronomy PixelGrid() instance (or class with inheritance of PixelGrid() - :param lens_model: LensModel() class instance - :param kwargs_lens: lens model keyword argument list - :param fast_caustic: boolean, if True, uses faster but less precise caustic calculation - (might have troubles for the outer caustic (inner critical curve) - :param coord_inverse: bool, if True, inverts the x-coordinates to go from right-to-left - (effectively the RA definition) - :param color_crit: string, color of critical curve - :param color_caustic: string, color of caustic curve - :param pixel_offset: boolean; if True (default plotting), the coordinates are shifted a half a pixel to match with - the matshow() command to center the coordinates in the pixel center - :param args: argument for plotting curve - :param kwargs: keyword arguments for plotting curves - :return: updated matplotlib axis instance - """ - lens_model_ext = LensModelExtensions(lens_model) - pixel_width = pixel_grid.pixel_width - frame_size = np.max(pixel_grid.width) - coord_center_ra, coord_center_dec = pixel_grid.center - ra0, dec0 = pixel_grid.radec_at_xy_0 - origin = [ra0, dec0] - if fast_caustic: - ra_crit_list, dec_crit_list, ra_caustic_list, dec_caustic_list = lens_model_ext.critical_curve_caustics( - kwargs_lens, compute_window=frame_size, grid_scale=pixel_width, center_x=coord_center_ra, - center_y=coord_center_dec) - points_only = False - else: - # only supports individual points due to output of critical_curve_tiling definition - points_only = True - ra_crit_list, dec_crit_list = lens_model_ext.critical_curve_tiling(kwargs_lens, compute_window=frame_size, - start_scale=pixel_width, max_order=10, - center_x=coord_center_ra, - center_y=coord_center_dec) - ra_caustic_list, dec_caustic_list = lens_model.ray_shooting(ra_crit_list, dec_crit_list, kwargs_lens) - # ra_crit_list, dec_crit_list = list(ra_crit_list), list(dec_crit_list) - # ra_caustic_list, dec_caustic_list = list(ra_caustic_list), list(dec_caustic_list) - plot_util.plot_line_set(ax, pixel_grid, ra_caustic_list, dec_caustic_list, color=color_caustic, origin=origin, - flipped_x=coord_inverse, points_only=points_only, pixel_offset=pixel_offset, *args, - **kwargs) - plot_util.plot_line_set(ax, pixel_grid, ra_crit_list, dec_crit_list, color=color_crit, origin=origin, - flipped_x=coord_inverse, points_only=points_only, pixel_offset=pixel_offset, *args, - **kwargs) - return ax - - -def point_source_plot(ax, pixel_grid, lens_model, kwargs_lens, source_x, source_y, **kwargs): - """ - plots and illustrates images of a point source - The plotting routine orders the image labels according to the arrival time and illustrates a diamond shape of the - size of the magnification. The coordinates are chosen in pixel coordinates - - :param ax: matplotlib axis instance - :param pixel_grid: lenstronomy PixelGrid() instance (or class with inheritance of PixelGrid() - :param lens_model: LensModel() class instance - :param kwargs_lens: lens model keyword argument list - :param source_x: x-position of source - :param source_y: y-position of source - :param kwargs: additional plotting keyword arguments - :return: matplotlib axis instance with figure - """ - from lenstronomy.LensModel.Solver.lens_equation_solver import LensEquationSolver - solver = LensEquationSolver(lens_model) - x_center, y_center = pixel_grid.center - delta_pix = pixel_grid.pixel_width - ra0, dec0 = pixel_grid.radec_at_xy_0 - tranform = pixel_grid.transform_angle2pix - if np.linalg.det(tranform) < 0: # if coordiate transform has negative parity (#TODO temporary fix) - delta_pix_x = -delta_pix - else: - delta_pix_x = delta_pix - origin = [ra0, dec0] - - theta_x, theta_y = solver.image_position_from_source(source_x, source_y, kwargs_lens, - search_window=np.max(pixel_grid.width), x_center=x_center, - y_center=y_center, min_distance=pixel_grid.pixel_width) - mag_images = lens_model.magnification(theta_x, theta_y, kwargs_lens) - - x_image, y_image = pixel_grid.map_coord2pix(theta_x, theta_y) - abc_list = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'] - for i in range(len(x_image)): - x_ = (x_image[i] + 0.5) * delta_pix_x + origin[0] - y_ = (y_image[i] + 0.5) * delta_pix + origin[1] - ax.plot(x_, y_, 'dk', markersize=4 * (1 + np.log(np.abs(mag_images[i]))), alpha=0.5) - ax.text(x_, y_, abc_list[i], fontsize=20, color='k') - x_source, y_source = pixel_grid.map_coord2pix(source_x, source_y) - ax.plot((x_source + 0.5) * delta_pix_x + origin[0], (y_source + 0.5) * delta_pix + origin[1], '*k', markersize=10) - return ax - - -
[docs]@export -def arrival_time_surface(ax, lensModel, kwargs_lens, numPix=500, deltaPix=0.01, sourcePos_x=0, sourcePos_y=0, - with_caustics=False, point_source=False, n_levels=10, kwargs_contours=None, - image_color_list=None, letter_font_size=20): - """ - - :param ax: matplotlib axis instance - :param lensModel: LensModel() class instance - :param kwargs_lens: lens model keyword argument list - :param numPix: - :param deltaPix: - :param sourcePos_x: - :param sourcePos_y: - :param with_caustics: - :return: - """ - kwargs_data = sim_util.data_configure_simple(numPix, deltaPix) - data = ImageData(**kwargs_data) - ra0, dec0 = data.radec_at_xy_0 - origin = [ra0, dec0] - _frame_size = numPix * deltaPix - _coords = data - x_grid, y_grid = data.pixel_coordinates - lensModelExt = LensModelExtensions(lensModel) - #ra_crit_list, dec_crit_list, ra_caustic_list, dec_caustic_list = lensModelExt.critical_curve_caustics( - # kwargs_lens, compute_window=_frame_size, grid_scale=deltaPix/2.) - x_grid1d = util.image2array(x_grid) - y_grid1d = util.image2array(y_grid) - fermat_surface = lensModel.fermat_potential(x_grid1d, y_grid1d, kwargs_lens, sourcePos_x, sourcePos_y) - fermat_surface = util.array2image(fermat_surface) - if kwargs_contours is None: - kwargs_contours = {} - - #, cmap='Greys', vmin=-1, vmax=1) #, cmap=self._cmap, vmin=v_min, vmax=v_max) - if with_caustics is True: - ra_crit_list, dec_crit_list = lensModelExt.critical_curve_tiling(kwargs_lens, compute_window=_frame_size, - start_scale=deltaPix/5, max_order=10) - ra_caustic_list, dec_caustic_list = lensModel.ray_shooting(ra_crit_list, dec_crit_list, kwargs_lens) - plot_util.plot_line_set(ax, _coords, ra_caustic_list, dec_caustic_list, origin=origin, color='g') - plot_util.plot_line_set(ax, _coords, ra_crit_list, dec_crit_list, origin=origin, color='r') - if point_source is True: - from lenstronomy.LensModel.Solver.lens_equation_solver import LensEquationSolver - solver = LensEquationSolver(lensModel) - theta_x, theta_y = solver.image_position_from_source(sourcePos_x, sourcePos_y, kwargs_lens, - min_distance=deltaPix, search_window=deltaPix*numPix) - - fermat_pot_images = lensModel.fermat_potential(theta_x, theta_y, kwargs_lens) - _ = ax.contour(x_grid, y_grid, fermat_surface, origin='lower', # extent=[0, _frame_size, 0, _frame_size], - levels=np.sort(fermat_pot_images), **kwargs_contours) - # mag_images = lensModel.magnification(theta_x, theta_y, kwargs_lens) - x_image, y_image = _coords.map_coord2pix(theta_x, theta_y) - abc_list = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'] - - for i in range(len(x_image)): - x_ = (x_image[i] + 0.5) * deltaPix - _frame_size/2 - y_ = (y_image[i] + 0.5) * deltaPix - _frame_size/2 - if image_color_list is None: - color = 'k' - else: - color = image_color_list[i] - ax.plot(x_, y_, 'x', markersize=10, alpha=1, color=color) # markersize=8*(1 + np.log(np.abs(mag_images[i]))) - ax.text(x_ + deltaPix, y_ + deltaPix, abc_list[i], fontsize=letter_font_size, color='k') - x_source, y_source = _coords.map_coord2pix(sourcePos_x, sourcePos_y) - ax.plot((x_source + 0.5) * deltaPix - _frame_size/2, (y_source + 0.5) * deltaPix - _frame_size/2, '*k', markersize=20) - else: - vmin = np.min(fermat_surface) - vmax = np.max(fermat_surface) - levels = np.linspace(start=vmin, stop=vmax, num=n_levels) - im = ax.contour(x_grid, y_grid, fermat_surface, origin='lower', # extent=[0, _frame_size, 0, _frame_size], - levels=levels, **kwargs_contours) - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) - ax.autoscale(False) - return ax
- - -
[docs]@export -def curved_arc_illustration(ax, lensModel, kwargs_lens, with_centroid=True, stretch_scale=0.1, color='k'): - """ - - :param ax: matplotlib axis instance - :param lensModel: LensModel() instance - :param kwargs_lens: list of lens model keyword arguments (only those of CURVED_ARC considered - :param with_centroid: plots the center of the curvature radius - :param stretch_scale: float, relative scale of banana to the tangential and radial stretches (effectively intrinsic source size) - :param color: string, matplotlib color for plot - :return: matplotlib axis instance - """ - - # loop through lens models - # check whether curved arc - lens_model_list = lensModel.lens_model_list - for i, lens_type in enumerate(lens_model_list): - if lens_type in ['CURVED_ARC', 'CURVED_ARC_SIS_MST', 'CURVED_ARC_CONST', 'CURVED_ARC_CONST_MST', - 'CURVED_ARC_SPT', 'CURVED_ARC_TAN_DIFF']: - plot_arc(ax, with_centroid=with_centroid, stretch_scale=stretch_scale, color=color, **kwargs_lens[i]) - - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) - ax.autoscale(False) - # rectangular frame - ax.axis('scaled')
- - # plot coordinate frame and scale - - -
[docs]@export -def plot_arc(ax, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y, stretch_scale=0.1, - with_centroid=True, linewidth=1, color='k', dtan_dtan=0): - """ - - :param ax: matplotlib.axes instance - :param tangential_stretch: float, stretch of intrinsic source in tangential direction - :param radial_stretch: float, stretch of intrinsic source in radial direction - :param curvature: 1/curvature radius - :param direction: float, angle in radian - :param center_x: center of source in image plane - :param center_y: center of source in image plane - :param with_centroid: plots the center of the curvature radius - :param stretch_scale: float, relative scale of banana to the tangential and radial stretches - (effectively intrinsic source size) - :param dtan_dtan: tangential eigenvector differential in tangential direction (not implemented yet as illustration) - :return: - """ - # plot line to centroid - center_x_spp, center_y_spp = center_deflector(curvature, direction, center_x, center_y) - if with_centroid: - ax.plot([center_x, center_x_spp], [center_y, center_y_spp], '--', color=color, alpha=0.5, linewidth=linewidth) - ax.plot([center_x_spp], [center_y_spp], '*', color=color, alpha=0.5, linewidth=linewidth) - - # plot radial stretch to scale - x_r = np.cos(direction) * radial_stretch * stretch_scale - y_r = np.sin(direction) * radial_stretch * stretch_scale - ax.plot([center_x - x_r, center_x + x_r], [center_y - y_r, center_y + y_r], '--', color=color, linewidth=linewidth) - - # compute angle of size of the tangential stretch - r = 1. / curvature - - # make sure tangential stretch * stretch_scale is not larger than r * 2pi such that the full circle is only plotted once - tangential_stretch_ = min(tangential_stretch, np.pi * r / stretch_scale) - d_phi = tangential_stretch_ * stretch_scale / r - - # linearly interpolate angle around center - phi = np.linspace(-1, 1, 50) * d_phi + direction - # plot points on circle - x_curve = r * np.cos(phi) + center_x_spp - y_curve = r * np.sin(phi) + center_y_spp - ax.plot(x_curve, y_curve, '--', color=color, linewidth=linewidth) - - # make round circle with start point to end to close the circle - r_c, t_c = util.points_on_circle(radius=stretch_scale, num_points=200) - r_c = radial_stretch * r_c + r - phi_c = t_c * tangential_stretch_ / r_c + direction - x_c = r_c * np.cos(phi_c) + center_x_spp - y_c = r_c * np.sin(phi_c) + center_y_spp - ax.plot(x_c, y_c, '-', color=color, linewidth=linewidth) - return ax
- - # TODO add different colors for each quarter to identify parities - - -
[docs]@export -def distortions(lensModel, kwargs_lens, num_pix=100, delta_pix=0.05, center_ra=0, center_dec=0, - differential_scale=0.0001, smoothing_scale=None, **kwargs): - """ - - :param lensModel: LensModel instance - :param kwargs_lens: lens model keyword argument list - :param num_pix: number of pixels per axis - :param delta_pix: pixel scale per axis - :param center_ra: center of the grid - :param center_dec: center of the grid - :param differential_scale: scale of the finite derivative length in units of angles - :param smoothing_scale: float or None, Gaussian FWHM of a smoothing kernel applied before plotting - :return: matplotlib instance with different panels - """ - kwargs_grid = sim_util.data_configure_simple(num_pix, delta_pix, center_ra=center_ra, center_dec=center_dec) - _coords = ImageData(**kwargs_grid) - _frame_size = num_pix * delta_pix - ra_grid, dec_grid = _coords.pixel_coordinates - - extensions = LensModelExtensions(lensModel=lensModel) - ra_grid1d = util.image2array(ra_grid) - dec_grid1d = util.image2array(dec_grid) - lambda_rad, lambda_tan, orientation_angle, dlambda_tan_dtan, dlambda_tan_drad, dlambda_rad_drad, dlambda_rad_dtan, dphi_tan_dtan, dphi_tan_drad, dphi_rad_drad, dphi_rad_dtan = extensions.radial_tangential_differentials( - ra_grid1d, dec_grid1d, kwargs_lens=kwargs_lens, center_x=center_ra, center_y=center_dec, smoothing_3rd=differential_scale, smoothing_2nd=None) - - lambda_rad2d, lambda_tan2d, orientation_angle2d, dlambda_tan_dtan2d, dlambda_tan_drad2d, dlambda_rad_drad2d, dlambda_rad_dtan2d, dphi_tan_dtan2d, dphi_tan_drad2d, dphi_rad_drad2d, dphi_rad_dtan2d = util.array2image(lambda_rad), \ - util.array2image(lambda_tan), util.array2image(orientation_angle), util.array2image(dlambda_tan_dtan), util.array2image(dlambda_tan_drad), util.array2image(dlambda_rad_drad), util.array2image(dlambda_rad_dtan), \ - util.array2image(dphi_tan_dtan), util.array2image(dphi_tan_drad), util.array2image(dphi_rad_drad), util.array2image(dphi_rad_dtan) - - if smoothing_scale is not None: - lambda_rad2d = ndimage.gaussian_filter(lambda_rad2d, sigma=smoothing_scale/delta_pix) - dlambda_rad_drad2d = ndimage.gaussian_filter(dlambda_rad_drad2d, sigma=smoothing_scale/delta_pix) - lambda_tan2d = np.abs(lambda_tan2d) - # the magnification cut is made to make a stable integral/convolution - lambda_tan2d[lambda_tan2d > 100] = 100 - lambda_tan2d = ndimage.gaussian_filter(lambda_tan2d, sigma=smoothing_scale/delta_pix) - # the magnification cut is made to make a stable integral/convolution - dlambda_tan_dtan2d[dlambda_tan_dtan2d > 100] = 100 - dlambda_tan_dtan2d[dlambda_tan_dtan2d < -100] = -100 - dlambda_tan_dtan2d = ndimage.gaussian_filter(dlambda_tan_dtan2d, sigma=smoothing_scale/delta_pix) - orientation_angle2d = ndimage.gaussian_filter(orientation_angle2d, sigma=smoothing_scale/delta_pix) - dphi_tan_dtan2d = ndimage.gaussian_filter(dphi_tan_dtan2d, sigma=smoothing_scale/delta_pix) - - def _plot_frame(ax, map, vmin, vmax, text_string): - """ - - :param ax: matplotlib.axis instance - :param map: 2d array - :param vmin: minimum plotting scale - :param vmax: maximum plotting scale - :param text_string: string to describe the label - :return: - """ - font_size = 10 - _arrow_size = 0.02 - im = ax.matshow(map, extent=[0, _frame_size, 0, _frame_size], vmin=vmin, vmax=vmax) - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) - ax.autoscale(False) - divider = make_axes_locatable(ax) - cax = divider.append_axes("right", size="5%", pad=0.05) - cb = plt.colorbar(im, cax=cax, orientation='vertical') - #cb.set_label(text_string, fontsize=10) - #plot_util.scale_bar(ax, _frame_size, dist=1, text='1"', font_size=font_size) - plot_util.text_description(ax, _frame_size, text=text_string, color="k", - backgroundcolor='w', font_size=font_size) - #if 'no_arrow' not in kwargs or not kwargs['no_arrow']: - # plot_util.coordinate_arrows(ax, _frame_size, _coords, - # color='w', arrow_size=_arrow_size, - # font_size=font_size) - - f, axes = plt.subplots(3, 4, figsize=(12, 8)) - _plot_frame(axes[0, 0], lambda_rad2d, vmin=0.6, vmax=1.4, text_string=r"$\lambda_{rad}$") - _plot_frame(axes[0, 1], lambda_tan2d, vmin=-20, vmax=20, text_string=r"$\lambda_{tan}$") - _plot_frame(axes[0, 2], orientation_angle2d, vmin=-np.pi / 10, vmax=np.pi / 10, text_string=r"$\phi$") - _plot_frame(axes[0, 3], util.array2image(lambda_tan * lambda_rad), vmin=-20, vmax=20, text_string='magnification') - _plot_frame(axes[1, 0], dlambda_rad_drad2d/lambda_rad2d, vmin=-.1, vmax=.1, text_string='dlambda_rad_drad') - _plot_frame(axes[1, 1], dlambda_tan_dtan2d/lambda_tan2d, vmin=-20, vmax=20, text_string='dlambda_tan_dtan') - _plot_frame(axes[1, 2], dlambda_tan_drad2d/lambda_tan2d, vmin=-20, vmax=20, text_string='dlambda_tan_drad') - _plot_frame(axes[1, 3], dlambda_rad_dtan2d/lambda_rad2d, vmin=-.1, vmax=.1, text_string='dlambda_rad_dtan') - - _plot_frame(axes[2, 0], dphi_rad_drad2d, vmin=-.1, vmax=.1, text_string='dphi_rad_drad') - _plot_frame(axes[2, 1], dphi_tan_dtan2d, vmin=0, vmax=20, text_string='dphi_tan_dtan: curvature radius') - _plot_frame(axes[2, 2], dphi_tan_drad2d, vmin=-.1, vmax=.1, text_string='dphi_tan_drad') - _plot_frame(axes[2, 3], dphi_rad_dtan2d, vmin=0, vmax=20, text_string='dphi_rad_dtan') - - return f, axes
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Plots/model_band_plot.html b/docs/_build/html/_modules/lenstronomy/Plots/model_band_plot.html deleted file mode 100644 index 1ebd0de6b..000000000 --- a/docs/_build/html/_modules/lenstronomy/Plots/model_band_plot.html +++ /dev/null @@ -1,704 +0,0 @@ - - - - - - - - lenstronomy.Plots.model_band_plot — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Plots.model_band_plot

-
-import lenstronomy.Util.util as util
-import matplotlib.pyplot as plt
-import numpy as np
-from mpl_toolkits.axes_grid1 import make_axes_locatable
-from lenstronomy.LensModel.lens_model_extensions import LensModelExtensions
-from lenstronomy.Data.coord_transforms import Coordinates
-from lenstronomy.Plots import plot_util
-from lenstronomy.Analysis.image_reconstruction import ModelBand
-
-__all__ = ['ModelBandPlot']
-
-
-
[docs]class ModelBandPlot(ModelBand): - """ - class to plot a single band given the modeling results - - """ - def __init__(self, multi_band_list, kwargs_model, model, error_map, cov_param, param, kwargs_params, - likelihood_mask_list=None, band_index=0, arrow_size=0.02, cmap_string="gist_heat", - fast_caustic=True): - """ - - :param multi_band_list: list of imaging data configuration [[kwargs_data, kwargs_psf, kwargs_numerics], [...]] - :param kwargs_model: model keyword argument list for the full multi-band modeling - :param model: 2d numpy array of modeled image for the specified band - :param error_map: 2d numpy array of size of the image, additional error in the pixels coming from PSF uncertainties - :param cov_param: covariance matrix of the linear inversion - :param param: 1d numpy array of the linear coefficients of this imaging band - :param kwargs_params: keyword argument of keyword argument lists of the different model components selected for - the imaging band, NOT including linear amplitudes (not required as being overwritten by the param list) - :param likelihood_mask_list: list of 2d numpy arrays of likelihood masks (for all bands) - :param band_index: integer of the band to be considered in this class - :param arrow_size: size of the scale and orientation arrow - :param cmap_string: string of color map (or cmap matplotlib object) - :param fast_caustic: boolean; if True, uses fast (but less accurate) caustic calculation method - """ - ModelBand.__init__(self, multi_band_list, kwargs_model, model, error_map, cov_param, param, kwargs_params, - image_likelihood_mask_list=likelihood_mask_list, band_index=band_index) - - self._lensModel = self._bandmodel.LensModel - self._lensModelExt = LensModelExtensions(self._lensModel) - log_model = np.log10(model) - log_model[np.isnan(log_model)] = -5 - self._v_min_default = max(np.min(log_model), -5) - self._v_max_default = min(np.max(log_model), 10) - self._coords = self._bandmodel.Data - self._data = self._coords.data - self._deltaPix = self._coords.pixel_width - self._frame_size = np.max(self._coords.width) - x_grid, y_grid = self._coords.pixel_coordinates - self._x_grid = util.image2array(x_grid) - self._y_grid = util.image2array(y_grid) - self._x_center, self._y_center = self._coords.center - - self._cmap = plot_util.cmap_conf(cmap_string) - self._arrow_size = arrow_size - self._fast_caustic = fast_caustic - - def _critical_curves(self): - if not hasattr(self, '_ra_crit_list') or not hasattr(self, '_dec_crit_list'): - #self._ra_crit_list, self._dec_crit_list, self._ra_caustic_list, self._dec_caustic_list = self._lensModelExt.critical_curve_caustics( - # self._kwargs_lens_partial, compute_window=self._frame_size, grid_scale=self._deltaPix / 5., - # center_x=self._x_center, center_y=self._y_center) - if self._fast_caustic: - self._ra_crit_list, self._dec_crit_list, self._ra_caustic_list, self._dec_caustic_list = self._lensModelExt.critical_curve_caustics( - self._kwargs_lens_partial, compute_window=self._frame_size, grid_scale=self._deltaPix, - center_x=self._x_center, center_y=self._y_center) - self._caustic_points_only = False - else: - # only supports individual points due to output of critical_curve_tiling definition - self._caustic_points_only = True - self._ra_crit_list, self._dec_crit_list = self._lensModelExt.critical_curve_tiling( - self._kwargs_lens_partial, - compute_window=self._frame_size, - start_scale=self._deltaPix / 5., - max_order=10, - center_x=self._x_center, - center_y=self._y_center) - self._ra_caustic_list, self._dec_caustic_list = self._lensModel.ray_shooting(self._ra_crit_list, - self._dec_crit_list, - self._kwargs_lens_partial) - return self._ra_crit_list, self._dec_crit_list - - def _caustics(self): - if not hasattr(self, '_ra_caustic_list') or not hasattr(self, '_dec_caustic_list'): - _, _ = self._critical_curves() - return self._ra_caustic_list, self._dec_caustic_list - -
[docs] def data_plot(self, ax, v_min=None, v_max=None, text='Observed', - font_size=15, colorbar_label=r'log$_{10}$ flux', **kwargs): - """ - - :param ax: - :return: - """ - if v_min is None: - v_min = self._v_min_default - if v_max is None: - v_max = self._v_max_default - im = ax.matshow(np.log10(self._data), origin='lower', - extent=[0, self._frame_size, 0, self._frame_size], cmap=self._cmap, vmin=v_min, vmax=v_max) # , vmin=0, vmax=2 - - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) - ax.autoscale(False) - - plot_util.scale_bar(ax, self._frame_size, dist=1, text='1"', font_size=font_size) - plot_util.text_description(ax, self._frame_size, text=text, color="w", - backgroundcolor='k', font_size=font_size) - - if 'no_arrow' not in kwargs or not kwargs['no_arrow']: - plot_util.coordinate_arrows(ax, self._frame_size, self._coords, color='w', - arrow_size=self._arrow_size, font_size=font_size) - - divider = make_axes_locatable(ax) - cax = divider.append_axes("right", size="5%", pad=0.05) - cb = plt.colorbar(im, cax=cax, orientation='vertical') - cb.set_label(colorbar_label, fontsize=font_size) - return ax
- -
[docs] def model_plot(self, ax, v_min=None, v_max=None, image_names=False, - colorbar_label=r'log$_{10}$ flux', - font_size=15, text='Reconstructed', **kwargs): - """ - - :param ax: matplotib axis instance - :param v_min: - :param v_max: - :return: - """ - if v_min is None: - v_min = self._v_min_default - if v_max is None: - v_max = self._v_max_default - im = ax.matshow(np.log10(self._model), origin='lower', vmin=v_min, vmax=v_max, - extent=[0, self._frame_size, 0, self._frame_size], cmap=self._cmap) - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) - ax.autoscale(False) - plot_util.scale_bar(ax, self._frame_size, dist=1, text='1"', font_size=font_size) - plot_util.text_description(ax, self._frame_size, text=text, color="w", - backgroundcolor='k', font_size=font_size) - if 'no_arrow' not in kwargs or not kwargs['no_arrow']: - plot_util.coordinate_arrows(ax, self._frame_size, self._coords, - color='w', arrow_size=self._arrow_size, - font_size=font_size) - divider = make_axes_locatable(ax) - cax = divider.append_axes("right", size="5%", pad=0.05) - cb = plt.colorbar(im, cax=cax) - cb.set_label(colorbar_label, fontsize=font_size) - - #plot_line_set(ax, self._coords, self._ra_caustic_list, self._dec_caustic_list, color='b') - #plot_line_set(ax, self._coords, self._ra_crit_list, self._dec_crit_list, color='r') - if image_names is True: - ra_image, dec_image = self._bandmodel.PointSource.image_position(self._kwargs_ps_partial, - self._kwargs_lens_partial, - original_position=kwargs.get('original_position', True)) - plot_util.image_position_plot(ax, self._coords, ra_image, dec_image, - image_name_list=kwargs.get('image_name_list', None))
- #source_position_plot(ax, self._coords, self._kwargs_source) - -
[docs] def convergence_plot(self, ax, text='Convergence', v_min=None, v_max=None, - font_size=15, colorbar_label=r'$\log_{10}\ \kappa$', - **kwargs): - """ - - :param ax: matplotib axis instance - :return: convergence plot in ax instance - """ - if not 'cmap' in kwargs: - kwargs['cmap'] = self._cmap - - kappa_result = util.array2image(self._lensModel.kappa(self._x_grid, self._y_grid, self._kwargs_lens_partial)) - im = ax.matshow(np.log10(kappa_result), origin='lower', - extent=[0, self._frame_size, 0, self._frame_size], - cmap=kwargs['cmap'], vmin=v_min, vmax=v_max) - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) - ax.autoscale(False) - plot_util.scale_bar(ax, self._frame_size, dist=1, text='1"', color='w', font_size=font_size) - if 'no_arrow' not in kwargs or not kwargs['no_arrow']: - plot_util.coordinate_arrows(ax, self._frame_size, self._coords, color='w', - arrow_size=self._arrow_size, font_size=font_size) - plot_util.text_description(ax, self._frame_size, text=text, - color="w", backgroundcolor='k', flipped=False, - font_size=font_size) - divider = make_axes_locatable(ax) - cax = divider.append_axes("right", size="5%", pad=0.05) - cb = plt.colorbar(im, cax=cax) - cb.set_label(colorbar_label, fontsize=font_size) - return ax
- -
[docs] def normalized_residual_plot(self, ax, v_min=-6, v_max=6, font_size=15, text="Normalized Residuals", - colorbar_label=r'(f${}_{\rm model}$ - f${}_{\rm data}$)/$\sigma$', - no_arrow=False, color_bar=True, **kwargs): - """ - - :param ax: - :param v_min: - :param v_max: - :param kwargs: kwargs to send to matplotlib.pyplot.matshow() - :param color_bar: Option to display the color bar - :return: - """ - if not 'cmap' in kwargs: - kwargs['cmap'] = 'bwr' - im = ax.matshow(self._norm_residuals, vmin=v_min, vmax=v_max, - extent=[0, self._frame_size, 0, self._frame_size], origin='lower', - **kwargs) - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) - ax.autoscale(False) - plot_util.scale_bar(ax, self._frame_size, dist=1, text='1"', color='k', - font_size=font_size) - plot_util.text_description(ax, self._frame_size, text=text, color="k", - backgroundcolor='w', font_size=font_size) - if not no_arrow: - plot_util.coordinate_arrows(ax, self._frame_size, self._coords, color='w', - arrow_size=self._arrow_size, font_size=font_size) - if color_bar : - divider = make_axes_locatable(ax) - cax = divider.append_axes("right", size="5%", pad=0.05) - cb = plt.colorbar(im, cax=cax) - cb.set_label(colorbar_label, - fontsize=font_size) - return ax
- -
[docs] def absolute_residual_plot(self, ax, v_min=-1, v_max=1, font_size=15, - text="Residuals", - colorbar_label=r'(f$_{model}$-f$_{data}$)'): - """ - - :param ax: - :return: - """ - im = ax.matshow(self._model - self._data, vmin=v_min, vmax=v_max, - extent=[0, self._frame_size, 0, self._frame_size], cmap='bwr', origin='lower') - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) - ax.autoscale(False) - plot_util.scale_bar(ax, self._frame_size, dist=1, text='1"', color='k', - font_size=font_size) - plot_util.text_description(ax, self._frame_size, text=text, color="k", - backgroundcolor='w', font_size=font_size) - plot_util.coordinate_arrows(ax, self._frame_size, self._coords, - font_size=font_size, - color='k', - arrow_size=self._arrow_size) - divider = make_axes_locatable(ax) - cax = divider.append_axes("right", size="5%", pad=0.05) - cb = plt.colorbar(im, cax=cax) - cb.set_label(colorbar_label, fontsize=font_size) - return ax
- -
[docs] def source(self, numPix, deltaPix, center=None, image_orientation=True): - """ - - :param numPix: number of pixels per axes - :param deltaPix: pixel size - :param image_orientation: bool, if True, uses frame in orientation of the image, otherwise in RA-DEC coordinates - :return: 2d surface brightness grid of the reconstructed source and Coordinates() instance of source grid - """ - if image_orientation is True: - Mpix2coord = self._coords.transform_pix2angle * deltaPix / self._deltaPix - x_grid_source, y_grid_source = util.make_grid_transformed(numPix, Mpix2Angle=Mpix2coord) - ra_at_xy_0, dec_at_xy_0 = x_grid_source[0], y_grid_source[0] - else: - x_grid_source, y_grid_source, ra_at_xy_0, dec_at_xy_0, x_at_radec_0, y_at_radec_0, Mpix2coord, Mcoord2pix = util.make_grid_with_coordtransform( - numPix, deltaPix) - - center_x = 0 - center_y = 0 - if center is not None: - center_x, center_y = center[0], center[1] - elif len(self._kwargs_source_partial) > 0: - center_x = self._kwargs_source_partial[0]['center_x'] - center_y = self._kwargs_source_partial[0]['center_y'] - x_grid_source += center_x - y_grid_source += center_y - - coords_source = Coordinates(transform_pix2angle=Mpix2coord, - ra_at_xy_0=ra_at_xy_0 + center_x, - dec_at_xy_0=dec_at_xy_0 + center_y) - - source = self._bandmodel.SourceModel.surface_brightness(x_grid_source, y_grid_source, - self._kwargs_source_partial) - source = util.array2image(source) * deltaPix ** 2 - return source, coords_source
- -
[docs] def source_plot(self, ax, numPix, deltaPix_source, center=None, v_min=None, - v_max=None, with_caustics=False, caustic_color='yellow', - font_size=15, plot_scale='log', - scale_size=0.1, - text="Reconstructed source", - colorbar_label=r'log$_{10}$ flux', point_source_position=True, - **kwargs): - """ - - :param ax: - :param numPix: - :param deltaPix_source: - :param center: [center_x, center_y], if specified, uses this as the center - :param v_min: - :param v_max: - :param caustic_color: - :param font_size: - :param plot_scale: string, log or linear, scale of surface brightness plot - :param kwargs: - :return: - """ - if v_min is None: - v_min = self._v_min_default - if v_max is None: - v_max = self._v_max_default - d_s = numPix * deltaPix_source - source, coords_source = self.source(numPix, deltaPix_source, center=center) - if plot_scale == 'log': - source[source < 10**v_min] = 10**(v_min) # to remove weird shadow in plot - source_scale = np.log10(source) - elif plot_scale == 'linear': - source_scale = source - else: - raise ValueError('variable plot_scale needs to be "log" or "linear", not %s.' % plot_scale) - im = ax.matshow(source_scale, origin='lower', extent=[0, d_s, 0, d_s], - cmap=self._cmap, vmin=v_min, vmax=v_max) # source - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) - ax.autoscale(False) - divider = make_axes_locatable(ax) - cax = divider.append_axes("right", size="5%", pad=0.05) - cb = plt.colorbar(im, cax=cax) - cb.set_label(colorbar_label, fontsize=font_size) - - if with_caustics is True: - ra_caustic_list, dec_caustic_list = self._caustics() - plot_util.plot_line_set(ax, coords_source, ra_caustic_list, dec_caustic_list, color=caustic_color, - points_only=self._caustic_points_only) - plot_util.plot_line_set(ax, coords_source, ra_caustic_list, dec_caustic_list, color=caustic_color, - points_only=self._caustic_points_only, **kwargs.get('kwargs_caustic', {})) - plot_util.scale_bar(ax, d_s, dist=scale_size, text='{:.1f}"'.format(scale_size), color='w', flipped=False, - font_size=font_size) - if 'no_arrow' not in kwargs or not kwargs['no_arrow']: - plot_util.coordinate_arrows(ax, self._frame_size, self._coords, color='w', - arrow_size=self._arrow_size, font_size=font_size) - plot_util.text_description(ax, d_s, text=text, color="w", backgroundcolor='k', - flipped=False, font_size=font_size) - if point_source_position is True: - ra_source, dec_source = self._bandmodel.PointSource.source_position(self._kwargs_ps_partial, self._kwargs_lens_partial) - plot_util.source_position_plot(ax, coords_source, ra_source, dec_source) - return ax
- -
[docs] def error_map_source_plot(self, ax, numPix, deltaPix_source, v_min=None, v_max=None, with_caustics=False, - font_size=15, point_source_position=True): - """ - plots the uncertainty in the surface brightness in the source from the linear inversion by taking the diagonal - elements of the covariance matrix of the inversion of the basis set to be propagated to the source plane. - #TODO illustration of the uncertainties in real space with the full covariance matrix is subtle. The best way is probably to draw realizations from the covariance matrix. - - :param ax: matplotlib axis instance - :param numPix: number of pixels in plot per axis - :param deltaPix_source: pixel spacing in the source resolution illustrated in plot - :param v_min: minimum plotting scale of the map - :param v_max: maximum plotting scale of the map - :param with_caustics: plot the caustics on top of the source reconstruction (may take some time) - :param font_size: font size of labels - :param point_source_position: boolean, if True, plots a point at the position of the point source - :return: plot of source surface brightness errors in the reconstruction on the axis instance - """ - x_grid_source, y_grid_source = util.make_grid_transformed(numPix, - self._coords.transform_pix2angle * deltaPix_source / self._deltaPix) - x_center = self._kwargs_source_partial[0]['center_x'] - y_center = self._kwargs_source_partial[0]['center_y'] - x_grid_source += x_center - y_grid_source += y_center - coords_source = Coordinates(self._coords.transform_pix2angle * deltaPix_source / self._deltaPix, ra_at_xy_0=x_grid_source[0], - dec_at_xy_0=y_grid_source[0]) - error_map_source = self._bandmodel.error_map_source(self._kwargs_source_partial, x_grid_source, y_grid_source, - self._cov_param, model_index_select=False) - error_map_source = util.array2image(error_map_source) - d_s = numPix * deltaPix_source - im = ax.matshow(error_map_source, origin='lower', extent=[0, d_s, 0, d_s], - cmap=self._cmap, vmin=v_min, vmax=v_max) # source - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) - ax.autoscale(False) - divider = make_axes_locatable(ax) - cax = divider.append_axes("right", size="5%", pad=0.05) - cb = plt.colorbar(im, cax=cax) - cb.set_label(r'error variance', fontsize=font_size) - if with_caustics: - ra_caustic_list, dec_caustic_list = self._caustics() - plot_util.plot_line_set(ax, coords_source, ra_caustic_list, dec_caustic_list, color='b', - points_only=self._caustic_points_only) - plot_util.scale_bar(ax, d_s, dist=0.1, text='0.1"', color='w', flipped=False, font_size=font_size) - plot_util.coordinate_arrows(ax, d_s, coords_source, arrow_size=self._arrow_size, color='w', font_size=font_size) - plot_util.text_description(ax, d_s, text="Error map in source", color="w", backgroundcolor='k', flipped=False, - font_size=font_size) - if point_source_position is True: - ra_source, dec_source = self._bandmodel.PointSource.source_position(self._kwargs_ps_partial, self._kwargs_lens_partial) - plot_util.source_position_plot(ax, coords_source, ra_source, dec_source) - return ax
- -
[docs] def magnification_plot(self, ax, v_min=-10, v_max=10, - image_name_list=None, font_size=15, no_arrow=False, - text="Magnification model", - colorbar_label=r"$\det\ (\mathsf{A}^{-1})$", - **kwargs): - """ - - :param ax: matplotib axis instance - :param v_min: minimum range of plotting - :param v_max: maximum range of plotting - :param kwargs: kwargs to send to matplotlib.pyplot.matshow() - :return: - """ - if 'cmap' not in kwargs: - kwargs['cmap'] = self._cmap - if 'alpha' not in kwargs: - kwargs['alpha'] = 0.5 - mag_result = util.array2image(self._lensModel.magnification(self._x_grid, self._y_grid, self._kwargs_lens_partial)) - im = ax.matshow(mag_result, origin='lower', extent=[0, self._frame_size, 0, self._frame_size], - vmin=v_min, vmax=v_max, **kwargs) - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) - ax.autoscale(False) - plot_util.scale_bar(ax, self._frame_size, dist=1, text='1"', color='k', font_size=font_size) - if not no_arrow: - plot_util.coordinate_arrows(ax, self._frame_size, self._coords, color='k', arrow_size=self._arrow_size, - font_size=font_size) - plot_util.text_description(ax, self._frame_size, text=text, color="k", backgroundcolor='w', font_size=font_size) - divider = make_axes_locatable(ax) - cax = divider.append_axes("right", size="5%", pad=0.05) - cb = plt.colorbar(im, cax=cax) - cb.set_label(colorbar_label, fontsize=font_size) - ra_image, dec_image = self._bandmodel.PointSource.image_position(self._kwargs_ps_partial, self._kwargs_lens_partial) - plot_util.image_position_plot(ax, self._coords, ra_image, dec_image, color='k', image_name_list=image_name_list) - return ax
- -
[docs] def deflection_plot(self, ax, v_min=None, v_max=None, axis=0, - with_caustics=False, image_name_list=None, - text="Deflection model", font_size=15, - colorbar_label=r'arcsec'): - """ - - :return: - """ - - alpha1, alpha2 = self._lensModel.alpha(self._x_grid, self._y_grid, self._kwargs_lens_partial) - alpha1 = util.array2image(alpha1) - alpha2 = util.array2image(alpha2) - if axis == 0: - alpha = alpha1 - else: - alpha = alpha2 - im = ax.matshow(alpha, origin='lower', extent=[0, self._frame_size, 0, self._frame_size], - vmin=v_min, vmax=v_max, cmap=self._cmap, alpha=0.5) - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) - ax.autoscale(False) - plot_util.scale_bar(ax, self._frame_size, dist=1, text='1"', color='k', font_size=font_size) - plot_util.coordinate_arrows(ax, self._frame_size, self._coords, color='k', arrow_size=self._arrow_size, - font_size=font_size) - plot_util.text_description(ax, self._frame_size, text=text, color="k", backgroundcolor='w', font_size=font_size) - divider = make_axes_locatable(ax) - cax = divider.append_axes("right", size="5%", pad=0.05) - cb = plt.colorbar(im, cax=cax) - cb.set_label(colorbar_label, fontsize=font_size) - if with_caustics is True: - ra_crit_list, dec_crit_list = self._critical_curves() - ra_caustic_list, dec_caustic_list = self._caustics() - plot_util.plot_line_set(ax, self._coords, ra_caustic_list, dec_caustic_list, color='b', - points_only=self._caustic_points_only) - plot_util.plot_line_set(ax, self._coords, ra_crit_list, dec_crit_list, color='r', - points_only=self._caustic_points_only) - ra_image, dec_image = self._bandmodel.PointSource.image_position(self._kwargs_ps_partial, self._kwargs_lens_partial) - plot_util.image_position_plot(ax, self._coords, ra_image, dec_image, image_name_list=image_name_list) - return ax
- -
[docs] def decomposition_plot(self, ax, text='Reconstructed', v_min=None, v_max=None, - unconvolved=False, point_source_add=False, - font_size=15, - source_add=False, lens_light_add=False, **kwargs): - """ - - :param ax: - :param text: - :param v_min: - :param v_max: - :param unconvolved: - :param point_source_add: - :param source_add: - :param lens_light_add: - :param kwargs: kwargs to send matplotlib.pyplot.matshow() - :return: - """ - model = self._bandmodel.image(self._kwargs_lens_partial, self._kwargs_source_partial, self._kwargs_lens_light_partial, - self._kwargs_ps_partial, unconvolved=unconvolved, source_add=source_add, - lens_light_add=lens_light_add, point_source_add=point_source_add) - if v_min is None: - v_min = self._v_min_default - if v_max is None: - v_max = self._v_max_default - if 'cmap' not in kwargs: - kwargs['cmap'] = self._cmap - im = ax.matshow(np.log10(model), origin='lower', vmin=v_min, vmax=v_max, - extent=[0, self._frame_size, 0, self._frame_size], **kwargs) - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) - ax.autoscale(False) - plot_util.scale_bar(ax, self._frame_size, dist=1, text='1"', font_size=font_size) - plot_util.text_description(ax, self._frame_size, text=text, color="w", backgroundcolor='k') - plot_util.coordinate_arrows(ax, self._frame_size, self._coords, arrow_size=self._arrow_size, - font_size=font_size) - divider = make_axes_locatable(ax) - cax = divider.append_axes("right", size="5%", pad=0.05) - cb = plt.colorbar(im, cax=cax) - cb.set_label(r'log$_{10}$ flux', fontsize=font_size) - return ax
- -
[docs] def subtract_from_data_plot(self, ax, text='Subtracted', v_min=None, - v_max=None, point_source_add=False, - source_add=False, lens_light_add=False, - font_size=15 - ): - model = self._bandmodel.image(self._kwargs_lens_partial, self._kwargs_source_partial, self._kwargs_lens_light_partial, - self._kwargs_ps_partial, unconvolved=False, source_add=source_add, - lens_light_add=lens_light_add, point_source_add=point_source_add) - if v_min is None: - v_min = self._v_min_default - if v_max is None: - v_max = self._v_max_default - im = ax.matshow(np.log10(self._data - model), origin='lower', vmin=v_min, vmax=v_max, - extent=[0, self._frame_size, 0, self._frame_size], cmap=self._cmap) - ax.get_xaxis().set_visible(False) - ax.get_yaxis().set_visible(False) - ax.autoscale(False) - plot_util.scale_bar(ax, self._frame_size, dist=1, text='1"', font_size=font_size) - plot_util.text_description(ax, self._frame_size, text=text, color="w", backgroundcolor='k', font_size=font_size) - plot_util.coordinate_arrows(ax, self._frame_size, self._coords, arrow_size=self._arrow_size, - font_size=font_size) - divider = make_axes_locatable(ax) - cax = divider.append_axes("right", size="5%", pad=0.05) - cb = plt.colorbar(im, cax=cax) - cb.set_label(r'log$_{10}$ flux', fontsize=font_size) - return ax
- -
[docs] def plot_main(self, with_caustics=False): - """ - print the main plots together in a joint frame - - :return: - """ - - f, axes = plt.subplots(2, 3, figsize=(16, 8)) - self.data_plot(ax=axes[0, 0]) - self.model_plot(ax=axes[0, 1], image_names=True) - self.normalized_residual_plot(ax=axes[0, 2], v_min=-6, v_max=6) - self.source_plot(ax=axes[1, 0], deltaPix_source=0.01, numPix=100, with_caustics=with_caustics) - self.convergence_plot(ax=axes[1, 1], v_max=1) - self.magnification_plot(ax=axes[1, 2]) - f.tight_layout() - f.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0., hspace=0.05) - return f, axes
- -
[docs] def plot_separate(self): - """ - plot the different model components separately - - :return: - """ - f, axes = plt.subplots(2, 3, figsize=(16, 8)) - - self.decomposition_plot(ax=axes[0, 0], text='Lens light', lens_light_add=True, unconvolved=True) - self.decomposition_plot(ax=axes[1, 0], text='Lens light convolved', lens_light_add=True) - self.decomposition_plot(ax=axes[0, 1], text='Source light', source_add=True, unconvolved=True) - self.decomposition_plot(ax=axes[1, 1], text='Source light convolved', source_add=True) - self.decomposition_plot(ax=axes[0, 2], text='All components', source_add=True, lens_light_add=True, - unconvolved=True) - self.decomposition_plot(ax=axes[1, 2], text='All components convolved', source_add=True, - lens_light_add=True, point_source_add=True) - f.tight_layout() - f.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0., hspace=0.05) - return f, axes
- -
[docs] def plot_subtract_from_data_all(self): - """ - subtract model components from data - - :return: - """ - f, axes = plt.subplots(2, 3, figsize=(16, 8)) - - self.subtract_from_data_plot(ax=axes[0, 0], text='Data') - self.subtract_from_data_plot(ax=axes[0, 1], text='Data - Point Source', point_source_add=True) - self.subtract_from_data_plot(ax=axes[0, 2], text='Data - Lens Light', lens_light_add=True) - self.subtract_from_data_plot(ax=axes[1, 0], text='Data - Source Light', source_add=True) - self.subtract_from_data_plot(ax=axes[1, 1], text='Data - Source Light - Point Source', source_add=True, - point_source_add=True) - self.subtract_from_data_plot(ax=axes[1, 2], text='Data - Lens Light - Point Source', lens_light_add=True, - point_source_add=True) - f.tight_layout() - f.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0., hspace=0.05) - return f, axes
- -
[docs] def plot_extinction_map(self, ax, v_min=None, v_max=None, **kwargs): - """ - - :param ax: - :param v_min: - :param v_max: - :return: - """ - model = self._bandmodel.extinction_map(self._kwargs_extinction_partial, self._kwargs_special_partial) - if v_min is None: - v_min = 0 - if v_max is None: - v_max = 1 - - _ = ax.matshow(model, origin='lower', vmin=v_min, vmax=v_max, - extent=[0, self._frame_size, 0, self._frame_size], **kwargs) - return ax
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Plots/model_plot.html b/docs/_build/html/_modules/lenstronomy/Plots/model_plot.html deleted file mode 100644 index 8d16e02fc..000000000 --- a/docs/_build/html/_modules/lenstronomy/Plots/model_plot.html +++ /dev/null @@ -1,372 +0,0 @@ - - - - - - - - lenstronomy.Plots.model_plot — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Plots.model_plot

-import copy
-import numpy as np
-
-import lenstronomy.Util.class_creator as class_creator
-from lenstronomy.Plots.model_band_plot import ModelBandPlot
-from lenstronomy.Analysis.image_reconstruction import check_solver_error
-
-__all__ = ['ModelPlot']
-
-
-
[docs]class ModelPlot(object): - """ - class that manages the summary plots of a lens model - The class uses the same conventions as being used in the FittingSequence and interfaces with the ImSim module. - The linear inversion is re-done given the likelihood settings in the init of this class (make sure this is the same - as you perform the FittingSequence) to make sure the linear amplitude parameters are computed as they are not part - of the output of the FittingSequence results. - - """ - def __init__(self, multi_band_list, kwargs_model, kwargs_params, image_likelihood_mask_list=None, - bands_compute=None, multi_band_type='multi-linear', source_marg=False, linear_prior=None, - arrow_size=0.02, cmap_string="gist_heat", fast_caustic=True): - """ - - :param multi_band_list: list of [[kwargs_data, kwargs_psf, kwargs_numerics], [], ..] - :param multi_band_type: string, option when having multiple imaging data sets modelled simultaneously. - Options are: - - 'multi-linear': linear amplitudes are inferred on single data set - - 'linear-joint': linear amplitudes ae jointly inferred - - 'single-band': single band - :param kwargs_model: model keyword arguments - :param bands_compute: (optional), bool list to indicate which band to be included in the modeling - :param image_likelihood_mask_list: list of image likelihood mask - (same size as image_data with 1 indicating being evaluated and 0 being left out) - :param kwargs_params: keyword arguments of 'kwargs_lens', 'kwargs_source' etc as coming as kwargs_result from - FittingSequence class - :param source_marg: - :param linear_prior: - :param arrow_size: - :param cmap_string: - :param fast_caustic: boolean; if True, uses fast (but less accurate) caustic calculation method - """ - if bands_compute is None: - bands_compute = [True] * len(multi_band_list) - if multi_band_type == 'single-band': - multi_band_type = 'multi-linear' # this makes sure that the linear inversion outputs are coming in a list - self._imageModel = class_creator.create_im_sim(multi_band_list, multi_band_type, kwargs_model, - bands_compute=bands_compute, - image_likelihood_mask_list=image_likelihood_mask_list) - - model, error_map, cov_param, param = self._imageModel.image_linear_solve(inv_bool=True, **kwargs_params) - - check_solver_error(param) - log_l = self._imageModel.likelihood_data_given_model(source_marg=source_marg, linear_prior=linear_prior, - **kwargs_params) - - n_data = self._imageModel.num_data_evaluate - if n_data > 0: - print(log_l * 2 / n_data, 'reduced X^2 of all evaluated imaging data combined.') - - self._band_plot_list = [] - self._index_list = [] - index = 0 - for i in range(len(multi_band_list)): - if bands_compute[i] is True: - if multi_band_type == 'joint-linear': - param_i = param - cov_param_i = cov_param - else: - param_i = param[index] - cov_param_i = cov_param[index] - - bandplot = ModelBandPlot(multi_band_list, kwargs_model, model[index], error_map[index], cov_param_i, - param_i, copy.deepcopy(kwargs_params), - likelihood_mask_list=image_likelihood_mask_list, band_index=i, - arrow_size=arrow_size, cmap_string=cmap_string, fast_caustic=fast_caustic) - - self._band_plot_list.append(bandplot) - self._index_list.append(index) - else: - self._index_list.append(-1) - index += 1 - - def _select_band(self, band_index): - """ - - :param band_index: index of imaging band to be plotted - :return: bandplot() instance of selected band, raises when band is not computed - """ - i = self._index_list[band_index] - if i == -1: - raise ValueError("band %s is not computed or out of range." % band_index) - i = int(i) - return self._band_plot_list[i] - -
[docs] def reconstruction_all_bands(self, **kwargs): - """ - - :param kwargs: arguments of plotting - :return: 3 x n_data plot with data, model, reduced residual plots of all the images/bands that are being modeled - - """ - n_bands = len(self._band_plot_list) - import matplotlib.pyplot as plt - f, axes = plt.subplots(n_bands, 3, figsize=(12, 4*n_bands)) - if n_bands == 1: # make sure axis can be called as 2d array - _axes = np.empty((1, 3), dtype=object) - _axes[:] = axes - axes = _axes - i = 0 - for band_index in self._index_list: - if band_index >= 0: - axes[i, 0].set_title('image ' + str(band_index)) - self.data_plot(ax=axes[i, 0], band_index=band_index, **kwargs) - self.model_plot(ax=axes[i, 1], image_names=True, band_index=band_index, **kwargs) - self.normalized_residual_plot(ax=axes[i, 2], v_min=-6, v_max=6, band_index=band_index, **kwargs) - i += 1 - return f, axes
- -
[docs] def data_plot(self, band_index=0, **kwargs): - """ - illustrates data - - :param band_index: index of band - :param kwargs: arguments of plotting - :return: plot instance - """ - plot_band = self._select_band(band_index) - return plot_band.data_plot(**kwargs)
- -
[docs] def model_plot(self, band_index=0, **kwargs): - """ - illustrates model - - :param band_index: index of band - :param kwargs: arguments of plotting - :return: plot instance - """ - plot_band = self._select_band(band_index) - return plot_band.model_plot(**kwargs)
- -
[docs] def convergence_plot(self, band_index=0, **kwargs): - """ - illustrates lensing convergence in data frame - - :param band_index: index of band - :param kwargs: arguments of plotting - :return: plot instance - """ - plot_band = self._select_band(band_index) - return plot_band.convergence_plot(**kwargs)
- -
[docs] def normalized_residual_plot(self, band_index=0, **kwargs): - """ - illustrates normalized residuals between data and model fit - - :param band_index: index of band - :param kwargs: arguments of plotting - :return: plot instance - """ - plot_band = self._select_band(band_index) - return plot_band.normalized_residual_plot(**kwargs)
- -
[docs] def absolute_residual_plot(self, band_index=0, **kwargs): - """ - illustrates absolute residuals between data and model fit - - :param band_index: index of band - :param kwargs: arguments of plotting - :return: plot instance - """ - plot_band = self._select_band(band_index) - return plot_band.absolute_residual_plot(**kwargs)
- -
[docs] def source_plot(self, band_index=0, **kwargs): - """ - illustrates reconstructed source (de-lensed de-convolved) - - :param band_index: index of band - :param kwargs: arguments of plotting - :return: plot instance - """ - plot_band = self._select_band(band_index) - return plot_band.source_plot(**kwargs)
- -
[docs] def error_map_source_plot(self, band_index=0, **kwargs): - """ - illustrates surface brightness variance in the reconstruction in the source plane - - :param band_index: index of band - :param kwargs: arguments of plotting - :return: plot instance - """ - plot_band = self._select_band(band_index) - return plot_band.error_map_source_plot(**kwargs)
- -
[docs] def magnification_plot(self, band_index=0, **kwargs): - """ - illustrates lensing magnification in the field of view of the data frame - - :param band_index: index of band - :param kwargs: arguments of plotting - :return: plot instance - """ - plot_band = self._select_band(band_index) - return plot_band.magnification_plot(**kwargs)
- -
[docs] def deflection_plot(self, band_index=0, **kwargs): - """ - illustrates lensing deflections on the field of view of the data frame - - :param band_index: index of band - :param kwargs: arguments of plotting - :return: plot instance - """ - plot_band = self._select_band(band_index) - return plot_band.deflection_plot(**kwargs)
- -
[docs] def decomposition_plot(self, band_index=0, **kwargs): - """ - illustrates decomposition of model components - - :param band_index: index of band - :param kwargs: arguments of plotting - :return: plot instance - """ - plot_band = self._select_band(band_index) - return plot_band.decomposition_plot(**kwargs)
- -
[docs] def subtract_from_data_plot(self, band_index=0, **kwargs): - """ - subtracts individual model components from the data - - :param band_index: index of band - :param kwargs: arguments of plotting - :return: plot instance - """ - plot_band = self._select_band(band_index) - return plot_band.subtract_from_data_plot(**kwargs)
- -
[docs] def plot_main(self, band_index=0, **kwargs): - """ - plot a set of 'main' modelling diagnostics - - :param band_index: index of band - :param kwargs: arguments of plotting - :return: plot instance - """ - plot_band = self._select_band(band_index) - return plot_band.plot_main(**kwargs)
- -
[docs] def plot_separate(self, band_index=0): - """ - plot a set of 'main' modelling diagnostics - - :param band_index: index of band - :return: plot instance - """ - plot_band = self._select_band(band_index) - return plot_band.plot_separate()
- -
[docs] def plot_subtract_from_data_all(self, band_index=0): - """ - plot a set of 'main' modelling diagnostics - - :param band_index: index of band - :return: plot instance - """ - plot_band = self._select_band(band_index) - return plot_band.plot_subtract_from_data_all()
- -
[docs] def plot_extinction_map(self, band_index=0, **kwargs): - """ - - :param band_index: index of band - :param kwargs: arguments of plotting - :return: plot instance of differential extinction map - """ - plot_band = self._select_band(band_index) - return plot_band.plot_extinction_map(**kwargs)
- -
[docs] def source(self, band_index=0, **kwargs): - """ - - :param band_index: index of band - :param kwargs: keyword arguments accessible in model_band_plot.source() - :return: 2d array of source surface brightness - """ - plot_band = self._select_band(band_index) - return plot_band.source(**kwargs)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Plots/plot_util.html b/docs/_build/html/_modules/lenstronomy/Plots/plot_util.html deleted file mode 100644 index c45a2bde0..000000000 --- a/docs/_build/html/_modules/lenstronomy/Plots/plot_util.html +++ /dev/null @@ -1,325 +0,0 @@ - - - - - - - - lenstronomy.Plots.plot_util — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Plots.plot_util

-import numpy as np
-import math
-import matplotlib.pyplot as plt
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -def sqrt(inputArray, scale_min=None, scale_max=None): - """Performs sqrt scaling of the input numpy array. - - @type inputArray: numpy array - @param inputArray: image data array - @type scale_min: float - @param scale_min: minimum data value - @type scale_max: float - @param scale_max: maximum data value - @rtype: numpy array - @return: image data array - - """ - - imageData = np.array(inputArray, copy=True) - - if scale_min is None: - scale_min = imageData.min() - if scale_max is None: - scale_max = imageData.max() - - imageData = imageData.clip(min=scale_min, max=scale_max) - imageData = imageData - scale_min - indices = np.where(imageData < 0) - imageData[indices] = 0.0 - imageData = np.sqrt(imageData) - imageData = imageData / math.sqrt(scale_max - scale_min) - return imageData
- - -
[docs]@export -def text_description(ax, d, text, color='w', backgroundcolor='k', - flipped=False, font_size=15): - c_vertical = 1/15. #+ font_size / d / 10.**2 - c_horizontal = 1./30 - if flipped: - ax.text(d - d * c_horizontal, d - d * c_vertical, text, color=color, - fontsize=font_size, - backgroundcolor=backgroundcolor) - else: - ax.text(d * c_horizontal, d - d * c_vertical, text, color=color, fontsize=font_size, - backgroundcolor=backgroundcolor)
- - -
[docs]@export -def scale_bar(ax, d, dist=1., text='1"', color='w', font_size=15, flipped=False): - if flipped: - p0 = d - d / 15. - dist - p1 = d / 15. - ax.plot([p0, p0 + dist], [p1, p1], linewidth=2, color=color) - ax.text(p0 + dist / 2., p1 + 0.01 * d, text, fontsize=font_size, - color=color, ha='center') - else: - p0 = d / 15. - ax.plot([p0, p0 + dist], [p0, p0], linewidth=2, color=color) - ax.text(p0 + dist / 2., p0 + 0.01 * d, text, fontsize=font_size, color=color, ha='center')
- - -
[docs]@export -def coordinate_arrows(ax, d, coords, color='w', font_size=15, arrow_size=0.05): - d0 = d / 8. - p0 = d / 15. - pt = d / 9. - deltaPix = coords.pixel_width - ra0, dec0 = coords.map_pix2coord((d - d0) / deltaPix, d0 / deltaPix) - xx_, yy_ = coords.map_coord2pix(ra0, dec0) - xx_ra, yy_ra = coords.map_coord2pix(ra0 + p0, dec0) - xx_dec, yy_dec = coords.map_coord2pix(ra0, dec0 + p0) - xx_ra_t, yy_ra_t = coords.map_coord2pix(ra0 + pt, dec0) - xx_dec_t, yy_dec_t = coords.map_coord2pix(ra0, dec0 + pt) - - ax.arrow(xx_ * deltaPix, yy_ * deltaPix, (xx_ra - xx_) * deltaPix, (yy_ra - yy_) * deltaPix, - head_width=arrow_size * d, head_length=arrow_size * d, fc=color, ec=color, linewidth=1) - ax.text(xx_ra_t * deltaPix, yy_ra_t * deltaPix, "E", color=color, fontsize=font_size, ha='center') - ax.arrow(xx_ * deltaPix, yy_ * deltaPix, (xx_dec - xx_) * deltaPix, (yy_dec - yy_) * deltaPix, - head_width=arrow_size * d, head_length=arrow_size * d, fc - =color, ec=color, linewidth=1) - ax.text(xx_dec_t * deltaPix, yy_dec_t * deltaPix, "N", color=color, fontsize=font_size, ha='center')
- - -
[docs]@export -def plot_line_set(ax, coords, line_set_list_x, line_set_list_y, origin=None, flipped_x=False, points_only=False, - pixel_offset=True, *args, **kwargs): - """ - plotting a line set on a matplotlib instance where the coordinates are defined in pixel units with the lower left - corner (defined as origin) is by default (0, 0). The coordinates are moved by 0.5 pixels to be placed in the center - of the pixel in accordance with the matplotlib.matshow() routine. - - :param ax: matplotlib.axis instance - :param coords: Coordinates() class instance - :param origin: [x0, y0], lower left pixel coordinate in the frame of the pixels - :param line_set_list_x: numpy arrays corresponding of different disconnected regions of the line - (e.g. caustic or critical curve) - :param line_set_list_y: numpy arrays corresponding of different disconnected regions of the line - (e.g. caustic or critical curve) - :param color: string with matplotlib color - :param flipped_x: bool, if True, flips x-axis - :param points_only: bool, if True, sets plotting keywords to plot single points without connecting lines - :param pixel_offset: boolean; if True (default plotting), the coordinates are shifted a half a pixel to match with - the matshow() command to center the coordinates in the pixel center - :return: plot with line sets on matplotlib axis in pixel coordinates - """ - if origin is None: - origin = [0, 0] - pixel_width = coords.pixel_width - pixel_width_x = pixel_width - if points_only: - if 'linestyle' not in kwargs: - kwargs['linestyle'] = "" - if 'marker' not in kwargs: - kwargs['marker'] = "o" - if 'markersize' not in kwargs: - kwargs['markersize'] = 0.01 - if flipped_x: - pixel_width_x = -pixel_width - if pixel_offset is True: - shift = 0.5 - else: - shift = 0 - if isinstance(line_set_list_x, list): - for i in range(len(line_set_list_x)): - x_c, y_c = coords.map_coord2pix(line_set_list_x[i], line_set_list_y[i]) - ax.plot((x_c + shift) * pixel_width_x + origin[0], (y_c + shift) * pixel_width + origin[1], *args, **kwargs) - else: - x_c, y_c = coords.map_coord2pix(line_set_list_x, line_set_list_y) - ax.plot((x_c + shift) * pixel_width_x + origin[0], (y_c + shift) * pixel_width + origin[1], *args, **kwargs) - return ax
- - -
[docs]@export -def image_position_plot(ax, coords, ra_image, dec_image, color='w', image_name_list=None, origin=None, flipped_x=False, - pixel_offset=True): - """ - - :param ax: matplotlib axis instance - :param coords: Coordinates() class instance or inherited class (such as PixelGrid(), or Data()) - :param ra_image: Ra/x-coordinates of image positions (list of arrays in angular units) - :param dec_image: Dec/y-coordinates of image positions (list of arrays in angular units) - :param color: color of ticks and text - :param image_name_list: list of strings for names of the images in the same order as the positions - :param origin: [x0, y0], lower left pixel coordinate in the frame of the pixels - :param flipped_x: bool, if True, flips x-axis - :param pixel_offset: boolean; if True (default plotting), the coordinates are shifted a half a pixel to match with - the matshow() command to center the coordinates in the pixel center - :return: matplotlib axis instance with images plotted on - """ - if origin is None: - origin = [0, 0] - pixel_width = coords.pixel_width - pixel_width_x = pixel_width - if flipped_x: - pixel_width_x = -pixel_width - if image_name_list is None: - image_name_list = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'] - - if not isinstance(ra_image, list): - ra_image_, dec_image_ = [ra_image], [dec_image] - else: - ra_image_, dec_image_ = ra_image, dec_image - if pixel_offset is True: - shift = 0.5 - else: - shift = 0 - for ra, dec in zip(ra_image_, dec_image_): - x_image, y_image = coords.map_coord2pix(ra, dec) - - for i in range(len(x_image)): - x_ = (x_image[i] + shift) * pixel_width_x + origin[0] - y_ = (y_image[i] + shift) * pixel_width + origin[1] - ax.plot(x_, y_, 'o', color=color) - ax.text(x_, y_, image_name_list[i], fontsize=20, color=color) - return ax
- - -
[docs]@export -def source_position_plot(ax, coords, ra_source, dec_source, marker='*', markersize=10, **kwargs): - """ - - :param ax: matplotlib axis instance - :param coords: Coordinates() class instance or inherited class (such as PixelGrid(), or Data()) - :param ra_source: list of source position in angular units - :param dec_source: list of source position in angular units - :param marker: marker style for matplotlib - :param markersize: marker size for matplotlib - :return: matplotlib axis instance with images plotted on - """ - delta_pix = coords.pixel_width - if len(ra_source) > 0: - for ra, dec in zip(ra_source, dec_source): - x_source, y_source = coords.map_coord2pix(ra, dec) - ax.plot((x_source + 0.5) * delta_pix, (y_source + 0.5) * delta_pix, marker=marker, markersize=markersize, - **kwargs) - return ax
- - -
[docs]@export -def result_string(x, weights=None, title_fmt=".2f", label=None): - """ - - :param x: marginalized 1-d posterior - :param weights: weights of posteriors (optional) - :param title_fmt: format to what digit the results are presented - :param label: string of parameter label (optional) - :return: string with mean :math:`\\pm` quartile - """ - from corner import quantile - - q_16, q_50, q_84 = quantile(x, [0.16, 0.5, 0.84], weights=weights) - q_m, q_p = q_50 - q_16, q_84 - q_50 - - # Format the quantile display. - fmt = "{{0:{0}}}".format(title_fmt).format - title = r"${{{0}}}_{{-{1}}}^{{+{2}}}$" - title = title.format(fmt(q_50), fmt(q_m), fmt(q_p)) - if label is not None: - title = "{0} = {1}".format(label, title) - return title
- - -
[docs]@export -def cmap_conf(cmap_string): - """ - configures matplotlib color map - - :param cmap_string: string of cmap name, or cmap instance - :return: cmap instance with setting for bad pixels and values below the threshold - """ - if isinstance(cmap_string, str): - cmap = plt.get_cmap(cmap_string) - else: - cmap = cmap_string - cmap.set_bad(color='k', alpha=1.) - cmap.set_under('k') - return cmap
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/PointSource/Types/base_ps.html b/docs/_build/html/_modules/lenstronomy/PointSource/Types/base_ps.html deleted file mode 100644 index 17a78e4cc..000000000 --- a/docs/_build/html/_modules/lenstronomy/PointSource/Types/base_ps.html +++ /dev/null @@ -1,196 +0,0 @@ - - - - - - - - lenstronomy.PointSource.Types.base_ps — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.PointSource.Types.base_ps

-from lenstronomy.LensModel.Solver.lens_equation_solver import LensEquationSolver
-import numpy as np
-
-__all__ = ['PSBase', '_expand_to_array', '_shrink_array']
-
-
-
[docs]class PSBase(object): - """ - base point source type class - """ - def __init__(self, lens_model=None, fixed_magnification=False, additional_image=False): - """ - - :param lens_model: instance of the LensModel() class - :param fixed_magnification: bool. If True, magnification - ratio of point sources is fixed to the one given by the lens model - :param additional_image: bool. If True, search for additional images of the same source is conducted. - """ - self._lens_model = lens_model - if self._lens_model is None: - self._solver = None - else: - self._solver = LensEquationSolver(lens_model) - self._fixed_magnification = fixed_magnification - self._additional_image = additional_image - if fixed_magnification is True and additional_image is True: - Warning('The combination of fixed_magnification=True and additional_image=True is not optimal for the ' - 'current computation. If you see this warning, please approach the developers.') - -
[docs] def image_position(self, kwargs_ps, **kwargs): - """ - on-sky position - - :param kwargs_ps: keyword argument of point source model - :return: numpy array of x, y image positions - """ - raise ValueError('image_position definition is not defined in the profile you want to execute.')
- -
[docs] def source_position(self, kwargs_ps, **kwargs): - """ - original unlensed position - - :param kwargs_ps: keyword argument of point source model - :return: numpy array of x, y source positions - """ - raise ValueError('source_position definition is not defined in the profile you want to execute.')
- -
[docs] def image_amplitude(self, kwargs_ps, *args, **kwargs): - """ - amplitudes as observed on the sky - - :param kwargs_ps: keyword argument of point source model - :param kwargs: keyword arguments of function call - :return: numpy array of amplitudes - """ - raise ValueError('source_position definition is not defined in the profile you want to execute.')
- -
[docs] def source_amplitude(self, kwargs_ps, **kwargs): - """ - intrinsic source amplitudes (without lensing magnification, but still apparent) - - :param kwargs_ps: keyword argument of point source model - :param kwargs: keyword arguments of function call (which are not used for this object - :return: numpy array of amplitudes - """ - raise ValueError('source_position definition is not defined in the profile you want to execute.')
- -
[docs] def update_lens_model(self, lens_model_class): - """ - update LensModel() and LensEquationSolver() instance - - :param lens_model_class: LensModel() class instance - :return: internal lensModel class updated - """ - self._lens_model = lens_model_class - if lens_model_class is None: - self._solver = None - else: - self._solver = LensEquationSolver(lens_model_class)
- - -def _expand_to_array(array, num): - """ - - :param array: float/int or numpy array - :param num: number of array entries expected in array - :return: array of size num - """ - if np.isscalar(array): - return np.ones(num) * array - elif len(array) < num: - out = np.zeros(num) - out[0:len(array)] = array - return out - else: - return array - - -def _shrink_array(array, num): - """ - :param array: float/int or numpy array - :param num: number of array entries expected in array - :return: array of size num, or scalar if array is a scalar - """ - if np.isscalar(array): - return array - elif len(array) > num: - array_return = array[:num] - return array_return - elif len(array) < num: - raise ValueError("the length of the array (%s) needs to be larger or equal than the designated length %s " - % (len(array), num)) - else: - return array -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/PointSource/Types/lensed_position.html b/docs/_build/html/_modules/lenstronomy/PointSource/Types/lensed_position.html deleted file mode 100644 index f2e90b614..000000000 --- a/docs/_build/html/_modules/lenstronomy/PointSource/Types/lensed_position.html +++ /dev/null @@ -1,190 +0,0 @@ - - - - - - - - lenstronomy.PointSource.Types.lensed_position — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.PointSource.Types.lensed_position

-import numpy as np
-from lenstronomy.PointSource.Types.base_ps import PSBase, _expand_to_array
-
-__all__ = ['LensedPositions']
-
-
-
[docs]class LensedPositions(PSBase): - """ - class of a a lensed point source parameterized as the (multiple) observed image positions - Name within the PointSource module: 'LENSED_POSITION' - parameters: ra_image, dec_image, point_amp - If fixed_magnification=True, than 'source_amp' is a parameter instead of 'point_amp' - - """ - # def __init__(self, lens_model=None, fixed_magnification=False, additional_image=False): - # super(LensedPositions, self).__init__(lens_model=lens_model, fixed_magnification=fixed_magnification, - # additional_image=additional_image) - -
[docs] def image_position(self, kwargs_ps, kwargs_lens=None, magnification_limit=None, kwargs_lens_eqn_solver=None): - """ - on-sky image positions - - :param kwargs_ps: keyword arguments of the point source model - :param kwargs_lens: keyword argument list of the lens model(s), only used when requiring the lens equation - solver - :param magnification_limit: float >0 or None, if float is set and additional images are computed, only those - images will be computed that exceed the lensing magnification (absolute value) limit - :param kwargs_lens_eqn_solver: keyword arguments specifying the numerical settings for the lens equation solver - see LensEquationSolver() class for details - :return: image positions in x, y as arrays - """ - if self._additional_image is True: - if kwargs_lens_eqn_solver is None: - kwargs_lens_eqn_solver = {} - ra_source, dec_source = self.source_position(kwargs_ps, kwargs_lens) - ra_image, dec_image = self._solver.image_position_from_source(ra_source, dec_source, kwargs_lens, - magnification_limit=magnification_limit, - **kwargs_lens_eqn_solver) - else: - ra_image = kwargs_ps['ra_image'] - dec_image = kwargs_ps['dec_image'] - return np.array(ra_image), np.array(dec_image)
- -
[docs] def source_position(self, kwargs_ps, kwargs_lens=None): - """ - original source position (prior to lensing) - - :param kwargs_ps: point source keyword arguments - :param kwargs_lens: lens model keyword argument list (required to ray-trace back in the source plane) - :return: x, y position (as numpy arrays) - """ - ra_image = kwargs_ps['ra_image'] - dec_image = kwargs_ps['dec_image'] - x_source, y_source = self._lens_model.ray_shooting(ra_image, dec_image, kwargs_lens) - x_source = np.mean(x_source) - y_source = np.mean(y_source) - return np.array(x_source), np.array(y_source)
- -
[docs] def image_amplitude(self, kwargs_ps, kwargs_lens=None, x_pos=None, y_pos=None, magnification_limit=None, - kwargs_lens_eqn_solver=None): - """ - image brightness amplitudes - - :param kwargs_ps: keyword arguments of the point source model - :param kwargs_lens: keyword argument list of the lens model(s), only used when requiring the lens equation - solver - :param x_pos: pre-computed image position (no lens equation solver applied) - :param y_pos: pre-computed image position (no lens equation solver applied) - :param magnification_limit: float >0 or None, if float is set and additional images are computed, only those - images will be computed that exceed the lensing magnification (absolute value) limit - :param kwargs_lens_eqn_solver: keyword arguments specifying the numerical settings for the lens equation solver - see LensEquationSolver() class for details - :return: array of image amplitudes - """ - if self._fixed_magnification: - if x_pos is not None and y_pos is not None: - ra_image, dec_image = x_pos, y_pos - else: - ra_image, dec_image = self.image_position(kwargs_ps, kwargs_lens, - magnification_limit=magnification_limit, - kwargs_lens_eqn_solver=kwargs_lens_eqn_solver) - mag = self._lens_model.magnification(ra_image, dec_image, kwargs_lens) - point_amp = kwargs_ps['source_amp'] * np.abs(mag) - else: - point_amp = kwargs_ps['point_amp'] - if x_pos is not None: - point_amp = _expand_to_array(point_amp, len(x_pos)) - return np.array(point_amp)
- -
[docs] def source_amplitude(self, kwargs_ps, kwargs_lens=None): - """ - intrinsic brightness amplitude of point source - When brightnesses are defined in magnified on-sky positions, the intrinsic brightness is computed as the mean - in the magnification corrected image position brightnesses. - - :param kwargs_ps: keyword arguments of the point source model - :param kwargs_lens: keyword argument list of the lens model(s), used when brightness are defined in - magnified on-sky positions - :return: brightness amplitude (as numpy array) - """ - if self._fixed_magnification: - source_amp = kwargs_ps['source_amp'] - else: - ra_image, dec_image = kwargs_ps['ra_image'], kwargs_ps['dec_image'] - mag = self._lens_model.magnification(ra_image, dec_image, kwargs_lens) - point_amp = kwargs_ps['point_amp'] - source_amp = np.mean(np.array(point_amp) / np.array(np.abs(mag))) - return np.array(source_amp)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/PointSource/Types/source_position.html b/docs/_build/html/_modules/lenstronomy/PointSource/Types/source_position.html deleted file mode 100644 index 231da0fbd..000000000 --- a/docs/_build/html/_modules/lenstronomy/PointSource/Types/source_position.html +++ /dev/null @@ -1,187 +0,0 @@ - - - - - - - - lenstronomy.PointSource.Types.source_position — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.PointSource.Types.source_position

-import numpy as np
-from lenstronomy.PointSource.Types.base_ps import PSBase, _expand_to_array, _shrink_array
-
-__all__ = ['SourcePositions']
-
-
-
[docs]class SourcePositions(PSBase): - """ - class of a single point source defined in the original source coordinate position that is lensed. - The lens equation is solved to compute the image positions for the specified source position. - - Name within the PointSource module: 'SOURCE_POSITION' - parameters: ra_source, dec_source, source_amp, mag_pert (optional) - If fixed_magnification=True, than 'source_amp' is a parameter instead of 'point_amp' - mag_pert is a list of fractional magnification pertubations applied to point source images - - """ - -
[docs] def image_position(self, kwargs_ps, kwargs_lens=None, magnification_limit=None, kwargs_lens_eqn_solver=None): - """ - on-sky image positions - - :param kwargs_ps: keyword arguments of the point source model - :param kwargs_lens: keyword argument list of the lens model(s), only used when requiring the lens equation - solver - :param magnification_limit: float >0 or None, if float is set and additional images are computed, only those - images will be computed that exceed the lensing magnification (absolute value) limit - :param kwargs_lens_eqn_solver: keyword arguments specifying the numerical settings for the lens equation solver - see LensEquationSolver() class for details - :return: image positions in x, y as arrays - """ - if kwargs_lens_eqn_solver is None: - kwargs_lens_eqn_solver = {} - ra_source, dec_source = self.source_position(kwargs_ps) - ra_image, dec_image = self._solver.image_position_from_source(ra_source, dec_source, kwargs_lens, - magnification_limit=magnification_limit, - **kwargs_lens_eqn_solver) - return ra_image, dec_image
- -
[docs] def source_position(self, kwargs_ps, **kwargs): - """ - original source position (prior to lensing) - - :param kwargs_ps: point source keyword arguments - :return: x, y position (as numpy arrays) - """ - ra_source = kwargs_ps['ra_source'] - dec_source = kwargs_ps['dec_source'] - return np.array(ra_source), np.array(dec_source)
- -
[docs] def image_amplitude(self, kwargs_ps, kwargs_lens=None, x_pos=None, y_pos=None, magnification_limit=None, - kwargs_lens_eqn_solver=None): - """ - image brightness amplitudes - - :param kwargs_ps: keyword arguments of the point source model - :param kwargs_lens: keyword argument list of the lens model(s), only ignored when providing image positions - directly - :param x_pos: pre-computed image position (no lens equation solver applied) - :param y_pos: pre-computed image position (no lens equation solver applied) - :param magnification_limit: float >0 or None, if float is set and additional images are computed, only those - images will be computed that exceed the lensing magnification (absolute value) limit - :param kwargs_lens_eqn_solver: keyword arguments specifying the numerical settings for the lens equation solver - see LensEquationSolver() class for details - :return: array of image amplitudes - """ - if self._fixed_magnification: - if x_pos is not None and y_pos is not None: - ra_image, dec_image = x_pos, y_pos - else: - if kwargs_lens_eqn_solver is None: - kwargs_lens_eqn_solver = {} - ra_image, dec_image = self.image_position(kwargs_ps, kwargs_lens=kwargs_lens, - magnification_limit=magnification_limit, - **kwargs_lens_eqn_solver) - mag = self._lens_model.magnification(ra_image, dec_image, kwargs_lens) - point_amp = kwargs_ps['source_amp'] * np.abs(mag) - else: - point_amp = kwargs_ps['point_amp'] - if x_pos is not None: - point_amp = _expand_to_array(point_amp, len(x_pos)) - mag_pert = kwargs_ps.get('mag_pert', 1) - mag_pert = _shrink_array(mag_pert, len(point_amp)) - point_amp *= np.array(mag_pert) - return np.array(point_amp)
- -
[docs] def source_amplitude(self, kwargs_ps, kwargs_lens=None): - """ - intrinsic brightness amplitude of point source - When brightnesses are defined in magnified on-sky positions, the intrinsic brightness is computed as the mean - in the magnification corrected image position brightnesses. - - :param kwargs_ps: keyword arguments of the point source model - :param kwargs_lens: keyword argument list of the lens model(s), used when brightness are defined in - magnified on-sky positions - :return: brightness amplitude (as numpy array) - """ - if self._fixed_magnification: - source_amp = kwargs_ps['source_amp'] - else: - ra_image, dec_image = self.image_position(kwargs_ps, kwargs_lens) - mag = self._lens_model.magnification(ra_image, dec_image, kwargs_lens) - point_amp = kwargs_ps['point_amp'] - source_amp = np.mean(np.array(point_amp) / np.array(mag)) - return np.array(source_amp)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/PointSource/Types/unlensed.html b/docs/_build/html/_modules/lenstronomy/PointSource/Types/unlensed.html deleted file mode 100644 index 96ac0239d..000000000 --- a/docs/_build/html/_modules/lenstronomy/PointSource/Types/unlensed.html +++ /dev/null @@ -1,140 +0,0 @@ - - - - - - - - lenstronomy.PointSource.Types.unlensed — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.PointSource.Types.unlensed

-from lenstronomy.PointSource.Types.base_ps import PSBase
-import numpy as np
-
-__all__ = ['Unlensed']
-
-
-
[docs]class Unlensed(PSBase): - """ - class of a single point source in the image plane, aka star - Name within the PointSource module: 'UNLENSED' - This model can deal with arrays of point sources. - parameters: ra_image, dec_image, point_amp - - """ - -
[docs] def image_position(self, kwargs_ps, **kwargs): - """ - on-sky position - - :param kwargs_ps: keyword argument of point source model - :return: numpy array of x, y image positions - """ - ra_image = kwargs_ps['ra_image'] - dec_image = kwargs_ps['dec_image'] - return np.array(ra_image), np.array(dec_image)
- -
[docs] def source_position(self, kwargs_ps, **kwargs): - """ - original physical position (identical for this object) - - :param kwargs_ps: keyword argument of point source model - :return: numpy array of x, y source positions - """ - ra_image = kwargs_ps['ra_image'] - dec_image = kwargs_ps['dec_image'] - return np.array(ra_image), np.array(dec_image)
- -
[docs] def image_amplitude(self, kwargs_ps, **kwargs): - """ - amplitudes as observed on the sky - - :param kwargs_ps: keyword argument of point source model - :param kwargs: keyword arguments of function call (which are not used for this object - :return: numpy array of amplitudes - """ - point_amp = kwargs_ps['point_amp'] - return np.array(point_amp)
- -
[docs] def source_amplitude(self, kwargs_ps, **kwargs): - """ - intrinsic source amplitudes - - :param kwargs_ps: keyword argument of point source model - :param kwargs: keyword arguments of function call (which are not used for this object - :return: numpy array of amplitudes - """ - point_amp = kwargs_ps['point_amp'] - return np.array(point_amp)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/PointSource/point_source.html b/docs/_build/html/_modules/lenstronomy/PointSource/point_source.html deleted file mode 100644 index 35085ecd0..000000000 --- a/docs/_build/html/_modules/lenstronomy/PointSource/point_source.html +++ /dev/null @@ -1,504 +0,0 @@ - - - - - - - - lenstronomy.PointSource.point_source — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.PointSource.point_source

-import numpy as np
-import copy
-from lenstronomy.PointSource.point_source_cached import PointSourceCached
-
-__all__ = ['PointSource']
-
-_SUPPORTED_MODELS = ['UNLENSED', 'LENSED_POSITION', 'SOURCE_POSITION']
-
-
-
[docs]class PointSource(object): - - def __init__(self, point_source_type_list, lensModel=None, fixed_magnification_list=None, - additional_images_list=None, flux_from_point_source_list=None, magnification_limit=None, - save_cache=False, kwargs_lens_eqn_solver=None): - """ - - :param point_source_type_list: list of point source types - :param lensModel: instance of the LensModel() class - :param fixed_magnification_list: list of booleans (same length as point_source_type_list). - If True, magnification ratio of point sources is fixed to the one given by the lens model - :param additional_images_list: list of booleans (same length as point_source_type_list). If True, search for - additional images of the same source is conducted. - :param flux_from_point_source_list: list of booleans (optional), if set, will only return image positions - (for imaging modeling) for the subset of the point source lists that =True. This option enables to model - imaging data with transient point sources, when the point source positions are measured and present at a - different time than the imaging data - :param magnification_limit: float >0 or None, if float is set and additional images are computed, only those - images will be computed that exceed the lensing magnification (absolute value) limit - :param save_cache: bool, saves image positions and only if delete_cache is executed, a new solution of the lens - equation is conducted with the lens model parameters provided. This can increase the speed as multiple times - the image positions are requested for the same lens model. Attention in usage! - :param kwargs_lens_eqn_solver: keyword arguments specifying the numerical settings for the lens equation solver - see LensEquationSolver() class for details - - for the kwargs_lens_eqn_solver parameters: have a look at the lensEquationSolver class, such as: - min_distance=0.01, search_window=5, precision_limit=10**(-10), num_iter_max=100 - - """ - self._lensModel = lensModel - self.point_source_type_list = point_source_type_list - self._point_source_list = [] - if fixed_magnification_list is None: - fixed_magnification_list = [False] * len(point_source_type_list) - self._fixed_magnification_list = fixed_magnification_list - if additional_images_list is None: - additional_images_list = [False] * len(point_source_type_list) - if flux_from_point_source_list is None: - flux_from_point_source_list = [True] * len(point_source_type_list) - self._flux_from_point_source_list = flux_from_point_source_list - for i, model in enumerate(point_source_type_list): - if model == 'UNLENSED': - from lenstronomy.PointSource.Types.unlensed import Unlensed - self._point_source_list.append(PointSourceCached(Unlensed(), save_cache=save_cache)) - elif model == 'LENSED_POSITION': - from lenstronomy.PointSource.Types.lensed_position import LensedPositions - self._point_source_list.append(PointSourceCached(LensedPositions(lensModel, fixed_magnification=fixed_magnification_list[i], - additional_image=additional_images_list[i]), - save_cache=save_cache)) - elif model == 'SOURCE_POSITION': - from lenstronomy.PointSource.Types.source_position import SourcePositions - self._point_source_list.append(PointSourceCached(SourcePositions(lensModel, - fixed_magnification=fixed_magnification_list[i]), - save_cache=save_cache)) - else: - raise ValueError("Point-source model %s not available. Supported models are %s ." - % (model, _SUPPORTED_MODELS)) - if kwargs_lens_eqn_solver is None: - kwargs_lens_eqn_solver = {} - self._kwargs_lens_eqn_solver = kwargs_lens_eqn_solver - self._magnification_limit = magnification_limit - self._save_cache = save_cache - -
[docs] def update_search_window(self, search_window, x_center, y_center, min_distance=None, only_from_unspecified=False): - """ - update the search area for the lens equation solver - - :param search_window: search_window: window size of the image position search with the lens equation solver. - :param x_center: center of search window - :param y_center: center of search window - :param min_distance: minimum search distance - :param only_from_unspecified: bool, if True, only sets keywords that previously have not been set - :return: updated self instances - """ - if min_distance is not None and 'min_distance' not in self._kwargs_lens_eqn_solver and only_from_unspecified: - self._kwargs_lens_eqn_solver['min_distance'] = min_distance - if only_from_unspecified: - self._kwargs_lens_eqn_solver['search_window'] = self._kwargs_lens_eqn_solver.get('search_window', - search_window) - self._kwargs_lens_eqn_solver['x_center'] = self._kwargs_lens_eqn_solver.get('x_center', x_center) - self._kwargs_lens_eqn_solver['y_center'] = self._kwargs_lens_eqn_solver.get('y_center', y_center) - else: - self._kwargs_lens_eqn_solver['search_window'] = search_window - self._kwargs_lens_eqn_solver['x_center'] = x_center - self._kwargs_lens_eqn_solver['y_center'] = y_center
- -
[docs] def update_lens_model(self, lens_model_class): - """ - - :param lens_model_class: instance of LensModel class - :return: update instance of lens model class - """ - self.delete_lens_model_cache() - self._lensModel = lens_model_class - for model in self._point_source_list: - model.update_lens_model(lens_model_class=lens_model_class)
- -
[docs] def delete_lens_model_cache(self): - """ - deletes the variables saved for a specific lens model - - :return: None - """ - for model in self._point_source_list: - model.delete_lens_model_cache()
- -
[docs] def set_save_cache(self, save_cache): - """ - set the save cache boolean to new value - - :param save_cache: bool, if True, saves (or uses a previously saved) values - :return: updated class and sub-class instances to either save or not save the point source information in cache - """ - self._set_save_cache(save_cache) - self._save_cache = save_cache
- - def _set_save_cache(self, save_cache): - """ - set the save cache boolean to new value. This function is for use within this class for temporarily set the - cache within a single routine. - - :param save_cache: bool, if True, saves (or uses a previously saved) values - :return: None - """ - for model in self._point_source_list: - model.set_save_cache(save_cache) - -
[docs] def source_position(self, kwargs_ps, kwargs_lens): - """ - intrinsic source positions of the point sources - - :param kwargs_ps: keyword argument list of point source models - :param kwargs_lens: keyword argument list of lens models - :return: list of source positions for each point source model - """ - x_source_list = [] - y_source_list = [] - for i, model in enumerate(self._point_source_list): - kwargs = kwargs_ps[i] - x_source, y_source = model.source_position(kwargs, kwargs_lens) - x_source_list.append(x_source) - y_source_list.append(y_source) - return x_source_list, y_source_list
- -
[docs] def image_position(self, kwargs_ps, kwargs_lens, k=None, original_position=False): - """ - image positions as observed on the sky of the point sources - - :param kwargs_ps: point source parameter keyword argument list - :param kwargs_lens: lens model keyword argument list - :param k: None, int or boolean list; only returns a subset of the model predictions - :param original_position: boolean (only applies to 'LENSED_POSITION' models), returns the image positions in - the model parameters and does not re-compute images (which might be differently ordered) in case of the lens - equation solver - :return: list of: list of image positions per point source model component - """ - x_image_list = [] - y_image_list = [] - for i, model in enumerate(self._point_source_list): - if k is None or k == i: - kwargs = kwargs_ps[i] - x_image, y_image = model.image_position(kwargs, kwargs_lens, - magnification_limit=self._magnification_limit, - kwargs_lens_eqn_solver=self._kwargs_lens_eqn_solver) - if original_position is True and self.point_source_type_list[i] == 'LENSED_POSITION': - x_o, y_o = kwargs['ra_image'], kwargs['dec_image'] - x_image, y_image = _sort_position_by_original(x_o, y_o, x_image, y_image) - - x_image_list.append(x_image) - y_image_list.append(y_image) - return x_image_list, y_image_list
- -
[docs] def point_source_list(self, kwargs_ps, kwargs_lens, k=None, with_amp=True): - """ - returns the coordinates and amplitudes of all point sources in a single array - - :param kwargs_ps: point source keyword argument list - :param kwargs_lens: lens model keyword argument list - :param k: None, int or list of int's to select a subset of the point source models in the return - :param with_amp: bool, if False, ignores the amplitude parameters in the return and instead provides ones for - each point source image - :return: ra_array, dec_array, amp_array - """ - # here we save the cache of the individual models but do not overwrite the class boolean variable to do so - self._set_save_cache(True) - # we make sure we do not re-compute the image positions twice when evaluating position and their amplitudes - ra_list, dec_list = self.image_position(kwargs_ps, kwargs_lens, k=k) - if with_amp is True: - amp_list = self.image_amplitude(kwargs_ps, kwargs_lens, k=k) - else: - amp_list = np.ones_like(ra_list) - - # here we delete the individual modeling caches in case this was the option - if self._save_cache is False: - self.delete_lens_model_cache() - self._set_save_cache(self._save_cache) - - ra_array, dec_array, amp_array = [], [], [] - for i, ra in enumerate(ra_list): - for j in range(len(ra)): - ra_array.append(ra_list[i][j]) - dec_array.append(dec_list[i][j]) - amp_array.append(amp_list[i][j]) - return ra_array, dec_array, amp_array
- -
[docs] def num_basis(self, kwargs_ps, kwargs_lens): - """ - number of basis functions for linear inversion - - :param kwargs_ps: point source keyword argument list - :param kwargs_lens: lens model keyword argument list - :return: int - """ - n = 0 - ra_pos_list, dec_pos_list = self.image_position(kwargs_ps, kwargs_lens) - for i, model in enumerate(self.point_source_type_list): - if self._flux_from_point_source_list[i]: - if self._fixed_magnification_list[i]: - n += 1 - else: - n += len(ra_pos_list[i]) - return n
- -
[docs] def image_amplitude(self, kwargs_ps, kwargs_lens, k=None): - """ - returns the image amplitudes - - :param kwargs_ps: point source keyword argument list - :param kwargs_lens: lens model keyword argument list - :param k: None, int or list of int's to select a subset of the point source models in the return - :return: list of image amplitudes per model component - """ - amp_list = [] - for i, model in enumerate(self._point_source_list): - if (k is None or k == i) and self._flux_from_point_source_list[i]: - amp_list.append(model.image_amplitude(kwargs_ps=kwargs_ps[i], kwargs_lens=kwargs_lens, - kwargs_lens_eqn_solver=self._kwargs_lens_eqn_solver)) - return amp_list
- -
[docs] def source_amplitude(self, kwargs_ps, kwargs_lens): - """ - intrinsic (unlensed) point source amplitudes - - :param kwargs_ps: point source keyword argument list - :param kwargs_lens: lens model keyword argument list - :return: list of intrinsic (unlensed) point source amplitudes - """ - amp_list = [] - for i, model in enumerate(self._point_source_list): - if self._flux_from_point_source_list[i]: - amp_list.append(model.source_amplitude(kwargs_ps=kwargs_ps[i], kwargs_lens=kwargs_lens)) - return amp_list
- -
[docs] def linear_response_set(self, kwargs_ps, kwargs_lens=None, with_amp=False): - """ - - :param kwargs_ps: point source keyword argument list - :param kwargs_lens: lens model keyword argument list - :param with_amp: bool, if True returns the image amplitude derived from kwargs_ps, - otherwise the magnification of the lens model - :return: ra_pos, dec_pos, amp, n - """ - ra_pos = [] - dec_pos = [] - amp = [] - self._set_save_cache(True) - x_image_list, y_image_list = self.image_position(kwargs_ps, kwargs_lens) - for i, model in enumerate(self._point_source_list): - if self._flux_from_point_source_list[i]: - x_pos = x_image_list[i] - y_pos = y_image_list[i] - if self._fixed_magnification_list[i]: - ra_pos.append(list(x_pos)) - dec_pos.append(list(y_pos)) - if with_amp: - mag = self.image_amplitude(kwargs_ps, kwargs_lens, k=i)[0] - else: - mag = self._lensModel.magnification(x_pos, y_pos, kwargs_lens) - mag = np.abs(mag) - amp.append(list(mag)) - else: - if with_amp: - mag = self.image_amplitude(kwargs_ps, kwargs_lens, k=i)[0] - else: - mag = np.ones_like(x_pos) - for j in range(len(x_pos)): - ra_pos.append([x_pos[j]]) - dec_pos.append([y_pos[j]]) - amp.append([mag[j]]) - n = len(ra_pos) - if self._save_cache is False: - self.delete_lens_model_cache() - self._set_save_cache(self._save_cache) - return ra_pos, dec_pos, amp, n
- -
[docs] def update_linear(self, param, i, kwargs_ps, kwargs_lens): - """ - - :param param: list of floats corresponding ot the parameters being sampled - :param i: index of the first parameter relevant for this class - :param kwargs_ps: point source keyword argument list - :param kwargs_lens: lens model keyword argument list - :return: kwargs_ps with updated linear parameters, index of the next parameter relevant for another class - """ - ra_pos_list, dec_pos_list = self.image_position(kwargs_ps, kwargs_lens) - for k, model in enumerate(self._point_source_list): - if self._flux_from_point_source_list[k]: - kwargs = kwargs_ps[k] - if self._fixed_magnification_list[k]: - kwargs['source_amp'] = param[i] - i += 1 - else: - n_points = len(ra_pos_list[k]) - kwargs['point_amp'] = np.array(param[i:i + n_points]) - i += n_points - return kwargs_ps, i
- -
[docs] def check_image_positions(self, kwargs_ps, kwargs_lens, tolerance=0.001): - """ - checks whether the point sources in kwargs_ps satisfy the lens equation with a tolerance - (computed by ray-tracing in the source plane) - - :param kwargs_ps: point source keyword argument list - :param kwargs_lens: lens model keyword argument list - :param tolerance: Eucledian distance between the source positions ray-traced backwards to be tolerated - :return: bool: True, if requirement on tolerance is fulfilled, False if not. - """ - x_image_list, y_image_list = self.image_position(kwargs_ps, kwargs_lens) - for i, model in enumerate(self.point_source_type_list): - if model in ['LENSED_POSITION', 'SOURCE_POSITION']: - x_pos = x_image_list[i] - y_pos = y_image_list[i] - x_source, y_source = self._lensModel.ray_shooting(x_pos, y_pos, kwargs_lens) - dist = np.sqrt((x_source - x_source[0]) ** 2 + (y_source - y_source[0]) ** 2) - if np.max(dist) > tolerance: - return False - return True
- -
[docs] def set_amplitudes(self, amp_list, kwargs_ps): - """ - translates the amplitude parameters into the convention of the keyword argument list - currently only used in SimAPI to transform magnitudes to amplitudes in the lenstronomy conventions - - :param amp_list: list of model amplitudes for each point source model - :param kwargs_ps: list of point source keywords - :return: overwrites kwargs_ps with new amplitudes - """ - kwargs_list = copy.deepcopy(kwargs_ps) - for i, model in enumerate(self.point_source_type_list): - if self._flux_from_point_source_list[i]: - amp = amp_list[i] - if model == 'UNLENSED': - kwargs_list[i]['point_amp'] = amp - elif model in ['LENSED_POSITION', 'SOURCE_POSITION']: - if self._fixed_magnification_list[i] is True: - kwargs_list[i]['source_amp'] = amp - else: - kwargs_list[i]['point_amp'] = amp - return kwargs_list
- -
[docs] @classmethod - def check_positive_flux(cls, kwargs_ps): - """ - check whether inferred linear parameters are positive - - :param kwargs_ps: point source keyword argument list - :return: bool, True, if all 'point_amp' parameters are positive semi-definite - """ - pos_bool = True - for kwargs in kwargs_ps: - if 'point_amp' in kwargs: - point_amp = kwargs['point_amp'] - if not np.all(point_amp >= 0): - pos_bool = False - break - if 'source_amp' in kwargs: - point_amp = kwargs['source_amp'] - if not np.all(point_amp >= 0): - pos_bool = False - break - return pos_bool
- - -def _sort_position_by_original(x_o, y_o, x_solved, y_solved): - """ - sorting new image positions such that the old order is best preserved - - :param x_o: numpy array; original image positions - :param y_o: numpy array; original image positions - :param x_solved: numpy array; solved image positions with potentially more or fewer images - :param y_solved: numpy array; solved image positions with potentially more or fewer images - :return: sorted new image positions with the order best matching the original positions first, - and then all other images in the same order as solved for - """ - if len(x_o) > len(x_solved): - # if new images are less , then return the original images (no sorting required) - x_solved_new, y_solved_new = x_o, y_o - else: - x_solved_new, y_solved_new = [], [] - for i in range(len(x_o)): - x, y = x_o[i], y_o[i] - r2_i = (x - x_solved) ** 2 + (y - y_solved) ** 2 - # index of minimum radios - index = np.argmin(r2_i) - x_solved_new.append(x_solved[index]) - y_solved_new.append(y_solved[index]) - # delete this index - x_solved = np.delete(x_solved, index) - y_solved = np.delete(y_solved, index) - # now we append the remaining additional images in the same order behind the original ones - x_solved_new = np.append(np.array(x_solved_new), x_solved) - y_solved_new = np.append(np.array(y_solved_new), y_solved) - return x_solved_new, y_solved_new -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/PointSource/point_source_cached.html b/docs/_build/html/_modules/lenstronomy/PointSource/point_source_cached.html deleted file mode 100644 index 48cbfa84b..000000000 --- a/docs/_build/html/_modules/lenstronomy/PointSource/point_source_cached.html +++ /dev/null @@ -1,170 +0,0 @@ - - - - - - - - lenstronomy.PointSource.point_source_cached — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.PointSource.point_source_cached

-__all__ = ['PointSourceCached']
-
-
-
[docs]class PointSourceCached(object): - """ - This class is the same as PointSource() except that it saves image and source positions in cache. - This speeds-up repeated calls for the same source and lens model and avoids duplicating the lens equation solving. - Attention: cache needs to be deleted before calling functions with different lens and point source parameters. - - """ - def __init__(self, point_source_model, save_cache=False): - self._model = point_source_model - self._save_cache = save_cache - -
[docs] def delete_lens_model_cache(self): - if hasattr(self, '_x_image'): - del self._x_image - if hasattr(self, '_y_image'): - del self._y_image - if hasattr(self, '_x_source'): - del self._x_source - if hasattr(self, '_y_source'): - del self._y_source
- -
[docs] def set_save_cache(self, save_bool): - self._save_cache = save_bool
- -
[docs] def update_lens_model(self, lens_model_class): - self._model.update_lens_model(lens_model_class)
- -
[docs] def image_position(self, kwargs_ps, kwargs_lens=None, magnification_limit=None, kwargs_lens_eqn_solver=None): - """ - on-sky image positions - - :param kwargs_ps: keyword arguments of the point source model - :param kwargs_lens: keyword argument list of the lens model(s), only used when requiring the lens equation - solver - :param magnification_limit: float >0 or None, if float is set and additional images are computed, only those - images will be computed that exceed the lensing magnification (absolute value) limit - :param kwargs_lens_eqn_solver: keyword arguments specifying the numerical settings for the lens equation solver - see LensEquationSolver() class for details - :return: image positions in x, y as arrays - """ - if not self._save_cache or not hasattr(self, '_x_image') or not hasattr(self, '_y_image'): - self._x_image, self._y_image = self._model.image_position(kwargs_ps, kwargs_lens=kwargs_lens, - magnification_limit=magnification_limit, - kwargs_lens_eqn_solver=kwargs_lens_eqn_solver) - return self._x_image, self._y_image
- -
[docs] def source_position(self, kwargs_ps, kwargs_lens=None): - """ - original source position (prior to lensing) - - :param kwargs_ps: point source keyword arguments - :param kwargs_lens: lens model keyword argument list (only used when required) - :return: x, y position - """ - if not self._save_cache or not hasattr(self, '_x_source') or not hasattr(self, '_y_source'): - self._x_source, self._y_source = self._model.source_position(kwargs_ps, kwargs_lens=kwargs_lens) - return self._x_source, self._y_source
- -
[docs] def image_amplitude(self, kwargs_ps, kwargs_lens=None, magnification_limit=None, kwargs_lens_eqn_solver=None): - """ - image brightness amplitudes - - :param kwargs_ps: keyword arguments of the point source model - :param kwargs_lens: keyword argument list of the lens model(s), only used when requiring the lens equation - solver - :param magnification_limit: float >0 or None, if float is set and additional images are computed, only those - images will be computed that exceed the lensing magnification (absolute value) limit - :param kwargs_lens_eqn_solver: keyword arguments specifying the numerical settings for the lens equation solver - see LensEquationSolver() class for details - :return: array of image amplitudes - """ - x_pos, y_pos = self.image_position(kwargs_ps, kwargs_lens, magnification_limit=magnification_limit, - kwargs_lens_eqn_solver=kwargs_lens_eqn_solver) - return self._model.image_amplitude(kwargs_ps, kwargs_lens=kwargs_lens, x_pos=x_pos, y_pos=y_pos)
- -
[docs] def source_amplitude(self, kwargs_ps, kwargs_lens=None): - """ - intrinsic brightness amplitude of point source - - :param kwargs_ps: keyword arguments of the point source model - :param kwargs_lens: keyword argument list of the lens model(s), only used when positions are defined in image - plane and have to be ray-traced back - :return: brightness amplitude (as numpy array) - """ - return self._model.source_amplitude(kwargs_ps, kwargs_lens=kwargs_lens)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/PointSource/point_source_param.html b/docs/_build/html/_modules/lenstronomy/PointSource/point_source_param.html deleted file mode 100644 index 8dc667fff..000000000 --- a/docs/_build/html/_modules/lenstronomy/PointSource/point_source_param.html +++ /dev/null @@ -1,299 +0,0 @@ - - - - - - - - lenstronomy.PointSource.point_source_param — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.PointSource.point_source_param

-import numpy as np
-
-__all__ = ['PointSourceParam']
-
-
-
[docs]class PointSourceParam(object): - """ - - """ - - def __init__(self, model_list, kwargs_fixed, num_point_source_list=None, linear_solver=True, - fixed_magnification_list=None, kwargs_lower=None, kwargs_upper=None): - """ - - :param model_list: list of point source model names - :param kwargs_fixed: list of keyword arguments with parameters to be held fixed - :param num_point_source_list: list of number of point sources per point source model class - :param linear_solver: bool, if True, does not return linear parameters for the sampler - (will be solved linearly instead) - :param fixed_magnification_list: list of booleans, if entry is True, keeps one overall scaling among the - point sources in this class - """ - self.model_list = model_list - if num_point_source_list is None: - num_point_source_list = [1] * len(model_list) - self._num_point_sources_list = num_point_source_list - if fixed_magnification_list is None: - fixed_magnification_list = [False] * len(model_list) - self._fixed_magnification_list = fixed_magnification_list - self.kwargs_fixed = kwargs_fixed - if linear_solver is True: - self.kwargs_fixed = self.add_fix_linear(kwargs_fixed) - self._linear_solver = linear_solver - - if kwargs_lower is None: - kwargs_lower = [] - for k, model in enumerate(self.model_list): - num = self._num_point_sources_list[k] - if model in ['LENSED_POSITION', 'UNLENSED']: - fixed_low = {'ra_image': [-100] * num, 'dec_image': [-100] * num} - elif model in ['SOURCE_POSITION']: - fixed_low = {'ra_source': -100, 'dec_source': -100} - else: - raise ValueError("%s not a valid point source model" % model) - if self._fixed_magnification_list[k] is True and model in ['LENSED_POSITION', 'SOURCE_POSITION']: - fixed_low['source_amp'] = 0 - else: - fixed_low['point_amp'] = np.zeros(num) - kwargs_lower.append(fixed_low) - if kwargs_upper is None: - kwargs_upper = [] - for k, model in enumerate(self.model_list): - num = self._num_point_sources_list[k] - if model in ['LENSED_POSITION', 'UNLENSED']: - fixed_high = {'ra_image': [100] * num, 'dec_image': [100] * num} - elif model in ['SOURCE_POSITION']: - fixed_high = {'ra_source': 100, 'dec_source': 100} - else: - raise ValueError("%s not a valid point source model" % model) - if self._fixed_magnification_list[k] is True and model in ['LENSED_POSITION', 'SOURCE_POSITION']: - fixed_high['source_amp'] = 100 - else: - fixed_high['point_amp'] = np.ones(num)*100 - kwargs_upper.append(fixed_high) - self.lower_limit = kwargs_lower - self.upper_limit = kwargs_upper - -
[docs] def get_params(self, args, i): - """ - - :param args: sorted list of floats corresponding to the parameters being sampled - :param i: int, index of first entry relevant for being managed by this class - :return: keyword argument list of point sources, index relevant for the next class - """ - kwargs_list = [] - for k, model in enumerate(self.model_list): - kwargs = {} - kwargs_fixed = self.kwargs_fixed[k] - if model in ['LENSED_POSITION', 'UNLENSED']: - if 'ra_image' not in kwargs_fixed: - kwargs['ra_image'] = np.array(args[i:i + self._num_point_sources_list[k]]) - i += self._num_point_sources_list[k] - else: - kwargs['ra_image'] = kwargs_fixed['ra_image'] - if 'dec_image' not in kwargs_fixed: - kwargs['dec_image'] = np.array(args[i:i + self._num_point_sources_list[k]]) - i += self._num_point_sources_list[k] - else: - kwargs['dec_image'] = kwargs_fixed['dec_image'] - if model in ['SOURCE_POSITION']: - if 'ra_source' not in kwargs_fixed: - kwargs['ra_source'] = args[i] - i += 1 - else: - kwargs['ra_source'] = kwargs_fixed['ra_source'] - if 'dec_source' not in kwargs_fixed: - kwargs['dec_source'] = args[i] - i += 1 - else: - kwargs['dec_source'] = kwargs_fixed['dec_source'] - # amplitude parameter handling - if self._fixed_magnification_list[k] is True and model in ['LENSED_POSITION', 'SOURCE_POSITION']: - if 'source_amp' not in kwargs_fixed: - kwargs['source_amp'] = args[i] - i += 1 - else: - kwargs['source_amp'] = kwargs_fixed['source_amp'] - else: - if 'point_amp' not in kwargs_fixed: - kwargs['point_amp'] = np.array(args[i:i + self._num_point_sources_list[k]]) - i += self._num_point_sources_list[k] - else: - kwargs['point_amp'] = kwargs_fixed['point_amp'] - - kwargs_list.append(kwargs) - return kwargs_list, i
- -
[docs] def set_params(self, kwargs_list): - """ - - :param kwargs_list: keyword argument list - :return: sorted list of parameters being sampled extracted from kwargs_list - """ - args = [] - for k, model in enumerate(self.model_list): - kwargs = kwargs_list[k] - kwargs_fixed = self.kwargs_fixed[k] - if model in ['LENSED_POSITION', 'UNLENSED']: - if 'ra_image' not in kwargs_fixed: - x_pos = kwargs['ra_image'][0:self._num_point_sources_list[k]] - for x in x_pos: - args.append(x) - if 'dec_image' not in kwargs_fixed: - y_pos = kwargs['dec_image'][0:self._num_point_sources_list[k]] - for y in y_pos: - args.append(y) - if model in ['SOURCE_POSITION']: - if 'ra_source' not in kwargs_fixed: - args.append(kwargs['ra_source']) - if 'dec_source' not in kwargs_fixed: - args.append(kwargs['dec_source']) - # amplitude parameter handling - if self._fixed_magnification_list[k] is True and model in ['LENSED_POSITION', 'SOURCE_POSITION']: - if 'source_amp' not in kwargs_fixed: - args.append(kwargs['source_amp']) - else: - if 'point_amp' not in kwargs_fixed: - amp = kwargs['point_amp'][0:self._num_point_sources_list[k]] - for a in amp: - args.append(a) - return args
- -
[docs] def num_param(self): - """ - number of parameters and their names - - :return: int, list of parameter names - """ - num = 0 - name_list = [] - for k, model in enumerate(self.model_list): - kwargs_fixed = self.kwargs_fixed[k] - if model in ['LENSED_POSITION', 'UNLENSED']: - if 'ra_image' not in kwargs_fixed: - num += self._num_point_sources_list[k] - for i in range(self._num_point_sources_list[k]): - name_list.append('ra_image') - if 'dec_image' not in kwargs_fixed: - num += self._num_point_sources_list[k] - for i in range(self._num_point_sources_list[k]): - name_list.append('dec_image') - if model in ['SOURCE_POSITION']: - if 'ra_source' not in kwargs_fixed: - num += 1 - name_list.append('ra_source') - if 'dec_source' not in kwargs_fixed: - num += 1 - name_list.append('dec_source') - # amplitude handling - if self._fixed_magnification_list[k] is True and model in ['LENSED_POSITION', 'SOURCE_POSITION']: - if 'source_amp' not in kwargs_fixed: - num += 1 - name_list.append('source_amp') - else: - if 'point_amp' not in kwargs_fixed: - num += self._num_point_sources_list[k] - for i in range(self._num_point_sources_list[k]): - name_list.append('point_amp') - return num, name_list
- -
[docs] def add_fix_linear(self, kwargs_fixed): - """ - updates fixed keyword argument list with linear parameters - - :param kwargs_fixed: list of keyword arguments held fixed during sampling - :return: updated keyword argument list - """ - for k, model in enumerate(self.model_list): - if self._fixed_magnification_list[k] is True and model in ['LENSED_POSITION', 'SOURCE_POSITION']: - kwargs_fixed[k]['source_amp'] = 1 - else: - kwargs_fixed[k]['point_amp'] = np.ones(self._num_point_sources_list[k]) - return kwargs_fixed
- -
[docs] def num_param_linear(self): - """ - - :return: number of linear parameters - """ - num = 0 - if self._linear_solver is True: - for k, model in enumerate(self.model_list): - if self._fixed_magnification_list[k] is True and model in ['LENSED_POSITION', 'SOURCE_POSITION']: - num += 1 - else: - num += self._num_point_sources_list[k] - return num
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Sampling/Likelihoods/image_likelihood.html b/docs/_build/html/_modules/lenstronomy/Sampling/Likelihoods/image_likelihood.html deleted file mode 100644 index 1ad3e6194..000000000 --- a/docs/_build/html/_modules/lenstronomy/Sampling/Likelihoods/image_likelihood.html +++ /dev/null @@ -1,164 +0,0 @@ - - - - - - - - lenstronomy.Sampling.Likelihoods.image_likelihood — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Sampling.Likelihoods.image_likelihood

-import numpy as np
-from lenstronomy.Util import class_creator
-
-__all__ = ['ImageLikelihood']
-
-
-
[docs]class ImageLikelihood(object): - """ - manages imaging data likelihoods - """ - - def __init__(self, multi_band_list, multi_band_type, kwargs_model, bands_compute=None, - image_likelihood_mask_list=None, source_marg=False, linear_prior=None, check_positive_flux=False, - kwargs_pixelbased=None): - """ - - :param bands_compute: list of bools with same length as data objects, indicates which "band" to include in the - fitting - :param image_likelihood_mask_list: list of boolean 2d arrays of size of images marking the pixels to be - evaluated in the likelihood - :param source_marg: marginalization addition on the imaging likelihood based on the covariance of the inferred - linear coefficients - :param linear_prior: float or list of floats (when multi-linear setting is chosen) indicating the range of - linear amplitude priors when computing the marginalization term. - :param check_positive_flux: bool, option to punish models that do not have all positive linear amplitude - parameters - :param kwargs_pixelbased: keyword arguments with various settings related to the pixel-based solver - (see SLITronomy documentation) - """ - self.imSim = class_creator.create_im_sim(multi_band_list, multi_band_type, kwargs_model, - bands_compute=bands_compute, - image_likelihood_mask_list=image_likelihood_mask_list, - kwargs_pixelbased=kwargs_pixelbased) - self._model_type = self.imSim.type - self._source_marg = source_marg - self._linear_prior = linear_prior - self._check_positive_flux = check_positive_flux - -
[docs] def logL(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_special=None, - kwargs_extinction=None): - """ - - :param kwargs_lens: lens model keyword argument list according to LensModel module - :param kwargs_source: source light keyword argument list according to LightModel module - :param kwargs_lens_light: deflector light (not lensed) keyword argument list according to LightModel module - :param kwargs_ps: point source keyword argument list according to PointSource module - :param kwargs_special: special keyword argument list as part of the Param module - :param kwargs_extinction: extinction parameter keyword argument list according to LightModel module - :return: log likelihood of the data given the model - """ - logL = self.imSim.likelihood_data_given_model(kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, - kwargs_extinction=kwargs_extinction, - kwargs_special=kwargs_special, - source_marg=self._source_marg, linear_prior=self._linear_prior, - check_positive_flux=self._check_positive_flux) - if np.isnan(logL) is True: - return -10 ** 15 - return logL
- - @property - def num_data(self): - """ - - :return: number of image data points - """ - return self.imSim.num_data_evaluate - -
[docs] def num_param_linear(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - kwargs_special=None, kwargs_extinction=None): - """ - - :return: number of linear parameters solved for during the image reconstruction process - """ - return self.imSim.num_param_linear(kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps)
- -
[docs] def reset_point_source_cache(self, cache=True): - """ - - :param cache: boolean - :return: - """ - self.imSim.reset_point_source_cache(cache=cache)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Sampling/Likelihoods/position_likelihood.html b/docs/_build/html/_modules/lenstronomy/Sampling/Likelihoods/position_likelihood.html deleted file mode 100644 index 0eec44544..000000000 --- a/docs/_build/html/_modules/lenstronomy/Sampling/Likelihoods/position_likelihood.html +++ /dev/null @@ -1,312 +0,0 @@ - - - - - - - - lenstronomy.Sampling.Likelihoods.position_likelihood — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Sampling.Likelihoods.position_likelihood

-import numpy as np
-from numpy.linalg import inv
-
-__all__ = ['PositionLikelihood']
-
-
-
[docs]class PositionLikelihood(object): - """ - likelihood of positions of multiply imaged point sources - """ - def __init__(self, point_source_class, image_position_uncertainty=0.005, astrometric_likelihood=False, - image_position_likelihood=False, ra_image_list=None, dec_image_list=None, - source_position_likelihood=False, check_matched_source_position=False, source_position_tolerance=0.001, - source_position_sigma=0.001, force_no_add_image=False, restrict_image_number=False, - max_num_images=None): - """ - - :param point_source_class: Instance of PointSource() class - :param image_position_uncertainty: uncertainty in image position uncertainty (1-sigma Gaussian radially), - this is applicable for astrometric uncertainties as well as if image positions are provided as data - :param astrometric_likelihood: bool, if True, evaluates the astrometric uncertainty of the predicted and modeled - image positions with an offset 'delta_x_image' and 'delta_y_image' - :param image_position_likelihood: bool, if True, evaluates the likelihood of the model predicted image position - given the data/measured image positions - :param ra_image_list: list or RA image positions per model component - :param dec_image_list: list or DEC image positions per model component - :param source_position_likelihood: bool, if True, ray-traces image positions back to source plane and evaluates - relative errors in respect ot the position_uncertainties in the image plane - :param check_matched_source_position: bool, if True, checks whether multiple images are a solution of the same - source - :param source_position_tolerance: tolerance level (in arc seconds in the source plane) of the different images - :param source_position_sigma: r.m.s. value corresponding to a 1-sigma Gaussian likelihood accepted by the model - precision in matching the source position - :param force_no_add_image: bool, if True, will punish additional images appearing in the frame of the modelled - image(first calculate them) - :param restrict_image_number: bool, if True, searches for all appearing images in the frame of the data and - compares with max_num_images - :param max_num_images: integer, maximum number of appearing images. Default is the number of images given in - the Param() class - """ - self._pointSource = point_source_class - # TODO replace with public function of ray_shooting - self._lensModel = point_source_class._lensModel - self._astrometric_likelihood = astrometric_likelihood - self._image_position_sigma = image_position_uncertainty - self._source_position_sigma = source_position_sigma - self._check_matched_source_position = check_matched_source_position - self._bound_source_position_scatter = source_position_tolerance - self._force_no_add_image = force_no_add_image - self._restrict_number_images = restrict_image_number - self._source_position_likelihood = source_position_likelihood - self._max_num_images = max_num_images - if max_num_images is None and restrict_image_number is True: - raise ValueError('max_num_images needs to be provided when restrict_number_images is True!') - self._image_position_likelihood = image_position_likelihood - if ra_image_list is None: - ra_image_list = [] - if dec_image_list is None: - dec_image_list = [] - self._ra_image_list, self._dec_image_list = ra_image_list, dec_image_list - -
[docs] def logL(self, kwargs_lens, kwargs_ps, kwargs_special, verbose=False): - """ - - :param kwargs_lens: lens model parameter keyword argument list - :param kwargs_ps: point source model parameter keyword argument list - :param kwargs_special: special keyword arguments - :param verbose: bool - :return: log likelihood of the optional likelihoods being computed - """ - - logL = 0 - if self._astrometric_likelihood is True: - logL_astrometry = self.astrometric_likelihood(kwargs_ps, kwargs_special, self._image_position_sigma) - logL += logL_astrometry - if verbose is True: - print('Astrometric likelihood = %s' % logL_astrometry) - if self._check_matched_source_position is True: - logL_source_scatter = self.source_position_likelihood(kwargs_lens, kwargs_ps, self._source_position_sigma, hard_bound_rms=self._bound_source_position_scatter, verbose=verbose) - logL += logL_source_scatter - if verbose is True: - print('Source scatter punishing likelihood = %s' % logL_source_scatter) - if self._force_no_add_image: - additional_image_bool = self.check_additional_images(kwargs_ps, kwargs_lens) - if additional_image_bool is True: - logL -= 10.**5 - if verbose is True: - print('force no additional image penalty as additional images are found!') - if self._restrict_number_images is True: - ra_image_list, dec_image_list = self._pointSource.image_position(kwargs_ps=kwargs_ps, kwargs_lens=kwargs_lens) - if len(ra_image_list[0]) > self._max_num_images: - logL -= 10.**5 - if verbose is True: - print('Number of images found %s exceeded the limited number allowed %s' % (len(ra_image_list[0]), self._max_num_images)) - if self._source_position_likelihood is True: - logL_source_pos = self.source_position_likelihood(kwargs_lens, kwargs_ps, sigma=self._image_position_sigma) - logL += logL_source_pos - if verbose is True: - print('source position likelihood %s' % logL_source_pos) - if self._image_position_likelihood is True: - logL_image_pos = self.image_position_likelihood(kwargs_ps=kwargs_ps, kwargs_lens=kwargs_lens, sigma=self._image_position_sigma) - logL += logL_image_pos - if verbose is True: - print('image position likelihood %s' % logL_image_pos) - return logL
- -
[docs] def check_additional_images(self, kwargs_ps, kwargs_lens): - """ - checks whether additional images have been found and placed in kwargs_ps of the first point source model - #TODO check for all point source models - :param kwargs_ps: point source kwargs - :return: bool, True if more image positions are found than originally been assigned - """ - ra_image_list, dec_image_list = self._pointSource.image_position(kwargs_ps=kwargs_ps, kwargs_lens=kwargs_lens) - if len(ra_image_list) > 0: - if 'ra_image' in kwargs_ps[0]: - if len(ra_image_list[0]) > len(kwargs_ps[0]['ra_image']): - return True - return False
- -
[docs] @staticmethod - def astrometric_likelihood(kwargs_ps, kwargs_special, sigma): - """ - evaluates the astrometric uncertainty of the model plotted point sources (only available for 'LENSED_POSITION' - point source model) and predicted image position by the lens model including an astrometric correction term. - - :param kwargs_ps: point source model kwargs list - :param kwargs_special: kwargs list, should include the astrometric corrections 'delta_x', 'delta_y' - :param sigma: 1-sigma Gaussian uncertainty in the astrometry - :return: log likelihood of the astrometirc correction between predicted image positions and model placement of the point sources - """ - if not len(kwargs_ps) > 0: - return 0 - if 'ra_image' not in kwargs_ps[0]: - return 0 - if 'delta_x_image' in kwargs_special: - delta_x, delta_y = np.array(kwargs_special['delta_x_image']), np.array(kwargs_special['delta_y_image']) - dist = (delta_x ** 2 + delta_y ** 2) / sigma ** 2 / 2 - logL = -np.sum(dist) - if np.isnan(logL) is True: - return -10**15 - return logL - else: - return 0
- -
[docs] def image_position_likelihood(self, kwargs_ps, kwargs_lens, sigma): - """ - computes the likelihood of the model predicted image position relative to measured image positions with an astrometric error. - This routine requires the 'ra_image_list' and 'dec_image_list' being declared in the initiation of the class - - :param kwargs_ps: point source keyword argument list - :param kwargs_lens: lens model keyword argument list - :param sigma: 1-sigma uncertainty in the measured position of the images - :return: log likelihood of the model predicted image positions given the data/measured image positions. - """ - ra_image_list, dec_image_list = self._pointSource.image_position(kwargs_ps=kwargs_ps, kwargs_lens=kwargs_lens) - logL = 0 - for i in range(len(ra_image_list)): # sum over the images of the different model components - logL += -np.sum(((ra_image_list[i] - self._ra_image_list[i])**2 + (dec_image_list[i] - self._dec_image_list[i])**2) / sigma**2 / 2) - return logL
- -
[docs] def source_position_likelihood(self, kwargs_lens, kwargs_ps, sigma, hard_bound_rms=None, verbose=False): - """ - computes a likelihood/punishing factor of how well the source positions of multiple images match given the image - position and a lens model. - The likelihood level is computed in respect of a displacement in the image plane and transposed through the - Hessian into the source plane. - - :param kwargs_lens: lens model keyword argument list - :param kwargs_ps: point source keyword argument list - :param sigma: 1-sigma Gaussian uncertainty in the image plane - :param hard_bound_rms: hard bound deviation between the mapping of the images back to the source plane (in source frame) - :param verbose: bool, if True provides print statements with useful information. - :return: log likelihood of the model reproducing the correct image positions given an image position uncertainty - """ - if len(kwargs_ps) < 1: - return 0 - logL = 0 - source_x, source_y = self._pointSource.source_position(kwargs_ps, kwargs_lens) - for k in range(len(kwargs_ps)): - if 'ra_image' in kwargs_ps[k] and self._pointSource.point_source_type_list[k] == 'LENSED_POSITION': - - x_image = kwargs_ps[k]['ra_image'] - y_image = kwargs_ps[k]['dec_image'] - # calculating the individual source positions from the image positions - # TODO: have option for ray-shooting back to specific redshift in multi-plane lensing - x_source, y_source = self._lensModel.ray_shooting(x_image, y_image, kwargs_lens) - for i in range(len(x_image)): - # TODO: add redshift information in computation - f_xx, f_xy, f_yx, f_yy = self._lensModel.hessian(x_image[i], y_image[i], kwargs_lens) - A = np.array([[1 - f_xx, -f_xy], [-f_yx, 1 - f_yy]]) - Sigma_theta = np.array([[1, 0], [0, 1]]) * sigma ** 2 - Sigma_beta = image2source_covariance(A, Sigma_theta) - delta = np.array([source_x[k] - x_source[i], source_y[k] - y_source[i]]) - if hard_bound_rms is not None: - if delta[0]**2 + delta[1]**2 > hard_bound_rms**2: - if verbose is True: - print('Image positions do not match to the same source position to the required ' - 'precision. Achieved: %s, Required: %s.' % (delta, hard_bound_rms)) - logL -= 10 ** 3 - try: - Sigma_inv = inv(Sigma_beta) - except: - return -10**15 - chi2 = delta.T.dot(Sigma_inv.dot(delta)) - logL -= chi2 / 2 - return logL
- - @property - def num_data(self): - """ - - :return: integer, number of data points associated with the class instance - """ - num = 0 - if self._image_position_likelihood is True: - for i in range(len(self._ra_image_list)): # sum over the images of the different model components - num += len(self._ra_image_list[i]) * 2 - return num
- - -# Equation (13) in Birrer & Treu 2019 -def image2source_covariance(A, Sigma_theta): - """ - computes error covariance in the source plane - A: Hessian lensing matrix - Sigma_theta: image plane covariance matrix of uncertainties - """ - ATSigma = np.matmul(A.T, Sigma_theta) - return np.matmul(ATSigma, A) -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Sampling/Likelihoods/prior_likelihood.html b/docs/_build/html/_modules/lenstronomy/Sampling/Likelihoods/prior_likelihood.html deleted file mode 100644 index 1ed05e0be..000000000 --- a/docs/_build/html/_modules/lenstronomy/Sampling/Likelihoods/prior_likelihood.html +++ /dev/null @@ -1,283 +0,0 @@ - - - - - - - - lenstronomy.Sampling.Likelihoods.prior_likelihood — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Sampling.Likelihoods.prior_likelihood

-import numpy as np
-from lenstronomy.Util.prob_density import KDE1D
-
-__all__ = ['PriorLikelihood']
-
-
-
[docs]class PriorLikelihood(object): - """ - class containing additional Gaussian priors to be folded into the likelihood - - """ - def __init__(self, prior_lens=None, prior_source=None, prior_lens_light=None, prior_ps=None, prior_special=None, - prior_extinction=None, prior_lens_kde=None, prior_source_kde=None, prior_lens_light_kde=None, - prior_ps_kde=None, - prior_special_kde=None, prior_extinction_kde=None, - prior_lens_lognormal=None, prior_source_lognormal=None, - prior_lens_light_lognormal=None, - prior_ps_lognormal=None, prior_special_lognormal=None, - prior_extinction_lognormal=None, - ): - """ - - :param prior_lens: list of [index_model, param_name, mean, 1-sigma priors] - :param prior_source: list of [index_model, param_name, mean, 1-sigma priors] - :param prior_lens_light: list of [index_model, param_name, mean, 1-sigma priors] - :param prior_ps: list of [index_model, param_name, mean, 1-sigma priors] - :param prior_special: list of [param_name, mean, 1-sigma priors] - :param prior_extinction: list of [index_model, param_name, mean, 1-sigma priors] - - :param prior_lens_kde: list of [index_model, param_name, samples] - :param prior_source_kde: list of [index_model, param_name, samples] - :param prior_lens_light_kde: list of [index_model, param_name, samples] - :param prior_ps_kde: list of [index_model, param_name, samples] - :param prior_special_kde: list of [param_name, samples] - :param prior_extinction_kde: list of [index_model, param_name, samples] - - :param prior_lens_lognormal: list of [index_model, param_name, mean, 1-sigma - priors] - :param prior_source_lognormal: list of [index_model, param_name, mean, 1-sigma priors] - :param prior_lens_light_lognormal: list of [index_model, param_name, mean, 1-sigma priors] - :param prior_ps_lognormal: list of [index_model, param_name, mean, 1-sigma priors] - :param prior_special_lognormal: list of [param_name, mean, 1-sigma priors] - :param prior_extinction_lognormal: list of [index_model, param_name, mean, 1-sigma priors] - - """ - - self._prior_lens, self._prior_source, self._prior_lens_light, self._prior_ps, self._prior_special, self._prior_extinction = \ - prior_lens, prior_source, prior_lens_light, prior_ps, prior_special, prior_extinction - self._prior_lens_kde, self._prior_source_kde, self._prior_lens_light_kde, self._prior_ps_kde = prior_lens_kde, \ - prior_source_kde, \ - prior_lens_light_kde, \ - prior_ps_kde - self._prior_lens_lognormal, self._prior_source_lognormal, \ - self._prior_lens_light_lognormal, \ - self._prior_ps_lognormal, self._prior_special_lognormal, \ - self._prior_extinction_lognormal = \ - prior_lens_lognormal, prior_source_lognormal, \ - prior_lens_light_lognormal, prior_ps_lognormal, \ - prior_special_lognormal, prior_extinction_lognormal - - self._kde_lens_list = self._init_kde(prior_lens_kde) - self._kde_source_list = self._init_kde(prior_source_kde) - self._kde_lens_light_list = self._init_kde(prior_lens_light_kde) - self._kde_ps_list = self._init_kde(prior_ps_kde) - self._kde_lens_light_list = self._init_kde(prior_lens_light_kde) - - @staticmethod - def _init_kde(prior_list_kde): - """ - - :param prior_list_kde: list of [index_model, param_name, samples] - :return: list of initiated KDE's - """ - if prior_list_kde is None: - return 0 - kde_list = [] - for prior in prior_list_kde: - index, param_name, samples = prior - kde_list.append(KDE1D(values=samples)) - return kde_list - -
[docs] def logL(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_special=None, - kwargs_extinction=None): - """ - - :param kwargs_lens: lens model parameter list - :return: log likelihood of lens center - """ - logL = 0 - logL += self._prior_kwargs_list(kwargs_lens, self._prior_lens) - logL += self._prior_kwargs_list(kwargs_source, self._prior_source) - logL += self._prior_kwargs_list(kwargs_lens_light, self._prior_lens_light) - logL += self._prior_kwargs_list(kwargs_ps, self._prior_ps) - logL += self._prior_kwargs(kwargs_special, self._prior_special) - logL += self._prior_kwargs_list(kwargs_extinction, self._prior_extinction) - - logL += self._prior_lognormal_kwargs_list(kwargs_lens, - self._prior_lens_lognormal) - logL += self._prior_lognormal_kwargs_list(kwargs_source, self._prior_source_lognormal) - logL += self._prior_lognormal_kwargs_list(kwargs_lens_light, - self._prior_lens_light_lognormal) - logL += self._prior_lognormal_kwargs_list(kwargs_ps, self._prior_ps_lognormal) - logL += self._prior_lognormal_kwargs(kwargs_special, self._prior_special_lognormal) - logL += self._prior_lognormal_kwargs_list(kwargs_extinction, - self._prior_extinction_lognormal) - - logL += self._prior_kde_list(kwargs_lens, self._prior_lens_kde, self._kde_lens_list) - logL += self._prior_kde_list(kwargs_source, self._prior_source_kde, self._kde_source_list) - logL += self._prior_kde_list(kwargs_lens_light, self._prior_lens_light_kde, self._kde_lens_light_list) - logL += self._prior_kde_list(kwargs_ps, self._prior_ps_kde, self._kde_ps_list) - return logL
- - @staticmethod - def _prior_kde_list(kwargs_list, prior_list, kde_list): - """ - - :param kwargs_list: - :param prior_list: - :return: - """ - if prior_list is None: - return 0 - logL = 0 - for i in range(len(prior_list)): - index, param_name, values = prior_list[i] - model_value = kwargs_list[index][param_name] - likelihood = kde_list[i].likelihood(model_value)[0] - logL += np.log(likelihood) - return logL - - @staticmethod - def _prior_kwargs_list(kwargs_list, prior_list): - """ - - :param kwargs_list: keyword argument list - :param prior_list: prior list - :return: logL - """ - if prior_list is None: - return 0 - logL = 0 - for i in range(len(prior_list)): - index, param_name, value, sigma = prior_list[i] - model_value = kwargs_list[index][param_name] - dist = (model_value - value) ** 2 / sigma ** 2 / 2 - logL -= np.sum(dist) - return logL - - @staticmethod - def _prior_kwargs(kwargs, prior_list): - """ - prior computation for a keyword argument (not list thereof) - - :param kwargs: keyword argument - :return: logL - """ - if prior_list is None: - return 0 - logL = 0 - for i in range(len(prior_list)): - param_name, value, sigma = prior_list[i] - model_value = kwargs[param_name] - dist = (model_value - value) ** 2 / sigma ** 2 / 2 - logL -= np.sum(dist) - return logL - - @staticmethod - def _prior_lognormal_kwargs_list(kwargs_list, prior_list): - """ - - :param kwargs_list: keyword argument list - :param prior_list: prior list - :return: logL - """ - if prior_list is None: - return 0 - logL = 0 - for i in range(len(prior_list)): - index, param_name, value, sigma = prior_list[i] - model_value = kwargs_list[index][param_name] - dist = (np.log(model_value) - value) ** 2 / sigma ** 2 / 2 + model_value - logL -= np.sum(dist) - return logL - - @staticmethod - def _prior_lognormal_kwargs(kwargs, prior_list): - """ - prior computation for a keyword argument (not list thereof) - - :param kwargs: keyword argument - :return: logL - """ - if prior_list is None: - return 0 - logL = 0 - for i in range(len(prior_list)): - param_name, value, sigma = prior_list[i] - model_value = kwargs[param_name] - dist = (np.log(model_value) - value) ** 2 / sigma ** 2 / 2 + model_value - logL -= np.sum(dist) - return logL
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Sampling/Likelihoods/time_delay_likelihood.html b/docs/_build/html/_modules/lenstronomy/Sampling/Likelihoods/time_delay_likelihood.html deleted file mode 100644 index 36a404b82..000000000 --- a/docs/_build/html/_modules/lenstronomy/Sampling/Likelihoods/time_delay_likelihood.html +++ /dev/null @@ -1,158 +0,0 @@ - - - - - - - - lenstronomy.Sampling.Likelihoods.time_delay_likelihood — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Sampling.Likelihoods.time_delay_likelihood

-import numpy as np
-import lenstronomy.Util.constants as const
-
-__all__ = ['TimeDelayLikelihood']
-
-
-
[docs]class TimeDelayLikelihood(object): - """ - class to compute the likelihood of a model given a measurement of time delays - """ - def __init__(self, time_delays_measured, time_delays_uncertainties, lens_model_class, point_source_class): - """ - - :param time_delays_measured: relative time delays (in days) in respect to the first image of the point source - :param time_delays_uncertainties: time-delay uncertainties in same order as time_delay_measured. Alternatively - a full covariance matrix that describes the likelihood. - :param lens_model_class: instance of the LensModel() class - :param point_source_class: instance of the PointSource() class, note: the first point source type is the one the - time delays are imposed on - """ - - if time_delays_measured is None: - raise ValueError("time_delay_measured need to be specified to evaluate the time-delay likelihood.") - if time_delays_uncertainties is None: - raise ValueError("time_delay_uncertainties need to be specified to evaluate the time-delay likelihood.") - self._delays_measured = np.array(time_delays_measured) - self._delays_errors = np.array(time_delays_uncertainties) - self._lensModel = lens_model_class - self._pointSource = point_source_class - -
[docs] def logL(self, kwargs_lens, kwargs_ps, kwargs_cosmo): - """ - routine to compute the log likelihood of the time delay distance - :param kwargs_lens: lens model kwargs list - :param kwargs_ps: point source kwargs list - :param kwargs_cosmo: cosmology and other kwargs - :return: log likelihood of the model given the time delay data - """ - x_pos, y_pos = self._pointSource.image_position(kwargs_ps=kwargs_ps, kwargs_lens=kwargs_lens, original_position=True) - x_pos, y_pos = x_pos[0], y_pos[0] - delay_arcsec = self._lensModel.fermat_potential(x_pos, y_pos, kwargs_lens) - D_dt_model = kwargs_cosmo['D_dt'] - delay_days = const.delay_arcsec2days(delay_arcsec, D_dt_model) - logL = self._logL_delays(delay_days, self._delays_measured, self._delays_errors) - return logL
- - @staticmethod - def _logL_delays(delays_model, delays_measured, delays_errors): - """ - log likelihood of modeled delays vs measured time delays under considerations of errors - - :param delays_model: n delays of the model (not relative delays) - :param delays_measured: relative delays (1-2,1-3,1-4) relative to the first in the list - :param delays_errors: gaussian errors on the measured delays - :return: log likelihood of data given model - """ - if len(delays_model)-1 != len(delays_measured): - return -10**15 - delta_t_model = np.array(delays_model[1:]) - delays_model[0] - if delays_errors.ndim <= 1: - logL = np.sum(-(delta_t_model - delays_measured) ** 2 / (2 * delays_errors ** 2)) - elif delays_errors.ndim == 2: - D = delta_t_model - delays_measured - logL = -1/2 * D @ np.linalg.inv(delays_errors) @ D # TODO: only calculate the inverse once - else: - raise ValueError('Dimension of time delay error needs to be either one- or two-dimensional, not %s' - % delays_errors.ndim) - return logL - - @property - def num_data(self): - """ - - :return: number of time delay measurements - """ - return len(self._delays_measured)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Sampling/Pool/multiprocessing.html b/docs/_build/html/_modules/lenstronomy/Sampling/Pool/multiprocessing.html deleted file mode 100644 index f24a79682..000000000 --- a/docs/_build/html/_modules/lenstronomy/Sampling/Pool/multiprocessing.html +++ /dev/null @@ -1,212 +0,0 @@ - - - - - - - - lenstronomy.Sampling.Pool.multiprocessing — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Sampling.Pool.multiprocessing

-"""
-this file is taken from schwimmbad (https://github.com/adrn/schwimmbad) and an explicit fork by Aymeric Galan
-to replace the multiprocessing with the multiprocess dependence as for multi-threading, multiprocessing is
-not supporting dill (only pickle) which is required.
-
-The class also extends with a ``is_master()`` definition
-
-"""
-
-
-# Standard library
-
-import signal
-import functools
-import multiprocess
-from multiprocess.pool import Pool
-
-__all__ = ['MultiPool']
-
-
-def _initializer_wrapper(actual_initializer, *rest):
-    """
-    We ignore SIGINT. It's up to our parent to kill us in the typical condition of this arising from ``^C`` on a
-    terminal. If someone is manually killing us with that signal, well... nothing will happen.
-    """
-    signal.signal(signal.SIGINT, signal.SIG_IGN)
-    if actual_initializer is not None:
-        actual_initializer(*rest)
-
-
-class CallbackWrapper(object):
-
-    def __init__(self, callback):
-        self.callback = callback
-
-    def __call__(self, tasks):
-        for task in tasks:
-            self.callback(task)
-
-
-
[docs]class MultiPool(Pool): - """ - A modified version of :class:`multiprocessing.pool.Pool` that has better - behavior with regard to ``KeyboardInterrupts`` in the :func:`map` method. - (Original author: `Peter K. G. Williams <peter@newton.cx>`_) - - Parameters - ---------- - processes : int, optional - The number of worker processes to use; defaults to the number of CPUs. - - initializer : callable, optional - If specified, a callable that will be invoked by each worker process when it starts. - - initargs : iterable, optional - Arguments for ``initializer``; it will be called as ``initializer(*initargs)``. - - kwargs: - Extra arguments passed to the :class:`multiprocessing.pool.Pool` superclass. - - """ - wait_timeout = 3600 - - def __init__(self, processes=None, initializer=None, initargs=(), **kwargs): - new_initializer = functools.partial(_initializer_wrapper, initializer) - super(MultiPool, self).__init__(processes, new_initializer, - initargs, **kwargs) - self.size = self._processes - self.rank = 0 - -
[docs] def is_master(self): - return self.rank == 0
- -
[docs] def is_worker(self): - return self.rank != 0
- -
[docs] @staticmethod - def enabled(): - return True
- -
[docs] def map(self, func, iterable, chunksize=None, callback=None): - """ - Equivalent to the built-in ``map()`` function and - :meth:`multiprocessing.pool.Pool.map()`, without catching - ``KeyboardInterrupt``. - - Parameters - ---------- - func : callable - A function or callable object that is executed on each element of - the specified ``tasks`` iterable. This object must be picklable - (i.e. it can't be a function scoped within a function or a - ``lambda`` function). This should accept a single positional - argument and return a single object. - iterable : iterable - A list or iterable of tasks. Each task can be itself an iterable - (e.g., tuple) of values or data to pass in to the worker function. - callback : callable, optional - An optional callback function (or callable) that is called with the - result from each worker run and is executed on the master process. - This is useful for, e.g., saving results to a file, since the - callback is only called on the master thread. - - Returns - ------- - results : list - A list of results from the output of each ``worker()`` call. - - """ - - if callback is None: - callbackwrapper = None - else: - callbackwrapper = CallbackWrapper(callback) - - # The key magic is that we must call r.get() with a timeout, because - # a Condition.wait() without a timeout swallows KeyboardInterrupts. - r = self.map_async(func, iterable, chunksize=chunksize, callback=callbackwrapper) - - while True: - try: - return r.get(self.wait_timeout) - - except multiprocess.TimeoutError: - pass - - except KeyboardInterrupt: - self.terminate() - self.join() - raise
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Sampling/Pool/pool.html b/docs/_build/html/_modules/lenstronomy/Sampling/Pool/pool.html deleted file mode 100644 index df09faec3..000000000 --- a/docs/_build/html/_modules/lenstronomy/Sampling/Pool/pool.html +++ /dev/null @@ -1,180 +0,0 @@ - - - - - - - - lenstronomy.Sampling.Pool.pool — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Sampling.Pool.pool

-# coding: utf-8
-"""
-this file is taken from schwimmbad (https://github.com/adrn/schwimmbad) and an explicit fork by Aymeric Galan
-to replace the multiprocessing with the multiprocess dependence as for multi-threading, multiprocessing is
-not supporting dill (only pickle) which is required.
-
-Tests show that the MPI mode works with Python 3.7.2 but not with Python 3.7.0 on a specific system due to mpi4py
-dependencies and configurations.
-
-
-Contributions by:
-- Peter K. G. Williams
-- Júlio Hoffimann Mendes
-- Dan Foreman-Mackey
-- Aymeric Galan
-- Simon Birrer
-
-Implementations of four different types of processing pools:
-
-    - MPIPool: An MPI pool.
-    - MultiPool: A multiprocessing for local parallelization.
-    - SerialPool: A serial pool, which uses the built-in `map` function
-
-"""
-
-__version__ = "0.3.0"
-__author__ = "Adrian Price-Whelan <adrianmpw@gmail.com>"
-
-# Standard library
-import sys
-import logging
-log = logging.getLogger(__name__)
-_VERBOSE = 5
-
-# from schwimmbad.multiprocessing import MultiPool
-# from schwimmbad.jl import JoblibPool
-
-__all__ = ['choose_pool']
-
-
-
[docs]def choose_pool(mpi=False, processes=1, **kwargs): - """ - Extends the capabilities of the schwimmbad.choose_pool method. - - It handles the `use_dill` parameters in kwargs, that would otherwise raise an error when processes > 1. - Any thread in the returned multiprocessing pool (e.g. processes > 1) also default - - The requirement of schwimmbad relies on the master branch (as specified in requirements.txt). - The 'use_dill' functionality can raise if not following the requirement specified. - - Choose between the different pools given options from, e.g., argparse. - - Parameters - ---------- - mpi : bool, optional - Use the MPI processing pool, :class:`~schwimmbad.mpi.MPIPool`. By - default, ``False``, will use the :class:`~schwimmbad.serial.SerialPool`. - processes : int, optional - Use the multiprocessing pool, - :class:`~schwimmbad.multiprocessing.MultiPool`, with this number of - processes. By default, ``processes=1``, will use them:class:`~schwimmbad.serial.SerialPool`. - - Any additional kwargs are passed in to the pool class initializer selected by the arguments. - - """ - # Imports moved here to avoid crashing at import time if dependencies - # are missing - from lenstronomy.Sampling.Pool.multiprocessing import MultiPool - from schwimmbad.serial import SerialPool - from schwimmbad.mpi import MPIPool - - if mpi: - if not MPIPool.enabled(): - raise SystemError("Tried to run with MPI but MPIPool not enabled.") - try: - pool = MPIPool(**kwargs) - except: - raise ImportError('MPIPool of schwimmbad can not be generated. lenstronomy uses a specific branch of ' - 'schwimmbad specified in the requirements.txt. Make sure you are using the correct ' - 'version of schwimmbad. In particular the "use_dill" argument is not supported in the ' - 'pypi version 0.3.0.') - if not pool.is_master(): - pool.wait() - sys.exit(0) - - log.info("Running with MPI on {0} cores".format(pool.size)) - return pool - - elif processes != 1 and MultiPool.enabled(): - if 'use_dill' in kwargs: - # schwimmbad MultiPool does not support dill so we remove this option from the kwargs - _ = kwargs.pop('use_dill') - log.info("Running with MultiPool on {0} cores".format(processes)) - return MultiPool(processes=processes, **kwargs) - - else: - log.info("Running with SerialPool") - return SerialPool(**kwargs)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Sampling/Samplers/base_nested_sampler.html b/docs/_build/html/_modules/lenstronomy/Sampling/Samplers/base_nested_sampler.html deleted file mode 100644 index ee6c4d98d..000000000 --- a/docs/_build/html/_modules/lenstronomy/Sampling/Samplers/base_nested_sampler.html +++ /dev/null @@ -1,142 +0,0 @@ - - - - - - - - lenstronomy.Sampling.Samplers.base_nested_sampler — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Sampling.Samplers.base_nested_sampler

-__author__ = 'aymgal'
-
-import lenstronomy.Util.sampling_util as utils
-
-__all__ = ['NestedSampler']
-
-
-
[docs]class NestedSampler(object): - """ - Base class for nested samplers - """ - - def __init__(self, likelihood_module, prior_type, - prior_means, prior_sigmas, width_scale, sigma_scale): - """ - :param likelihood_module: likelihood_module like in likelihood.py (should be callable) - :param prior_type: 'uniform' of 'gaussian', for converting the unit hypercube to param cube - :param prior_means: if prior_type is 'gaussian', mean for each param - :param prior_sigmas: if prior_type is 'gaussian', std dev for each param - :param width_scale: scale the widths of the parameters space by this factor - :param sigma_scale: if prior_type is 'gaussian', scale the gaussian sigma by this factor - """ - self._ll = likelihood_module - self.n_dims, self.param_names = self._ll.param.num_param() - - lowers, uppers = self._ll.param_limits - if width_scale < 1: - self.lowers, self.uppers = utils.scale_limits(lowers, uppers, width_scale) - else: - self.lowers, self.uppers = lowers, uppers - - if prior_type == 'gaussian': - if prior_means is None or prior_sigmas is None: - raise ValueError("For gaussian prior type, means and sigmas are required") - self.means, self.sigmas = prior_means, prior_sigmas * sigma_scale - self.lowers, self.uppers = lowers, uppers - elif prior_type != 'uniform': - raise ValueError("Sampling type {} not supported".format(prior_type)) - self.prior_type = prior_type - self._has_warned = False - -
[docs] def prior(self, *args, **kwargs): - """ - compute the mapping between the unit cube and parameter cube - - :return: hypercube in parameter space - """ - raise NotImplementedError("Method not be implemented in base class")
- -
[docs] def log_likelihood(self, *args, **kwargs): - """ - compute the log-likelihood given list of parameters - - :return: log-likelihood (from the likelihood module) - """ - raise NotImplementedError("Method not be implemented in base class")
- -
[docs] def run(self, kwargs_run): - """run the nested sampling algorithm""" - raise NotImplementedError("Method not be implemented in base class")
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Sampling/Samplers/dynesty_sampler.html b/docs/_build/html/_modules/lenstronomy/Sampling/Samplers/dynesty_sampler.html deleted file mode 100644 index 6a5258d95..000000000 --- a/docs/_build/html/_modules/lenstronomy/Sampling/Samplers/dynesty_sampler.html +++ /dev/null @@ -1,218 +0,0 @@ - - - - - - - - lenstronomy.Sampling.Samplers.dynesty_sampler — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Sampling.Samplers.dynesty_sampler

-__author__ = 'aymgal'
-
-import numpy as np
-
-from lenstronomy.Sampling.Samplers.base_nested_sampler import NestedSampler
-import lenstronomy.Util.sampling_util as utils
-
-__all__ = ['DynestySampler']
-
-
-
[docs]class DynestySampler(NestedSampler): - """ - Wrapper for dynamical nested sampling algorithm Dynesty by J. Speagle - - paper : https://arxiv.org/abs/1904.02180 - doc : https://dynesty.readthedocs.io/ - """ - - def __init__(self, likelihood_module, prior_type='uniform', - prior_means=None, prior_sigmas=None, width_scale=1, sigma_scale=1, - bound='multi', sample='auto', use_mpi=False, use_pool=None): - """ - :param likelihood_module: likelihood_module like in likelihood.py (should be callable) - :param prior_type: 'uniform' of 'gaussian', for converting the unit hypercube to param cube - :param prior_means: if prior_type is 'gaussian', mean for each param - :param prior_sigmas: if prior_type is 'gaussian', std dev for each param - :param width_scale: scale the widths of the parameters space by this factor - :param sigma_scale: if prior_type is 'gaussian', scale the gaussian sigma by this factor - :param bound: specific to Dynesty, see https://dynesty.readthedocs.io - :param sample: specific to Dynesty, see https://dynesty.readthedocs.io - :param use_mpi: Use MPI computing if `True` - :param use_pool: specific to Dynesty, see https://dynesty.readthedocs.io - """ - self._check_install() - super(DynestySampler, self).__init__(likelihood_module, prior_type, - prior_means, prior_sigmas, - width_scale, sigma_scale) - - # create the Dynesty sampler - if use_mpi: - from schwimmbad import MPIPool - import sys - - pool = MPIPool(use_dill=True) # use_dill=True not supported for some versions of schwimmbad - if not pool.is_master(): - pool.wait() - sys.exit(0) - - self._sampler = self._dynesty.DynamicNestedSampler(self.log_likelihood, self.prior, self.n_dims, - bound=bound, sample=sample, pool=pool, use_pool=use_pool) - else: - self._sampler = self._dynesty.DynamicNestedSampler(self.log_likelihood, self.prior, self.n_dims, - bound=bound, sample=sample) - self._has_warned = False - -
[docs] def prior(self, u): - """ - compute the mapping between the unit cube and parameter cube - - :param u: unit hypercube, sampled by the algorithm - :return: hypercube in parameter space - """ - if self.prior_type == 'gaussian': - p = utils.cube2args_gaussian(u, self.lowers, self.uppers, - self.means, self.sigmas, self.n_dims, - copy=True) - elif self.prior_type == 'uniform': - p = utils.cube2args_uniform(u, self.lowers, self.uppers, - self.n_dims, copy=True) - else: - raise ValueError('prior type %s not supported! Chose "gaussian" or "uniform".') - return p
- -
[docs] def log_likelihood(self, x): - """ - compute the log-likelihood given list of parameters - - :param x: parameter values - :return: log-likelihood (from the likelihood module) - """ - log_l = self._ll(x) - if not np.isfinite(log_l): - if not self._has_warned: - print("WARNING : logL is not finite : return very low value instead") - log_l = -1e15 - self._has_warned = True - return float(log_l)
- -
[docs] def run(self, kwargs_run): - """ - run the Dynesty nested sampler - - see https://dynesty.readthedocs.io for content of kwargs_run - - :param kwargs_run: kwargs directly passed to DynamicNestedSampler.run_nested - :return: samples, means, logZ, logZ_err, logL, results - """ - print("prior type :", self.prior_type) - print("parameter names :", self.param_names) - - self._sampler.run_nested(**kwargs_run) - - results = self._sampler.results - samples_w = results.samples # weighted samples - log_l = results.logl - log_z = results.logz - log_z_err = results.logzerr - - # Compute weighted mean and covariance. - weights = np.exp(results.logwt - log_z[-1]) # normalized weights - if np.sum(weights) != 1.: - # TODO : clearly this is not optimal... - # weights should by definition be normalized, but it appears that for very small - # number of live points (typically in test routines), - # it is not *quite* the case (up to 6 decimals) - weights = weights / np.sum(weights) - - means, covs = self._dyfunc.mean_and_cov(samples_w, weights) - - # Resample weighted samples to get equally weighted (aka unweighted) samples - samples = self._dyfunc.resample_equal(samples_w, weights) - - return samples, means, log_z, log_z_err, log_l, results
- - def _check_install(self): - try: - import dynesty - import dynesty.utils as dyfunc - except ImportError: - print("Warning : dynesty not properly installed (results might be unexpected). \ - You can get it with $pip install dynesty.") - self._dynesty_installed = False - else: - self._dynesty_installed = True - self._dynesty = dynesty - self._dyfunc = dyfunc
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Sampling/Samplers/multinest_sampler.html b/docs/_build/html/_modules/lenstronomy/Sampling/Samplers/multinest_sampler.html deleted file mode 100644 index ab62a66b3..000000000 --- a/docs/_build/html/_modules/lenstronomy/Sampling/Samplers/multinest_sampler.html +++ /dev/null @@ -1,259 +0,0 @@ - - - - - - - - lenstronomy.Sampling.Samplers.multinest_sampler — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Sampling.Samplers.multinest_sampler

-__author__ = 'aymgal'
-
-import os
-import json
-import shutil
-import numpy as np
-
-from lenstronomy.Sampling.Samplers.base_nested_sampler import NestedSampler
-import lenstronomy.Util.sampling_util as utils
-
-__all__ = ['MultiNestSampler']
-
-
-
[docs]class MultiNestSampler(NestedSampler): - """ - Wrapper for nested sampling algorithm MultInest by F. Feroz & M. Hobson - papers : arXiv:0704.3704, arXiv:0809.3437, arXiv:1306.2144 - pymultinest doc : https://johannesbuchner.github.io/PyMultiNest/pymultinest.html - """ - - def __init__(self, likelihood_module, prior_type='uniform', - prior_means=None, prior_sigmas=None, width_scale=1, sigma_scale=1, - output_dir=None, output_basename='-', - remove_output_dir=False, use_mpi=False): - """ - :param likelihood_module: likelihood_module like in likelihood.py (should be callable) - :param prior_type: 'uniform' of 'gaussian', for converting the unit hypercube to param cube - :param prior_means: if prior_type is 'gaussian', mean for each param - :param prior_sigmas: if prior_type is 'gaussian', std dev for each param - :param width_scale: scale the widths of the parameters space by this factor - :param sigma_scale: if prior_type is 'gaussian', scale the gaussian sigma by this factor - :param output_dir: name of the folder that will contain output files - :param output_basename: prefix for output files - :param remove_output_dir: remove the output_dir folder after completion - :param use_mpi: flag directly passed to MultInest sampler (NOT TESTED) - """ - self._check_install() - super(MultiNestSampler, self).__init__(likelihood_module, prior_type, - prior_means, prior_sigmas, - width_scale, sigma_scale) - - # here we assume number of dimensons = number of parameters - self.n_params = self.n_dims - - if output_dir is None: - self._output_dir = 'multinest_out_default' - else: - self._output_dir = output_dir - - self._is_master = True - self._use_mpi = use_mpi - - if self._use_mpi: - from mpi4py import MPI - self._comm = MPI.COMM_WORLD - - if self._comm.Get_rank() != 0: - self._is_master = False - else: - self._comm = None - - if self._is_master: - if os.path.exists(self._output_dir): - shutil.rmtree(self._output_dir, ignore_errors=True) - os.mkdir(self._output_dir) - - self.files_basename = os.path.join(self._output_dir, output_basename) - - # required for analysis : save parameter names in json file - if self._is_master: - with open(self.files_basename + 'params.json', 'w') as file: - json.dump(self.param_names, file, indent=2) - - self._rm_output = remove_output_dir - self._has_warned = False - -
[docs] def prior(self, cube, ndim, nparams): - """ - compute the mapping between the unit cube and parameter cube (in-place) - - :param cube: unit hypercube, sampled by the algorithm - :param ndim: number of sampled parameters - :param nparams: total number of parameters - """ - cube_py = self._multinest2python(cube, ndim) - if self.prior_type == 'gaussian': - utils.cube2args_gaussian(cube_py, self.lowers, self.uppers, - self.means, self.sigmas, self.n_dims) - elif self.prior_type == 'uniform': - utils.cube2args_uniform(cube_py, self.lowers, self.uppers, self.n_dims) - for i in range(self.n_dims): - cube[i] = cube_py[i]
- -
[docs] def log_likelihood(self, args, ndim, nparams): - """ - compute the log-likelihood given list of parameters - - :param args: parameter values - :param ndim: number of sampled parameters - :param nparams: total number of parameters - :return: log-likelihood (from the likelihood module) - """ - args_py = self._multinest2python(args, ndim) - logL = self._ll(args_py) - if not np.isfinite(logL): - if not self._has_warned: - print("WARNING : logL is not finite : return very low value instead") - logL = -1e15 - self._has_warned = True - return float(logL)
- -
[docs] def run(self, kwargs_run): - """ - run the MultiNest nested sampler - - see https://johannesbuchner.github.io/PyMultiNest/pymultinest.html for content of kwargs_run - - :param kwargs_run: kwargs directly passed to pymultinest.run - :return: samples, means, logZ, logZ_err, logL, stats - """ - print("prior type :", self.prior_type) - print("parameter names :", self.param_names) - - if self._pymultinest_installed: - self._pymultinest.run(self.log_likelihood, self.prior, self.n_dims, - outputfiles_basename=self.files_basename, - resume=False, verbose=True, - init_MPI=self._use_mpi, **kwargs_run) - - analyzer = self._Analyzer(self.n_dims, outputfiles_basename=self.files_basename) - samples = analyzer.get_equal_weighted_posterior()[:, :-1] - data = analyzer.get_data() # gets data from the *.txt output file - stats = analyzer.get_stats() - - else: - # in case MultiNest was not compiled properly, for unit tests - samples = np.zeros((1, self.n_dims)) - data = np.zeros((self.n_dims, 3)) - stats = { - 'global evidence': np.zeros(self.n_dims), - 'global evidence error': np.zeros(self.n_dims), - 'modes': [{'mean': np.zeros(self.n_dims)}] - } - - logL = -0.5 * data[:, 1] # since the second data column is -2*logL - logZ = stats['global evidence'] - logZ_err = stats['global evidence error'] - means = stats['modes'][0]['mean'] # or better to use stats['marginals'][:]['median'] ??? - - print("MultiNest output files have been saved to {}*" - .format(self.files_basename)) - - if self._rm_output and self._is_master: - shutil.rmtree(self._output_dir, ignore_errors=True) - print("MultiNest output directory removed") - - return samples, means, logZ, logZ_err, logL, stats
- - def _multinest2python(self, multinest_list, num_dims): - """convert ctypes list to standard python list""" - python_list = [] - for i in range(num_dims): - python_list.append(multinest_list[i]) - return python_list - - def _check_install(self): - try: - import pymultinest - from pymultinest.analyse import Analyzer - except: - print("Warning : MultiNest/pymultinest not properly installed (results might be unexpected). \ - You can get it from : https://johannesbuchner.github.io/PyMultiNest/pymultinest.html") - self._pymultinest_installed = False - else: - self._pymultinest_installed = True - self._pymultinest = pymultinest - self._Analyzer = Analyzer
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Sampling/Samplers/polychord_sampler.html b/docs/_build/html/_modules/lenstronomy/Sampling/Samplers/polychord_sampler.html deleted file mode 100644 index 350d5d7d0..000000000 --- a/docs/_build/html/_modules/lenstronomy/Sampling/Samplers/polychord_sampler.html +++ /dev/null @@ -1,312 +0,0 @@ - - - - - - - - lenstronomy.Sampling.Samplers.polychord_sampler — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Sampling.Samplers.polychord_sampler

-__author__ = 'aymgal'
-
-import os
-import shutil
-import numpy as np
-import sys
-import copy
-
-from lenstronomy.Sampling.Samplers.base_nested_sampler import NestedSampler
-import lenstronomy.Util.sampling_util as utils
-
-__all__ = ['DyPolyChordSampler']
-
-
-
[docs]class DyPolyChordSampler(NestedSampler): - """ - Wrapper for dynamical nested sampling algorithm DyPolyChord - by E. Higson, M. Hobson, W. Handley, A. Lasenby - - papers : arXiv:1704.03459, arXiv:1804.06406 - doc : https://dypolychord.readthedocs.io - """ - - def __init__(self, likelihood_module, prior_type='uniform', - prior_means=None, prior_sigmas=None, width_scale=1, sigma_scale=1, - output_dir=None, output_basename='-', - resume_dyn_run=False, - polychord_settings=None, - remove_output_dir=False, use_mpi=False): #, num_mpi_procs=1): - """ - :param likelihood_module: likelihood_module like in likelihood.py (should be callable) - :param prior_type: 'uniform' of 'gaussian', for converting the unit hypercube to param cube - :param prior_means: if prior_type is 'gaussian', mean for each param - :param prior_sigmas: if prior_type is 'gaussian', std dev for each param - :param width_scale: scale the widths of the parameters space by this factor - :param sigma_scale: if prior_type is 'gaussian', scale the gaussian sigma by this factor - :param output_dir: name of the folder that will contain output files - :param output_basename: prefix for output files - :param resume_dyn_run: if True, previous resume files will not be deleted so that previous run can be resumed - :param polychord_settings: settings dictionary to send to pypolychord. Check dypolychord documentation for details. - :param remove_output_dir: remove the output_dir folder after completion - :param use_mpi: Use MPI computing if `True` - """ - self._check_install() - super(DyPolyChordSampler, self).__init__(likelihood_module, prior_type, - prior_means, prior_sigmas, - width_scale, sigma_scale) - - # if use_mpi: - # mpi_str = 'mpirun -np {}'.format(num_mpi_procs) - # else: - # mpi_str = None - if polychord_settings == None: - polychord_settings = {} - self._use_mpi = use_mpi - - self._output_dir= output_dir - self._is_master = True - - if self._use_mpi: - from mpi4py import MPI - self._comm = MPI.COMM_WORLD - - if self._comm.Get_rank() != 0: - self._is_master = False - else: - self._comm = None - - if not resume_dyn_run: - if self._is_master: - if os.path.exists(self._output_dir): - shutil.rmtree(self._output_dir, ignore_errors=True) - os.mkdir(self._output_dir) - - self._output_basename = output_basename - self._settings = copy.deepcopy(polychord_settings) - self._settings['file_root'] = self._output_basename - self._settings['base_dir'] = self._output_dir - - if self._all_installed: - # create the dyPolyChord callable object - self._sampler = self._RunPyPolyChord(self.log_likelihood, - self.prior, self.n_dims) - else: - self._sampler = None - - self._rm_output = remove_output_dir - self._has_warned = False - -
[docs] def prior(self, cube): - """ - compute the mapping between the unit cube and parameter cube - - 'copy=True' below because cube can not be modified in-place (read-only) - - :param cube: unit hypercube, sampled by the algorithm - :return: hypercube in parameter space - """ - if self.prior_type == 'gaussian': - p = utils.cube2args_gaussian(cube, self.lowers, self.uppers, - self.means, self.sigmas, self.n_dims, - copy=True) - elif self.prior_type == 'uniform': - p = utils.cube2args_uniform(cube, self.lowers, self.uppers, - self.n_dims, copy=True) - else: - raise ValueError("Variable prior_type with entry %s not supported!" % self.prior_type) - return p
- -
[docs] def log_likelihood(self, args): - """ - compute the log-likelihood given list of parameters - - :param args: parameter values - :return: log-likelihood (from the likelihood module) - """ - phi = [] - logL = self._ll.likelihood(args) - if not np.isfinite(logL): - if not self._has_warned: - print("WARNING : logL is not finite : return very low value instead") - logL = -1e15 - self._has_warned = True - return float(logL), phi
- -
[docs] def run(self, dynamic_goal, kwargs_run): - """ - run the DyPolyChord dynamical nested sampler - - see https://dypolychord.readthedocs.io for content of kwargs_run - - :param dynamic_goal: 0 for evidence computation, 1 for posterior computation - :param kwargs_run: kwargs directly passed to dyPolyChord.run_dypolychord - :return: samples, means, logZ, logZ_err, logL, ns_run - """ - print("prior type :", self.prior_type) - print("parameter names :", self.param_names) - - if self._all_installed: - # TODO : put a default dynamic_goal ? - # dynamic_goal = 0 for evidence-only, 1 for posterior-only - - self._dyPolyChord.run_dypolychord(self._sampler, dynamic_goal, - settings_dict_in=self._settings, - comm=self._comm, **kwargs_run) - - if self._is_master: - ns_run = self._ns_process_run(self._settings['file_root'], - self._settings['base_dir']) - - else: - # in case DyPolyChord or NestCheck was not compiled properly, for unit tests - ns_run = { - 'theta': np.zeros((1, self.n_dims)), - 'logl': np.zeros(1), - 'output': { - 'logZ': np.zeros(1), - 'logZerr': np.zeros(1), - 'param_means': np.zeros(self.n_dims) - } - } - self._write_equal_weights(ns_run['theta'], ns_run['logl']) - - if self._is_master: - samples, logL = self._get_equal_weight_samples() - # logL = ns_run['logl'] - # samples_w = ns_run['theta'] - logZ = ns_run['output']['logZ'] - logZ_err = ns_run['output']['logZerr'] - means = ns_run['output']['param_means'] - - print('The log evidence estimate using the first run is {}' - .format(logZ)) - print('The estimated mean of the first parameter is {}' - .format(means[0])) - - if self._rm_output: - shutil.rmtree(self._output_dir, ignore_errors=True) - - return samples, means, logZ, logZ_err, logL, ns_run - else: - sys.exit(0)
- - def _get_equal_weight_samples(self): - """ - Inspired by pymultinest's Analyzer, - because DyPolyChord has more or less the same output conventions as MultiNest - """ - file_name = '{}_equal_weights.txt'.format(self._output_basename) - file_path = os.path.join(self._output_dir, file_name) - data = np.loadtxt(file_path, ndmin=2) - logL = -0.5 * data[:, 0] - samples = data[:, 1:] - return samples, logL - - def _write_equal_weights(self, samples, logL): - # write fake output file for unit tests - file_name = '{}_equal_weights.txt'.format(self._output_basename) - file_path = os.path.join(self._output_dir, file_name) - data = np.zeros((samples.shape[0], 1+samples.shape[1]), dtype=float) - data[:, 0] = -2. * logL - data[:, 1:] = samples - np.savetxt(file_path, data, fmt='% .14E') - - def _check_install(self): - try: - import dyPolyChord - from dyPolyChord import pypolychord_utils - except ImportError: - dyPolyChord = None - pypolychord_utils = None - print("Warning : dyPolyChord not properly installed. \ - You can get it from : https://github.com/ejhigson/dyPolyChord") - dypolychord_installed = False - else: - dypolychord_installed = True - self._dyPolyChord = dyPolyChord - self._RunPyPolyChord = pypolychord_utils.RunPyPolyChord - - try: - from nestcheck import data_processing - except ImportError: - print("Warning : nestcheck not properly installed (results might be unexpected). \ - You can get it from : https://github.com/ejhigson/nestcheck") - nestcheck_installed = False - else: - nestcheck_installed = True - self._ns_process_run = data_processing.process_polychord_run - - self._all_installed = dypolychord_installed and nestcheck_installed
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Sampling/likelihood.html b/docs/_build/html/_modules/lenstronomy/Sampling/likelihood.html deleted file mode 100644 index e9a9dc38a..000000000 --- a/docs/_build/html/_modules/lenstronomy/Sampling/likelihood.html +++ /dev/null @@ -1,394 +0,0 @@ - - - - - - - - lenstronomy.Sampling.likelihood — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Sampling.likelihood

-__author__ = 'sibirrer'
-
-from lenstronomy.Sampling.Likelihoods.time_delay_likelihood import TimeDelayLikelihood
-from lenstronomy.Sampling.Likelihoods.image_likelihood import ImageLikelihood
-from lenstronomy.Sampling.Likelihoods.position_likelihood import PositionLikelihood
-from lenstronomy.Sampling.Likelihoods.flux_ratio_likelihood import FluxRatioLikelihood
-from lenstronomy.Sampling.Likelihoods.prior_likelihood import PriorLikelihood
-import lenstronomy.Util.class_creator as class_creator
-import numpy as np
-
-__all__ = ['LikelihoodModule']
-
-
-
[docs]class LikelihoodModule(object): - """ - this class contains the routines to run a MCMC process - the key components are: - - imSim_class: an instance of a class that simulates one (or more) images and returns the likelihood, such as - ImageModel(), Multiband(), MultiExposure() - - param_class: instance of a Param() class that can cast the sorted list of parameters that are sampled into the - conventions of the imSim_class - - Additional arguments are supported for adding a time-delay likelihood etc (see __init__ definition) - """ - def __init__(self, kwargs_data_joint, kwargs_model, param_class, image_likelihood=True, check_bounds=True, - check_matched_source_position=False, astrometric_likelihood=False, image_position_likelihood=False, - source_position_likelihood=False, image_position_uncertainty=0.004, check_positive_flux=False, - source_position_tolerance=0.001, source_position_sigma=0.001, force_no_add_image=False, - source_marg=False, linear_prior=None, restrict_image_number=False, - max_num_images=None, bands_compute=None, time_delay_likelihood=False, - image_likelihood_mask_list=None, - flux_ratio_likelihood=False, kwargs_flux_compute=None, prior_lens=None, prior_source=None, - prior_extinction=None, prior_lens_light=None, prior_ps=None, prior_special=None, prior_lens_kde=None, - prior_source_kde=None, prior_lens_light_kde=None, prior_ps_kde=None, prior_special_kde=None, - prior_extinction_kde=None, prior_lens_lognormal=None, prior_source_lognormal=None, - prior_extinction_lognormal=None, prior_lens_light_lognormal=None, prior_ps_lognormal=None, - prior_special_lognormal=None, custom_logL_addition=None, kwargs_pixelbased=None): - """ - initializing class - - - :param param_class: instance of a Param() class that can cast the sorted list of parameters that are sampled - into the conventions of the imSim_class - :param image_likelihood: bool, option to compute the imaging likelihood - :param source_position_likelihood: bool, if True, ray-traces image positions back to source plane and evaluates - relative errors in respect ot the position_uncertainties in the image plane - :param check_bounds: bool, option to punish the hard bounds in parameter space - :param check_matched_source_position: bool, option to check whether point source position of solver finds a - solution to match all the image positions in the same source plane coordinate - :param astrometric_likelihood: bool, additional likelihood term of the predicted vs modelled point source - position - :param image_position_uncertainty: float, 1-sigma Gaussian uncertainty on the point source position - (only used if point_source_likelihood=True) - :param check_positive_flux: bool, option to punish models that do not have all positive linear amplitude - parameters - :param source_position_tolerance: float, punishment of check_solver occurs when image positions are predicted - further away than this number - :param image_likelihood_mask_list: list of boolean 2d arrays of size of images marking the pixels to be - evaluated in the likelihood - :param force_no_add_image: bool, if True: computes ALL image positions of the point source. If there are more - images predicted than modelled, a punishment occures - :param source_marg: marginalization addition on the imaging likelihood based on the covariance of the inferred - linear coefficients - :param linear_prior: float or list of floats (when multi-linear setting is chosen) indicating the range of - linear amplitude priors when computing the marginalization term. - :param restrict_image_number: bool, if True: computes ALL image positions of the point source. If there are more - images predicted than indicated in max_num_images, a punishment occurs - :param max_num_images: int, see restrict_image_number - :param bands_compute: list of bools with same length as data objects, indicates which "band" to include in the - fitting - :param time_delay_likelihood: bool, if True computes the time-delay likelihood of the FIRST point source - :param kwargs_flux_compute: keyword arguments of how to compute the image position fluxes - (see FluxRatioLikeliood) - :param custom_logL_addition: a definition taking as arguments (kwargs_lens, kwargs_source, kwargs_lens_light, - kwargs_ps, kwargs_special, kwargs_extinction) and returns a logL (punishing) value. - :param kwargs_pixelbased: keyword arguments with various settings related to the pixel-based solver - (see SLITronomy documentation) - """ - multi_band_list, multi_band_type, time_delays_measured, time_delays_uncertainties, flux_ratios, flux_ratio_errors, ra_image_list, dec_image_list = self._unpack_data(**kwargs_data_joint) - if len(multi_band_list) == 0: - image_likelihood = False - - self.param = param_class - self._lower_limit, self._upper_limit = self.param.param_limits() - self._prior_likelihood = PriorLikelihood(prior_lens, prior_source, prior_lens_light, prior_ps, prior_special, - prior_extinction, - prior_lens_kde, prior_source_kde, prior_lens_light_kde, prior_ps_kde, - prior_special_kde, prior_extinction_kde, - prior_lens_lognormal, prior_source_lognormal, - prior_lens_light_lognormal, prior_ps_lognormal, - prior_special_lognormal, prior_extinction_lognormal, - ) - self._time_delay_likelihood = time_delay_likelihood - self._image_likelihood = image_likelihood - self._flux_ratio_likelihood = flux_ratio_likelihood - if kwargs_flux_compute is None: - kwargs_flux_compute = {} - self._kwargs_flux_compute = kwargs_flux_compute - self._check_bounds = check_bounds - self._custom_logL_addition = custom_logL_addition - self._kwargs_time_delay = {'time_delays_measured': time_delays_measured, - 'time_delays_uncertainties': time_delays_uncertainties} - self._kwargs_imaging = {'multi_band_list': multi_band_list, 'multi_band_type': multi_band_type, - 'bands_compute': bands_compute, - 'image_likelihood_mask_list': image_likelihood_mask_list, 'source_marg': source_marg, - 'linear_prior': linear_prior, 'check_positive_flux': check_positive_flux, - 'kwargs_pixelbased': kwargs_pixelbased} - self._kwargs_position = {'astrometric_likelihood': astrometric_likelihood, - 'image_position_likelihood': image_position_likelihood, - 'source_position_likelihood': source_position_likelihood, - 'ra_image_list': ra_image_list, 'dec_image_list': dec_image_list, - 'image_position_uncertainty': image_position_uncertainty, - 'check_matched_source_position': check_matched_source_position, - 'source_position_tolerance': source_position_tolerance, - 'source_position_sigma': source_position_sigma, - 'force_no_add_image': force_no_add_image, - 'restrict_image_number': restrict_image_number, 'max_num_images': max_num_images} - self._kwargs_flux = {'flux_ratios': flux_ratios, 'flux_ratio_errors': flux_ratio_errors} - self._kwargs_flux.update(self._kwargs_flux_compute) - self._class_instances(kwargs_model=kwargs_model, kwargs_imaging=self._kwargs_imaging, - kwargs_position=self._kwargs_position, kwargs_flux=self._kwargs_flux, - kwargs_time_delay=self._kwargs_time_delay) - - def _class_instances(self, kwargs_model, kwargs_imaging, kwargs_position, kwargs_flux, kwargs_time_delay): - """ - - :param kwargs_model: lenstronomy model keyword arguments - :param kwargs_imaging: keyword arguments for imaging likelihood - :param kwargs_position: keyword arguments for positional likelihood - :param kwargs_flux: keyword arguments for flux ratio likelihood - :param kwargs_time_delay: keyword arguments for time delay likelihood - :return: updated model instances of this class - """ - - # TODO: in case lens model or point source models are only applied on partial images, then this current class - # has ambiguities when it comes to time-delay likelihood and flux ratio likelihood - lens_model_class, _, _, point_source_class, _ = class_creator.create_class_instances(all_models=True, - **kwargs_model) - self.PointSource = point_source_class - - if self._time_delay_likelihood is True: - self.time_delay_likelihood = TimeDelayLikelihood(lens_model_class=lens_model_class, - point_source_class=point_source_class, - **kwargs_time_delay) - - if self._image_likelihood is True: - self.image_likelihood = ImageLikelihood(kwargs_model=kwargs_model, **kwargs_imaging) - self._position_likelihood = PositionLikelihood(point_source_class, **kwargs_position) - if self._flux_ratio_likelihood is True: - self.flux_ratio_likelihood = FluxRatioLikelihood(lens_model_class, **kwargs_flux) - - def __call__(self, a): - return self.logL(a) - -
[docs] def logL(self, args, verbose=False): - """ - routine to compute X2 given variable parameters for a MCMC/PSO chain - """ - # extract parameters - kwargs_return = self.param.args2kwargs(args) - if self._check_bounds is True: - penalty, bound_hit = self.check_bounds(args, self._lower_limit, self._upper_limit, verbose=verbose) - if bound_hit is True: - return -10**15 - return self.log_likelihood(kwargs_return, verbose=verbose)
- -
[docs] def log_likelihood(self, kwargs_return, verbose=False): - kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, kwargs_special = kwargs_return['kwargs_lens'], \ - kwargs_return['kwargs_source'], \ - kwargs_return['kwargs_lens_light'], \ - kwargs_return['kwargs_ps'], \ - kwargs_return['kwargs_special'] - # update model instance in case of changes affecting it (i.e. redshift sampling in multi-plane) - self._update_model(kwargs_special) - # generate image and computes likelihood - self._reset_point_source_cache(bool_input=True) - logL = 0 - - if self._image_likelihood is True: - logL_image = self.image_likelihood.logL(**kwargs_return) - logL += logL_image - if verbose is True: - print('image logL = %s' % logL_image) - if self._time_delay_likelihood is True: - logL_time_delay = self.time_delay_likelihood.logL(kwargs_lens, kwargs_ps, kwargs_special) - logL += logL_time_delay - if verbose is True: - print('time-delay logL = %s' % logL_time_delay) - if self._flux_ratio_likelihood is True: - ra_image_list, dec_image_list = self.PointSource.image_position(kwargs_ps=kwargs_ps, - kwargs_lens=kwargs_lens) - x_pos, y_pos = ra_image_list[0], dec_image_list[0] - logL_flux_ratios = self.flux_ratio_likelihood.logL(x_pos, y_pos, kwargs_lens, kwargs_special) - logL += logL_flux_ratios - if verbose is True: - print('flux ratio logL = %s' % logL_flux_ratios) - logL += self._position_likelihood.logL(kwargs_lens, kwargs_ps, kwargs_special, verbose=verbose) - logL_prior = self._prior_likelihood.logL(**kwargs_return) - logL += logL_prior - if verbose is True: - print('Prior likelihood = %s' % logL_prior) - if self._custom_logL_addition is not None: - logL_cond = self._custom_logL_addition(**kwargs_return) - logL += logL_cond - if verbose is True: - print('custom added logL = %s' % logL_cond) - self._reset_point_source_cache(bool_input=False) - return logL # , None
- -
[docs] @staticmethod - def check_bounds(args, lowerLimit, upperLimit, verbose=False): - """ - checks whether the parameter vector has left its bound, if so, adds a big number - """ - penalty = 0. - bound_hit = False - args = np.atleast_1d(args) - for i in range(0, len(args)): - if args[i] < lowerLimit[i] or args[i] > upperLimit[i]: - penalty = 10.**5 - bound_hit = True - if verbose is True: - print('parameter %s with value %s hit the bounds [%s, %s] ' % (i, args[i], lowerLimit[i], - upperLimit[i])) - return penalty, bound_hit - return penalty, bound_hit
- - @property - def num_data(self): - """ - - :return: number of independent data points in the combined fitting - """ - num_data = 0 - if self._image_likelihood is True: - num_data += self.image_likelihood.num_data - if self._time_delay_likelihood is True: - num_data += self.time_delay_likelihood.num_data - if self._flux_ratio_likelihood is True: - num_data += self.flux_ratio_likelihood.num_data - num_data += self._position_likelihood.num_data - return num_data - - @property - def param_limits(self): - return self._lower_limit, self._upper_limit - -
[docs] def effective_num_data_points(self, **kwargs): - """ - returns the effective number of data points considered in the X2 estimation to compute the reduced X2 value - """ - num_linear = 0 - if self._image_likelihood is True: - num_linear = self.image_likelihood.num_param_linear(**kwargs) - num_param, param_names = self.param.num_param() - return self.num_data - num_param - num_linear
- -
[docs] def likelihood(self, a): - return self.logL(a)
- -
[docs] def negativelogL(self, a): - """ - for minimizer function, the negative value of the logl value is requested - - :param a: array of parameters - :return: -logL - """ - return -self.logL(a)
- - @staticmethod - def _unpack_data(multi_band_list=None, multi_band_type='multi-linear', time_delays_measured=None, - time_delays_uncertainties=None, flux_ratios=None, flux_ratio_errors=None, ra_image_list=None, - dec_image_list=None): - """ - - :param multi_band_list: list of [[kwargs_data, kwargs_psf, kwargs_numerics], [], ...] - :param multi_band_type: string, type of multi-plane settings (multi-linear or joint-linear) - :param time_delays_measured: measured time delays (units of days) - :param time_delays_uncertainties: uncertainties in time-delay measurement - :param flux_ratios: flux ratios of point sources - :param flux_ratio_errors: error in flux ratio measurement - :return: - """ - if multi_band_list is None: - multi_band_list = [] - if ra_image_list is None: - ra_image_list = [] - if dec_image_list is None: - dec_image_list = [] - return multi_band_list, multi_band_type, time_delays_measured, time_delays_uncertainties, flux_ratios, \ - flux_ratio_errors, ra_image_list, dec_image_list - - def _reset_point_source_cache(self, bool_input=True): - self.PointSource.delete_lens_model_cache() - self.PointSource.set_save_cache(bool_input) - if self._image_likelihood is True: - self.image_likelihood.reset_point_source_cache(bool_input) - - def _update_model(self, kwargs_special): - """ - updates lens model instance of this class (and all class instances related to it) when an update to the - modeled redshifts of the deflector and/or source planes are made - - :param kwargs_special: keyword arguments from SpecialParam() class return of sampling arguments - :return: None, all class instances updated to recent modek - """ - kwargs_model, update_bool = self.param.update_kwargs_model(kwargs_special) - if update_bool is True: - self._class_instances(kwargs_model=kwargs_model, kwargs_imaging=self._kwargs_imaging, - kwargs_position=self._kwargs_position, kwargs_flux=self._kwargs_flux, - kwargs_time_delay=self._kwargs_time_delay)
- # TODO remove redundancies with Param() calls updates -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Sampling/parameters.html b/docs/_build/html/_modules/lenstronomy/Sampling/parameters.html deleted file mode 100644 index 5922ce91c..000000000 --- a/docs/_build/html/_modules/lenstronomy/Sampling/parameters.html +++ /dev/null @@ -1,736 +0,0 @@ - - - - - - - - lenstronomy.Sampling.parameters — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Sampling.parameters

-__author__ = 'sibirrer'
-
-import numpy as np
-import copy
-from lenstronomy.Util import class_creator
-from lenstronomy.ImSim.image2source_mapping import Image2SourceMapping
-from lenstronomy.LensModel.Solver.solver import Solver
-from lenstronomy.LensModel.lens_param import LensParam
-from lenstronomy.LightModel.light_param import LightParam
-from lenstronomy.PointSource.point_source_param import PointSourceParam
-from lenstronomy.Sampling.special_param import SpecialParam
-
-__all__ = ['Param']
-
-
-
[docs]class Param(object): - """ - class that handles the parameter constraints. In particular when different model profiles share joint constraints. - - - Options between same model classes: - - 'joint_lens_with_lens':list [[i_lens, k_lens, ['param_name1', 'param_name2', ...]], [...], ...], - joint parameter between two lens models - - 'joint_lens_light_with_lens_light':list [[i_lens_light, k_lens_light, ['param_name1', 'param_name2', ...]], [...], ...], - joint parameter between two lens light models, the second adopts the value of the first - - 'joint_source_with_source':list [[i_source, k_source, ['param_name1', 'param_name2', ...]], [...], ...], - joint parameter between two source surface brightness models, the second adopts the value of the first - - - Options between different model classes: - - 'joint_lens_with_light': list [[i_light, k_lens, ['param_name1', 'param_name2', ...]], [...], ...], - joint parameter between lens model and lens light model - - 'joint_source_with_point_source': list [[i_point_source, k_source], [...], ...], - joint position parameter between lens model and source light model - - 'joint_lens_light_with_point_source': list [[i_point_source, k_lens_light], [...], ...], - joint position parameter between lens model and lens light model - - 'joint_extinction_with_lens_light': list [[i_lens_light, k_extinction, ['param_name1', 'param_name2', ...]], [...], ...], - joint parameters between the lens surface brightness and the optical depth models - - 'joint_lens_with_source_light': [[i_source, k_lens, ['param_name1', 'param_name2', ...]], [...], ...], - joint parameter between lens model and source light model. Samples light model parameter only. - - hierarchy is as follows: - 1. Point source parameters are inferred - 2. Lens light joint parameters are set - 3. Lens model joint constraints are set - 4. Lens model solver is applied - 5. Joint source and point source is applied - - Alternatively to the format of the linking of parameters with IDENTICAL names as listed above as: - [[i_1, k_2, ['param_name1', 'param_name2', ...]], [...], ...] - the following format of the arguments are supported to join parameters with DIFFERENT names: - [[i_1, k_2, {'param_old1': 'param_new1', 'ra_0': 'center_x'}], [...], ...]\ - - Log10 sampling of the lens parameters : - 'log_sampling_lens': [[i_lens, ['param_name1', 'param_name2', ...]], [...], ...], - Sample the log10 of the lens model parameters. - - - """ - - def __init__(self, kwargs_model, - kwargs_fixed_lens=None, kwargs_fixed_source=None, kwargs_fixed_lens_light=None, kwargs_fixed_ps=None, - kwargs_fixed_special=None, kwargs_fixed_extinction=None, - kwargs_lower_lens=None, kwargs_lower_source=None, kwargs_lower_lens_light=None, kwargs_lower_ps=None, - kwargs_lower_special=None, kwargs_lower_extinction=None, - kwargs_upper_lens=None, kwargs_upper_source=None, kwargs_upper_lens_light=None, kwargs_upper_ps=None, - kwargs_upper_special=None, kwargs_upper_extinction=None, - kwargs_lens_init=None, linear_solver=True, joint_lens_with_lens=[], joint_lens_light_with_lens_light=[], - joint_source_with_source=[], joint_lens_with_light=[], joint_source_with_point_source=[], - joint_lens_light_with_point_source=[], joint_extinction_with_lens_light=[], - joint_lens_with_source_light=[], mass_scaling_list=None, point_source_offset=False, - num_point_source_list=None, image_plane_source_list=None, solver_type='NONE', Ddt_sampling=None, - source_size=False, num_tau0=0, lens_redshift_sampling_indexes=None, - source_redshift_sampling_indexes=None, source_grid_offset=False, num_shapelet_lens=0, - log_sampling_lens=[]): - """ - - :param kwargs_model: keyword arguments to describe all model components used in class_creator.create_class_instances() - :param kwargs_fixed_lens: fixed parameters for lens model (keyword argument list) - :param kwargs_fixed_source: fixed parameters for source model (keyword argument list) - :param kwargs_fixed_lens_light: fixed parameters for lens light model (keyword argument list) - :param kwargs_fixed_ps: fixed parameters for point source model (keyword argument list) - :param kwargs_fixed_special: fixed parameters for special model parameters (keyword arguments) - :param kwargs_fixed_extinction: fixed parameters for extinction model parameters (keyword argument list) - :param kwargs_lower_lens: lower limits for parameters of lens model (keyword argument list) - :param kwargs_lower_source: lower limits for parameters of source model (keyword argument list) - :param kwargs_lower_lens_light: lower limits for parameters of lens light model (keyword argument list) - :param kwargs_lower_ps: lower limits for parameters of point source model (keyword argument list) - :param kwargs_lower_special: lower limits for parameters of special model parameters (keyword arguments) - :param kwargs_lower_extinction: lower limits for parameters of extinction model (keyword argument list) - :param kwargs_upper_lens: upper limits for parameters of lens model (keyword argument list) - :param kwargs_upper_source: upper limits for parameters of source model (keyword argument list) - :param kwargs_upper_lens_light: upper limits for parameters of lens light model (keyword argument list) - :param kwargs_upper_ps: upper limits for parameters of point source model (keyword argument list) - :param kwargs_upper_special: upper limits for parameters of special model parameters (keyword arguments) - :param kwargs_upper_extinction: upper limits for parameters of extinction model (keyword argument list) - :param kwargs_lens_init: initial guess of lens model keyword arguments (only relevant as the starting point of - the non-linear solver) - :param linear_solver: bool, if True fixes the linear amplitude parameters 'amp' (avoid sampling) such that they - get overwritten by the linear solver solution. - :param joint_lens_with_lens: list [[i_lens, k_lens, ['param_name1', 'param_name2', ...]], [...], ...], - joint parameter between two lens models - :param joint_lens_light_with_lens_light: list [[i_lens_light, k_lens_light, ['param_name1', 'param_name2', ...]], [...], ...], - joint parameter between two lens light models, the second adopts the value of the first - :param joint_source_with_source: [[i_source, k_source, ['param_name1', 'param_name2', ...]], [...], ...], - joint parameter between two source surface brightness models, the second adopts the value of the first - :param joint_lens_with_light: list [[i_light, k_lens, ['param_name1', 'param_name2', ...]], [...], ...], - joint parameter between lens model and lens light model - :param joint_source_with_point_source: list [[i_point_source, k_source], [...], ...], - joint position parameter between lens model and source light model - :param joint_lens_light_with_point_source: list [[i_point_source, k_lens_light], [...], ...], - joint position parameter between lens model and lens light model - :param joint_extinction_with_lens_light: list [[i_lens_light, k_extinction, ['param_name1', 'param_name2', ...]], [...], ...], - joint parameters between the lens surface brightness and the optical depth models - :param joint_lens_with_source_light: [[i_source, k_lens, ['param_name1', 'param_name2', ...]], [...], ...], - joint parameter between lens model and source light model. Samples light model parameter only. - :param mass_scaling_list: boolean list of length of lens model list (optional) models with identical integers - will be scaled with the same additional scaling factor. First integer starts with 1 (not 0) - :param point_source_offset: bool, if True, adds relative offsets ot the modeled image positions relative to the - time-delay and lens equation solver - :param num_point_source_list: list of number of point sources per point source model class - :param image_plane_source_list: optional, list of booleans for the source_light components. - If a component is set =True it will parameterized the positions in the image plane and ray-trace the - parameters back to the source position on the fly during the fitting. - :param solver_type: string, option for specific solver type - see detailed instruction of the Solver4Point and Solver2Point classes - :param Ddt_sampling: bool, if True, samples the time-delay distance D_dt (in units of Mpc) - :param source_size: bool, if True, samples a source size parameters to be evaluated in the flux ratio likelihood - :param num_tau0: integer, number of different optical depth re-normalization factors - :param lens_redshift_sampling_indexes: list of integers corresponding to the lens model components whose redshifts - are a free parameter (only has an effect in multi-plane lensing) with same indexes indicating joint redshift, - in ascending numbering e.g. [-1, 0, 0, 1, 0, 2], -1 indicating not sampled fixed indexes - :param source_redshift_sampling_indexes: list of integers corresponding to the source model components whose redshifts - are a free parameter (only has an effect in multi-plane lensing) with same indexes indicating joint redshift, - in ascending numbering e.g. [-1, 0, 0, 1, 0, 2], -1 indicating not sampled fixed indexes. These indexes are - the sample as for the lens - :param source_grid_offset: optional, if True when using a pixel-based modelling (e.g. with STARLETS-like profiles), - adds two additional sampled parameters describing RA/Dec offsets between data coordinate grid and pixelated source plane coordinate grid. - :param num_shapelet_lens: number of shapelet coefficients in the 'SHAPELETS_CART' or 'SHAPELETS_POLAR' mass profile. - :param log_sampling_lens: Sample the log10 of the lens model parameters. Format : [[i_lens, ['param_name1', 'param_name2', ...]], [...], ...], - """ - - self._lens_model_list = kwargs_model.get('lens_model_list', []) - self._lens_redshift_list = kwargs_model.get('lens_redshift_list', None) - self._source_light_model_list = kwargs_model.get('source_light_model_list', []) - self._source_redshift_list = kwargs_model.get('source_redshift_list', None) - self._lens_light_model_list = kwargs_model.get('lens_light_model_list', []) - self._point_source_model_list = kwargs_model.get('point_source_model_list', []) - self._optical_depth_model_list = kwargs_model.get('optical_depth_model_list', []) - self._kwargs_model = kwargs_model - - # check how many redshifts need to be sampled - num_z_sampling = 0 - if lens_redshift_sampling_indexes is not None: - num_z_sampling = int(np.max(lens_redshift_sampling_indexes) + 1) - if source_redshift_sampling_indexes is not None: - num_z_source = int(np.max(source_redshift_sampling_indexes) + 1) - num_z_sampling = max(num_z_sampling, num_z_source) - self._num_z_sampling, self._lens_redshift_sampling_indexes, self._source_redshift_sampling_indexes = num_z_sampling, lens_redshift_sampling_indexes, source_redshift_sampling_indexes - - self._lens_model_class, self._source_model_class, _, _, _ = class_creator.create_class_instances(all_models=True, **kwargs_model) - self._image2SourceMapping = Image2SourceMapping(lensModel=self._lens_model_class, - sourceModel=self._source_model_class) - - if kwargs_fixed_lens is None: - kwargs_fixed_lens = [{} for i in range(len(self._lens_model_list))] - if kwargs_fixed_source is None: - kwargs_fixed_source = [{} for i in range(len(self._source_light_model_list))] - if kwargs_fixed_lens_light is None: - kwargs_fixed_lens_light = [{} for i in range(len(self._lens_light_model_list))] - if kwargs_fixed_ps is None: - kwargs_fixed_ps = [{} for i in range(len(self._point_source_model_list))] - if kwargs_fixed_special is None: - kwargs_fixed_special = {} - - self._joint_lens_with_lens = joint_lens_with_lens - self._joint_lens_light_with_lens_light = joint_lens_light_with_lens_light - self._joint_source_with_source = joint_source_with_source - - self._joint_lens_with_light = joint_lens_with_light - self._joint_lens_with_source_light = joint_lens_with_source_light - self._joint_source_with_point_source = copy.deepcopy(joint_source_with_point_source) - - # Set up the parameters being sampled in log space in a similar way than the parameters being fixed. - self._log_sampling_lens = log_sampling_lens - kwargs_logsampling_lens = [[] for i in range(len(self._lens_model_list))] - kwargs_logsampling_lens = self._update_log_sampling(kwargs_logsampling_lens, log_sampling_lens) - - for param_list in self._joint_source_with_point_source: - if len(param_list) == 2: - param_list.append(['center_x', 'center_y']) - self._joint_lens_light_with_point_source = copy.deepcopy(joint_lens_light_with_point_source) - for param_list in self._joint_lens_light_with_point_source: - if len(param_list) == 2: - param_list.append(['center_x', 'center_y']) - if mass_scaling_list is None: - mass_scaling_list = [False] * len(self._lens_model_list) - self._mass_scaling_list = mass_scaling_list - if 1 in self._mass_scaling_list: - self._num_scale_factor = np.max(self._mass_scaling_list) - self._mass_scaling = True - else: - self._num_scale_factor = 0 - self._mass_scaling = False - self._point_source_offset = point_source_offset - if num_point_source_list is None: - num_point_source_list = [1] * len(self._point_source_model_list) - - # Attention: if joint coordinates with other source profiles, only indicate one as bool - if image_plane_source_list is None: - image_plane_source_list = [False] * len(self._source_light_model_list) - self._image_plane_source_list = image_plane_source_list - - try: - self._num_images = num_point_source_list[0] - except: - self._num_images = 0 - self._solver_type = solver_type - if self._solver_type == 'NONE': - self._solver = False - else: - self._solver = True - self._solver_module = Solver(solver_type=self._solver_type, lensModel=self._lens_model_class, - num_images=self._num_images) - - source_model_list = self._source_light_model_list - if len(source_model_list) != 1 or source_model_list[0] not in ['SLIT_STARLETS', 'SLIT_STARLETS_GEN2']: - # source_grid_offset only defined for source profiles compatible with pixel-based solver - source_grid_offset = False - - self._joint_extinction_with_lens_light = joint_extinction_with_lens_light - # fix parameters joint within the same model types - kwargs_fixed_lens_updated = self._add_fixed_lens(kwargs_fixed_lens, kwargs_lens_init) - kwargs_fixed_lens_updated = self._fix_joint_param(kwargs_fixed_lens_updated, self._joint_lens_with_lens) - kwargs_fixed_lens_updated = self._fix_joint_param(kwargs_fixed_lens_updated, self._joint_lens_with_source_light) - kwargs_fixed_lens_light_updated = self._fix_joint_param(kwargs_fixed_lens_light, self._joint_lens_light_with_lens_light) - kwargs_fixed_source_updated = self._fix_joint_param(kwargs_fixed_source, self._joint_source_with_source) - kwargs_fixed_ps_updated = copy.deepcopy(kwargs_fixed_ps) - kwargs_fixed_extinction_updated = self._fix_joint_param(kwargs_fixed_extinction, self._joint_extinction_with_lens_light) - # fix parameters joint with other model types - kwargs_fixed_lens_updated = self._fix_joint_param(kwargs_fixed_lens_updated, self._joint_lens_with_light) - kwargs_fixed_source_updated = self._fix_joint_param(kwargs_fixed_source_updated, self._joint_source_with_point_source) - kwargs_fixed_lens_light_updated = self._fix_joint_param(kwargs_fixed_lens_light_updated, - self._joint_lens_light_with_point_source) - self.lensParams = LensParam(self._lens_model_list, kwargs_fixed_lens_updated, - kwargs_logsampling=kwargs_logsampling_lens, - num_images=self._num_images, - solver_type=self._solver_type, kwargs_lower=kwargs_lower_lens, - kwargs_upper=kwargs_upper_lens, num_shapelet_lens=num_shapelet_lens) - self.lensLightParams = LightParam(self._lens_light_model_list, kwargs_fixed_lens_light_updated, param_type='lens_light', - linear_solver=linear_solver, kwargs_lower=kwargs_lower_lens_light, - kwargs_upper=kwargs_upper_lens_light) - self.souceParams = LightParam(self._source_light_model_list, kwargs_fixed_source_updated, param_type='source_light', - linear_solver=linear_solver, kwargs_lower=kwargs_lower_source, - kwargs_upper=kwargs_upper_source) - self.pointSourceParams = PointSourceParam(self._point_source_model_list, kwargs_fixed_ps_updated, - num_point_source_list=num_point_source_list, - linear_solver=linear_solver, kwargs_lower=kwargs_lower_ps, - kwargs_upper=kwargs_upper_ps) - self.extinctionParams = LightParam(self._optical_depth_model_list, kwargs_fixed_extinction_updated, - kwargs_lower=kwargs_lower_extinction, kwargs_upper=kwargs_upper_extinction, - linear_solver=False) - self.specialParams = SpecialParam(Ddt_sampling=Ddt_sampling, mass_scaling=self._mass_scaling, - kwargs_fixed=kwargs_fixed_special, num_scale_factor=self._num_scale_factor, - kwargs_lower=kwargs_lower_special, kwargs_upper=kwargs_upper_special, - point_source_offset=self._point_source_offset, num_images=self._num_images, - source_size=source_size, num_tau0=num_tau0, num_z_sampling=num_z_sampling, - source_grid_offset=source_grid_offset) - for lens_source_joint in self._joint_lens_with_source_light: - i_source = lens_source_joint[0] - if i_source in self._image_plane_source_list: - raise ValueError("linking a source light model with a lens model AND simultaneously parameterizing the" - " source position in the image plane is not valid!") - - @property - def num_point_source_images(self): - return self._num_images - -
[docs] def args2kwargs(self, args, bijective=False): - """ - - :param args: tuple of parameter values (float, strings, ...) - :param bijective: boolean, if True (default) returns the parameters in the form as they are sampled - (e.g. if image_plane_source_list is set =True it returns the position in the image plane coordinates), - if False, returns the parameters in the form to render a model (e.g. image_plane_source_list positions are - ray-traced back to the source plane). - :return: keyword arguments sorted in lenstronomy conventions - """ - i = 0 - args = np.atleast_1d(args) - kwargs_lens, i = self.lensParams.get_params(args, i) - kwargs_source, i = self.souceParams.get_params(args, i) - kwargs_lens_light, i = self.lensLightParams.get_params(args, i) - kwargs_ps, i = self.pointSourceParams.get_params(args, i) - kwargs_special, i = self.specialParams.get_params(args, i) - kwargs_extinction, i = self.extinctionParams.get_params(args, i) - self._update_lens_model(kwargs_special) - # update lens_light joint parameters - kwargs_lens_light = self._update_lens_light_joint_with_point_source(kwargs_lens_light, kwargs_ps) - kwargs_lens_light = self._update_joint_param(kwargs_lens_light, kwargs_lens_light, - self._joint_lens_light_with_lens_light) - # update lens_light joint with lens model parameters - kwargs_lens = self._update_joint_param(kwargs_lens_light, kwargs_lens, self._joint_lens_with_light) - kwargs_lens = self._update_joint_param(kwargs_source, kwargs_lens, self._joint_lens_with_source_light) - # update extinction model with lens light model - kwargs_extinction = self._update_joint_param(kwargs_lens_light, kwargs_extinction, - self._joint_extinction_with_lens_light) - # update lens model joint parameters (including scaling) - kwargs_lens = self._update_joint_param(kwargs_lens, kwargs_lens, self._joint_lens_with_lens) - kwargs_lens = self.update_lens_scaling(kwargs_special, kwargs_lens) - # update point source constraint solver - if self._solver is True: - x_pos, y_pos = kwargs_ps[0]['ra_image'], kwargs_ps[0]['dec_image'] - kwargs_lens = self._solver_module.update_solver(kwargs_lens, x_pos, y_pos) - # update source joint with point source - kwargs_source = self._update_source_joint_with_point_source(kwargs_lens, kwargs_source, kwargs_ps, - kwargs_special, image_plane=bijective) - # update source joint with source - kwargs_source = self._update_joint_param(kwargs_source, kwargs_source, self._joint_source_with_source) - # optional revert lens_scaling for bijective - if bijective is True: - kwargs_lens = self.update_lens_scaling(kwargs_special, kwargs_lens, inverse=True) - kwargs_return = {'kwargs_lens': kwargs_lens, 'kwargs_source': kwargs_source, - 'kwargs_lens_light': kwargs_lens_light, 'kwargs_ps': kwargs_ps, - 'kwargs_special': kwargs_special, 'kwargs_extinction': kwargs_extinction} - return kwargs_return
- -
[docs] def kwargs2args(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - kwargs_special=None, kwargs_extinction=None): - """ - inverse of getParam function - :param kwargs_lens: keyword arguments depending on model options - :param kwargs_source: keyword arguments depending on model options - :param kwargs_lens_light: lens light model keyword argument list - :param kwargs_ps: point source model keyword argument list - :param kwargs_special: special keyword arguments - :param kwargs_extinction: extinction model keyword argument list - :return: numpy array of parameters - """ - - args = self.lensParams.set_params(kwargs_lens) - args += self.souceParams.set_params(kwargs_source) - args += self.lensLightParams.set_params(kwargs_lens_light) - args += self.pointSourceParams.set_params(kwargs_ps) - args += self.specialParams.set_params(kwargs_special) - args += self.extinctionParams.set_params(kwargs_extinction) - return np.array(args, dtype=float)
- -
[docs] def param_limits(self): - """ - - :return: lower and upper limits of the arguments being sampled - """ - lower_limit = self.kwargs2args(kwargs_lens=self.lensParams.lower_limit, - kwargs_source=self.souceParams.lower_limit, - kwargs_lens_light=self.lensLightParams.lower_limit, - kwargs_ps=self.pointSourceParams.lower_limit, - kwargs_special=self.specialParams.lower_limit, - kwargs_extinction=self.extinctionParams.lower_limit) - upper_limit = self.kwargs2args(kwargs_lens=self.lensParams.upper_limit, - kwargs_source=self.souceParams.upper_limit, - kwargs_lens_light=self.lensLightParams.upper_limit, - kwargs_ps=self.pointSourceParams.upper_limit, - kwargs_special=self.specialParams.upper_limit, - kwargs_extinction=self.extinctionParams.upper_limit) - return lower_limit, upper_limit
- -
[docs] def num_param(self): - """ - - :return: number of parameters involved (int), list of parameter names - """ - num, name_list = self.lensParams.num_param() - _num, _list = self.souceParams.num_param() - num += _num - name_list += _list - _num, _list = self.lensLightParams.num_param() - num += _num - name_list += _list - _num, _list = self.pointSourceParams.num_param() - num += _num - name_list += _list - _num, _list = self.specialParams.num_param() - num += _num - name_list += _list - _num, _list = self.extinctionParams.num_param() - num += _num - name_list += _list - return num, name_list
- -
[docs] def num_param_linear(self): - """ - - :return: number of linear basis set coefficients that are solved for - """ - num = 0 - num += self.souceParams.num_param_linear() - num += self.lensLightParams.num_param_linear() - num += self.pointSourceParams.num_param_linear() - return num
- -
[docs] def image2source_plane(self, kwargs_source, kwargs_lens, image_plane=False): - """ - maps the image plane position definition of the source plane - - :param kwargs_source: source light model keyword argument list - :param kwargs_lens: lens model keyword argument list - :param image_plane: boolean, if True, does not up map image plane parameters to source plane - :return: source light model keyword arguments with mapped position arguments from image to source plane - """ - kwargs_source_copy = copy.deepcopy(kwargs_source) - for i, kwargs in enumerate(kwargs_source_copy): - if self._image_plane_source_list[i] is True and not image_plane: - if 'center_x' in kwargs: - x_mapped, y_mapped = self._image2SourceMapping.image2source(kwargs['center_x'], kwargs['center_y'], - kwargs_lens, index_source=i) - kwargs['center_x'] = x_mapped - kwargs['center_y'] = y_mapped - return kwargs_source_copy
- - def _update_source_joint_with_point_source(self, kwargs_lens_list, kwargs_source_list, kwargs_ps, kwargs_special, image_plane=False): - kwargs_source_list = self.image2source_plane(kwargs_source_list, kwargs_lens_list, image_plane=image_plane) - - for setting in self._joint_source_with_point_source: - i_point_source, k_source, param_list = setting - if 'ra_source' in kwargs_ps[i_point_source]: - x_mapped = kwargs_ps[i_point_source]['ra_source'] - y_mapped = kwargs_ps[i_point_source]['dec_source'] - else: - x_pos, y_pos = kwargs_ps[i_point_source]['ra_image'], kwargs_ps[i_point_source]['dec_image'] - # x_pos, y_pos = self.real_image_positions(x_pos, y_pos, kwargs_special) - x_mapped, y_mapped = self._image2SourceMapping.image2source(x_pos, y_pos, kwargs_lens_list, - index_source=k_source) - for param_name in param_list: - if param_name == 'center_x': - kwargs_source_list[k_source][param_name] = np.mean(x_mapped) - elif param_name == 'center_y': - kwargs_source_list[k_source][param_name] = np.mean(y_mapped) - else: - kwargs_source_list[k_source][param_name] = kwargs_ps[i_point_source][param_name] - return kwargs_source_list - - def _update_lens_light_joint_with_point_source(self, kwargs_lens_light_list, kwargs_ps): - - for setting in self._joint_lens_light_with_point_source: - i_point_source, k_lens_light, param_list = setting - if 'ra_image' in kwargs_ps[i_point_source]: - x_mapped = kwargs_ps[i_point_source]['ra_image'] - y_mapped = kwargs_ps[i_point_source]['dec_image'] - else: - raise ValueError("Joint lens light with point source not possible as point source is defined in the source plane!") - for param_name in param_list: - if param_name == 'center_x': - kwargs_lens_light_list[k_lens_light][param_name] = np.mean(x_mapped) - elif param_name == 'center_y': - kwargs_lens_light_list[k_lens_light][param_name] = np.mean(y_mapped) - return kwargs_lens_light_list - - @staticmethod - def _update_joint_param(kwargs_list_1, kwargs_list_2, joint_setting_list): - """ - - :param kwargs_list_1: list of keyword arguments - :param kwargs_list_2: list of keyword arguments - :param joint_setting_list: [[i_1, k_2, ['param_name1', 'param_name2', ...]], [...], ...] - or: [[i_1, k_2, {'param_old1': 'param_new1', 'ra_0': 'center_x'}], [...], ...] - :return: updated kwargs_list_2 with arguments from kwargs_list_1 as defined in joint_setting_list - """ - for setting in joint_setting_list: - i_1, k_2, param_list = setting - if type(param_list) == list: - for param_name in param_list: - kwargs_list_2[k_2][param_name] = kwargs_list_1[i_1][param_name] - elif type(param_list) == dict: - for param_to, param_from in param_list.items(): - kwargs_list_2[k_2][param_to] = kwargs_list_1[i_1][param_from] - else: - raise TypeError("Bad format for constraint setting: got %s" % param_list) - return kwargs_list_2 - - @staticmethod - def _update_log_sampling(kwargs_logsampling_lens, log_sampling_lens): - """ - Update the list of parameters being sampled in log-space - :param kwargs_logsampling_lens: list of list of parameters to sample in log10 - :param log_sampling_lens: [[i_1, ['param_name1', 'param_name2', ...]], [...], ...] - :return: updated kwargs_logsampling_lens - """ - for setting in log_sampling_lens: - i_1, param_list = setting - if type(param_list) == list: - kwargs_logsampling_lens[i_1] = param_list - else: - raise TypeError( - "Bad format for constraint setting: got %s. This should be in the format [[i_1, ['param_name1', 'param_name2', ...]], [...], ...]" % param_list) - return kwargs_logsampling_lens - - @staticmethod - def _fix_joint_param(kwargs_list_2, joint_setting_list): - """ - - :param kwargs_list_2: list of keyword arguments - :param joint_setting_list: [[i_1, k_2, ['param_name1', 'param_name2', ...]], [...], ...] - :return: fixes entries in kwargs_list_2 that are joint with other kwargs_list as defined in joint_setting_list - """ - kwargs_list_2_update = copy.deepcopy(kwargs_list_2) - for setting in joint_setting_list: - i_1, k_2, param_list = setting - for param_name in param_list: - kwargs_list_2_update[k_2][param_name] = 0 - return kwargs_list_2_update - -
[docs] def update_lens_scaling(self, kwargs_special, kwargs_lens, inverse=False): - """ - multiplies the scaling parameters of the profiles - - :param kwargs_special: keyword arguments of the 'special' arguments - :param kwargs_lens: lens model keyword argument list - :param inverse: bool, if True, performs the inverse lens scaling for bijective transforms - :return: updated lens model keyword argument list - """ - kwargs_lens_updated = copy.deepcopy(kwargs_lens) - if self._mass_scaling is False: - return kwargs_lens_updated - scale_factor_list = np.array(kwargs_special['scale_factor']) - if inverse is True: - scale_factor_list = 1. / np.array(kwargs_special['scale_factor']) - for i, kwargs in enumerate(kwargs_lens_updated): - if self._mass_scaling_list[i] is not False: - scale_factor = scale_factor_list[self._mass_scaling_list[i] - 1] - if 'theta_E' in kwargs: - kwargs['theta_E'] *= scale_factor - elif 'alpha_Rs' in kwargs: - kwargs['alpha_Rs'] *= scale_factor - elif 'alpha_1' in kwargs: - kwargs['alpha_1'] *= scale_factor - elif 'sigma0' in kwargs: - kwargs['sigma0'] *= scale_factor - elif 'k_eff' in kwargs: - kwargs['k_eff'] *= scale_factor - return kwargs_lens_updated
- - def _add_fixed_lens(self, kwargs_fixed, kwargs_init): - kwargs_fixed_update = copy.deepcopy(kwargs_fixed) - if self._solver is True: - if kwargs_init is None: - raise ValueError("kwargs_lens_init must be specified when the point source solver is enabled!") - kwargs_fixed_update = self._solver_module.add_fixed_lens(kwargs_fixed_update, kwargs_init) - return kwargs_fixed_update - -
[docs] def update_kwargs_model(self, kwargs_special): - """ - updates model keyword arguments with redshifts being sampled - - :param kwargs_special: keyword arguments from SpecialParam() class return of sampling arguments - :return: kwargs_model, bool (True if kwargs_model has changed, else False) - """ - if self._num_z_sampling == 0: - return self._kwargs_model, False - z_samples = kwargs_special.get('z_sampling') - lens_redshift_list = copy.deepcopy(self._lens_redshift_list) - if not(self._lens_redshift_list is None or self._lens_redshift_sampling_indexes is None): - # iterate through index lists - for i, index in enumerate(self._lens_redshift_sampling_indexes): - # update redshifts of lens and source redshift list in new form - if index > -1: - lens_redshift_list[i] = z_samples[index] - source_redshift_list = copy.deepcopy(self._source_redshift_list) - if not (self._source_redshift_list is None or self._source_redshift_sampling_indexes is None): - # iterate through index lists - for i, index in enumerate(self._source_redshift_sampling_indexes): - # update redshifts of lens and source redshift list in new form - if index > -1: - source_redshift_list[i] = z_samples[index] - # update lens model and source model classes - kwargs_model = copy.deepcopy(self._kwargs_model) - kwargs_model['lens_redshift_list'] = lens_redshift_list - kwargs_model['source_redshift_list'] = source_redshift_list - return kwargs_model, True
- - def _update_lens_model(self, kwargs_special): - """ - updates lens model instance of this class (and all class instances related to it) when an update to the - modeled redshifts of the deflector and/or source planes are made - - :param kwargs_special: keyword arguments from SpecialParam() class return of sampling arguments - :return: None, internal calls instance updated - """ - kwargs_model, update_bool = self.update_kwargs_model(kwargs_special) - if update_bool is True: - # TODO: this class instances are effectively duplicated in the likelihood module and may cause a lot of overhead - # in the calculation as the instances are re-generated every step, and even so doing it twice! - self._lens_model_class, self._source_model_class, _, _, _ = class_creator.create_class_instances( - all_models=True, **kwargs_model) - self._image2SourceMapping = Image2SourceMapping(lensModel=self._lens_model_class, - sourceModel=self._source_model_class) - -
[docs] def check_solver(self, kwargs_lens, kwargs_ps): - """ - test whether the image positions map back to the same source position - :param kwargs_lens: lens model keyword argument list - :param kwargs_ps: point source model keyword argument list - :return: Euclidean distance between the ray-shooting of the image positions - """ - if self._solver is True: - image_x, image_y = kwargs_ps[0]['ra_image'], kwargs_ps[0]['dec_image'] - dist = self._solver_module.check_solver(image_x, image_y, kwargs_lens) - return np.max(dist) - else: - return 0
- -
[docs] def print_setting(self): - """ - prints the setting of the parameter class - - :return: - """ - num, param_list = self.num_param() - num_linear = self.num_param_linear() - - print("The following model options are chosen:") - print("Lens models:", self._lens_model_list) - print("Source models:", self._source_light_model_list) - print("Lens light models:", self._lens_light_model_list) - print("Point source models:", self._point_source_model_list) - print("===================") - print("The following parameters are being fixed:") - print("Lens:", self.lensParams.kwargs_fixed) - print("Source:", self.souceParams.kwargs_fixed) - print("Lens light:", self.lensLightParams.kwargs_fixed) - print("Point source:", self.pointSourceParams.kwargs_fixed) - print("===================") - print("Joint parameters for different models") - print("Joint lens with lens:", self._joint_lens_with_lens) - print("Joint lens light with lens light:", self._joint_lens_light_with_lens_light) - print("Joint source with source:", self._joint_source_with_source) - print("Joint lens with light:", self._joint_lens_with_light) - print("Joint source with point source:", self._joint_source_with_point_source) - print("Joint lens light with point source:", self._joint_lens_light_with_point_source) - print("===================") - print("Number of non-linear parameters being sampled: ", num) - print("Parameters being sampled: ", param_list) - print("Number of linear parameters being solved for: ", num_linear) - print("===================") - print("The log10 of following parameters is being sampled:") - print("Lens:", self.lensParams.kwargs_logsampling)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Sampling/sampler.html b/docs/_build/html/_modules/lenstronomy/Sampling/sampler.html deleted file mode 100644 index 048236e35..000000000 --- a/docs/_build/html/_modules/lenstronomy/Sampling/sampler.html +++ /dev/null @@ -1,276 +0,0 @@ - - - - - - - - lenstronomy.Sampling.sampler — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Sampling.sampler

-__author__ = ['sibirrer', 'ajshajib', 'dgilman']
-
-import time
-
-import numpy as np
-from lenstronomy.Sampling.Samplers.pso import ParticleSwarmOptimizer
-from lenstronomy.Util import sampling_util
-from lenstronomy.Sampling.Pool.pool import choose_pool
-from scipy.optimize import minimize
-
-__all__ = ['Sampler']
-
-
-
[docs]class Sampler(object): - """ - class which executes the different sampling methods - Available are: MCMC with emcee and comsoHammer and a Particle Swarm Optimizer. - This are examples and depending on your problem, you might find other/better solutions. - Feel free to sample with your convenient sampler! - - """ - def __init__(self, likelihoodModule): - """ - - :param likelihoodModule: instance of LikelihoodModule class - """ - self.chain = likelihoodModule - self.lower_limit, self.upper_limit = self.chain.param_limits - -
[docs] def simplex(self, init_pos, n_iterations, method, print_key='SIMPLEX'): - """ - - :param init_pos: starting point for the optimization - :param n_iterations: maximum number of iterations - :param method: the optimization method, default is 'Nelder-Mead' - :return: the best fit for the lens model using the optimization routine specified by method - """ - print('Performing the optimization using algorithm:', method) - time_start = time.time() - - #negativelogL = lambda x: -1 * self.chain.logL(x) - - result = minimize(self.chain.negativelogL, x0=init_pos, method=method, - options={'maxiter': n_iterations, 'disp': True}) - logL = self.chain.logL(result['x']) - kwargs_return = self.chain.param.args2kwargs(result['x']) - print(-logL * 2 / (max(self.chain.effective_num_data_points(**kwargs_return), 1)), - 'reduced X^2 of best position') - print(logL, 'logL') - print(self.chain.effective_num_data_points(**kwargs_return), 'effective number of data points') - print(kwargs_return.get('kwargs_lens', None), 'lens result') - print(kwargs_return.get('kwargs_source', None), 'source result') - print(kwargs_return.get('kwargs_lens_light', None), 'lens light result') - print(kwargs_return.get('kwargs_ps', None), 'point source result') - print(kwargs_return.get('kwargs_special', None), 'special param result') - time_end = time.time() - print(time_end - time_start, 'time used for ', print_key) - print('===================') - - return result['x']
- -
[docs] def pso(self, n_particles, n_iterations, lower_start=None, upper_start=None, - threadCount=1, init_pos=None, mpi=False, print_key='PSO'): - """ - Return the best fit for the lens model on catalogue basis with - particle swarm optimizer. - - :param n_particles: number of particles in the sampling process - :param n_iterations: number of iterations of the swarm - :param lower_start: numpy array, lower end parameter of the values of the starting particles - :param upper_start: numpy array, upper end parameter of the values of the starting particles - :param threadCount: number of threads in the computation (only applied if mpi=False) - :param init_pos: numpy array, position of the initial best guess model - :param mpi: bool, if True, makes instance of MPIPool to allow for MPI execution - :param print_key: string, prints the process name in the progress bar (optional) - :return: kwargs_result (of best fit), [lnlikelihood of samples, positions of samples, velocity of sampels) - """ - if lower_start is None or upper_start is None: - lower_start, upper_start = np.array(self.lower_limit), np.array(self.upper_limit) - print("PSO initialises its particles with default values") - else: - lower_start = np.maximum(lower_start, self.lower_limit) - upper_start = np.minimum(upper_start, self.upper_limit) - - pool = choose_pool(mpi=mpi, processes=threadCount, use_dill=True) - - if mpi is True and pool.is_master(): print('MPI option chosen for PSO.') - - pso = ParticleSwarmOptimizer(self.chain.logL, - lower_start, upper_start, n_particles, - pool=pool) - - if init_pos is None: - init_pos = (upper_start - lower_start) / 2 + lower_start - - pso.set_global_best(init_pos, [0]*len(init_pos), - self.chain.logL(init_pos)) - - if pool.is_master(): - print('Computing the %s ...' % print_key) - - time_start = time.time() - - result, [chi2_list, pos_list, vel_list] = pso.optimize(n_iterations) - - if pool.is_master(): - kwargs_return = self.chain.param.args2kwargs(result) - print(pso.global_best.fitness * 2 / (max( - self.chain.effective_num_data_points(**kwargs_return), 1)), 'reduced X^2 of best position') - print(pso.global_best.fitness, 'logL') - print(self.chain.effective_num_data_points(**kwargs_return), 'effective number of data points') - print(kwargs_return.get('kwargs_lens', None), 'lens result') - print(kwargs_return.get('kwargs_source', None), 'source result') - print(kwargs_return.get('kwargs_lens_light', None), 'lens light result') - print(kwargs_return.get('kwargs_ps', None), 'point source result') - print(kwargs_return.get('kwargs_special', None), 'special param result') - time_end = time.time() - print(time_end - time_start, 'time used for ', print_key) - print('===================') - return result, [chi2_list, pos_list, vel_list]
- -
[docs] def mcmc_emcee(self, n_walkers, n_run, n_burn, mean_start, sigma_start, mpi=False, progress=False, threadCount=1, - initpos=None, backup_filename=None, start_from_backup=False): - """ - Run MCMC with emcee. - For details, please have a look at the documentation of the emcee packager. - - :param n_walkers: number of walkers in the emcee process - :type n_walkers: integer - :param n_run: number of sampling (after burn-in) of the emcee - :type n_run: integer - :param n_burn: number of burn-in iterations (those will not be saved in the output sample) - :type n_burn: integer - :param mean_start: mean of the parameter position of the initialising sample - :type mean_start: numpy array of length the number of parameters - :param sigma_start: spread of the parameter values (uncorrelated in each dimension) of the initialising sample - :type sigma_start: numpy array of length the number of parameters - :param mpi: if True, initializes an MPIPool to allow for MPI execution of the sampler - :type mpi: bool - :param progress: if True, prints the progress bar - :type progress: bool - :param threadCount: number of threats in multi-processing (not applicable for MPI) - :type threadCount: integer - :param initpos: initial walker position to start sampling (optional) - :type initpos: numpy array of size num param x num walkser - :param backup_filename: name of the HDF5 file where sampling state is saved (through emcee backend engine) - :type backup_filename: string - :param start_from_backup: if True, start from the state saved in `backup_filename`. - Otherwise, create a new backup file with name `backup_filename` (any already existing file is overwritten!). - :type start_from_backup: bool - :return: samples, ln likelihood value of samples - :rtype: numpy 2d array, numpy 1d array - """ - import emcee - - num_param, _ = self.chain.param.num_param() - if initpos is None: - initpos = sampling_util.sample_ball_truncated(mean_start, sigma_start, self.lower_limit, self.upper_limit, - size=n_walkers) - - pool = choose_pool(mpi=mpi, processes=threadCount, use_dill=True) - - if backup_filename is not None: - backend = emcee.backends.HDFBackend(backup_filename, name="lenstronomy_mcmc_emcee") - if pool.is_master(): - print("Warning: All samples (including burn-in) will be saved in backup file '{}'.".format(backup_filename)) - if start_from_backup: - initpos = None - n_run_eff = n_run - else: - n_run_eff = n_burn + n_run - backend.reset(n_walkers, num_param) - if pool.is_master(): - print("Warning: backup file '{}' has been reset!".format(backup_filename)) - else: - backend = None - n_run_eff = n_burn + n_run - - time_start = time.time() - - sampler = emcee.EnsembleSampler(n_walkers, num_param, self.chain.logL, - pool=pool, backend=backend) - - sampler.run_mcmc(initpos, n_run_eff, progress=progress) - flat_samples = sampler.get_chain(discard=n_burn, thin=1, flat=True) - dist = sampler.get_log_prob(flat=True, discard=n_burn, thin=1) - if pool.is_master(): - print('Computing the MCMC...') - print('Number of walkers = ', n_walkers) - print('Burn-in iterations: ', n_burn) - print('Sampling iterations (in current run):', n_run_eff) - time_end = time.time() - print(time_end - time_start, 'time taken for MCMC sampling') - return flat_samples, dist
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Sampling/special_param.html b/docs/_build/html/_modules/lenstronomy/Sampling/special_param.html deleted file mode 100644 index b6c87f12d..000000000 --- a/docs/_build/html/_modules/lenstronomy/Sampling/special_param.html +++ /dev/null @@ -1,318 +0,0 @@ - - - - - - - - lenstronomy.Sampling.special_param — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Sampling.special_param

-__author__ = 'sibirrer'
-
-__all__ = ['SpecialParam']
-
-
-
[docs]class SpecialParam(object): - """ - class that handles special parameters that are not directly part of a specific model component. - These includes cosmology relevant parameters, astrometric errors and overall scaling parameters. - """ - - def __init__(self, Ddt_sampling=False, mass_scaling=False, num_scale_factor=1, kwargs_fixed=None, kwargs_lower=None, - kwargs_upper=None, point_source_offset=False, source_size=False, num_images=0, num_tau0=0, - num_z_sampling=0, source_grid_offset=False): - """ - - :param Ddt_sampling: bool, if True, samples the time-delay distance D_dt (in units of Mpc) - :param mass_scaling: bool, if True, samples a mass scaling factor between different profiles - :param num_scale_factor: int, number of independent mass scaling factors being sampled - :param kwargs_fixed: keyword arguments, fixed parameters during sampling - :param kwargs_lower: keyword arguments, lower bound of parameters being sampled - :param kwargs_upper: keyword arguments, upper bound of parameters being sampled - :param point_source_offset: bool, if True, adds relative offsets ot the modeled image positions relative to the - time-delay and lens equation solver - :param num_images: number of point source images such that the point source offset parameters match their numbers - :param source_size: bool, if True, samples a source size parameters to be evaluated in the flux ratio likelihood - :param num_tau0: integer, number of different optical depth re-normalization factors - :param num_z_sampling: integer, number of different lens redshifts to be sampled - :param source_grid_offset: bool, if True, samples two parameters (x, y) for the offset of the pixelated source plane grid coordinates. - Warning: this is only defined for pixel-based source modelling (e.g. 'SLIT_STARLETS' light profile) - """ - - self._D_dt_sampling = Ddt_sampling - self._mass_scaling = mass_scaling - self._num_scale_factor = num_scale_factor - self._point_source_offset = point_source_offset - self._num_images = num_images - self._num_tau0 = num_tau0 - self._num_z_sampling = num_z_sampling - if num_z_sampling > 0: - self._z_sampling = True - else: - self._z_sampling = False - - if kwargs_fixed is None: - kwargs_fixed = {} - self._kwargs_fixed = kwargs_fixed - self._source_size = source_size - self._source_grid_offset = source_grid_offset - if kwargs_lower is None: - kwargs_lower = {} - if self._D_dt_sampling is True: - kwargs_lower['D_dt'] = 0 - if self._mass_scaling is True: - kwargs_lower['scale_factor'] = [0] * self._num_scale_factor - if self._point_source_offset is True: - kwargs_lower['delta_x_image'] = [-1] * self._num_images - kwargs_lower['delta_y_image'] = [-1] * self._num_images - if self._source_size is True: - kwargs_lower['source_size'] = 0 - if self._num_tau0 > 0: - kwargs_lower['tau0_list'] = [0] * self._num_tau0 - if self._z_sampling is True: - kwargs_lower['z_sampling'] = [0] * self._num_z_sampling - if self._source_grid_offset: - kwargs_lower['delta_x_source_grid'] = -100 - kwargs_lower['delta_y_source_grid'] = -100 - if kwargs_upper is None: - kwargs_upper = {} - if self._D_dt_sampling is True: - kwargs_upper['D_dt'] = 100000 - if self._mass_scaling is True: - kwargs_upper['scale_factor'] = [1000] * self._num_scale_factor - if self._point_source_offset is True: - kwargs_upper['delta_x_image'] = [1] * self._num_images - kwargs_upper['delta_y_image'] = [1] * self._num_images - if self._source_size is True: - kwargs_upper[source_size] = 1 - if self._num_tau0 > 0: - kwargs_upper['tau0_list'] = [1000] * self._num_tau0 - if self._z_sampling is True: - kwargs_upper['z_sampling'] = [20] * self._num_z_sampling - if self._source_grid_offset: - kwargs_upper['delta_x_source_grid'] = 100 - kwargs_upper['delta_y_source_grid'] = 100 - self.lower_limit = kwargs_lower - self.upper_limit = kwargs_upper - -
[docs] def get_params(self, args, i): - """ - - :param args: argument list - :param i: integer, list index to start the read out for this class - :return: keyword arguments related to args, index after reading out arguments of this class - """ - kwargs_special = {} - if self._D_dt_sampling is True: - if 'D_dt' not in self._kwargs_fixed: - kwargs_special['D_dt'] = args[i] - i += 1 - else: - kwargs_special['D_dt'] = self._kwargs_fixed['D_dt'] - if self._mass_scaling is True: - if 'scale_factor' not in self._kwargs_fixed: - kwargs_special['scale_factor'] = args[i: i + self._num_scale_factor] - i += self._num_scale_factor - else: - kwargs_special['scale_factor'] = self._kwargs_fixed['scale_factor'] - if self._point_source_offset is True: - if 'delta_x_image' not in self._kwargs_fixed: - kwargs_special['delta_x_image'] = args[i: i + self._num_images] - i += self._num_images - else: - kwargs_special['delta_x_image'] = self._kwargs_fixed['delta_x_image'] - if 'delta_y_image' not in self._kwargs_fixed: - kwargs_special['delta_y_image'] = args[i: i + self._num_images] - i += self._num_images - else: - kwargs_special['delta_y_image'] = self._kwargs_fixed['delta_y_image'] - if self._source_size is True: - if 'source_size' not in self._kwargs_fixed: - kwargs_special['source_size'] = args[i] - i += 1 - else: - kwargs_special['source_size'] = self._kwargs_fixed['source_size'] - if self._num_tau0 > 0: - if 'tau0_list' not in self._kwargs_fixed: - kwargs_special['tau0_list'] = args[i:i + self._num_tau0] - i += self._num_tau0 - else: - kwargs_special['tau0_list'] = self._kwargs_fixed['tau0_list'] - if self._z_sampling is True: - if 'z_sampling' not in self._kwargs_fixed: - kwargs_special['z_sampling'] = args[i:i + self._num_z_sampling] - i += self._num_z_sampling - else: - kwargs_special['z_sampling'] = self._kwargs_fixed['z_sampling'] - if self._source_grid_offset: - if 'delta_x_source_grid' not in self._kwargs_fixed: - kwargs_special['delta_x_source_grid'] = args[i] - i += 1 - else: - kwargs_special['delta_x_source_grid'] = self._kwargs_fixed['delta_x_source_grid'] - if 'delta_y_source_grid' not in self._kwargs_fixed: - kwargs_special['delta_y_source_grid'] = args[i] - i += 1 - else: - kwargs_special['delta_y_source_grid'] = self._kwargs_fixed['delta_y_source_grid'] - return kwargs_special, i
- -
[docs] def set_params(self, kwargs_special): - """ - - :param kwargs_special: keyword arguments with parameter settings - :return: argument list of the sampled parameters extracted from kwargs_special - """ - args = [] - if self._D_dt_sampling is True: - if 'D_dt' not in self._kwargs_fixed: - args.append(kwargs_special['D_dt']) - if self._mass_scaling is True: - if 'scale_factor' not in self._kwargs_fixed: - for i in range(self._num_scale_factor): - args.append(kwargs_special['scale_factor'][i]) - if self._point_source_offset is True: - if 'delta_x_image' not in self._kwargs_fixed: - for i in range(self._num_images): - args.append(kwargs_special['delta_x_image'][i]) - if 'delta_y_image' not in self._kwargs_fixed: - for i in range(self._num_images): - args.append(kwargs_special['delta_y_image'][i]) - if self._source_size is True: - if 'source_size' not in self._kwargs_fixed: - args.append(kwargs_special['source_size']) - if self._num_tau0 > 0: - if 'tau0_list' not in self._kwargs_fixed: - for i in range(self._num_tau0): - args.append(kwargs_special['tau0_list'][i]) - if self._z_sampling is True: - if 'z_sampling' not in self._kwargs_fixed: - for i in range(self._num_z_sampling): - args.append(kwargs_special['z_sampling'][i]) - if self._source_grid_offset is True: - if 'delta_x_source_grid' not in self._kwargs_fixed: - args.append(kwargs_special['delta_x_source_grid']) - if 'delta_y_source_grid' not in self._kwargs_fixed: - args.append(kwargs_special['delta_y_source_grid']) - return args
- -
[docs] def num_param(self): - """ - - :return: integer, number of free parameters sampled (and managed) by this class, parameter names (list of strings) - """ - num = 0 - string_list = [] - if self._D_dt_sampling is True: - if 'D_dt' not in self._kwargs_fixed: - num += 1 - string_list.append('D_dt') - if self._mass_scaling is True: - if 'scale_factor' not in self._kwargs_fixed: - num += self._num_scale_factor - for i in range(self._num_scale_factor): - string_list.append('scale_factor') - if self._point_source_offset is True: - if 'delta_x_image' not in self._kwargs_fixed: - num += self._num_images - for i in range(self._num_images): - string_list.append('delta_x_image') - if 'delta_y_image' not in self._kwargs_fixed: - num += self._num_images - for i in range(self._num_images): - string_list.append('delta_y_image') - if self._source_size is True: - if 'source_size' not in self._kwargs_fixed: - num += 1 - string_list.append('source_size') - if self._num_tau0 > 0: - if 'tau0_list' not in self._kwargs_fixed: - num += self._num_tau0 - for i in range(self._num_tau0): - string_list.append('tau0') - if self._z_sampling is True: - if 'z_sampling' not in self._kwargs_fixed: - num += self._num_z_sampling - for i in range(self._num_z_sampling): - string_list.append('z') - if self._source_grid_offset is True: - if 'delta_x_source_grid' not in self._kwargs_fixed: - num += 1 - string_list.append('delta_x_source_grid') - if 'delta_y_source_grid' not in self._kwargs_fixed: - num += 1 - string_list.append('delta_y_source_grid') - return num, string_list
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/SimulationAPI/ObservationConfig/DES.html b/docs/_build/html/_modules/lenstronomy/SimulationAPI/ObservationConfig/DES.html deleted file mode 100644 index 997199a62..000000000 --- a/docs/_build/html/_modules/lenstronomy/SimulationAPI/ObservationConfig/DES.html +++ /dev/null @@ -1,183 +0,0 @@ - - - - - - - - lenstronomy.SimulationAPI.ObservationConfig.DES — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.SimulationAPI.ObservationConfig.DES

-"""Provisional DES instrument and observational settings.
-See Optics and Observation Conditions spreadsheet at
-https://docs.google.com/spreadsheets/d/1pMUB_OOZWwXON2dd5oP8PekhCT5MBBZJO1HV7IMZg4Y/edit?usp=sharing for list of
-sources. """
-import lenstronomy.Util.util as util
-
-__all__ = ['DES']
-
-g_band_obs = {'exposure_time': 90.,
-              'sky_brightness': 22.01,
-              'magnitude_zero_point': 26.58,
-              'num_exposures': 10,
-              'seeing': 1.12,
-              'psf_type': 'GAUSSIAN'}
-
-r_band_obs = {'exposure_time': 90.,
-              'sky_brightness': 21.15,
-              'magnitude_zero_point': 26.78,
-              'num_exposures': 10,
-              'seeing': 0.96,
-              'psf_type': 'GAUSSIAN'}
-
-i_band_obs = {'exposure_time': 90.,
-              'sky_brightness': 19.89,
-              'magnitude_zero_point': 26.75,
-              'num_exposures': 10,
-              'seeing': 0.88,
-              'psf_type': 'GAUSSIAN'}
-
-z_band_obs = {'exposure_time': 90.,
-              'sky_brightness': 18.72,
-              'magnitude_zero_point': 26.48,
-              'num_exposures': 10,
-              'seeing': 0.84,
-              'psf_type': 'GAUSSIAN'}
-
-Y_band_obs = {'exposure_time': 45.,
-              'sky_brightness': 17.96,
-              'magnitude_zero_point': 25.40,
-              'num_exposures': 10,
-              'seeing': 0.9,
-              'psf_type': 'GAUSSIAN'}
-
-"""
-:keyword exposure_time: exposure time per image (in seconds)
-:keyword sky_brightness: sky brightness (in magnitude per square arcseconds in units of electrons)
-:keyword magnitude_zero_point: magnitude in which 1 count (e-) per second per arcsecond square is registered
-:keyword num_exposures: number of exposures that are combined (depends on coadd_years)  
-:keyword seeing: Full-Width-at-Half-Maximum (FWHM) of PSF
-:keyword psf_type: string, type of PSF ('GAUSSIAN' supported) 
-"""
-
-
-
[docs]class DES(object): - """ - class contains DES instrument and observation configurations - """ - def __init__(self, band='g', psf_type='GAUSSIAN', coadd_years=3): - """ - - :param band: string, 'g', 'r', 'i', 'z', or 'Y' supported. Determines obs dictionary. - :param psf_type: string, type of PSF ('GAUSSIAN' supported). - :param coadd_years: int, number of years corresponding to num_exposures in obs dict. Currently supported: 1-6. - """ - if band == 'g': - self.obs = g_band_obs - elif band == 'r': - self.obs = r_band_obs - elif band == 'i': - self.obs = i_band_obs - elif band == 'z': - self.obs = z_band_obs - elif band == 'Y': - self.obs = Y_band_obs - else: - raise ValueError("band %s not supported! Choose 'g', 'r', 'i', 'z', or 'Y'." % band) - - if psf_type != 'GAUSSIAN': - raise ValueError("psf_type %s not supported!" % psf_type) - - if coadd_years > 6 or coadd_years < 1: - raise ValueError(" %s coadd_years not supported! Choose an integer between 1 and 6." % coadd_years) - elif coadd_years != 3: - self.obs['num_exposures'] = (coadd_years * 10) // 3 - - self.camera = {'read_noise': 7, - 'pixel_scale': 0.263, - 'ccd_gain': 4} - """ - :keyword read_noise: std of noise generated by read-out (in units of electrons) - :keyword pixel_scale: scale (in arcseconds) of pixels - :keyword ccd_gain: electrons/ADU (analog-to-digital unit). - """ - -
[docs] def kwargs_single_band(self): - """ - - :return: merged kwargs from camera and obs dicts - """ - kwargs = util.merge_dicts(self.camera, self.obs) - return kwargs
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/SimulationAPI/ObservationConfig/Euclid.html b/docs/_build/html/_modules/lenstronomy/SimulationAPI/ObservationConfig/Euclid.html deleted file mode 100644 index 33397dde7..000000000 --- a/docs/_build/html/_modules/lenstronomy/SimulationAPI/ObservationConfig/Euclid.html +++ /dev/null @@ -1,146 +0,0 @@ - - - - - - - - lenstronomy.SimulationAPI.ObservationConfig.Euclid — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.SimulationAPI.ObservationConfig.Euclid

-"""Provisional Euclid instrument and observational settings.
-See Optics and Observation Conditions spreadsheet at
-https://docs.google.com/spreadsheets/d/1pMUB_OOZWwXON2dd5oP8PekhCT5MBBZJO1HV7IMZg4Y/edit?usp=sharing for list of
-sources. """
-import lenstronomy.Util.util as util
-
-__all__ = ['Euclid']
-
-VIS_obs = {'exposure_time': 565.,
-           'sky_brightness': 22.35,
-           'magnitude_zero_point': 24.0,
-           'num_exposures': 4,
-           'seeing': 0.16,
-           'psf_type': 'GAUSSIAN'}
-
-"""
-:keyword exposure_time: exposure time per image (in seconds)
-:keyword sky_brightness: sky brightness (in magnitude per square arcseconds in units of electrons)
-:keyword magnitude_zero_point: magnitude in which 1 count (e-) per second per arcsecond square is registered
-:keyword num_exposures: number of exposures that are combined (depends on coadd_years)  
-:keyword seeing: Full-Width-at-Half-Maximum (FWHM) of PSF
-:keyword psf_type: string, type of PSF ('GAUSSIAN' supported) 
-"""
-
-
-
[docs]class Euclid(object): - """ - class contains Euclid instrument and observation configurations - """ - def __init__(self, band='VIS', psf_type='GAUSSIAN', coadd_years=6): - """ - - :param band: string, only 'VIS' supported. Determines obs dictionary. - :param psf_type: string, type of PSF ('GAUSSIAN' supported). - :param coadd_years: int, number of years corresponding to num_exposures in obs dict. Currently supported: 2-6. - """ - self.obs = VIS_obs - if band != 'VIS': - raise ValueError("band %s not supported! Choose 'VIS'." % band) - - if psf_type != 'GAUSSIAN': - raise ValueError("psf_type %s not supported!" % psf_type) - - if coadd_years > 6 or coadd_years < 2: - raise ValueError(" %s coadd_years not supported! Choose an integer between 2 and 6." % coadd_years) - elif coadd_years != 6: - self.obs['num_exposures'] = (coadd_years * VIS_obs["num_exposures"]) // 6 - - self.camera = {'read_noise': 4.2, - 'pixel_scale': 0.101, - 'ccd_gain': 3.1} - """ - :keyword read_noise: std of noise generated by read-out (in units of electrons) - :keyword pixel_scale: scale (in arcseconds) of pixels - :keyword ccd_gain: electrons/ADU (analog-to-digital unit). - """ - -
[docs] def kwargs_single_band(self): - """ - - :return: merged kwargs from camera and obs dicts - """ - kwargs = util.merge_dicts(self.camera, self.obs) - return kwargs
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/SimulationAPI/ObservationConfig/HST.html b/docs/_build/html/_modules/lenstronomy/SimulationAPI/ObservationConfig/HST.html deleted file mode 100644 index a818964e5..000000000 --- a/docs/_build/html/_modules/lenstronomy/SimulationAPI/ObservationConfig/HST.html +++ /dev/null @@ -1,168 +0,0 @@ - - - - - - - - lenstronomy.SimulationAPI.ObservationConfig.HST — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.SimulationAPI.ObservationConfig.HST

-"""Provisional HST instrument and observational settings.
-See Optics and Observation Conditions spreadsheet at
-https://docs.google.com/spreadsheets/d/1pMUB_OOZWwXON2dd5oP8PekhCT5MBBZJO1HV7IMZg4Y/edit?usp=sharing for list of
-sources. """
-import lenstronomy.Util.util as util
-
-__all__ = ['HST']
-
-# F160W filter configs
-WFC3_F160W_band_obs = {'exposure_time': 5400.,  # ~90mins orbit on HST, but this number corresponds to
-                       # approximately two HST orbits with overheads, guide star aquisition. ~2700s science exposure per orbit
-                       'sky_brightness': 22.3,
-                       'magnitude_zero_point': 25.96,
-                       'num_exposures': 1,
-                       'seeing': 0.08,  # set equal to the approx pixel size for drizzled PSF. Note that undrizzled PSF FWHM ~ 0.15" (Windhorst et al 2011)
-                       'psf_type': 'GAUSSIAN'
-                       }
-
-# configs meant to simulate images close to those provided as part of the Time Delay Lens Modeling Challenge
-TDLMC_F160W_band_obs = {'exposure_time': 5400.,  # ~90mins orbit on HST, but this number corresponds to
-                        # approximately two HST orbits with overheads, guide star aquisition. ~2700s science exposure per orbit
-                        'sky_brightness': 22.0,
-                        'magnitude_zero_point': 25.9463,
-                        'num_exposures': 1,
-                        'seeing': None,
-                        'psf_type': 'PIXEL'  # note kernel_point_source (the PSF map) must be provided separately
-                        }
-
-"""
-:keyword exposure_time: exposure time per image (in seconds)
-:keyword sky_brightness: sky brightness (in magnitude per square arcseconds in units of electrons)
-:keyword magnitude_zero_point: magnitude in which 1 count (e-) per second per arcsecond square is registered
-:keyword num_exposures: number of exposures that are combined (depends on coadd_years)
-:keyword seeing: Full-Width-at-Half-Maximum (FWHM) of PSF
-:keyword psf_type: string, type of PSF ('GAUSSIAN' and 'PIXEL' supported)
-"""
-
-
-
[docs]class HST(object): - """ - class contains HST instrument and observation configurations - """ - - def __init__(self, band='TDLMC_F160W', psf_type='PIXEL', coadd_years=None): - """ - - :param band: string, 'WFC3_F160W' or 'TDLMC_F160W' supported. Determines obs dictionary. - :param psf_type: string, type of PSF ('GAUSSIAN', 'PIXEL' supported). - :param coadd_years: int, number of years corresponding to num_exposures in obs dict. Currently supported: None. - """ - - if band == 'TDLMC_F160W': - self.obs = TDLMC_F160W_band_obs - elif band == 'WFC3_F160W' or band == 'F160W': - self.obs = WFC3_F160W_band_obs - - else: - raise ValueError("band %s not supported! Choose 'WFC3_F160W' or 'TDLMC_F160W'." % band) - - if psf_type == 'GAUSSIAN': - self.obs['psf_type'] = 'GAUSSIAN' - elif psf_type != 'PIXEL': - raise ValueError("psf_type %s not supported!" % psf_type) - - if coadd_years is not None: - raise ValueError(" %s coadd_years not supported! " - "You may manually adjust num_exposures in obs dict if required." % coadd_years) - - # WFC3 camera settings - self.camera = {'read_noise': 4, - 'pixel_scale': 0.08, # approx pixel size for drizzled PSF - 'ccd_gain': 2.5, - } - """ - :keyword read_noise: std of noise generated by read-out (in units of electrons) - :keyword pixel_scale: scale (in arcseconds) of pixels - :keyword ccd_gain: electrons/ADU (analog-to-digital unit). - """ - -
[docs] def kwargs_single_band(self): - """ - - :return: merged kwargs from camera and obs dicts - """ - kwargs = util.merge_dicts(self.camera, self.obs) - return kwargs
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/SimulationAPI/ObservationConfig/LSST.html b/docs/_build/html/_modules/lenstronomy/SimulationAPI/ObservationConfig/LSST.html deleted file mode 100644 index 6975a5a22..000000000 --- a/docs/_build/html/_modules/lenstronomy/SimulationAPI/ObservationConfig/LSST.html +++ /dev/null @@ -1,198 +0,0 @@ - - - - - - - - lenstronomy.SimulationAPI.ObservationConfig.LSST — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.SimulationAPI.ObservationConfig.LSST

-"""Provisional LSST instrument and observational settings.
-See Optics and Observation Conditions spreadsheet at
-https://docs.google.com/spreadsheets/d/1pMUB_OOZWwXON2dd5oP8PekhCT5MBBZJO1HV7IMZg4Y/edit?usp=sharing for list of
-sources. """
-import lenstronomy.Util.util as util
-
-__all__ = ['LSST']
-
-u_band_obs = {'exposure_time': 15.,
-              'sky_brightness': 22.99,
-              'magnitude_zero_point': 26.5,
-              'num_exposures': 140,
-              'seeing': 0.81,
-              'psf_type': 'GAUSSIAN'}
-
-g_band_obs = {'exposure_time': 15.,
-              'sky_brightness': 22.26,
-              'magnitude_zero_point': 28.30,
-              'num_exposures': 200,
-              'seeing': 0.77,
-              'psf_type': 'GAUSSIAN'}
-
-r_band_obs = {'exposure_time': 15.,
-              'sky_brightness': 21.2,
-              'magnitude_zero_point': 28.13,
-              'num_exposures': 460,
-              'seeing': 0.73,
-              'psf_type': 'GAUSSIAN'}
-
-i_band_obs = {'exposure_time': 15.,
-              'sky_brightness': 20.48,
-              'magnitude_zero_point': 27.79,
-              'num_exposures': 460,
-              'seeing': 0.71,
-              'psf_type': 'GAUSSIAN'}
-
-z_band_obs = {'exposure_time': 15.,
-              'sky_brightness': 19.6,
-              'magnitude_zero_point': 27.40,
-              'num_exposures': 400,
-              'seeing': 0.69,
-              'psf_type': 'GAUSSIAN'}
-
-y_band_obs = {'exposure_time': 15.,
-              'sky_brightness': 18.61,
-              'magnitude_zero_point': 26.58,
-              'num_exposures': 400,
-              'seeing': 0.68,
-              'psf_type': 'GAUSSIAN'}
-
-
-"""
-:keyword exposure_time: exposure time per image (in seconds)
-:keyword sky_brightness: sky brightness (in magnitude per square arcseconds in units of electrons)
-:keyword magnitude_zero_point: magnitude in which 1 count (e-) per second per arcsecond square is registered
-:keyword num_exposures: number of exposures that are combined (depends on coadd_years)
-    when coadd_years = 10: num_exposures is baseline num of visits over 10 years (x2 since 2x15s exposures per visit)
-:keyword seeing: Full-Width-at-Half-Maximum (FWHM) of PSF
-:keyword psf_type: string, type of PSF ('GAUSSIAN' supported)
-"""
-
-
-
[docs]class LSST(object): - """ - class contains LSST instrument and observation configurations - """ - - def __init__(self, band='g', psf_type='GAUSSIAN', coadd_years=10): - """ - - :param band: string, 'u', 'g', 'r', 'i', 'z' or 'y' supported. Determines obs dictionary. - :param psf_type: string, type of PSF ('GAUSSIAN' supported). - :param coadd_years: int, number of years corresponding to num_exposures in obs dict. Currently supported: 1-10. - """ - if band.isalpha(): - band = band.lower() - if band == 'g': - self.obs = g_band_obs - elif band == 'r': - self.obs = r_band_obs - elif band == 'i': - self.obs = i_band_obs - elif band == 'u': - self.obs = u_band_obs - elif band == 'z': - self.obs = z_band_obs - elif band == 'y': - self.obs = y_band_obs - else: - raise ValueError("band %s not supported! Choose 'u', 'g', 'r', 'i', 'z' or 'y'." % band) - - if psf_type != 'GAUSSIAN': - raise ValueError("psf_type %s not supported!" % psf_type) - - if coadd_years > 10 or coadd_years < 1: - raise ValueError(" %s coadd_years not supported! Choose an integer between 1 and 10." % coadd_years) - elif coadd_years != 10: - self.obs['num_exposures'] = coadd_years*self.obs['num_exposures']//10 - - self.camera = {'read_noise': 10, # will be <10 - 'pixel_scale': 0.2, - 'ccd_gain': 2.3, - } - """ - :keyword read_noise: std of noise generated by read-out (in units of electrons) - :keyword pixel_scale: scale (in arcseconds) of pixels - :keyword ccd_gain: electrons/ADU (analog-to-digital unit). - """ - -
[docs] def kwargs_single_band(self): - """ - - :return: merged kwargs from camera and obs dicts - """ - kwargs = util.merge_dicts(self.camera, self.obs) - return kwargs
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/SimulationAPI/data_api.html b/docs/_build/html/_modules/lenstronomy/SimulationAPI/data_api.html deleted file mode 100644 index d19c57d67..000000000 --- a/docs/_build/html/_modules/lenstronomy/SimulationAPI/data_api.html +++ /dev/null @@ -1,133 +0,0 @@ - - - - - - - - lenstronomy.SimulationAPI.data_api — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.SimulationAPI.data_api

-from lenstronomy.SimulationAPI.observation_api import SingleBand
-from lenstronomy.Data.imaging_data import ImageData
-import lenstronomy.Util.util as util
-import numpy as np
-
-__all__ = ['DataAPI']
-
-
-
[docs]class DataAPI(SingleBand): - """ - This class is a wrapper of the general description of data in SingleBand() to translate those quantities into - configurations in the core lenstronomy Data modules to simulate images according to those quantities. - This class is meant to be an example of a wrapper. More possibilities in terms of PSF and data type - options are available. Have a look in the specific modules if you are interested in. - - """ - def __init__(self, numpix, **kwargs_single_band): - """ - - :param numpix: number of pixels per axis in the simulation to be modelled - :param kwargs_single_band: keyword arguments used to create instance of SingleBand class - """ - self.numpix = numpix - SingleBand.__init__(self, **kwargs_single_band) - - @property - def data_class(self): - """ - creates a Data() instance of lenstronomy based on knowledge of the observation - - :return: instance of Data() class - """ - data_class = ImageData(**self.kwargs_data) - return data_class - - @property - def kwargs_data(self): - """ - - :return: keyword arguments for ImageData class instance - """ - x_grid, y_grid, ra_at_xy_0, dec_at_xy_0, x_at_radec_0, y_at_radec_0, transform_pix2angle, transform_angle2pix = util.make_grid_with_coordtransform( - numPix=self.numpix, deltapix=self.pixel_scale, subgrid_res=1, left_lower=False, inverse=False) - # CCD gain corrected exposure time to allow a direct Poisson estimates based on IID counts - scaled_exposure_time = self.flux_iid(1) - kwargs_data = {'image_data': np.zeros((self.numpix, self.numpix)), 'ra_at_xy_0': ra_at_xy_0, - 'dec_at_xy_0': dec_at_xy_0, - 'transform_pix2angle': transform_pix2angle, - 'background_rms': self.background_noise, - 'exposure_time': scaled_exposure_time} - return kwargs_data
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/SimulationAPI/model_api.html b/docs/_build/html/_modules/lenstronomy/SimulationAPI/model_api.html deleted file mode 100644 index f4caedd0c..000000000 --- a/docs/_build/html/_modules/lenstronomy/SimulationAPI/model_api.html +++ /dev/null @@ -1,220 +0,0 @@ - - - - - - - - lenstronomy.SimulationAPI.model_api — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.SimulationAPI.model_api

-from lenstronomy.LensModel.lens_model import LensModel
-from lenstronomy.LightModel.light_model import LightModel
-from lenstronomy.PointSource.point_source import PointSource
-from astropy.cosmology import default_cosmology
-from lenstronomy.Cosmo.lens_cosmo import LensCosmo
-
-import copy
-
-__all__ = ['ModelAPI']
-
-
-
[docs]class ModelAPI(object): - """ - This class manages the model choices. The role is to return instances of the lenstronomy LightModel, LensModel, - PointSource modules according to the options chosen by the user. - Currently, all other model choices are equivalent to the ones provided by LightModel, LensModel, PointSource. - The current options of the class instance only describe a subset of possibilities. - """ - def __init__(self, lens_model_list=None, z_lens=None, z_source=None, lens_redshift_list=None, - source_light_model_list=None, lens_light_model_list=None, point_source_model_list=None, - source_redshift_list=None, cosmo=None, z_source_convention=None): - """ - - :param lens_model_list: list of strings with lens model names - :param z_lens: redshift of the deflector (only considered when operating in single plane mode). - Is only needed for specific functions that require a cosmology. - :param z_source: redshift of the source: Needed in multi_plane option only, - not required for the core functionalities in the single plane mode. This will be the redshift of the source - plane (if not further specified the 'source_redshift_list') and the point source redshift - (regardless of 'source_redshift_list') - :param lens_redshift_list: list of deflector redshift (corresponding to the lens model list), - only applicable in multi_plane mode. - :param source_light_model_list: list of strings with source light model names (lensed light profiles) - :param lens_light_model_list: list of strings with lens light model names (not lensed light profiles) - :param point_source_model_list: list of strings with point source model names - :param source_redshift_list: list of redshifts of the source profiles (optional) - :param cosmo: instance of the astropy cosmology class. If not specified, uses the default cosmology. - :param z_source_convention: float, redshift of a source to define the reduced deflection angles of the lens - models. If None, 'z_source' is used. - """ - if lens_model_list is None: - lens_model_list = [] - if source_light_model_list is None: - source_light_model_list = [] - if lens_light_model_list is None: - lens_light_model_list = [] - if point_source_model_list is None: - point_source_model_list = [] - if cosmo is None: - cosmo = default_cosmology.get() - if lens_redshift_list is not None or source_redshift_list is not None: - multi_plane = True - else: - multi_plane = False - if z_source_convention is None: - z_source_convention = z_source - - self._lens_model_class = LensModel(lens_model_list=lens_model_list, z_source=z_source, z_lens=z_lens, - lens_redshift_list=lens_redshift_list, multi_plane=multi_plane, cosmo=cosmo, - z_source_convention=z_source_convention) - self._source_model_class = LightModel(light_model_list=source_light_model_list, - source_redshift_list=source_redshift_list) - self._lens_light_model_class = LightModel(light_model_list=lens_light_model_list) - fixed_magnification = [False] * len(point_source_model_list) - for i, ps_type in enumerate(point_source_model_list): - if ps_type == 'SOURCE_POSITION': - fixed_magnification[i] = True - self._point_source_model_class = PointSource(point_source_type_list=point_source_model_list, - lensModel=self._lens_model_class, - fixed_magnification_list=fixed_magnification) - self._cosmo = cosmo - self._z_source_convention = z_source_convention - self._lens_redshift_list = lens_redshift_list - self._z_lens = z_lens - - @property - def lens_model_class(self): - """ - - :return: instance of lenstronomy LensModel class - """ - return self._lens_model_class - - @property - def lens_light_model_class(self): - """ - - :return: instance of lenstronomy LightModel class describing the non-lensed light profiles - """ - return self._lens_light_model_class - - @property - def source_model_class(self): - """ - - :return: instance of lenstronomy LightModel class describing the source light profiles - """ - return self._source_model_class - - @property - def point_source_model_class(self): - """ - - :return: instance of lenstronomy PointSource class describing the point sources (lensed and unlensed) - """ - return self._point_source_model_class - -
[docs] def physical2lensing_conversion(self, kwargs_mass): - """ - - :param kwargs_mass: list of keyword arguments of all the lens models. Einstein radius 'theta_E' are replaced by - 'sigma_v', velocity dispersion in km/s, 'alpha_Rs' and 'Rs' of NFW profiles are replaced by 'M200' and - 'concentration' - :return: kwargs_lens in reduced deflection angles compatible with the lensModel instance of this module - """ - kwargs_lens = copy.deepcopy(kwargs_mass) - for i in range(len(kwargs_mass)): - kwargs_mass_i = kwargs_mass[i] - if self._lens_redshift_list is None: - z_lens = self._z_lens - else: - z_lens = self._lens_redshift_list[i] - lens_cosmo = LensCosmo(z_lens, self._z_source_convention, cosmo=self._cosmo) - - if 'sigma_v' in kwargs_mass_i: - sigma_v = kwargs_mass_i['sigma_v'] - theta_E = lens_cosmo.sis_sigma_v2theta_E(sigma_v) - kwargs_lens[i]['theta_E'] = theta_E - del kwargs_lens[i]['sigma_v'] - elif 'M200' in kwargs_mass_i: - M200 = kwargs_mass_i['M200'] - c = kwargs_mass_i['concentration'] - Rs, alpha_RS = lens_cosmo.nfw_physical2angle(M200, c) - kwargs_lens[i]['Rs'] = Rs - kwargs_lens[i]['alpha_Rs'] = alpha_RS - del kwargs_lens[i]['M200'] - del kwargs_lens[i]['concentration'] - return kwargs_lens
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/SimulationAPI/observation_api.html b/docs/_build/html/_modules/lenstronomy/SimulationAPI/observation_api.html deleted file mode 100644 index 4f7f7a724..000000000 --- a/docs/_build/html/_modules/lenstronomy/SimulationAPI/observation_api.html +++ /dev/null @@ -1,369 +0,0 @@ - - - - - - - - lenstronomy.SimulationAPI.observation_api — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.SimulationAPI.observation_api

-import numpy as np
-import warnings
-import lenstronomy.Util.data_util as data_util
-from lenstronomy.Data.psf import PSF
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -class Instrument(object): - """ - basic access points to instrument properties - """ - def __init__(self, pixel_scale, read_noise=None, ccd_gain=None): - """ - - :param read_noise: std of noise generated by read-out (in units of electrons) - :param pixel_scale: scale (in arcseconds) of pixels - :param ccd_gain: electrons/ADU (analog-to-digital unit). - A gain of 8 means that the camera digitizes the CCD signal - so that each ADU corresponds to 8 photoelectrons. - """ - if ccd_gain is not None: - ccd_gain = float(ccd_gain) - self.ccd_gain = ccd_gain - self._read_noise = read_noise - self.pixel_scale = pixel_scale
- - -
[docs]@export -class Observation(object): - """ - basic access point to observation properties - """ - def __init__(self, exposure_time, sky_brightness=None, seeing=None, num_exposures=1, - psf_type='GAUSSIAN', kernel_point_source=None, truncation=5, point_source_supersampling_factor=1): - """ - - :param exposure_time: exposure time per image (in seconds) - :param sky_brightness: sky brightness (in magnitude per square arcseconds) - :param seeing: full width at half maximum of the PSF (if not specific psf_model is specified) - :param num_exposures: number of exposures that are combined - :param psf_type: string, type of PSF ('GAUSSIAN' and 'PIXEL' supported) - :param kernel_point_source: 2d numpy array, model of PSF centered with odd number of pixels per axis - (optional when psf_type='PIXEL' is chosen) - :param point_source_supersampling_factor: int, supersampling factor of kernel_point_source - (optional when psf_type='PIXEL' is chosen) - """ - self._exposure_time = exposure_time - self._sky_brightness_ = sky_brightness - self._num_exposures = num_exposures - self._seeing = seeing - self._psf_type = psf_type - self._truncation = truncation - self._kernel_point_source = kernel_point_source - self._point_source_supersampling_factor = point_source_supersampling_factor - -
[docs] def update_observation(self, exposure_time=None, sky_brightness=None, seeing=None, num_exposures=None, - psf_type=None, kernel_point_source=None): - """ - updates class instance with new properties if specific argument is not None - - :param exposure_time: exposure time per image (in seconds) - :param sky_brightness: sky brightness (in magnitude per square arcseconds) - :param seeing: full width at half maximum of the PSF (if not specific psf_model is specified) - :param num_exposures: number of exposures that are combined - :param psf_type: string, type of PSF ('GAUSSIAN' and 'PIXEL' supported) - :param kernel_point_source: 2d numpy array, model of PSF centered with odd number of pixels per axis - (optional when psf_type='PIXEL' is chosen) - :return: None, updated class instance - """ - if exposure_time is not None: - self._exposure_time = exposure_time - if sky_brightness is not None: - self._sky_brightness_ = sky_brightness - if seeing is not None: - self._seeing = seeing - if num_exposures is not None: - self._num_exposures = num_exposures - if psf_type is not None: - self._psf_type = psf_type - if kernel_point_source is not None: - self._kernel_point_source = kernel_point_source
- - @property - def _sky_brightness(self): - if self._sky_brightness_ is None: - raise ValueError('sky_brightness is not set in the class instance!') - return self._sky_brightness_ - - @property - def exposure_time(self): - """ - total exposure time - - :return: summed exposure time - """ - return self._exposure_time * self._num_exposures - - @property - def psf_class(self): - """ - creates instance of PSF() class based on knowledge of the observations - For the full possibility of how to create such an instance, see the PSF() class documentation - - :return: instance of PSF() class - """ - if self._psf_type == 'GAUSSIAN': - psf_type = "GAUSSIAN" - fwhm = self._seeing - truncation = self._truncation - kwargs_psf = {'psf_type': psf_type, 'fwhm': fwhm, 'truncation': truncation} - elif self._psf_type == 'PIXEL': - if self._kernel_point_source is not None: - kwargs_psf = {'psf_type': "PIXEL", 'kernel_point_source': self._kernel_point_source, - 'point_source_supersampling_factor': self._point_source_supersampling_factor} - else: - raise ValueError("You need to create the class instance with a psf_model!") - elif self._psf_type == 'NONE': - kwargs_psf = {'psf_type': "NONE"} - else: - raise ValueError("psf_type %s not supported!" % self._psf_type) - psf_class = PSF(**kwargs_psf) - return psf_class
- - -
[docs]@export -class SingleBand(Instrument, Observation): - """ - class that combines Instrument and Observation - """ - def __init__(self, pixel_scale, exposure_time, magnitude_zero_point, read_noise=None, ccd_gain=None, - sky_brightness=None, seeing=None, num_exposures=1, psf_type='GAUSSIAN', kernel_point_source=None, - truncation=5, point_source_supersampling_factor=1, data_count_unit='e-', background_noise=None): - """ - - :param read_noise: std of noise generated by read-out (in units of electrons) - :param pixel_scale: scale (in arcseconds) of pixels - :param ccd_gain: electrons/ADU (analog-to-digital unit). - A gain of 8 means that the camera digitizes the CCD signal - so that each ADU corresponds to 8 photoelectrons. - :param exposure_time: exposure time per image (in seconds) - :param sky_brightness: sky brightness (in magnitude per square arcseconds in units of electrons) - :param seeing: Full-Width-at-Half-Maximum (FWHM) of PSF - :param magnitude_zero_point: magnitude in which 1 count (e-) per second per arcsecond square is registered - :param num_exposures: number of exposures that are combined - :param point_source_supersampling_factor: int, supersampling factor of kernel_point_source - (optional when psf_type='PIXEL' is chosen) - :param data_count_unit: string, unit of the data (not noise properties - see other definitions), - 'e-': (electrons assumed to be IID), - 'ADU': (analog-to-digital unit) - :param background_noise: sqrt(variance of background) as a total contribution from readnoise, - sky brightness etc in units of the data_count_units (e- or ADU) - If you set this parameter, it will use this value regardless of the values of read_noise, sky_brightness - """ - Instrument.__init__(self, pixel_scale, read_noise, ccd_gain) # read_noise and ccd_gain can be None - Observation.__init__(self, exposure_time=exposure_time, sky_brightness=sky_brightness, - seeing=seeing, num_exposures=num_exposures, - psf_type=psf_type, kernel_point_source=kernel_point_source, - point_source_supersampling_factor=point_source_supersampling_factor, - truncation=truncation) - if data_count_unit not in ['e-', 'ADU']: - raise ValueError("count_unit type %s not supported! Please choose e- or ADU." % data_count_unit) - self._data_count_unit = data_count_unit - self._background_noise = background_noise - self._magnitude_zero_point = magnitude_zero_point - - @property - def sky_brightness(self): - """ - - :return: sky brightness (counts per square arcseconds in unit of data (e- or ADU's) per unit time) - """ - cps = self._sky_brightness_cps - if self._data_count_unit == 'ADU': - cps /= self.ccd_gain - return cps - - @property - def _sky_brightness_cps(self): - """ - - :return: sky brightness in electrons per second - """ - cps = data_util.magnitude2cps(self._sky_brightness, magnitude_zero_point=self._magnitude_zero_point) - return cps - - @property - def background_noise(self): - """ - Gaussian sigma of noise level per pixel in counts (e- or ADU) per second - - :return: sqrt(variance) of background noise level in data units - """ - if self._background_noise is None: - if self._read_noise is None: - raise ValueError('read_noise is not specified to evaluate background noise!') - bkg_noise = data_util.bkg_noise(self._read_noise, self._exposure_time, self._sky_brightness_cps, - self.pixel_scale, num_exposures=self._num_exposures) - if self._data_count_unit == 'ADU': - bkg_noise /= self.ccd_gain - return bkg_noise - else: - if self._read_noise is not None: - warnings.warn('read noise is specified but not used for noise properties. background noise is estimated' - ' from "background_noise" argument') - return self._background_noise - -
[docs] def flux_noise(self, flux): - """ - - :param flux: float or array, units of count_unit/seconds, needs to be positive semi-definite in the flux value - :return: Gaussian approximation of Poisson statistics in IIDs sqrt(variance) - """ - flux_iid = self.flux_iid(flux) - variance = flux_iid # the variance of a Poisson distribution is the IID count number - if isinstance(variance, int) or isinstance(variance, float): - variance = max(variance, 0) - else: - variance[flux_iid < 0] = 0 # make sure negative pixels do not lead to variances (or nans) in the return - noise = np.sqrt(variance) / self.exposure_time - if self._data_count_unit == 'ADU': - noise /= self.ccd_gain - return noise
- -
[docs] def flux_iid(self, flux_per_second): - """ - IID counts. This can be used by lenstronomy to estimate the Poisson errors - keeping the assumption that the counts are IIDs (even if they are not). - - :param flux_per_second: flux count per second in the units set in this class (ADU or e-) - :return: IID count number - """ - if self._data_count_unit == 'ADU': - exp_time = self.ccd_gain * self.exposure_time - else: - exp_time = self.exposure_time - return exp_time * flux_per_second
- -
[docs] def noise_for_model(self, model, background_noise=True, poisson_noise=True, seed=None): - """ - - :param model: 2d numpy array of modelled image (with pixels in units of data specified in class) - :param background_noise: bool, if True, adds background noise - :param poisson_noise: bool, if True, adds Poisson noise of modelled flux - :param seed: int, seed number to be used to render the noise properties. - If None, then uses the current numpy.random seed to render the noise properties. - :return: noise realization corresponding to the model - """ - if seed is not None: - g = np.random.RandomState(seed=seed) - else: - g = np.random - nx, ny = np.shape(model) - noise = np.zeros_like(model) - if background_noise is True: - noise += g.randn(nx, ny) * self.background_noise - if poisson_noise is True: - noise += g.randn(nx, ny) * self.flux_noise(model) - return noise
- -
[docs] def estimate_noise(self, image): - """ - - :param image: noisy data, background subtracted - :return: estimated noise map sqrt(variance) for each pixel as estimated from the instrument and observation - """ - return np.sqrt(self.background_noise**2 + self.flux_noise(image)**2)
- -
[docs] def magnitude2cps(self, magnitude): - """ - converts an apparent magnitude to counts per second (in units of the data) - - The zero point of an instrument, by definition, is the magnitude of an object that produces one count - (or data number, DN) per second. The magnitude of an arbitrary object producing DN counts in an observation of - length EXPTIME is therefore: - m = -2.5 x log10(DN / EXPTIME) + ZEROPOINT - - :param magnitude: magnitude of object - :return: counts per second of object - """ - # compute counts in units of ADS (as magnitude zero point is defined) - cps = data_util.magnitude2cps(magnitude, magnitude_zero_point=self._magnitude_zero_point) - if self._data_count_unit == 'ADU': - cps /= self.ccd_gain - return cps
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/SimulationAPI/observation_constructor.html b/docs/_build/html/_modules/lenstronomy/SimulationAPI/observation_constructor.html deleted file mode 100644 index fa6eff37a..000000000 --- a/docs/_build/html/_modules/lenstronomy/SimulationAPI/observation_constructor.html +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - lenstronomy.SimulationAPI.observation_constructor — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.SimulationAPI.observation_constructor

-import lenstronomy.Util.util as util
-
-
-instrument_name_list = ['LSST']
-observation_name_list = ['LSST_g_band', 'LSST_r_band', 'LSST_i_band']
-
-__all__ = ['observation_constructor']
-
-
-
[docs]def observation_constructor(instrument_name, observation_name): - """ - - :param instrument_name: string, name of instrument referenced in this file - :param observation_name: string, name of observation referenced in this file - :return: instance of the SimulationAPI.data_type instance - """ - - if instrument_name == 'LSST': - kwargs_instrument = LSST_camera - else: - raise ValueError("instrument name %s not supported! Choose among %s" % (instrument_name, instrument_name_list)) - - if observation_name == 'LSST_g_band': - kwargs_observation = LSST_g_band_obs - elif observation_name == 'LSST_r_band': - kwargs_observation = LSST_r_band_obs - elif observation_name == 'LSST_i_band': - kwargs_observation = LSST_i_band_obs - else: - raise ValueError('observation name %s not supported! Choose among %s' % - (observation_name, observation_name_list)) - kwargs_data = util.merge_dicts(kwargs_instrument, kwargs_observation) - return kwargs_data
- - -LSST_camera = {'read_noise': 10, - 'pixel_scale': 0.263, - 'ccd_gain': 4.5} - -LSST_g_band_obs = {'exposure_time': 90., - 'sky_brightness': 21.7, - 'magnitude_zero_point': 30, - 'num_exposures': 10, - 'seeing': 0.9, - 'psf_type': 'GAUSSIAN'} - -LSST_r_band_obs = {'exposure_time': 90., - 'sky_brightness': 20.7, - 'magnitude_zero_point': 30, - 'num_exposures': 10, - 'seeing': 0.9, - 'psf_type': 'GAUSSIAN'} - -LSST_i_band_obs = {'exposure_time': 90., - 'sky_brightness': 20.1, - 'magnitude_zero_point': 30, - 'num_exposures': 10, - 'seeing': 0.9, - 'psf_type': 'GAUSSIAN'} -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/SimulationAPI/point_source_variability.html b/docs/_build/html/_modules/lenstronomy/SimulationAPI/point_source_variability.html deleted file mode 100644 index 4947319de..000000000 --- a/docs/_build/html/_modules/lenstronomy/SimulationAPI/point_source_variability.html +++ /dev/null @@ -1,190 +0,0 @@ - - - - - - - - lenstronomy.SimulationAPI.point_source_variability — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.SimulationAPI.point_source_variability

-from lenstronomy.LensModel.Solver.lens_equation_solver import LensEquationSolver
-from lenstronomy.SimulationAPI.sim_api import SimAPI
-
-import numpy as np
-
-__all__ = ['PointSourceVariability']
-
-
-
[docs]class PointSourceVariability(object): - """ - This class enables to plug in a variable point source in the source plane to be added on top of a fixed lens and - extended surface brightness model. The class inherits SimAPI and additionally requires the lens and light model - parameters as well as a position in the source plane. - - The intrinsic source variability can be defined by the user and additional uncorrelated variability in the image - plane can be plugged in as well (e.g. due to micro-lensing) - """ - - def __init__(self, source_x, source_y, variability_func, numpix, kwargs_single_band, kwargs_model, kwargs_numerics, - kwargs_lens, kwargs_source_mag=None, kwargs_lens_light_mag=None, kwargs_ps_mag=None): - """ - - :param source_x: RA of source position - :param source_y: DEC of source position - :param variability_func: function that returns a brightness (in magnitude) as a function of time t - :param numpix: number of pixels per axis - :param kwargs_single_band: - :param kwargs_model: - :param kwargs_numerics: - :param kwargs_lens: - :param kwargs_source_mag: - :param kwargs_lens_light_mag: - :param kwargs_ps_mag: - """ - - # create background SimAPI class instance - sim_api_bkg = SimAPI(numpix, kwargs_single_band, kwargs_model) - image_model_bkg = sim_api_bkg.image_model_class(kwargs_numerics) - kwargs_lens_light, kwargs_source, kwargs_ps = sim_api_bkg.magnitude2amplitude(kwargs_lens_light_mag, - kwargs_source_mag, - kwargs_ps_mag) - self._image_bkg = image_model_bkg.image(kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps) - # compute image positions of point source - x_center, y_center = sim_api_bkg.data_class.center - search_window = np.max(sim_api_bkg.data_class.width) - lensModel = image_model_bkg.LensModel - solver = LensEquationSolver(lensModel=lensModel) - image_x, image_y = solver.image_position_from_source(source_x, source_y, kwargs_lens, min_distance=0.1, - search_window=search_window, precision_limit=10**(-10), - num_iter_max=100, arrival_time_sort=True, - x_center=x_center, y_center=y_center) - mag = lensModel.magnification(image_x, image_y, kwargs_lens) - dt_days = lensModel.arrival_time(image_x, image_y, kwargs_lens) - dt_days -= np.min(dt_days) # shift the arrival times such that the first image arrives at t=0 and the other - # times at t>=0 - # add image plane source model - kwargs_model_ps = {'point_source_model_list': ['LENSED_POSITION']} - self.sim_api_ps = SimAPI(numpix, kwargs_single_band, kwargs_model_ps) - self._image_model_ps = self.sim_api_ps.image_model_class(kwargs_numerics) - self._kwargs_lens = kwargs_lens - self._dt_days = dt_days - self._mag = mag - self._image_x, self._image_y = image_x, image_y - self._variability_func = variability_func - # save the computed image position of the lensed point source in cache such that the solving the lens equation - # only needs to be applied once. - # self.sim_api_bkg.reset_point_source_cache(bool=True) - # self.sim_api_ps.reset_point_source_cache(bool=True) - - @property - def delays(self): - """ - - :return: time delays - """ - return self._dt_days - - @property - def image_bkg(self): - """ - - :return: 2d numpy array, image of the extended light components without the variable source - """ - return self._image_bkg - -
[docs] def image_time(self, time=0): - """ - - :param time: time relative to the definition of t=0 for the first appearing image - :return: image with time variable source at given time - """ - kwargs_ps_time = self.point_source_time(time) - point_source = self._image_model_ps.point_source(kwargs_ps_time, kwargs_lens=self._kwargs_lens) - return point_source + self.image_bkg
- -
[docs] def point_source_time(self, t): - """ - - :param t: time (in units of days) - :return: image plane parameters of the point source observed at t - """ - mag = np.zeros_like(self._dt_days) - kwargs_ps = [{'ra_image': self._image_x, 'dec_image': self._image_y}] - for i, dt in enumerate(self._dt_days): - t_i = -dt + t - mag[i] = self._variability_func(t_i) - kwargs_ps[0]['point_amp'] = self.sim_api_ps.magnitude2cps(mag) * np.abs(self._mag) - return kwargs_ps
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/SimulationAPI/sim_api.html b/docs/_build/html/_modules/lenstronomy/SimulationAPI/sim_api.html deleted file mode 100644 index b58fe7bfd..000000000 --- a/docs/_build/html/_modules/lenstronomy/SimulationAPI/sim_api.html +++ /dev/null @@ -1,169 +0,0 @@ - - - - - - - - lenstronomy.SimulationAPI.sim_api — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.SimulationAPI.sim_api

-from lenstronomy.SimulationAPI.data_api import DataAPI
-from lenstronomy.SimulationAPI.model_api import ModelAPI
-from lenstronomy.ImSim.image_model import ImageModel
-
-import copy
-import numpy as np
-
-__all__ = ['SimAPI']
-
-
-
[docs]class SimAPI(DataAPI, ModelAPI): - """ - This class manages the model parameters in regard of the data specified in SingleBand. In particular, - this API translates models specified in units of astronomical magnitudes into the amplitude parameters used in the - LightModel module of lenstronomy. - Optionally, this class can also handle inputs with cosmology dependent lensing quantities and translates them to - the optical quantities being used in the lenstronomy LensModel module. - All other model choices are equivalent to the ones provided by LightModel, LensModel, PointSource modules - """ - def __init__(self, numpix, kwargs_single_band, kwargs_model): - """ - - :param numpix: number of pixels per axis - :param kwargs_single_band: keyword arguments specifying the class instance of DataAPI - :param kwargs_model: keyword arguments specifying the class instance of ModelAPI - """ - DataAPI.__init__(self, numpix, **kwargs_single_band) - ModelAPI.__init__(self, **kwargs_model) - -
[docs] def image_model_class(self, kwargs_numerics=None): - """ - - :param kwargs_numerics: keyword arguments list of Numerics module - :return: instance of the ImageModel class with all the specified configurations - """ - return ImageModel(self.data_class, self.psf_class, self.lens_model_class, self.source_model_class, - self.lens_light_model_class, self.point_source_model_class, kwargs_numerics=kwargs_numerics)
- -
[docs] def magnitude2amplitude(self, kwargs_lens_light_mag=None, kwargs_source_mag=None, kwargs_ps_mag=None): - """ - 'magnitude' definition are in APPARENT magnitudes as observed on the sky, not intrinsic! - - :param kwargs_lens_light_mag: keyword argument list as for LightModel module except that 'amp' parameters are - 'magnitude' parameters. - :param kwargs_source_mag: keyword argument list as for LightModel module except that 'amp' parameters are - 'magnitude' parameters. - :param kwargs_ps_mag: keyword argument list as for PointSource module except that 'amp' parameters are - 'magnitude' parameters. - :return: value of the lenstronomy 'amp' parameter such that the total flux of the profile type results in this - magnitude for all the light models. These keyword arguments conform with the lenstronomy LightModel syntax. - """ - - kwargs_lens_light = copy.deepcopy(kwargs_lens_light_mag) - if kwargs_lens_light_mag is not None: - for i, kwargs_mag in enumerate(kwargs_lens_light_mag): - kwargs_new = kwargs_lens_light[i] - del kwargs_new['magnitude'] - cps_norm = self.lens_light_model_class.total_flux(kwargs_list=kwargs_lens_light, norm=True, k=i)[0] - magnitude = kwargs_mag['magnitude'] - cps = self.magnitude2cps(magnitude) - amp = cps / cps_norm - kwargs_new['amp'] = amp - - kwargs_source = copy.deepcopy(kwargs_source_mag) - if kwargs_source_mag is not None: - for i, kwargs_mag in enumerate(kwargs_source_mag): - kwargs_new = kwargs_source[i] - del kwargs_new['magnitude'] - cps_norm = self.source_model_class.total_flux(kwargs_list=kwargs_source, norm=True, k=i)[0] - magnitude = kwargs_mag['magnitude'] - cps = self.magnitude2cps(magnitude) - amp = cps / cps_norm - kwargs_new['amp'] = amp - - kwargs_ps = copy.deepcopy(kwargs_ps_mag) - if kwargs_ps_mag is not None: - amp_list = [] - for i, kwargs_mag in enumerate(kwargs_ps_mag): - kwargs_new = kwargs_ps[i] - del kwargs_new['magnitude'] - cps_norm = 1 - magnitude = np.array(kwargs_mag['magnitude']) - cps = self.magnitude2cps(magnitude) - amp = cps / cps_norm - amp_list.append(amp) - kwargs_ps = self.point_source_model_class.set_amplitudes(amp_list, kwargs_ps) - return kwargs_lens_light, kwargs_source, kwargs_ps
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Util/analysis_util.html b/docs/_build/html/_modules/lenstronomy/Util/analysis_util.html deleted file mode 100644 index 946a1867d..000000000 --- a/docs/_build/html/_modules/lenstronomy/Util/analysis_util.html +++ /dev/null @@ -1,251 +0,0 @@ - - - - - - - - lenstronomy.Util.analysis_util — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Util.analysis_util

-import numpy as np
-import copy
-import lenstronomy.Util.mask_util as mask_util
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -def half_light_radius(lens_light, x_grid, y_grid, center_x=0, center_y=0): - """ - - :param lens_light: array of surface brightness - :param x_grid: x-axis coordinates - :param y_grid: y-axis coordinates - :param center_x: center of light - :param center_y: center of light - :return: - """ - lens_light[lens_light < 0] = 0 - total_flux_2 = np.sum(lens_light)/2. - r_max = np.max(np.sqrt((x_grid-center_x)**2 + (y_grid-center_y)**2)) - for i in range(1000): - r = i/500. * r_max - mask = mask_util.mask_azimuthal(x_grid, y_grid, center_x, center_y, r) - flux_enclosed = np.sum(np.array(lens_light)*mask) - if flux_enclosed > total_flux_2: - return r - return -1
- - -
[docs]@export -def radial_profile(light_grid, x_grid, y_grid, center_x=0, center_y=0, n=None): - """ - - :param light_grid: array of surface brightness - :param x_grid: x-axis coordinates - :param y_grid: y-axis coordinates - :param center_x: center of light - :param center_y: center of light - :param n: number of discrete steps - :return: - """ - r_max = np.max(np.sqrt((x_grid-center_x)**2 + (y_grid-center_y)**2)) - if n is None: - n = int(np.sqrt(len(x_grid))) - I_r = np.zeros(n) - I_enclosed = 0 - r = np.linspace(1./n*r_max, r_max, n) - for i, r_i in enumerate(r): - mask = mask_util.mask_azimuthal(x_grid, y_grid, center_x, center_y, r_i) - flux_enclosed = np.sum(np.array(light_grid)*mask) - I_r[i] = flux_enclosed - I_enclosed - I_enclosed = flux_enclosed - return I_r, r
- - -
[docs]@export -def azimuthalAverage(image, center=None): - """ - - Calculate the azimuthally averaged radial profile. - - image - The 2D image - center - The [x,y] pixel coordinates used as the center. The default is None, which then uses the center of the - image (including fractional pixels). - :return: I(r) (averaged), r of bin edges - """ - # Calculate the indices from the image - y, x = np.indices(image.shape) - - if not center: - center = np.array([(x.max()-x.min())/2.0, (x.max()-x.min())/2.0]) - - r = np.hypot(x - center[0], y - center[1]) - - # Get sorted radii - ind = np.argsort(r.flat) - r_sorted = r.flat[ind] - i_sorted = image.flat[ind] - - # Get the integer part of the radii (bin size = 1) - r_int = r_sorted.astype(int) - - # Find all pixels that fall within each radial bin. - deltar = r_int[1:] - r_int[:-1] # Assumes all radii represented - rind = np.where(deltar)[0] # location of changed radius - nr = rind[1:] - rind[:-1] # number of radius bin - - # Cumulative sum to figure out sums for each radius bin - csim = np.cumsum(i_sorted, dtype=float) - tbin = csim[rind[1:]] - csim[rind[:-1]] - r_bin = np.linspace(start=1, stop=len(tbin) + 1 - 0.5, num=len(tbin)) - radial_prof = tbin / nr - return radial_prof, r_bin
- - -
[docs]@export -def moments(I_xy_input, x, y): - """ - compute quadrupole moments from a light distribution - - :param I_xy_input: light distribution - :param x: x-coordinates of I_xy - :param y: y-coordinates of I_xy - :return: Q_xx, Q_xy, Q_yy - """ - I_xy = copy.deepcopy(I_xy_input) - background = np.minimum(0, np.min(I_xy)) - I_xy -= background - x_ = np.sum(I_xy * x) - y_ = np.sum(I_xy * y) - r = (np.max(x) - np.min(x)) / 3. - mask = mask_util.mask_azimuthal(x, y, center_x=x_, center_y=y_, r=r) - Q_xx = np.sum(I_xy * mask * (x - x_) ** 2) - Q_xy = np.sum(I_xy * mask * (x - x_) * (y - y_)) - Q_yy = np.sum(I_xy * mask * (y - y_) ** 2) - return Q_xx, Q_xy, Q_yy, background / np.mean(I_xy)
- - -
[docs]@export -def ellipticities(I_xy, x, y): - """ - compute ellipticities of a light distribution - - :param I_xy: - :param x: - :param y: - :return: - """ - Q_xx, Q_xy, Q_yy, bkg = moments(I_xy, x, y) - norm = Q_xx + Q_yy + 2 * np.sqrt(Q_xx*Q_yy - Q_xy**2) - e1 = (Q_xx - Q_yy) / norm - e2 = 2 * Q_xy / norm - return e1 / (1+bkg), e2 / (1+bkg)
- - -
[docs]@export -def bic_model(logL, num_data, num_param): - """ - Bayesian information criteria - - :param logL: log likelihood value - :param num_data: numbers of data - :param num_param: numbers of model parameters - :return: BIC value - """ - bic = -2 * logL + (np.log(num_data) * num_param) - return bic
- - -
[docs]@export -def profile_center(kwargs_list, center_x=None, center_y=None): - """ - utility routine that results in the centroid estimate for the profile estimates - - :param kwargs_list: light parameter keyword argument list (can be light or mass) - :param center_x: None or center - :param center_y: None or center - :return: center_x, center_y - """ - if center_x is None or center_y is None: - if 'center_x' in kwargs_list[0]: - center_x = kwargs_list[0]['center_x'] - center_y = kwargs_list[0]['center_y'] - else: - raise ValueError('The center has to be provided as a function argument or the first profile in the list' - ' must come with a center.') - return center_x, center_y
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Util/class_creator.html b/docs/_build/html/_modules/lenstronomy/Util/class_creator.html deleted file mode 100644 index 2ac54b640..000000000 --- a/docs/_build/html/_modules/lenstronomy/Util/class_creator.html +++ /dev/null @@ -1,293 +0,0 @@ - - - - - - - - lenstronomy.Util.class_creator — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Util.class_creator

-from lenstronomy.Data.imaging_data import ImageData
-from lenstronomy.Data.psf import PSF
-from lenstronomy.LensModel.lens_model import LensModel
-from lenstronomy.LightModel.light_model import LightModel
-from lenstronomy.PointSource.point_source import PointSource
-from lenstronomy.ImSim.differential_extinction import DifferentialExtinction
-from lenstronomy.ImSim.image_linear_solve import ImageLinearFit
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -def create_class_instances(lens_model_list=None, z_lens=None, z_source=None, z_source_convention=None, - lens_redshift_list=None, kwargs_interp=None, - multi_plane=False, observed_convention_index=None, source_light_model_list=None, - lens_light_model_list=None, point_source_model_list=None, fixed_magnification_list=None, - flux_from_point_source_list=None, - additional_images_list=None, kwargs_lens_eqn_solver=None, - source_deflection_scaling_list=None, source_redshift_list=None, cosmo=None, - index_lens_model_list=None, index_source_light_model_list=None, - index_lens_light_model_list=None, index_point_source_model_list=None, - optical_depth_model_list=None, index_optical_depth_model_list=None, - band_index=0, tau0_index_list=None, all_models=False, point_source_magnification_limit=None, - surface_brightness_smoothing=0.001, sersic_major_axis=None): - """ - - :param lens_model_list: list of strings indicating the type of lens models - :param z_lens: redshift of the deflector (for single lens plane mode, but only relevant when computing physical quantities) - :param z_source: redshift of source (for single source plane mode, or for multiple source planes the redshift of the point source). In regard to this redshift the reduced deflection angles are defined in the lens model. - :param z_source_convention: float, redshift of a source to define the reduced deflection angles of the lens models. - If None, 'z_source' is used. - :param lens_redshift_list: - :param multi_plane: - :param kwargs_interp: interpolation keyword arguments specifying the numerics. - See description in the Interpolate() class. Only applicable for 'INTERPOL' and 'INTERPOL_SCALED' models. - :param observed_convention_index: - :param source_light_model_list: - :param lens_light_model_list: - :param point_source_model_list: - :param fixed_magnification_list: - :param flux_from_point_source_list: list of bools (optional), if set, will only return image positions - (for imaging modeling) for the subset of the point source lists that =True. This option enables to model - :param additional_images_list: - :param kwargs_lens_eqn_solver: keyword arguments specifying the numerical settings for the lens equation solver - see LensEquationSolver() class for details - :param source_deflection_scaling_list: List of floats for each source ligth model (optional, and only applicable - for single-plane lensing. The factors re-scale the reduced deflection angles described from the lens model. - =1 means identical source position as without this option. This option enables multiple source planes. - The geometric difference between the different source planes needs to be pre-computed and is cosmology dependent. - :param source_redshift_list: - :param cosmo: astropy.cosmology instance - :param index_lens_model_list: - :param index_source_light_model_list: - :param index_lens_light_model_list: - :param index_point_source_model_list: - :param optical_depth_model_list: list of strings indicating the optical depth model to compute (differential) extinctions from the source - :param index_optical_depth_model_list: - :param band_index: int, index of band to consider. Has an effect if only partial models are considered for a specific band - :param tau0_index_list: list of integers of the specific extinction scaling parameter tau0 for each band - :param all_models: bool, if True, will make class instances of all models ignoring potential keywords that are excluding specific models as indicated. - :param point_source_magnification_limit: float >0 or None, if set and additional images are computed, then it will cut the point sources computed to the limiting (absolute) magnification - :param surface_brightness_smoothing: float, smoothing scale of light profile (minimal distance to the center of a profile) - this can help to avoid inaccuracies in the very center of a cuspy light profile - :param sersic_major_axis: boolean or None, if True, uses the semi-major axis as the definition of the Sersic - half-light radius, if False, uses the product average of semi-major and semi-minor axis. If None, uses the - convention in the lenstronomy yaml setting (which by default is =False) - :return: - """ - if lens_model_list is None: - lens_model_list = [] - if lens_light_model_list is None: - lens_light_model_list = [] - if source_light_model_list is None: - source_light_model_list = [] - if point_source_model_list is None: - point_source_model_list = [] - - if index_lens_model_list is None or all_models is True: - lens_model_list_i = lens_model_list - lens_redshift_list_i = lens_redshift_list - observed_convention_index_i = observed_convention_index - else: - lens_model_list_i = [lens_model_list[k] for k in index_lens_model_list[band_index]] - if lens_redshift_list is not None: - lens_redshift_list_i = [lens_redshift_list[k] for k in index_lens_model_list[band_index]] - else: - lens_redshift_list_i = lens_redshift_list - if observed_convention_index is not None: - counter = 0 - observed_convention_index_i = [] - for k in index_lens_model_list[band_index]: - if k in observed_convention_index: - observed_convention_index_i.append(counter) - counter += 1 - else: - observed_convention_index_i = observed_convention_index - lens_model_class = LensModel(lens_model_list=lens_model_list_i, z_lens=z_lens, z_source=z_source, - z_source_convention=z_source_convention, - lens_redshift_list=lens_redshift_list_i, - multi_plane=multi_plane, cosmo=cosmo, - observed_convention_index=observed_convention_index_i, kwargs_interp=kwargs_interp) - - if index_source_light_model_list is None or all_models is True: - source_light_model_list_i = source_light_model_list - source_deflection_scaling_list_i = source_deflection_scaling_list - source_redshift_list_i = source_redshift_list - else: - source_light_model_list_i = [source_light_model_list[k] for k in index_source_light_model_list[band_index]] - if source_deflection_scaling_list is None: - source_deflection_scaling_list_i = source_deflection_scaling_list - else: - source_deflection_scaling_list_i = [source_deflection_scaling_list[k] for k in index_source_light_model_list[band_index]] - if source_redshift_list is None: - source_redshift_list_i = source_redshift_list - else: - source_redshift_list_i = [source_redshift_list[k] for k in index_source_light_model_list[band_index]] - source_model_class = LightModel(light_model_list=source_light_model_list_i, - deflection_scaling_list=source_deflection_scaling_list_i, - source_redshift_list=source_redshift_list_i, smoothing=surface_brightness_smoothing, - sersic_major_axis=sersic_major_axis) - - if index_lens_light_model_list is None or all_models is True: - lens_light_model_list_i = lens_light_model_list - else: - lens_light_model_list_i = [lens_light_model_list[k] for k in index_lens_light_model_list[band_index]] - lens_light_model_class = LightModel(light_model_list=lens_light_model_list_i, - smoothing=surface_brightness_smoothing, sersic_major_axis=sersic_major_axis) - - point_source_model_list_i = point_source_model_list - fixed_magnification_list_i = fixed_magnification_list - additional_images_list_i = additional_images_list - - if index_point_source_model_list is not None and not all_models: - point_source_model_list_i = [point_source_model_list[k] for k in index_point_source_model_list[band_index]] - if fixed_magnification_list is not None: - fixed_magnification_list_i = [fixed_magnification_list[k] for k in index_point_source_model_list[band_index]] - if additional_images_list is not None: - additional_images_list_i = [additional_images_list[k] for k in index_point_source_model_list[band_index]] - point_source_class = PointSource(point_source_type_list=point_source_model_list_i, lensModel=lens_model_class, - fixed_magnification_list=fixed_magnification_list_i, - flux_from_point_source_list=flux_from_point_source_list, - additional_images_list=additional_images_list_i, - magnification_limit=point_source_magnification_limit, - kwargs_lens_eqn_solver=kwargs_lens_eqn_solver) - if tau0_index_list is None: - tau0_index = 0 - else: - tau0_index = tau0_index_list[band_index] - if index_optical_depth_model_list is not None: - optical_depth_model_list_i = [optical_depth_model_list[k] for k in index_optical_depth_model_list[band_index]] - else: - optical_depth_model_list_i = optical_depth_model_list - extinction_class = DifferentialExtinction(optical_depth_model=optical_depth_model_list_i, tau0_index=tau0_index) - return lens_model_class, source_model_class, lens_light_model_class, point_source_class, extinction_class
- - -
[docs]@export -def create_image_model(kwargs_data, kwargs_psf, kwargs_numerics, kwargs_model, image_likelihood_mask=None): - """ - - :param kwargs_data: ImageData keyword arguments - :param kwargs_psf: PSF keyword arguments - :param kwargs_numerics: numerics keyword arguments for Numerics() class - :param kwargs_model: model keyword arguments - :param image_likelihood_mask: image likelihood mask - (same size as image_data with 1 indicating being evaluated and 0 being left out) - :return: ImageLinearFit() instance - """ - data_class = ImageData(**kwargs_data) - psf_class = PSF(**kwargs_psf) - lens_model_class, source_model_class, lens_light_model_class, point_source_class, extinction_class = create_class_instances(**kwargs_model) - imageModel = ImageLinearFit(data_class, psf_class, lens_model_class, source_model_class, lens_light_model_class, - point_source_class, extinction_class, kwargs_numerics, likelihood_mask=image_likelihood_mask) - return imageModel
- - -
[docs]@export -def create_im_sim(multi_band_list, multi_band_type, kwargs_model, bands_compute=None, image_likelihood_mask_list=None, - band_index=0, kwargs_pixelbased=None): - """ - - - :param multi_band_list: list of [[kwargs_data, kwargs_psf, kwargs_numerics], [], ..] - :param multi_band_type: string, option when having multiple imaging data sets modelled simultaneously. Options are: - - 'multi-linear': linear amplitudes are inferred on single data set - - 'linear-joint': linear amplitudes ae jointly inferred - - 'single-band': single band - :param kwargs_model: model keyword arguments - :param bands_compute: (optional), bool list to indicate which band to be included in the modeling - :param image_likelihood_mask_list: list of image likelihood mask - (same size as image_data with 1 indicating being evaluated and 0 being left out) - :param band_index: integer, index of the imaging band to model (only applied when using 'single-band' as option) - :param kwargs_pixelbased: keyword arguments with various settings related to the pixel-based solver (see SLITronomy documentation) - - :return: MultiBand class instance - """ - - if multi_band_type == 'multi-linear': - from lenstronomy.ImSim.MultiBand.multi_linear import MultiLinear - multiband = MultiLinear(multi_band_list, kwargs_model, compute_bool=bands_compute, likelihood_mask_list=image_likelihood_mask_list) - elif multi_band_type == 'joint-linear': - from lenstronomy.ImSim.MultiBand.joint_linear import JointLinear - multiband = JointLinear(multi_band_list, kwargs_model, compute_bool=bands_compute, likelihood_mask_list=image_likelihood_mask_list) - elif multi_band_type == 'single-band': - from lenstronomy.ImSim.MultiBand.single_band_multi_model import SingleBandMultiModel - multiband = SingleBandMultiModel(multi_band_list, kwargs_model, likelihood_mask_list=image_likelihood_mask_list, - band_index=band_index, kwargs_pixelbased=kwargs_pixelbased) - else: - raise ValueError("type %s is not supported!" % multi_band_type) - return multiband
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Util/constants.html b/docs/_build/html/_modules/lenstronomy/Util/constants.html deleted file mode 100644 index 5d8dd6572..000000000 --- a/docs/_build/html/_modules/lenstronomy/Util/constants.html +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - - - lenstronomy.Util.constants — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Util.constants

-__author__ = 'sibirrer'
-
-
-"""
-this class contains physical constants and conversion factors between units
-"""
-import numpy as np
-
-__all__ = ('G c M_sun M_earth AU Mpc day_s arcsec '
-           'a_ES F_ES delay_arcsec2days'.split())
-
-G = 6.67384*10**(-11)  # Gravitational constant [m^3 kg^-1 s^-2]
-c = 299792458  # [m/s]
-
-M_sun = 1.9891 * 10**30  # solar mass in [kg]
-M_earth = 5.9972 * 10**24  # Earth mass in [kg]
-AU = 1.495978707 * 10**11  # Distance Earth Sun (Astronomical unit) in [m]
-
-Mpc = 3.08567758 * 10**22  # Mpc in [m]
-day_s = 24 * 3600  # day in second
-arcsec = 2 * np.pi / 360 / 3600  # arc second in radian
-
-# derived quantities
-
-a_ES = G * M_sun / AU**2  # Earth-Sun acceleration
-F_ES = G * M_sun * M_earth / AU**2
-
-
-
[docs]def delay_arcsec2days(delay_arcsec, ddt): - """ - given a delay in arcsec^2 and a Delay distance, the delay is computed in days - - :param delay_arcsec: gravitational delay in units of arcsec^2 (e.g. Fermat potential) - :param ddt: Time delay distance (in units of Mpc) - :return: time-delay in units of days - """ - return ddt * Mpc / c * delay_arcsec / day_s * arcsec ** 2
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Util/correlation.html b/docs/_build/html/_modules/lenstronomy/Util/correlation.html deleted file mode 100644 index 4e019f037..000000000 --- a/docs/_build/html/_modules/lenstronomy/Util/correlation.html +++ /dev/null @@ -1,132 +0,0 @@ - - - - - - - - lenstronomy.Util.correlation — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Util.correlation

-__author__ = 'sibirrer'
-
-from scipy import fftpack
-import numpy as np
-import lenstronomy.Util.analysis_util as analysis_util
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -def correlation_2D(image): - """ - #TODO document normalization output in units - - :param image: 2d image - :return: 2d fourier transform - """ - # Take the fourier transform of the image. - f1 = fftpack.fft2(image) - - # Now shift the quadrants around so that low spatial frequencies are in - # the center of the 2D fourier transformed image. - f2 = fftpack.fftshift(f1) - return np.abs(f2)
- - -
[docs]@export -def power_spectrum_2d(image): - """ - - :param image: 2d numpy array - :return: 2d power spectrum in frequency units of the pixels - """ - nx, ny = np.shape(image) - corr2d = correlation_2D(image) - return (corr2d / nx / ny) ** 2
- - -
[docs]@export -def power_spectrum_1d(image): - """ - - :param image: 2d numpy array - :return: 1d radially averaged power spectrum of image in frequency units of pixels - """ - psd2D = power_spectrum_2d(image) - # Calculate the azimuthally averaged 1D power spectrum - psd1D, r = analysis_util.azimuthalAverage(psd2D) - return psd1D, r
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Util/data_util.html b/docs/_build/html/_modules/lenstronomy/Util/data_util.html deleted file mode 100644 index f550dbfe2..000000000 --- a/docs/_build/html/_modules/lenstronomy/Util/data_util.html +++ /dev/null @@ -1,187 +0,0 @@ - - - - - - - - lenstronomy.Util.data_util — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Util.data_util

-import numpy as np
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -def bkg_noise(readout_noise, exposure_time, sky_brightness, pixel_scale, num_exposures=1): - """ - computes the expected Gaussian background noise of a pixel in units of counts/second - - :param readout_noise: noise added per readout - :param exposure_time: exposure time per exposure (in seconds) - :param sky_brightness: counts per second per unit arcseconds square - :param pixel_scale: size of pixel in units arcseonds - :param num_exposures: number of exposures (with same exposure time) to be co-added - :return: estimated Gaussian noise sqrt(variance) - """ - exposure_time_tot = num_exposures * exposure_time - readout_noise_tot = num_exposures * readout_noise ** 2 # square of readout noise - sky_per_pixel = sky_brightness * pixel_scale ** 2 - sky_brightness_tot = exposure_time_tot * sky_per_pixel - sigma_bkg = np.sqrt(readout_noise_tot + sky_brightness_tot) / exposure_time_tot - return sigma_bkg
- - -
[docs]@export -def flux_noise(cps_pixel, exposure_time): - """ - computes the variance of the shot noise Gaussian approximation of Poisson noise term - - :param cps_pixel: counts per second of the intensity per pixel unit - :param exposure_time: total exposure time (in units seconds or equivalent unit as cps_pixel) - :return: sqrt(variance) of pixel value - """ - return cps_pixel / np.sqrt(exposure_time)
- - -
[docs]@export -def magnitude2cps(magnitude, magnitude_zero_point): - """ - converts an apparent magnitude to counts per second - - The zero point of an instrument, by definition, is the magnitude of an object that produces one count - (or data number, DN) per second. The magnitude of an arbitrary object producing DN counts in an observation of - length EXPTIME is therefore: - m = -2.5 x log10(DN / EXPTIME) + ZEROPOINT - - :param magnitude: astronomical magnitude - :param magnitude_zero_point: magnitude zero point (astronomical magnitude with 1 count per second) - :return: counts per second of astronomical object - """ - delta_m = magnitude - magnitude_zero_point - counts = 10**(-delta_m / 2.5) - return counts
- - -
[docs]@export -def cps2magnitude(cps, magnitude_zero_point): - """ - - :param cps: float, count-per-second - :param magnitude_zero_point: magnitude zero point - :return: magnitude for given counts - """ - delta_m = -np.log10(cps) * 2.5 - magnitude = delta_m + magnitude_zero_point - return magnitude
- - -
[docs]@export -def absolute2apparent_magnitude(absolute_magnitude, d_parsec): - """ - converts absolute to apparent magnitudes - - :param absolute_magnitude: absolute magnitude of object - :param d_parsec: distance to object in units parsec - :return: apparent magnitude - """ - m_apparent = 5.8 * (np.log10(d_parsec) - 1) + absolute_magnitude - return m_apparent
- - -
[docs]@export -def adu2electrons(adu, ccd_gain): - """ - converts analog-to-digital units into electron counts - - :param adu: counts in analog-to-digital unit - :param ccd_gain: CCD gain, meaning how many electrons are counted per unit ADU - :return: counts in electrons - """ - return adu * ccd_gain
- - -
[docs]@export -def electrons2adu(electrons, ccd_gain): - """ - converts electron counts into analog-to-digital unit - - :param electrons: number of electrons received on detector - :param ccd_gain: CCD gain, meaning how many electrons are counted per unit ADU - :return: adu value in Analog-to-digital units corresponding to electron count - """ - return electrons / ccd_gain
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Util/derivative_util.html b/docs/_build/html/_modules/lenstronomy/Util/derivative_util.html deleted file mode 100644 index 356f9b9c8..000000000 --- a/docs/_build/html/_modules/lenstronomy/Util/derivative_util.html +++ /dev/null @@ -1,257 +0,0 @@ - - - - - - - - lenstronomy.Util.derivative_util — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Util.derivative_util

-"""
-routines to compute derivatives of spherical functions
-"""
-import numpy as np
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -def d_r_dx(x, y): - """ - derivative of r with respect to x - :param x: - :param y: - :return: - """ - return x / np.sqrt(x**2 + y**2)
- - -
[docs]@export -def d_r_dy(x, y): - """ - differential dr/dy - - :param x: - :param y: - :return: - """ - return y / np.sqrt(x**2 + y**2)
- - -
[docs]@export -def d_r_dxx(x, y): - """ - second derivative dr/dxdx - :param x: - :param y: - :return: - """ - return y**2 / (x**2 + y**2)**(3./2)
- - -
[docs]@export -def d_r_dyy(x, y): - """ - second derivative dr/dxdx - :param x: - :param y: - :return: - """ - return x**2 / (x**2 + y**2)**(3./2)
- - -
[docs]@export -def d_r_dxy(x, y): - """ - second derivative dr/dxdx - :param x: - :param y: - :return: - """ - return -x * y / (x ** 2 + y ** 2) ** (3 / 2.)
- - -
[docs]@export -def d_phi_dx(x, y): - """ - angular derivative in respect to x when phi = arctan2(y, x) - - :param x: - :param y: - :return: - """ - return -y / (x**2 + y**2)
- - -
[docs]@export -def d_phi_dy(x, y): - """ - angular derivative in respect to y when phi = arctan2(y, x) - - :param x: - :param y: - :return: - """ - return x / (x**2 + y**2)
- - -
[docs]@export -def d_phi_dxx(x, y): - """ - second derivative of the orientation angle - - :param x: - :param y: - :return: - """ - return 2 * x * y / (x**2 + y**2)**2
- - -
[docs]@export -def d_phi_dyy(x, y): - """ - second derivative of the orientation angle in dydy - - :param x: - :param y: - :return: - """ - return -2 * x * y / (x ** 2 + y ** 2) ** 2
- - -
[docs]@export -def d_phi_dxy(x, y): - """ - second derivative of the orientation angle in dxdy - - :param x: - :param y: - :return: - """ - return (-x**2 + y**2) / (x ** 2 + y ** 2) ** 2
- - -
[docs]@export -def d_x_diffr_dx(x, y): - """ - derivative of d(x/r)/dx - equivalent to second order derivatives dr_dxx - - :param x: - :param y: - :return: - """ - return y**2 / (x**2 + y**2)**(3/2.)
- - -
[docs]@export -def d_y_diffr_dy(x, y): - """ - derivative of d(y/r)/dy - equivalent to second order derivatives dr_dyy - - :param x: - :param y: - :return: - """ - return x**2 / (x**2 + y**2)**(3/2.)
- - -
[docs]@export -def d_y_diffr_dx(x, y): - """ - derivative of d(y/r)/dx - equivalent to second order derivatives dr_dxy - - :param x: - :param y: - :return: - """ - return -x*y / (x**2 + y**2)**(3/2.)
- - -
[docs]@export -def d_x_diffr_dy(x, y): - """ - derivative of d(x/r)/dy - equivalent to second order derivatives dr_dyx - - :param x: - :param y: - :return: - """ - return -x*y / (x**2 + y**2)**(3/2.)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Util/image_util.html b/docs/_build/html/_modules/lenstronomy/Util/image_util.html deleted file mode 100644 index f8cfdf087..000000000 --- a/docs/_build/html/_modules/lenstronomy/Util/image_util.html +++ /dev/null @@ -1,420 +0,0 @@ - - - - - - - - lenstronomy.Util.image_util — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Util.image_util

-__author__ = 'sibirrer'
-
-import numpy as np
-from scipy import ndimage
-from scipy import interpolate
-from scipy.ndimage import interpolation as interp
-import copy
-import lenstronomy.Util.util as util
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -def add_layer2image(grid2d, x_pos, y_pos, kernel, order=1): - """ - adds a kernel on the grid2d image at position x_pos, y_pos with an interpolated subgrid pixel shift of order=order - :param grid2d: 2d pixel grid (i.e. image) - :param x_pos: x-position center (pixel coordinate) of the layer to be added - :param y_pos: y-position center (pixel coordinate) of the layer to be added - :param kernel: the layer to be added to the image - :param order: interpolation order for sub-pixel shift of the kernel to be added - :return: image with added layer, cut to original size - """ - - x_int = int(round(x_pos)) - y_int = int(round(y_pos)) - shift_x = x_int - x_pos - shift_y = y_int - y_pos - kernel_shifted = interp.shift(kernel, [-shift_y, -shift_x], order=order) - return add_layer2image_int(grid2d, x_int, y_int, kernel_shifted)
- - -
[docs]@export -def add_layer2image_int(grid2d, x_pos, y_pos, kernel): - """ - adds a kernel on the grid2d image at position x_pos, y_pos at integer positions of pixel - :param grid2d: 2d pixel grid (i.e. image) - :param x_pos: x-position center (pixel coordinate) of the layer to be added - :param y_pos: y-position center (pixel coordinate) of the layer to be added - :param kernel: the layer to be added to the image - :return: image with added layer - """ - nx, ny = np.shape(kernel) - if nx % 2 == 0: - raise ValueError("kernel needs odd numbers of pixels") - - num_x, num_y = np.shape(grid2d) - x_int = int(round(x_pos)) - y_int = int(round(y_pos)) - - k_x, k_y = np.shape(kernel) - k_l2_x = int((k_x - 1) / 2) - k_l2_y = int((k_y - 1) / 2) - - min_x = np.maximum(0, x_int-k_l2_x) - min_y = np.maximum(0, y_int-k_l2_y) - max_x = np.minimum(num_x, x_int+k_l2_x + 1) - max_y = np.minimum(num_y, y_int+k_l2_y + 1) - - min_xk = np.maximum(0, -x_int + k_l2_x) - min_yk = np.maximum(0, -y_int + k_l2_y) - max_xk = np.minimum(k_x, -x_int + k_l2_x + num_x) - max_yk = np.minimum(k_y, -y_int + k_l2_y + num_y) - if min_x >= max_x or min_y >= max_y or min_xk >= max_xk or min_yk >= max_yk or (max_x-min_x != max_xk-min_xk) or (max_y-min_y != max_yk-min_yk): - return grid2d - kernel_re_sized = kernel[min_yk:max_yk, min_xk:max_xk] - new = grid2d.copy() - new[min_y:max_y, min_x:max_x] += kernel_re_sized - return new
- - -
[docs]@export -def add_background(image, sigma_bkd): - """ - adds background noise to image - :param image: pixel values of image - :param sigma_bkd: background noise (sigma) - :return: a realisation of Gaussian noise of the same size as image - """ - nx, ny = np.shape(image) - background = np.random.randn(nx, ny) * sigma_bkd - return background
- - -
[docs]@export -def add_poisson(image, exp_time): - """ - adds a poison (or Gaussian) distributed noise with mean given by surface brightness - :param image: pixel values (photon counts per unit exposure time) - :param exp_time: exposure time - :return: Poisson noise realization of input image - """ - """ - adds a poison (or Gaussian) distributed noise with mean given by surface brightness - """ - - # Gaussian approximation for Poisson distribution, normalized to exposure time - sigma = np.sqrt(np.abs(image)/exp_time) - nx, ny = np.shape(image) - poisson = np.random.randn(nx, ny) * sigma - return poisson
- - -
[docs]@export -def rotateImage(img, angle): - """ - - querries scipy.ndimage.rotate routine - :param img: image to be rotated - :param angle: angle to be rotated (radian) - :return: rotated image - """ - imgR = ndimage.rotate(img, angle, reshape=False) - return imgR
- - -
[docs]@export -def re_size_array(x_in, y_in, input_values, x_out, y_out): - """ - resizes 2d array (i.e. image) to new coordinates. So far only works with square output aligned with coordinate axis. - :param x_in: - :param y_in: - :param input_values: - :param x_out: - :param y_out: - :return: - """ - interp_2d = interpolate.interp2d(x_in, y_in, input_values, kind='linear') - # interp_2d = scipy.interpolate.RectBivariateSpline(x_in, y_in, input_values, kx=1, ky=1) - out_values = interp_2d.__call__(x_out, y_out) - return out_values
- - -
[docs]@export -def symmetry_average(image, symmetry): - """ - symmetry averaged image - :param image: - :param symmetry: - :return: - """ - img_sym = np.zeros_like(image) - angle = 360./symmetry - for i in range(symmetry): - img_sym += rotateImage(image, angle*i) - img_sym /= symmetry - return img_sym
- - -
[docs]@export -def findOverlap(x_mins, y_mins, min_distance): - """ - finds overlapping solutions, deletes multiples and deletes non-solutions and if it is not a solution, deleted as well - """ - n = len(x_mins) - idex = [] - for i in range(n): - if i == 0: - pass - else: - for j in range(0, i): - if abs(x_mins[i] - x_mins[j] < min_distance and abs(y_mins[i] - y_mins[j]) < min_distance): - idex.append(i) - break - x_mins = np.delete(x_mins, idex, axis=0) - y_mins = np.delete(y_mins, idex, axis=0) - return x_mins, y_mins
- - -
[docs]@export -def coordInImage(x_coord, y_coord, num_pix, deltapix): - """ - checks whether image positions are within the pixel image in units of arcsec - if not: remove it - - :param imcoord: image coordinate (in units of angels) [[x,y,delta,magnification][...]] - :type imcoord: (n,4) numpy array - :returns: image positions within the pixel image - """ - idex = [] - min_ = -deltapix * num_pix / 2 - max_ = deltapix * num_pix / 2 - for i in range(len(x_coord)): # sum over image positions - if x_coord[i] < min_ or x_coord[i] > max_ or y_coord[i] < min_ or y_coord[i] > max_: - idex.append(i) - x_coord = np.delete(x_coord, idex, axis=0) - y_coord = np.delete(y_coord, idex, axis=0) - return x_coord, y_coord
- - -
[docs]@export -def re_size(image, factor=1): - """ - re-sizes image with nx x ny to nx/factor x ny/factor - - :param image: 2d image with shape (nx,ny) - :param factor: integer >=1 - :return: - """ - if factor < 1: - raise ValueError('scaling factor in re-sizing %s < 1' %factor) - elif factor == 1: - return image - f = int(factor) - nx, ny = np.shape(image) - if int(nx/f) == nx/f and int(ny/f) == ny/f: - small = image.reshape([int(nx/f), f, int(ny/f), f]).mean(3).mean(1) - return small - else: - raise ValueError("scaling with factor %s is not possible with grid size %s, %s" %(f, nx, ny))
- - -
[docs]@export -def rebin_image(bin_size, image, wht_map, sigma_bkg, ra_coords, dec_coords, idex_mask): - """ - re-bins pixels, updates cutout image, wht_map, sigma_bkg, coordinates, PSF - - :param bin_size: number of pixels (per axis) to merge - :return: - """ - numPix = int(len(image)/bin_size) - numPix_precut = numPix * bin_size - factor = int(len(image)/numPix) - if not numPix * bin_size == len(image): - image_precut = image[0:numPix_precut, 0:numPix_precut] - else: - image_precut = image - image_resized = re_size(image_precut, factor) - image_resized *= bin_size**2 - wht_map_resized = re_size(wht_map[0:numPix_precut, 0:numPix_precut], factor) - sigma_bkg_resized = bin_size*sigma_bkg - ra_coords_resized = re_size(ra_coords[0:numPix_precut, 0:numPix_precut], factor) - dec_coords_resized = re_size(dec_coords[0:numPix_precut, 0:numPix_precut], factor) - idex_mask_resized = re_size(idex_mask[0:numPix_precut, 0:numPix_precut], factor) - idex_mask_resized[idex_mask_resized > 0] = 1 - return image_resized, wht_map_resized, sigma_bkg_resized, ra_coords_resized, dec_coords_resized, idex_mask_resized
- - -
[docs]@export -def rebin_coord_transform(factor, x_at_radec_0, y_at_radec_0, Mpix2coord, Mcoord2pix): - """ - adopt coordinate system and transformation between angular and pixel coordinates of a re-binned image - :param bin_size: - :param ra_0: - :param dec_0: - :param x_0: - :param y_0: - :param Matrix: - :param Matrix_inv: - :return: - """ - factor = int(factor) - Mcoord2pix_resized = Mcoord2pix / factor - Mpix2coord_resized = Mpix2coord * factor - x_at_radec_0_resized = (x_at_radec_0 + 0.5) / factor - 0.5 - y_at_radec_0_resized = (y_at_radec_0 + 0.5) / factor - 0.5 - ra_at_xy_0_resized, dec_at_xy_0_resized = util.map_coord2pix(-x_at_radec_0_resized, -y_at_radec_0_resized, 0, 0, Mpix2coord_resized) - return ra_at_xy_0_resized, dec_at_xy_0_resized, x_at_radec_0_resized, y_at_radec_0_resized, Mpix2coord_resized, Mcoord2pix_resized
- - -
[docs]@export -def stack_images(image_list, wht_list, sigma_list): - """ - stacks images and saves new image as a fits file - :param image_name_list: list of image_names to be stacked - :return: - """ - image_stacked = np.zeros_like(image_list[0]) - wht_stacked = np.zeros_like(image_stacked) - sigma_stacked = 0. - for i in range(len(image_list)): - image_stacked += image_list[i]*wht_list[i] - sigma_stacked += sigma_list[i]**2 * np.median(wht_list[i]) - wht_stacked += wht_list[i] - image_stacked /= wht_stacked - sigma_stacked /= np.median(wht_stacked) - wht_stacked /= len(wht_list) - return image_stacked, wht_stacked, np.sqrt(sigma_stacked)
- - -
[docs]@export -def cut_edges(image, num_pix): - """ - cuts out the edges of a 2d image and returns re-sized image to numPix - center is well defined for odd pixel sizes. - :param image: 2d numpy array - :param num_pix: square size of cut out image - :return: cutout image with size numPix - """ - nx, ny = image.shape - if nx < num_pix or ny < num_pix: - raise ValueError('image can not be resized, in routine cut_edges with image shape (%s %s) ' - 'and desired new shape (%s %s)' % (nx, ny, num_pix, num_pix)) - if (nx % 2 == 0 and ny % 2 == 1) or (nx % 2 == 1 and ny % 2 == 0): - raise ValueError('image with odd and even axis (%s %s) not supported for re-sizeing' % (nx, ny)) - if (nx % 2 == 0 and num_pix % 2 == 1) or (nx % 2 == 1 and num_pix % 2 == 0): - raise ValueError('image can only be re-sized from even to even or odd to odd number.') - - x_min = int((nx - num_pix) / 2) - y_min = int((ny - num_pix) / 2) - x_max = nx - x_min - y_max = ny - y_min - resized = image[x_min:x_max, y_min:y_max] - return copy.deepcopy(resized)
- - -
[docs]@export -def radial_profile(data, center=None): - """ - computes radial profile - - :param data: 2d numpy array - :param center: center [x, y] from where to compute the radial profile - :return: radial profile (in units pixel) - """ - if center is None: - center = np.array([0, 0]) - y, x = np.indices(data.shape) - r = np.sqrt((x - center[0])**2 + (y - center[1])**2) - r = r.astype(int) - - tbin = np.bincount(r.ravel(), data.ravel()) - nr = np.bincount(r.ravel()) - radialprofile = tbin / nr - return radialprofile
- - -
[docs]@export -def gradient_map(image): - """ - computes gradients of images with the sobel transform - - :param image: 2d numpy array - :return: array of same size as input, with gradients between neighboring pixels - """ - from skimage import filters - return filters.sobel(image)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Util/kernel_util.html b/docs/_build/html/_modules/lenstronomy/Util/kernel_util.html deleted file mode 100644 index fa32e4cd6..000000000 --- a/docs/_build/html/_modules/lenstronomy/Util/kernel_util.html +++ /dev/null @@ -1,569 +0,0 @@ - - - - - - - - lenstronomy.Util.kernel_util — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Util.kernel_util

-"""
-routines that manipulate convolution kernels
-"""
-import numpy as np
-import copy
-import scipy.ndimage.interpolation as interp
-import lenstronomy.Util.util as util
-import lenstronomy.Util.image_util as image_util
-from lenstronomy.LightModel.Profiles.gaussian import Gaussian
-import lenstronomy.Util.multi_gauss_expansion as mge
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -def de_shift_kernel(kernel, shift_x, shift_y, iterations=20, fractional_step_size=1): - """ - de-shifts a shifted kernel to the center of a pixel. This is performed iteratively. - - The input kernel is the solution of a linear interpolated shift of a sharper kernel centered in the middle of the - pixel. To find the de-shifted kernel, we perform an iterative correction of proposed de-shifted kernels and compare - its shifted version with the input kernel. - - :param kernel: (shifted) kernel, e.g. a star in an image that is not centered in the pixel grid - :param shift_x: x-offset relative to the center of the pixel (sub-pixel shift) - :param shift_y: y-offset relative to the center of the pixel (sub-pixel shift) - :param iterations: number of repeated iterations of shifting a new de-shifted kernel and apply corrections - :param fractional_step_size: float (0, 1] correction factor relative to previous proposal (can be used for stability - :return: de-shifted kernel such that the interpolated shift boy (shift_x, shift_y) results in the input kernel - """ - nx, ny = np.shape(kernel) - kernel_new = np.zeros((nx+2, ny+2)) + (kernel[0, 0] + kernel[0, -1] + kernel[-1, 0] + kernel[-1, -1]) / 4. - kernel_new[1:-1, 1:-1] = kernel - int_shift_x = int(round(shift_x)) - frac_x_shift = shift_x - int_shift_x - int_shift_y = int(round(shift_y)) - frac_y_shift = shift_y - int_shift_y - kernel_init = copy.deepcopy(kernel_new) - kernel_init_shifted = copy.deepcopy(interp.shift(kernel_init, [int_shift_y, int_shift_x], order=1)) - kernel_new = interp.shift(kernel_new, [int_shift_y, int_shift_x], order=1) - norm = np.sum(kernel_init_shifted) - for i in range(iterations): - kernel_shifted_inv = interp.shift(kernel_new, [-frac_y_shift, -frac_x_shift], order=1) - delta = kernel_init_shifted - kernel_norm(kernel_shifted_inv) * norm - kernel_new += delta * fractional_step_size - kernel_new = kernel_norm(kernel_new) * norm - return kernel_new[1:-1, 1:-1]
- - -
[docs]@export -def center_kernel(kernel, iterations=20): - """ - given a kernel that might not be perfectly centered, this routine computes its light weighted center and then - moves the center in an iterative process such that it is centered - - :param kernel: 2d array (odd numbers) - :param iterations: int, number of iterations - :return: centered kernel - """ - kernel = kernel_norm(kernel) - nx, ny = np.shape(kernel) - if nx % 2 == 0: - raise ValueError("kernel needs odd number of pixels") - # make coordinate grid of kernel - x_grid, y_grid = util.make_grid(nx, deltapix=1, left_lower=False) - # compute 1st moments to get light weighted center - x_w = np.sum(kernel * util.array2image(x_grid)) - y_w = np.sum(kernel * util.array2image(y_grid)) - # de-shift kernel - kernel_centered = de_shift_kernel(kernel, shift_x=-x_w, shift_y=-y_w, iterations=iterations) - return kernel_norm(kernel_centered)
- - -
[docs]@export -def kernel_norm(kernel): - """ - - :param kernel: - :return: normalisation of the psf kernel - """ - norm = np.sum(np.array(kernel)) - kernel /= norm - return kernel
- - -
[docs]@export -def subgrid_kernel(kernel, subgrid_res, odd=False, num_iter=100): - """ - creates a higher resolution kernel with subgrid resolution as an interpolation of the original kernel in an - iterative approach - - :param kernel: initial kernel - :param subgrid_res: subgrid resolution required - :return: kernel with higher resolution (larger) - """ - subgrid_res = int(subgrid_res) - if subgrid_res == 1: - return kernel - nx, ny = np.shape(kernel) - d_x = 1. / nx - x_in = np.linspace(d_x/2, 1-d_x/2, nx) - d_y = 1. / nx - y_in = np.linspace(d_y/2, 1-d_y/2, ny) - nx_new = nx * subgrid_res - ny_new = ny * subgrid_res - if odd is True: - if nx_new % 2 == 0: - nx_new -= 1 - if ny_new % 2 == 0: - ny_new -= 1 - - d_x_new = 1. / nx_new - d_y_new = 1. / ny_new - x_out = np.linspace(d_x_new/2., 1-d_x_new/2., nx_new) - y_out = np.linspace(d_y_new/2., 1-d_y_new/2., ny_new) - kernel_input = copy.deepcopy(kernel) - kernel_subgrid = image_util.re_size_array(x_in, y_in, kernel_input, x_out, y_out) - kernel_subgrid = kernel_norm(kernel_subgrid) - for i in range(max(num_iter, 1)): - # given a proposition, re-size it to original pixel size - if subgrid_res % 2 == 0: - kernel_pixel = averaging_even_kernel(kernel_subgrid, subgrid_res) - else: - kernel_pixel = util.averaging(kernel_subgrid, numGrid=nx_new, numPix=nx) - delta = kernel - kernel_pixel - temp_kernel = kernel_input + delta - kernel_subgrid = image_util.re_size_array(x_in, y_in, temp_kernel, x_out, y_out)#/norm_subgrid - kernel_subgrid = kernel_norm(kernel_subgrid) - kernel_input = temp_kernel - - #from scipy.ndimage import zoom - - #ratio = subgrid_res - #kernel_subgrid = zoom(kernel, ratio, order=4) / ratio ** 2 - #print(np.shape(kernel_subgrid)) - # whatever has not been matched is added to zeroth order (in squares of the undersampled PSF) - if subgrid_res % 2 == 0: - return kernel_subgrid - kernel_pixel = util.averaging(kernel_subgrid, numGrid=nx_new, numPix=nx) - kernel_pixel = kernel_norm(kernel_pixel) - delta_kernel = kernel_pixel - kernel_norm(kernel) - id = np.ones((subgrid_res, subgrid_res)) - delta_kernel_sub = np.kron(delta_kernel, id)/subgrid_res**2 - return kernel_norm(kernel_subgrid - delta_kernel_sub)
- - -
[docs]@export -def averaging_even_kernel(kernel_high_res, subgrid_res): - """ - makes a lower resolution kernel based on the kernel_high_res (odd numbers) and the subgrid_res (even number), both - meant to be centered. - - :param kernel_high_res: high resolution kernel with even subsampling resolution, centered - :param subgrid_res: subsampling resolution (even number) - :return: averaged undersampling kernel - """ - n_kernel_high_res = len(kernel_high_res) - n_low = int(round(n_kernel_high_res / subgrid_res + 0.5)) - if n_low % 2 == 0: - n_low += 1 - n_high = int(n_low * subgrid_res - 1) - assert n_high % 2 == 1 - if n_high == n_kernel_high_res: - kernel_high_res_edges = kernel_high_res - else: - i_start = int((n_high - n_kernel_high_res) / 2) - kernel_high_res_edges = np.zeros((n_high, n_high)) - kernel_high_res_edges[i_start:-i_start, i_start:-i_start] = kernel_high_res - kernel_low_res = np.zeros((n_low, n_low)) - # adding pixels that are fully within a single re-binned pixel - for i in range(subgrid_res-1): - for j in range(subgrid_res-1): - kernel_low_res += kernel_high_res_edges[i::subgrid_res, j::subgrid_res] - # adding half of a pixel that has over-lap with two pixels - i = subgrid_res - 1 - for j in range(subgrid_res - 1): - kernel_low_res[1:, :] += kernel_high_res_edges[i::subgrid_res, j::subgrid_res] / 2 - kernel_low_res[:-1, :] += kernel_high_res_edges[i::subgrid_res, j::subgrid_res] / 2 - j = subgrid_res - 1 - for i in range(subgrid_res - 1): - kernel_low_res[:, 1:] += kernel_high_res_edges[i::subgrid_res, j::subgrid_res] / 2 - kernel_low_res[:, :-1] += kernel_high_res_edges[i::subgrid_res, j::subgrid_res] / 2 - # adding a quarter of a pixel value that is at the boarder of four pixels - i = subgrid_res - 1 - j = subgrid_res - 1 - kernel_edge = kernel_high_res_edges[i::subgrid_res, j::subgrid_res] - kernel_low_res[1:, 1:] += kernel_edge / 4 - kernel_low_res[:-1, 1:] += kernel_edge / 4 - kernel_low_res[1:, :-1] += kernel_edge / 4 - kernel_low_res[:-1, :-1] += kernel_edge / 4 - return kernel_low_res
- - -
[docs]@export -def kernel_pixelsize_change(kernel, deltaPix_in, deltaPix_out): - """ - change the pixel size of a given kernel - :param kernel: - :param deltaPix_in: - :param deltaPix_out: - :return: - """ - numPix = len(kernel) - numPix_new = int(round(numPix * deltaPix_in/deltaPix_out)) - if numPix_new % 2 == 0: - numPix_new -= 1 - x_in = np.linspace(-(numPix-1)/2*deltaPix_in, (numPix-1)/2*deltaPix_in, numPix) - x_out = np.linspace(-(numPix_new-1)/2*deltaPix_out, (numPix_new-1)/2*deltaPix_out, numPix_new) - kernel_out = image_util.re_size_array(x_in, x_in, kernel, x_out, x_out) - kernel_out = kernel_norm(kernel_out) - return kernel_out
- - -
[docs]@export -def cut_psf(psf_data, psf_size): - """ - cut the psf properly - :param psf_data: image of PSF - :param psf_size: size of psf - :return: re-sized and re-normalized PSF - """ - kernel = image_util.cut_edges(psf_data, psf_size) - kernel = kernel_norm(kernel) - return kernel
- - -
[docs]@export -def pixel_kernel(point_source_kernel, subgrid_res=7): - """ - converts a pixelised kernel of a point source to a kernel representing a uniform extended pixel - - :param point_source_kernel: - :param subgrid_res: - :return: convolution kernel for an extended pixel - """ - kernel_subgrid = subgrid_kernel(point_source_kernel, subgrid_res, num_iter=10) - kernel_size = len(point_source_kernel) - kernel_pixel = np.zeros((kernel_size*subgrid_res, kernel_size*subgrid_res)) - for i in range(subgrid_res): - k_x = int((kernel_size-1) / 2 * subgrid_res + i) - for j in range(subgrid_res): - k_y = int((kernel_size-1) / 2 * subgrid_res + j) - kernel_pixel = image_util.add_layer2image(kernel_pixel, k_x, k_y, kernel_subgrid) - kernel_pixel = util.averaging(kernel_pixel, numGrid=kernel_size*subgrid_res, numPix=kernel_size) - return kernel_norm(kernel_pixel)
- - -
[docs]@export -def kernel_average_pixel(kernel_super, supersampling_factor): - """ - computes the effective convolution kernel assuming a uniform surface brightness on the scale of a pixel - - :param kernel_super: supersampled PSF of a point source (odd number per axis - :param supersampling_factor: supersampling factor (int) - :return: - """ - kernel_sum = np.sum(kernel_super) - kernel_size = int(round(len(kernel_super)/float(supersampling_factor) + 0.5)) - if kernel_size % 2 == 0: - kernel_size += 1 - n_high = kernel_size*supersampling_factor - if n_high % 2 == 0: - n_high += 1 - kernel_pixel = np.zeros((n_high, n_high)) - for i in range(supersampling_factor): - k_x = int((kernel_size - 1) / 2 * supersampling_factor + i) - for j in range(supersampling_factor): - k_y = int((kernel_size - 1) / 2 * supersampling_factor + j) - kernel_pixel = image_util.add_layer2image(kernel_pixel, k_x, k_y, kernel_super) - - if supersampling_factor % 2 == 0: - kernel_pixel = averaging_even_kernel(kernel_pixel, supersampling_factor) - else: - kernel_pixel = util.averaging(kernel_pixel, numGrid=n_high, - numPix=kernel_size) - kernel_pixel /= np.sum(kernel_pixel) - return kernel_pixel * kernel_sum
- - -
[docs]@export -def kernel_gaussian(kernel_numPix, deltaPix, fwhm): - sigma = util.fwhm2sigma(fwhm) - #if kernel_numPix % 2 == 0: - # kernel_numPix += 1 - x_grid, y_grid = util.make_grid(kernel_numPix, deltaPix) - gaussian = Gaussian() - kernel = gaussian.function(x_grid, y_grid, amp=1., sigma=sigma, center_x=0, center_y=0) - kernel /= np.sum(kernel) - kernel = util.array2image(kernel) - return kernel
- - -
[docs]@export -def split_kernel(kernel_super, supersampling_kernel_size, supersampling_factor, normalized=True): - """ - pixel kernel and subsampling kernel such that the convolution of both applied on an image can be - performed, i.e. smaller subsampling PSF and hole in larger PSF - - :param kernel_super: super-sampled kernel - :param supersampling_kernel_size: size of super-sampled PSF in units of degraded pixels - :param normalized: boolean, if True returns a split kernel that is area normalized=1 representing a convolution kernel - :return: degraded kernel with hole and super-sampled kernel - """ - if supersampling_factor <= 1: - raise ValueError('To split a kernel, the supersampling_factor needs to be > 1, givn %s' %supersampling_factor) - if supersampling_kernel_size % 2 == 0: - raise ValueError('supersampling_kernel_size needs to be an odd number!') - n_super = len(kernel_super) - n_sub = supersampling_kernel_size * supersampling_factor - if n_sub % 2 == 0: - n_sub += 1 - if n_sub > n_super: - n_sub = n_super - - kernel_hole = copy.deepcopy(kernel_super) - n_min = int((n_super-1) / 2 - (n_sub - 1) / 2) - n_max = int((n_super-1) / 2 + (n_sub - 1) / 2 + 1) - kernel_hole[n_min:n_max, n_min:n_max] = 0 - kernel_hole_resized = degrade_kernel(kernel_hole, degrading_factor=supersampling_factor) - kernel_subgrid_cut = kernel_super[n_min:n_max, n_min:n_max] - if normalized is True: - flux_subsampled = np.sum(kernel_subgrid_cut) - flux_hole = np.sum(kernel_hole_resized) - if flux_hole > 0: - kernel_hole_resized *= (1. - flux_subsampled) / np.sum(kernel_hole_resized) - else: - kernel_subgrid_cut /= np.sum(kernel_subgrid_cut) - else: - kernel_hole_resized /= supersampling_factor ** 2 - return kernel_hole_resized, kernel_subgrid_cut
- - -
[docs]@export -def degrade_kernel(kernel_super, degrading_factor): - """ - - :param kernel_super: higher resolution kernel (odd number per axis) - :param degrading_factor: degrading factor (effectively the super-sampling resolution of the kernel given - :return: degraded kernel with odd axis number with the sum of the flux/values in the kernel being preserved - """ - if degrading_factor == 1: - return kernel_super - if degrading_factor % 2 == 0: - kernel_low_res = averaging_even_kernel(kernel_super, degrading_factor) - else: - n_kernel = len(kernel_super) - numPix = int(round(n_kernel / degrading_factor + 0.5)) - if numPix % 2 == 0: - numPix += 1 - n_high = numPix * degrading_factor - - kernel_super_ = np.zeros((n_high, n_high)) - i_start = int((n_high-n_kernel)/2) - kernel_super_[i_start:i_start+n_kernel, i_start:i_start+n_kernel] = kernel_super - kernel_low_res = util.averaging(kernel_super_, numGrid=n_high, numPix=numPix) * degrading_factor**2 # multiplicative factor added when providing flux conservation - return kernel_low_res
- - -
[docs]@export -def cutout_source(x_pos, y_pos, image, kernelsize, shift=True): - """ - cuts out point source (e.g. PSF estimate) out of image and shift it to the center of a pixel - :param x_pos: - :param y_pos: - :param image: - :param kernelsize: - :return: - """ - if kernelsize % 2 == 0: - raise ValueError("even pixel number kernel size not supported!") - x_int = int(round(x_pos)) - y_int = int(round(y_pos)) - n = len(image) - d = (kernelsize - 1)/2 - x_max = int(np.minimum(x_int + d + 1, n)) - x_min = int(np.maximum(x_int - d, 0)) - y_max = int(np.minimum(y_int + d + 1, n)) - y_min = int(np.maximum(y_int - d, 0)) - image_cut = copy.deepcopy(image[y_min:y_max, x_min:x_max]) - shift_x = x_int - x_pos - shift_y = y_int - y_pos - if shift is True: - kernel_shift = de_shift_kernel(image_cut, shift_x, shift_y, iterations=50) - else: - kernel_shift = image_cut - kernel_final = np.zeros((kernelsize, kernelsize)) - - k_l2_x = int((kernelsize - 1) / 2) - k_l2_y = int((kernelsize - 1) / 2) - - xk_min = np.maximum(0, -x_int + k_l2_x) - yk_min = np.maximum(0, -y_int + k_l2_y) - xk_max = np.minimum(kernelsize, -x_int + k_l2_x + n) - yk_max = np.minimum(kernelsize, -y_int + k_l2_y + n) - - kernel_final[yk_min:yk_max, xk_min:xk_max] = kernel_shift - return kernel_final
- - -
[docs]@export -def fwhm_kernel(kernel): - """ - - :param kernel: - :return: - """ - n = len(kernel) - center = (n - 1) / 2. - I_r = image_util.radial_profile(kernel, center=[center, center]) - if n % 2 == 0: - raise ValueError('only works with odd number of pixels in kernel!') - max_flux = kernel[int((n-1)/2), int((n-1)/2)] - I_2 = max_flux / 2. - r = np.linspace(0, (n - 1) / 2, int((n + 1) / 2)) + 0.33 - for i in range(1, len(I_r)): - if I_r[i] < I_2: - fwhm_2 = (I_2 - I_r[i - 1]) / (I_r[i] - I_r[i - 1]) + r[i - 1] - return fwhm_2 * 2 - raise ValueError('The kernel did not drop to half the max value - fwhm not determined!')
- - -
[docs]@export -def estimate_amp(data, x_pos, y_pos, psf_kernel): - """ - estimates the amplitude of a point source located at x_pos, y_pos - :param data: - :param x_pos: - :param y_pos: - :param psf_kernel: - :return: - """ - numPix_x, numPix_y = np.shape(data) - #data_center = int((numPix-1.)/2) - x_int = int(round(x_pos-0.49999))#+data_center - y_int = int(round(y_pos-0.49999))#+data_center - # TODO: make amplitude estimate not sucebtible to rounding effects on which pixels to chose to estimate the amplitude - if x_int > 2 and x_int < numPix_x-2 and y_int > 2 and y_int < numPix_y-2: - mean_image = max(np.sum(data[y_int - 2:y_int+3, x_int-2:x_int+3]), 0) - num = len(psf_kernel) - center = int((num-0.5)/2) - mean_kernel = np.sum(psf_kernel[center-2:center+3, center-2:center+3]) - amp_estimated = mean_image/mean_kernel - else: - amp_estimated = 0 - return amp_estimated
- - -
[docs]@export -def mge_kernel(kernel, order=5): - """ - azimutal Multi-Gaussian expansion of a pixelized kernel - - :param kernel: 2d numpy array - :return: - """ - # radial average - n = len(kernel) - center = (n - 1) / 2. - psf_r = image_util.radial_profile(kernel, center=[center, center]) - # MGE of radial average - n_r = len(psf_r) - r_array = np.linspace(start=0., stop=n_r - 1, num=n_r) - amps, sigmas, norm = mge.mge_1d(r_array, psf_r, N=order, linspace=True) - return amps, sigmas, norm
- - -
[docs]@export -def match_kernel_size(image, size): - """ - matching kernel/image to a dedicated size by either expanding the image with zeros at the edges or chopping of the - edges. - - :param image: 2d array (square with odd number of pixels) - :param size: integer (odd number) - :return: image with matched size, either by cutting or by adding zeros in the outskirts - """ - n = len(image) - if n == size: - return image - image_copy = copy.deepcopy(image) - if n > size: - return image_copy[int((n-size)/2): int(n - (n-size)/2), int((n-size)/2): int(n - (n-size)/2)] - else: - image_add = np.zeros((size, size)) - image_add[int((size - n)/2): int(size - (size - n)/2), int((size - n)/2): int(size - (size - n)/2)] = image_copy - return image_add
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Util/mask_util.html b/docs/_build/html/_modules/lenstronomy/Util/mask_util.html deleted file mode 100644 index 3db9d8df7..000000000 --- a/docs/_build/html/_modules/lenstronomy/Util/mask_util.html +++ /dev/null @@ -1,179 +0,0 @@ - - - - - - - - lenstronomy.Util.mask_util — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Util.mask_util

-import numpy as np
-import lenstronomy.Util.util as util
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -def mask_center_2d(center_x, center_y, r, x_grid, y_grid): - """ - - :param center_x: x-coordinate of center position of circular mask - :param center_y: y-coordinate of center position of circular mask - :param r: radius of mask in pixel values - :param x_grid: x-coordinate grid - :param y_grid: y-coordinate grid - :return: mask array of shape x_grid with =0 inside the radius and =1 outside - """ - x_shift = x_grid - center_x - y_shift = y_grid - center_y - R = np.sqrt(x_shift*x_shift + y_shift*y_shift) - mask = np.empty_like(R) - mask[R > r] = 1 - mask[R <= r] = 0 - return mask
- - -
[docs]@export -def mask_azimuthal(x, y, center_x, center_y, r): - """ - - :param x: x-coordinates (1d or 2d array numpy array) - :param y: y-coordinates (1d or 2d array numpy array) - :param center_x: center of azimuthal mask in x - :param center_y: center of azimuthal mask in y - :param r: radius of azimuthal mask - :return: array with zeros outside r and ones inside azimuthal radius r - """ - x_shift = x - center_x - y_shift = y - center_y - R = np.sqrt(x_shift*x_shift + y_shift*y_shift) - mask = np.empty_like(R) - mask[R > r] = 0 - mask[R <= r] = 1 - return mask
- - -
[docs]@export -def mask_ellipse(x, y, center_x, center_y, a, b, angle): - """ - - :param x: x-coordinates of pixels - :param y: y-coordinates of pixels - :param center_x: center of mask - :param center_y: center of mask - :param a: major axis - :param b: minor axis - :param angle: angle of major axis - :return: mask (list of zeros and ones) - """ - x_shift = x - center_x - y_shift = y - center_y - x_rot, y_rot = util.rotate(x_shift, y_shift, angle) - r_ab = x_rot**2 / a**2 + y_rot**2 / b**2 - mask = np.empty_like(r_ab) - mask[r_ab > 1] = 0 - mask[r_ab <= 1] = 1 - return mask
- - -
[docs]@export -def mask_half_moon(x, y, center_x, center_y, r_in, r_out, phi0=0, delta_phi=2*np.pi): - """ - - :param x: - :param y: - :param center_x: - :param center_y: - :param r_in: - :param r_out: - :param phi0: - :param delta_phi: - :return: - """ - x_shift = x - center_x - y_shift = y - center_y - R = np.sqrt(x_shift*x_shift + y_shift*y_shift) - phi = np.arctan2(x_shift, y_shift) - phi_min = phi0 - delta_phi/2. - phi_max = phi0 + delta_phi/2. - mask = np.zeros_like(x) - if phi_max > phi_min: - mask[(R < r_out) & (R > r_in) & (phi > phi_min) & (phi < phi_max)] = 1 - else: - mask[(R < r_out) & (R > r_in) & (phi > phi_max)] = 1 - mask[(R < r_out) & (R > r_in) & (phi < phi_min)] = 1 - return mask
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Util/multi_gauss_expansion.html b/docs/_build/html/_modules/lenstronomy/Util/multi_gauss_expansion.html deleted file mode 100644 index 02e941ae6..000000000 --- a/docs/_build/html/_modules/lenstronomy/Util/multi_gauss_expansion.html +++ /dev/null @@ -1,165 +0,0 @@ - - - - - - - - lenstronomy.Util.multi_gauss_expansion — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Util.multi_gauss_expansion

-__author__ = "ajshajib", "sibirrer"
-"""
-Multi-Gaussian expansion fitting, based on Capellari 2002, http://adsabs.harvard.edu/abs/2002MNRAS.333..400C
-"""
-
-import numpy as np
-from scipy.optimize import nnls
-import warnings
-from lenstronomy.Util.package_util import exporter
-from lenstronomy.LightModel.Profiles.gaussian import Gaussian
-gaussian_func = Gaussian()
-
-export, __all__ = exporter()
-
-
-
[docs]@export -def gaussian(R, sigma, amp): - """ - - :param R: radius - :param sigma: gaussian sigma - :param amp: normalization - :return: Gaussian function - """ - c = amp / (2 * np.pi * sigma**2) - return c * np.exp(-(R/float(sigma))**2/2.)
- - -
[docs]@export -def mge_1d(r_array, flux_r, N=20, linspace=False): - """ - - :param r_array: list or radii (numpy array) - :param flux_r: list of flux values (numpy array) - :param N: number of Gaussians - :return: amplitudes and Gaussian sigmas for the best 1d flux profile - """ - if N == 0: - warnings.warn('Number of MGE went down to zero! This should not happen!', Warning) - amplitudes = [0] - sigmas = [1] - norm = 0 - return amplitudes, sigmas, norm - try: - amplitudes, sigmas, norm = _mge_1d(r_array, flux_r, N, linspace=linspace) - except: - N_new = N - 1 - amplitudes, sigmas, norm = mge_1d(r_array, flux_r, N=N_new, linspace=linspace) - return amplitudes, sigmas, norm
- - -@export -def _mge_1d(r_array, flux_r, N=20, linspace=False): - """ - - :param r_array: - :param flux_r: - :param N: - :return: - """ - if linspace is True: - sigmas = np.linspace(r_array[0], r_array[-1] / 2, N + 2)[1:-1] - else: - sigmas = np.logspace(np.log10(r_array[0]), np.log10((r_array[-1] + 0.0000001) / 2.), N + 2)[1:-1] - # sigmas = np.linspace(r_array[0], r_array[-1]/2, N + 2)[1:-1] - - A = np.zeros((len(flux_r), N)) - for j in np.arange(A.shape[1]): - A[:, j] = gaussian(r_array, sigmas[j], 1.) - amplitudes, norm = nnls(A, flux_r) - return amplitudes, sigmas, norm - - -
[docs]@export -def de_projection_3d(amplitudes, sigmas): - """ - de-projects a gaussian (or list of multiple Gaussians from a 2d projected to a 3d profile) - :param amplitudes: - :param sigmas: - :return: - """ - amplitudes_3d = amplitudes / sigmas / np.sqrt(2*np.pi) - return amplitudes_3d, sigmas
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Util/numba_util.html b/docs/_build/html/_modules/lenstronomy/Util/numba_util.html deleted file mode 100644 index f669f921e..000000000 --- a/docs/_build/html/_modules/lenstronomy/Util/numba_util.html +++ /dev/null @@ -1,181 +0,0 @@ - - - - - - - - lenstronomy.Util.numba_util — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Util.numba_util

-import numpy as np
-from lenstronomy.Conf import config_loader
-from os import environ
-
-"""
-From pyautolens:
-Depending on if we're using a super computer, we want two different numba decorators:
-If on laptop:
-@numba.jit(nopython=True, cache=True, parallel=False)
-If on super computer:
-@numba.jit(nopython=True, cache=False, parallel=True)
-"""
-
-numba_conf = config_loader.numba_conf()
-nopython = numba_conf['nopython']
-cache = numba_conf['cache']
-parallel = numba_conf['parallel']
-numba_enabled = numba_conf['enable'] and not environ.get("NUMBA_DISABLE_JIT", False)
-fastmath = numba_conf['fastmath']
-error_model = numba_conf['error_model']
-
-if numba_enabled:
-    try:
-        import numba
-    except ImportError:
-        numba_enabled = False
-        numba = None
-
-__all__ = ['jit', 'generated_jit', 'nan_to_num', 'nan_to_num_arr', 'nan_to_num_single']
-
-
-
[docs]def jit(nopython=nopython, cache=cache, parallel=parallel, fastmath=fastmath, error_model=error_model, inline='never'): - if numba_enabled: - def wrapper(func): - return numba.jit(func, nopython=nopython, cache=cache, parallel=parallel, fastmath=fastmath, - error_model=error_model, inline=inline) - else: - def wrapper(func): - return func - return wrapper
- - -
[docs]def generated_jit(nopython=nopython, cache=cache, parallel=parallel, fastmath=fastmath, error_model=error_model): - """ - Wrapper around numba.generated_jit. Allows you to redirect a function to another based on its type - - see the Numba docs for more info - """ - if numba_enabled: - def wrapper(func): - return numba.generated_jit(func, nopython=nopython, cache=cache, parallel=parallel, fastmath=fastmath, - error_model=error_model) - else: - def wrapper(func): - return func - - return wrapper
- - -
[docs]@generated_jit() -def nan_to_num(x, posinf=1e10, neginf=-1e10, nan=0.): - """ - Implements a Numba equivalent to np.nan_to_num (with copy=False!) array or scalar in Numba. - Behaviour is the same as np.nan_to_num with copy=False, although it only supports 1-dimensional arrays and - scalar inputs. - """ - # The generated_jit part is necessary because of the need to support both arrays and scalars for all input - # functions. - if ((numba_enabled and isinstance(x, numba.types.Array)) or isinstance(x, np.ndarray)) and x.ndim > 0: - return nan_to_num_arr if numba_enabled else nan_to_num_arr(x, posinf, neginf, nan) - else: - return nan_to_num_single if numba_enabled else nan_to_num_single(x, posinf, neginf, nan)
- - -
[docs]@jit() -def nan_to_num_arr(x, posinf=1e10, neginf=-1e10, nan=0.): - """Part of the Numba implementation of np.nan_to_num - see nan_to_num""" - for i in range(len(x)): - if np.isnan(x[i]): - x[i] = nan - if np.isinf(x[i]): - if x[i] > 0: - x[i] = posinf - else: - x[i] = neginf - return x
- - -
[docs]@jit() -def nan_to_num_single(x, posinf=1e10, neginf=-1e10, nan=0.): - """Part of the Numba implementation of np.nan_to_num - see nan_to_num""" - if np.isnan(x): - return nan - elif np.isinf(x): - if x > 0: - return posinf - else: - return neginf - else: - return x
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Util/param_util.html b/docs/_build/html/_modules/lenstronomy/Util/param_util.html deleted file mode 100644 index 524337488..000000000 --- a/docs/_build/html/_modules/lenstronomy/Util/param_util.html +++ /dev/null @@ -1,249 +0,0 @@ - - - - - - - - lenstronomy.Util.param_util — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Util.param_util

-import numpy as np
-
-from lenstronomy.Util.numba_util import jit
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -def cart2polar(x, y, center_x=0, center_y=0): - """ - transforms cartesian coords [x,y] into polar coords [r,phi] in the frame of the lens center - - :param x: set of x-coordinates - :type x: array of size (n) - :param y: set of x-coordinates - :type y: array of size (n) - :param center_x: rotation point - :type center_x: float - :param center_y: rotation point - :type center_y: float - :returns: array of same size with coords [r,phi] - """ - coord_shift_x = x - center_x - coord_shift_y = y - center_y - r = np.sqrt(coord_shift_x**2+coord_shift_y**2) - phi = np.arctan2(coord_shift_y, coord_shift_x) - return r, phi
- - -
[docs]@export -def polar2cart(r, phi, center): - """ - transforms polar coords [r,phi] into cartesian coords [x,y] in the frame of the lense center - - :param coord: set of coordinates - :type coord: array of size (n,2) - :param center: rotation point - :type center: array of size (2) - :returns: array of same size with coords [x,y] - :raises: AttributeError, KeyError - """ - x = r*np.cos(phi) - y = r*np.sin(phi) - return x - center[0], y - center[1]
- - -
[docs]@export -def shear_polar2cartesian(phi, gamma): - """ - - :param phi: shear angle (radian) - :param gamma: shear strength - :return: shear components gamma1, gamma2 - """ - gamma1 = gamma*np.cos(2*phi) - gamma2 = gamma*np.sin(2*phi) - return gamma1, gamma2
- - -
[docs]@export -def shear_cartesian2polar(gamma1, gamma2): - """ - :param gamma1: cartesian shear component - :param gamma2: cartesian shear component - :return: shear angle, shear strength - """ - phi = np.arctan2(gamma2, gamma1) / 2 - gamma = np.sqrt(gamma1 ** 2 + gamma2 ** 2) - return phi, gamma
- - -
[docs]@export -@jit() -def phi_q2_ellipticity(phi, q): - """ - transforms orientation angle and axis ratio into complex ellipticity moduli e1, e2 - - :param phi: angle of orientation (in radian) - :param q: axis ratio minor axis / major axis - :return: eccentricities e1 and e2 in complex ellipticity moduli - """ - e1 = (1. - q) / (1. + q) * np.cos(2 * phi) - e2 = (1. - q) / (1. + q) * np.sin(2 * phi) - return e1, e2
- - -
[docs]@export -@jit() -def ellipticity2phi_q(e1, e2): - """ - transforms complex ellipticity moduli in orientation angle and axis ratio - - :param e1: eccentricity in x-direction - :param e2: eccentricity in xy-direction - :return: angle in radian, axis ratio (minor/major) - """ - phi = np.arctan2(e2, e1)/2 - c = np.sqrt(e1**2+e2**2) - c = np.minimum(c, 0.9999) - q = (1-c)/(1+c) - return phi, q
- - -
[docs]@export -def transform_e1e2_product_average(x, y, e1, e2, center_x, center_y): - """ - maps the coordinates x, y with eccentricities e1 e2 into a new elliptical coordinate system - such that R = sqrt(R_major * R_minor) - - :param x: x-coordinate - :param y: y-coordinate - :param e1: eccentricity - :param e2: eccentricity - :param center_x: center of distortion - :param center_y: center of distortion - :return: distorted coordinates x', y' - """ - phi_G, q = ellipticity2phi_q(e1, e2) - x_shift = x - center_x - y_shift = y - center_y - - cos_phi = np.cos(phi_G) - sin_phi = np.sin(phi_G) - - xt1 = cos_phi * x_shift + sin_phi * y_shift - xt2 = -sin_phi * x_shift + cos_phi * y_shift - return xt1 * np.sqrt(q), xt2 / np.sqrt(q)
- - -
[docs]@export -def transform_e1e2_square_average(x, y, e1, e2, center_x, center_y): - """ - maps the coordinates x, y with eccentricities e1 e2 into a new elliptical coordinate system - such that R = sqrt(R_major**2 + R_minor**2) - - :param x: x-coordinate - :param y: y-coordinate - :param e1: eccentricity - :param e2: eccentricity - :param center_x: center of distortion - :param center_y: center of distortion - :return: distorted coordinates x', y' - """ - phi_G, q = ellipticity2phi_q(e1, e2) - x_shift = x - center_x - y_shift = y - center_y - cos_phi = np.cos(phi_G) - sin_phi = np.sin(phi_G) - #e = abs(1 - q) - e = q2e(q) - x_ = (cos_phi * x_shift + sin_phi * y_shift) * np.sqrt(1 - e) - y_ = (-sin_phi * x_shift + cos_phi * y_shift) * np.sqrt(1 + e) - return x_, y_
- - -def q2e(q): - """ - computes - - .. math:: - e = \\equic \\frac{1 - q^2}{1 + q^2} - - :param q: axis ratio of minor to major axis - :return: ellipticity e - """ - e = abs(1 - q ** 2) / (1 + q ** 2) - return e -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Util/prob_density.html b/docs/_build/html/_modules/lenstronomy/Util/prob_density.html deleted file mode 100644 index a2c1fc267..000000000 --- a/docs/_build/html/_modules/lenstronomy/Util/prob_density.html +++ /dev/null @@ -1,239 +0,0 @@ - - - - - - - - lenstronomy.Util.prob_density — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Util.prob_density

-__author__ = 'sibirrer'
-
-from scipy import stats
-import numpy as np
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -class SkewGaussian(object): - """ - class for the Skew Gaussian distribution - """ -
[docs] def pdf(self, x, e=0., w=1., a=0.): - """ - probability density function - see: https://en.wikipedia.org/wiki/Skew_normal_distribution - :param x: input value - :param e: - :param w: - :param a: - :return: - """ - t = (x-e) / w - return 2. / w * stats.norm.pdf(t) * stats.norm.cdf(a*t)
- -
[docs] def pdf_skew(self, x, mu, sigma, skw): - """ - function with different parameterisation - :param x: - :param mu: mean - :param sigma: sigma - :param skw: skewness - :return: - """ - if skw >= 1 or skw <= -1: - raise ValueError("skewness %s out of range" % skw) - e, w, a = self.map_mu_sigma_skw(mu, sigma, skw) - pdf = self.pdf(x, e, w, a) - return pdf
- - def _delta_skw(self, skw): - """ - - :param skw: skewness parameter - :return: delta - """ - skw_23 = np.abs(skw)**(2./3) - delta2 = skw_23*np.pi/2 / (skw_23 + ((4-np.pi)/2)**(2./3)) - return np.sqrt(delta2)*skw/np.abs(skw) - - def _alpha_delta(self, delta): - """ - - :param delta: delta parameter - :return: alpha (a) - """ - return delta/np.sqrt(1-delta**2) - - def _w_sigma_delta(self, sigma, delta): - """ - invert variance - :param sigma: - :param delta: - :return: w parameter - """ - sigma2=sigma**2 - w2 = sigma2/(1-2*delta**2/np.pi) - w = np.sqrt(w2) - return w - - def _e_mu_w_delta(self, mu, w, delta): - """ - - :param mu: - :param w: - :param delta: - :return: epsilon (e) - """ - e = mu - w*delta*np.sqrt(2/np.pi) - return e - -
[docs] def map_mu_sigma_skw(self, mu, sigma, skw): - """ - map to parameters e, w, a - :param mu: mean - :param sigma: standard deviation - :param skw: skewness - :return: e, w, a - """ - delta = self._delta_skw(skw) - a = self._alpha_delta(delta) - w = self._w_sigma_delta(sigma, delta) - e = self._e_mu_w_delta(mu, w, delta) - return e, w, a
- - -
[docs]@export -class KDE1D(object): - """ - class that allows to compute likelihoods based on a 1-d posterior sample - """ - def __init__(self, values): - """ - - :param values: 1d numpy array of points representing a PDF - """ - self._points = values - self._kernel = stats.gaussian_kde(values) - -
[docs] def likelihood(self, x): - """ - - :param x: position where to evaluate the density - :return: likelihood given the sample distribution - """ - - dens = self._kernel.evaluate(points=x) - return dens
- - -
[docs]@export -def compute_lower_upper_errors(sample, num_sigma=1): - """ - computes the upper and lower sigma from the median value. - This functions gives good error estimates for skewed pdf's - :param sample: 1-D sample - :param num_sigma: integer, number of sigmas to be returned - :return: median, lower_sigma, upper_sigma - """ - if num_sigma > 3: - raise ValueError("Number of sigma-constraints restricted to three. %s not valid" % num_sigma) - num = len(sample) - num_threshold1 = int(round((num-1)*0.841345)) - num_threshold2 = int(round((num-1)*0.977249868)) - num_threshold3 = int(round((num-1)*0.998650102)) - - median = np.median(sample) - sorted_sample = np.sort(sample) - if num_sigma > 0: - upper_sigma1 = sorted_sample[num_threshold1-1] - lower_sigma1 = sorted_sample[num-num_threshold1-1] - else: - return median, [[]] - if num_sigma > 1: - upper_sigma2 = sorted_sample[num_threshold2-1] - lower_sigma2 = sorted_sample[num-num_threshold2-1] - else: - return median, [[median-lower_sigma1, upper_sigma1-median]] - if num_sigma > 2: - upper_sigma3 = sorted_sample[num_threshold3-1] - lower_sigma3 = sorted_sample[num-num_threshold3-1] - return median, [[median-lower_sigma1, upper_sigma1-median], [median-lower_sigma2, upper_sigma2-median], - [median-lower_sigma3, upper_sigma3-median]] - else: - return median, [[median-lower_sigma1, upper_sigma1-median], [median-lower_sigma2, upper_sigma2-median]]
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Util/sampling_util.html b/docs/_build/html/_modules/lenstronomy/Util/sampling_util.html deleted file mode 100644 index 098f4884b..000000000 --- a/docs/_build/html/_modules/lenstronomy/Util/sampling_util.html +++ /dev/null @@ -1,208 +0,0 @@ - - - - - - - - lenstronomy.Util.sampling_util — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Util.sampling_util

-__author__ = 'aymgal'
-
-import numpy as np
-from scipy import stats
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-# transform the unit hypercube to pysical parameters for (nested) sampling
-
-
[docs]@export -def unit2uniform(x, vmin, vmax): - """ - mapping from uniform distribution on parameter space - to uniform distribution on unit hypercube - """ - return vmin + (vmax - vmin) * x
- - -
[docs]@export -def uniform2unit(theta, vmin, vmax): - """ - mapping from uniform distribution on unit hypercube - to uniform distribution on parameter space - """ - return (theta - vmin) / (vmax - vmin)
- - -
[docs]@export -def cube2args_uniform(cube, lowers, uppers, num_dims, copy=False): - """ - mapping from uniform distribution on unit hypercube 'cube' - to uniform distribution on parameter space - - :param cube: list or 1D-array of parameter values on unit hypercube - :param lowers: lower bounds for each parameter - :param uppers: upper bounds for each parameter - :param num_dims: parameter space dimension (= number of parameters) - :param copy: If False, this function modifies 'cube' in-place. Default to False. - :return: hypercube mapped to parameters space - """ - if copy: - cube_ = cube - cube = np.zeros_like(cube_) - for i in range(num_dims): - val = cube_[i] if copy else cube[i] - low, upp = lowers[i], uppers[i] - cube[i] = unit2uniform(val, low, upp) - return cube
- - -
[docs]@export -def cube2args_gaussian(cube, lowers, uppers, means, sigmas, num_dims, copy=False): - """ - mapping from uniform distribution on unit hypercube 'cube' - to truncated gaussian distribution on parameter space, - with mean 'mu' and std dev 'sigma' - - :param cube: list or 1D-array of parameter values on unit hypercube - :param lowers: lower bounds for each parameter - :param uppers: upper bounds for each parameter - :param means: gaussian mean for each parameter - :param sigmas: gaussian std deviation for each parameter - :param num_dims: parameter space dimension (= number of parameters) - :param copy: If False, this function modifies 'cube' in-place. Default to False. - :return: hypercube mapped to parameters space - """ - if copy: - cube_ = cube - cube = np.zeros_like(cube_) - a, b = (np.array(lowers)-means)/sigmas, (np.array(uppers)-means)/sigmas - cube[:] = stats.truncnorm.ppf(cube_ if copy else cube, a=a, b=b, loc=means, scale=sigmas) - return cube
- - -
[docs]@export -def scale_limits(lowers, uppers, scale): - if not isinstance(lowers, np.ndarray): - lowers = np.asarray(lowers) - uppers = np.asarray(uppers) - mid_points = (lowers + uppers) / 2. - widths_scaled = (uppers - lowers) * scale - lowers_scaled = mid_points - widths_scaled / 2. - uppers_scaled = mid_points + widths_scaled / 2. - return lowers_scaled, uppers_scaled
- - -
[docs]@export -def sample_ball(p0, std, size=1, dist='uniform'): - """ - Produce a ball of walkers around an initial parameter value. - this routine is from the emcee package as it became deprecated there - - :param p0: The initial parameter values (array). - :param std: The axis-aligned standard deviation (array). - :param size: The number of samples to produce. - :param dist: string, specifies the distribution being sampled, supports 'uniform' and 'normal' - - """ - assert(len(p0) == len(std)) - if dist == 'uniform': - return np.vstack([p0 + std * np.random.uniform(low=-1, high=1, size=len(p0)) - for i in range(size)]) - elif dist == 'normal': - return np.vstack([p0 + std * np.random.normal(loc=0, scale=1, size=len(p0)) - for i in range(size)]) - else: - raise ValueError('distribution %s not supported. Chose among "uniform" or "normal".' % dist)
- - -
[docs]@export -def sample_ball_truncated(mean, sigma, lower_limit, upper_limit, size): - """ - samples gaussian ball with truncation at lower and upper limit of the distribution - - :param mean: numpy array, mean of the distribution to be sampled - :param sigma: numpy array, sigma of the distribution to be sampled - :param lower_limit: numpy array, lower bound of to be sampled distribution - :param upper_limit: numpy array, upper bound of to be sampled distribution - :param size: number of tuples to be sampled - :return: realization of truncated normal distribution with shape (size, dim(parameters)) - """ - a, b = (lower_limit - mean) / sigma, (upper_limit - mean) / sigma - draws = np.vstack([mean + sigma * stats.truncnorm.rvs(a, b, size=len(a)) for i in range(size)]) - return draws
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Util/simulation_util.html b/docs/_build/html/_modules/lenstronomy/Util/simulation_util.html deleted file mode 100644 index 2f8791358..000000000 --- a/docs/_build/html/_modules/lenstronomy/Util/simulation_util.html +++ /dev/null @@ -1,146 +0,0 @@ - - - - - - - - lenstronomy.Util.simulation_util — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Util.simulation_util

-import lenstronomy.Util.util as util
-import lenstronomy.Util.image_util as image_util
-
-import numpy as np
-
-from lenstronomy.Util.package_util import exporter
-export, __all__ = exporter()
-
-
-
[docs]@export -def data_configure_simple(numPix, deltaPix, exposure_time=None, background_rms=None, center_ra=0, center_dec=0, - inverse=False): - """ - configures the data keyword arguments with a coordinate grid centered at zero. - - :param numPix: number of pixel (numPix x numPix) - :param deltaPix: pixel size (in angular units) - :param exposure_time: exposure time - :param background_rms: background noise (Gaussian sigma) - :param center_ra: RA at the center of the image - :param center_dec: DEC at the center of the image - :param inverse: if True, coordinate system is ra to the left, if False, to the right - :return: keyword arguments that can be used to construct a Data() class instance of lenstronomy - """ - - # 1d list of coordinates (x,y) of a numPix x numPix square grid, centered to zero - x_grid, y_grid, ra_at_xy_0, dec_at_xy_0, x_at_radec_0, y_at_radec_0, Mpix2coord, Mcoord2pix = util.make_grid_with_coordtransform(numPix=numPix, deltapix=deltaPix, center_ra=center_ra, center_dec=center_dec, subgrid_res=1, inverse=inverse) - # mask (1= model this pixel, 0= leave blanck) - # exposure_map = np.ones((numPix, numPix)) * exposure_time # individual exposure time/weight per pixel - - kwargs_data = { - 'background_rms': background_rms, - 'exposure_time': exposure_time - , 'ra_at_xy_0': ra_at_xy_0, 'dec_at_xy_0': dec_at_xy_0, 'transform_pix2angle': Mpix2coord - , 'image_data': np.zeros((numPix, numPix)) - } - return kwargs_data
- - -
[docs]@export -def simulate_simple(image_model_class, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - no_noise=False, source_add=True, lens_light_add=True, point_source_add=True): - """ - - :param image_model_class: - :param kwargs_lens: - :param kwargs_source: - :param kwargs_lens_light: - :param kwargs_ps: - :param no_noise: - :param source_add: - :param lens_light_add: - :param point_source_add: - :return: - """ - - image = image_model_class.image(kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps, source_add=source_add, lens_light_add=lens_light_add, point_source_add=point_source_add) - # add noise - if no_noise: - return image - else: - poisson = image_util.add_poisson(image, exp_time=image_model_class.Data.exposure_map) - bkg = image_util.add_background(image, sigma_bkd=image_model_class.Data.background_rms) - return image + bkg + poisson
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Util/util.html b/docs/_build/html/_modules/lenstronomy/Util/util.html deleted file mode 100644 index 90bc46734..000000000 --- a/docs/_build/html/_modules/lenstronomy/Util/util.html +++ /dev/null @@ -1,756 +0,0 @@ - - - - - - - - lenstronomy.Util.util — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Util.util

-__author__ = 'Simon Birrer'
-
-"""
-this file contains standard routines
-"""
-
-import numpy as np
-import itertools
-from lenstronomy.Util.numba_util import jit
-from lenstronomy.Util.package_util import exporter
-
-export, __all__ = exporter()
-
-
-
[docs]@export -def merge_dicts(*dict_args): - """ - Given any number of dicts, shallow copy and merge into a new dict, - precedence goes to key value pairs in latter dicts. - """ - result = {} - for dictionary in dict_args: - result.update(dictionary) - return result
- - -
[docs]@export -def approx_theta_E(ximg, yimg): - dis = [] - xinds, yinds = [0, 0, 0, 1, 1, 2], [1, 2, 3, 2, 3, 3] - - for (i, j) in zip(xinds, yinds): - dx, dy = ximg[i] - ximg[j], yimg[i] - yimg[j] - dr = (dx ** 2 + dy ** 2) ** 0.5 - dis.append(dr) - dis = np.array(dis) - - greatest = np.argmax(dis) - dr_greatest = dis[greatest] - dis[greatest] = 0 - - second_greatest = np.argmax(dis) - dr_second = dis[second_greatest] - - return 0.5 * (dr_greatest * dr_second) ** 0.5
- - -
[docs]@export -def sort_image_index(ximg, yimg, xref, yref): - """ - - :param ximg: x coordinates to sort - :param yimg: y coordinates to sort - :param xref: reference x coordinate - :param yref: reference y coordinate - :return: indexes such that ximg[indexes],yimg[indexes] matches xref,yref - """ - - assert len(xref) == len(ximg) - ximg, yimg = np.array(ximg), np.array(yimg) - x_self = np.array(list(itertools.permutations(ximg))) - y_self = np.array(list(itertools.permutations(yimg))) - - indexes = [0, 1, 2, 3] - index_iterations = list(itertools.permutations(indexes)) - delta_r = [] - - for i in range(0, int(len(x_self))): - dr = 0 - for j in range(0, int(len(x_self[0]))): - dr += (x_self[i][j] - xref[j]) ** 2 + (y_self[i][j] - yref[j]) ** 2 - - delta_r.append(dr ** .5) - - min_indexes = np.array(index_iterations[np.argmin(delta_r)]) - - return min_indexes
- - -
[docs]@export -@jit() -def rotate(xcoords, ycoords, angle): - """ - - :param xcoords: x points - :param ycoords: y points - :param angle: angle in radians - :return: x points and y points rotated ccw by angle theta - """ - return xcoords * np.cos(angle) + ycoords * np.sin(angle), -xcoords * np.sin(angle) + ycoords * np.cos(angle)
- - -
[docs]@export -def map_coord2pix(ra, dec, x_0, y_0, M): - """ - this routines performs a linear transformation between two coordinate systems. Mainly used to transform angular - into pixel coordinates in an image - :param ra: ra coordinates - :param dec: dec coordinates - :param x_0: pixel value in x-axis of ra,dec = 0,0 - :param y_0: pixel value in y-axis of ra,dec = 0,0 - :param M: 2x2 matrix to transform angular to pixel coordinates - :return: transformed coordinate systems of input ra and dec - """ - x, y = M.dot(np.array([ra, dec])) - return x + x_0, y + y_0
- - -
[docs]@export -def array2image(array, nx=0, ny=0): - """ - returns the information contained in a 1d array into an n*n 2d array - (only works when length of array is n**2, or nx and ny are provided) - - :param array: image values - :type array: array of size n**2 - :returns: 2d array - :raises: AttributeError, KeyError - """ - if nx == 0 or ny == 0: - n = int(np.sqrt(len(array))) - if n ** 2 != len(array): - raise ValueError("lenght of input array given as %s is not square of integer number!" % (len(array))) - nx, ny = n, n - image = array.reshape(int(nx), int(ny)) - return image
- - -
[docs]@export -def image2array(image): - """ - returns the information contained in a 2d array into an n*n 1d array - - :param image: image values - :type image: array of size (n,n) - :returns: 1d array - :raises: AttributeError, KeyError - """ - nx, ny = image.shape # find the size of the array - imgh = np.reshape(image, nx * ny) # change the shape to be 1d - return imgh
- - -
[docs]@export -def array2cube(array, n_1, n_23): - """ - returns the information contained in a 1d array of shape (n_1*n_23*n_23) into 3d array with shape (n_1, sqrt(n_23), sqrt(n_23)) - - :param array: image values - :type array: 1d array - :param n_1: first dimension of returned array - :type n_1: int - :param n_23: square of second and third dimensions of returned array - :type n_23: int - :returns: 3d array - :raises ValueError: when n_23 is not a perfect square - """ - n = int(np.sqrt(n_23)) - if n ** 2 != n_23: - raise ValueError("2nd and 3rd dims (%s) are not square of integer number!" % n_23) - n_2, n_3 = n, n - cube = array.reshape(n_1, n_2, n_3) - return cube
- - -
[docs]@export -def cube2array(cube): - """ - returns the information contained in a 3d array of shape (n_1, n_2, n_3) into 1d array with shape (n_1*n_2*n_3) - - :param cube: image values - :type cube: 3d array - :returns: 1d array - """ - n_1, n_2, n_3 = cube.shape - array = cube.reshape(n_1 * n_2 * n_3) - return array
- - -
[docs]@export -def make_grid(numPix, deltapix, subgrid_res=1, left_lower=False): - """ - creates pixel grid (in 1d arrays of x- and y- positions) - default coordinate frame is such that (0,0) is in the center of the coordinate grid - - :param numPix: number of pixels per axis - Give an integers for a square grid, or a 2-length sequence - (first, second axis length) for a non-square grid. - :param deltapix: pixel size - :param subgrid_res: sub-pixel resolution (default=1) - :return: x, y position information in two 1d arrays - """ - - # Check numPix is an integer, or 2-sequence of integers - if isinstance(numPix, (tuple, list, np.ndarray)): - assert len(numPix) == 2 - if any(x != round(x) for x in numPix): - raise ValueError("numPix contains non-integers: %s" % numPix) - numPix = np.asarray(numPix, dtype=int) - else: - if numPix != round(numPix): - raise ValueError("Attempt to specify non-int numPix: %s" % numPix) - numPix = np.array([numPix, numPix], dtype=int) - - # Super-resolution sampling - numPix_eff = (numPix * subgrid_res).astype(int) - deltapix_eff = deltapix / float(subgrid_res) - - # Compute unshifted grids. - # X values change quickly, Y values are repeated many times - x_grid = np.tile(np.arange(numPix_eff[0]), numPix_eff[1]) * deltapix_eff - y_grid = np.repeat(np.arange(numPix_eff[1]), numPix_eff[0]) * deltapix_eff - - if left_lower is True: - # Shift so (0, 0) is in the "lower left" - # Note this does not shift when subgrid_res = 1 - shift = -1. / 2 + 1. / (2 * subgrid_res) * np.array([1, 1]) - else: - # Shift so (0, 0) is centered - shift = deltapix_eff * (numPix_eff - 1) / 2 - - return x_grid - shift[0], y_grid - shift[1]
- - -
[docs]@export -def make_grid_transformed(numPix, Mpix2Angle): - """ - returns grid with linear transformation (deltaPix and rotation) - :param numPix: number of Pixels - :param Mpix2Angle: 2-by-2 matrix to mat a pixel to a coordinate - :return: coordinate grid - """ - x_grid, y_grid = make_grid(numPix, deltapix=1) - ra_grid, dec_grid = map_coord2pix(x_grid, y_grid, 0, 0, Mpix2Angle) - return ra_grid, dec_grid
- - -
[docs]@export -def make_grid_with_coordtransform(numPix, deltapix, subgrid_res=1, center_ra=0, center_dec=0, left_lower=False, - inverse=True): - """ - same as make_grid routine, but returns the transformation matrix and shift between coordinates and pixel - - :param numPix: number of pixels per axis - :param deltapix: pixel scale per axis - :param subgrid_res: super-sampling resolution relative to the stated pixel size - :param center_ra: center of the grid - :param center_dec: center of the grid - :param left_lower: sets the zero point at the lower left corner of the pixels - :param inverse: bool, if true sets East as left, otherwise East is righrt - :return: ra_grid, dec_grid, ra_at_xy_0, dec_at_xy_0, x_at_radec_0, y_at_radec_0, Mpix2coord, Mcoord2pix - """ - numPix_eff = numPix * subgrid_res - deltapix_eff = deltapix / float(subgrid_res) - a = np.arange(numPix_eff) - matrix = np.dstack(np.meshgrid(a, a)).reshape(-1, 2) - if inverse is True: - delta_x = -deltapix_eff - else: - delta_x = deltapix_eff - if left_lower is True: - ra_grid = matrix[:, 0] * delta_x - dec_grid = matrix[:, 1] * deltapix_eff - else: - ra_grid = (matrix[:, 0] - (numPix_eff - 1) / 2.) * delta_x - dec_grid = (matrix[:, 1] - (numPix_eff - 1) / 2.) * deltapix_eff - shift = (subgrid_res - 1) / (2. * subgrid_res) * deltapix - ra_grid += -shift + center_ra - dec_grid += -shift + center_dec - ra_at_xy_0 = ra_grid[0] - dec_at_xy_0 = dec_grid[0] - - Mpix2coord = np.array([[delta_x, 0], [0, deltapix_eff]]) - Mcoord2pix = np.linalg.inv(Mpix2coord) - x_at_radec_0, y_at_radec_0 = map_coord2pix(-ra_at_xy_0, -dec_at_xy_0, x_0=0, y_0=0, M=Mcoord2pix) - return ra_grid, dec_grid, ra_at_xy_0, dec_at_xy_0, x_at_radec_0, y_at_radec_0, Mpix2coord, Mcoord2pix
- - -
[docs]@export -def grid_from_coordinate_transform(nx, ny, Mpix2coord, ra_at_xy_0, dec_at_xy_0): - """ - return a grid in x and y coordinates that satisfy the coordinate system - - - :param nx: number of pixels in x-axis - :param ny: number of pixels in y-axis - :param Mpix2coord: transformation matrix (2x2) of pixels into coordinate displacements - :param ra_at_xy_0: RA coordinate at (x,y) = (0,0) - :param dec_at_xy_0: DEC coordinate at (x,y) = (0,0) - :return: RA coordinate grid, DEC coordinate grid - """ - a = np.arange(nx) - b = np.arange(ny) - matrix = np.dstack(np.meshgrid(a, b)).reshape(-1, 2) - x_grid = matrix[:, 0] - y_grid = matrix[:, 1] - ra_grid = x_grid * Mpix2coord[0, 0] + y_grid * Mpix2coord[0, 1] + ra_at_xy_0 - dec_grid = x_grid * Mpix2coord[1, 0] + y_grid * Mpix2coord[1, 1] + dec_at_xy_0 - return ra_grid, dec_grid
- - -
[docs]@export -def get_axes(x, y): - """ - computes the axis x and y of a given 2d grid - :param x: - :param y: - :return: - """ - n = int(np.sqrt(len(x))) - if n ** 2 != len(x): - raise ValueError("lenght of input array given as %s is not square of integer number!" % (len(x))) - x_image = x.reshape(n, n) - y_image = y.reshape(n, n) - x_axes = x_image[0, :] - y_axes = y_image[:, 0] - return x_axes, y_axes
- - -
[docs]@export -def averaging(grid, numGrid, numPix): - """ - resize 2d pixel grid with numGrid to numPix and averages over the pixels - :param grid: higher resolution pixel grid - :param numGrid: number of pixels per axis in the high resolution input image - :param numPix: lower number of pixels per axis in the output image (numGrid/numPix is integer number) - :return: - """ - - Nbig = numGrid - Nsmall = numPix - small = grid.reshape([int(Nsmall), int(Nbig / Nsmall), int(Nsmall), int(Nbig / Nsmall)]).mean(3).mean(1) - return small
- - -
[docs]@export -def displaceAbs(x, y, sourcePos_x, sourcePos_y): - """ - calculates a grid of distances to the observer in angel - - :param x: cartesian coordinates - :type x: numpy array - :param y: cartesian coordinates - :type y: numpy array - :param sourcePos_x: source position - :type sourcePos_x: float - :param sourcePos_y: source position - :type sourcePos_y: float - :returns: array of displacement - :raises: AttributeError, KeyError - """ - x_mapped = x - sourcePos_x - y_mapped = y - sourcePos_y - absmapped = np.sqrt(x_mapped ** 2 + y_mapped ** 2) - return absmapped
- - -
[docs]@export -def get_distance(x_mins, y_mins, x_true, y_true): - """ - - :param x_mins: - :param y_mins: - :param x_true: - :param y_true: - :return: - """ - if len(x_mins) != len(x_true): - return 10 ** 10 - dist = 0 - x_true_list = np.array(x_true) - y_true_list = np.array(y_true) - - for i in range(0, len(x_mins)): - dist_list = (x_mins[i] - x_true_list) ** 2 + (y_mins[i] - y_true_list) ** 2 - dist += min(dist_list) - k = np.where(dist_list == min(dist_list)) - if type(k) != int: - k = k[0] - x_true_list = np.delete(x_true_list, k) - y_true_list = np.delete(y_true_list, k) - return dist
- - -
[docs]@export -def compare_distance(x_mapped, y_mapped): - """ - - :param x_mapped: array of x-positions of remapped catalogue image - :param y_mapped: array of y-positions of remapped catalogue image - :return: sum of distance square of positions - """ - X2 = 0 - for i in range(0, len(x_mapped) - 1): - for j in range(i + 1, len(x_mapped)): - dx = x_mapped[i] - x_mapped[j] - dy = y_mapped[i] - y_mapped[j] - X2 += dx ** 2 + dy ** 2 - return X2
- - -
[docs]@export -def min_square_dist(x_1, y_1, x_2, y_2): - """ - return minimum of quadratic distance of pairs (x1, y1) to pairs (x2, y2) - :param x_1: - :param y_1: - :param x_2: - :param y_2: - :return: - """ - dist = np.zeros_like(x_1) - for i in range(len(x_1)): - dist[i] = np.min((x_1[i] - x_2) ** 2 + (y_1[i] - y_2) ** 2) - return dist
- - -
[docs]@export -def selectBest(array, criteria, numSelect, highest=True): - """ - - :param array: numpy array to be selected from - :param criteria: criteria of selection - :param highest: bool, if false the lowest will be selected - :param numSelect: number of elements to be selected - :return: - """ - n = len(array) - m = len(criteria) - if n != m: - raise ValueError('Elements in array (%s) not equal to elements in criteria (%s)' % (n, m)) - if n < numSelect: - return array - array_sorted = array[criteria.argsort()] - if highest: - result = array_sorted[n - numSelect:] - else: - result = array_sorted[0:numSelect] - return result[::-1]
- - -
[docs]@export -def select_best(array, criteria, num_select, highest=True): - """ - - :param array: numpy array to be selected from - :param criteria: criteria of selection - :param highest: bool, if false the lowest will be selected - :param num_select: number of elements to be selected - :return: - """ - n = len(array) - m = len(criteria) - if n != m: - raise ValueError('Elements in array (%s) not equal to elements in criteria (%s)' % (n, m)) - if n < num_select: - return array - array = np.array(array) - if highest is True: - indexes = criteria.argsort()[::-1][:num_select] - else: - indexes = criteria.argsort()[::-1][n - num_select:] - return array[indexes]
- - -
[docs]@export -def points_on_circle(radius, num_points, connect_ends=True): - """ - returns a set of uniform points around a circle - :param radius: radius of the circle - :param num_points: number of points on the circle - :param connect_ends: boolean, if True, start and end point are the same - :return: x-coords, y-coords of points on the circle - """ - if connect_ends: - angle = np.linspace(0, 2 * np.pi, num_points) - else: - angle = np.linspace(0, 2 * np.pi * (1 - 1./num_points), num_points) - x_coord = np.cos(angle) * radius - y_coord = np.sin(angle) * radius - return x_coord, y_coord
- - -
[docs]@export -@jit() -def neighborSelect(a, x, y): - """ - #TODO replace by from scipy.signal import argrelextrema for speed up - >>> from scipy.signal import argrelextrema - >>> x = np.array([2, 1, 2, 3, 2, 0, 1, 0]) - >>> argrelextrema(x, np.greater) - (array([3, 6]),) - >>> y = np.array([[1, 2, 1, 2], - ... [2, 2, 0, 0], - ... [5, 3, 4, 4]]) - ... - >>> argrelextrema(y, np.less, axis=1) - (array([0, 2]), array([2, 1])) - - - finds (local) minima in a 2d grid - - :param a: 1d array of displacements from the source positions - :type a: numpy array with length numPix**2 in float - :returns: array of indices of local minima, values of those minima - :raises: AttributeError, KeyError - """ - dim = int(np.sqrt(len(a))) - values = [] - x_mins = [] - y_mins = [] - for i in range(dim + 1, len(a) - dim - 1): - if (a[i] < a[i - 1] - and a[i] < a[i + 1] - and a[i] < a[i - dim] - and a[i] < a[i + dim] - and a[i] < a[i - (dim - 1)] - and a[i] < a[i - (dim + 1)] - and a[i] < a[i + (dim - 1)] - and a[i] < a[i + (dim + 1)]): - if (a[i] < a[(i - 2 * dim - 1) % dim ** 2] - and a[i] < a[(i - 2 * dim + 1) % dim ** 2] - and a[i] < a[(i - dim - 2) % dim ** 2] - and a[i] < a[(i - dim + 2) % dim ** 2] - and a[i] < a[(i + dim - 2) % dim ** 2] - and a[i] < a[(i + dim + 2) % dim ** 2] - and a[i] < a[(i + 2 * dim - 1) % dim ** 2] - and a[i] < a[(i + 2 * dim + 1) % dim ** 2] - and a[i] < a[(i + 2 * dim) % dim ** 2] - and a[i] < a[(i - 2 * dim) % dim ** 2] - and a[i] < a[(i - 2) % dim ** 2] - and a[i] < a[(i + 2) % dim ** 2]): - x_mins.append(x[i]) - y_mins.append(y[i]) - values.append(a[i]) - return np.array(x_mins), np.array(y_mins), np.array(values)
- - -
[docs]@export -def fwhm2sigma(fwhm): - """ - - :param fwhm: full-widt-half-max value - :return: gaussian sigma (sqrt(var)) - """ - sigma = fwhm / (2 * np.sqrt(2 * np.log(2))) - return sigma
- - -
[docs]@export -def sigma2fwhm(sigma): - """ - - :param sigma: - :return: - """ - fwhm = sigma * (2 * np.sqrt(2 * np.log(2))) - return fwhm
- - -
[docs]@export -def hyper2F2_array(a, b, c, d, x): - """ - - :param a: - :param b: - :param c: - :param d: - :param x: - :return: - """ - import mpmath - - if isinstance(x, int) or isinstance(x, float): - out = mpmath.hyp2f2(a, b, c, d, x) - else: - n = len(x) - out = np.zeros(n) - for i in range(n): - out[i] = mpmath.hyp2f2(a, b, c, d, x[i]) - return out
- - -
[docs]@export -def make_subgrid(ra_coord, dec_coord, subgrid_res=2): - """ - return a grid with subgrid resolution - :param ra_coord: - :param dec_coord: - :param subgrid_res: - :return: - """ - ra_array = array2image(ra_coord) - dec_array = array2image(dec_coord) - n = len(ra_array) - d_ra_x = ra_array[0][1] - ra_array[0][0] - d_ra_y = ra_array[1][0] - ra_array[0][0] - d_dec_x = dec_array[0][1] - dec_array[0][0] - d_dec_y = dec_array[1][0] - dec_array[0][0] - - ra_array_new = np.zeros((n * subgrid_res, n * subgrid_res)) - dec_array_new = np.zeros((n * subgrid_res, n * subgrid_res)) - for i in range(0, subgrid_res): - for j in range(0, subgrid_res): - ra_array_new[i::subgrid_res, j::subgrid_res] = ra_array + d_ra_x * ( - -1 / 2. + 1 / (2. * subgrid_res) + j / float(subgrid_res)) + d_ra_y * ( - -1 / 2. + 1 / (2. * subgrid_res) + i / float( - subgrid_res)) - dec_array_new[i::subgrid_res, j::subgrid_res] = dec_array + d_dec_x * ( - -1 / 2. + 1 / (2. * subgrid_res) + j / float(subgrid_res)) + d_dec_y * ( - -1 / 2. + 1 / (2. * subgrid_res) + i / float( - subgrid_res)) - - ra_coords_sub = image2array(ra_array_new) - dec_coords_sub = image2array(dec_array_new) - return ra_coords_sub, dec_coords_sub
- - -
[docs]@export -def convert_bool_list(n, k=None): - """ - returns a bool list of the length of the lens models - if k = None: returns bool list with True's - if k is int, returns bool list with False's but k'th is True - if k is a list of int, e.g. [0, 3, 5], returns a bool list with True's in the integers listed and False elsewhere - if k is a boolean list, checks for size to match the numbers of models and returns it - - :param n: integer, total lenght of output boolean list - :param k: None, int, or list of ints - :return: bool list - """ - if k is None: - bool_list = [True] * n - elif isinstance(k, (int, np.integer)): # single integer - bool_list = [False] * n - bool_list[k] = True - elif len(k) == 0: # empty list - bool_list = [False] * n - elif isinstance(k[0], bool): - if n != len(k): - raise ValueError('length of selected lens models in format of boolean list is %s ' - 'and does not match the models of this class instance %s.' % (len(k), n)) - bool_list = k - elif isinstance(k[0], (int, np.integer)): # list of integers - bool_list = [False] * n - for i, k_i in enumerate(k): - if k_i is not False: - # if k_i is True: - # bool_list[i] = True - if k_i < n: - bool_list[k_i] = True - else: - raise ValueError("k as set by %s is not convertable in a bool string!" % k) - else: - raise ValueError('input list k as %s not compatible' % k) - return bool_list
- - -def area(vs): - """ - Use Green's theorem to compute the area enclosed by the given contour. - - param vs: 2d array of vertices of a contour line - return: area within contour line - """ - a = 0 - x0, y0 = vs[0] - for [x1, y1] in vs[1:]: - dx = x1 - x0 - dy = y1 - y0 - a += 0.5 * (y0 * dx - x0 * dy) - x0 = x1 - y0 = y1 - return abs(a) -
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Workflow/alignment_matching.html b/docs/_build/html/_modules/lenstronomy/Workflow/alignment_matching.html deleted file mode 100644 index f48540430..000000000 --- a/docs/_build/html/_modules/lenstronomy/Workflow/alignment_matching.html +++ /dev/null @@ -1,218 +0,0 @@ - - - - - - - - lenstronomy.Workflow.alignment_matching — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Workflow.alignment_matching

-__author__ = 'sibirrer'
-
-import time
-import copy
-from lenstronomy.Sampling.Pool.pool import choose_pool
-from lenstronomy.ImSim.MultiBand.single_band_multi_model import SingleBandMultiModel
-from lenstronomy.Sampling.Samplers.pso import ParticleSwarmOptimizer
-
-__all__ = ['AlignmentFitting', 'AlignmentLikelihood']
-
-
-
[docs]class AlignmentFitting(object): - """ - class which executes the different sampling methods - """ - def __init__(self, multi_band_list, kwargs_model, kwargs_params, band_index=0, likelihood_mask_list=None): - """ - initialise the classes of the chain and for parameter options - """ - self.chain = AlignmentLikelihood(multi_band_list, kwargs_model, kwargs_params, band_index, likelihood_mask_list) - -
[docs] def pso(self, n_particles=10, n_iterations=10, lowerLimit=-0.2, upperLimit=0.2, threadCount=1, mpi=False, - print_key='default'): - """ - returns the best fit for the lense model on catalogue basis with particle swarm optimizer - """ - init_pos = self.chain.get_args(self.chain.kwargs_data_init) - num_param = self.chain.num_param - lowerLimit = [lowerLimit] * num_param - upperLimit = [upperLimit] * num_param - - pool = choose_pool(mpi=mpi, processes=threadCount, use_dill=True) - - pso = ParticleSwarmOptimizer(self.chain, lowerLimit, upperLimit, - n_particles, pool=pool) - if init_pos is not None: - pso.set_global_best(init_pos, [0]*len(init_pos), - self.chain.likelihood(init_pos)) - - if pool.is_master(): - print('Computing the %s ...' % print_key) - - time_start = time.time() - - result, [chi2_list, pos_list, vel_list] = pso.optimize(n_iterations) - - kwargs_data = self.chain.update_data(result) - - if pool.is_master(): - time_end = time.time() - print("Shifts found: ", result) - print(time_end - time_start, 'time used for ', print_key) - return kwargs_data, [chi2_list, pos_list, vel_list]
- - -
[docs]class AlignmentLikelihood(object): - - def __init__(self, multi_band_list, kwargs_model, kwargs_params, band_index=0, likelihood_mask_list=None): - """ - initializes all the classes needed for the chain - """ - # print('initialized on cpu', threading.current_thread()) - self._multi_band_list = multi_band_list - self.kwargs_data_init = multi_band_list[band_index][0] - self._kwargs_data_shifted = copy.deepcopy(self.kwargs_data_init) - - self._kwargs_model = kwargs_model - self._source_marg = False - self._band_index = band_index - self._likelihood_mask_list = likelihood_mask_list - self._kwargs_params = kwargs_params - - def _likelihood(self, args): - """ - routine to compute X2 given variable parameters for a MCMC/PSO chainF - """ - # generate image and computes likelihood - multi_band_list = self.update_multi_band(args) - image_model = SingleBandMultiModel(multi_band_list, self._kwargs_model, - likelihood_mask_list=self._likelihood_mask_list, band_index=self._band_index) - logL = image_model.likelihood_data_given_model(source_marg=self._source_marg, **self._kwargs_params) - return logL - - def __call__(self, a): - return self._likelihood(a) - -
[docs] def likelihood(self, a): - return self._likelihood(a)
- -
[docs] def computeLikelihood(self, ctx): - logL, _ = self._likelihood(ctx.args2kwargs()) - return logL
- -
[docs] def setup(self): - pass
- -
[docs] def update_multi_band(self, args): - """ - - :param args: list of parameters - :return: updated multi_band_list - """ - kwargs_data = self.update_data(args) - multi_band_list = self._multi_band_list - multi_band_list[self._band_index][0] = kwargs_data - return multi_band_list
- -
[docs] def update_data(self, args): - """ - - :param args: - :return: - """ - k = 0 - kwargs_data = self._kwargs_data_shifted - kwargs_data['ra_shift'] = args[k] - kwargs_data['dec_shift'] = args[k+1] - k += 2 - return kwargs_data
- -
[docs] @staticmethod - def get_args(kwargs_data): - """ - - :param kwargs_data: - :return: - """ - args = [] - args.append(kwargs_data.get('ra_shift', 0)) - args.append(kwargs_data.get('dec_shift', 0)) - return args
- - @property - def num_param(self): - n = 2 - return n
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Workflow/fitting_sequence.html b/docs/_build/html/_modules/lenstronomy/Workflow/fitting_sequence.html deleted file mode 100644 index bd3d0cfee..000000000 --- a/docs/_build/html/_modules/lenstronomy/Workflow/fitting_sequence.html +++ /dev/null @@ -1,609 +0,0 @@ - - - - - - - - lenstronomy.Workflow.fitting_sequence — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Workflow.fitting_sequence

-from lenstronomy.Workflow.psf_fitting import PsfFitting
-from lenstronomy.Workflow.alignment_matching import AlignmentFitting
-from lenstronomy.ImSim.MultiBand.single_band_multi_model import SingleBandMultiModel
-from lenstronomy.Workflow.multi_band_manager import MultiBandUpdateManager
-from lenstronomy.Sampling.likelihood import LikelihoodModule
-from lenstronomy.Sampling.sampler import Sampler
-from lenstronomy.Sampling.Samplers.multinest_sampler import MultiNestSampler
-from lenstronomy.Sampling.Samplers.polychord_sampler import DyPolyChordSampler
-from lenstronomy.Sampling.Samplers.dynesty_sampler import DynestySampler
-import numpy as np
-import lenstronomy.Util.analysis_util as analysis_util
-
-__all__ = ['FittingSequence']
-
-
-
[docs]class FittingSequence(object): - """ - class to define a sequence of fitting applied, inherit the Fitting class - this is a Workflow manager that allows to update model configurations before executing another step in the modelling - The user can take this module as an example of how to create their own workflows or build their own around the FittingSequence - """ - def __init__(self, kwargs_data_joint, kwargs_model, kwargs_constraints, kwargs_likelihood, kwargs_params, mpi=False, - verbose=True): - """ - - :param kwargs_data_joint: keyword argument specifying the data according to LikelihoodModule - :param kwargs_model: keyword arguments to describe all model components used in - class_creator.create_class_instances() - :param kwargs_constraints: keyword arguments of the Param() class to handle parameter constraints during the - sampling (except upper and lower limits and sampling input mean and width) - :param kwargs_likelihood: keyword arguments of the Likelihood() class to handle parameters and settings of the - likelihood - :param kwargs_params: setting of the sampling bounds and initial guess mean and spread. - The argument is organized as: - 'lens_model': [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] - 'source_model': [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] - 'lens_light_model': [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] - 'point_source_model': [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] - 'extinction_model': [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] - 'special': [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] - :param mpi: MPI option (bool), if True, will launch an MPI Pool job for the steps in the fitting sequence where - possible - :param verbose: bool, if True prints temporary results and indicators of the fitting process - """ - self.kwargs_data_joint = kwargs_data_joint - self.multi_band_list = kwargs_data_joint.get('multi_band_list', []) - self.multi_band_type = kwargs_data_joint.get('multi_band_type', 'single-band') - self._verbose = verbose - self._mpi = mpi - self._updateManager = MultiBandUpdateManager(kwargs_model, kwargs_constraints, kwargs_likelihood, kwargs_params, - num_bands=len(self.multi_band_list)) - self._mcmc_init_samples = None - -
[docs] def kwargs_fixed(self): - """ - returns the updated kwargs_fixed from the update Manager - - :return: list of fixed kwargs, see UpdateManager() - """ - return self._updateManager.fixed_kwargs
- -
[docs] def fit_sequence(self, fitting_list): - """ - - :param fitting_list: list of [['string', {kwargs}], ..] with 'string being the specific fitting option and - kwargs being the arguments passed to this option - :return: fitting results - """ - chain_list = [] - for i, fitting in enumerate(fitting_list): - fitting_type = fitting[0] - kwargs = fitting[1] - - if fitting_type == 'restart': - self._updateManager.set_init_state() - - elif fitting_type == 'update_settings': - self.update_settings(**kwargs) - - elif fitting_type == 'set_param_value': - self.set_param_value(**kwargs) - - elif fitting_type == 'fix_not_computed': - self.fix_not_computed(**kwargs) - - elif fitting_type == 'psf_iteration': - #from lenstronomy.Sampling.Pool.pool import choose_pool - #pool = choose_pool(mpi=self._mpi, processes=1, use_dill=True) - #if pool.is_master(): - # self.psf_iteration(**kwargs) - self.psf_iteration(**kwargs) - - elif fitting_type == 'align_images': - self.align_images(**kwargs) - - elif fitting_type == 'PSO': - kwargs_result, chain, param = self.pso(**kwargs) - self._updateManager.update_param_state(**kwargs_result) - chain_list.append([fitting_type, chain, param]) - - elif fitting_type == 'SIMPLEX': - kwargs_result = self.simplex(**kwargs) - self._updateManager.update_param_state(**kwargs_result) - chain_list.append([fitting_type, kwargs_result]) - - elif fitting_type == 'MCMC': - if not 'init_samples' in kwargs: - kwargs['init_samples'] = self._mcmc_init_samples - elif kwargs['init_samples'] is None: - kwargs['init_samples'] = self._mcmc_init_samples - mcmc_output = self.mcmc(**kwargs) - kwargs_result = self._result_from_mcmc(mcmc_output) - self._updateManager.update_param_state(**kwargs_result) - chain_list.append(mcmc_output) - - elif fitting_type == 'nested_sampling': - ns_output = self.nested_sampling(**kwargs) - chain_list.append(ns_output) - - else: - raise ValueError("fitting_sequence %s is not supported. Please use: 'PSO', 'SIMPLEX', 'MCMC', " - "'psf_iteration', 'restart', 'update_settings' or ""'align_images'" % fitting_type) - return chain_list
- -
[docs] def best_fit(self, bijective=False): - """ - - :param bijective: bool, if True, the mapping of image2source_plane and the mass_scaling parameterisation are inverted. If you do not use those options, there is no effect. - :return: best fit model of the current state of the FittingSequence class - """ - - return self._updateManager.best_fit(bijective=bijective)
- -
[docs] def update_state(self, kwargs_update): - """ - updates current best fit state to the input model keywords specified. - - :param kwargs_update: format of kwargs_result - :return: None - """ - self._updateManager.update_param_state(**kwargs_update)
- - @property - def best_fit_likelihood(self): - """ - returns the log likelihood of the best fit model of the current state of this class - - :return: log likelihood, float - """ - kwargs_result = self.best_fit(bijective=False) - param_class = self.param_class - likelihoodModule = self.likelihoodModule - logL = likelihoodModule.logL(param_class.kwargs2args(**kwargs_result)) - return logL - - @property - def bic(self): - """ - returns the bayesian information criterion of the model. - :return: bic value, float - """ - num_data = self.likelihoodModule.num_data - num_param_nonlinear = self.param_class.num_param()[0] - num_param_linear = self.param_class.num_param_linear() - num_param = num_param_nonlinear + num_param_linear - bic = analysis_util.bic_model(self.best_fit_likelihood, num_data,num_param) - return bic - - @property - def param_class(self): - """ - - :return: Param() class instance reflecting the current state of FittingSequence - """ - return self._updateManager.param_class - - @property - def likelihoodModule(self): - """ - - :return: Likelihood() class instance reflecting the current state of FittingSequence - """ - kwargs_model = self._updateManager.kwargs_model - kwargs_likelihood = self._updateManager.kwargs_likelihood - likelihoodModule = LikelihoodModule(self.kwargs_data_joint, kwargs_model, self.param_class, **kwargs_likelihood) - return likelihoodModule - -
[docs] def simplex(self, n_iterations, method='Nelder-Mead'): - """ - Downhill simplex optimization using the Nelder-Mead algorithm. - - :param n_iterations: maximum number of iterations to perform - :param method: the optimization method used, see documentation in scipy.optimize.minimize - :return: result of the best fit - """ - - param_class = self.param_class - kwargs_temp = self._updateManager.parameter_state - init_pos = param_class.kwargs2args(**kwargs_temp) - sampler = Sampler(likelihoodModule=self.likelihoodModule) - result = sampler.simplex(init_pos, n_iterations, method) - - kwargs_result = param_class.args2kwargs(result, bijective=True) - return kwargs_result
- -
[docs] def mcmc(self, n_burn, n_run, walkerRatio, n_walkers=None, sigma_scale=1, threadCount=1, init_samples=None, - re_use_samples=True, sampler_type='EMCEE', progress=True, backup_filename=None, start_from_backup=False): - """ - MCMC routine - - :param n_burn: number of burn in iterations (will not be saved) - :param n_run: number of MCMC iterations that are saved - :param walkerRatio: ratio of walkers/number of free parameters - :param n_walkers: integer, number of walkers of emcee (optional, if set, overwrites the walkerRatio input - :param sigma_scale: scaling of the initial parameter spread relative to the width in the initial settings - :param threadCount: number of CPU threads. If MPI option is set, threadCount=1 - :param init_samples: initial sample from where to start the MCMC process - :param re_use_samples: bool, if True, re-uses the samples described in init_samples.nOtherwise starts from scratch. - :param sampler_type: string, which MCMC sampler to be used. Options are: 'EMCEE' - :param progress: boolean, if True shows progress bar in EMCEE - :return: list of output arguments, e.g. MCMC samples, parameter names, logL distances of all samples specified by the specific sampler used - """ - - param_class = self.param_class - # run PSO - mcmc_class = Sampler(likelihoodModule=self.likelihoodModule) - kwargs_temp = self._updateManager.parameter_state - mean_start = param_class.kwargs2args(**kwargs_temp) - kwargs_sigma = self._updateManager.sigma_kwargs - sigma_start = np.array(param_class.kwargs2args(**kwargs_sigma)) * sigma_scale - num_param, param_list = param_class.num_param() - if n_walkers is None: - n_walkers = num_param * walkerRatio - # run MCMC - if not init_samples is None and re_use_samples is True: - num_samples, num_param_prev = np.shape(init_samples) - if num_param_prev == num_param: - print("re-using previous samples to initialize the next MCMC run.") - idxs = np.random.choice(len(init_samples), n_walkers) - initpos = init_samples[idxs] - else: - raise ValueError("Can not re-use previous MCMC samples as number of parameters have changed!") - else: - initpos = None - - if sampler_type == 'EMCEE': - samples, dist = mcmc_class.mcmc_emcee(n_walkers, n_run, n_burn, mean_start, sigma_start, mpi=self._mpi, - threadCount=threadCount, progress=progress, initpos=initpos, - backup_filename=backup_filename, start_from_backup=start_from_backup) - output = [sampler_type, samples, param_list, dist] - else: - raise ValueError('sampler_type %s not supported!' % sampler_type) - self._mcmc_init_samples = samples # overwrites previous samples to continue from there in the next MCMC run - return output
- -
[docs] def pso(self, n_particles, n_iterations, sigma_scale=1, print_key='PSO', threadCount=1): - """ - Particle Swarm Optimization - - :param n_particles: number of particles in the Particle Swarm Optimization - :param n_iterations: number of iterations in the optimization process - :param sigma_scale: scaling of the initial parameter spread relative to the width in the initial settings - :param print_key: string, printed text when executing this routine - :param threadCount: number of CPU threads. If MPI option is set, threadCount=1 - :return: result of the best fit, the chain of the best fit parameter after each iteration, list of parameters in same order - """ - - param_class = self.param_class - kwargs_temp = self._updateManager.parameter_state - init_pos = param_class.kwargs2args(**kwargs_temp) - kwargs_sigma = self._updateManager.sigma_kwargs - sigma_start = param_class.kwargs2args(**kwargs_sigma) - lowerLimit = np.array(init_pos) - np.array(sigma_start) * sigma_scale - upperLimit = np.array(init_pos) + np.array(sigma_start) * sigma_scale - num_param, param_list = param_class.num_param() - - # run PSO - sampler = Sampler(likelihoodModule=self.likelihoodModule) - result, chain = sampler.pso(n_particles, n_iterations, lowerLimit, upperLimit, init_pos=init_pos, - threadCount=threadCount, mpi=self._mpi, print_key=print_key) - kwargs_result = param_class.args2kwargs(result, bijective=True) - return kwargs_result, chain, param_list
- -
[docs] def nested_sampling(self, sampler_type='MULTINEST', kwargs_run={}, - prior_type='uniform', width_scale=1, sigma_scale=1, - output_basename='chain', remove_output_dir=True, - dypolychord_dynamic_goal=0.8, - polychord_settings={}, - dypolychord_seed_increment=200, - output_dir="nested_sampling_chains", - dynesty_bound='multi', dynesty_sample='auto'): - """ - Run (Dynamic) Nested Sampling algorithms, depending on the type of algorithm. - - :param sampler_type: 'MULTINEST', 'DYPOLYCHORD', 'DYNESTY' - :param kwargs_run: keywords passed to the core sampling method - :param prior_type: 'uniform' of 'gaussian', for converting the unit hypercube to param cube - :param width_scale: scale the width (lower/upper limits) of the parameters space by this factor - :param sigma_scale: if prior_type is 'gaussian', scale the gaussian sigma by this factor - :param output_basename: name of the folder in which the core MultiNest/PolyChord code will save output files - :param remove_output_dir: if True, the above folder is removed after completion - :param dypolychord_dynamic_goal: dynamic goal for DyPolyChord (trade-off between evidence (0) and posterior (1) computation) - :param polychord_settings: settings dictionary to send to pypolychord. Check dypolychord documentation for details. - :param dypolychord_seed_increment: seed increment for dypolychord with MPI. Check dypolychord documentation for details. - :param dynesty_bound: see https://dynesty.readthedocs.io for details - :param dynesty_sample: see https://dynesty.readthedocs.io for details - :return: list of output arguments : samples, mean inferred values, log-likelihood, log-evidence, error on log-evidence for each sample - """ - mean_start, sigma_start = self._prepare_sampling(prior_type) - - if sampler_type == 'MULTINEST': - sampler = MultiNestSampler(self.likelihoodModule, - prior_type=prior_type, - prior_means=mean_start, - prior_sigmas=sigma_start, - width_scale=width_scale, - sigma_scale=sigma_scale, - output_dir=output_dir, - output_basename=output_basename, - remove_output_dir=remove_output_dir, - use_mpi=self._mpi) - samples, means, logZ, logZ_err, logL, results_object = sampler.run(kwargs_run) - - elif sampler_type == 'DYPOLYCHORD': - if 'resume_dyn_run' in kwargs_run and kwargs_run['resume_dyn_run'] is True: - resume_dyn_run = True - else: - resume_dyn_run = False - sampler = DyPolyChordSampler(self.likelihoodModule, - prior_type=prior_type, - prior_means=mean_start, - prior_sigmas=sigma_start, - width_scale=width_scale, - sigma_scale=sigma_scale, - output_dir=output_dir, - output_basename=output_basename, - polychord_settings=polychord_settings, - remove_output_dir=remove_output_dir, - resume_dyn_run=resume_dyn_run, - use_mpi=self._mpi) - samples, means, logZ, logZ_err, logL, results_object = sampler.run(dypolychord_dynamic_goal, kwargs_run) - - elif sampler_type == 'DYNESTY': - sampler = DynestySampler(self.likelihoodModule, - prior_type=prior_type, - prior_means=mean_start, - prior_sigmas=sigma_start, - width_scale=width_scale, - sigma_scale=sigma_scale, - bound=dynesty_bound, - sample=dynesty_sample, - use_mpi=self._mpi) - samples, means, logZ, logZ_err, logL, results_object = sampler.run(kwargs_run) - - else: - raise ValueError('Sampler type %s not supported.' % sampler_type) - # update current best fit values - self._update_state(samples[-1]) - - output = [sampler_type, samples, sampler.param_names, logL, - logZ, logZ_err, results_object] - return output
- -
[docs] def psf_iteration(self, compute_bands=None, **kwargs_psf_iter): - """ - iterative PSF reconstruction - - :param compute_bands: bool list, if multiple bands, this process can be limited to a subset of bands - :param kwargs_psf_iter: keyword arguments as used or available in PSFIteration.update_iterative() definition - :return: 0, updated PSF is stored in self.multi_band_list - """ - kwargs_model = self._updateManager.kwargs_model - kwargs_likelihood = self._updateManager.kwargs_likelihood - likelihood_mask_list = kwargs_likelihood.get('image_likelihood_mask_list', None) - kwargs_pixelbased = kwargs_likelihood.get('kwargs_pixelbased', None) - kwargs_temp = self.best_fit(bijective=False) - if compute_bands is None: - compute_bands = [True] * len(self.multi_band_list) - - for band_index in range(len(self.multi_band_list)): - if compute_bands[band_index] is True: - kwargs_psf = self.multi_band_list[band_index][1] - image_model = SingleBandMultiModel(self.multi_band_list, kwargs_model, - likelihood_mask_list=likelihood_mask_list, band_index=band_index, - kwargs_pixelbased=kwargs_pixelbased) - psf_iter = PsfFitting(image_model_class=image_model) - kwargs_psf = psf_iter.update_iterative(kwargs_psf, kwargs_params=kwargs_temp, **kwargs_psf_iter) - self.multi_band_list[band_index][1] = kwargs_psf - return 0
- -
[docs] def align_images(self, n_particles=10, n_iterations=10, lowerLimit=-0.2, upperLimit=0.2, threadCount=1, - compute_bands=None): - """ - aligns the coordinate systems of different exposures within a fixed model parameterisation by executing a PSO - with relative coordinate shifts as free parameters - - :param n_particles: number of particles in the Particle Swarm Optimization - :param n_iterations: number of iterations in the optimization process - :param lowerLimit: lower limit of relative shift - :param upperLimit: upper limit of relative shift - :param compute_bands: bool list, if multiple bands, this process can be limited to a subset of bands - :return: 0, updated coordinate system for the band(s) - """ - kwargs_model = self._updateManager.kwargs_model - kwargs_likelihood = self._updateManager.kwargs_likelihood - likelihood_mask_list = kwargs_likelihood.get('image_likelihood_mask_list', None) - kwargs_temp = self.best_fit(bijective=False) - if compute_bands is None: - compute_bands = [True] * len(self.multi_band_list) - - for i in range(len(self.multi_band_list)): - if compute_bands[i] is True: - - alignmentFitting = AlignmentFitting(self.multi_band_list, kwargs_model, kwargs_temp, band_index=i, - likelihood_mask_list=likelihood_mask_list) - - kwargs_data, chain = alignmentFitting.pso(n_particles=n_particles, n_iterations=n_iterations, - lowerLimit=lowerLimit, upperLimit=upperLimit, - threadCount=threadCount, mpi=self._mpi, - print_key='Alignment fitting for band %s ...' % i) - print('Align completed for band %s.' % i) - print('ra_shift: %s, dec_shift: %s' %(kwargs_data['ra_shift'], kwargs_data['dec_shift'])) - self.multi_band_list[i][0] = kwargs_data - return 0
- -
[docs] def update_settings(self, kwargs_model={}, kwargs_constraints={}, kwargs_likelihood={}, lens_add_fixed=[], - source_add_fixed=[], lens_light_add_fixed=[], ps_add_fixed=[], cosmo_add_fixed=[], - lens_remove_fixed=[], - source_remove_fixed=[], lens_light_remove_fixed=[], ps_remove_fixed=[], cosmo_remove_fixed=[], - change_source_lower_limit=None, change_source_upper_limit=None, - change_lens_lower_limit=None, change_lens_upper_limit=None): - """ - updates lenstronomy settings "on the fly" - - :param kwargs_model: kwargs, specified keyword arguments overwrite the existing ones - :param kwargs_constraints: kwargs, specified keyword arguments overwrite the existing ones - :param kwargs_likelihood: kwargs, specified keyword arguments overwrite the existing ones - :param lens_add_fixed: [[i_model, ['param1', 'param2',...], [...]] - :param source_add_fixed: [[i_model, ['param1', 'param2',...], [...]] - :param lens_light_add_fixed: [[i_model, ['param1', 'param2',...], [...]] - :param ps_add_fixed: [[i_model, ['param1', 'param2',...], [...]] - :param cosmo_add_fixed: ['param1', 'param2',...] - :param lens_remove_fixed: [[i_model, ['param1', 'param2',...], [...]] - :param source_remove_fixed: [[i_model, ['param1', 'param2',...], [...]] - :param lens_light_remove_fixed: [[i_model, ['param1', 'param2',...], [...]] - :param ps_remove_fixed: [[i_model, ['param1', 'param2',...], [...]] - :param cosmo_remove_fixed: ['param1', 'param2',...] - :param change_lens_lower_limit: [[i_model, ['param_name', ...], [value1, value2, ...]]] - :return: 0, the settings are overwritten for the next fitting step to come - """ - self._updateManager.update_options(kwargs_model, kwargs_constraints, kwargs_likelihood) - self._updateManager.update_fixed(lens_add_fixed, source_add_fixed, lens_light_add_fixed, - ps_add_fixed, cosmo_add_fixed, lens_remove_fixed, source_remove_fixed, - lens_light_remove_fixed, ps_remove_fixed, cosmo_remove_fixed) - self._updateManager.update_limits(change_source_lower_limit, change_source_upper_limit, change_lens_lower_limit, - change_lens_upper_limit) - return 0
- -
[docs] def set_param_value(self, **kwargs): - """ - Set a parameter to a specific value. `kwargs` are below. - :param lens: [[i_model, ['param1', 'param2',...], [...]] - :type lens: - :param source: [[i_model, ['param1', 'param2',...], [...]] - :type source: - :param lens_light: [[i_model, ['param1', 'param2',...], [...]] - :type lens_light: - :param ps: [[i_model, ['param1', 'param2',...], [...]] - :type ps: - :return: 0, the value of the param is overwritten - :rtype: - """ - self._updateManager.update_param_value(**kwargs)
- -
[docs] def fix_not_computed(self, free_bands): - """ - fixes lens model parameters of imaging bands/frames that are not computed and frees the parameters of the other - lens models to the initial kwargs_fixed options - - :param free_bands: bool list of length of imaging bands in order of imaging bands, if False: set fixed lens model - :return: None - """ - self._updateManager.fix_not_computed(free_bands=free_bands)
- - def _prepare_sampling(self, prior_type): - if prior_type == 'gaussian': - mean_start = self.param_class.kwargs2args(**self._updateManager.parameter_state) - sigma_start = self.param_class.kwargs2args(**self._updateManager.sigma_kwargs) - mean_start = np.array(mean_start) - sigma_start = np.array(sigma_start) - else: - mean_start, sigma_start = None, None - return mean_start, sigma_start - - def _update_state(self, result): - """ - - :param result: array of parameters being sampled (e.g. result of MCMC chain) - :return: None, updates the parameter state of the class instance - """ - kwargs_result = self.param_class.args2kwargs(result, bijective=True) - self._updateManager.update_param_state(**kwargs_result) - - def _result_from_mcmc(self, mcmc_output): - """ - - :param mcmc_output: list returned by self.mcmc() - :return: kwargs_result like returned by self.pso(), from best logL MCMC sample - """ - _, samples, _, logL_values = mcmc_output - return self.best_fit_from_samples(samples, logL_values) - -
[docs] def best_fit_from_samples(self, samples, logl): - """ - return best fit (max likelihood) value of samples in lenstronomy conventions - - :param samples: samples of multi-dimensional parameter space - :param logl: likelihood values for each sample - :return: kwargs_result in lenstronomy convention - """ - # get index of best logL sample - best_fit_index = np.argmax(logl) - best_fit_sample = samples[best_fit_index, :] - best_fit_result = best_fit_sample.tolist() - # get corresponding kwargs - kwargs_result = self.param_class.args2kwargs(best_fit_result, bijective=True) - return kwargs_result
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Workflow/psf_fitting.html b/docs/_build/html/_modules/lenstronomy/Workflow/psf_fitting.html deleted file mode 100644 index d1d3d9654..000000000 --- a/docs/_build/html/_modules/lenstronomy/Workflow/psf_fitting.html +++ /dev/null @@ -1,645 +0,0 @@ - - - - - - - - lenstronomy.Workflow.psf_fitting — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Workflow.psf_fitting

-from lenstronomy.Data.psf import PSF
-import lenstronomy.Util.util as util
-import lenstronomy.Util.image_util as image_util
-import lenstronomy.Util.kernel_util as kernel_util
-import lenstronomy.Util.mask_util as mask_util
-
-import numpy as np
-import copy
-import scipy.ndimage.interpolation as interp
-
-__all__ = ['PsfFitting']
-
-
-
[docs]class PsfFitting(object): - """ - class to find subsequently a better psf - The method make use of a model and subtracts all the non-point source components of the model from the data. - If the model is sufficient, then the data will be a (better) representation of the actual PSF. The method cuts out - those point sources and combines them to update the estimate of the PSF. This is done in an iterative procedure as - the model components of the extended features is PSF-dependent (hopefully not too much). - - Various options can be chosen. There is no guarantee that the method works for specific data and models. - - 'stacking_method': 'median', 'mean'; the different estimates of the PSF are stacked and combined together. The choices are: - 'mean': mean of pixel values as the estimator (not robust to outliers) - 'median': median of pixel values as the estimator (outlier rejection robust but needs >2 point sources in the data - - 'block_center_neighbour': angle, radius of neighbouring point sources around their centers the estimates is ignored. - Default is zero, meaning a not optimal subtraction of the neighbouring point sources might contaminate the estimate. - - 'keep_error_map': bool, if True, does not replace the error term associated with the PSF estimate. - If false, re-estimates the variance between the PSF estimates. - - 'psf_symmetry': number of rotational invariant symmetries in the estimated PSF. - =1 mean no additional symmetries. =4 means 90 deg symmetry. This is enforced by a rotatioanl stack according to - the symmetry specified. These additional imposed symmetries can help stabelize the PSF estimate when there are - limited constraints/number of point sources in the image. - - - The procedure only requires and changes the 'point_source_kernel' in the PSF() class and the 'psf_error_map'. - Any previously set subgrid kernels or pixel_kernels are removed and constructed from the 'point_source_kernel'. - - """ - def __init__(self, image_model_class): - self._image_model_class = image_model_class - -
[docs] def update_iterative(self, kwargs_psf, kwargs_params, num_iter=10, keep_psf_error_map=True, no_break=True, - verbose=True, **kwargs_psf_update): - """ - - :param kwargs_psf: keyword arguments to construct the PSF() class - :param kwargs_params: keyword arguments of the parameters of the model components (e.g. 'kwargs_lens' etc) - :param num_iter: number of iterations in the PSF fitting and image fitting process - :param keep_psf_error_map: boolean, if True keeps previous psf_error_map - :param no_break: boolean, if True, runs until the end regardless of the next step getting worse, and then - reads out the overall best fit - :param verbose: print statements informing about progress of iterative procedure - :param kwargs_psf_update: keyword arguments providing the settings for a single iteration of the PSF, as being - passed to update_psf() method - :return: keyword argument of PSF constructor for PSF() class with updated PSF - """ - self._image_model_class.PointSource.set_save_cache(True) - if not 'kernel_point_source_init' in kwargs_psf: - kernel_point_source_init = copy.deepcopy(kwargs_psf['kernel_point_source']) - else: - kernel_point_source_init = kwargs_psf['kernel_point_source_init'] - kwargs_psf_new = copy.deepcopy(kwargs_psf) - kwargs_psf_final = copy.deepcopy(kwargs_psf) - if 'psf_error_map' in kwargs_psf: - error_map_final = kwargs_psf['psf_error_map'] - else: - error_map_final = np.zeros_like(kernel_point_source_init) - error_map_init = copy.deepcopy(error_map_final) - psf_class = PSF(**kwargs_psf) - self._image_model_class.update_psf(psf_class) - logL_before = self._image_model_class.likelihood_data_given_model(**kwargs_params) - logL_best = copy.deepcopy(logL_before) - i_best = 0 - for i in range(num_iter): - kwargs_psf_new, logL_after, error_map = self.update_psf(kwargs_psf_new, kwargs_params, **kwargs_psf_update) - - if logL_after > logL_best: - kwargs_psf_final = copy.deepcopy(kwargs_psf_new) - error_map_final = copy.deepcopy(error_map) - logL_best = logL_after - i_best = i + 1 - else: - if not no_break: - if verbose: - print("iterative PSF reconstruction makes reconstruction worse in step %s - aborted" % i) - break - if verbose is True: - print("iteration of step %s gave best reconstruction." % i_best) - print("log likelihood before: %s and log likelihood after: %s" % (logL_before, logL_best)) - if keep_psf_error_map is True: - kwargs_psf_final['psf_error_map'] = error_map_init - else: - kwargs_psf_final['psf_error_map'] = error_map_final - kwargs_psf_final['kernel_point_source_init'] = kernel_point_source_init - return kwargs_psf_final
- -
[docs] def update_psf(self, kwargs_psf, kwargs_params, stacking_method='median', psf_symmetry=1, psf_iter_factor=.2, - block_center_neighbour=0, error_map_radius=None, block_center_neighbour_error_map=None, - new_procedure=False): - """ - - :param kwargs_psf: keyword arguments to construct the PSF() class - :param kwargs_params: keyword arguments of the parameters of the model components (e.g. 'kwargs_lens' etc) - :param stacking_method: 'median', 'mean'; the different estimates of the PSF are stacked and combined together. - The choices are: - 'mean': mean of pixel values as the estimator (not robust to outliers) - 'median': median of pixel values as the estimator (outlier rejection robust but needs >2 point sources in the data - :param psf_symmetry: number of rotational invariant symmetries in the estimated PSF. - =1 mean no additional symmetries. =4 means 90 deg symmetry. This is enforced by a rotatioanl stack according to - the symmetry specified. These additional imposed symmetries can help stabelize the PSF estimate when there are - limited constraints/number of point sources in the image. - :param psf_iter_factor: factor in (0, 1] of ratio of old vs new PSF in the update in the iteration. - :param block_center_neighbour: angle, radius of neighbouring point sources around their centers the estimates - is ignored. Default is zero, meaning a not optimal subtraction of the neighbouring point sources might - contaminate the estimate. - :param block_center_neighbour_error_map: angle, radius of neighbouring point sources around their centers the - estimates of the ERROR MAP is ignored. If None, then the value of block_center_neighbour is used (recommended) - :param error_map_radius: float, radius (in arc seconds) of the outermost error in the PSF estimate - (e.g. to avoid double counting of overlapping PSF errors), if None, all of the pixels are considered - (unless blocked through other means) - :param new_procedure: boolean, uses post lenstronomy 1.9.2 procedure which is more optimal for super-sampled PSF's - :return: kwargs_psf_new, logL_after, error_map - """ - if block_center_neighbour_error_map is None: - block_center_neighbour_error_map = block_center_neighbour - psf_class = PSF(**kwargs_psf) - kwargs_psf_copy = copy.deepcopy(kwargs_psf) - - point_source_supersampling_factor = kwargs_psf_copy.get('point_source_supersampling_factor', 1) - kwargs_psf_new = {'psf_type': 'PIXEL', 'kernel_point_source': kwargs_psf_copy['kernel_point_source'], - 'point_source_supersampling_factor': point_source_supersampling_factor, - 'psf_error_map': kwargs_psf_copy.get('psf_error_map', None)} - #if 'psf_error_map' in kwargs_psf_copy: - # kwargs_psf_new['psf_error_map'] = kwargs_psf_copy['psf_error_map'] / 10 - self._image_model_class.update_psf(PSF(**kwargs_psf_new)) - - model, error_map_image, cov_param, param = self._image_model_class.image_linear_solve(**kwargs_params) - kwargs_ps = kwargs_params.get('kwargs_ps', None) - kwargs_lens = kwargs_params.get('kwargs_lens', None) - ra_image, dec_image, point_amp = self._image_model_class.PointSource.point_source_list(kwargs_ps, kwargs_lens) - x_, y_ = self._image_model_class.Data.map_coord2pix(ra_image, dec_image) - kernel_old = psf_class.kernel_point_source - kernel_size = len(kernel_old) - - if not new_procedure: - image_single_point_source_list = self.image_single_point_source(self._image_model_class, kwargs_params) - star_cutout_list = self.point_like_source_cutouts(x_pos=x_, y_pos=y_, - image_list=image_single_point_source_list, - cutout_size=kernel_size) - psf_kernel_list = self.cutout_psf(ra_image, dec_image, x_, y_, image_single_point_source_list, kernel_size, - kernel_old, block_center_neighbour=block_center_neighbour) - - kernel_new = self.combine_psf(psf_kernel_list, kernel_old, factor=psf_iter_factor, - stacking_option=stacking_method, symmetry=psf_symmetry) - kernel_new = kernel_util.cut_psf(kernel_new, psf_size=kernel_size) - error_map = self.error_map_estimate(kernel_new, star_cutout_list, point_amp, x_, y_, - error_map_radius=error_map_radius, - block_center_neighbour=block_center_neighbour_error_map) - - if point_source_supersampling_factor > 1: - # The current version of using a super-sampled PSF in the iterative reconstruction is to first - # constrain a down-sampled version and then in a second step perform a super-sampling of it. This is not - # optimal and should be changed in the future that the corrections of the super-sampled version is done - # rather than constraining a totally new PSF first - kernel_new = kernel_util.subgrid_kernel(kernel_new, subgrid_res=point_source_supersampling_factor, - odd=True, num_iter=10) - # chop edges - n_kernel = len(kwargs_psf['kernel_point_source']) - kernel_new = kernel_util.cut_psf(kernel_new, psf_size=n_kernel) - - else: - kernel_old_high_res = psf_class.kernel_point_source_supersampled(supersampling_factor=point_source_supersampling_factor) - kernel_size_high = len(kernel_old_high_res) - data = self._image_model_class.Data.data - residuals = data - model - - psf_kernel_list = self.psf_estimate_individual(ra_image, dec_image, point_amp, residuals, - cutout_size=kernel_size, kernel_guess=kernel_old_high_res, - supersampling_factor=point_source_supersampling_factor, - block_center_neighbour=block_center_neighbour) - - kernel_new = self.combine_psf(psf_kernel_list, kernel_old_high_res, factor=psf_iter_factor, - stacking_option=stacking_method, symmetry=psf_symmetry) - kernel_new = kernel_util.cut_psf(kernel_new, psf_size=kernel_size_high) - - # resize kernel for error_map estimate - kernel_new_low = kernel_util.degrade_kernel(kernel_new, point_source_supersampling_factor) - # compute error map on pixel level - error_map = self.error_map_estimate_new(kernel_new, psf_kernel_list, ra_image, dec_image, point_amp, - point_source_supersampling_factor, - error_map_radius=error_map_radius) - - kwargs_psf_new['kernel_point_source'] = kernel_new - #if 'psf_error_map' in kwargs_psf_new: - # kwargs_psf_new['psf_error_map'] *= 10 - self._image_model_class.update_psf(PSF(**kwargs_psf_new)) - logL_after = self._image_model_class.likelihood_data_given_model(**kwargs_params) - return kwargs_psf_new, logL_after, error_map
- -
[docs] def image_single_point_source(self, image_model_class, kwargs_params): - """ - return model without including the point source contributions as a list (for each point source individually) - - :param image_model_class: ImageModel class instance - :param kwargs_params: keyword arguments of model component keyword argument lists - :return: list of images with point source isolated - """ - # reconstructed model with given psf - model, error_map, cov_param, param = image_model_class.image_linear_solve(**kwargs_params) - data = image_model_class.Data.data - mask = image_model_class.likelihood_mask - kwargs_ps = kwargs_params.get('kwargs_ps', None) - kwargs_lens = kwargs_params.get('kwargs_lens', None) - point_source_list = self._point_sources_list(image_model_class, kwargs_ps, kwargs_lens) - n = len(point_source_list) - model_single_source_list = [] - for i in range(n): - model_single_source = (data - model + point_source_list[i]) * mask - model_single_source_list.append(model_single_source) - return model_single_source_list
- - @staticmethod - def _point_sources_list(image_model_class, kwargs_ps, kwargs_lens, k=None): - """ - - :param kwargs_ps: - :return: list of images containing only single point sources - """ - point_list = [] - ra_array, dec_array, amp_array = image_model_class.PointSource.point_source_list(kwargs_ps, kwargs_lens, k=k) - for i in range(len(ra_array)): - point_source = image_model_class.ImageNumerics.point_source_rendering([ra_array[i]], [dec_array[i]], [amp_array[i]]) - point_list.append(point_source) - return point_list - -
[docs] def cutout_psf(self, ra_image, dec_image, x, y, image_list, kernel_size, kernel_init, block_center_neighbour=0): - """ - - :param ra_image: coordinate array of images in angles - :param dec_image: coordinate array of images in angles - :param x: image position array in x-pixel - :param y: image position array in y-pixel - :param image_list: list of images (i.e. data - all models subtracted, except a single point source) - :param kernel_size: width in pixel of the kernel - :param kernel_init: initial guess of kernel (pixels that are masked are replaced by those values) - :param block_center_neighbour: angle, radius of neighbouring point sources around their centers the estimates - is ignored. Default is zero, meaning a not optimal subtraction of the neighbouring point sources might - contaminate the estimate. - :return: list of de-shifted kernel estimates - """ - mask = self._image_model_class.likelihood_mask - ra_grid, dec_grid = self._image_model_class.Data.pixel_coordinates - ra_grid = util.image2array(ra_grid) - dec_grid = util.image2array(dec_grid) - radius = block_center_neighbour - - kernel_list = [] - for l in range(len(x)): - mask_point_source = self.mask_point_source(ra_image, dec_image, ra_grid, dec_grid, radius, i=l) - mask_i = mask * mask_point_source - kernel_deshifted = self.cutout_psf_single(x[l], y[l], image_list[l], mask_i, kernel_size, kernel_init) - kernel_list.append(kernel_deshifted) - return kernel_list
- -
[docs] def psf_estimate_individual(self, ra_image, dec_image, point_amp, residuals, cutout_size, kernel_guess, - supersampling_factor, block_center_neighbour): - """ - - :param ra_image: list; position in angular units of the image - :param dec_image: list; position in angular units of the image - :param point_amp: list of model amplitudes of point sources - :param residuals: data - model - :param cutout_size: pixel size of cutout around single star/quasar to be considered for the psf reconstruction - :param kernel_guess: initial guess of super-sampled PSF - :param supersampling_factor: int, super-sampling factor - :param block_center_neighbour: - :return: list of best-guess PSF's for each star based on the residual patterns - """ - mask = self._image_model_class.likelihood_mask - ra_grid, dec_grid = self._image_model_class.Data.pixel_coordinates - ra_grid = util.image2array(ra_grid) - dec_grid = util.image2array(dec_grid) - radius = block_center_neighbour - x_, y_ = self._image_model_class.Data.map_coord2pix(ra_image, dec_image) - - kernel_list = [] - for l in range(len(ra_image)): - mask_point_source = self.mask_point_source(ra_image, dec_image, ra_grid, dec_grid, radius, i=l) - mask_i = mask * mask_point_source - - # cutout residuals - x_int = int(round(x_[l])) - y_int = int(round(y_[l])) - residual_cutout = kernel_util.cutout_source(x_int, y_int, residuals, cutout_size + 2, shift=False) - # cutout the mask - mask_cutout = kernel_util.cutout_source(x_int, y_int, mask_i, cutout_size + 2, shift=False) - # apply mask - residual_cutout_mask = residual_cutout * mask_cutout - # re-scale residuals with point source brightness - residual_cutout_mask /= point_amp[l] - # enlarge residuals by super-sampling factor - residual_cutout_mask = residual_cutout_mask.repeat(supersampling_factor, axis=0).repeat(supersampling_factor, axis=1) - - # inverse shift residuals - shift_x = (x_int - x_[l]) * supersampling_factor - shift_y = (y_int - y_[l]) * supersampling_factor - # for odd number super-sampling - if supersampling_factor % 2 == 1: - residuals_shifted = interp.shift(residual_cutout_mask, [shift_y, shift_x], order=1) - - else: - # for even number super-sampling half a super-sampled pixel offset needs to be performed - residuals_shifted = interp.shift(residual_cutout_mask, [shift_y - 0.5, shift_x - 0.5], order=1) - # and the last column and row need to be removed - residuals_shifted = residuals_shifted[:-1, :-1] - - # re-size shift residuals - psf_size = len(kernel_guess) - residuals_shifted = image_util.cut_edges(residuals_shifted, psf_size) - - # normalize residuals - correction = residuals_shifted - np.mean(residuals_shifted) - # correct old PSF with inverse shifted residuals - kernel_new = kernel_guess + correction - kernel_list.append(kernel_new) - return kernel_list
- -
[docs] @staticmethod - def point_like_source_cutouts(x_pos, y_pos, image_list, cutout_size): - """ - cutouts of point-like objects - - :param x_pos: list of image positions in pixel units - :param y_pos: list of image position in pixel units - :param image_list: list of 2d numpy arrays with cleaned images, with all contaminating sources removed except - the point-like object to be cut out. - :param cutout_size: odd integer, size of cutout. - :return: list of cutouts - """ - - star_cutout_list = [] - for l in range(len(x_pos)): - x_int = int(round(x_pos[l])) - y_int = int(round(y_pos[l])) - star_cutout = kernel_util.cutout_source(x_int, y_int, image_list[l], cutout_size, shift=False) - star_cutout_list.append(star_cutout) - return star_cutout_list
- -
[docs] @staticmethod - def cutout_psf_single(x, y, image, mask, kernel_size, kernel_init): - """ - - :param x: x-coordinate of point source - :param y: y-coordinate of point source - :param image: image (i.e. data - all models subtracted, except a single point source) - :param mask: mask of pixels in the image not to be considered in the PSF estimate (being replaced by kernel_init) - :param kernel_size: width in pixel of the kernel - :param kernel_init: initial guess of kernel (pixels that are masked are replaced by those values) - :return: estimate of the PSF based on the image and position of the point source - """ - # cutout the star - x_int = int(round(x)) - y_int = int(round(y)) - star_cutout = kernel_util.cutout_source(x_int, y_int, image, kernel_size + 2, shift=False) - # cutout the mask - mask_cutout = kernel_util.cutout_source(x_int, y_int, mask, kernel_size + 2, shift=False) - # enlarge the initial PSF kernel to the new cutout size - kernel_enlarged = np.zeros((kernel_size + 2, kernel_size + 2)) - kernel_enlarged[1:-1, 1:-1] = kernel_init - # shift the initial kernel to the shift of the star - shift_x = x_int - x - shift_y = y_int - y - kernel_shifted = interp.shift(kernel_enlarged, [-shift_y, -shift_x], order=1) - # compute normalization of masked and unmasked region of the shifted kernel - # norm_masked = np.sum(kernel_shifted[mask_i == 0]) - norm_unmasked = np.sum(kernel_shifted[mask_cutout == 1]) - # normalize star within the unmasked region to the norm of the initial kernel of the same region - star_cutout /= np.sum(star_cutout[mask_cutout == 1]) * norm_unmasked - # replace mask with shifted initial kernel (+2 size) - star_cutout[mask_cutout == 0] = kernel_shifted[mask_cutout == 0] - star_cutout[star_cutout < 0] = 0 - # de-shift kernel - kernel_deshifted = kernel_util.de_shift_kernel(star_cutout, shift_x, shift_y, iterations=20, - fractional_step_size=0.1) - # re-size kernel - kernel_deshifted = image_util.cut_edges(kernel_deshifted, kernel_size) - # re-normalize kernel again - kernel_deshifted = kernel_util.kernel_norm(kernel_deshifted) - return kernel_deshifted
- -
[docs] @staticmethod - def combine_psf(kernel_list_new, kernel_old, factor=1., stacking_option='median', symmetry=1): - """ - updates psf estimate based on old kernel and several new estimates - :param kernel_list_new: list of new PSF kernels estimated from the point sources in the image (un-normalized) - :param kernel_old: old PSF kernel - :param factor: weight of updated estimate based on new and old estimate, factor=1 means new estimate, - factor=0 means old estimate - :param stacking_option: option of stacking, mean or median - :param symmetry: imposed symmetry of PSF estimate - :return: updated PSF estimate and error_map associated with it - """ - - n = int(len(kernel_list_new) * symmetry) - angle = 360. / symmetry - kernelsize = len(kernel_old) - kernel_list = np.zeros((n, kernelsize, kernelsize)) - i = 0 - for kernel_new in kernel_list_new: - for k in range(symmetry): - kernel_rotated = image_util.rotateImage(kernel_new, angle * k) - kernel_norm = kernel_util.kernel_norm(kernel_rotated) - kernel_list[i, :, :] = kernel_norm - i += 1 - - kernel_old_rotated = np.zeros((symmetry, kernelsize, kernelsize)) - for i in range(symmetry): - kernel_old_rotated[i, :, :] = kernel_old/np.sum(kernel_old) - - kernel_list_new_extended = np.append(kernel_list, kernel_old_rotated, axis=0) - if stacking_option == 'median': - kernel_new = np.median(kernel_list_new_extended, axis=0) - elif stacking_option == 'mean': - kernel_new = np.mean(kernel_list_new_extended, axis=0) - else: - raise ValueError(" stack_option must be 'median' or 'mean', %s is not supported." % stacking_option) - kernel_new = np.nan_to_num(kernel_new) - kernel_new[kernel_new < 0] = 0 - kernel_new = kernel_util.kernel_norm(kernel_new) - kernel_return = factor * kernel_new + (1.-factor) * kernel_old - return kernel_return
- -
[docs] def error_map_estimate_new(self, psf_kernel, psf_kernel_list, ra_image, dec_image, point_amp, supersampling_factor, - error_map_radius=None): - """ - relative uncertainty in the psf model (in quadrature) per pixel based on residuals achieved in the image - - :param psf_kernel: PSF kernel (super-sampled) - :param psf_kernel_list: list of individual best PSF kernel estimates - :param ra_image: image positions in angles - :param dec_image: image positions in angles - :param point_amp: image amplitude - :param supersampling_factor: super-sampling factor - :param error_map_radius: radius (in angle) to cut the error map - :return: psf error map such that square of the uncertainty gets boosted by error_map * (psf * amp)**2 - """ - kernel_low = kernel_util.degrade_kernel(psf_kernel, supersampling_factor) - error_map_list = np.zeros((len(psf_kernel_list), len(kernel_low), len(kernel_low))) - x_pos, y_pos = self._image_model_class.Data.map_coord2pix(ra_image, dec_image) - - for i, psf_kernel_i in enumerate(psf_kernel_list): - kernel_low_i = kernel_util.degrade_kernel(psf_kernel_i, supersampling_factor) - - x, y, amp_i = x_pos[i], y_pos[i], point_amp[i] - x_int = int(round(x)) - y_int = int(round(y)) - - C_D_cutout = kernel_util.cutout_source(x_int, y_int, self._image_model_class.Data.C_D, len(kernel_low_i), - shift=False) - residuals_i = np.abs(kernel_low - kernel_low_i) - residuals_i -= np.sqrt(C_D_cutout) / amp_i - residuals_i[residuals_i < 0] = 0 - error_map_list[i, :, :] = residuals_i**2 - - error_map = np.median(error_map_list, axis=0) - error_map[kernel_low > 0] /= kernel_low[kernel_low > 0] ** 2 - error_map = np.nan_to_num(error_map) - error_map[error_map > 1] = 1 # cap on error to be the same - - # mask the error map outside a certain radius (can avoid double counting of errors when map is overlapping - if error_map_radius is not None: - pixel_scale = self._image_model_class.Data.pixel_width - x_grid, y_grid = util.make_grid(numPix=len(error_map), deltapix=pixel_scale) - mask = mask_util.mask_azimuthal(x_grid, y_grid, center_x=0, center_y=0, r=error_map_radius) - error_map *= util.array2image(mask) - return error_map
- -
[docs] def error_map_estimate(self, kernel, star_cutout_list, amp, x_pos, y_pos, error_map_radius=None, - block_center_neighbour=0): - """ - provides a psf_error_map based on the goodness of fit of the given PSF kernel on the point source cutouts, - their estimated amplitudes and positions - - :param kernel: PSF kernel - :param star_cutout_list: list of 2d arrays of cutouts of the point sources with all other model components subtracted - :param amp: list of amplitudes of the estimated PSF kernel - :param x_pos: pixel position (in original data unit, not in cutout) of the point sources (same order as amp and star cutouts) - :param y_pos: pixel position (in original data unit, not in cutout) of the point sources (same order as amp and star cutouts) - :param error_map_radius: float, radius (in arc seconds) of the outermost error in the PSF estimate (e.g. to avoid double counting of overlapping PSF erros) - :param block_center_neighbour: angle, radius of neighbouring point sources around their centers the estimates - is ignored. Default is zero, meaning a not optimal subtraction of the neighbouring point sources might - contaminate the estimate. - :return: relative uncertainty in the psf model (in quadrature) per pixel based on residuals achieved in the image - """ - error_map_list = np.zeros((len(star_cutout_list), len(kernel), len(kernel))) - mask_list = np.zeros((len(star_cutout_list), len(kernel), len(kernel))) - ra_grid, dec_grid = self._image_model_class.Data.pixel_coordinates - ra_grid = util.image2array(ra_grid) - dec_grid = util.image2array(dec_grid) - mask = self._image_model_class.likelihood_mask - for i, star in enumerate(star_cutout_list): - x, y, amp_i = x_pos[i], y_pos[i], amp[i] - # shift kernel - x_int = int(round(x)) - y_int = int(round(y)) - shift_x = x_int - x - shift_y = y_int - y - kernel_shifted = interp.shift(kernel, [-shift_y, -shift_x], order=1) - # multiply kernel with amplitude - model = kernel_shifted * amp_i - # compute residuals - residual = np.abs(star - model) - # subtract background and Poisson noise residuals - C_D_cutout = kernel_util.cutout_source(x_int, y_int, self._image_model_class.Data.C_D, len(star), shift=False) - # block neighbor points in error estimate - mask_point_source = self.mask_point_source(x_pos, y_pos, ra_grid, dec_grid, radius=block_center_neighbour, - i=i) - mask_i = mask * mask_point_source - mask_i = kernel_util.cutout_source(x_int, y_int, mask_i, len(star), shift=False) - residual -= np.sqrt(C_D_cutout) - residual[residual < 0] = 0 - # estimate relative error per star - residual /= amp_i - error_map_list[i, :, :] = residual**2*mask_i - mask_list[i, :, :] = mask_i - # take median absolute error for each pixel - # TODO: only for pixels that are not masked - error_map = np.median(error_map_list, axis=0) - error_map[kernel > 0] /= kernel[kernel > 0]**2 - error_map = np.nan_to_num(error_map) - error_map[error_map > 1] = 1 # cap on error to be the same - - # mask the error map outside a certain radius (can avoid double counting of errors when map is overlapping - if error_map_radius is not None: - pixel_scale = self._image_model_class.Data.pixel_width - x_grid, y_grid = util.make_grid(numPix=len(error_map), deltapix=pixel_scale) - mask = mask_util.mask_azimuthal(x_grid, y_grid, center_x=0, center_y=0, r=error_map_radius) - error_map *= util.array2image(mask) - return error_map
- -
[docs] @staticmethod - def mask_point_source(x_pos, y_pos, x_grid, y_grid, radius, i=0): - """ - - :param x_pos: x-position of list of point sources - :param y_pos: y-position of list of point sources - :param x_grid: x-coordinates of grid - :param y_grid: y-coordinates of grid - :param i: index of point source not to mask out - :param radius: radius to mask out other point sources - :return: a mask of the size of the image with cutouts around the position - """ - mask = np.ones_like(x_grid) - for k in range(len(x_pos)): - if k != i: - mask_point = 1 - mask_util.mask_azimuthal(x_grid, y_grid, x_pos[k], y_pos[k], radius) - mask *= mask_point - return util.array2image(mask)
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_modules/lenstronomy/Workflow/update_manager.html b/docs/_build/html/_modules/lenstronomy/Workflow/update_manager.html deleted file mode 100644 index f0ebb4e0e..000000000 --- a/docs/_build/html/_modules/lenstronomy/Workflow/update_manager.html +++ /dev/null @@ -1,444 +0,0 @@ - - - - - - - - lenstronomy.Workflow.update_manager — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- -

Source code for lenstronomy.Workflow.update_manager

-import copy
-from lenstronomy.Sampling.parameters import Param
-
-__all__ = ['UpdateManager']
-
-
-
[docs]class UpdateManager(object): - """ - this class manages the parameter constraints as they may evolve through the steps of the modeling. - This includes: keeping certain parameters fixed during one modelling step - - """ - - def __init__(self, kwargs_model, kwargs_constraints, kwargs_likelihood, kwargs_params): - """ - - :param kwargs_model: keyword arguments to describe all model components used in - class_creator.create_class_instances() - :param kwargs_constraints: keyword arguments of the Param() class to handle parameter constraints during the - sampling (except upper and lower limits and sampling input mean and width) - :param kwargs_likelihood: keyword arguments of the Likelihood() class to handle parameters and settings of the - likelihood - :param kwargs_params: setting of the sampling bounds and initial guess mean and spread. - The argument is organized as: - 'lens_model': [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] - 'source_model': [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] - 'lens_light_model': [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] - 'point_source_model': [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] - 'extinction_model': [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] - 'special': [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] - - """ - self.kwargs_model = kwargs_model - self.kwargs_constraints = kwargs_constraints - self.kwargs_likelihood = kwargs_likelihood - - if kwargs_model.get('lens_model_list', None) is not None: - self._lens_init, self._lens_sigma, self._lens_fixed, self._lens_lower, self._lens_upper = kwargs_params[ - 'lens_model'] - else: - self._lens_init, self._lens_sigma, self._lens_fixed, self._lens_lower, self._lens_upper = [], [], [], [], [] - if kwargs_model.get('source_light_model_list', None) is not None: - self._source_init, self._source_sigma, self._source_fixed, self._source_lower, self._source_upper = \ - kwargs_params['source_model'] - else: - self._source_init, self._source_sigma, self._source_fixed, self._source_lower, self._source_upper = [], [], [], [], [] - if kwargs_model.get('lens_light_model_list', None) is not None: - self._lens_light_init, self._lens_light_sigma, self._lens_light_fixed, self._lens_light_lower, self._lens_light_upper = \ - kwargs_params['lens_light_model'] - else: - self._lens_light_init, self._lens_light_sigma, self._lens_light_fixed, self._lens_light_lower, self._lens_light_upper = [], [], [], [], [] - if kwargs_model.get('point_source_model_list', None) is not None: - self._ps_init, self._ps_sigma, self._ps_fixed, self._ps_lower, self._ps_upper = kwargs_params[ - 'point_source_model'] - else: - self._ps_init, self._ps_sigma, self._ps_fixed, self._ps_lower, self._ps_upper = [], [], [], [], [] - if kwargs_model.get('optical_depth_model_list', None) is not None: - self._extinction_init, self._extinction_sigma, self._extinction_fixed, self._extinction_lower, self._extinction_upper = kwargs_params[ - 'extinction_model'] - else: - self._extinction_init, self._extinction_sigma, self._extinction_fixed, self._extinction_lower, self._extinction_upper = [], [], [], [], [] - if 'special' in kwargs_params: - self._special_init, self._special_sigma, self._special_fixed, self._special_lower, self._special_upper = \ - kwargs_params['special'] - else: - self._special_init, self._special_sigma, self._special_fixed, self._special_lower, self._special_upper = {}, {}, {}, {}, {} - - self._kwargs_temp = self.init_kwargs - - # TODO: check compatibility with number of point sources provided as well as other parameter labeling - - @property - def init_kwargs(self): - """ - - :return: keyword arguments for all model components of the initial mean model proposition in the sampling - """ - return {'kwargs_lens': self._lens_init, 'kwargs_source': self._source_init, - 'kwargs_lens_light': self._lens_light_init, 'kwargs_ps': self._ps_init, - 'kwargs_special': self._special_init, 'kwargs_extinction': self._extinction_init} - - @property - def sigma_kwargs(self): - """ - - :return: keyword arguments for all model components of the initial 1-sigma width proposition in the sampling - """ - return {'kwargs_lens': self._lens_sigma, 'kwargs_source': self._source_sigma, - 'kwargs_lens_light': self._lens_light_sigma, 'kwargs_ps': self._ps_sigma, - 'kwargs_special': self._special_sigma, 'kwargs_extinction': self._extinction_sigma} - - @property - def _lower_kwargs(self): - return self._lens_lower, self._source_lower, self._lens_light_lower, self._ps_lower, self._special_lower, self._extinction_lower - - @property - def _upper_kwargs(self): - return self._lens_upper, self._source_upper, self._lens_light_upper, self._ps_upper, self._special_upper, self._extinction_upper - - @property - def fixed_kwargs(self): - return self._lens_fixed, self._source_fixed, self._lens_light_fixed, self._ps_fixed, self._special_fixed, self._extinction_fixed - -
[docs] def set_init_state(self): - """ - set the current state of the parameters to the initial one. - - :return: - """ - self._kwargs_temp = self.init_kwargs
- - @property - def parameter_state(self): - """ - - :return: parameter state saved in this class - """ - return self._kwargs_temp - -
[docs] def best_fit(self, bijective=False): - """ - best fit (max likelihood) position for all the model parameters - - :param bijective: boolean, if True, returns the parameters in the argument of the sampling that might deviate - from the convention of the ImSim module. For example, if parameterized in the image position, the parameters - remain in the image plane rather than being mapped to the source plane. - :return: kwargs_result with all the keyword arguments of the best fit for the model components - """ - lens_temp, source_temp, lens_light_temp, ps_temp, special_temp, extinction_temp = self._kwargs_temp['kwargs_lens'], \ - self._kwargs_temp['kwargs_source'], \ - self._kwargs_temp['kwargs_lens_light'], \ - self._kwargs_temp['kwargs_ps'], \ - self._kwargs_temp['kwargs_special'], \ - self._kwargs_temp['kwargs_extinction'] - if bijective is False: - lens_temp = self.param_class.update_lens_scaling(special_temp, lens_temp, inverse=False) - source_temp = self.param_class.image2source_plane(source_temp, lens_temp) - return {'kwargs_lens': lens_temp, 'kwargs_source': source_temp, 'kwargs_lens_light': lens_light_temp, - 'kwargs_ps': ps_temp, 'kwargs_special': special_temp, 'kwargs_extinction': extinction_temp}
- -
[docs] def update_param_state(self, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, - kwargs_special=None, kwargs_extinction=None): - """ - updates the temporary state of the parameters being saved. ATTENTION: Any previous knowledge gets lost if you - call this function - - :param kwargs_lens: - :param kwargs_source: - :param kwargs_lens_light: - :param kwargs_ps: - :param kwargs_special: - :param kwargs_extinction: - :return: - """ - self._kwargs_temp = {'kwargs_lens': kwargs_lens, 'kwargs_source': kwargs_source, - 'kwargs_lens_light': kwargs_lens_light, 'kwargs_ps': kwargs_ps, - 'kwargs_special': kwargs_special, 'kwargs_extinction': kwargs_extinction}
- -
[docs] def update_param_value(self, lens=None, source=None, lens_light=None, ps=None): - """ - Set a model parameter to a specific value. - - :param lens: [[i_model, ['param1', 'param2',...], [...]] - :param source: [[i_model, ['param1', 'param2',...], [...]] - :param lens_light: [[i_model, ['param1', 'param2',...], [...]] - :param ps: [[i_model, ['param1', 'param2',...], [...]] - :return: 0, the value of the param is overwritten - """ - if lens is None: - lens = [] - if source is None: - source = [] - if lens_light is None: - lens_light = [] - if ps is None: - ps = [] - for items, kwargs_key in zip([lens, source, lens_light, ps], - ['kwargs_lens', 'kwargs_source', 'kwargs_lens_light', 'kwargs_ps']): - for item in items: - index = item[0] - keys = item[1] - values = item[2] - - for key, value in zip(keys, values): - self._kwargs_temp[kwargs_key][index][key] = value
- - @property - def param_class(self): - """ - creating instance of lenstronomy Param() class. It uses the keyword arguments in self.kwargs_constraints as - __init__() arguments, as well as self.kwargs_model, and the set of kwargs_fixed___, kwargs_lower___, - kwargs_upper___ arguments for lens, lens_light, source, point source, extinction and special parameters. - - :return: instance of the Param class with the recent options and bounds - """ - kwargs_fixed_lens, kwargs_fixed_source, kwargs_fixed_lens_light, kwargs_fixed_ps, kwargs_fixed_special, kwargs_fixed_extinction = self.fixed_kwargs - kwargs_lower_lens, kwargs_lower_source, kwargs_lower_lens_light, kwargs_lower_ps, kwargs_lower_special, kwargs_lower_extinction = self._lower_kwargs - kwargs_upper_lens, kwargs_upper_source, kwargs_upper_lens_light, kwargs_upper_ps, kwargs_upper_special, kwargs_upper_extinction = self._upper_kwargs - kwargs_model = self.kwargs_model - kwargs_constraints = self.kwargs_constraints - lens_temp = self._kwargs_temp['kwargs_lens'] - param_class = Param(kwargs_model, kwargs_fixed_lens, kwargs_fixed_source, - kwargs_fixed_lens_light, kwargs_fixed_ps, kwargs_fixed_special, kwargs_fixed_extinction, - kwargs_lower_lens, kwargs_lower_source, kwargs_lower_lens_light, kwargs_lower_ps, - kwargs_lower_special, kwargs_lower_extinction, - kwargs_upper_lens, kwargs_upper_source, kwargs_upper_lens_light, kwargs_upper_ps, - kwargs_upper_special, kwargs_upper_extinction, - kwargs_lens_init=lens_temp, **kwargs_constraints) - return param_class - -
[docs] def update_options(self, kwargs_model, kwargs_constraints, kwargs_likelihood): - """ - updates the options by overwriting the kwargs with the new ones being added/changed - WARNING: some updates may not be valid depending on the model options. Use carefully! - - :param kwargs_model: keyword arguments to describe all model components used in - class_creator.create_class_instances() that are updated from previous arguments - :param kwargs_constraints: - :param kwargs_likelihood: - :return: kwargs_model, kwargs_constraints, kwargs_likelihood - """ - kwargs_model_updated = self.kwargs_model.update(kwargs_model) - kwargs_constraints_updated = self.kwargs_constraints.update(kwargs_constraints) - kwargs_likelihood_updated = self.kwargs_likelihood.update(kwargs_likelihood) - return kwargs_model_updated, kwargs_constraints_updated, kwargs_likelihood_updated
- -
[docs] def update_limits(self, change_source_lower_limit=None, change_source_upper_limit=None, - change_lens_lower_limit=None, change_lens_upper_limit=None,): - """ - updates the limits (lower and upper) of the update manager instance - - :param change_source_lower_limit: [[i_model, ['param_name', ...], [value1, value2, ...]]] - :param change_lens_lower_limit: [[i_model, ['param_name', ...], [value1, value2, ...]]] - :param change_source_upper_limit: [[i_model, ['param_name', ...], [value1, value2, ...]]] - :param change_lens_upper_limit: [[i_model, ['param_name', ...], [value1, value2, ...]]] - :return: updates internal state of lower and upper limits accessible from outside - """ - if change_source_lower_limit is not None: - self._source_lower = self._update_limit(change_source_lower_limit, self._source_lower) - if change_source_upper_limit is not None: - self._source_upper = self._update_limit(change_source_upper_limit, self._source_upper) - if change_lens_lower_limit is not None: - self._lens_lower = self._update_limit(change_lens_lower_limit, self._lens_lower) - if change_lens_upper_limit is not None: - self._lens_upper = self._update_limit(change_lens_upper_limit, self._lens_upper)
- - @staticmethod - def _update_limit(change_limit, kwargs_limit_previous): - """ - - :param change_limit: input format of def update_limits - :param kwargs_limit_previous: all limits of a model type - :return: update limits - """ - kwargs_limit_updated = copy.deepcopy(kwargs_limit_previous) - for i in range(len(change_limit)): - i_model = change_limit[i][0] - change_names = change_limit[i][1] - values = change_limit[i][2] - for j, param_name in enumerate(change_names): - kwargs_limit_updated[i_model][param_name] = values[j] - return kwargs_limit_updated - -
[docs] def update_fixed(self, lens_add_fixed=None, source_add_fixed=None, lens_light_add_fixed=None, ps_add_fixed=None, - special_add_fixed=None, lens_remove_fixed=None, source_remove_fixed=None, - lens_light_remove_fixed=None, ps_remove_fixed=None, special_remove_fixed=None): - """ - adds or removes the values of the keyword arguments that are stated in the _add_fixed to the existing fixed - arguments. convention for input arguments are: - [[i_model, ['param_name1', 'param_name2', ...], [value1, value2, ... (optional)], [], ...] - - :param lens_add_fixed: added fixed parameter in lens model - :param source_add_fixed: added fixed parameter in source model - :param lens_light_add_fixed: added fixed parameter in lens light model - :param ps_add_fixed: added fixed parameter in point source model - :param special_add_fixed: added fixed parameter in special model - :param lens_remove_fixed: remove fixed parameter in lens model - :param source_remove_fixed: remove fixed parameter in source model - :param lens_light_remove_fixed: remove fixed parameter in lens light model - :param ps_remove_fixed: remove fixed parameter in point source model - :param special_remove_fixed: remove fixed parameter in special model - :return: updated kwargs fixed - """ - lens_fixed = self._add_fixed(self._kwargs_temp['kwargs_lens'], self._lens_fixed, lens_add_fixed) - lens_fixed = self._remove_fixed(lens_fixed, lens_remove_fixed) - source_fixed = self._add_fixed(self._kwargs_temp['kwargs_source'], self._source_fixed, source_add_fixed) - source_fixed = self._remove_fixed(source_fixed, source_remove_fixed) - lens_light_fixed = self._add_fixed(self._kwargs_temp['kwargs_lens_light'], self._lens_light_fixed, lens_light_add_fixed) - lens_light_fixed = self._remove_fixed(lens_light_fixed, lens_light_remove_fixed) - ps_fixed = self._add_fixed(self._kwargs_temp['kwargs_ps'], self._ps_fixed, ps_add_fixed) - ps_fixed = self._remove_fixed(ps_fixed, ps_remove_fixed) - special_fixed = copy.deepcopy(self._special_fixed) - special_temp = self._kwargs_temp['kwargs_special'] - if special_add_fixed is None: - special_add_fixed = [] - for param_name in special_add_fixed: - if param_name in special_fixed: - pass - else: - special_fixed[param_name] = special_temp[param_name] - if special_remove_fixed is None: - special_remove_fixed = [] - for param_name in special_remove_fixed: - if param_name in special_fixed: - del special_fixed[param_name] - self._lens_fixed, self._source_fixed, self._lens_light_fixed, self._ps_fixed, self._special_fixed = lens_fixed, source_fixed, lens_light_fixed, ps_fixed, special_fixed
- - @staticmethod - def _add_fixed(kwargs_model, kwargs_fixed, add_fixed): - """ - - :param kwargs_model: model parameters - :param kwargs_fixed: parameters that are held fixed (even before) - :param add_fixed: additional fixed parameters - [[i_model, ['param_name1', 'param_name2', ...], [value1, value2, ... (optional)], [], ...] - :return: updated kwargs_fixed - """ - if add_fixed is None: - add_fixed = [] - # fixed_kwargs = copy.deepcopy(kwargs_fixed) - for i in range(len(add_fixed)): - i_model = add_fixed[i][0] - fix_names = add_fixed[i][1] - if len(add_fixed[i]) > 2: - values = add_fixed[i][2] - else: - values = [None] * len(fix_names) - for j, param_name in enumerate(fix_names): - if values[j] is None: - kwargs_fixed[i_model][param_name] = kwargs_model[i_model][param_name] # add fixed list - else: - kwargs_fixed[i_model][param_name] = values[j] - return kwargs_fixed - - @staticmethod - def _remove_fixed(kwargs_fixed, remove_fixed): - """ - - :param kwargs_fixed: fixed parameters (before) - :param remove_fixed: list of parameters to be removed from the fixed list and initialized by the valuye of - kwargs_model [[i_model, ['param_name1', 'param_name2', ...]], [], ...] - :return: updated kwargs fixed parameters - """ - if remove_fixed is None: - remove_fixed = [] - for i in range(len(remove_fixed)): - i_model = remove_fixed[i][0] - fix_names = remove_fixed[i][1] - for param_name in fix_names: - if param_name in kwargs_fixed[i_model]: # if the parameter already is in the fixed list, do not change it - del kwargs_fixed[i_model][param_name] - return kwargs_fixed - -
[docs] def fix_image_parameters(self, image_index=0): - """ - fixes all parameters that are only assigned to a specific image. This allows to sample only parameters that - constraint by the fitting of a sub-set of the images. - - :param image_index: index - :return: None - """ - pass
-
- -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/_sources/installation.rst.txt b/docs/_build/html/_sources/installation.rst.txt deleted file mode 100644 index 9d5cc4fdc..000000000 --- a/docs/_build/html/_sources/installation.rst.txt +++ /dev/null @@ -1,93 +0,0 @@ -============ -Installation -============ - -This page outlines how to install one of the officially distributed lenstronomy releases and its dependencies, -or install and test the latest development version. - -From PyPI ---------- - -All lenstronomy releases are distributed through the Python Package Index (PyPI). To install the latest version use pip: - -At the command line with pip:: - - $ pip install lenstronomy - -Or, if you have virtualenvwrapper installed:: - - $ mkvirtualenv lenstronomy - $ pip install lenstronomy - -From conda-forge ----------------- - -All lenstronomy releases are also distributed for conda through the conda-forge channel. To install the latest version for your active conda environment:: - - $ conda install -c conda-forge lenstronomy - - -You can also clone the github repository for development purposes. - - -Requirements ------------- - -Make sure the standard python libraries as specified in the `requirements `_. -The standard usage does not require all libraries to be installed, in particular the different posterior samplers are only required when being used. - -In the following, a few specific cases are mentioned that may require special attention in the installation and settings, in particular when it comes -to MPI and HPC applications. - - -MPI ---- -MPI support is provided for several sampling techniques for parallel computing. A specific version of the library schwimmbad is required -for the correct support of the moving of the likelihood elements from one processor to another with MPI. Pay attention ot the -`requirements `_. - - -NUMBA ------ -Just-in-time (jit) compilation with numba can provide significant speed-up for certain calculations. -There are specific settings for the settings provided as per default, but these may need to be adopted when running on a HPC cluster. -You can define your own configuration file in your $XDG_CONFIG_HOME/lenstronomy/config.yaml file. E.g. (check your system for the path):: - - $ ~/.conf/lenstronomy/config.yaml - -following the format of the default configuration which is `here `_. - - -FASTELL -------- -The fastell4py package, originally from Barkana (fastell), is required to run the PEMD (power-law elliptical mass distribution) lens model -and can be cloned from: `https://github.com/sibirrer/fastell4py `_ (needs a fortran compiler). -We recommend using the EPL model as it is a pure python version of the same profile. - -.. code-block:: bash - - $ sudo apt-get install gfortran - $ git clone https://github.com/sibirrer/fastell4py.git - $ cd - $ python setup.py install --user - - -Check installation by running tests ------------------------------------ - -You can check your installation with pytest:: - - $ cd - $ py.test - -Or you can run a partial test with:: - - $ cd - $ py.test/test/test_LensModel/ - -You can also run the tests with tox in a virtual environment with:: - - $ cd - $ tox - -Note: tox might have trouble with the PyMultiNest installation and the cmake part of it. diff --git a/docs/_build/html/_static/documentation_options.js b/docs/_build/html/_static/documentation_options.js deleted file mode 100644 index a2ceafbb4..000000000 --- a/docs/_build/html/_static/documentation_options.js +++ /dev/null @@ -1,12 +0,0 @@ -var DOCUMENTATION_OPTIONS = { - URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), - VERSION: '1.10.3', - LANGUAGE: 'None', - COLLAPSE_INDEX: false, - BUILDER: 'html', - FILE_SUFFIX: '.html', - LINK_SUFFIX: '.html', - HAS_SOURCE: true, - SOURCELINK_SUFFIX: '.txt', - NAVIGATION_WITH_KEYS: false -}; \ No newline at end of file diff --git a/docs/_build/html/affiliatedpackages.html b/docs/_build/html/affiliatedpackages.html deleted file mode 100644 index 5646ec4fd..000000000 --- a/docs/_build/html/affiliatedpackages.html +++ /dev/null @@ -1,144 +0,0 @@ - - - - - - - - - Affiliated packages — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

Affiliated packages

-

Here is an (incomplete) list of packages and wrappers that are using lenstronomy in various ways for specific scientific -applications:

-
    -
  • baobab: Training data generator for hierarchically modeling of strong lenses with Bayesian neural networks.

  • -
  • dolphin: Automated pipeline for lens modeling based on lenstronomy.

  • -
  • hierArc: Hierarchical Bayesian time-delay cosmography to infer the Hubble constant and galaxy density profiles in conjunction with lenstronomy.

  • -
  • lenstruction: Versatile tool for cluster source reconstruction and local perturbative lens modeling.

  • -
  • SLITronomy: Updated and improved version of the Sparse Lens Inversion Technique (SLIT), developed within the framework of lenstronomy.

  • -
  • LSSTDESC SLSprinkler: The DESC SL (Strong Lensing) Sprinkler adds strongly lensed AGN and SNe to simulated catalogs and generates postage stamps for these systems.

  • -
  • lensingGW: A Python package designed to handle both strong and microlensing of compact binaries and the related gravitational-wave signals.

  • -
  • ovejero: Conducts hierarchical inference of strongly-lensed systems with Bayesian neural networks.

  • -
  • h0rton: H0 inferences with Bayesian neural network lens modeling.

  • -
  • deeplenstronomy: Tool for simulating large datasets for applying deep learning to strong gravitational lensing.

  • -
  • pyHalo: Tool for rendering full substructure mass distributions for gravitational lensing simulations.

  • -
  • GaLight: Tool to perform two-dimensional model fitting of optical and near-infrared images to characterize surface brightness distributions.

  • -
  • paltas: Package for conducting simulation-based inference on strong gravitational lensing images.

  • -
  • LensingETC: A Python package to select an optimal observing strategy for multi-filter imaging campaigns of strong lensing systems. This package simulates imaging data corresponding to provided instrument specifications and extract lens model parameter uncertainties from the simulated images.

  • -
-

These packages come with their own documentation and examples - so check them out!

-
-

Guidelines for affiliated packages

-

If you have a package/wrapper/analysis pipeline that is open source and you would like to have it advertised here, please let the developers know! -Before you write your own wrapper and scripts in executing lenstronomy for your purpose check out the list -of existing add-on packages. Affiliated packages should not duplicate the core routines of lenstronomy and whenever possible make use of the lenstronomy modules. -The packages should be maintained to keep up with the development of lenstronomy. Please also make sure the citation guidelines are presented.

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/authors.html b/docs/_build/html/authors.html deleted file mode 100644 index 93ba6fbc4..000000000 --- a/docs/_build/html/authors.html +++ /dev/null @@ -1,166 +0,0 @@ - - - - - - - - - Credits — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

Credits

-
-

Development Lead

- -
-
-

Key contributors

- -
-
-

Contributors (alphabetic)

- -
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/contributing.html b/docs/_build/html/contributing.html deleted file mode 100644 index c6d4ef5b6..000000000 --- a/docs/_build/html/contributing.html +++ /dev/null @@ -1,258 +0,0 @@ - - - - - - - - - Contributing to lenstronomy — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

Contributing to lenstronomy

-
-

Contributing to lenstronomy

-
-

GitHub Workflow

-

### Fork and Clone the lenstronomy Repository -You should only need to do this step once

-

First fork the lenstronomy repository. A fork is your own remote copy of the repository on GitHub. To create a fork:

-
-
    -
  1. Go to the [lenstronomy GitHub Repository](https://github.com/sibirrer/lenstronomy)

  2. -
  3. Click the Fork button (in the top-right-hand corner)

  4. -
  5. Choose where to create the fork, typically your personal GitHub account

  6. -
-
-

Next clone your fork. Cloning creates a local copy of the repository on your computer to work with. To clone your fork:

-
-

`bash -git clone https://github.com/<your-account>/lenstronomy.git -`

-
-

Finally add the lenstronomy repository as a remote. This will allow you to fetch changes made to the codebase. To add the skypyproject remote:

-
-

`bash -cd lenstronomy -git remote add lenstronomyproject https://github.com/sibirrer/lenstronomy.git -`

-
-

### Install your local lenstronomy version

-

To enable that your new code gets accessible by python also outside of the development environment, -make sure all previous versions of lenstronomy are uninstalled and then install your version of lenstronomy (aka add the software to the python path)

-
-

`bash -cd lenstronomy -python setup.py develop --user -`

-
-

Alternatively, create virtual environments for the development (recommended for advanced usage with multiple branches).

-

### Create a branch for your new feature

-

Create a branch off the lenstronomyproject main branch. Working on unique branches for each new feature simplifies the development, review and merge processes by maintining logical separation. To create a feature branch:

-
-

`bash -git fetch lenstronomyproject -git checkout -b <your-branch-name> lenstronomyproject/main -`

-
-

### Hack away!

-

Write the new code you would like to contribute and commit it to the feature branch on your local repository. Ideally commit small units of work often with clear and descriptive commit messages describing the changes you made. To commit changes to a file:

-
-

`bash -git add file_containing_your_contribution -git commit -m 'Your clear and descriptive commit message' -`

-
-

Push the contributions in your feature branch to your remote fork on GitHub:

-
-

`bash -git push origin <your-branch-name> -`

-
-

Note: The first time you push a feature branch you will probably need to use –set-upstream origin to link to your remote fork:

-
-

`bash -git push --set-upstream origin <your-branch-name> -`

-
-

### Open a Pull Request

-

When you feel that work on your new feature is complete, you should create a Pull Request. This will propose your work to be merged into the main lenstronomy repository.

-
-
    -
  1. Go to [lenstronomy Pull Requests](https://github.com/sibirrer/lenstronomy/pulls)

  2. -
  3. Click the green New pull request button

  4. -
  5. Click compare across forks

  6. -
  7. Confirm that the base fork is sibirrer/lenstronomy and the base branch is main

  8. -
  9. Confirm the head fork is <your-account>/lenstronomy and the compare branch is <your-branch-name>

  10. -
  11. Give your pull request a title and fill out the the template for the description

  12. -
  13. Click the green Create pull request button

  14. -
-
-

### Updating your branch

-

As you work on your feature, new commits might be made to the sibirrer/lenstronomy main branch. You will need to update your branch with these new commits before your pull request can be accepted. You can achieve this in a few different ways:

-
-
    -
  • If your pull request has no conflicts, click Update branch

  • -
  • If your pull request has conflicts, click Resolve conflicts, manually resolve the conflicts and click Mark as resolved

  • -
  • merge the lenstronomyproject main branch from the command line: -`bash -git fetch lenstronomyproject -git merge lenstronomyproject/main -`

  • -
  • rebase your feature branch onto the lenstronomy main branch from the command line: -`bash -git fetch lenstronomyproject -git rebase lenstronomyproject/main -`

  • -
-
-

Warning: It is bad practice to rebase commits that have already been pushed to a remote such as your fork. Rebasing creates new copies of your commits that can cause the local and remote branches to diverge. git push –force will overwrite the remote branch with your newly rebased local branch. This is strongly discouraged, particularly when working on a shared branch where you could erase a collaborators commits.

-
-
For more information about resolving conflicts see the GitHub guides:
-
-
-

### More Information

-

More information regarding the usage of GitHub can be found in the [GitHub Guides](https://guides.github.com/).

-
-
-

Coding Guidelines

-

Before your pull request can be merged into the codebase, it will be reviewed by one of the lenstronomy developers and required to pass a number of automated checks. Below are a minimum set of guidelines for developers to follow:

-

### General Guidelines

- -

### Unit Tests

-

Pull requests will require existing unit tests to pass before they can be merged. Additionally, new unit tests should be written for all new public methods and functions. Unit tests for each submodule are contained in subdirectories called tests and you can run them locally using python setup.py test. For more information see the [Astropy Testing Guidelines](https://docs.astropy.org/en/stable/development/testguide.html).

-

### Docstrings

-

All public classes, methods and functions require docstrings. You can build documentation locally by installing [sphinx-astropy](https://github.com/astropy/sphinx-astropy) and calling python setup.py build_docs. Docstrings should include the following sections:

-
-
    -
  • Description

  • -
  • Parameters

  • -
  • Notes

  • -
  • Examples

  • -
  • References

  • -
-
-

For more information see the Astropy guide to [Writing Documentation](https://docs.astropy.org/en/stable/development/docguide.html).

-

This page is inspired by the Contributions guidelines of the [Skypy project](https://github.com/skypyproject/skypy/blob/main/CONTRIBUTING.md).

-
-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/genindex.html b/docs/_build/html/genindex.html deleted file mode 100644 index d13b6fce0..000000000 --- a/docs/_build/html/genindex.html +++ /dev/null @@ -1,6138 +0,0 @@ - - - - - - - - Index — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - -
-
-
-
- - -

Index

- -
- A - | B - | C - | D - | E - | F - | G - | H - | I - | J - | K - | L - | M - | N - | O - | P - | R - | S - | T - | U - | V - | W - | X - | Z - -
-

A

- - - -
- -

B

- - - -
- -

C

- - - -
- -

D

- - - -
- -

E

- - - -
- -

F

- - - -
- -

G

- - - -
- -

H

- - - -
- -

I

- - - -
- -

J

- - - -
- -

K

- - - -
- -

L

- - - -
    -
  • LCDM (class in lenstronomy.Cosmo.lcdm) -
  • -
  • lens_light_model_class (lenstronomy.SimulationAPI.model_api.ModelAPI property) -
  • -
  • lens_model_class (lenstronomy.SimulationAPI.model_api.ModelAPI property) -
  • -
  • lens_model_plot() (in module lenstronomy.Plots.lens_plot) -
  • -
  • lens_surface_brightness() (lenstronomy.ImSim.image_model.ImageModel method) -
  • -
  • LensCosmo (class in lenstronomy.Cosmo.lens_cosmo) -
  • -
  • LensedLocation (class in lenstronomy.LensModel.MultiPlane.multi_plane) -
  • -
  • LensedPositions (class in lenstronomy.PointSource.Types.lensed_position) -
  • -
  • LensEquationSolver (class in lenstronomy.LensModel.Solver.lens_equation_solver) -
  • -
  • LensModel (class in lenstronomy.LensModel.lens_model) -
  • -
  • LensModelExtensions (class in lenstronomy.LensModel.lens_model_extensions) -
  • -
  • LensParam (class in lenstronomy.LensModel.lens_param) -
  • -
  • LensProfileAnalysis (class in lenstronomy.Analysis.lens_profile) -
  • -
  • LensProfileBase (class in lenstronomy.LensModel.Profiles.base_profile) -
  • -
  • - lenstronomy - -
  • -
  • - lenstronomy.Analysis - -
  • -
  • - lenstronomy.Analysis.kinematics_api - -
  • -
  • - lenstronomy.Analysis.lens_profile - -
  • -
  • - lenstronomy.Analysis.light2mass - -
  • -
  • - lenstronomy.Analysis.light_profile - -
  • -
  • - lenstronomy.Analysis.td_cosmography - -
  • -
  • - lenstronomy.Conf - -
  • -
  • - lenstronomy.Conf.config_loader - -
  • -
  • - lenstronomy.Cosmo - -
  • -
  • - lenstronomy.Cosmo.background - -
  • -
  • - lenstronomy.Cosmo.cosmo_solver - -
  • -
  • - lenstronomy.Cosmo.kde_likelihood - -
  • -
  • - lenstronomy.Cosmo.lcdm - -
  • -
  • - lenstronomy.Cosmo.lens_cosmo - -
  • -
  • - lenstronomy.Cosmo.nfw_param - -
  • -
  • - lenstronomy.Data - -
  • -
  • - lenstronomy.Data.coord_transforms - -
  • -
  • - lenstronomy.Data.imaging_data - -
  • -
  • - lenstronomy.Data.psf - -
  • -
  • - lenstronomy.GalKin - -
  • -
  • - lenstronomy.GalKin.analytic_kinematics - -
  • -
  • - lenstronomy.GalKin.anisotropy - -
  • -
  • - lenstronomy.GalKin.aperture - -
  • -
  • - lenstronomy.GalKin.aperture_types - -
  • -
  • - lenstronomy.GalKin.cosmo - -
  • -
  • - lenstronomy.GalKin.galkin - -
  • -
  • - lenstronomy.GalKin.galkin_model - -
  • -
  • - lenstronomy.GalKin.light_profile - -
  • -
  • - lenstronomy.GalKin.numeric_kinematics - -
  • -
  • - lenstronomy.GalKin.observation - -
  • -
  • - lenstronomy.GalKin.psf - -
  • -
  • - lenstronomy.GalKin.velocity_util - -
  • -
  • - lenstronomy.ImSim - -
  • -
  • - lenstronomy.ImSim.de_lens - -
  • -
  • - lenstronomy.ImSim.image2source_mapping - -
  • -
  • - lenstronomy.ImSim.image_linear_solve - -
  • -
  • - lenstronomy.ImSim.image_model - -
  • -
  • - lenstronomy.ImSim.MultiBand - -
  • -
  • - lenstronomy.ImSim.MultiBand.joint_linear - -
  • -
  • - lenstronomy.ImSim.MultiBand.multi_data_base - -
  • -
  • - lenstronomy.ImSim.MultiBand.multi_linear - -
  • -
  • - lenstronomy.ImSim.MultiBand.single_band_multi_model - -
  • -
  • - lenstronomy.ImSim.Numerics - -
  • -
  • - lenstronomy.ImSim.Numerics.adaptive_numerics - -
  • -
  • - lenstronomy.ImSim.Numerics.convolution - -
  • -
  • - lenstronomy.ImSim.Numerics.grid - -
  • -
  • - lenstronomy.ImSim.Numerics.numba_convolution - -
  • -
  • - lenstronomy.ImSim.Numerics.numerics - -
  • -
  • - lenstronomy.ImSim.Numerics.partial_image - -
  • -
  • - lenstronomy.ImSim.Numerics.point_source_rendering - -
  • -
  • - lenstronomy.LensModel - -
  • -
  • - lenstronomy.LensModel.convergence_integrals - -
  • -
  • - lenstronomy.LensModel.lens_model - -
  • -
  • - lenstronomy.LensModel.lens_model_extensions - -
  • -
  • - lenstronomy.LensModel.lens_param - -
  • -
  • - lenstronomy.LensModel.LightConeSim - -
  • -
  • - lenstronomy.LensModel.LightConeSim.light_cone - -
  • -
  • - lenstronomy.LensModel.MultiPlane - -
  • -
  • - lenstronomy.LensModel.MultiPlane.multi_plane - -
  • -
  • - lenstronomy.LensModel.MultiPlane.multi_plane_base - -
  • -
  • - lenstronomy.LensModel.profile_integrals - -
  • -
  • - lenstronomy.LensModel.profile_list_base - -
  • -
  • - lenstronomy.LensModel.Profiles - -
  • -
  • - lenstronomy.LensModel.Profiles.arc_perturbations - -
  • -
  • - lenstronomy.LensModel.Profiles.base_profile - -
  • -
  • - lenstronomy.LensModel.Profiles.chameleon - -
  • -
  • - lenstronomy.LensModel.Profiles.cnfw - -
  • -
  • - lenstronomy.LensModel.Profiles.cnfw_ellipse - -
  • -
  • - lenstronomy.LensModel.Profiles.const_mag - -
  • -
  • - lenstronomy.LensModel.Profiles.constant_shift - -
  • -
  • - lenstronomy.LensModel.Profiles.convergence - -
  • -
  • - lenstronomy.LensModel.Profiles.coreBurkert - -
  • -
  • - lenstronomy.LensModel.Profiles.cored_density - -
  • -
  • - lenstronomy.LensModel.Profiles.cored_density_2 - -
  • -
  • - lenstronomy.LensModel.Profiles.cored_density_exp - -
  • -
  • - lenstronomy.LensModel.Profiles.cored_density_mst - -
  • -
  • - lenstronomy.LensModel.Profiles.curved_arc_const - -
  • -
  • - lenstronomy.LensModel.Profiles.curved_arc_sis_mst - -
  • -
  • - lenstronomy.LensModel.Profiles.curved_arc_spp - -
  • -
  • - lenstronomy.LensModel.Profiles.curved_arc_spt - -
  • -
  • - lenstronomy.LensModel.Profiles.curved_arc_tan_diff - -
  • -
  • - lenstronomy.LensModel.Profiles.dipole - -
  • -
  • - lenstronomy.LensModel.Profiles.elliptical_density_slice - -
  • -
  • - lenstronomy.LensModel.Profiles.epl - -
  • -
  • - lenstronomy.LensModel.Profiles.epl_numba - -
  • -
  • - lenstronomy.LensModel.Profiles.flexion - -
  • -
  • - lenstronomy.LensModel.Profiles.flexionfg - -
  • -
  • - lenstronomy.LensModel.Profiles.gauss_decomposition - -
  • -
  • - lenstronomy.LensModel.Profiles.gaussian_ellipse_kappa - -
  • -
  • - lenstronomy.LensModel.Profiles.gaussian_ellipse_potential - -
  • -
  • - lenstronomy.LensModel.Profiles.gaussian_kappa - -
  • -
  • - lenstronomy.LensModel.Profiles.gaussian_potential - -
  • -
  • - lenstronomy.LensModel.Profiles.hernquist - -
  • -
  • - lenstronomy.LensModel.Profiles.hernquist_ellipse - -
  • -
  • - lenstronomy.LensModel.Profiles.hessian - -
  • -
  • - lenstronomy.LensModel.Profiles.interpol - -
  • -
  • - lenstronomy.LensModel.Profiles.multi_gaussian_kappa - -
  • -
  • - lenstronomy.LensModel.Profiles.multipole - -
  • -
  • - lenstronomy.LensModel.Profiles.nfw - -
  • -
  • - lenstronomy.LensModel.Profiles.nfw_ellipse - -
  • -
  • - lenstronomy.LensModel.Profiles.nfw_mass_concentration - -
  • -
  • - lenstronomy.LensModel.Profiles.nfw_vir_trunc - -
  • -
  • - lenstronomy.LensModel.Profiles.nie - -
  • -
  • - lenstronomy.LensModel.Profiles.nie_potential - -
  • -
  • - lenstronomy.LensModel.Profiles.numerical_deflections - -
  • -
  • - lenstronomy.LensModel.Profiles.p_jaffe - -
  • -
  • - lenstronomy.LensModel.Profiles.p_jaffe_ellipse - -
  • -
  • - lenstronomy.LensModel.Profiles.pemd - -
  • -
  • - lenstronomy.LensModel.Profiles.point_mass - -
  • -
  • - lenstronomy.LensModel.Profiles.sersic - -
  • -
  • - lenstronomy.LensModel.Profiles.sersic_ellipse_kappa - -
  • -
  • - lenstronomy.LensModel.Profiles.sersic_ellipse_potential - -
  • -
  • - lenstronomy.LensModel.Profiles.sersic_utils - -
  • -
  • - lenstronomy.LensModel.Profiles.shapelet_pot_cartesian - -
  • -
  • - lenstronomy.LensModel.Profiles.shapelet_pot_polar - -
  • -
  • - lenstronomy.LensModel.Profiles.shear - -
  • -
  • - lenstronomy.LensModel.Profiles.sie - -
  • -
  • - lenstronomy.LensModel.Profiles.sis - -
  • -
  • - lenstronomy.LensModel.Profiles.sis_truncate - -
  • -
  • - lenstronomy.LensModel.Profiles.spemd - -
  • -
  • - lenstronomy.LensModel.Profiles.spep - -
  • -
  • - lenstronomy.LensModel.Profiles.splcore - -
  • -
  • - lenstronomy.LensModel.Profiles.spp - -
  • -
  • - lenstronomy.LensModel.Profiles.tnfw - -
  • -
  • - lenstronomy.LensModel.Profiles.uldm - -
  • -
  • - lenstronomy.LensModel.QuadOptimizer - -
  • -
  • - lenstronomy.LensModel.QuadOptimizer.multi_plane_fast - -
  • -
  • - lenstronomy.LensModel.QuadOptimizer.optimizer - -
  • -
  • - lenstronomy.LensModel.QuadOptimizer.param_manager - -
  • -
  • - lenstronomy.LensModel.single_plane - -
  • -
  • - lenstronomy.LensModel.Solver - -
  • -
  • - lenstronomy.LensModel.Solver.lens_equation_solver - -
  • -
  • - lenstronomy.LensModel.Solver.solver - -
  • -
  • - lenstronomy.LensModel.Solver.solver2point - -
  • -
  • - lenstronomy.LensModel.Solver.solver4point - -
  • -
  • - lenstronomy.LensModel.Util - -
  • -
  • - lenstronomy.LensModel.Util.epl_util - -
  • -
  • - lenstronomy.LightModel - -
  • -
  • - lenstronomy.LightModel.light_model - -
  • -
  • - lenstronomy.LightModel.light_param - -
  • -
  • - lenstronomy.LightModel.Profiles - -
  • -
  • - lenstronomy.LightModel.Profiles.chameleon - -
  • -
- -

M

- - - -
- -

N

- - - -
- -

O

- - - -
- -

P

- - - -
- -

R

- - - -
- -

S

- - - -
- -

T

- - - -
- -

U

- - -
- -

V

- - - -
- -

W

- - - -
- -

X

- - -
- -

Z

- - -
- - - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/history.html b/docs/_build/html/history.html deleted file mode 100644 index e063cf384..000000000 --- a/docs/_build/html/history.html +++ /dev/null @@ -1,512 +0,0 @@ - - - - - - - - - History — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

History

-
-

0.0.1 (2018-01-09)

-
    -
  • First release on PyPI.

  • -
-
-
-

0.0.2 (2018-01-16)

-
    -
  • Improved testing and stability

  • -
-
-
-

0.0.6 (2018-01-29)

-
    -
  • Added feature to align coordinate system of different images

  • -
-
-
-

0.1.0 (2018-02-25)

-
    -
  • Major design update

  • -
-
-
-

0.1.1 (2018-03-05)

-
    -
  • minor update to facilitate options without lensing

  • -
-
-
-

0.2.0 (2018-03-10)

-
    -
  • ellipticity parameter handling changed

  • -
  • time-delay distance sampling included

  • -
  • parameter handling for sampling more flexible

  • -
  • removed redundancies in the light and mass profiles

  • -
-
-
-

0.2.1 (2018-03-19)

-
    -
  • updated documentation

  • -
  • improved sub-sampling of the PSF

  • -
-
-
-

0.2.2 (2018-03-25)

-
    -
  • improved parameter handling

  • -
  • minor bugs with parameter handling fixed

  • -
-
-
-

0.2.8 (2018-05-31)

-
    -
  • improved GalKin module

  • -
  • minor improvements in PSF reconstruction

  • -
  • mass-to-light ratio parameterization

  • -
-
-
-

0.3.1 (2018-07-21)

-
    -
  • subgrid psf sampling for inner parts of psf exclusively

  • -
  • minor stability improvements

  • -
  • cleaner likelihood definition

  • -
  • additional Chameleon lens and light profiles

  • -
-
-
-

0.3.3 (2018-08-21)

-
    -
  • minor updates, better documentation and handling of parameters

  • -
-
-
-

0.4.1-3 (2018-11-27)

-
    -
  • various multi-band modelling frameworks added

  • -
  • lens models added

  • -
  • Improved fitting sequence, solver and psf iteration

  • -
-
-
-

0.5.0 (2019-1-30)

-
    -
  • Workflow module redesign

  • -
  • improved parameter handling

  • -
  • improved PSF subsampling module

  • -
  • relative astrometric precision of point sources implemented

  • -
-
-
-

0.6.0 (2019-2-26)

-
    -
  • Simulation API module for mock generations

  • -
  • Multi-source plane modelling

  • -
-
-
-

0.7.0 (2019-4-13)

-
    -
  • New design of Likelihood module

  • -
  • Updated design of FittingSequence

  • -
  • Exponential Shapelets implemented

  • -
-
-
-

0.8.0 (2019-5-23)

-
    -
  • New design of Numerics module

  • -
  • New design of PSF and Data module

  • -
  • New design of multi-band fitting module

  • -
-
-
-

0.8.1 (2019-5-23)

-
    -
  • PSF numerics improved and redundancies removed.

  • -
-
-
-

0.8.2 (2019-5-27)

-
    -
  • psf_construction simplified

  • -
  • parameter handling for catalogue modelling improved

  • -
-
-
-

0.9.0 (2019-7-06)

-
    -
  • faster fft convolutions

  • -
  • re-design of multi-plane lensing module

  • -
  • re-design of plotting module

  • -
  • nested samplers implemented

  • -
  • Workflow module with added features

  • -
-
-
-

0.9.1 (2019-7-21)

-
    -
  • non-linear solver for 4 point sources updated

  • -
  • new lens models added

  • -
  • updated Workflow module

  • -
  • implemented differential extinction

  • -
-
-
-

0.9.2 (2019-8-29)

-
    -
  • non-linear solver for 4 point sources updated

  • -
  • Moffat PSF for GalKin in place

  • -
  • Likelihood module for point sources and catalogue data improved

  • -
  • Design improvements in the LensModel module

  • -
  • minor stability updates

  • -
-
-
-

0.9.3 (2019-9-25)

-
    -
  • improvements in SimulationAPI design

  • -
  • improvements in astrometric uncertainty handling of parameters

  • -
  • local arc lens model description and differentials

  • -
-
-
-

1.0.0 (2019-9-25)

-
    -
  • marking version as 5 - Stable/production mode

  • -
-
-
-

1.0.1 (2019-10-01)

-
    -
  • compatible with emcee 3.0.0

  • -
  • removed CosmoHammer MCMC sampling

  • -
-
-
-

1.1.0 (2019-11-5)

-
    -
  • plotting routines split in different files

  • -
  • curved arc parameterization and eigenvector differentials

  • -
  • numerical differentials as part of the LensModel core class

  • -
-
-
-

1.2.0 (2019-11-17)

-
    -
  • Analysis module re-designed

  • -
  • GalKin module partially re-designed

  • -
  • Added cosmography module

  • -
  • parameterization of cartesian shear coefficients changed

  • -
-
-
-

1.2.4 (2020-01-02)

-
    -
  • First implementation of a LightCone module for numerical ray-tracing

  • -
  • Improved cosmology sampling from time-delay cosmography measurements

  • -
  • TNFW profile lensing potential implemented

  • -
-
-
-

1.3.0 (2020-01-10)

-
    -
  • image position likelihood description improved

  • -
-
-
-

1.4.0 (2020-03-26)

-
    -
  • Major re-design of GalKin module, added new anisotropy modeling and IFU aperture type

  • -
  • Updated design of the Analysis.kinematicsAPI sub-module

  • -
  • Convention and redundancy in the Cosmo module changed

  • -
  • NIE, SIE and SPEMD model consistent with their ellipticity and Einstein radius definition

  • -
  • added cored-Sersic profile

  • -
  • dependency for PSO to CosmoHammer removed

  • -
  • MPI and multi-threading for PSO and MCMC improved and compatible with python3

  • -
-
-
-

1.5.0 (2020-04-05)

-
    -
  • Re-naming SPEMD to PEMD, SPEMD_SMOOTH to SPEMD

  • -
  • adaptive numerics improvement

  • -
  • multi-processing improvements

  • -
-
-
-

1.5.1 (2020-06-20)

-
    -
  • bug fix in Hession of POINT_SOURCE model

  • -
  • EPL model from Tessore et al. 2015 implemented

  • -
  • multi-observation mode for kinematics calculation

  • -
-
-
-

1.6.0 (2020-09-07)

-
    -
  • SLITronomy integration

  • -
  • observation configuration templates and examples

  • -
  • lens equation solver arguments in single sub-kwargs

  • -
  • adapted imports to latest scipy release

  • -
  • iterative PSF reconstruction improved

  • -
  • multipole lens model

  • -
-
-
-

1.7.0 (2020-12-16)

-
    -
  • cosmo.NFWParam mass definition changed

  • -
  • QuadOptimizer re-factored

  • -
  • interpol light model support for non-square grid

  • -
  • add functionality to psf error map

  • -
  • fix in multiband reconstruction

  • -
  • observational config for ZTF

  • -
  • short-hand class imports

  • -
-
-
-

1.8.0 (2020-03-21)

-
    -
  • EPL numba version

  • -
  • numba configuration variables can be set globally with configuration file

  • -
  • Series of curved arc models available

  • -
  • single plane hessian return all for differentials

  • -
  • elliptical density slice lens model

  • -
  • vectorized lens and light interpolation models

  • -
  • updated installation description

  • -
  • fast caustic calculation replacing matplotlib with skitlearn

  • -
  • multi-patch illustration class and plotting routines

  • -
  • updated PSF iteration procedure with more settings

  • -
-
-
-

1.8.1 (2020-04-19)

-
    -
  • illustration plots for curved arcs updated

  • -
  • documentation of elliptical lens models updated

  • -
-
-
-

1.8.2 (2020-06-08)

-
    -
  • JOSS paper added

  • -
  • improved testing documentation and tox compatibility

  • -
  • TNFW_ELLIPSE lens model implemented

  • -
  • ULDM lens model implemented

  • -
-
-
-

1.9.0 (2020-07-15)

-
    -
  • re-defined half light radius in Sersic profile

  • -
  • re-named parameter in ‘CONVERGENCE’ profile

  • -
  • improved numerics in Galkin

  • -
  • configuration import design changed

  • -
-
-
-

1.9.1 (2020-08-27)

-
    -
  • re-defined amplitude normalization in NIE and CHAMELEON light profiles

  • -
  • bug fix in sky brightness errors (SimulationAPI)

  • -
-
-
-

1.9.2 (2020-12-12)

-
    -
  • support for astropy v5

  • -
  • new PSF iteration procedure implemented

  • -
  • updated caustic plotting feature

  • -
  • magnification perturbations in point source amplitudes

  • -
  • analytic point source solver for SIE+shear

  • -
-
-
-

1.9.3 (2020-12-22)

-
    -
  • changed syntax to be compatible with python3 version <3.9

  • -
-
-
-

1.10.0 (2022-03-23)

-
    -
  • schwimmbad dependency to pip version

  • -
  • ellipticity definition in lensing potential changed

  • -
  • Implemented Cored steep ellipsoid approximation of NFW and Hernquist profile

  • -
-
-
-

1.10.1 (2022-03-26)

-
    -
  • install requirements changed

  • -
-
-
-

1.10.2 (2022-03-27)

-
    -
  • requirement from sklearn changed to scikit-learn

  • -
-
-
-

1.10.3 (2022-04-18)

-
    -
  • class_creator update

  • -
  • conda-forge linked and installation updated

  • -
-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/index.html b/docs/_build/html/index.html deleted file mode 100644 index 5cb4cfdb6..000000000 --- a/docs/_build/html/index.html +++ /dev/null @@ -1,333 +0,0 @@ - - - - - - - - - lenstronomy - gravitational lensing software package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy - gravitational lensing software package

-https://github.com/sibirrer/lenstronomy/workflows/Tests/badge.svg -Documentation Status -https://coveralls.io/repos/github/sibirrer/lenstronomy/badge.svg?branch=main -https://img.shields.io/badge/license-MIT-blue.svg?style=flat -https://img.shields.io/badge/arXiv-1803.09746%20-yellowgreen.svg -Powered by Astropy Badge -https://joss.theoj.org/papers/6a562375312c9a9e4466912a16f27589/status.svg -https://raw.githubusercontent.com/sibirrer/lenstronomy/main/docs/figures/readme_fig.png -

lenstronomy is a multi-purpose package to model strong gravitational lenses. The software package is presented in -Birrer & Amara 2018 and Birrer et al. 2021 , and is based on Birrer et al 2015. -lenstronomy finds application for time-delay cosmography and measuring -the expansion rate of the Universe, for quantifying lensing substructure to infer dark matter properties, morphological quantification of galaxies, -quasar-host galaxy decomposition and much more. -A (incomplete) list of publications making use of lenstronomy can be found at this link.

-

The development is coordinated on GitHub and contributions are welcome. -The documentation of lenstronomy is available at readthedocs.org and -the package is distributed through PyPI and conda-forge. -lenstronomy is an affiliated package of astropy.

-
-

Installation

-

PyPI conda-forge

-

lenstronomy releases are distributed through PyPI and conda-forge. Instructions for -installing lenstronomy and its dependencies can be found in the Installation -section of the documentation. -Specific instructions for settings and installation requirements for special cases that can provide speed-ups, -we also refer to the Installation page.

-
-
-

Getting started

-

The starting guide jupyter notebook -leads through the main modules and design features of lenstronomy. The modular design of lenstronomy allows the -user to directly access a lot of tools and each module can also be used as stand-alone packages.

-

If you are new to gravitational lensing, check out the mini lecture series giving an introduction to gravitational lensing -with interactive Jupyter notebooks in the cloud.

-
-
-

Example notebooks

-

We have made an extension module available at https://github.com/sibirrer/lenstronomy_extensions. -You can find simple examle notebooks for various cases. The latest versions of the notebooks should be compatible with the recent pip version of lenstronomy.

- -
-
-

Affiliated packages

-

Multiple affiliated packages that make use of lenstronomy can be found here -(not complete) and further packages are under development by the community.

-
-
-

Mailing list and Slack channel

-

You can join the lenstronomy mailing list by signing up on the -google groups page.

-

The email list is meant to provide a communication platform between users and developers. You can ask questions, -and suggest new features. New releases will be announced via this mailing list.

-

We also have a Slack channel for the community. -Please send me an email such that I can add you to the channel.

-

If you encounter errors or problems with lenstronomy, please let us know!

-
-
-

Contribution

-

Check out the contributing page -and become an author of lenstronomy! A big shutout to the current list of contributors and developers!

-
-
-

Shapelet reconstruction demonstration movies

-

We provide some examples where a real galaxy has been lensed and then been reconstructed by a shapelet basis set.

- -
-
-

Attribution

-

The design concept of lenstronomy is reported by Birrer & Amara 2018. -The current JOSS software publication is presented by Birrer et al. 2021. -Please cite these two publications when you use lenstronomy in a publication and link to https://github.com/sibirrer/lenstronomy. -Please also cite Birrer et al 2015 -when you make use of the lenstronomy work-flow or the Shapelet source reconstruction and make sure to cite also -the relevant work that was implemented in lenstronomy, as described in the release paper and the documentation. -Don’t hesitate to reach out to the developers if you have questions!

-
-

Contents:

-
- -
-
-
-

Feedback

-

If you have any suggestions or questions about lenstronomy feel free to email me -at sibirrer@gmail.com.

-

If you encounter any errors or problems with lenstronomy, please let me know!

-
-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/installation.html b/docs/_build/html/installation.html deleted file mode 100644 index dfcefeb6a..000000000 --- a/docs/_build/html/installation.html +++ /dev/null @@ -1,201 +0,0 @@ - - - - - - - - - Installation — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

Installation

-

This page outlines how to install one of the officially distributed lenstronomy releases and its dependencies, -or install and test the latest development version.

-
-

From PyPI

-

All lenstronomy releases are distributed through the Python Package Index (PyPI). To install the latest version use pip:

-

At the command line with pip:

-
$ pip install lenstronomy
-
-
-

Or, if you have virtualenvwrapper installed:

-
$ mkvirtualenv lenstronomy
-$ pip install lenstronomy
-
-
-
-
-

From conda-forge

-

All lenstronomy releases are also distributed for conda through the conda-forge channel. To install the latest version for your active conda environment:

-
$ conda install -c conda-forge lenstronomy
-
-
-

You can also clone the github repository for development purposes.

-
-
-

Requirements

-

Make sure the standard python libraries as specified in the requirements. -The standard usage does not require all libraries to be installed, in particular the different posterior samplers are only required when being used.

-

In the following, a few specific cases are mentioned that may require special attention in the installation and settings, in particular when it comes -to MPI and HPC applications.

-
-
-

MPI

-

MPI support is provided for several sampling techniques for parallel computing. A specific version of the library schwimmbad is required -for the correct support of the moving of the likelihood elements from one processor to another with MPI. Pay attention ot the -requirements.

-
-
-

NUMBA

-

Just-in-time (jit) compilation with numba can provide significant speed-up for certain calculations. -There are specific settings for the settings provided as per default, but these may need to be adopted when running on a HPC cluster. -You can define your own configuration file in your $XDG_CONFIG_HOME/lenstronomy/config.yaml file. E.g. (check your system for the path):

-
$ ~/.conf/lenstronomy/config.yaml
-
-
-

following the format of the default configuration which is here.

-
-
-

FASTELL

-

The fastell4py package, originally from Barkana (fastell), is required to run the PEMD (power-law elliptical mass distribution) lens model -and can be cloned from: https://github.com/sibirrer/fastell4py (needs a fortran compiler). -We recommend using the EPL model as it is a pure python version of the same profile.

-
$ sudo apt-get install gfortran
-$ git clone https://github.com/sibirrer/fastell4py.git <desired location>
-$ cd <desired location>
-$ python setup.py install --user
-
-
-
-
-

Check installation by running tests

-

You can check your installation with pytest:

-
$ cd <lenstronomy_repo>
-$ py.test
-
-
-

Or you can run a partial test with:

-
$ cd <lenstronomy_repo>
-$ py.test/test/test_LensModel/
-
-
-

You can also run the tests with tox in a virtual environment with:

-
$ cd <lenstronomy_repo>
-$ tox
-
-
-

Note: tox might have trouble with the PyMultiNest installation and the cmake part of it.

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.Analysis.html b/docs/_build/html/lenstronomy.Analysis.html deleted file mode 100644 index eca9cb508..000000000 --- a/docs/_build/html/lenstronomy.Analysis.html +++ /dev/null @@ -1,835 +0,0 @@ - - - - - - - - - lenstronomy.Analysis package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.Analysis package

-
-

Submodules

-
-
-

lenstronomy.Analysis.kinematics_api module

-
-
-class lenstronomy.Analysis.kinematics_api.KinematicsAPI(z_lens, z_source, kwargs_model, kwargs_aperture, kwargs_seeing, anisotropy_model, cosmo=None, lens_model_kinematics_bool=None, light_model_kinematics_bool=None, multi_observations=False, kwargs_numerics_galkin=None, analytic_kinematics=False, Hernquist_approx=False, MGE_light=False, MGE_mass=False, kwargs_mge_light=None, kwargs_mge_mass=None, sampling_number=1000, num_kin_sampling=1000, num_psf_sampling=100)[source]
-

Bases: object

-

this class contains routines to compute time delays, magnification ratios, line of sight velocity dispersions etc -for a given lens model

-
-
-galkin_settings(kwargs_lens, kwargs_lens_light, r_eff=None, theta_E=None, gamma=None)[source]
-
-
Parameters
-
    -
  • kwargs_lens – lens model keyword argument list

  • -
  • kwargs_lens_light – deflector light keyword argument list

  • -
  • r_eff – half-light radius (optional)

  • -
  • theta_E – Einstein radius (optional)

  • -
  • gamma – local power-law slope at the Einstein radius (optional)

  • -
-
-
Returns
-

Galkin() instance and mass and light profiles configured for the Galkin module

-
-
-
- -
-
-kinematic_lens_profiles(kwargs_lens, MGE_fit=False, model_kinematics_bool=None, theta_E=None, gamma=None, kwargs_mge=None, analytic_kinematics=False)[source]
-

translates the lenstronomy lens and mass profiles into a (sub) set of profiles that are compatible with the -GalKin module to compute the kinematics thereof. -The requirement is that the -profiles are centered at (0, 0) and that for all profile types there exists a 3d de-projected analytical -representation.

-
-
Parameters
-
    -
  • kwargs_lens – lens model parameters

  • -
  • MGE_fit – bool, if true performs the MGE for the mass distribution

  • -
  • 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

  • -
  • theta_E – (optional float) estimate of the Einstein radius. If present, does not numerically compute this -quantity in this routine numerically

  • -
  • gamma – local power-law slope at the Einstein radius (optional)

  • -
  • kwargs_mge – keyword arguments that go into the MGE decomposition routine

  • -
  • analytic_kinematics – bool, if True, solves the Jeans equation analytically for the -power-law mass profile with Hernquist light profile

  • -
-
-
Returns
-

mass_profile_list, keyword argument list

-
-
-
- -
-
-kinematic_light_profile(kwargs_lens_light, r_eff=None, MGE_fit=False, model_kinematics_bool=None, Hernquist_approx=False, kwargs_mge=None, analytic_kinematics=False)[source]
-

setting up of the light profile to compute the kinematics in the GalKin module. The requirement is that the -profiles are centered at (0, 0) and that for all profile types there exists a 3d de-projected analytical -representation.

-
-
Parameters
-
    -
  • kwargs_lens_light – deflector light model keyword argument list

  • -
  • r_eff – (optional float, else=None) Pre-calculated projected half-light radius of the deflector profile. -If not provided, numerical calculation is done in this routine if required.

  • -
  • MGE_fit – boolean, if True performs a Multi-Gaussian expansion of the radial light profile and returns -this solution.

  • -
  • model_kinematics_bool – list of booleans to indicate a subset of light profiles to be part of the physical -deflector light.

  • -
  • Hernquist_approx – boolean, if True replaces the actual light profile(s) with a Hernquist model with -matched half-light radius.

  • -
  • kwargs_mge – keyword arguments that go into the MGE decomposition routine

  • -
  • analytic_kinematics – bool, if True, solves the Jeans equation analytically for the -power-law mass profile with Hernquist light profile and adjust the settings accordingly

  • -
-
-
Returns
-

deflector type list, keyword arguments list

-
-
-
- -
-
-kinematics_modeling_settings(anisotropy_model, kwargs_numerics_galkin, analytic_kinematics=False, Hernquist_approx=False, MGE_light=False, MGE_mass=False, kwargs_mge_light=None, kwargs_mge_mass=None, sampling_number=1000, num_kin_sampling=1000, num_psf_sampling=100)[source]
-
-
Parameters
-
    -
  • anisotropy_model – type of stellar anisotropy model. See details in MamonLokasAnisotropy() class of lenstronomy.GalKin.anisotropy

  • -
  • analytic_kinematics – boolean, if True, used the analytic JAM modeling for a power-law profile on top of a Hernquist light profile -ATTENTION: This may not be accurate for your specific problem!

  • -
  • 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

  • -
  • MGE_light – bool, if true performs the MGE for the light distribution

  • -
  • MGE_mass – bool, if true performs the MGE for the mass distribution

  • -
  • kwargs_numerics_galkin – numerical settings for the integrated line-of-sight velocity dispersion

  • -
  • kwargs_mge_mass – keyword arguments that go into the MGE decomposition routine

  • -
  • kwargs_mge_light – keyword arguments that go into the MGE decomposition routine

  • -
  • sampling_number – number of spectral rendering on a single slit

  • -
  • num_kin_sampling – number of kinematic renderings on a total IFU

  • -
  • num_psf_sampling – number of PSF displacements for each kinematic rendering on the IFU

  • -
-
-
Returns
-

-
-
-
- -
-
-static transform_kappa_ext(sigma_v, kappa_ext=0)[source]
-
-
Parameters
-
    -
  • sigma_v – velocity dispersion estimate of the lensing deflector without considering external convergence

  • -
  • kappa_ext – external convergence to be used in the mass-sheet degeneracy

  • -
-
-
Returns
-

transformed velocity dispersion

-
-
-
- -
-
-velocity_dispersion(kwargs_lens, kwargs_lens_light, kwargs_anisotropy, r_eff=None, theta_E=None, gamma=None, kappa_ext=0)[source]
-

API for both, analytic and numerical JAM to compute the velocity dispersion [km/s] -This routine uses the galkin_setting() routine for the Galkin configurations (see there what options and input -is relevant.

-
-
Parameters
-
    -
  • kwargs_lens – lens model keyword arguments

  • -
  • kwargs_lens_light – lens light model keyword arguments

  • -
  • kwargs_anisotropy – stellar anisotropy keyword arguments

  • -
  • r_eff – projected half-light radius of the stellar light associated with the deflector galaxy, optional, -if set to None will be computed in this function with default settings that may not be accurate.

  • -
  • theta_E – Einstein radius (optional)

  • -
  • gamma – power-law slope (optional)

  • -
  • kappa_ext – external convergence (optional)

  • -
-
-
Returns
-

velocity dispersion [km/s]

-
-
-
- -
-
-velocity_dispersion_analytical(theta_E, gamma, r_eff, r_ani, kappa_ext=0)[source]
-

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.

-
-
Parameters
-
    -
  • theta_E – Einstein radius

  • -
  • gamma – power-low slope of the mass profile (=2 corresponds to isothermal)

  • -
  • r_ani – anisotropy radius in units of angles

  • -
  • r_eff – projected half-light radius

  • -
  • kappa_ext – external convergence not accounted in the lens models

  • -
-
-
Returns
-

velocity dispersion in units [km/s]

-
-
-
- -
-
-velocity_dispersion_map(kwargs_lens, kwargs_lens_light, kwargs_anisotropy, r_eff=None, theta_E=None, gamma=None, kappa_ext=0)[source]
-

API for both, analytic and numerical JAM to compute the velocity dispersion map with IFU data [km/s]

-
-
Parameters
-
    -
  • kwargs_lens – lens model keyword arguments

  • -
  • kwargs_lens_light – lens light model keyword arguments

  • -
  • kwargs_anisotropy – stellar anisotropy keyword arguments

  • -
  • r_eff – projected half-light radius of the stellar light associated with the deflector galaxy, optional, -if set to None will be computed in this function with default settings that may not be accurate.

  • -
  • theta_E – circularized Einstein radius, optional, if not provided will either be computed in this -function with default settings or not required

  • -
  • gamma – power-law slope at the Einstein radius, optional

  • -
  • kappa_ext – external convergence

  • -
-
-
Returns
-

velocity dispersion [km/s]

-
-
-
- -
- -
-
-

lenstronomy.Analysis.lens_profile module

-
-
-class lenstronomy.Analysis.lens_profile.LensProfileAnalysis(lens_model)[source]
-

Bases: object

-

class with analysis routines to compute derived properties of the lens model

-
-
-convergence_peak(kwargs_lens, model_bool_list=None, grid_num=200, grid_spacing=0.01, center_x_init=0, center_y_init=0)[source]
-

computes the maximal convergence position on a grid and returns its coordinate

-
-
Parameters
-
    -
  • kwargs_lens – lens model keyword argument list

  • -
  • model_bool_list – bool list (optional) to include certain models or not

  • -
-
-
Returns
-

center_x, center_y

-
-
-
- -
-
-effective_einstein_radius(kwargs_lens, center_x=None, center_y=None, model_bool_list=None, grid_num=200, grid_spacing=0.05, get_precision=False, verbose=True)[source]
-

computes the radius with mean convergence=1

-
-
Parameters
-
    -
  • kwargs_lens – list of lens model keyword arguments

  • -
  • center_x – position of the center (if not set, is attempting to find it from the parameters kwargs_lens)

  • -
  • center_y – position of the center (if not set, is attempting to find it from the parameters kwargs_lens)

  • -
  • model_bool_list – list of booleans indicating the addition (=True) of a model component in computing the -Einstein radius

  • -
  • grid_num – integer, number of grid points to numerically evaluate the convergence and estimate the -Einstein radius

  • -
  • grid_spacing – spacing in angular units of the grid

  • -
  • get_precision – If True, return the precision of estimated Einstein radius

  • -
  • verbose – boolean, if True prints warning if indication of insufficient result

  • -
-
-
Returns
-

estimate of the Einstein radius

-
-
-
- -
-
-local_lensing_effect(kwargs_lens, ra_pos=0, dec_pos=0, model_list_bool=None)[source]
-

computes deflection, shear and convergence at (ra_pos,dec_pos) for those part of the lens model not included -in the main deflector.

-
-
Parameters
-
    -
  • kwargs_lens – lens model keyword argument list

  • -
  • ra_pos – RA position where to compute the external effect

  • -
  • dec_pos – DEC position where to compute the external effect

  • -
  • model_list_bool – boolean list indicating which models effect to be added to the estimate

  • -
-
-
Returns
-

alpha_x, alpha_y, kappa, shear1, shear2

-
-
-
- -
-
-mass_fraction_within_radius(kwargs_lens, center_x, center_y, theta_E, numPix=100)[source]
-

computes the mean convergence of all the different lens model components within a spherical aperture

-
-
Parameters
-
    -
  • kwargs_lens – lens model keyword argument list

  • -
  • center_x – center of the aperture

  • -
  • center_y – center of the aperture

  • -
  • theta_E – radius of aperture

  • -
-
-
Returns
-

list of average convergences for all the model components

-
-
-
- -
-
-mst_invariant_differential(kwargs_lens, radius, center_x=None, center_y=None, model_list_bool=None, num_points=10)[source]
-

Average of the radial stretch differential in radial direction, divided by the radial stretch factor.

-
-\[\xi = \frac{\partial \lambda_{\rm rad}}{\partial r} \frac{1}{\lambda_{\rm rad}}\]
-

This quantity is invariant under the MST. -The specific definition is provided by Birrer 2021. Equivalent (proportional) definitions are provided by e.g. -Kochanek 2020, Sonnenfeld 2018.

-
-
Parameters
-
    -
  • kwargs_lens – lens model keyword argument list

  • -
  • radius – radius from the center where to compute the MST invariant differential

  • -
  • center_x – center position

  • -
  • center_y – center position

  • -
  • model_list_bool – indicate which part of the model to consider

  • -
  • num_points – number of estimates around the radius

  • -
-
-
Returns
-

xi

-
-
-
- -
-
-multi_gaussian_lens(kwargs_lens, center_x=None, center_y=None, model_bool_list=None, n_comp=20)[source]
-

multi-gaussian lens model in convergence space

-
-
Parameters
-
    -
  • kwargs_lens

  • -
  • n_comp

  • -
-
-
Returns
-

-
-
-
- -
-
-profile_slope(kwargs_lens, radius, center_x=None, center_y=None, model_list_bool=None, num_points=10)[source]
-

computes the logarithmic power-law slope of a profile. ATTENTION: this is not an observable!

-
-
Parameters
-
    -
  • kwargs_lens – lens model keyword argument list

  • -
  • radius – radius from the center where to compute the logarithmic slope (angular units

  • -
  • center_x – center of profile from where to compute the slope

  • -
  • center_y – center of profile from where to compute the slope

  • -
  • model_list_bool – bool list, indicate which part of the model to consider

  • -
  • num_points – number of estimates around the Einstein radius

  • -
-
-
Returns
-

logarithmic power-law slope

-
-
-
- -
-
-radial_lens_profile(r_list, kwargs_lens, center_x=None, center_y=None, model_bool_list=None)[source]
-
-
Parameters
-
    -
  • r_list – list of radii to compute the spherically averaged lens light profile

  • -
  • center_x – center of the profile

  • -
  • center_y – center of the profile

  • -
  • kwargs_lens – lens parameter keyword argument list

  • -
  • model_bool_list – bool list or None, indicating which profiles to sum over

  • -
-
-
Returns
-

flux amplitudes at r_list radii azimuthally averaged

-
-
-
- -
- -
-
-

lenstronomy.Analysis.light2mass module

-
-
-lenstronomy.Analysis.light2mass.light2mass_interpol(lens_light_model_list, kwargs_lens_light, numPix=100, deltaPix=0.05, subgrid_res=5, center_x=0, center_y=0)[source]
-

takes a lens light model and turns it numerically in a lens model -(with all lensmodel quantities computed on a grid). Then provides an interpolated grid for the quantities.

-
-
Parameters
-
    -
  • kwargs_lens_light – lens light keyword argument list

  • -
  • numPix – number of pixels per axis for the return interpolation

  • -
  • deltaPix – interpolation/pixel size

  • -
  • center_x – center of the grid

  • -
  • center_y – center of the grid

  • -
  • subgrid_res – subgrid for the numerical integrals

  • -
-
-
Returns
-

keyword arguments for ‘INTERPOL’ lens model

-
-
-
- -
-
-

lenstronomy.Analysis.light_profile module

-
-
-class lenstronomy.Analysis.light_profile.LightProfileAnalysis(light_model)[source]
-

Bases: object

-

class with analysis routines to compute derived properties of the lens model

-
-
-ellipticity(kwargs_light, grid_spacing, grid_num, center_x=None, center_y=None, model_bool_list=None)[source]
-

make sure that the window covers all the light, otherwise the moments may give a too low answers.

-
-
Parameters
-
    -
  • kwargs_light – keyword argument list of profiles

  • -
  • center_x – center of profile, if None takes it from the first profile in kwargs_light

  • -
  • center_y – center of profile, if None takes it from the first profile in kwargs_light

  • -
  • model_bool_list – list of booleans to select subsets of the profile

  • -
  • grid_spacing – grid spacing over which the moments are computed

  • -
  • grid_num – grid size over which the moments are computed

  • -
-
-
Returns
-

eccentricities e1, e2

-
-
-
- -
-
-flux_components(kwargs_light, grid_num=400, grid_spacing=0.01)[source]
-

computes the total flux in each component of the model

-
-
Parameters
-
    -
  • kwargs_light

  • -
  • grid_num

  • -
  • grid_spacing

  • -
-
-
Returns
-

-
-
-
- -
-
-half_light_radius(kwargs_light, grid_spacing, grid_num, center_x=None, center_y=None, model_bool_list=None)[source]
-

computes numerically the half-light-radius of the deflector light and the total photon flux

-
-
Parameters
-
    -
  • kwargs_light – keyword argument list of profiles

  • -
  • center_x – center of profile, if None takes it from the first profile in kwargs_light

  • -
  • center_y – center of profile, if None takes it from the first profile in kwargs_light

  • -
  • model_bool_list – list of booleans to select subsets of the profile

  • -
  • grid_spacing – grid spacing over which the moments are computed

  • -
  • grid_num – grid size over which the moments are computed

  • -
-
-
Returns
-

half-light radius

-
-
-
- -
-
-multi_gaussian_decomposition(kwargs_light, model_bool_list=None, n_comp=20, center_x=None, center_y=None, r_h=None, grid_spacing=0.02, grid_num=200)[source]
-

multi-gaussian decomposition of the lens light profile (in 1-dimension)

-
-
Parameters
-
    -
  • kwargs_light – keyword argument list of profiles

  • -
  • center_x – center of profile, if None takes it from the first profile in kwargs_light

  • -
  • center_y – center of profile, if None takes it from the first profile in kwargs_light

  • -
  • model_bool_list – list of booleans to select subsets of the profile

  • -
  • grid_spacing – grid spacing over which the moments are computed for the half-light radius

  • -
  • grid_num – grid size over which the moments are computed

  • -
  • n_comp – maximum number of Gaussian’s in the MGE

  • -
  • r_h – float, half light radius to be used for MGE (optional, otherwise using a numerical grid)

  • -
-
-
Returns
-

amplitudes, sigmas, center_x, center_y

-
-
-
- -
-
-multi_gaussian_decomposition_ellipse(kwargs_light, model_bool_list=None, center_x=None, center_y=None, grid_num=100, grid_spacing=0.05, n_comp=20)[source]
-

MGE with ellipticity estimate. -Attention: numerical grid settings for ellipticity estimate and radial MGE may not necessarily be the same!

-
-
Parameters
-
    -
  • kwargs_light – keyword argument list of profiles

  • -
  • center_x – center of profile, if None takes it from the first profile in kwargs_light

  • -
  • center_y – center of profile, if None takes it from the first profile in kwargs_light

  • -
  • model_bool_list – list of booleans to select subsets of the profile

  • -
  • grid_spacing – grid spacing over which the moments are computed

  • -
  • grid_num – grid size over which the moments are computed

  • -
  • n_comp – maximum number of Gaussians in the MGE

  • -
-
-
Returns
-

keyword arguments of the elliptical multi Gaussian profile in lenstronomy conventions

-
-
-
- -
-
-radial_light_profile(r_list, kwargs_light, center_x=None, center_y=None, model_bool_list=None)[source]
-
-
Parameters
-
    -
  • r_list – list of radii to compute the spherically averaged lens light profile

  • -
  • center_x – center of the profile

  • -
  • center_y – center of the profile

  • -
  • kwargs_light – lens light parameter keyword argument list

  • -
  • model_bool_list – bool list or None, indicating which profiles to sum over

  • -
-
-
Returns
-

flux amplitudes at r_list radii spherically averaged

-
-
-
- -
- -
-
-

lenstronomy.Analysis.td_cosmography module

-
-
-class lenstronomy.Analysis.td_cosmography.TDCosmography(z_lens, z_source, kwargs_model, cosmo_fiducial=None, lens_model_kinematics_bool=None, light_model_kinematics_bool=None, kwargs_seeing=None, kwargs_aperture=None, anisotropy_model=None, **kwargs_kin_api)[source]
-

Bases: lenstronomy.Analysis.kinematics_api.KinematicsAPI

-

class equipped to perform a cosmographic analysis from a lens model with added measurements of time delays and -kinematics. -This class does not require any cosmological knowledge and can return angular diameter distance estimates -self-consistently integrating the kinematics routines and time delay estimates in the lens modeling. -This description follows Birrer et al. 2016, 2019.

-
-
-ddt_dd_from_time_delay_and_kinematics(d_fermat_model, dt_measured, sigma_v_measured, J, kappa_s=0, kappa_ds=0, kappa_d=0)[source]
-
-
Parameters
-
    -
  • d_fermat_model – relative Fermat potential in units arcsec^2

  • -
  • dt_measured – measured relative time delay [days]

  • -
  • sigma_v_measured – 1-sigma Gaussian uncertainty in the measured velocity dispersion

  • -
  • J – modeled dimensionless kinematic estimate

  • -
  • kappa_s – LOS convergence from observer to source

  • -
  • kappa_ds – LOS convergence from deflector to source

  • -
  • kappa_d – LOS convergence from observer to deflector

  • -
-
-
Returns
-

D_dt, D_d

-
-
-
- -
-
-static ddt_from_time_delay(d_fermat_model, dt_measured, kappa_s=0, kappa_ds=0, kappa_d=0)[source]
-

Time-delay distance in units of Mpc from the modeled Fermat potential and measured time delay from an image pair.

-
-
Parameters
-
    -
  • d_fermat_model – relative Fermat potential between two images from the same source in units arcsec^2

  • -
  • dt_measured – measured time delay between the same image pair in units of days

  • -
  • kappa_s – external convergence from observer to source

  • -
  • kappa_ds – external convergence from lens to source

  • -
  • kappa_d – external convergence form observer to lens

  • -
-
-
Returns
-

D_dt, time-delay distance

-
-
-
- -
-
-static ds_dds_from_kinematics(sigma_v, J, kappa_s=0, kappa_ds=0)[source]
-

computes the estimate of the ratio of angular diameter distances Ds/Dds from the kinematic estimate of the lens -and the measured dispersion.

-
-
Parameters
-
    -
  • sigma_v – velocity dispersion [km/s]

  • -
  • J – dimensionless kinematic constraint (see Birrer et al. 2016, 2019)

  • -
-
-
Returns
-

Ds/Dds

-
-
-
- -
-
-fermat_potential(kwargs_lens, kwargs_ps, original_ps_position=False)[source]
-

Fermat potential (negative sign means earlier arrival time)

-
-
Parameters
-
    -
  • kwargs_lens – lens model keyword argument list

  • -
  • kwargs_ps – point source keyword argument list

  • -
  • original_ps_position – boolean (only applies when first point source model is of type ‘LENSED_POSITION’), -uses the image positions in the model parameters and does not re-compute images (which might be differently ordered) -in case of the lens equation solver

  • -
-
-
Returns
-

Fermat potential of all the image positions in the first point source list entry

-
-
-
- -
-
-time_delays(kwargs_lens, kwargs_ps, kappa_ext=0, original_ps_position=False)[source]
-

predicts the time delays of the image positions given the fiducial cosmology relative to a straight line -without lensing. -Negative values correspond to images arriving earlier, and positive signs correspond to images arriving later.

-
-
Parameters
-
    -
  • kwargs_lens – lens model parameters

  • -
  • kwargs_ps – point source parameters

  • -
  • kappa_ext – external convergence (optional)

  • -
  • original_ps_position – boolean (only applies when first point source model is of type ‘LENSED_POSITION’), -uses the image positions in the model parameters and does not re-compute images (which might be differently ordered) -in case of the lens equation solver

  • -
-
-
Returns
-

time delays at image positions for the fixed cosmology in units of days

-
-
-
- -
-
-velocity_dispersion_dimension_less(kwargs_lens, kwargs_lens_light, kwargs_anisotropy, r_eff=None, theta_E=None, gamma=None)[source]
-

sigma**2 = Dd/Dds * c**2 * J(kwargs_lens, kwargs_light, anisotropy) -(Equation 4.11 in Birrer et al. 2016 or Equation 6 in Birrer et al. 2019) J() is a dimensionless and -cosmological independent quantity only depending on angular units. This function returns J given the lens -and light parameters and the anisotropy choice without an external mass sheet correction.

-
-
Parameters
-
    -
  • kwargs_lens – lens model keyword arguments

  • -
  • kwargs_lens_light – lens light model keyword arguments

  • -
  • kwargs_anisotropy – stellar anisotropy keyword arguments

  • -
  • r_eff – projected half-light radius of the stellar light associated with the deflector galaxy, optional, -if set to None will be computed in this function with default settings that may not be accurate.

  • -
  • theta_E – pre-computed Einstein radius (optional)

  • -
  • gamma – pre-computed power-law slope of mass profile

  • -
-
-
Returns
-

dimensionless velocity dispersion (see e.g. Birrer et al. 2016, 2019)

-
-
-
- -
-
-velocity_dispersion_map_dimension_less(kwargs_lens, kwargs_lens_light, kwargs_anisotropy, r_eff=None, theta_E=None, gamma=None)[source]
-

sigma**2 = Dd/Dds * c**2 * J(kwargs_lens, kwargs_light, anisotropy) -(Equation 4.11 in Birrer et al. 2016 or Equation 6 in Birrer et al. 2019) J() is a dimensionless and -cosmological independent quantity only depending on angular units. This function returns J given the lens -and light parameters and the anisotropy choice without an external mass sheet correction. -This routine computes the IFU map of the kinematic quantities.

-
-
Parameters
-
    -
  • kwargs_lens – lens model keyword arguments

  • -
  • kwargs_lens_light – lens light model keyword arguments

  • -
  • kwargs_anisotropy – stellar anisotropy keyword arguments

  • -
  • r_eff – projected half-light radius of the stellar light associated with the deflector galaxy, optional, -if set to None will be computed in this function with default settings that may not be accurate.

  • -
-
-
Returns
-

dimensionless velocity dispersion (see e.g. Birrer et al. 2016, 2019)

-
-
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.Conf.html b/docs/_build/html/lenstronomy.Conf.html deleted file mode 100644 index 265c1df4d..000000000 --- a/docs/_build/html/lenstronomy.Conf.html +++ /dev/null @@ -1,151 +0,0 @@ - - - - - - - - - lenstronomy.Conf package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.Conf package

-
-

Submodules

-
-
-

lenstronomy.Conf.config_loader module

-
-
-lenstronomy.Conf.config_loader.conventions_conf()[source]
-
-
Returns
-

convention keyword arguments

-
-
-
- -
-
-lenstronomy.Conf.config_loader.numba_conf()[source]
-
-
Returns
-

keyword arguments of numba configurations from yaml file

-
-
-
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.Cosmo.html b/docs/_build/html/lenstronomy.Cosmo.html deleted file mode 100644 index febedbdc3..000000000 --- a/docs/_build/html/lenstronomy.Cosmo.html +++ /dev/null @@ -1,762 +0,0 @@ - - - - - - - - - lenstronomy.Cosmo package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.Cosmo package

-
-

Submodules

-
-
-

lenstronomy.Cosmo.background module

-
-
-class lenstronomy.Cosmo.background.Background(cosmo=None, interp=False, **kwargs_interp)[source]
-

Bases: object

-

class to compute cosmological distances

-
-
-T_xy(z_observer, z_source)[source]
-
-
Parameters
-
    -
  • z_observer – observer

  • -
  • z_source – source

  • -
-
-
Returns
-

transverse comoving distance in units of Mpc

-
-
-
- -
-
-a_z(z)[source]
-

returns scale factor (a_0 = 1) for given redshift -:param z: redshift -:return: scale factor

-
- -
-
-d_xy(z_observer, z_source)[source]
-
-
Parameters
-
    -
  • z_observer – observer redshift

  • -
  • z_source – source redshift

  • -
-
-
Returns
-

angular diameter distance in units of Mpc

-
-
-
- -
-
-ddt(z_lens, z_source)[source]
-

time-delay distance

-
-
Parameters
-
    -
  • z_lens – redshift of lens

  • -
  • z_source – redshift of source

  • -
-
-
Returns
-

time-delay distance in units of proper Mpc

-
-
-
- -
-
-property rho_crit
-

critical density -:return: value in M_sol/Mpc^3

-
- -
- -
-
-

lenstronomy.Cosmo.cosmo_solver module

-
-
-class lenstronomy.Cosmo.cosmo_solver.InvertCosmo(z_d, z_s, H0_range=array([10., 11.01123596, 12.02247191, 13.03370787, 14.04494382, 15.05617978, 16.06741573, 17.07865169, 18.08988764, 19.1011236, 20.11235955, 21.12359551, 22.13483146, 23.14606742, 24.15730337, 25.16853933, 26.17977528, 27.19101124, 28.20224719, 29.21348315, 30.2247191, 31.23595506, 32.24719101, 33.25842697, 34.26966292, 35.28089888, 36.29213483, 37.30337079, 38.31460674, 39.3258427, 40.33707865, 41.34831461, 42.35955056, 43.37078652, 44.38202247, 45.39325843, 46.40449438, 47.41573034, 48.42696629, 49.43820225, 50.4494382, 51.46067416, 52.47191011, 53.48314607, 54.49438202, 55.50561798, 56.51685393, 57.52808989, 58.53932584, 59.5505618, 60.56179775, 61.57303371, 62.58426966, 63.59550562, 64.60674157, 65.61797753, 66.62921348, 67.64044944, 68.65168539, 69.66292135, 70.6741573, 71.68539326, 72.69662921, 73.70786517, 74.71910112, 75.73033708, 76.74157303, 77.75280899, 78.76404494, 79.7752809, 80.78651685, 81.79775281, 82.80898876, 83.82022472, 84.83146067, 85.84269663, 86.85393258, 87.86516854, 88.87640449, 89.88764045, 90.8988764, 91.91011236, 92.92134831, 93.93258427, 94.94382022, 95.95505618, 96.96629213, 97.97752809, 98.98876404, 100.]), omega_m_range=array([0.05, 0.06010638, 0.07021277, 0.08031915, 0.09042553, 0.10053191, 0.1106383, 0.12074468, 0.13085106, 0.14095745, 0.15106383, 0.16117021, 0.1712766, 0.18138298, 0.19148936, 0.20159574, 0.21170213, 0.22180851, 0.23191489, 0.24202128, 0.25212766, 0.26223404, 0.27234043, 0.28244681, 0.29255319, 0.30265957, 0.31276596, 0.32287234, 0.33297872, 0.34308511, 0.35319149, 0.36329787, 0.37340426, 0.38351064, 0.39361702, 0.4037234, 0.41382979, 0.42393617, 0.43404255, 0.44414894, 0.45425532, 0.4643617, 0.47446809, 0.48457447, 0.49468085, 0.50478723, 0.51489362, 0.525, 0.53510638, 0.54521277, 0.55531915, 0.56542553, 0.57553191, 0.5856383, 0.59574468, 0.60585106, 0.61595745, 0.62606383, 0.63617021, 0.6462766, 0.65638298, 0.66648936, 0.67659574, 0.68670213, 0.69680851, 0.70691489, 0.71702128, 0.72712766, 0.73723404, 0.74734043, 0.75744681, 0.76755319, 0.77765957, 0.78776596, 0.79787234, 0.80797872, 0.81808511, 0.82819149, 0.83829787, 0.84840426, 0.85851064, 0.86861702, 0.8787234, 0.88882979, 0.89893617, 0.90904255, 0.91914894, 0.92925532, 0.9393617, 0.94946809, 0.95957447, 0.96968085, 0.97978723, 0.98989362, 1.]))[source]
-

Bases: object

-

class to do an interpolation and call the inverse of this interpolation to get H_0 and omega_m

-
-
-get_cosmo(Dd, Ds_Dds)[source]
-

return the values of H0 and omega_m computed with an interpolation -:param Dd: flat -:param Ds_Dds: float -:return:

-
- -
- -
-
-class lenstronomy.Cosmo.cosmo_solver.SolverFlatLCDM(z_d, z_s)[source]
-

Bases: object

-

class to solve multidimensional non-linear equations to determine the cosmological parameters H0 and omega_m given -the angular diameter distance relations

-
-
-F(x, Dd, Ds_Dds)[source]
-
-
Parameters
-

x – array of parameters (H_0, omega_m)

-
-
Returns
-

-
-
-
- -
-
-solve(init, dd, ds_dds)[source]
-
- -
- -
-
-lenstronomy.Cosmo.cosmo_solver.cosmo2angular_diameter_distances(H_0, omega_m, z_lens, z_source)[source]
-
-
Parameters
-
    -
  • H_0 – Hubble constant [km/s/Mpc]

  • -
  • omega_m – dimensionless matter density at z=0

  • -
  • z_lens – deflector redshift

  • -
  • z_source – source redshift

  • -
-
-
Returns
-

angular diameter distances Dd and Ds/Dds

-
-
-
- -
-
-lenstronomy.Cosmo.cosmo_solver.ddt2h0(ddt, z_lens, z_source, cosmo)[source]
-

converts time-delay distance to H0 for a given expansion history

-
-
Parameters
-
    -
  • ddt – time-delay distance in Mpc

  • -
  • z_lens – deflector redshift

  • -
  • z_source – source redshift

  • -
  • cosmo – astropy.cosmology class instance

  • -
-
-
Returns
-

h0 value which matches the cosmology class effectively replacing the h0 value used in the creation of this class

-
-
-
- -
-
-

lenstronomy.Cosmo.kde_likelihood module

-
-
-class lenstronomy.Cosmo.kde_likelihood.KDELikelihood(D_d_sample, D_delta_t_sample, kde_type='scipy_gaussian', bandwidth=1)[source]
-

Bases: object

-

class that samples the cosmographic likelihood given a distribution of points in the 2-dimensional distribution -of D_d and D_delta_t

-
-
-logLikelihood(D_d, D_delta_t)[source]
-

likelihood of the data (represented in the distribution of this class) given a model with predicted angular -diameter distances.

-
-
Parameters
-
    -
  • D_d – model predicted angular diameter distance

  • -
  • D_delta_t – model predicted time-delay distance

  • -
-
-
Returns
-

loglikelihood (log of KDE value)

-
-
-
- -
- -
-
-

lenstronomy.Cosmo.lcdm module

-
-
-class lenstronomy.Cosmo.lcdm.LCDM(z_lens, z_source, flat=True)[source]
-

Bases: object

-

Flat LCDM cosmology background with free Hubble parameter and Omega_m at fixed lens redshift configuration

-
-
-D_d(H_0, Om0, Ode0=None)[source]
-

angular diameter to deflector -:param H_0: Hubble parameter [km/s/Mpc] -:param Om0: normalized matter density at present time -:return: float [Mpc]

-
- -
-
-D_ds(H_0, Om0, Ode0=None)[source]
-

angular diameter from deflector to source -:param H_0: Hubble parameter [km/s/Mpc] -:param Om0: normalized matter density at present time -:return: float [Mpc]

-
- -
-
-D_dt(H_0, Om0, Ode0=None)[source]
-

time delay distance -:param H_0: Hubble parameter [km/s/Mpc] -:param Om0: normalized matter density at present time -:return: float [Mpc]

-
- -
-
-D_s(H_0, Om0, Ode0=None)[source]
-

angular diameter to source -:param H_0: Hubble parameter [km/s/Mpc] -:param Om0: normalized matter density at present time -:return: float [Mpc]

-
- -
- -
-
-

lenstronomy.Cosmo.lens_cosmo module

-
-
-class lenstronomy.Cosmo.lens_cosmo.LensCosmo(z_lens, z_source, cosmo=None)[source]
-

Bases: object

-

class to manage the physical units and distances present in a single plane lens with fixed input cosmology

-
-
-a_z(z)[source]
-

convert redshift into scale factor -:param z: redshift -:return: scale factor

-
- -
-
-arcsec2phys_lens(arcsec)[source]
-

convert angular to physical quantities for lens plane -:param arcsec: angular size at lens plane [arcsec] -:return: physical size at lens plane [Mpc]

-
- -
-
-arcsec2phys_source(arcsec)[source]
-

convert angular to physical quantities for source plane -:param arcsec: angular size at source plane [arcsec] -:return: physical size at source plane [Mpc]

-
- -
-
-property dd
-
-
Returns
-

angular diameter distance to the deflector [Mpc]

-
-
-
- -
-
-property dds
-
-
Returns
-

angular diameter distance from deflector to source [Mpc]

-
-
-
- -
-
-property ddt
-
-
Returns
-

time delay distance [Mpc]

-
-
-
- -
-
-property ds
-
-
Returns
-

angular diameter distance to the source [Mpc]

-
-
-
- -
-
-property h
-
- -
-
-kappa2proj_mass(kappa)[source]
-

convert convergence to projected mass M_sun/Mpc^2 -:param kappa: lensing convergence -:return: projected mass [M_sun/Mpc^2]

-
- -
-
-mass_in_coin(theta_E)[source]
-
-
Parameters
-

theta_E – Einstein radius [arcsec]

-
-
Returns
-

mass in coin calculated in mean density of the universe

-
-
-
- -
-
-mass_in_theta_E(theta_E)[source]
-

mass within Einstein radius (area * epsilon crit) [M_sun] -:param theta_E: Einstein radius [arcsec] -:return: mass within Einstein radius [M_sun]

-
- -
-
-nfwParam_physical(M, c)[source]
-

returns the NFW parameters in physical units

-
-
Parameters
-
    -
  • M – physical mass in M_sun

  • -
  • c – concentration

  • -
-
-
Returns
-

rho0 [Msun/Mpc^3], Rs [Mpc], r200 [Mpc]

-
-
-
- -
-
-nfw_M_theta_r200(M)[source]
-

returns r200 radius in angular units of arc seconds on the sky

-
-
Parameters
-

M – physical mass in M_sun

-
-
Returns
-

angle (in arc seconds) of the r200 radius

-
-
-
- -
-
-nfw_angle2physical(Rs_angle, alpha_Rs)[source]
-

converts the angular parameters into the physical ones for an NFW profile

-
-
Parameters
-
    -
  • alpha_Rs – observed bending angle at the scale radius in units of arcsec

  • -
  • Rs_angle – scale radius in units of arcsec

  • -
-
-
Returns
-

rho0 [Msun/Mpc^3], Rs [Mpc], c, r200 [Mpc], M200 [Msun]

-
-
-
- -
-
-nfw_physical2angle(M, c)[source]
-

converts the physical mass and concentration parameter of an NFW profile into the lensing quantities

-
-
Parameters
-
    -
  • M – mass enclosed 200 rho_crit in units of M_sun (physical units, meaning no little h)

  • -
  • c – NFW concentration parameter (r200/r_s)

  • -
-
-
Returns
-

Rs_angle (angle at scale radius) (in units of arcsec), alpha_Rs (observed bending angle at the scale radius

-
-
-
- -
-
-phys2arcsec_lens(phys)[source]
-

convert physical Mpc into arc seconds -:param phys: physical distance [Mpc] -:return: angular diameter [arcsec]

-
- -
-
-property sigma_crit
-

returns the critical projected lensing mass density in units of M_sun/Mpc^2 -:return: critical projected lensing mass density

-
- -
-
-property sigma_crit_angle
-

returns the critical surface density in units of M_sun/arcsec^2 (in physical solar mass units) -when provided a physical mass per physical Mpc^2 -:return: critical projected mass density

-
- -
-
-sis_sigma_v2theta_E(v_sigma)[source]
-

converts the velocity dispersion into an Einstein radius for a SIS profile -:param v_sigma: velocity dispersion (km/s) -:return: theta_E (arcsec)

-
- -
-
-sis_theta_E2sigma_v(theta_E)[source]
-

converts the lensing Einstein radius into a physical velocity dispersion -:param theta_E: Einstein radius (in arcsec) -:return: velocity dispersion in units (km/s)

-
- -
-
-time_delay2fermat_pot(dt)[source]
-
-
Parameters
-

dt – time delay in units of days

-
-
Returns
-

Fermat potential in units arcsec**2 for a given cosmology

-
-
-
- -
-
-time_delay_units(fermat_pot, kappa_ext=0)[source]
-
-
Parameters
-
    -
  • fermat_pot – in units of arcsec^2 (e.g. Fermat potential)

  • -
  • kappa_ext – unit-less external shear not accounted for in the Fermat potential

  • -
-
-
Returns
-

time delay in days

-
-
-
- -
-
-uldm_angular2phys(kappa_0, theta_c)[source]
-

converts the anguar parameters entering the LensModel Uldm() (Ultra Light -Dark Matter) class in physical masses, i.e. the total soliton mass and the -mass of the particle -:param kappa_0: central convergence of profile -:param theta_c: core radius (in arcseconds) -:return: m_eV_log10, M_sol_log10, the log10 of the masses, m in eV and M in M_sun

-
- -
-
-uldm_mphys2angular(m_log10, M_log10)[source]
-

converts physical ULDM mass in the ones, in angular units, that enter -the LensModel Uldm() class -:param m_log10: exponent of ULDM mass in eV -:param M_log10: exponent of soliton mass in M_sun -:return: kappa_0, theta_c, the central convergence and core radius (in arcseconds)

-
- -
- -
-
-

lenstronomy.Cosmo.nfw_param module

-
-
-class lenstronomy.Cosmo.nfw_param.NFWParam(cosmo=None)[source]
-

Bases: object

-

class which contains a halo model parameters dependent on cosmology for NFW profile -All distances are given in physical units. Mass definitions are relative to 200 crit including redshift evolution. -The redshift evolution is cosmology dependent (dark energy). -The H0 dependence is propagated into the input and return units.

-
-
-M200(rs, rho0, c)[source]
-

M(R_200) calculation for NFW profile

-
-
Parameters
-
    -
  • rs (float) – scale radius

  • -
  • rho0 (float) – density normalization (characteristic density)

  • -
  • c (float [4,40]) – concentration

  • -
-
-
Returns
-

M(R_200) density

-
-
-
- -
-
-M_r200(r200, z)[source]
-
-
Parameters
-
    -
  • r200 – r200 in physical Mpc/h

  • -
  • z – redshift

  • -
-
-
Returns
-

M200 in M_sun/h

-
-
-
- -
-
-c_M_z(M, z)[source]
-

fitting function of http://moriond.in2p3.fr/J08/proceedings/duffy.pdf for the mass and redshift dependence of -the concentration parameter

-
-
Parameters
-
    -
  • M (float or numpy array) – halo mass in M_sun/h

  • -
  • z (float >0) – redshift

  • -
-
-
Returns
-

concentration parameter as float

-
-
-
- -
-
-c_rho0(rho0, z)[source]
-

computes the concentration given density normalization rho_0 in h^2/Mpc^3 (physical) (inverse of function rho0_c) -:param rho0: density normalization in h^2/Mpc^3 (physical) -:param z: redshift -:return: concentration parameter c

-
- -
-
-nfw_Mz(M, z)[source]
-

returns all needed parameter (in physical units modulo h) to draw the profile of the main halo -r200 in physical Mpc/h -rho_s in h^2/Mpc^3 (physical) -Rs in Mpc/h physical -c unit less

-
- -
-
-r200_M(M, z)[source]
-

computes the radius R_200 crit of a halo of mass M in physical distances M/h

-
-
Parameters
-
    -
  • M (float or numpy array) – halo mass in M_sun/h

  • -
  • z (float) – redshift

  • -
-
-
Returns
-

radius R_200 in physical Mpc/h

-
-
-
- -
-
-rho0_c(c, z)[source]
-

computes density normalization as a function of concentration parameter

-
-
Parameters
-
    -
  • c – concentration

  • -
  • z – redshift

  • -
-
-
Returns
-

density normalization in h^2/Mpc^3 (physical)

-
-
-
- -
-
-rhoc = 277536627000.0
-
- -
-
-rhoc_z(z)[source]
-
-
Parameters
-

z – redshift

-
-
Returns
-

critical density of the universe at redshift z in physical units [h^2 M_sun Mpc^-3]

-
-
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.Data.html b/docs/_build/html/lenstronomy.Data.html deleted file mode 100644 index b8e378803..000000000 --- a/docs/_build/html/lenstronomy.Data.html +++ /dev/null @@ -1,426 +0,0 @@ - - - - - - - - - lenstronomy.Data package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.Data package

-
-

Submodules

-
-
-

lenstronomy.Data.coord_transforms module

-
-
-class lenstronomy.Data.coord_transforms.Coordinates(transform_pix2angle, ra_at_xy_0, dec_at_xy_0)[source]
-

Bases: object

-

class to handle linear coordinate transformations of a square pixel image

-
-
-coordinate_grid(nx, ny)[source]
-
-
Parameters
-
    -
  • nx – number of pixels in x-direction

  • -
  • ny – number of pixels in y-direction

  • -
-
-
Returns
-

2d arrays with coordinates in RA/DEC with ra_coord[y-axis, x-axis]

-
-
-
- -
-
-map_coord2pix(ra, dec)[source]
-

maps the (ra,dec) coordinates of the system into the pixel coordinate of the image

-
-
Parameters
-
    -
  • ra – relative RA coordinate as defined by the coordinate frame

  • -
  • dec – relative DEC coordinate as defined by the coordinate frame

  • -
-
-
Returns
-

(x, y) pixel coordinates

-
-
-
- -
-
-map_pix2coord(x, y)[source]
-

maps the (x,y) pixel coordinates of the image into the system coordinates

-
-
Parameters
-
    -
  • x – pixel coordinate (can be 1d numpy array), defined in the center of the pixel

  • -
  • y – pixel coordinate (can be 1d numpy array), defined in the center of the pixel

  • -
-
-
Returns
-

relative (RA, DEC) coordinates of the system

-
-
-
- -
-
-property pixel_area
-

angular area of a pixel in the image -:return: area [arcsec^2]

-
- -
-
-property pixel_width
-

size of pixel -:return: sqrt(pixel_area)

-
- -
-
-property radec_at_xy_0
-
-
Returns
-

RA, DEC coordinate at (0,0) pixel coordinate

-
-
-
- -
-
-shift_coordinate_system(x_shift, y_shift, pixel_unit=False)[source]
-

shifts the coordinate system -:param x_shift: shift in x (or RA) -:param y_shift: shift in y (or DEC) -:param pixel_unit: bool, if True, units of pixels in input, otherwise RA/DEC -:return: updated data class with change in coordinate system

-
- -
-
-property transform_angle2pix
-
-
Returns
-

transformation matrix from angular to pixel coordinates

-
-
-
- -
-
-property transform_pix2angle
-
-
Returns
-

transformation matrix from pixel to angular coordinates

-
-
-
- -
-
-property xy_at_radec_0
-
-
Returns
-

pixel coordinate at angular (0,0) point

-
-
-
- -
- -
-
-class lenstronomy.Data.coord_transforms.Coordinates1D(transform_pix2angle, ra_at_xy_0, dec_at_xy_0)[source]
-

Bases: lenstronomy.Data.coord_transforms.Coordinates

-

coordinate grid described in 1-d arrays

-
-
-coordinate_grid(nx, ny)[source]
-
-
Parameters
-
    -
  • nx – number of pixels in x-direction

  • -
  • ny – number of pixels in y-direction

  • -
-
-
Returns
-

2d arrays with coordinates in RA/DEC with ra_coord[y-axis, x-axis]

-
-
-
- -
- -
-
-

lenstronomy.Data.imaging_data module

-
-
-class lenstronomy.Data.imaging_data.ImageData(image_data, exposure_time=None, background_rms=None, noise_map=None, gradient_boost_factor=None, ra_at_xy_0=0, dec_at_xy_0=0, transform_pix2angle=None, ra_shift=0, dec_shift=0)[source]
-

Bases: lenstronomy.Data.pixel_grid.PixelGrid, lenstronomy.Data.image_noise.ImageNoise

-

class to handle the data, coordinate system and masking, including convolution with various numerical precisions

-

The Data() class is initialized with keyword arguments:

-
    -
  • ‘image_data’: 2d numpy array of the image data

  • -
  • ‘transform_pix2angle’ 2x2 transformation matrix (linear) to transform a pixel shift into a coordinate shift (x, y) -> (ra, dec)

  • -
  • ‘ra_at_xy_0’ RA coordinate of pixel (0,0)

  • -
  • ‘dec_at_xy_0’ DEC coordinate of pixel (0,0)

  • -
-

optional keywords for shifts in the coordinate system: -- ‘ra_shift’: shifts the coordinate system with respect to ‘ra_at_xy_0’ -- ‘dec_shift’: shifts the coordinate system with respect to ‘dec_at_xy_0’

-

optional keywords for noise properties: -- ‘background_rms’: rms value of the background noise -- ‘exp_time’: float, exposure time to compute the Poisson noise contribution -- ‘exposure_map’: 2d numpy array, effective exposure time for each pixel. If set, will replace ‘exp_time’ -- ‘noise_map’: Gaussian noise (1-sigma) for each individual pixel. -If this keyword is set, the other noise properties will be ignored.

-

the likelihood for the data given model P(data|model) is defined in the function below. Please make sure that -your definitions and units of ‘exposure_map’, ‘background_rms’ and ‘image_data’ are in accordance with the -likelihood function. In particular, make sure that the Poisson noise contribution is defined in the count rate.

-
-
-property data
-
-
Returns
-

2d numpy array of data

-
-
-
- -
-
-log_likelihood(model, mask, additional_error_map=0)[source]
-

computes the likelihood of the data given the model p(data|model) -The Gaussian errors are estimated with the covariance matrix, based on the model image. The errors include the -background rms value and the exposure time to compute the Poisson noise level (in Gaussian approximation).

-
-
Parameters
-
    -
  • model – the model (same dimensions and units as data)

  • -
  • mask – bool (1, 0) values per pixel. If =0, the pixel is ignored in the likelihood

  • -
  • additional_error_map – additional error term (in same units as covariance matrix). -This can e.g. come from model errors in the PSF estimation.

  • -
-
-
Returns
-

the natural logarithm of the likelihood p(data|model)

-
-
-
- -
-
-update_data(image_data)[source]
-

update the data as well as the error matrix estimated from it when done so using the data

-
-
Parameters
-

image_data – 2d numpy array of same size as nx, ny

-
-
Returns
-

None

-
-
-
- -
- -
-
-

lenstronomy.Data.psf module

-
-
-class lenstronomy.Data.psf.PSF(psf_type='NONE', fwhm=None, truncation=5, pixel_size=None, kernel_point_source=None, psf_error_map=None, point_source_supersampling_factor=1, kernel_point_source_init=None)[source]
-

Bases: object

-

Point Spread Function class. -This class describes and manages products used to perform the PSF modeling (convolution for extended surface -brightness and painting of PSF’s for point sources).

-
-
-property fwhm
-
-
Returns
-

full width at half maximum of kernel (in units of pixel)

-
-
-
- -
-
-property kernel_pixel
-

returns the convolution kernel for a uniform surface brightness on a pixel size

-
-
Returns
-

2d numpy array

-
-
-
- -
-
-property kernel_point_source
-
- -
-
-kernel_point_source_supersampled(supersampling_factor, updata_cache=True)[source]
-

generates (if not already available) a supersampled PSF with ood numbers of pixels centered

-
-
Parameters
-
    -
  • supersampling_factor – int >=1, supersampling factor relative to pixel resolution

  • -
  • updata_cache – boolean, if True, updates the cached supersampling PSF if generated. -Attention, this will overwrite a previously used supersampled PSF if the resolution is changing.

  • -
-
-
Returns
-

super-sampled PSF as 2d numpy array

-
-
-
- -
-
-property psf_error_map
-
- -
-
-set_pixel_size(deltaPix)[source]
-

update pixel size

-
-
Parameters
-

deltaPix – pixel size in angular units (arc seconds)

-
-
Returns
-

None

-
-
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.GalKin.html b/docs/_build/html/lenstronomy.GalKin.html deleted file mode 100644 index 6f4c24cdf..000000000 --- a/docs/_build/html/lenstronomy.GalKin.html +++ /dev/null @@ -1,1604 +0,0 @@ - - - - - - - - - lenstronomy.GalKin package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.GalKin package

-
-

Submodules

-
-
-

lenstronomy.GalKin.analytic_kinematics module

-
-
-class lenstronomy.GalKin.analytic_kinematics.AnalyticKinematics(kwargs_cosmo, interpol_grid_num=100, log_integration=False, max_integrate=100, min_integrate=0.001)[source]
-

Bases: lenstronomy.GalKin.anisotropy.Anisotropy

-

class to compute eqn 20 in Suyu+2010 with a Monte-Carlo from rendering from the -light profile distribution and displacing them with a Gaussian seeing convolution

-
-
This class assumes spherical symmetry in light and mass distribution and
    -
  • a Hernquist light profile (parameterised by the half-light radius)

  • -
  • a power-law mass profile (parameterized by the Einstein radius and logarithmic slop)

  • -
-
-
-

The analytic equations for the kinematics in this approximation are presented e.g. in Suyu et al. 2010 and -the spectral rendering approach to compute the seeing convolved slit measurement is presented in Birrer et al. 2016. -The stellar anisotropy is parameterised based on Osipkov 1979; Merritt 1985.

-

all units are meant to be in angular arc seconds. The physical units are fold in through the angular diameter -distances

-
-
-delete_cache()[source]
-

deletes temporary cache tight to a specific model

-
-
Returns
-

-
-
-
- -
-
-static draw_light(kwargs_light)[source]
-
-
Parameters
-

kwargs_light – keyword argument (list) of the light model

-
-
Returns
-

3d radius (if possible), 2d projected radius, x-projected coordinate, y-projected coordinate

-
-
-
- -
-
-grav_potential(r, kwargs_mass)[source]
-

Gravitational potential in SI units

-
-
Parameters
-
    -
  • r – radius (arc seconds)

  • -
  • kwargs_mass

  • -
-
-
Returns
-

gravitational potential

-
-
-
- -
-
-sigma_r2(r, kwargs_mass, kwargs_light, kwargs_anisotropy)[source]
-

equation (19) in Suyu+ 2010

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • kwargs_mass – mass profile keyword arguments

  • -
  • kwargs_light – light profile keyword arguments

  • -
  • kwargs_anisotropy – anisotropy keyword arguments

  • -
-
-
Returns
-

velocity dispersion in [m/s]

-
-
-
- -
-
-sigma_s2(r, R, kwargs_mass, kwargs_light, kwargs_anisotropy)[source]
-

returns unweighted los velocity dispersion for a specified projected radius, with weight 1

-
-
Parameters
-
    -
  • r – 3d radius (not needed for this calculation)

  • -
  • R – 2d projected radius (in angular units of arcsec)

  • -
  • kwargs_mass – mass model parameters (following lenstronomy lens model conventions)

  • -
  • kwargs_light – deflector light parameters (following lenstronomy light model conventions)

  • -
  • kwargs_anisotropy – anisotropy parameters, may vary according to anisotropy type chosen. -We refer to the Anisotropy() class for details on the parameters.

  • -
-
-
Returns
-

line-of-sight projected velocity dispersion at projected radius R from 3d radius r

-
-
-
- -
- -
-
-

lenstronomy.GalKin.anisotropy module

-
-
-class lenstronomy.GalKin.anisotropy.Anisotropy(anisotropy_type)[source]
-

Bases: object

-

class that handles the kinematic anisotropy -sources: Mamon & Lokas 2005 -https://arxiv.org/pdf/astro-ph/0405491.pdf

-

Agnello et al. 2014 -https://arxiv.org/pdf/1401.4462.pdf

-
-
-K(r, R, **kwargs)[source]
-

equation A16 im Mamon & Lokas for Osipkov&Merrit anisotropy

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • R – projected 2d radius

  • -
  • kwargs – parameters of the specified anisotropy model

  • -
-
-
Returns
-

K(r, R)

-
-
-
- -
-
-anisotropy_solution(r, **kwargs)[source]
-

the solution to -d ln(f)/ d ln(r) = 2 beta(r)

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • kwargs – parameters of the specified anisotropy model

  • -
-
-
Returns
-

f(r)

-
-
-
- -
-
-beta_r(r, **kwargs)[source]
-

returns the anisotropy parameter at a given radius -:param r: 3d radius -:param kwargs: parameters of the specified anisotropy model -:return: beta(r)

-
- -
-
-delete_anisotropy_cache()[source]
-

deletes cached interpolations for a fixed anisotropy model -:return:

-
- -
- -
-
-class lenstronomy.GalKin.anisotropy.Colin[source]
-

Bases: object

-

class for stellar orbits anisotropy parameter based on Colin et al. (2000) -See Mamon & Lokas 2005 for details

-
-
-K(r, R, r_ani)[source]
-

equation A16 im Mamon & Lokas for Osipkov&Merrit anisotropy

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • R – projected 2d radius

  • -
  • r_ani – anisotropy radius

  • -
-
-
Returns
-

K(r, R)

-
-
-
- -
-
-static beta_r(r, r_ani)[source]
-

anisotropy as a function of radius

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • r_ani – anisotropy radius

  • -
-
-
Returns
-

beta

-
-
-
- -
- -
-
-class lenstronomy.GalKin.anisotropy.Const[source]
-

Bases: object

-

constant anisotropy model class -See Mamon & Lokas 2005 for details

-
-
-static K(r, R, beta)[source]
-

equation A16 im Mamon & Lokas for constant anisotropy

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • R – projected 2d radius

  • -
  • beta – anisotropy

  • -
-
-
Returns
-

K(r, R, beta)

-
-
-
- -
-
-anisotropy_solution(r, **kwargs)[source]
-

the solution to -d ln(f)/ d ln(r) = 2 beta(r)

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • kwargs – parameters of the specified anisotropy model

  • -
-
-
Returns
-

f(r)

-
-
-
- -
-
-static beta_r(r, beta)[source]
-

anisotropy as a function of radius

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • beta – anisotropy

  • -
-
-
Returns
-

beta

-
-
-
- -
- -
-
-class lenstronomy.GalKin.anisotropy.GeneralizedOM[source]
-

Bases: object

-

generalized Osipkov&Merrit profile -see Agnello et al. 2014 https://arxiv.org/pdf/1401.4462.pdf -b(r) = beta_inf * r^2 / (r^2 + r_ani^2)

-
-
-K(r, R, r_ani, beta_inf)[source]
-

equation19 in Agnello et al. 2014 for k_beta(R, r) such that -K(R, r) = (sqrt(r^2 - R^2) + k_beta(R, r)) / r

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • R – projected 2d radius

  • -
  • r_ani – anisotropy radius

  • -
  • beta_inf – anisotropy at infinity

  • -
-
-
Returns
-

K(r, R)

-
-
-
- -
-
-anisotropy_solution(r, r_ani, beta_inf)[source]
-

the solution to -d ln(f)/ d ln(r) = 2 beta(r) -See e.g. A5 in Mamon & Lokas with a scaling (nominator of Agnello et al. 2014 Equation (12)

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • r_ani – anisotropy radius

  • -
  • beta_inf – anisotropy at infinity

  • -
-
-
Returns
-

f(r)

-
-
-
- -
-
-static beta_r(r, r_ani, beta_inf)[source]
-

anisotropy as a function of radius

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • r_ani – anisotropy radius

  • -
  • beta_inf – anisotropy at infinity

  • -
-
-
Returns
-

beta

-
-
-
- -
-
-delete_cache()[source]
-

deletes the interpolation function of the hypergeometic function for a specific beta_inf

-
-
Returns
-

deleted self variables

-
-
-
- -
- -
-
-class lenstronomy.GalKin.anisotropy.Isotropic[source]
-

Bases: object

-

class for isotropic (beta=0) stellar orbits -See Mamon & Lokas 2005 for details

-
-
-static K(r, R)[source]
-

equation A16 im Mamon & Lokas for constant anisotropy

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • R – projected 2d radius

  • -
-
-
Returns
-

K(r, R)

-
-
-
- -
-
-anisotropy_solution(r, **kwargs)[source]
-

the solution to -d ln(f)/ d ln(r) = 2 beta(r) -See e.g. A3 in Mamon & Lokas

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • kwargs – parameters of the specified anisotropy model

  • -
-
-
Returns
-

f(r)

-
-
-
- -
-
-static beta_r(r)[source]
-

anisotropy as a function of radius

-
-
Parameters
-

r – 3d radius

-
-
Returns
-

beta

-
-
-
- -
- -
-
-class lenstronomy.GalKin.anisotropy.OsipkovMerritt[source]
-

Bases: object

-

class for Osipkov&Merrit stellar orbits -See Mamon & Lokas 2005 for details

-
-
-K(r, R, r_ani)[source]
-

equation A16 im Mamon & Lokas 2005 for Osipkov&Merrit anisotropy

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • R – projected 2d radius

  • -
  • r_ani – anisotropy radius

  • -
-
-
Returns
-

K(r, R)

-
-
-
- -
-
-static anisotropy_solution(r, r_ani)[source]
-

the solution to -d ln(f)/ d ln(r) = 2 beta(r) -See e.g. A5 in Mamon & Lokas

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • r_ani – anisotropy radius

  • -
-
-
Returns
-

f(r)

-
-
-
- -
-
-static beta_r(r, r_ani)[source]
-

anisotropy as a function of radius

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • r_ani – anisotropy radius

  • -
-
-
Returns
-

beta

-
-
-
- -
- -
-
-class lenstronomy.GalKin.anisotropy.Radial[source]
-

Bases: object

-

class for radial (beta=1) stellar orbits -See Mamon & Lokas 2005 for details

-
-
-K(r, R)[source]
-

equation A16 im Mamon & Lokas for constant anisotropy

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • R – projected 2d radius

  • -
-
-
Returns
-

K(r, R)

-
-
-
- -
-
-anisotropy_solution(r)[source]
-

the solution to -d ln(f)/ d ln(r) = 2 beta(r) -See e.g. A4 in Mamon & Lokas

-
-
Parameters
-

r – 3d radius

-
-
Returns
-

f(r)

-
-
-
- -
-
-static beta_r(r)[source]
-

anisotropy as a function of radius

-
-
Parameters
-

r – 3d radius

-
-
Returns
-

beta

-
-
-
- -
- -
-
-

lenstronomy.GalKin.aperture module

-
-
-class lenstronomy.GalKin.aperture.Aperture(aperture_type, **kwargs_aperture)[source]
-

Bases: object

-

defines mask(s) of spectra, can handle IFU and single slit/box type data.

-
-
-aperture_select(ra, dec)[source]
-
-
Parameters
-
    -
  • ra – angular coordinate of photon/ray

  • -
  • dec – angular coordinate of photon/ray

  • -
-
-
Returns
-

bool, True if photon/ray is within the slit, False otherwise, int of the segment of the IFU

-
-
-
- -
-
-property num_segments
-
- -
- -
-
-

lenstronomy.GalKin.aperture_types module

-
-
-class lenstronomy.GalKin.aperture_types.Frame(width_outer, width_inner, center_ra=0, center_dec=0, angle=0)[source]
-

Bases: object

-

rectangular box with a hole in the middle (also rectangular), effectively a frame

-
-
-aperture_select(ra, dec)[source]
-
-
Parameters
-
    -
  • ra – angular coordinate of photon/ray

  • -
  • dec – angular coordinate of photon/ray

  • -
-
-
Returns
-

bool, True if photon/ray is within the slit, False otherwise

-
-
-
- -
-
-property num_segments
-

number of segments with separate measurements of the velocity dispersion -:return: int

-
- -
- -
-
-class lenstronomy.GalKin.aperture_types.IFUShells(r_bins, center_ra=0, center_dec=0)[source]
-

Bases: object

-

class for an Integral Field Unit spectrograph with azimuthal shells where the kinematics are measured

-
-
-aperture_select(ra, dec)[source]
-
-
Parameters
-
    -
  • ra – angular coordinate of photon/ray

  • -
  • dec – angular coordinate of photon/ray

  • -
-
-
Returns
-

bool, True if photon/ray is within the slit, False otherwise, index of shell

-
-
-
- -
-
-property num_segments
-

number of segments with separate measurements of the velocity dispersion -:return: int

-
- -
- -
-
-class lenstronomy.GalKin.aperture_types.Shell(r_in, r_out, center_ra=0, center_dec=0)[source]
-

Bases: object

-

Shell aperture

-
-
-aperture_select(ra, dec)[source]
-
-
Parameters
-
    -
  • ra – angular coordinate of photon/ray

  • -
  • dec – angular coordinate of photon/ray

  • -
-
-
Returns
-

bool, True if photon/ray is within the slit, False otherwise

-
-
-
- -
-
-property num_segments
-

number of segments with separate measurements of the velocity dispersion -:return: int

-
- -
- -
-
-class lenstronomy.GalKin.aperture_types.Slit(length, width, center_ra=0, center_dec=0, angle=0)[source]
-

Bases: object

-

Slit aperture description

-
-
-aperture_select(ra, dec)[source]
-
-
Parameters
-
    -
  • ra – angular coordinate of photon/ray

  • -
  • dec – angular coordinate of photon/ray

  • -
-
-
Returns
-

bool, True if photon/ray is within the slit, False otherwise

-
-
-
- -
-
-property num_segments
-

number of segments with separate measurements of the velocity dispersion -:return: int

-
- -
- -
-
-lenstronomy.GalKin.aperture_types.frame_select(ra, dec, width_outer, width_inner, center_ra=0, center_dec=0, angle=0)[source]
-
-
Parameters
-
    -
  • ra – angular coordinate of photon/ray

  • -
  • dec – angular coordinate of photon/ray

  • -
  • width_outer – width of box to the outer parts

  • -
  • width_inner – width of inner removed box

  • -
  • center_ra – center of slit

  • -
  • center_dec – center of slit

  • -
  • angle – orientation angle of slit, angle=0 corresponds length in RA direction

  • -
-
-
Returns
-

bool, True if photon/ray is within the box with a hole, False otherwise

-
-
-
- -
-
-lenstronomy.GalKin.aperture_types.shell_ifu_select(ra, dec, r_bin, center_ra=0, center_dec=0)[source]
-
-
Parameters
-
    -
  • ra – angular coordinate of photon/ray

  • -
  • dec – angular coordinate of photon/ray

  • -
  • r_bin – array of radial bins to average the dispersion spectra in ascending order. -It starts with the inner-most edge to the outermost edge.

  • -
  • center_ra – center of the sphere

  • -
  • center_dec – center of the sphere

  • -
-
-
Returns
-

boolean, True if within the radial range, False otherwise

-
-
-
- -
-
-lenstronomy.GalKin.aperture_types.shell_select(ra, dec, r_in, r_out, center_ra=0, center_dec=0)[source]
-
-
Parameters
-
    -
  • ra – angular coordinate of photon/ray

  • -
  • dec – angular coordinate of photon/ray

  • -
  • r_in – innermost radius to be selected

  • -
  • r_out – outermost radius to be selected

  • -
  • center_ra – center of the sphere

  • -
  • center_dec – center of the sphere

  • -
-
-
Returns
-

boolean, True if within the radial range, False otherwise

-
-
-
- -
-
-lenstronomy.GalKin.aperture_types.slit_select(ra, dec, length, width, center_ra=0, center_dec=0, angle=0)[source]
-
-
Parameters
-
    -
  • ra – angular coordinate of photon/ray

  • -
  • dec – angular coordinate of photon/ray

  • -
  • length – length of slit

  • -
  • width – width of slit

  • -
  • center_ra – center of slit

  • -
  • center_dec – center of slit

  • -
  • angle – orientation angle of slit, angle=0 corresponds length in RA direction

  • -
-
-
Returns
-

bool, True if photon/ray is within the slit, False otherwise

-
-
-
- -
-
-

lenstronomy.GalKin.cosmo module

-
-
-class lenstronomy.GalKin.cosmo.Cosmo(d_d, d_s, d_ds)[source]
-

Bases: object

-

cosmological quantities

-
-
-arcsec2phys_lens(theta)[source]
-

converts are seconds to physical units on the deflector -:param theta: angle observed on the sky in units of arc seconds -:return: pyhsical distance of the angle in units of Mpc

-
- -
-
-property epsilon_crit
-

returns the critical projected mass density in units of M_sun/Mpc^2 (physical units)

-
- -
- -
-
-

lenstronomy.GalKin.galkin module

-
-
-class lenstronomy.GalKin.galkin.Galkin(kwargs_model, kwargs_aperture, kwargs_psf, kwargs_cosmo, kwargs_numerics=None, analytic_kinematics=False)[source]
-

Bases: lenstronomy.GalKin.galkin_model.GalkinModel, lenstronomy.GalKin.observation.GalkinObservation

-

Major class to compute velocity dispersion measurements given light and mass models

-

The class supports any mass and light distribution (and superposition thereof) that has a 3d correspondance in their -2d lens model distribution. For models that do not have this correspondance, you may want to apply a -Multi-Gaussian Expansion (MGE) on their models and use the MGE to be de-projected to 3d.

-

The computation follows Mamon&Lokas 2005 and performs the spectral rendering of the seeing convolved apperture with -the method introduced by Birrer et al. 2016.

-

The class supports various types of anisotropy models (see Anisotropy class) and aperture types (see Aperture class).

-

Solving the Jeans Equation requires a numerical integral over the 3d light and mass profile (see Mamon&Lokas 2005). -This class (as well as the dedicated LightModel and MassModel classes) perform those integral numerically with an -interpolated grid.

-

The seeing convolved integral over the aperture is computed by rendering spectra (light weighted LOS kinematics) -from the light distribution.

-
-
The cosmology assumed to compute the physical mass and distances are set via the kwargs_cosmo keyword arguments.

d_d: Angular diameter distance to the deflector (in Mpc) -d_s: Angular diameter distance to the source (in Mpc) -d_ds: Angular diameter distance from the deflector to the source (in Mpc)

-
-
-

The numerical options can be chosen through the kwargs_numerics keywords

-
-

interpol_grid_num: number of interpolation points in the light and mass profile (radially). This number should -be chosen high enough to accurately describe the true light profile underneath. -log_integration: bool, if True, performs the interpolation and numerical integration in log-scale.

-

max_integrate: maximum 3d radius to where the numerical integration of the Jeans Equation solver is made. -This value should be large enough to contain most of the light and to lead to a converged result. -min_integrate: minimal integration value. This value should be very close to zero but some mass and light -profiles are diverging and a numerically stabel value should be chosen.

-
-

These numerical options should be chosen to allow for a converged result (within your tolerance) but not too -conservative to impact too much the computational cost. Reasonable values might depend on the specific problem.

-
-
-dispersion(kwargs_mass, kwargs_light, kwargs_anisotropy, sampling_number=1000)[source]
-

computes the averaged LOS velocity dispersion in the slit (convolved)

-
-
Parameters
-
    -
  • kwargs_mass – mass model parameters (following lenstronomy lens model conventions)

  • -
  • kwargs_light – deflector light parameters (following lenstronomy light model conventions)

  • -
  • kwargs_anisotropy – anisotropy parameters, may vary according to anisotropy type chosen. -We refer to the Anisotropy() class for details on the parameters.

  • -
  • sampling_number – int, number of spectral sampling of the light distribution

  • -
-
-
Returns
-

integrated LOS velocity dispersion in units [km/s]

-
-
-
- -
-
-dispersion_map(kwargs_mass, kwargs_light, kwargs_anisotropy, num_kin_sampling=1000, num_psf_sampling=100)[source]
-

computes the velocity dispersion in each Integral Field Unit

-
-
Parameters
-
    -
  • kwargs_mass – keyword arguments of the mass model

  • -
  • kwargs_light – keyword argument of the light model

  • -
  • kwargs_anisotropy – anisotropy keyword arguments

  • -
  • num_kin_sampling – int, number of draws from a kinematic prediction of a LOS

  • -
  • num_psf_sampling – int, number of displacements/render from a spectra to be displaced on the IFU

  • -
-
-
Returns
-

ordered array of velocity dispersions [km/s] for each unit

-
-
-
- -
- -
-
-

lenstronomy.GalKin.galkin_model module

-
-
-class lenstronomy.GalKin.galkin_model.GalkinModel(kwargs_model, kwargs_cosmo, kwargs_numerics=None, analytic_kinematics=False)[source]
-

Bases: object

-

this class handles all the kinematic modeling aspects of Galkin -Excluded are observational conditions (seeing, aperture etc) -Major class to compute velocity dispersion measurements given light and mass models

-

The class supports any mass and light distribution (and superposition thereof) that has a 3d correspondance in their -2d lens model distribution. For models that do not have this correspondence, you may want to apply a -Multi-Gaussian Expansion (MGE) on their models and use the MGE to be de-projected to 3d.

-

The computation follows Mamon&Lokas 2005.

-

The class supports various types of anisotropy models (see Anisotropy class). -Solving the Jeans Equation requires a numerical integral over the 3d light and mass profile (see Mamon&Lokas 2005). -This class (as well as the dedicated LightModel and MassModel classes) perform those integral numerically with an -interpolated grid.

-
-
The cosmology assumed to compute the physical mass and distances are set via the kwargs_cosmo keyword arguments.

d_d: Angular diameter distance to the deflector (in Mpc) -d_s: Angular diameter distance to the source (in Mpc) -d_ds: Angular diameter distance from the deflector to the source (in Mpc)

-
-
-

The numerical options can be chosen through the kwargs_numerics keywords

-
-

interpol_grid_num: number of interpolation points in the light and mass profile (radially). This number should -be chosen high enough to accurately describe the true light profile underneath. -log_integration: bool, if True, performs the interpolation and numerical integration in log-scale.

-

max_integrate: maximum 3d radius to where the numerical integration of the Jeans Equation solver is made. -This value should be large enough to contain most of the light and to lead to a converged result. -min_integrate: minimal integration value. This value should be very close to zero but some mass and light -profiles are diverging and a numerically stable value should be chosen.

-
-

These numerical options should be chosen to allow for a converged result (within your tolerance) but not too -conservative to impact too much the computational cost. Reasonable values might depend on the specific problem.

-
-
-check_df(r, kwargs_mass, kwargs_light, kwargs_anisotropy)[source]
-

checks whether the phase space distribution function of a given anisotropy model is positive. -Currently this is implemented by the relation provided by Ciotti and Morganti 2010 equation (10) -https://arxiv.org/pdf/1006.2344.pdf

-
-
Parameters
-
    -
  • r – 3d radius to check slope-anisotropy constraint

  • -
  • kwargs_mass – keyword arguments for mass (lens) profile

  • -
  • kwargs_light – keyword arguments for light profile

  • -
  • kwargs_anisotropy – keyword arguments for stellar anisotropy distribution

  • -
-
-
Returns
-

equation (10) >= 0 for physical interpretation

-
-
-
- -
- -
-
-

lenstronomy.GalKin.light_profile module

-
-
-class lenstronomy.GalKin.light_profile.LightProfile(profile_list, interpol_grid_num=2000, max_interpolate=1000, min_interpolate=0.001, max_draw=None)[source]
-

Bases: object

-

class to deal with the light distribution for GalKin

-
-
In particular, this class allows for:
    -
  • (faster) interpolated calculation for a given profile (for a range that the Jeans equation is computed)

  • -
  • drawing 3d and 2d distributions from a given (spherical) profile -(within bounds where the Jeans equation is expected to be accurate)

  • -
  • 2d projected profiles within the 3d integration range (truncated)

  • -
-
-
-
-
-delete_cache()[source]
-

deletes cached interpolation function of the CDF for a specific light profile

-
-
Returns
-

None

-
-
-
- -
-
-draw_light_2d(kwargs_list, n=1, new_compute=False)[source]
-

constructs the CDF and draws from it random realizations of projected radii R -CDF is constructed in logarithmic projected radius spacing

-
-
Parameters
-
    -
  • kwargs_list – light model keyword argument list

  • -
  • n – int, number of draws per functino call

  • -
  • new_compute – re-computes the interpolated CDF

  • -
-
-
Returns
-

realization of projected radius following the distribution of the light model

-
-
-
- -
-
-draw_light_2d_linear(kwargs_list, n=1, new_compute=False)[source]
-

constructs the CDF and draws from it random realizations of projected radii R -The interpolation of the CDF is done in linear projected radius space

-
-
Parameters
-
    -
  • kwargs_list – list of keyword arguments of light profiles (see LightModule)

  • -
  • n – int; number of draws

  • -
  • new_compute – boolean, if True, re-computes the interpolation -(becomes valid with updated kwargs_list argument)

  • -
-
-
Returns
-

draw of projected radius for the given light profile distribution

-
-
-
- -
-
-draw_light_3d(kwargs_list, n=1, new_compute=False)[source]
-

constructs the CDF and draws from it random realizations of 3D radii r

-
-
Parameters
-
    -
  • kwargs_list – light model keyword argument list

  • -
  • n – int, number of draws per function call

  • -
  • new_compute – re-computes the interpolated CDF

  • -
-
-
Returns
-

realization of projected radius following the distribution of the light model

-
-
-
- -
-
-light_2d(R, kwargs_list)[source]
-

projected light profile (integrated to infinity in the projected axis)

-
-
Parameters
-
    -
  • R – projected 2d radius

  • -
  • kwargs_list – list of keyword arguments of light profiles (see LightModule)

  • -
-
-
Returns
-

projected surface brightness

-
-
-
- -
-
-light_2d_finite(R, kwargs_list)[source]
-

projected light profile (integrated to FINITE 3d boundaries from the max_interpolate)

-
-
Parameters
-
    -
  • R – projected 2d radius (between min_interpolate and max_interpolate

  • -
  • kwargs_list – list of keyword arguments of light profiles (see LightModule)

  • -
-
-
Returns
-

projected surface brightness

-
-
-
- -
-
-light_3d(r, kwargs_list)[source]
-

three-dimensional light profile

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • kwargs_list – list of keyword arguments of light profiles (see LightModule)

  • -
-
-
Returns
-

flux per 3d volume at radius r

-
-
-
- -
-
-light_3d_interp(r, kwargs_list, new_compute=False)[source]
-

interpolated three-dimensional light profile within bounds [min_interpolate, max_interpolate] -in logarithmic units with interpol_grid_num numbers of interpolation steps

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • kwargs_list – list of keyword arguments of light profiles (see LightModule)

  • -
  • new_compute – boolean, if True, re-computes the interpolation -(becomes valid with updated kwargs_list argument)

  • -
-
-
Returns
-

flux per 3d volume at radius r

-
-
-
- -
- -
-
-

lenstronomy.GalKin.numeric_kinematics module

-
-
-class lenstronomy.GalKin.numeric_kinematics.NumericKinematics(kwargs_model, kwargs_cosmo, interpol_grid_num=1000, log_integration=True, max_integrate=1000, min_integrate=0.0001, max_light_draw=None, lum_weight_int_method=True)[source]
-

Bases: lenstronomy.GalKin.anisotropy.Anisotropy

-
-
-delete_cache()[source]
-

delete interpolation function for a specific mass and light profile as well as for a specific anisotropy model

-
-
Returns
-

-
-
-
- -
-
-draw_light(kwargs_light)[source]
-
-
Parameters
-

kwargs_light – keyword argument (list) of the light model

-
-
Returns
-

3d radius (if possible), 2d projected radius, x-projected coordinate, y-projected coordinate

-
-
-
- -
-
-grav_potential(r, kwargs_mass)[source]
-

Gravitational potential in SI units

-
-
Parameters
-
    -
  • r – radius (arc seconds)

  • -
  • kwargs_mass

  • -
-
-
Returns
-

gravitational potential

-
-
-
- -
-
-mass_3d(r, kwargs)[source]
-

mass enclosed a 3d radius

-
-
Parameters
-
    -
  • r – in arc seconds

  • -
  • kwargs – lens model parameters in arc seconds

  • -
-
-
Returns
-

mass enclosed physical radius in kg

-
-
-
- -
-
-sigma_r2(r, kwargs_mass, kwargs_light, kwargs_anisotropy)[source]
-

computes numerically the solution of the Jeans equation for a specific 3d radius -E.g. Equation (A1) of Mamon & Lokas https://arxiv.org/pdf/astro-ph/0405491.pdf

-
-\[l(r) \sigma_r(r) ^ 2 = 1/f(r) \int_r^{\infty} f(s) l(s) G M(s) / s^2 ds\]
-

where l(r) is the 3d light profile -M(s) is the enclosed 3d mass -f is the solution to -d ln(f)/ d ln(r) = 2 beta(r)

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • kwargs_mass – mass model parameters (following lenstronomy lens model conventions)

  • -
  • kwargs_light – deflector light parameters (following lenstronomy light model conventions)

  • -
  • kwargs_anisotropy – anisotropy parameters, may vary according to anisotropy type chosen. -We refer to the Anisotropy() class for details on the parameters.

  • -
-
-
Returns
-

sigma_r**2

-
-
-
- -
-
-sigma_s2(r, R, kwargs_mass, kwargs_light, kwargs_anisotropy)[source]
-

returns unweighted los velocity dispersion for a specified 3d and projected radius -(if lum_weight_int_method=True then the 3d radius is not required and the function directly performs the -luminosity weighted integral in projection at R)

-
-
Parameters
-
    -
  • r – 3d radius (not needed for this calculation)

  • -
  • R – 2d projected radius (in angular units of arcsec)

  • -
  • kwargs_mass – mass model parameters (following lenstronomy lens model conventions)

  • -
  • kwargs_light – deflector light parameters (following lenstronomy light model conventions)

  • -
  • kwargs_anisotropy – anisotropy parameters, may vary according to anisotropy type chosen. -We refer to the Anisotropy() class for details on the parameters.

  • -
-
-
Returns
-

weighted line-of-sight projected velocity dispersion at projected radius R with weights I

-
-
-
- -
-
-sigma_s2_project(R, kwargs_mass, kwargs_light, kwargs_anisotropy)[source]
-

returns luminosity-weighted los velocity dispersion for a specified projected radius R and weight

-
-
Parameters
-
    -
  • R – 2d projected radius (in angular units of arcsec)

  • -
  • kwargs_mass – mass model parameters (following lenstronomy lens model conventions)

  • -
  • kwargs_light – deflector light parameters (following lenstronomy light model conventions)

  • -
  • kwargs_anisotropy – anisotropy parameters, may vary according to anisotropy type chosen. -We refer to the Anisotropy() class for details on the parameters.

  • -
-
-
Returns
-

line-of-sight projected velocity dispersion at projected radius R

-
-
-
- -
-
-sigma_s2_r(r, R, kwargs_mass, kwargs_light, kwargs_anisotropy)[source]
-

returns unweighted los velocity dispersion for a specified 3d radius r at projected radius R

-
-
Parameters
-
    -
  • r – 3d radius (not needed for this calculation)

  • -
  • R – 2d projected radius (in angular units of arcsec)

  • -
  • kwargs_mass – mass model parameters (following lenstronomy lens model conventions)

  • -
  • kwargs_light – deflector light parameters (following lenstronomy light model conventions)

  • -
  • kwargs_anisotropy – anisotropy parameters, may vary according to anisotropy type chosen. -We refer to the Anisotropy() class for details on the parameters.

  • -
-
-
Returns
-

line-of-sight projected velocity dispersion at projected radius R from 3d radius r

-
-
-
- -
- -
-
-

lenstronomy.GalKin.observation module

-
-
-class lenstronomy.GalKin.observation.GalkinObservation(kwargs_aperture, kwargs_psf)[source]
-

Bases: lenstronomy.GalKin.psf.PSF, lenstronomy.GalKin.aperture.Aperture

-

this class sets the base for the observational properties (aperture and seeing condition)

-
- -
-
-

lenstronomy.GalKin.psf module

-
-
-class lenstronomy.GalKin.psf.PSF(psf_type, **kwargs_psf)[source]
-

Bases: object

-

general class to handle the PSF in the GalKin module for rendering the displacement of photons/spectro

-
-
-displace_psf(x, y)[source]
-
-
Parameters
-
    -
  • x – x-coordinate of light ray

  • -
  • y – y-coordinate of light ray

  • -
-
-
Returns
-

x’, y’ displaced by the two dimensional PSF distribution function

-
-
-
- -
- -
-
-class lenstronomy.GalKin.psf.PSFGaussian(fwhm)[source]
-

Bases: object

-

Gaussian PSF

-
-
-displace_psf(x, y)[source]
-
-
Parameters
-
    -
  • x – x-coordinate of light ray

  • -
  • y – y-coordinate of light ray

  • -
-
-
Returns
-

x’, y’ displaced by the two dimensional PSF distribution function

-
-
-
- -
- -
-
-class lenstronomy.GalKin.psf.PSFMoffat(fwhm, moffat_beta)[source]
-

Bases: object

-

Moffat PSF

-
-
-displace_psf(x, y)[source]
-
-
Parameters
-
    -
  • x – x-coordinate of light ray

  • -
  • y – y-coordinate of light ray

  • -
-
-
Returns
-

x’, y’ displaced by the two dimensional PSF distribution function

-
-
-
- -
- -
-
-

lenstronomy.GalKin.velocity_util module

-
-
-lenstronomy.GalKin.velocity_util.displace_PSF_gaussian(x, y, FWHM)[source]
-
-
Parameters
-
    -
  • x – x-coord (arc sec)

  • -
  • y – y-coord (arc sec)

  • -
  • FWHM – psf size (arc sec)

  • -
-
-
Returns
-

x’, y’ random displaced according to psf

-
-
-
- -
-
-lenstronomy.GalKin.velocity_util.displace_PSF_moffat(x, y, FWHM, beta)[source]
-
-
Parameters
-
    -
  • x – x-coordinate of light ray

  • -
  • y – y-coordinate of light ray

  • -
  • FWHM – full width at half maximum

  • -
  • beta – Moffat beta parameter

  • -
-
-
Returns
-

displaced ray by PSF

-
-
-
- -
-
-lenstronomy.GalKin.velocity_util.draw_cdf_Y(beta)[source]
-

Draw c.d.f for Moffat function according to Berge et al. Ufig paper, equation B2 -cdf(Y) = 1-Y**(1-beta)

-
-
Returns
-

-
-
-
- -
-
-lenstronomy.GalKin.velocity_util.draw_hernquist(a)[source]
-
-
Parameters
-

a – 0.551*r_eff

-
-
Returns
-

realisation of radius of Hernquist luminosity weighting in 3d

-
-
-
- -
-
-lenstronomy.GalKin.velocity_util.draw_moffat_r(FWHM, beta)[source]
-
-
Parameters
-
    -
  • FWHM – full width at half maximum

  • -
  • beta – Moffat beta parameter

  • -
-
-
Returns
-

draw from radial Moffat distribution

-
-
-
- -
-
-lenstronomy.GalKin.velocity_util.draw_xy(R)[source]
-
-
Parameters
-

R – projected radius

-
-
Returns
-

-
-
-
- -
-
-lenstronomy.GalKin.velocity_util.hyp_2F1(a, b, c, z)[source]
-

http://docs.sympy.org/0.7.1/modules/mpmath/functions/hypergeometric.html

-
- -
-
-lenstronomy.GalKin.velocity_util.moffat_fwhm_alpha(FWHM, beta)[source]
-

computes alpha parameter from FWHM and beta for a Moffat profile

-
-
Parameters
-
    -
  • FWHM – full width at half maximum

  • -
  • beta – beta parameter of Moffat profile

  • -
-
-
Returns
-

alpha parameter of Moffat profile

-
-
-
- -
-
-lenstronomy.GalKin.velocity_util.moffat_r(r, alpha, beta)[source]
-

Moffat profile

-
-
Parameters
-
    -
  • r – radial coordinate

  • -
  • alpha – Moffat parameter

  • -
  • beta – exponent

  • -
-
-
Returns
-

Moffat profile

-
-
-
- -
-
-lenstronomy.GalKin.velocity_util.project2d_random(r)[source]
-

draws a random projection from radius r in 2d and 1d -:param r: 3d radius -:return: R, x, y

-
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.ImSim.MultiBand.html b/docs/_build/html/lenstronomy.ImSim.MultiBand.html deleted file mode 100644 index 0ad7f5e3a..000000000 --- a/docs/_build/html/lenstronomy.ImSim.MultiBand.html +++ /dev/null @@ -1,490 +0,0 @@ - - - - - - - - - lenstronomy.ImSim.MultiBand package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.ImSim.MultiBand package

-
-

Submodules

-
-
-

lenstronomy.ImSim.MultiBand.joint_linear module

-
-
-class lenstronomy.ImSim.MultiBand.joint_linear.JointLinear(multi_band_list, kwargs_model, compute_bool=None, likelihood_mask_list=None)[source]
-

Bases: lenstronomy.ImSim.MultiBand.multi_linear.MultiLinear

-

class to model multiple exposures in the same band and makes a constraint fit to all bands simultaneously -with joint constraints on the surface brightness of the model. This model setting require the same surface -brightness models to be called in all available images/bands

-
-
-property data_response
-

returns the 1d array of the data element that is fitted for (including masking)

-
-
Returns
-

1d numpy array

-
-
-
- -
-
-error_response(kwargs_lens, kwargs_ps, kwargs_special=None)[source]
-

returns the 1d array of the error estimate corresponding to the data response

-
-
Returns
-

1d numpy array of response, 2d array of additonal errors (e.g. point source uncertainties)

-
-
-
- -
-
-image_linear_solve(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None, inv_bool=False)[source]
-

computes the image (lens and source surface brightness with a given lens model). -The linear parameters are computed with a weighted linear least square optimization -(i.e. flux normalization of the brightness profiles)

-
-
Parameters
-
    -
  • kwargs_lens – list of keyword arguments corresponding to the superposition of different lens profiles

  • -
  • kwargs_source – list of keyword arguments corresponding to the superposition of different source light profiles

  • -
  • kwargs_lens_light – list of keyword arguments corresponding to different lens light surface brightness profiles

  • -
  • kwargs_ps – keyword arguments corresponding to “other” parameters, such as external shear and point source image positions

  • -
  • inv_bool – if True, invert the full linear solver Matrix Ax = y for the purpose of the covariance matrix.

  • -
-
-
Returns
-

1d array of surface brightness pixels of the optimal solution of the linear parameters to match the data

-
-
-
- -
-
-likelihood_data_given_model(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None, source_marg=False, linear_prior=None, check_positive_flux=False)[source]
-

computes the likelihood of the data given a model -This is specified with the non-linear parameters and a linear inversion and prior marginalisation.

-
-
Parameters
-
    -
  • kwargs_lens

  • -
  • kwargs_source

  • -
  • kwargs_lens_light

  • -
  • kwargs_ps

  • -
  • check_positive_flux – bool, if True, checks whether the linear inversion resulted in non-negative flux -components and applies a punishment in the likelihood if so.

  • -
-
-
Returns
-

log likelihood (natural logarithm) (sum of the log likelihoods of the individual images)

-
-
-
- -
-
-linear_response_matrix(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None)[source]
-

computes the linear response matrix (m x n), with n being the data size and m being the coefficients

-
-
Parameters
-
    -
  • kwargs_lens

  • -
  • kwargs_source

  • -
  • kwargs_lens_light

  • -
  • kwargs_ps

  • -
-
-
Returns
-

-
-
-
- -
- -
-
-

lenstronomy.ImSim.MultiBand.multi_data_base module

-
-
-class lenstronomy.ImSim.MultiBand.multi_data_base.MultiDataBase(image_model_list, compute_bool=None)[source]
-

Bases: object

-

Base class with definitions that are shared among all variations of modelling multiple data sets

-
-
-property num_bands
-
- -
-
-property num_data_evaluate
-
- -
-
-num_param_linear(kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps)[source]
-
-
Returns
-

number of linear coefficients to be solved for in the linear inversion

-
-
-
- -
-
-property num_response_list
-

list of number of data elements that are used in the minimization

-
-
Returns
-

list of integers

-
-
-
- -
-
-reduced_residuals(model_list, error_map_list=None)[source]
-
-
Parameters
-
    -
  • model_list – list of models

  • -
  • error_map_list – list of error maps

  • -
-
-
Returns
-

-
-
-
- -
-
-reset_point_source_cache(cache=True)[source]
-

deletes all the cache in the point source class and saves it from then on

-
-
Returns
-

-
-
-
- -
- -
-
-

lenstronomy.ImSim.MultiBand.multi_linear module

-
-
-class lenstronomy.ImSim.MultiBand.multi_linear.MultiLinear(multi_band_list, kwargs_model, likelihood_mask_list=None, compute_bool=None, kwargs_pixelbased=None)[source]
-

Bases: lenstronomy.ImSim.MultiBand.multi_data_base.MultiDataBase

-

class to simulate/reconstruct images in multi-band option. -This class calls functions of image_model.py with different bands with -joint non-linear parameters and decoupled linear parameters.

-

the class supports keyword arguments ‘index_lens_model_list’, ‘index_source_light_model_list’, -‘index_lens_light_model_list’, ‘index_point_source_model_list’, ‘index_optical_depth_model_list’ in kwargs_model -These arguments should be lists of length the number of imaging bands available and each entry in the list -is a list of integers specifying the model components being evaluated for the specific band.

-

E.g. there are two bands and you want to different light profiles being modeled. -- you define two different light profiles lens_light_model_list = [‘SERSIC’, ‘SERSIC’] -- set index_lens_light_model_list = [[0], [1]] -- (optional) for now all the parameters between the two light profiles are independent in the model. You have -the possibility to join a subset of model parameters (e.g. joint centroid). See the Param() class for documentation.

-
-
-image_linear_solve(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None, inv_bool=False)[source]
-

computes the image (lens and source surface brightness with a given lens model). -The linear parameters are computed with a weighted linear least square optimization -(i.e. flux normalization of the brightness profiles)

-
-
Parameters
-
    -
  • kwargs_lens – list of keyword arguments corresponding to the superposition of different lens profiles

  • -
  • kwargs_source – list of keyword arguments corresponding to the superposition of different source light profiles

  • -
  • kwargs_lens_light – list of keyword arguments corresponding to different lens light surface brightness profiles

  • -
  • kwargs_ps – keyword arguments corresponding to “other” parameters, such as external shear and point source image positions

  • -
  • inv_bool – if True, invert the full linear solver Matrix Ax = y for the purpose of the covariance matrix.

  • -
-
-
Returns
-

1d array of surface brightness pixels of the optimal solution of the linear parameters to match the data

-
-
-
- -
-
-likelihood_data_given_model(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None, source_marg=False, linear_prior=None, check_positive_flux=False)[source]
-

computes the likelihood of the data given a model -This is specified with the non-linear parameters and a linear inversion and prior marginalisation.

-
-
Parameters
-
    -
  • kwargs_lens

  • -
  • kwargs_source

  • -
  • kwargs_lens_light

  • -
  • kwargs_ps

  • -
  • check_positive_flux – bool, if True, checks whether the linear inversion resulted in non-negative flux -components and applies a punishment in the likelihood if so.

  • -
-
-
Returns
-

log likelihood (natural logarithm) (sum of the log likelihoods of the individual images)

-
-
-
- -
- -
-
-

lenstronomy.ImSim.MultiBand.single_band_multi_model module

-
-
-class lenstronomy.ImSim.MultiBand.single_band_multi_model.SingleBandMultiModel(multi_band_list, kwargs_model, likelihood_mask_list=None, band_index=0, kwargs_pixelbased=None)[source]
-

Bases: lenstronomy.ImSim.image_linear_solve.ImageLinearFit

-

class to simulate/reconstruct images in multi-band option. -This class calls functions of image_model.py with different bands with -decoupled linear parameters and the option to pass/select different light models for the different bands

-

the class supports keyword arguments ‘index_lens_model_list’, ‘index_source_light_model_list’, -‘index_lens_light_model_list’, ‘index_point_source_model_list’, ‘index_optical_depth_model_list’ in kwargs_model -These arguments should be lists of length the number of imaging bands available and each entry in the list -is a list of integers specifying the model components being evaluated for the specific band.

-

E.g. there are two bands and you want to different light profiles being modeled. -- you define two different light profiles lens_light_model_list = [‘SERSIC’, ‘SERSIC’] -- set index_lens_light_model_list = [[0], [1]] -- (optional) for now all the parameters between the two light profiles are independent in the model. You have -the possibility to join a subset of model parameters (e.g. joint centroid). See the Param() class for documentation.

-
-
-error_map_source(kwargs_source, x_grid, y_grid, cov_param, model_index_select=True)[source]
-

variance of the linear source reconstruction in the source plane coordinates, -computed by the diagonal elements of the covariance matrix of the source reconstruction as a sum of the errors -of the basis set.

-
-
Parameters
-
    -
  • kwargs_source – keyword arguments of source model

  • -
  • x_grid – x-axis of positions to compute error map

  • -
  • y_grid – y-axis of positions to compute error map

  • -
  • cov_param – covariance matrix of liner inversion parameters

  • -
  • model_index_select – boolean, if True, selects the model components of this band (default). If False, -assumes input kwargs_source is already selected list.

  • -
-
-
Returns
-

diagonal covariance errors at the positions (x_grid, y_grid)

-
-
-
- -
-
-image_linear_solve(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None, inv_bool=False)[source]
-

computes the image (lens and source surface brightness with a given lens model). -The linear parameters are computed with a weighted linear least square optimization (i.e. flux normalization of the brightness profiles) -:param kwargs_lens: list of keyword arguments corresponding to the superposition of different lens profiles -:param kwargs_source: list of keyword arguments corresponding to the superposition of different source light profiles -:param kwargs_lens_light: list of keyword arguments corresponding to different lens light surface brightness profiles -:param kwargs_ps: keyword arguments corresponding to “other” parameters, such as external shear and point source image positions -:param inv_bool: if True, invert the full linear solver Matrix Ax = y for the purpose of the covariance matrix. -:return: 1d array of surface brightness pixels of the optimal solution of the linear parameters to match the data

-
- -
-
-likelihood_data_given_model(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None, source_marg=False, linear_prior=None, check_positive_flux=False)[source]
-

computes the likelihood of the data given a model -This is specified with the non-linear parameters and a linear inversion and prior marginalisation.

-
-
Parameters
-
    -
  • kwargs_lens

  • -
  • kwargs_source

  • -
  • kwargs_lens_light

  • -
  • kwargs_ps

  • -
  • check_positive_flux – bool, if True, checks whether the linear inversion resulted in non-negative flux -components and applies a punishment in the likelihood if so.

  • -
-
-
Returns
-

log likelihood (natural logarithm) (sum of the log likelihoods of the individual images)

-
-
-
- -
-
-linear_response_matrix(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None)[source]
-

computes the linear response matrix (m x n), with n beeing the data size and m being the coefficients

-
-
Parameters
-
    -
  • kwargs_lens

  • -
  • kwargs_source

  • -
  • kwargs_lens_light

  • -
  • kwargs_ps

  • -
-
-
Returns
-

-
-
-
- -
-
-num_param_linear(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None)[source]
-
-
Returns
-

number of linear coefficients to be solved for in the linear inversion

-
-
-
- -
-
-select_kwargs(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None)[source]
-

select subset of kwargs lists referenced to this imaging band

-
-
Parameters
-
    -
  • kwargs_lens

  • -
  • kwargs_source

  • -
  • kwargs_lens_light

  • -
  • kwargs_ps

  • -
-
-
Returns
-

-
-
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.ImSim.Numerics.html b/docs/_build/html/lenstronomy.ImSim.Numerics.html deleted file mode 100644 index 4d4293f2f..000000000 --- a/docs/_build/html/lenstronomy.ImSim.Numerics.html +++ /dev/null @@ -1,678 +0,0 @@ - - - - - - - - - lenstronomy.ImSim.Numerics package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.ImSim.Numerics package

-
-

Submodules

-
-
-

lenstronomy.ImSim.Numerics.adaptive_numerics module

-
-
-class lenstronomy.ImSim.Numerics.adaptive_numerics.AdaptiveConvolution(kernel_super, supersampling_factor, conv_supersample_pixels, supersampling_kernel_size=None, compute_pixels=None, nopython=True, cache=True, parallel=False)[source]
-

Bases: object

-

This class performs convolutions of a subset of pixels at higher supersampled resolution -Goal: speed up relative to higher resolution FFT when only considering a (small) subset of pixels to be convolved -on the higher resolution grid.

-

strategy: -1. lower resolution convolution over full image with FFT -2. subset of pixels with higher resolution Numba convolution (with smaller kernel) -3. the same subset of pixels with low resolution Numba convolution (with same kernel as step 2) -adaptive solution is 1 + 2 - 3

-
-
-convolve2d(image_high_res)[source]
-
-
Parameters
-

image_high_res – supersampled image/model to be convolved on a regular pixel grid

-
-
Returns
-

convolved and re-sized image

-
-
-
- -
-
-re_size_convolve(image_low_res, image_high_res)[source]
-
-
Parameters
-
    -
  • image_low_res – regular sampled image/model

  • -
  • image_high_res – supersampled image/model to be convolved on a regular pixel grid

  • -
-
-
Returns
-

convolved and re-sized image

-
-
-
- -
- -
-
-

lenstronomy.ImSim.Numerics.convolution module

-
-
-class lenstronomy.ImSim.Numerics.convolution.FWHMGaussianConvolution(kernel, truncation=4)[source]
-

Bases: object

-

uses a two-dimensional Gaussian function with same FWHM of given kernel as approximation

-
-
-convolution2d(image)[source]
-

2d convolution

-
-
Parameters
-

image – 2d numpy array, image to be convolved

-
-
Returns
-

convolved image, 2d numpy array

-
-
-
- -
- -
-
-class lenstronomy.ImSim.Numerics.convolution.MGEConvolution(kernel, pixel_scale, order=1)[source]
-

Bases: object

-

approximates a 2d kernel with an azimuthal Multi-Gaussian expansion

-
-
-convolution2d(image)[source]
-
-
Parameters
-

image

-
-
Returns
-

-
-
-
- -
-
-kernel_difference()[source]
-
-
Returns
-

difference between true kernel and MGE approximation

-
-
-
- -
- -
-
-class lenstronomy.ImSim.Numerics.convolution.MultiGaussianConvolution(sigma_list, fraction_list, pixel_scale, supersampling_factor=1, supersampling_convolution=False, truncation=2)[source]
-

Bases: object

-

class to perform a convolution consisting of multiple 2d Gaussians -This is aimed to lead to a speed-up without significant loss of accuracy do to the simplified convolution kernel -relative to a pixelized kernel.

-
-
-convolution2d(image)[source]
-

2d convolution

-
-
Parameters
-

image – 2d numpy array, image to be convolved

-
-
Returns
-

convolved image, 2d numpy array

-
-
-
- -
-
-pixel_kernel(num_pix)[source]
-

computes a pixelized kernel from the MGE parameters

-
-
Parameters
-

num_pix – int, size of kernel (odd number per axis)

-
-
Returns
-

pixel kernel centered

-
-
-
- -
-
-re_size_convolve(image_low_res, image_high_res)[source]
-
-
Parameters
-

image_high_res – supersampled image/model to be convolved on a regular pixel grid

-
-
Returns
-

convolved and re-sized image

-
-
-
- -
- -
-
-class lenstronomy.ImSim.Numerics.convolution.PixelKernelConvolution(kernel, convolution_type='fft_static')[source]
-

Bases: object

-

class to compute convolutions for a given pixelized kernel (fft, grid)

-
-
-convolution2d(image)[source]
-
-
Parameters
-

image – 2d array (image) to be convolved

-
-
Returns
-

fft convolution

-
-
-
- -
-
-copy_transpose()[source]
-
-
Returns
-

copy of the class with kernel set to the transpose of original one

-
-
-
- -
-
-pixel_kernel(num_pix=None)[source]
-

access pixelated kernel

-
-
Parameters
-

num_pix – size of returned kernel (odd number per axis). If None, return the original kernel.

-
-
Returns
-

pixel kernel centered

-
-
-
- -
-
-re_size_convolve(image_low_res, image_high_res=None)[source]
-
-
Parameters
-
    -
  • image_low_res – regular sampled image/model

  • -
  • image_high_res – supersampled image/model to be convolved on a regular pixel grid

  • -
-
-
Returns
-

convolved and re-sized image

-
-
-
- -
- -
-
-class lenstronomy.ImSim.Numerics.convolution.SubgridKernelConvolution(kernel_supersampled, supersampling_factor, supersampling_kernel_size=None, convolution_type='fft_static')[source]
-

Bases: object

-

class to compute the convolution on a supersampled grid with partial convolution computed on the regular grid

-
-
-convolution2d(image)[source]
-
-
Parameters
-

image – 2d array (high resoluton image) to be convolved and re-sized

-
-
Returns
-

convolved image

-
-
-
- -
-
-re_size_convolve(image_low_res, image_high_res)[source]
-
-
Parameters
-

image_high_res – supersampled image/model to be convolved on a regular pixel grid

-
-
Returns
-

convolved and re-sized image

-
-
-
- -
- -
-
-

lenstronomy.ImSim.Numerics.grid module

-
-
-class lenstronomy.ImSim.Numerics.grid.AdaptiveGrid(nx, ny, transform_pix2angle, ra_at_xy_0, dec_at_xy_0, supersampling_indexes, supersampling_factor, flux_evaluate_indexes=None)[source]
-

Bases: lenstronomy.Data.coord_transforms.Coordinates1D

-

manages a super-sampled grid on the partial image

-
-
-property coordinates_evaluate
-
-
Returns
-

1d array of all coordinates being evaluated to perform the image computation

-
-
-
- -
-
-flux_array2image_low_high(flux_array, high_res_return=True)[source]
-
-
Parameters
-
    -
  • flux_array – 1d array of low and high resolution flux values corresponding to the coordinates_evaluate order

  • -
  • high_res_return – bool, if True also returns the high resolution image -(needs more computation and is only needed when convolution is performed on the supersampling level)

  • -
-
-
Returns
-

2d array, 2d array, corresponding to (partial) images in low and high resolution (to be convolved)

-
-
-
- -
- -
-
-class lenstronomy.ImSim.Numerics.grid.RegularGrid(nx, ny, transform_pix2angle, ra_at_xy_0, dec_at_xy_0, supersampling_factor=1, flux_evaluate_indexes=None)[source]
-

Bases: lenstronomy.Data.coord_transforms.Coordinates1D

-

manages a super-sampled grid on the partial image

-
-
-property coordinates_evaluate
-
-
Returns
-

1d array of all coordinates being evaluated to perform the image computation

-
-
-
- -
-
-flux_array2image_low_high(flux_array, **kwargs)[source]
-
-
Parameters
-

flux_array – 1d array of low and high resolution flux values corresponding to the coordinates_evaluate order

-
-
Returns
-

2d array, 2d array, corresponding to (partial) images in low and high resolution (to be convolved)

-
-
-
- -
-
-property grid_points_spacing
-

effective spacing between coordinate points, after supersampling -:return: sqrt(pixel_area)/supersampling_factor

-
- -
-
-property num_grid_points_axes
-

effective number of points along each axes, after supersampling -:return: number of pixels per axis, nx*supersampling_factor ny*supersampling_factor

-
- -
-
-property supersampling_factor
-
-
Returns
-

factor (per axis) of super-sampling relative to a pixel

-
-
-
- -
- -
-
-

lenstronomy.ImSim.Numerics.numba_convolution module

-
-
-class lenstronomy.ImSim.Numerics.numba_convolution.NumbaConvolution(kernel, conv_pixels, compute_pixels=None, nopython=True, cache=True, parallel=False, memory_raise=True)[source]
-

Bases: object

-

class to convolve explicit pixels only

-

the convolution is inspired by pyautolens: https://github.com/Jammy2211/PyAutoLens

-
-
-convolve2d(image)[source]
-

2d convolution

-
-
Parameters
-

image – 2d numpy array, image to be convolved

-
-
Returns
-

convolved image, 2d numpy array

-
-
-
- -
- -
-
-

lenstronomy.ImSim.Numerics.numerics module

-
-
-class lenstronomy.ImSim.Numerics.numerics.Numerics(pixel_grid, psf, supersampling_factor=1, compute_mode='regular', supersampling_convolution=False, supersampling_kernel_size=5, flux_evaluate_indexes=None, supersampled_indexes=None, compute_indexes=None, point_source_supersampling_factor=1, convolution_kernel_size=None, convolution_type='fft_static', truncation=4)[source]
-

Bases: lenstronomy.ImSim.Numerics.point_source_rendering.PointSourceRendering

-

this classes manages the numerical options and computations of an image. -The class has two main functions, re_size_convolve() and coordinates_evaluate()

-
-
-property convolution_class
-
-
Returns
-

convolution class (can be SubgridKernelConvolution, PixelKernelConvolution, MultiGaussianConvolution, …)

-
-
-
- -
-
-property coordinates_evaluate
-
-
Returns
-

1d array of all coordinates being evaluated to perform the image computation

-
-
-
- -
-
-property grid_class
-
-
Returns
-

grid class (can be RegularGrid, AdaptiveGrid)

-
-
-
- -
-
-property grid_supersampling_factor
-
-
Returns
-

supersampling factor set for higher resolution sub-pixel sampling of surface brightness

-
-
-
- -
-
-re_size_convolve(flux_array, unconvolved=False)[source]
-
-
Parameters
-
    -
  • flux_array – 1d array, flux values corresponding to coordinates_evaluate

  • -
  • unconvolved – boolean, if True, does not apply a convolution

  • -
-
-
Returns
-

convolved image on regular pixel grid, 2d array

-
-
-
- -
- -
-
-

lenstronomy.ImSim.Numerics.partial_image module

-
-
-class lenstronomy.ImSim.Numerics.partial_image.PartialImage(partial_read_bools)[source]
-

Bases: object

-

class to deal with the use of partial slicing of a 2d data array, to be used for various computations where only -a subset of pixels need to be know.

-
-
-array_from_partial(partial_array)[source]
-
-
Parameters
-

partial_array – 1d array of the partial indexes

-
-
Returns
-

full 1d array

-
-
-
- -
-
-image_from_partial(partial_array)[source]
-
-
Parameters
-

partial_array – 1d array corresponding to the indexes of the partial read

-
-
Returns
-

full image with zeros elsewhere

-
-
-
- -
-
-property index_array
-
-
Returns
-

2d array with indexes (integers) corresponding to the 1d array, -1 when masked

-
-
-
- -
-
-property num_partial
-
-
Returns
-

number of indexes handled in the partial section

-
-
-
- -
-
-partial_array(image)[source]
-
-
Parameters
-

image – 2d array

-
-
Returns
-

1d array of partial list

-
-
-
- -
- -
-
-

lenstronomy.ImSim.Numerics.point_source_rendering module

-
-
-class lenstronomy.ImSim.Numerics.point_source_rendering.PointSourceRendering(pixel_grid, supersampling_factor, psf)[source]
-

Bases: object

-

numerics to compute the point source response on an image

-
-
-point_source_rendering(ra_pos, dec_pos, amp)[source]
-
-
Parameters
-
    -
  • ra_pos – list of RA positions of point source(s)

  • -
  • dec_pos – list of DEC positions of point source(s)

  • -
  • amp – list of amplitudes of point source(s)

  • -
-
-
Returns
-

2d numpy array of size of the image with the point source(s) rendered

-
-
-
- -
-
-psf_error_map(ra_pos, dec_pos, amp, data, fix_psf_error_map=False)[source]
-
-
Parameters
-
    -
  • ra_pos – image positions of point sources

  • -
  • dec_pos – image positions of point sources

  • -
  • amp – amplitude of modeled point sources

  • -
  • data – 2d numpy array of the data

  • -
  • fix_psf_error_map – bool, if True, estimates the error based on the imput (modeled) amplitude, else uses the data to do so.

  • -
-
-
Returns
-

2d array of size of the image with error terms (sigma**2) expected from inaccuracies in the PSF modeling

-
-
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.ImSim.html b/docs/_build/html/lenstronomy.ImSim.html deleted file mode 100644 index 2260ce5a0..000000000 --- a/docs/_build/html/lenstronomy.ImSim.html +++ /dev/null @@ -1,700 +0,0 @@ - - - - - - - - - lenstronomy.ImSim package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.ImSim package

-
-

Subpackages

- -
-
-

Submodules

-
-
-

lenstronomy.ImSim.de_lens module

-
-
-lenstronomy.ImSim.de_lens.get_param_WLS(A, C_D_inv, d, inv_bool=True)[source]
-

returns the parameter values given -:param A: response matrix Nd x Ns (Nd = # data points, Ns = # parameters) -:param C_D_inv: inverse covariance matrix of the data, Nd x Nd, diagonal form -:param d: data array, 1-d Nd -:param inv_bool: boolean, wheter returning also the inverse matrix or just solve the linear system -:return: 1-d array of parameter values

-
- -
-
-lenstronomy.ImSim.de_lens.marginalisation_const(M_inv)[source]
-

get marginalisation constant 1/2 log(M_beta) for flat priors -:param M_inv: 2D covariance matrix -:return: float

-
- -
-
-lenstronomy.ImSim.de_lens.marginalization_new(M_inv, d_prior=None)[source]
-
-
Parameters
-
    -
  • M_inv – 2D covariance matrix

  • -
  • d_prior – maximum prior length of linear parameters

  • -
-
-
Returns
-

log determinant with eigenvalues to be smaller or equal d_prior

-
-
-
- -
-
-

lenstronomy.ImSim.image2source_mapping module

-
-
-class lenstronomy.ImSim.image2source_mapping.Image2SourceMapping(lensModel, sourceModel)[source]
-

Bases: object

-

this class handles multiple source planes and performs the computation of predicted surface brightness at given -image positions. -The class is enable to deal with an arbitrary number of different source planes. There are two different settings:

-

Single lens plane modelling: -In case of a single deflector, lenstronomy models the reduced deflection angles -(matched to the source plane in single source plane mode). Each source light model can be added a number -(scale_factor) that rescales the reduced deflection angle to the specific source plane.

-

Multiple lens plane modelling: -The multi-plane lens modelling requires the assumption of a cosmology and the redshifts of the multiple lens and -source planes. The backwards ray-tracing is performed and stopped at the different source plane redshift to compute -the mapping between source to image plane.

-
-
-image2source(x, y, kwargs_lens, index_source)[source]
-

mapping of image plane to source plane coordinates -WARNING: for multi lens plane computations and multi source planes, this computation can be slow and should be -used as rarely as possible.

-
-
Parameters
-
    -
  • x – image plane coordinate (angle)

  • -
  • y – image plane coordinate (angle)

  • -
  • kwargs_lens – lens model kwargs list

  • -
  • index_source – int, index of source model

  • -
-
-
Returns
-

source plane coordinate corresponding to the source model of index idex_source

-
-
-
- -
-
-image_flux_joint(x, y, kwargs_lens, kwargs_source, k=None)[source]
-
-
Parameters
-
    -
  • x – coordinate in image plane

  • -
  • y – coordinate in image plane

  • -
  • kwargs_lens – lens model kwargs list

  • -
  • kwargs_source – source model kwargs list

  • -
  • k – None or int or list of int for partial evaluation of light models

  • -
-
-
Returns
-

surface brightness of all joint light components at image position (x, y)

-
-
-
- -
-
-image_flux_split(x, y, kwargs_lens, kwargs_source)[source]
-
-
Parameters
-
    -
  • x – coordinate in image plane

  • -
  • y – coordinate in image plane

  • -
  • kwargs_lens – lens model kwargs list

  • -
  • kwargs_source – source model kwargs list

  • -
-
-
Returns
-

list of responses of every single basis component with default amplitude amp=1, in the same order as the light_model_list

-
-
-
- -
- -
-
-

lenstronomy.ImSim.image_linear_solve module

-
-
-class lenstronomy.ImSim.image_linear_solve.ImageLinearFit(data_class, psf_class=None, lens_model_class=None, source_model_class=None, lens_light_model_class=None, point_source_class=None, extinction_class=None, kwargs_numerics=None, likelihood_mask=None, psf_error_map_bool_list=None, kwargs_pixelbased=None)[source]
-

Bases: lenstronomy.ImSim.image_model.ImageModel

-

linear version class, inherits ImageModel.

-

When light models use pixel-based profile types, such as ‘SLIT_STARLETS’, -the WLS linear inversion is replaced by the regularized inversion performed by an external solver. -The current pixel-based solver is provided by the SLITronomy plug-in.

-
-
-array_masked2image(array)[source]
-
-
Parameters
-

array – 1d array of values not masked out (part of linear fitting)

-
-
Returns
-

2d array of full image

-
-
-
- -
-
-check_positive_flux(kwargs_source, kwargs_lens_light, kwargs_ps)[source]
-

checks whether the surface brightness profiles contain positive fluxes and returns bool if True

-
-
Parameters
-
    -
  • kwargs_source – source surface brightness keyword argument list

  • -
  • kwargs_lens_light – lens surface brightness keyword argument list

  • -
  • kwargs_ps – point source keyword argument list

  • -
-
-
Returns
-

boolean

-
-
-
- -
-
-property data_response
-

returns the 1d array of the data element that is fitted for (including masking)

-
-
Returns
-

1d numpy array

-
-
-
- -
-
-error_map_source(kwargs_source, x_grid, y_grid, cov_param)[source]
-

variance of the linear source reconstruction in the source plane coordinates, -computed by the diagonal elements of the covariance matrix of the source reconstruction as a sum of the errors -of the basis set.

-
-
Parameters
-
    -
  • kwargs_source – keyword arguments of source model

  • -
  • x_grid – x-axis of positions to compute error map

  • -
  • y_grid – y-axis of positions to compute error map

  • -
  • cov_param – covariance matrix of liner inversion parameters

  • -
-
-
Returns
-

diagonal covariance errors at the positions (x_grid, y_grid)

-
-
-
- -
-
-error_response(kwargs_lens, kwargs_ps, kwargs_special)[source]
-

returns the 1d array of the error estimate corresponding to the data response

-
-
Returns
-

1d numpy array of response, 2d array of additonal errors (e.g. point source uncertainties)

-
-
-
- -
-
-image2array_masked(image)[source]
-

returns 1d array of values in image that are not masked out for the likelihood computation/linear minimization -:param image: 2d numpy array of full image -:return: 1d array

-
- -
-
-image_linear_solve(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None, inv_bool=False)[source]
-

computes the image (lens and source surface brightness with a given lens model). -The linear parameters are computed with a weighted linear least square optimization (i.e. flux normalization of the brightness profiles) -However in case of pixel-based modelling, pixel values are constrained by an external solver (e.g. SLITronomy).

-
-
Parameters
-
    -
  • kwargs_lens – list of keyword arguments corresponding to the superposition of different lens profiles

  • -
  • kwargs_source – list of keyword arguments corresponding to the superposition of different source light profiles

  • -
  • kwargs_lens_light – list of keyword arguments corresponding to different lens light surface brightness profiles

  • -
  • kwargs_ps – keyword arguments corresponding to “other” parameters, such as external shear and point source image positions

  • -
  • inv_bool – if True, invert the full linear solver Matrix Ax = y for the purpose of the covariance matrix.

  • -
-
-
Returns
-

2d array of surface brightness pixels of the optimal solution of the linear parameters to match the data

-
-
-
- -
-
-image_pixelbased_solve(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None, init_lens_light_model=None)[source]
-

computes the image (lens and source surface brightness with a given lens model) using the pixel-based solver.

-
-
Parameters
-
    -
  • kwargs_lens – list of keyword arguments corresponding to the superposition of different lens profiles

  • -
  • kwargs_source – list of keyword arguments corresponding to the superposition of different source light profiles

  • -
  • kwargs_lens_light – list of keyword arguments corresponding to different lens light surface brightness profiles

  • -
  • kwargs_ps – keyword arguments corresponding to point sources

  • -
  • kwargs_extinction – keyword arguments corresponding to dust extinction

  • -
  • kwargs_special – keyword arguments corresponding to “special” parameters

  • -
  • init_lens_light_model – optional initial guess for the lens surface brightness

  • -
-
-
Returns
-

2d array of surface brightness pixels of the optimal solution of the linear parameters to match the data

-
-
-
- -
-
-likelihood_data_given_model(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None, source_marg=False, linear_prior=None, check_positive_flux=False)[source]
-

computes the likelihood of the data given a model -This is specified with the non-linear parameters and a linear inversion and prior marginalisation.

-
-
Parameters
-
    -
  • kwargs_lens – list of keyword arguments corresponding to the superposition of different lens profiles

  • -
  • kwargs_source – list of keyword arguments corresponding to the superposition of different source light profiles

  • -
  • kwargs_lens_light – list of keyword arguments corresponding to different lens light surface brightness profiles

  • -
  • kwargs_ps – keyword arguments corresponding to “other” parameters, such as external shear and point source image positions

  • -
  • kwargs_extinction

  • -
  • kwargs_special

  • -
  • source_marg – bool, performs a marginalization over the linear parameters

  • -
  • linear_prior – linear prior width in eigenvalues

  • -
  • check_positive_flux – bool, if True, checks whether the linear inversion resulted in non-negative flux -components and applies a punishment in the likelihood if so.

  • -
-
-
Returns
-

log likelihood (natural logarithm)

-
-
-
- -
-
-linear_response_matrix(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None)[source]
-

computes the linear response matrix (m x n), with n being the data size and m being the coefficients

-
-
Parameters
-
    -
  • kwargs_lens – lens model keyword argument list

  • -
  • kwargs_source – extended source model keyword argument list

  • -
  • kwargs_lens_light – lens light model keyword argument list

  • -
  • kwargs_ps – point source model keyword argument list

  • -
  • kwargs_extinction – extinction model keyword argument list

  • -
  • kwargs_special – special keyword argument list

  • -
-
-
Returns
-

linear response matrix

-
-
-
- -
-
-property num_data_evaluate
-

number of data points to be used in the linear solver -:return:

-
- -
-
-num_param_linear(kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps)[source]
-
-
Returns
-

number of linear coefficients to be solved for in the linear inversion

-
-
-
- -
-
-point_source_linear_response_set(kwargs_ps, kwargs_lens, kwargs_special, with_amp=True)[source]
-
-
Parameters
-
    -
  • kwargs_ps – point source keyword argument list

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • kwargs_special – special keyword argument list, may include ‘delta_x_image’ and ‘delta_y_image’

  • -
  • with_amp – bool, if True, relative magnification between multiply imaged point sources are held fixed.

  • -
-
-
Returns
-

list of positions and amplitudes split in different basis components with applied astrometric corrections

-
-
-
- -
-
-reduced_chi2(model, error_map=0)[source]
-

returns reduced chi2 -:param model: 2d numpy array of a model predicted image -:param error_map: same format as model, additional error component (such as PSF errors) -:return: reduced chi2

-
- -
-
-reduced_residuals(model, error_map=0)[source]
-
-
Parameters
-
    -
  • model – 2d numpy array of the modeled image

  • -
  • error_map – 2d numpy array of additional noise/error terms from model components (such as PSF model uncertainties)

  • -
-
-
Returns
-

2d numpy array of reduced residuals per pixel

-
-
-
- -
-
-update_data(data_class)[source]
-
-
Parameters
-

data_class – instance of Data() class

-
-
Returns
-

no return. Class is updated.

-
-
-
- -
-
-update_linear_kwargs(param, kwargs_lens, kwargs_source, kwargs_lens_light, kwargs_ps)[source]
-

links linear parameters to kwargs arguments

-
-
Parameters
-

param – linear parameter vector corresponding to the response matrix

-
-
Returns
-

updated list of kwargs with linear parameter values

-
-
-
- -
-
-update_pixel_kwargs(kwargs_source, kwargs_lens_light)[source]
-

Update kwargs arguments for pixel-based profiles with fixed properties -such as their number of pixels, scale, and center coordinates (fixed to the origin).

-
-
Parameters
-
    -
  • kwargs_source – list of keyword arguments corresponding to the superposition of different source light profiles

  • -
  • kwargs_lens_light – list of keyword arguments corresponding to the superposition of different lens light profiles

  • -
-
-
Returns
-

updated kwargs_source and kwargs_lens_light

-
-
-
- -
- -
-
-

lenstronomy.ImSim.image_model module

-
-
-class lenstronomy.ImSim.image_model.ImageModel(data_class, psf_class, lens_model_class=None, source_model_class=None, lens_light_model_class=None, point_source_class=None, extinction_class=None, kwargs_numerics=None, kwargs_pixelbased=None)[source]
-

Bases: object

-

this class uses functions of lens_model and source_model to make a lensed image

-
-
-extinction_map(kwargs_extinction=None, kwargs_special=None)[source]
-

differential extinction per pixel

-
-
Parameters
-
    -
  • kwargs_extinction – list of keyword arguments corresponding to the optical depth models tau, such that extinction is exp(-tau)

  • -
  • kwargs_special – keyword arguments, additional parameter to the extinction

  • -
-
-
Returns
-

2d array of size of the image

-
-
-
- -
-
-image(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_extinction=None, kwargs_special=None, unconvolved=False, source_add=True, lens_light_add=True, point_source_add=True)[source]
-

make an image with a realisation of linear parameter values “param”

-
-
Parameters
-
    -
  • kwargs_lens – list of keyword arguments corresponding to the superposition of different lens profiles

  • -
  • kwargs_source – list of keyword arguments corresponding to the superposition of different source light profiles

  • -
  • kwargs_lens_light – list of keyword arguments corresponding to different lens light surface brightness profiles

  • -
  • kwargs_ps – keyword arguments corresponding to “other” parameters, such as external shear and point source image positions

  • -
  • unconvolved – if True: returns the unconvolved light distribution (prefect seeing)

  • -
  • source_add – if True, compute source, otherwise without

  • -
  • lens_light_add – if True, compute lens light, otherwise without

  • -
  • point_source_add – if True, add point sources, otherwise without

  • -
-
-
Returns
-

2d array of surface brightness pixels of the simulation

-
-
-
- -
-
-lens_surface_brightness(kwargs_lens_light, unconvolved=False, k=None)[source]
-

computes the lens surface brightness distribution

-
-
Parameters
-
    -
  • kwargs_lens_light – list of keyword arguments corresponding to different lens light surface brightness profiles

  • -
  • unconvolved – if True, returns unconvolved surface brightness (perfect seeing), otherwise convolved with PSF kernel

  • -
-
-
Returns
-

2d array of surface brightness pixels

-
-
-
- -
-
-point_source(kwargs_ps, kwargs_lens=None, kwargs_special=None, unconvolved=False, k=None)[source]
-

computes the point source positions and paints PSF convolutions on them

-
-
Parameters
-
    -
  • kwargs_ps

  • -
  • k

  • -
-
-
Returns
-

-
-
-
- -
-
-reset_point_source_cache(cache=True)[source]
-

deletes all the cache in the point source class and saves it from then on

-
-
Parameters
-

cache – boolean, if True, saves the next occuring point source positions in the cache

-
-
Returns
-

None

-
-
-
- -
-
-source_surface_brightness(kwargs_source, kwargs_lens=None, kwargs_extinction=None, kwargs_special=None, unconvolved=False, de_lensed=False, k=None, update_pixelbased_mapping=True)[source]
-

computes the source surface brightness distribution

-
-
Parameters
-
    -
  • kwargs_source – list of keyword arguments corresponding to the superposition of different source light profiles

  • -
  • kwargs_lens – list of keyword arguments corresponding to the superposition of different lens profiles

  • -
  • kwargs_extinction – list of keyword arguments of extinction model

  • -
  • unconvolved – if True: returns the unconvolved light distribution (prefect seeing)

  • -
  • de_lensed – if True: returns the un-lensed source surface brightness profile, otherwise the lensed.

  • -
  • k – integer, if set, will only return the model of the specific index

  • -
-
-
Returns
-

2d array of surface brightness pixels

-
-
-
- -
-
-update_psf(psf_class)[source]
-

update the instance of the class with a new instance of PSF() with a potentially different point spread function

-
-
Parameters
-

psf_class

-
-
Returns
-

no return. Class is updated.

-
-
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.LensModel.LightConeSim.html b/docs/_build/html/lenstronomy.LensModel.LightConeSim.html deleted file mode 100644 index b7eb77471..000000000 --- a/docs/_build/html/lenstronomy.LensModel.LightConeSim.html +++ /dev/null @@ -1,193 +0,0 @@ - - - - - - - - - lenstronomy.LensModel.LightConeSim package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.LensModel.LightConeSim package

-
-

Submodules

-
-
-

lenstronomy.LensModel.LightConeSim.light_cone module

-
-
-class lenstronomy.LensModel.LightConeSim.light_cone.LightCone(mass_map_list, grid_spacing_list, redshift_list)[source]
-

Bases: object

-

class to perform multi-plane ray-tracing from convergence maps at different redshifts -From the convergence maps the deflection angles and lensing potential are computed (from different settings) -and then an interpolated grid of all those quantities generate an instance of the lenstronomy LensModel multi-plane -instance. All features of the LensModel module are supported.

-

Improvements that can be made for accuracy and speed: -1. adaptive mesh integral for the convergence map -2. Interpolated deflection map on different scales than the mass map.

-

The design principles should allow those implementations ‘under the hook’ of this class.

-
-
-cone_instance(z_source, cosmo, multi_plane=True, kwargs_interp=None)[source]
-
-
Parameters
-
    -
  • z_source – redshift to where lensing quantities are computed

  • -
  • cosmo – astropy.cosmology class

  • -
  • multi_plane – boolean, if True, computes multi-plane ray-tracing

  • -
  • kwargs_interp – interpolation keyword arguments specifying the numerics. -See description in the Interpolate() class. Only applicable for ‘INTERPOL’ and ‘INTERPOL_SCALED’ models.

  • -
-
-
Returns
-

LensModel instance, keyword argument list of lens model

-
-
-
- -
- -
-
-class lenstronomy.LensModel.LightConeSim.light_cone.MassSlice(mass_map, grid_spacing, redshift)[source]
-

Bases: object

-

class to describe a single mass slice

-
-
-interpol_instance(z_source, cosmo)[source]
-

scales the mass map integrals (with units of mass not convergence) into a convergence map for the given -cosmology and source redshift and returns the keyword arguments of the interpolated reduced deflection and -lensing potential.

-
-
Parameters
-
    -
  • z_source – redshift of the source

  • -
  • cosmo – astropy.cosmology instance

  • -
-
-
Returns
-

keyword arguments of the interpolation instance with numerically computed deflection angles and lensing -potential

-
-
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.LensModel.MultiPlane.html b/docs/_build/html/lenstronomy.LensModel.MultiPlane.html deleted file mode 100644 index 2d1578aa7..000000000 --- a/docs/_build/html/lenstronomy.LensModel.MultiPlane.html +++ /dev/null @@ -1,462 +0,0 @@ - - - - - - - - - lenstronomy.LensModel.MultiPlane package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.LensModel.MultiPlane package

-
-

Submodules

-
-
-

lenstronomy.LensModel.MultiPlane.multi_plane module

-
-
-class lenstronomy.LensModel.MultiPlane.multi_plane.LensedLocation(multiplane_instance, observed_convention_index)[source]
-

Bases: object

-

center_x and center_y kwargs correspond to observed (lensed) locations of deflectors -given a model for the line of sight structure, compute the angular position of the deflector without lensing -contribution along the LOS

-
- -
-
-class lenstronomy.LensModel.MultiPlane.multi_plane.MultiPlane(z_source, lens_model_list, lens_redshift_list, cosmo=None, numerical_alpha_class=None, observed_convention_index=None, ignore_observed_positions=False, z_source_convention=None, cosmo_interp=False, z_interp_stop=None, num_z_interp=100, kwargs_interp=None)[source]
-

Bases: object

-

Multi-plane lensing class with option to assign positions of a selected set of lens models in the observed plane.

-

The lens model deflection angles are in units of reduced deflections from the specified redshift of the lens to the -source redshift of the class instance.

-
-
-alpha(theta_x, theta_y, kwargs_lens, check_convention=True, k=None)[source]
-

reduced deflection angle

-
-
Parameters
-
    -
  • theta_x – angle in x-direction

  • -
  • theta_y – angle in y-direction

  • -
  • kwargs_lens – lens model kwargs

  • -
  • check_convention – flag to check the image position convention (leave this alone)

  • -
-
-
Returns
-

deflection angles in x and y directions

-
-
-
- -
-
-arrival_time(theta_x, theta_y, kwargs_lens, check_convention=True)[source]
-

light travel time relative to a straight path through the coordinate (0,0) -Negative sign means earlier arrival time

-
-
Parameters
-
    -
  • theta_x – angle in x-direction on the image

  • -
  • theta_y – angle in y-direction on the image

  • -
  • kwargs_lens – lens model keyword argument list

  • -
-
-
Returns
-

travel time in unit of days

-
-
-
- -
-
-co_moving2angle_source(x, y)[source]
-

special case of the co_moving2angle definition at the source redshift

-
-
Parameters
-
    -
  • x – co-moving distance

  • -
  • y – co-moving distance

  • -
-
-
Returns
-

angles on the sky at the nominal source plane

-
-
-
- -
-
-geo_shapiro_delay(theta_x, theta_y, kwargs_lens, check_convention=True)[source]
-

geometric and Shapiro (gravitational) light travel time relative to a straight path through the coordinate (0,0) -Negative sign means earlier arrival time

-
-
Parameters
-
    -
  • theta_x – angle in x-direction on the image

  • -
  • theta_y – angle in y-direction on the image

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • check_convention – boolean, if True goes through the lens model list and checks whether the positional -conventions are satisfied.

  • -
-
-
Returns
-

geometric delay, gravitational delay [days]

-
-
-
- -
-
-hessian(theta_x, theta_y, kwargs_lens, k=None, diff=1e-08, check_convention=True)[source]
-

computes the hessian components f_xx, f_yy, f_xy from f_x and f_y with numerical differentiation

-
-
Parameters
-
    -
  • theta_x (numpy array) – x-position (preferentially arcsec)

  • -
  • theta_y (numpy array) – y-position (preferentially arcsec)

  • -
  • kwargs_lens – list of keyword arguments of lens model parameters matching the lens model classes

  • -
  • diff – numerical differential step (float)

  • -
  • check_convention – boolean, if True goes through the lens model list and checks whether the positional -conventions are satisfied.

  • -
-
-
Returns
-

f_xx, f_xy, f_yx, f_yy

-
-
-
- -
-
-observed2flat_convention(kwargs_lens)[source]
-
-
Parameters
-

kwargs_lens – keyword argument list of lens model parameters in the observed convention

-
-
Returns
-

kwargs_lens positions mapped into angular position without lensing along its LOS

-
-
-
- -
-
-ray_shooting(theta_x, theta_y, kwargs_lens, check_convention=True, k=None)[source]
-

ray-tracing (backwards light cone) to the default z_source redshift

-
-
Parameters
-
    -
  • theta_x – angle in x-direction on the image -(usually arc seconds, in the same convention as lensing deflection angles)

  • -
  • theta_y – angle in y-direction on the image -(usually arc seconds, in the same convention as lensing deflection angles)

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • check_convention – flag to check the image position convention (leave this alone)

  • -
-
-
Returns
-

angles in the source plane

-
-
-
- -
-
-ray_shooting_partial(x, y, alpha_x, alpha_y, z_start, z_stop, kwargs_lens, include_z_start=False, check_convention=True, T_ij_start=None, T_ij_end=None)[source]
-

ray-tracing through parts of the coin, starting with (x,y) co-moving distances and angles (alpha_x, alpha_y) at -redshift z_start and then backwards to redshift z_stop

-
-
Parameters
-
    -
  • x – co-moving position [Mpc] / angle definition

  • -
  • y – co-moving position [Mpc] / angle definition

  • -
  • alpha_x – ray angle at z_start [arcsec]

  • -
  • alpha_y – ray angle at z_start [arcsec]

  • -
  • z_start – redshift of start of computation

  • -
  • z_stop – redshift where output is computed

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • include_z_start – bool, if True, includes the computation of the deflection angle at the same redshift as -the start of the ray-tracing. ATTENTION: deflection angles at the same redshift as z_stop will be computed! -This can lead to duplications in the computation of deflection angles.

  • -
  • check_convention – flag to check the image position convention (leave this alone)

  • -
  • T_ij_start – transverse angular distance between the starting redshift to the first lens plane to follow. -If not set, will compute the distance each time this function gets executed.

  • -
  • T_ij_end – transverse angular distance between the last lens plane being computed and z_end. If not set, -will compute the distance each time this function gets executed.

  • -
-
-
Returns
-

co-moving position (modulo angle definition) and angles at redshift z_stop

-
-
-
- -
-
-set_dynamic()[source]
-
-
Returns
-

-
-
-
- -
-
-set_static(kwargs)[source]
-
-
Parameters
-

kwargs – lens model keyword argument list

-
-
Returns
-

lens model keyword argument list with positional parameters all in flat sky coordinates

-
-
-
- -
-
-transverse_distance_start_stop(z_start, z_stop, include_z_start=False)[source]
-

computes the transverse distance (T_ij) that is required by the ray-tracing between the starting redshift and -the first deflector afterwards and the last deflector before the end of the ray-tracing.

-
-
Parameters
-
    -
  • z_start – redshift of the start of the ray-tracing

  • -
  • z_stop – stop of ray-tracing

  • -
  • include_z_start – bool, i

  • -
-
-
Returns
-

T_ij_start, T_ij_end

-
-
-
- -
-
-update_source_redshift(z_source)[source]
-

update instance of this class to compute reduced lensing quantities and time delays to a specific source -redshift

-
-
Parameters
-

z_source – float; source redshift

-
-
Returns
-

self variables update to new redshift

-
-
-
- -
- -
-
-class lenstronomy.LensModel.MultiPlane.multi_plane.PhysicalLocation[source]
-

Bases: object

-

center_x and center_y kwargs correspond to angular location of deflectors without lensing along the LOS

-
- -
-
-

lenstronomy.LensModel.MultiPlane.multi_plane_base module

-
-
-class lenstronomy.LensModel.MultiPlane.multi_plane_base.MultiPlaneBase(lens_model_list, lens_redshift_list, z_source_convention, cosmo=None, numerical_alpha_class=None, cosmo_interp=False, z_interp_stop=None, num_z_interp=100, kwargs_interp=None)[source]
-

Bases: lenstronomy.LensModel.profile_list_base.ProfileListBase

-

Multi-plane lensing class

-

The lens model deflection angles are in units of reduced deflections from the specified redshift of the lens to the -source redshift of the class instance.

-
-
-geo_shapiro_delay(theta_x, theta_y, kwargs_lens, z_stop, T_z_stop=None, T_ij_end=None)[source]
-

geometric and Shapiro (gravitational) light travel time relative to a straight path through the coordinate (0,0) -Negative sign means earlier arrival time

-
-
Parameters
-
    -
  • theta_x – angle in x-direction on the image

  • -
  • theta_y – angle in y-direction on the image

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • z_stop – redshift of the source to stop the backwards ray-tracing

  • -
  • T_z_stop – optional, transversal angular distance from z=0 to z_stop

  • -
  • T_ij_end – optional, transversal angular distance between the last lensing plane and the source plane

  • -
-
-
Returns
-

dt_geo, dt_shapiro, [days]

-
-
-
- -
-
-ray_shooting_partial(x, y, alpha_x, alpha_y, z_start, z_stop, kwargs_lens, include_z_start=False, T_ij_start=None, T_ij_end=None)[source]
-

ray-tracing through parts of the coin, starting with (x,y) co-moving distances and angles (alpha_x, alpha_y) -at redshift z_start and then backwards to redshift z_stop

-
-
Parameters
-
    -
  • x – co-moving position [Mpc]

  • -
  • y – co-moving position [Mpc]

  • -
  • alpha_x – ray angle at z_start [arcsec]

  • -
  • alpha_y – ray angle at z_start [arcsec]

  • -
  • z_start – redshift of start of computation

  • -
  • z_stop – redshift where output is computed

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • include_z_start – bool, if True, includes the computation of the deflection angle at the same redshift as -the start of the ray-tracing. ATTENTION: deflection angles at the same redshift as z_stop will be computed always! -This can lead to duplications in the computation of deflection angles.

  • -
  • T_ij_start – transverse angular distance between the starting redshift to the first lens plane to follow. -If not set, will compute the distance each time this function gets executed.

  • -
  • T_ij_end – transverse angular distance between the last lens plane being computed and z_end. -If not set, will compute the distance each time this function gets executed.

  • -
-
-
Returns
-

co-moving position and angles at redshift z_stop

-
-
-
- -
-
-transverse_distance_start_stop(z_start, z_stop, include_z_start=False)[source]
-

computes the transverse distance (T_ij) that is required by the ray-tracing between the starting redshift and -the first deflector afterwards and the last deflector before the end of the ray-tracing.

-
-
Parameters
-
    -
  • z_start – redshift of the start of the ray-tracing

  • -
  • z_stop – stop of ray-tracing

  • -
  • include_z_start – boolean, if True includes the computation of the starting position if the first -deflector is at z_start

  • -
-
-
Returns
-

T_ij_start, T_ij_end

-
-
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.LensModel.Profiles.html b/docs/_build/html/lenstronomy.LensModel.Profiles.html deleted file mode 100644 index be50d4864..000000000 --- a/docs/_build/html/lenstronomy.LensModel.Profiles.html +++ /dev/null @@ -1,10317 +0,0 @@ - - - - - - - - - lenstronomy.LensModel.Profiles package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.LensModel.Profiles package

-
-

Submodules

-
-
-

lenstronomy.LensModel.Profiles.arc_perturbations module

-
-
-class lenstronomy.LensModel.Profiles.arc_perturbations.ArcPerturbations[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

uses radial and tangential fourier modes within a specific range in both directions to perturb a lensing potential

-
-
-derivatives(x, y, coeff, d_r, d_phi, center_x, center_y)[source]
-
-
Parameters
-
    -
  • x – x-coordinate

  • -
  • y – y-coordinate

  • -
  • coeff – float, amplitude of basis

  • -
  • d_r – period of radial sinusoidal in units of angle

  • -
  • d_phi – period of tangential sinusoidal in radian

  • -
  • center_x – center of rotation for tangential basis

  • -
  • center_y – center of rotation for tangential basis

  • -
-
-
Returns
-

f_x, f_y

-
-
-
- -
-
-function(x, y, coeff, d_r, d_phi, center_x, center_y)[source]
-
-
Parameters
-
    -
  • x – x-coordinate

  • -
  • y – y-coordinate

  • -
  • coeff – float, amplitude of basis

  • -
  • d_r – period of radial sinusoidal in units of angle

  • -
  • d_phi – period of tangential sinusoidal in radian

  • -
  • center_x – center of rotation for tangential basis

  • -
  • center_y – center of rotation for tangential basis

  • -
-
-
Returns
-

-
-
-
- -
-
-hessian(x, y, coeff, d_r, d_phi, center_x, center_y)[source]
-
-
Parameters
-
    -
  • x – x-coordinate

  • -
  • y – y-coordinate

  • -
  • coeff – float, amplitude of basis

  • -
  • d_r – period of radial sinusoidal in units of angle

  • -
  • d_phi – period of tangential sinusoidal in radian

  • -
  • center_x – center of rotation for tangential basis

  • -
  • center_y – center of rotation for tangential basis

  • -
-
-
Returns
-

f_xx, f_yy, f_xy

-
-
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.base_profile module

-
-
-class lenstronomy.LensModel.Profiles.base_profile.LensProfileBase(*args, **kwargs)[source]
-

Bases: object

-

this class acts as the base class of all lens model functions and indicates raise statements and default outputs -if these functions are not defined in the specific lens model class

-
-
-density_lens(*args, **kwargs)[source]
-

computes the density at 3d radius r given lens model parameterization. -The integral in the LOS projection of this quantity results in the convergence quantity.

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-derivatives(*args, **kwargs)[source]
-

deflection angles

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-function(*args, **kwargs)[source]
-

lensing potential

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-hessian(*args, **kwargs)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-mass_3d_lens(*args, **kwargs)[source]
-

mass enclosed a 3d sphere or radius r given a lens parameterization with angular units -For this profile those are identical.

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-set_dynamic()[source]
-
-
Returns
-

no return, deletes pre-computed variables for certain lens models

-
-
-
- -
-
-set_static(**kwargs)[source]
-

pre-computes certain computations that do only relate to the lens model parameters and not to the specific -position where to evaluate the lens model

-
-
Parameters
-

kwargs – lens model parameters

-
-
Returns
-

no return, for certain lens model some private self variables are initiated

-
-
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.chameleon module

-
-
-class lenstronomy.LensModel.Profiles.chameleon.Chameleon(static=False)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class of the Chameleon model (See Suyu+2014) an elliptical truncated double isothermal profile

-
-
-density_lens(r, alpha_1, w_c, w_t, e1=0, e2=0, center_x=0, center_y=0)[source]
-

spherical average density as a function of 3d radius

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • -
  • w_c – see Suyu+2014

  • -
  • w_t – see Suyu+2014

  • -
  • e1 – ellipticity parameter

  • -
  • e2 – ellipticity parameter

  • -
  • center_x – ra center

  • -
  • center_y – dec center

  • -
-
-
Returns
-

matter density at 3d radius r

-
-
-
- -
-
-derivatives(x, y, alpha_1, w_c, w_t, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – ra-coordinate

  • -
  • y – dec-coordinate

  • -
  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • -
  • w_c – see Suyu+2014

  • -
  • w_t – see Suyu+2014

  • -
  • e1 – ellipticity parameter

  • -
  • e2 – ellipticity parameter

  • -
  • center_x – ra center

  • -
  • center_y – dec center

  • -
-
-
Returns
-

deflection angles (RA, DEC)

-
-
-
- -
-
-function(x, y, alpha_1, w_c, w_t, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – ra-coordinate

  • -
  • y – dec-coordinate

  • -
  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • -
  • w_c – see Suyu+2014

  • -
  • w_t – see Suyu+2014

  • -
  • e1 – ellipticity parameter

  • -
  • e2 – ellipticity parameter

  • -
  • center_x – ra center

  • -
  • center_y – dec center

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, alpha_1, w_c, w_t, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – ra-coordinate

  • -
  • y – dec-coordinate

  • -
  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • -
  • w_c – see Suyu+2014

  • -
  • w_t – see Suyu+2014

  • -
  • e1 – ellipticity parameter

  • -
  • e2 – ellipticity parameter

  • -
  • center_x – ra center

  • -
  • center_y – dec center

  • -
-
-
Returns
-

second derivatives of the lensing potential (Hessian: f_xx, f_xy, f_yx, f_yy)

-
-
-
- -
-
-lower_limit_default = {'alpha_1': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.8, 'e2': -0.8, 'w_c': 0, 'w_t': 0}
-
- -
-
-mass_3d_lens(r, alpha_1, w_c, w_t, e1=0, e2=0, center_x=0, center_y=0)[source]
-

mass enclosed 3d radius

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • -
  • w_c – see Suyu+2014

  • -
  • w_t – see Suyu+2014

  • -
  • e1 – ellipticity parameter

  • -
  • e2 – ellipticity parameter

  • -
  • center_x – ra center

  • -
  • center_y – dec center

  • -
-
-
Returns
-

mass enclosed 3d radius r

-
-
-
- -
-
-param_convert(alpha_1, w_c, w_t, e1, e2)[source]
-

convert the parameter alpha_1 (deflection angle one arcsecond from the center) into the -“Einstein radius” scale parameter of the two NIE profiles

-
-
Parameters
-
    -
  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • -
  • w_c – see Suyu+2014

  • -
  • w_t – see Suyu+2014

  • -
  • e1 – eccentricity modulus

  • -
  • e2 – eccentricity modulus

  • -
-
-
Returns
-

-
-
-
- -
-
-param_names = ['alpha_1', 'w_c', 'w_t', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-set_dynamic()[source]
-
-
Returns
-

-
-
-
- -
-
-set_static(alpha_1, w_c, w_t, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • alpha_1

  • -
  • w_c

  • -
  • w_t

  • -
  • e1

  • -
  • e2

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-upper_limit_default = {'alpha_1': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.8, 'e2': 0.8, 'w_c': 100, 'w_t': 100}
-
- -
- -
-
-class lenstronomy.LensModel.Profiles.chameleon.DoubleChameleon[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class of the Chameleon model (See Suyu+2014) an elliptical truncated double isothermal profile

-
-
-density_lens(r, alpha_1, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • -
  • ratio – ratio of deflection amplitude at radius = 1 of the first to second Chameleon profile

  • -
  • w_c1 – Suyu+2014 for first profile

  • -
  • w_t1 – Suyu+2014 for first profile

  • -
  • e11 – ellipticity parameter for first profile

  • -
  • e21 – ellipticity parameter for first profile

  • -
  • w_c2 – Suyu+2014 for second profile

  • -
  • w_t2 – Suyu+2014 for second profile

  • -
  • e12 – ellipticity parameter for second profile

  • -
  • e22 – ellipticity parameter for second profile

  • -
  • center_x – ra center

  • -
  • center_y – dec center

  • -
-
-
Returns
-

3d density at radius r

-
-
-
- -
-
-derivatives(x, y, alpha_1, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – ra-coordinate

  • -
  • y – dec-coordinate

  • -
  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • -
  • ratio – ratio of deflection amplitude at radius = 1 of the first to second Chameleon profile

  • -
  • w_c1 – Suyu+2014 for first profile

  • -
  • w_t1 – Suyu+2014 for first profile

  • -
  • e11 – ellipticity parameter for first profile

  • -
  • e21 – ellipticity parameter for first profile

  • -
  • w_c2 – Suyu+2014 for second profile

  • -
  • w_t2 – Suyu+2014 for second profile

  • -
  • e12 – ellipticity parameter for second profile

  • -
  • e22 – ellipticity parameter for second profile^V

  • -
  • center_x – ra center

  • -
  • center_y – dec center

  • -
-
-
Returns
-

deflection angles (RA, DEC)

-
-
-
- -
-
-function(x, y, alpha_1, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – ra-coordinate

  • -
  • y – dec-coordinate

  • -
  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • -
  • ratio – ratio of deflection amplitude at radius = 1 of the first to second Chameleon profile

  • -
  • w_c1 – Suyu+2014 for first profile

  • -
  • w_t1 – Suyu+2014 for first profile

  • -
  • e11 – ellipticity parameter for first profile

  • -
  • e21 – ellipticity parameter for first profile

  • -
  • w_c2 – Suyu+2014 for second profile

  • -
  • w_t2 – Suyu+2014 for second profile

  • -
  • e12 – ellipticity parameter for second profile

  • -
  • e22 – ellipticity parameter for second profile

  • -
  • center_x – ra center

  • -
  • center_y – dec center

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, alpha_1, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – ra-coordinate

  • -
  • y – dec-coordinate

  • -
  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • -
  • ratio – ratio of deflection amplitude at radius = 1 of the first to second Chameleon profile

  • -
  • w_c1 – Suyu+2014 for first profile

  • -
  • w_t1 – Suyu+2014 for first profile

  • -
  • e11 – ellipticity parameter for first profile

  • -
  • e21 – ellipticity parameter for first profile

  • -
  • w_c2 – Suyu+2014 for second profile

  • -
  • w_t2 – Suyu+2014 for second profile

  • -
  • e12 – ellipticity parameter for second profile

  • -
  • e22 – ellipticity parameter for second profile

  • -
  • center_x – ra center

  • -
  • center_y – dec center

  • -
-
-
Returns
-

second derivatives of the lensing potential (Hessian: f_xx, f_yy, f_xy)

-
-
-
- -
-
-lower_limit_default = {'alpha_1': 0, 'center_x': -100, 'center_y': -100, 'e11': -0.8, 'e12': -0.8, 'e21': -0.8, 'e22': -0.8, 'ratio': 0, 'w_c1': 0, 'w_c2': 0, 'w_t1': 0, 'w_t2': 0}
-
- -
-
-mass_3d_lens(r, alpha_1, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • alpha_1 – deflection angle at 1 (arcseconds) from the center

  • -
  • ratio – ratio of deflection amplitude at radius = 1 of the first to second Chameleon profile

  • -
  • w_c1 – Suyu+2014 for first profile

  • -
  • w_t1 – Suyu+2014 for first profile

  • -
  • e11 – ellipticity parameter for first profile

  • -
  • e21 – ellipticity parameter for first profile

  • -
  • w_c2 – Suyu+2014 for second profile

  • -
  • w_t2 – Suyu+2014 for second profile

  • -
  • e12 – ellipticity parameter for second profile

  • -
  • e22 – ellipticity parameter for second profile

  • -
  • center_x – ra center

  • -
  • center_y – dec center

  • -
-
-
Returns
-

mass enclosed 3d radius

-
-
-
- -
-
-param_names = ['alpha_1', 'ratio', 'w_c1', 'w_t1', 'e11', 'e21', 'w_c2', 'w_t2', 'e12', 'e22', 'center_x', 'center_y']
-
- -
-
-set_dynamic()[source]
-
-
Returns
-

no return, deletes pre-computed variables for certain lens models

-
-
-
- -
-
-set_static(alpha_1, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]
-

pre-computes certain computations that do only relate to the lens model parameters and not to the specific -position where to evaluate the lens model

-
-
Parameters
-

kwargs – lens model parameters

-
-
Returns
-

no return, for certain lens model some private self variables are initiated

-
-
-
- -
-
-upper_limit_default = {'alpha_1': 100, 'center_x': 100, 'center_y': 100, 'e11': 0.8, 'e12': 0.8, 'e21': 0.8, 'e22': 0.8, 'ratio': 100, 'w_c1': 100, 'w_c2': 100, 'w_t1': 100, 'w_t2': 100}
-
- -
- -
-
-class lenstronomy.LensModel.Profiles.chameleon.DoubleChameleonPointMass[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class of the Chameleon model (See Suyu+2014) an elliptical truncated double isothermal profile

-
-
-derivatives(x, y, alpha_1, ratio_pointmass, ratio_chameleon, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • alpha_1

  • -
  • ratio_pointmass – ratio of point source Einstein radius to combined Chameleon deflection angle at r=1

  • -
  • ratio_chameleon – ratio in deflection angles at r=1 for the two Chameleon profiles

  • -
  • w_c1 – Suyu+2014 for first profile

  • -
  • w_t1 – Suyu+2014 for first profile

  • -
  • e11 – ellipticity parameter for first profile

  • -
  • e21 – ellipticity parameter for first profile

  • -
  • w_c2 – Suyu+2014 for second profile

  • -
  • w_t2 – Suyu+2014 for second profile

  • -
  • e12 – ellipticity parameter for second profile

  • -
  • e22 – ellipticity parameter for second profile

  • -
  • center_x – ra center

  • -
  • center_y – dec center

  • -
-
-
Returns
-

-
-
-
- -
-
-function(x, y, alpha_1, ratio_pointmass, ratio_chameleon, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]
-

#TODO chose better parameterization for combining point mass and Chameleon profiles -:param x: ra-coordinate -:param y: dec-coordinate -:param alpha_1: deflection angle at 1 (arcseconds) from the center -:param ratio_pointmass: ratio of point source Einstein radius to combined Chameleon deflection angle at r=1 -:param ratio_chameleon: ratio in deflection angles at r=1 for the two Chameleon profiles -:param w_c1: Suyu+2014 for first profile -:param w_t1: Suyu+2014 for first profile -:param e11: ellipticity parameter for first profile -:param e21: ellipticity parameter for first profile -:param w_c2: Suyu+2014 for second profile -:param w_t2: Suyu+2014 for second profile -:param e12: ellipticity parameter for second profile -:param e22: ellipticity parameter for second profile -:param center_x: ra center -:param center_y: dec center -:return:

-
- -
-
-hessian(x, y, alpha_1, ratio_pointmass, ratio_chameleon, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • alpha_1

  • -
  • ratio_pointmass – ratio of point source Einstein radius to combined Chameleon deflection angle at r=1

  • -
  • ratio_chameleon – ratio in deflection angles at r=1 for the two Chameleon profiles

  • -
  • w_c1 – Suyu+2014 for first profile

  • -
  • w_t1 – Suyu+2014 for first profile

  • -
  • e11 – ellipticity parameter for first profile

  • -
  • e21 – ellipticity parameter for first profile

  • -
  • w_c2 – Suyu+2014 for second profile

  • -
  • w_t2 – Suyu+2014 for second profile

  • -
  • e12 – ellipticity parameter for second profile

  • -
  • e22 – ellipticity parameter for second profile

  • -
  • center_x – ra center

  • -
  • center_y – dec center

  • -
-
-
Returns
-

-
-
-
- -
-
-lower_limit_default = {'alpha_1': 0, 'center_x': -100, 'center_y': -100, 'e11': -0.8, 'e12': -0.8, 'e21': -0.8, 'e22': -0.8, 'ratio_chameleon': 0, 'ratio_pointmass': 0, 'w_c1': 0, 'w_c2': 0, 'w_t1': 0, 'w_t2': 0}
-
- -
-
-param_names = ['alpha_1', 'ratio_chameleon', 'ratio_pointmass', 'w_c1', 'w_t1', 'e11', 'e21', 'w_c2', 'w_t2', 'e12', 'e22', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'alpha_1': 100, 'center_x': 100, 'center_y': 100, 'e11': 0.8, 'e12': 0.8, 'e21': 0.8, 'e22': 0.8, 'ratio_chameleon': 100, 'ratio_pointmass': 100, 'w_c1': 100, 'w_c2': 100, 'w_t1': 100, 'w_t2': 100}
-
- -
- -
-
-class lenstronomy.LensModel.Profiles.chameleon.TripleChameleon[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class of the Chameleon model (See Suyu+2014) an elliptical truncated double isothermal profile

-
-
-density_lens(r, alpha_1, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • alpha_1

  • -
  • ratio12 – ratio of first to second amplitude

  • -
  • ratio13 – ratio of first to third amplitude

  • -
  • w_c1

  • -
  • w_t1

  • -
  • e11

  • -
  • e21

  • -
  • w_c2

  • -
  • w_t2

  • -
  • e12

  • -
  • e22

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

density at radius r (spherical average)

-
-
-
- -
-
-derivatives(x, y, alpha_1, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • alpha_1

  • -
  • ratio12 – ratio of first to second amplitude

  • -
  • ratio13 – ratio of first to third amplidute

  • -
  • w_c1

  • -
  • w_t1

  • -
  • e11

  • -
  • e21

  • -
  • w_c2

  • -
  • w_t2

  • -
  • e12

  • -
  • e22

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-function(x, y, alpha_1, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • alpha_1

  • -
  • ratio12 – ratio of first to second amplitude

  • -
  • ratio13 – ratio of first to third amplitude

  • -
  • w_c1

  • -
  • w_t1

  • -
  • e11

  • -
  • e21

  • -
  • w_c2

  • -
  • w_t2

  • -
  • e12

  • -
  • e22

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-hessian(x, y, alpha_1, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • alpha_1

  • -
  • ratio12 – ratio of first to second amplitude

  • -
  • ratio13 – ratio of first to third amplidute

  • -
  • w_c1

  • -
  • w_t1

  • -
  • e11

  • -
  • e21

  • -
  • w_c2

  • -
  • w_t2

  • -
  • e12

  • -
  • e22

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-lower_limit_default = {'alpha_1': 0, 'center_x': -100, 'center_y': -100, 'e11': -0.8, 'e12': -0.8, 'e13': -0.8, 'e21': -0.8, 'e22': -0.8, 'e23': -0.8, 'ratio12': 0, 'ratio13': 0, 'w_c1': 0, 'w_c2': 0, 'w_c3': 0, 'w_t1': 0, 'w_t2': 0, 'w_t3': 0}
-
- -
-
-mass_3d_lens(r, alpha_1, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • alpha_1

  • -
  • ratio12 – ratio of first to second amplitude

  • -
  • ratio13 – ratio of first to third amplitude

  • -
  • w_c1

  • -
  • w_t1

  • -
  • e11

  • -
  • e21

  • -
  • w_c2

  • -
  • w_t2

  • -
  • e12

  • -
  • e22

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

mass enclosed 3d radius

-
-
-
- -
-
-param_names = ['alpha_1', 'ratio12', 'ratio13', 'w_c1', 'w_t1', 'e11', 'e21', 'w_c2', 'w_t2', 'e12', 'e22', 'w_c3', 'w_t3', 'e13', 'e23', 'center_x', 'center_y']
-
- -
-
-set_dynamic()[source]
-
-
Returns
-

no return, deletes pre-computed variables for certain lens models

-
-
-
- -
-
-set_static(alpha_1, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, center_x=0, center_y=0)[source]
-

pre-computes certain computations that do only relate to the lens model parameters and not to the specific -position where to evaluate the lens model

-
-
Parameters
-

kwargs – lens model parameters

-
-
Returns
-

no return, for certain lens model some private self variables are initiated

-
-
-
- -
-
-upper_limit_default = {'alpha_1': 100, 'center_x': 100, 'center_y': 100, 'e11': 0.8, 'e12': 0.8, 'e13': 0.8, 'e21': 0.8, 'e22': 0.8, 'e23': 0.8, 'ratio12': 100, 'ratio13': 100, 'w_c1': 100, 'w_c2': 100, 'w_c3': 100, 'w_t1': 100, 'w_t2': 100, 'w_t3': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.cnfw module

-
-
-class lenstronomy.LensModel.Profiles.cnfw.CNFW[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class computes the lensing quantities of a cored NFW profile: -rho = rho0 * (r + r_core)^-1 * (r + rs)^-2 -alpha_Rs is the normalization equivalent to the deflection angle at rs in the absence of a core

-
-
-alpha_r(R, Rs, rho0, r_core)[source]
-

deflection angel of NFW profile along the radial direction

-
-
Parameters
-
    -
  • R (float/numpy array) – radius of interest

  • -
  • Rs (float) – scale radius

  • -
-
-
Returns
-

Epsilon(R) projected density at radius R

-
-
-
- -
-
-cnfwGamma(R, Rs, rho0, r_core, ax_x, ax_y)[source]
-

shear gamma of NFW profile (times Sigma_crit) along the projection to coordinate ‘axis’

-
-
Parameters
-
    -
  • R (float/numpy array) – radius of interest

  • -
  • Rs (float) – scale radius

  • -
  • rho0 (float) – density normalization (characteristic density)

  • -
-
-
Returns
-

Epsilon(R) projected density at radius R

-
-
-
- -
-
-density(R, Rs, rho0, r_core)[source]
-

three dimensional truncated NFW profile

-
-
Parameters
-
    -
  • R (float/numpy array) – radius of interest

  • -
  • Rs (float) – scale radius

  • -
  • rho0 (float) – density normalization (central core density)

  • -
-
-
Returns
-

rho(R) density

-
-
-
- -
-
-density_2d(x, y, Rs, rho0, r_core, center_x=0, center_y=0)[source]
-

projected two dimenstional NFW profile (kappa*Sigma_crit)

-
-
Parameters
-
    -
  • x (float/numpy array) – radius of interest

  • -
  • Rs (float) – scale radius

  • -
  • rho0 (float) – density normalization (characteristic density)

  • -
-
-
Returns
-

Epsilon(R) projected density at radius R

-
-
-
- -
-
-density_lens(R, Rs, alpha_Rs, r_core)[source]
-

computes the density at 3d radius r given lens model parameterization. -The integral in the LOS projection of this quantity results in the convergence quantity.

-
- -
-
-derivatives(x, y, Rs, alpha_Rs, r_core, center_x=0, center_y=0)[source]
-

deflection angles

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-function(x, y, Rs, alpha_Rs, r_core, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – angular position

  • -
  • y – angular position

  • -
  • Rs – angular turn over point

  • -
  • alpha_Rs – deflection at Rs (in the absence of a core

  • -
  • r_core – core radius

  • -
  • center_x – center of halo

  • -
  • center_y – center of halo

  • -
-
-
Returns
-

-
-
-
- -
-
-hessian(x, y, Rs, alpha_Rs, r_core, center_x=0, center_y=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^f/dy^2, d^2/dxdy

-
- -
-
-lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100, 'r_core': 0}
-
- -
-
-mass_2d(R, Rs, rho0, r_core)[source]
-

analytic solution of the projection integral -(convergence)

-
- -
-
-mass_3d(R, Rs, rho0, r_core)[source]
-

mass enclosed a 3d sphere or radius r

-
-
Parameters
-
    -
  • R

  • -
  • Rs

  • -
  • rho0

  • -
  • r_core

  • -
-
-
Returns
-

-
-
-
- -
-
-mass_3d_lens(R, Rs, alpha_Rs, r_core)[source]
-

mass enclosed a 3d sphere or radius r given a lens parameterization with angular units

-
-
Returns
-

-
-
-
- -
-
-model_name = 'CNFW'
-
- -
-
-param_names = ['Rs', 'alpha_Rs', 'r_core', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'center_x': 100, 'center_y': 100, 'r_core': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.cnfw_ellipse module

-
-
-class lenstronomy.LensModel.Profiles.cnfw_ellipse.CNFW_ELLIPSE[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class contains functions concerning the NFW profile

-

relation are: R_200 = c * Rs

-
-
-density_lens(R, Rs, alpha_Rs, r_core, e1=0, e2=0)[source]
-

computes the density at 3d radius r given lens model parameterization. -The integral in the LOS projection of this quantity results in the convergence quantity.

-
- -
-
-derivatives(x, y, Rs, alpha_Rs, r_core, e1, e2, center_x=0, center_y=0)[source]
-

returns df/dx and df/dy of the function (integral of NFW)

-
- -
-
-function(x, y, Rs, alpha_Rs, r_core, e1, e2, center_x=0, center_y=0)[source]
-

returns double integral of NFW profile

-
- -
-
-hessian(x, y, Rs, alpha_Rs, r_core, e1, e2, center_x=0, center_y=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^f/dy^2, d^2/dxdy

-
- -
-
-lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'r_core': 0}
-
- -
-
-mass_3d_lens(R, Rs, alpha_Rs, r_core, e1=0, e2=0)[source]
-

mass enclosed a 3d sphere or radius r given a lens parameterization with angular units

-
-
Returns
-

-
-
-
- -
-
-param_names = ['Rs', 'alpha_Rs', 'r_core', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'r_core': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.const_mag module

-
-
-class lenstronomy.LensModel.Profiles.const_mag.ConstMag(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class implements the macromodel potential of Diego et al. -Convergence and shear are computed according to Diego2018

-
-
-derivatives(x, y, mu_r, mu_t, parity, phi_G, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coord (in angles)

  • -
  • y – y-coord (in angles)

  • -
  • mu_r – radial magnification

  • -
  • mu_t – tangential magnification

  • -
  • parity – parity of the side of the macromodel. Either +1 (positive parity) or -1 (negative parity)

  • -
  • phi_G – shear orientation angle (relative to the x-axis)

  • -
-
-
Returns
-

deflection angle (in angles)

-
-
-
- -
-
-function(x, y, mu_r, mu_t, parity, phi_G, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coord (in angles)

  • -
  • y – y-coord (in angles)

  • -
  • mu_r – radial magnification

  • -
  • mu_t – tangential magnification

  • -
  • parity – parity side of the macromodel. Either +1 (positive parity) or -1 (negative parity)

  • -
  • phi_G – shear orientation angle (relative to the x-axis)

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, mu_r, mu_t, parity, phi_G, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coord (in angles)

  • -
  • y – y-coord (in angles)

  • -
  • mu_r – radial magnification

  • -
  • mu_t – tangential magnification

  • -
  • parity – parity of the side of the macromodel. Either +1 (positive parity) or -1 (negative parity)

  • -
  • phi_G – shear orientation angle (relative to the x-axis)

  • -
-
-
Returns
-

hessian matrix (in angles)

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'mu_r': 1, 'mu_t': 1000, 'parity': -1, 'phi_G': 0.0}
-
- -
-
-param_names = ['center_x', 'center_y', 'mu_r', 'mu_t', 'parity', 'phi_G']
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'mu_r': 1, 'mu_t': 1000, 'parity': 1, 'phi_G': 3.141592653589793}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.constant_shift module

-
-
-class lenstronomy.LensModel.Profiles.constant_shift.Shift(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

Lens model with a constant shift of the deflection field

-
-
-derivatives(x, y, alpha_x, alpha_y)[source]
-
-
Parameters
-
    -
  • x – coordinate in image plane (angle)

  • -
  • y – coordinate in image plane (angle)

  • -
  • alpha_x – shift in x-direction (angle)

  • -
  • alpha_y – shift in y-direction (angle)

  • -
-
-
Returns
-

deflection in x- and y-direction

-
-
-
- -
-
-function(x, y, alpha_x, alpha_y)[source]
-
-
Parameters
-
    -
  • x – coordinate in image plane (angle)

  • -
  • y – coordinate in image plane (angle)

  • -
  • alpha_x – shift in x-direction (angle)

  • -
  • alpha_y – shift in y-direction (angle)

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, alpha_x, alpha_y)[source]
-
-
Parameters
-
    -
  • x – coordinate in image plane (angle)

  • -
  • y – coordinate in image plane (angle)

  • -
  • alpha_x – shift in x-direction (angle)

  • -
  • alpha_y – shift in y-direction (angle)

  • -
-
-
Returns
-

hessian elements f_xx, f_xy, f_yx, f_yy

-
-
-
- -
-
-lower_limit_default = {'alpha_x': -1000, 'alpha_y': -1000}
-
- -
-
-param_names = ['alpha_x', 'alpha_y']
-
- -
-
-upper_limit_default = {'alpha_x': 1000, 'alpha_y': 1000}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.convergence module

-
-
-class lenstronomy.LensModel.Profiles.convergence.Convergence(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

a single mass sheet (external convergence)

-
-
-derivatives(x, y, kappa, ra_0=0, dec_0=0)[source]
-

deflection angle

-
-
Parameters
-
    -
  • x – x-coordinate

  • -
  • y – y-coordinate

  • -
  • kappa – (external) convergence

  • -
-
-
Returns
-

deflection angles (first order derivatives)

-
-
-
- -
-
-function(x, y, kappa, ra_0=0, dec_0=0)[source]
-

lensing potential

-
-
Parameters
-
    -
  • x – x-coordinate

  • -
  • y – y-coordinate

  • -
  • kappa – (external) convergence

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, kappa, ra_0=0, dec_0=0)[source]
-

Hessian matrix

-
-
Parameters
-
    -
  • x – x-coordinate

  • -
  • y – y-coordinate

  • -
  • kappa – external convergence

  • -
  • ra_0 – zero point of polynomial expansion (no deflection added)

  • -
  • dec_0 – zero point of polynomial expansion (no deflection added)

  • -
-
-
Returns
-

second order derivatives f_xx, f_xy, f_yx, f_yy

-
-
-
- -
-
-lower_limit_default = {'dec_0': -100, 'kappa': -10, 'ra_0': -100}
-
- -
-
-model_name = 'CONVERGENCE'
-
- -
-
-param_names = ['kappa', 'ra_0', 'dec_0']
-
- -
-
-upper_limit_default = {'dec_0': 100, 'kappa': 10, 'ra_0': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.coreBurkert module

-
-
-class lenstronomy.LensModel.Profiles.coreBurkert.CoreBurkert(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

lensing properties of a modified Burkert profile with variable core size -normalized by rho0, the central core density

-
-
-cBurkGamma(R, Rs, rho0, r_core, ax_x, ax_y)[source]
-
-
Parameters
-
    -
  • R – projected distance

  • -
  • Rs – scale radius

  • -
  • rho0 – central core density

  • -
  • r_core – core radius

  • -
  • ax_x – x coordinate

  • -
  • ax_y – y coordinate

  • -
-
-
Returns
-

-
-
-
- -
-
-cBurkPot(R, Rs, rho0, r_core)[source]
-
-
Parameters
-
    -
  • R – projected distance

  • -
  • Rs – scale radius

  • -
  • rho0 – central core density

  • -
  • r_core – core radius

  • -
-
-
-
- -
-
-coreBurkAlpha(R, Rs, rho0, r_core, ax_x, ax_y)[source]
-

deflection angle

-
-
Parameters
-
    -
  • R

  • -
  • Rs

  • -
  • rho0

  • -
  • r_core

  • -
  • ax_x

  • -
  • ax_y

  • -
-
-
Returns
-

-
-
-
- -
-
-density(R, Rs, rho0, r_core)[source]
-

three dimensional cored Burkert profile

-
-
Parameters
-
    -
  • R (float/numpy array) – radius of interest

  • -
  • Rs (float) – scale radius

  • -
  • rho0 (float) – characteristic density

  • -
-
-
Returns
-

rho(R) density

-
-
-
- -
-
-density_2d(x, y, Rs, rho0, r_core, center_x=0, center_y=0)[source]
-

projected two dimenstional core Burkert profile (kappa*Sigma_crit)

-
-
Parameters
-
    -
  • x – x coordinate

  • -
  • y – y coordinate

  • -
  • Rs – scale radius

  • -
  • rho0 – central core density

  • -
  • r_core – core radius

  • -
-
-
-
- -
-
-derivatives(x, y, Rs, alpha_Rs, r_core, center_x=0, center_y=0)[source]
-

deflection angles -:param x: x coordinate -:param y: y coordinate -:param Rs: scale radius -:param alpha_Rs: deflection angle at Rs -:param r_core: core radius -:param center_x: -:param center_y: -:return:

-
- -
-
-function(x, y, Rs, alpha_Rs, r_core, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – angular position

  • -
  • y – angular position

  • -
  • Rs – angular turn over point

  • -
  • alpha_Rs – deflection angle at Rs

  • -
  • center_x – center of halo

  • -
  • center_y – center of halo

  • -
-
-
Returns
-

-
-
-
- -
-
-hessian(x, y, Rs, alpha_Rs, r_core, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x coordinate

  • -
  • y – y coordinate

  • -
  • Rs – scale radius

  • -
  • alpha_Rs – deflection angle at Rs

  • -
  • r_core – core radius

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-lower_limit_default = {'Rs': 1, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100, 'r_core': 0.5}
-
- -
-
-mass_2d(R, Rs, rho0, r_core)[source]
-

analytic solution of the projection integral -(convergence)

-
-
Parameters
-
    -
  • R – projected distance

  • -
  • Rs – scale radius

  • -
  • rho0 – central core density

  • -
  • r_core – core radius

  • -
-
-
-
- -
-
-mass_3d(R, Rs, rho0, r_core)[source]
-
-
Parameters
-
    -
  • R – projected distance

  • -
  • Rs – scale radius

  • -
  • rho0 – central core density

  • -
  • r_core – core radius

  • -
-
-
-
- -
-
-param_names = ['Rs', 'alpha_Rs', 'r_core', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'Rs': 100, 'alpha_Rs': 100, 'center_x': 100, 'center_y': 100, 'r_core': 50}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.cored_density module

-
-
-class lenstronomy.LensModel.Profiles.cored_density.CoredDensity(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class for a uniform cored density dropping steep in the outskirts -This profile is e.g. featured in Blum et al. 2020 https://arxiv.org/abs/2001.07182v1 -3d rho(r) = 2/pi * Sigma_crit R_c**3 * (R_c**2 + r**2)**(-2)

-
-
-static alpha_r(r, sigma0, r_core)[source]
-

radial deflection angle of the cored density profile

-
-
Parameters
-
    -
  • r – radius (angular scale)

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
-
-
Returns
-

deflection angle

-
-
-
- -
-
-static d_alpha_dr(r, sigma0, r_core)[source]
-

radial derivatives of the radial deflection angle

-
-
Parameters
-
    -
  • r – radius (angular scale)

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
-
-
Returns
-

dalpha/dr

-
-
-
- -
-
-static density(r, sigma0, r_core)[source]
-

rho(r) = 2/pi * Sigma_crit R_c**3 * (R_c**2 + r**2)**(-2)

-
-
Parameters
-
    -
  • r – radius (angular scale)

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
-
-
Returns
-

density at radius r

-
-
-
- -
-
-density_2d(x, y, sigma0, r_core, center_x=0, center_y=0)[source]
-

projected density at projected radius r

-
-
Parameters
-
    -
  • x – x-coordinate in angular units

  • -
  • y – y-coordinate in angular units

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
  • center_x – center of the profile

  • -
  • center_y – center of the profile

  • -
-
-
Returns
-

projected density

-
-
-
- -
-
-density_lens(r, sigma0, r_core)[source]
-

computes the density at 3d radius r given lens model parameterization. -The integral in the LOS projection of this quantity results in the convergence quantity.

-
-
Parameters
-
    -
  • r – radius (angular scale)

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
-
-
Returns
-

desnity at radius r

-
-
-
- -
-
-derivatives(x, y, sigma0, r_core, center_x=0, center_y=0)[source]
-

deflection angle of cored density profile

-
-
Parameters
-
    -
  • x – x-coordinate in angular units

  • -
  • y – y-coordinate in angular units

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
  • center_x – center of the profile

  • -
  • center_y – center of the profile

  • -
-
-
Returns
-

alpha_x, alpha_y at (x, y)

-
-
-
- -
-
-function(x, y, sigma0, r_core, center_x=0, center_y=0)[source]
-

potential of cored density profile

-
-
Parameters
-
    -
  • x – x-coordinate in angular units

  • -
  • y – y-coordinate in angular units

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
  • center_x – center of the profile

  • -
  • center_y – center of the profile

  • -
-
-
Returns
-

lensing potential at (x, y)

-
-
-
- -
-
-hessian(x, y, sigma0, r_core, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate in angular units

  • -
  • y – y-coordinate in angular units

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
  • center_x – center of the profile

  • -
  • center_y – center of the profile

  • -
-
-
Returns
-

Hessian df/dxdx, df/dxdy, df/dydx, df/dydy at position (x, y)

-
-
-
- -
-
-static kappa_r(r, sigma0, r_core)[source]
-

convergence of the cored density profile. This routine is also for testing

-
-
Parameters
-
    -
  • r – radius (angular scale)

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
-
-
Returns
-

convergence at r

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'r_core': 0, 'sigma0': -1}
-
- -
-
-mass_2d(r, sigma0, r_core)[source]
-

mass enclosed in cylinder of radius r

-
-
Parameters
-
    -
  • r – radius (angular scale)

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
-
-
Returns
-

mass enclosed in cylinder of radius r

-
-
-
- -
-
-static mass_3d(r, sigma0, r_core)[source]
-

mass enclosed 3d radius

-
-
Parameters
-
    -
  • r – radius (angular scale)

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
-
-
Returns
-

mass enclosed 3d radius

-
-
-
- -
-
-mass_3d_lens(r, sigma0, r_core)[source]
-

mass enclosed a 3d sphere or radius r given a lens parameterization with angular units -For this profile those are identical.

-
-
Parameters
-
    -
  • r – radius (angular scale)

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
-
-
Returns
-

mass enclosed 3d radius

-
-
-
- -
-
-param_names = ['sigma0', 'r_core', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'r_core': 100, 'sigma0': 10}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.cored_density_2 module

-
-
-class lenstronomy.LensModel.Profiles.cored_density_2.CoredDensity2(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class for a uniform cored density dropping steep in the outskirts -credits for suggesting this profile goes to Kfir Blum

-
-\[\rho(r) = 2/\pi * \Sigma_{\rm crit} R_c^2 * (R_c^2 + r^2)^{-3/2}\]
-

This profile drops like an NFW profile as math:rho(r)^{-3}.

-
-
-static alpha_r(r, sigma0, r_core)[source]
-

radial deflection angle of the cored density profile

-
-
Parameters
-
    -
  • r – radius (angular scale)

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
-
-
Returns
-

deflection angle

-
-
-
- -
-
-static d_alpha_dr(r, sigma0, r_core)[source]
-

radial derivatives of the radial deflection angle

-
-
Parameters
-
    -
  • r – radius (angular scale)

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
-
-
Returns
-

dalpha/dr

-
-
-
- -
-
-static density(r, sigma0, r_core)[source]
-

rho(r) = 2/pi * Sigma_crit R_c**3 * (R_c**2 + r**2)**(-3/2)

-
-
Parameters
-
    -
  • r – radius (angular scale)

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
-
-
Returns
-

density at radius r

-
-
-
- -
-
-density_2d(x, y, sigma0, r_core, center_x=0, center_y=0)[source]
-

projected density at projected radius r

-
-
Parameters
-
    -
  • x – x-coordinate in angular units

  • -
  • y – y-coordinate in angular units

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
  • center_x – center of the profile

  • -
  • center_y – center of the profile

  • -
-
-
Returns
-

projected density

-
-
-
- -
-
-density_lens(r, sigma0, r_core)[source]
-

computes the density at 3d radius r given lens model parameterization. -The integral in the LOS projection of this quantity results in the convergence quantity.

-
-
Parameters
-
    -
  • r – radius (angular scale)

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
-
-
Returns
-

density at radius r

-
-
-
- -
-
-derivatives(x, y, sigma0, r_core, center_x=0, center_y=0)[source]
-

deflection angle of cored density profile

-
-
Parameters
-
    -
  • x – x-coordinate in angular units

  • -
  • y – y-coordinate in angular units

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
  • center_x – center of the profile

  • -
  • center_y – center of the profile

  • -
-
-
Returns
-

alpha_x, alpha_y at (x, y)

-
-
-
- -
-
-function(x, y, sigma0, r_core, center_x=0, center_y=0)[source]
-

potential of cored density profile

-
-
Parameters
-
    -
  • x – x-coordinate in angular units

  • -
  • y – y-coordinate in angular units

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
  • center_x – center of the profile

  • -
  • center_y – center of the profile

  • -
-
-
Returns
-

lensing potential at (x, y)

-
-
-
- -
-
-hessian(x, y, sigma0, r_core, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate in angular units

  • -
  • y – y-coordinate in angular units

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
  • center_x – center of the profile

  • -
  • center_y – center of the profile

  • -
-
-
Returns
-

Hessian df/dxdx, df/dxdy, df/dydx, df/dydy at position (x, y)

-
-
-
- -
-
-static kappa_r(r, sigma0, r_core)[source]
-

convergence of the cored density profile. This routine is also for testing

-
-
Parameters
-
    -
  • r – radius (angular scale)

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
-
-
Returns
-

convergence at r

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'r_core': 0, 'sigma0': -1}
-
- -
-
-static mass_2d(r, sigma0, r_core)[source]
-

mass enclosed in cylinder of radius r

-
-
Parameters
-
    -
  • r – radius (angular scale)

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
-
-
Returns
-

mass enclosed in cylinder of radius r

-
-
-
- -
-
-static mass_3d(r, sigma0, r_core)[source]
-

mass enclosed 3d radius

-
-
Parameters
-
    -
  • r – radius (angular scale)

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
-
-
Returns
-

mass enclosed 3d radius

-
-
-
- -
-
-mass_3d_lens(r, sigma0, r_core)[source]
-

mass enclosed a 3d sphere or radius r given a lens parameterization with angular units -For this profile those are identical.

-
-
Parameters
-
    -
  • r – radius (angular scale)

  • -
  • sigma0 – convergence in the core

  • -
  • r_core – core radius

  • -
-
-
Returns
-

mass enclosed 3d radius

-
-
-
- -
-
-model_name = 'CORED_DENSITY_2'
-
- -
-
-param_names = ['sigma0', 'r_core', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'r_core': 100, 'sigma0': 10}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.cored_density_exp module

-
-
-class lenstronomy.LensModel.Profiles.cored_density_exp.CoredDensityExp(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class contains functions concerning an exponential cored density profile, -namely

-
-
..math::

rho(r) = rho_0 exp(- (theta / theta_c)^2)

-
-
-
-
-static alpha_radial(r, kappa_0, theta_c)[source]
-

returns the radial part of the deflection angle -:param r: angular position (normally in units of arc seconds) -:param kappa_0: central convergence of profile -:param theta_c: core radius (in arcsec) -:return: radial deflection angle

-
- -
-
-density(R, kappa_0, theta_c)[source]
-

three dimensional density profile in angular units -(rho0_physical = rho0_angular Sigma_crit / D_lens)

-
-
Parameters
-
    -
  • R – projected angular position (normally in units of arc seconds)

  • -
  • kappa_0 – central convergence of profile

  • -
  • theta_c – core radius (in arcsec)

  • -
-
-
Returns
-

rho(R) density

-
-
-
- -
-
-density_2d(x, y, kappa_0, theta_c, center_x=0, center_y=0)[source]
-

projected two dimensional ULDM profile (convergence * Sigma_crit), but given our -units convention for rho0, it is basically the convergence

-
-
Parameters
-
    -
  • x – angular position (normally in units of arc seconds)

  • -
  • y – angular position (normally in units of arc seconds)

  • -
  • kappa_0 – central convergence of profile

  • -
  • theta_c – core radius (in arcsec)

  • -
-
-
Returns
-

Epsilon(R) projected density at radius R

-
-
-
- -
-
-density_lens(r, kappa_0, theta_c)[source]
-

computes the density at 3d radius r given lens model parameterization. -The integral in the LOS projection of this quantity results in the convergence quantity.

-
-
Parameters
-
    -
  • r – angular position (normally in units of arc seconds)

  • -
  • kappa_0 – central convergence of profile

  • -
  • theta_c – core radius (in arcsec)

  • -
-
-
Returns
-

density rho(r)

-
-
-
- -
-
-derivatives(x, y, kappa_0, theta_c, center_x=0, center_y=0)[source]
-

returns df/dx and df/dy of the function (lensing potential), which are -the deflection angles

-
-
Parameters
-
    -
  • x – angular position (normally in units of arc seconds)

  • -
  • y – angular position (normally in units of arc seconds)

  • -
  • kappa_0 – central convergence of profile

  • -
  • theta_c – core radius (in arcsec)

  • -
  • center_x – center of halo (in angular units)

  • -
  • center_y – center of halo (in angular units)

  • -
-
-
Returns
-

deflection angle in x, deflection angle in y

-
-
-
- -
-
-function(x, y, kappa_0, theta_c, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – angular position (normally in units of arc seconds)

  • -
  • y – angular position (normally in units of arc seconds)

  • -
  • kappa_0 – central convergence of profile

  • -
  • theta_c – core radius (in arcsec)

  • -
  • center_x – center of halo (in angular units)

  • -
  • center_y – center of halo (in angular units)

  • -
-
-
Returns
-

lensing potential (in arcsec^2)

-
-
-
- -
-
-hessian(x, y, kappa_0, theta_c, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – angular position (normally in units of arc seconds)

  • -
  • y – angular position (normally in units of arc seconds)

  • -
  • kappa_0 – central convergence of profile

  • -
  • theta_c – core radius (in arcsec)

  • -
  • center_x – center of halo (in angular units)

  • -
  • center_y – center of halo (in angular units)

  • -
-
-
Returns
-

Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
-
-
- -
-
-static kappa_r(R, kappa_0, theta_c)[source]
-

convergence of the cored density profile. This routine is also for testing

-
-
Parameters
-
    -
  • R – radius (angular scale)

  • -
  • kappa_0 – convergence in the core

  • -
  • theta_c – core radius

  • -
-
-
Returns
-

convergence at r

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'kappa_0': 0, 'theta_c': 0}
-
- -
-
-mass_2d(R, kappa_0, theta_c)[source]
-

mass enclosed a 2d sphere of radius r -returns

-
-\[M_{2D} = 2 \pi \int_0^r dr' r' \int dz \rho(\sqrt(r'^2 + z^2))\]
-
-
Parameters
-
    -
  • kappa_0 – central convergence of soliton

  • -
  • theta_c – core radius (in arcsec)

  • -
-
-
Returns
-

M_2D (ULDM only)

-
-
-
- -
-
-static mass_3d(R, kappa_0, theta_c)[source]
-

mass enclosed a 3d sphere or radius r -:param kappa_0: central convergence of profile -:param theta_c: core radius (in arcsec) -:param R: radius in arcseconds -:return: mass of soliton in angular units

-
- -
-
-mass_3d_lens(r, kappa_0, theta_c)[source]
-

mass enclosed a 3d sphere or radius r -:param kappa_0: central convergence of profile -:param theta_c: core radius (in arcsec) -:return: mass

-
- -
-
-param_names = ['kappa_0', 'theta_c', 'center_x', 'center_y']
-
- -
-
-static rhotilde(kappa_0, theta_c)[source]
-

Computes the central density in angular units -:param kappa_0: central convergence of profile -:param theta_c: core radius (in arcsec) -:return: central density in 1/arcsec

-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'kappa_0': 10, 'theta_c': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.cored_density_mst module

-
-
-class lenstronomy.LensModel.Profiles.cored_density_mst.CoredDensityMST(profile_type='CORED_DENSITY')[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

approximate mass-sheet transform of a density core. This routine takes the parameters of the density core and -subtracts a mass-sheet that approximates the cored profile in it’s center to counter-act (in approximation) this -model. This allows for better sampling of the mass-sheet transformed quantities that do not have strong covariances. -The subtraction of the mass-sheet is done such that the sampler returns the real central convergence of the original -model (but be careful, the output of quantities like the Einstein angle of the main deflector are still the -not-scaled one). -Attention!!! The interpretation of the result is that the mass sheet as ‘CONVERGENCE’ that is present needs to be -subtracted in post-processing.

-
-
-derivatives(x, y, lambda_approx, r_core, center_x=0, center_y=0)[source]
-

deflection angles of approximate mass-sheet correction

-
-
Parameters
-
    -
  • x – x-coordinate

  • -
  • y – y-coordinate

  • -
  • lambda_approx – approximate mass sheet transform

  • -
  • r_core – core radius of the cored density profile

  • -
  • center_x – x-center of the profile

  • -
  • center_y – y-center of the profile

  • -
-
-
Returns
-

alpha_x, alpha_y

-
-
-
- -
-
-function(x, y, lambda_approx, r_core, center_x=0, center_y=0)[source]
-

lensing potential of approximate mass-sheet correction

-
-
Parameters
-
    -
  • x – x-coordinate

  • -
  • y – y-coordinate

  • -
  • lambda_approx – approximate mass sheet transform

  • -
  • r_core – core radius of the cored density profile

  • -
  • center_x – x-center of the profile

  • -
  • center_y – y-center of the profile

  • -
-
-
Returns
-

lensing potential correction

-
-
-
- -
-
-hessian(x, y, lambda_approx, r_core, center_x=0, center_y=0)[source]
-

Hessian terms of approximate mass-sheet correction

-
-
Parameters
-
    -
  • x – x-coordinate

  • -
  • y – y-coordinate

  • -
  • lambda_approx – approximate mass sheet transform

  • -
  • r_core – core radius of the cored density profile

  • -
  • center_x – x-center of the profile

  • -
  • center_y – y-center of the profile

  • -
-
-
Returns
-

df/dxx, df/dxy, df/dyx, df/dyy

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'lambda_approx': -1, 'r_core': 0}
-
- -
-
-param_names = ['lambda_approx', 'r_core', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'lambda_approx': 10, 'r_core': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.curved_arc_const module

-
-
-class lenstronomy.LensModel.Profiles.curved_arc_const.CurvedArcConst(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

curved arc lensing with orientation of curvature perpendicular to the x-axis with unity radial stretch

-
-
-derivatives(x, y, tangential_stretch, curvature, direction, center_x, center_y)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

-
-
-
- -
-
-function(x, y, tangential_stretch, curvature, direction, center_x, center_y)[source]
-

ATTENTION: there may not be a global lensing potential!

-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

-
-
-
- -
-
-hessian(x, y, tangential_stretch, curvature, direction, center_x, center_y)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'curvature': 1e-06, 'direction': -3.141592653589793, 'tangential_stretch': -100}
-
- -
-
-param_names = ['tangential_stretch', 'curvature', 'direction', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'curvature': 100, 'direction': 3.141592653589793, 'tangential_stretch': 100}
-
- -
- -
-
-class lenstronomy.LensModel.Profiles.curved_arc_const.CurvedArcConstMST[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

lens model that describes a section of a highly magnified deflector region. -The parameterization is chosen to describe local observables efficient.

-

Observables are: -- curvature radius (basically bending relative to the center of the profile) -- radial stretch (plus sign) thickness of arc with parity (more generalized than the power-law slope) -- tangential stretch (plus sign). Infinity means at critical curve -- direction of curvature -- position of arc

-

Requirements: -- Should work with other perturbative models without breaking its meaning (say when adding additional shear terms) -- Must best reflect the observables in lensing -- minimal covariances between the parameters, intuitive parameterization.

-
-
-derivatives(x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

-
-
-
- -
-
-function(x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
-

ATTENTION: there may not be a global lensing potential!

-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

-
-
-
- -
-
-hessian(x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'curvature': 1e-06, 'direction': -3.141592653589793, 'radial_stretch': -5, 'tangential_stretch': -100}
-
- -
-
-param_names = ['tangential_stretch', 'radial_stretch', 'curvature', 'direction', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'curvature': 100, 'direction': 3.141592653589793, 'radial_stretch': 5, 'tangential_stretch': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.curved_arc_sis_mst module

-
-
-class lenstronomy.LensModel.Profiles.curved_arc_sis_mst.CurvedArcSISMST[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

lens model that describes a section of a highly magnified deflector region. -The parameterization is chosen to describe local observables efficient.

-

Observables are: -- curvature radius (basically bending relative to the center of the profile) -- radial stretch (plus sign) thickness of arc with parity (more generalized than the power-law slope) -- tangential stretch (plus sign). Infinity means at critical curve -- direction of curvature -- position of arc

-

Requirements: -- Should work with other perturbative models without breaking its meaning (say when adding additional shear terms) -- Must best reflect the observables in lensing -- minimal covariances between the parameters, intuitive parameterization.

-
-
-derivatives(x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

-
-
-
- -
-
-function(x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
-

ATTENTION: there may not be a global lensing potential!

-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

-
-
-
- -
-
-hessian(x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'curvature': 1e-06, 'direction': -3.141592653589793, 'radial_stretch': -5, 'tangential_stretch': -100}
-
- -
-
-param_names = ['tangential_stretch', 'radial_stretch', 'curvature', 'direction', 'center_x', 'center_y']
-
- -
-
-static sis_mst2stretch(theta_E, kappa_ext, center_x_sis, center_y_sis, center_x, center_y)[source]
-

turn Singular power-law lens model into stretch parameterization at position (center_x, center_y) -This is the inverse function of stretch2spp()

-
-
Parameters
-
    -
  • theta_E – Einstein radius of SIS profile

  • -
  • kappa_ext – external convergence (MST factor 1 - kappa_ext)

  • -
  • center_x_sis – center of SPP model

  • -
  • center_y_sis – center of SPP model

  • -
  • center_x – center of curved model definition

  • -
  • center_y – center of curved model definition

  • -
-
-
Returns
-

tangential_stretch, radial_stretch, curvature, direction

-
-
Returns
-

-
-
-
- -
-
-static stretch2sis_mst(tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
-
-
Parameters
-
    -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

parameters in terms of a spherical SIS + MST resulting in the same observables

-
-
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'curvature': 100, 'direction': 3.141592653589793, 'radial_stretch': 5, 'tangential_stretch': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.curved_arc_spp module

-
-
-class lenstronomy.LensModel.Profiles.curved_arc_spp.CurvedArcSPP[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

lens model that describes a section of a highly magnified deflector region. -The parameterization is chosen to describe local observables efficient.

-

Observables are: -- curvature radius (basically bending relative to the center of the profile) -- radial stretch (plus sign) thickness of arc with parity (more generalized than the power-law slope) -- tangential stretch (plus sign). Infinity means at critical curve -- direction of curvature -- position of arc

-

Requirements: -- Should work with other perturbative models without breaking its meaning (say when adding additional shear terms) -- Must best reflect the observables in lensing -- minimal covariances between the parameters, intuitive parameterization.

-
-
-derivatives(x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

-
-
-
- -
-
-function(x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
-

ATTENTION: there may not be a global lensing potential!

-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

-
-
-
- -
-
-hessian(x, y, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'curvature': 1e-06, 'direction': -3.141592653589793, 'radial_stretch': -5, 'tangential_stretch': -100}
-
- -
-
-param_names = ['tangential_stretch', 'radial_stretch', 'curvature', 'direction', 'center_x', 'center_y']
-
- -
-
-static spp2stretch(theta_E, gamma, center_x_spp, center_y_spp, center_x, center_y)[source]
-

turn Singular power-law lens model into stretch parameterization at position (center_x, center_y) -This is the inverse function of stretch2spp()

-
-
Parameters
-
    -
  • theta_E – Einstein radius of SPP model

  • -
  • gamma – power-law slope

  • -
  • center_x_spp – center of SPP model

  • -
  • center_y_spp – center of SPP model

  • -
  • center_x – center of curved model definition

  • -
  • center_y – center of curved model definition

  • -
-
-
Returns
-

tangential_stretch, radial_stretch, curvature, direction

-
-
-
- -
-
-static stretch2spp(tangential_stretch, radial_stretch, curvature, direction, center_x, center_y)[source]
-
-
Parameters
-
    -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

parameters in terms of a spherical power-law profile resulting in the same observables

-
-
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'curvature': 100, 'direction': 3.141592653589793, 'radial_stretch': 5, 'tangential_stretch': 100}
-
- -
- -
-
-lenstronomy.LensModel.Profiles.curved_arc_spp.center_deflector(curvature, direction, center_x, center_y)[source]
-
-
Parameters
-
    -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

center_spp_x, center_spp_y

-
-
-
- -
-
-

lenstronomy.LensModel.Profiles.curved_arc_spt module

-
-
-class lenstronomy.LensModel.Profiles.curved_arc_spt.CurvedArcSPT[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

Curved arc model based on SIS+MST with an additional non-linear shear distortions applied on the source coordinates -around the center. -This profile is effectively a Source Position Transform of a curved arc and a shear distortion.

-
-
-derivatives(x, y, tangential_stretch, radial_stretch, curvature, direction, gamma1, gamma2, center_x, center_y)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • gamma1 – non-linear reduced shear distortion in the source plane

  • -
  • gamma2 – non-linear reduced shear distortion in the source plane

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

-
-
-
- -
-
-function(x, y, tangential_stretch, radial_stretch, curvature, direction, gamma1, gamma2, center_x, center_y)[source]
-

ATTENTION: there may not be a global lensing potential!

-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • gamma1 – non-linear reduced shear distortion in the source plane

  • -
  • gamma2 – non-linear reduced shear distortion in the source plane

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

-
-
-
- -
-
-hessian(x, y, tangential_stretch, radial_stretch, curvature, direction, gamma1, gamma2, center_x, center_y)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • gamma1 – non-linear reduced shear distortion in the source plane

  • -
  • gamma2 – non-linear reduced shear distortion in the source plane

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'curvature': 1e-06, 'direction': -3.141592653589793, 'gamma1': -0.5, 'gamma2': -0.5, 'radial_stretch': -5, 'tangential_stretch': -100}
-
- -
-
-param_names = ['tangential_stretch', 'radial_stretch', 'curvature', 'direction', 'gamma1', 'gamma2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'curvature': 100, 'direction': 3.141592653589793, 'gamma1': 0.5, 'gamma2': 0.5, 'radial_stretch': 5, 'tangential_stretch': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.curved_arc_tan_diff module

-
-
-class lenstronomy.LensModel.Profiles.curved_arc_tan_diff.CurvedArcTanDiff[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

Curved arc model with an additional non-zero tangential stretch differential in tangential direction component

-

Observables are: -- curvature radius (basically bending relative to the center of the profile) -- radial stretch (plus sign) thickness of arc with parity (more generalized than the power-law slope) -- tangential stretch (plus sign). Infinity means at critical curve -- direction of curvature -- position of arc

-

Requirements: -- Should work with other perturbative models without breaking its meaning (say when adding additional shear terms) -- Must best reflect the observables in lensing -- minimal covariances between the parameters, intuitive parameterization.

-
-
-derivatives(x, y, tangential_stretch, radial_stretch, curvature, dtan_dtan, direction, center_x, center_y)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • dtan_dtan – d(tangential_stretch) / d(tangential direction) / tangential stretch

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

-
-
-
- -
-
-function(x, y, tangential_stretch, radial_stretch, curvature, dtan_dtan, direction, center_x, center_y)[source]
-

ATTENTION: there may not be a global lensing potential!

-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • dtan_dtan – d(tangential_stretch) / d(tangential direction) / tangential stretch

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

-
-
-
- -
-
-hessian(x, y, tangential_stretch, radial_stretch, curvature, dtan_dtan, direction, center_x, center_y)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • dtan_dtan – d(tangential_stretch) / d(tangential direction) / tangential stretch

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'curvature': 1e-06, 'direction': -3.141592653589793, 'dtan_dtan': -10, 'radial_stretch': -5, 'tangential_stretch': -100}
-
- -
-
-param_names = ['tangential_stretch', 'radial_stretch', 'curvature', 'dtan_dtan', 'direction', 'center_x', 'center_y']
-
- -
-
-static stretch2sie_mst(tangential_stretch, radial_stretch, curvature, dtan_dtan, direction, center_x, center_y)[source]
-
-
Parameters
-
    -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • dtan_dtan – d(tangential_stretch) / d(tangential direction) / tangential stretch

  • -
  • direction – float, angle in radian

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
-
-
Returns
-

parameters in terms of a spherical SIS + MST resulting in the same observables

-
-
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'curvature': 100, 'direction': 3.141592653589793, 'dtan_dtab': 10, 'radial_stretch': 5, 'tangential_stretch': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.dipole module

-
-
-class lenstronomy.LensModel.Profiles.dipole.Dipole(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class for dipole response of two massive bodies (experimental)

-
-
-derivatives(x, y, com_x, com_y, phi_dipole, coupling)[source]
-

deflection angles

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-function(x, y, com_x, com_y, phi_dipole, coupling)[source]
-

lensing potential

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-hessian(x, y, com_x, com_y, phi_dipole, coupling)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-lower_limit_default = {'com_x': -100, 'com_y': -100, 'coupling': -10, 'phi_dipole': -10}
-
- -
-
-param_names = ['com_x', 'com_y', 'phi_dipole', 'coupling']
-
- -
-
-upper_limit_default = {'com_x': 100, 'com_y': 100, 'coupling': 10, 'phi_dipole': 10}
-
- -
- -
-
-class lenstronomy.LensModel.Profiles.dipole.DipoleUtil[source]
-

Bases: object

-

pre-calculation of dipole properties

-
-
-static angle(center1_x, center1_y, center2_x, center2_y)[source]
-

compute the rotation angle of the dipole -:return:

-
- -
-
-static com(center1_x, center1_y, center2_x, center2_y, Fm)[source]
-
-
Returns
-

center of mass

-
-
-
- -
-
-static mass_ratio(theta_E, theta_E_sub)[source]
-

computes mass ration of the two clumps with given Einstein radius and power law slope (clump1/sub-clump) -:param theta_E: -:param theta_E_sub: -:return:

-
- -
- -
-
-

lenstronomy.LensModel.Profiles.elliptical_density_slice module

-
-
-class lenstronomy.LensModel.Profiles.elliptical_density_slice.ElliSLICE(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

This class computes the lensing quantities for an elliptical slice of constant density. -Based on Schramm 1994 https://ui.adsabs.harvard.edu/abs/1994A%26A…284…44S/abstract

-

Computes the lensing quantities of an elliptical slice with semi major axis ‘a’ and -semi minor axis ‘b’, centered on ‘center_x’ and ‘center_y’, oriented with an angle ‘psi’ -in radian, and with constant surface mass density ‘sigma_0’. -In other words, this lens model is characterized by the surface mass density :

-
-
..math::
-
kappa(x,y) = left{
-
begin{array}{ll}

sigma_0 & mbox{if } frac{x_{rot}^2}{a^2} + frac{y_{rot}^2}{b^2} leq 1 0 & mbox{else}

-
-
-

end{array}

-
-
-

right}.

-
-
-

with

-
-
..math::

x_{rot} = x_c cos psi + y_c sin psi y_{rot} = - x_c sin psi + y_c cos psi x_c = x - center_x y_c = y - center_y

-
-
-
-
-alpha_ext(x, y, kwargs_slice)[source]
-

deflection angle for (x,y) outside the elliptical slice

-
-
Parameters
-

kwargs_slice – dict, dictionary with the slice definition (a,b,psi,sigma_0)

-
-
-
- -
-
-alpha_in(x, y, kwargs_slice)[source]
-

deflection angle for (x,y) inside the elliptical slice

-
-
Parameters
-

kwargs_slice – dict, dictionary with the slice definition (a,b,psi,sigma_0)

-
-
-
- -
-
-derivatives(x, y, a, b, psi, sigma_0, center_x=0.0, center_y=0.0)[source]
-

lensing deflection angle

-
-
Parameters
-
    -
  • a – float, semi-major axis, must be positive

  • -
  • b – float, semi-minor axis, must be positive

  • -
  • psi – float, orientation in radian

  • -
  • sigma_0 – float, surface mass density, must be positive

  • -
  • center_x – float, center on the x axis

  • -
  • center_y – float, center on the y axis

  • -
-
-
-
- -
-
-function(x, y, a, b, psi, sigma_0, center_x=0.0, center_y=0.0)[source]
-

lensing potential

-
-
Parameters
-
    -
  • a – float, semi-major axis, must be positive

  • -
  • b – float, semi-minor axis, must be positive

  • -
  • psi – float, orientation in radian

  • -
  • sigma_0 – float, surface mass density, must be positive

  • -
  • center_x – float, center on the x axis

  • -
  • center_y – float, center on the y axis

  • -
-
-
-
- -
-
-hessian(x, y, a, b, psi, sigma_0, center_x=0.0, center_y=0.0)[source]
-

lensing second derivatives

-
-
Parameters
-
    -
  • a – float, semi-major axis, must be positive

  • -
  • b – float, semi-minor axis, must be positive

  • -
  • psi – float, orientation in radian

  • -
  • sigma_0 – float, surface mass density, must be positive

  • -
  • center_x – float, center on the x axis

  • -
  • center_y – float, center on the y axis

  • -
-
-
-
- -
-
-lower_limit_default = {'a': 0.0, 'b': 0.0, 'center_x': -100.0, 'center_y': -100.0, 'psi': -1.5707963267948966}
-
- -
-
-param_names = ['a', 'b', 'psi', 'sigma_0', 'center_x', 'center_y']
-
- -
-
-pot_ext(x, y, kwargs_slice)[source]
-

lensing potential for (x,y) outside the elliptical slice

-
-
Parameters
-

kwargs_slice – dict, dictionary with the slice definition (a,b,psi,sigma_0)

-
-
-
- -
-
-static pot_in(x, y, kwargs_slice)[source]
-

lensing potential for (x,y) inside the elliptical slice

-
-
Parameters
-

kwargs_slice – dict, dictionary with the slice definition (a,b,psi,sigma_0)

-
-
-
- -
-
-static sign(z)[source]
-

sign function

-
-
Parameters
-

z – complex

-
-
-
- -
-
-upper_limit_default = {'a': 100.0, 'b': 100.0, 'center_x': 100.0, 'center_y': 100.0, 'psi': 1.5707963267948966}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.epl module

-
-
-class lenstronomy.LensModel.Profiles.epl.EPL[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

” -Elliptical Power Law mass profile

-
-\[\kappa(x, y) = \frac{3-\gamma}{2} \left(\frac{\theta_{E}}{\sqrt{q x^2 + y^2/q}} \right)^{\gamma-1}\]
-

with \(\theta_{E}\) is the (circularized) Einstein radius, -\(\gamma\) is the negative power-law slope of the 3D mass distributions, -\(q\) is the minor/major axis ratio, -and \(x\) and \(y\) are defined in a coordinate sys- tem aligned with the major and minor axis of the lens.

-

In terms of eccentricities, this profile is defined as

-
-\[\kappa(r) = \frac{3-\gamma}{2} \left(\frac{\theta'_{E}}{r \sqrt{1 − e*\cos(2*\phi)}} \right)^{\gamma-1}\]
-

with \(\epsilon\) is the ellipticity defined as

-
-\[\epsilon = \frac{1-q^2}{1+q^2}\]
-

And an Einstein radius \(\theta'_{\rm E}\) related to the definition used is

-
-\[\left(\frac{\theta'_{\rm E}}{\theta_{\rm E}}\right)^{2} = \frac{2q}{1+q^2}.\]
-

The mathematical form of the calculation is presented by Tessore & Metcalf (2015), https://arxiv.org/abs/1507.01819. -The current implementation is using hyperbolic functions. The paper presents an iterative calculation scheme, -converging in few iterations to high precision and accuracy.

-

A (faster) implementation of the same model using numba is accessible as ‘EPL_NUMBA’ with the iterative calculation -scheme.

-
-
-density_lens(r, theta_E, gamma, e1=None, e2=None)[source]
-

computes the density at 3d radius r given lens model parameterization. -The integral in the LOS projection of this quantity results in the convergence quantity.

-
-
Parameters
-
    -
  • r – radius within the mass is computed

  • -
  • theta_E – Einstein radius

  • -
  • gamma – power-law slope

  • -
  • e1 – eccentricity component (not used)

  • -
  • e2 – eccentricity component (not used)

  • -
-
-
Returns
-

mass enclosed a 3D radius r

-
-
-
- -
-
-derivatives(x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate in image plane

  • -
  • y – y-coordinate in image plane

  • -
  • theta_E – Einstein radius

  • -
  • gamma – power law slope

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • center_x – profile center

  • -
  • center_y – profile center

  • -
-
-
Returns
-

alpha_x, alpha_y

-
-
-
- -
-
-function(x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate in image plane

  • -
  • y – y-coordinate in image plane

  • -
  • theta_E – Einstein radius

  • -
  • gamma – power law slope

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • center_x – profile center

  • -
  • center_y – profile center

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate in image plane

  • -
  • y – y-coordinate in image plane

  • -
  • theta_E – Einstein radius

  • -
  • gamma – power law slope

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • center_x – profile center

  • -
  • center_y – profile center

  • -
-
-
Returns
-

f_xx, f_xy, f_yx, f_yy

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'gamma': 1.5, 'theta_E': 0}
-
- -
-
-mass_3d_lens(r, theta_E, gamma, e1=None, e2=None)[source]
-

computes the spherical power-law mass enclosed (with SPP routine) -:param r: radius within the mass is computed -:param theta_E: Einstein radius -:param gamma: power-law slope -:param e1: eccentricity component (not used) -:param e2: eccentricity component (not used) -:return: mass enclosed a 3D radius r

-
- -
-
-param_conv(theta_E, gamma, e1, e2)[source]
-

converts parameters as defined in this class to the parameters used in the EPLMajorAxis() class

-
-
Parameters
-
    -
  • theta_E – Einstein radius as defined in the profile class

  • -
  • gamma – negative power-law slope

  • -
  • e1 – eccentricity modulus

  • -
  • e2 – eccentricity modulus

  • -
-
-
Returns
-

b, t, q, phi_G

-
-
-
- -
-
-param_names = ['theta_E', 'gamma', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-set_dynamic()[source]
-
-
Returns
-

-
-
-
- -
-
-set_static(theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • theta_E – Einstein radius

  • -
  • gamma – power law slope

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • center_x – profile center

  • -
  • center_y – profile center

  • -
-
-
Returns
-

self variables set

-
-
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'gamma': 2.5, 'theta_E': 100}
-
- -
- -
-
-class lenstronomy.LensModel.Profiles.epl.EPLMajorAxis[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

This class contains the function and the derivatives of the -elliptical power law.

-
-\[\kappa = (2-t)/2 * \left[\frac{b}{\sqrt{q^2 x^2 + y^2}}\right]^t\]
-

where with \(t = \gamma - 1\) (from EPL class) being the projected power-law slope of the convergence profile, -critical radius b, axis ratio q.

-

Tessore & Metcalf (2015), https://arxiv.org/abs/1507.01819

-
-
-derivatives(x, y, b, t, q)[source]
-

returns the deflection angles

-
-
Parameters
-
    -
  • x – x-coordinate in image plane relative to center (major axis)

  • -
  • y – y-coordinate in image plane relative to center (minor axis)

  • -
  • b – critical radius

  • -
  • t – projected power-law slope

  • -
  • q – axis ratio

  • -
-
-
Returns
-

f_x, f_y

-
-
-
- -
-
-function(x, y, b, t, q)[source]
-

returns the lensing potential

-
-
Parameters
-
    -
  • x – x-coordinate in image plane relative to center (major axis)

  • -
  • y – y-coordinate in image plane relative to center (minor axis)

  • -
  • b – critical radius

  • -
  • t – projected power-law slope

  • -
  • q – axis ratio

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, b, t, q)[source]
-

Hessian matrix of the lensing potential

-
-
Parameters
-
    -
  • x – x-coordinate in image plane relative to center (major axis)

  • -
  • y – y-coordinate in image plane relative to center (minor axis)

  • -
  • b – critical radius

  • -
  • t – projected power-law slope

  • -
  • q – axis ratio

  • -
-
-
Returns
-

f_xx, f_yy, f_xy

-
-
-
- -
-
-param_names = ['b', 't', 'q', 'center_x', 'center_y']
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.epl_numba module

-
-
-class lenstronomy.LensModel.Profiles.epl_numba.EPL_numba[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

” -Elliptical Power Law mass profile - computation accelerated with numba

-
-\[\kappa(x, y) = \frac{3-\gamma}{2} \left(\frac{\theta_{E}}{\sqrt{q x^2 + y^2/q}} \right)^{\gamma-1}\]
-

with \(\theta_{E}\) is the (circularized) Einstein radius, -\(\gamma\) is the negative power-law slope of the 3D mass distributions, -\(q\) is the minor/major axis ratio, -and \(x\) and \(y\) are defined in a coordinate system aligned with the major and minor axis of the lens.

-

In terms of eccentricities, this profile is defined as

-
-\[\kappa(r) = \frac{3-\gamma}{2} \left(\frac{\theta'_{E}}{r \sqrt{1 − e*\cos(2*\phi)}} \right)^{\gamma-1}\]
-

with \(\epsilon\) is the ellipticity defined as

-
-\[\epsilon = \frac{1-q^2}{1+q^2}\]
-

And an Einstein radius \(\theta'_{\rm E}\) related to the definition used is

-
-\[\left(\frac{\theta'_{\rm E}}{\theta_{\rm E}}\right)^{2} = \frac{2q}{1+q^2}.\]
-

The mathematical form of the calculation is presented by Tessore & Metcalf (2015), https://arxiv.org/abs/1507.01819. -The current implementation is using hyperbolic functions. The paper presents an iterative calculation scheme, -converging in few iterations to high precision and accuracy.

-

A (slower) implementation of the same model using hyperbolic functions without the iterative calculation -is accessible as ‘EPL’ not requiring numba.

-
-
-static derivatives(x, y, theta_E, gamma, e1, e2, center_x=0.0, center_y=0.0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y-coordinate (angle)

  • -
  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • -
  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • center_x – x-position of lens center

  • -
  • center_y – y-position of lens center

  • -
-
-
Returns
-

deflection angles alpha_x, alpha_y

-
-
-
- -
-
-static function(x, y, theta_E, gamma, e1, e2, center_x=0.0, center_y=0.0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y-coordinate (angle)

  • -
  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • -
  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • center_x – x-position of lens center

  • -
  • center_y – y-position of lens center

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-static hessian(x, y, theta_E, gamma, e1, e2, center_x=0.0, center_y=0.0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y-coordinate (angle)

  • -
  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • -
  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • center_x – x-position of lens center

  • -
  • center_y – y-position of lens center

  • -
-
-
Returns
-

Hessian components f_xx, f_yy, f_xy

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'gamma': 1.5, 'theta_E': 0}
-
- -
-
-param_names = ['theta_E', 'gamma', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'gamma': 2.5, 'theta_E': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.flexion module

-
-
-class lenstronomy.LensModel.Profiles.flexion.Flexion(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class for flexion

-
-
-derivatives(x, y, g1, g2, g3, g4, ra_0=0, dec_0=0)[source]
-

deflection angles

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-function(x, y, g1, g2, g3, g4, ra_0=0, dec_0=0)[source]
-

lensing potential

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-hessian(x, y, g1, g2, g3, g4, ra_0=0, dec_0=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-lower_limit_default = {'dec_0': -100, 'g1': -0.1, 'g2': -0.1, 'g3': -0.1, 'g4': -0.1, 'ra_0': -100}
-
- -
-
-param_names = ['g1', 'g2', 'g3', 'g4', 'ra_0', 'dec_0']
-
- -
-
-upper_limit_default = {'dec_0': 100, 'g1': 0.1, 'g2': 0.1, 'g3': 0.1, 'g4': 0.1, 'ra_0': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.flexionfg module

-
-
-class lenstronomy.LensModel.Profiles.flexionfg.Flexionfg[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

Flexion consist of basis F flexion and G flexion (F1,F2,G1,G2), -see formulas 2.54, 2.55 in Massimo Meneghetti 2017 - “Introduction to Gravitational Lensing”.

-
-
-derivatives(x, y, F1, F2, G1, G2, ra_0=0, dec_0=0)[source]
-

deflection angle -:param x: x-coordinate -:param y: y-coordinate -:param F1: F1 flexion, derivative of kappa in x direction -:param F2: F2 flexion, derivative of kappa in y direction -:param G1: G1 flexion -:param G2: G2 flexion -:param ra_0: center x-coordinate -:param dec_0: center x-coordinate -:return: deflection angle

-
- -
-
-function(x, y, F1, F2, G1, G2, ra_0=0, dec_0=0)[source]
-

lensing potential

-
-
Parameters
-
    -
  • x – x-coordinate

  • -
  • y – y-coordinate

  • -
  • F1 – F1 flexion, derivative of kappa in x direction

  • -
  • F2 – F2 flexion, derivative of kappa in y direction

  • -
  • G1 – G1 flexion

  • -
  • G2 – G2 flexion

  • -
  • ra_0 – center x-coordinate

  • -
  • dec_0 – center y-coordinate

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, F1, F2, G1, G2, ra_0=0, dec_0=0)[source]
-

Hessian matrix -:param x: x-coordinate -:param y: y-coordinate -:param F1: F1 flexion, derivative of kappa in x direction -:param F2: F2 flexion, derivative of kappa in y direction -:param G1: G1 flexion -:param G2: G2 flexion -:param ra_0: center x-coordinate -:param dec_0: center y-coordinate -:return: second order derivatives f_xx, f_yy, f_xy

-
- -
-
-lower_limit_default = {'F1': -0.1, 'F2': -0.1, 'G1': -0.1, 'G2': -0.1, 'dec_0': -100, 'ra_0': -100}
-
- -
-
-param_names = ['F1', 'F2', 'G1', 'G2', 'ra_0', 'dec_0']
-
- -
-
-static transform_fg(F1, F2, G1, G2)[source]
-

basis transform from (F1,F2,G1,G2) to (g1,g2,g3,g4) -:param F1: F1 flexion, derivative of kappa in x direction -:param F2: F2 flexion, derivative of kappa in y direction -:param G1: G1 flexion -:param G2: G2 flexion -:return: g1,g2,g3,g4 (phi_xxx, phi_xxy, phi_xyy, phi_yyy)

-
- -
-
-upper_limit_default = {'F1': 0.1, 'F2': 0.1, 'G1': 0.1, 'G2': 0.1, 'dec_0': 100, 'ra_0': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.gauss_decomposition module

-

This module contains the class to compute lensing properties of any -elliptical profile using Shajib (2019)’s Gauss decomposition.

-
-
-class lenstronomy.LensModel.Profiles.gauss_decomposition.CTNFWGaussDec(n_sigma=15, sigma_start_mult=0.01, sigma_end_mult=20.0, precision=10, use_scipy_wofz=True)[source]
-

Bases: lenstronomy.LensModel.Profiles.gauss_decomposition.GaussDecompositionAbstract3D

-

This class computes the lensing properties of an projection from a -spherical cored-truncated NFW profile using Shajib (2019)’s Gauss -decomposition method.

-
-
-get_kappa_1d(y, **kwargs)[source]
-

Compute the spherical cored-truncated NFW profile at y.

-
-
Parameters
-
    -
  • y (float) – y coordinate

  • -
  • kwargs – Keyword arguments

  • -
-
-
Keyword Arguments
-
    -
  • r_s (float) – -Scale radius

  • -
  • r_trunc (float) – -Truncation radius

  • -
  • r_core (float) – -Core radius

  • -
  • rho_s (float) – -Density normalization

  • -
  • a (float) – -Core regularization parameter

  • -
-
-
Returns
-

projected NFW profile at y

-
-
Return type
-

type(y)

-
-
-
- -
-
-get_scale(**kwargs)[source]
-

Identify the scale size from the keyword arguments.

-
-
Parameters
-

kwargs – Keyword arguments

-
-
Keyword Arguments
-
    -
  • r_s (float) – -Scale radius

  • -
  • r_trunc (float) – -Truncation radius

  • -
  • r_core (float) – -Core radius

  • -
  • rho_s (float) – -Density normalization

  • -
  • a (float) – -Core regularization parameter

  • -
-
-
Returns
-

NFW scale radius

-
-
Return type
-

float

-
-
-
- -
-
-lower_limit_default = {'a': 0.0, 'center_x': -100, 'center_y': -100, 'r_core': 0, 'r_s': 0, 'r_trunc': 0, 'rho_s': 0}
-
- -
-
-param_names = ['r_s', 'r_core', 'r_trunc', 'a', 'rho_s', 'center_xcenter_y']
-
- -
-
-upper_limit_default = {'a': 10.0, 'center_x': 100, 'center_y': 100, 'r_core': 100, 'r_s': 100, 'r_trunc': 100, 'rho_s': 1000}
-
- -
- -
-
-class lenstronomy.LensModel.Profiles.gauss_decomposition.GaussDecompositionAbstract(n_sigma=15, sigma_start_mult=0.02, sigma_end_mult=15.0, precision=10, use_scipy_wofz=True, min_ellipticity=1e-05)[source]
-

Bases: object

-

This abstract class sets up a template for computing lensing properties of -an elliptical convergence through Shajib (2019)’s Gauss decomposition.

-
-
-density_2d(x, y, e1=0.0, e2=0.0, center_x=0.0, center_y=0.0, **kwargs)[source]
-

Compute the convergence profile for Gauss-decomposed elliptic Sersic profile.

-
-
Parameters
-
    -
  • x (float or numpy.array) – x coordinate

  • -
  • y (float or numpy.array) – y coordinate

  • -
  • e1 (float) – Ellipticity parameter 1

  • -
  • e2 (float) – Ellipticity parameter 2

  • -
  • center_x (float) – x coordinate of centroid

  • -
  • center_y (float) – y coordinate of centroid

  • -
  • kwargs – Keyword arguments that are defined by the child class that are particular for the convergence profile in the child class.

  • -
-
-
Returns
-

Convergence profile

-
-
Return type
-

type(x)

-
-
-
- -
-
-derivatives(x, y, e1=0.0, e2=0.0, center_x=0.0, center_y=0.0, **kwargs)[source]
-

Compute the derivatives of the deflection potential \(\partial -f/\partial x\), \(\partial f/\partial y\) for a Gauss-decomposed -elliptic convergence.

-
-
Parameters
-
    -
  • x (float or numpy.array) – x coordinate

  • -
  • y (float or numpy.array) – y coordinate

  • -
  • e1 (float) – Ellipticity parameter 1

  • -
  • e2 (float) – Ellipticity parameter 2

  • -
  • center_x (float) – x coordinate of centroid

  • -
  • center_y (float) – y coordinate of centroid

  • -
  • kwargs – Keyword arguments that are defined by the child class that are particular for the convergence profile

  • -
-
-
Returns
-

Derivatives of deflection potential

-
-
Return type
-

tuple (type(x), type(x))

-
-
-
- -
-
-function(x, y, e1=0.0, e2=0.0, center_x=0.0, center_y=0.0, **kwargs)[source]
-

Compute the deflection potential of a Gauss-decomposed -elliptic convergence.

-
-
Parameters
-
    -
  • x (float) – x coordinate

  • -
  • y (float) – y coordinate

  • -
  • e1 (float) – Ellipticity parameter 1

  • -
  • e2 (float) – Ellipticity parameter 2

  • -
  • center_x (float) – x coordinate of centroid

  • -
  • center_y (float) – y coordinate of centroid

  • -
  • kwargs – Keyword arguments that are defined by the child class that are particular for the convergence profile

  • -
-
-
Returns
-

Deflection potential

-
-
Return type
-

float

-
-
-
- -
-
-gauss_decompose(**kwargs)[source]
-

Compute the amplitudes and sigmas of Gaussian components using the -integral transform with Gaussian kernel from Shajib (2019). The -returned values are in the convention of eq. (2.13).

-
-
Parameters
-

kwargs – Keyword arguments to send to func

-
-
Returns
-

Amplitudes and standard deviations of the Gaussian components

-
-
Return type
-

tuple (numpy.array, numpy.array)

-
-
-
- -
-
-abstract get_kappa_1d(y, **kwargs)[source]
-

Abstract method to compute the spherical Sersic profile at y. -The concrete method has to defined by the child class.

-
-
Parameters
-
    -
  • y (float or numpy.array) – y coordinate

  • -
  • kwargs – Keyword arguments that are defined by the child class that are particular for the convergence profile

  • -
-
-
-
- -
-
-abstract get_scale(**kwargs)[source]
-

Abstract method to identify the keyword argument for the scale size -among the profile parameters of the child class’ convergence profile.

-
-
Parameters
-

kwargs – Keyword arguments

-
-
Returns
-

Scale size

-
-
Return type
-

float

-
-
-
- -
-
-hessian(x, y, e1=0.0, e2=0.0, center_x=0.0, center_y=0.0, **kwargs)[source]
-

Compute the Hessian of the deflection potential -\(\partial^2f/\partial x^2\), \(\partial^2 f/ \partial -y^2\), \(\partial^2 f/\partial x\partial y\) of a Gauss-decomposed -elliptic Sersic convergence.

-
-
Parameters
-
    -
  • x (float or numpy.array) – x coordinate

  • -
  • y (float or numpy.array) – y coordinate

  • -
  • e1 (float) – Ellipticity parameter 1

  • -
  • e2 (float) – Ellipticity parameter 2

  • -
  • center_x (float) – x coordinate of centroid

  • -
  • center_y (float) – y coordinate of centroid

  • -
  • kwargs – Keyword arguments that are defined by the child class that are particular for the convergence profile

  • -
-
-
Returns
-

Hessian of deflection potential

-
-
Return type
-

tuple (type(x), type(x), type(x))

-
-
-
- -
- -
-
-class lenstronomy.LensModel.Profiles.gauss_decomposition.GaussDecompositionAbstract3D(n_sigma=15, sigma_start_mult=0.02, sigma_end_mult=15.0, precision=10, use_scipy_wofz=True, min_ellipticity=1e-05)[source]
-

Bases: lenstronomy.LensModel.Profiles.gauss_decomposition.GaussDecompositionAbstract

-

This abstract class sets up a template for computing lensing properties of -a convergence from 3D spherical profile through Shajib (2019)’s Gauss -decomposition.

-
-
-gauss_decompose(**kwargs)[source]
-

Compute the amplitudes and sigmas of Gaussian components using the -integral transform with Gaussian kernel from Shajib (2019). The -returned values are in the convention of eq. (2.13).

-
-
Parameters
-

kwargs – Keyword arguments to send to func

-
-
Returns
-

Amplitudes and standard deviations of the Gaussian components

-
-
Return type
-

tuple (numpy.array, numpy.array)

-
-
-
- -
- -
-
-class lenstronomy.LensModel.Profiles.gauss_decomposition.GaussianEllipseKappaSet(use_scipy_wofz=True, min_ellipticity=1e-05)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

This class computes the lensing properties of a set of concentric -elliptical Gaussian convergences.

-
-
-density_2d(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]
-

Compute the density of a set of concentric elliptical Gaussian -convergence profiles \(\sum A/(2\pi \sigma^2) \exp(-( -x^2+y^2/q^2)/2\sigma^2)\).

-
-
Parameters
-
    -
  • x (float or numpy.array) – x coordinate

  • -
  • y (float or numpy.array) – y coordinate

  • -
  • amp (numpy.array with dtype=float) – Amplitude of Gaussian, convention: \(A/(2 \pi\sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\)

  • -
  • sigma (numpy.array with dtype=float) – Standard deviation of Gaussian

  • -
  • e1 (float) – Ellipticity parameter 1

  • -
  • e2 (float) – Ellipticity parameter 2

  • -
  • center_x (float) – x coordinate of centroid

  • -
  • center_y (float) – y coordianate of centroid

  • -
-
-
Returns
-

Density \(\kappa\) for elliptical Gaussian convergence

-
-
Return type
-

float, or numpy.array with shape equal to x.shape

-
-
-
- -
-
-derivatives(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]
-

Compute the derivatives of function angles \(\partial -f/\partial x\), \(\partial f/\partial y\) at \(x,\ y\) for a -set of concentric elliptic Gaussian convergence profiles.

-
-
Parameters
-
    -
  • x (float or numpy.array) – x coordinate

  • -
  • y (float or numpy.array) – y coordinate

  • -
  • amp (numpy.array with dtype=float) – Amplitude of Gaussian, convention: \(A/(2 \pi\sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\)

  • -
  • sigma (numpy.array with dtype=float) – Standard deviation of Gaussian

  • -
  • e1 (float) – Ellipticity parameter 1

  • -
  • e2 (float) – Ellipticity parameter 2

  • -
  • center_x (float) – x coordinate of centroid

  • -
  • center_y (float) – y coordianate of centroid

  • -
-
-
Returns
-

Deflection angle \(\partial f/\partial x\), \(\partial f/\partial y\) for elliptical Gaussian convergence

-
-
Return type
-

tuple (float, float) or (numpy.array, numpy.array) with each numpy array’s shape equal to x.shape

-
-
-
- -
-
-function(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]
-

Compute the potential function for a set of concentric elliptical -Gaussian convergence profiles.

-
-
Parameters
-
    -
  • x (float or numpy.array) – x coordinate

  • -
  • y (float or numpy.array) – y coordinate

  • -
  • amp (numpy.array with dtype=float) – Amplitude of Gaussian, convention: \(A/(2 \pi\sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\)

  • -
  • sigma (numpy.array with dtype=float) – Standard deviation of Gaussian

  • -
  • e1 (float) – Ellipticity parameter 1

  • -
  • e2 (float) – Ellipticity parameter 2

  • -
  • center_x (float) – x coordinate of centroid

  • -
  • center_y (float) – y coordianate of centroid

  • -
-
-
Returns
-

Potential for elliptical Gaussian convergence

-
-
Return type
-

float, or numpy.array with shape = x.shape

-
-
-
- -
-
-hessian(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]
-

Compute Hessian matrix of function \(\partial^2f/\partial x^2\), -\(\partial^2 f/\partial y^2\), \(\partial^2 f/\partial -x\partial y\) for a set of concentric elliptic Gaussian convergence -profiles.

-
-
Parameters
-
    -
  • x (float or numpy.array) – x coordinate

  • -
  • y (float or numpy.array) – y coordinate

  • -
  • amp (numpy.array with dtype=float) – Amplitude of Gaussian, convention: \(A/(2 \pi\sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\)

  • -
  • sigma (numpy.array with dtype=float) – Standard deviation of Gaussian

  • -
  • e1 (float) – Ellipticity parameter 1

  • -
  • e2 (float) – Ellipticity parameter 2

  • -
  • center_x (float) – x coordinate of centroid

  • -
  • center_y (float) – y coordianate of centroid

  • -
-
-
Returns
-

Hessian \(\partial^2f/\partial x^2\), \(\partial^2/\partial x\partial y\), -\(\partial^2/\partial y\partial x\), \(\partial^2 f/\partial y^2\) for elliptical Gaussian convergence.

-
-
Return type
-

tuple (float, float, float) , or (numpy.array, numpy.array, numpy.array) -with each numpy array’s shape equal to x.shape

-
-
-
- -
-
-lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'sigma': 0}
-
- -
-
-param_names = ['amp', 'sigma', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'sigma': 100}
-
- -
- -
-
-class lenstronomy.LensModel.Profiles.gauss_decomposition.NFWEllipseGaussDec(n_sigma=15, sigma_start_mult=0.005, sigma_end_mult=50.0, precision=10, use_scipy_wofz=True, min_ellipticity=1e-05)[source]
-

Bases: lenstronomy.LensModel.Profiles.gauss_decomposition.GaussDecompositionAbstract

-

This class computes the lensing properties of an elliptical, projected NFW -profile using Shajib (2019)’s Gauss decomposition method.

-
-
-get_kappa_1d(y, **kwargs)[source]
-

Compute the spherical projected NFW profile at y.

-
-
Parameters
-
    -
  • y (float) – y coordinate

  • -
  • kwargs – Keyword arguments

  • -
-
-
Keyword Arguments
-
    -
  • alpha_Rs (float) – -Deflection angle at Rs

  • -
  • R_s (float) – -NFW scale radius

  • -
-
-
Returns
-

projected NFW profile at y

-
-
Return type
-

type(y)

-
-
-
- -
-
-get_scale(**kwargs)[source]
-

Identify the scale size from the keyword arguments.

-
-
Parameters
-

kwargs – Keyword arguments

-
-
Keyword Arguments
-
    -
  • alpha_Rs (float) – -Deflection angle at Rs

  • -
  • R_s (float) – -NFW scale radius

  • -
-
-
Returns
-

NFW scale radius

-
-
Return type
-

float

-
-
-
- -
-
-lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5}
-
- -
-
-param_names = ['Rs', 'alpha_Rs', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5}
-
- -
- -
-
-class lenstronomy.LensModel.Profiles.gauss_decomposition.SersicEllipseGaussDec(n_sigma=15, sigma_start_mult=0.02, sigma_end_mult=15.0, precision=10, use_scipy_wofz=True, min_ellipticity=1e-05)[source]
-

Bases: lenstronomy.LensModel.Profiles.gauss_decomposition.GaussDecompositionAbstract

-

This class computes the lensing properties of an elliptical Sersic -profile using the Shajib (2019)’s Gauss decomposition method.

-
-
-get_kappa_1d(y, **kwargs)[source]
-

Compute the spherical Sersic profile at y.

-
-
Parameters
-
    -
  • y (float) – y coordinate

  • -
  • kwargs – Keyword arguments

  • -
-
-
Keyword Arguments
-
    -
  • n_sersic (float) – -Sersic index

  • -
  • R_sersic (float) – -Sersic scale radius

  • -
  • k_eff (float) – -Sersic convergence at R_sersic

  • -
-
-
Returns
-

Sersic function at y

-
-
Return type
-

type(y)

-
-
-
- -
-
-get_scale(**kwargs)[source]
-

Identify the scale size from the keyword arguments.

-
-
Parameters
-

kwargs – Keyword arguments

-
-
Keyword Arguments
-
    -
  • n_sersic (float) – -Sersic index

  • -
  • R_sersic (float) – -Sersic scale radius

  • -
  • k_eff (float) – -Sersic convergence at R_sersic

  • -
-
-
Returns
-

Sersic radius

-
-
Return type
-

float

-
-
-
- -
-
-lower_limit_default = {'R_sersic': 0.0, 'center_x': -100.0, 'center_y': -100.0, 'e1': -0.5, 'e2': -0.5, 'k_eff': 0.0, 'n_sersic': 0.5}
-
- -
-
-param_names = ['k_eff', 'R_sersic', 'n_sersic', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'R_sersic': 100.0, 'center_x': 100.0, 'center_y': 100.0, 'e1': 0.5, 'e2': 0.5, 'k_eff': 100.0, 'n_sersic': 8.0}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.gaussian_ellipse_kappa module

-

This module defines class GaussianEllipseKappa to compute the lensing -properties of an elliptical Gaussian profile with ellipticity in the -convergence using the formulae from Shajib (2019).

-
-
-class lenstronomy.LensModel.Profiles.gaussian_ellipse_kappa.GaussianEllipseKappa(use_scipy_wofz=True, min_ellipticity=1e-05)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

This class contains functions to evaluate the derivative and hessian matrix -of the deflection potential for an elliptical Gaussian convergence.

-

The formulae are from Shajib (2019).

-
-
-density_2d(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]
-

Compute the density of elliptical Gaussian \(A/(2 \pi -\sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\).

-
-
Parameters
-
    -
  • x (float or numpy.array) – x coordinate.

  • -
  • y (float or numpy.array) – y coordinate.

  • -
  • amp (float) – Amplitude of Gaussian, convention: \(A/(2 \pi\sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\)

  • -
  • sigma (float) – Standard deviation of Gaussian.

  • -
  • e1 (float) – Ellipticity parameter 1.

  • -
  • e2 (float) – Ellipticity parameter 2.

  • -
  • center_x (float) – x coordinate of centroid.

  • -
  • center_y (float) – y coordianate of centroid.

  • -
-
-
Returns
-

Density \(\kappa\) for elliptical Gaussian convergence.

-
-
Return type
-

float, or numpy.array with shape = x.shape.

-
-
-
- -
-
-derivatives(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]
-

Compute the derivatives of function angles \(\partial -f/\partial x\), \(\partial f/\partial y\) at \(x,\ y\).

-
-
Parameters
-
    -
  • x (float or numpy.array) – x coordinate

  • -
  • y (float or numpy.array) – y coordinate

  • -
  • amp (float) – Amplitude of Gaussian, convention: \(A/(2 \pi\sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\)

  • -
  • sigma (float) – Standard deviation of Gaussian

  • -
  • e1 (float) – Ellipticity parameter 1

  • -
  • e2 (float) – Ellipticity parameter 2

  • -
  • center_x (float) – x coordinate of centroid

  • -
  • center_y (float) – y coordianate of centroid

  • -
-
-
Returns
-

Deflection angle \(\partial f/\partial x\), \(\partial f/\partial y\) -for elliptical Gaussian convergence.

-
-
Return type
-

tuple (float, float) or (numpy.array, numpy.array) with each numpy.array’s shape equal -to x.shape.

-
-
-
- -
-
-function(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]
-

Compute the potential function for elliptical Gaussian convergence.

-
-
Parameters
-
    -
  • x (float or numpy.array) – x coordinate

  • -
  • y (float or numpy.array) – y coordinate

  • -
  • amp (float) – Amplitude of Gaussian, convention: \(A/(2 \pi\sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\)

  • -
  • sigma (float) – Standard deviation of Gaussian

  • -
  • e1 (float) – Ellipticity parameter 1

  • -
  • e2 (float) – Ellipticity parameter 2

  • -
  • center_x (float) – x coordinate of centroid

  • -
  • center_y (float) – y coordianate of centroid

  • -
-
-
Returns
-

Potential for elliptical Gaussian convergence

-
-
Return type
-

float, or numpy.array with shape equal to x.shape

-
-
-
- -
-
-hessian(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]
-

Compute Hessian matrix of function \(\partial^2f/\partial x^2\), -\(\partial^2 f/\partial y^2\), \(\partial^2/\partial -x\partial y\).

-
-
Parameters
-
    -
  • x (float or numpy.array) – x coordinate

  • -
  • y (float or numpy.array) – y coordinate

  • -
  • amp (float) – Amplitude of Gaussian, convention: \(A/(2 \pi\sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\)

  • -
  • sigma (float) – Standard deviation of Gaussian

  • -
  • e1 (float) – Ellipticity parameter 1

  • -
  • e2 (float) – Ellipticity parameter 2

  • -
  • center_x (float) – x coordinate of centroid

  • -
  • center_y (float) – y coordianate of centroid

  • -
-
-
Returns
-

Hessian \(A/(2 \pi \sigma^2) \exp(-(x^2+y^2/q^2)/2\sigma^2)\) for elliptical Gaussian -convergence.

-
-
Return type
-

tuple (float, float, float) , or (numpy.array, numpy.array, numpy.array) with each numpy.array’s shape equal to x.shape.

-
-
-
- -
-
-lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'sigma': 0}
-
- -
-
-param_names = ['amp', 'sigma', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-static sgn(z)[source]
-

Compute the sign function \(\mathrm{sgn}(z)\) factor for -deflection as sugggested by Bray (1984). For current implementation, returning 1 is sufficient.

-
-
Parameters
-

z (complex) – Complex variable \(z = x + \mathrm{i}y\)

-
-
Returns
-

\(\mathrm{sgn}(z)\)

-
-
Return type
-

float

-
-
-
- -
-
-sigma_function(x, y, q)[source]
-

Compute the function \(\varsigma (z; q)\) from equation (4.12) -of Shajib (2019).

-
-
Parameters
-
    -
  • x (float or numpy.array) – Real part of complex variable, \(x = \mathrm{Re}(z)\)

  • -
  • y (float or numpy.array) – Imaginary part of complex variable, \(y = \mathrm{Im}(z)\)

  • -
  • q (float) – Axis ratio

  • -
-
-
Returns
-

real and imaginary part of \(\varsigma(z; q)\) function

-
-
Return type
-

tuple (type(x), type(x))

-
-
-
- -
-
-upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'sigma': 100}
-
- -
-
-static w_f_approx(z)[source]
-

Compute the Faddeeva function \(w_{\mathrm F}(z)\) using the -approximation given in Zaghloul (2017).

-
-
Parameters
-

z (complex or numpy.array(dtype=complex)) – complex number

-
-
Returns
-

\(w_\mathrm{F}(z)\)

-
-
Return type
-

complex

-
-
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.gaussian_ellipse_potential module

-
-
-class lenstronomy.LensModel.Profiles.gaussian_ellipse_potential.GaussianEllipsePotential[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class contains functions to evaluate a Gaussian function and calculates its derivative and hessian matrix -with ellipticity in the convergence

-

the calculation follows Glenn van de Ven et al. 2009

-
-
-density(r, amp, sigma, e1, e2)[source]
-
-
Parameters
-
    -
  • r

  • -
  • amp

  • -
  • sigma

  • -
-
-
Returns
-

-
-
-
- -
-
-density_2d(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp

  • -
  • sigma

  • -
  • e1

  • -
  • e2

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-derivatives(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]
-

returns df/dx and df/dy of the function

-
- -
-
-function(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]
-

returns Gaussian

-
- -
-
-hessian(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
- -
-
-lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'sigma': 0}
-
- -
-
-mass_2d(R, amp, sigma, e1, e2)[source]
-
-
Parameters
-
    -
  • R

  • -
  • amp

  • -
  • sigma

  • -
  • e1

  • -
  • e2

  • -
-
-
Returns
-

-
-
-
- -
-
-mass_2d_lens(R, amp, sigma, e1, e2)[source]
-
-
Parameters
-
    -
  • R

  • -
  • amp

  • -
  • sigma

  • -
  • e1

  • -
  • e2

  • -
-
-
Returns
-

-
-
-
- -
-
-mass_3d(R, amp, sigma, e1, e2)[source]
-
-
Parameters
-
    -
  • R

  • -
  • amp

  • -
  • sigma

  • -
  • e1

  • -
  • e2

  • -
-
-
Returns
-

-
-
-
- -
-
-mass_3d_lens(R, amp, sigma, e1, e2)[source]
-
-
Parameters
-
    -
  • R

  • -
  • amp

  • -
  • sigma

  • -
  • e1

  • -
  • e2

  • -
-
-
Returns
-

-
-
-
- -
-
-param_names = ['amp', 'sigma', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'sigma': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.gaussian_kappa module

-
-
-class lenstronomy.LensModel.Profiles.gaussian_kappa.GaussianKappa[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class contains functions to evaluate a Gaussian function and calculates its derivative and hessian matrix

-
-
-alpha_abs(R, amp, sigma)[source]
-

absolute value of the deflection -:param R: -:param amp: -:param sigma: -:return:

-
- -
-
-d_alpha_dr(R, amp, sigma_x, sigma_y)[source]
-
-
Parameters
-
    -
  • R

  • -
  • amp

  • -
  • sigma_x

  • -
  • sigma_y

  • -
-
-
Returns
-

-
-
-
- -
-
-density(r, amp, sigma)[source]
-
-
Parameters
-
    -
  • r

  • -
  • amp

  • -
  • sigma

  • -
-
-
Returns
-

-
-
-
- -
-
-density_2d(x, y, amp, sigma, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp

  • -
  • sigma

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-derivatives(x, y, amp, sigma, center_x=0, center_y=0)[source]
-

returns df/dx and df/dy of the function

-
- -
-
-function(x, y, amp, sigma, center_x=0, center_y=0)[source]
-

returns Gaussian

-
- -
-
-hessian(x, y, amp, sigma, center_x=0, center_y=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
- -
-
-lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'sigma': 0}
-
- -
-
-mass_2d(R, amp, sigma)[source]
-
-
Parameters
-
    -
  • R

  • -
  • amp

  • -
  • sigma

  • -
-
-
Returns
-

-
-
-
- -
-
-mass_2d_lens(R, amp, sigma)[source]
-
-
Parameters
-
    -
  • R

  • -
  • amp

  • -
  • sigma

  • -
-
-
Returns
-

-
-
-
- -
-
-mass_3d(R, amp, sigma)[source]
-
-
Parameters
-
    -
  • R

  • -
  • amp

  • -
  • sigma

  • -
-
-
Returns
-

-
-
-
- -
-
-mass_3d_lens(R, amp, sigma)[source]
-
-
Parameters
-
    -
  • R

  • -
  • amp

  • -
  • sigma

  • -
-
-
Returns
-

-
-
-
- -
-
-param_names = ['amp', 'sigma', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'sigma': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.gaussian_potential module

-
-
-class lenstronomy.LensModel.Profiles.gaussian_potential.Gaussian(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class contains functions to evaluate a Gaussian function and calculates its derivative and hessian matrix

-
-
-derivatives(x, y, amp, sigma_x, sigma_y, center_x=0, center_y=0)[source]
-

returns df/dx and df/dy of the function

-
- -
-
-function(x, y, amp, sigma_x, sigma_y, center_x=0, center_y=0)[source]
-

returns Gaussian

-
- -
-
-hessian(x, y, amp, sigma_x, sigma_y, center_x=0, center_y=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
- -
-
-lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'sigma': 0}
-
- -
-
-param_names = ['amp', 'sigma_x', 'sigma_y', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'sigma': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.hernquist module

-
-
-class lenstronomy.LensModel.Profiles.hernquist.Hernquist(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class to compute the Hernquist 1990 model, which is in 3d: -rho(r) = rho0 / (r/Rs * (1 + (r/Rs))**3)

-

in lensing terms, the normalization parameter ‘sigma0’ is defined such that the deflection at projected RS leads to -alpha = 2./3 * Rs * sigma0

-
-
-density(r, rho0, Rs)[source]
-

computes the 3-d density

-
-
Parameters
-
    -
  • r – 3-d radius

  • -
  • rho0 – density normalization

  • -
  • Rs – Hernquist radius

  • -
-
-
Returns
-

density at radius r

-
-
-
- -
-
-density_2d(x, y, rho0, Rs, center_x=0, center_y=0)[source]
-

projected density along the line of sight at coordinate (x, y)

-
-
Parameters
-
    -
  • x – x-coordinate

  • -
  • y – y-coordinate

  • -
  • rho0 – density normalization

  • -
  • Rs – Hernquist radius

  • -
  • center_x – x-center of the profile

  • -
  • center_y – y-center of the profile

  • -
-
-
Returns
-

projected density

-
-
-
- -
-
-density_lens(r, sigma0, Rs)[source]
-

Density as a function of 3d radius in lensing parameters -This function converts the lensing definition sigma0 into the 3d density

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • sigma0 – rho0 * Rs (units of projected density)

  • -
  • Rs – Hernquist radius

  • -
-
-
Returns
-

enclosed mass in 3d

-
-
-
- -
-
-derivatives(x, y, sigma0, Rs, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate position (units of angle)

  • -
  • y – y-coordinate position (units of angle)

  • -
  • sigma0 – normalization parameter defined such that the deflection at projected RS leads to alpha = 2./3 * Rs * sigma0

  • -
  • Rs – Hernquist radius in units of angle

  • -
  • center_x – x-center of the profile (units of angle)

  • -
  • center_y – y-center of the profile (units of angle)

  • -
-
-
Returns
-

derivative of function (deflection angles in x- and y-direction)

-
-
-
- -
-
-function(x, y, sigma0, Rs, center_x=0, center_y=0)[source]
-

lensing potential

-
-
Parameters
-
    -
  • x – x-coordinate position (units of angle)

  • -
  • y – y-coordinate position (units of angle)

  • -
  • sigma0 – normalization parameter defined such that the deflection at projected RS leads to alpha = 2./3 * Rs * sigma0

  • -
  • Rs – Hernquist radius in units of angle

  • -
  • center_x – x-center of the profile (units of angle)

  • -
  • center_y – y-center of the profile (units of angle)

  • -
-
-
Returns
-

lensing potential at (x,y)

-
-
-
- -
-
-grav_pot(x, y, rho0, Rs, center_x=0, center_y=0)[source]
-

#TODO decide whether these functions are needed or not

-

gravitational potential (modulo 4 pi G and rho0 in appropriate units) -:param x: x-coordinate position (units of angle) -:param y: y-coordinate position (units of angle) -:param rho0: density normalization parameter of Hernquist profile -:param Rs: Hernquist radius in units of angle -:param center_x: x-center of the profile (units of angle) -:param center_y: y-center of the profile (units of angle) -:return: gravitational potential at projected radius

-
- -
-
-hessian(x, y, sigma0, Rs, center_x=0, center_y=0)[source]
-

Hessian terms of the function

-
-
Parameters
-
    -
  • x – x-coordinate position (units of angle)

  • -
  • y – y-coordinate position (units of angle)

  • -
  • sigma0 – normalization parameter defined such that the deflection at projected RS leads to alpha = 2./3 * Rs * sigma0

  • -
  • Rs – Hernquist radius in units of angle

  • -
  • center_x – x-center of the profile (units of angle)

  • -
  • center_y – y-center of the profile (units of angle)

  • -
-
-
Returns
-

df/dxdx, df/dxdy, df/dydx, df/dydy

-
-
-
- -
-
-lower_limit_default = {'Rs': 0, 'center_x': -100, 'center_y': -100, 'sigma0': 0}
-
- -
-
-mass_2d(r, rho0, Rs)[source]
-

mass enclosed projected 2d sphere of radius r

-
-
Parameters
-
    -
  • r – projected radius

  • -
  • rho0 – density normalization

  • -
  • Rs – Hernquist radius

  • -
-
-
Returns
-

mass enclosed 2d projected radius

-
-
-
- -
-
-mass_2d_lens(r, sigma0, Rs)[source]
-

mass enclosed projected 2d sphere of radius r -Same as mass_2d but with input normalization in units of projected density -:param r: projected radius -:param sigma0: rho0 * Rs (units of projected density) -:param Rs: Hernquist radius -:return: mass enclosed 2d projected radius

-
- -
-
-mass_3d(r, rho0, Rs)[source]
-

mass enclosed a 3d sphere or radius r

-
-
Parameters
-
    -
  • r – 3-d radius within the mass is integrated (same distance units as density definition)

  • -
  • rho0 – density normalization

  • -
  • Rs – Hernquist radius

  • -
-
-
Returns
-

enclosed mass

-
-
-
- -
-
-mass_3d_lens(r, sigma0, Rs)[source]
-

mass enclosed a 3d sphere or radius r for lens parameterisation -This function converts the lensing definition sigma0 into the 3d density

-
-
Parameters
-
    -
  • sigma0 – rho0 * Rs (units of projected density)

  • -
  • Rs – Hernquist radius

  • -
-
-
Returns
-

enclosed mass in 3d

-
-
-
- -
-
-mass_tot(rho0, Rs)[source]
-

total mass within the profile -:param rho0: density normalization -:param Rs: Hernquist radius -:return: total mass within profile

-
- -
-
-param_names = ['sigma0', 'Rs', 'center_x', 'center_y']
-
- -
-
-rho2sigma(rho0, Rs)[source]
-

converts 3d density into 2d projected density parameter -:param rho0: 3d density normalization of Hernquist model -:param Rs: Hernquist radius -:return: sigma0 defined quantity in projected units

-
- -
-
-sigma2rho(sigma0, Rs)[source]
-

converts projected density parameter (in units of deflection) into 3d density parameter -:param sigma0: density defined quantity in projected units -:param Rs: Hernquist radius -:return: rho0 the 3d density normalization of Hernquist model

-
- -
-
-upper_limit_default = {'Rs': 100, 'center_x': 100, 'center_y': 100, 'sigma0': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.hernquist_ellipse module

-
-
-class lenstronomy.LensModel.Profiles.hernquist_ellipse.Hernquist_Ellipse[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class contains functions for the elliptical Hernquist profile. Ellipticity is defined in the potential.

-
-
-density(r, rho0, Rs, e1=0, e2=0)[source]
-

computes the 3-d density

-
-
Parameters
-
    -
  • r – 3-d radius

  • -
  • rho0 – density normalization

  • -
  • Rs – Hernquist radius

  • -
-
-
Returns
-

density at radius r

-
-
-
- -
-
-density_2d(x, y, rho0, Rs, e1=0, e2=0, center_x=0, center_y=0)[source]
-

projected density along the line of sight at coordinate (x, y)

-
-
Parameters
-
    -
  • x – x-coordinate

  • -
  • y – y-coordinate

  • -
  • rho0 – density normalization

  • -
  • Rs – Hernquist radius

  • -
  • center_x – x-center of the profile

  • -
  • center_y – y-center of the profile

  • -
-
-
Returns
-

projected density

-
-
-
- -
-
-density_lens(r, sigma0, Rs, e1=0, e2=0)[source]
-

Density as a function of 3d radius in lensing parameters -This function converts the lensing definition sigma0 into the 3d density

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • sigma0 – rho0 * Rs (units of projected density)

  • -
  • Rs – Hernquist radius

  • -
-
-
Returns
-

enclosed mass in 3d

-
-
-
- -
-
-derivatives(x, y, sigma0, Rs, e1, e2, center_x=0, center_y=0)[source]
-

returns df/dx and df/dy of the function (integral of NFW)

-
- -
-
-function(x, y, sigma0, Rs, e1, e2, center_x=0, center_y=0)[source]
-

returns double integral of NFW profile

-
- -
-
-hessian(x, y, sigma0, Rs, e1, e2, center_x=0, center_y=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
- -
-
-lower_limit_default = {'Rs': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'sigma0': 0}
-
- -
-
-mass_2d(r, rho0, Rs, e1=0, e2=0)[source]
-

mass enclosed projected 2d sphere of radius r

-
-
Parameters
-
    -
  • r – projected radius

  • -
  • rho0 – density normalization

  • -
  • Rs – Hernquist radius

  • -
-
-
Returns
-

mass enclosed 2d projected radius

-
-
-
- -
-
-mass_2d_lens(r, sigma0, Rs, e1=0, e2=0)[source]
-

mass enclosed projected 2d sphere of radius r -Same as mass_2d but with input normalization in units of projected density -:param r: projected radius -:param sigma0: rho0 * Rs (units of projected density) -:param Rs: Hernquist radius -:return: mass enclosed 2d projected radius

-
- -
-
-mass_3d(r, rho0, Rs, e1=0, e2=0)[source]
-

mass enclosed a 3d sphere or radius r

-
-
Parameters
-
    -
  • r – 3-d radius within the mass is integrated (same distance units as density definition)

  • -
  • rho0 – density normalization

  • -
  • Rs – Hernquist radius

  • -
-
-
Returns
-

enclosed mass

-
-
-
- -
-
-mass_3d_lens(r, sigma0, Rs, e1=0, e2=0)[source]
-

mass enclosed a 3d sphere or radius r in lensing parameterization

-
-
Parameters
-
    -
  • r – 3-d radius within the mass is integrated (same distance units as density definition)

  • -
  • sigma0 – rho0 * Rs (units of projected density)

  • -
  • Rs – Hernquist radius

  • -
-
-
Returns
-

enclosed mass

-
-
-
- -
-
-param_names = ['sigma0', 'Rs', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'Rs': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'sigma0': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.hessian module

-
-
-class lenstronomy.LensModel.Profiles.hessian.Hessian(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class for constant Hessian distortion (second order) -The input is in the same convention as the LensModel.hessian() output.

-
-
-derivatives(x, y, f_xx, f_yy, f_xy, f_yx, ra_0=0, dec_0=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y0-coordinate (angle)

  • -
  • f_xx – dalpha_x/dx

  • -
  • f_yy – dalpha_y/dy

  • -
  • f_xy – dalpha_x/dy

  • -
  • f_yx – dalpha_y/dx

  • -
  • ra_0 – x/ra position where shear deflection is 0

  • -
  • dec_0 – y/dec position where shear deflection is 0

  • -
-
-
Returns
-

deflection angles

-
-
-
- -
-
-function(x, y, f_xx, f_yy, f_xy, f_yx, ra_0=0, dec_0=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y0-coordinate (angle)

  • -
  • f_xx – dalpha_x/dx

  • -
  • f_yy – dalpha_y/dy

  • -
  • f_xy – dalpha_x/dy

  • -
  • f_yx – dalpha_y/dx

  • -
  • ra_0 – x/ra position where shear deflection is 0

  • -
  • dec_0 – y/dec position where shear deflection is 0

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, f_xx, f_yy, f_xy, f_yx, ra_0=0, dec_0=0)[source]
-

Hessian. Attention: If f_xy != f_yx then this function is not accurate!

-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y0-coordinate (angle)

  • -
  • f_xx – dalpha_x/dx

  • -
  • f_yy – dalpha_y/dy

  • -
  • f_xy – dalpha_x/dy

  • -
  • f_yx – dalpha_y/dx

  • -
  • ra_0 – x/ra position where shear deflection is 0

  • -
  • dec_0 – y/dec position where shear deflection is 0

  • -
-
-
Returns
-

f_xx, f_yy, f_xy

-
-
-
- -
-
-lower_limit_default = {'dec_0': -100, 'f_xx': -100, 'f_xy': -100, 'f_yx': -100, 'f_yy': -100, 'ra_0': -100}
-
- -
-
-param_names = ['f_xx', 'f_yy', 'f_xy', 'f_yx', 'ra_0', 'dec_0']
-
- -
-
-upper_limit_default = {'dec_0': 100, 'f_xx': 100, 'f_xy': 100, 'f_yx': 100, 'f_yy': 100, 'ra_0': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.interpol module

-
-
-class lenstronomy.LensModel.Profiles.interpol.Interpol(grid=False, min_grid_number=100, kwargs_spline=None)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class which uses an interpolation of a lens model and its first and second order derivatives

-

See also the tests in lenstronomy.test.test_LensModel.test_Profiles.test_interpol.py for example use cases -as checks against known analytic models.

-

The deflection angle is in the same convention as the one in the LensModel module, meaning that: -source position = image position - deflection angle

-
-
-derivatives(x, y, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None, f_xx=None, f_yy=None, f_xy=None)[source]
-

returns df/dx and df/dy of the function

-
-
Parameters
-
    -
  • x – x-coordinate (angular position), float or numpy array

  • -
  • y – y-coordinate (angular position), float or numpy array

  • -
  • grid_interp_x – numpy array (ascending) to mark the x-direction of the interpolation grid

  • -
  • grid_interp_y – numpy array (ascending) to mark the y-direction of the interpolation grid

  • -
  • f – 2d numpy array of lensing potential, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_x – 2d numpy array of deflection in x-direction, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_y – 2d numpy array of deflection in y-direction, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_xx – 2d numpy array of df/dxx, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_yy – 2d numpy array of df/dyy, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_xy – 2d numpy array of df/dxy, matching the grids in grid_interp_x and grid_interp_y

  • -
-
-
Returns
-

f_x, f_y at interpolated positions (x, y)

-
-
-
- -
-
-do_interp(x_grid, y_grid, f_, f_x, f_y, f_xx=None, f_yy=None, f_xy=None)[source]
-
- -
-
-f_interp(x, y, x_grid=None, y_grid=None, f_=None, grid=False)[source]
-
- -
-
-f_x_interp(x, y, x_grid=None, y_grid=None, f_x=None, grid=False)[source]
-
- -
-
-f_xx_interp(x, y, x_grid=None, y_grid=None, f_xx=None, grid=False)[source]
-
- -
-
-f_xy_interp(x, y, x_grid=None, y_grid=None, f_xy=None, grid=False)[source]
-
- -
-
-f_y_interp(x, y, x_grid=None, y_grid=None, f_y=None, grid=False)[source]
-
- -
-
-f_yy_interp(x, y, x_grid=None, y_grid=None, f_yy=None, grid=False)[source]
-
- -
-
-function(x, y, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None, f_xx=None, f_yy=None, f_xy=None)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angular position), float or numpy array

  • -
  • y – y-coordinate (angular position), float or numpy array

  • -
  • grid_interp_x – numpy array (ascending) to mark the x-direction of the interpolation grid

  • -
  • grid_interp_y – numpy array (ascending) to mark the y-direction of the interpolation grid

  • -
  • f – 2d numpy array of lensing potential, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_x – 2d numpy array of deflection in x-direction, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_y – 2d numpy array of deflection in y-direction, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_xx – 2d numpy array of df/dxx, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_yy – 2d numpy array of df/dyy, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_xy – 2d numpy array of df/dxy, matching the grids in grid_interp_x and grid_interp_y

  • -
-
-
Returns
-

potential at interpolated positions (x, y)

-
-
-
- -
-
-hessian(x, y, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None, f_xx=None, f_yy=None, f_xy=None)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
-
Parameters
-
    -
  • x – x-coordinate (angular position), float or numpy array

  • -
  • y – y-coordinate (angular position), float or numpy array

  • -
  • grid_interp_x – numpy array (ascending) to mark the x-direction of the interpolation grid

  • -
  • grid_interp_y – numpy array (ascending) to mark the y-direction of the interpolation grid

  • -
  • f – 2d numpy array of lensing potential, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_x – 2d numpy array of deflection in x-direction, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_y – 2d numpy array of deflection in y-direction, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_xx – 2d numpy array of df/dxx, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_yy – 2d numpy array of df/dyy, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_xy – 2d numpy array of df/dxy, matching the grids in grid_interp_x and grid_interp_y

  • -
-
-
Returns
-

f_xx, f_xy, f_yx, f_yy at interpolated positions (x, y)

-
-
-
- -
-
-lower_limit_default = {}
-
- -
-
-param_names = ['grid_interp_x', 'grid_interp_y', 'f_', 'f_x', 'f_y', 'f_xx', 'f_yy', 'f_xy']
-
- -
-
-upper_limit_default = {}
-
- -
- -
-
-class lenstronomy.LensModel.Profiles.interpol.InterpolScaled(grid=True, min_grid_number=100, kwargs_spline=None)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class for handling an interpolated lensing map and has the freedom to scale its lensing effect. -Applications are e.g. mass to light ratio.

-
-
-derivatives(x, y, scale_factor=1, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None, f_xx=None, f_yy=None, f_xy=None)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angular position), float or numpy array

  • -
  • y – y-coordinate (angular position), float or numpy array

  • -
  • scale_factor – float, overall scaling of the lens model relative to the input interpolation grid

  • -
  • grid_interp_x – numpy array (ascending) to mark the x-direction of the interpolation grid

  • -
  • grid_interp_y – numpy array (ascending) to mark the y-direction of the interpolation grid

  • -
  • f – 2d numpy array of lensing potential, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_x – 2d numpy array of deflection in x-direction, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_y – 2d numpy array of deflection in y-direction, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_xx – 2d numpy array of df/dxx, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_yy – 2d numpy array of df/dyy, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_xy – 2d numpy array of df/dxy, matching the grids in grid_interp_x and grid_interp_y

  • -
-
-
Returns
-

deflection angles in x- and y-direction at position (x, y)

-
-
-
- -
-
-function(x, y, scale_factor=1, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None, f_xx=None, f_yy=None, f_xy=None)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angular position), float or numpy array

  • -
  • y – y-coordinate (angular position), float or numpy array

  • -
  • scale_factor – float, overall scaling of the lens model relative to the input interpolation grid

  • -
  • grid_interp_x – numpy array (ascending) to mark the x-direction of the interpolation grid

  • -
  • grid_interp_y – numpy array (ascending) to mark the y-direction of the interpolation grid

  • -
  • f – 2d numpy array of lensing potential, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_x – 2d numpy array of deflection in x-direction, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_y – 2d numpy array of deflection in y-direction, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_xx – 2d numpy array of df/dxx, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_yy – 2d numpy array of df/dyy, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_xy – 2d numpy array of df/dxy, matching the grids in grid_interp_x and grid_interp_y

  • -
-
-
Returns
-

potential at interpolated positions (x, y)

-
-
-
- -
-
-hessian(x, y, scale_factor=1, grid_interp_x=None, grid_interp_y=None, f_=None, f_x=None, f_y=None, f_xx=None, f_yy=None, f_xy=None)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angular position), float or numpy array

  • -
  • y – y-coordinate (angular position), float or numpy array

  • -
  • scale_factor – float, overall scaling of the lens model relative to the input interpolation grid

  • -
  • grid_interp_x – numpy array (ascending) to mark the x-direction of the interpolation grid

  • -
  • grid_interp_y – numpy array (ascending) to mark the y-direction of the interpolation grid

  • -
  • f – 2d numpy array of lensing potential, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_x – 2d numpy array of deflection in x-direction, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_y – 2d numpy array of deflection in y-direction, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_xx – 2d numpy array of df/dxx, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_yy – 2d numpy array of df/dyy, matching the grids in grid_interp_x and grid_interp_y

  • -
  • f_xy – 2d numpy array of df/dxy, matching the grids in grid_interp_x and grid_interp_y

  • -
-
-
Returns
-

second derivatives of the lensing potential f_xx, f_yy, f_xy at position (x, y)

-
-
-
- -
-
-lower_limit_default = {'scale_factor': 0}
-
- -
-
-param_names = ['scale_factor', 'grid_interp_x', 'grid_interp_y', 'f_', 'f_x', 'f_y', 'f_xx', 'f_yy', 'f_xy']
-
- -
-
-upper_limit_default = {'scale_factor': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.multi_gaussian_kappa module

-
-
-class lenstronomy.LensModel.Profiles.multi_gaussian_kappa.MultiGaussianKappa[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-
-
-density(r, amp, sigma, scale_factor=1)[source]
-
-
Parameters
-
    -
  • r

  • -
  • amp

  • -
  • sigma

  • -
-
-
Returns
-

-
-
-
- -
-
-density_2d(x, y, amp, sigma, center_x=0, center_y=0, scale_factor=1)[source]
-
-
Parameters
-
    -
  • R

  • -
  • am

  • -
  • sigma_x

  • -
  • sigma_y

  • -
-
-
Returns
-

-
-
-
- -
-
-derivatives(x, y, amp, sigma, center_x=0, center_y=0, scale_factor=1)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp

  • -
  • sigma

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-function(x, y, amp, sigma, center_x=0, center_y=0, scale_factor=1)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp

  • -
  • sigma

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-hessian(x, y, amp, sigma, center_x=0, center_y=0, scale_factor=1)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp

  • -
  • sigma

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'sigma': 0}
-
- -
-
-mass_3d_lens(R, amp, sigma, scale_factor=1)[source]
-
-
Parameters
-
    -
  • R

  • -
  • amp

  • -
  • sigma

  • -
-
-
Returns
-

-
-
-
- -
-
-param_names = ['amp', 'sigma', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'sigma': 100}
-
- -
- -
-
-class lenstronomy.LensModel.Profiles.multi_gaussian_kappa.MultiGaussianKappaEllipse[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-
-
-density(r, amp, sigma, e1, e2, scale_factor=1)[source]
-
-
Parameters
-
    -
  • r

  • -
  • amp

  • -
  • sigma

  • -
-
-
Returns
-

-
-
-
- -
-
-density_2d(x, y, amp, sigma, e1, e2, center_x=0, center_y=0, scale_factor=1)[source]
-
-
Parameters
-
    -
  • R

  • -
  • am

  • -
  • sigma_x

  • -
  • sigma_y

  • -
-
-
Returns
-

-
-
-
- -
-
-derivatives(x, y, amp, sigma, e1, e2, center_x=0, center_y=0, scale_factor=1)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp

  • -
  • sigma

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-function(x, y, amp, sigma, e1, e2, center_x=0, center_y=0, scale_factor=1)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp

  • -
  • sigma

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-hessian(x, y, amp, sigma, e1, e2, center_x=0, center_y=0, scale_factor=1)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp

  • -
  • sigma

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'sigma': 0}
-
- -
-
-mass_3d_lens(R, amp, sigma, e1, e2, scale_factor=1)[source]
-
-
Parameters
-
    -
  • R

  • -
  • amp

  • -
  • sigma

  • -
-
-
Returns
-

-
-
-
- -
-
-param_names = ['amp', 'sigma', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'sigma': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.multipole module

-
-
-class lenstronomy.LensModel.Profiles.multipole.Multipole(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

This class contains a multipole contribution (for 1 component with m>=2) -This uses the same definitions as Xu et al.(2013) in Appendix B3 https://arxiv.org/pdf/1307.4220.pdf -m : int, multipole order, m>=2 -a_m : float, multipole strength -phi_m : float, multipole orientation in radian

-
-
-derivatives(x, y, m, a_m, phi_m, center_x=0, center_y=0)[source]
-

Deflection of a multipole contribution (for 1 component with m>=2) -This uses the same definitions as Xu et al.(2013) in Appendix B3 https://arxiv.org/pdf/1307.4220.pdf

-
-
Parameters
-
    -
  • m – int, multipole order, m>=2

  • -
  • a_m – float, multipole strength

  • -
  • phi_m – float, multipole orientation in radian

  • -
  • center_x – x-position

  • -
  • center_y – x-position

  • -
-
-
Returns
-

deflection angles alpha_x, alpha_y

-
-
-
- -
-
-function(x, y, m, a_m, phi_m, center_x=0, center_y=0)[source]
-

Lensing potential of multipole contribution (for 1 component with m>=2) -This uses the same definitions as Xu et al.(2013) in Appendix B3 https://arxiv.org/pdf/1307.4220.pdf

-
-
Parameters
-
    -
  • m – int, multipole order, m>=2

  • -
  • a_m – float, multipole strength

  • -
  • phi_m – float, multipole orientation in radian

  • -
  • center_x – x-position

  • -
  • center_y – x-position

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, m, a_m, phi_m, center_x=0, center_y=0)[source]
-

Hessian of a multipole contribution (for 1 component with m>=2) -This uses the same definitions as Xu et al.(2013) in Appendix B3 https://arxiv.org/pdf/1307.4220.pdf

-
-
Parameters
-
    -
  • m – int, multipole order, m>=2

  • -
  • a_m – float, multipole strength

  • -
  • phi_m – float, multipole orientation in radian

  • -
  • center_x – x-position

  • -
  • center_y – x-position

  • -
-
-
Returns
-

f_xx, f_xy, f_yx, f_yy

-
-
-
- -
-
-lower_limit_default = {'a_m': 0, 'center_x': -100, 'center_y': -100, 'm': 2, 'phi_m': -3.141592653589793}
-
- -
-
-param_names = ['m', 'a_m', 'phi_m', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'a_m': 100, 'center_x': 100, 'center_y': 100, 'm': 100, 'phi_m': 3.141592653589793}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.nfw module

-
-
-class lenstronomy.LensModel.Profiles.nfw.NFW(interpol=False, num_interp_X=1000, max_interp_X=10)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class contains functions concerning the NFW profile

-

relation are: R_200 = c * Rs -The definition of ‘Rs’ is in angular (arc second) units and the normalization is put in in regards to a deflection -angle at ‘Rs’ - ‘alpha_Rs’. To convert a physical mass and concentration definition into those lensing quantities -for a specific redshift configuration and cosmological model, you can find routines in lenstronomy.Cosmo.lens_cosmo.py

-
>>> from lenstronomy.Cosmo.lens_cosmo import LensCosmo
->>> from astropy.cosmology import FlatLambdaCDM
->>> cosmo = FlatLambdaCDM(H0=70, Om0=0.3, Ob0=0.05)
->>> lens_cosmo = LensCosmo(z_lens=0.5, z_source=1.5, cosmo=cosmo)
-
-
-

Here we compute the angular scale of Rs on the sky (in arc seconds) and the deflection angle at Rs (in arc seconds):

-
>>> Rs_angle, alpha_Rs = lens_cosmo.nfw_physical2angle(M=10**13, c=6)
-
-
-

And here we perform the inverse calculation given Rs_angle and alpha_Rs to return the physical halo properties.

-
>>> rho0, Rs, c, r200, M200 = lens_cosmo.nfw_angle2physical(Rs_angle=Rs_angle, alpha_Rs=alpha_Rs)
-
-
-

The lens model calculation uses angular units as arguments! So to execute a deflection angle calculation one uses

-
>>> from lenstronomy.LensModel.Profiles.hernquist import NFW
->>> nfw = NFW()
->>> alpha_x, alpha_y = nfw.derivatives(x=1, y=1, Rs=Rs_angle, alpha_Rs=alpha_Rs, center_x=0, center_y=0)
-
-
-
-
-F_(X)[source]
-

computes h()

-
-
Parameters
-

X

-
-
Returns
-

-
-
-
- -
-
-static alpha2rho0(alpha_Rs, Rs)[source]
-

convert angle at Rs into rho0

-
-
Parameters
-
    -
  • alpha_Rs – deflection angle at RS

  • -
  • Rs – scale radius

  • -
-
-
Returns
-

density normalization (characteristic density)

-
-
-
- -
-
-density(R, Rs, rho0)[source]
-

three dimensional NFW profile

-
-
Parameters
-
    -
  • R (float/numpy array) – radius of interest

  • -
  • Rs (float) – scale radius

  • -
  • rho0 (float) – density normalization (characteristic density)

  • -
-
-
Returns
-

rho(R) density

-
-
-
- -
-
-density_2d(x, y, Rs, rho0, center_x=0, center_y=0)[source]
-

projected two dimensional NFW profile (kappa*Sigma_crit)

-
-
Parameters
-
    -
  • R (float/numpy array) – radius of interest

  • -
  • Rs (float) – scale radius

  • -
  • rho0 (float) – density normalization (characteristic density)

  • -
  • r200 (float>0) – radius of (sub)halo

  • -
-
-
Returns
-

Epsilon(R) projected density at radius R

-
-
-
- -
-
-density_lens(r, Rs, alpha_Rs)[source]
-

computes the density at 3d radius r given lens model parameterization. -The integral in the LOS projection of this quantity results in the convergence quantity.

-
-
Parameters
-
    -
  • r – 3d radios

  • -
  • Rs – turn-over radius of NFW profile

  • -
  • alpha_Rs – deflection at Rs

  • -
-
-
Returns
-

density rho(r)

-
-
-
- -
-
-derivatives(x, y, Rs, alpha_Rs, center_x=0, center_y=0)[source]
-

returns df/dx and df/dy of the function (integral of NFW), which are the deflection angles

-
-
Parameters
-
    -
  • x – angular position (normally in units of arc seconds)

  • -
  • y – angular position (normally in units of arc seconds)

  • -
  • Rs – turn over point in the slope of the NFW profile in angular unit

  • -
  • alpha_Rs – deflection (angular units) at projected Rs

  • -
  • center_x – center of halo (in angular units)

  • -
  • center_y – center of halo (in angular units)

  • -
-
-
Returns
-

deflection angle in x, deflection angle in y

-
-
-
- -
-
-function(x, y, Rs, alpha_Rs, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – angular position (normally in units of arc seconds)

  • -
  • y – angular position (normally in units of arc seconds)

  • -
  • Rs – turn over point in the slope of the NFW profile in angular unit

  • -
  • alpha_Rs – deflection (angular units) at projected Rs

  • -
  • center_x – center of halo (in angular units)

  • -
  • center_y – center of halo (in angular units)

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-g_(X)[source]
-

computes h()

-
-
Parameters
-

X (float >0) – R/Rs

-
-
Returns
-

-
-
-
- -
-
-h_(X)[source]
-

computes h()

-
-
Parameters
-

X (float >0) – R/Rs

-
-
Returns
-

h(X)

-
-
-
- -
-
-hessian(x, y, Rs, alpha_Rs, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – angular position (normally in units of arc seconds)

  • -
  • y – angular position (normally in units of arc seconds)

  • -
  • Rs – turn over point in the slope of the NFW profile in angular unit

  • -
  • alpha_Rs – deflection (angular units) at projected Rs

  • -
  • center_x – center of halo (in angular units)

  • -
  • center_y – center of halo (in angular units)

  • -
-
-
Returns
-

Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
-
-
- -
-
-lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100}
-
- -
-
-mass_2d(R, Rs, rho0)[source]
-

mass enclosed a 2d cylinder or projected radius R -:param R: projected radius -:param Rs: scale radius -:param rho0: density normalization (characteristic density) -:return: mass in cylinder

-
- -
-
-mass_3d(r, Rs, rho0)[source]
-

mass enclosed a 3d sphere or radius r

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • Rs – scale radius

  • -
  • rho0 – density normalization (characteristic density)

  • -
-
-
Returns
-

M(<r)

-
-
-
- -
-
-mass_3d_lens(r, Rs, alpha_Rs)[source]
-

mass enclosed a 3d sphere or radius r. -This function takes as input the lensing parameterization.

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • Rs – scale radius

  • -
  • alpha_Rs – deflection (angular units) at projected Rs

  • -
-
-
Returns
-

M(<r)

-
-
-
- -
-
-nfwAlpha(R, Rs, rho0, ax_x, ax_y)[source]
-

deflection angel of NFW profile (times Sigma_crit D_OL) along the projection to coordinate ‘axis’

-
-
Parameters
-
    -
  • R (float/numpy array) – radius of interest

  • -
  • Rs (float) – scale radius

  • -
  • rho0 (float) – density normalization (characteristic density)

  • -
  • r200 (float>0) – radius of (sub)halo

  • -
  • axis (same as R) – projection to either x- or y-axis

  • -
-
-
Returns
-

Epsilon(R) projected density at radius R

-
-
-
- -
-
-nfwGamma(R, Rs, rho0, ax_x, ax_y)[source]
-

shear gamma of NFW profile (times Sigma_crit) along the projection to coordinate ‘axis’

-
-
Parameters
-
    -
  • R (float/numpy array) – radius of interest

  • -
  • Rs (float) – scale radius

  • -
  • rho0 (float) – density normalization (characteristic density)

  • -
  • r200 (float>0) – radius of (sub)halo

  • -
  • axis (same as R) – projection to either x- or y-axis

  • -
-
-
Returns
-

Epsilon(R) projected density at radius R

-
-
-
- -
-
-nfwPot(R, Rs, rho0)[source]
-

lensing potential of NFW profile (Sigma_crit D_OL**2)

-
-
Parameters
-
    -
  • R (float/numpy array) – radius of interest

  • -
  • Rs (float) – scale radius

  • -
  • rho0 (float) – density normalization (characteristic density)

  • -
  • r200 (float>0) – radius of (sub)halo

  • -
-
-
Returns
-

Epsilon(R) projected density at radius R

-
-
-
- -
-
-param_names = ['Rs', 'alpha_Rs', 'center_x', 'center_y']
-
- -
-
-profile_name = 'NFW'
-
- -
-
-static rho02alpha(rho0, Rs)[source]
-

convert rho0 to angle at Rs

-
-
Parameters
-
    -
  • rho0 – density normalization (characteristic density)

  • -
  • Rs – scale radius

  • -
-
-
Returns
-

deflection angle at RS

-
-
-
- -
-
-upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'center_x': 100, 'center_y': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.nfw_ellipse module

-
-
-class lenstronomy.LensModel.Profiles.nfw_ellipse.NFW_ELLIPSE(interpol=False, num_interp_X=1000, max_interp_X=10)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class contains functions concerning the NFW profile with an ellipticity defined in the potential -parameterization of alpha_Rs and Rs is the same as for the spherical NFW profile

-

from Glose & Kneib: https://cds.cern.ch/record/529584/files/0112138.pdf

-

relation are: R_200 = c * Rs

-
-
-density_lens(r, Rs, alpha_Rs, e1=1, e2=0)[source]
-

computes the density at 3d radius r given lens model parameterization. -The integral in the LOS projection of this quantity results in the convergence quantity.

-
-
Parameters
-
    -
  • r – 3d radios

  • -
  • Rs – turn-over radius of NFW profile

  • -
  • alpha_Rs – deflection at Rs

  • -
-
-
Returns
-

density rho(r)

-
-
-
- -
-
-derivatives(x, y, Rs, alpha_Rs, e1, e2, center_x=0, center_y=0)[source]
-

returns df/dx and df/dy of the function, calculated as an elliptically distorted deflection angle of the -spherical NFW profile

-
-
Parameters
-
    -
  • x – angular position (normally in units of arc seconds)

  • -
  • y – angular position (normally in units of arc seconds)

  • -
  • Rs – turn over point in the slope of the NFW profile in angular unit

  • -
  • alpha_Rs – deflection (angular units) at projected Rs

  • -
  • e1 – eccentricity component in x-direction

  • -
  • e2 – eccentricity component in y-direction

  • -
  • center_x – center of halo (in angular units)

  • -
  • center_y – center of halo (in angular units)

  • -
-
-
Returns
-

deflection in x-direction, deflection in y-direction

-
-
-
- -
-
-function(x, y, Rs, alpha_Rs, e1, e2, center_x=0, center_y=0)[source]
-

returns elliptically distorted NFW lensing potential

-
-
Parameters
-
    -
  • x – angular position (normally in units of arc seconds)

  • -
  • y – angular position (normally in units of arc seconds)

  • -
  • Rs – turn over point in the slope of the NFW profile in angular unit

  • -
  • alpha_Rs – deflection (angular units) at projected Rs

  • -
  • e1 – eccentricity component in x-direction

  • -
  • e2 – eccentricity component in y-direction

  • -
  • center_x – center of halo (in angular units)

  • -
  • center_y – center of halo (in angular units)

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, Rs, alpha_Rs, e1, e2, center_x=0, center_y=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^f/dy^2, d^2/dxdy -the calculation is performed as a numerical differential from the deflection field. Analytical relations are -possible

-
-
Parameters
-
    -
  • x – angular position (normally in units of arc seconds)

  • -
  • y – angular position (normally in units of arc seconds)

  • -
  • Rs – turn over point in the slope of the NFW profile in angular unit

  • -
  • alpha_Rs – deflection (angular units) at projected Rs

  • -
  • e1 – eccentricity component in x-direction

  • -
  • e2 – eccentricity component in y-direction

  • -
  • center_x – center of halo (in angular units)

  • -
  • center_y – center of halo (in angular units)

  • -
-
-
Returns
-

d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
-
-
- -
-
-lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5}
-
- -
-
-mass_3d_lens(R, Rs, alpha_Rs, e1=1, e2=0)[source]
-
-
Parameters
-
    -
  • R – radius (in angular units)

  • -
  • Rs

  • -
  • alpha_Rs

  • -
  • e1

  • -
  • e2

  • -
-
-
Returns
-

-
-
-
- -
-
-param_names = ['Rs', 'alpha_Rs', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-profile_name = 'NFW_ELLIPSE'
-
- -
-
-upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.nfw_mass_concentration module

-
-
-class lenstronomy.LensModel.Profiles.nfw_mass_concentration.NFWMC(z_lens, z_source, cosmo=None, static=False)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class contains functions parameterises the NFW profile with log10 M200 and the concentration rs/r200 -relation are: R_200 = c * Rs

-

ATTENTION: the parameterization is cosmology and redshift dependent! -The cosmology to connect mass and deflection relations is fixed to default H0=70km/s Omega_m=0.3 flat LCDM. -It is recommended to keep a given cosmology definition in the lens modeling as the observable reduced deflection -angles are sensitive in this parameterization. If you do not want to impose a mass-concentration relation, it is -recommended to use the default NFW lensing profile parameterized in reduced deflection angles.

-
-
-derivatives(x, y, logM, concentration, center_x=0, center_y=0)[source]
-

returns df/dx and df/dy of the function (integral of NFW)

-
- -
-
-function(x, y, logM, concentration, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – angular position

  • -
  • y – angular position

  • -
  • Rs – angular turn over point

  • -
  • alpha_Rs – deflection at Rs

  • -
  • center_x – center of halo

  • -
  • center_y – center of halo

  • -
-
-
Returns
-

-
-
-
- -
-
-hessian(x, y, logM, concentration, center_x=0, center_y=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'concentration': 0.01, 'logM': 0}
-
- -
-
-param_names = ['logM', 'concentration', 'center_x', 'center_y']
-
- -
-
-set_dynamic()[source]
-
-
Returns
-

-
-
-
- -
-
-set_static(logM, concentration, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • logM

  • -
  • concentration

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'concentration': 1000, 'logM': 16}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.nfw_vir_trunc module

-
-
-class lenstronomy.LensModel.Profiles.nfw_vir_trunc.NFWVirTrunc(z_lens, z_source, cosmo=None)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class contains functions concerning the NFW profile that is sharply truncated at the virial radius -https://arxiv.org/pdf/astro-ph/0304034.pdf

-

relation are: R_200 = c * Rs

-
-
-kappa(theta, logM, c)[source]
-

projected surface brightness

-
-
Parameters
-
    -
  • theta – radial angle from the center of the profile

  • -
  • logM – log_10 halo mass in physical units of M_sun

  • -
  • c – concentration of the halo; r_200 = c * r_s

  • -
-
-
Returns
-

convergence at theta

-
-
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.nie module

-
-
-class lenstronomy.LensModel.Profiles.nie.NIE[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

Non-singular isothermal ellipsoid (NIE)

-
-\[\kappa = \theta_E/2 \left[s_{scale} + qx^2 + y^2/q]−1/2\]
-
-
-density_lens(r, theta_E, e1, e2, s_scale, center_x=0, center_y=0)[source]
-

3d mass density at 3d radius r. This function assumes spherical symmetry/ignoring the eccentricity.

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • theta_E – Einstein radius

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • s_scale – smoothing scale

  • -
  • center_x – profile center

  • -
  • center_y – profile center

  • -
-
-
Returns
-

3d mass density at 3d radius r

-
-
-
- -
-
-derivatives(x, y, theta_E, e1, e2, s_scale, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate in image plane

  • -
  • y – y-coordinate in image plane

  • -
  • theta_E – Einstein radius

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • s_scale – smoothing scale

  • -
  • center_x – profile center

  • -
  • center_y – profile center

  • -
-
-
Returns
-

alpha_x, alpha_y

-
-
-
- -
-
-function(x, y, theta_E, e1, e2, s_scale, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate in image plane

  • -
  • y – y-coordinate in image plane

  • -
  • theta_E – Einstein radius

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • s_scale – smoothing scale

  • -
  • center_x – profile center

  • -
  • center_y – profile center

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, theta_E, e1, e2, s_scale, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate in image plane

  • -
  • y – y-coordinate in image plane

  • -
  • theta_E – Einstein radius

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • s_scale – smoothing scale

  • -
  • center_x – profile center

  • -
  • center_y – profile center

  • -
-
-
Returns
-

f_xx, f_xy, f_yx, f_yy

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 's_scale': 0, 'theta_E': 0}
-
- -
-
-mass_3d_lens(r, theta_E, e1, e2, s_scale, center_x=0, center_y=0)[source]
-

mass enclosed a 3d radius r. This function assumes spherical symmetry/ignoring the eccentricity.

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • theta_E – Einstein radius

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • s_scale – smoothing scale

  • -
  • center_x – profile center

  • -
  • center_y – profile center

  • -
-
-
Returns
-

3d mass density at 3d radius r

-
-
-
- -
-
-param_conv(theta_E, e1, e2, s_scale)[source]
-
- -
-
-param_names = ['theta_E', 'e1', 'e2', 's_scale', 'center_x', 'center_y']
-
- -
-
-set_dynamic()[source]
-
-
Returns
-

-
-
-
- -
-
-set_static(theta_E, e1, e2, s_scale, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate in image plane

  • -
  • y – y-coordinate in image plane

  • -
  • theta_E – Einstein radius

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • s_scale – smoothing scale

  • -
  • center_x – profile center

  • -
  • center_y – profile center

  • -
-
-
Returns
-

self variables set

-
-
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 's_scale': 100, 'theta_E': 10}
-
- -
- -
-
-class lenstronomy.LensModel.Profiles.nie.NIEMajorAxis(diff=1e-10)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

This class contains the function and the derivatives of the non-singular isothermal ellipse. -See Keeton and Kochanek 1998, https://arxiv.org/pdf/astro-ph/9705194.pdf

-
-\[\kappa = b * (q2(s2 + x2) + y2􏰉)^{−1/2}`\]
-
-
-derivatives(x, y, b, s, q)[source]
-

returns df/dx and df/dy of the function

-
- -
-
-function(x, y, b, s, q)[source]
-

lensing potential

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-hessian(x, y, b, s, q)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
- -
-
-static kappa(x, y, b, s, q)[source]
-

convergence

-
-
Parameters
-
    -
  • x – major axis coordinate

  • -
  • y – minor axis coordinate

  • -
  • b – normalization

  • -
  • s – smoothing scale

  • -
  • q – axis ratio

  • -
-
-
Returns
-

convergence

-
-
-
- -
-
-param_names = ['b', 's', 'q', 'center_x', 'center_y']
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.nie_potential module

-
-
-class lenstronomy.LensModel.Profiles.nie_potential.NIEPotentialMajorAxis(diff=1e-10)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class implements the elliptical potential of Eq. (67) of LECTURES ON GRAVITATIONAL LENSING -and Eq. (1) of Blandford & Kochanek 1987, -mapped to Eq. (8) of Barnaka1998 -to find the ellipticity bounds

-
-
-derivatives(x, y, theta_E, theta_c, eps)[source]
-

returns df/dx and df/dy of the function

-
- -
-
-function(x, y, theta_E, theta_c, eps)[source]
-

lensing potential

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-hessian(x, y, theta_E, theta_c, eps)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
- -
-
-param_names = ['theta_E', 'theta_c', 'eps', 'center_x', 'center_y']
-
- -
- -
-
-class lenstronomy.LensModel.Profiles.nie_potential.NIE_POTENTIAL[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class implements the elliptical potential of Eq. (67) of LECTURES ON GRAVITATIONAL LENSING -and Eq. (1) of Blandford & Kochanek 1987, -mapped to Eq. (8) of Barnaka1998 -to find the ellipticity bounds

-
-
-derivatives(x, y, theta_E, theta_c, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coord (in angles)

  • -
  • y – y-coord (in angles)

  • -
  • theta_E – Einstein radius (in angles)

  • -
  • theta_c – core radius (in angles)

  • -
  • e1 – eccentricity component, x direction(dimensionless)

  • -
  • e2 – eccentricity component, y direction (dimensionless)

  • -
-
-
Returns
-

deflection angle (in angles)

-
-
-
- -
-
-function(x, y, theta_E, theta_c, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coord (in angles)

  • -
  • y – y-coord (in angles)

  • -
  • theta_E – Einstein radius (in angles)

  • -
  • theta_c – core radius (in angles)

  • -
  • e1 – eccentricity component, x direction(dimensionless)

  • -
  • e2 – eccentricity component, y direction (dimensionless)

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, theta_E, theta_c, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coord (in angles)

  • -
  • y – y-coord (in angles)

  • -
  • theta_E – Einstein radius (in angles)

  • -
  • theta_c – core radius (in angles)

  • -
  • e1 – eccentricity component, x direction(dimensionless)

  • -
  • e2 – eccentricity component, y direction (dimensionless)

  • -
-
-
Returns
-

hessian matrix (in angles)

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'e1': 0, 'e2': 0, 'theta_E': 0, 'theta_c': 0}
-
- -
-
-param_conv(theta_E, theta_c, e1, e2)[source]
-
- -
-
-param_names = ['center_x', 'center_y', 'theta_E', 'theta_c', 'e1', 'e2']
-
- -
-
-set_dynamic()[source]
-
-
Returns
-

-
-
-
- -
-
-set_static(theta_E, theta_c, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate in image plane

  • -
  • y – y-coordinate in image plane

  • -
  • theta_E – Einstein radius

  • -
  • theta_c – core radius

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • center_x – profile center

  • -
  • center_y – profile center

  • -
-
-
Returns
-

self variables set

-
-
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'e1': 0.2, 'e2': 0.2, 'theta_E': 10, 'theta_c': 10}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.numerical_deflections module

-
-
-class lenstronomy.LensModel.Profiles.numerical_deflections.NumericalAlpha(custom_class)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

This class allows one to incorporate any lens profile into the usage framework of lenstronomy. When creating the -instance of LensModel with this lens profile, you must pass in numerical_alpha_class = CustomClass(), where -CustomClass is a class with a call method that returns the x/y deflection angles. This allows one to numerically -compute and interpolate deflection angles for potentially very complex mass profiles, and then use the results with -lenstronomy without having to heavily modify the existing structure of the software.

-
-
-derivatives(x, y, center_x=0, center_y=0, **kwargs)[source]
-
-
Parameters
-
    -
  • x – x coordinate [arcsec]

  • -
  • y – x coordinate [arcsec]

  • -
  • center_x – deflector x center [arcsec]

  • -
  • center_y – deflector y center [arcsec]

  • -
  • kwargs – keyword arguments for the custom profile

  • -
-
-
Returns
-

-
-
-
- -
-
-function(x, y, center_x=0, center_y=0, **kwargs)[source]
-

lensing potential

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-hessian(x, y, center_x=0, center_y=0, **kwargs)[source]
-

Returns the components of the hessian matrix -:param x: x coordinate [arcsec] -:param y: y coordinate [arcsec] -:param center_x: the deflector x coordinate -:param center_y: the deflector y coordinate -:param kwargs: keyword arguments for the profile -:return: the derivatives of the deflection angles that make up the hessian matrix

-
- -
- -
-
-

lenstronomy.LensModel.Profiles.p_jaffe module

-
-
-class lenstronomy.LensModel.Profiles.p_jaffe.PJaffe[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class to compute the DUAL PSEUDO ISOTHERMAL ELLIPTICAL MASS DISTRIBUTION -based on Eliasdottir (2007) https://arxiv.org/pdf/0710.5636.pdf Appendix A

-

Module name: ‘PJAFFE’;

-

An alternative name is dPIED.

-

The 3D density distribution is

-
-\[\rho(r) = \frac{\rho_0}{(1+r^2/Ra^2)(1+r^2/Rs^2)}\]
-

with \(Rs > Ra\).

-

The projected density is

-
-\[\Sigma(R) = \Sigma_0 \frac{Ra Rs}{Rs-Ra}\left(\frac{1}{\sqrt{Ra^2+R^2}} - \frac{1}{\sqrt{Rs^2+R^2}} \right)\]
-

with

-
-\[\Sigma_0 = \pi \rho_0 \frac{Ra Rs}{Rs + Ra}\]
-

In the lensing parameterization,

-
-\[\sigma_0 = \frac{\Sigma_0}{\Sigma_{\rm crit}}\]
-
-
-density(r, rho0, Ra, Rs)[source]
-

computes the density

-
-
Parameters
-
    -
  • r – radial distance from the center (in 3D)

  • -
  • rho0 – density normalization (see class documentation above)

  • -
  • Ra – core radius

  • -
  • Rs – transition radius from logarithmic slope -2 to -4

  • -
-
-
Returns
-

density at r

-
-
-
- -
-
-density_2d(x, y, rho0, Ra, Rs, center_x=0, center_y=0)[source]
-

projected density

-
-
Parameters
-
    -
  • x – projected coordinate on the sky

  • -
  • y – projected coordinate on the sky

  • -
  • rho0 – density normalization (see class documentation above)

  • -
  • Ra – core radius

  • -
  • Rs – transition radius from logarithmic slope -2 to -4

  • -
  • center_x – center of profile

  • -
  • center_y – center of profile

  • -
-
-
Returns
-

projected density

-
-
-
- -
-
-derivatives(x, y, sigma0, Ra, Rs, center_x=0, center_y=0)[source]
-

deflection angles

-
-
Parameters
-
    -
  • x – projected coordinate on the sky

  • -
  • y – projected coordinate on the sky

  • -
  • sigma0 – sigma0/sigma_crit (see class documentation above)

  • -
  • Ra – core radius (see class documentation above)

  • -
  • Rs – transition radius from logarithmic slope -2 to -4 (see class documentation above)

  • -
  • center_x – center of profile

  • -
  • center_y – center of profile

  • -
-
-
Returns
-

f_x, f_y

-
-
-
- -
-
-function(x, y, sigma0, Ra, Rs, center_x=0, center_y=0)[source]
-

lensing potential

-
-
Parameters
-
    -
  • x – projected coordinate on the sky

  • -
  • y – projected coordinate on the sky

  • -
  • sigma0 – sigma0/sigma_crit (see class documentation above)

  • -
  • Ra – core radius (see class documentation above)

  • -
  • Rs – transition radius from logarithmic slope -2 to -4 (see class documentation above)

  • -
  • center_x – center of profile

  • -
  • center_y – center of profile

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-grav_pot(r, rho0, Ra, Rs)[source]
-

gravitational potential (modulo 4 pi G and rho0 in appropriate units)

-
-
Parameters
-
    -
  • r – radial distance from the center (in 3D)

  • -
  • rho0 – density normalization (see class documentation above)

  • -
  • Ra – core radius

  • -
  • Rs – transition radius from logarithmic slope -2 to -4

  • -
-
-
Returns
-

gravitational potential (modulo 4 pi G and rho0 in appropriate units)

-
-
-
- -
-
-hessian(x, y, sigma0, Ra, Rs, center_x=0, center_y=0)[source]
-

Hessian of lensing potential

-
-
Parameters
-
    -
  • x – projected coordinate on the sky

  • -
  • y – projected coordinate on the sky

  • -
  • sigma0 – sigma0/sigma_crit (see class documentation above)

  • -
  • Ra – core radius (see class documentation above)

  • -
  • Rs – transition radius from logarithmic slope -2 to -4 (see class documentation above)

  • -
  • center_x – center of profile

  • -
  • center_y – center of profile

  • -
-
-
Returns
-

f_xx, f_xy, f_yx, f_yy

-
-
-
- -
-
-lower_limit_default = {'Ra': 0, 'Rs': 0, 'center_x': -100, 'center_y': -100, 'sigma0': 0}
-
- -
-
-mass_2d(r, rho0, Ra, Rs)[source]
-

mass enclosed projected 2d sphere of radius r

-
-
Parameters
-
    -
  • r – radial distance from the center in projection

  • -
  • rho0 – density normalization (see class documentation above)

  • -
  • Ra – core radius

  • -
  • Rs – transition radius from logarithmic slope -2 to -4

  • -
-
-
Returns
-

Sigma(<r)

-
-
-
- -
-
-mass_3d(r, rho0, Ra, Rs)[source]
-

mass enclosed a 3d sphere or radius r

-
-
Parameters
-
    -
  • r – radial distance from the center (in 3D)

  • -
  • rho0 – density normalization (see class documentation above)

  • -
  • Ra – core radius

  • -
  • Rs – transition radius from logarithmic slope -2 to -4

  • -
-
-
Returns
-

M(<r)

-
-
-
- -
-
-mass_3d_lens(r, sigma0, Ra, Rs)[source]
-

mass enclosed a 3d sphere or radius r given a lens parameterization with angular units

-
-
Parameters
-
    -
  • r – radial distance from the center (in 3D)

  • -
  • sigma0 – density normalization (see class documentation above)

  • -
  • Ra – core radius

  • -
  • Rs – transition radius from logarithmic slope -2 to -4

  • -
-
-
Returns
-

M(<r) in angular units (modulo critical mass density)

-
-
-
- -
-
-mass_tot(rho0, Ra, Rs)[source]
-

total mass within the profile

-
-
Parameters
-
    -
  • rho0 – density normalization (see class documentation above)

  • -
  • Ra – core radius

  • -
  • Rs – transition radius from logarithmic slope -2 to -4

  • -
-
-
Returns
-

total mass

-
-
-
- -
-
-param_names = ['sigma0', 'Ra', 'Rs', 'center_x', 'center_y']
-
- -
-
-rho2sigma(rho0, Ra, Rs)[source]
-

converts 3d density into 2d projected density parameter, Equation A4 in Eliasdottir (2007)

-
-
Parameters
-
    -
  • rho0 – density normalization

  • -
  • Ra – core radius (see class documentation above)

  • -
  • Rs – transition radius from logarithmic slope -2 to -4 (see class documentation above)

  • -
-
-
Returns
-

projected density normalization

-
-
-
- -
-
-sigma2rho(sigma0, Ra, Rs)[source]
-

inverse of rho2sigma()

-
-
Parameters
-
    -
  • sigma0 – projected density normalization

  • -
  • Ra – core radius (see class documentation above)

  • -
  • Rs – transition radius from logarithmic slope -2 to -4 (see class documentation above)

  • -
-
-
Returns
-

3D density normalization

-
-
-
- -
-
-upper_limit_default = {'Ra': 100, 'Rs': 100, 'center_x': 100, 'center_y': 100, 'sigma0': 10}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.p_jaffe_ellipse module

-
-
-class lenstronomy.LensModel.Profiles.p_jaffe_ellipse.PJaffe_Ellipse[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class to compute the DUAL PSEUDO ISOTHERMAL ELLIPTICAL MASS DISTRIBUTION -based on Eliasdottir (2007) https://arxiv.org/pdf/0710.5636.pdf Appendix A -with the ellipticity implemented in the potential

-

Module name: ‘PJAFFE_ELLIPSE’;

-

An alternative name is dPIED.

-

The 3D density distribution is

-
-\[\rho(r) = \frac{\rho_0}{(1+r^2/Ra^2)(1+r^2/Rs^2)}\]
-

with \(Rs > Ra\).

-

The projected density is

-
-\[\Sigma(R) = \Sigma_0 \frac{Ra Rs}{Rs-Ra}\left(\frac{1}{\sqrt{Ra^2+R^2}} - \frac{1}{\sqrt{Rs^2+R^2}} \right)\]
-

with

-
-\[\Sigma_0 = \pi \rho_0 \frac{Ra Rs}{Rs + Ra}\]
-

In the lensing parameterization,

-
-\[\sigma_0 = \frac{\Sigma_0}{\Sigma_{\rm crit}}\]
-
-
-derivatives(x, y, sigma0, Ra, Rs, e1, e2, center_x=0, center_y=0)[source]
-

returns df/dx and df/dy of the function (integral of NFW)

-
- -
-
-function(x, y, sigma0, Ra, Rs, e1, e2, center_x=0, center_y=0)[source]
-

returns double integral of NFW profile

-
- -
-
-hessian(x, y, sigma0, Ra, Rs, e1, e2, center_x=0, center_y=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
- -
-
-lower_limit_default = {'Ra': 0, 'Rs': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'sigma0': 0}
-
- -
-
-mass_3d_lens(r, sigma0, Ra, Rs, e1=0, e2=0)[source]
-
-
Parameters
-
    -
  • r

  • -
  • sigma0

  • -
  • Ra

  • -
  • Rs

  • -
  • e1

  • -
  • e2

  • -
-
-
Returns
-

-
-
-
- -
-
-param_names = ['sigma0', 'Ra', 'Rs', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'Ra': 100, 'Rs': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'sigma0': 10}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.pemd module

-
-
-class lenstronomy.LensModel.Profiles.pemd.PEMD(suppress_fastell=False)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class for power law ellipse mass density profile. -This class effectively calls the class SPEMD_SMOOTH with a fixed and very small central smoothing scale -to perform the numerical integral using the FASTELL code by Renan Barkana.

-
-\[\kappa(x, y) = \frac{3-\gamma}{2} \left(\frac{\theta_{E}}{\sqrt{q x^2 + y^2/q}} \right)^{\gamma-1}\]
-

with \(\theta_{E}\) is the (circularized) Einstein radius, -\(\gamma\) is the negative power-law slope of the 3D mass distributions, -\(q\) is the minor/major axis ratio, -and \(x\) and \(y\) are defined in a coordinate system aligned with the major and minor axis of the lens.

-

In terms of eccentricities, this profile is defined as

-
-\[\kappa(r) = \frac{3-\gamma}{2} \left(\frac{\theta'_{E}}{r \sqrt{1 − e*\cos(2*\phi)}} \right)^{\gamma-1}\]
-

with \(\epsilon\) is the ellipticity defined as

-
-\[\epsilon = \frac{1-q^2}{1+q^2}\]
-

And an Einstein radius \(\theta'_{\rm E}\) related to the definition used is

-
-\[\left(\frac{\theta'_{\rm E}}{\theta_{\rm E}}\right)^{2} = \frac{2q}{1+q^2}.\]
-
-
-density_lens(r, theta_E, gamma, e1=None, e2=None)[source]
-

computes the density at 3d radius r given lens model parameterization. -The integral in the LOS projection of this quantity results in the convergence quantity.

-
-
Parameters
-
    -
  • r – radius within the mass is computed

  • -
  • theta_E – Einstein radius

  • -
  • gamma – power-law slope

  • -
  • e1 – eccentricity component (not used)

  • -
  • e2 – eccentricity component (not used)

  • -
-
-
Returns
-

mass enclosed a 3D radius r

-
-
-
- -
-
-derivatives(x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y-coordinate (angle)

  • -
  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • -
  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • center_x – x-position of lens center

  • -
  • center_y – y-position of lens center

  • -
-
-
Returns
-

deflection angles alpha_x, alpha_y

-
-
-
- -
-
-function(x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y-coordinate (angle)

  • -
  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • -
  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • center_x – x-position of lens center

  • -
  • center_y – y-position of lens center

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y-coordinate (angle)

  • -
  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • -
  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • center_x – x-position of lens center

  • -
  • center_y – y-position of lens center

  • -
-
-
Returns
-

Hessian components f_xx, f_xy, f_yx, f_yy

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'gamma': 1.5, 'theta_E': 0}
-
- -
-
-mass_3d_lens(r, theta_E, gamma, e1=None, e2=None)[source]
-

computes the spherical power-law mass enclosed (with SPP routine) -:param r: radius within the mass is computed -:param theta_E: Einstein radius -:param gamma: power-law slope -:param e1: eccentricity component (not used) -:param e2: eccentricity component (not used) -:return: mass enclosed a 3D radius r

-
- -
-
-param_names = ['theta_E', 'gamma', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'gamma': 2.5, 'theta_E': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.point_mass module

-
-
-class lenstronomy.LensModel.Profiles.point_mass.PointMass[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class to compute the physical deflection angle of a point mass, given as an Einstein radius

-
-
-derivatives(x, y, theta_E, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coord (in angles)

  • -
  • y – y-coord (in angles)

  • -
  • theta_E – Einstein radius (in angles)

  • -
-
-
Returns
-

deflection angle (in angles)

-
-
-
- -
-
-function(x, y, theta_E, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coord (in angles)

  • -
  • y – y-coord (in angles)

  • -
  • theta_E – Einstein radius (in angles)

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, theta_E, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coord (in angles)

  • -
  • y – y-coord (in angles)

  • -
  • theta_E – Einstein radius (in angles)

  • -
-
-
Returns
-

hessian matrix (in angles)

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'theta_E': 0}
-
- -
-
-param_names = ['theta_E', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'theta_E': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.sersic module

-
-
-class lenstronomy.LensModel.Profiles.sersic.Sersic(smoothing=1e-05, sersic_major_axis=False)[source]
-

Bases: lenstronomy.LensModel.Profiles.sersic_utils.SersicUtil, lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class contains functions to evaluate a Sersic mass profile: https://arxiv.org/pdf/astro-ph/0311559.pdf

-
-
-derivatives(x, y, n_sersic, R_sersic, k_eff, center_x=0, center_y=0)[source]
-

returns df/dx and df/dy of the function

-
- -
-
-function(x, y, n_sersic, R_sersic, k_eff, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate

  • -
  • y – y-coordinate

  • -
  • n_sersic – Sersic index

  • -
  • R_sersic – half light radius

  • -
  • k_eff – convergence at half light radius

  • -
  • center_x – x-center

  • -
  • center_y – y-center

  • -
-
-
Returns
-

-
-
-
- -
-
-hessian(x, y, n_sersic, R_sersic, k_eff, center_x=0, center_y=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
- -
-
-lower_limit_default = {'R_sersic': 0, 'center_x': -100, 'center_y': -100, 'k_eff': 0, 'n_sersic': 0.5}
-
- -
-
-param_names = ['k_eff', 'R_sersic', 'n_sersic', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'R_sersic': 100, 'center_x': 100, 'center_y': 100, 'k_eff': 10, 'n_sersic': 8}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.sersic_ellipse_kappa module

-
-
-class lenstronomy.LensModel.Profiles.sersic_ellipse_kappa.SersicEllipseKappa[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class contains the function and the derivatives of an elliptical sersic profile -with the ellipticity introduced in the convergence (not the potential).

-

This requires the use of numerical integrals (Keeton 2004)

-
-
-derivatives(x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y=0)[source]
-

deflection angles

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-function(x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y=0)[source]
-

lensing potential

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-hessian(x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
- -
-
-lower_limit_default = {'R_sersic': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'k_eff': 0, 'n_sersic': 0.5}
-
- -
-
-param_names = ['k_eff', 'R_sersic', 'n_sersic', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-projected_mass(x, y, q, n_sersic, R_sersic, k_eff, u=1, power=1)[source]
-
- -
-
-upper_limit_default = {'R_sersic': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'k_eff': 10, 'n_sersic': 8}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.sersic_ellipse_potential module

-
-
-class lenstronomy.LensModel.Profiles.sersic_ellipse_potential.SersicEllipse[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class contains functions to evaluate a Sersic mass profile: https://arxiv.org/pdf/astro-ph/0311559.pdf

-
-
-derivatives(x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y=0)[source]
-

returns df/dx and df/dy of the function

-
- -
-
-function(x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y=0)[source]
-

returns Gaussian

-
- -
-
-hessian(x, y, n_sersic, R_sersic, k_eff, e1, e2, center_x=0, center_y=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
- -
-
-lower_limit_default = {'R_sersic': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'k_eff': 0, 'n_sersic': 0.5}
-
- -
-
-param_names = ['k_eff', 'R_sersic', 'n_sersic', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'R_sersic': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'k_eff': 10, 'n_sersic': 8}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.sersic_utils module

-
-
-class lenstronomy.LensModel.Profiles.sersic_utils.SersicUtil(smoothing=1e-05, sersic_major_axis=False)[source]
-

Bases: object

-
-
-alpha_abs(x, y, n_sersic, r_eff, k_eff, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • n_sersic

  • -
  • r_eff

  • -
  • k_eff

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-static b_n(n)[source]
-

b(n) computation. This is the approximation of the exact solution to the relation, 2*incomplete_gamma_function(2n; b_n) = Gamma_function(2*n). -:param n: the sersic index -:return:

-
- -
-
-d_alpha_dr(x, y, n_sersic, r_eff, k_eff, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • n_sersic

  • -
  • r_eff

  • -
  • k_eff

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-density(x, y, n_sersic, r_eff, k_eff, center_x=0, center_y=0)[source]
-

de-projection of the Sersic profile based on -Prugniel & Simien (1997) -:return:

-
- -
-
-get_distance_from_center(x, y, e1, e2, center_x, center_y)[source]
-

Get the distance from the center of Sersic, accounting for orientation and axis ratio -:param x: -:param y: -:param e1: eccentricity -:param e2: eccentricity -:param center_x: center x of sersic -:param center_y: center y of sersic

-
- -
-
-k_Re(n, k)[source]
-
- -
-
-k_bn(n, Re)[source]
-

returns normalisation of the sersic profile such that Re is the half light radius given n_sersic slope

-
- -
-
-total_flux(amp, R_sersic, n_sersic, e1=0, e2=0, **kwargs)[source]
-

computes analytical integral to compute total flux of the Sersic profile

-
-
Parameters
-
    -
  • amp – amplitude parameter in Sersic function (surface brightness at R_sersic

  • -
  • R_sersic – half-light radius in semi-major axis

  • -
  • n_sersic – Sersic index

  • -
  • e1 – eccentricity

  • -
  • e2 – eccentricity

  • -
-
-
Returns
-

Analytic integral of the total flux of the Sersic profile

-
-
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.shapelet_pot_cartesian module

-
-
-class lenstronomy.LensModel.Profiles.shapelet_pot_cartesian.CartShapelets(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class contains the function and the derivatives of the cartesian shapelets

-
-
-H_n(n, x)[source]
-

constructs the Hermite polynomial of order n at position x (dimensionless)

-
-
Parameters
-
    -
  • n – The n’the basis function.

  • -
  • x – 1-dim position (dimensionless)

  • -
-
-
Returns
-

array– H_n(x).

-
-
Raises
-

AttributeError, KeyError

-
-
-
- -
-
-derivatives(x, y, coeffs, beta, center_x=0, center_y=0)[source]
-

returns df/dx and df/dy of the function

-
- -
-
-function(x, y, coeffs, beta, center_x=0, center_y=0)[source]
-

lensing potential

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-hessian(x, y, coeffs, beta, center_x=0, center_y=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
- -
-
-lower_limit_default = {'beta': 0, 'center_x': -100, 'center_y': -100, 'coeffs': [0]}
-
- -
-
-param_names = ['coeffs', 'beta', 'center_x', 'center_y']
-
- -
-
-phi_n(n, x)[source]
-

constructs the 1-dim basis function (formula (1) in Refregier et al. 2001)

-
-
Parameters
-
    -
  • n – The n’the basis function.

  • -
  • x – 1-dim position (dimensionless)

  • -
-
-
Returns
-

array– phi_n(x).

-
-
Raises
-

AttributeError, KeyError

-
-
-
- -
-
-pre_calc(x, y, beta, n_order, center_x, center_y)[source]
-

calculates the H_n(x) and H_n(y) for a given x-array and y-array -:param x: -:param y: -:param amp: -:param beta: -:param n_order: -:param center_x: -:param center_y: -:return: list of H_n(x) and H_n(y)

-
- -
-
-upper_limit_default = {'beta': 100, 'center_x': 100, 'center_y': 100, 'coeffs': [100]}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.shapelet_pot_polar module

-
-
-class lenstronomy.LensModel.Profiles.shapelet_pot_polar.PolarShapelets[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class contains the function and the derivatives of the Singular Isothermal Sphere

-
-
-derivatives(x, y, coeffs, beta, center_x=0, center_y=0)[source]
-

returns df/dx and df/dy of the function

-
- -
-
-function(x, y, coeffs, beta, center_x=0, center_y=0)[source]
-

lensing potential

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-hessian(x, y, coeffs, beta, center_x=0, center_y=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
- -
-
-lower_limit_default = {'beta': 0, 'center_x': -100, 'center_y': -100, 'coeffs': [0]}
-
- -
-
-param_names = ['coeffs', 'beta', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'beta': 100, 'center_x': 100, 'center_y': 100, 'coeffs': [100]}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.shear module

-
-
-class lenstronomy.LensModel.Profiles.shear.Shear(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class for external shear gamma1, gamma2 expression

-
-
-derivatives(x, y, gamma1, gamma2, ra_0=0, dec_0=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y0-coordinate (angle)

  • -
  • gamma1 – shear component

  • -
  • gamma2 – shear component

  • -
  • ra_0 – x/ra position where shear deflection is 0

  • -
  • dec_0 – y/dec position where shear deflection is 0

  • -
-
-
Returns
-

deflection angles

-
-
-
- -
-
-function(x, y, gamma1, gamma2, ra_0=0, dec_0=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y0-coordinate (angle)

  • -
  • gamma1 – shear component

  • -
  • gamma2 – shear component

  • -
  • ra_0 – x/ra position where shear deflection is 0

  • -
  • dec_0 – y/dec position where shear deflection is 0

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, gamma1, gamma2, ra_0=0, dec_0=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y0-coordinate (angle)

  • -
  • gamma1 – shear component

  • -
  • gamma2 – shear component

  • -
  • ra_0 – x/ra position where shear deflection is 0

  • -
  • dec_0 – y/dec position where shear deflection is 0

  • -
-
-
Returns
-

f_xx, f_xy, f_yx, f_yy

-
-
-
- -
-
-lower_limit_default = {'dec_0': -100, 'gamma1': -0.5, 'gamma2': -0.5, 'ra_0': -100}
-
- -
-
-param_names = ['gamma1', 'gamma2', 'ra_0', 'dec_0']
-
- -
-
-upper_limit_default = {'dec_0': 100, 'gamma1': 0.5, 'gamma2': 0.5, 'ra_0': 100}
-
- -
- -
-
-class lenstronomy.LensModel.Profiles.shear.ShearGammaPsi[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class to model a shear field with shear strength and direction. The translation ot the cartesian shear distortions -is as follow:

-
-\[\gamma_1 = \gamma_{ext} \cos(2 \phi_{ext} -\gamma_2 = \gamma_{ext} \sin(2 \phi_{ext}\]
-
-
-derivatives(x, y, gamma_ext, psi_ext, ra_0=0, dec_0=0)[source]
-

deflection angles

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-static function(x, y, gamma_ext, psi_ext, ra_0=0, dec_0=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y0-coordinate (angle)

  • -
  • gamma_ext – shear strength

  • -
  • psi_ext – shear angle (radian)

  • -
  • ra_0 – x/ra position where shear deflection is 0

  • -
  • dec_0 – y/dec position where shear deflection is 0

  • -
-
-
Returns
-

-
-
-
- -
-
-hessian(x, y, gamma_ext, psi_ext, ra_0=0, dec_0=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-lower_limit_default = {'dec_0': -100, 'gamma_ext': 0, 'psi_ext': -3.141592653589793, 'ra_0': -100}
-
- -
-
-param_names = ['gamma_ext', 'psi_ext', 'ra_0', 'dec_0']
-
- -
-
-upper_limit_default = {'dec_0': 100, 'gamma_ext': 1, 'psi_ext': 3.141592653589793, 'ra_0': 100}
-
- -
- -
-
-class lenstronomy.LensModel.Profiles.shear.ShearReduced[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

reduced shear distortions \(\gamma' = \gamma / (1-\kappa)\). -This distortion keeps the magnification as unity and, thus, does not change the size of apparent objects. -To keep the magnification at unity, it requires

-
-\[(1-\kappa)^2 - \gamma_1^2 - \gamma_2^ = 1\]
-

Thus, for given pair of reduced shear \((\gamma'_1, \gamma'_2)\), an additional convergence term is calculated -and added to the lensing distortions.

-
-
-derivatives(x, y, gamma1, gamma2, ra_0=0, dec_0=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y0-coordinate (angle)

  • -
  • gamma1 – shear component

  • -
  • gamma2 – shear component

  • -
  • ra_0 – x/ra position where shear deflection is 0

  • -
  • dec_0 – y/dec position where shear deflection is 0

  • -
-
-
Returns
-

deflection angles

-
-
-
- -
-
-function(x, y, gamma1, gamma2, ra_0=0, dec_0=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y0-coordinate (angle)

  • -
  • gamma1 – shear component

  • -
  • gamma2 – shear component

  • -
  • ra_0 – x/ra position where shear deflection is 0

  • -
  • dec_0 – y/dec position where shear deflection is 0

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, gamma1, gamma2, ra_0=0, dec_0=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y0-coordinate (angle)

  • -
  • gamma1 – shear component

  • -
  • gamma2 – shear component

  • -
  • ra_0 – x/ra position where shear deflection is 0

  • -
  • dec_0 – y/dec position where shear deflection is 0

  • -
-
-
Returns
-

f_xx, f_xy, f_yx, f_yy

-
-
-
- -
-
-lower_limit_default = {'dec_0': -100, 'gamma1': -0.5, 'gamma2': -0.5, 'ra_0': -100}
-
- -
-
-param_names = ['gamma1', 'gamma2', 'ra_0', 'dec_0']
-
- -
-
-upper_limit_default = {'dec_0': 100, 'gamma1': 0.5, 'gamma2': 0.5, 'ra_0': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.sie module

-
-
-class lenstronomy.LensModel.Profiles.sie.SIE(NIE=True)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class for singular isothermal ellipsoid (SIS with ellipticity)

-
-\[\kappa(x, y) = \frac{1}{2} \left(\frac{\theta_{E}}{\sqrt{q x^2 + y^2/q}} \right)\]
-

with \(\theta_{E}\) is the (circularized) Einstein radius, -\(q\) is the minor/major axis ratio, -and \(x\) and \(y\) are defined in a coordinate sys- tem aligned with the major and minor axis of the lens.

-

In terms of eccentricities, this profile is defined as

-
-\[\kappa(r) = \frac{1}{2} \left(\frac{\theta'_{E}}{r \sqrt{1 − e*\cos(2*\phi)}} \right)\]
-

with \(\epsilon\) is the ellipticity defined as

-
-\[\epsilon = \frac{1-q^2}{1+q^2}\]
-

And an Einstein radius \(\theta'_{\rm E}\) related to the definition used is

-
-\[\left(\frac{\theta'_{\rm E}}{\theta_{\rm E}}\right)^{2} = \frac{2q}{1+q^2}.\]
-
-
-static density(r, rho0, e1=0, e2=0)[source]
-

computes the density -:param r: radius in angles -:param rho0: density at angle=1 -:return: density at r

-
- -
-
-static density_2d(x, y, rho0, e1=0, e2=0, center_x=0, center_y=0)[source]
-

projected density -:param x: -:param y: -:param rho0: -:param center_x: -:param center_y: -:return:

-
- -
-
-density_lens(r, theta_E, e1=0, e2=0)[source]
-

computes the density at 3d radius r given lens model parameterization. -The integral in the LOS projection of this quantity results in the convergence quantity.

-
-
Parameters
-
    -
  • r – radius in angles

  • -
  • theta_E – Einstein radius

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
-
-
Returns
-

density

-
-
-
- -
-
-derivatives(x, y, theta_E, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • theta_E

  • -
  • q

  • -
  • phi_G

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-function(x, y, theta_E, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • theta_E

  • -
  • q

  • -
  • phi_G

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-grav_pot(x, y, rho0, e1=0, e2=0, center_x=0, center_y=0)[source]
-

gravitational potential (modulo 4 pi G and rho0 in appropriate units) -:param x: -:param y: -:param rho0: -:param a: -:param s: -:param center_x: -:param center_y: -:return:

-
- -
-
-hessian(x, y, theta_E, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • theta_E

  • -
  • q

  • -
  • phi_G

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'theta_E': 0}
-
- -
-
-mass_2d(r, rho0, e1=0, e2=0)[source]
-

mass enclosed projected 2d sphere of radius r -:param r: -:param rho0: -:param a: -:param s: -:return:

-
- -
-
-mass_2d_lens(r, theta_E, e1=0, e2=0)[source]
-
-
Parameters
-
    -
  • r

  • -
  • theta_E

  • -
-
-
Returns
-

-
-
-
- -
-
-static mass_3d(r, rho0, e1=0, e2=0)[source]
-

mass enclosed a 3d sphere or radius r -:param r: radius in angular units -:param rho0: density at angle=1 -:return: mass in angular units

-
- -
-
-mass_3d_lens(r, theta_E, e1=0, e2=0)[source]
-

mass enclosed a 3d sphere or radius r given a lens parameterization with angular units

-
-
Parameters
-
    -
  • r – radius in angular units

  • -
  • theta_E – Einstein radius

  • -
-
-
Returns
-

mass in angular units

-
-
-
- -
-
-param_names = ['theta_E', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-static theta2rho(theta_E)[source]
-

converts projected density parameter (in units of deflection) into 3d density parameter -:param theta_E: -:return:

-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'theta_E': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.sis module

-
-
-class lenstronomy.LensModel.Profiles.sis.SIS(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class contains the function and the derivatives of the Singular Isothermal Sphere

-
-\[\kappa(x, y) = \frac{1}{2} \left(\frac{\theta_{E}}{\sqrt{x^2 + y^2}} \right)\]
-

with \(\theta_{E}\) is the Einstein radius,

-
-
-static density(r, rho0)[source]
-

computes the density -:param r: radius in angles -:param rho0: density at angle=1 -:return: density at r

-
- -
-
-static density_2d(x, y, rho0, center_x=0, center_y=0)[source]
-

projected density -:param x: -:param y: -:param rho0: -:param center_x: -:param center_y: -:return:

-
- -
-
-density_lens(r, theta_E)[source]
-

computes the density at 3d radius r given lens model parameterization. -The integral in projected in units of angles (i.e. arc seconds) results in the convergence quantity.

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • theta_E – Einstein radius

  • -
-
-
Returns
-

density(r)

-
-
-
- -
-
-derivatives(x, y, theta_E, center_x=0, center_y=0)[source]
-

returns df/dx and df/dy of the function

-
- -
-
-function(x, y, theta_E, center_x=0, center_y=0)[source]
-

lensing potential

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-grav_pot(x, y, rho0, center_x=0, center_y=0)[source]
-

gravitational potential (modulo 4 pi G and rho0 in appropriate units) -:param x: -:param y: -:param rho0: -:param center_x: -:param center_y: -:return:

-
- -
-
-hessian(x, y, theta_E, center_x=0, center_y=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'theta_E': 0}
-
- -
-
-static mass_2d(r, rho0)[source]
-

mass enclosed projected 2d sphere of radius r -:param r: -:param rho0: -:return:

-
- -
-
-mass_2d_lens(r, theta_E)[source]
-
-
Parameters
-
    -
  • r – radius

  • -
  • theta_E – Einstein radius

  • -
-
-
Returns
-

mass within a radius in projection

-
-
-
- -
-
-static mass_3d(r, rho0)[source]
-

mass enclosed a 3d sphere or radius r -:param r: radius in angular units -:param rho0: density at angle=1 -:return: mass in angular units

-
- -
-
-mass_3d_lens(r, theta_E)[source]
-

mass enclosed a 3d sphere or radius r given a lens parameterization with angular units

-
-
Parameters
-
    -
  • r – radius in angular units

  • -
  • theta_E – Einstein radius

  • -
-
-
Returns
-

mass in angular units

-
-
-
- -
-
-param_names = ['theta_E', 'center_x', 'center_y']
-
- -
-
-static rho2theta(rho0)[source]
-

converts 3d density into 2d projected density parameter -:param rho0: -:return:

-
- -
-
-static theta2rho(theta_E)[source]
-

converts projected density parameter (in units of deflection) into 3d density parameter -:param theta_E: -:return:

-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'theta_E': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.sis_truncate module

-
-
-class lenstronomy.LensModel.Profiles.sis_truncate.SIS_truncate(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class contains the function and the derivatives of the Singular Isothermal Sphere

-
-
-derivatives(x, y, theta_E, r_trunc, center_x=0, center_y=0)[source]
-

returns df/dx and df/dy of the function

-
- -
-
-function(x, y, theta_E, r_trunc, center_x=0, center_y=0)[source]
-

lensing potential

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-hessian(x, y, theta_E, r_trunc, center_x=0, center_y=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'r_trunc': 0, 'theta_E': 0}
-
- -
-
-param_names = ['theta_E', 'r_trunc', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'r_trunc': 100, 'theta_E': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.spemd module

-
-
-class lenstronomy.LensModel.Profiles.spemd.SPEMD(suppress_fastell=False)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class for smooth power law ellipse mass density profile (SPEMD). This class effectively performs the FASTELL calculations -by Renan Barkana. The parameters are changed and represent a spherically averaged Einstein radius an a logarithmic -3D mass profile slope.

-

The SPEMD mass profile is defined as follow:

-
-\[\kappa(x, y) = \frac{3-\gamma}{2} \left(\frac{\theta_{E}}{\sqrt{q x^2 + y^2/q + s^2}} \right)^{\gamma-1}\]
-

with \(\theta_{E}\) is the (circularized) Einstein radius, -\(\gamma\) is the negative power-law slope of the 3D mass distributions, \(q\) is the minor/major axis ratio, -and \(x\) and \(y\) are defined in a coordinate system aligned with the major and minor axis of the lens.

-

the FASTELL definitions are as follows:

-

The parameters are position \((x1,x2)\), overall factor -(\(b\)), power (gam), axis ratio (arat) which is <=1, core radius -squared (\(s2\)), and the output potential (\(\phi\)). -The projected mass density distribution, in units of the -critical density, is

-
-\[\kappa(x1,x2)=b_{fastell} \left[u2+s2\right]^{-gam},\]
-

with \(u2=\left[x1^2+x2^2/(arat^2)\right]\).

-

The conversion from lenstronomy definitions of this class to FASTELL are:

-
-\[q_{fastell} \equiv q_{lenstronomy}\]
-
-\[gam \equiv (\gamma-1)/2\]
-
-\[b_{fastell} \equiv (3-\gamma)/2. * \left(\theta_{E}^2 / q\right)^{gam}\]
-
-\[s2_{fastell} = s_{lenstronomy}^2 * q\]
-
-
-static convert_params(theta_E, gamma, q, s_scale)[source]
-

converts parameter definitions into quantities used by the FASTELL fortran library

-
-
Parameters
-
    -
  • theta_E – Einstein radius

  • -
  • gamma – 3D power-law slope of mass profile

  • -
  • q – axis ratio minor/major

  • -
  • s_scale – float, smoothing scale in the core

  • -
-
-
Returns
-

pre-factors to SPEMP profile for FASTELL

-
-
-
- -
-
-derivatives(x, y, theta_E, gamma, e1, e2, s_scale, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y-coordinate (angle)

  • -
  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • -
  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • s_scale – smoothing scale in the center of the profile

  • -
  • center_x – x-position of lens center

  • -
  • center_y – y-position of lens center

  • -
-
-
Returns
-

deflection angles alpha_x, alpha_y

-
-
-
- -
-
-function(x, y, theta_E, gamma, e1, e2, s_scale, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y-coordinate (angle)

  • -
  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • -
  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • s_scale – smoothing scale in the center of the profile (angle)

  • -
  • center_x – x-position of lens center

  • -
  • center_y – y-position of lens center

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, theta_E, gamma, e1, e2, s_scale, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y-coordinate (angle)

  • -
  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • -
  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • s_scale – smoothing scale in the center of the profile

  • -
  • center_x – x-position of lens center

  • -
  • center_y – y-position of lens center

  • -
-
-
Returns
-

Hessian components f_xx, f_xy, f_yx, f_yy

-
-
-
- -
-
-static is_not_empty(x1, x2)[source]
-

Check if float or not an empty array -:return: True if x1 and x2 are either floats/ints or an non-empty array, False if e.g. objects are [] -:rtype: bool

-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'gamma': 0, 's_scale': 0, 'theta_E': 0}
-
- -
-
-param_names = ['theta_E', 'gamma', 'e1', 'e2', 's_scale', 'center_x', 'center_y']
-
- -
-
-param_transform(x, y, theta_E, gamma, e1, e2, s_scale, center_x=0, center_y=0)[source]
-

transforms parameters in the format of fastell4py

-
-
Parameters
-
    -
  • x – x-coordinate (angle)

  • -
  • y – y-coordinate (angle)

  • -
  • theta_E – Einstein radius (angle), pay attention to specific definition!

  • -
  • gamma – logarithmic slope of the power-law profile. gamma=2 corresponds to isothermal

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • s_scale – smoothing scale in the center of the profile

  • -
  • center_x – x-position of lens center

  • -
  • center_y – y-position of lens center

  • -
-
-
Returns
-

x-rotated, y-rotated, q_fastell, gam, s2, q, phi_G

-
-
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'gamma': 100, 's_scale': 100, 'theta_E': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.spep module

-
-
-class lenstronomy.LensModel.Profiles.spep.SPEP[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class for Softened power-law elliptical potential (SPEP)

-
-
-density_lens(r, theta_E, gamma, e1=None, e2=None)[source]
-

computes the density at 3d radius r given lens model parameterization. -The integral in the LOS projection of this quantity results in the convergence quantity.

-
-
Parameters
-
    -
  • r – radius within the mass is computed

  • -
  • theta_E – Einstein radius

  • -
  • gamma – power-law slope

  • -
  • e1 – eccentricity component (not used)

  • -
  • e2 – eccentricity component (not used)

  • -
-
-
Returns
-

mass enclosed a 3D radius r

-
-
-
- -
-
-derivatives(x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
-

deflection angles

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-function(x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x (array of size (n)) – set of x-coordinates

  • -
  • theta_E (float.) – Einstein radius of lense

  • -
  • gamma (<2 float) – power law slope of mass profifle

  • -
  • q (0<phi_G<pi/2) – Axis ratio

  • -
  • phi_G – position angel of SES

  • -
-
-
Returns
-

function

-
-
Raises
-

AttributeError, KeyError

-
-
-
- -
-
-hessian(x, y, theta_E, gamma, e1, e2, center_x=0, center_y=0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'gamma': 0, 'theta_E': 0}
-
- -
-
-mass_3d_lens(r, theta_E, gamma, e1=None, e2=None)[source]
-

computes the spherical power-law mass enclosed (with SPP routine) -:param r: radius within the mass is computed -:param theta_E: Einstein radius -:param gamma: power-law slope -:param e1: eccentricity component (not used) -:param e2: eccentricity component (not used) -:return: mass enclosed a 3D radius r

-
- -
-
-param_names = ['theta_E', 'gamma', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'gamma': 100, 'theta_E': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.splcore module

-
-
-class lenstronomy.LensModel.Profiles.splcore.SPLCORE(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

This lens profile corresponds to a spherical power law (SPL) mass distribution with logarithmic slope gamma and -a 3D core radius r_core

-
-\[\rho\left(r, \rho_0, r_c, \gamma\right) = \rho_0 -\frac{{r_c}^\gamma}{\left(r^2 + r_c^2\right)^{\frac{\gamma}{2}}}\]
-

The difference between this and EPL is that this model contains a core radius, is circular, -and is also defined for gamma=3.

-

With respect to SPEMD, this model is different in that it is also defined for gamma = 3, is circular, and is defined -in terms of a physical density parameter rho0, or the central density at r=0 divided by the critical density for -lensing such that rho0 has units 1/arcsec.

-

This class is defined for all gamma > 1

-
-
-alpha(r, sigma0, r_core, gamma)[source]
-

Returns the deflection angle at r -:param r: radius [arcsec] -:param sigma0: convergence at r=0 -:param r_core: core radius [arcsec] -:param gamma: logarithmic slope at r -> infinity -:return: deflection angle at r

-
- -
-
-static density(r, rho0, r_core, gamma)[source]
-

Returns the 3D density at r -:param r: radius [arcsec] -:param rho0: convergence at r=0 -:param r_core: core radius [arcsec] -:param gamma: logarithmic slope at r -> infinity -:return: density at r

-
- -
-
-density_2d(x, y, rho0, r_core, gamma)[source]
-

Returns the convergence at radius r -:param x: x position [arcsec] -:param y: y position [arcsec] -:param rho0: convergence at r=0 -:param r_core: core radius [arcsec] -:param gamma: logarithmic slope at r -> infinity -:return: convergence at r

-
- -
-
-density_lens(r, sigma0, r_core, gamma)[source]
-

Returns the 3D density at r -:param r: radius [arcsec] -:param sigma0: convergence at r=0 -:param r_core: core radius [arcsec] -:param gamma: logarithmic slope at r -> infinity -:return: density at r

-
- -
-
-derivatives(x, y, sigma0, r_core, gamma, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – projected x position at which to evaluate function [arcsec]

  • -
  • y – projected y position at which to evaluate function [arcsec]

  • -
  • sigma0 – convergence at r = 0

  • -
  • r_core – core radius [arcsec]

  • -
  • gamma – logarithmic slope at r -> infinity

  • -
  • center_x – x coordinate center of lens model [arcsec]

  • -
  • center_y – y coordinate center of lens model [arcsec]

  • -
-
-
Returns
-

deflection angle alpha in x and y directions

-
-
-
- -
-
-function(x, y, sigma0, r_core, gamma, center_x=0, center_y=0)[source]
-

lensing potential

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-hessian(x, y, sigma0, r_core, gamma, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – projected x position at which to evaluate function [arcsec]

  • -
  • y – projected y position at which to evaluate function [arcsec]

  • -
  • sigma0 – convergence at r = 0

  • -
  • r_core – core radius [arcsec]

  • -
  • gamma – logarithmic slope at r -> infinity

  • -
  • center_x – x coordinate center of lens model [arcsec]

  • -
  • center_y – y coordinate center of lens model [arcsec]

  • -
-
-
Returns
-

hessian elements

-
-
-

alpha_(x/y) = alpha_r * cos/sin(x/y / r)

-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'gamma': 1.000001, 'r_core': 1e-06, 'sigma0': 0}
-
- -
-
-mass_2d(r, rho0, r_core, gamma)[source]
-

mass enclosed projected 2d disk of radius r -:param r: radius [arcsec] -:param rho0: density at r = 0 in units [rho_0_physical / sigma_crit] (which should be equal to [1/arcsec]) -where rho_0_physical is a physical density normalization and sigma_crit is the critical density for lensing -:param r_core: core radius [arcsec] -:param gamma: logarithmic slope at r -> infinity -:return: projected mass inside disk of radius r

-
- -
-
-mass_2d_lens(r, sigma0, r_core, gamma)[source]
-

mass enclosed projected 2d disk of radius r -:param r: radius [arcsec] -:param sigma0: convergence at r = 0 -where rho_0_physical is a physical density normalization and sigma_crit is the critical density for lensing -:param r_core: core radius [arcsec] -:param gamma: logarithmic slope at r -> infinity -:return: projected mass inside disk of radius r

-
- -
-
-mass_3d(r, rho0, r_core, gamma)[source]
-

mass enclosed a 3d sphere or radius r -:param r: radius [arcsec] -:param rho0: density at r = 0 in units [rho_0_physical / sigma_crit] (which should be equal to [arcsec]) -where rho_0_physical is a physical density normalization and sigma_crit is the critical density for lensing -:param r_core: core radius [arcsec] -:param gamma: logarithmic slope at r -> infinity -:return: mass inside radius r

-
- -
-
-mass_3d_lens(r, sigma0, r_core, gamma)[source]
-

mass enclosed a 3d sphere or radius r -:param r: radius [arcsec] -:param sigma0: convergence at r = 0 -:param r_core: core radius [arcsec] -:param gamma: logarithmic slope at r -> infinity -:return: mass inside radius r

-
- -
-
-param_names = ['sigma0', 'center_x', 'center_y', 'r_core', 'gamma']
-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'gamma': 5.0, 'r_core': 100, 'sigma0': 1000000000000.0}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.spp module

-
-
-class lenstronomy.LensModel.Profiles.spp.SPP(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

class for circular power-law mass distribution

-
-
-static density(r, rho0, gamma)[source]
-

computes the density -:param x: -:param y: -:param rho0: -:param a: -:param s: -:return:

-
- -
-
-static density_2d(x, y, rho0, gamma, center_x=0, center_y=0)[source]
-

projected density -:param x: -:param y: -:param rho0: -:param a: -:param s: -:param center_x: -:param center_y: -:return:

-
- -
-
-density_lens(r, theta_E, gamma)[source]
-

computes the density at 3d radius r given lens model parameterization. -The integral in projected in units of angles (i.e. arc seconds) results in the convergence quantity.

-
- -
-
-derivatives(x, y, theta_E, gamma, center_x=0.0, center_y=0.0)[source]
-

deflection angles

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-function(x, y, theta_E, gamma, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x (array of size (n)) – set of x-coordinates

  • -
  • theta_E (float.) – Einstein radius of lens

  • -
  • gamma (<2 float) – power law slope of mass profile

  • -
-
-
Returns
-

function

-
-
Raises
-

AttributeError, KeyError

-
-
-
- -
-
-grav_pot(x, y, rho0, gamma, center_x=0, center_y=0)[source]
-

gravitational potential (modulo 4 pi G and rho0 in appropriate units) -:param x: -:param y: -:param rho0: -:param a: -:param s: -:param center_x: -:param center_y: -:return:

-
- -
-
-hessian(x, y, theta_E, gamma, center_x=0.0, center_y=0.0)[source]
-

returns Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
-
Parameters
-

kwargs – keywords of the profile

-
-
Returns
-

raise as definition is not defined

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'gamma': 1.5, 'theta_E': 0}
-
- -
-
-mass_2d(r, rho0, gamma)[source]
-

mass enclosed projected 2d sphere of radius r -:param r: -:param rho0: -:param a: -:param s: -:return:

-
- -
-
-mass_2d_lens(r, theta_E, gamma)[source]
-
-
Parameters
-
    -
  • r – projected radius

  • -
  • theta_E – Einstein radius

  • -
  • gamma – power-law slope

  • -
-
-
Returns
-

2d projected radius enclosed

-
-
-
- -
-
-static mass_3d(r, rho0, gamma)[source]
-

mass enclosed a 3d sphere or radius r -:param r: -:param a: -:param s: -:return:

-
- -
-
-mass_3d_lens(r, theta_E, gamma)[source]
-
-
Parameters
-
    -
  • r

  • -
  • theta_E

  • -
  • gamma

  • -
-
-
Returns
-

-
-
-
- -
-
-param_names = ['theta_E', 'gamma', 'center_x', 'center_y']
-
- -
-
-static rho2theta(rho0, gamma)[source]
-

converts 3d density into 2d projected density parameter -:param rho0: -:param gamma: -:return:

-
- -
-
-static theta2rho(theta_E, gamma)[source]
-

converts projected density parameter (in units of deflection) into 3d density parameter -:param theta_E: -:param gamma: -:return:

-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'gamma': 2.5, 'theta_E': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.tnfw module

-
-
-class lenstronomy.LensModel.Profiles.tnfw.TNFW[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

this class contains functions concerning the truncated NFW profile with a truncation function (r_trunc^2)*(r^2+r_trunc^2)

-

density equation is:

-
-\[\rho(r) = \frac{r_\text{trunc}^2}{r^2+r_\text{trunc}^2}\frac{\rho_0(\alpha_{R_s})}{r/R_s(1+r/R_s)^2}\]
-

relation are: R_200 = c * Rs

-
-
-F(x)[source]
-

Classic NFW function in terms of arctanh and arctan -:param x: r/Rs -:return:

-
- -
-
-static alpha2rho0(alpha_Rs, Rs)[source]
-

convert angle at Rs into rho0; neglects the truncation

-
-
Parameters
-
    -
  • alpha_Rs – deflection angle at RS

  • -
  • Rs – scale radius

  • -
-
-
Returns
-

density normalization (characteristic density)

-
-
-
- -
-
-static density(r, Rs, rho0, r_trunc)[source]
-

three dimensional truncated NFW profile

-
-
Parameters
-
    -
  • r (float/numpy array) – radius of interest

  • -
  • Rs (float > 0) – scale radius

  • -
  • r_trunc (float > 0) – truncation radius (angular units)

  • -
-
-
Returns
-

rho(r) density

-
-
-
- -
-
-density_2d(x, y, Rs, rho0, r_trunc, center_x=0, center_y=0)[source]
-

projected two dimensional NFW profile (kappa*Sigma_crit)

-
-
Parameters
-
    -
  • R (float/numpy array) – projected radius of interest

  • -
  • Rs (float) – scale radius

  • -
  • rho0 (float) – density normalization (characteristic density)

  • -
  • r_trunc (float > 0) – truncation radius (angular units)

  • -
-
-
Returns
-

Epsilon(R) projected density at radius R

-
-
-
- -
-
-derivatives(x, y, Rs, alpha_Rs, r_trunc, center_x=0, center_y=0)[source]
-

returns df/dx and df/dy of the function (integral of TNFW), which are the deflection angles

-
-
Parameters
-
    -
  • x – angular position (normally in units of arc seconds)

  • -
  • y – angular position (normally in units of arc seconds)

  • -
  • Rs – turn over point in the slope of the NFW profile in angular unit

  • -
  • alpha_Rs – deflection (angular units) at projected Rs

  • -
  • r_trunc – truncation radius (angular units)

  • -
  • center_x – center of halo (in angular units)

  • -
  • center_y – center of halo (in angular units)

  • -
-
-
Returns
-

deflection angle in x, deflection angle in y

-
-
-
- -
-
-function(x, y, Rs, alpha_Rs, r_trunc, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – angular position

  • -
  • y – angular position

  • -
  • Rs – angular turn over point

  • -
  • alpha_Rs – deflection at Rs

  • -
  • r_trunc – truncation radius

  • -
  • center_x – center of halo

  • -
  • center_y – center of halo

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-hessian(x, y, Rs, alpha_Rs, r_trunc, center_x=0, center_y=0)[source]
-

returns d^2f/dx^2, d^2f/dxdy, d^2f/dydx, d^2f/dy^2 of the TNFW potential f

-
-
Parameters
-
    -
  • x – angular position (normally in units of arc seconds)

  • -
  • y – angular position (normally in units of arc seconds)

  • -
  • Rs – turn over point in the slope of the NFW profile in angular unit

  • -
  • alpha_Rs – deflection (angular units) at projected Rs

  • -
  • r_trunc – truncation radius (angular units)

  • -
  • center_x – center of halo (in angular units)

  • -
  • center_y – center of halo (in angular units)

  • -
-
-
Returns
-

Hessian matrix of function d^2f/dx^2, d^f/dy^2, d^2/dxdy

-
-
-
- -
-
-lower_limit_default = {'Rs': 0, 'alpha_Rs': 0, 'center_x': -100, 'center_y': -100, 'r_trunc': 0}
-
- -
-
-mass_2d(R, Rs, rho0, r_trunc)[source]
-

analytic solution of the projection integral (convergence)

-
-
Parameters
-
    -
  • R – projected radius

  • -
  • Rs – scale radius

  • -
  • rho0 – density normalization (characteristic density)

  • -
  • r_trunc – truncation radius (angular units)

  • -
-
-
Returns
-

mass enclosed 2d projected cylinder

-
-
-
- -
-
-mass_3d(r, Rs, rho0, r_trunc)[source]
-

mass enclosed a 3d sphere or radius r

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • Rs – scale radius

  • -
  • rho0 – density normalization (characteristic density)

  • -
  • r_trunc – truncation radius (angular units)

  • -
-
-
Returns
-

M(<r)

-
-
-
- -
-
-nfwAlpha(R, Rs, rho0, r_trunc, ax_x, ax_y)[source]
-

deflection angel of NFW profile along the projection to coordinate axis

-
-
Parameters
-
    -
  • R (float/numpy array) – radius of interest

  • -
  • Rs (float) – scale radius

  • -
  • rho0 (float) – density normalization (characteristic density)

  • -
  • r_trunc (float > 0) – truncation radius (angular units)

  • -
  • axis (same as R) – projection to either x- or y-axis

  • -
-
-
Returns
-

-
-
-
- -
-
-nfwGamma(R, Rs, rho0, r_trunc, ax_x, ax_y)[source]
-

shear gamma of NFW profile (times Sigma_crit) along the projection to coordinate ‘axis’

-
-
Parameters
-
    -
  • R (float/numpy array) – radius of interest

  • -
  • Rs (float) – scale radius

  • -
  • rho0 (float) – density normalization (characteristic density)

  • -
  • r_trunc (float > 0) – truncation radius (angular units)

  • -
  • axis (same as R) – projection to either x- or y-axis

  • -
-
-
Returns
-

-
-
-
- -
-
-nfwPot(R, Rs, rho0, r_trunc)[source]
-

lensing potential of truncated NFW profile

-
-
Parameters
-
    -
  • R (float/numpy array) – radius of interest

  • -
  • Rs (float) – scale radius

  • -
  • rho0 (float) – density normalization (characteristic density)

  • -
  • r_trunc (float > 0) – truncation radius (angular units)

  • -
-
-
Returns
-

lensing potential

-
-
-
- -
-
-param_names = ['Rs', 'alpha_Rs', 'r_trunc', 'center_x', 'center_y']
-
- -
-
-profile_name = 'TNFW'
-
- -
-
-static rho02alpha(rho0, Rs)[source]
-

convert rho0 to angle at Rs; neglects the truncation

-
-
Parameters
-
    -
  • rho0 – density normalization (characteristic density)

  • -
  • Rs – scale radius

  • -
-
-
Returns
-

deflection angle at RS

-
-
-
- -
-
-upper_limit_default = {'Rs': 100, 'alpha_Rs': 10, 'center_x': 100, 'center_y': 100, 'r_trunc': 100}
-
- -
- -
-
-

lenstronomy.LensModel.Profiles.uldm module

-
-
-class lenstronomy.LensModel.Profiles.uldm.Uldm(*args, **kwargs)[source]
-

Bases: lenstronomy.LensModel.Profiles.base_profile.LensProfileBase

-

This class contains functions concerning the ULDM soliton density profile, -whose good approximation is (see for example https://arxiv.org/pdf/1406.6586.pdf )

-
-\[\rho = \rho_0 (1 + a(\theta/\theta_c)^2)^{-\beta}\]
-

where \(\theta_c\) is the core radius, corresponding to the radius where the -density drops by half its central value, :math: beta is the slope (called just slope -in the parameters of this model), :math: rho_0 = kappa_0 Sigma_c/D_lens, -and :math: a is a parameter, dependent on :math: beta, chosen such -that :math: theta_c indeed corresponds to the radius where the density drops by half -(simple math gives :math: a = 0.5^{-1/beta} - 1 ). -For an ULDM soliton profile without contributions to background potential, it -turns out that :math: beta = 8, a = 0.091. We allow :math: beta to be -different from 8 to model solitons which feel the influence of background -potential (see 2105.10873) -The profile has, as parameters: -:param kappa_0: central convergence -:param theta_c: core radius (in arcseconds) -:param slope: exponent entering the profile, default value is 8

-
-
-alpha_radial(r, kappa_0, theta_c, slope=8)[source]
-

returns the radial part of the deflection angle

-
-
Parameters
-
    -
  • kappa_0 – central convergence of profile

  • -
  • theta_c – core radius (in arcsec)

  • -
  • slope – exponent entering the profile

  • -
  • r – radius where the deflection angle is computed

  • -
-
-
Returns
-

radial deflection angle

-
-
-
- -
-
-density(R, kappa_0, theta_c, slope=8)[source]
-

three dimensional ULDM profile in angular units -(rho0_physical = rho0_angular Sigma_crit / D_lens) -:param R: radius of interest -:param kappa_0: central convergence of profile -:param theta_c: core radius (in arcsec) -:param slope: exponent entering the profile -:return: rho(R) density in angular units

-
- -
-
-density_2d(x, y, kappa_0, theta_c, center_x=0, center_y=0, slope=8)[source]
-

projected two dimensional ULDM profile (convergence * Sigma_crit), but -given our units convention for rho0, it is basically the convergence

-
-
Parameters
-
    -
  • R – radius of interest

  • -
  • kappa_0 – central convergence of profile

  • -
  • theta_c – core radius (in arcsec)

  • -
  • slope – exponent entering the profile

  • -
-
-
Returns
-

Epsilon(R) projected density at radius R

-
-
-
- -
-
-density_lens(r, kappa_0, theta_c, slope=8)[source]
-

computes the density at 3d radius r given lens model parameterization. -The integral in the LOS projection of this quantity results in the -convergence quantity.

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • kappa_0 – central convergence of profile

  • -
  • theta_c – core radius (in arcsec)

  • -
  • slope – exponent entering the profile

  • -
-
-
Returns
-

density rho(r)

-
-
-
- -
-
-derivatives(x, y, kappa_0, theta_c, center_x=0, center_y=0, slope=8)[source]
-

returns df/dx and df/dy of the function (lensing potential), which are the deflection angles

-
-
Parameters
-
    -
  • x – angular position (normally in units of arc seconds)

  • -
  • y – angular position (normally in units of arc seconds)

  • -
  • kappa_0 – central convergence of profile

  • -
  • theta_c – core radius (in arcsec)

  • -
  • slope – exponent entering the profile

  • -
  • center_x – center of halo (in angular units)

  • -
  • center_y – center of halo (in angular units)

  • -
-
-
Returns
-

deflection angle in x, deflection angle in y

-
-
-
- -
-
-function(x, y, kappa_0, theta_c, center_x=0, center_y=0, slope=8)[source]
-
-
Parameters
-
    -
  • x – angular position (normally in units of arc seconds)

  • -
  • y – angular position (normally in units of arc seconds)

  • -
  • kappa_0 – central convergence of profile

  • -
  • theta_c – core radius (in arcsec)

  • -
  • slope – exponent entering the profile

  • -
  • center_x – center of halo (in angular units)

  • -
  • center_y – center of halo (in angular units)

  • -
-
-
Returns
-

lensing potential (in arcsec^2)

-
-
-
- -
-
-hessian(x, y, kappa_0, theta_c, center_x=0, center_y=0, slope=8)[source]
-
-
Parameters
-
    -
  • x – angular position (normally in units of arc seconds)

  • -
  • y – angular position (normally in units of arc seconds)

  • -
  • kappa_0 – central convergence of profile

  • -
  • theta_c – core radius (in arcsec)

  • -
  • slope – exponent entering the profile

  • -
  • center_x – center of halo (in angular units)

  • -
  • center_y – center of halo (in angular units)

  • -
-
-
Returns
-

Hessian matrix of function d^2f/dx^2, d^2/dxdy, d^2/dydx, d^f/dy^2

-
-
-
- -
-
-kappa_r(R, kappa_0, theta_c, slope=8)[source]
-

convergence of the cored density profile. This routine is also for testing

-
-
Parameters
-
    -
  • R – radius (angular scale)

  • -
  • kappa_0 – convergence in the core

  • -
  • theta_c – core radius

  • -
  • slope – exponent entering the profile

  • -
-
-
Returns
-

convergence at r

-
-
-
- -
-
-lower_limit_default = {'center_x': -100, 'center_y': -100, 'kappa_0': 0, 'slope': 3.5, 'theta_c': 0}
-
- -
-
-mass_2d(R, kappa_0, theta_c, slope=8)[source]
-

mass enclosed a 2d sphere or radius r -:param R: radius over which the mass is computed -:param kappa_0: central convergence of profile -:param theta_c: core radius (in arcsec) -:param slope: exponent entering the profile -:return: mass enclosed in 2d sphere

-
- -
-
-mass_3d(R, kappa_0, theta_c, slope=8)[source]
-

mass enclosed a 3d sphere or radius r -:param R: radius in arcseconds -:param kappa_0: central convergence of profile -:param theta_c: core radius (in arcsec) -:param slope: exponent entering the profile -:return: mass of soliton in angular units

-
- -
-
-mass_3d_lens(r, kappa_0, theta_c, slope=8)[source]
-

mass enclosed a 3d sphere or radius r -:param r: radius over which the mass is computed -:param kappa_0: central convergence of profile -:param theta_c: core radius (in arcsec) -:param slope: exponent entering the profile -:return: mass enclosed in 3D ball

-
- -
-
-param_names = ['kappa_0', 'theta_c', 'slope', 'center_x', 'center_y']
-
- -
-
-rhotilde(kappa_0, theta_c, slope=8)[source]
-

Computes the central density in angular units -:param kappa_0: central convergence of profile -:param theta_c: core radius (in arcsec) -:param slope: exponent entering the profile -:return: central density in 1/arcsec

-
- -
-
-upper_limit_default = {'center_x': 100, 'center_y': 100, 'kappa_0': 1.0, 'slope': 10, 'theta_c': 100}
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.LensModel.QuadOptimizer.html b/docs/_build/html/lenstronomy.LensModel.QuadOptimizer.html deleted file mode 100644 index e52d46d30..000000000 --- a/docs/_build/html/lenstronomy.LensModel.QuadOptimizer.html +++ /dev/null @@ -1,393 +0,0 @@ - - - - - - - - - lenstronomy.LensModel.QuadOptimizer package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.LensModel.QuadOptimizer package

-
-

Submodules

-
-
-

lenstronomy.LensModel.QuadOptimizer.multi_plane_fast module

-
-
-class lenstronomy.LensModel.QuadOptimizer.multi_plane_fast.MultiplaneFast(x_image, y_image, z_lens, z_source, lens_model_list, redshift_list, astropy_instance, param_class, foreground_rays, tol_source=1e-05, numerical_alpha_class=None)[source]
-

Bases: object

-

This class accelerates ray tracing computations in multi plane lensing for quadruple image lenses by only -computing the deflection from objects in front of the main deflector at z_lens one time. The first ray tracing -computation through the foreground is saved and re-used, but it will always have the same shape as the initial -x_image, y_image arrays.

-
-
-chi_square(args_lens, *args, **kwargs)[source]
-
-
Parameters
-

args_lens – array of lens model parameters being optimized, computed from kwargs_lens in a specified -param_class, see documentation in QuadOptimizer.param_manager

-
-
Returns
-

total chi^2 penalty (source chi^2 + param chi^2), where param chi^2 is computed by the specified -param_class

-
-
-
- -
-
-logL(args_lens, *args, **kwargs)[source]
-
-
Parameters
-

args_lens – array of lens model parameters being optimized, computed from kwargs_lens in a specified -param_class, see documentation in QuadOptimizer.param_manager

-
-
Returns
-

the log likelihood corresponding to the given chi^2

-
-
-
- -
-
-ray_shooting_fast(args_lens)[source]
-

Performs a ray tracing computation through observed coordinates on the sky (self._x_image, self._y_image) -to the source plane, returning the final coordinates of each ray on the source plane

-
-
Parameters
-

args_lens – An array of parameters being optimized. The array is computed from a set of key word arguments -by an instance of ParamClass (see documentation in QuadOptimizer.param_manager)

-
-
Returns
-

the xy coordinate of each ray traced back to the source plane

-
-
-
- -
-
-source_plane_chi_square(args_lens, *args, **kwargs)[source]
-
-
Parameters
-

args_lens – array of lens model parameters being optimized, computed from kwargs_lens in a specified -param_class, see documentation in QuadOptimizer.param_manager

-
-
Returns
-

chi2 penalty for the source position (all images must map to the same source coordinate)

-
-
-
- -
- -
-
-

lenstronomy.LensModel.QuadOptimizer.optimizer module

-
-
-class lenstronomy.LensModel.QuadOptimizer.optimizer.Optimizer(x_image, y_image, lens_model_list, redshift_list, z_lens, z_source, parameter_class, astropy_instance=None, numerical_alpha_class=None, particle_swarm=True, re_optimize=False, re_optimize_scale=1.0, pso_convergence_mean=50000, foreground_rays=None, tol_source=1e-05, tol_simplex_func=0.001, simplex_n_iterations=400)[source]
-

Bases: object

-

class which executes the optimization routines. Currently implemented as a particle swarm optimization followed by -a downhill simplex routine.

-

Particle swarm optimizer is modified from the CosmoHammer particle swarm routine with different convergence criteria implemented.

-
-
-optimize(n_particles=50, n_iterations=250, verbose=False, threadCount=1)[source]
-
-
Parameters
-
    -
  • n_particles – number of PSO particles, will be ignored if self._particle_swarm is False

  • -
  • n_iterations – number of PSO iterations, will be ignored if self._particle_swarm is False

  • -
  • verbose – whether to print stuff

  • -
  • threadCount – integer; number of threads in multi-threading mode

  • -
-
-
Returns
-

keyword arguments that map (x_image, y_image) to the same source coordinate (source_x, source_y)

-
-
-
- -
- -
-
-

lenstronomy.LensModel.QuadOptimizer.param_manager module

-
-
-class lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawFixedShear(kwargs_lens_init, shear_strength)[source]
-

Bases: lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawParamManager

-

This class implements a fit of EPL + external shear with every parameter except the power law slope AND the -shear strength allowed to vary. The user should specify shear_strengh in the args_param_class keyword when -creating the Optimizer class

-
-
-args_to_kwargs(args)[source]
-
-
Parameters
-

args – array of lens model parameters

-
-
Returns
-

dictionary of lens model parameters with fixed shear = shear_strength

-
-
-
- -
- -
-
-class lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawFixedShearMultipole(kwargs_lens_init, shear_strength)[source]
-

Bases: lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawFixedShear

-

This class implements a fit of EPL + external shear + a multipole term with every parameter except the -power law slope, shear strength, and multipole moment free to vary. The mass centroid and orientation of the -multipole term are fixed to that of the EPL profile

-
-
-args_to_kwargs(args)[source]
-
-
Parameters
-

args – array of lens model parameters

-
-
Returns
-

dictionary of lens model parameters with fixed shear = shear_strength

-
-
-
- -
-
-property to_vary_index
-

The number of lens models being varied in this routine. This is set to 3 because the first three lens models -are EPL, SHEAR, and MULTIPOLE, and their parameters are being optimized.

-

The kwargs_list is split at to to_vary_index with indicies < to_vary_index accessed in this class, -and lens models with indicies > to_vary_index kept fixed.

-

Note that this requires a specific ordering of lens_model_list -:return:

-
- -
- -
-
-class lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawFreeShear(kwargs_lens_init)[source]
-

Bases: lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawParamManager

-

This class implements a fit of EPL + external shear with every parameter except the power law slope allowed to vary

-
-
-args_to_kwargs(args)[source]
-
-
Parameters
-

args – array of lens model parameters

-
-
Returns
-

dictionary of lens model parameters

-
-
-
- -
- -
-
-class lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawFreeShearMultipole(kwargs_lens_init)[source]
-

Bases: lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawParamManager

-

This class implements a fit of EPL + external shear + a multipole term with every parameter except the -power law slope and multipole moment free to vary. The mass centroid and orientation of the multipole term are -fixed to that of the EPL profile

-
-
-args_to_kwargs(args)[source]
-
- -
-
-property to_vary_index
-

The number of lens models being varied in this routine. This is set to 3 because the first three lens models -are EPL, SHEAR, and MULTIPOLE, and their parameters are being optimized.

-

The kwargs_list is split at to to_vary_index with indicies < to_vary_index accessed in this class, -and lens models with indicies > to_vary_index kept fixed.

-

Note that this requires a specific ordering of lens_model_list -:return:

-
- -
- -
-
-class lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawParamManager(kwargs_lens_init)[source]
-

Bases: object

-

Base class for handling the translation between key word arguments and parameter arrays for -EPL mass models. This class is intended for use in modeling galaxy-scale lenses

-
-
-bounds(re_optimize, scale=1.0)[source]
-

Sets the low/high parameter bounds for the particle swarm optimization

-

NOTE: The low/high values specified here are intended for galaxy-scale lenses. If you want to use this -for a different size system you should create a new ParamClass with different settings

-
-
Parameters
-
    -
  • re_optimize – keep a narrow window around each parameter

  • -
  • scale – scales the size of the uncertainty window

  • -
-
-
Returns
-

-
-
-
- -
-
-static kwargs_to_args(kwargs)[source]
-
-
Parameters
-

kwargs – keyword arguments corresponding to the lens model parameters being optimized

-
-
Returns
-

array of lens model parameters

-
-
-
- -
-
-param_chi_square_penalty(args)[source]
-
- -
-
-property to_vary_index
-

The number of lens models being varied in this routine. This is set to 2 because the first three lens models -are EPL and SHEAR, and their parameters are being optimized.

-

The kwargs_list is split at to to_vary_index with indicies < to_vary_index accessed in this class, -and lens models with indicies > to_vary_index kept fixed.

-

Note that this requires a specific ordering of lens_model_list -:return:

-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.LensModel.Solver.html b/docs/_build/html/lenstronomy.LensModel.Solver.html deleted file mode 100644 index 4cc8d0c4d..000000000 --- a/docs/_build/html/lenstronomy.LensModel.Solver.html +++ /dev/null @@ -1,516 +0,0 @@ - - - - - - - - - lenstronomy.LensModel.Solver package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.LensModel.Solver package

-
-

Submodules

-
-
-

lenstronomy.LensModel.Solver.lens_equation_solver module

-
-
-class lenstronomy.LensModel.Solver.lens_equation_solver.LensEquationSolver(lensModel)[source]
-

Bases: object

-

class to solve for image positions given lens model and source position

-
-
-candidate_solutions(sourcePos_x, sourcePos_y, kwargs_lens, min_distance=0.1, search_window=10, verbose=False, x_center=0, y_center=0)[source]
-

finds pixels in the image plane possibly hosting a solution of the lens equation, for the given source position and lens model

-
-
Parameters
-
    -
  • sourcePos_x – source position in units of angle

  • -
  • sourcePos_y – source position in units of angle

  • -
  • kwargs_lens – lens model parameters as keyword arguments

  • -
  • min_distance – minimum separation to consider for two images in units of angle

  • -
  • search_window – window size to be considered by the solver. Will not find image position outside this window

  • -
  • verbose – bool, if True, prints some useful information for the user

  • -
  • x_center – float, center of the window to search for point sources

  • -
  • y_center – float, center of the window to search for point sources

  • -
-
-
Returns
-

(approximate) angular position of (multiple) images ra_pos, dec_pos in units of angles, related ray-traced source displacements and pixel width

-
-
Raises
-

AttributeError, KeyError

-
-
-
- -
-
-findBrightImage(sourcePos_x, sourcePos_y, kwargs_lens, numImages=4, min_distance=0.01, search_window=5, precision_limit=1e-10, num_iter_max=10, arrival_time_sort=True, x_center=0, y_center=0, num_random=0, non_linear=False, magnification_limit=None, initial_guess_cut=True, verbose=False)[source]
-
-
Parameters
-
    -
  • sourcePos_x – source position in units of angle

  • -
  • sourcePos_y – source position in units of angle

  • -
  • kwargs_lens – lens model parameters as keyword arguments

  • -
  • min_distance – minimum separation to consider for two images in units of angle

  • -
  • search_window – window size to be considered by the solver. Will not find image position outside this window

  • -
  • precision_limit – required precision in the lens equation solver (in units of angle in the source plane).

  • -
  • num_iter_max – maximum iteration of lens-source mapping conducted by solver to match the required precision

  • -
  • arrival_time_sort – bool, if True, sorts image position in arrival time (first arrival photon first listed)

  • -
  • initial_guess_cut – bool, if True, cuts initial local minima selected by the grid search based on distance criteria from the source position

  • -
  • verbose – bool, if True, prints some useful information for the user

  • -
  • x_center – float, center of the window to search for point sources

  • -
  • y_center – float, center of the window to search for point sources

  • -
  • num_random – int, number of random positions within the search window to be added to be starting -positions for the gradient decent solver

  • -
  • non_linear – bool, if True applies a non-linear solver not dependent on Hessian computation

  • -
  • magnification_limit – None or float, if set will only return image positions that have an -abs(magnification) larger than this number

  • -
-
-
Returns
-

(exact) angular position of (multiple) images ra_pos, dec_pos in units of angle

-
-
-
- -
-
-image_position_analytical(x, y, kwargs_lens, arrival_time_sort=True, magnification_limit=None, **kwargs_solver)[source]
-
-
Solves the lens equation. Only supports EPL-like (plus shear) models. Uses a specialized recipe that solves a

one-dimensional lens equation that is easier and more reliable to solve than the usual two-dimensional lens equation.

-
-
-
-
Parameters
-
    -
  • x – source position in units of angle, an array of positions is also supported.

  • -
  • y – source position in units of angle, an array of positions is also supported.

  • -
  • kwargs_lens – lens model parameters as keyword arguments

  • -
  • arrival_time_sort – bool, if True, sorts image position in arrival time (first arrival photon first listed)

  • -
  • magnification_limit – None or float, if set will only return image positions that have an -abs(magnification) larger than this number

  • -
  • kwargs_solver – additional kwargs to be supplied to the solver. Particularly relevant are Nmeas and Nmeas_extra

  • -
-
-
Returns
-

(exact) angular position of (multiple) images ra_pos, dec_pos in units of angle -Note: in contrast to the other solvers, generally the (heavily demagnified) central image will also be included, so -setting a a proper magnification_limit is more important. To get similar behaviour, a limit of 1e-1 is acceptable

-
-
-
- -
-
-image_position_from_source(sourcePos_x, sourcePos_y, kwargs_lens, solver='lenstronomy', **kwargs)[source]
-

Solves the lens equation, i.e. finds the image positions in the lens plane that are mapped to a given source -position.

-
-
Parameters
-
    -
  • sourcePos_x – source position in units of angle

  • -
  • sourcePos_y – source position in units of angle

  • -
  • kwargs_lens – lens model parameters as keyword arguments

  • -
  • solver – which solver to use, can be ‘lenstronomy’ (default), ‘analytical’ or ‘stochastic’.

  • -
  • kwargs – Any additional kwargs are passed to the chosen solver, see the documentation of -image_position_lenstronomy, image_position_analytical and image_position_stochastic

  • -
-
-
Returns
-

(exact) angular position of (multiple) images ra_pos, dec_pos in units of angle

-
-
-
- -
-
-image_position_lenstronomy(sourcePos_x, sourcePos_y, kwargs_lens, min_distance=0.1, search_window=10, precision_limit=1e-10, num_iter_max=100, arrival_time_sort=True, initial_guess_cut=True, verbose=False, x_center=0, y_center=0, num_random=0, non_linear=False, magnification_limit=None)[source]
-

Finds image position given source position and lens model. The solver first samples does a grid search in the -lens plane, and the grid points that are closest to the supplied source position are fed to a -specialized gradient-based root finder that finds the exact solutions. Works with all lens models.

-
-
Parameters
-
    -
  • sourcePos_x – source position in units of angle

  • -
  • sourcePos_y – source position in units of angle

  • -
  • kwargs_lens – lens model parameters as keyword arguments

  • -
  • min_distance – minimum separation to consider for two images in units of angle

  • -
  • search_window – window size to be considered by the solver. Will not find image position outside this window

  • -
  • precision_limit – required precision in the lens equation solver (in units of angle in the source plane).

  • -
  • num_iter_max – maximum iteration of lens-source mapping conducted by solver to match the required precision

  • -
  • arrival_time_sort – bool, if True, sorts image position in arrival time (first arrival photon first listed)

  • -
  • initial_guess_cut – bool, if True, cuts initial local minima selected by the grid search based on distance criteria from the source position

  • -
  • verbose – bool, if True, prints some useful information for the user

  • -
  • x_center – float, center of the window to search for point sources

  • -
  • y_center – float, center of the window to search for point sources

  • -
  • num_random – int, number of random positions within the search window to be added to be starting -positions for the gradient decent solver

  • -
  • non_linear – bool, if True applies a non-linear solver not dependent on Hessian computation

  • -
  • magnification_limit – None or float, if set will only return image positions that have an -abs(magnification) larger than this number

  • -
-
-
Returns
-

(exact) angular position of (multiple) images ra_pos, dec_pos in units of angle

-
-
Raises
-

AttributeError, KeyError

-
-
-
- -
-
-image_position_stochastic(source_x, source_y, kwargs_lens, search_window=10, precision_limit=1e-10, arrival_time_sort=True, x_center=0, y_center=0, num_random=1000)[source]
-

Solves the lens equation stochastic with the scipy minimization routine on the quadratic distance between -the backwards ray-shooted proposed image position and the source position. -Credits to Giulia Pagano

-
-
Parameters
-
    -
  • source_x – source position

  • -
  • source_y – source position

  • -
  • kwargs_lens – lens model list of keyword arguments

  • -
  • search_window – angular size of search window

  • -
  • precision_limit – limit required on the precision in the source plane

  • -
  • arrival_time_sort – bool, if True sorts according to arrival time

  • -
  • x_center – center of search window

  • -
  • y_center – center of search window

  • -
  • num_random – number of random starting points of the non-linear solver in the search window

  • -
-
-
Returns
-

x_image, y_image

-
-
-
- -
-
-sort_arrival_times(x_mins, y_mins, kwargs_lens)[source]
-

sort arrival times (fermat potential) of image positions in increasing order of light travel time

-
-
Parameters
-
    -
  • x_mins – ra position of images

  • -
  • y_mins – dec position of images

  • -
  • kwargs_lens – keyword arguments of lens model

  • -
-
-
Returns
-

sorted lists of x_mins and y_mins

-
-
-
- -
- -
-
-

lenstronomy.LensModel.Solver.solver module

-
-
-class lenstronomy.LensModel.Solver.solver.Solver(solver_type, lensModel, num_images)[source]
-

Bases: object

-

joint solve class to manage with type of solver to be executed and checks whether the requirements are fulfilled.

-
-
-add_fixed_lens(kwargs_fixed_lens, kwargs_lens_init)[source]
-

returns kwargs that are kept fixed during run, depending on options

-
-
Parameters
-
    -
  • kwargs_fixed_lens – keyword argument list of fixed parameters (indicated by fitting argument of the user)

  • -
  • kwargs_lens_init – Initial values of the full lens model keyword arguments

  • -
-
-
Returns
-

updated kwargs_fixed_lens, added fixed parameters being added (and replaced later on) by the -non-linear solver.

-
-
-
- -
-
-check_solver(image_x, image_y, kwargs_lens)[source]
-

returns the precision of the solver to match the image position

-
-
Parameters
-
    -
  • kwargs_lens – full lens model (including solved parameters)

  • -
  • image_x – point source in image

  • -
  • image_y – point source in image

  • -
-
-
Returns
-

precision of Euclidean distances between the different rays arriving at the image positions

-
-
-
- -
-
-constraint_lensmodel(x_pos, y_pos, kwargs_list, xtol=1.49012e-12)[source]
-
-
Parameters
-
    -
  • x_pos

  • -
  • y_pos

  • -
  • kwargs_list

  • -
  • xtol

  • -
-
-
Returns
-

-
-
-
- -
-
-update_solver(kwargs_lens, x_pos, y_pos)[source]
-
-
Parameters
-
    -
  • kwargs_lens

  • -
  • x_pos

  • -
  • y_pos

  • -
-
-
Returns
-

-
-
-
- -
- -
-
-

lenstronomy.LensModel.Solver.solver2point module

-
-
-class lenstronomy.LensModel.Solver.solver2point.Solver2Point(lensModel, solver_type='CENTER', decoupling=True)[source]
-

Bases: object

-

class to solve a constraint lens model with two point source positions

-

options are: -‘CENTER’: solves for ‘center_x’, ‘center_y’ parameters of the first lens model -‘ELLIPSE’: solves for ‘e1’, ‘e2’ of the first lens (can also be shear) -‘SHAPELETS’: solves for shapelet coefficients c01, c10 -‘THETA_E_PHI: solves for Einstein radius of first lens model and shear angle of second model

-
-
-add_fixed_lens(kwargs_fixed_lens_list, kwargs_lens_init)[source]
-
-
Parameters
-
    -
  • kwargs_fixed_lens_list

  • -
  • kwargs_lens_init

  • -
-
-
Returns
-

-
-
-
- -
-
-constraint_lensmodel(x_pos, y_pos, kwargs_list, xtol=1.49012e-12)[source]
-

constrains lens model parameters by demanding the solution to match the image positions to a single source -position

-
-
Parameters
-
    -
  • x_pos – list of image positions (x-axis)

  • -
  • y_pos – list of image position (y-axis)

  • -
  • kwargs_list – list of lens model kwargs

  • -
  • xtol – tolerance level of solution when to stop the non-linear solver

  • -
-
-
Returns
-

updated lens model that satisfies the lens equation for the point sources

-
-
-
- -
-
-solve(x_pos, y_pos, init, kwargs_list, a, xtol=1.49012e-12)[source]
-
- -
- -
-
-

lenstronomy.LensModel.Solver.solver4point module

-
-
-class lenstronomy.LensModel.Solver.solver4point.Solver4Point(lensModel, solver_type='PROFILE')[source]
-

Bases: object

-

class to make the constraints for the solver

-
-
-add_fixed_lens(kwargs_fixed_lens_list, kwargs_lens_init)[source]
-
-
Parameters
-
    -
  • kwargs_fixed_lens_list

  • -
  • kwargs_lens_init

  • -
-
-
Returns
-

-
-
-
- -
-
-constraint_lensmodel(x_pos, y_pos, kwargs_list, xtol=1.49012e-12)[source]
-
-
Parameters
-
    -
  • x_pos – list of image positions (x-axis)

  • -
  • y_pos – list of image position (y-axis)

  • -
  • xtol – numerical tolerance level

  • -
  • kwargs_list – list of lens model kwargs

  • -
-
-
Returns
-

updated lens model that satisfies the lens equation for the point sources

-
-
-
- -
-
-solve(x_pos, y_pos, init, kwargs_list, a, xtol=1.49012e-10)[source]
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.LensModel.Util.html b/docs/_build/html/lenstronomy.LensModel.Util.html deleted file mode 100644 index 7f8a2266f..000000000 --- a/docs/_build/html/lenstronomy.LensModel.Util.html +++ /dev/null @@ -1,249 +0,0 @@ - - - - - - - - - lenstronomy.LensModel.Util package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.LensModel.Util package

-
-

Submodules

-
-
-

lenstronomy.LensModel.Util.epl_util module

-
-
-lenstronomy.LensModel.Util.epl_util.brentq_inline(f, xa, xb, xtol=2e-14, rtol=3.552713678800501e-15, maxiter=100, args=())
-

A numba-compatible implementation of brentq (largely copied from scipy.optimize.brentq). -Unfortunately, the scipy verison is not compatible with numba, hence this reimplementation :( -:param f: function to optimize -:param xa: left bound -:param xb: right bound -:param xtol: x-coord root tolerance -:param rtol: x-coord relative tolerance -:param maxiter: maximum num of iterations -:param args: additional arguments to pass to function in the form f(x, args) -:return:

-
- -
-
-lenstronomy.LensModel.Util.epl_util.brentq_nojit(f, xa, xb, xtol=2e-14, rtol=3.552713678800501e-15, maxiter=100, args=())[source]
-

A numba-compatible implementation of brentq (largely copied from scipy.optimize.brentq). -Unfortunately, the scipy verison is not compatible with numba, hence this reimplementation :( -:param f: function to optimize -:param xa: left bound -:param xb: right bound -:param xtol: x-coord root tolerance -:param rtol: x-coord relative tolerance -:param maxiter: maximum num of iterations -:param args: additional arguments to pass to function in the form f(x, args) -:return:

-
- -
-
-lenstronomy.LensModel.Util.epl_util.cart_to_pol(x, y)[source]
-

Convert from cartesian to polar -:param x: x-coordinate -:param y: y-coordinate -:return: tuple of (r, theta)

-
- -
-
-lenstronomy.LensModel.Util.epl_util.cdot(a, b)[source]
-

Calculates some complex dot-product that simplifies the math -:param a: complex number -:param b: complex number -:return: dot-product

-
- -
-
-lenstronomy.LensModel.Util.epl_util.ell_to_pol(rell, theta, q)[source]
-

Converts from elliptical to polar coordinates

-
- -
-
-lenstronomy.LensModel.Util.epl_util.geomlinspace(a, b, N)[source]
-

Constructs a geomspace from a to b, with a linspace prepended to it from 0 to a, with the same spacing as the -geomspace would have at a

-
- -
-
-lenstronomy.LensModel.Util.epl_util.min_approx(x1, x2, x3, y1, y2, y3)[source]
-

Get the x-value of the minimum of the parabola through the points (x1,y1), … -:param x1: x-coordinate point 1 -:param x2: x-coordinate point 2 -:param x3: x-coordinate point 3 -:param y1: y-coordinate point 1 -:param y2: y-coordinate point 2 -:param y3: y-coordinate point 3 -:return: x-location of the minimum

-
- -
-
-lenstronomy.LensModel.Util.epl_util.pol_to_cart(r, th)[source]
-

Convert from polar to cartesian -:param r: r-coordinate -:param th: theta-coordinate -:return: tuple of (x,y)

-
- -
-
-lenstronomy.LensModel.Util.epl_util.pol_to_ell(r, theta, q)[source]
-

Converts from polar to elliptical coordinates

-
- -
-
-lenstronomy.LensModel.Util.epl_util.ps(x, p)[source]
-

A regularized power-law that gets rid of singularities, abs(x)**p*sign(x) -:param x: x -:param p: p -:return:

-
- -
-
-lenstronomy.LensModel.Util.epl_util.rotmat(th)[source]
-

Calculates the rotation matrix -:param th: angle -:return: rotation matrix

-
- -
-
-lenstronomy.LensModel.Util.epl_util.solvequadeq(a, b, c)[source]
-

Solves a quadratic equation. Care is taken for the numerics, see also https://en.wikipedia.org/wiki/Loss_of_significance -:param a: a -:param b: b -:param c: c -:return: tuple of two solutions

-
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.LensModel.html b/docs/_build/html/lenstronomy.LensModel.html deleted file mode 100644 index 3e3206061..000000000 --- a/docs/_build/html/lenstronomy.LensModel.html +++ /dev/null @@ -1,1212 +0,0 @@ - - - - - - - - - lenstronomy.LensModel package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.LensModel package

-
-

Subpackages

-
- -
-
-
-

Submodules

-
-
-

lenstronomy.LensModel.convergence_integrals module

-
-
-lenstronomy.LensModel.convergence_integrals.deflection_from_kappa_grid(kappa, grid_spacing)[source]
-

deflection angles on the convergence grid -the computation is performed as a convolution of the Green’s function with the convergence map using FFT

-
-
Parameters
-
    -
  • kappa – convergence values for each pixel (2-d array)

  • -
  • grid_spacing – pixel size of grid

  • -
-
-
Returns
-

numerical deflection angles in x- and y- direction

-
-
-
- -
-
-lenstronomy.LensModel.convergence_integrals.deflection_from_kappa_grid_adaptive(kappa_high_res, grid_spacing, low_res_factor, high_res_kernel_size)[source]
-

deflection angles on the convergence grid with adaptive FFT -the computation is performed as a convolution of the Green’s function with the convergence map using FFT -The grid is returned in the lower resolution grid

-
-
Parameters
-
    -
  • kappa_high_res – convergence values for each pixel (2-d array)

  • -
  • grid_spacing – pixel size of high resolution grid

  • -
  • low_res_factor – lower resolution factor of larger scale kernel.

  • -
  • high_res_kernel_size – int, size of high resolution kernel in units of degraded pixels

  • -
-
-
Returns
-

numerical deflection angles in x- and y- direction

-
-
-
- -
-
-lenstronomy.LensModel.convergence_integrals.deflection_kernel(num_pix, delta_pix)[source]
-

numerical gridded integration kernel for convergence to deflection angle with given pixel size

-
-
Parameters
-
    -
  • num_pix – integer; number of pixels of kernel per axis, should be odd number to have a defined center

  • -
  • delta_pix – pixel size (per dimension in units of angle)

  • -
-
-
Returns
-

kernel for x-direction and kernel of y-direction deflection angles

-
-
-
- -
-
-lenstronomy.LensModel.convergence_integrals.potential_from_kappa_grid(kappa, grid_spacing)[source]
-

lensing potential on the convergence grid -the computation is performed as a convolution of the Green’s function with the convergence map using FFT

-
-
Parameters
-
    -
  • kappa – 2d grid of convergence values

  • -
  • grid_spacing – pixel size of grid

  • -
-
-
Returns
-

lensing potential in a 2d grid at positions x_grid, y_grid

-
-
-
- -
-
-lenstronomy.LensModel.convergence_integrals.potential_from_kappa_grid_adaptive(kappa_high_res, grid_spacing, low_res_factor, high_res_kernel_size)[source]
-

lensing potential on the convergence grid -the computation is performed as a convolution of the Green’s function with the convergence map using FFT

-
-
Parameters
-
    -
  • kappa_high_res – 2d grid of convergence values

  • -
  • grid_spacing – pixel size of grid

  • -
  • low_res_factor – lower resolution factor of larger scale kernel.

  • -
  • high_res_kernel_size – int, size of high resolution kernel in units of degraded pixels

  • -
-
-
Returns
-

lensing potential in a 2d grid at positions x_grid, y_grid

-
-
-
- -
-
-lenstronomy.LensModel.convergence_integrals.potential_kernel(num_pix, delta_pix)[source]
-

numerical gridded integration kernel for convergence to lensing kernel with given pixel size

-
-
Parameters
-
    -
  • num_pix – integer; number of pixels of kernel per axis

  • -
  • delta_pix – pixel size (per dimension in units of angle)

  • -
-
-
Returns
-

kernel for lensing potential

-
-
-
- -
-
-

lenstronomy.LensModel.lens_model module

-
-
-class lenstronomy.LensModel.lens_model.LensModel(lens_model_list, z_lens=None, z_source=None, lens_redshift_list=None, cosmo=None, multi_plane=False, numerical_alpha_class=None, observed_convention_index=None, z_source_convention=None, cosmo_interp=False, z_interp_stop=None, num_z_interp=100, kwargs_interp=None)[source]
-

Bases: object

-

class to handle an arbitrary list of lens models. This is the main lenstronomy LensModel API for all other modules.

-
-
-alpha(x, y, kwargs, k=None, diff=None)[source]
-

deflection angles

-
-
Parameters
-
    -
  • x (numpy array) – x-position (preferentially arcsec)

  • -
  • y (numpy array) – y-position (preferentially arcsec)

  • -
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes

  • -
  • k – only evaluate the k-th lens model

  • -
  • diff – None or float. If set, computes the deflection as a finite numerical differential of the lensing -potential. This differential is only applicable in the single lensing plane where the form of the lensing -potential is analytically known

  • -
-
-
Returns
-

deflection angles in units of arcsec

-
-
-
- -
-
-arrival_time(x_image, y_image, kwargs_lens, kappa_ext=0, x_source=None, y_source=None)[source]
-

Arrival time of images relative to a straight line without lensing. -Negative values correspond to images arriving earlier, and positive signs correspond to images arriving later.

-
-
Parameters
-
    -
  • x_image – image position

  • -
  • y_image – image position

  • -
  • kwargs_lens – lens model parameter keyword argument list

  • -
  • kappa_ext – external convergence contribution not accounted in the lens model that leads to the same -observables in position and relative fluxes but rescales the time delays

  • -
  • x_source – source position (optional), otherwise computed with ray-tracing

  • -
  • y_source – source position (optional), otherwise computed with ray-tracing

  • -
-
-
Returns
-

arrival time of image positions in units of days

-
-
-
- -
-
-curl(x, y, kwargs, k=None, diff=None, diff_method='square')[source]
-

curl computation F_xy - F_yx

-
-
Parameters
-
    -
  • x (numpy array) – x-position (preferentially arcsec)

  • -
  • y (numpy array) – y-position (preferentially arcsec)

  • -
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes

  • -
  • k – only evaluate the k-th lens model

  • -
  • diff – float, scale over which the finite numerical differential is computed. If None, then using the -exact (if available) differentials.

  • -
  • diff_method – string, ‘square’ or ‘cross’, indicating whether finite differentials are computed from a -cross or a square of points around (x, y)

  • -
-
-
Returns
-

curl at position (x, y)

-
-
-
- -
-
-fermat_potential(x_image, y_image, kwargs_lens, x_source=None, y_source=None)[source]
-

Fermat potential (negative sign means earlier arrival time) -for Multi-plane lensing, it computes the effective Fermat potential (derived from the arrival time and -subtracted off the time-delay distance for the given cosmology). The units are given in arcsecond square.

-
-
Parameters
-
    -
  • x_image – image position

  • -
  • y_image – image position

  • -
  • x_source – source position

  • -
  • y_source – source position

  • -
  • kwargs_lens – list of keyword arguments of lens model parameters matching the lens model classes

  • -
-
-
Returns
-

fermat potential in arcsec**2 without geometry term (second part of Eqn 1 in Suyu et al. 2013) as a list

-
-
-
- -
-
-flexion(x, y, kwargs, k=None, diff=1e-06, hessian_diff=True)[source]
-

third derivatives (flexion)

-
-
Parameters
-
    -
  • x (numpy array) – x-position (preferentially arcsec)

  • -
  • y (numpy array) – y-position (preferentially arcsec)

  • -
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes

  • -
  • k – int or None, if set, only evaluates the differential from one model component

  • -
  • diff – numerical differential length of Flexion

  • -
  • hessian_diff – boolean, if true also computes the numerical differential length of Hessian (optional)

  • -
-
-
Returns
-

f_xxx, f_xxy, f_xyy, f_yyy

-
-
-
- -
-
-gamma(x, y, kwargs, k=None, diff=None, diff_method='square')[source]
-

shear computation -g1 = 1/2(d^2phi/dx^2 - d^2phi/dy^2) -g2 = d^2phi/dxdy

-
-
Parameters
-
    -
  • x (numpy array) – x-position (preferentially arcsec)

  • -
  • y (numpy array) – y-position (preferentially arcsec)

  • -
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes

  • -
  • k – only evaluate the k-th lens model

  • -
  • diff – float, scale over which the finite numerical differential is computed. If None, then using the -exact (if available) differentials.

  • -
  • diff_method – string, ‘square’ or ‘cross’, indicating whether finite differentials are computed from a -cross or a square of points around (x, y)

  • -
-
-
Returns
-

gamma1, gamma2

-
-
-
- -
-
-hessian(x, y, kwargs, k=None, diff=None, diff_method='square')[source]
-

hessian matrix

-
-
Parameters
-
    -
  • x (numpy array) – x-position (preferentially arcsec)

  • -
  • y (numpy array) – y-position (preferentially arcsec)

  • -
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes

  • -
  • k – only evaluate the k-th lens model

  • -
  • diff – float, scale over which the finite numerical differential is computed. If None, then using the -exact (if available) differentials.

  • -
  • diff_method – string, ‘square’ or ‘cross’, indicating whether finite differentials are computed from a -cross or a square of points around (x, y)

  • -
-
-
Returns
-

f_xx, f_xy, f_yx, f_yy components

-
-
-
- -
-
-kappa(x, y, kwargs, k=None, diff=None, diff_method='square')[source]
-

lensing convergence k = 1/2 laplacian(phi)

-
-
Parameters
-
    -
  • x (numpy array) – x-position (preferentially arcsec)

  • -
  • y (numpy array) – y-position (preferentially arcsec)

  • -
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes

  • -
  • k – only evaluate the k-th lens model

  • -
  • diff – float, scale over which the finite numerical differential is computed. If None, then using the -exact (if available) differentials.

  • -
  • diff_method – string, ‘square’ or ‘cross’, indicating whether finite differentials are computed from a -cross or a square of points around (x, y)

  • -
-
-
Returns
-

lensing convergence

-
-
-
- -
-
-magnification(x, y, kwargs, k=None, diff=None, diff_method='square')[source]
-

mag = 1/det(A) -A = 1 - d^2phi/d_ij

-
-
Parameters
-
    -
  • x (numpy array) – x-position (preferentially arcsec)

  • -
  • y (numpy array) – y-position (preferentially arcsec)

  • -
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes

  • -
  • k – only evaluate the k-th lens model

  • -
  • diff – float, scale over which the finite numerical differential is computed. If None, then using the -exact (if available) differentials.

  • -
  • diff_method – string, ‘square’ or ‘cross’, indicating whether finite differentials are computed from a -cross or a square of points around (x, y)

  • -
-
-
Returns
-

magnification

-
-
-
- -
-
-potential(x, y, kwargs, k=None)[source]
-

lensing potential

-
-
Parameters
-
    -
  • x (numpy array) – x-position (preferentially arcsec)

  • -
  • y (numpy array) – y-position (preferentially arcsec)

  • -
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes

  • -
  • k – only evaluate the k-th lens model

  • -
-
-
Returns
-

lensing potential in units of arcsec^2

-
-
-
- -
-
-ray_shooting(x, y, kwargs, k=None)[source]
-

maps image to source position (inverse deflection)

-
-
Parameters
-
    -
  • x (numpy array) – x-position (preferentially arcsec)

  • -
  • y (numpy array) – y-position (preferentially arcsec)

  • -
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes

  • -
  • k – only evaluate the k-th lens model

  • -
-
-
Returns
-

source plane positions corresponding to (x, y) in the image plane

-
-
-
- -
-
-set_dynamic()[source]
-

deletes cache for static setting and makes sure the observed convention in the position of lensing profiles in -the multi-plane setting is enabled. Dynamic is the default setting of this class enabling an accurate computation -of lensing quantities with different parameters in the lensing profiles.

-
-
Returns
-

None

-
-
-
- -
-
-set_static(kwargs)[source]
-

set this instance to a static lens model. This can improve the speed in evaluating lensing quantities at -different positions but must not be used with different lens model parameters!

-
-
Parameters
-

kwargs – lens model keyword argument list

-
-
Returns
-

kwargs_updated (in case of image position convention in multiplane lensing this is changed)

-
-
-
- -
- -
-
-

lenstronomy.LensModel.lens_model_extensions module

-
-
-class lenstronomy.LensModel.lens_model_extensions.LensModelExtensions(lensModel)[source]
-

Bases: object

-

class with extension routines not part of the LensModel core routines

-
-
-caustic_area(kwargs_lens, kwargs_caustic_num, index_vertices=0)[source]
-

computes the area inside a connected caustic curve

-
-
Parameters
-
    -
  • kwargs_lens – lens model keyword argument list

  • -
  • kwargs_caustic_num – keyword arguments for the numerical calculation of the caustics, as input of -self.critical_curve_caustics()

  • -
  • index_vertices – integer, index of connected vortex from the output of self.critical_curve_caustics() -of disconnected curves.

  • -
-
-
Returns
-

area within the caustic curve selected

-
-
-
- -
-
-critical_curve_caustics(kwargs_lens, compute_window=5, grid_scale=0.01, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • kwargs_lens – lens model kwargs

  • -
  • compute_window – window size in arcsec where the critical curve is computed

  • -
  • grid_scale – numerical grid spacing of the computation of the critical curves

  • -
  • center_x – float, center of the window to compute critical curves and caustics

  • -
  • center_y – float, center of the window to compute critical curves and caustics

  • -
-
-
Returns
-

lists of ra and dec arrays corresponding to different disconnected critical curves and their caustic counterparts

-
-
-
- -
-
-critical_curve_tiling(kwargs_lens, compute_window=5, start_scale=0.5, max_order=10, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • kwargs_lens – lens model keyword argument list

  • -
  • compute_window – total window in the image plane where to search for critical curves

  • -
  • start_scale – float, angular scale on which to start the tiling from (if there are two distinct curves in -a region, it might only find one.

  • -
  • max_order – int, maximum order in the tiling to compute critical curve triangles

  • -
  • center_x – float, center of the window to compute critical curves and caustics

  • -
  • center_y – float, center of the window to compute critical curves and caustics

  • -
-
-
Returns
-

list of positions representing coordinates of the critical curve (in RA and DEC)

-
-
-
- -
-
-curved_arc_estimate(x, y, kwargs_lens, smoothing=None, smoothing_3rd=0.001, tan_diff=False)[source]
-

performs the estimation of the curved arc description at a particular position of an arbitrary lens profile

-
-
Parameters
-
    -
  • x – float, x-position where the estimate is provided

  • -
  • y – float, y-position where the estimate is provided

  • -
  • kwargs_lens – lens model keyword arguments

  • -
  • smoothing – (optional) finite differential of second derivative (radial and tangential stretches)

  • -
  • smoothing_3rd – differential scale for third derivative to estimate the tangential curvature

  • -
  • tan_diff – boolean, if True, also returns the relative tangential stretch differential in tangential direction

  • -
-
-
Returns
-

keyword argument list corresponding to a CURVED_ARC profile at (x, y) given the initial lens model

-
-
-
- -
-
-curved_arc_finite_area(x, y, kwargs_lens, dr)[source]
-

computes an estimated curved arc over a finite extent mimicking the appearance of a finite source with radius dr

-
-
Parameters
-
    -
  • x – x-position (float)

  • -
  • y – y-position (float)

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • dr – radius of finite source

  • -
-
-
Returns
-

keyword arguments of curved arc

-
-
-
- -
-
-hessian_eigenvectors(x, y, kwargs_lens, diff=None)[source]
-

computes magnification eigenvectors at position (x, y)

-
-
Parameters
-
    -
  • x – x-position

  • -
  • y – y-position

  • -
  • kwargs_lens – lens model keyword arguments

  • -
-
-
Returns
-

radial stretch, tangential stretch

-
-
-
- -
-
-magnification_finite(x_pos, y_pos, kwargs_lens, source_sigma=0.003, window_size=0.1, grid_number=100, polar_grid=False, aspect_ratio=0.5)[source]
-

returns the magnification of an extended source with Gaussian light profile -:param x_pos: x-axis positons of point sources -:param y_pos: y-axis position of point sources -:param kwargs_lens: lens model kwargs -:param source_sigma: Gaussian sigma in arc sec in source -:param window_size: size of window to compute the finite flux -:param grid_number: number of grid cells per axis in the window to numerically compute the flux -:return: numerically computed brightness of the sources

-
- -
-
-magnification_finite_adaptive(x_image, y_image, source_x, source_y, kwargs_lens, source_fwhm_parsec, z_source, cosmo=None, grid_resolution=None, grid_radius_arcsec=None, axis_ratio=0.5, tol=0.001, step_size=0.05, use_largest_eigenvalue=True, source_light_model='SINGLE_GAUSSIAN', dx=None, dy=None, size_scale=None, amp_scale=None, fixed_aperture_size=False)[source]
-

This method computes image magnifications with a finite-size background source assuming a Gaussian or a -double Gaussian source light profile. It can be much faster that magnification_finite for lens models with many -deflectors and a compact source. This is because most pixels in a rectangular window around a lensed -image of a compact source do not map onto the source, and therefore don’t contribute to the integrated flux in -the image plane.

-

Rather than ray tracing through a rectangular grid, this routine accelerates the computation of image -magnifications with finite-size sources by ray tracing through an elliptical region oriented such that -tracks the surface brightness of the lensed image. The aperture size is initially quite small, -and increases in size until the flux inside of it (and hence the magnification) converges. The orientation of -the elliptical aperture is computed from the magnification tensor evaluated at the image coordinate.

-

If for whatever reason you prefer a circular aperture to the elliptical approximation using the hessian -eigenvectors, you can just set axis_ratio = 1.

-

To use the eigenvalues of the hessian matrix to estimate the optimum axis ratio, set axis_ratio = 0.

-

The default settings for the grid resolution and ray tracing window size work well for sources with fwhm between -0.5 - 100 pc.

-
-
Parameters
-
    -
  • x_image – a list or array of x coordinates [units arcsec]

  • -
  • y_image – a list or array of y coordinates [units arcsec]

  • -
  • source_x – float, source position

  • -
  • source_y – float, source position

  • -
  • kwargs_lens – keyword arguments for the lens model

  • -
  • source_fwhm_parsec – the size of the background source [units parsec]

  • -
  • z_source – the source redshift

  • -
  • cosmo – (optional) an instance of astropy.cosmology; if not specified, a default cosmology will be used

  • -
  • grid_resolution – the grid resolution in units arcsec/pixel; if not specified, an appropriate value will -be estimated from the source size

  • -
  • grid_radius_arcsec – (optional) the size of the ray tracing region in arcsec; if not specified, an appropriate value -will be estimated from the source size

  • -
  • axis_ratio – the axis ratio of the ellipse used for ray tracing; if axis_ratio = 0, then the eigenvalues -the hessian matrix will be used to estimate an appropriate axis ratio. Be warned: if the image is highly -magnified it will tend to curve out of the resulting ellipse

  • -
  • tol – tolerance for convergence in the magnification

  • -
  • step_size – sets the increment for the successively larger ray tracing windows

  • -
  • use_largest_eigenvalue – bool; if True, then the major axis of the ray tracing ellipse region -will be aligned with the eigenvector corresponding to the largest eigenvalue of the hessian matrix

  • -
  • source_light_model – the model for backgourn source light; currently implemented are ‘SINGLE_GAUSSIAN’ and -‘DOUBLE_GAUSSIAN’.

  • -
  • dx – used with source model ‘DOUBLE_GAUSSIAN’, the offset of the second source light profile from the first -[arcsec]

  • -
  • dy – used with source model ‘DOUBLE_GAUSSIAN’, the offset of the second source light profile from the first -[arcsec]

  • -
  • size_scale – used with source model ‘DOUBLE_GAUSSIAN’, the size of the second source light profile relative -to the first

  • -
  • amp_scale – used with source model ‘DOUBLE_GAUSSIAN’, the peak brightness of the second source light profile -relative to the first

  • -
  • fixed_aperture_size – bool, if True the flux is computed inside a fixed aperture size with radius -grid_radius_arcsec

  • -
-
-
Returns
-

an array of image magnifications

-
-
-
- -
-
-radial_tangential_differentials(x, y, kwargs_lens, center_x=0, center_y=0, smoothing_3rd=0.001, smoothing_2nd=None)[source]
-

computes the differentials in stretches and directions

-
-
Parameters
-
    -
  • x – x-position

  • -
  • y – y-position

  • -
  • kwargs_lens – lens model keyword arguments

  • -
  • center_x – x-coord of center towards which the rotation direction is defined

  • -
  • center_y – x-coord of center towards which the rotation direction is defined

  • -
  • smoothing_3rd – finite differential length of third order in units of angle

  • -
  • smoothing_2nd – float or None, finite average differential scale of Hessian

  • -
-
-
Returns
-

-
-
-
- -
-
-radial_tangential_stretch(x, y, kwargs_lens, diff=None, ra_0=0, dec_0=0, coordinate_frame_definitions=False)[source]
-

computes the radial and tangential stretches at a given position

-
-
Parameters
-
    -
  • x – x-position

  • -
  • y – y-position

  • -
  • kwargs_lens – lens model keyword arguments

  • -
  • diff – float or None, finite average differential scale

  • -
-
-
Returns
-

radial stretch, tangential stretch

-
-
-
- -
-
-tangential_average(x, y, kwargs_lens, dr, smoothing=None, num_average=9)[source]
-

computes average tangential stretch around position (x, y) within dr in radial direction

-
-
Parameters
-
    -
  • x – x-position (float)

  • -
  • y – y-position (float)

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • dr – averaging scale in radial direction

  • -
  • smoothing – smoothing scale of derivative

  • -
  • num_average – integer, number of points averaged over within dr in the radial direction

  • -
-
-
Returns
-

-
-
-
- -
-
-zoom_source(x_pos, y_pos, kwargs_lens, source_sigma=0.003, window_size=0.1, grid_number=100, shape='GAUSSIAN')[source]
-

computes the surface brightness on an image with a zoomed window

-
-
Parameters
-
    -
  • x_pos – angular coordinate of center of image

  • -
  • y_pos – angular coordinate of center of image

  • -
  • kwargs_lens – lens model parameter list

  • -
  • source_sigma – source size (in angular units)

  • -
  • window_size – window size in angular units

  • -
  • grid_number – number of grid points per axis

  • -
  • shape – string, shape of source, supports ‘GAUSSIAN’ and ‘TORUS

  • -
-
-
Returns
-

2d numpy array

-
-
-
- -
- -
-
-

lenstronomy.LensModel.lens_param module

-
-
-class lenstronomy.LensModel.lens_param.LensParam(lens_model_list, kwargs_fixed, kwargs_lower=None, kwargs_upper=None, kwargs_logsampling=None, num_images=0, solver_type='NONE', num_shapelet_lens=0)[source]
-

Bases: object

-

class to handle the lens model parameter

-
-
-get_params(args, i)[source]
-
-
Parameters
-
    -
  • args – tuple of individual floats of sampling argument

  • -
  • i – integer, index at the beginning of the tuple for read out to keyword argument convention

  • -
-
-
Returns
-

kwargs_list, index at the end of read out of this model component

-
-
-
- -
-
-num_param()[source]
-
-
Returns
-

integer, number of free parameters being sampled from the lens model components

-
-
-
- -
-
-set_params(kwargs_list)[source]
-
-
Parameters
-

kwargs_list – keyword argument list of lens model components

-
-
Returns
-

tuple of arguments (floats) that are being sampled

-
-
-
- -
- -
-
-

lenstronomy.LensModel.profile_integrals module

-
-
-class lenstronomy.LensModel.profile_integrals.ProfileIntegrals(profile_class)[source]
-

Bases: object

-

class to perform integrals of spherical profiles to compute: -- projected densities -- enclosed densities -- projected enclosed densities

-
-
-density_2d(r, kwargs_profile, lens_param=False)[source]
-

computes the projected density along the line-of-sight

-
-
Parameters
-
    -
  • r – radius (arcsec)

  • -
  • kwargs_profile – keyword argument list with lens model parameters

  • -
  • lens_param – boolean, if True uses the lens model parameterization in computing the 3d density convention -and the return is the convergence

  • -
-
-
Returns
-

2d projected density at projected radius r

-
-
-
- -
-
-mass_enclosed_2d(r, kwargs_profile)[source]
-

computes the mass enclosed the projected line-of-sight -:param r: radius (arcsec) -:param kwargs_profile: keyword argument list with lens model parameters -:return: projected mass enclosed radius r

-
- -
-
-mass_enclosed_3d(r, kwargs_profile, lens_param=False)[source]
-

computes the mass enclosed within a sphere of radius r

-
-
Parameters
-
    -
  • r – radius (arcsec)

  • -
  • kwargs_profile – keyword argument list with lens model parameters

  • -
  • lens_param – boolean, if True uses the lens model parameterization in computing the 3d density convention -and the return is the convergence

  • -
-
-
Returns
-

3d mass enclosed of r

-
-
-
- -
- -
-
-

lenstronomy.LensModel.profile_list_base module

-
-
-class lenstronomy.LensModel.profile_list_base.ProfileListBase(lens_model_list, numerical_alpha_class=None, lens_redshift_list=None, z_source_convention=None, kwargs_interp=None)[source]
-

Bases: object

-

class that manages the list of lens model class instances. This class is applicable for single plane and multi -plane lensing

-
-
-set_dynamic()[source]
-

frees cache set by static model (if exists) and re-computes all lensing quantities each time a definition is -called assuming different parameters are executed. This is the default mode if not specified as set_static()

-
-
Returns
-

None

-
-
-
- -
-
-set_static(kwargs_list)[source]
-
-
Parameters
-

kwargs_list – list of keyword arguments for each profile

-
-
Returns
-

kwargs_list

-
-
-
- -
- -
-
-

lenstronomy.LensModel.single_plane module

-
-
-class lenstronomy.LensModel.single_plane.SinglePlane(lens_model_list, numerical_alpha_class=None, lens_redshift_list=None, z_source_convention=None, kwargs_interp=None)[source]
-

Bases: lenstronomy.LensModel.profile_list_base.ProfileListBase

-

class to handle an arbitrary list of lens models in a single lensing plane

-
-
-alpha(x, y, kwargs, k=None)[source]
-

deflection angles -:param x: x-position (preferentially arcsec) -:type x: numpy array -:param y: y-position (preferentially arcsec) -:type y: numpy array -:param kwargs: list of keyword arguments of lens model parameters matching the lens model classes -:param k: only evaluate the k-th lens model -:return: deflection angles in units of arcsec

-
- -
-
-density(r, kwargs, bool_list=None)[source]
-

3d mass density at radius r -The integral in the LOS projection of this quantity results in the convergence quantity.

-
-
Parameters
-
    -
  • r – radius (in angular units)

  • -
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes

  • -
  • bool_list – list of bools that are part of the output

  • -
-
-
Returns
-

mass density at radius r (in angular units, modulo epsilon_crit)

-
-
-
- -
-
-fermat_potential(x_image, y_image, kwargs_lens, x_source=None, y_source=None, k=None)[source]
-

fermat potential (negative sign means earlier arrival time)

-
-
Parameters
-
    -
  • x_image – image position

  • -
  • y_image – image position

  • -
  • x_source – source position

  • -
  • y_source – source position

  • -
  • kwargs_lens – list of keyword arguments of lens model parameters matching the lens model classes

  • -
  • k

  • -
-
-
Returns
-

fermat potential in arcsec**2 without geometry term (second part of Eqn 1 in Suyu et al. 2013) as a list

-
-
-
- -
-
-hessian(x, y, kwargs, k=None)[source]
-

hessian matrix -:param x: x-position (preferentially arcsec) -:type x: numpy array -:param y: y-position (preferentially arcsec) -:type y: numpy array -:param kwargs: list of keyword arguments of lens model parameters matching the lens model classes -:param k: only evaluate the k-th lens model -:return: f_xx, f_xy, f_yx, f_yy components

-
- -
-
-mass_2d(r, kwargs, bool_list=None)[source]
-

computes the mass enclosed a projected (2d) radius r

-
-
Parameters
-
    -
  • r – radius (in angular units)

  • -
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes

  • -
  • bool_list – list of bools that are part of the output

  • -
-
-
Returns
-

projected mass (in angular units, modulo epsilon_crit)

-
-
-
- -
-
-mass_3d(r, kwargs, bool_list=None)[source]
-

computes the mass within a 3d sphere of radius r

-

if you want to have physical units of kg, you need to multiply by this factor: -const.arcsec ** 2 * self._cosmo.dd * self._cosmo.ds / self._cosmo.dds * const.Mpc * const.c ** 2 / (4 * np.pi * const.G) -grav_pot = -const.G * mass_dim / (r * const.arcsec * self._cosmo.dd * const.Mpc)

-
-
Parameters
-
    -
  • r – radius (in angular units)

  • -
  • kwargs – list of keyword arguments of lens model parameters matching the lens model classes

  • -
  • bool_list – list of bools that are part of the output

  • -
-
-
Returns
-

mass (in angular units, modulo epsilon_crit)

-
-
-
- -
-
-potential(x, y, kwargs, k=None)[source]
-

lensing potential -:param x: x-position (preferentially arcsec) -:type x: numpy array -:param y: y-position (preferentially arcsec) -:type y: numpy array -:param kwargs: list of keyword arguments of lens model parameters matching the lens model classes -:param k: only evaluate the k-th lens model -:return: lensing potential in units of arcsec^2

-
- -
-
-ray_shooting(x, y, kwargs, k=None)[source]
-

maps image to source position (inverse deflection) -:param x: x-position (preferentially arcsec) -:type x: numpy array -:param y: y-position (preferentially arcsec) -:type y: numpy array -:param kwargs: list of keyword arguments of lens model parameters matching the lens model classes -:param k: only evaluate the k-th lens model -:return: source plane positions corresponding to (x, y) in the image plane

-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.LightModel.Profiles.html b/docs/_build/html/lenstronomy.LightModel.Profiles.html deleted file mode 100644 index 4b6c9fe1a..000000000 --- a/docs/_build/html/lenstronomy.LightModel.Profiles.html +++ /dev/null @@ -1,1978 +0,0 @@ - - - - - - - - - lenstronomy.LightModel.Profiles package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.LightModel.Profiles package

-
-

Submodules

-
-
-

lenstronomy.LightModel.Profiles.chameleon module

-
-
-class lenstronomy.LightModel.Profiles.chameleon.Chameleon[source]
-

Bases: object

-

class of the Chameleon model (See Dutton+ 2011, Suyu+2014) an elliptical truncated double isothermal profile

-
-
-function(x, y, amp, w_c, w_t, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – ra-coordinate

  • -
  • y – dec-coordinate

  • -
  • w_c

  • -
  • w_t

  • -
  • amp – amplitude of first power-law flux

  • -
  • e1 – eccentricity parameter

  • -
  • e2 – eccentricity parameter

  • -
  • center_x – center

  • -
  • center_y – center

  • -
-
-
Returns
-

flux of chameleon profile

-
-
-
- -
-
-light_3d(r, amp, w_c, w_t, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • w_c

  • -
  • w_t

  • -
  • amp – amplitude of first power-law flux

  • -
  • e1 – eccentricity parameter

  • -
  • e2 – eccentricity parameter

  • -
  • center_x – center

  • -
  • center_y – center

  • -
-
-
Returns
-

3d flux of chameleon profile at radius r

-
-
-
- -
-
-lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'w_c': 0, 'w_t': 0}
-
- -
-
-param_names = ['amp', 'w_c', 'w_t', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'w_c': 100, 'w_t': 100}
-
- -
- -
-
-class lenstronomy.LightModel.Profiles.chameleon.DoubleChameleon[source]
-

Bases: object

-

class of the double Chameleon model. See Dutton+2011, Suyu+2014 for the single Chameleon model.

-
-
-function(x, y, amp, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp

  • -
  • ratio

  • -
  • w_c1

  • -
  • w_t1

  • -
  • e11

  • -
  • e21

  • -
  • w_c2

  • -
  • w_t2

  • -
  • e12

  • -
  • e22

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-light_3d(r, amp, ratio, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • amp

  • -
  • ratio – ratio of first to second amplitude of Chameleon surface brightness

  • -
  • w_c1

  • -
  • w_t1

  • -
  • e11

  • -
  • e21

  • -
  • w_c2

  • -
  • w_t2

  • -
  • e12

  • -
  • e22

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

3d light density at radius r

-
-
-
- -
-
-lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'e11': -0.8, 'e12': -0.8, 'e21': -0.8, 'e22': -0.8, 'ratio': 0, 'w_c1': 0, 'w_c2': 0, 'w_t1': 0, 'w_t2': 0}
-
- -
-
-param_names = ['amp', 'ratio', 'w_c1', 'w_t1', 'e11', 'e21', 'w_c2', 'w_t2', 'e12', 'e22', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'e11': 0.8, 'e12': 0.8, 'e21': 0.8, 'e22': 0.8, 'ratio': 100, 'w_c1': 100, 'w_c2': 100, 'w_t1': 100, 'w_t2': 100}
-
- -
- -
-
-class lenstronomy.LightModel.Profiles.chameleon.TripleChameleon[source]
-

Bases: object

-

class of the Chameleon model (See Suyu+2014) an elliptical truncated double isothermal profile

-
-
-function(x, y, amp, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp

  • -
  • ratio12 – ratio of first to second amplitude

  • -
  • ratio13 – ratio of first to third amplitude

  • -
  • w_c1

  • -
  • w_t1

  • -
  • e11

  • -
  • e21

  • -
  • w_c2

  • -
  • w_t2

  • -
  • e12

  • -
  • e22

  • -
  • w_c3

  • -
  • w_t3

  • -
  • e13

  • -
  • e23

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-light_3d(r, amp, ratio12, ratio13, w_c1, w_t1, e11, e21, w_c2, w_t2, e12, e22, w_c3, w_t3, e13, e23, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • r – 3d light radius

  • -
  • amp

  • -
  • ratio12 – ratio of first to second amplitude

  • -
  • ratio13 – ratio of first to third amplitude

  • -
  • w_c1

  • -
  • w_t1

  • -
  • e11

  • -
  • e21

  • -
  • w_c2

  • -
  • w_t2

  • -
  • e12

  • -
  • e22

  • -
  • w_c3

  • -
  • w_t3

  • -
  • e13

  • -
  • e23

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'e11': -0.8, 'e12': -0.8, 'e13': -0.8, 'e21': -0.8, 'e22': -0.8, 'e23': -0.8, 'ratio12': 0, 'ratio13': 0.0, 'w_c1': 0, 'w_c2': 0, 'w_c3': 0, 'w_t1': 0, 'w_t2': 0, 'w_t3': 0}
-
- -
-
-param_names = ['amp', 'ratio12', 'ratio13', 'w_c1', 'w_t1', 'e11', 'e21', 'w_c2', 'w_t2', 'e12', 'e22', 'w_c3', 'w_t3', 'e13', 'e23', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'e11': 0.8, 'e12': 0.8, 'e13': 0.8, 'e21': 0.8, 'e22': 0.8, 'e23': 0.8, 'ratio12': 100, 'ratio13': 100, 'w_c1': 100, 'w_c2': 100, 'w_c3': 100, 'w_t1': 100, 'w_t2': 100, 'w_t3': 100}
-
- -
- -
-
-

lenstronomy.LightModel.Profiles.ellipsoid module

-
-
-class lenstronomy.LightModel.Profiles.ellipsoid.Ellipsoid[source]
-

Bases: object

-

class for an universal surface brightness within an ellipsoid

-
-
-function(x, y, amp, radius, e1, e2, center_x, center_y)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp – surface brightness within the ellipsoid

  • -
  • radius – radius (product average of semi-major and semi-minor axis) of the ellipsoid

  • -
  • e1 – eccentricity

  • -
  • e2 – eccentricity

  • -
  • center_x – center

  • -
  • center_y – center

  • -
-
-
Returns
-

surface brightness

-
-
-
- -
- -
-
-

lenstronomy.LightModel.Profiles.gaussian module

-
-
-class lenstronomy.LightModel.Profiles.gaussian.Gaussian[source]
-

Bases: object

-

class for Gaussian light profile -The two-dimensional Gaussian profile amplitude is defined such that the 2D integral leads to the ‘amp’ value.

-

profile name in LightModel module: ‘GAUSSIAN’

-
-
-function(x, y, amp, sigma, center_x=0, center_y=0)[source]
-

surface brightness per angular unit

-
-
Parameters
-
    -
  • x – coordinate on the sky

  • -
  • y – coordinate on the sky

  • -
  • amp – amplitude, such that 2D integral leads to this value

  • -
  • sigma – sigma of Gaussian in each direction

  • -
  • center_x – center of profile

  • -
  • center_y – center of profile

  • -
-
-
Returns
-

surface brightness at (x, y)

-
-
-
- -
-
-light_3d(r, amp, sigma)[source]
-

3D brightness per angular volume element

-
-
Parameters
-
    -
  • r – 3d distance from center of profile

  • -
  • amp – amplitude, such that 2D integral leads to this value

  • -
  • sigma – sigma of Gaussian in each direction

  • -
-
-
Returns
-

3D brightness per angular volume element

-
-
-
- -
-
-total_flux(amp, sigma, center_x=0, center_y=0)[source]
-

integrated flux of the profile

-
-
Parameters
-
    -
  • amp – amplitude, such that 2D integral leads to this value

  • -
  • sigma – sigma of Gaussian in each direction

  • -
  • center_x – center of profile

  • -
  • center_y – center of profile

  • -
-
-
Returns
-

total flux

-
-
-
- -
- -
-
-class lenstronomy.LightModel.Profiles.gaussian.GaussianEllipse[source]
-

Bases: object

-

class for Gaussian light profile with ellipticity

-

profile name in LightModel module: ‘GAUSSIAN_ELLIPSE’

-
-
-function(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – coordinate on the sky

  • -
  • y – coordinate on the sky

  • -
  • amp – amplitude, such that 2D integral leads to this value

  • -
  • sigma – sigma of Gaussian in each direction

  • -
  • e1 – eccentricity modulus

  • -
  • e2 – eccentricity modulus

  • -
  • center_x – center of profile

  • -
  • center_y – center of profile

  • -
-
-
Returns
-

surface brightness at (x, y)

-
-
-
- -
-
-light_3d(r, amp, sigma, e1=0, e2=0)[source]
-

3D brightness per angular volume element

-
-
Parameters
-
    -
  • r – 3d distance from center of profile

  • -
  • amp – amplitude, such that 2D integral leads to this value

  • -
  • sigma – sigma of Gaussian in each direction

  • -
  • e1 – eccentricity modulus

  • -
  • e2 – eccentricity modulus

  • -
-
-
Returns
-

3D brightness per angular volume element

-
-
-
- -
-
-lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'sigma': 0}
-
- -
-
-param_names = ['amp', 'sigma', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-total_flux(amp, sigma=None, e1=None, e2=None, center_x=None, center_y=None)[source]
-

total integrated flux of profile

-
-
Parameters
-
    -
  • amp – amplitude, such that 2D integral leads to this value

  • -
  • sigma – sigma of Gaussian in each direction

  • -
  • e1 – eccentricity modulus

  • -
  • e2 – eccentricity modulus

  • -
  • center_x – center of profile

  • -
  • center_y – center of profile

  • -
-
-
Returns
-

total flux

-
-
-
- -
-
-upper_limit_default = {'amp': 1000, 'center_x': 100, 'center_y': 100, 'e1': -0.5, 'e2': -0.5, 'sigma': 100}
-
- -
- -
-
-class lenstronomy.LightModel.Profiles.gaussian.MultiGaussian[source]
-

Bases: object

-

class for elliptical pseudo Jaffe lens light (2d projected light/mass distribution

-

profile name in LightModel module: ‘MULTI_GAUSSIAN’

-
-
-function(x, y, amp, sigma, center_x=0, center_y=0)[source]
-

surface brightness per angular unit

-
-
Parameters
-
    -
  • x – coordinate on the sky

  • -
  • y – coordinate on the sky

  • -
  • amp – list of amplitudes of individual Gaussian profiles

  • -
  • sigma – list of widths of individual Gaussian profiles

  • -
  • center_x – center of profile

  • -
  • center_y – center of profile

  • -
-
-
Returns
-

surface brightness at (x, y)

-
-
-
- -
-
-function_split(x, y, amp, sigma, center_x=0, center_y=0)[source]
-

split surface brightness in individual components

-
-
Parameters
-
    -
  • x – coordinate on the sky

  • -
  • y – coordinate on the sky

  • -
  • amp – list of amplitudes of individual Gaussian profiles

  • -
  • sigma – list of widths of individual Gaussian profiles

  • -
  • center_x – center of profile

  • -
  • center_y – center of profile

  • -
-
-
Returns
-

list of arrays of surface brightness

-
-
-
- -
-
-light_3d(r, amp, sigma)[source]
-

3D brightness per angular volume element

-
-
Parameters
-
    -
  • r – 3d distance from center of profile

  • -
  • amp – list of amplitudes of individual Gaussian profiles

  • -
  • sigma – list of widths of individual Gaussian profiles

  • -
-
-
Returns
-

3D brightness per angular volume element

-
-
-
- -
-
-lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'sigma': 0}
-
- -
-
-param_names = ['amp', 'sigma', 'center_x', 'center_y']
-
- -
-
-total_flux(amp, sigma, center_x=0, center_y=0)[source]
-

total integrated flux of profile

-
-
Parameters
-
    -
  • amp – list of amplitudes of individual Gaussian profiles

  • -
  • sigma – list of widths of individual Gaussian profiles

  • -
  • center_x – center of profile

  • -
  • center_y – center of profile

  • -
-
-
Returns
-

total flux

-
-
-
- -
-
-upper_limit_default = {'amp': 1000, 'center_x': 100, 'center_y': 100, 'e1': -0.5, 'e2': -0.5, 'sigma': 100}
-
- -
- -
-
-class lenstronomy.LightModel.Profiles.gaussian.MultiGaussianEllipse[source]
-

Bases: object

-

class for elliptical multi Gaussian profile

-

profile name in LightModel module: ‘MULTI_GAUSSIAN_ELLIPSE’

-
-
-function(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]
-

surface brightness per angular unit

-
-
Parameters
-
    -
  • x – coordinate on the sky

  • -
  • y – coordinate on the sky

  • -
  • amp – list of amplitudes of individual Gaussian profiles

  • -
  • sigma – list of widths of individual Gaussian profiles

  • -
  • e1 – eccentricity modulus

  • -
  • e2 – eccentricity modulus

  • -
  • center_x – center of profile

  • -
  • center_y – center of profile

  • -
-
-
Returns
-

surface brightness at (x, y)

-
-
-
- -
-
-function_split(x, y, amp, sigma, e1, e2, center_x=0, center_y=0)[source]
-

split surface brightness in individual components

-
-
Parameters
-
    -
  • x – coordinate on the sky

  • -
  • y – coordinate on the sky

  • -
  • amp – list of amplitudes of individual Gaussian profiles

  • -
  • sigma – list of widths of individual Gaussian profiles

  • -
  • e1 – eccentricity modulus

  • -
  • e2 – eccentricity modulus

  • -
  • center_x – center of profile

  • -
  • center_y – center of profile

  • -
-
-
Returns
-

list of arrays of surface brightness

-
-
-
- -
-
-light_3d(r, amp, sigma, e1=0, e2=0)[source]
-

3D brightness per angular volume element

-
-
Parameters
-
    -
  • r – 3d distance from center of profile

  • -
  • amp – list of amplitudes of individual Gaussian profiles

  • -
  • sigma – list of widths of individual Gaussian profiles

  • -
  • e1 – eccentricity modulus

  • -
  • e2 – eccentricity modulus

  • -
-
-
Returns
-

3D brightness per angular volume element

-
-
-
- -
-
-lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'sigma': 0}
-
- -
-
-param_names = ['amp', 'sigma', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-total_flux(amp, sigma, e1, e2, center_x=0, center_y=0)[source]
-

total integrated flux of profile

-
-
Parameters
-
    -
  • amp – list of amplitudes of individual Gaussian profiles

  • -
  • sigma – list of widths of individual Gaussian profiles

  • -
  • e1 – eccentricity modulus

  • -
  • e2 – eccentricity modulus

  • -
  • center_x – center of profile

  • -
  • center_y – center of profile

  • -
-
-
Returns
-

total flux

-
-
-
- -
-
-upper_limit_default = {'amp': 1000, 'center_x': 100, 'center_y': 100, 'e1': -0.5, 'e2': -0.5, 'sigma': 100}
-
- -
- -
-
-

lenstronomy.LightModel.Profiles.hernquist module

-
-
-class lenstronomy.LightModel.Profiles.hernquist.Hernquist[source]
-

Bases: object

-

class for pseudo Jaffe lens light (2d projected light/mass distribution

-
-
-function(x, y, amp, Rs, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp

  • -
  • Rs – scale radius: half-light radius = Rs / 0.551

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-light_3d(r, amp, Rs)[source]
-
-
Parameters
-
    -
  • r

  • -
  • amp

  • -
  • Rs

  • -
-
-
Returns
-

-
-
-
- -
- -
-
-class lenstronomy.LightModel.Profiles.hernquist.HernquistEllipse[source]
-

Bases: object

-

class for elliptical pseudo Jaffe lens light (2d projected light/mass distribution

-
-
-function(x, y, amp, Rs, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp

  • -
  • Rs

  • -
  • e1

  • -
  • e2

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-light_3d(r, amp, Rs, e1=0, e2=0)[source]
-
-
Parameters
-
    -
  • r

  • -
  • amp

  • -
  • Rs

  • -
  • e1

  • -
  • e2

  • -
-
-
Returns
-

-
-
-
- -
-
-lower_limit_default = {'Rs': 0, 'amp': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5}
-
- -
-
-param_names = ['amp', 'Rs', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'Rs': 100, 'amp': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5}
-
- -
- -
-
-

lenstronomy.LightModel.Profiles.interpolation module

-
-
-class lenstronomy.LightModel.Profiles.interpolation.Interpol[source]
-

Bases: object

-

class which uses an interpolation of an image to compute the surface brightness

-

parameters are -‘image’: 2d numpy array of surface brightness (not integrated flux per pixel!) -‘center_x’: coordinate of center of image in angular units (i.e. arc seconds) -‘center_y’: coordinate of center of image in angular units (i.e. arc seconds) -‘phi_G’: rotation of image relative to the rectangular ra-to-dec orientation -‘scale’: arcseconds per pixel of the image to be interpolated

-
-
-static coord2image_pixel(ra, dec, center_x, center_y, phi_G, scale)[source]
-
-
Parameters
-
    -
  • ra – angular coordinate

  • -
  • dec – angular coordinate

  • -
  • center_x – center of image in angular coordinates

  • -
  • center_y – center of image in angular coordinates

  • -
  • phi_G – rotation angle

  • -
  • scale – pixel scale of image

  • -
-
-
Returns
-

pixel coordinates

-
-
-
- -
-
-delete_cache()[source]
-

delete the cached interpolated image

-
- -
-
-function(x, y, image=None, amp=1, center_x=0, center_y=0, phi_G=0, scale=1)[source]
-
-
Parameters
-
    -
  • x – x-coordinate to evaluate surface brightness

  • -
  • y – y-coordinate to evaluate surface brightness

  • -
  • image – 2d numpy array (image) to be used to interpolate

  • -
  • amp – amplitude of surface brightness scaling in respect of original image

  • -
  • center_x – center of interpolated image

  • -
  • center_y – center of interpolated image

  • -
  • phi_G – rotation angle of simulated image in respect to input gird

  • -
  • scale – pixel scale (in angular units) of the simulated image

  • -
-
-
Returns
-

surface brightness from the model at coordinates (x, y)

-
-
-
- -
-
-image_interp(x, y, image)[source]
-
- -
-
-lower_limit_default = {'amp': 0, 'center_x': -1000, 'center_y': -1000, 'phi_G': -3.141592653589793, 'scale': 1e-09}
-
- -
-
-param_names = ['image', 'amp', 'center_x', 'center_y', 'phi_G', 'scale']
-
- -
-
-total_flux(image, scale, amp=1, center_x=0, center_y=0, phi_G=0)[source]
-

sums up all the image surface brightness (image pixels defined in surface brightness at the coordinate of the pixel) -times pixel area

-
-
Parameters
-
    -
  • image – pixelized surface brightness

  • -
  • scale – scale of the pixel in units of angle

  • -
  • amp – linear scaling parameter of the surface brightness multiplicative with the initial image

  • -
  • center_x – center of image in angular coordinates

  • -
  • center_y – center of image in angular coordinates

  • -
  • phi_G – rotation angle

  • -
-
-
Returns
-

total flux of the image

-
-
-
- -
-
-upper_limit_default = {'amp': 1000000, 'center_x': 1000, 'center_y': 1000, 'phi_G': 3.141592653589793, 'scale': 10000000000}
-
- -
- -
-
-

lenstronomy.LightModel.Profiles.moffat module

-
-
-class lenstronomy.LightModel.Profiles.moffat.Moffat[source]
-

Bases: object

-

this class contains functions to evaluate a Moffat surface brightness profile

-
-\[I(r) = I_0 * (1 + (r/\alpha)^2)^{-\beta}\]
-

with \(I_0 = amp\).

-
-
-function(x, y, amp, alpha, beta, center_x=0, center_y=0)[source]
-

2D Moffat profile

-
-
Parameters
-
    -
  • x – x-position (angle)

  • -
  • y – y-position (angle)

  • -
  • amp – normalization

  • -
  • alpha – scale

  • -
  • beta – exponent

  • -
  • center_x – x-center

  • -
  • center_y – y-center

  • -
-
-
Returns
-

surface brightness

-
-
-
- -
- -
-
-

lenstronomy.LightModel.Profiles.nie module

-
-
-class lenstronomy.LightModel.Profiles.nie.NIE[source]
-

Bases: lenstronomy.LightModel.Profiles.profile_base.LightProfileBase

-

non-divergent isothermal ellipse (projected) -This is effectively the convergence profile of the NIE lens model with an amplitude ‘amp’ rather than an Einstein -radius ‘theta_E’

-
-
-function(x, y, amp, e1, e2, s_scale, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinate

  • -
  • y – y-coordinate

  • -
  • amp – surface brightness normalization

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • s_scale – smoothing scale (square averaged of minor and major axis)

  • -
  • center_x – center of profile

  • -
  • center_y – center of profile

  • -
-
-
Returns
-

surface brightness of NIE profile

-
-
-
- -
-
-light_3d(r, amp, e1, e2, s_scale, center_x=0, center_y=0)[source]
-

3d light distribution (in spherical regime)

-
-
Parameters
-
    -
  • r – 3d radius

  • -
  • amp – surface brightness normalization

  • -
  • e1 – eccentricity component

  • -
  • e2 – eccentricity component

  • -
  • s_scale – smoothing scale (square averaged of minor and major axis)

  • -
  • center_x – center of profile

  • -
  • center_y – center of profile

  • -
-
-
Returns
-

light density at 3d radius

-
-
-
- -
-
-lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 's_scale': 0}
-
- -
-
-param_names = ['amp', 'e1', 'e2', 's_scale', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 's_scale': 100}
-
- -
- -
-
-

lenstronomy.LightModel.Profiles.p_jaffe module

-
-
-class lenstronomy.LightModel.Profiles.p_jaffe.PJaffe[source]
-

Bases: object

-

class for pseudo Jaffe lens light (2d projected light/mass distribution)

-
-
-function(x, y, amp, Ra, Rs, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp

  • -
  • Ra

  • -
  • Rs

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-light_3d(r, amp, Ra, Rs)[source]
-
-
Parameters
-
    -
  • r

  • -
  • amp

  • -
  • Rs

  • -
  • Ra

  • -
-
-
Returns
-

-
-
-
- -
-
-lower_limit_default = {'Ra': 0, 'Rs': 0, 'amp': 0, 'center_x': -100, 'center_y': -100}
-
- -
-
-param_names = ['amp', 'Ra', 'Rs', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'Ra': 100, 'Rs': 100, 'amp': 100, 'center_x': 100, 'center_y': 100}
-
- -
- -
-
-class lenstronomy.LightModel.Profiles.p_jaffe.PJaffeEllipse[source]
-

Bases: object

-

calss for elliptical pseudo Jaffe lens light

-
-
-function(x, y, amp, Ra, Rs, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp

  • -
  • Ra

  • -
  • Rs

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-light_3d(r, amp, Ra, Rs, e1=0, e2=0)[source]
-
-
Parameters
-
    -
  • r

  • -
  • amp

  • -
  • Ra

  • -
  • Rs

  • -
-
-
Returns
-

-
-
-
- -
-
-lower_limit_default = {'Ra': 0, 'Rs': 0, 'amp': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5}
-
- -
-
-param_names = ['amp', 'Ra', 'Rs', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'Ra': 100, 'Rs': 100, 'amp': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5}
-
- -
- -
-
-

lenstronomy.LightModel.Profiles.power_law module

-
-
-class lenstronomy.LightModel.Profiles.power_law.PowerLaw[source]
-

Bases: object

-

class for power-law elliptical light distribution

-
-
-function(x, y, amp, gamma, e1, e2, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – ra-coordinate

  • -
  • y – dec-coordinate

  • -
  • amp – amplitude of flux

  • -
  • gamma – projected power-law slope

  • -
  • e1 – ellipticity

  • -
  • e2 – ellipticity

  • -
  • center_x – center

  • -
  • center_y – center

  • -
-
-
Returns
-

projected flux

-
-
-
- -
-
-light_3d(r, amp, gamma, e1=0, e2=0)[source]
-
-
Parameters
-
    -
  • r

  • -
  • amp

  • -
  • gamma

  • -
  • e1

  • -
  • e2

  • -
-
-
Returns
-

-
-
-
- -
-
-lower_limit_default = {'amp': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'gamma': 1}
-
- -
-
-param_names = ['amp', 'gamma', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'amp': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'gamma': 3}
-
- -
- -
-
-

lenstronomy.LightModel.Profiles.sersic module

-
-
-class lenstronomy.LightModel.Profiles.sersic.CoreSersic(smoothing=1e-05, sersic_major_axis=False)[source]
-

Bases: lenstronomy.LensModel.Profiles.sersic_utils.SersicUtil

-

this class contains the Core-Sersic function introduced by e.g Trujillo et al. 2004

-
-\[I(R) = I' \left[1 + (R_b/R)^{\alpha} \right]^{\gamma / \alpha} -\exp \left{ -b_n \left[(R^{\alpha} + R_b^{lpha})/R_e^{\alpha} \right]^{1 / (n\alpha)} \right}\]
-

with

-
-\[I' = I_b 2^{-\gamma/ \alpha} \exp \left[b_n 2^{1 / (n\alpha)} (R_b/R_e)^{1/n} \right]\]
-

where \(I_b\) is the intensity at the break radius.

-
-
-function(x, y, amp, R_sersic, Rb, n_sersic, gamma, e1, e2, center_x=0, center_y=0, alpha=3.0, max_R_frac=100.0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp – surface brightness/amplitude value at the half light radius

  • -
  • R_sersic – half light radius (either semi-major axis or product average of semi-major and semi-minor axis)

  • -
  • Rb – “break” core radius

  • -
  • n_sersic – Sersic index

  • -
  • gamma – inner power-law exponent

  • -
  • e1 – eccentricity parameter

  • -
  • e2 – eccentricity parameter

  • -
  • center_x – center in x-coordinate

  • -
  • center_y – center in y-coordinate

  • -
  • alpha – sharpness of the transition between the cusp and the outer Sersic profile (float)

  • -
  • max_R_frac – maximum window outside of which the mass is zeroed, in units of R_sersic (float)

  • -
-
-
Returns
-

Cored Sersic profile value at (x, y)

-
-
-
- -
-
-lower_limit_default = {'Rb': 0, 'amp': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'gamma': 0, 'n_sersic': 0.5}
-
- -
-
-param_names = ['amp', 'R_sersic', 'Rb', 'n_sersic', 'gamma', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'Rb': 100, 'amp': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'gamma': 10, 'n_sersic': 8}
-
- -
- -
-
-class lenstronomy.LightModel.Profiles.sersic.Sersic(smoothing=1e-05, sersic_major_axis=False)[source]
-

Bases: lenstronomy.LensModel.Profiles.sersic_utils.SersicUtil

-

this class contains functions to evaluate an spherical Sersic function

-
-\[I(R) = I_0 \exp \left[ -b_n (R/R_{\rm Sersic})^{\frac{1}{n}}\right]\]
-

with \(I_0 = amp\) -and -with \(b_{n}\approx 1.999n-0.327\)

-
-
-function(x, y, amp, R_sersic, n_sersic, center_x=0, center_y=0, max_R_frac=100.0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp – surface brightness/amplitude value at the half light radius

  • -
  • R_sersic – semi-major axis half light radius

  • -
  • n_sersic – Sersic index

  • -
  • center_x – center in x-coordinate

  • -
  • center_y – center in y-coordinate

  • -
  • max_R_frac – maximum window outside of which the mass is zeroed, in units of R_sersic (float)

  • -
-
-
Returns
-

Sersic profile value at (x, y)

-
-
-
- -
-
-lower_limit_default = {'R_sersic': 0, 'amp': 0, 'center_x': -100, 'center_y': -100, 'n_sersic': 0.5}
-
- -
-
-param_names = ['amp', 'R_sersic', 'n_sersic', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'R_sersic': 100, 'amp': 100, 'center_x': 100, 'center_y': 100, 'n_sersic': 8}
-
- -
- -
-
-class lenstronomy.LightModel.Profiles.sersic.SersicElliptic(smoothing=1e-05, sersic_major_axis=False)[source]
-

Bases: lenstronomy.LensModel.Profiles.sersic_utils.SersicUtil

-

this class contains functions to evaluate an elliptical Sersic function

-
-
-function(x, y, amp, R_sersic, n_sersic, e1, e2, center_x=0, center_y=0, max_R_frac=100.0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp – surface brightness/amplitude value at the half light radius

  • -
  • R_sersic – half light radius (either semi-major axis or product average of semi-major and semi-minor axis)

  • -
  • n_sersic – Sersic index

  • -
  • e1 – eccentricity parameter

  • -
  • e2 – eccentricity parameter

  • -
  • center_x – center in x-coordinate

  • -
  • center_y – center in y-coordinate

  • -
  • max_R_frac – maximum window outside of which the mass is zeroed, in units of R_sersic (float)

  • -
-
-
Returns
-

Sersic profile value at (x, y)

-
-
-
- -
-
-lower_limit_default = {'R_sersic': 0, 'amp': 0, 'center_x': -100, 'center_y': -100, 'e1': -0.5, 'e2': -0.5, 'n_sersic': 0.5}
-
- -
-
-param_names = ['amp', 'R_sersic', 'n_sersic', 'e1', 'e2', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'R_sersic': 100, 'amp': 100, 'center_x': 100, 'center_y': 100, 'e1': 0.5, 'e2': 0.5, 'n_sersic': 8}
-
- -
- -
-
-

lenstronomy.LightModel.Profiles.shapelets module

-
-
-class lenstronomy.LightModel.Profiles.shapelets.ShapeletSet[source]
-

Bases: object

-

class to operate on entire shapelet set limited by a maximal polynomial order n_max, such that n1 + n2 <= n_max

-
-
-decomposition(image, x, y, n_max, beta, deltaPix, center_x=0, center_y=0)[source]
-

decomposes an image into the shapelet coefficients in same order as for the function call -:param image: -:param x: -:param y: -:param n_max: -:param beta: -:param center_x: -:param center_y: -:return:

-
- -
-
-function(x, y, amp, n_max, beta, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x – x-coordinates

  • -
  • y – y-coordinates

  • -
  • amp – array of amplitudes in pre-defined order of shapelet basis functions

  • -
  • beta – shapelet scale

  • -
  • n_max – maximum polynomial order in Hermite polynomial

  • -
  • center_x – shapelet center

  • -
  • center_y – shapelet center

  • -
-
-
Returns
-

surface brightness of combined shapelet set

-
-
-
- -
-
-function_split(x, y, amp, n_max, beta, center_x=0, center_y=0)[source]
-

splits shapelet set in list of individual shapelet basis function responses

-
-
Parameters
-
    -
  • x – x-coordinates

  • -
  • y – y-coordinates

  • -
  • amp – array of amplitudes in pre-defined order of shapelet basis functions

  • -
  • beta – shapelet scale

  • -
  • n_max – maximum polynomial order in Hermite polynomial

  • -
  • center_x – shapelet center

  • -
  • center_y – shapelet center

  • -
-
-
Returns
-

list of individual shapelet basis function responses

-
-
-
- -
-
-lower_limit_default = {'beta': 0.01, 'center_x': -100, 'center_y': -100}
-
- -
-
-param_names = ['amp', 'n_max', 'beta', 'center_x', 'center_y']
-
- -
-
-shapelet_basis_2d(num_order, beta, numPix, deltaPix=1, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • num_order – max shapelet order

  • -
  • beta – shapelet scale

  • -
  • numPix – number of pixel of the grid

  • -
-
-
Returns
-

list of shapelets drawn on pixel grid, centered.

-
-
-
- -
-
-upper_limit_default = {'beta': 100, 'center_x': 100, 'center_y': 100}
-
- -
- -
-
-class lenstronomy.LightModel.Profiles.shapelets.Shapelets(interpolation=False, precalc=False, stable_cut=True, cut_scale=5)[source]
-

Bases: object

-

class for 2d cartesian Shapelets.

-

Sources: -Refregier 2003: Shapelets: I. A Method for Image Analysis https://arxiv.org/abs/astro-ph/0105178 -Refregier 2003: Shapelets: II. A Method for Weak Lensing Measurements https://arxiv.org/abs/astro-ph/0105179

-

For one dimension, the shapelets are defined as

-
-\[\phi_n(x) \equiv \left[2^n \pi^{1/2} n! \right]]^{-1/2}H_n(x) e^{-\frac{x^2}{2}}\]
-

This basis is orthonormal. The dimensional basis function is

-
-\[B_n(x;\beta) \equiv \beta^{-1/2} \phi_n(\beta^{-1}x)\]
-

which are orthonormal as well.

-

The two-dimensional basis function is

-
-\[\phi_{\bf n}({f x}) \equiv \phi_{n1}(x1) \phi_{n2}(x2)\]
-

where \({\bf n} \equiv (n1, n2)\) and \({\bf x} \equiv (x1, x2)\).

-

The dimensional two-dimentional basis function is

-
-\[B_{\bf n}({\bf x};\beta) \equiv \beta^{-1/2} \phi_{\bf n}(\beta^{-1}{\bf x}).\]
-
-
-H_n(n, x)[source]
-

constructs the Hermite polynomial of order n at position x (dimensionless)

-
-
Parameters
-
    -
  • n – The n’the basis function.

  • -
  • x (float or numpy array.) – 1-dim position (dimensionless)

  • -
-
-
Returns
-

array– H_n(x).

-
-
-
- -
-
-function(x, y, amp, beta, n1, n2, center_x, center_y)[source]
-

2d cartesian shapelet

-
-
Parameters
-
    -
  • x – x-coordinate

  • -
  • y – y-coordinate

  • -
  • amp – amplitude of shapelet

  • -
  • beta – scale factor of shapelet

  • -
  • n1 – x-order of Hermite polynomial

  • -
  • n2 – y-order of Hermite polynomial

  • -
  • center_x – center in x

  • -
  • center_y – center in y

  • -
-
-
Returns
-

flux surface brighness at (x, y)

-
-
-
- -
-
-hermval(x, n_array, tensor=True)[source]
-

computes the Hermit polynomial as numpy.polynomial.hermite.hermval -difference: for values more than sqrt(n_max + 1) * cut_scale, the value is set to zero -this should be faster and numerically stable

-
-
Parameters
-
    -
  • x – array of values

  • -
  • n_array – list of coeffs in H_n

  • -
  • tensor – see numpy.polynomial.hermite.hermval

  • -
-
-
Returns
-

see numpy.polynomial.hermite.hermval

-
-
-
- -
-
-lower_limit_default = {'amp': 0, 'beta': 0.01, 'center_x': -100, 'center_y': -100, 'n1': 0, 'n2': 0}
-
- -
-
-param_names = ['amp', 'beta', 'n1', 'n2', 'center_x', 'center_y']
-
- -
-
-phi_n(n, x)[source]
-

constructs the 1-dim basis function (formula (1) in Refregier et al. 2001)

-
-
Parameters
-
    -
  • n (int.) – The n’the basis function.

  • -
  • x (float or numpy array.) – 1-dim position (dimensionless)

  • -
-
-
Returns
-

array– phi_n(x).

-
-
-
- -
-
-pre_calc(x, y, beta, n_order, center_x, center_y)[source]
-

calculates the H_n(x) and H_n(y) for a given x-array and y-array for the full order in the polynomials

-
-
Parameters
-
    -
  • x – x-coordinates (numpy array)

  • -
  • y – 7-coordinates (numpy array)

  • -
  • beta – shapelet scale

  • -
  • n_order – order of shapelets

  • -
  • center_x – shapelet center

  • -
  • center_y – shapelet center

  • -
-
-
Returns
-

list of H_n(x) and H_n(y)

-
-
-
- -
-
-upper_limit_default = {'amp': 100, 'beta': 100, 'center_x': 100, 'center_y': 100, 'n1': 150, 'n2': 150}
-
- -
- -
-
-

lenstronomy.LightModel.Profiles.shapelets_polar module

-
-
-class lenstronomy.LightModel.Profiles.shapelets_polar.ShapeletSetPolar(exponential=False)[source]
-

Bases: object

-

class to operate on entire shapelet set

-
-
-decomposition(image, x, y, n_max, beta, deltaPix, center_x=0, center_y=0)[source]
-

decomposes an image into the shapelet coefficients in same order as for the function call -:param image: -:param x: -:param y: -:param n_max: -:param beta: -:param center_x: -:param center_y: -:return:

-
- -
-
-function(x, y, amp, n_max, beta, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • amp

  • -
  • n_max

  • -
  • beta

  • -
  • center_x

  • -
  • center_y

  • -
-
-
Returns
-

-
-
-
- -
-
-function_split(x, y, amp, n_max, beta, center_x=0, center_y=0)[source]
-
- -
-
-index2poly(index)[source]
-
-
Parameters
-

index – index of coefficient in the convention here

-
-
Returns
-

n, m, complex_bool

-
-
-
- -
-
-lower_limit_default = {'beta': 0, 'center_x': -100, 'center_y': -100}
-
- -
-
-param_names = ['amp', 'n_max', 'beta', 'center_x', 'center_y']
-
- -
-
-upper_limit_default = {'beta': 100, 'center_x': 100, 'center_y': 100}
-
- -
- -
-
-class lenstronomy.LightModel.Profiles.shapelets_polar.ShapeletsPolar[source]
-

Bases: object

-

2D polar Shapelets, see Massey & Refregier 2005

-
-
-function(x, y, amp, beta, n, m, complex_bool, center_x, center_y)[source]
-
-
Parameters
-
    -
  • x – x-coordinate, numpy array

  • -
  • y – y-ccordinate, numpy array

  • -
  • amp – amplitude normalization

  • -
  • beta – shaplet scale

  • -
  • n – order of polynomial

  • -
  • m – rotational invariance

  • -
  • complex_bool – boolean; if True uses complex value of function _chi_n_m()

  • -
  • center_x – center of shapelet

  • -
  • center_y – center of shapelet

  • -
-
-
Returns
-

amplitude of shapelet at possition (x, y)

-
-
-
- -
-
-index2poly(index)[source]
-

manages the convention from an iterative index to the specific polynomial n, m, (real/imaginary part)

-
-
Parameters
-

index – int, index of list

-
-
Returns
-

n, m bool

-
-
-
- -
-
-lower_limit_default = {'amp': 0, 'beta': 0, 'center_x': -100, 'center_y': -100, 'm': 0, 'n': 0}
-
- -
-
-static num_param(n_max)[source]
-
-
Parameters
-

n_max – maximal polynomial order

-
-
Returns
-

number of basis components

-
-
-
- -
-
-param_names = ['amp', 'beta', 'n', 'm', 'center_x', 'center_y']
-
- -
-
-static poly2index(n, m, complex_bool)[source]
-
-
Parameters
-
    -
  • n – non-negative integer

  • -
  • m – integer, running from -n to n in steps of two

  • -
  • complex_bool – bool, if True, assigns complex part

  • -
-
-
Returns
-

-
-
-
- -
-
-upper_limit_default = {'amp': 100, 'beta': 100, 'center_x': 100, 'center_y': 100, 'm': 150, 'n': 150}
-
- -
- -
-
-class lenstronomy.LightModel.Profiles.shapelets_polar.ShapeletsPolarExp[source]
-

Bases: object

-

2D exponential shapelets, Berge et al. 2019

-
-
-function(x, y, amp, beta, n, m, complex_bool, center_x, center_y)[source]
-
-
Parameters
-
    -
  • x – x-coordinate, numpy array

  • -
  • y – y-ccordinate, numpy array

  • -
  • amp – amplitude normalization

  • -
  • beta – shaplet scale

  • -
  • n – order of polynomial

  • -
  • m – rotational invariance

  • -
  • complex_bool – boolean; if True uses complex value of function _chi_n_m()

  • -
  • center_x – center of shapelet

  • -
  • center_y – center of shapelet

  • -
-
-
Returns
-

amplitude of shapelet at possition (x, y)

-
-
-
- -
-
-index2poly(index)[source]
-
-
Parameters
-

index

-
-
Returns
-

-
-
-
- -
-
-lower_limit_default = {'amp': 0, 'beta': 0, 'center_x': -100, 'center_y': -100, 'm': 0, 'n': 0}
-
- -
-
-static num_param(n_max)[source]
-
-
Parameters
-

n_max – maximal polynomial order

-
-
Returns
-

number of basis components

-
-
-
- -
-
-param_names = ['amp', 'beta', 'n', 'm', 'center_x', 'center_y']
-
- -
-
-static poly2index(n, m, complex_bool)[source]
-
-
Parameters
-
    -
  • n

  • -
  • m

  • -
  • complex_bool

  • -
-
-
Returns
-

index convention, integer

-
-
-
- -
-
-upper_limit_default = {'amp': 100, 'beta': 100, 'center_x': 100, 'center_y': 100, 'm': 150, 'n': 150}
-
- -
- -
-
-

lenstronomy.LightModel.Profiles.uniform module

-
-
-class lenstronomy.LightModel.Profiles.uniform.Uniform[source]
-

Bases: object

-

uniform light profile. This profile can also compensate for an inaccurate background subtraction. -name for profile: ‘UNIFORM’

-
-
-function(x, y, amp)[source]
-
-
Parameters
-
    -
  • x – x-coordinate

  • -
  • y – y-coordinate

  • -
  • amp – surface brightness

  • -
-
-
Returns
-

constant flux

-
-
-
- -
-
-lower_limit_default = {'amp': -100}
-
- -
-
-param_names = ['amp']
-
- -
-
-upper_limit_default = {'amp': 100}
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.LightModel.html b/docs/_build/html/lenstronomy.LightModel.html deleted file mode 100644 index 2fb3a1048..000000000 --- a/docs/_build/html/lenstronomy.LightModel.html +++ /dev/null @@ -1,238 +0,0 @@ - - - - - - - - - lenstronomy.LightModel package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.LightModel package

-
-

Subpackages

- -
-
-

Submodules

-
-
-

lenstronomy.LightModel.light_model module

-
-
-class lenstronomy.LightModel.light_model.LightModel(light_model_list, deflection_scaling_list=None, source_redshift_list=None, smoothing=0.001, sersic_major_axis=None)[source]
-

Bases: lenstronomy.LightModel.linear_basis.LinearBasis

-

class to handle extended surface brightness profiles (for e.g. source and lens light)

-

all profiles come with a surface_brightness parameterization (in units per square angle and independent of -the pixel scale). -The parameter ‘amp’ is the linear scaling parameter of surface brightness. -Some functional forms come with a total_flux() definition that provide the integral of the surface brightness for a -given set of parameters.

-

The SimulationAPI module allows to use astronomical magnitudes to be used and translated into the surface brightness -conventions of this module given a magnitude zero point.

-
- -
-
-

lenstronomy.LightModel.light_param module

-
-
-class lenstronomy.LightModel.light_param.LightParam(light_model_list, kwargs_fixed, kwargs_lower=None, kwargs_upper=None, param_type='light', linear_solver=True)[source]
-

Bases: object

-

class manages the parameters corresponding to the LightModel() module. Also manages linear parameter handling.

-
-
-get_params(args, i)[source]
-
-
Parameters
-
    -
  • args – list of floats corresponding ot the arguments being sampled

  • -
  • i – int, index of the first argument that is managed/read-out by this class

  • -
-
-
Returns
-

keyword argument list of the light profile, index after reading out the arguments corresponding to -this class

-
-
-
- -
-
-num_param()[source]
-
-
Returns
-

int, list of strings with param names

-
-
-
- -
-
-num_param_linear()[source]
-
-
Returns
-

number of linear basis set coefficients

-
-
-
- -
-
-property param_name_list
-
- -
-
-set_params(kwargs_list)[source]
-
-
Parameters
-

kwargs_list – list of keyword arguments of the light profile (free parameter as well as optionally the -fixed ones)

-
-
Returns
-

list of floats corresponding to the free parameters

-
-
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.Plots.html b/docs/_build/html/lenstronomy.Plots.html deleted file mode 100644 index 2026656b7..000000000 --- a/docs/_build/html/lenstronomy.Plots.html +++ /dev/null @@ -1,1005 +0,0 @@ - - - - - - - - - lenstronomy.Plots package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.Plots package

-
-

Submodules

-
-
-

lenstronomy.Plots.chain_plot module

-
-
-lenstronomy.Plots.chain_plot.plot_chain(chain, param_list)[source]
-
- -
-
-lenstronomy.Plots.chain_plot.plot_chain_list(chain_list, index=0, num_average=100)[source]
-

plots the output of a chain of samples (MCMC or PSO) with the some diagnostics of convergence. -This routine is an example and more tests might be appropriate to analyse a specific chain.

-
-
Parameters
-
    -
  • chain_list – list of chains with arguments [type string, samples etc…]

  • -
  • index – index of chain to be plotted

  • -
  • num_average – in chains, number of steps to average over in plotting diagnostics

  • -
-
-
Returns
-

plotting instance

-
-
-
- -
-
-lenstronomy.Plots.chain_plot.plot_mcmc_behaviour(ax, samples_mcmc, param_mcmc, dist_mcmc=None, num_average=100)[source]
-

plots the MCMC behaviour and looks for convergence of the chain

-
-
Parameters
-
    -
  • ax – matplotlib.axis instance

  • -
  • samples_mcmc – parameters sampled 2d numpy array

  • -
  • param_mcmc – list of parameters

  • -
  • dist_mcmc – log likelihood of the chain

  • -
  • num_average – number of samples to average (should coincide with the number of samples in the emcee process)

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Plots.chain_plot.psf_iteration_compare(kwargs_psf, **kwargs)[source]
-
-
Parameters
-
    -
  • kwargs_psf

  • -
  • kwargs – kwargs to send to matplotlib.pyplot.matshow()

  • -
-
-
Returns
-

-
-
-
- -
-
-

lenstronomy.Plots.lens_plot module

-
-
-lenstronomy.Plots.lens_plot.arrival_time_surface(ax, lensModel, kwargs_lens, numPix=500, deltaPix=0.01, sourcePos_x=0, sourcePos_y=0, with_caustics=False, point_source=False, n_levels=10, kwargs_contours=None, image_color_list=None, letter_font_size=20)[source]
-
-
Parameters
-
    -
  • ax – matplotlib axis instance

  • -
  • lensModel – LensModel() class instance

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • numPix

  • -
  • deltaPix

  • -
  • sourcePos_x

  • -
  • sourcePos_y

  • -
  • with_caustics

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Plots.lens_plot.curved_arc_illustration(ax, lensModel, kwargs_lens, with_centroid=True, stretch_scale=0.1, color='k')[source]
-
-
Parameters
-
    -
  • ax – matplotlib axis instance

  • -
  • lensModel – LensModel() instance

  • -
  • kwargs_lens – list of lens model keyword arguments (only those of CURVED_ARC considered

  • -
  • with_centroid – plots the center of the curvature radius

  • -
  • stretch_scale – float, relative scale of banana to the tangential and radial stretches (effectively intrinsic source size)

  • -
  • color – string, matplotlib color for plot

  • -
-
-
Returns
-

matplotlib axis instance

-
-
-
- -
-
-lenstronomy.Plots.lens_plot.distortions(lensModel, kwargs_lens, num_pix=100, delta_pix=0.05, center_ra=0, center_dec=0, differential_scale=0.0001, smoothing_scale=None, **kwargs)[source]
-
-
Parameters
-
    -
  • lensModel – LensModel instance

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • num_pix – number of pixels per axis

  • -
  • delta_pix – pixel scale per axis

  • -
  • center_ra – center of the grid

  • -
  • center_dec – center of the grid

  • -
  • differential_scale – scale of the finite derivative length in units of angles

  • -
  • smoothing_scale – float or None, Gaussian FWHM of a smoothing kernel applied before plotting

  • -
-
-
Returns
-

matplotlib instance with different panels

-
-
-
- -
-
-lenstronomy.Plots.lens_plot.lens_model_plot(ax, lensModel, kwargs_lens, numPix=500, deltaPix=0.01, sourcePos_x=0, sourcePos_y=0, point_source=False, with_caustics=False, with_convergence=True, coord_center_ra=0, coord_center_dec=0, coord_inverse=False, fast_caustic=True, **kwargs)[source]
-

plots a lens model (convergence) and the critical curves and caustics

-
-
Parameters
-
    -
  • ax – matplotlib axis instance

  • -
  • lensModel – LensModel() class instance

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • numPix – total nnumber of pixels (for convergence map)

  • -
  • deltaPix – width of pixel (total frame size is deltaPix x numPix)

  • -
  • sourcePos_x – float, x-position of point source (image positions computed by the lens equation)

  • -
  • sourcePos_y – float, y-position of point source (image positions computed by the lens equation)

  • -
  • point_source – bool, if True, illustrates and computes the image positions of the point source

  • -
  • with_caustics – bool, if True, illustrates the critical curve and caustics of the system

  • -
  • with_convergence – bool, if True, illustrates the convergence map

  • -
  • coord_center_ra – float, x-coordinate of the center of the frame

  • -
  • coord_center_dec – float, y-coordinate of the center of the frame

  • -
  • coord_inverse – bool, if True, inverts the x-coordinates to go from right-to-left -(effectively the RA definition)

  • -
  • fast_caustic – boolean, if True, uses faster but less precise caustic calculation -(might have troubles for the outer caustic (inner critical curve)

  • -
  • with_convergence – boolean, if True, plots the convergence of the deflector

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Plots.lens_plot.plot_arc(ax, tangential_stretch, radial_stretch, curvature, direction, center_x, center_y, stretch_scale=0.1, with_centroid=True, linewidth=1, color='k', dtan_dtan=0)[source]
-
-
Parameters
-
    -
  • ax – matplotlib.axes instance

  • -
  • tangential_stretch – float, stretch of intrinsic source in tangential direction

  • -
  • radial_stretch – float, stretch of intrinsic source in radial direction

  • -
  • curvature – 1/curvature radius

  • -
  • direction – float, angle in radian

  • -
  • center_x – center of source in image plane

  • -
  • center_y – center of source in image plane

  • -
  • with_centroid – plots the center of the curvature radius

  • -
  • stretch_scale – float, relative scale of banana to the tangential and radial stretches -(effectively intrinsic source size)

  • -
  • dtan_dtan – tangential eigenvector differential in tangential direction (not implemented yet as illustration)

  • -
-
-
Returns
-

-
-
-
- -
-
-

lenstronomy.Plots.model_band_plot module

-
-
-class lenstronomy.Plots.model_band_plot.ModelBandPlot(multi_band_list, kwargs_model, model, error_map, cov_param, param, kwargs_params, likelihood_mask_list=None, band_index=0, arrow_size=0.02, cmap_string='gist_heat', fast_caustic=True)[source]
-

Bases: lenstronomy.Analysis.image_reconstruction.ModelBand

-

class to plot a single band given the modeling results

-
-
-absolute_residual_plot(ax, v_min=- 1, v_max=1, font_size=15, text='Residuals', colorbar_label='(f$_{model}$-f$_{data}$)')[source]
-
-
Parameters
-

ax

-
-
Returns
-

-
-
-
- -
-
-convergence_plot(ax, text='Convergence', v_min=None, v_max=None, font_size=15, colorbar_label='$\\log_{10}\\ \\kappa$', **kwargs)[source]
-
-
Parameters
-

ax – matplotib axis instance

-
-
Returns
-

convergence plot in ax instance

-
-
-
- -
-
-data_plot(ax, v_min=None, v_max=None, text='Observed', font_size=15, colorbar_label='log$_{10}$ flux', **kwargs)[source]
-
-
Parameters
-

ax

-
-
Returns
-

-
-
-
- -
-
-decomposition_plot(ax, text='Reconstructed', v_min=None, v_max=None, unconvolved=False, point_source_add=False, font_size=15, source_add=False, lens_light_add=False, **kwargs)[source]
-
-
Parameters
-
    -
  • ax

  • -
  • text

  • -
  • v_min

  • -
  • v_max

  • -
  • unconvolved

  • -
  • point_source_add

  • -
  • source_add

  • -
  • lens_light_add

  • -
  • kwargs – kwargs to send matplotlib.pyplot.matshow()

  • -
-
-
Returns
-

-
-
-
- -
-
-deflection_plot(ax, v_min=None, v_max=None, axis=0, with_caustics=False, image_name_list=None, text='Deflection model', font_size=15, colorbar_label='arcsec')[source]
-
-
Returns
-

-
-
-
- -
-
-error_map_source_plot(ax, numPix, deltaPix_source, v_min=None, v_max=None, with_caustics=False, font_size=15, point_source_position=True)[source]
-

plots the uncertainty in the surface brightness in the source from the linear inversion by taking the diagonal -elements of the covariance matrix of the inversion of the basis set to be propagated to the source plane. -#TODO illustration of the uncertainties in real space with the full covariance matrix is subtle. The best way is probably to draw realizations from the covariance matrix.

-
-
Parameters
-
    -
  • ax – matplotlib axis instance

  • -
  • numPix – number of pixels in plot per axis

  • -
  • deltaPix_source – pixel spacing in the source resolution illustrated in plot

  • -
  • v_min – minimum plotting scale of the map

  • -
  • v_max – maximum plotting scale of the map

  • -
  • with_caustics – plot the caustics on top of the source reconstruction (may take some time)

  • -
  • font_size – font size of labels

  • -
  • point_source_position – boolean, if True, plots a point at the position of the point source

  • -
-
-
Returns
-

plot of source surface brightness errors in the reconstruction on the axis instance

-
-
-
- -
-
-magnification_plot(ax, v_min=- 10, v_max=10, image_name_list=None, font_size=15, no_arrow=False, text='Magnification model', colorbar_label='$\\det\\ (\\mathsf{A}^{-1})$', **kwargs)[source]
-
-
Parameters
-
    -
  • ax – matplotib axis instance

  • -
  • v_min – minimum range of plotting

  • -
  • v_max – maximum range of plotting

  • -
  • kwargs – kwargs to send to matplotlib.pyplot.matshow()

  • -
-
-
Returns
-

-
-
-
- -
-
-model_plot(ax, v_min=None, v_max=None, image_names=False, colorbar_label='log$_{10}$ flux', font_size=15, text='Reconstructed', **kwargs)[source]
-
-
Parameters
-
    -
  • ax – matplotib axis instance

  • -
  • v_min

  • -
  • v_max

  • -
-
-
Returns
-

-
-
-
- -
-
-normalized_residual_plot(ax, v_min=- 6, v_max=6, font_size=15, text='Normalized Residuals', colorbar_label='(f${}_{\\rm model}$ - f${}_{\\rm data}$)/$\\sigma$', no_arrow=False, color_bar=True, **kwargs)[source]
-
-
Parameters
-
    -
  • ax

  • -
  • v_min

  • -
  • v_max

  • -
  • kwargs – kwargs to send to matplotlib.pyplot.matshow()

  • -
  • color_bar – Option to display the color bar

  • -
-
-
Returns
-

-
-
-
- -
-
-plot_extinction_map(ax, v_min=None, v_max=None, **kwargs)[source]
-
-
Parameters
-
    -
  • ax

  • -
  • v_min

  • -
  • v_max

  • -
-
-
Returns
-

-
-
-
- -
-
-plot_main(with_caustics=False)[source]
-

print the main plots together in a joint frame

-
-
Returns
-

-
-
-
- -
-
-plot_separate()[source]
-

plot the different model components separately

-
-
Returns
-

-
-
-
- -
-
-plot_subtract_from_data_all()[source]
-

subtract model components from data

-
-
Returns
-

-
-
-
- -
-
-source(numPix, deltaPix, center=None, image_orientation=True)[source]
-
-
Parameters
-
    -
  • numPix – number of pixels per axes

  • -
  • deltaPix – pixel size

  • -
  • image_orientation – bool, if True, uses frame in orientation of the image, otherwise in RA-DEC coordinates

  • -
-
-
Returns
-

2d surface brightness grid of the reconstructed source and Coordinates() instance of source grid

-
-
-
- -
-
-source_plot(ax, numPix, deltaPix_source, center=None, v_min=None, v_max=None, with_caustics=False, caustic_color='yellow', font_size=15, plot_scale='log', scale_size=0.1, text='Reconstructed source', colorbar_label='log$_{10}$ flux', point_source_position=True, **kwargs)[source]
-
-
Parameters
-
    -
  • ax

  • -
  • numPix

  • -
  • deltaPix_source

  • -
  • center – [center_x, center_y], if specified, uses this as the center

  • -
  • v_min

  • -
  • v_max

  • -
  • caustic_color

  • -
  • font_size

  • -
  • plot_scale – string, log or linear, scale of surface brightness plot

  • -
  • kwargs

  • -
-
-
Returns
-

-
-
-
- -
-
-subtract_from_data_plot(ax, text='Subtracted', v_min=None, v_max=None, point_source_add=False, source_add=False, lens_light_add=False, font_size=15)[source]
-
- -
- -
-
-

lenstronomy.Plots.model_plot module

-
-
-class lenstronomy.Plots.model_plot.ModelPlot(multi_band_list, kwargs_model, kwargs_params, image_likelihood_mask_list=None, bands_compute=None, multi_band_type='multi-linear', source_marg=False, linear_prior=None, arrow_size=0.02, cmap_string='gist_heat', fast_caustic=True)[source]
-

Bases: object

-

class that manages the summary plots of a lens model -The class uses the same conventions as being used in the FittingSequence and interfaces with the ImSim module. -The linear inversion is re-done given the likelihood settings in the init of this class (make sure this is the same -as you perform the FittingSequence) to make sure the linear amplitude parameters are computed as they are not part -of the output of the FittingSequence results.

-
-
-absolute_residual_plot(band_index=0, **kwargs)[source]
-

illustrates absolute residuals between data and model fit

-
-
Parameters
-
    -
  • band_index – index of band

  • -
  • kwargs – arguments of plotting

  • -
-
-
Returns
-

plot instance

-
-
-
- -
-
-convergence_plot(band_index=0, **kwargs)[source]
-

illustrates lensing convergence in data frame

-
-
Parameters
-
    -
  • band_index – index of band

  • -
  • kwargs – arguments of plotting

  • -
-
-
Returns
-

plot instance

-
-
-
- -
-
-data_plot(band_index=0, **kwargs)[source]
-

illustrates data

-
-
Parameters
-
    -
  • band_index – index of band

  • -
  • kwargs – arguments of plotting

  • -
-
-
Returns
-

plot instance

-
-
-
- -
-
-decomposition_plot(band_index=0, **kwargs)[source]
-

illustrates decomposition of model components

-
-
Parameters
-
    -
  • band_index – index of band

  • -
  • kwargs – arguments of plotting

  • -
-
-
Returns
-

plot instance

-
-
-
- -
-
-deflection_plot(band_index=0, **kwargs)[source]
-

illustrates lensing deflections on the field of view of the data frame

-
-
Parameters
-
    -
  • band_index – index of band

  • -
  • kwargs – arguments of plotting

  • -
-
-
Returns
-

plot instance

-
-
-
- -
-
-error_map_source_plot(band_index=0, **kwargs)[source]
-

illustrates surface brightness variance in the reconstruction in the source plane

-
-
Parameters
-
    -
  • band_index – index of band

  • -
  • kwargs – arguments of plotting

  • -
-
-
Returns
-

plot instance

-
-
-
- -
-
-magnification_plot(band_index=0, **kwargs)[source]
-

illustrates lensing magnification in the field of view of the data frame

-
-
Parameters
-
    -
  • band_index – index of band

  • -
  • kwargs – arguments of plotting

  • -
-
-
Returns
-

plot instance

-
-
-
- -
-
-model_plot(band_index=0, **kwargs)[source]
-

illustrates model

-
-
Parameters
-
    -
  • band_index – index of band

  • -
  • kwargs – arguments of plotting

  • -
-
-
Returns
-

plot instance

-
-
-
- -
-
-normalized_residual_plot(band_index=0, **kwargs)[source]
-

illustrates normalized residuals between data and model fit

-
-
Parameters
-
    -
  • band_index – index of band

  • -
  • kwargs – arguments of plotting

  • -
-
-
Returns
-

plot instance

-
-
-
- -
-
-plot_extinction_map(band_index=0, **kwargs)[source]
-
-
Parameters
-
    -
  • band_index – index of band

  • -
  • kwargs – arguments of plotting

  • -
-
-
Returns
-

plot instance of differential extinction map

-
-
-
- -
-
-plot_main(band_index=0, **kwargs)[source]
-

plot a set of ‘main’ modelling diagnostics

-
-
Parameters
-
    -
  • band_index – index of band

  • -
  • kwargs – arguments of plotting

  • -
-
-
Returns
-

plot instance

-
-
-
- -
-
-plot_separate(band_index=0)[source]
-

plot a set of ‘main’ modelling diagnostics

-
-
Parameters
-

band_index – index of band

-
-
Returns
-

plot instance

-
-
-
- -
-
-plot_subtract_from_data_all(band_index=0)[source]
-

plot a set of ‘main’ modelling diagnostics

-
-
Parameters
-

band_index – index of band

-
-
Returns
-

plot instance

-
-
-
- -
-
-reconstruction_all_bands(**kwargs)[source]
-
-
Parameters
-

kwargs – arguments of plotting

-
-
Returns
-

3 x n_data plot with data, model, reduced residual plots of all the images/bands that are being modeled

-
-
-
- -
-
-source(band_index=0, **kwargs)[source]
-
-
Parameters
-
    -
  • band_index – index of band

  • -
  • kwargs – keyword arguments accessible in model_band_plot.source()

  • -
-
-
Returns
-

2d array of source surface brightness

-
-
-
- -
-
-source_plot(band_index=0, **kwargs)[source]
-

illustrates reconstructed source (de-lensed de-convolved)

-
-
Parameters
-
    -
  • band_index – index of band

  • -
  • kwargs – arguments of plotting

  • -
-
-
Returns
-

plot instance

-
-
-
- -
-
-subtract_from_data_plot(band_index=0, **kwargs)[source]
-

subtracts individual model components from the data

-
-
Parameters
-
    -
  • band_index – index of band

  • -
  • kwargs – arguments of plotting

  • -
-
-
Returns
-

plot instance

-
-
-
- -
- -
-
-

lenstronomy.Plots.plot_util module

-
-
-lenstronomy.Plots.plot_util.cmap_conf(cmap_string)[source]
-

configures matplotlib color map

-
-
Parameters
-

cmap_string – string of cmap name, or cmap instance

-
-
Returns
-

cmap instance with setting for bad pixels and values below the threshold

-
-
-
- -
-
-lenstronomy.Plots.plot_util.coordinate_arrows(ax, d, coords, color='w', font_size=15, arrow_size=0.05)[source]
-
- -
-
-lenstronomy.Plots.plot_util.image_position_plot(ax, coords, ra_image, dec_image, color='w', image_name_list=None, origin=None, flipped_x=False, pixel_offset=True)[source]
-
-
Parameters
-
    -
  • ax – matplotlib axis instance

  • -
  • coords – Coordinates() class instance or inherited class (such as PixelGrid(), or Data())

  • -
  • ra_image – Ra/x-coordinates of image positions (list of arrays in angular units)

  • -
  • dec_image – Dec/y-coordinates of image positions (list of arrays in angular units)

  • -
  • color – color of ticks and text

  • -
  • image_name_list – list of strings for names of the images in the same order as the positions

  • -
  • origin – [x0, y0], lower left pixel coordinate in the frame of the pixels

  • -
  • flipped_x – bool, if True, flips x-axis

  • -
  • pixel_offset – boolean; if True (default plotting), the coordinates are shifted a half a pixel to match with -the matshow() command to center the coordinates in the pixel center

  • -
-
-
Returns
-

matplotlib axis instance with images plotted on

-
-
-
- -
-
-lenstronomy.Plots.plot_util.plot_line_set(ax, coords, line_set_list_x, line_set_list_y, origin=None, flipped_x=False, points_only=False, pixel_offset=True, *args, **kwargs)[source]
-

plotting a line set on a matplotlib instance where the coordinates are defined in pixel units with the lower left -corner (defined as origin) is by default (0, 0). The coordinates are moved by 0.5 pixels to be placed in the center -of the pixel in accordance with the matplotlib.matshow() routine.

-
-
Parameters
-
    -
  • ax – matplotlib.axis instance

  • -
  • coords – Coordinates() class instance

  • -
  • origin – [x0, y0], lower left pixel coordinate in the frame of the pixels

  • -
  • line_set_list_x – numpy arrays corresponding of different disconnected regions of the line -(e.g. caustic or critical curve)

  • -
  • line_set_list_y – numpy arrays corresponding of different disconnected regions of the line -(e.g. caustic or critical curve)

  • -
  • color – string with matplotlib color

  • -
  • flipped_x – bool, if True, flips x-axis

  • -
  • points_only – bool, if True, sets plotting keywords to plot single points without connecting lines

  • -
  • pixel_offset – boolean; if True (default plotting), the coordinates are shifted a half a pixel to match with -the matshow() command to center the coordinates in the pixel center

  • -
-
-
Returns
-

plot with line sets on matplotlib axis in pixel coordinates

-
-
-
- -
-
-lenstronomy.Plots.plot_util.result_string(x, weights=None, title_fmt='.2f', label=None)[source]
-
-
Parameters
-
    -
  • x – marginalized 1-d posterior

  • -
  • weights – weights of posteriors (optional)

  • -
  • title_fmt – format to what digit the results are presented

  • -
  • label – string of parameter label (optional)

  • -
-
-
Returns
-

string with mean \(\pm\) quartile

-
-
-
- -
-
-lenstronomy.Plots.plot_util.scale_bar(ax, d, dist=1.0, text='1"', color='w', font_size=15, flipped=False)[source]
-
- -
-
-lenstronomy.Plots.plot_util.source_position_plot(ax, coords, ra_source, dec_source, marker='*', markersize=10, **kwargs)[source]
-
-
Parameters
-
    -
  • ax – matplotlib axis instance

  • -
  • coords – Coordinates() class instance or inherited class (such as PixelGrid(), or Data())

  • -
  • ra_source – list of source position in angular units

  • -
  • dec_source – list of source position in angular units

  • -
  • marker – marker style for matplotlib

  • -
  • markersize – marker size for matplotlib

  • -
-
-
Returns
-

matplotlib axis instance with images plotted on

-
-
-
- -
-
-lenstronomy.Plots.plot_util.sqrt(inputArray, scale_min=None, scale_max=None)[source]
-

Performs sqrt scaling of the input numpy array.

-

@type inputArray: numpy array -@param inputArray: image data array -@type scale_min: float -@param scale_min: minimum data value -@type scale_max: float -@param scale_max: maximum data value -@rtype: numpy array -@return: image data array

-
- -
-
-lenstronomy.Plots.plot_util.text_description(ax, d, text, color='w', backgroundcolor='k', flipped=False, font_size=15)[source]
-
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.PointSource.Types.html b/docs/_build/html/lenstronomy.PointSource.Types.html deleted file mode 100644 index b7584a47b..000000000 --- a/docs/_build/html/lenstronomy.PointSource.Types.html +++ /dev/null @@ -1,485 +0,0 @@ - - - - - - - - - lenstronomy.PointSource.Types package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.PointSource.Types package

-
-

Submodules

-
-
-

lenstronomy.PointSource.Types.base_ps module

-
-
-class lenstronomy.PointSource.Types.base_ps.PSBase(lens_model=None, fixed_magnification=False, additional_image=False)[source]
-

Bases: object

-

base point source type class

-
-
-image_amplitude(kwargs_ps, *args, **kwargs)[source]
-

amplitudes as observed on the sky

-
-
Parameters
-
    -
  • kwargs_ps – keyword argument of point source model

  • -
  • kwargs – keyword arguments of function call

  • -
-
-
Returns
-

numpy array of amplitudes

-
-
-
- -
-
-image_position(kwargs_ps, **kwargs)[source]
-

on-sky position

-
-
Parameters
-

kwargs_ps – keyword argument of point source model

-
-
Returns
-

numpy array of x, y image positions

-
-
-
- -
-
-source_amplitude(kwargs_ps, **kwargs)[source]
-

intrinsic source amplitudes (without lensing magnification, but still apparent)

-
-
Parameters
-
    -
  • kwargs_ps – keyword argument of point source model

  • -
  • kwargs – keyword arguments of function call (which are not used for this object

  • -
-
-
Returns
-

numpy array of amplitudes

-
-
-
- -
-
-source_position(kwargs_ps, **kwargs)[source]
-

original unlensed position

-
-
Parameters
-

kwargs_ps – keyword argument of point source model

-
-
Returns
-

numpy array of x, y source positions

-
-
-
- -
-
-update_lens_model(lens_model_class)[source]
-

update LensModel() and LensEquationSolver() instance

-
-
Parameters
-

lens_model_class – LensModel() class instance

-
-
Returns
-

internal lensModel class updated

-
-
-
- -
- -
-
-

lenstronomy.PointSource.Types.lensed_position module

-
-
-class lenstronomy.PointSource.Types.lensed_position.LensedPositions(lens_model=None, fixed_magnification=False, additional_image=False)[source]
-

Bases: lenstronomy.PointSource.Types.base_ps.PSBase

-

class of a a lensed point source parameterized as the (multiple) observed image positions -Name within the PointSource module: ‘LENSED_POSITION’ -parameters: ra_image, dec_image, point_amp -If fixed_magnification=True, than ‘source_amp’ is a parameter instead of ‘point_amp’

-
-
-image_amplitude(kwargs_ps, kwargs_lens=None, x_pos=None, y_pos=None, magnification_limit=None, kwargs_lens_eqn_solver=None)[source]
-

image brightness amplitudes

-
-
Parameters
-
    -
  • kwargs_ps – keyword arguments of the point source model

  • -
  • kwargs_lens – keyword argument list of the lens model(s), only used when requiring the lens equation -solver

  • -
  • x_pos – pre-computed image position (no lens equation solver applied)

  • -
  • y_pos – pre-computed image position (no lens equation solver applied)

  • -
  • magnification_limit – float >0 or None, if float is set and additional images are computed, only those -images will be computed that exceed the lensing magnification (absolute value) limit

  • -
  • kwargs_lens_eqn_solver – keyword arguments specifying the numerical settings for the lens equation solver -see LensEquationSolver() class for details

  • -
-
-
Returns
-

array of image amplitudes

-
-
-
- -
-
-image_position(kwargs_ps, kwargs_lens=None, magnification_limit=None, kwargs_lens_eqn_solver=None)[source]
-

on-sky image positions

-
-
Parameters
-
    -
  • kwargs_ps – keyword arguments of the point source model

  • -
  • kwargs_lens – keyword argument list of the lens model(s), only used when requiring the lens equation -solver

  • -
  • magnification_limit – float >0 or None, if float is set and additional images are computed, only those -images will be computed that exceed the lensing magnification (absolute value) limit

  • -
  • kwargs_lens_eqn_solver – keyword arguments specifying the numerical settings for the lens equation solver -see LensEquationSolver() class for details

  • -
-
-
Returns
-

image positions in x, y as arrays

-
-
-
- -
-
-source_amplitude(kwargs_ps, kwargs_lens=None)[source]
-

intrinsic brightness amplitude of point source -When brightnesses are defined in magnified on-sky positions, the intrinsic brightness is computed as the mean -in the magnification corrected image position brightnesses.

-
-
Parameters
-
    -
  • kwargs_ps – keyword arguments of the point source model

  • -
  • kwargs_lens – keyword argument list of the lens model(s), used when brightness are defined in -magnified on-sky positions

  • -
-
-
Returns
-

brightness amplitude (as numpy array)

-
-
-
- -
-
-source_position(kwargs_ps, kwargs_lens=None)[source]
-

original source position (prior to lensing)

-
-
Parameters
-
    -
  • kwargs_ps – point source keyword arguments

  • -
  • kwargs_lens – lens model keyword argument list (required to ray-trace back in the source plane)

  • -
-
-
Returns
-

x, y position (as numpy arrays)

-
-
-
- -
- -
-
-

lenstronomy.PointSource.Types.source_position module

-
-
-class lenstronomy.PointSource.Types.source_position.SourcePositions(lens_model=None, fixed_magnification=False, additional_image=False)[source]
-

Bases: lenstronomy.PointSource.Types.base_ps.PSBase

-

class of a single point source defined in the original source coordinate position that is lensed. -The lens equation is solved to compute the image positions for the specified source position.

-

Name within the PointSource module: ‘SOURCE_POSITION’ -parameters: ra_source, dec_source, source_amp, mag_pert (optional) -If fixed_magnification=True, than ‘source_amp’ is a parameter instead of ‘point_amp’ -mag_pert is a list of fractional magnification pertubations applied to point source images

-
-
-image_amplitude(kwargs_ps, kwargs_lens=None, x_pos=None, y_pos=None, magnification_limit=None, kwargs_lens_eqn_solver=None)[source]
-

image brightness amplitudes

-
-
Parameters
-
    -
  • kwargs_ps – keyword arguments of the point source model

  • -
  • kwargs_lens – keyword argument list of the lens model(s), only ignored when providing image positions -directly

  • -
  • x_pos – pre-computed image position (no lens equation solver applied)

  • -
  • y_pos – pre-computed image position (no lens equation solver applied)

  • -
  • magnification_limit – float >0 or None, if float is set and additional images are computed, only those -images will be computed that exceed the lensing magnification (absolute value) limit

  • -
  • kwargs_lens_eqn_solver – keyword arguments specifying the numerical settings for the lens equation solver -see LensEquationSolver() class for details

  • -
-
-
Returns
-

array of image amplitudes

-
-
-
- -
-
-image_position(kwargs_ps, kwargs_lens=None, magnification_limit=None, kwargs_lens_eqn_solver=None)[source]
-

on-sky image positions

-
-
Parameters
-
    -
  • kwargs_ps – keyword arguments of the point source model

  • -
  • kwargs_lens – keyword argument list of the lens model(s), only used when requiring the lens equation -solver

  • -
  • magnification_limit – float >0 or None, if float is set and additional images are computed, only those -images will be computed that exceed the lensing magnification (absolute value) limit

  • -
  • kwargs_lens_eqn_solver – keyword arguments specifying the numerical settings for the lens equation solver -see LensEquationSolver() class for details

  • -
-
-
Returns
-

image positions in x, y as arrays

-
-
-
- -
-
-source_amplitude(kwargs_ps, kwargs_lens=None)[source]
-

intrinsic brightness amplitude of point source -When brightnesses are defined in magnified on-sky positions, the intrinsic brightness is computed as the mean -in the magnification corrected image position brightnesses.

-
-
Parameters
-
    -
  • kwargs_ps – keyword arguments of the point source model

  • -
  • kwargs_lens – keyword argument list of the lens model(s), used when brightness are defined in -magnified on-sky positions

  • -
-
-
Returns
-

brightness amplitude (as numpy array)

-
-
-
- -
-
-source_position(kwargs_ps, **kwargs)[source]
-

original source position (prior to lensing)

-
-
Parameters
-

kwargs_ps – point source keyword arguments

-
-
Returns
-

x, y position (as numpy arrays)

-
-
-
- -
- -
-
-

lenstronomy.PointSource.Types.unlensed module

-
-
-class lenstronomy.PointSource.Types.unlensed.Unlensed(lens_model=None, fixed_magnification=False, additional_image=False)[source]
-

Bases: lenstronomy.PointSource.Types.base_ps.PSBase

-

class of a single point source in the image plane, aka star -Name within the PointSource module: ‘UNLENSED’ -This model can deal with arrays of point sources. -parameters: ra_image, dec_image, point_amp

-
-
-image_amplitude(kwargs_ps, **kwargs)[source]
-

amplitudes as observed on the sky

-
-
Parameters
-
    -
  • kwargs_ps – keyword argument of point source model

  • -
  • kwargs – keyword arguments of function call (which are not used for this object

  • -
-
-
Returns
-

numpy array of amplitudes

-
-
-
- -
-
-image_position(kwargs_ps, **kwargs)[source]
-

on-sky position

-
-
Parameters
-

kwargs_ps – keyword argument of point source model

-
-
Returns
-

numpy array of x, y image positions

-
-
-
- -
-
-source_amplitude(kwargs_ps, **kwargs)[source]
-

intrinsic source amplitudes

-
-
Parameters
-
    -
  • kwargs_ps – keyword argument of point source model

  • -
  • kwargs – keyword arguments of function call (which are not used for this object

  • -
-
-
Returns
-

numpy array of amplitudes

-
-
-
- -
-
-source_position(kwargs_ps, **kwargs)[source]
-

original physical position (identical for this object)

-
-
Parameters
-

kwargs_ps – keyword argument of point source model

-
-
Returns
-

numpy array of x, y source positions

-
-
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.PointSource.html b/docs/_build/html/lenstronomy.PointSource.html deleted file mode 100644 index a3ae52beb..000000000 --- a/docs/_build/html/lenstronomy.PointSource.html +++ /dev/null @@ -1,590 +0,0 @@ - - - - - - - - - lenstronomy.PointSource package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.PointSource package

-
-

Subpackages

- -
-
-

Submodules

-
-
-

lenstronomy.PointSource.point_source module

-
-
-class lenstronomy.PointSource.point_source.PointSource(point_source_type_list, lensModel=None, fixed_magnification_list=None, additional_images_list=None, flux_from_point_source_list=None, magnification_limit=None, save_cache=False, kwargs_lens_eqn_solver=None)[source]
-

Bases: object

-
-
-check_image_positions(kwargs_ps, kwargs_lens, tolerance=0.001)[source]
-

checks whether the point sources in kwargs_ps satisfy the lens equation with a tolerance -(computed by ray-tracing in the source plane)

-
-
Parameters
-
    -
  • kwargs_ps – point source keyword argument list

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • tolerance – Eucledian distance between the source positions ray-traced backwards to be tolerated

  • -
-
-
Returns
-

bool: True, if requirement on tolerance is fulfilled, False if not.

-
-
-
- -
-
-classmethod check_positive_flux(kwargs_ps)[source]
-

check whether inferred linear parameters are positive

-
-
Parameters
-

kwargs_ps – point source keyword argument list

-
-
Returns
-

bool, True, if all ‘point_amp’ parameters are positive semi-definite

-
-
-
- -
-
-delete_lens_model_cache()[source]
-

deletes the variables saved for a specific lens model

-
-
Returns
-

None

-
-
-
- -
-
-image_amplitude(kwargs_ps, kwargs_lens, k=None)[source]
-

returns the image amplitudes

-
-
Parameters
-
    -
  • kwargs_ps – point source keyword argument list

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • k – None, int or list of int’s to select a subset of the point source models in the return

  • -
-
-
Returns
-

list of image amplitudes per model component

-
-
-
- -
-
-image_position(kwargs_ps, kwargs_lens, k=None, original_position=False)[source]
-

image positions as observed on the sky of the point sources

-
-
Parameters
-
    -
  • kwargs_ps – point source parameter keyword argument list

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • k – None, int or boolean list; only returns a subset of the model predictions

  • -
  • original_position – boolean (only applies to ‘LENSED_POSITION’ models), returns the image positions in -the model parameters and does not re-compute images (which might be differently ordered) in case of the lens -equation solver

  • -
-
-
Returns
-

list of: list of image positions per point source model component

-
-
-
- -
-
-linear_response_set(kwargs_ps, kwargs_lens=None, with_amp=False)[source]
-
-
Parameters
-
    -
  • kwargs_ps – point source keyword argument list

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • with_amp – bool, if True returns the image amplitude derived from kwargs_ps, -otherwise the magnification of the lens model

  • -
-
-
Returns
-

ra_pos, dec_pos, amp, n

-
-
-
- -
-
-num_basis(kwargs_ps, kwargs_lens)[source]
-

number of basis functions for linear inversion

-
-
Parameters
-
    -
  • kwargs_ps – point source keyword argument list

  • -
  • kwargs_lens – lens model keyword argument list

  • -
-
-
Returns
-

int

-
-
-
- -
-
-point_source_list(kwargs_ps, kwargs_lens, k=None, with_amp=True)[source]
-

returns the coordinates and amplitudes of all point sources in a single array

-
-
Parameters
-
    -
  • kwargs_ps – point source keyword argument list

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • k – None, int or list of int’s to select a subset of the point source models in the return

  • -
  • with_amp – bool, if False, ignores the amplitude parameters in the return and instead provides ones for -each point source image

  • -
-
-
Returns
-

ra_array, dec_array, amp_array

-
-
-
- -
-
-set_amplitudes(amp_list, kwargs_ps)[source]
-

translates the amplitude parameters into the convention of the keyword argument list -currently only used in SimAPI to transform magnitudes to amplitudes in the lenstronomy conventions

-
-
Parameters
-
    -
  • amp_list – list of model amplitudes for each point source model

  • -
  • kwargs_ps – list of point source keywords

  • -
-
-
Returns
-

overwrites kwargs_ps with new amplitudes

-
-
-
- -
-
-set_save_cache(save_cache)[source]
-

set the save cache boolean to new value

-
-
Parameters
-

save_cache – bool, if True, saves (or uses a previously saved) values

-
-
Returns
-

updated class and sub-class instances to either save or not save the point source information in cache

-
-
-
- -
-
-source_amplitude(kwargs_ps, kwargs_lens)[source]
-

intrinsic (unlensed) point source amplitudes

-
-
Parameters
-
    -
  • kwargs_ps – point source keyword argument list

  • -
  • kwargs_lens – lens model keyword argument list

  • -
-
-
Returns
-

list of intrinsic (unlensed) point source amplitudes

-
-
-
- -
-
-source_position(kwargs_ps, kwargs_lens)[source]
-

intrinsic source positions of the point sources

-
-
Parameters
-
    -
  • kwargs_ps – keyword argument list of point source models

  • -
  • kwargs_lens – keyword argument list of lens models

  • -
-
-
Returns
-

list of source positions for each point source model

-
-
-
- -
-
-update_lens_model(lens_model_class)[source]
-
-
Parameters
-

lens_model_class – instance of LensModel class

-
-
Returns
-

update instance of lens model class

-
-
-
- -
-
-update_linear(param, i, kwargs_ps, kwargs_lens)[source]
-
-
Parameters
-
    -
  • param – list of floats corresponding ot the parameters being sampled

  • -
  • i – index of the first parameter relevant for this class

  • -
  • kwargs_ps – point source keyword argument list

  • -
  • kwargs_lens – lens model keyword argument list

  • -
-
-
Returns
-

kwargs_ps with updated linear parameters, index of the next parameter relevant for another class

-
-
-
- -
-
-update_search_window(search_window, x_center, y_center, min_distance=None, only_from_unspecified=False)[source]
-

update the search area for the lens equation solver

-
-
Parameters
-
    -
  • search_window – search_window: window size of the image position search with the lens equation solver.

  • -
  • x_center – center of search window

  • -
  • y_center – center of search window

  • -
  • min_distance – minimum search distance

  • -
  • only_from_unspecified – bool, if True, only sets keywords that previously have not been set

  • -
-
-
Returns
-

updated self instances

-
-
-
- -
- -
-
-

lenstronomy.PointSource.point_source_cached module

-
-
-class lenstronomy.PointSource.point_source_cached.PointSourceCached(point_source_model, save_cache=False)[source]
-

Bases: object

-

This class is the same as PointSource() except that it saves image and source positions in cache. -This speeds-up repeated calls for the same source and lens model and avoids duplicating the lens equation solving. -Attention: cache needs to be deleted before calling functions with different lens and point source parameters.

-
-
-delete_lens_model_cache()[source]
-
- -
-
-image_amplitude(kwargs_ps, kwargs_lens=None, magnification_limit=None, kwargs_lens_eqn_solver=None)[source]
-

image brightness amplitudes

-
-
Parameters
-
    -
  • kwargs_ps – keyword arguments of the point source model

  • -
  • kwargs_lens – keyword argument list of the lens model(s), only used when requiring the lens equation -solver

  • -
  • magnification_limit – float >0 or None, if float is set and additional images are computed, only those -images will be computed that exceed the lensing magnification (absolute value) limit

  • -
  • kwargs_lens_eqn_solver – keyword arguments specifying the numerical settings for the lens equation solver -see LensEquationSolver() class for details

  • -
-
-
Returns
-

array of image amplitudes

-
-
-
- -
-
-image_position(kwargs_ps, kwargs_lens=None, magnification_limit=None, kwargs_lens_eqn_solver=None)[source]
-

on-sky image positions

-
-
Parameters
-
    -
  • kwargs_ps – keyword arguments of the point source model

  • -
  • kwargs_lens – keyword argument list of the lens model(s), only used when requiring the lens equation -solver

  • -
  • magnification_limit – float >0 or None, if float is set and additional images are computed, only those -images will be computed that exceed the lensing magnification (absolute value) limit

  • -
  • kwargs_lens_eqn_solver – keyword arguments specifying the numerical settings for the lens equation solver -see LensEquationSolver() class for details

  • -
-
-
Returns
-

image positions in x, y as arrays

-
-
-
- -
-
-set_save_cache(save_bool)[source]
-
- -
-
-source_amplitude(kwargs_ps, kwargs_lens=None)[source]
-

intrinsic brightness amplitude of point source

-
-
Parameters
-
    -
  • kwargs_ps – keyword arguments of the point source model

  • -
  • kwargs_lens – keyword argument list of the lens model(s), only used when positions are defined in image -plane and have to be ray-traced back

  • -
-
-
Returns
-

brightness amplitude (as numpy array)

-
-
-
- -
-
-source_position(kwargs_ps, kwargs_lens=None)[source]
-

original source position (prior to lensing)

-
-
Parameters
-
    -
  • kwargs_ps – point source keyword arguments

  • -
  • kwargs_lens – lens model keyword argument list (only used when required)

  • -
-
-
Returns
-

x, y position

-
-
-
- -
-
-update_lens_model(lens_model_class)[source]
-
- -
- -
-
-

lenstronomy.PointSource.point_source_param module

-
-
-class lenstronomy.PointSource.point_source_param.PointSourceParam(model_list, kwargs_fixed, num_point_source_list=None, linear_solver=True, fixed_magnification_list=None, kwargs_lower=None, kwargs_upper=None)[source]
-

Bases: object

-
-
-add_fix_linear(kwargs_fixed)[source]
-

updates fixed keyword argument list with linear parameters

-
-
Parameters
-

kwargs_fixed – list of keyword arguments held fixed during sampling

-
-
Returns
-

updated keyword argument list

-
-
-
- -
-
-get_params(args, i)[source]
-
-
Parameters
-
    -
  • args – sorted list of floats corresponding to the parameters being sampled

  • -
  • i – int, index of first entry relevant for being managed by this class

  • -
-
-
Returns
-

keyword argument list of point sources, index relevant for the next class

-
-
-
- -
-
-num_param()[source]
-

number of parameters and their names

-
-
Returns
-

int, list of parameter names

-
-
-
- -
-
-num_param_linear()[source]
-
-
Returns
-

number of linear parameters

-
-
-
- -
-
-set_params(kwargs_list)[source]
-
-
Parameters
-

kwargs_list – keyword argument list

-
-
Returns
-

sorted list of parameters being sampled extracted from kwargs_list

-
-
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.Sampling.Likelihoods.html b/docs/_build/html/lenstronomy.Sampling.Likelihoods.html deleted file mode 100644 index 1910b0366..000000000 --- a/docs/_build/html/lenstronomy.Sampling.Likelihoods.html +++ /dev/null @@ -1,357 +0,0 @@ - - - - - - - - - lenstronomy.Sampling.Likelihoods package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.Sampling.Likelihoods package

-
-

Submodules

-
-
-

lenstronomy.Sampling.Likelihoods.image_likelihood module

-
-
-class lenstronomy.Sampling.Likelihoods.image_likelihood.ImageLikelihood(multi_band_list, multi_band_type, kwargs_model, bands_compute=None, image_likelihood_mask_list=None, source_marg=False, linear_prior=None, check_positive_flux=False, kwargs_pixelbased=None)[source]
-

Bases: object

-

manages imaging data likelihoods

-
-
-logL(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_special=None, kwargs_extinction=None)[source]
-
-
Parameters
-
    -
  • kwargs_lens – lens model keyword argument list according to LensModel module

  • -
  • kwargs_source – source light keyword argument list according to LightModel module

  • -
  • kwargs_lens_light – deflector light (not lensed) keyword argument list according to LightModel module

  • -
  • kwargs_ps – point source keyword argument list according to PointSource module

  • -
  • kwargs_special – special keyword argument list as part of the Param module

  • -
  • kwargs_extinction – extinction parameter keyword argument list according to LightModel module

  • -
-
-
Returns
-

log likelihood of the data given the model

-
-
-
- -
-
-property num_data
-
-
Returns
-

number of image data points

-
-
-
- -
-
-num_param_linear(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_special=None, kwargs_extinction=None)[source]
-
-
Returns
-

number of linear parameters solved for during the image reconstruction process

-
-
-
- -
-
-reset_point_source_cache(cache=True)[source]
-
-
Parameters
-

cache – boolean

-
-
Returns
-

-
-
-
- -
- -
-
-

lenstronomy.Sampling.Likelihoods.position_likelihood module

-
-
-class lenstronomy.Sampling.Likelihoods.position_likelihood.PositionLikelihood(point_source_class, image_position_uncertainty=0.005, astrometric_likelihood=False, image_position_likelihood=False, ra_image_list=None, dec_image_list=None, source_position_likelihood=False, check_matched_source_position=False, source_position_tolerance=0.001, source_position_sigma=0.001, force_no_add_image=False, restrict_image_number=False, max_num_images=None)[source]
-

Bases: object

-

likelihood of positions of multiply imaged point sources

-
-
-static astrometric_likelihood(kwargs_ps, kwargs_special, sigma)[source]
-

evaluates the astrometric uncertainty of the model plotted point sources (only available for ‘LENSED_POSITION’ -point source model) and predicted image position by the lens model including an astrometric correction term.

-
-
Parameters
-
    -
  • kwargs_ps – point source model kwargs list

  • -
  • kwargs_special – kwargs list, should include the astrometric corrections ‘delta_x’, ‘delta_y’

  • -
  • sigma – 1-sigma Gaussian uncertainty in the astrometry

  • -
-
-
Returns
-

log likelihood of the astrometirc correction between predicted image positions and model placement of the point sources

-
-
-
- -
-
-check_additional_images(kwargs_ps, kwargs_lens)[source]
-

checks whether additional images have been found and placed in kwargs_ps of the first point source model -#TODO check for all point source models -:param kwargs_ps: point source kwargs -:return: bool, True if more image positions are found than originally been assigned

-
- -
-
-image_position_likelihood(kwargs_ps, kwargs_lens, sigma)[source]
-

computes the likelihood of the model predicted image position relative to measured image positions with an astrometric error. -This routine requires the ‘ra_image_list’ and ‘dec_image_list’ being declared in the initiation of the class

-
-
Parameters
-
    -
  • kwargs_ps – point source keyword argument list

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • sigma – 1-sigma uncertainty in the measured position of the images

  • -
-
-
Returns
-

log likelihood of the model predicted image positions given the data/measured image positions.

-
-
-
- -
-
-logL(kwargs_lens, kwargs_ps, kwargs_special, verbose=False)[source]
-
-
Parameters
-
    -
  • kwargs_lens – lens model parameter keyword argument list

  • -
  • kwargs_ps – point source model parameter keyword argument list

  • -
  • kwargs_special – special keyword arguments

  • -
  • verbose – bool

  • -
-
-
Returns
-

log likelihood of the optional likelihoods being computed

-
-
-
- -
-
-property num_data
-
-
Returns
-

integer, number of data points associated with the class instance

-
-
-
- -
-
-source_position_likelihood(kwargs_lens, kwargs_ps, sigma, hard_bound_rms=None, verbose=False)[source]
-

computes a likelihood/punishing factor of how well the source positions of multiple images match given the image -position and a lens model. -The likelihood level is computed in respect of a displacement in the image plane and transposed through the -Hessian into the source plane.

-
-
Parameters
-
    -
  • kwargs_lens – lens model keyword argument list

  • -
  • kwargs_ps – point source keyword argument list

  • -
  • sigma – 1-sigma Gaussian uncertainty in the image plane

  • -
  • hard_bound_rms – hard bound deviation between the mapping of the images back to the source plane (in source frame)

  • -
  • verbose – bool, if True provides print statements with useful information.

  • -
-
-
Returns
-

log likelihood of the model reproducing the correct image positions given an image position uncertainty

-
-
-
- -
- -
-
-

lenstronomy.Sampling.Likelihoods.prior_likelihood module

-
-
-class lenstronomy.Sampling.Likelihoods.prior_likelihood.PriorLikelihood(prior_lens=None, prior_source=None, prior_lens_light=None, prior_ps=None, prior_special=None, prior_extinction=None, prior_lens_kde=None, prior_source_kde=None, prior_lens_light_kde=None, prior_ps_kde=None, prior_special_kde=None, prior_extinction_kde=None, prior_lens_lognormal=None, prior_source_lognormal=None, prior_lens_light_lognormal=None, prior_ps_lognormal=None, prior_special_lognormal=None, prior_extinction_lognormal=None)[source]
-

Bases: object

-

class containing additional Gaussian priors to be folded into the likelihood

-
-
-logL(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_special=None, kwargs_extinction=None)[source]
-
-
Parameters
-

kwargs_lens – lens model parameter list

-
-
Returns
-

log likelihood of lens center

-
-
-
- -
- -
-
-

lenstronomy.Sampling.Likelihoods.time_delay_likelihood module

-
-
-class lenstronomy.Sampling.Likelihoods.time_delay_likelihood.TimeDelayLikelihood(time_delays_measured, time_delays_uncertainties, lens_model_class, point_source_class)[source]
-

Bases: object

-

class to compute the likelihood of a model given a measurement of time delays

-
-
-logL(kwargs_lens, kwargs_ps, kwargs_cosmo)[source]
-

routine to compute the log likelihood of the time delay distance -:param kwargs_lens: lens model kwargs list -:param kwargs_ps: point source kwargs list -:param kwargs_cosmo: cosmology and other kwargs -:return: log likelihood of the model given the time delay data

-
- -
-
-property num_data
-
-
Returns
-

number of time delay measurements

-
-
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.Sampling.Pool.html b/docs/_build/html/lenstronomy.Sampling.Pool.html deleted file mode 100644 index 044739a94..000000000 --- a/docs/_build/html/lenstronomy.Sampling.Pool.html +++ /dev/null @@ -1,248 +0,0 @@ - - - - - - - - - lenstronomy.Sampling.Pool package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.Sampling.Pool package

-
-

Submodules

-
-
-

lenstronomy.Sampling.Pool.multiprocessing module

-

this file is taken from schwimmbad (https://github.com/adrn/schwimmbad) and an explicit fork by Aymeric Galan -to replace the multiprocessing with the multiprocess dependence as for multi-threading, multiprocessing is -not supporting dill (only pickle) which is required.

-

The class also extends with a is_master() definition

-
-
-class lenstronomy.Sampling.Pool.multiprocessing.MultiPool(processes=None, initializer=None, initargs=(), **kwargs)[source]
-

Bases: multiprocess.pool.Pool

-

A modified version of multiprocessing.pool.Pool that has better -behavior with regard to KeyboardInterrupts in the map() method. -(Original author: Peter K. G. Williams)

-
-
processesint, optional

The number of worker processes to use; defaults to the number of CPUs.

-
-
initializercallable, optional

If specified, a callable that will be invoked by each worker process when it starts.

-
-
initargsiterable, optional

Arguments for initializer; it will be called as initializer(*initargs).

-
-
kwargs:

Extra arguments passed to the multiprocessing.pool.Pool superclass.

-
-
-
-
-static enabled()[source]
-
- -
-
-is_master()[source]
-
- -
-
-is_worker()[source]
-
- -
-
-map(func, iterable, chunksize=None, callback=None)[source]
-

Equivalent to the built-in map() function and -multiprocessing.pool.Pool.map(), without catching -KeyboardInterrupt.

-
-
funccallable

A function or callable object that is executed on each element of -the specified tasks iterable. This object must be picklable -(i.e. it can’t be a function scoped within a function or a -lambda function). This should accept a single positional -argument and return a single object.

-
-
iterableiterable

A list or iterable of tasks. Each task can be itself an iterable -(e.g., tuple) of values or data to pass in to the worker function.

-
-
callbackcallable, optional

An optional callback function (or callable) that is called with the -result from each worker run and is executed on the master process. -This is useful for, e.g., saving results to a file, since the -callback is only called on the master thread.

-
-
-
-
resultslist

A list of results from the output of each worker() call.

-
-
-
- -
-
-wait_timeout = 3600
-
- -
- -
-
-

lenstronomy.Sampling.Pool.pool module

-

this file is taken from schwimmbad (https://github.com/adrn/schwimmbad) and an explicit fork by Aymeric Galan -to replace the multiprocessing with the multiprocess dependence as for multi-threading, multiprocessing is -not supporting dill (only pickle) which is required.

-

Tests show that the MPI mode works with Python 3.7.2 but not with Python 3.7.0 on a specific system due to mpi4py -dependencies and configurations.

-

Contributions by: -- Peter K. G. Williams -- Júlio Hoffimann Mendes -- Dan Foreman-Mackey -- Aymeric Galan -- Simon Birrer

-

Implementations of four different types of processing pools:

-
-
    -
  • MPIPool: An MPI pool.

  • -
  • MultiPool: A multiprocessing for local parallelization.

  • -
  • SerialPool: A serial pool, which uses the built-in map function

  • -
-
-
-
-lenstronomy.Sampling.Pool.pool.choose_pool(mpi=False, processes=1, **kwargs)[source]
-

Extends the capabilities of the schwimmbad.choose_pool method.

-

It handles the use_dill parameters in kwargs, that would otherwise raise an error when processes > 1. -Any thread in the returned multiprocessing pool (e.g. processes > 1) also default

-

The requirement of schwimmbad relies on the master branch (as specified in requirements.txt). -The ‘use_dill’ functionality can raise if not following the requirement specified.

-

Choose between the different pools given options from, e.g., argparse.

-
-
mpibool, optional

Use the MPI processing pool, MPIPool. By -default, False, will use the SerialPool.

-
-
processesint, optional

Use the multiprocessing pool, -MultiPool, with this number of -processes. By default, processes=1, will use them:class:~schwimmbad.serial.SerialPool.

-
-
-

Any additional kwargs are passed in to the pool class initializer selected by the arguments.

-
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.Sampling.Samplers.html b/docs/_build/html/lenstronomy.Sampling.Samplers.html deleted file mode 100644 index 7be4c59e3..000000000 --- a/docs/_build/html/lenstronomy.Sampling.Samplers.html +++ /dev/null @@ -1,346 +0,0 @@ - - - - - - - - - lenstronomy.Sampling.Samplers package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.Sampling.Samplers package

-
-

Submodules

-
-
-

lenstronomy.Sampling.Samplers.base_nested_sampler module

-
-
-class lenstronomy.Sampling.Samplers.base_nested_sampler.NestedSampler(likelihood_module, prior_type, prior_means, prior_sigmas, width_scale, sigma_scale)[source]
-

Bases: object

-

Base class for nested samplers

-
-
-log_likelihood(*args, **kwargs)[source]
-

compute the log-likelihood given list of parameters

-
-
Returns
-

log-likelihood (from the likelihood module)

-
-
-
- -
-
-prior(*args, **kwargs)[source]
-

compute the mapping between the unit cube and parameter cube

-
-
Returns
-

hypercube in parameter space

-
-
-
- -
-
-run(kwargs_run)[source]
-

run the nested sampling algorithm

-
- -
- -
-
-

lenstronomy.Sampling.Samplers.dynesty_sampler module

-
-
-class lenstronomy.Sampling.Samplers.dynesty_sampler.DynestySampler(likelihood_module, prior_type='uniform', prior_means=None, prior_sigmas=None, width_scale=1, sigma_scale=1, bound='multi', sample='auto', use_mpi=False, use_pool=None)[source]
-

Bases: lenstronomy.Sampling.Samplers.base_nested_sampler.NestedSampler

-

Wrapper for dynamical nested sampling algorithm Dynesty by J. Speagle

-

paper : https://arxiv.org/abs/1904.02180 -doc : https://dynesty.readthedocs.io/

-
-
-log_likelihood(x)[source]
-

compute the log-likelihood given list of parameters

-
-
Parameters
-

x – parameter values

-
-
Returns
-

log-likelihood (from the likelihood module)

-
-
-
- -
-
-prior(u)[source]
-

compute the mapping between the unit cube and parameter cube

-
-
Parameters
-

u – unit hypercube, sampled by the algorithm

-
-
Returns
-

hypercube in parameter space

-
-
-
- -
-
-run(kwargs_run)[source]
-

run the Dynesty nested sampler

-

see https://dynesty.readthedocs.io for content of kwargs_run

-
-
Parameters
-

kwargs_run – kwargs directly passed to DynamicNestedSampler.run_nested

-
-
Returns
-

samples, means, logZ, logZ_err, logL, results

-
-
-
- -
- -
-
-

lenstronomy.Sampling.Samplers.multinest_sampler module

-
-
-class lenstronomy.Sampling.Samplers.multinest_sampler.MultiNestSampler(likelihood_module, prior_type='uniform', prior_means=None, prior_sigmas=None, width_scale=1, sigma_scale=1, output_dir=None, output_basename='-', remove_output_dir=False, use_mpi=False)[source]
-

Bases: lenstronomy.Sampling.Samplers.base_nested_sampler.NestedSampler

-

Wrapper for nested sampling algorithm MultInest by F. Feroz & M. Hobson -papers : arXiv:0704.3704, arXiv:0809.3437, arXiv:1306.2144 -pymultinest doc : https://johannesbuchner.github.io/PyMultiNest/pymultinest.html

-
-
-log_likelihood(args, ndim, nparams)[source]
-

compute the log-likelihood given list of parameters

-
-
Parameters
-
    -
  • args – parameter values

  • -
  • ndim – number of sampled parameters

  • -
  • nparams – total number of parameters

  • -
-
-
Returns
-

log-likelihood (from the likelihood module)

-
-
-
- -
-
-prior(cube, ndim, nparams)[source]
-

compute the mapping between the unit cube and parameter cube (in-place)

-
-
Parameters
-
    -
  • cube – unit hypercube, sampled by the algorithm

  • -
  • ndim – number of sampled parameters

  • -
  • nparams – total number of parameters

  • -
-
-
-
- -
-
-run(kwargs_run)[source]
-

run the MultiNest nested sampler

-

see https://johannesbuchner.github.io/PyMultiNest/pymultinest.html for content of kwargs_run

-
-
Parameters
-

kwargs_run – kwargs directly passed to pymultinest.run

-
-
Returns
-

samples, means, logZ, logZ_err, logL, stats

-
-
-
- -
- -
-
-

lenstronomy.Sampling.Samplers.polychord_sampler module

-
-
-class lenstronomy.Sampling.Samplers.polychord_sampler.DyPolyChordSampler(likelihood_module, prior_type='uniform', prior_means=None, prior_sigmas=None, width_scale=1, sigma_scale=1, output_dir=None, output_basename='-', resume_dyn_run=False, polychord_settings=None, remove_output_dir=False, use_mpi=False)[source]
-

Bases: lenstronomy.Sampling.Samplers.base_nested_sampler.NestedSampler

-

Wrapper for dynamical nested sampling algorithm DyPolyChord -by E. Higson, M. Hobson, W. Handley, A. Lasenby

-

papers : arXiv:1704.03459, arXiv:1804.06406 -doc : https://dypolychord.readthedocs.io

-
-
-log_likelihood(args)[source]
-

compute the log-likelihood given list of parameters

-
-
Parameters
-

args – parameter values

-
-
Returns
-

log-likelihood (from the likelihood module)

-
-
-
- -
-
-prior(cube)[source]
-

compute the mapping between the unit cube and parameter cube

-

‘copy=True’ below because cube can not be modified in-place (read-only)

-
-
Parameters
-

cube – unit hypercube, sampled by the algorithm

-
-
Returns
-

hypercube in parameter space

-
-
-
- -
-
-run(dynamic_goal, kwargs_run)[source]
-

run the DyPolyChord dynamical nested sampler

-

see https://dypolychord.readthedocs.io for content of kwargs_run

-
-
Parameters
-
    -
  • dynamic_goal – 0 for evidence computation, 1 for posterior computation

  • -
  • kwargs_run – kwargs directly passed to dyPolyChord.run_dypolychord

  • -
-
-
Returns
-

samples, means, logZ, logZ_err, logL, ns_run

-
-
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.Sampling.html b/docs/_build/html/lenstronomy.Sampling.html deleted file mode 100644 index 4a83f014b..000000000 --- a/docs/_build/html/lenstronomy.Sampling.html +++ /dev/null @@ -1,550 +0,0 @@ - - - - - - - - - lenstronomy.Sampling package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.Sampling package

-
-

Subpackages

- -
-
-

Submodules

-
-
-

lenstronomy.Sampling.likelihood module

-
-
-class lenstronomy.Sampling.likelihood.LikelihoodModule(kwargs_data_joint, kwargs_model, param_class, image_likelihood=True, check_bounds=True, check_matched_source_position=False, astrometric_likelihood=False, image_position_likelihood=False, source_position_likelihood=False, image_position_uncertainty=0.004, check_positive_flux=False, source_position_tolerance=0.001, source_position_sigma=0.001, force_no_add_image=False, source_marg=False, linear_prior=None, restrict_image_number=False, max_num_images=None, bands_compute=None, time_delay_likelihood=False, image_likelihood_mask_list=None, flux_ratio_likelihood=False, kwargs_flux_compute=None, prior_lens=None, prior_source=None, prior_extinction=None, prior_lens_light=None, prior_ps=None, prior_special=None, prior_lens_kde=None, prior_source_kde=None, prior_lens_light_kde=None, prior_ps_kde=None, prior_special_kde=None, prior_extinction_kde=None, prior_lens_lognormal=None, prior_source_lognormal=None, prior_extinction_lognormal=None, prior_lens_light_lognormal=None, prior_ps_lognormal=None, prior_special_lognormal=None, custom_logL_addition=None, kwargs_pixelbased=None)[source]
-

Bases: object

-

this class contains the routines to run a MCMC process -the key components are: -- imSim_class: an instance of a class that simulates one (or more) images and returns the likelihood, such as -ImageModel(), Multiband(), MultiExposure() -- param_class: instance of a Param() class that can cast the sorted list of parameters that are sampled into the -conventions of the imSim_class

-

Additional arguments are supported for adding a time-delay likelihood etc (see __init__ definition)

-
-
-static check_bounds(args, lowerLimit, upperLimit, verbose=False)[source]
-

checks whether the parameter vector has left its bound, if so, adds a big number

-
- -
-
-effective_num_data_points(**kwargs)[source]
-

returns the effective number of data points considered in the X2 estimation to compute the reduced X2 value

-
- -
-
-likelihood(a)[source]
-
- -
-
-logL(args, verbose=False)[source]
-

routine to compute X2 given variable parameters for a MCMC/PSO chain

-
- -
-
-log_likelihood(kwargs_return, verbose=False)[source]
-
- -
-
-negativelogL(a)[source]
-

for minimizer function, the negative value of the logl value is requested

-
-
Parameters
-

a – array of parameters

-
-
Returns
-

-logL

-
-
-
- -
-
-property num_data
-
-
Returns
-

number of independent data points in the combined fitting

-
-
-
- -
-
-property param_limits
-
- -
- -
-
-

lenstronomy.Sampling.parameters module

-
-
-class lenstronomy.Sampling.parameters.Param(kwargs_model, kwargs_fixed_lens=None, kwargs_fixed_source=None, kwargs_fixed_lens_light=None, kwargs_fixed_ps=None, kwargs_fixed_special=None, kwargs_fixed_extinction=None, kwargs_lower_lens=None, kwargs_lower_source=None, kwargs_lower_lens_light=None, kwargs_lower_ps=None, kwargs_lower_special=None, kwargs_lower_extinction=None, kwargs_upper_lens=None, kwargs_upper_source=None, kwargs_upper_lens_light=None, kwargs_upper_ps=None, kwargs_upper_special=None, kwargs_upper_extinction=None, kwargs_lens_init=None, linear_solver=True, joint_lens_with_lens=[], joint_lens_light_with_lens_light=[], joint_source_with_source=[], joint_lens_with_light=[], joint_source_with_point_source=[], joint_lens_light_with_point_source=[], joint_extinction_with_lens_light=[], joint_lens_with_source_light=[], mass_scaling_list=None, point_source_offset=False, num_point_source_list=None, image_plane_source_list=None, solver_type='NONE', Ddt_sampling=None, source_size=False, num_tau0=0, lens_redshift_sampling_indexes=None, source_redshift_sampling_indexes=None, source_grid_offset=False, num_shapelet_lens=0, log_sampling_lens=[])[source]
-

Bases: object

-

class that handles the parameter constraints. In particular when different model profiles share joint constraints.

-

Options between same model classes:

-

‘joint_lens_with_lens’:list [[i_lens, k_lens, [‘param_name1’, ‘param_name2’, …]], […], …], -joint parameter between two lens models

-

‘joint_lens_light_with_lens_light’:list [[i_lens_light, k_lens_light, [‘param_name1’, ‘param_name2’, …]], […], …], -joint parameter between two lens light models, the second adopts the value of the first

-

‘joint_source_with_source’:list [[i_source, k_source, [‘param_name1’, ‘param_name2’, …]], […], …], -joint parameter between two source surface brightness models, the second adopts the value of the first

-

Options between different model classes:

-

‘joint_lens_with_light’: list [[i_light, k_lens, [‘param_name1’, ‘param_name2’, …]], […], …], -joint parameter between lens model and lens light model

-

‘joint_source_with_point_source’: list [[i_point_source, k_source], […], …], -joint position parameter between lens model and source light model

-

‘joint_lens_light_with_point_source’: list [[i_point_source, k_lens_light], […], …], -joint position parameter between lens model and lens light model

-

‘joint_extinction_with_lens_light’: list [[i_lens_light, k_extinction, [‘param_name1’, ‘param_name2’, …]], […], …], -joint parameters between the lens surface brightness and the optical depth models

-

‘joint_lens_with_source_light’: [[i_source, k_lens, [‘param_name1’, ‘param_name2’, …]], […], …], -joint parameter between lens model and source light model. Samples light model parameter only.

-

hierarchy is as follows: -1. Point source parameters are inferred -2. Lens light joint parameters are set -3. Lens model joint constraints are set -4. Lens model solver is applied -5. Joint source and point source is applied

-

Alternatively to the format of the linking of parameters with IDENTICAL names as listed above as: -[[i_1, k_2, [‘param_name1’, ‘param_name2’, …]], […], …] -the following format of the arguments are supported to join parameters with DIFFERENT names: -[[i_1, k_2, {‘param_old1’: ‘param_new1’, ‘ra_0’: ‘center_x’}], […], …] -Log10 sampling of the lens parameters : -‘log_sampling_lens’: [[i_lens, [‘param_name1’, ‘param_name2’, …]], […], …], -Sample the log10 of the lens model parameters.

-
-
-args2kwargs(args, bijective=False)[source]
-
-
Parameters
-
    -
  • args – tuple of parameter values (float, strings, …)

  • -
  • bijective – boolean, if True (default) returns the parameters in the form as they are sampled -(e.g. if image_plane_source_list is set =True it returns the position in the image plane coordinates), -if False, returns the parameters in the form to render a model (e.g. image_plane_source_list positions are -ray-traced back to the source plane).

  • -
-
-
Returns
-

keyword arguments sorted in lenstronomy conventions

-
-
-
- -
-
-check_solver(kwargs_lens, kwargs_ps)[source]
-

test whether the image positions map back to the same source position -:param kwargs_lens: lens model keyword argument list -:param kwargs_ps: point source model keyword argument list -:return: Euclidean distance between the ray-shooting of the image positions

-
- -
-
-image2source_plane(kwargs_source, kwargs_lens, image_plane=False)[source]
-

maps the image plane position definition of the source plane

-
-
Parameters
-
    -
  • kwargs_source – source light model keyword argument list

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • image_plane – boolean, if True, does not up map image plane parameters to source plane

  • -
-
-
Returns
-

source light model keyword arguments with mapped position arguments from image to source plane

-
-
-
- -
-
-kwargs2args(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_special=None, kwargs_extinction=None)[source]
-

inverse of getParam function -:param kwargs_lens: keyword arguments depending on model options -:param kwargs_source: keyword arguments depending on model options -:param kwargs_lens_light: lens light model keyword argument list -:param kwargs_ps: point source model keyword argument list -:param kwargs_special: special keyword arguments -:param kwargs_extinction: extinction model keyword argument list -:return: numpy array of parameters

-
- -
-
-num_param()[source]
-
-
Returns
-

number of parameters involved (int), list of parameter names

-
-
-
- -
-
-num_param_linear()[source]
-
-
Returns
-

number of linear basis set coefficients that are solved for

-
-
-
- -
-
-property num_point_source_images
-
- -
-
-param_limits()[source]
-
-
Returns
-

lower and upper limits of the arguments being sampled

-
-
-
- -
-
-print_setting()[source]
-

prints the setting of the parameter class

-
-
Returns
-

-
-
-
- -
-
-update_kwargs_model(kwargs_special)[source]
-

updates model keyword arguments with redshifts being sampled

-
-
Parameters
-

kwargs_special – keyword arguments from SpecialParam() class return of sampling arguments

-
-
Returns
-

kwargs_model, bool (True if kwargs_model has changed, else False)

-
-
-
- -
-
-update_lens_scaling(kwargs_special, kwargs_lens, inverse=False)[source]
-

multiplies the scaling parameters of the profiles

-
-
Parameters
-
    -
  • kwargs_special – keyword arguments of the ‘special’ arguments

  • -
  • kwargs_lens – lens model keyword argument list

  • -
  • inverse – bool, if True, performs the inverse lens scaling for bijective transforms

  • -
-
-
Returns
-

updated lens model keyword argument list

-
-
-
- -
- -
-
-

lenstronomy.Sampling.sampler module

-
-
-class lenstronomy.Sampling.sampler.Sampler(likelihoodModule)[source]
-

Bases: object

-

class which executes the different sampling methods -Available are: MCMC with emcee and comsoHammer and a Particle Swarm Optimizer. -This are examples and depending on your problem, you might find other/better solutions. -Feel free to sample with your convenient sampler!

-
-
-mcmc_emcee(n_walkers, n_run, n_burn, mean_start, sigma_start, mpi=False, progress=False, threadCount=1, initpos=None, backup_filename=None, start_from_backup=False)[source]
-

Run MCMC with emcee. -For details, please have a look at the documentation of the emcee packager.

-
-
Parameters
-
    -
  • n_walkers (integer) – number of walkers in the emcee process

  • -
  • n_run (integer) – number of sampling (after burn-in) of the emcee

  • -
  • n_burn (integer) – number of burn-in iterations (those will not be saved in the output sample)

  • -
  • mean_start (numpy array of length the number of parameters) – mean of the parameter position of the initialising sample

  • -
  • sigma_start (numpy array of length the number of parameters) – spread of the parameter values (uncorrelated in each dimension) of the initialising sample

  • -
  • mpi (bool) – if True, initializes an MPIPool to allow for MPI execution of the sampler

  • -
  • progress (bool) – if True, prints the progress bar

  • -
  • threadCount (integer) – number of threats in multi-processing (not applicable for MPI)

  • -
  • initpos (numpy array of size num param x num walkser) – initial walker position to start sampling (optional)

  • -
  • backup_filename (string) – name of the HDF5 file where sampling state is saved (through emcee backend engine)

  • -
  • start_from_backup (bool) – if True, start from the state saved in backup_filename. -Otherwise, create a new backup file with name backup_filename (any already existing file is overwritten!).

  • -
-
-
Returns
-

samples, ln likelihood value of samples

-
-
Return type
-

numpy 2d array, numpy 1d array

-
-
-
- -
-
-pso(n_particles, n_iterations, lower_start=None, upper_start=None, threadCount=1, init_pos=None, mpi=False, print_key='PSO')[source]
-

Return the best fit for the lens model on catalogue basis with -particle swarm optimizer.

-
-
Parameters
-
    -
  • n_particles – number of particles in the sampling process

  • -
  • n_iterations – number of iterations of the swarm

  • -
  • lower_start – numpy array, lower end parameter of the values of the starting particles

  • -
  • upper_start – numpy array, upper end parameter of the values of the starting particles

  • -
  • threadCount – number of threads in the computation (only applied if mpi=False)

  • -
  • init_pos – numpy array, position of the initial best guess model

  • -
  • mpi – bool, if True, makes instance of MPIPool to allow for MPI execution

  • -
  • print_key – string, prints the process name in the progress bar (optional)

  • -
-
-
Returns
-

kwargs_result (of best fit), [lnlikelihood of samples, positions of samples, velocity of sampels)

-
-
-
- -
-
-simplex(init_pos, n_iterations, method, print_key='SIMPLEX')[source]
-
-
Parameters
-
    -
  • init_pos – starting point for the optimization

  • -
  • n_iterations – maximum number of iterations

  • -
  • method – the optimization method, default is ‘Nelder-Mead’

  • -
-
-
Returns
-

the best fit for the lens model using the optimization routine specified by method

-
-
-
- -
- -
-
-

lenstronomy.Sampling.special_param module

-
-
-class lenstronomy.Sampling.special_param.SpecialParam(Ddt_sampling=False, mass_scaling=False, num_scale_factor=1, kwargs_fixed=None, kwargs_lower=None, kwargs_upper=None, point_source_offset=False, source_size=False, num_images=0, num_tau0=0, num_z_sampling=0, source_grid_offset=False)[source]
-

Bases: object

-

class that handles special parameters that are not directly part of a specific model component. -These includes cosmology relevant parameters, astrometric errors and overall scaling parameters.

-
-
-get_params(args, i)[source]
-
-
Parameters
-
    -
  • args – argument list

  • -
  • i – integer, list index to start the read out for this class

  • -
-
-
Returns
-

keyword arguments related to args, index after reading out arguments of this class

-
-
-
- -
-
-num_param()[source]
-
-
Returns
-

integer, number of free parameters sampled (and managed) by this class, parameter names (list of strings)

-
-
-
- -
-
-set_params(kwargs_special)[source]
-
-
Parameters
-

kwargs_special – keyword arguments with parameter settings

-
-
Returns
-

argument list of the sampled parameters extracted from kwargs_special

-
-
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.SimulationAPI.ObservationConfig.html b/docs/_build/html/lenstronomy.SimulationAPI.ObservationConfig.html deleted file mode 100644 index a4eff3c09..000000000 --- a/docs/_build/html/lenstronomy.SimulationAPI.ObservationConfig.html +++ /dev/null @@ -1,285 +0,0 @@ - - - - - - - - - lenstronomy.SimulationAPI.ObservationConfig package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.SimulationAPI.ObservationConfig package

-
-

Submodules

-
-
-

lenstronomy.SimulationAPI.ObservationConfig.DES module

-

Provisional DES instrument and observational settings. -See Optics and Observation Conditions spreadsheet at -https://docs.google.com/spreadsheets/d/1pMUB_OOZWwXON2dd5oP8PekhCT5MBBZJO1HV7IMZg4Y/edit?usp=sharing for list of -sources.

-
-
-class lenstronomy.SimulationAPI.ObservationConfig.DES.DES(band='g', psf_type='GAUSSIAN', coadd_years=3)[source]
-

Bases: object

-

class contains DES instrument and observation configurations

-
-
-camera
-
-
Parameters
-
    -
  • read_noise – std of noise generated by read-out (in units of electrons)

  • -
  • pixel_scale – scale (in arcseconds) of pixels

  • -
  • ccd_gain – electrons/ADU (analog-to-digital unit).

  • -
-
-
-
- -
-
-kwargs_single_band()[source]
-
-
Returns
-

merged kwargs from camera and obs dicts

-
-
-
- -
- -
-
-

lenstronomy.SimulationAPI.ObservationConfig.Euclid module

-

Provisional Euclid instrument and observational settings. -See Optics and Observation Conditions spreadsheet at -https://docs.google.com/spreadsheets/d/1pMUB_OOZWwXON2dd5oP8PekhCT5MBBZJO1HV7IMZg4Y/edit?usp=sharing for list of -sources.

-
-
-class lenstronomy.SimulationAPI.ObservationConfig.Euclid.Euclid(band='VIS', psf_type='GAUSSIAN', coadd_years=6)[source]
-

Bases: object

-

class contains Euclid instrument and observation configurations

-
-
-camera
-
-
Parameters
-
    -
  • read_noise – std of noise generated by read-out (in units of electrons)

  • -
  • pixel_scale – scale (in arcseconds) of pixels

  • -
  • ccd_gain – electrons/ADU (analog-to-digital unit).

  • -
-
-
-
- -
-
-kwargs_single_band()[source]
-
-
Returns
-

merged kwargs from camera and obs dicts

-
-
-
- -
- -
-
-

lenstronomy.SimulationAPI.ObservationConfig.HST module

-

Provisional HST instrument and observational settings. -See Optics and Observation Conditions spreadsheet at -https://docs.google.com/spreadsheets/d/1pMUB_OOZWwXON2dd5oP8PekhCT5MBBZJO1HV7IMZg4Y/edit?usp=sharing for list of -sources.

-
-
-class lenstronomy.SimulationAPI.ObservationConfig.HST.HST(band='TDLMC_F160W', psf_type='PIXEL', coadd_years=None)[source]
-

Bases: object

-

class contains HST instrument and observation configurations

-
-
-camera
-
-
Parameters
-
    -
  • read_noise – std of noise generated by read-out (in units of electrons)

  • -
  • pixel_scale – scale (in arcseconds) of pixels

  • -
  • ccd_gain – electrons/ADU (analog-to-digital unit).

  • -
-
-
-
- -
-
-kwargs_single_band()[source]
-
-
Returns
-

merged kwargs from camera and obs dicts

-
-
-
- -
- -
-
-

lenstronomy.SimulationAPI.ObservationConfig.LSST module

-

Provisional LSST instrument and observational settings. -See Optics and Observation Conditions spreadsheet at -https://docs.google.com/spreadsheets/d/1pMUB_OOZWwXON2dd5oP8PekhCT5MBBZJO1HV7IMZg4Y/edit?usp=sharing for list of -sources.

-
-
-class lenstronomy.SimulationAPI.ObservationConfig.LSST.LSST(band='g', psf_type='GAUSSIAN', coadd_years=10)[source]
-

Bases: object

-

class contains LSST instrument and observation configurations

-
-
-camera
-
-
Parameters
-
    -
  • read_noise – std of noise generated by read-out (in units of electrons)

  • -
  • pixel_scale – scale (in arcseconds) of pixels

  • -
  • ccd_gain – electrons/ADU (analog-to-digital unit).

  • -
-
-
-
- -
-
-kwargs_single_band()[source]
-
-
Returns
-

merged kwargs from camera and obs dicts

-
-
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.SimulationAPI.html b/docs/_build/html/lenstronomy.SimulationAPI.html deleted file mode 100644 index a84017d65..000000000 --- a/docs/_build/html/lenstronomy.SimulationAPI.html +++ /dev/null @@ -1,549 +0,0 @@ - - - - - - - - - lenstronomy.SimulationAPI package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.SimulationAPI package

-
-

Subpackages

- -
-
-

Submodules

-
-
-

lenstronomy.SimulationAPI.data_api module

-
-
-class lenstronomy.SimulationAPI.data_api.DataAPI(numpix, **kwargs_single_band)[source]
-

Bases: lenstronomy.SimulationAPI.observation_api.SingleBand

-

This class is a wrapper of the general description of data in SingleBand() to translate those quantities into -configurations in the core lenstronomy Data modules to simulate images according to those quantities. -This class is meant to be an example of a wrapper. More possibilities in terms of PSF and data type -options are available. Have a look in the specific modules if you are interested in.

-
-
-property data_class
-

creates a Data() instance of lenstronomy based on knowledge of the observation

-
-
Returns
-

instance of Data() class

-
-
-
- -
-
-property kwargs_data
-
-
Returns
-

keyword arguments for ImageData class instance

-
-
-
- -
- -
-
-

lenstronomy.SimulationAPI.model_api module

-
-
-class lenstronomy.SimulationAPI.model_api.ModelAPI(lens_model_list=None, z_lens=None, z_source=None, lens_redshift_list=None, source_light_model_list=None, lens_light_model_list=None, point_source_model_list=None, source_redshift_list=None, cosmo=None, z_source_convention=None)[source]
-

Bases: object

-

This class manages the model choices. The role is to return instances of the lenstronomy LightModel, LensModel, -PointSource modules according to the options chosen by the user. -Currently, all other model choices are equivalent to the ones provided by LightModel, LensModel, PointSource. -The current options of the class instance only describe a subset of possibilities.

-
-
-property lens_light_model_class
-
-
Returns
-

instance of lenstronomy LightModel class describing the non-lensed light profiles

-
-
-
- -
-
-property lens_model_class
-
-
Returns
-

instance of lenstronomy LensModel class

-
-
-
- -
-
-physical2lensing_conversion(kwargs_mass)[source]
-
-
Parameters
-

kwargs_mass – list of keyword arguments of all the lens models. Einstein radius ‘theta_E’ are replaced by -‘sigma_v’, velocity dispersion in km/s, ‘alpha_Rs’ and ‘Rs’ of NFW profiles are replaced by ‘M200’ and -‘concentration’

-
-
Returns
-

kwargs_lens in reduced deflection angles compatible with the lensModel instance of this module

-
-
-
- -
-
-property point_source_model_class
-
-
Returns
-

instance of lenstronomy PointSource class describing the point sources (lensed and unlensed)

-
-
-
- -
-
-property source_model_class
-
-
Returns
-

instance of lenstronomy LightModel class describing the source light profiles

-
-
-
- -
- -
-
-

lenstronomy.SimulationAPI.observation_api module

-
-
-class lenstronomy.SimulationAPI.observation_api.Instrument(pixel_scale, read_noise=None, ccd_gain=None)[source]
-

Bases: object

-

basic access points to instrument properties

-
- -
-
-class lenstronomy.SimulationAPI.observation_api.Observation(exposure_time, sky_brightness=None, seeing=None, num_exposures=1, psf_type='GAUSSIAN', kernel_point_source=None, truncation=5, point_source_supersampling_factor=1)[source]
-

Bases: object

-

basic access point to observation properties

-
-
-property exposure_time
-

total exposure time

-
-
Returns
-

summed exposure time

-
-
-
- -
-
-property psf_class
-

creates instance of PSF() class based on knowledge of the observations -For the full possibility of how to create such an instance, see the PSF() class documentation

-
-
Returns
-

instance of PSF() class

-
-
-
- -
-
-update_observation(exposure_time=None, sky_brightness=None, seeing=None, num_exposures=None, psf_type=None, kernel_point_source=None)[source]
-

updates class instance with new properties if specific argument is not None

-
-
Parameters
-
    -
  • exposure_time – exposure time per image (in seconds)

  • -
  • sky_brightness – sky brightness (in magnitude per square arcseconds)

  • -
  • seeing – full width at half maximum of the PSF (if not specific psf_model is specified)

  • -
  • num_exposures – number of exposures that are combined

  • -
  • psf_type – string, type of PSF (‘GAUSSIAN’ and ‘PIXEL’ supported)

  • -
  • kernel_point_source – 2d numpy array, model of PSF centered with odd number of pixels per axis -(optional when psf_type=’PIXEL’ is chosen)

  • -
-
-
Returns
-

None, updated class instance

-
-
-
- -
- -
-
-class lenstronomy.SimulationAPI.observation_api.SingleBand(pixel_scale, exposure_time, magnitude_zero_point, read_noise=None, ccd_gain=None, sky_brightness=None, seeing=None, num_exposures=1, psf_type='GAUSSIAN', kernel_point_source=None, truncation=5, point_source_supersampling_factor=1, data_count_unit='e-', background_noise=None)[source]
-

Bases: lenstronomy.SimulationAPI.observation_api.Instrument, lenstronomy.SimulationAPI.observation_api.Observation

-

class that combines Instrument and Observation

-
-
-property background_noise
-

Gaussian sigma of noise level per pixel in counts (e- or ADU) per second

-
-
Returns
-

sqrt(variance) of background noise level in data units

-
-
-
- -
-
-estimate_noise(image)[source]
-
-
Parameters
-

image – noisy data, background subtracted

-
-
Returns
-

estimated noise map sqrt(variance) for each pixel as estimated from the instrument and observation

-
-
-
- -
-
-flux_iid(flux_per_second)[source]
-

IID counts. This can be used by lenstronomy to estimate the Poisson errors -keeping the assumption that the counts are IIDs (even if they are not).

-
-
Parameters
-

flux_per_second – flux count per second in the units set in this class (ADU or e-)

-
-
Returns
-

IID count number

-
-
-
- -
-
-flux_noise(flux)[source]
-
-
Parameters
-

flux – float or array, units of count_unit/seconds, needs to be positive semi-definite in the flux value

-
-
Returns
-

Gaussian approximation of Poisson statistics in IIDs sqrt(variance)

-
-
-
- -
-
-magnitude2cps(magnitude)[source]
-

converts an apparent magnitude to counts per second (in units of the data)

-

The zero point of an instrument, by definition, is the magnitude of an object that produces one count -(or data number, DN) per second. The magnitude of an arbitrary object producing DN counts in an observation of -length EXPTIME is therefore: -m = -2.5 x log10(DN / EXPTIME) + ZEROPOINT

-
-
Parameters
-

magnitude – magnitude of object

-
-
Returns
-

counts per second of object

-
-
-
- -
-
-noise_for_model(model, background_noise=True, poisson_noise=True, seed=None)[source]
-
-
Parameters
-
    -
  • model – 2d numpy array of modelled image (with pixels in units of data specified in class)

  • -
  • background_noise – bool, if True, adds background noise

  • -
  • poisson_noise – bool, if True, adds Poisson noise of modelled flux

  • -
  • seed – int, seed number to be used to render the noise properties. -If None, then uses the current numpy.random seed to render the noise properties.

  • -
-
-
Returns
-

noise realization corresponding to the model

-
-
-
- -
-
-property sky_brightness
-
-
Returns
-

sky brightness (counts per square arcseconds in unit of data (e- or ADU’s) per unit time)

-
-
-
- -
- -
-
-

lenstronomy.SimulationAPI.observation_constructor module

-
-
-lenstronomy.SimulationAPI.observation_constructor.observation_constructor(instrument_name, observation_name)[source]
-
-
Parameters
-
    -
  • instrument_name – string, name of instrument referenced in this file

  • -
  • observation_name – string, name of observation referenced in this file

  • -
-
-
Returns
-

instance of the SimulationAPI.data_type instance

-
-
-
- -
-
-

lenstronomy.SimulationAPI.point_source_variability module

-
-
-class lenstronomy.SimulationAPI.point_source_variability.PointSourceVariability(source_x, source_y, variability_func, numpix, kwargs_single_band, kwargs_model, kwargs_numerics, kwargs_lens, kwargs_source_mag=None, kwargs_lens_light_mag=None, kwargs_ps_mag=None)[source]
-

Bases: object

-

This class enables to plug in a variable point source in the source plane to be added on top of a fixed lens and -extended surface brightness model. The class inherits SimAPI and additionally requires the lens and light model -parameters as well as a position in the source plane.

-

The intrinsic source variability can be defined by the user and additional uncorrelated variability in the image -plane can be plugged in as well (e.g. due to micro-lensing)

-
-
-property delays
-
-
Returns
-

time delays

-
-
-
- -
-
-property image_bkg
-
-
Returns
-

2d numpy array, image of the extended light components without the variable source

-
-
-
- -
-
-image_time(time=0)[source]
-
-
Parameters
-

time – time relative to the definition of t=0 for the first appearing image

-
-
Returns
-

image with time variable source at given time

-
-
-
- -
-
-point_source_time(t)[source]
-
-
Parameters
-

t – time (in units of days)

-
-
Returns
-

image plane parameters of the point source observed at t

-
-
-
- -
- -
-
-

lenstronomy.SimulationAPI.sim_api module

-
-
-class lenstronomy.SimulationAPI.sim_api.SimAPI(numpix, kwargs_single_band, kwargs_model)[source]
-

Bases: lenstronomy.SimulationAPI.data_api.DataAPI, lenstronomy.SimulationAPI.model_api.ModelAPI

-

This class manages the model parameters in regard of the data specified in SingleBand. In particular, -this API translates models specified in units of astronomical magnitudes into the amplitude parameters used in the -LightModel module of lenstronomy. -Optionally, this class can also handle inputs with cosmology dependent lensing quantities and translates them to -the optical quantities being used in the lenstronomy LensModel module. -All other model choices are equivalent to the ones provided by LightModel, LensModel, PointSource modules

-
-
-image_model_class(kwargs_numerics=None)[source]
-
-
Parameters
-

kwargs_numerics – keyword arguments list of Numerics module

-
-
Returns
-

instance of the ImageModel class with all the specified configurations

-
-
-
- -
-
-magnitude2amplitude(kwargs_lens_light_mag=None, kwargs_source_mag=None, kwargs_ps_mag=None)[source]
-

‘magnitude’ definition are in APPARENT magnitudes as observed on the sky, not intrinsic!

-
-
Parameters
-
    -
  • kwargs_lens_light_mag – keyword argument list as for LightModel module except that ‘amp’ parameters are -‘magnitude’ parameters.

  • -
  • kwargs_source_mag – keyword argument list as for LightModel module except that ‘amp’ parameters are -‘magnitude’ parameters.

  • -
  • kwargs_ps_mag – keyword argument list as for PointSource module except that ‘amp’ parameters are -‘magnitude’ parameters.

  • -
-
-
Returns
-

value of the lenstronomy ‘amp’ parameter such that the total flux of the profile type results in this -magnitude for all the light models. These keyword arguments conform with the lenstronomy LightModel syntax.

-
-
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.Util.html b/docs/_build/html/lenstronomy.Util.html deleted file mode 100644 index c82a77a0a..000000000 --- a/docs/_build/html/lenstronomy.Util.html +++ /dev/null @@ -1,2206 +0,0 @@ - - - - - - - - - lenstronomy.Util package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.Util package

-
-

Submodules

-
-
-

lenstronomy.Util.analysis_util module

-
-
-lenstronomy.Util.analysis_util.azimuthalAverage(image, center=None)[source]
-

Calculate the azimuthally averaged radial profile.

-

image - The 2D image -center - The [x,y] pixel coordinates used as the center. The default is None, which then uses the center of the -image (including fractional pixels). -:return: I(r) (averaged), r of bin edges

-
- -
-
-lenstronomy.Util.analysis_util.bic_model(logL, num_data, num_param)[source]
-

Bayesian information criteria

-
-
Parameters
-
    -
  • logL – log likelihood value

  • -
  • num_data – numbers of data

  • -
  • num_param – numbers of model parameters

  • -
-
-
Returns
-

BIC value

-
-
-
- -
-
-lenstronomy.Util.analysis_util.ellipticities(I_xy, x, y)[source]
-

compute ellipticities of a light distribution

-
-
Parameters
-
    -
  • I_xy

  • -
  • x

  • -
  • y

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.analysis_util.half_light_radius(lens_light, x_grid, y_grid, center_x=0, center_y=0)[source]
-
-
Parameters
-
    -
  • lens_light – array of surface brightness

  • -
  • x_grid – x-axis coordinates

  • -
  • y_grid – y-axis coordinates

  • -
  • center_x – center of light

  • -
  • center_y – center of light

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.analysis_util.moments(I_xy_input, x, y)[source]
-

compute quadrupole moments from a light distribution

-
-
Parameters
-
    -
  • I_xy_input – light distribution

  • -
  • x – x-coordinates of I_xy

  • -
  • y – y-coordinates of I_xy

  • -
-
-
Returns
-

Q_xx, Q_xy, Q_yy

-
-
-
- -
-
-lenstronomy.Util.analysis_util.profile_center(kwargs_list, center_x=None, center_y=None)[source]
-

utility routine that results in the centroid estimate for the profile estimates

-
-
Parameters
-
    -
  • kwargs_list – light parameter keyword argument list (can be light or mass)

  • -
  • center_x – None or center

  • -
  • center_y – None or center

  • -
-
-
Returns
-

center_x, center_y

-
-
-
- -
-
-lenstronomy.Util.analysis_util.radial_profile(light_grid, x_grid, y_grid, center_x=0, center_y=0, n=None)[source]
-
-
Parameters
-
    -
  • light_grid – array of surface brightness

  • -
  • x_grid – x-axis coordinates

  • -
  • y_grid – y-axis coordinates

  • -
  • center_x – center of light

  • -
  • center_y – center of light

  • -
  • n – number of discrete steps

  • -
-
-
Returns
-

-
-
-
- -
-
-

lenstronomy.Util.class_creator module

-
-
-lenstronomy.Util.class_creator.create_class_instances(lens_model_list=None, z_lens=None, z_source=None, z_source_convention=None, lens_redshift_list=None, kwargs_interp=None, multi_plane=False, observed_convention_index=None, source_light_model_list=None, lens_light_model_list=None, point_source_model_list=None, fixed_magnification_list=None, flux_from_point_source_list=None, additional_images_list=None, kwargs_lens_eqn_solver=None, source_deflection_scaling_list=None, source_redshift_list=None, cosmo=None, index_lens_model_list=None, index_source_light_model_list=None, index_lens_light_model_list=None, index_point_source_model_list=None, optical_depth_model_list=None, index_optical_depth_model_list=None, band_index=0, tau0_index_list=None, all_models=False, point_source_magnification_limit=None, surface_brightness_smoothing=0.001, sersic_major_axis=None)[source]
-
-
Parameters
-
    -
  • lens_model_list – list of strings indicating the type of lens models

  • -
  • z_lens – redshift of the deflector (for single lens plane mode, but only relevant when computing physical quantities)

  • -
  • z_source – redshift of source (for single source plane mode, or for multiple source planes the redshift of the point source). In regard to this redshift the reduced deflection angles are defined in the lens model.

  • -
  • z_source_convention – float, redshift of a source to define the reduced deflection angles of the lens models. -If None, ‘z_source’ is used.

  • -
  • lens_redshift_list

  • -
  • multi_plane

  • -
  • kwargs_interp – interpolation keyword arguments specifying the numerics. -See description in the Interpolate() class. Only applicable for ‘INTERPOL’ and ‘INTERPOL_SCALED’ models.

  • -
  • observed_convention_index

  • -
  • source_light_model_list

  • -
  • lens_light_model_list

  • -
  • point_source_model_list

  • -
  • fixed_magnification_list

  • -
  • flux_from_point_source_list – list of bools (optional), if set, will only return image positions -(for imaging modeling) for the subset of the point source lists that =True. This option enables to model

  • -
  • additional_images_list

  • -
  • kwargs_lens_eqn_solver – keyword arguments specifying the numerical settings for the lens equation solver -see LensEquationSolver() class for details

  • -
  • source_deflection_scaling_list – List of floats for each source ligth model (optional, and only applicable -for single-plane lensing. The factors re-scale the reduced deflection angles described from the lens model. -=1 means identical source position as without this option. This option enables multiple source planes. -The geometric difference between the different source planes needs to be pre-computed and is cosmology dependent.

  • -
  • source_redshift_list

  • -
  • cosmo – astropy.cosmology instance

  • -
  • index_lens_model_list

  • -
  • index_source_light_model_list

  • -
  • index_lens_light_model_list

  • -
  • index_point_source_model_list

  • -
  • optical_depth_model_list – list of strings indicating the optical depth model to compute (differential) extinctions from the source

  • -
  • index_optical_depth_model_list

  • -
  • band_index – int, index of band to consider. Has an effect if only partial models are considered for a specific band

  • -
  • tau0_index_list – list of integers of the specific extinction scaling parameter tau0 for each band

  • -
  • all_models – bool, if True, will make class instances of all models ignoring potential keywords that are excluding specific models as indicated.

  • -
  • point_source_magnification_limit – float >0 or None, if set and additional images are computed, then it will cut the point sources computed to the limiting (absolute) magnification

  • -
  • surface_brightness_smoothing – float, smoothing scale of light profile (minimal distance to the center of a profile) -this can help to avoid inaccuracies in the very center of a cuspy light profile

  • -
  • sersic_major_axis – boolean or None, if True, uses the semi-major axis as the definition of the Sersic -half-light radius, if False, uses the product average of semi-major and semi-minor axis. If None, uses the -convention in the lenstronomy yaml setting (which by default is =False)

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.class_creator.create_im_sim(multi_band_list, multi_band_type, kwargs_model, bands_compute=None, image_likelihood_mask_list=None, band_index=0, kwargs_pixelbased=None)[source]
-
-
Parameters
-
    -
  • multi_band_list – list of [[kwargs_data, kwargs_psf, kwargs_numerics], [], ..]

  • -
  • multi_band_type – string, option when having multiple imaging data sets modelled simultaneously. Options are: -- ‘multi-linear’: linear amplitudes are inferred on single data set -- ‘linear-joint’: linear amplitudes ae jointly inferred -- ‘single-band’: single band

  • -
  • kwargs_model – model keyword arguments

  • -
  • bands_compute – (optional), bool list to indicate which band to be included in the modeling

  • -
  • image_likelihood_mask_list – list of image likelihood mask -(same size as image_data with 1 indicating being evaluated and 0 being left out)

  • -
  • band_index – integer, index of the imaging band to model (only applied when using ‘single-band’ as option)

  • -
  • kwargs_pixelbased – keyword arguments with various settings related to the pixel-based solver (see SLITronomy documentation)

  • -
-
-
Returns
-

MultiBand class instance

-
-
-
- -
-
-lenstronomy.Util.class_creator.create_image_model(kwargs_data, kwargs_psf, kwargs_numerics, kwargs_model, image_likelihood_mask=None)[source]
-
-
Parameters
-
    -
  • kwargs_data – ImageData keyword arguments

  • -
  • kwargs_psf – PSF keyword arguments

  • -
  • kwargs_numerics – numerics keyword arguments for Numerics() class

  • -
  • kwargs_model – model keyword arguments

  • -
  • image_likelihood_mask – image likelihood mask -(same size as image_data with 1 indicating being evaluated and 0 being left out)

  • -
-
-
Returns
-

ImageLinearFit() instance

-
-
-
- -
-
-

lenstronomy.Util.constants module

-
-
-lenstronomy.Util.constants.delay_arcsec2days(delay_arcsec, ddt)[source]
-

given a delay in arcsec^2 and a Delay distance, the delay is computed in days

-
-
Parameters
-
    -
  • delay_arcsec – gravitational delay in units of arcsec^2 (e.g. Fermat potential)

  • -
  • ddt – Time delay distance (in units of Mpc)

  • -
-
-
Returns
-

time-delay in units of days

-
-
-
- -
-
-

lenstronomy.Util.correlation module

-
-
-lenstronomy.Util.correlation.correlation_2D(image)[source]
-

#TODO document normalization output in units

-
-
Parameters
-

image – 2d image

-
-
Returns
-

2d fourier transform

-
-
-
- -
-
-lenstronomy.Util.correlation.power_spectrum_1d(image)[source]
-
-
Parameters
-

image – 2d numpy array

-
-
Returns
-

1d radially averaged power spectrum of image in frequency units of pixels

-
-
-
- -
-
-lenstronomy.Util.correlation.power_spectrum_2d(image)[source]
-
-
Parameters
-

image – 2d numpy array

-
-
Returns
-

2d power spectrum in frequency units of the pixels

-
-
-
- -
-
-

lenstronomy.Util.data_util module

-
-
-lenstronomy.Util.data_util.absolute2apparent_magnitude(absolute_magnitude, d_parsec)[source]
-

converts absolute to apparent magnitudes

-
-
Parameters
-
    -
  • absolute_magnitude – absolute magnitude of object

  • -
  • d_parsec – distance to object in units parsec

  • -
-
-
Returns
-

apparent magnitude

-
-
-
- -
-
-lenstronomy.Util.data_util.adu2electrons(adu, ccd_gain)[source]
-

converts analog-to-digital units into electron counts

-
-
Parameters
-
    -
  • adu – counts in analog-to-digital unit

  • -
  • ccd_gain – CCD gain, meaning how many electrons are counted per unit ADU

  • -
-
-
Returns
-

counts in electrons

-
-
-
- -
-
-lenstronomy.Util.data_util.bkg_noise(readout_noise, exposure_time, sky_brightness, pixel_scale, num_exposures=1)[source]
-

computes the expected Gaussian background noise of a pixel in units of counts/second

-
-
Parameters
-
    -
  • readout_noise – noise added per readout

  • -
  • exposure_time – exposure time per exposure (in seconds)

  • -
  • sky_brightness – counts per second per unit arcseconds square

  • -
  • pixel_scale – size of pixel in units arcseonds

  • -
  • num_exposures – number of exposures (with same exposure time) to be co-added

  • -
-
-
Returns
-

estimated Gaussian noise sqrt(variance)

-
-
-
- -
-
-lenstronomy.Util.data_util.cps2magnitude(cps, magnitude_zero_point)[source]
-
-
Parameters
-
    -
  • cps – float, count-per-second

  • -
  • magnitude_zero_point – magnitude zero point

  • -
-
-
Returns
-

magnitude for given counts

-
-
-
- -
-
-lenstronomy.Util.data_util.electrons2adu(electrons, ccd_gain)[source]
-

converts electron counts into analog-to-digital unit

-
-
Parameters
-
    -
  • electrons – number of electrons received on detector

  • -
  • ccd_gain – CCD gain, meaning how many electrons are counted per unit ADU

  • -
-
-
Returns
-

adu value in Analog-to-digital units corresponding to electron count

-
-
-
- -
-
-lenstronomy.Util.data_util.flux_noise(cps_pixel, exposure_time)[source]
-

computes the variance of the shot noise Gaussian approximation of Poisson noise term

-
-
Parameters
-
    -
  • cps_pixel – counts per second of the intensity per pixel unit

  • -
  • exposure_time – total exposure time (in units seconds or equivalent unit as cps_pixel)

  • -
-
-
Returns
-

sqrt(variance) of pixel value

-
-
-
- -
-
-lenstronomy.Util.data_util.magnitude2cps(magnitude, magnitude_zero_point)[source]
-

converts an apparent magnitude to counts per second

-

The zero point of an instrument, by definition, is the magnitude of an object that produces one count -(or data number, DN) per second. The magnitude of an arbitrary object producing DN counts in an observation of -length EXPTIME is therefore: -m = -2.5 x log10(DN / EXPTIME) + ZEROPOINT

-
-
Parameters
-
    -
  • magnitude – astronomical magnitude

  • -
  • magnitude_zero_point – magnitude zero point (astronomical magnitude with 1 count per second)

  • -
-
-
Returns
-

counts per second of astronomical object

-
-
-
- -
-
-

lenstronomy.Util.derivative_util module

-

routines to compute derivatives of spherical functions

-
-
-lenstronomy.Util.derivative_util.d_phi_dx(x, y)[source]
-

angular derivative in respect to x when phi = arctan2(y, x)

-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.derivative_util.d_phi_dxx(x, y)[source]
-

second derivative of the orientation angle

-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.derivative_util.d_phi_dxy(x, y)[source]
-

second derivative of the orientation angle in dxdy

-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.derivative_util.d_phi_dy(x, y)[source]
-

angular derivative in respect to y when phi = arctan2(y, x)

-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.derivative_util.d_phi_dyy(x, y)[source]
-

second derivative of the orientation angle in dydy

-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.derivative_util.d_r_dx(x, y)[source]
-

derivative of r with respect to x -:param x: -:param y: -:return:

-
- -
-
-lenstronomy.Util.derivative_util.d_r_dxx(x, y)[source]
-

second derivative dr/dxdx -:param x: -:param y: -:return:

-
- -
-
-lenstronomy.Util.derivative_util.d_r_dxy(x, y)[source]
-

second derivative dr/dxdx -:param x: -:param y: -:return:

-
- -
-
-lenstronomy.Util.derivative_util.d_r_dy(x, y)[source]
-

differential dr/dy

-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.derivative_util.d_r_dyy(x, y)[source]
-

second derivative dr/dxdx -:param x: -:param y: -:return:

-
- -
-
-lenstronomy.Util.derivative_util.d_x_diffr_dx(x, y)[source]
-

derivative of d(x/r)/dx -equivalent to second order derivatives dr_dxx

-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.derivative_util.d_x_diffr_dy(x, y)[source]
-

derivative of d(x/r)/dy -equivalent to second order derivatives dr_dyx

-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.derivative_util.d_y_diffr_dx(x, y)[source]
-

derivative of d(y/r)/dx -equivalent to second order derivatives dr_dxy

-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.derivative_util.d_y_diffr_dy(x, y)[source]
-

derivative of d(y/r)/dy -equivalent to second order derivatives dr_dyy

-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
-
-
Returns
-

-
-
-
- -
-
-

lenstronomy.Util.image_util module

-
-
-lenstronomy.Util.image_util.add_background(image, sigma_bkd)[source]
-

adds background noise to image -:param image: pixel values of image -:param sigma_bkd: background noise (sigma) -:return: a realisation of Gaussian noise of the same size as image

-
- -
-
-lenstronomy.Util.image_util.add_layer2image(grid2d, x_pos, y_pos, kernel, order=1)[source]
-

adds a kernel on the grid2d image at position x_pos, y_pos with an interpolated subgrid pixel shift of order=order -:param grid2d: 2d pixel grid (i.e. image) -:param x_pos: x-position center (pixel coordinate) of the layer to be added -:param y_pos: y-position center (pixel coordinate) of the layer to be added -:param kernel: the layer to be added to the image -:param order: interpolation order for sub-pixel shift of the kernel to be added -:return: image with added layer, cut to original size

-
- -
-
-lenstronomy.Util.image_util.add_layer2image_int(grid2d, x_pos, y_pos, kernel)[source]
-

adds a kernel on the grid2d image at position x_pos, y_pos at integer positions of pixel -:param grid2d: 2d pixel grid (i.e. image) -:param x_pos: x-position center (pixel coordinate) of the layer to be added -:param y_pos: y-position center (pixel coordinate) of the layer to be added -:param kernel: the layer to be added to the image -:return: image with added layer

-
- -
-
-lenstronomy.Util.image_util.add_poisson(image, exp_time)[source]
-

adds a poison (or Gaussian) distributed noise with mean given by surface brightness -:param image: pixel values (photon counts per unit exposure time) -:param exp_time: exposure time -:return: Poisson noise realization of input image

-
- -
-
-lenstronomy.Util.image_util.coordInImage(x_coord, y_coord, num_pix, deltapix)[source]
-

checks whether image positions are within the pixel image in units of arcsec -if not: remove it

-
-
Parameters
-

imcoord ((n,4) numpy array) – image coordinate (in units of angels) [[x,y,delta,magnification][…]]

-
-
Returns
-

image positions within the pixel image

-
-
-
- -
-
-lenstronomy.Util.image_util.cut_edges(image, num_pix)[source]
-

cuts out the edges of a 2d image and returns re-sized image to numPix -center is well defined for odd pixel sizes. -:param image: 2d numpy array -:param num_pix: square size of cut out image -:return: cutout image with size numPix

-
- -
-
-lenstronomy.Util.image_util.findOverlap(x_mins, y_mins, min_distance)[source]
-

finds overlapping solutions, deletes multiples and deletes non-solutions and if it is not a solution, deleted as well

-
- -
-
-lenstronomy.Util.image_util.gradient_map(image)[source]
-

computes gradients of images with the sobel transform

-
-
Parameters
-

image – 2d numpy array

-
-
Returns
-

array of same size as input, with gradients between neighboring pixels

-
-
-
- -
-
-lenstronomy.Util.image_util.radial_profile(data, center=None)[source]
-

computes radial profile

-
-
Parameters
-
    -
  • data – 2d numpy array

  • -
  • center – center [x, y] from where to compute the radial profile

  • -
-
-
Returns
-

radial profile (in units pixel)

-
-
-
- -
-
-lenstronomy.Util.image_util.re_size(image, factor=1)[source]
-

re-sizes image with nx x ny to nx/factor x ny/factor

-
-
Parameters
-
    -
  • image – 2d image with shape (nx,ny)

  • -
  • factor – integer >=1

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.image_util.re_size_array(x_in, y_in, input_values, x_out, y_out)[source]
-

resizes 2d array (i.e. image) to new coordinates. So far only works with square output aligned with coordinate axis. -:param x_in: -:param y_in: -:param input_values: -:param x_out: -:param y_out: -:return:

-
- -
-
-lenstronomy.Util.image_util.rebin_coord_transform(factor, x_at_radec_0, y_at_radec_0, Mpix2coord, Mcoord2pix)[source]
-

adopt coordinate system and transformation between angular and pixel coordinates of a re-binned image -:param bin_size: -:param ra_0: -:param dec_0: -:param x_0: -:param y_0: -:param Matrix: -:param Matrix_inv: -:return:

-
- -
-
-lenstronomy.Util.image_util.rebin_image(bin_size, image, wht_map, sigma_bkg, ra_coords, dec_coords, idex_mask)[source]
-

re-bins pixels, updates cutout image, wht_map, sigma_bkg, coordinates, PSF

-
-
Parameters
-

bin_size – number of pixels (per axis) to merge

-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.image_util.rotateImage(img, angle)[source]
-

querries scipy.ndimage.rotate routine -:param img: image to be rotated -:param angle: angle to be rotated (radian) -:return: rotated image

-
- -
-
-lenstronomy.Util.image_util.stack_images(image_list, wht_list, sigma_list)[source]
-

stacks images and saves new image as a fits file -:param image_name_list: list of image_names to be stacked -:return:

-
- -
-
-lenstronomy.Util.image_util.symmetry_average(image, symmetry)[source]
-

symmetry averaged image -:param image: -:param symmetry: -:return:

-
- -
-
-

lenstronomy.Util.kernel_util module

-

routines that manipulate convolution kernels

-
-
-lenstronomy.Util.kernel_util.averaging_even_kernel(kernel_high_res, subgrid_res)[source]
-

makes a lower resolution kernel based on the kernel_high_res (odd numbers) and the subgrid_res (even number), both -meant to be centered.

-
-
Parameters
-
    -
  • kernel_high_res – high resolution kernel with even subsampling resolution, centered

  • -
  • subgrid_res – subsampling resolution (even number)

  • -
-
-
Returns
-

averaged undersampling kernel

-
-
-
- -
-
-lenstronomy.Util.kernel_util.center_kernel(kernel, iterations=20)[source]
-

given a kernel that might not be perfectly centered, this routine computes its light weighted center and then -moves the center in an iterative process such that it is centered

-
-
Parameters
-
    -
  • kernel – 2d array (odd numbers)

  • -
  • iterations – int, number of iterations

  • -
-
-
Returns
-

centered kernel

-
-
-
- -
-
-lenstronomy.Util.kernel_util.cut_psf(psf_data, psf_size)[source]
-

cut the psf properly -:param psf_data: image of PSF -:param psf_size: size of psf -:return: re-sized and re-normalized PSF

-
- -
-
-lenstronomy.Util.kernel_util.cutout_source(x_pos, y_pos, image, kernelsize, shift=True)[source]
-

cuts out point source (e.g. PSF estimate) out of image and shift it to the center of a pixel -:param x_pos: -:param y_pos: -:param image: -:param kernelsize: -:return:

-
- -
-
-lenstronomy.Util.kernel_util.de_shift_kernel(kernel, shift_x, shift_y, iterations=20, fractional_step_size=1)[source]
-

de-shifts a shifted kernel to the center of a pixel. This is performed iteratively.

-
-
The input kernel is the solution of a linear interpolated shift of a sharper kernel centered in the middle of the

pixel. To find the de-shifted kernel, we perform an iterative correction of proposed de-shifted kernels and compare -its shifted version with the input kernel.

-
-
-
-
Parameters
-
    -
  • kernel – (shifted) kernel, e.g. a star in an image that is not centered in the pixel grid

  • -
  • shift_x – x-offset relative to the center of the pixel (sub-pixel shift)

  • -
  • shift_y – y-offset relative to the center of the pixel (sub-pixel shift)

  • -
  • iterations – number of repeated iterations of shifting a new de-shifted kernel and apply corrections

  • -
  • fractional_step_size – float (0, 1] correction factor relative to previous proposal (can be used for stability

  • -
-
-
Returns
-

de-shifted kernel such that the interpolated shift boy (shift_x, shift_y) results in the input kernel

-
-
-
- -
-
-lenstronomy.Util.kernel_util.degrade_kernel(kernel_super, degrading_factor)[source]
-
-
Parameters
-
    -
  • kernel_super – higher resolution kernel (odd number per axis)

  • -
  • degrading_factor – degrading factor (effectively the super-sampling resolution of the kernel given

  • -
-
-
Returns
-

degraded kernel with odd axis number with the sum of the flux/values in the kernel being preserved

-
-
-
- -
-
-lenstronomy.Util.kernel_util.estimate_amp(data, x_pos, y_pos, psf_kernel)[source]
-

estimates the amplitude of a point source located at x_pos, y_pos -:param data: -:param x_pos: -:param y_pos: -:param psf_kernel: -:return:

-
- -
-
-lenstronomy.Util.kernel_util.fwhm_kernel(kernel)[source]
-
-
Parameters
-

kernel

-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.kernel_util.kernel_average_pixel(kernel_super, supersampling_factor)[source]
-

computes the effective convolution kernel assuming a uniform surface brightness on the scale of a pixel

-
-
Parameters
-
    -
  • kernel_super – supersampled PSF of a point source (odd number per axis

  • -
  • supersampling_factor – supersampling factor (int)

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.kernel_util.kernel_gaussian(kernel_numPix, deltaPix, fwhm)[source]
-
- -
-
-lenstronomy.Util.kernel_util.kernel_norm(kernel)[source]
-
-
Parameters
-

kernel

-
-
Returns
-

normalisation of the psf kernel

-
-
-
- -
-
-lenstronomy.Util.kernel_util.kernel_pixelsize_change(kernel, deltaPix_in, deltaPix_out)[source]
-

change the pixel size of a given kernel -:param kernel: -:param deltaPix_in: -:param deltaPix_out: -:return:

-
- -
-
-lenstronomy.Util.kernel_util.match_kernel_size(image, size)[source]
-

matching kernel/image to a dedicated size by either expanding the image with zeros at the edges or chopping of the -edges.

-
-
Parameters
-
    -
  • image – 2d array (square with odd number of pixels)

  • -
  • size – integer (odd number)

  • -
-
-
Returns
-

image with matched size, either by cutting or by adding zeros in the outskirts

-
-
-
- -
-
-lenstronomy.Util.kernel_util.mge_kernel(kernel, order=5)[source]
-

azimutal Multi-Gaussian expansion of a pixelized kernel

-
-
Parameters
-

kernel – 2d numpy array

-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.kernel_util.pixel_kernel(point_source_kernel, subgrid_res=7)[source]
-

converts a pixelised kernel of a point source to a kernel representing a uniform extended pixel

-
-
Parameters
-
    -
  • point_source_kernel

  • -
  • subgrid_res

  • -
-
-
Returns
-

convolution kernel for an extended pixel

-
-
-
- -
-
-lenstronomy.Util.kernel_util.split_kernel(kernel_super, supersampling_kernel_size, supersampling_factor, normalized=True)[source]
-

pixel kernel and subsampling kernel such that the convolution of both applied on an image can be -performed, i.e. smaller subsampling PSF and hole in larger PSF

-
-
Parameters
-
    -
  • kernel_super – super-sampled kernel

  • -
  • supersampling_kernel_size – size of super-sampled PSF in units of degraded pixels

  • -
  • normalized – boolean, if True returns a split kernel that is area normalized=1 representing a convolution kernel

  • -
-
-
Returns
-

degraded kernel with hole and super-sampled kernel

-
-
-
- -
-
-lenstronomy.Util.kernel_util.subgrid_kernel(kernel, subgrid_res, odd=False, num_iter=100)[source]
-

creates a higher resolution kernel with subgrid resolution as an interpolation of the original kernel in an -iterative approach

-
-
Parameters
-
    -
  • kernel – initial kernel

  • -
  • subgrid_res – subgrid resolution required

  • -
-
-
Returns
-

kernel with higher resolution (larger)

-
-
-
- -
-
-

lenstronomy.Util.mask_util module

-
-
-lenstronomy.Util.mask_util.mask_azimuthal(x, y, center_x, center_y, r)[source]
-
-
Parameters
-
    -
  • x – x-coordinates (1d or 2d array numpy array)

  • -
  • y – y-coordinates (1d or 2d array numpy array)

  • -
  • center_x – center of azimuthal mask in x

  • -
  • center_y – center of azimuthal mask in y

  • -
  • r – radius of azimuthal mask

  • -
-
-
Returns
-

array with zeros outside r and ones inside azimuthal radius r

-
-
-
- -
-
-lenstronomy.Util.mask_util.mask_center_2d(center_x, center_y, r, x_grid, y_grid)[source]
-
-
Parameters
-
    -
  • center_x – x-coordinate of center position of circular mask

  • -
  • center_y – y-coordinate of center position of circular mask

  • -
  • r – radius of mask in pixel values

  • -
  • x_grid – x-coordinate grid

  • -
  • y_grid – y-coordinate grid

  • -
-
-
Returns
-

mask array of shape x_grid with =0 inside the radius and =1 outside

-
-
-
- -
-
-lenstronomy.Util.mask_util.mask_ellipse(x, y, center_x, center_y, a, b, angle)[source]
-
-
Parameters
-
    -
  • x – x-coordinates of pixels

  • -
  • y – y-coordinates of pixels

  • -
  • center_x – center of mask

  • -
  • center_y – center of mask

  • -
  • a – major axis

  • -
  • b – minor axis

  • -
  • angle – angle of major axis

  • -
-
-
Returns
-

mask (list of zeros and ones)

-
-
-
- -
-
-lenstronomy.Util.mask_util.mask_half_moon(x, y, center_x, center_y, r_in, r_out, phi0=0, delta_phi=6.283185307179586)[source]
-
-
Parameters
-
    -
  • x

  • -
  • y

  • -
  • center_x

  • -
  • center_y

  • -
  • r_in

  • -
  • r_out

  • -
  • phi0

  • -
  • delta_phi

  • -
-
-
Returns
-

-
-
-
- -
-
-

lenstronomy.Util.multi_gauss_expansion module

-
-
-lenstronomy.Util.multi_gauss_expansion.de_projection_3d(amplitudes, sigmas)[source]
-

de-projects a gaussian (or list of multiple Gaussians from a 2d projected to a 3d profile) -:param amplitudes: -:param sigmas: -:return:

-
- -
-
-lenstronomy.Util.multi_gauss_expansion.gaussian(R, sigma, amp)[source]
-
-
Parameters
-
    -
  • R – radius

  • -
  • sigma – gaussian sigma

  • -
  • amp – normalization

  • -
-
-
Returns
-

Gaussian function

-
-
-
- -
-
-lenstronomy.Util.multi_gauss_expansion.mge_1d(r_array, flux_r, N=20, linspace=False)[source]
-
-
Parameters
-
    -
  • r_array – list or radii (numpy array)

  • -
  • flux_r – list of flux values (numpy array)

  • -
  • N – number of Gaussians

  • -
-
-
Returns
-

amplitudes and Gaussian sigmas for the best 1d flux profile

-
-
-
- -
-
-

lenstronomy.Util.numba_util module

-
-
-lenstronomy.Util.numba_util.generated_jit(nopython=True, cache=True, parallel=False, fastmath=False, error_model='numpy')[source]
-
-
Wrapper around numba.generated_jit. Allows you to redirect a function to another based on its type
    -
  • see the Numba docs for more info

  • -
-
-
-
- -
-
-lenstronomy.Util.numba_util.jit(nopython=True, cache=True, parallel=False, fastmath=False, error_model='numpy', inline='never')[source]
-
- -
-
-lenstronomy.Util.numba_util.nan_to_num(x, posinf=10000000000.0, neginf=- 10000000000.0, nan=0.0)[source]
-

Implements a Numba equivalent to np.nan_to_num (with copy=False!) array or scalar in Numba. -Behaviour is the same as np.nan_to_num with copy=False, although it only supports 1-dimensional arrays and -scalar inputs.

-
- -
-
-lenstronomy.Util.numba_util.nan_to_num_arr(x, posinf=10000000000.0, neginf=- 10000000000.0, nan=0.0)[source]
-

Part of the Numba implementation of np.nan_to_num - see nan_to_num

-
- -
-
-lenstronomy.Util.numba_util.nan_to_num_single(x, posinf=10000000000.0, neginf=- 10000000000.0, nan=0.0)[source]
-

Part of the Numba implementation of np.nan_to_num - see nan_to_num

-
- -
-
-

lenstronomy.Util.param_util module

-
-
-lenstronomy.Util.param_util.cart2polar(x, y, center_x=0, center_y=0)[source]
-

transforms cartesian coords [x,y] into polar coords [r,phi] in the frame of the lens center

-
-
Parameters
-
    -
  • x (array of size (n)) – set of x-coordinates

  • -
  • y (array of size (n)) – set of x-coordinates

  • -
  • center_x (float) – rotation point

  • -
  • center_y (float) – rotation point

  • -
-
-
Returns
-

array of same size with coords [r,phi]

-
-
-
- -
-
-lenstronomy.Util.param_util.ellipticity2phi_q(e1, e2)[source]
-

transforms complex ellipticity moduli in orientation angle and axis ratio

-
-
Parameters
-
    -
  • e1 – eccentricity in x-direction

  • -
  • e2 – eccentricity in xy-direction

  • -
-
-
Returns
-

angle in radian, axis ratio (minor/major)

-
-
-
- -
-
-lenstronomy.Util.param_util.phi_q2_ellipticity(phi, q)[source]
-

transforms orientation angle and axis ratio into complex ellipticity moduli e1, e2

-
-
Parameters
-
    -
  • phi – angle of orientation (in radian)

  • -
  • q – axis ratio minor axis / major axis

  • -
-
-
Returns
-

eccentricities e1 and e2 in complex ellipticity moduli

-
-
-
- -
-
-lenstronomy.Util.param_util.polar2cart(r, phi, center)[source]
-

transforms polar coords [r,phi] into cartesian coords [x,y] in the frame of the lense center

-
-
Parameters
-
    -
  • coord (array of size (n,2)) – set of coordinates

  • -
  • center (array of size (2)) – rotation point

  • -
-
-
Returns
-

array of same size with coords [x,y]

-
-
Raises
-

AttributeError, KeyError

-
-
-
- -
-
-lenstronomy.Util.param_util.shear_cartesian2polar(gamma1, gamma2)[source]
-
-
Parameters
-
    -
  • gamma1 – cartesian shear component

  • -
  • gamma2 – cartesian shear component

  • -
-
-
Returns
-

shear angle, shear strength

-
-
-
- -
-
-lenstronomy.Util.param_util.shear_polar2cartesian(phi, gamma)[source]
-
-
Parameters
-
    -
  • phi – shear angle (radian)

  • -
  • gamma – shear strength

  • -
-
-
Returns
-

shear components gamma1, gamma2

-
-
-
- -
-
-lenstronomy.Util.param_util.transform_e1e2_product_average(x, y, e1, e2, center_x, center_y)[source]
-

maps the coordinates x, y with eccentricities e1 e2 into a new elliptical coordinate system -such that R = sqrt(R_major * R_minor)

-
-
Parameters
-
    -
  • x – x-coordinate

  • -
  • y – y-coordinate

  • -
  • e1 – eccentricity

  • -
  • e2 – eccentricity

  • -
  • center_x – center of distortion

  • -
  • center_y – center of distortion

  • -
-
-
Returns
-

distorted coordinates x’, y’

-
-
-
- -
-
-lenstronomy.Util.param_util.transform_e1e2_square_average(x, y, e1, e2, center_x, center_y)[source]
-

maps the coordinates x, y with eccentricities e1 e2 into a new elliptical coordinate system -such that R = sqrt(R_major**2 + R_minor**2)

-
-
Parameters
-
    -
  • x – x-coordinate

  • -
  • y – y-coordinate

  • -
  • e1 – eccentricity

  • -
  • e2 – eccentricity

  • -
  • center_x – center of distortion

  • -
  • center_y – center of distortion

  • -
-
-
Returns
-

distorted coordinates x’, y’

-
-
-
- -
-
-

lenstronomy.Util.prob_density module

-
-
-class lenstronomy.Util.prob_density.KDE1D(values)[source]
-

Bases: object

-

class that allows to compute likelihoods based on a 1-d posterior sample

-
-
-likelihood(x)[source]
-
-
Parameters
-

x – position where to evaluate the density

-
-
Returns
-

likelihood given the sample distribution

-
-
-
- -
- -
-
-class lenstronomy.Util.prob_density.SkewGaussian[source]
-

Bases: object

-

class for the Skew Gaussian distribution

-
-
-map_mu_sigma_skw(mu, sigma, skw)[source]
-

map to parameters e, w, a -:param mu: mean -:param sigma: standard deviation -:param skw: skewness -:return: e, w, a

-
- -
-
-pdf(x, e=0.0, w=1.0, a=0.0)[source]
-

probability density function -see: https://en.wikipedia.org/wiki/Skew_normal_distribution -:param x: input value -:param e: -:param w: -:param a: -:return:

-
- -
-
-pdf_skew(x, mu, sigma, skw)[source]
-

function with different parameterisation -:param x: -:param mu: mean -:param sigma: sigma -:param skw: skewness -:return:

-
- -
- -
-
-lenstronomy.Util.prob_density.compute_lower_upper_errors(sample, num_sigma=1)[source]
-

computes the upper and lower sigma from the median value. -This functions gives good error estimates for skewed pdf’s -:param sample: 1-D sample -:param num_sigma: integer, number of sigmas to be returned -:return: median, lower_sigma, upper_sigma

-
- -
-
-

lenstronomy.Util.sampling_util module

-
-
-lenstronomy.Util.sampling_util.cube2args_gaussian(cube, lowers, uppers, means, sigmas, num_dims, copy=False)[source]
-

mapping from uniform distribution on unit hypercube ‘cube’ -to truncated gaussian distribution on parameter space, -with mean ‘mu’ and std dev ‘sigma’

-
-
Parameters
-
    -
  • cube – list or 1D-array of parameter values on unit hypercube

  • -
  • lowers – lower bounds for each parameter

  • -
  • uppers – upper bounds for each parameter

  • -
  • means – gaussian mean for each parameter

  • -
  • sigmas – gaussian std deviation for each parameter

  • -
  • num_dims – parameter space dimension (= number of parameters)

  • -
  • copy – If False, this function modifies ‘cube’ in-place. Default to False.

  • -
-
-
Returns
-

hypercube mapped to parameters space

-
-
-
- -
-
-lenstronomy.Util.sampling_util.cube2args_uniform(cube, lowers, uppers, num_dims, copy=False)[source]
-

mapping from uniform distribution on unit hypercube ‘cube’ -to uniform distribution on parameter space

-
-
Parameters
-
    -
  • cube – list or 1D-array of parameter values on unit hypercube

  • -
  • lowers – lower bounds for each parameter

  • -
  • uppers – upper bounds for each parameter

  • -
  • num_dims – parameter space dimension (= number of parameters)

  • -
  • copy – If False, this function modifies ‘cube’ in-place. Default to False.

  • -
-
-
Returns
-

hypercube mapped to parameters space

-
-
-
- -
-
-lenstronomy.Util.sampling_util.sample_ball(p0, std, size=1, dist='uniform')[source]
-

Produce a ball of walkers around an initial parameter value. -this routine is from the emcee package as it became deprecated there

-
-
Parameters
-
    -
  • p0 – The initial parameter values (array).

  • -
  • std – The axis-aligned standard deviation (array).

  • -
  • size – The number of samples to produce.

  • -
  • dist – string, specifies the distribution being sampled, supports ‘uniform’ and ‘normal’

  • -
-
-
-
- -
-
-lenstronomy.Util.sampling_util.sample_ball_truncated(mean, sigma, lower_limit, upper_limit, size)[source]
-

samples gaussian ball with truncation at lower and upper limit of the distribution

-
-
Parameters
-
    -
  • mean – numpy array, mean of the distribution to be sampled

  • -
  • sigma – numpy array, sigma of the distribution to be sampled

  • -
  • lower_limit – numpy array, lower bound of to be sampled distribution

  • -
  • upper_limit – numpy array, upper bound of to be sampled distribution

  • -
  • size – number of tuples to be sampled

  • -
-
-
Returns
-

realization of truncated normal distribution with shape (size, dim(parameters))

-
-
-
- -
-
-lenstronomy.Util.sampling_util.scale_limits(lowers, uppers, scale)[source]
-
- -
-
-lenstronomy.Util.sampling_util.uniform2unit(theta, vmin, vmax)[source]
-

mapping from uniform distribution on unit hypercube -to uniform distribution on parameter space

-
- -
-
-lenstronomy.Util.sampling_util.unit2uniform(x, vmin, vmax)[source]
-

mapping from uniform distribution on parameter space -to uniform distribution on unit hypercube

-
- -
-
-

lenstronomy.Util.simulation_util module

-
-
-lenstronomy.Util.simulation_util.data_configure_simple(numPix, deltaPix, exposure_time=None, background_rms=None, center_ra=0, center_dec=0, inverse=False)[source]
-

configures the data keyword arguments with a coordinate grid centered at zero.

-
-
Parameters
-
    -
  • numPix – number of pixel (numPix x numPix)

  • -
  • deltaPix – pixel size (in angular units)

  • -
  • exposure_time – exposure time

  • -
  • background_rms – background noise (Gaussian sigma)

  • -
  • center_ra – RA at the center of the image

  • -
  • center_dec – DEC at the center of the image

  • -
  • inverse – if True, coordinate system is ra to the left, if False, to the right

  • -
-
-
Returns
-

keyword arguments that can be used to construct a Data() class instance of lenstronomy

-
-
-
- -
-
-lenstronomy.Util.simulation_util.simulate_simple(image_model_class, kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, no_noise=False, source_add=True, lens_light_add=True, point_source_add=True)[source]
-
-
Parameters
-
    -
  • image_model_class

  • -
  • kwargs_lens

  • -
  • kwargs_source

  • -
  • kwargs_lens_light

  • -
  • kwargs_ps

  • -
  • no_noise

  • -
  • source_add

  • -
  • lens_light_add

  • -
  • point_source_add

  • -
-
-
Returns
-

-
-
-
- -
-
-

lenstronomy.Util.util module

-
-
-lenstronomy.Util.util.approx_theta_E(ximg, yimg)[source]
-
- -
-
-lenstronomy.Util.util.array2cube(array, n_1, n_23)[source]
-

returns the information contained in a 1d array of shape (n_1*n_23*n_23) into 3d array with shape (n_1, sqrt(n_23), sqrt(n_23))

-
-
Parameters
-
    -
  • array (1d array) – image values

  • -
  • n_1 (int) – first dimension of returned array

  • -
  • n_23 (int) – square of second and third dimensions of returned array

  • -
-
-
Returns
-

3d array

-
-
Raises
-

ValueError – when n_23 is not a perfect square

-
-
-
- -
-
-lenstronomy.Util.util.array2image(array, nx=0, ny=0)[source]
-

returns the information contained in a 1d array into an n*n 2d array -(only works when length of array is n**2, or nx and ny are provided)

-
-
Parameters
-

array (array of size n**2) – image values

-
-
Returns
-

2d array

-
-
Raises
-

AttributeError, KeyError

-
-
-
- -
-
-lenstronomy.Util.util.averaging(grid, numGrid, numPix)[source]
-

resize 2d pixel grid with numGrid to numPix and averages over the pixels -:param grid: higher resolution pixel grid -:param numGrid: number of pixels per axis in the high resolution input image -:param numPix: lower number of pixels per axis in the output image (numGrid/numPix is integer number) -:return:

-
- -
-
-lenstronomy.Util.util.compare_distance(x_mapped, y_mapped)[source]
-
-
Parameters
-
    -
  • x_mapped – array of x-positions of remapped catalogue image

  • -
  • y_mapped – array of y-positions of remapped catalogue image

  • -
-
-
Returns
-

sum of distance square of positions

-
-
-
- -
-
-lenstronomy.Util.util.convert_bool_list(n, k=None)[source]
-

returns a bool list of the length of the lens models -if k = None: returns bool list with True’s -if k is int, returns bool list with False’s but k’th is True -if k is a list of int, e.g. [0, 3, 5], returns a bool list with True’s in the integers listed and False elsewhere -if k is a boolean list, checks for size to match the numbers of models and returns it

-
-
Parameters
-
    -
  • n – integer, total lenght of output boolean list

  • -
  • k – None, int, or list of ints

  • -
-
-
Returns
-

bool list

-
-
-
- -
-
-lenstronomy.Util.util.cube2array(cube)[source]
-

returns the information contained in a 3d array of shape (n_1, n_2, n_3) into 1d array with shape (n_1*n_2*n_3)

-
-
Parameters
-

cube (3d array) – image values

-
-
Returns
-

1d array

-
-
-
- -
-
-lenstronomy.Util.util.displaceAbs(x, y, sourcePos_x, sourcePos_y)[source]
-

calculates a grid of distances to the observer in angel

-
-
Parameters
-
    -
  • x (numpy array) – cartesian coordinates

  • -
  • y (numpy array) – cartesian coordinates

  • -
  • sourcePos_x (float) – source position

  • -
  • sourcePos_y (float) – source position

  • -
-
-
Returns
-

array of displacement

-
-
Raises
-

AttributeError, KeyError

-
-
-
- -
-
-lenstronomy.Util.util.fwhm2sigma(fwhm)[source]
-
-
Parameters
-

fwhm – full-widt-half-max value

-
-
Returns
-

gaussian sigma (sqrt(var))

-
-
-
- -
-
-lenstronomy.Util.util.get_axes(x, y)[source]
-

computes the axis x and y of a given 2d grid -:param x: -:param y: -:return:

-
- -
-
-lenstronomy.Util.util.get_distance(x_mins, y_mins, x_true, y_true)[source]
-
-
Parameters
-
    -
  • x_mins

  • -
  • y_mins

  • -
  • x_true

  • -
  • y_true

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.util.grid_from_coordinate_transform(nx, ny, Mpix2coord, ra_at_xy_0, dec_at_xy_0)[source]
-

return a grid in x and y coordinates that satisfy the coordinate system

-
-
Parameters
-
    -
  • nx – number of pixels in x-axis

  • -
  • ny – number of pixels in y-axis

  • -
  • Mpix2coord – transformation matrix (2x2) of pixels into coordinate displacements

  • -
  • ra_at_xy_0 – RA coordinate at (x,y) = (0,0)

  • -
  • dec_at_xy_0 – DEC coordinate at (x,y) = (0,0)

  • -
-
-
Returns
-

RA coordinate grid, DEC coordinate grid

-
-
-
- -
-
-lenstronomy.Util.util.hyper2F2_array(a, b, c, d, x)[source]
-
-
Parameters
-
    -
  • a

  • -
  • b

  • -
  • c

  • -
  • d

  • -
  • x

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.util.image2array(image)[source]
-

returns the information contained in a 2d array into an n*n 1d array

-
-
Parameters
-

image (array of size (n,n)) – image values

-
-
Returns
-

1d array

-
-
Raises
-

AttributeError, KeyError

-
-
-
- -
-
-lenstronomy.Util.util.make_grid(numPix, deltapix, subgrid_res=1, left_lower=False)[source]
-

creates pixel grid (in 1d arrays of x- and y- positions) -default coordinate frame is such that (0,0) is in the center of the coordinate grid

-
-
Parameters
-
    -
  • numPix – number of pixels per axis -Give an integers for a square grid, or a 2-length sequence -(first, second axis length) for a non-square grid.

  • -
  • deltapix – pixel size

  • -
  • subgrid_res – sub-pixel resolution (default=1)

  • -
-
-
Returns
-

x, y position information in two 1d arrays

-
-
-
- -
-
-lenstronomy.Util.util.make_grid_transformed(numPix, Mpix2Angle)[source]
-

returns grid with linear transformation (deltaPix and rotation) -:param numPix: number of Pixels -:param Mpix2Angle: 2-by-2 matrix to mat a pixel to a coordinate -:return: coordinate grid

-
- -
-
-lenstronomy.Util.util.make_grid_with_coordtransform(numPix, deltapix, subgrid_res=1, center_ra=0, center_dec=0, left_lower=False, inverse=True)[source]
-

same as make_grid routine, but returns the transformation matrix and shift between coordinates and pixel

-
-
Parameters
-
    -
  • numPix – number of pixels per axis

  • -
  • deltapix – pixel scale per axis

  • -
  • subgrid_res – super-sampling resolution relative to the stated pixel size

  • -
  • center_ra – center of the grid

  • -
  • center_dec – center of the grid

  • -
  • left_lower – sets the zero point at the lower left corner of the pixels

  • -
  • inverse – bool, if true sets East as left, otherwise East is righrt

  • -
-
-
Returns
-

ra_grid, dec_grid, ra_at_xy_0, dec_at_xy_0, x_at_radec_0, y_at_radec_0, Mpix2coord, Mcoord2pix

-
-
-
- -
-
-lenstronomy.Util.util.make_subgrid(ra_coord, dec_coord, subgrid_res=2)[source]
-

return a grid with subgrid resolution -:param ra_coord: -:param dec_coord: -:param subgrid_res: -:return:

-
- -
-
-lenstronomy.Util.util.map_coord2pix(ra, dec, x_0, y_0, M)[source]
-

this routines performs a linear transformation between two coordinate systems. Mainly used to transform angular -into pixel coordinates in an image -:param ra: ra coordinates -:param dec: dec coordinates -:param x_0: pixel value in x-axis of ra,dec = 0,0 -:param y_0: pixel value in y-axis of ra,dec = 0,0 -:param M: 2x2 matrix to transform angular to pixel coordinates -:return: transformed coordinate systems of input ra and dec

-
- -
-
-lenstronomy.Util.util.merge_dicts(*dict_args)[source]
-

Given any number of dicts, shallow copy and merge into a new dict, -precedence goes to key value pairs in latter dicts.

-
- -
-
-lenstronomy.Util.util.min_square_dist(x_1, y_1, x_2, y_2)[source]
-

return minimum of quadratic distance of pairs (x1, y1) to pairs (x2, y2) -:param x_1: -:param y_1: -:param x_2: -:param y_2: -:return:

-
- -
-
-lenstronomy.Util.util.neighborSelect(a, x, y)[source]
-

#TODO replace by from scipy.signal import argrelextrema for speed up ->>> from scipy.signal import argrelextrema ->>> x = np.array([2, 1, 2, 3, 2, 0, 1, 0]) ->>> argrelextrema(x, np.greater) -(array([3, 6]),) ->>> y = np.array([[1, 2, 1, 2], -… [2, 2, 0, 0], -… [5, 3, 4, 4]]) -… ->>> argrelextrema(y, np.less, axis=1) -(array([0, 2]), array([2, 1]))

-

finds (local) minima in a 2d grid

-
-
Parameters
-

a (numpy array with length numPix**2 in float) – 1d array of displacements from the source positions

-
-
Returns
-

array of indices of local minima, values of those minima

-
-
Raises
-

AttributeError, KeyError

-
-
-
- -
-
-lenstronomy.Util.util.points_on_circle(radius, num_points, connect_ends=True)[source]
-

returns a set of uniform points around a circle -:param radius: radius of the circle -:param num_points: number of points on the circle -:param connect_ends: boolean, if True, start and end point are the same -:return: x-coords, y-coords of points on the circle

-
- -
-
-lenstronomy.Util.util.rotate(xcoords, ycoords, angle)[source]
-
-
Parameters
-
    -
  • xcoords – x points

  • -
  • ycoords – y points

  • -
  • angle – angle in radians

  • -
-
-
Returns
-

x points and y points rotated ccw by angle theta

-
-
-
- -
-
-lenstronomy.Util.util.selectBest(array, criteria, numSelect, highest=True)[source]
-
-
Parameters
-
    -
  • array – numpy array to be selected from

  • -
  • criteria – criteria of selection

  • -
  • highest – bool, if false the lowest will be selected

  • -
  • numSelect – number of elements to be selected

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.util.select_best(array, criteria, num_select, highest=True)[source]
-
-
Parameters
-
    -
  • array – numpy array to be selected from

  • -
  • criteria – criteria of selection

  • -
  • highest – bool, if false the lowest will be selected

  • -
  • num_select – number of elements to be selected

  • -
-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.util.sigma2fwhm(sigma)[source]
-
-
Parameters
-

sigma

-
-
Returns
-

-
-
-
- -
-
-lenstronomy.Util.util.sort_image_index(ximg, yimg, xref, yref)[source]
-
-
Parameters
-
    -
  • ximg – x coordinates to sort

  • -
  • yimg – y coordinates to sort

  • -
  • xref – reference x coordinate

  • -
  • yref – reference y coordinate

  • -
-
-
Returns
-

indexes such that ximg[indexes],yimg[indexes] matches xref,yref

-
-
-
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.Workflow.html b/docs/_build/html/lenstronomy.Workflow.html deleted file mode 100644 index 7a321bd86..000000000 --- a/docs/_build/html/lenstronomy.Workflow.html +++ /dev/null @@ -1,996 +0,0 @@ - - - - - - - - - lenstronomy.Workflow package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy.Workflow package

-
-

Submodules

-
-
-

lenstronomy.Workflow.alignment_matching module

-
-
-class lenstronomy.Workflow.alignment_matching.AlignmentFitting(multi_band_list, kwargs_model, kwargs_params, band_index=0, likelihood_mask_list=None)[source]
-

Bases: object

-

class which executes the different sampling methods

-
-
-pso(n_particles=10, n_iterations=10, lowerLimit=- 0.2, upperLimit=0.2, threadCount=1, mpi=False, print_key='default')[source]
-

returns the best fit for the lense model on catalogue basis with particle swarm optimizer

-
- -
- -
-
-class lenstronomy.Workflow.alignment_matching.AlignmentLikelihood(multi_band_list, kwargs_model, kwargs_params, band_index=0, likelihood_mask_list=None)[source]
-

Bases: object

-
-
-computeLikelihood(ctx)[source]
-
- -
-
-static get_args(kwargs_data)[source]
-
-
Parameters
-

kwargs_data

-
-
Returns
-

-
-
-
- -
-
-likelihood(a)[source]
-
- -
-
-property num_param
-
- -
-
-setup()[source]
-
- -
-
-update_data(args)[source]
-
-
Parameters
-

args

-
-
Returns
-

-
-
-
- -
-
-update_multi_band(args)[source]
-
-
Parameters
-

args – list of parameters

-
-
Returns
-

updated multi_band_list

-
-
-
- -
- -
-
-

lenstronomy.Workflow.fitting_sequence module

-
-
-class lenstronomy.Workflow.fitting_sequence.FittingSequence(kwargs_data_joint, kwargs_model, kwargs_constraints, kwargs_likelihood, kwargs_params, mpi=False, verbose=True)[source]
-

Bases: object

-

class to define a sequence of fitting applied, inherit the Fitting class -this is a Workflow manager that allows to update model configurations before executing another step in the modelling -The user can take this module as an example of how to create their own workflows or build their own around the FittingSequence

-
-
-align_images(n_particles=10, n_iterations=10, lowerLimit=- 0.2, upperLimit=0.2, threadCount=1, compute_bands=None)[source]
-

aligns the coordinate systems of different exposures within a fixed model parameterisation by executing a PSO -with relative coordinate shifts as free parameters

-
-
Parameters
-
    -
  • n_particles – number of particles in the Particle Swarm Optimization

  • -
  • n_iterations – number of iterations in the optimization process

  • -
  • lowerLimit – lower limit of relative shift

  • -
  • upperLimit – upper limit of relative shift

  • -
  • compute_bands – bool list, if multiple bands, this process can be limited to a subset of bands

  • -
-
-
Returns
-

0, updated coordinate system for the band(s)

-
-
-
- -
-
-best_fit(bijective=False)[source]
-
-
Parameters
-

bijective – bool, if True, the mapping of image2source_plane and the mass_scaling parameterisation are inverted. If you do not use those options, there is no effect.

-
-
Returns
-

best fit model of the current state of the FittingSequence class

-
-
-
- -
-
-best_fit_from_samples(samples, logl)[source]
-

return best fit (max likelihood) value of samples in lenstronomy conventions

-
-
Parameters
-
    -
  • samples – samples of multi-dimensional parameter space

  • -
  • logl – likelihood values for each sample

  • -
-
-
Returns
-

kwargs_result in lenstronomy convention

-
-
-
- -
-
-property best_fit_likelihood
-

returns the log likelihood of the best fit model of the current state of this class

-
-
Returns
-

log likelihood, float

-
-
-
- -
-
-property bic
-

returns the bayesian information criterion of the model. -:return: bic value, float

-
- -
-
-fit_sequence(fitting_list)[source]
-
-
Parameters
-

fitting_list – list of [[‘string’, {kwargs}], ..] with ‘string being the specific fitting option and -kwargs being the arguments passed to this option

-
-
Returns
-

fitting results

-
-
-
- -
-
-fix_not_computed(free_bands)[source]
-

fixes lens model parameters of imaging bands/frames that are not computed and frees the parameters of the other -lens models to the initial kwargs_fixed options

-
-
Parameters
-

free_bands – bool list of length of imaging bands in order of imaging bands, if False: set fixed lens model

-
-
Returns
-

None

-
-
-
- -
-
-kwargs_fixed()[source]
-

returns the updated kwargs_fixed from the update Manager

-
-
Returns
-

list of fixed kwargs, see UpdateManager()

-
-
-
- -
-
-property likelihoodModule
-
-
Returns
-

Likelihood() class instance reflecting the current state of FittingSequence

-
-
-
- -
-
-mcmc(n_burn, n_run, walkerRatio, n_walkers=None, sigma_scale=1, threadCount=1, init_samples=None, re_use_samples=True, sampler_type='EMCEE', progress=True, backup_filename=None, start_from_backup=False)[source]
-

MCMC routine

-
-
Parameters
-
    -
  • n_burn – number of burn in iterations (will not be saved)

  • -
  • n_run – number of MCMC iterations that are saved

  • -
  • walkerRatio – ratio of walkers/number of free parameters

  • -
  • n_walkers – integer, number of walkers of emcee (optional, if set, overwrites the walkerRatio input

  • -
  • sigma_scale – scaling of the initial parameter spread relative to the width in the initial settings

  • -
  • threadCount – number of CPU threads. If MPI option is set, threadCount=1

  • -
  • init_samples – initial sample from where to start the MCMC process

  • -
  • re_use_samples – bool, if True, re-uses the samples described in init_samples.nOtherwise starts from scratch.

  • -
  • sampler_type – string, which MCMC sampler to be used. Options are: ‘EMCEE’

  • -
  • progress – boolean, if True shows progress bar in EMCEE

  • -
-
-
Returns
-

list of output arguments, e.g. MCMC samples, parameter names, logL distances of all samples specified by the specific sampler used

-
-
-
- -
-
-nested_sampling(sampler_type='MULTINEST', kwargs_run={}, prior_type='uniform', width_scale=1, sigma_scale=1, output_basename='chain', remove_output_dir=True, dypolychord_dynamic_goal=0.8, polychord_settings={}, dypolychord_seed_increment=200, output_dir='nested_sampling_chains', dynesty_bound='multi', dynesty_sample='auto')[source]
-

Run (Dynamic) Nested Sampling algorithms, depending on the type of algorithm.

-
-
Parameters
-
    -
  • sampler_type – ‘MULTINEST’, ‘DYPOLYCHORD’, ‘DYNESTY’

  • -
  • kwargs_run – keywords passed to the core sampling method

  • -
  • prior_type – ‘uniform’ of ‘gaussian’, for converting the unit hypercube to param cube

  • -
  • width_scale – scale the width (lower/upper limits) of the parameters space by this factor

  • -
  • sigma_scale – if prior_type is ‘gaussian’, scale the gaussian sigma by this factor

  • -
  • output_basename – name of the folder in which the core MultiNest/PolyChord code will save output files

  • -
  • remove_output_dir – if True, the above folder is removed after completion

  • -
  • dypolychord_dynamic_goal – dynamic goal for DyPolyChord (trade-off between evidence (0) and posterior (1) computation)

  • -
  • polychord_settings – settings dictionary to send to pypolychord. Check dypolychord documentation for details.

  • -
  • dypolychord_seed_increment – seed increment for dypolychord with MPI. Check dypolychord documentation for details.

  • -
  • dynesty_bound – see https://dynesty.readthedocs.io for details

  • -
  • dynesty_sample – see https://dynesty.readthedocs.io for details

  • -
-
-
Returns
-

list of output arguments : samples, mean inferred values, log-likelihood, log-evidence, error on log-evidence for each sample

-
-
-
- -
-
-property param_class
-
-
Returns
-

Param() class instance reflecting the current state of FittingSequence

-
-
-
- -
-
-psf_iteration(compute_bands=None, **kwargs_psf_iter)[source]
-

iterative PSF reconstruction

-
-
Parameters
-
    -
  • compute_bands – bool list, if multiple bands, this process can be limited to a subset of bands

  • -
  • kwargs_psf_iter – keyword arguments as used or available in PSFIteration.update_iterative() definition

  • -
-
-
Returns
-

0, updated PSF is stored in self.multi_band_list

-
-
-
- -
-
-pso(n_particles, n_iterations, sigma_scale=1, print_key='PSO', threadCount=1)[source]
-

Particle Swarm Optimization

-
-
Parameters
-
    -
  • n_particles – number of particles in the Particle Swarm Optimization

  • -
  • n_iterations – number of iterations in the optimization process

  • -
  • sigma_scale – scaling of the initial parameter spread relative to the width in the initial settings

  • -
  • print_key – string, printed text when executing this routine

  • -
  • threadCount – number of CPU threads. If MPI option is set, threadCount=1

  • -
-
-
Returns
-

result of the best fit, the chain of the best fit parameter after each iteration, list of parameters in same order

-
-
-
- -
-
-set_param_value(**kwargs)[source]
-

Set a parameter to a specific value. kwargs are below. -:param lens: [[i_model, [‘param1’, ‘param2’,…], […]] -:type lens: -:param source: [[i_model, [‘param1’, ‘param2’,…], […]] -:type source: -:param lens_light: [[i_model, [‘param1’, ‘param2’,…], […]] -:type lens_light: -:param ps: [[i_model, [‘param1’, ‘param2’,…], […]] -:type ps: -:return: 0, the value of the param is overwritten -:rtype:

-
- -
-
-simplex(n_iterations, method='Nelder-Mead')[source]
-

Downhill simplex optimization using the Nelder-Mead algorithm.

-
-
Parameters
-
    -
  • n_iterations – maximum number of iterations to perform

  • -
  • method – the optimization method used, see documentation in scipy.optimize.minimize

  • -
-
-
Returns
-

result of the best fit

-
-
-
- -
-
-update_settings(kwargs_model={}, kwargs_constraints={}, kwargs_likelihood={}, lens_add_fixed=[], source_add_fixed=[], lens_light_add_fixed=[], ps_add_fixed=[], cosmo_add_fixed=[], lens_remove_fixed=[], source_remove_fixed=[], lens_light_remove_fixed=[], ps_remove_fixed=[], cosmo_remove_fixed=[], change_source_lower_limit=None, change_source_upper_limit=None, change_lens_lower_limit=None, change_lens_upper_limit=None)[source]
-

updates lenstronomy settings “on the fly”

-
-
Parameters
-
    -
  • kwargs_model – kwargs, specified keyword arguments overwrite the existing ones

  • -
  • kwargs_constraints – kwargs, specified keyword arguments overwrite the existing ones

  • -
  • kwargs_likelihood – kwargs, specified keyword arguments overwrite the existing ones

  • -
  • lens_add_fixed – [[i_model, [‘param1’, ‘param2’,…], […]]

  • -
  • source_add_fixed – [[i_model, [‘param1’, ‘param2’,…], […]]

  • -
  • lens_light_add_fixed – [[i_model, [‘param1’, ‘param2’,…], […]]

  • -
  • ps_add_fixed – [[i_model, [‘param1’, ‘param2’,…], […]]

  • -
  • cosmo_add_fixed – [‘param1’, ‘param2’,…]

  • -
  • lens_remove_fixed – [[i_model, [‘param1’, ‘param2’,…], […]]

  • -
  • source_remove_fixed – [[i_model, [‘param1’, ‘param2’,…], […]]

  • -
  • lens_light_remove_fixed – [[i_model, [‘param1’, ‘param2’,…], […]]

  • -
  • ps_remove_fixed – [[i_model, [‘param1’, ‘param2’,…], […]]

  • -
  • cosmo_remove_fixed – [‘param1’, ‘param2’,…]

  • -
  • change_lens_lower_limit – [[i_model, [‘param_name’, …], [value1, value2, …]]]

  • -
-
-
Returns
-

0, the settings are overwritten for the next fitting step to come

-
-
-
- -
-
-update_state(kwargs_update)[source]
-

updates current best fit state to the input model keywords specified.

-
-
Parameters
-

kwargs_update – format of kwargs_result

-
-
Returns
-

None

-
-
-
- -
- -
-
-

lenstronomy.Workflow.psf_fitting module

-
-
-class lenstronomy.Workflow.psf_fitting.PsfFitting(image_model_class)[source]
-

Bases: object

-

class to find subsequently a better psf -The method make use of a model and subtracts all the non-point source components of the model from the data. -If the model is sufficient, then the data will be a (better) representation of the actual PSF. The method cuts out -those point sources and combines them to update the estimate of the PSF. This is done in an iterative procedure as -the model components of the extended features is PSF-dependent (hopefully not too much).

-

Various options can be chosen. There is no guarantee that the method works for specific data and models.

-
-
‘stacking_method’: ‘median’, ‘mean’; the different estimates of the PSF are stacked and combined together. The choices are:

‘mean’: mean of pixel values as the estimator (not robust to outliers) -‘median’: median of pixel values as the estimator (outlier rejection robust but needs >2 point sources in the data

-
-
‘block_center_neighbour’: angle, radius of neighbouring point sources around their centers the estimates is ignored.

Default is zero, meaning a not optimal subtraction of the neighbouring point sources might contaminate the estimate.

-
-
‘keep_error_map’: bool, if True, does not replace the error term associated with the PSF estimate.

If false, re-estimates the variance between the PSF estimates.

-
-
‘psf_symmetry’: number of rotational invariant symmetries in the estimated PSF.

=1 mean no additional symmetries. =4 means 90 deg symmetry. This is enforced by a rotatioanl stack according to -the symmetry specified. These additional imposed symmetries can help stabelize the PSF estimate when there are -limited constraints/number of point sources in the image.

-
-
-

The procedure only requires and changes the ‘point_source_kernel’ in the PSF() class and the ‘psf_error_map’. -Any previously set subgrid kernels or pixel_kernels are removed and constructed from the ‘point_source_kernel’.

-
-
-static combine_psf(kernel_list_new, kernel_old, factor=1.0, stacking_option='median', symmetry=1)[source]
-

updates psf estimate based on old kernel and several new estimates -:param kernel_list_new: list of new PSF kernels estimated from the point sources in the image (un-normalized) -:param kernel_old: old PSF kernel -:param factor: weight of updated estimate based on new and old estimate, factor=1 means new estimate, -factor=0 means old estimate -:param stacking_option: option of stacking, mean or median -:param symmetry: imposed symmetry of PSF estimate -:return: updated PSF estimate and error_map associated with it

-
- -
-
-cutout_psf(ra_image, dec_image, x, y, image_list, kernel_size, kernel_init, block_center_neighbour=0)[source]
-
-
Parameters
-
    -
  • ra_image – coordinate array of images in angles

  • -
  • dec_image – coordinate array of images in angles

  • -
  • x – image position array in x-pixel

  • -
  • y – image position array in y-pixel

  • -
  • image_list – list of images (i.e. data - all models subtracted, except a single point source)

  • -
  • kernel_size – width in pixel of the kernel

  • -
  • kernel_init – initial guess of kernel (pixels that are masked are replaced by those values)

  • -
  • block_center_neighbour – angle, radius of neighbouring point sources around their centers the estimates -is ignored. Default is zero, meaning a not optimal subtraction of the neighbouring point sources might -contaminate the estimate.

  • -
-
-
Returns
-

list of de-shifted kernel estimates

-
-
-
- -
-
-static cutout_psf_single(x, y, image, mask, kernel_size, kernel_init)[source]
-
-
Parameters
-
    -
  • x – x-coordinate of point source

  • -
  • y – y-coordinate of point source

  • -
  • image – image (i.e. data - all models subtracted, except a single point source)

  • -
  • mask – mask of pixels in the image not to be considered in the PSF estimate (being replaced by kernel_init)

  • -
  • kernel_size – width in pixel of the kernel

  • -
  • kernel_init – initial guess of kernel (pixels that are masked are replaced by those values)

  • -
-
-
Returns
-

estimate of the PSF based on the image and position of the point source

-
-
-
- -
-
-error_map_estimate(kernel, star_cutout_list, amp, x_pos, y_pos, error_map_radius=None, block_center_neighbour=0)[source]
-

provides a psf_error_map based on the goodness of fit of the given PSF kernel on the point source cutouts, -their estimated amplitudes and positions

-
-
Parameters
-
    -
  • kernel – PSF kernel

  • -
  • star_cutout_list – list of 2d arrays of cutouts of the point sources with all other model components subtracted

  • -
  • amp – list of amplitudes of the estimated PSF kernel

  • -
  • x_pos – pixel position (in original data unit, not in cutout) of the point sources (same order as amp and star cutouts)

  • -
  • y_pos – pixel position (in original data unit, not in cutout) of the point sources (same order as amp and star cutouts)

  • -
  • error_map_radius – float, radius (in arc seconds) of the outermost error in the PSF estimate (e.g. to avoid double counting of overlapping PSF erros)

  • -
  • block_center_neighbour – angle, radius of neighbouring point sources around their centers the estimates -is ignored. Default is zero, meaning a not optimal subtraction of the neighbouring point sources might -contaminate the estimate.

  • -
-
-
Returns
-

relative uncertainty in the psf model (in quadrature) per pixel based on residuals achieved in the image

-
-
-
- -
-
-error_map_estimate_new(psf_kernel, psf_kernel_list, ra_image, dec_image, point_amp, supersampling_factor, error_map_radius=None)[source]
-

relative uncertainty in the psf model (in quadrature) per pixel based on residuals achieved in the image

-
-
Parameters
-
    -
  • psf_kernel – PSF kernel (super-sampled)

  • -
  • psf_kernel_list – list of individual best PSF kernel estimates

  • -
  • ra_image – image positions in angles

  • -
  • dec_image – image positions in angles

  • -
  • point_amp – image amplitude

  • -
  • supersampling_factor – super-sampling factor

  • -
  • error_map_radius – radius (in angle) to cut the error map

  • -
-
-
Returns
-

psf error map such that square of the uncertainty gets boosted by error_map * (psf * amp)**2

-
-
-
- -
-
-image_single_point_source(image_model_class, kwargs_params)[source]
-

return model without including the point source contributions as a list (for each point source individually)

-
-
Parameters
-
    -
  • image_model_class – ImageModel class instance

  • -
  • kwargs_params – keyword arguments of model component keyword argument lists

  • -
-
-
Returns
-

list of images with point source isolated

-
-
-
- -
-
-static mask_point_source(x_pos, y_pos, x_grid, y_grid, radius, i=0)[source]
-
-
Parameters
-
    -
  • x_pos – x-position of list of point sources

  • -
  • y_pos – y-position of list of point sources

  • -
  • x_grid – x-coordinates of grid

  • -
  • y_grid – y-coordinates of grid

  • -
  • i – index of point source not to mask out

  • -
  • radius – radius to mask out other point sources

  • -
-
-
Returns
-

a mask of the size of the image with cutouts around the position

-
-
-
- -
-
-static point_like_source_cutouts(x_pos, y_pos, image_list, cutout_size)[source]
-

cutouts of point-like objects

-
-
Parameters
-
    -
  • x_pos – list of image positions in pixel units

  • -
  • y_pos – list of image position in pixel units

  • -
  • image_list – list of 2d numpy arrays with cleaned images, with all contaminating sources removed except -the point-like object to be cut out.

  • -
  • cutout_size – odd integer, size of cutout.

  • -
-
-
Returns
-

list of cutouts

-
-
-
- -
-
-psf_estimate_individual(ra_image, dec_image, point_amp, residuals, cutout_size, kernel_guess, supersampling_factor, block_center_neighbour)[source]
-
-
Parameters
-
    -
  • ra_image – list; position in angular units of the image

  • -
  • dec_image – list; position in angular units of the image

  • -
  • point_amp – list of model amplitudes of point sources

  • -
  • residuals – data - model

  • -
  • cutout_size – pixel size of cutout around single star/quasar to be considered for the psf reconstruction

  • -
  • kernel_guess – initial guess of super-sampled PSF

  • -
  • supersampling_factor – int, super-sampling factor

  • -
  • block_center_neighbour

  • -
-
-
Returns
-

list of best-guess PSF’s for each star based on the residual patterns

-
-
-
- -
-
-update_iterative(kwargs_psf, kwargs_params, num_iter=10, keep_psf_error_map=True, no_break=True, verbose=True, **kwargs_psf_update)[source]
-
-
Parameters
-
    -
  • kwargs_psf – keyword arguments to construct the PSF() class

  • -
  • kwargs_params – keyword arguments of the parameters of the model components (e.g. ‘kwargs_lens’ etc)

  • -
  • num_iter – number of iterations in the PSF fitting and image fitting process

  • -
  • keep_psf_error_map – boolean, if True keeps previous psf_error_map

  • -
  • no_break – boolean, if True, runs until the end regardless of the next step getting worse, and then -reads out the overall best fit

  • -
  • verbose – print statements informing about progress of iterative procedure

  • -
  • kwargs_psf_update – keyword arguments providing the settings for a single iteration of the PSF, as being -passed to update_psf() method

  • -
-
-
Returns
-

keyword argument of PSF constructor for PSF() class with updated PSF

-
-
-
- -
-
-update_psf(kwargs_psf, kwargs_params, stacking_method='median', psf_symmetry=1, psf_iter_factor=0.2, block_center_neighbour=0, error_map_radius=None, block_center_neighbour_error_map=None, new_procedure=False)[source]
-
-
Parameters
-
    -
  • kwargs_psf – keyword arguments to construct the PSF() class

  • -
  • kwargs_params – keyword arguments of the parameters of the model components (e.g. ‘kwargs_lens’ etc)

  • -
  • stacking_method – ‘median’, ‘mean’; the different estimates of the PSF are stacked and combined together. -The choices are: -‘mean’: mean of pixel values as the estimator (not robust to outliers) -‘median’: median of pixel values as the estimator (outlier rejection robust but needs >2 point sources in the data

  • -
  • psf_symmetry – number of rotational invariant symmetries in the estimated PSF. -=1 mean no additional symmetries. =4 means 90 deg symmetry. This is enforced by a rotatioanl stack according to -the symmetry specified. These additional imposed symmetries can help stabelize the PSF estimate when there are -limited constraints/number of point sources in the image.

  • -
  • psf_iter_factor – factor in (0, 1] of ratio of old vs new PSF in the update in the iteration.

  • -
  • block_center_neighbour – angle, radius of neighbouring point sources around their centers the estimates -is ignored. Default is zero, meaning a not optimal subtraction of the neighbouring point sources might -contaminate the estimate.

  • -
  • block_center_neighbour_error_map – angle, radius of neighbouring point sources around their centers the -estimates of the ERROR MAP is ignored. If None, then the value of block_center_neighbour is used (recommended)

  • -
  • error_map_radius – float, radius (in arc seconds) of the outermost error in the PSF estimate -(e.g. to avoid double counting of overlapping PSF errors), if None, all of the pixels are considered -(unless blocked through other means)

  • -
  • new_procedure – boolean, uses post lenstronomy 1.9.2 procedure which is more optimal for super-sampled PSF’s

  • -
-
-
Returns
-

kwargs_psf_new, logL_after, error_map

-
-
-
- -
- -
-
-

lenstronomy.Workflow.update_manager module

-
-
-class lenstronomy.Workflow.update_manager.UpdateManager(kwargs_model, kwargs_constraints, kwargs_likelihood, kwargs_params)[source]
-

Bases: object

-

this class manages the parameter constraints as they may evolve through the steps of the modeling. -This includes: keeping certain parameters fixed during one modelling step

-
-
-best_fit(bijective=False)[source]
-

best fit (max likelihood) position for all the model parameters

-
-
Parameters
-

bijective – boolean, if True, returns the parameters in the argument of the sampling that might deviate -from the convention of the ImSim module. For example, if parameterized in the image position, the parameters -remain in the image plane rather than being mapped to the source plane.

-
-
Returns
-

kwargs_result with all the keyword arguments of the best fit for the model components

-
-
-
- -
-
-fix_image_parameters(image_index=0)[source]
-

fixes all parameters that are only assigned to a specific image. This allows to sample only parameters that -constraint by the fitting of a sub-set of the images.

-
-
Parameters
-

image_index – index

-
-
Returns
-

None

-
-
-
- -
-
-property fixed_kwargs
-
- -
-
-property init_kwargs
-
-
Returns
-

keyword arguments for all model components of the initial mean model proposition in the sampling

-
-
-
- -
-
-property param_class
-

creating instance of lenstronomy Param() class. It uses the keyword arguments in self.kwargs_constraints as -__init__() arguments, as well as self.kwargs_model, and the set of kwargs_fixed___, kwargs_lower___, -kwargs_upper___ arguments for lens, lens_light, source, point source, extinction and special parameters.

-
-
Returns
-

instance of the Param class with the recent options and bounds

-
-
-
- -
-
-property parameter_state
-
-
Returns
-

parameter state saved in this class

-
-
-
- -
-
-set_init_state()[source]
-

set the current state of the parameters to the initial one.

-
-
Returns
-

-
-
-
- -
-
-property sigma_kwargs
-
-
Returns
-

keyword arguments for all model components of the initial 1-sigma width proposition in the sampling

-
-
-
- -
-
-update_fixed(lens_add_fixed=None, source_add_fixed=None, lens_light_add_fixed=None, ps_add_fixed=None, special_add_fixed=None, lens_remove_fixed=None, source_remove_fixed=None, lens_light_remove_fixed=None, ps_remove_fixed=None, special_remove_fixed=None)[source]
-

adds or removes the values of the keyword arguments that are stated in the _add_fixed to the existing fixed -arguments. convention for input arguments are: -[[i_model, [‘param_name1’, ‘param_name2’, …], [value1, value2, … (optional)], [], …]

-
-
Parameters
-
    -
  • lens_add_fixed – added fixed parameter in lens model

  • -
  • source_add_fixed – added fixed parameter in source model

  • -
  • lens_light_add_fixed – added fixed parameter in lens light model

  • -
  • ps_add_fixed – added fixed parameter in point source model

  • -
  • special_add_fixed – added fixed parameter in special model

  • -
  • lens_remove_fixed – remove fixed parameter in lens model

  • -
  • source_remove_fixed – remove fixed parameter in source model

  • -
  • lens_light_remove_fixed – remove fixed parameter in lens light model

  • -
  • ps_remove_fixed – remove fixed parameter in point source model

  • -
  • special_remove_fixed – remove fixed parameter in special model

  • -
-
-
Returns
-

updated kwargs fixed

-
-
-
- -
-
-update_limits(change_source_lower_limit=None, change_source_upper_limit=None, change_lens_lower_limit=None, change_lens_upper_limit=None)[source]
-

updates the limits (lower and upper) of the update manager instance

-
-
Parameters
-
    -
  • change_source_lower_limit – [[i_model, [‘param_name’, …], [value1, value2, …]]]

  • -
  • change_lens_lower_limit – [[i_model, [‘param_name’, …], [value1, value2, …]]]

  • -
  • change_source_upper_limit – [[i_model, [‘param_name’, …], [value1, value2, …]]]

  • -
  • change_lens_upper_limit – [[i_model, [‘param_name’, …], [value1, value2, …]]]

  • -
-
-
Returns
-

updates internal state of lower and upper limits accessible from outside

-
-
-
- -
-
-update_options(kwargs_model, kwargs_constraints, kwargs_likelihood)[source]
-

updates the options by overwriting the kwargs with the new ones being added/changed -WARNING: some updates may not be valid depending on the model options. Use carefully!

-
-
Parameters
-
    -
  • kwargs_model – keyword arguments to describe all model components used in -class_creator.create_class_instances() that are updated from previous arguments

  • -
  • kwargs_constraints

  • -
  • kwargs_likelihood

  • -
-
-
Returns
-

kwargs_model, kwargs_constraints, kwargs_likelihood

-
-
-
- -
-
-update_param_state(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_special=None, kwargs_extinction=None)[source]
-

updates the temporary state of the parameters being saved. ATTENTION: Any previous knowledge gets lost if you -call this function

-
-
Parameters
-
    -
  • kwargs_lens

  • -
  • kwargs_source

  • -
  • kwargs_lens_light

  • -
  • kwargs_ps

  • -
  • kwargs_special

  • -
  • kwargs_extinction

  • -
-
-
Returns
-

-
-
-
- -
-
-update_param_value(lens=None, source=None, lens_light=None, ps=None)[source]
-

Set a model parameter to a specific value.

-
-
Parameters
-
    -
  • lens – [[i_model, [‘param1’, ‘param2’,…], […]]

  • -
  • source – [[i_model, [‘param1’, ‘param2’,…], […]]

  • -
  • lens_light – [[i_model, [‘param1’, ‘param2’,…], […]]

  • -
  • ps – [[i_model, [‘param1’, ‘param2’,…], […]]

  • -
-
-
Returns
-

0, the value of the param is overwritten

-
-
-
- -
- -
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/lenstronomy.html b/docs/_build/html/lenstronomy.html deleted file mode 100644 index b6034b3a9..000000000 --- a/docs/_build/html/lenstronomy.html +++ /dev/null @@ -1,480 +0,0 @@ - - - - - - - - - lenstronomy package — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy package

-
-

Subpackages

-
- -
-
-
-

Module contents

-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/mailinglist.html b/docs/_build/html/mailinglist.html deleted file mode 100644 index 6ede06751..000000000 --- a/docs/_build/html/mailinglist.html +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - - - - Mailing list — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

Mailing list

-

You can join the lenstronomy mailing list by signing up on the -google groups page.

-

The email list is meant to provide a communication platform between users and developers. You can ask questions, -and suggest new features. New releases will be announced via this mailing list.

-

If you encounter errors or problems with lenstronomy, please let us know!

-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/modules.html b/docs/_build/html/modules.html deleted file mode 100644 index 9d6e093ad..000000000 --- a/docs/_build/html/modules.html +++ /dev/null @@ -1,265 +0,0 @@ - - - - - - - - - lenstronomy — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - -
-
-
-
- -
-

lenstronomy

-
- -
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/objects.inv b/docs/_build/html/objects.inv deleted file mode 100644 index a0eeee0bf..000000000 Binary files a/docs/_build/html/objects.inv and /dev/null differ diff --git a/docs/_build/html/published.html b/docs/_build/html/published.html deleted file mode 100644 index 911bd60f4..000000000 --- a/docs/_build/html/published.html +++ /dev/null @@ -1,653 +0,0 @@ - - - - - - - - - Published work with lenstronomy — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
-
-
- -
-

Published work with lenstronomy

-

In this section you can find the concept papers lenstronomy is based on the list of science publications that made -use of lenstronomy. Please let the developers know when you publish a paper that made use of lenstronomy. -We are happy to include your publication in this list.

-
-

Core lenstronomy methodology and software publications

-
    -
  • -
    lenstronomy: Multi-purpose gravitational lens modelling software package; Birrer & Amara 2018

    This is the lenstronomy software paper. Please cite this paper whenever you make use of lenstronomy. The paper gives a design overview and highlights some use cases.

    -
    -
    -
  • -
  • -
    lenstronomy II: A gravitational lensing software ecosystem; Birrer et al. 2021

    JOSS software publication. Please cite this paper whenever you make use of lenstronomy.

    -
    -
    -
  • -
  • -
    Gravitational Lens Modeling with Basis Sets; Birrer et al. 2015

    This is the method paper lenstronomy is primary based on. Please cite this paper whenever you publish results with lenstronomy by using Shapelet basis sets and/or the PSO and MCMC chain.

    -
    -
    -
  • -
-
- -
-

Measuring the Hubble constant

-
    -
  • -
    The mass-sheet degeneracy and time-delay cosmography: analysis of the strong lens RXJ1131-1231; Birrer et al. 2016

    This paper performs a cosmographic analysis and applies the Shapelet basis set scaling to marginalize over a major lensing degeneracy.

    -
    -
    -
  • -
  • -
    H0LiCOW - IX. Cosmographic analysis of the doubly imaged quasar SDSS 1206+4332 and a new measurement of the Hubble constant; Birrer et al. 2019

    This paper performs a cosmographic analysis with power-law and composite models and covers a range in complexity in the source reconstruction

    -
    -
    -
  • -
  • -
    Astrometric requirements for strong lensing time-delay cosmography; Birrer & Treu 2019

    Derives requirements on how well the image positions of time-variable sources has to be known to perform a time-delay cosmographic measurement

    -
    -
    -
  • -
  • -
    H0LiCOW XIII. A 2.4% measurement of H0 from lensed quasars: 5.3σ tension between early and late-Universe probes; Wong et al. 2019

    Joint analysis of the six H0LiCOW lenses including the lenstronomy analysis of J1206

    -
    -
    -
  • -
  • -
    STRIDES: A 3.9 per cent measurement of the Hubble constant from the strongly lensed system DES J0408-5354; Shajib et al. 2019

    most precise single lensing constraint on the Hubble constant. This analysis includes two source planes and three lensing planes

    -
    -
    -
  • -
  • -
    TDCOSMO. I. An exploration of systematic uncertainties in the inference of H0 from time-delay cosmography Millon et al. 2020

    mock lenses to test accuracy on the recovered H0 value

    -
    -
    -
  • -
  • -
    Lens modelling of the strongly lensed Type Ia supernova iPTF16geu Moertsell et al. 2020

    Modeling of a lensed supernova to measure the Hubble constant

    -
    -
    -
  • -
  • -
    The impact of line-of-sight structures on measuring H0 with strong lensing time-delays Li, Becker and Dye 2020

    Point source position and time-delay modeling of quads

    -
    -
    -
  • -
  • -
    TDCOSMO III: Dark matter substructure meets dark energy – the effects of (sub)halos on strong-lensing measurements of H0 Gilman, Birrer and Treu 2020

    Full line-of-sight halo rendering and time-delay analysis on mock images

    -
    -
    -
  • -
  • -
    TDCOSMO IV: Hierarchical time-delay cosmography – joint inference of the Hubble constant and galaxy density profiles Birrer et al. 2020

    lenstronomy.Galkin for kinematics calculation that folds in the hierarchical analysis

    -
    -
    -
  • -
  • -
    TDCOSMO V: strategies for precise and accurate measurements of the Hubble constant with strong lensing Birrer & Treu 2020

    lenstronomy.Galkin for kinematics calculation that folds in the hierarchical analysis for a forecast for future Hubble constant constraints

    -
    -
    -
  • -
  • -
    Large-Scale Gravitational Lens Modeling with Bayesian Neural Networks for Accurate and Precise Inference of the Hubble Constant Park et al. 2020

    BBN lens model inference using lenstronomy through `baobab <https://github.com/jiwoncpark/baobab>`_ for training set generation.

    -
    -
    -
  • -
  • -
    Improved time-delay lens modelling and H0 inference with transient sources Ding et al. 2021a

    Simulations and models with and without lensed point sources to perform a time-delay cosmography analysis.

    -
    -
    -
  • -
  • -
    Gravitational lensing H0 tension from ultralight axion galactic cores Blum & Teodori 2021

    Investigating the detectability of a cored component with mock imaging modeling and comparison of kinematic modeling.

    -
    -
    -
  • -
  • -
    The Hubble constant from strongly lensed supernovae with standardizable magnifications Birrer, Dhawan, Shajib 2021

    Methodology and forecast to use standardizable magnifications to break the mass-sheet degeneracy and hierarchically measure H0.

    -
    -
    -
  • -
  • -
    AI-driven spatio-temporal engine for finding gravitationally lensed supernovae Ramanah et al. 2021

    Simulated images with time series of lensed supernovae.

    -
    -
    -
  • -
  • -
    Systematic errors induced by the elliptical power-law model in galaxy-galaxy strong lens modeling Cao et al. 2021

    Computing lensing quantities from mass maps.

    -
    -
    -
  • -
  • -
    TDCOSMO. VII. Boxyness/discyness in lensing galaxiesDetectability and impact on H0 Van de Vyvere et al. 2021

    Assessment of boxy and discy lens model on the inference of H0.

    -
    -
    -
  • -
  • -
    TDCOSMO. IX. Systematic comparison between lens modelling software programs: time delay prediction for WGD 2038−4008 Shajib et al. 2022a

    modeling of a time-delay lens and comprehensive analysis between two modeling codes.

    -
    -
    -
  • -
  • -
    Forecast of observing time delay of the strongly lensed quasars with Muztagh-Ata 1.93m telescope Zhu et al. 2022a

    Using lenstronomy to reproduce a lens and simulate the observed images based on parameters fitted by other work.

    -
    -
    -
  • -
-
-
-

Dark Matter substructure

-
    -
  • -
    Lensing substructure quantification in RXJ1131-1231: a 2 keV lower bound on dark matter thermal relic mass; Birrer et al. 2017b

    This paper quantifies the substructure content of a lens by a sub-clump scanning procedure and the application of Approximate Bayesian Computing.

    -
    -
    -
  • -
  • -
    Probing the nature of dark matter by forward modelling flux ratios in strong gravitational lenses; Gilman et al. 2018
      -
      • -
      • -
      -
    • -
    -
    -
    -
  • -
  • -
    Probing dark matter structure down to 10**7 solar masses: flux ratio statistics in gravitational lenses with line-of-sight haloes; Gilman et al. 2019a
      -
      • -
      • -
      -
    • -
    -
    -
    -
  • -
  • -
    Double dark matter vision: twice the number of compact-source lenses with narrow-line lensing and the WFC3 Grism; Nierenberg et al. 2019
      -
      • -
      • -
      -
    • -
    -
    -
    -
  • -
  • -
    Warm dark matter chills out: constraints on the halo mass function and the free-streaming length of dark matter with 8 quadruple-image strong gravitational lenses; Gilman et al. 2019b
      -
      • -
      • -
      -
    • -
    -
    -
    -
  • -
  • -
    Constraints on the mass-concentration relation of cold dark matter halos with 11 strong gravitational lenses; Gilman et al. 2019c
      -
      • -
      • -
      -
    • -
    -
    -
    -
  • -
  • -
    Circumventing Lens Modeling to Detect Dark Matter Substructure in Strong Lens Images with Convolutional Neural Networks; Diaz Rivero & Dvorkin
      -
      • -
      • -
      -
    • -
    -
    -
    -
  • -
  • -
    Dark Matter Subhalos, Strong Lensing and Machine Learning; Varma, Fairbairn, Figueroa
      -
      • -
      • -
      -
    • -
    -
    -
    -
  • -
  • -
    Quantifying the Line-of-Sight Halo Contribution to the Dark Matter Convergence Power Spectrum from Strong Gravitational Lenses; Sengul et al. 2020
      -
      • -
      • -
      -
    • -
    -
    -
    -
  • -
  • -
    Detecting Subhalos in Strong Gravitational Lens Images with Image Segmentation; Ostdiek et al. 2020a
      -
      • -
      • -
      -
    • -
    -
    -
    -
  • -
  • -
    Extracting the Subhalo Mass Function from Strong Lens Images with Image Segmentation; Ostdiek et al. 2020b
      -
      • -
      • -
      -
    • -
    -
    -
    -
  • -
  • -
    Strong lensing signatures of self-interacting dark matter in low-mass halos; Gilman et al. 2021a
      -
      • -
      • -
      -
    • -
    -
    -
    -
  • -
  • -
    Substructure Detection Reanalyzed: Dark Perturber shown to be a Line-of-Sight Halo; Sengul et al. 2021

    modeling a line-of-sight mini-halo

    -
    -
    -
  • -
  • -
    The primordial matter power spectrum on sub-galactic scales; Gilman et al. 2021b

    rendering sub- and line-of-sight halos

    -
    -
    -
  • -
  • -
    From Images to Dark Matter: End-To-End Inference of Substructure From Hundreds of Strong Gravitational Lenses; Wagner-Carena et al. 2022

    rendering sub- and line-of-sight halos and generating realistic training sets of images for substructure quantifications

    -
    -
    -
  • -
  • -
    Interlopers speak out: Studying the dark universe using small-scale lensing anisotropies; Dhanasingham et al. 2022

    rendering line of sight and subhalos with pyhalo on top of lenstronomy

    -
    -
    -
  • -
-
-
-

Lens searches

-
    -
  • -
    Strong lens systems search in the Dark Energy Survey using Convolutional Neural Networks; Rojas et al. 2021

    simulating training sets for lens searches

    -
    -
    -
  • -
  • -
    On machine learning search for gravitational lenses; Khachatryan 2021

    simulating training sets for lens searches

    -
    -
    -
  • -
  • -
    DeepZipper: A Novel Deep Learning Architecture for Lensed Supernovae Identification; Morgan et al. 2021b

    Using deeplenstronomy to simulate lensed supernovae data sets

    -
    -
    -
  • -
  • -
    Detecting gravitational lenses using machine learning: exploring interpretability and sensitivity to rare lensing configurations; Wilde et al. 2021b

    Simulating compound lenses

    -
    -
    -
  • -
  • -
    DeepZipper II: Searching for Lensed Supernovae in Dark Energy Survey Data with Deep Learning; Morgan et al. 2022

    Using deeplenstronomy to simulate lensed supernovae training sets

    -
    -
    -
  • -
-
-
-

Galaxy formation and evolution

-
    -
  • -
    Massive elliptical galaxies at z∼0.2 are well described by stars and a Navarro-Frenk-White dark matter halo; Shajib et al. 2020a

    Automatized modeling of 23 SLACS lenses with dolphin, a lenstronomy wrapper

    -
    -
    -
  • -
  • -
    High-resolution imaging follow-up of doubly imaged quasars; Shajib et al. 2020b

    Modeling of doubly lensed quasars from Keck Adaptive Optics data

    -
    -
    -
  • -
  • -
    The evolution of the size-mass relation at z=1-3 derived from the complete Hubble Frontier Fields data set; Yang et al. 2020b

    reconstructing the intrinsic size-mass relation of strongly lensed sources in clusters

    -
    -
    -
  • -
  • -
    PS J1721+8842: A gravitationally lensed dual AGN system at redshift 2.37 with two radio components; Mangat et al. 2021

    Imaging modeling of a dual lensed AGN with point sources and extended surface brightness

    -
    -
    -
  • -
  • -
    RELICS: Small Lensed z≥5.5 Galaxies Selected as Potential Lyman Continuum Leakers; Neufeld et al. 2021

    size measurements of high-z lensed galaxies

    -
    -
    -
  • -
  • -
    The size-luminosity relation of lensed galaxies at z=6−9 in the Hubble Frontier Fields; Yang et al. 2022

    size measurements of high-z lensed galaxies

    -
    -
    -
  • -
  • -
    The Near Infrared Imager and Slitless Spectrograph for the James Webb Space Telescope – II. Wide Field Slitless Spectroscopy; Willott et al. 2022

    lensing calculations in cluster environments

    -
    -
    -
  • -
-
-
-

Automatized Lens Modeling

-
    -
  • -
    Is every strong lens model unhappy in its own way? Uniform modelling of a sample of 12 quadruply+ imaged quasars; Shajib et al. 2018

    This work presents a uniform modelling framework to model 13 quadruply lensed quasars in three HST bands.

    -
    -
    -
  • -
  • -
    Hierarchical Inference With Bayesian Neural Networks: An Application to Strong Gravitational Lensing; Wagner-Carena et al. 2020

    This work conducts hierarchical inference of strongly-lensed systems with Bayesian neural networks.

    -
    -
    -
  • -
  • -
    A search for galaxy-scale strong gravitational lenses in the Ultraviolet Near Infrared Optical Northern Survey (UNIONS); Savary et al. 2021

    Automated modeling of best candidates of ground based data.

    -
    -
    -
  • -
  • -
    GIGA-Lens: Fast Bayesian Inference for Strong Gravitational Lens Modeling; Gu et al. 2022

    lenstronomy-inspired GPU lensing code with PEMD+shear and Sersic modeling, and tested against lenstronomy.

    -
    -
    -
  • -
-
-
-

Quasar-host galaxy decomposition

-
    -
  • -
    The mass relations between supermassive black holes and their host galaxies at 1<z<2 with HST-WFC3; Ding et al. 2019

    Quasar host galaxy decomposition at high redshift on HST imaging and marginalization over PSF uncertainties.

    -
    -
    -
  • -
  • -
    Testing the Evolution of the Correlations between Supermassive Black Holes and their Host Galaxies using Eight Strongly Lensed Quasars; Ding et al. 2020

    Quasar host galaxy decomposition with lensed quasars.

    -
    -
    -
  • -
  • -
    A local baseline of the black hole mass scaling relations for active galaxies. IV. Correlations between MBH and host galaxy σ, stellar mass, and luminosity; Bennert et al. 2021

    Detailed measurement of galaxy morphology, decomposing in spheroid, disk and bar, and central AGN

    -
    -
    -
  • -
  • -
    The Sizes of Quasar Host Galaxies with the Hyper Suprime-Cam Subaru Strategic Program; Li et al. 2021a

    Quasar-host decomposition of 5000 SDSS quasars

    -
    -
    -
  • -
  • -
    The eROSITA Final Equatorial-Depth Survey (eFEDS): A multiwavelength view of WISE mid-infrared galaxies/active galactic nuclei; Toba et al. 2021

    Quasar-host decomposition of HSC imaging

    -
    -
    -
  • -
  • -
    Synchronized Co-evolution between Supermassive Black Holes and Galaxies Over the Last Seven Billion Years as Revealed by the Hyper Suprime-Cam; Li et al. 2021b

    Quasar-host decomposition of SDSS quasars with HSC data

    -
    -
    -
  • -
-
-
-

Lensing of Gravitational Waves

-
    -
  • -
    lensingGW: a Python package for lensing of gravitational waves; Pagano et al. 2020

    A Python package designed to handle both strong and microlensing of compact binaries and the related gravitational-wave signals.

    -
    -
    -
  • -
  • -
    Localizing merging black holes with sub-arcsecond precision using gravitational-wave lensing; Hannuksela et al. 2020

    solving the lens equation with lenstronomy using lensingGW

    -
    -
    -
  • -
  • -
    Lensing magnification: gravitational wave from coalescing stellar-mass binary black holes; Shan & Hu 2020

    lensing magnificatoin calculations

    -
    -
    -
  • -
  • -
    Identifying Type-II Strongly-Lensed Gravitational-Wave Images in Third-Generation Gravitational-Wave Detectors; Y. Wang et al. 2021

    solving the lens equation

    -
    -
    -
  • -
  • -
    Beyond the detector horizon: Forecasting gravitational-wave strong lensing; Renske et al. 2021

    computing image positions, time delays and magnifications for gravitational wave forecasting

    -
    -
    -
  • -
-
-
-

Theory papers

-
    -
  • -
    Line-of-sight effects in strong lensing: putting theory into practice; Birrer et al. 2017a

    This paper formulates an effective parameterization of line-of-sight structure for strong gravitational lens modelling and applies this technique to an Einstein ring in the COSMOS field

    -
    -
    -
  • -
  • -
    Cosmic Shear with Einstein Rings; Birrer et al. 2018a

    Forecast paper to measure cosmic shear with Einstein ring lenses. The forecast is made based on lenstronomy simulations.

    -
    -
    -
  • -
  • -
    Unified lensing and kinematic analysis for any elliptical mass profile; Shajib 2019

    Provides a methodology to generalize the multi-Gaussian expansion to general elliptical mass and light profiles

    -
    -
    -
  • -
  • -
    Gravitational lensing formalism in a curved arc basis: A continuous description of observables and degeneracies from the weak to the strong lensing regime; Birrer 2021

    Lensing formalism with curved arc distortion formalism. Link to code repository `here <https://github.com/sibirrer/curved_arcs>`_.

    -
    -
    -
  • -
-
-
-

Simulation products

-
    -
  • -
    The LSST DESC DC2 Simulated Sky Survey; LSST Dark Energy Science Collaboration et al. 2020

    Strong lensing simulations produced by SLSprinkler utilizing lenstronomy functionalities

    -
    -
    -
  • -
  • -
    The impact of mass map truncation on strong lensing simulations; Van de Vyvere et al. 2020

    Uses numerical integration to compute lensing quantities from projected mass maps from simulations.

    -
    -
    -
  • -
-
-
-

Large scale structure

-
    -
  • -
    Combining strong and weak lensingestimates in the Cosmos field; Kuhn et al. 2020

    inferring cosmic shear with three strong lenses in the COSMOS field

    -
    -
    -
  • -
-
-
-

Others

-
    -
  • -
    Predicting future astronomical events using deep learning; Singh et al.

    simulating strongly lensed galaxy merger pairs in time sequence

    -
    -
    -
  • -
  • -
    Role of the companion lensing galaxy in the CLASS gravitational lens B1152+199; Zhang et al. 2022

    modeling of a double lensed quasar with HST and VLBI data

    -
    -
    -
  • -
-
-
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/py-modindex.html b/docs/_build/html/py-modindex.html deleted file mode 100644 index 32306fc0b..000000000 --- a/docs/_build/html/py-modindex.html +++ /dev/null @@ -1,1205 +0,0 @@ - - - - - - - - Python Module Index — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - - -
-
-
-
- - -

Python Module Index

- -
- l -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
- l
- lenstronomy -
    - lenstronomy.Analysis -
    - lenstronomy.Analysis.kinematics_api -
    - lenstronomy.Analysis.lens_profile -
    - lenstronomy.Analysis.light2mass -
    - lenstronomy.Analysis.light_profile -
    - lenstronomy.Analysis.td_cosmography -
    - lenstronomy.Conf -
    - lenstronomy.Conf.config_loader -
    - lenstronomy.Cosmo -
    - lenstronomy.Cosmo.background -
    - lenstronomy.Cosmo.cosmo_solver -
    - lenstronomy.Cosmo.kde_likelihood -
    - lenstronomy.Cosmo.lcdm -
    - lenstronomy.Cosmo.lens_cosmo -
    - lenstronomy.Cosmo.nfw_param -
    - lenstronomy.Data -
    - lenstronomy.Data.coord_transforms -
    - lenstronomy.Data.imaging_data -
    - lenstronomy.Data.psf -
    - lenstronomy.GalKin -
    - lenstronomy.GalKin.analytic_kinematics -
    - lenstronomy.GalKin.anisotropy -
    - lenstronomy.GalKin.aperture -
    - lenstronomy.GalKin.aperture_types -
    - lenstronomy.GalKin.cosmo -
    - lenstronomy.GalKin.galkin -
    - lenstronomy.GalKin.galkin_model -
    - lenstronomy.GalKin.light_profile -
    - lenstronomy.GalKin.numeric_kinematics -
    - lenstronomy.GalKin.observation -
    - lenstronomy.GalKin.psf -
    - lenstronomy.GalKin.velocity_util -
    - lenstronomy.ImSim -
    - lenstronomy.ImSim.de_lens -
    - lenstronomy.ImSim.image2source_mapping -
    - lenstronomy.ImSim.image_linear_solve -
    - lenstronomy.ImSim.image_model -
    - lenstronomy.ImSim.MultiBand -
    - lenstronomy.ImSim.MultiBand.joint_linear -
    - lenstronomy.ImSim.MultiBand.multi_data_base -
    - lenstronomy.ImSim.MultiBand.multi_linear -
    - lenstronomy.ImSim.MultiBand.single_band_multi_model -
    - lenstronomy.ImSim.Numerics -
    - lenstronomy.ImSim.Numerics.adaptive_numerics -
    - lenstronomy.ImSim.Numerics.convolution -
    - lenstronomy.ImSim.Numerics.grid -
    - lenstronomy.ImSim.Numerics.numba_convolution -
    - lenstronomy.ImSim.Numerics.numerics -
    - lenstronomy.ImSim.Numerics.partial_image -
    - lenstronomy.ImSim.Numerics.point_source_rendering -
    - lenstronomy.LensModel -
    - lenstronomy.LensModel.convergence_integrals -
    - lenstronomy.LensModel.lens_model -
    - lenstronomy.LensModel.lens_model_extensions -
    - lenstronomy.LensModel.lens_param -
    - lenstronomy.LensModel.LightConeSim -
    - lenstronomy.LensModel.LightConeSim.light_cone -
    - lenstronomy.LensModel.MultiPlane -
    - lenstronomy.LensModel.MultiPlane.multi_plane -
    - lenstronomy.LensModel.MultiPlane.multi_plane_base -
    - lenstronomy.LensModel.profile_integrals -
    - lenstronomy.LensModel.profile_list_base -
    - lenstronomy.LensModel.Profiles -
    - lenstronomy.LensModel.Profiles.arc_perturbations -
    - lenstronomy.LensModel.Profiles.base_profile -
    - lenstronomy.LensModel.Profiles.chameleon -
    - lenstronomy.LensModel.Profiles.cnfw -
    - lenstronomy.LensModel.Profiles.cnfw_ellipse -
    - lenstronomy.LensModel.Profiles.const_mag -
    - lenstronomy.LensModel.Profiles.constant_shift -
    - lenstronomy.LensModel.Profiles.convergence -
    - lenstronomy.LensModel.Profiles.coreBurkert -
    - lenstronomy.LensModel.Profiles.cored_density -
    - lenstronomy.LensModel.Profiles.cored_density_2 -
    - lenstronomy.LensModel.Profiles.cored_density_exp -
    - lenstronomy.LensModel.Profiles.cored_density_mst -
    - lenstronomy.LensModel.Profiles.curved_arc_const -
    - lenstronomy.LensModel.Profiles.curved_arc_sis_mst -
    - lenstronomy.LensModel.Profiles.curved_arc_spp -
    - lenstronomy.LensModel.Profiles.curved_arc_spt -
    - lenstronomy.LensModel.Profiles.curved_arc_tan_diff -
    - lenstronomy.LensModel.Profiles.dipole -
    - lenstronomy.LensModel.Profiles.elliptical_density_slice -
    - lenstronomy.LensModel.Profiles.epl -
    - lenstronomy.LensModel.Profiles.epl_numba -
    - lenstronomy.LensModel.Profiles.flexion -
    - lenstronomy.LensModel.Profiles.flexionfg -
    - lenstronomy.LensModel.Profiles.gauss_decomposition -
    - lenstronomy.LensModel.Profiles.gaussian_ellipse_kappa -
    - lenstronomy.LensModel.Profiles.gaussian_ellipse_potential -
    - lenstronomy.LensModel.Profiles.gaussian_kappa -
    - lenstronomy.LensModel.Profiles.gaussian_potential -
    - lenstronomy.LensModel.Profiles.hernquist -
    - lenstronomy.LensModel.Profiles.hernquist_ellipse -
    - lenstronomy.LensModel.Profiles.hessian -
    - lenstronomy.LensModel.Profiles.interpol -
    - lenstronomy.LensModel.Profiles.multi_gaussian_kappa -
    - lenstronomy.LensModel.Profiles.multipole -
    - lenstronomy.LensModel.Profiles.nfw -
    - lenstronomy.LensModel.Profiles.nfw_ellipse -
    - lenstronomy.LensModel.Profiles.nfw_mass_concentration -
    - lenstronomy.LensModel.Profiles.nfw_vir_trunc -
    - lenstronomy.LensModel.Profiles.nie -
    - lenstronomy.LensModel.Profiles.nie_potential -
    - lenstronomy.LensModel.Profiles.numerical_deflections -
    - lenstronomy.LensModel.Profiles.p_jaffe -
    - lenstronomy.LensModel.Profiles.p_jaffe_ellipse -
    - lenstronomy.LensModel.Profiles.pemd -
    - lenstronomy.LensModel.Profiles.point_mass -
    - lenstronomy.LensModel.Profiles.sersic -
    - lenstronomy.LensModel.Profiles.sersic_ellipse_kappa -
    - lenstronomy.LensModel.Profiles.sersic_ellipse_potential -
    - lenstronomy.LensModel.Profiles.sersic_utils -
    - lenstronomy.LensModel.Profiles.shapelet_pot_cartesian -
    - lenstronomy.LensModel.Profiles.shapelet_pot_polar -
    - lenstronomy.LensModel.Profiles.shear -
    - lenstronomy.LensModel.Profiles.sie -
    - lenstronomy.LensModel.Profiles.sis -
    - lenstronomy.LensModel.Profiles.sis_truncate -
    - lenstronomy.LensModel.Profiles.spemd -
    - lenstronomy.LensModel.Profiles.spep -
    - lenstronomy.LensModel.Profiles.splcore -
    - lenstronomy.LensModel.Profiles.spp -
    - lenstronomy.LensModel.Profiles.tnfw -
    - lenstronomy.LensModel.Profiles.uldm -
    - lenstronomy.LensModel.QuadOptimizer -
    - lenstronomy.LensModel.QuadOptimizer.multi_plane_fast -
    - lenstronomy.LensModel.QuadOptimizer.optimizer -
    - lenstronomy.LensModel.QuadOptimizer.param_manager -
    - lenstronomy.LensModel.single_plane -
    - lenstronomy.LensModel.Solver -
    - lenstronomy.LensModel.Solver.lens_equation_solver -
    - lenstronomy.LensModel.Solver.solver -
    - lenstronomy.LensModel.Solver.solver2point -
    - lenstronomy.LensModel.Solver.solver4point -
    - lenstronomy.LensModel.Util -
    - lenstronomy.LensModel.Util.epl_util -
    - lenstronomy.LightModel -
    - lenstronomy.LightModel.light_model -
    - lenstronomy.LightModel.light_param -
    - lenstronomy.LightModel.Profiles -
    - lenstronomy.LightModel.Profiles.chameleon -
    - lenstronomy.LightModel.Profiles.ellipsoid -
    - lenstronomy.LightModel.Profiles.gaussian -
    - lenstronomy.LightModel.Profiles.hernquist -
    - lenstronomy.LightModel.Profiles.interpolation -
    - lenstronomy.LightModel.Profiles.moffat -
    - lenstronomy.LightModel.Profiles.nie -
    - lenstronomy.LightModel.Profiles.p_jaffe -
    - lenstronomy.LightModel.Profiles.power_law -
    - lenstronomy.LightModel.Profiles.sersic -
    - lenstronomy.LightModel.Profiles.shapelets -
    - lenstronomy.LightModel.Profiles.shapelets_polar -
    - lenstronomy.LightModel.Profiles.uniform -
    - lenstronomy.Plots -
    - lenstronomy.Plots.chain_plot -
    - lenstronomy.Plots.lens_plot -
    - lenstronomy.Plots.model_band_plot -
    - lenstronomy.Plots.model_plot -
    - lenstronomy.Plots.plot_util -
    - lenstronomy.PointSource -
    - lenstronomy.PointSource.point_source -
    - lenstronomy.PointSource.point_source_cached -
    - lenstronomy.PointSource.point_source_param -
    - lenstronomy.PointSource.Types -
    - lenstronomy.PointSource.Types.base_ps -
    - lenstronomy.PointSource.Types.lensed_position -
    - lenstronomy.PointSource.Types.source_position -
    - lenstronomy.PointSource.Types.unlensed -
    - lenstronomy.Sampling -
    - lenstronomy.Sampling.likelihood -
    - lenstronomy.Sampling.Likelihoods -
    - lenstronomy.Sampling.Likelihoods.image_likelihood -
    - lenstronomy.Sampling.Likelihoods.position_likelihood -
    - lenstronomy.Sampling.Likelihoods.prior_likelihood -
    - lenstronomy.Sampling.Likelihoods.time_delay_likelihood -
    - lenstronomy.Sampling.parameters -
    - lenstronomy.Sampling.Pool -
    - lenstronomy.Sampling.Pool.multiprocessing -
    - lenstronomy.Sampling.Pool.pool -
    - lenstronomy.Sampling.sampler -
    - lenstronomy.Sampling.Samplers -
    - lenstronomy.Sampling.Samplers.base_nested_sampler -
    - lenstronomy.Sampling.Samplers.dynesty_sampler -
    - lenstronomy.Sampling.Samplers.multinest_sampler -
    - lenstronomy.Sampling.Samplers.polychord_sampler -
    - lenstronomy.Sampling.special_param -
    - lenstronomy.SimulationAPI -
    - lenstronomy.SimulationAPI.data_api -
    - lenstronomy.SimulationAPI.model_api -
    - lenstronomy.SimulationAPI.observation_api -
    - lenstronomy.SimulationAPI.observation_constructor -
    - lenstronomy.SimulationAPI.ObservationConfig -
    - lenstronomy.SimulationAPI.ObservationConfig.DES -
    - lenstronomy.SimulationAPI.ObservationConfig.Euclid -
    - lenstronomy.SimulationAPI.ObservationConfig.HST -
    - lenstronomy.SimulationAPI.ObservationConfig.LSST -
    - lenstronomy.SimulationAPI.point_source_variability -
    - lenstronomy.SimulationAPI.sim_api -
    - lenstronomy.Util -
    - lenstronomy.Util.analysis_util -
    - lenstronomy.Util.class_creator -
    - lenstronomy.Util.constants -
    - lenstronomy.Util.correlation -
    - lenstronomy.Util.data_util -
    - lenstronomy.Util.derivative_util -
    - lenstronomy.Util.image_util -
    - lenstronomy.Util.kernel_util -
    - lenstronomy.Util.mask_util -
    - lenstronomy.Util.multi_gauss_expansion -
    - lenstronomy.Util.numba_util -
    - lenstronomy.Util.param_util -
    - lenstronomy.Util.prob_density -
    - lenstronomy.Util.sampling_util -
    - lenstronomy.Util.simulation_util -
    - lenstronomy.Util.util -
    - lenstronomy.Workflow -
    - lenstronomy.Workflow.alignment_matching -
    - lenstronomy.Workflow.fitting_sequence -
    - lenstronomy.Workflow.psf_fitting -
    - lenstronomy.Workflow.update_manager -
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/search.html b/docs/_build/html/search.html deleted file mode 100644 index fed539823..000000000 --- a/docs/_build/html/search.html +++ /dev/null @@ -1,104 +0,0 @@ - - - - - - - - Search — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - - - - - -
-
-
-
- -

Search

- - - - -

- Searching for multiple words only shows matches that contain - all words. -

- - -
- - - -
- - - -
- -
- - -
-
-
-
- -
-
- - - - \ No newline at end of file diff --git a/docs/_build/html/searchindex.js b/docs/_build/html/searchindex.js deleted file mode 100644 index 86df6eae9..000000000 --- a/docs/_build/html/searchindex.js +++ /dev/null @@ -1 +0,0 @@ -Search.setIndex({docnames:["affiliatedpackages","authors","contributing","history","index","installation","lenstronomy","lenstronomy.Analysis","lenstronomy.Conf","lenstronomy.Cosmo","lenstronomy.Data","lenstronomy.GalKin","lenstronomy.ImSim","lenstronomy.ImSim.MultiBand","lenstronomy.ImSim.Numerics","lenstronomy.LensModel","lenstronomy.LensModel.LightConeSim","lenstronomy.LensModel.MultiPlane","lenstronomy.LensModel.Profiles","lenstronomy.LensModel.QuadOptimizer","lenstronomy.LensModel.Solver","lenstronomy.LensModel.Util","lenstronomy.LightModel","lenstronomy.LightModel.Profiles","lenstronomy.Plots","lenstronomy.PointSource","lenstronomy.PointSource.Types","lenstronomy.Sampling","lenstronomy.Sampling.Likelihoods","lenstronomy.Sampling.Pool","lenstronomy.Sampling.Samplers","lenstronomy.SimulationAPI","lenstronomy.SimulationAPI.ObservationConfig","lenstronomy.Util","lenstronomy.Workflow","mailinglist","modules","published","usage"],envversion:{"sphinx.domains.c":2,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":4,"sphinx.domains.index":1,"sphinx.domains.javascript":2,"sphinx.domains.math":2,"sphinx.domains.python":3,"sphinx.domains.rst":2,"sphinx.domains.std":2,"sphinx.ext.viewcode":1,sphinx:56},filenames:["affiliatedpackages.rst","authors.rst","contributing.rst","history.rst","index.rst","installation.rst","lenstronomy.rst","lenstronomy.Analysis.rst","lenstronomy.Conf.rst","lenstronomy.Cosmo.rst","lenstronomy.Data.rst","lenstronomy.GalKin.rst","lenstronomy.ImSim.rst","lenstronomy.ImSim.MultiBand.rst","lenstronomy.ImSim.Numerics.rst","lenstronomy.LensModel.rst","lenstronomy.LensModel.LightConeSim.rst","lenstronomy.LensModel.MultiPlane.rst","lenstronomy.LensModel.Profiles.rst","lenstronomy.LensModel.QuadOptimizer.rst","lenstronomy.LensModel.Solver.rst","lenstronomy.LensModel.Util.rst","lenstronomy.LightModel.rst","lenstronomy.LightModel.Profiles.rst","lenstronomy.Plots.rst","lenstronomy.PointSource.rst","lenstronomy.PointSource.Types.rst","lenstronomy.Sampling.rst","lenstronomy.Sampling.Likelihoods.rst","lenstronomy.Sampling.Pool.rst","lenstronomy.Sampling.Samplers.rst","lenstronomy.SimulationAPI.rst","lenstronomy.SimulationAPI.ObservationConfig.rst","lenstronomy.Util.rst","lenstronomy.Workflow.rst","mailinglist.rst","modules.rst","published.rst","usage.rst"],objects:{"":[[6,0,0,"-","lenstronomy"]],"lenstronomy.Analysis":[[7,0,0,"-","kinematics_api"],[7,0,0,"-","lens_profile"],[7,0,0,"-","light2mass"],[7,0,0,"-","light_profile"],[7,0,0,"-","td_cosmography"]],"lenstronomy.Analysis.kinematics_api":[[7,1,1,"","KinematicsAPI"]],"lenstronomy.Analysis.kinematics_api.KinematicsAPI":[[7,2,1,"","galkin_settings"],[7,2,1,"","kinematic_lens_profiles"],[7,2,1,"","kinematic_light_profile"],[7,2,1,"","kinematics_modeling_settings"],[7,2,1,"","transform_kappa_ext"],[7,2,1,"","velocity_dispersion"],[7,2,1,"","velocity_dispersion_analytical"],[7,2,1,"","velocity_dispersion_map"]],"lenstronomy.Analysis.lens_profile":[[7,1,1,"","LensProfileAnalysis"]],"lenstronomy.Analysis.lens_profile.LensProfileAnalysis":[[7,2,1,"","convergence_peak"],[7,2,1,"","effective_einstein_radius"],[7,2,1,"","local_lensing_effect"],[7,2,1,"","mass_fraction_within_radius"],[7,2,1,"","mst_invariant_differential"],[7,2,1,"","multi_gaussian_lens"],[7,2,1,"","profile_slope"],[7,2,1,"","radial_lens_profile"]],"lenstronomy.Analysis.light2mass":[[7,3,1,"","light2mass_interpol"]],"lenstronomy.Analysis.light_profile":[[7,1,1,"","LightProfileAnalysis"]],"lenstronomy.Analysis.light_profile.LightProfileAnalysis":[[7,2,1,"","ellipticity"],[7,2,1,"","flux_components"],[7,2,1,"","half_light_radius"],[7,2,1,"","multi_gaussian_decomposition"],[7,2,1,"","multi_gaussian_decomposition_ellipse"],[7,2,1,"","radial_light_profile"]],"lenstronomy.Analysis.td_cosmography":[[7,1,1,"","TDCosmography"]],"lenstronomy.Analysis.td_cosmography.TDCosmography":[[7,2,1,"","ddt_dd_from_time_delay_and_kinematics"],[7,2,1,"","ddt_from_time_delay"],[7,2,1,"","ds_dds_from_kinematics"],[7,2,1,"","fermat_potential"],[7,2,1,"","time_delays"],[7,2,1,"","velocity_dispersion_dimension_less"],[7,2,1,"","velocity_dispersion_map_dimension_less"]],"lenstronomy.Conf":[[8,0,0,"-","config_loader"]],"lenstronomy.Conf.config_loader":[[8,3,1,"","conventions_conf"],[8,3,1,"","numba_conf"]],"lenstronomy.Cosmo":[[9,0,0,"-","background"],[9,0,0,"-","cosmo_solver"],[9,0,0,"-","kde_likelihood"],[9,0,0,"-","lcdm"],[9,0,0,"-","lens_cosmo"],[9,0,0,"-","nfw_param"]],"lenstronomy.Cosmo.background":[[9,1,1,"","Background"]],"lenstronomy.Cosmo.background.Background":[[9,2,1,"","T_xy"],[9,2,1,"","a_z"],[9,2,1,"","d_xy"],[9,2,1,"","ddt"],[9,4,1,"","rho_crit"]],"lenstronomy.Cosmo.cosmo_solver":[[9,1,1,"","InvertCosmo"],[9,1,1,"","SolverFlatLCDM"],[9,3,1,"","cosmo2angular_diameter_distances"],[9,3,1,"","ddt2h0"]],"lenstronomy.Cosmo.cosmo_solver.InvertCosmo":[[9,2,1,"","get_cosmo"]],"lenstronomy.Cosmo.cosmo_solver.SolverFlatLCDM":[[9,2,1,"","F"],[9,2,1,"","solve"]],"lenstronomy.Cosmo.kde_likelihood":[[9,1,1,"","KDELikelihood"]],"lenstronomy.Cosmo.kde_likelihood.KDELikelihood":[[9,2,1,"","logLikelihood"]],"lenstronomy.Cosmo.lcdm":[[9,1,1,"","LCDM"]],"lenstronomy.Cosmo.lcdm.LCDM":[[9,2,1,"","D_d"],[9,2,1,"","D_ds"],[9,2,1,"","D_dt"],[9,2,1,"","D_s"]],"lenstronomy.Cosmo.lens_cosmo":[[9,1,1,"","LensCosmo"]],"lenstronomy.Cosmo.lens_cosmo.LensCosmo":[[9,2,1,"","a_z"],[9,2,1,"","arcsec2phys_lens"],[9,2,1,"","arcsec2phys_source"],[9,4,1,"","dd"],[9,4,1,"","dds"],[9,4,1,"","ddt"],[9,4,1,"","ds"],[9,4,1,"","h"],[9,2,1,"","kappa2proj_mass"],[9,2,1,"","mass_in_coin"],[9,2,1,"","mass_in_theta_E"],[9,2,1,"","nfwParam_physical"],[9,2,1,"","nfw_M_theta_r200"],[9,2,1,"","nfw_angle2physical"],[9,2,1,"","nfw_physical2angle"],[9,2,1,"","phys2arcsec_lens"],[9,4,1,"","sigma_crit"],[9,4,1,"","sigma_crit_angle"],[9,2,1,"","sis_sigma_v2theta_E"],[9,2,1,"","sis_theta_E2sigma_v"],[9,2,1,"","time_delay2fermat_pot"],[9,2,1,"","time_delay_units"],[9,2,1,"","uldm_angular2phys"],[9,2,1,"","uldm_mphys2angular"]],"lenstronomy.Cosmo.nfw_param":[[9,1,1,"","NFWParam"]],"lenstronomy.Cosmo.nfw_param.NFWParam":[[9,2,1,"","M200"],[9,2,1,"","M_r200"],[9,2,1,"","c_M_z"],[9,2,1,"","c_rho0"],[9,2,1,"","nfw_Mz"],[9,2,1,"","r200_M"],[9,2,1,"","rho0_c"],[9,5,1,"","rhoc"],[9,2,1,"","rhoc_z"]],"lenstronomy.Data":[[10,0,0,"-","coord_transforms"],[10,0,0,"-","imaging_data"],[10,0,0,"-","psf"]],"lenstronomy.Data.coord_transforms":[[10,1,1,"","Coordinates"],[10,1,1,"","Coordinates1D"]],"lenstronomy.Data.coord_transforms.Coordinates":[[10,2,1,"","coordinate_grid"],[10,2,1,"","map_coord2pix"],[10,2,1,"","map_pix2coord"],[10,4,1,"","pixel_area"],[10,4,1,"","pixel_width"],[10,4,1,"","radec_at_xy_0"],[10,2,1,"","shift_coordinate_system"],[10,4,1,"","transform_angle2pix"],[10,4,1,"","transform_pix2angle"],[10,4,1,"","xy_at_radec_0"]],"lenstronomy.Data.coord_transforms.Coordinates1D":[[10,2,1,"","coordinate_grid"]],"lenstronomy.Data.imaging_data":[[10,1,1,"","ImageData"]],"lenstronomy.Data.imaging_data.ImageData":[[10,4,1,"","data"],[10,2,1,"","log_likelihood"],[10,2,1,"","update_data"]],"lenstronomy.Data.psf":[[10,1,1,"","PSF"]],"lenstronomy.Data.psf.PSF":[[10,4,1,"","fwhm"],[10,4,1,"","kernel_pixel"],[10,4,1,"","kernel_point_source"],[10,2,1,"","kernel_point_source_supersampled"],[10,4,1,"","psf_error_map"],[10,2,1,"","set_pixel_size"]],"lenstronomy.GalKin":[[11,0,0,"-","analytic_kinematics"],[11,0,0,"-","anisotropy"],[11,0,0,"-","aperture"],[11,0,0,"-","aperture_types"],[11,0,0,"-","cosmo"],[11,0,0,"-","galkin"],[11,0,0,"-","galkin_model"],[11,0,0,"-","light_profile"],[11,0,0,"-","numeric_kinematics"],[11,0,0,"-","observation"],[11,0,0,"-","psf"],[11,0,0,"-","velocity_util"]],"lenstronomy.GalKin.analytic_kinematics":[[11,1,1,"","AnalyticKinematics"]],"lenstronomy.GalKin.analytic_kinematics.AnalyticKinematics":[[11,2,1,"","delete_cache"],[11,2,1,"","draw_light"],[11,2,1,"","grav_potential"],[11,2,1,"","sigma_r2"],[11,2,1,"","sigma_s2"]],"lenstronomy.GalKin.anisotropy":[[11,1,1,"","Anisotropy"],[11,1,1,"","Colin"],[11,1,1,"","Const"],[11,1,1,"","GeneralizedOM"],[11,1,1,"","Isotropic"],[11,1,1,"","OsipkovMerritt"],[11,1,1,"","Radial"]],"lenstronomy.GalKin.anisotropy.Anisotropy":[[11,2,1,"","K"],[11,2,1,"","anisotropy_solution"],[11,2,1,"","beta_r"],[11,2,1,"","delete_anisotropy_cache"]],"lenstronomy.GalKin.anisotropy.Colin":[[11,2,1,"","K"],[11,2,1,"","beta_r"]],"lenstronomy.GalKin.anisotropy.Const":[[11,2,1,"","K"],[11,2,1,"","anisotropy_solution"],[11,2,1,"","beta_r"]],"lenstronomy.GalKin.anisotropy.GeneralizedOM":[[11,2,1,"","K"],[11,2,1,"","anisotropy_solution"],[11,2,1,"","beta_r"],[11,2,1,"","delete_cache"]],"lenstronomy.GalKin.anisotropy.Isotropic":[[11,2,1,"","K"],[11,2,1,"","anisotropy_solution"],[11,2,1,"","beta_r"]],"lenstronomy.GalKin.anisotropy.OsipkovMerritt":[[11,2,1,"","K"],[11,2,1,"","anisotropy_solution"],[11,2,1,"","beta_r"]],"lenstronomy.GalKin.anisotropy.Radial":[[11,2,1,"","K"],[11,2,1,"","anisotropy_solution"],[11,2,1,"","beta_r"]],"lenstronomy.GalKin.aperture":[[11,1,1,"","Aperture"]],"lenstronomy.GalKin.aperture.Aperture":[[11,2,1,"","aperture_select"],[11,4,1,"","num_segments"]],"lenstronomy.GalKin.aperture_types":[[11,1,1,"","Frame"],[11,1,1,"","IFUShells"],[11,1,1,"","Shell"],[11,1,1,"","Slit"],[11,3,1,"","frame_select"],[11,3,1,"","shell_ifu_select"],[11,3,1,"","shell_select"],[11,3,1,"","slit_select"]],"lenstronomy.GalKin.aperture_types.Frame":[[11,2,1,"","aperture_select"],[11,4,1,"","num_segments"]],"lenstronomy.GalKin.aperture_types.IFUShells":[[11,2,1,"","aperture_select"],[11,4,1,"","num_segments"]],"lenstronomy.GalKin.aperture_types.Shell":[[11,2,1,"","aperture_select"],[11,4,1,"","num_segments"]],"lenstronomy.GalKin.aperture_types.Slit":[[11,2,1,"","aperture_select"],[11,4,1,"","num_segments"]],"lenstronomy.GalKin.cosmo":[[11,1,1,"","Cosmo"]],"lenstronomy.GalKin.cosmo.Cosmo":[[11,2,1,"","arcsec2phys_lens"],[11,4,1,"","epsilon_crit"]],"lenstronomy.GalKin.galkin":[[11,1,1,"","Galkin"]],"lenstronomy.GalKin.galkin.Galkin":[[11,2,1,"","dispersion"],[11,2,1,"","dispersion_map"]],"lenstronomy.GalKin.galkin_model":[[11,1,1,"","GalkinModel"]],"lenstronomy.GalKin.galkin_model.GalkinModel":[[11,2,1,"","check_df"]],"lenstronomy.GalKin.light_profile":[[11,1,1,"","LightProfile"]],"lenstronomy.GalKin.light_profile.LightProfile":[[11,2,1,"","delete_cache"],[11,2,1,"","draw_light_2d"],[11,2,1,"","draw_light_2d_linear"],[11,2,1,"","draw_light_3d"],[11,2,1,"","light_2d"],[11,2,1,"","light_2d_finite"],[11,2,1,"","light_3d"],[11,2,1,"","light_3d_interp"]],"lenstronomy.GalKin.numeric_kinematics":[[11,1,1,"","NumericKinematics"]],"lenstronomy.GalKin.numeric_kinematics.NumericKinematics":[[11,2,1,"","delete_cache"],[11,2,1,"","draw_light"],[11,2,1,"","grav_potential"],[11,2,1,"","mass_3d"],[11,2,1,"","sigma_r2"],[11,2,1,"","sigma_s2"],[11,2,1,"","sigma_s2_project"],[11,2,1,"","sigma_s2_r"]],"lenstronomy.GalKin.observation":[[11,1,1,"","GalkinObservation"]],"lenstronomy.GalKin.psf":[[11,1,1,"","PSF"],[11,1,1,"","PSFGaussian"],[11,1,1,"","PSFMoffat"]],"lenstronomy.GalKin.psf.PSF":[[11,2,1,"","displace_psf"]],"lenstronomy.GalKin.psf.PSFGaussian":[[11,2,1,"","displace_psf"]],"lenstronomy.GalKin.psf.PSFMoffat":[[11,2,1,"","displace_psf"]],"lenstronomy.GalKin.velocity_util":[[11,3,1,"","displace_PSF_gaussian"],[11,3,1,"","displace_PSF_moffat"],[11,3,1,"","draw_cdf_Y"],[11,3,1,"","draw_hernquist"],[11,3,1,"","draw_moffat_r"],[11,3,1,"","draw_xy"],[11,3,1,"","hyp_2F1"],[11,3,1,"","moffat_fwhm_alpha"],[11,3,1,"","moffat_r"],[11,3,1,"","project2d_random"]],"lenstronomy.ImSim":[[13,0,0,"-","MultiBand"],[14,0,0,"-","Numerics"],[12,0,0,"-","de_lens"],[12,0,0,"-","image2source_mapping"],[12,0,0,"-","image_linear_solve"],[12,0,0,"-","image_model"]],"lenstronomy.ImSim.MultiBand":[[13,0,0,"-","joint_linear"],[13,0,0,"-","multi_data_base"],[13,0,0,"-","multi_linear"],[13,0,0,"-","single_band_multi_model"]],"lenstronomy.ImSim.MultiBand.joint_linear":[[13,1,1,"","JointLinear"]],"lenstronomy.ImSim.MultiBand.joint_linear.JointLinear":[[13,4,1,"","data_response"],[13,2,1,"","error_response"],[13,2,1,"","image_linear_solve"],[13,2,1,"","likelihood_data_given_model"],[13,2,1,"","linear_response_matrix"]],"lenstronomy.ImSim.MultiBand.multi_data_base":[[13,1,1,"","MultiDataBase"]],"lenstronomy.ImSim.MultiBand.multi_data_base.MultiDataBase":[[13,4,1,"","num_bands"],[13,4,1,"","num_data_evaluate"],[13,2,1,"","num_param_linear"],[13,4,1,"","num_response_list"],[13,2,1,"","reduced_residuals"],[13,2,1,"","reset_point_source_cache"]],"lenstronomy.ImSim.MultiBand.multi_linear":[[13,1,1,"","MultiLinear"]],"lenstronomy.ImSim.MultiBand.multi_linear.MultiLinear":[[13,2,1,"","image_linear_solve"],[13,2,1,"","likelihood_data_given_model"]],"lenstronomy.ImSim.MultiBand.single_band_multi_model":[[13,1,1,"","SingleBandMultiModel"]],"lenstronomy.ImSim.MultiBand.single_band_multi_model.SingleBandMultiModel":[[13,2,1,"","error_map_source"],[13,2,1,"","image_linear_solve"],[13,2,1,"","likelihood_data_given_model"],[13,2,1,"","linear_response_matrix"],[13,2,1,"","num_param_linear"],[13,2,1,"","select_kwargs"]],"lenstronomy.ImSim.Numerics":[[14,0,0,"-","adaptive_numerics"],[14,0,0,"-","convolution"],[14,0,0,"-","grid"],[14,0,0,"-","numba_convolution"],[14,0,0,"-","numerics"],[14,0,0,"-","partial_image"],[14,0,0,"-","point_source_rendering"]],"lenstronomy.ImSim.Numerics.adaptive_numerics":[[14,1,1,"","AdaptiveConvolution"]],"lenstronomy.ImSim.Numerics.adaptive_numerics.AdaptiveConvolution":[[14,2,1,"","convolve2d"],[14,2,1,"","re_size_convolve"]],"lenstronomy.ImSim.Numerics.convolution":[[14,1,1,"","FWHMGaussianConvolution"],[14,1,1,"","MGEConvolution"],[14,1,1,"","MultiGaussianConvolution"],[14,1,1,"","PixelKernelConvolution"],[14,1,1,"","SubgridKernelConvolution"]],"lenstronomy.ImSim.Numerics.convolution.FWHMGaussianConvolution":[[14,2,1,"","convolution2d"]],"lenstronomy.ImSim.Numerics.convolution.MGEConvolution":[[14,2,1,"","convolution2d"],[14,2,1,"","kernel_difference"]],"lenstronomy.ImSim.Numerics.convolution.MultiGaussianConvolution":[[14,2,1,"","convolution2d"],[14,2,1,"","pixel_kernel"],[14,2,1,"","re_size_convolve"]],"lenstronomy.ImSim.Numerics.convolution.PixelKernelConvolution":[[14,2,1,"","convolution2d"],[14,2,1,"","copy_transpose"],[14,2,1,"","pixel_kernel"],[14,2,1,"","re_size_convolve"]],"lenstronomy.ImSim.Numerics.convolution.SubgridKernelConvolution":[[14,2,1,"","convolution2d"],[14,2,1,"","re_size_convolve"]],"lenstronomy.ImSim.Numerics.grid":[[14,1,1,"","AdaptiveGrid"],[14,1,1,"","RegularGrid"]],"lenstronomy.ImSim.Numerics.grid.AdaptiveGrid":[[14,4,1,"","coordinates_evaluate"],[14,2,1,"","flux_array2image_low_high"]],"lenstronomy.ImSim.Numerics.grid.RegularGrid":[[14,4,1,"","coordinates_evaluate"],[14,2,1,"","flux_array2image_low_high"],[14,4,1,"","grid_points_spacing"],[14,4,1,"","num_grid_points_axes"],[14,4,1,"","supersampling_factor"]],"lenstronomy.ImSim.Numerics.numba_convolution":[[14,1,1,"","NumbaConvolution"]],"lenstronomy.ImSim.Numerics.numba_convolution.NumbaConvolution":[[14,2,1,"","convolve2d"]],"lenstronomy.ImSim.Numerics.numerics":[[14,1,1,"","Numerics"]],"lenstronomy.ImSim.Numerics.numerics.Numerics":[[14,4,1,"","convolution_class"],[14,4,1,"","coordinates_evaluate"],[14,4,1,"","grid_class"],[14,4,1,"","grid_supersampling_factor"],[14,2,1,"","re_size_convolve"]],"lenstronomy.ImSim.Numerics.partial_image":[[14,1,1,"","PartialImage"]],"lenstronomy.ImSim.Numerics.partial_image.PartialImage":[[14,2,1,"","array_from_partial"],[14,2,1,"","image_from_partial"],[14,4,1,"","index_array"],[14,4,1,"","num_partial"],[14,2,1,"","partial_array"]],"lenstronomy.ImSim.Numerics.point_source_rendering":[[14,1,1,"","PointSourceRendering"]],"lenstronomy.ImSim.Numerics.point_source_rendering.PointSourceRendering":[[14,2,1,"","point_source_rendering"],[14,2,1,"","psf_error_map"]],"lenstronomy.ImSim.de_lens":[[12,3,1,"","get_param_WLS"],[12,3,1,"","marginalisation_const"],[12,3,1,"","marginalization_new"]],"lenstronomy.ImSim.image2source_mapping":[[12,1,1,"","Image2SourceMapping"]],"lenstronomy.ImSim.image2source_mapping.Image2SourceMapping":[[12,2,1,"","image2source"],[12,2,1,"","image_flux_joint"],[12,2,1,"","image_flux_split"]],"lenstronomy.ImSim.image_linear_solve":[[12,1,1,"","ImageLinearFit"]],"lenstronomy.ImSim.image_linear_solve.ImageLinearFit":[[12,2,1,"","array_masked2image"],[12,2,1,"","check_positive_flux"],[12,4,1,"","data_response"],[12,2,1,"","error_map_source"],[12,2,1,"","error_response"],[12,2,1,"","image2array_masked"],[12,2,1,"","image_linear_solve"],[12,2,1,"","image_pixelbased_solve"],[12,2,1,"","likelihood_data_given_model"],[12,2,1,"","linear_response_matrix"],[12,4,1,"","num_data_evaluate"],[12,2,1,"","num_param_linear"],[12,2,1,"","point_source_linear_response_set"],[12,2,1,"","reduced_chi2"],[12,2,1,"","reduced_residuals"],[12,2,1,"","update_data"],[12,2,1,"","update_linear_kwargs"],[12,2,1,"","update_pixel_kwargs"]],"lenstronomy.ImSim.image_model":[[12,1,1,"","ImageModel"]],"lenstronomy.ImSim.image_model.ImageModel":[[12,2,1,"","extinction_map"],[12,2,1,"","image"],[12,2,1,"","lens_surface_brightness"],[12,2,1,"","point_source"],[12,2,1,"","reset_point_source_cache"],[12,2,1,"","source_surface_brightness"],[12,2,1,"","update_psf"]],"lenstronomy.LensModel":[[16,0,0,"-","LightConeSim"],[17,0,0,"-","MultiPlane"],[18,0,0,"-","Profiles"],[19,0,0,"-","QuadOptimizer"],[20,0,0,"-","Solver"],[21,0,0,"-","Util"],[15,0,0,"-","convergence_integrals"],[15,0,0,"-","lens_model"],[15,0,0,"-","lens_model_extensions"],[15,0,0,"-","lens_param"],[15,0,0,"-","profile_integrals"],[15,0,0,"-","profile_list_base"],[15,0,0,"-","single_plane"]],"lenstronomy.LensModel.LightConeSim":[[16,0,0,"-","light_cone"]],"lenstronomy.LensModel.LightConeSim.light_cone":[[16,1,1,"","LightCone"],[16,1,1,"","MassSlice"]],"lenstronomy.LensModel.LightConeSim.light_cone.LightCone":[[16,2,1,"","cone_instance"]],"lenstronomy.LensModel.LightConeSim.light_cone.MassSlice":[[16,2,1,"","interpol_instance"]],"lenstronomy.LensModel.MultiPlane":[[17,0,0,"-","multi_plane"],[17,0,0,"-","multi_plane_base"]],"lenstronomy.LensModel.MultiPlane.multi_plane":[[17,1,1,"","LensedLocation"],[17,1,1,"","MultiPlane"],[17,1,1,"","PhysicalLocation"]],"lenstronomy.LensModel.MultiPlane.multi_plane.MultiPlane":[[17,2,1,"","alpha"],[17,2,1,"","arrival_time"],[17,2,1,"","co_moving2angle_source"],[17,2,1,"","geo_shapiro_delay"],[17,2,1,"","hessian"],[17,2,1,"","observed2flat_convention"],[17,2,1,"","ray_shooting"],[17,2,1,"","ray_shooting_partial"],[17,2,1,"","set_dynamic"],[17,2,1,"","set_static"],[17,2,1,"","transverse_distance_start_stop"],[17,2,1,"","update_source_redshift"]],"lenstronomy.LensModel.MultiPlane.multi_plane_base":[[17,1,1,"","MultiPlaneBase"]],"lenstronomy.LensModel.MultiPlane.multi_plane_base.MultiPlaneBase":[[17,2,1,"","geo_shapiro_delay"],[17,2,1,"","ray_shooting_partial"],[17,2,1,"","transverse_distance_start_stop"]],"lenstronomy.LensModel.Profiles":[[18,0,0,"-","arc_perturbations"],[18,0,0,"-","base_profile"],[18,0,0,"-","chameleon"],[18,0,0,"-","cnfw"],[18,0,0,"-","cnfw_ellipse"],[18,0,0,"-","const_mag"],[18,0,0,"-","constant_shift"],[18,0,0,"-","convergence"],[18,0,0,"-","coreBurkert"],[18,0,0,"-","cored_density"],[18,0,0,"-","cored_density_2"],[18,0,0,"-","cored_density_exp"],[18,0,0,"-","cored_density_mst"],[18,0,0,"-","curved_arc_const"],[18,0,0,"-","curved_arc_sis_mst"],[18,0,0,"-","curved_arc_spp"],[18,0,0,"-","curved_arc_spt"],[18,0,0,"-","curved_arc_tan_diff"],[18,0,0,"-","dipole"],[18,0,0,"-","elliptical_density_slice"],[18,0,0,"-","epl"],[18,0,0,"-","epl_numba"],[18,0,0,"-","flexion"],[18,0,0,"-","flexionfg"],[18,0,0,"-","gauss_decomposition"],[18,0,0,"-","gaussian_ellipse_kappa"],[18,0,0,"-","gaussian_ellipse_potential"],[18,0,0,"-","gaussian_kappa"],[18,0,0,"-","gaussian_potential"],[18,0,0,"-","hernquist"],[18,0,0,"-","hernquist_ellipse"],[18,0,0,"-","hessian"],[18,0,0,"-","interpol"],[18,0,0,"-","multi_gaussian_kappa"],[18,0,0,"-","multipole"],[18,0,0,"-","nfw"],[18,0,0,"-","nfw_ellipse"],[18,0,0,"-","nfw_mass_concentration"],[18,0,0,"-","nfw_vir_trunc"],[18,0,0,"-","nie"],[18,0,0,"-","nie_potential"],[18,0,0,"-","numerical_deflections"],[18,0,0,"-","p_jaffe"],[18,0,0,"-","p_jaffe_ellipse"],[18,0,0,"-","pemd"],[18,0,0,"-","point_mass"],[18,0,0,"-","sersic"],[18,0,0,"-","sersic_ellipse_kappa"],[18,0,0,"-","sersic_ellipse_potential"],[18,0,0,"-","sersic_utils"],[18,0,0,"-","shapelet_pot_cartesian"],[18,0,0,"-","shapelet_pot_polar"],[18,0,0,"-","shear"],[18,0,0,"-","sie"],[18,0,0,"-","sis"],[18,0,0,"-","sis_truncate"],[18,0,0,"-","spemd"],[18,0,0,"-","spep"],[18,0,0,"-","splcore"],[18,0,0,"-","spp"],[18,0,0,"-","tnfw"],[18,0,0,"-","uldm"]],"lenstronomy.LensModel.Profiles.arc_perturbations":[[18,1,1,"","ArcPerturbations"]],"lenstronomy.LensModel.Profiles.arc_perturbations.ArcPerturbations":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"]],"lenstronomy.LensModel.Profiles.base_profile":[[18,1,1,"","LensProfileBase"]],"lenstronomy.LensModel.Profiles.base_profile.LensProfileBase":[[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,2,1,"","mass_3d_lens"],[18,2,1,"","set_dynamic"],[18,2,1,"","set_static"]],"lenstronomy.LensModel.Profiles.chameleon":[[18,1,1,"","Chameleon"],[18,1,1,"","DoubleChameleon"],[18,1,1,"","DoubleChameleonPointMass"],[18,1,1,"","TripleChameleon"]],"lenstronomy.LensModel.Profiles.chameleon.Chameleon":[[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_3d_lens"],[18,2,1,"","param_convert"],[18,5,1,"","param_names"],[18,2,1,"","set_dynamic"],[18,2,1,"","set_static"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.chameleon.DoubleChameleon":[[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,2,1,"","set_dynamic"],[18,2,1,"","set_static"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.chameleon.DoubleChameleonPointMass":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.chameleon.TripleChameleon":[[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,2,1,"","set_dynamic"],[18,2,1,"","set_static"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.cnfw":[[18,1,1,"","CNFW"]],"lenstronomy.LensModel.Profiles.cnfw.CNFW":[[18,2,1,"","alpha_r"],[18,2,1,"","cnfwGamma"],[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_2d"],[18,2,1,"","mass_3d"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","model_name"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.cnfw_ellipse":[[18,1,1,"","CNFW_ELLIPSE"]],"lenstronomy.LensModel.Profiles.cnfw_ellipse.CNFW_ELLIPSE":[[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.const_mag":[[18,1,1,"","ConstMag"]],"lenstronomy.LensModel.Profiles.const_mag.ConstMag":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.constant_shift":[[18,1,1,"","Shift"]],"lenstronomy.LensModel.Profiles.constant_shift.Shift":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.convergence":[[18,1,1,"","Convergence"]],"lenstronomy.LensModel.Profiles.convergence.Convergence":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","model_name"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.coreBurkert":[[18,1,1,"","CoreBurkert"]],"lenstronomy.LensModel.Profiles.coreBurkert.CoreBurkert":[[18,2,1,"","cBurkGamma"],[18,2,1,"","cBurkPot"],[18,2,1,"","coreBurkAlpha"],[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_2d"],[18,2,1,"","mass_3d"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.cored_density":[[18,1,1,"","CoredDensity"]],"lenstronomy.LensModel.Profiles.cored_density.CoredDensity":[[18,2,1,"","alpha_r"],[18,2,1,"","d_alpha_dr"],[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,2,1,"","kappa_r"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_2d"],[18,2,1,"","mass_3d"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.cored_density_2":[[18,1,1,"","CoredDensity2"]],"lenstronomy.LensModel.Profiles.cored_density_2.CoredDensity2":[[18,2,1,"","alpha_r"],[18,2,1,"","d_alpha_dr"],[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,2,1,"","kappa_r"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_2d"],[18,2,1,"","mass_3d"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","model_name"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.cored_density_exp":[[18,1,1,"","CoredDensityExp"]],"lenstronomy.LensModel.Profiles.cored_density_exp.CoredDensityExp":[[18,2,1,"","alpha_radial"],[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,2,1,"","kappa_r"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_2d"],[18,2,1,"","mass_3d"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,2,1,"","rhotilde"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.cored_density_mst":[[18,1,1,"","CoredDensityMST"]],"lenstronomy.LensModel.Profiles.cored_density_mst.CoredDensityMST":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.curved_arc_const":[[18,1,1,"","CurvedArcConst"],[18,1,1,"","CurvedArcConstMST"]],"lenstronomy.LensModel.Profiles.curved_arc_const.CurvedArcConst":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.curved_arc_const.CurvedArcConstMST":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.curved_arc_sis_mst":[[18,1,1,"","CurvedArcSISMST"]],"lenstronomy.LensModel.Profiles.curved_arc_sis_mst.CurvedArcSISMST":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,2,1,"","sis_mst2stretch"],[18,2,1,"","stretch2sis_mst"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.curved_arc_spp":[[18,1,1,"","CurvedArcSPP"],[18,3,1,"","center_deflector"]],"lenstronomy.LensModel.Profiles.curved_arc_spp.CurvedArcSPP":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,2,1,"","spp2stretch"],[18,2,1,"","stretch2spp"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.curved_arc_spt":[[18,1,1,"","CurvedArcSPT"]],"lenstronomy.LensModel.Profiles.curved_arc_spt.CurvedArcSPT":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.curved_arc_tan_diff":[[18,1,1,"","CurvedArcTanDiff"]],"lenstronomy.LensModel.Profiles.curved_arc_tan_diff.CurvedArcTanDiff":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,2,1,"","stretch2sie_mst"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.dipole":[[18,1,1,"","Dipole"],[18,1,1,"","DipoleUtil"]],"lenstronomy.LensModel.Profiles.dipole.Dipole":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.dipole.DipoleUtil":[[18,2,1,"","angle"],[18,2,1,"","com"],[18,2,1,"","mass_ratio"]],"lenstronomy.LensModel.Profiles.elliptical_density_slice":[[18,1,1,"","ElliSLICE"]],"lenstronomy.LensModel.Profiles.elliptical_density_slice.ElliSLICE":[[18,2,1,"","alpha_ext"],[18,2,1,"","alpha_in"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,2,1,"","pot_ext"],[18,2,1,"","pot_in"],[18,2,1,"","sign"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.epl":[[18,1,1,"","EPL"],[18,1,1,"","EPLMajorAxis"]],"lenstronomy.LensModel.Profiles.epl.EPL":[[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_3d_lens"],[18,2,1,"","param_conv"],[18,5,1,"","param_names"],[18,2,1,"","set_dynamic"],[18,2,1,"","set_static"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.epl.EPLMajorAxis":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","param_names"]],"lenstronomy.LensModel.Profiles.epl_numba":[[18,1,1,"","EPL_numba"]],"lenstronomy.LensModel.Profiles.epl_numba.EPL_numba":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.flexion":[[18,1,1,"","Flexion"]],"lenstronomy.LensModel.Profiles.flexion.Flexion":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.flexionfg":[[18,1,1,"","Flexionfg"]],"lenstronomy.LensModel.Profiles.flexionfg.Flexionfg":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,2,1,"","transform_fg"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.gauss_decomposition":[[18,1,1,"","CTNFWGaussDec"],[18,1,1,"","GaussDecompositionAbstract"],[18,1,1,"","GaussDecompositionAbstract3D"],[18,1,1,"","GaussianEllipseKappaSet"],[18,1,1,"","NFWEllipseGaussDec"],[18,1,1,"","SersicEllipseGaussDec"]],"lenstronomy.LensModel.Profiles.gauss_decomposition.CTNFWGaussDec":[[18,2,1,"","get_kappa_1d"],[18,2,1,"","get_scale"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.gauss_decomposition.GaussDecompositionAbstract":[[18,2,1,"","density_2d"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","gauss_decompose"],[18,2,1,"","get_kappa_1d"],[18,2,1,"","get_scale"],[18,2,1,"","hessian"]],"lenstronomy.LensModel.Profiles.gauss_decomposition.GaussDecompositionAbstract3D":[[18,2,1,"","gauss_decompose"]],"lenstronomy.LensModel.Profiles.gauss_decomposition.GaussianEllipseKappaSet":[[18,2,1,"","density_2d"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.gauss_decomposition.NFWEllipseGaussDec":[[18,2,1,"","get_kappa_1d"],[18,2,1,"","get_scale"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.gauss_decomposition.SersicEllipseGaussDec":[[18,2,1,"","get_kappa_1d"],[18,2,1,"","get_scale"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.gaussian_ellipse_kappa":[[18,1,1,"","GaussianEllipseKappa"]],"lenstronomy.LensModel.Profiles.gaussian_ellipse_kappa.GaussianEllipseKappa":[[18,2,1,"","density_2d"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,2,1,"","sgn"],[18,2,1,"","sigma_function"],[18,5,1,"","upper_limit_default"],[18,2,1,"","w_f_approx"]],"lenstronomy.LensModel.Profiles.gaussian_ellipse_potential":[[18,1,1,"","GaussianEllipsePotential"]],"lenstronomy.LensModel.Profiles.gaussian_ellipse_potential.GaussianEllipsePotential":[[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_2d"],[18,2,1,"","mass_2d_lens"],[18,2,1,"","mass_3d"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.gaussian_kappa":[[18,1,1,"","GaussianKappa"]],"lenstronomy.LensModel.Profiles.gaussian_kappa.GaussianKappa":[[18,2,1,"","alpha_abs"],[18,2,1,"","d_alpha_dr"],[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_2d"],[18,2,1,"","mass_2d_lens"],[18,2,1,"","mass_3d"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.gaussian_potential":[[18,1,1,"","Gaussian"]],"lenstronomy.LensModel.Profiles.gaussian_potential.Gaussian":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.hernquist":[[18,1,1,"","Hernquist"]],"lenstronomy.LensModel.Profiles.hernquist.Hernquist":[[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","grav_pot"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_2d"],[18,2,1,"","mass_2d_lens"],[18,2,1,"","mass_3d"],[18,2,1,"","mass_3d_lens"],[18,2,1,"","mass_tot"],[18,5,1,"","param_names"],[18,2,1,"","rho2sigma"],[18,2,1,"","sigma2rho"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.hernquist_ellipse":[[18,1,1,"","Hernquist_Ellipse"]],"lenstronomy.LensModel.Profiles.hernquist_ellipse.Hernquist_Ellipse":[[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_2d"],[18,2,1,"","mass_2d_lens"],[18,2,1,"","mass_3d"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.hessian":[[18,1,1,"","Hessian"]],"lenstronomy.LensModel.Profiles.hessian.Hessian":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.interpol":[[18,1,1,"","Interpol"],[18,1,1,"","InterpolScaled"]],"lenstronomy.LensModel.Profiles.interpol.Interpol":[[18,2,1,"","derivatives"],[18,2,1,"","do_interp"],[18,2,1,"","f_interp"],[18,2,1,"","f_x_interp"],[18,2,1,"","f_xx_interp"],[18,2,1,"","f_xy_interp"],[18,2,1,"","f_y_interp"],[18,2,1,"","f_yy_interp"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.interpol.InterpolScaled":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.multi_gaussian_kappa":[[18,1,1,"","MultiGaussianKappa"],[18,1,1,"","MultiGaussianKappaEllipse"]],"lenstronomy.LensModel.Profiles.multi_gaussian_kappa.MultiGaussianKappa":[[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.multi_gaussian_kappa.MultiGaussianKappaEllipse":[[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.multipole":[[18,1,1,"","Multipole"]],"lenstronomy.LensModel.Profiles.multipole.Multipole":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.nfw":[[18,1,1,"","NFW"]],"lenstronomy.LensModel.Profiles.nfw.NFW":[[18,2,1,"","F_"],[18,2,1,"","alpha2rho0"],[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","g_"],[18,2,1,"","h_"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_2d"],[18,2,1,"","mass_3d"],[18,2,1,"","mass_3d_lens"],[18,2,1,"","nfwAlpha"],[18,2,1,"","nfwGamma"],[18,2,1,"","nfwPot"],[18,5,1,"","param_names"],[18,5,1,"","profile_name"],[18,2,1,"","rho02alpha"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.nfw_ellipse":[[18,1,1,"","NFW_ELLIPSE"]],"lenstronomy.LensModel.Profiles.nfw_ellipse.NFW_ELLIPSE":[[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,5,1,"","profile_name"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.nfw_mass_concentration":[[18,1,1,"","NFWMC"]],"lenstronomy.LensModel.Profiles.nfw_mass_concentration.NFWMC":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,2,1,"","set_dynamic"],[18,2,1,"","set_static"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.nfw_vir_trunc":[[18,1,1,"","NFWVirTrunc"]],"lenstronomy.LensModel.Profiles.nfw_vir_trunc.NFWVirTrunc":[[18,2,1,"","kappa"]],"lenstronomy.LensModel.Profiles.nie":[[18,1,1,"","NIE"],[18,1,1,"","NIEMajorAxis"]],"lenstronomy.LensModel.Profiles.nie.NIE":[[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_3d_lens"],[18,2,1,"","param_conv"],[18,5,1,"","param_names"],[18,2,1,"","set_dynamic"],[18,2,1,"","set_static"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.nie.NIEMajorAxis":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,2,1,"","kappa"],[18,5,1,"","param_names"]],"lenstronomy.LensModel.Profiles.nie_potential":[[18,1,1,"","NIEPotentialMajorAxis"],[18,1,1,"","NIE_POTENTIAL"]],"lenstronomy.LensModel.Profiles.nie_potential.NIEPotentialMajorAxis":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","param_names"]],"lenstronomy.LensModel.Profiles.nie_potential.NIE_POTENTIAL":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","param_conv"],[18,5,1,"","param_names"],[18,2,1,"","set_dynamic"],[18,2,1,"","set_static"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.numerical_deflections":[[18,1,1,"","NumericalAlpha"]],"lenstronomy.LensModel.Profiles.numerical_deflections.NumericalAlpha":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"]],"lenstronomy.LensModel.Profiles.p_jaffe":[[18,1,1,"","PJaffe"]],"lenstronomy.LensModel.Profiles.p_jaffe.PJaffe":[[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","grav_pot"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_2d"],[18,2,1,"","mass_3d"],[18,2,1,"","mass_3d_lens"],[18,2,1,"","mass_tot"],[18,5,1,"","param_names"],[18,2,1,"","rho2sigma"],[18,2,1,"","sigma2rho"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.p_jaffe_ellipse":[[18,1,1,"","PJaffe_Ellipse"]],"lenstronomy.LensModel.Profiles.p_jaffe_ellipse.PJaffe_Ellipse":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.pemd":[[18,1,1,"","PEMD"]],"lenstronomy.LensModel.Profiles.pemd.PEMD":[[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.point_mass":[[18,1,1,"","PointMass"]],"lenstronomy.LensModel.Profiles.point_mass.PointMass":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.sersic":[[18,1,1,"","Sersic"]],"lenstronomy.LensModel.Profiles.sersic.Sersic":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.sersic_ellipse_kappa":[[18,1,1,"","SersicEllipseKappa"]],"lenstronomy.LensModel.Profiles.sersic_ellipse_kappa.SersicEllipseKappa":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,2,1,"","projected_mass"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.sersic_ellipse_potential":[[18,1,1,"","SersicEllipse"]],"lenstronomy.LensModel.Profiles.sersic_ellipse_potential.SersicEllipse":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.sersic_utils":[[18,1,1,"","SersicUtil"]],"lenstronomy.LensModel.Profiles.sersic_utils.SersicUtil":[[18,2,1,"","alpha_abs"],[18,2,1,"","b_n"],[18,2,1,"","d_alpha_dr"],[18,2,1,"","density"],[18,2,1,"","get_distance_from_center"],[18,2,1,"","k_Re"],[18,2,1,"","k_bn"],[18,2,1,"","total_flux"]],"lenstronomy.LensModel.Profiles.shapelet_pot_cartesian":[[18,1,1,"","CartShapelets"]],"lenstronomy.LensModel.Profiles.shapelet_pot_cartesian.CartShapelets":[[18,2,1,"","H_n"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,2,1,"","phi_n"],[18,2,1,"","pre_calc"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.shapelet_pot_polar":[[18,1,1,"","PolarShapelets"]],"lenstronomy.LensModel.Profiles.shapelet_pot_polar.PolarShapelets":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.shear":[[18,1,1,"","Shear"],[18,1,1,"","ShearGammaPsi"],[18,1,1,"","ShearReduced"]],"lenstronomy.LensModel.Profiles.shear.Shear":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.shear.ShearGammaPsi":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.shear.ShearReduced":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.sie":[[18,1,1,"","SIE"]],"lenstronomy.LensModel.Profiles.sie.SIE":[[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","grav_pot"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_2d"],[18,2,1,"","mass_2d_lens"],[18,2,1,"","mass_3d"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,2,1,"","theta2rho"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.sis":[[18,1,1,"","SIS"]],"lenstronomy.LensModel.Profiles.sis.SIS":[[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","grav_pot"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_2d"],[18,2,1,"","mass_2d_lens"],[18,2,1,"","mass_3d"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,2,1,"","rho2theta"],[18,2,1,"","theta2rho"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.sis_truncate":[[18,1,1,"","SIS_truncate"]],"lenstronomy.LensModel.Profiles.sis_truncate.SIS_truncate":[[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.spemd":[[18,1,1,"","SPEMD"]],"lenstronomy.LensModel.Profiles.spemd.SPEMD":[[18,2,1,"","convert_params"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,2,1,"","is_not_empty"],[18,5,1,"","lower_limit_default"],[18,5,1,"","param_names"],[18,2,1,"","param_transform"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.spep":[[18,1,1,"","SPEP"]],"lenstronomy.LensModel.Profiles.spep.SPEP":[[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.splcore":[[18,1,1,"","SPLCORE"]],"lenstronomy.LensModel.Profiles.splcore.SPLCORE":[[18,2,1,"","alpha"],[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_2d"],[18,2,1,"","mass_2d_lens"],[18,2,1,"","mass_3d"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.spp":[[18,1,1,"","SPP"]],"lenstronomy.LensModel.Profiles.spp.SPP":[[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","grav_pot"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_2d"],[18,2,1,"","mass_2d_lens"],[18,2,1,"","mass_3d"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,2,1,"","rho2theta"],[18,2,1,"","theta2rho"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.tnfw":[[18,1,1,"","TNFW"]],"lenstronomy.LensModel.Profiles.tnfw.TNFW":[[18,2,1,"","F"],[18,2,1,"","alpha2rho0"],[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_2d"],[18,2,1,"","mass_3d"],[18,2,1,"","nfwAlpha"],[18,2,1,"","nfwGamma"],[18,2,1,"","nfwPot"],[18,5,1,"","param_names"],[18,5,1,"","profile_name"],[18,2,1,"","rho02alpha"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.Profiles.uldm":[[18,1,1,"","Uldm"]],"lenstronomy.LensModel.Profiles.uldm.Uldm":[[18,2,1,"","alpha_radial"],[18,2,1,"","density"],[18,2,1,"","density_2d"],[18,2,1,"","density_lens"],[18,2,1,"","derivatives"],[18,2,1,"","function"],[18,2,1,"","hessian"],[18,2,1,"","kappa_r"],[18,5,1,"","lower_limit_default"],[18,2,1,"","mass_2d"],[18,2,1,"","mass_3d"],[18,2,1,"","mass_3d_lens"],[18,5,1,"","param_names"],[18,2,1,"","rhotilde"],[18,5,1,"","upper_limit_default"]],"lenstronomy.LensModel.QuadOptimizer":[[19,0,0,"-","multi_plane_fast"],[19,0,0,"-","optimizer"],[19,0,0,"-","param_manager"]],"lenstronomy.LensModel.QuadOptimizer.multi_plane_fast":[[19,1,1,"","MultiplaneFast"]],"lenstronomy.LensModel.QuadOptimizer.multi_plane_fast.MultiplaneFast":[[19,2,1,"","chi_square"],[19,2,1,"","logL"],[19,2,1,"","ray_shooting_fast"],[19,2,1,"","source_plane_chi_square"]],"lenstronomy.LensModel.QuadOptimizer.optimizer":[[19,1,1,"","Optimizer"]],"lenstronomy.LensModel.QuadOptimizer.optimizer.Optimizer":[[19,2,1,"","optimize"]],"lenstronomy.LensModel.QuadOptimizer.param_manager":[[19,1,1,"","PowerLawFixedShear"],[19,1,1,"","PowerLawFixedShearMultipole"],[19,1,1,"","PowerLawFreeShear"],[19,1,1,"","PowerLawFreeShearMultipole"],[19,1,1,"","PowerLawParamManager"]],"lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawFixedShear":[[19,2,1,"","args_to_kwargs"]],"lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawFixedShearMultipole":[[19,2,1,"","args_to_kwargs"],[19,4,1,"","to_vary_index"]],"lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawFreeShear":[[19,2,1,"","args_to_kwargs"]],"lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawFreeShearMultipole":[[19,2,1,"","args_to_kwargs"],[19,4,1,"","to_vary_index"]],"lenstronomy.LensModel.QuadOptimizer.param_manager.PowerLawParamManager":[[19,2,1,"","bounds"],[19,2,1,"","kwargs_to_args"],[19,2,1,"","param_chi_square_penalty"],[19,4,1,"","to_vary_index"]],"lenstronomy.LensModel.Solver":[[20,0,0,"-","lens_equation_solver"],[20,0,0,"-","solver"],[20,0,0,"-","solver2point"],[20,0,0,"-","solver4point"]],"lenstronomy.LensModel.Solver.lens_equation_solver":[[20,1,1,"","LensEquationSolver"]],"lenstronomy.LensModel.Solver.lens_equation_solver.LensEquationSolver":[[20,2,1,"","candidate_solutions"],[20,2,1,"","findBrightImage"],[20,2,1,"","image_position_analytical"],[20,2,1,"","image_position_from_source"],[20,2,1,"","image_position_lenstronomy"],[20,2,1,"","image_position_stochastic"],[20,2,1,"","sort_arrival_times"]],"lenstronomy.LensModel.Solver.solver":[[20,1,1,"","Solver"]],"lenstronomy.LensModel.Solver.solver.Solver":[[20,2,1,"","add_fixed_lens"],[20,2,1,"","check_solver"],[20,2,1,"","constraint_lensmodel"],[20,2,1,"","update_solver"]],"lenstronomy.LensModel.Solver.solver2point":[[20,1,1,"","Solver2Point"]],"lenstronomy.LensModel.Solver.solver2point.Solver2Point":[[20,2,1,"","add_fixed_lens"],[20,2,1,"","constraint_lensmodel"],[20,2,1,"","solve"]],"lenstronomy.LensModel.Solver.solver4point":[[20,1,1,"","Solver4Point"]],"lenstronomy.LensModel.Solver.solver4point.Solver4Point":[[20,2,1,"","add_fixed_lens"],[20,2,1,"","constraint_lensmodel"],[20,2,1,"","solve"]],"lenstronomy.LensModel.Util":[[21,0,0,"-","epl_util"]],"lenstronomy.LensModel.Util.epl_util":[[21,3,1,"","brentq_inline"],[21,3,1,"","brentq_nojit"],[21,3,1,"","cart_to_pol"],[21,3,1,"","cdot"],[21,3,1,"","ell_to_pol"],[21,3,1,"","geomlinspace"],[21,3,1,"","min_approx"],[21,3,1,"","pol_to_cart"],[21,3,1,"","pol_to_ell"],[21,3,1,"","ps"],[21,3,1,"","rotmat"],[21,3,1,"","solvequadeq"]],"lenstronomy.LensModel.convergence_integrals":[[15,3,1,"","deflection_from_kappa_grid"],[15,3,1,"","deflection_from_kappa_grid_adaptive"],[15,3,1,"","deflection_kernel"],[15,3,1,"","potential_from_kappa_grid"],[15,3,1,"","potential_from_kappa_grid_adaptive"],[15,3,1,"","potential_kernel"]],"lenstronomy.LensModel.lens_model":[[15,1,1,"","LensModel"]],"lenstronomy.LensModel.lens_model.LensModel":[[15,2,1,"","alpha"],[15,2,1,"","arrival_time"],[15,2,1,"","curl"],[15,2,1,"","fermat_potential"],[15,2,1,"","flexion"],[15,2,1,"","gamma"],[15,2,1,"","hessian"],[15,2,1,"","kappa"],[15,2,1,"","magnification"],[15,2,1,"","potential"],[15,2,1,"","ray_shooting"],[15,2,1,"","set_dynamic"],[15,2,1,"","set_static"]],"lenstronomy.LensModel.lens_model_extensions":[[15,1,1,"","LensModelExtensions"]],"lenstronomy.LensModel.lens_model_extensions.LensModelExtensions":[[15,2,1,"","caustic_area"],[15,2,1,"","critical_curve_caustics"],[15,2,1,"","critical_curve_tiling"],[15,2,1,"","curved_arc_estimate"],[15,2,1,"","curved_arc_finite_area"],[15,2,1,"","hessian_eigenvectors"],[15,2,1,"","magnification_finite"],[15,2,1,"","magnification_finite_adaptive"],[15,2,1,"","radial_tangential_differentials"],[15,2,1,"","radial_tangential_stretch"],[15,2,1,"","tangential_average"],[15,2,1,"","zoom_source"]],"lenstronomy.LensModel.lens_param":[[15,1,1,"","LensParam"]],"lenstronomy.LensModel.lens_param.LensParam":[[15,2,1,"","get_params"],[15,2,1,"","num_param"],[15,2,1,"","set_params"]],"lenstronomy.LensModel.profile_integrals":[[15,1,1,"","ProfileIntegrals"]],"lenstronomy.LensModel.profile_integrals.ProfileIntegrals":[[15,2,1,"","density_2d"],[15,2,1,"","mass_enclosed_2d"],[15,2,1,"","mass_enclosed_3d"]],"lenstronomy.LensModel.profile_list_base":[[15,1,1,"","ProfileListBase"]],"lenstronomy.LensModel.profile_list_base.ProfileListBase":[[15,2,1,"","set_dynamic"],[15,2,1,"","set_static"]],"lenstronomy.LensModel.single_plane":[[15,1,1,"","SinglePlane"]],"lenstronomy.LensModel.single_plane.SinglePlane":[[15,2,1,"","alpha"],[15,2,1,"","density"],[15,2,1,"","fermat_potential"],[15,2,1,"","hessian"],[15,2,1,"","mass_2d"],[15,2,1,"","mass_3d"],[15,2,1,"","potential"],[15,2,1,"","ray_shooting"]],"lenstronomy.LightModel":[[23,0,0,"-","Profiles"],[22,0,0,"-","light_model"],[22,0,0,"-","light_param"]],"lenstronomy.LightModel.Profiles":[[23,0,0,"-","chameleon"],[23,0,0,"-","ellipsoid"],[23,0,0,"-","gaussian"],[23,0,0,"-","hernquist"],[23,0,0,"-","interpolation"],[23,0,0,"-","moffat"],[23,0,0,"-","nie"],[23,0,0,"-","p_jaffe"],[23,0,0,"-","power_law"],[23,0,0,"-","sersic"],[23,0,0,"-","shapelets"],[23,0,0,"-","shapelets_polar"],[23,0,0,"-","uniform"]],"lenstronomy.LightModel.Profiles.chameleon":[[23,1,1,"","Chameleon"],[23,1,1,"","DoubleChameleon"],[23,1,1,"","TripleChameleon"]],"lenstronomy.LightModel.Profiles.chameleon.Chameleon":[[23,2,1,"","function"],[23,2,1,"","light_3d"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.chameleon.DoubleChameleon":[[23,2,1,"","function"],[23,2,1,"","light_3d"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.chameleon.TripleChameleon":[[23,2,1,"","function"],[23,2,1,"","light_3d"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.ellipsoid":[[23,1,1,"","Ellipsoid"]],"lenstronomy.LightModel.Profiles.ellipsoid.Ellipsoid":[[23,2,1,"","function"]],"lenstronomy.LightModel.Profiles.gaussian":[[23,1,1,"","Gaussian"],[23,1,1,"","GaussianEllipse"],[23,1,1,"","MultiGaussian"],[23,1,1,"","MultiGaussianEllipse"]],"lenstronomy.LightModel.Profiles.gaussian.Gaussian":[[23,2,1,"","function"],[23,2,1,"","light_3d"],[23,2,1,"","total_flux"]],"lenstronomy.LightModel.Profiles.gaussian.GaussianEllipse":[[23,2,1,"","function"],[23,2,1,"","light_3d"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,2,1,"","total_flux"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.gaussian.MultiGaussian":[[23,2,1,"","function"],[23,2,1,"","function_split"],[23,2,1,"","light_3d"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,2,1,"","total_flux"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.gaussian.MultiGaussianEllipse":[[23,2,1,"","function"],[23,2,1,"","function_split"],[23,2,1,"","light_3d"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,2,1,"","total_flux"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.hernquist":[[23,1,1,"","Hernquist"],[23,1,1,"","HernquistEllipse"]],"lenstronomy.LightModel.Profiles.hernquist.Hernquist":[[23,2,1,"","function"],[23,2,1,"","light_3d"]],"lenstronomy.LightModel.Profiles.hernquist.HernquistEllipse":[[23,2,1,"","function"],[23,2,1,"","light_3d"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.interpolation":[[23,1,1,"","Interpol"]],"lenstronomy.LightModel.Profiles.interpolation.Interpol":[[23,2,1,"","coord2image_pixel"],[23,2,1,"","delete_cache"],[23,2,1,"","function"],[23,2,1,"","image_interp"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,2,1,"","total_flux"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.moffat":[[23,1,1,"","Moffat"]],"lenstronomy.LightModel.Profiles.moffat.Moffat":[[23,2,1,"","function"]],"lenstronomy.LightModel.Profiles.nie":[[23,1,1,"","NIE"]],"lenstronomy.LightModel.Profiles.nie.NIE":[[23,2,1,"","function"],[23,2,1,"","light_3d"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.p_jaffe":[[23,1,1,"","PJaffe"],[23,1,1,"","PJaffeEllipse"]],"lenstronomy.LightModel.Profiles.p_jaffe.PJaffe":[[23,2,1,"","function"],[23,2,1,"","light_3d"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.p_jaffe.PJaffeEllipse":[[23,2,1,"","function"],[23,2,1,"","light_3d"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.power_law":[[23,1,1,"","PowerLaw"]],"lenstronomy.LightModel.Profiles.power_law.PowerLaw":[[23,2,1,"","function"],[23,2,1,"","light_3d"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.sersic":[[23,1,1,"","CoreSersic"],[23,1,1,"","Sersic"],[23,1,1,"","SersicElliptic"]],"lenstronomy.LightModel.Profiles.sersic.CoreSersic":[[23,2,1,"","function"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.sersic.Sersic":[[23,2,1,"","function"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.sersic.SersicElliptic":[[23,2,1,"","function"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.shapelets":[[23,1,1,"","ShapeletSet"],[23,1,1,"","Shapelets"]],"lenstronomy.LightModel.Profiles.shapelets.ShapeletSet":[[23,2,1,"","decomposition"],[23,2,1,"","function"],[23,2,1,"","function_split"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,2,1,"","shapelet_basis_2d"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.shapelets.Shapelets":[[23,2,1,"","H_n"],[23,2,1,"","function"],[23,2,1,"","hermval"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,2,1,"","phi_n"],[23,2,1,"","pre_calc"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.shapelets_polar":[[23,1,1,"","ShapeletSetPolar"],[23,1,1,"","ShapeletsPolar"],[23,1,1,"","ShapeletsPolarExp"]],"lenstronomy.LightModel.Profiles.shapelets_polar.ShapeletSetPolar":[[23,2,1,"","decomposition"],[23,2,1,"","function"],[23,2,1,"","function_split"],[23,2,1,"","index2poly"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.shapelets_polar.ShapeletsPolar":[[23,2,1,"","function"],[23,2,1,"","index2poly"],[23,5,1,"","lower_limit_default"],[23,2,1,"","num_param"],[23,5,1,"","param_names"],[23,2,1,"","poly2index"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.shapelets_polar.ShapeletsPolarExp":[[23,2,1,"","function"],[23,2,1,"","index2poly"],[23,5,1,"","lower_limit_default"],[23,2,1,"","num_param"],[23,5,1,"","param_names"],[23,2,1,"","poly2index"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.Profiles.uniform":[[23,1,1,"","Uniform"]],"lenstronomy.LightModel.Profiles.uniform.Uniform":[[23,2,1,"","function"],[23,5,1,"","lower_limit_default"],[23,5,1,"","param_names"],[23,5,1,"","upper_limit_default"]],"lenstronomy.LightModel.light_model":[[22,1,1,"","LightModel"]],"lenstronomy.LightModel.light_param":[[22,1,1,"","LightParam"]],"lenstronomy.LightModel.light_param.LightParam":[[22,2,1,"","get_params"],[22,2,1,"","num_param"],[22,2,1,"","num_param_linear"],[22,4,1,"","param_name_list"],[22,2,1,"","set_params"]],"lenstronomy.Plots":[[24,0,0,"-","chain_plot"],[24,0,0,"-","lens_plot"],[24,0,0,"-","model_band_plot"],[24,0,0,"-","model_plot"],[24,0,0,"-","plot_util"]],"lenstronomy.Plots.chain_plot":[[24,3,1,"","plot_chain"],[24,3,1,"","plot_chain_list"],[24,3,1,"","plot_mcmc_behaviour"],[24,3,1,"","psf_iteration_compare"]],"lenstronomy.Plots.lens_plot":[[24,3,1,"","arrival_time_surface"],[24,3,1,"","curved_arc_illustration"],[24,3,1,"","distortions"],[24,3,1,"","lens_model_plot"],[24,3,1,"","plot_arc"]],"lenstronomy.Plots.model_band_plot":[[24,1,1,"","ModelBandPlot"]],"lenstronomy.Plots.model_band_plot.ModelBandPlot":[[24,2,1,"","absolute_residual_plot"],[24,2,1,"","convergence_plot"],[24,2,1,"","data_plot"],[24,2,1,"","decomposition_plot"],[24,2,1,"","deflection_plot"],[24,2,1,"","error_map_source_plot"],[24,2,1,"","magnification_plot"],[24,2,1,"","model_plot"],[24,2,1,"","normalized_residual_plot"],[24,2,1,"","plot_extinction_map"],[24,2,1,"","plot_main"],[24,2,1,"","plot_separate"],[24,2,1,"","plot_subtract_from_data_all"],[24,2,1,"","source"],[24,2,1,"","source_plot"],[24,2,1,"","subtract_from_data_plot"]],"lenstronomy.Plots.model_plot":[[24,1,1,"","ModelPlot"]],"lenstronomy.Plots.model_plot.ModelPlot":[[24,2,1,"","absolute_residual_plot"],[24,2,1,"","convergence_plot"],[24,2,1,"","data_plot"],[24,2,1,"","decomposition_plot"],[24,2,1,"","deflection_plot"],[24,2,1,"","error_map_source_plot"],[24,2,1,"","magnification_plot"],[24,2,1,"","model_plot"],[24,2,1,"","normalized_residual_plot"],[24,2,1,"","plot_extinction_map"],[24,2,1,"","plot_main"],[24,2,1,"","plot_separate"],[24,2,1,"","plot_subtract_from_data_all"],[24,2,1,"","reconstruction_all_bands"],[24,2,1,"","source"],[24,2,1,"","source_plot"],[24,2,1,"","subtract_from_data_plot"]],"lenstronomy.Plots.plot_util":[[24,3,1,"","cmap_conf"],[24,3,1,"","coordinate_arrows"],[24,3,1,"","image_position_plot"],[24,3,1,"","plot_line_set"],[24,3,1,"","result_string"],[24,3,1,"","scale_bar"],[24,3,1,"","source_position_plot"],[24,3,1,"","sqrt"],[24,3,1,"","text_description"]],"lenstronomy.PointSource":[[26,0,0,"-","Types"],[25,0,0,"-","point_source"],[25,0,0,"-","point_source_cached"],[25,0,0,"-","point_source_param"]],"lenstronomy.PointSource.Types":[[26,0,0,"-","base_ps"],[26,0,0,"-","lensed_position"],[26,0,0,"-","source_position"],[26,0,0,"-","unlensed"]],"lenstronomy.PointSource.Types.base_ps":[[26,1,1,"","PSBase"]],"lenstronomy.PointSource.Types.base_ps.PSBase":[[26,2,1,"","image_amplitude"],[26,2,1,"","image_position"],[26,2,1,"","source_amplitude"],[26,2,1,"","source_position"],[26,2,1,"","update_lens_model"]],"lenstronomy.PointSource.Types.lensed_position":[[26,1,1,"","LensedPositions"]],"lenstronomy.PointSource.Types.lensed_position.LensedPositions":[[26,2,1,"","image_amplitude"],[26,2,1,"","image_position"],[26,2,1,"","source_amplitude"],[26,2,1,"","source_position"]],"lenstronomy.PointSource.Types.source_position":[[26,1,1,"","SourcePositions"]],"lenstronomy.PointSource.Types.source_position.SourcePositions":[[26,2,1,"","image_amplitude"],[26,2,1,"","image_position"],[26,2,1,"","source_amplitude"],[26,2,1,"","source_position"]],"lenstronomy.PointSource.Types.unlensed":[[26,1,1,"","Unlensed"]],"lenstronomy.PointSource.Types.unlensed.Unlensed":[[26,2,1,"","image_amplitude"],[26,2,1,"","image_position"],[26,2,1,"","source_amplitude"],[26,2,1,"","source_position"]],"lenstronomy.PointSource.point_source":[[25,1,1,"","PointSource"]],"lenstronomy.PointSource.point_source.PointSource":[[25,2,1,"","check_image_positions"],[25,2,1,"","check_positive_flux"],[25,2,1,"","delete_lens_model_cache"],[25,2,1,"","image_amplitude"],[25,2,1,"","image_position"],[25,2,1,"","linear_response_set"],[25,2,1,"","num_basis"],[25,2,1,"","point_source_list"],[25,2,1,"","set_amplitudes"],[25,2,1,"","set_save_cache"],[25,2,1,"","source_amplitude"],[25,2,1,"","source_position"],[25,2,1,"","update_lens_model"],[25,2,1,"","update_linear"],[25,2,1,"","update_search_window"]],"lenstronomy.PointSource.point_source_cached":[[25,1,1,"","PointSourceCached"]],"lenstronomy.PointSource.point_source_cached.PointSourceCached":[[25,2,1,"","delete_lens_model_cache"],[25,2,1,"","image_amplitude"],[25,2,1,"","image_position"],[25,2,1,"","set_save_cache"],[25,2,1,"","source_amplitude"],[25,2,1,"","source_position"],[25,2,1,"","update_lens_model"]],"lenstronomy.PointSource.point_source_param":[[25,1,1,"","PointSourceParam"]],"lenstronomy.PointSource.point_source_param.PointSourceParam":[[25,2,1,"","add_fix_linear"],[25,2,1,"","get_params"],[25,2,1,"","num_param"],[25,2,1,"","num_param_linear"],[25,2,1,"","set_params"]],"lenstronomy.Sampling":[[28,0,0,"-","Likelihoods"],[29,0,0,"-","Pool"],[30,0,0,"-","Samplers"],[27,0,0,"-","likelihood"],[27,0,0,"-","parameters"],[27,0,0,"-","sampler"],[27,0,0,"-","special_param"]],"lenstronomy.Sampling.Likelihoods":[[28,0,0,"-","image_likelihood"],[28,0,0,"-","position_likelihood"],[28,0,0,"-","prior_likelihood"],[28,0,0,"-","time_delay_likelihood"]],"lenstronomy.Sampling.Likelihoods.image_likelihood":[[28,1,1,"","ImageLikelihood"]],"lenstronomy.Sampling.Likelihoods.image_likelihood.ImageLikelihood":[[28,2,1,"","logL"],[28,4,1,"","num_data"],[28,2,1,"","num_param_linear"],[28,2,1,"","reset_point_source_cache"]],"lenstronomy.Sampling.Likelihoods.position_likelihood":[[28,1,1,"","PositionLikelihood"]],"lenstronomy.Sampling.Likelihoods.position_likelihood.PositionLikelihood":[[28,2,1,"","astrometric_likelihood"],[28,2,1,"","check_additional_images"],[28,2,1,"","image_position_likelihood"],[28,2,1,"","logL"],[28,4,1,"","num_data"],[28,2,1,"","source_position_likelihood"]],"lenstronomy.Sampling.Likelihoods.prior_likelihood":[[28,1,1,"","PriorLikelihood"]],"lenstronomy.Sampling.Likelihoods.prior_likelihood.PriorLikelihood":[[28,2,1,"","logL"]],"lenstronomy.Sampling.Likelihoods.time_delay_likelihood":[[28,1,1,"","TimeDelayLikelihood"]],"lenstronomy.Sampling.Likelihoods.time_delay_likelihood.TimeDelayLikelihood":[[28,2,1,"","logL"],[28,4,1,"","num_data"]],"lenstronomy.Sampling.Pool":[[29,0,0,"-","multiprocessing"],[29,0,0,"-","pool"]],"lenstronomy.Sampling.Pool.multiprocessing":[[29,1,1,"","MultiPool"]],"lenstronomy.Sampling.Pool.multiprocessing.MultiPool":[[29,2,1,"","enabled"],[29,2,1,"","is_master"],[29,2,1,"","is_worker"],[29,2,1,"","map"],[29,5,1,"","wait_timeout"]],"lenstronomy.Sampling.Pool.pool":[[29,3,1,"","choose_pool"]],"lenstronomy.Sampling.Samplers":[[30,0,0,"-","base_nested_sampler"],[30,0,0,"-","dynesty_sampler"],[30,0,0,"-","multinest_sampler"],[30,0,0,"-","polychord_sampler"]],"lenstronomy.Sampling.Samplers.base_nested_sampler":[[30,1,1,"","NestedSampler"]],"lenstronomy.Sampling.Samplers.base_nested_sampler.NestedSampler":[[30,2,1,"","log_likelihood"],[30,2,1,"","prior"],[30,2,1,"","run"]],"lenstronomy.Sampling.Samplers.dynesty_sampler":[[30,1,1,"","DynestySampler"]],"lenstronomy.Sampling.Samplers.dynesty_sampler.DynestySampler":[[30,2,1,"","log_likelihood"],[30,2,1,"","prior"],[30,2,1,"","run"]],"lenstronomy.Sampling.Samplers.multinest_sampler":[[30,1,1,"","MultiNestSampler"]],"lenstronomy.Sampling.Samplers.multinest_sampler.MultiNestSampler":[[30,2,1,"","log_likelihood"],[30,2,1,"","prior"],[30,2,1,"","run"]],"lenstronomy.Sampling.Samplers.polychord_sampler":[[30,1,1,"","DyPolyChordSampler"]],"lenstronomy.Sampling.Samplers.polychord_sampler.DyPolyChordSampler":[[30,2,1,"","log_likelihood"],[30,2,1,"","prior"],[30,2,1,"","run"]],"lenstronomy.Sampling.likelihood":[[27,1,1,"","LikelihoodModule"]],"lenstronomy.Sampling.likelihood.LikelihoodModule":[[27,2,1,"","check_bounds"],[27,2,1,"","effective_num_data_points"],[27,2,1,"","likelihood"],[27,2,1,"","logL"],[27,2,1,"","log_likelihood"],[27,2,1,"","negativelogL"],[27,4,1,"","num_data"],[27,4,1,"","param_limits"]],"lenstronomy.Sampling.parameters":[[27,1,1,"","Param"]],"lenstronomy.Sampling.parameters.Param":[[27,2,1,"","args2kwargs"],[27,2,1,"","check_solver"],[27,2,1,"","image2source_plane"],[27,2,1,"","kwargs2args"],[27,2,1,"","num_param"],[27,2,1,"","num_param_linear"],[27,4,1,"","num_point_source_images"],[27,2,1,"","param_limits"],[27,2,1,"","print_setting"],[27,2,1,"","update_kwargs_model"],[27,2,1,"","update_lens_scaling"]],"lenstronomy.Sampling.sampler":[[27,1,1,"","Sampler"]],"lenstronomy.Sampling.sampler.Sampler":[[27,2,1,"","mcmc_emcee"],[27,2,1,"","pso"],[27,2,1,"","simplex"]],"lenstronomy.Sampling.special_param":[[27,1,1,"","SpecialParam"]],"lenstronomy.Sampling.special_param.SpecialParam":[[27,2,1,"","get_params"],[27,2,1,"","num_param"],[27,2,1,"","set_params"]],"lenstronomy.SimulationAPI":[[32,0,0,"-","ObservationConfig"],[31,0,0,"-","data_api"],[31,0,0,"-","model_api"],[31,0,0,"-","observation_api"],[31,0,0,"-","observation_constructor"],[31,0,0,"-","point_source_variability"],[31,0,0,"-","sim_api"]],"lenstronomy.SimulationAPI.ObservationConfig":[[32,0,0,"-","DES"],[32,0,0,"-","Euclid"],[32,0,0,"-","HST"],[32,0,0,"-","LSST"]],"lenstronomy.SimulationAPI.ObservationConfig.DES":[[32,1,1,"","DES"]],"lenstronomy.SimulationAPI.ObservationConfig.DES.DES":[[32,5,1,"","camera"],[32,2,1,"","kwargs_single_band"]],"lenstronomy.SimulationAPI.ObservationConfig.Euclid":[[32,1,1,"","Euclid"]],"lenstronomy.SimulationAPI.ObservationConfig.Euclid.Euclid":[[32,5,1,"","camera"],[32,2,1,"","kwargs_single_band"]],"lenstronomy.SimulationAPI.ObservationConfig.HST":[[32,1,1,"","HST"]],"lenstronomy.SimulationAPI.ObservationConfig.HST.HST":[[32,5,1,"","camera"],[32,2,1,"","kwargs_single_band"]],"lenstronomy.SimulationAPI.ObservationConfig.LSST":[[32,1,1,"","LSST"]],"lenstronomy.SimulationAPI.ObservationConfig.LSST.LSST":[[32,5,1,"","camera"],[32,2,1,"","kwargs_single_band"]],"lenstronomy.SimulationAPI.data_api":[[31,1,1,"","DataAPI"]],"lenstronomy.SimulationAPI.data_api.DataAPI":[[31,4,1,"","data_class"],[31,4,1,"","kwargs_data"]],"lenstronomy.SimulationAPI.model_api":[[31,1,1,"","ModelAPI"]],"lenstronomy.SimulationAPI.model_api.ModelAPI":[[31,4,1,"","lens_light_model_class"],[31,4,1,"","lens_model_class"],[31,2,1,"","physical2lensing_conversion"],[31,4,1,"","point_source_model_class"],[31,4,1,"","source_model_class"]],"lenstronomy.SimulationAPI.observation_api":[[31,1,1,"","Instrument"],[31,1,1,"","Observation"],[31,1,1,"","SingleBand"]],"lenstronomy.SimulationAPI.observation_api.Observation":[[31,4,1,"","exposure_time"],[31,4,1,"","psf_class"],[31,2,1,"","update_observation"]],"lenstronomy.SimulationAPI.observation_api.SingleBand":[[31,4,1,"","background_noise"],[31,2,1,"","estimate_noise"],[31,2,1,"","flux_iid"],[31,2,1,"","flux_noise"],[31,2,1,"","magnitude2cps"],[31,2,1,"","noise_for_model"],[31,4,1,"","sky_brightness"]],"lenstronomy.SimulationAPI.observation_constructor":[[31,3,1,"","observation_constructor"]],"lenstronomy.SimulationAPI.point_source_variability":[[31,1,1,"","PointSourceVariability"]],"lenstronomy.SimulationAPI.point_source_variability.PointSourceVariability":[[31,4,1,"","delays"],[31,4,1,"","image_bkg"],[31,2,1,"","image_time"],[31,2,1,"","point_source_time"]],"lenstronomy.SimulationAPI.sim_api":[[31,1,1,"","SimAPI"]],"lenstronomy.SimulationAPI.sim_api.SimAPI":[[31,2,1,"","image_model_class"],[31,2,1,"","magnitude2amplitude"]],"lenstronomy.Util":[[33,0,0,"-","analysis_util"],[33,0,0,"-","class_creator"],[33,0,0,"-","constants"],[33,0,0,"-","correlation"],[33,0,0,"-","data_util"],[33,0,0,"-","derivative_util"],[33,0,0,"-","image_util"],[33,0,0,"-","kernel_util"],[33,0,0,"-","mask_util"],[33,0,0,"-","multi_gauss_expansion"],[33,0,0,"-","numba_util"],[33,0,0,"-","param_util"],[33,0,0,"-","prob_density"],[33,0,0,"-","sampling_util"],[33,0,0,"-","simulation_util"],[33,0,0,"-","util"]],"lenstronomy.Util.analysis_util":[[33,3,1,"","azimuthalAverage"],[33,3,1,"","bic_model"],[33,3,1,"","ellipticities"],[33,3,1,"","half_light_radius"],[33,3,1,"","moments"],[33,3,1,"","profile_center"],[33,3,1,"","radial_profile"]],"lenstronomy.Util.class_creator":[[33,3,1,"","create_class_instances"],[33,3,1,"","create_im_sim"],[33,3,1,"","create_image_model"]],"lenstronomy.Util.constants":[[33,3,1,"","delay_arcsec2days"]],"lenstronomy.Util.correlation":[[33,3,1,"","correlation_2D"],[33,3,1,"","power_spectrum_1d"],[33,3,1,"","power_spectrum_2d"]],"lenstronomy.Util.data_util":[[33,3,1,"","absolute2apparent_magnitude"],[33,3,1,"","adu2electrons"],[33,3,1,"","bkg_noise"],[33,3,1,"","cps2magnitude"],[33,3,1,"","electrons2adu"],[33,3,1,"","flux_noise"],[33,3,1,"","magnitude2cps"]],"lenstronomy.Util.derivative_util":[[33,3,1,"","d_phi_dx"],[33,3,1,"","d_phi_dxx"],[33,3,1,"","d_phi_dxy"],[33,3,1,"","d_phi_dy"],[33,3,1,"","d_phi_dyy"],[33,3,1,"","d_r_dx"],[33,3,1,"","d_r_dxx"],[33,3,1,"","d_r_dxy"],[33,3,1,"","d_r_dy"],[33,3,1,"","d_r_dyy"],[33,3,1,"","d_x_diffr_dx"],[33,3,1,"","d_x_diffr_dy"],[33,3,1,"","d_y_diffr_dx"],[33,3,1,"","d_y_diffr_dy"]],"lenstronomy.Util.image_util":[[33,3,1,"","add_background"],[33,3,1,"","add_layer2image"],[33,3,1,"","add_layer2image_int"],[33,3,1,"","add_poisson"],[33,3,1,"","coordInImage"],[33,3,1,"","cut_edges"],[33,3,1,"","findOverlap"],[33,3,1,"","gradient_map"],[33,3,1,"","radial_profile"],[33,3,1,"","re_size"],[33,3,1,"","re_size_array"],[33,3,1,"","rebin_coord_transform"],[33,3,1,"","rebin_image"],[33,3,1,"","rotateImage"],[33,3,1,"","stack_images"],[33,3,1,"","symmetry_average"]],"lenstronomy.Util.kernel_util":[[33,3,1,"","averaging_even_kernel"],[33,3,1,"","center_kernel"],[33,3,1,"","cut_psf"],[33,3,1,"","cutout_source"],[33,3,1,"","de_shift_kernel"],[33,3,1,"","degrade_kernel"],[33,3,1,"","estimate_amp"],[33,3,1,"","fwhm_kernel"],[33,3,1,"","kernel_average_pixel"],[33,3,1,"","kernel_gaussian"],[33,3,1,"","kernel_norm"],[33,3,1,"","kernel_pixelsize_change"],[33,3,1,"","match_kernel_size"],[33,3,1,"","mge_kernel"],[33,3,1,"","pixel_kernel"],[33,3,1,"","split_kernel"],[33,3,1,"","subgrid_kernel"]],"lenstronomy.Util.mask_util":[[33,3,1,"","mask_azimuthal"],[33,3,1,"","mask_center_2d"],[33,3,1,"","mask_ellipse"],[33,3,1,"","mask_half_moon"]],"lenstronomy.Util.multi_gauss_expansion":[[33,3,1,"","de_projection_3d"],[33,3,1,"","gaussian"],[33,3,1,"","mge_1d"]],"lenstronomy.Util.numba_util":[[33,3,1,"","generated_jit"],[33,3,1,"","jit"],[33,3,1,"","nan_to_num"],[33,3,1,"","nan_to_num_arr"],[33,3,1,"","nan_to_num_single"]],"lenstronomy.Util.param_util":[[33,3,1,"","cart2polar"],[33,3,1,"","ellipticity2phi_q"],[33,3,1,"","phi_q2_ellipticity"],[33,3,1,"","polar2cart"],[33,3,1,"","shear_cartesian2polar"],[33,3,1,"","shear_polar2cartesian"],[33,3,1,"","transform_e1e2_product_average"],[33,3,1,"","transform_e1e2_square_average"]],"lenstronomy.Util.prob_density":[[33,1,1,"","KDE1D"],[33,1,1,"","SkewGaussian"],[33,3,1,"","compute_lower_upper_errors"]],"lenstronomy.Util.prob_density.KDE1D":[[33,2,1,"","likelihood"]],"lenstronomy.Util.prob_density.SkewGaussian":[[33,2,1,"","map_mu_sigma_skw"],[33,2,1,"","pdf"],[33,2,1,"","pdf_skew"]],"lenstronomy.Util.sampling_util":[[33,3,1,"","cube2args_gaussian"],[33,3,1,"","cube2args_uniform"],[33,3,1,"","sample_ball"],[33,3,1,"","sample_ball_truncated"],[33,3,1,"","scale_limits"],[33,3,1,"","uniform2unit"],[33,3,1,"","unit2uniform"]],"lenstronomy.Util.simulation_util":[[33,3,1,"","data_configure_simple"],[33,3,1,"","simulate_simple"]],"lenstronomy.Util.util":[[33,3,1,"","approx_theta_E"],[33,3,1,"","array2cube"],[33,3,1,"","array2image"],[33,3,1,"","averaging"],[33,3,1,"","compare_distance"],[33,3,1,"","convert_bool_list"],[33,3,1,"","cube2array"],[33,3,1,"","displaceAbs"],[33,3,1,"","fwhm2sigma"],[33,3,1,"","get_axes"],[33,3,1,"","get_distance"],[33,3,1,"","grid_from_coordinate_transform"],[33,3,1,"","hyper2F2_array"],[33,3,1,"","image2array"],[33,3,1,"","make_grid"],[33,3,1,"","make_grid_transformed"],[33,3,1,"","make_grid_with_coordtransform"],[33,3,1,"","make_subgrid"],[33,3,1,"","map_coord2pix"],[33,3,1,"","merge_dicts"],[33,3,1,"","min_square_dist"],[33,3,1,"","neighborSelect"],[33,3,1,"","points_on_circle"],[33,3,1,"","rotate"],[33,3,1,"","selectBest"],[33,3,1,"","select_best"],[33,3,1,"","sigma2fwhm"],[33,3,1,"","sort_image_index"]],"lenstronomy.Workflow":[[34,0,0,"-","alignment_matching"],[34,0,0,"-","fitting_sequence"],[34,0,0,"-","psf_fitting"],[34,0,0,"-","update_manager"]],"lenstronomy.Workflow.alignment_matching":[[34,1,1,"","AlignmentFitting"],[34,1,1,"","AlignmentLikelihood"]],"lenstronomy.Workflow.alignment_matching.AlignmentFitting":[[34,2,1,"","pso"]],"lenstronomy.Workflow.alignment_matching.AlignmentLikelihood":[[34,2,1,"","computeLikelihood"],[34,2,1,"","get_args"],[34,2,1,"","likelihood"],[34,4,1,"","num_param"],[34,2,1,"","setup"],[34,2,1,"","update_data"],[34,2,1,"","update_multi_band"]],"lenstronomy.Workflow.fitting_sequence":[[34,1,1,"","FittingSequence"]],"lenstronomy.Workflow.fitting_sequence.FittingSequence":[[34,2,1,"","align_images"],[34,2,1,"","best_fit"],[34,2,1,"","best_fit_from_samples"],[34,4,1,"","best_fit_likelihood"],[34,4,1,"","bic"],[34,2,1,"","fit_sequence"],[34,2,1,"","fix_not_computed"],[34,2,1,"","kwargs_fixed"],[34,4,1,"","likelihoodModule"],[34,2,1,"","mcmc"],[34,2,1,"","nested_sampling"],[34,4,1,"","param_class"],[34,2,1,"","psf_iteration"],[34,2,1,"","pso"],[34,2,1,"","set_param_value"],[34,2,1,"","simplex"],[34,2,1,"","update_settings"],[34,2,1,"","update_state"]],"lenstronomy.Workflow.psf_fitting":[[34,1,1,"","PsfFitting"]],"lenstronomy.Workflow.psf_fitting.PsfFitting":[[34,2,1,"","combine_psf"],[34,2,1,"","cutout_psf"],[34,2,1,"","cutout_psf_single"],[34,2,1,"","error_map_estimate"],[34,2,1,"","error_map_estimate_new"],[34,2,1,"","image_single_point_source"],[34,2,1,"","mask_point_source"],[34,2,1,"","point_like_source_cutouts"],[34,2,1,"","psf_estimate_individual"],[34,2,1,"","update_iterative"],[34,2,1,"","update_psf"]],"lenstronomy.Workflow.update_manager":[[34,1,1,"","UpdateManager"]],"lenstronomy.Workflow.update_manager.UpdateManager":[[34,2,1,"","best_fit"],[34,2,1,"","fix_image_parameters"],[34,4,1,"","fixed_kwargs"],[34,4,1,"","init_kwargs"],[34,4,1,"","param_class"],[34,4,1,"","parameter_state"],[34,2,1,"","set_init_state"],[34,4,1,"","sigma_kwargs"],[34,2,1,"","update_fixed"],[34,2,1,"","update_limits"],[34,2,1,"","update_options"],[34,2,1,"","update_param_state"],[34,2,1,"","update_param_value"]],lenstronomy:[[7,0,0,"-","Analysis"],[8,0,0,"-","Conf"],[9,0,0,"-","Cosmo"],[10,0,0,"-","Data"],[11,0,0,"-","GalKin"],[12,0,0,"-","ImSim"],[15,0,0,"-","LensModel"],[22,0,0,"-","LightModel"],[24,0,0,"-","Plots"],[25,0,0,"-","PointSource"],[27,0,0,"-","Sampling"],[31,0,0,"-","SimulationAPI"],[33,0,0,"-","Util"],[34,0,0,"-","Workflow"]]},objnames:{"0":["py","module","Python module"],"1":["py","class","Python class"],"2":["py","method","Python method"],"3":["py","function","Python function"],"4":["py","property","Python property"],"5":["py","attribute","Python attribute"]},objtypes:{"0":"py:module","1":"py:class","2":"py:method","3":"py:function","4":"py:property","5":"py:attribute"},terms:{"0":[4,7,9,10,11,12,13,15,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,33,34,37],"000001":18,"0001":[11,24],"0008":2,"001":[11,15,19,22,25,27,28,33],"003":15,"004":27,"005":[18,28],"01":[1,4,7,15,18,20,23,24],"0105178":23,"0105179":23,"0112138":18,"01123596":9,"01819":18,"02":[4,7,18,24],"02180":30,"02247191":9,"03":4,"0304034":18,"0311559":18,"03370787":9,"03459":30,"04":4,"0405491":11,"04494382":9,"05":[4,7,9,15,18,19,23,24],"05617978":9,"06":[4,15,18],"06010638":9,"06406":30,"06741573":9,"07":4,"07021277":9,"0704":30,"0710":18,"07182v1":18,"07865169":9,"08":[4,17],"08031915":9,"0809":30,"08988764":9,"09":[4,23],"09042553":9,"091":18,"1":[4,7,9,10,11,12,13,14,15,16,18,19,20,21,23,24,27,28,29,30,31,33,34,37],"10":[4,7,9,11,15,18,20,23,24,32,34,37],"100":[7,9,11,15,17,18,20,21,23,24,33],"1000":[7,11,18,20,23],"1000000":23,"10000000000":[23,33],"1000000000000":18,"10053191":9,"1006":11,"1011236":9,"10873":18,"11":[4,7,9,37],"1106383":9,"11235955":9,"12":[4,9,11,18,20,37],"1206":37,"12074468":9,"1231":37,"12359551":9,"13":[4,9,18,37],"1306":30,"1307":18,"13085106":9,"13483146":9,"14":[9,21],"1401":11,"1406":18,"14095745":9,"141592653589793":[18,23],"14606742":9,"15":[4,9,18,21,24],"150":23,"1507":18,"15106383":9,"15730337":9,"16":[4,9,18],"16117021":9,"16853933":9,"17":[4,9],"1704":30,"1712766":9,"17977528":9,"18":[4,9],"1804":30,"18138298":9,"19":[4,9,11],"1904":30,"19101124":9,"19148936":9,"1979":11,"1984":18,"1985":11,"1987":18,"199":37,"1990":18,"1994":18,"1994a":18,"1997":18,"1998":18,"1d":[10,11,12,13,14,27,33],"1e":[15,17,18,19,20,23],"1pmub_oozwwxon2dd5op8pekhct5mbbzjo1hv7imzg4i":32,"2":[2,4,7,9,10,11,12,14,15,16,18,19,21,23,27,29,31,33,34,37],"20":[4,7,9,11,18,24,33],"200":[7,9,34],"2000":11,"2001":[18,23],"2003":23,"2004":[18,23],"2005":[11,23],"2007":18,"2009":18,"2010":11,"2011":23,"2013":[15,18],"2014":[11,18,23],"2015":[3,4,18,37],"20159574":9,"2016":[7,11,37],"2017":18,"2017a":37,"2017b":37,"2018":[4,7,37],"2018a":37,"2019":[4,7,18,23,37],"2019a":37,"2019b":37,"2019c":37,"2020":[4,7,18,37],"2020a":37,"2020b":37,"2021":[4,7,37],"2021a":37,"2021b":37,"2022":[4,37],"20224719":9,"2022a":37,"2022b":37,"2038":37,"21":[4,9],"2105":18,"21170213":9,"21348315":9,"2144":30,"22":[4,9],"22180851":9,"2247191":9,"23":[4,9,37],"23191489":9,"2344":11,"23595506":9,"24":9,"24202128":9,"24719101":9,"25":[4,9],"250":19,"25212766":9,"25842697":9,"26":[4,9],"26223404":9,"26966292":9,"26a":18,"27":[4,9],"27234043":9,"277536627000":9,"28":9,"28089888":9,"28244681":9,"283185307179586":33,"284":18,"29":[4,9],"29213483":9,"29255319":9,"2d":[10,11,12,13,14,15,18,23,24,27,31,33,34,37],"2e":21,"2f":[18,24],"2n":18,"2phi":15,"2q":18,"2to3":2,"2x2":[10,33],"3":[2,4,9,14,18,19,21,23,24,27,29,32,33,37],"30":[4,9],"30265957":9,"30337079":9,"31":[4,9],"31276596":9,"31460674":9,"32":9,"32287234":9,"3258427":9,"327":23,"33":9,"33297872":9,"33707865":9,"34":9,"34308511":9,"3437":30,"34831461":9,"35":9,"35319149":9,"35955056":9,"36":9,"3600":29,"36329787":9,"37":[9,37],"3704":30,"37078652":9,"37340426":9,"3745":37,"38":9,"38202247":9,"38351064":9,"39":9,"39325843":9,"39361702":9,"3\u03c3":37,"3d":[7,11,15,18,23,33],"4":[4,7,9,14,15,18,20,27,33,34,37],"40":9,"400":[7,19],"4008":37,"4037234":9,"40449438":9,"41":9,"41382979":9,"41573034":9,"42":9,"4220":18,"42393617":9,"42696629":9,"43":9,"4332":37,"43404255":9,"43820225":9,"44":[9,18],"44414894":9,"4462":11,"4494382":9,"45":9,"45425532":9,"46":9,"46067416":9,"4643617":9,"47":9,"47191011":9,"47446809":9,"48":9,"48314607":9,"48457447":9,"49":9,"49012e":20,"49438202":9,"49468085":9,"5":[2,4,7,10,14,15,18,20,23,24,27,31,33,37],"50":[9,18,19],"500":24,"5000":37,"50000":19,"50478723":9,"50561798":9,"51":9,"51489362":9,"51685393":9,"52":9,"525":9,"52808989":9,"529584":18,"53":9,"53510638":9,"5354":37,"53932584":9,"54":[9,18],"54521277":9,"55":[9,18],"5505618":9,"551":[11,23],"552713678800501e":21,"55531915":9,"56":9,"56179775":9,"5636":18,"56542553":9,"57":9,"5707963267948966":18,"57303371":9,"57553191":9,"58":9,"58426966":9,"5856383":9,"59":9,"59550562":9,"59574468":9,"6":[4,7,18,24,32,33,37],"60":9,"60585106":9,"60674157":9,"61":9,"61595745":9,"61797753":9,"62":9,"62606383":9,"62921348":9,"63":9,"63617021":9,"64":9,"64044944":9,"6462766":9,"65":9,"65168539":9,"65638298":9,"6586":18,"66":9,"66292135":9,"66648936":9,"67":[9,18],"6741573":9,"67659574":9,"68":9,"68539326":9,"68670213":9,"69":9,"69662921":9,"69680851":9,"7":[4,11,23,29,33,37],"70":[9,18],"70691489":9,"70786517":9,"70km":18,"71":9,"71702128":9,"71910112":9,"72":9,"72712766":9,"73":9,"73033708":9,"73723404":9,"74":9,"74157303":9,"74734043":9,"75":9,"75280899":9,"75744681":9,"76":9,"76404494":9,"76755319":9,"77":9,"7752809":9,"77765957":9,"78":9,"78651685":9,"78776596":9,"79":9,"79775281":9,"79787234":9,"8":[4,18,23,34,37],"80":9,"80797872":9,"80898876":9,"81":9,"81808511":9,"82":9,"82022472":9,"82819149":9,"83":9,"83146067":9,"83829787":9,"84":9,"84269663":9,"84840426":9,"85":9,"85393258":9,"85851064":9,"86":9,"86516854":9,"86861702":9,"87":9,"87640449":9,"8787234":9,"88":9,"8842":37,"88764045":9,"88882979":9,"89":9,"8988764":9,"89893617":9,"9":[4,15,34,37],"90":[9,34],"90904255":9,"91":9,"91011236":9,"91914894":9,"92":9,"92134831":9,"92925532":9,"93":9,"93258427":9,"9393617":9,"93m":37,"94":9,"94382022":9,"94946809":9,"95":9,"95505618":9,"95957447":9,"96":9,"96629213":9,"96968085":9,"97":9,"9705194":18,"97752809":9,"97978723":9,"98":9,"98876404":9,"98989362":9,"999n":23,"\u03c3":37,"abstract":18,"boolean":[7,10,11,12,13,14,15,16,17,23,24,25,27,28,33,34],"break":[18,23,37],"case":[4,5,7,12,15,17,18,25,37,38],"catch":29,"class":[2,3,7,9,10,11,12,13,14,15,16,17,18,19,20,22,23,24,25,26,27,28,29,30,31,32,33,34,37],"const":[11,15],"default":[5,7,12,13,15,17,18,20,24,27,29,33,34],"do":[2,7,9,11,14,15,18,34],"final":[2,19,37],"float":[7,9,10,12,15,17,18,20,22,23,24,25,26,27,31,33,34],"function":[2,3,7,9,10,11,12,13,14,15,17,18,21,22,23,25,26,27,29,33,34,37],"import":[2,3,18,20,33,38],"int":[10,11,12,14,15,18,20,22,23,25,27,29,31,33,34],"j\u00falio":29,"new":[2,3,4,12,17,19,25,27,31,33,34,35,37],"public":[2,4],"return":[3,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34],"short":3,"static":[7,11,15,18,19,23,27,28,29,34],"super":[10,14,33,34],"transient":37,"true":[7,9,10,11,12,13,14,15,16,17,18,19,20,22,23,24,25,26,27,28,30,31,33,34],"var":33,A:[0,1,2,4,5,12,15,18,21,23,24,29,30,37],AND:19,And:18,As:2,At:5,Be:15,By:29,For:[2,11,18,23,27,31,34],If:[0,2,4,7,10,13,14,15,17,18,19,26,29,31,33,34,35],In:[5,10,11,12,18,27,31,33,37],Is:37,It:[2,11,15,18,29,34],Near:37,ON:18,On:37,Or:5,The:[0,2,4,5,7,9,10,11,12,13,14,15,16,17,18,19,20,22,23,24,26,28,29,31,33,34,35,37,38],Then:7,There:[2,5,12,34],These:[0,11,13,27,31,34],To:[2,5,15,18,20,33,37,38],Will:20,With:[18,37],_1:18,_2:18,_:[18,24,37],__future__:2,__init__:[27,34],_add_fix:34,_chi_n_m:23,_cosmo:15,_particle_swarm:19,_x_imag:19,_y_imag:19,a16:11,a1:11,a3:11,a4:[11,18],a5:11,a_0:9,a_m:18,a_z:9,aalber:1,aamara:1,ab:[18,20,21,23,30],about:[2,4,34],abov:[18,27,34],absenc:18,absolut:[18,24,25,26,33],absolute2apparent_magnitud:33,absolute_magnitud:33,absolute_residual_plot:24,acceler:[15,18,19],accept:[2,20,29],access:[2,4,14,18,19,24,31,34,38],accord:[10,11,18,20,24,28,31,34],accordingli:7,account:[2,7,9,15,18],accur:[7,11,15,18,37],accuraci:[14,16,18,37],achiev:[2,34],across:2,act:18,activ:[5,37],actual:[7,34],ad:[3,7,12,18,20,27,31,33,34],adam:1,adapt:[3,14,15,16,37],adaptive_numer:[6,12],adaptiveconvolut:14,adaptivegrid:14,add:[0,2,3,4,12,27,31,33,34],add_background:33,add_fix_linear:25,add_fixed_len:20,add_layer2imag:33,add_layer2image_int:33,add_poisson:33,addit:[3,7,10,12,18,20,21,25,26,27,28,29,31,33,34],addition:[2,31],additional_error_map:10,additional_imag:26,additional_images_list:[25,33],additon:[12,13],adjust:7,adopt:[5,27,33],adrn:29,adsab:18,adu2electron:33,adu:[31,32,33],advanc:2,advertis:0,ae:33,after:[14,22,27,34],afterward:17,against:[18,37],agn:[0,37],agnello:11,ai:37,aim:14,ajshajib:1,aka:[2,26],akeret:1,al:[3,4,7,11,15,18,23,37],algorithm:[30,34,37],align:[3,15,18,33,34],align_imag:34,alignment_match:[6,36],alignmentfit:34,alignmentlikelihood:34,all:[2,3,5,7,9,11,12,13,14,15,16,17,18,19,20,22,23,24,25,28,31,33,34],all_model:33,allow:[2,4,11,16,18,19,22,27,33,34,38],alon:[4,17,38],along:[14,15,17,18],alpha2rho0:18,alpha:[11,15,17,18,23],alpha_1:18,alpha_:18,alpha_ab:18,alpha_ext:18,alpha_i:[7,17,18],alpha_in:18,alpha_r:[9,18,31],alpha_radi:18,alpha_x:[7,17,18],alphabet:4,alreadi:[2,10,13,27],also:[0,2,4,5,11,12,14,15,18,20,21,22,23,29,31,38],altern:[2,18,27],although:33,alwai:[17,19],am:18,amara:[1,4,37],amn3142:1,among:[13,18],amp:[12,14,18,22,23,25,31,33,34],amp_arrai:25,amp_list:25,amp_scal:15,amplidut:18,amplitud:[3,7,12,14,18,23,24,25,26,31,33,34],an:[0,4,7,9,11,12,14,15,16,18,19,20,23,24,27,28,29,31,33,34,37,38],analog:[32,33],analys:24,analysi:[0,3,6,23,24,36,37],analysis_util:[6,36],analyt:[3,7,11,15,18,20],analytic_kinemat:[6,7,36],analytickinemat:[7,11],andrea:1,andreasfilipp:1,angel:[18,33],angl:[7,9,11,12,15,16,17,18,20,21,22,23,24,31,33,34],anguar:9,angular:[7,9,10,11,15,17,18,20,23,24,33,34],ani:[4,7,11,18,20,27,29,33,34,37],anisotropi:[3,6,7,36,37],anisotropy_model:7,anisotropy_solut:11,anisotropy_typ:11,anna:1,announc:[4,35],anoth:[5,25,33,34],anowar:1,answer:7,apertur:[3,6,7,15,36],aperture_select:11,aperture_typ:[6,36],api:[3,4,7,15,31,38],appar:[18,26,31,33],appear:[15,31],appendix:18,appertur:11,appli:[0,7,11,12,13,14,18,20,24,25,26,27,33,34,37],applic:[0,4,5,15,16,18,27,33,37],approach:[11,33],appropri:[15,18,24],approx:23,approx_theta_:33,approxim:[3,10,11,14,15,18,20,31,33,37],apt:5,ar:[0,2,4,5,7,9,10,11,12,13,15,16,17,18,19,20,23,24,25,26,27,28,29,31,33,34,37],arat:18,arbitrari:[12,15,31,33],arc:[3,9,10,11,15,17,18,23,34,37],arc_perturb:[6,15],architectur:37,arcperturb:18,arcsec2phys_len:[9,11],arcsec2phys_sourc:9,arcsec:[7,9,10,11,15,17,18,24,33],arcsecond:[9,15,18,23,31,32,33,37],arcseond:33,arctan2:33,arctan:18,arctanh:18,area:[9,10,15,23,25,33],arg:[15,18,19,21,22,24,25,26,27,30,34],argpars:29,argrelextrema:33,args2kwarg:27,args_len:19,args_param_class:19,args_to_kwarg:19,argument:[3,7,8,10,11,12,13,15,16,17,18,19,20,21,22,24,25,26,27,28,29,31,33,34],around:[7,15,18,19,33,34],arrai:[9,10,11,12,13,14,15,17,18,19,20,23,24,25,26,27,31,33,34],array2cub:33,array2imag:33,array_from_parti:14,array_masked2imag:12,arriv:[7,15,17,20],arrival_tim:[15,17],arrival_time_sort:20,arrival_time_surfac:24,arrow_s:24,arxiv:[11,18,23,30],ascend:[11,18],ask:[4,35],aspect:11,aspect_ratio:15,assess:37,assign:[17,23,28,34],associ:[7,28,34],assum:[11,13,15,18,33],assumpt:[7,12,31],astro:[11,18,23],astrometirc:28,astrometr:[3,12,27,28,37],astrometri:28,astrometric_likelihood:[27,28],astronom:[22,31,33,37],astropi:[2,3,4,9,15,16,18,33],astropy_inst:19,ata:37,attempt:7,attent:[5,7,10,17,18,25,34],attributeerror:[18,20,33],author:[4,29],auto:[30,34],autom:[0,2,37],automat:4,avail:[3,4,10,13,15,27,28,31,34,38],averag:[7,11,15,18,23,24,33],averaging_even_kernel:33,avoid:[25,33,34],awai:2,ax:[12,13,14,24],ax_i:18,ax_x:18,axi:[7,10,11,12,13,14,15,18,20,23,24,31,33],axion:37,axis_ratio:15,aymer:[1,29],aymgal:1,azimut:33,azimuth:[7,11,14,33],azimuthalaverag:33,b1152:37,b2:11,b3:18,b:[2,11,18,21,33],b_:[18,23],b_n:[18,23],back:[19,25,26,27,28],backend:27,backgourn:15,background:[6,10,15,18,23,31,33,36],background_nois:31,background_rm:[10,33],backgroundcolor:24,backup:27,backup_filenam:[27,34],backward:[2,12,17,20,25],bad:[2,24],ball:[18,33],banana:24,band:[3,4,13,24,32,33,34,37,38],band_index:[13,24,33,34],bands_comput:[24,27,28,33],bandwidth:9,baobab:[0,37],bar:[24,27,34,37],barkana:[5,18],barnaka1998:18,base:[0,2,4,7,9,10,11,12,13,14,15,16,17,18,19,20,22,23,24,25,26,27,28,29,30,31,32,33,34,37],base_nested_sampl:[6,27],base_p:[6,25],base_profil:[6,15],baselin:37,bash:2,basi:[4,12,13,18,22,23,24,25,27,34,37],basic:[18,31],bayesian:[0,33,34,37],bbn:37,becam:33,becaus:[15,19,30],becker:37,becom:[4,11],bee:13,been:[2,4,25,28],befor:[0,2,17,24,25,34],begin:[15,18],behavior:29,behaviour:[20,24,33],being:[5,12,13,14,15,17,18,19,20,22,24,25,27,28,31,33,34],below:[2,10,24,30,34],bend:[9,18],bennert:37,berg:[11,23],best:[18,24,27,33,34,37],best_fit:34,best_fit_from_sampl:34,best_fit_likelihood:34,beta:[11,18,23],beta_inf:11,beta_r:11,better:[3,18,27,29,34],between:[4,7,11,12,13,14,15,17,18,19,20,23,24,25,27,28,29,30,33,34,35,37],beyond:37,bf:23,bic:[33,34],bic_model:33,big:[4,27],biject:[27,34],billion:37,bin:[11,33],bin_siz:33,binari:[0,37],birrer:[1,4,7,11,29,37],bkg_nois:33,black:37,blandford:18,blob:2,block:34,block_center_neighbour:34,block_center_neighbour_error_map:34,blum:[18,37],bnord:1,bodi:18,boi:33,bool:[7,10,11,12,13,14,15,17,18,20,23,24,25,27,28,29,31,33,34],bool_list:15,boost:34,both:[0,7,18,33,37],bound:[11,18,19,21,27,28,30,33,34,37],boundari:11,box:11,boxi:37,boxy:37,brai:18,branch:[2,29],brentq:21,brentq_inlin:21,brentq_nojit:21,brian:1,brigh:23,bright:[0,3,10,11,12,13,14,15,18,22,23,24,25,26,27,31,33,37],bug:3,build:[2,34],build_doc:2,built:29,burkert:18,burn:[27,34],button:2,c01:20,c10:20,c:[5,7,9,11,15,18,21,33],c_d_inv:12,c_m_z:9,c_rho0:9,cach:[10,11,12,13,14,15,23,25,28,33],calcul:[3,5,7,9,11,15,18,21,23,24,33,37],call:[2,9,11,13,15,18,23,25,26,29,34],callabl:29,callback:29,calss:23,cam:37,camera:32,campaign:[0,37],can:[2,3,4,5,7,10,11,12,14,15,16,17,18,20,23,26,27,29,30,31,33,34,35,37,38],candid:37,candidate_solut:20,cao:37,capabl:29,care:[18,21],carefulli:34,carena:[1,37],carlo:11,cart2polar:33,cart_to_pol:21,cartesian:[3,18,21,23,33],cartshapelet:18,cast:27,catalog:0,catalogu:[3,4,27,33,34,38],caus:2,caustic:[3,15,24],caustic_area:15,caustic_color:24,cburkgamma:18,cburkpot:18,ccd:33,ccd_gain:[31,32,33],ccordin:23,ccw:33,cd:[2,5,18],cdf:11,cdot:21,cell:15,cent:37,center1_i:18,center1_x:18,center2_i:18,center2_x:18,center:[7,10,11,12,14,15,18,20,23,24,25,28,31,33,34],center_dec:[11,24,33],center_deflector:18,center_i:[7,15,17,18,20,23,24,33],center_kernel:33,center_ra:[11,24,33],center_spp_i:18,center_spp_x:18,center_x:[7,15,17,18,20,23,24,27,33],center_x_init:7,center_x_si:18,center_x_spp:18,center_xcenter_i:18,center_y_init:7,center_y_si:18,center_y_spp:18,central:[9,18,20,37],centroid:[13,18,19,33],cern:18,certain:[5,7,18,34],cfg:2,ch:18,chain:[24,27,34,37],chain_list:24,chain_plot:[6,36],chameleon:[3,6,15,22],chang:[2,3,10,15,18,27,33,34],change_lens_lower_limit:34,change_lens_upper_limit:34,change_source_lower_limit:34,change_source_upper_limit:34,channel:5,character:[0,18,37],characterist:[9,18],check:[0,2,4,11,12,13,17,18,20,25,27,28,33,34],check_additional_imag:28,check_bound:27,check_convent:17,check_df:11,check_image_posit:25,check_matched_source_posit:[27,28],check_positive_flux:[12,13,25,27,28],check_solv:[20,27],checkout:2,chi2:[12,19],chi:19,chi_squar:19,child:18,chill:37,choic:[7,31,34],choos:[2,29],choose_pool:29,chop:33,chose:18,chosen:[11,18,20,31,34],chunksiz:29,ciotti:11,circl:33,circular:[7,15,18,33],circumv:37,citat:0,cite:[4,37],class_creat:[3,6,34,36],classic:18,classmethod:25,clean:34,cleaner:3,clear:2,click:2,clone:[2,5],close:11,closest:20,cloud:4,clump1:18,clump:[4,18,37],cluster:[0,5,37],cmake:5,cmap:24,cmap_conf:24,cmap_str:24,cnfw:[6,15],cnfw_ellips:[6,15],cnfwgamma:18,co:[17,18,33,37],co_moving2angl:17,co_moving2angle_sourc:17,coadd_year:32,coalesc:37,code:[18,34,37],codebas:2,codeguid:2,coeff:[18,23],coeffici:[3,12,13,20,22,23,27],coin:[9,17],coincid:24,cold:37,colin:11,collabor:[2,37],color:[4,24,38],color_bar:24,colorbar_label:24,com:[1,2,4,5,14,18,29,32,37,38],com_i:18,com_x:18,combin:[18,23,27,31,34,37],combine_psf:34,come:[0,5,10,22,34],command:[2,5,24],commit:2,commun:[4,35],comov:9,compact:[0,15,37],companion:37,compar:[2,33],compare_dist:33,comparison:37,compat:[2,3,4,7,21,31,37,38],compens:23,compil:5,complet:[2,4,34,37],complex:[18,21,23,33,37],complex_bool:23,complianc:2,compon:[7,12,13,15,17,18,23,24,25,27,31,33,34,37],composit:37,compound:37,comprehens:37,comput:[2,5,7,9,10,11,12,13,14,15,16,17,18,19,20,23,24,25,26,27,28,30,33,34,37],compute_band:34,compute_bool:13,compute_index:14,compute_lower_upper_error:33,compute_mod:14,compute_pixel:14,compute_window:15,computelikelihood:34,comsohamm:27,concentr:[9,18,31,37],concept:[4,37],concern:18,concret:18,conda:[3,4],condit:[11,32],conduct:[0,20,37],cone:17,cone_inst:16,conf:[5,6,36],config:[3,5],config_load:[6,36],configur:[3,5,7,8,9,18,24,29,31,32,33,34,37],confirm:2,conflict:2,conform:31,conjunct:0,connect:[15,18,24],connect_end:33,conserv:11,consid:[7,14,20,24,27,33,34],consist:[3,7,14,18],const_mag:[6,15],constant:[0,4,6,9,11,12,18,23,36],constant_shift:[6,15],constmag:18,constrain:[12,20],constraint:[7,11,13,20,27,34,37],constraint_lensmodel:20,construct:[11,18,21,23,33,34],constructor:34,contain:[2,7,9,11,12,18,23,27,28,32,33],contamin:34,content:[36,37],continu:37,continuum:37,contrast:20,contribut:[10,15,17,18,29,34,37],contributor:4,conv_pixel:14,conv_supersample_pixel:14,conveni:27,convent:[3,7,8,11,15,17,18,22,23,24,25,27,33,34],conventions_conf:8,converg:[3,6,7,9,11,15,16,19,23,24,37],convergence_integr:[6,36],convergence_peak:7,convergence_plot:24,convers:18,convert:[9,11,18,21,31,33,34],convert_bool_list:33,convert_param:18,convolut:[3,4,6,10,11,12,15,33,37,38],convolution2d:14,convolution_class:14,convolution_kernel_s:14,convolution_typ:14,convolv:[11,12,14,24],convolve2d:14,coord2image_pixel:23,coord:[11,15,18,21,24,33],coord_center_dec:24,coord_center_ra:24,coord_invers:24,coord_transform:[6,14,36],coordian:18,coordin:[3,4,7,10,11,12,13,14,15,17,18,19,21,23,24,25,26,27,33,34,38],coordinate_arrow:24,coordinate_frame_definit:15,coordinate_grid:10,coordinates1d:[10,14],coordinates_evalu:14,coordinimag:33,copi:[2,14,21,30,33],copy_transpos:14,core:[0,3,4,9,15,18,23,31,34],coreburkalpha:18,coreburkert:[6,15],cored_dens:[6,15],cored_density_2:[6,15],cored_density_exp:[6,15],cored_density_mst:[6,15],coreddens:18,coreddensity2:18,coreddensityexp:18,coreddensitymst:18,coresers:23,corner:[2,24,33],correct:[5,7,12,18,26,28,33],correl:[6,36,37],correlation_2d:33,correspond:[0,7,11,12,13,14,15,17,18,19,22,24,25,31,33],cosmic:[4,37,38],cosmo2angular_diameter_dist:9,cosmo:[3,6,7,15,16,17,18,31,33,36,37],cosmo_add_fix:34,cosmo_fiduci:7,cosmo_interp:[15,17],cosmo_remove_fix:34,cosmo_solv:[6,36],cosmograph:[7,9,37],cosmographi:[0,3,4,37,38],cosmohamm:[3,19],cosmolog:[3,7,9,11,12,15,16,18,27,28,31,33],cost:11,could:2,count:[10,31,33,34],count_unit:31,counter:18,counterpart:15,coupl:18,cov_param:[12,13,24],covari:[10,12,13,18,24],cover:[7,37],cp:33,cps2magnitud:33,cps_pixel:33,cpu:[29,34],creat:[2,18,19,27,31,33,34],create_class_inst:[33,34],create_im_sim:33,create_image_model:33,creation:9,credit:[4,18,20],crit:[9,18],criteria:[19,20,33],criterion:34,critic:[9,11,15,18,24],critical_curve_caust:15,critical_curve_til:15,cross:15,ctnfwgaussdec:18,ctx:34,cube2args_gaussian:33,cube2args_uniform:33,cube2arrai:33,cube:[30,33,34],curl:15,current:[4,11,12,15,18,19,25,31,34],curv:[3,15,18,24,37],curvatur:[15,18,24],curved_arc:[15,24,37],curved_arc_const:[6,15],curved_arc_estim:15,curved_arc_finite_area:15,curved_arc_illustr:24,curved_arc_sis_mst:[6,15],curved_arc_spp:[6,15],curved_arc_spt:[6,15],curved_arc_tan_diff:[6,15],curvedarcconst:18,curvedarcconstmst:18,curvedarcsismst:18,curvedarcspp:18,curvedarcspt:18,curvedarctandiff:18,cusp:23,cuspi:33,custom:18,custom_class:18,custom_logl_addit:27,customclass:18,cut:[20,33,34],cut_edg:33,cut_psf:33,cut_scal:23,cutout:[33,34],cutout_psf:34,cutout_psf_singl:34,cutout_s:34,cutout_sourc:33,cylind:18,cyril:1,d:[10,11,12,15,18,24,32,33],d_:[9,11],d_alpha_dr:18,d_d:[7,9,11],d_d_sampl:9,d_delta_t:9,d_delta_t_sampl:9,d_dt:[7,9],d_fermat_model:7,d_ij:15,d_len:18,d_ol:18,d_parsec:33,d_phi:18,d_phi_di:33,d_phi_dx:33,d_phi_dxi:33,d_phi_dxx:33,d_phi_dyi:33,d_prior:12,d_r:18,d_r_dx:33,d_r_dxx:33,d_r_dxy:33,d_r_dy:33,d_r_dyi:33,d_x_diffr_di:33,d_x_diffr_dx:33,d_xy:9,d_y_diffr_di:33,d_y_diffr_dx:33,dai:[7,9,15,17,31,33],dalpha:18,dalpha_i:18,dalpha_x:18,dan:29,dangilman:1,daniel:1,dark:[4,9],dartoon:1,data:[0,3,4,6,7,9,11,12,13,14,24,27,28,29,31,33,34,36,37,38],data_api:[6,36],data_class:[12,31],data_configure_simpl:33,data_count_unit:31,data_plot:24,data_respons:[12,13],data_typ:31,data_util:[6,36],dataapi:31,dataset:[0,37],dc2:37,dd:[7,9,15],ddt2h0:9,ddt:[9,33],ddt_dd_from_time_delay_and_kinemat:7,ddt_from_time_delai:7,ddt_sampl:27,de:[1,6,7,11,18,24,31,33,34,37],de_len:[6,36],de_lens:12,de_projection_3d:33,de_shift_kernel:33,deal:[11,12,14,26],dec:[7,10,11,14,15,18,20,23,24,33],dec_0:[15,18,33],dec_arrai:25,dec_at_xy_0:[10,14,33],dec_coord:33,dec_grid:33,dec_imag:[24,26,34],dec_image_list:28,dec_po:[7,14,20,25],dec_shift:10,dec_sourc:[24,26],decent:20,decid:18,declar:28,decompos:[18,23,37],decomposit:[4,7,18,23,24,38],decomposition_plot:24,deconvolut:[4,38],decoupl:[13,20],dedic:[11,33],deep:[0,37],deeplenstronomi:[0,37],deepzipp:37,defin:[3,5,10,11,13,15,18,23,24,25,26,31,33,34],definit:[3,4,7,9,10,13,15,17,18,22,24,25,27,29,31,33,34,38],deflect:[7,12,15,16,17,18,19,24,31,33],deflection_from_kappa_grid:15,deflection_from_kappa_grid_adapt:15,deflection_kernel:15,deflection_plot:24,deflection_scaling_list:22,deflector:[7,9,11,12,15,17,18,19,24,28,33],deg:34,degeneraci:[7,37],degrad:[15,33],degrade_kernel:33,degrading_factor:33,delai:[0,3,4,7,9,15,17,27,28,31,33,37,38],delay_arcsec2dai:33,delay_arcsec:33,delet:[11,12,13,15,18,23,25,33],delete_anisotropy_cach:11,delete_cach:[11,23],delete_lens_model_cach:25,delta:33,delta_i:28,delta_phi:33,delta_pix:[15,24],delta_x:28,delta_x_imag:12,delta_y_imag:12,deltapix:[7,10,23,24,33],deltapix_in:33,deltapix_out:33,deltapix_sourc:24,demagnifi:20,demand:20,densiti:[0,3,9,11,15,18,23,33,37],density_2d:[15,18],density_len:18,depend:[2,3,4,5,7,9,11,18,20,27,29,31,33,34],deprec:33,depth:[12,27,33,37],deriv:[7,15,18,24,25,33,37],derivative_util:[6,36],desc:[0,37],describ:[2,4,7,10,11,16,18,31,33,34,37],descript:[2,3,7,11,15,16,31,33,37],design:[0,3,4,16,37,38],desir:5,desniti:18,det:[15,24],detail:[7,11,25,26,27,33,34,37],detect:37,detector:[33,37],determin:[9,12],dev:[2,33],develop:[0,2,4,5,35,37],deviat:[18,28,33,34],df:18,dhanasingham:37,dhawan:37,diagnost:24,diagon:[12,13,24],diamet:[7,9,11],diaz:37,dict:[18,32,33],dict_arg:33,dictionari:[18,19,34],diego2018:18,diego:18,diff:[15,17,18],diff_method:15,differ:[2,3,5,7,12,13,14,15,16,18,19,20,23,24,25,27,29,33,34],differenti:[3,7,12,15,17,18,24,33],differential_scal:24,digit:[24,32,33],dill:29,dim:[18,23,33],dimens:[7,10,15,23,27,33],dimension:[0,9,11,14,18,20,23,33,34,37],dimensionless:[7,9,18,23],dimenst:18,diment:23,ding:[1,37],dipol:[6,15],dipoleutil:18,direct:[7,10,11,15,17,18,23,24,33],directli:[4,11,26,27,30,38],disci:37,disconnect:[15,24],discourag:2,discret:33,discy:37,disk:[18,37],dispers:[7,9,11,31],dispersion_map:11,displac:[7,11,20,28,33],displace_psf:11,displace_psf_gaussian:11,displace_psf_moffat:11,displaceab:33,displai:24,dist:[24,33],dist_mcmc:24,distanc:[3,7,9,11,15,17,18,20,23,25,27,28,33,34],distinct:15,distort:[18,24,33,37],distribut:[0,4,5,7,9,11,12,18,23,33,37],diverg:[2,11,23],divid:[7,18],dn:[31,33],do_interp:18,doc:[2,11,30,32,33],docguid:2,docstr:2,document:[0,2,3,4,13,18,19,20,27,31,33,34],doe:[2,5,7,14,18,20,25,27,34],dolphin:[0,37],dominiqu:1,don:[4,15],done:[7,10,11,18,24,34],dot:21,doubl:[4,15,18,23,34,37,38],double_gaussian:15,doublechameleon:[18,23],doublechameleonpointmass:18,doubli:37,down:37,downhil:[19,34],dpi:18,dr:[15,18,33],dr_dxx:33,dr_dxy:33,dr_dyi:33,dr_dyx:33,dr_slit:7,draw:[9,11,24],draw_cdf_i:11,draw_hernquist:11,draw_light:11,draw_light_2d:11,draw_light_2d_linear:11,draw_light_3d:11,draw_moffat_r:11,draw_xi:11,drawn:23,driven:37,drop:18,ds:[7,9,11,15],ds_dd:9,ds_dds_from_kinemat:7,dt:9,dt_geo:17,dt_measur:7,dt_shapiro:17,dtan_dtab:18,dtan_dtan:[18,24],dtype:18,dual:[18,37],due:[29,31],duffi:9,duplic:[0,17,25],dure:[20,25,28,34],dust:12,dutton:23,dvorkin:37,dx:[15,18,33],dxdx:[18,33],dxdy:[15,18,33],dxx:18,dxy:18,dy:[15,18,33],dydi:[18,33],dydx:18,dye:37,dyi:18,dynam:[15,30,34],dynamic_go:30,dynamicnestedsampl:30,dynesti:[30,34],dynesty_bound:34,dynesty_sampl:[6,27,34],dynestysampl:30,dypolychord:[30,34],dypolychord_dynamic_go:34,dypolychord_seed_incr:34,dypolychordsampl:30,dyx:18,dz:18,e11:[18,23],e12:[18,23],e13:[18,23],e1:[7,18,20,23,33],e21:[18,23],e22:[18,23],e23:[18,23],e2:[7,18,20,23,33],e:[2,4,5,7,9,10,11,12,13,18,20,22,23,24,27,29,30,31,33,34,38],each:[2,4,7,10,11,12,13,14,15,17,18,19,23,25,27,29,31,33,34,38],earli:37,earlier:[7,15,17],easier:20,east:33,eccentr:[7,18,23,33],ecosystem:37,edg:[11,33],edit:32,edu:18,ef:37,effect:[7,9,10,11,14,15,18,23,24,27,33,34,37],effective_einstein_radiu:7,effective_num_data_point:27,effici:18,eigenvalu:[12,15],eigenvector:[3,15,24],eight:37,einstein:[3,4,7,9,11,18,20,23,31,37,38],either:[7,18,23,25,33],electron:[32,33],electrons2adu:33,element:[5,12,13,18,23,24,29,33],eliasdottir:18,ell_to_pol:21,ellips:[15,18,20,23],ellipsoid:[3,6,18,22],ellipt:[3,5,7,15,18,21,23,33,37],elliptical_density_slic:[6,15],ellipticity2phi_q:33,ellislic:18,els:[7,14,18,27],elsewher:[14,33],email:[4,35],emce:[3,24,27,33,34],empti:18,en:[2,21,33],enabl:[2,12,15,29,31,33],enclos:[9,11,15,18],encount:[4,35],end:[15,17,18,27,33,34,37],energi:[9,37],enforc:34,engin:[27,37],enough:11,enter:[9,18],entir:23,entri:[7,13,25],environ:[2,5,37],ep:18,epl:[3,5,6,15,19,20],epl_numba:[6,15],epl_util:[6,15],eplmajoraxi:18,epsilon:[9,18],epsilon_crit:[11,15],eq:18,eqn:[11,15],equal:[12,18],equat:[3,4,7,9,11,18,20,21,24,25,26,33,37,38],equation19:11,equatori:37,equip:7,equiv:[18,23],equival:[7,18,29,31,33],eras:2,erickson:1,erosita:37,erro:34,error:[3,4,10,12,13,14,24,27,28,29,31,33,34,35,37],error_map:[12,24,34],error_map_estim:34,error_map_estimate_new:34,error_map_list:13,error_map_radiu:34,error_map_sourc:[12,13],error_map_source_plot:24,error_model:33,error_respons:[12,13],estim:[7,10,12,13,14,15,27,31,33,34],estimate_amp:33,estimate_nois:31,et:[3,4,7,11,15,18,23,37],etc:[7,11,24,27,34],eucledian:25,euclid:[6,31],euclidean:[20,27],ev:9,evalu:[7,12,13,14,15,18,23,28,33],even:[31,33],event:37,everi:[12,19,37],evid:[30,34],evolut:[4,9],evolv:34,ewoud:1,ewoudwemp:1,exact:[15,18,20],examl:[4,38],exampl:[0,2,3,18,24,27,31,34],exce:[25,26],except:[19,25,31,34],exclud:[11,33],exclus:3,execut:[0,15,17,18,19,20,27,29,34],exist:[0,2,7,15,18,27,34],exp:[12,18,23],exp_tim:[10,33],expand:33,expans:[4,7,9,11,14,18,33,37],expect:[11,14,33],experiment:18,explicit:[14,29],explor:37,expon:[9,11,18,23],exponenti:[3,18,23],exposur:[10,13,31,33,34],exposure_map:10,exposure_tim:[10,31,33],express:18,exptim:[31,33],ext:18,extend:[10,12,15,22,29,31,33,34,37],extens:[4,15,38],extent:15,extern:[7,9,12,13,15,18,19],extinct:[3,12,24,27,28,33,34],extinction_class:12,extinction_map:12,extra:29,extract:[0,4,25,27,37,38],extrem:4,f1:18,f2:18,f:[9,11,18,21,23,24,30],f_:18,f_interp:18,f_x:[17,18],f_x_interp:18,f_xx:[15,17,18],f_xx_interp:18,f_xxx:15,f_xxy:15,f_xy:[15,17,18],f_xy_interp:18,f_xyi:15,f_y:[17,18],f_y_interp:18,f_yi:[15,17,18],f_yx:[15,17,18],f_yy_interp:18,f_yyi:15,facilit:3,factor:[3,7,9,10,14,15,18,23,28,33,34],faddeeva:18,fairbairn:37,fals:[7,9,10,11,12,13,14,15,17,18,19,20,23,24,25,26,27,28,29,30,33,34],far:33,fast:[3,37],fast_caust:24,fastel:[4,18],fastell4pi:[5,18],faster:[3,11,15,18,23,24],fastmath:33,featur:[2,3,4,16,18,34,35,38],fed:20,feel:[2,4,18,27],felix:1,fermat:[7,9,15,20,33],fermat_pot:9,fermat_potenti:[7,15],feroz:30,fetch:2,few:[2,5,18],fft:[3,14,15],fft_static:14,fiduci:7,field:[11,18,24,37],figueroa:37,file:[2,3,5,8,18,27,29,31,33,34],file_containing_your_contribut:2,filipp:1,fill:2,filter:[0,37],find:[4,7,15,18,20,27,33,34,37,38],findbrightimag:20,finder:20,findoverlap:33,finit:[11,15,24],first:[2,3,7,15,17,18,19,20,22,23,25,27,28,31,33],fit:[0,3,4,9,12,13,19,20,24,27,33,34,37,38],fit_sequ:34,fitting_list:34,fitting_sequ:[6,36],fittingsequ:[3,24,34],fix:[3,7,9,11,12,15,18,19,20,22,25,31,34],fix_image_paramet:34,fix_not_comput:34,fix_psf_error_map:14,fixed_aperture_s:15,fixed_kwarg:34,fixed_magnif:26,fixed_magnification_list:[25,33],flag:17,flake8:2,flat:[9,12,17,18],flatlambdacdm:18,flexibl:3,flexion:[6,15],flexionfg:[6,15],flip:24,flipped_x:24,flow:4,flux:[4,7,11,12,13,14,15,18,23,24,31,33,37,38],flux_arrai:14,flux_array2image_low_high:14,flux_compon:7,flux_evaluate_index:14,flux_from_point_source_list:[25,33],flux_iid:31,flux_nois:[31,33],flux_per_second:31,flux_r:33,flux_ratio_likelihood:27,fly:34,fm:18,fold:[11,28,37],folder:34,follow:[2,5,7,11,17,18,19,27,29,37],font:24,font_siz:24,forc:2,force_no_add_imag:[27,28],forecast:37,foreground:19,foreground_rai:19,foreman:29,forg:[3,4],fork:[2,29],form:[7,12,15,18,21,22,27],formal:37,format:[4,5,12,18,24,27,34],formul:37,formula:[18,23],fortran:[5,18],forward:37,found:[2,4,7,28],four:29,fourier:[18,33],fr:9,frac:[7,18,23],fraction:[26,33],fraction_list:14,fractional_step_s:33,frame:[10,11,24,28,33,34],frame_select:11,framework:[0,3,18,37],free:[4,9,15,19,22,27,34,37],free_band:34,freedom:18,frenk:37,frequenc:33,from:[0,2,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,23,24,25,27,29,30,31,32,33,34,37,38],front:19,frontier:37,fulfil:[20,25],full:[0,10,11,12,13,14,20,23,24,31,33,37],fulli:37,func:[18,29],functino:11,function_split:23,further:[4,7],fusshoel:1,futur:37,fwhm2sigma:33,fwhm:[10,11,14,15,24,33],fwhm_kernel:33,fwhmgaussianconvolut:14,g1:[15,18],g2:[15,18],g3:18,g4:18,g:[2,4,5,7,9,10,11,12,13,15,18,22,23,24,27,29,31,32,33,34,38],g_:18,gain:33,galact:37,galan:[1,29,37],galaxi:[0,4,7,19,38],galfit:[4,38],galight:[0,37],galkin:[3,6,7,36,37],galkin_model:[6,36],galkin_set:7,galkinmodel:11,galkinobserv:11,gam:18,gamma1:[15,18,33],gamma2:[15,18,33],gamma:[7,15,18,23,33],gamma_1:18,gamma_2:18,gamma_:18,gamma_ext:18,gamma_funct:18,gauss:18,gauss_decompos:18,gauss_decomposit:[6,15],gaussdecompositionabstract3d:18,gaussdecompositionabstract:18,gaussian:[6,7,10,11,14,15,18,22,24,28,31,32,33,34,37],gaussian_ellips:23,gaussian_ellipse_kappa:[6,15],gaussian_ellipse_potenti:[6,15],gaussian_kappa:[6,15],gaussian_potenti:[6,15],gaussianellips:23,gaussianellipsekappa:18,gaussianellipsekappaset:18,gaussianellipsepotenti:18,gaussiankappa:18,gener:[0,2,3,4,10,11,16,18,20,31,32,37,38],generalizedom:11,generated_jit:33,geo_shapiro_delai:17,geometr:[17,33],geometri:15,geomlinspac:21,geomspac:21,get:[2,5,9,12,17,18,20,21,34],get_arg:34,get_ax:33,get_cosmo:9,get_dist:33,get_distance_from_cent:18,get_kappa_1d:18,get_param:[15,22,25,27],get_param_wl:12,get_precis:7,get_scal:18,getparam:27,gfortran:5,giga:37,gilman:[1,37],gird:23,gist_heat:24,git:[2,5],github:[4,5,14,29,30,37,38],giulia:[1,20],give:[2,4,7,18,33,37],given:[7,9,10,11,12,13,14,15,16,17,18,19,20,22,23,24,27,28,29,30,31,33,34],glenn:18,global:[3,18],glose:18,gmail:[1,4],go:[2,7,24],goal:[14,34],goe:[17,18,33],gomer:1,good:[18,33,34],googl:[4,32,35],gpu:37,gradient:[20,33],gradient_boost_factor:10,gradient_map:33,grav_pot:[15,18],grav_potenti:11,gravit:[0,11,17,18,33],gravitation:37,greater:33,green:[2,15],grid2d:33,grid:[3,6,7,10,11,12,15,16,18,20,23,24,33,34],grid_class:14,grid_from_coordinate_transform:33,grid_interp_i:18,grid_interp_x:18,grid_num:7,grid_numb:15,grid_points_spac:14,grid_radius_arcsec:15,grid_resolut:15,grid_scal:15,grid_spac:[7,15,16],grid_spacing_list:16,grid_supersampling_factor:14,grism:37,ground:37,group:[2,4,35],gu:37,guarante:34,guess:[12,27,34],guid:[2,4,38],guidelin:4,h0:[0,9,18,37],h0_rang:9,h0licow:37,h0rton:0,h:[9,18],h_0:9,h_:18,h_n:[18,23],ha:[2,4,11,14,18,27,29,33,37],hack:2,half:[3,7,10,11,18,23,24,31,33],half_light_radiu:[7,33],halo:[9,18,37],hand:[2,3],handl:[0,3,4,10,11,12,14,15,18,19,22,27,29,31,37,38],handlei:30,hannuksela:37,happi:37,hard:28,hard_bound_rm:28,harvard:18,have:[0,2,4,5,11,13,15,18,19,20,21,24,25,27,28,31,33,38],hdf5:27,head:2,heavili:[18,20],held:[12,25],help:[2,33,34],henc:[15,21],here:[0,4,5,18,19,23,37],hermit:[18,23],hermval:23,hernquist:[3,6,7,11,15,22],hernquist_approx:7,hernquist_ellips:[6,15],hernquistellips:23,hesit:4,hessian:[3,6,15,17,20,28],hessian_diff:15,hessian_eigenvector:15,hession:3,hidden:4,hide:[4,38],hierarc:0,hierarch:[0,37],hierarchi:27,high:[11,14,15,18,19,33,37],high_res_kernel_s:15,high_res_return:14,higher:[14,33],highest:33,highli:[15,18],highlight:37,higson:30,histori:[4,9],hobson:30,hoffimann:29,hole:[11,33,37],hook:16,hopefulli:34,horizon:37,host:[4,20,38],how:[5,28,31,33,34,37],howev:12,hpc:5,hsc:37,hst:[4,6,31,37],html:[2,11,30],http:[2,4,5,9,11,14,18,21,23,29,30,32,33,34,37,38],hu:37,hubbl:[0,4,9],hundr:37,hyp_2f1:11,hyper2f2_arrai:33,hyper:37,hyperbol:18,hypercub:[30,33,34],hypergeomet:11,hypergeometr:11,i:[4,9,11,12,13,15,17,18,20,22,23,25,27,29,33,34,37],i_0:23,i_1:27,i_b:23,i_len:27,i_lens_light:27,i_light:27,i_model:34,i_point_sourc:27,i_sourc:27,i_xi:33,i_xy_input:33,ia:37,ideal:2,ident:[18,26,27,33],identif:37,identifi:[18,37],idex_mask:33,idex_sourc:12,ifu:[3,7,11],ifushel:11,ignor:[7,10,18,19,25,26,33,34],ignore_observed_posit:17,ii:[23,37],iid:31,iii:37,illustr:[3,24,37],im:[11,18],imag:[0,3,4,7,10,12,13,14,15,17,18,19,20,23,24,25,26,27,28,31,33,34,37,38],image2arrai:33,image2array_mask:12,image2sourc:12,image2source_map:[6,36],image2source_plan:[27,34],image2sourcemap:12,image_amplitud:[25,26],image_bkg:31,image_color_list:24,image_data:[10,33],image_flux_joint:12,image_flux_split:12,image_from_parti:14,image_high_r:14,image_i:20,image_index:34,image_interp:23,image_likelihood:[6,27],image_likelihood_mask:33,image_likelihood_mask_list:[24,27,28,33],image_linear_solv:[6,13,36],image_list:[33,34],image_low_r:14,image_model:[6,13,36],image_model_class:[31,33,34],image_model_list:13,image_nam:[24,33],image_name_list:[24,33],image_nois:10,image_orient:24,image_pixelbased_solv:12,image_plan:27,image_plane_source_list:27,image_posit:[25,26],image_position_analyt:20,image_position_from_sourc:20,image_position_lenstronomi:20,image_position_likelihood:[27,28],image_position_plot:24,image_position_stochast:20,image_position_uncertainti:[27,28],image_reconstruct:24,image_single_point_sourc:34,image_tim:31,image_util:[6,36],image_x:20,imagedata:[10,31,33],imagelikelihood:28,imagelinearfit:[12,13,33],imagemodel:[12,27,31,34],imagenois:10,imaginari:[18,23],imaging_data:[6,36],imcoord:33,img:33,impact:[11,37],implement:[3,4,11,15,16,18,19,21,24,29,33,37],impos:[18,34],improv:[0,3,15,16,37],imput:14,imsim:[2,6,24,34,36],imsim_class:27,in2p3:9,inaccur:23,inaccuraci:[14,33],includ:[2,3,7,9,10,12,13,17,20,27,28,33,34,37],include_z_start:17,incomplet:[0,4],incomplete_gamma_funct:18,incorpor:18,increas:[15,20],increment:[15,34],inde:18,independ:[7,13,22,27],index2poli:23,index:[5,11,12,14,15,18,22,23,24,25,27,33,34],index_arrai:14,index_lens_light_model_list:[13,33],index_lens_model_list:[13,33],index_optical_depth_model_list:[13,33],index_point_source_model_list:[13,33],index_sourc:12,index_source_light_model_list:[13,33],index_vertic:15,indic:[7,15,18,20,33],indici:19,individu:[10,13,15,23,24,34],induc:37,infer:[0,4,25,27,33,34,37],infin:[11,18],influenc:18,info:33,inform:[2,4,7,20,25,28,33,34,38],infrar:[0,37],infti:11,inherit:[12,24,31,34],init:[9,20,24],init_kwarg:34,init_lens_light_model:12,init_po:27,init_sampl:34,initarg:29,initi:[10,12,15,18,19,20,23,27,28,29,33,34],initial_guess_cut:20,initialis:27,initpo:27,inlin:33,inner:[3,11,23,24],innermost:11,input:[7,9,10,13,15,18,23,24,31,33,34],input_valu:33,inputarrai:24,insid:[15,18,33],inspir:[2,14,37],instal:[2,3],instanc:[7,9,12,15,16,17,18,19,24,25,26,27,28,31,33,34],instead:[25,26],instruct:4,instrument:[0,31,32,33],instrument_nam:31,insuffici:7,int_0:18,int_r:11,integ:[7,12,13,14,15,19,23,27,28,33,34],integr:[3,7,11,15,16,18,22,23,37],intend:19,intens:[23,33],interact:[4,37],interest:[18,31],interfac:24,interlop:37,intern:[26,34],interp:9,interpol:[3,6,7,9,11,15,16,22,33],interpol_grid_num:11,interpol_inst:16,interpol_sc:[16,33],interpolsc:18,interpret:[11,18,37],intrins:[18,24,25,26,31,37],introduc:[11,18,23],introduct:[4,18],intuit:18,inv_bool:[12,13],invari:[7,23,34],invers:[0,9,12,13,15,18,24,25,27,33,37],invert:[12,13,24,34],invertcosmo:9,investig:37,invok:29,involv:27,io:[30,34],iptf16geu:37,is_mast:29,is_not_empti:18,is_work:29,isol:34,isotherm:[7,18,23],isotrop:11,issu:2,iter:[3,18,19,20,21,23,27,29,33,34],its:[4,5,7,17,18,27,33,37],itself:29,iv:37,ix:37,j0408:37,j0717:37,j08:9,j1206:37,j1721:37,j:[7,30],jaff:23,jakeret:1,jam:7,jame:37,jammy2211:14,jean:[7,11],jell:1,jelleaalb:1,jerri:1,ji:1,jit:[5,33],jiwoncpark:[1,37],joel:1,johannesbuchn:30,join:[4,13,27,35],joint:[12,13,20,24,27,33,37],joint_extinction_with_lens_light:27,joint_lens_light_with_lens_light:27,joint_lens_light_with_point_sourc:27,joint_lens_with_len:27,joint_lens_with_light:27,joint_lens_with_source_light:27,joint_linear:[6,12],joint_source_with_point_sourc:27,joint_source_with_sourc:27,jointli:33,jointlinear:13,joss:[3,4,37],jupyt:[4,38],just:[5,12,15,18],k:[11,12,15,17,18,24,25,29,33],k_2:27,k_beta:11,k_bn:18,k_eff:18,k_extinct:27,k_len:27,k_lens_light:27,k_re:18,k_sourc:27,kappa2proj_mass:9,kappa:[7,9,15,18,24],kappa_0:[9,18],kappa_:7,kappa_d:7,kappa_ext:[7,9,15,18],kappa_high_r:15,kappa_r:18,kde1d:33,kde:9,kde_likelihood:[6,36],kde_typ:9,kdelikelihood:9,keck:37,keep:[0,18,19,31,34],keep_error_map:34,keep_psf_error_map:34,keeton:18,kei:[4,19,27,33],kept:[19,20],kernel:[10,12,14,15,18,24,33,34],kernel_average_pixel:33,kernel_differ:14,kernel_gaussian:33,kernel_guess:34,kernel_high_r:33,kernel_init:34,kernel_list_new:34,kernel_norm:33,kernel_numpix:33,kernel_old:34,kernel_pixel:10,kernel_pixelsize_chang:33,kernel_point_sourc:[10,31],kernel_point_source_init:10,kernel_point_source_supersampl:10,kernel_s:34,kernel_sup:[14,33],kernel_supersampl:14,kernel_util:[6,36],kernels:33,kev:37,kevin:1,keyboardinterrupt:29,keyerror:[18,20,33],keyword:[7,8,10,11,12,13,15,16,17,18,19,20,22,24,25,26,27,28,31,33,34],kfir:18,kg:[11,15],khachatryan:37,kinemat:[3,7,11,37],kinematic_lens_profil:7,kinematic_light_profil:7,kinematics_api:[6,36],kinematics_modeling_set:7,kinematicsapi:[3,7],km:[7,9,11,31],kneib:18,know:[0,4,14,35,37],knowledg:[4,7,31,34],known:[15,18,37],kochanek:[7,18],kuhn:[1,37],kwarg:[3,11,12,13,14,15,17,18,19,20,24,26,27,28,29,30,32,34],kwargs2arg:27,kwargs_anisotropi:[7,11],kwargs_apertur:[7,11],kwargs_caustic_num:15,kwargs_constraint:34,kwargs_contour:24,kwargs_cosmo:[11,28],kwargs_data:[31,33,34],kwargs_data_joint:[27,34],kwargs_extinct:[12,13,27,28,34],kwargs_fix:[15,22,25,27,34],kwargs_fixed___:34,kwargs_fixed_extinct:27,kwargs_fixed_len:[20,27],kwargs_fixed_lens_light:27,kwargs_fixed_lens_list:20,kwargs_fixed_p:27,kwargs_fixed_sourc:27,kwargs_fixed_speci:27,kwargs_flux_comput:27,kwargs_interp:[9,15,16,17,33],kwargs_kin_api:7,kwargs_len:[7,12,13,15,17,19,20,24,25,26,27,28,31,33,34],kwargs_lens_eqn_solv:[25,26,33],kwargs_lens_init:[19,20,27],kwargs_lens_light:[7,12,13,27,28,33,34],kwargs_lens_light_mag:31,kwargs_light:[7,11],kwargs_likelihood:34,kwargs_list:[11,15,19,20,22,25,33],kwargs_logsampl:15,kwargs_low:[15,22,25,27],kwargs_lower___:34,kwargs_lower_extinct:27,kwargs_lower_len:27,kwargs_lower_lens_light:27,kwargs_lower_p:27,kwargs_lower_sourc:27,kwargs_lower_speci:27,kwargs_mass:[11,31],kwargs_mg:7,kwargs_mge_light:7,kwargs_mge_mass:7,kwargs_model:[7,11,13,24,27,28,31,33,34],kwargs_numer:[11,12,31,33],kwargs_numerics_galkin:7,kwargs_p:[7,12,13,25,26,27,28,33,34],kwargs_param:[24,34],kwargs_pixelbas:[12,13,27,28,33],kwargs_profil:15,kwargs_ps_mag:31,kwargs_psf:[11,24,33,34],kwargs_psf_it:34,kwargs_psf_new:34,kwargs_psf_upd:34,kwargs_result:[27,34],kwargs_return:27,kwargs_run:[30,34],kwargs_se:7,kwargs_single_band:[31,32],kwargs_slic:18,kwargs_solv:20,kwargs_sourc:[12,13,27,28,33,34],kwargs_source_mag:31,kwargs_speci:[12,13,27,28,34],kwargs_splin:18,kwargs_to_arg:19,kwargs_upd:[15,34],kwargs_upp:[15,22,25,27],kwargs_upper___:34,kwargs_upper_extinct:27,kwargs_upper_len:27,kwargs_upper_lens_light:27,kwargs_upper_p:27,kwargs_upper_sourc:27,kwargs_upper_speci:27,l:11,label:24,lambda:29,lambda_:7,lambda_approx:18,laplacian:15,larg:[0,4,11,21],larger:[15,20,33],largest:15,lasenbi:30,last:[17,37],late:37,later:[7,15,20],latest:[2,3,4,5,38],latter:33,law:[5,7,11,18,19,21,23,37],layer:33,lcdm:[6,18,36],lead:[4,11,14,15,17,18,23,38],leaker:37,learn:[0,3,37],least:[12,13],leav:17,lectur:[4,18],left:[18,21,23,24,27,33],left_low:33,len:[0,3,4,5,7,9,11,12,13,15,16,17,18,19,20,22,23,24,25,26,27,28,31,33,34,38],lenght:33,length:[7,11,12,13,15,24,27,31,33,34,37],lens:[0,3,7,9,12,15,16,17,18,19,23,24,25,26,28,31,33,34,38],lens_add_fix:34,lens_cosmo:[6,18,36],lens_equation_solv:[6,15],lens_light:[33,34],lens_light_add:[12,24,33],lens_light_add_fix:34,lens_light_model_class:[12,31],lens_light_model_list:[7,13,31,33],lens_light_remove_fix:34,lens_model:[6,7,12,26,36],lens_model_class:[12,25,26,28,31],lens_model_extens:[6,36],lens_model_kinematics_bool:7,lens_model_list:[15,17,19,31,33],lens_model_plot:24,lens_param:[6,36],lens_plot:[6,36],lens_profil:[6,36],lens_redshift_list:[15,17,31,33],lens_redshift_sampling_index:27,lens_remove_fix:34,lens_surface_bright:12,lenscosmo:[9,18],lensed_posit:[6,7,25,28],lensedloc:17,lensedposit:26,lensequationsolv:[20,25,26,33],lensingestim:37,lensingetc:[0,37],lensinggw:[0,37],lensmodel:[2,3,6,7,9,12,23,24,25,26,28,31,36],lensmodelextens:15,lensparam:15,lensprofileanalysi:7,lensprofilebas:18,lenstronomi:[0,5,35,38],lenstronomy_extens:[4,38],lenstronomy_repo:5,lenstronomyproject:2,lenstruct:0,leq:18,less:[9,24,33],let:[0,4,35,37],letter_font_s:24,level:[10,14,20,28,31],li:37,librari:[5,18],light2mass:[6,36],light2mass_interpol:7,light:[3,4,7,9,11,12,13,15,17,18,20,22,23,27,28,31,33,34,37,38],light_2d:11,light_2d_finit:11,light_3d:[11,23],light_3d_interp:11,light_con:[6,15],light_grid:33,light_model:[6,7,36],light_model_kinematics_bool:7,light_model_list:[12,22],light_param:[6,36],light_profil:[6,36],lightcon:[3,16],lightconesim:[6,15],lightmodel:[2,6,11,28,31,36],lightmodul:11,lightparam:22,lightprofil:11,lightprofileanalysi:7,lightprofilebas:23,ligth:33,like:[0,2,4,18,20,34,38],likelihood:[3,5,6,9,10,12,13,19,24,30,33,34,36],likelihood_data_given_model:[12,13],likelihood_mask:12,likelihood_mask_list:[13,24,34],likelihood_modul:30,likelihoodmodul:[27,34],lilan:1,limit:[20,23,25,26,27,33,34],line:[2,5,7,11,15,17,18,24,37],line_set_list_i:24,line_set_list_x:24,linear:[3,9,10,11,12,13,18,20,22,23,24,25,27,28,33],linear_basi:22,linear_prior:[12,13,24,27,28],linear_response_matrix:[12,13],linear_response_set:25,linear_solv:[22,25,27],linearbasi:22,liner:[12,13],linewidth:24,link:[2,3,4,12,27,37],linspac:[21,33],list:[0,7,11,12,13,14,15,16,17,18,20,22,23,24,25,26,27,28,29,30,31,32,33,34,37],littl:9,ll:18,ln:[11,27],lnlikelihood:27,lo:[7,11,15,17,18],local:[0,2,3,7,18,20,29,33,37],local_lensing_effect:7,locat:[5,17,21,33],log10:[9,18,27,31,33],log:[9,11,12,13,19,24,28,30,33,34],log_10:18,log_:24,log_integr:11,log_likelihood:[10,27,30],log_sampling_len:27,logarithm:[7,10,11,12,13,18],logic:2,logl:[19,27,28,30,33,34],logl_aft:34,loglikelihood:9,logm:18,logz:30,logz_err:30,loka:11,look:[24,27,31],loss:14,loss_of_signific:21,lost:34,lot:[4,38],low:[7,14,19,37],low_res_factor:15,lower:[14,15,24,27,33,34,37],lower_limit:33,lower_limit_default:[18,23],lower_sigma:33,lower_start:27,lowerlimit:[27,34],lowest:33,lpha:23,lsst:[6,31,37],lsstdesc:0,luca:1,lucateo:1,lum_weight_int_method:11,luminos:[11,37],lyman:37,lyne:1,lynevdv:1,m200:[9,18,31],m:[2,9,11,12,13,18,23,30,31,33],m_2d:18,m_:18,m_beta:12,m_ev_log10:9,m_inv:12,m_log10:9,m_r200:9,m_sol:9,m_sol_log10:9,m_sun:[9,11,18],ma:1,mac:37,machin:37,mackei:29,macromodel:18,made:[2,4,11,16,37,38],madison:1,mag:15,mag_pert:26,magnif:[3,7,12,15,18,20,24,25,26,33,37],magnifi:[15,18,26],magnification_finit:15,magnification_finite_adapt:15,magnification_limit:[20,25,26],magnification_plot:24,magnificatoin:37,magnitud:[22,25,31,33],magnitude2amplitud:31,magnitude2cp:[31,33],magnitude_zero_point:[31,33],mai:[5,7,11,12,18,24,34],main:[2,4,7,9,14,15,18,19,24,38],mainli:33,maintain:0,maintin:2,major:[3,11,15,18,23,33,37],make:[0,2,4,5,7,10,12,13,15,18,20,24,27,33,34,37],make_grid:33,make_grid_transform:33,make_grid_with_coordtransform:33,make_subgrid:33,mamon:11,mamonlokasanisotropi:7,manag:[9,10,14,15,20,22,23,24,25,27,28,31,34],mangat:37,mani:[15,33],manipul:33,manual:2,map:[3,7,10,12,13,15,16,17,18,19,20,24,27,28,29,30,31,33,34,37],map_coord2pix:[10,33],map_mu_sigma_skw:33,map_pix2coord:10,margin:[12,24,37],marginalis:[12,13],marginalisation_const:12,marginalization_new:12,mark:[2,3,18],marker:24,markers:24,martin:1,mask:[10,11,12,13,14,33,34],mask_azimuth:33,mask_center_2d:33,mask_ellips:33,mask_half_moon:33,mask_point_sourc:34,mask_util:[6,36],mass:[0,3,5,7,9,11,15,16,18,19,23,33,37],mass_2d:[15,18],mass_2d_len:18,mass_3d:[11,15,18],mass_3d_len:18,mass_dim:15,mass_enclosed_2d:15,mass_enclosed_3d:15,mass_fraction_within_radiu:7,mass_in_coin:9,mass_in_theta_:9,mass_map:16,mass_map_list:16,mass_profile_list:7,mass_ratio:18,mass_scal:[27,34],mass_scaling_list:27,mass_tot:18,massei:23,massimo:18,massiv:[18,37],massmodel:11,massslic:16,master:29,mat:33,match:[7,9,12,13,15,17,18,20,24,28,33],match_kernel_s:33,math:[18,21],mathemat:18,mathrm:18,mathsf:24,matplotib:24,matplotlib:[3,24],matrix:[10,12,13,15,18,21,24,33],matrix_inv:33,matshow:24,matter:[4,9,18],mattgom:1,matthew:1,max:[23,33,34],max_draw:11,max_integr:11,max_interp_x:18,max_interpol:11,max_light_draw:11,max_num_imag:[27,28],max_ord:15,max_r_frac:23,maxim:[7,23],maximum:[7,10,11,12,15,20,21,23,24,27,31,34],maxit:21,mayor:1,mbh:37,mbox:18,mcmc:[3,24,27,34,37],mcmc_emce:27,mcoord2pix:33,md:2,me:4,mead:[27,34],mean:[7,9,15,17,18,24,26,27,30,33,34],mean_start:27,meant:[4,11,31,33,35],measur:[3,4,7,11,23,28,38],median:[33,34],meet:37,memory_rais:14,mend:29,meneghetti:18,mention:5,merg:[2,32,33,37],merge_dict:33,merger:37,merrit:11,merritt:[7,11],mesh:16,messag:2,metcalf:18,method:[2,11,15,18,23,27,29,34,37],methodolog:4,mge:[7,11,14],mge_1d:33,mge_fit:7,mge_kernel:33,mge_light:7,mge_mass:7,mgeconvolut:14,micro:31,microlens:[0,37],mid:37,middl:[11,33],might:[2,5,7,11,15,24,25,27,33,34],millon:[1,37],mimick:15,min_approx:21,min_dist:[20,25,33],min_ellipt:18,min_grid_numb:18,min_integr:11,min_interpol:11,min_square_dist:33,mini:[4,37],minim:[11,12,13,18,20,27,33,34],minima:[20,33],minimum:[2,20,21,24,25,33],minor:[3,18,23,33],mkvirtualenv:5,mock:[3,4,37,38],mode:[3,12,15,18,19,29,33],model:[0,3,4,5,7,9,10,11,12,13,14,15,16,17,18,19,20,23,24,25,26,27,28,31,33,34,38],model_api:[6,36],model_band_plot:[6,36],model_bool_list:7,model_index_select:13,model_kinematics_bool:7,model_list:[13,25],model_list_bool:7,model_nam:18,model_plot:[6,36],modelapi:31,modelband:24,modelbandplot:24,modelplot:24,modifi:[18,19,29,30,33],modul:[0,3,4,36,38],modular:[4,38],moduli:33,modulo:[9,15,17,18],modulu:[18,23],moertsel:37,moffat:[3,6,11,22],moffat_beta:11,moffat_fwhm_alpha:11,moffat_r:11,moment:[7,19,33],mont:11,more:[2,3,4,14,18,20,23,24,27,28,31,33,34],morgan:[1,37],morganti:11,moriond:9,morpholog:[4,37],most:[11,15,37],move:[5,17,24,33],mpc:[7,9,11,15,17,33],mpi4pi:29,mpi:[3,4,27,29,34],mpipool:[27,29],mpix2angl:33,mpix2coord:33,mpmath:11,mst:[7,18],mst_invariant_differenti:7,msun:9,mu:33,mu_r:18,mu_t:18,much:[4,11,15,34],mueland:1,multi:[0,3,4,7,11,12,13,14,15,16,17,19,23,24,27,29,30,33,34,37,38],multi_band_list:[13,24,28,33,34],multi_band_typ:[24,28,33],multi_data_bas:[6,12],multi_gauss_expans:[6,36],multi_gaussian:23,multi_gaussian_decomposit:7,multi_gaussian_decomposition_ellips:7,multi_gaussian_ellips:23,multi_gaussian_kappa:[6,15],multi_gaussian_len:7,multi_linear:[6,12],multi_observ:7,multi_plan:[6,15,16,33],multi_plane_bas:[6,15],multi_plane_fast:[6,15],multiband:[3,6,12,27,33],multidatabas:13,multidimension:9,multiexposur:27,multigaussian:23,multigaussianconvolut:14,multigaussianellips:23,multigaussiankappa:18,multigaussiankappaellips:18,multilinear:13,multinest:[30,34],multinest_sampl:[6,27],multinestsampl:30,multipl:[2,4,12,13,14,20,23,26,28,33,34],multiplan:[6,15],multiplane_inst:17,multiplanebas:17,multiplanefast:19,multipli:[12,15,27,28],multipol:[3,6,15,19],multipool:29,multiprocess:[6,27],multiwavelength:37,must:[15,18,19,29],muztagh:37,n1:23,n2:23,n:[11,12,13,18,21,23,25,33],n_1:33,n_23:33,n_2:33,n_3:33,n_arrai:23,n_burn:[27,34],n_comp:7,n_data:24,n_iter:[19,27,34],n_level:24,n_max:23,n_order:[18,23],n_particl:[19,27,34],n_run:[27,34],n_sersic:[18,23],n_sigma:18,n_walker:[27,34],name:[2,3,18,22,23,24,25,26,27,31,34],nan:33,nan_to_num:33,nan_to_num_arr:33,nan_to_num_singl:33,narrow:[19,37],natur:[10,12,13,37],navarro:37,nd:12,ndim:30,ndimag:33,necessarili:7,need:[2,4,5,9,11,14,15,18,25,31,33,34,38],neg:[7,12,13,15,17,18,23,27],negativelogl:27,neginf:33,neglect:18,neighbor:33,neighborselect:33,neighbour:34,nelder:[27,34],nest:[3,30,34],nested_sampl:34,nested_sampling_chain:34,nestedsampl:30,network:[0,37],neufeld:37,neural:[0,37],never:33,new_comput:11,new_procedur:34,newli:2,next:[2,12,25,34],nfw:[3,6,9,15,31],nfw_angle2phys:[9,18],nfw_ellips:[6,15],nfw_m_theta_r200:9,nfw_mass_concentr:[6,15],nfw_mz:9,nfw_param:[6,36],nfw_physical2angl:[9,18],nfw_vir_trunc:[6,15],nfwalpha:18,nfwellipsegaussdec:18,nfwgamma:18,nfwmc:18,nfwparam:[3,9],nfwparam_phys:9,nfwpot:18,nfwvirtrunc:18,nicola:1,nie:[3,6,15,22],nie_potenti:[6,15],niemajoraxi:18,niepotentialmajoraxi:18,nierenberg:[1,37],nmea:20,nmeas_extra:20,nnumber:24,no_arrow:24,no_break:34,no_nois:33,nois:[10,12,31,32,33],noise_for_model:31,noise_map:10,noisi:31,nomin:[11,17],non:[3,9,12,13,18,20,23,31,33,34],non_linear:20,none:[7,9,10,11,12,13,14,15,16,17,18,19,20,22,23,24,25,26,27,28,29,30,31,32,33,34],nopython:[14,33],nord:1,normal:[3,9,12,13,18,23,24,33,34],normalis:[18,33],normalized_residual_plot:24,northern:37,note:[2,5,19,20],notherwis:34,novel:37,now:13,np:[15,33],nparam:30,ns:12,ns_run:30,ntessor:1,nuclei:37,num:[21,27],num_averag:[15,24],num_band:13,num_basi:25,num_data:[27,28,33],num_data_evalu:[12,13],num_dim:33,num_exposur:[31,33],num_grid_points_ax:14,num_imag:[15,20,27],num_interp_x:18,num_it:[33,34],num_iter_max:20,num_kin_sampl:[7,11],num_ord:23,num_param:[15,22,23,25,27,33,34],num_param_linear:[12,13,22,25,27,28],num_parti:14,num_pix:[14,15,24,33],num_point:[7,33],num_point_source_imag:27,num_point_source_list:[25,27],num_psf_sampl:[7,11],num_random:20,num_response_list:13,num_scale_factor:27,num_seg:11,num_select:33,num_shapelet_len:[15,27],num_sigma:33,num_tau0:27,num_z_interp:[15,17],num_z_sampl:27,numba:[3,4,8,14,18,21,33],numba_conf:8,numba_convolut:[6,12],numba_util:[6,36],numbaconvolut:14,number:[2,7,10,11,12,13,14,15,18,19,20,21,22,23,24,25,27,28,29,30,31,33,34,37],numer:[3,4,6,7,10,11,12,15,16,17,18,20,21,23,25,26,31,33,37,38],numeric_kinemat:[6,36],numerical_alpha_class:[15,17,18,19],numerical_deflect:[6,15],numericalalpha:18,numerickinemat:11,numgrid:33,numimag:20,numpi:[2,9,10,12,13,14,15,17,18,23,24,25,26,27,31,33,34],numpix:[7,23,24,31,33],numselect:33,nx:[10,14,33],ny:[10,14,33],ob0:18,ob:32,object:[7,9,10,11,12,13,14,15,16,17,18,19,20,22,23,24,25,26,27,28,29,30,31,32,33,34],observ:[0,3,6,7,9,15,17,18,19,24,25,26,31,32,33,36,37],observation_api:[6,36],observation_constructor:[6,36],observation_nam:31,observationconfig:[6,31],observed2flat_convent:17,observed_convention_index:[15,17,33],occur:12,odd:[14,15,31,33,34],ode0:9,off:[2,15,34],offici:5,offset:[15,33],often:2,old:34,om0:[9,18],om:7,omega_m:[9,18],omega_m_rang:9,onc:2,one:[2,5,14,15,18,19,20,23,27,31,33,34],ones:[9,22,25,31,33,34],onli:[2,5,7,12,14,15,16,18,19,20,24,25,26,27,28,29,30,31,33,34],only_from_unspecifi:25,onto:[2,15],ood:10,open:[0,2],oper:23,optic:[0,12,27,31,32,33,37],optical_depth_model_list:33,optim:[0,6,12,13,15,21,27,34,37],optimum:15,option:[3,4,7,10,11,12,13,14,15,17,20,22,24,26,27,28,29,31,33,34,38],orbit:11,order:[7,11,12,14,15,18,19,20,23,24,25,33,34],org:[2,4,11,18,21,23,30,33],orient:[11,15,18,19,23,24,33],origin:[2,5,12,14,18,23,24,25,26,28,29,33,34],original_posit:25,original_ps_posit:7,orthonorm:23,osipkov:[7,11],osipkovmerritt:11,ostdiek:37,ot:[5,18,22,25],other:[4,10,12,13,15,18,20,27,28,31,34],otherwis:[7,10,11,12,15,24,25,27,29,33],our:18,out:[0,2,4,12,15,18,22,27,32,33,34,37],outer:[11,23,24],outermost:[11,34],outlier:34,outlin:5,output:[15,17,18,24,27,29,33,34],output_basenam:[30,34],output_dir:[30,34],outsid:[2,18,20,23,33,34],outskirt:[18,33],ovejero:0,over:[7,11,12,14,15,18,24,33,37],overal:[18,27,34],overlap:[33,34],overview:37,overwrit:[2,10,25,34],overwritten:[27,34],own:[0,2,5,34,37],p0:33,p:[10,21],p_jaff:[6,15,22],p_jaffe_ellips:[6,15],packag:[5,36,37,38],pagano:[1,20,37],page:[2,4,5,35],pai:[5,18],paint:[10,12],pair:[7,18,33,37],palta:0,panel:24,paper:[3,4,11,18,30],parabola:21,parallel:[5,14,29,33],param1:34,param2:34,param:[9,10,11,12,13,15,18,19,21,22,23,24,25,27,28,33,34],param_chi_square_penalti:19,param_class:[19,27,34],param_conv:18,param_convert:18,param_limit:27,param_list:24,param_manag:[6,15],param_mcmc:24,param_nam:[18,23,34],param_name1:[27,34],param_name2:[27,34],param_name_list:22,param_new1:27,param_old1:27,param_transform:18,param_typ:22,param_util:[6,36],paramclass:19,paramet:[0,2,3,4,6,7,9,10,11,12,13,14,15,16,17,18,19,20,22,23,24,25,26,28,29,30,31,32,33,34,36,37,38],parameter:[3,11,15,18,22,26,34,37],parameter_class:19,parameter_st:34,parameteris:[11,18,33,34],pariti:18,park:[1,37],parsec:[15,33],part:[3,5,7,11,12,15,17,18,23,24,27,28,33],partial:[3,5,7,12,14,18,33],partial_arrai:14,partial_imag:[6,12],partial_read_bool:14,partialimag:14,particl:[9,19,27,34],particle_swarm:19,particular:[5,10,11,15,18,27,31],particularli:[2,20],pass:[2,13,18,20,21,29,30,34],patch:3,path:[2,5,17],pattern:34,pc:15,pdf:[9,11,18,33],pdf_skew:33,peak:15,pemd:[3,5,6,15,37],penalti:19,pep8:2,pep:2,per:[5,7,9,10,11,12,14,15,22,23,24,25,31,33,34,37],perfect:[4,12,33],perfectli:33,perform:[0,7,10,11,12,14,15,16,18,19,24,27,33,34,37],period:18,perpendicular:18,person:2,pertub:26,perturb:[0,3,18,37],peter:29,ph:[11,18,23],phase:11,phi0:33,phi:[15,18,33],phi_:[18,23],phi_dipol:18,phi_g:[18,23],phi_m:18,phi_n:[18,23],phi_q2_ellipt:33,phi_xxi:18,phi_xxx:18,phi_xyi:18,phi_yyi:18,photon:[7,11,20,33],phy:9,phys2arcsec_len:9,physic:[7,9,11,15,18,26,33],physical2lensing_convers:31,physicalloc:17,pi:[15,18,23],pickl:29,picklabl:29,pip:[3,4,5,38],pipelin:0,pixel:[7,10,12,13,14,15,20,22,23,24,31,32,33,34],pixel_area:[10,14],pixel_grid:[10,14],pixel_kernel:[14,33,34],pixel_offset:24,pixel_s:10,pixel_scal:[14,31,32,33],pixel_unit:10,pixel_width:10,pixelgrid:[10,24],pixelis:33,pixelkernelconvolut:14,pjaff:[18,23],pjaffe_ellips:18,pjaffeellips:23,place:[3,24,28,30,33],placement:28,plane:[3,9,12,13,15,16,17,18,19,20,24,25,26,27,28,31,33,34,37],platform:[4,35],pleas:[0,4,10,27,35,37],plot:[3,6,28,36],plot_arc:24,plot_chain:24,plot_chain_list:24,plot_extinction_map:24,plot_line_set:24,plot_main:24,plot_mcmc_behaviour:24,plot_scal:24,plot_separ:24,plot_subtract_from_data_al:24,plot_util:[6,36],plu:[18,20],plug:[12,31],pm:24,point:[3,7,9,10,11,12,13,14,15,18,20,21,22,24,25,26,27,28,31,33,34,37],point_amp:[25,26,34],point_like_source_cutout:34,point_mass:[6,15],point_sourc:[3,6,12,24,36],point_source_add:[12,24,33],point_source_cach:[6,36],point_source_class:[12,28],point_source_kernel:[33,34],point_source_linear_response_set:12,point_source_list:25,point_source_magnification_limit:33,point_source_model:25,point_source_model_class:31,point_source_model_list:[31,33],point_source_offset:27,point_source_param:[6,36],point_source_posit:24,point_source_rend:[6,12],point_source_supersampling_factor:[10,14,31],point_source_tim:31,point_source_type_list:25,point_source_vari:[6,36],pointmass:18,points_on_circl:33,points_onli:24,pointsourc:[6,28,31,36],pointsourcecach:25,pointsourceparam:25,pointsourcerend:14,pointsourcevari:31,poison:33,poisson:[10,31,33],poisson_nois:31,pol_to_cart:21,pol_to_el:21,polar2cart:33,polar:[21,23,33],polar_grid:15,polarshapelet:18,poly2index:23,polychord:34,polychord_sampl:[6,27],polychord_set:[30,34],polynomi:[18,23],pool:[6,27],popul:[4,38],posinf:33,posit:[3,4,7,11,12,13,14,15,17,18,19,20,23,24,25,26,27,28,29,31,33,34,37,38],position_likelihood:[6,27],positionlikelihood:28,positon:15,possibl:[0,11,12,13,18,20,31],possit:23,post:[18,34],postag:0,posterior:[5,24,30,33,34],pot_ext:18,pot_in:18,potenti:[3,7,9,11,12,15,16,18,20,33,37],potential_from_kappa_grid:15,potential_from_kappa_grid_adapt:15,potential_kernel:15,power:[5,7,11,18,19,21,23,33,37],power_law:[6,22],power_spectrum_1d:33,power_spectrum_2d:33,powerlaw:23,powerlawfixedshear:19,powerlawfixedshearmultipol:19,powerlawfreeshear:19,powerlawfreeshearmultipol:19,powerlawparammanag:19,practic:[2,37],pre:[7,18,23,26,33],pre_calc:[18,23],precalc:23,preced:33,precis:[3,7,10,18,20,24,37],precision_limit:20,predict:[7,9,11,12,25,28,37],prefect:12,prefer:15,preferenti:[15,17],prepend:21,present:[0,4,7,9,11,18,24,37],preserv:33,previou:[2,33,34],previous:[10,25,34],primari:37,primordi:37,principl:16,print:[7,19,20,24,27,28,34],print_kei:[27,34],print_set:27,prior:[4,12,13,25,26,28,30,38],prior_extinct:[27,28],prior_extinction_kd:[27,28],prior_extinction_lognorm:[27,28],prior_len:[27,28],prior_lens_kd:[27,28],prior_lens_light:[27,28],prior_lens_light_kd:[27,28],prior_lens_light_lognorm:[27,28],prior_lens_lognorm:[27,28],prior_likelihood:[6,27],prior_mean:30,prior_p:[27,28],prior_ps_kd:[27,28],prior_ps_lognorm:[27,28],prior_sigma:30,prior_sourc:[27,28],prior_source_kd:[27,28],prior_source_lognorm:[27,28],prior_speci:[27,28],prior_special_kd:[27,28],prior_special_lognorm:[27,28],prior_typ:[30,34],priorlikelihood:28,privat:18,prob_dens:[6,36],probabl:[2,24,33],probe:37,problem:[4,7,11,27,35],procedur:[3,34,37],proceed:9,process:[2,3,18,24,27,28,29,33,34],processor:5,produc:[31,33,37],product:[3,4,10,21,23,33],profifl:18,profil:[0,3,4,5,6,7,9,11,12,13,15,19,20,22,27,31,33,37,38],profile_bas:23,profile_cent:33,profile_class:15,profile_integr:[6,36],profile_list:11,profile_list_bas:[6,17,36],profile_nam:18,profile_slop:7,profile_typ:18,profileintegr:15,profilelistbas:[15,17],program:37,progress:[27,34],project2d_random:11,project:[2,7,9,11,15,18,23,33,37,38],projected_mass:18,propag:[9,24],proper:[9,20],properli:33,properti:[4,7,9,10,11,12,13,14,18,19,22,27,28,31,34],proport:7,propos:[2,20,33],proposit:34,provid:[0,4,5,7,9,11,12,15,22,25,26,28,31,33,34,35,37],provision:32,prugniel:18,ps:[21,34,37],ps_add_fix:34,ps_remove_fix:34,psbase:26,pseudo:[18,23],psf:[3,6,7,12,14,31,33,34,36,37],psf_class:[12,31],psf_construct:3,psf_data:33,psf_error_map:[10,14,34],psf_error_map_bool_list:12,psf_estimate_individu:34,psf_fit:[6,36],psf_fwhm:7,psf_iter:34,psf_iter_factor:34,psf_iteration_compar:24,psf_kernel:[33,34],psf_kernel_list:34,psf_model:31,psf_size:33,psf_symmetri:34,psf_type:[10,11,31,32],psffit:34,psfgaussian:11,psfiter:34,psfmoffat:11,psi:18,psi_ext:18,pso:[3,19,24,27,34,37],pso_convergence_mean:19,publish:4,pull:2,punish:[12,13,28],pure:5,purpos:[0,4,5,12,13,37],push:2,put:[18,37],py:[2,5,13,18],pyautolen:14,pycqa:2,pyhalo:[0,37],pyhsic:11,pymultinest:[5,30],pypi:[3,4],pyplot:24,pypolychord:34,pytest:5,python3:3,python:[0,2,5,29,37],q2:18,q:[18,21,33],q_:18,q_fastel:18,q_xx:33,q_xy:33,q_yi:33,quad:37,quadoptim:[3,6,15],quadrat:[20,21,33],quadratur:34,quadrupl:[19,37],quadrupli:37,quadrupol:33,quadrupoli:[4,38],qualiti:4,quantif:[4,37],quantifi:[4,37],quantiti:[7,9,11,15,16,17,18,31,33,37],quartil:24,quasar:[4,34,38],querri:33,question:[4,35],quit:15,qx:18,r200:[9,18],r200_m:9,r:[1,7,11,15,18,21,23,33],r_200:[9,18],r_:[9,18,23],r_ani:[7,11],r_arrai:33,r_b:23,r_bin:11,r_c:18,r_core:18,r_e:23,r_eff:[7,11,18],r_h:7,r_in:[11,33],r_list:7,r_major:33,r_minor:33,r_out:[11,33],r_sersic:[18,23],r_slit:7,r_trunc:18,ra:[7,10,11,14,15,18,20,23,24,33],ra_0:[15,18,27,33],ra_arrai:25,ra_at_xy_0:[10,14,33],ra_coord:[10,33],ra_grid:33,ra_imag:[24,26,34],ra_image_list:28,ra_po:[7,14,20,25],ra_shift:10,ra_sourc:[24,26],rad:7,radec_at_xy_0:10,radial:[7,11,15,18,24,33],radial_lens_profil:7,radial_light_profil:7,radial_profil:33,radial_stretch:[18,24],radial_tangential_differenti:15,radial_tangential_stretch:15,radian:[18,24,33],radii:[7,11,33],radio:[18,37],radiu:[3,7,9,11,15,18,20,23,24,31,33,34],rai:[3,4,11,12,15,16,17,19,20,25,26,27,38],rais:[18,20,29,33],ramanah:37,random:[11,20,31],rang:[11,18,24,37],rare:[12,37],rate:[4,10],rather:[15,23,34],ratio12:[18,23],ratio13:[18,23],ratio:[3,4,7,15,18,23,33,34,37,38],ratio_chameleon:18,ratio_pointmass:18,ration:18,ray_shoot:[15,17],ray_shooting_fast:19,ray_shooting_parti:17,rb:23,re:[3,7,11,14,15,18,19,24,25,33,34],re_optim:19,re_optimize_scal:19,re_siz:33,re_size_arrai:33,re_size_convolv:14,re_use_sampl:34,reach:4,read:[14,15,22,27,30,32,34],read_nois:[31,32],readout:33,readout_nois:33,readthedoc:[4,30,34],real:[4,18,23,24],realis:[11,12,33],realist:[4,37,38],realiz:[11,24,31,33],reanalyz:37,reason:[11,15],rebas:2,rebin_coord_transform:33,rebin_imag:33,receiv:33,recent:[4,34,38],recip:20,recommend:[2,5,18,34],reconstruct:[0,3,12,13,24,28,34,37,38],reconstruction_all_band:24,record:18,recov:37,rectangular:[11,15,23],redesign:3,redirect:33,redshift:[9,12,15,16,17,18,27,33,37],redshift_list:[16,19],reduc:[12,16,17,18,24,27,31,33],reduced_chi2:12,reduced_residu:[12,13],redund:3,refer:[2,4,11,33],referenc:[13,31],reflect:[18,34],refregi:[18,23],regard:[2,18,29,31,33],regardless:34,regim:[23,37],region:[15,18,24],regular:[12,14,18,21],regulargrid:14,reimplement:21,reject:34,rel:[3,7,9,10,12,14,15,17,18,21,23,24,28,31,33,34],relat:[0,4,9,11,18,20,27,33],releas:[3,4,5,35],relev:[4,7,20,25,27,33],reli:29,reliabl:20,relic:37,rell:21,remain:34,remap:33,remot:2,remov:[3,11,33,34],remove_output_dir:[30,34],renan:18,render:[0,7,11,14,27,31,37],rensk:37,repeat:[25,33],replac:[3,7,9,10,12,20,29,31,33,34],report:4,repositori:[2,5,37],repres:[9,15,18,33],represent:[7,34],reproduc:[28,37],request:[2,27],requir:[2,3,4,7,11,12,13,17,18,19,20,25,26,28,29,31,33,34,37],rescal:[12,15],reset_point_source_cach:[12,13,28],residu:[12,24,34],resiz:33,resolut:[10,14,15,24,33,37],resoluton:14,resolv:2,respect:[10,18,23,28,33],respons:[12,13,14,18,23],restrict_image_numb:[27,28],result:[7,11,12,13,15,18,24,29,30,31,33,34,37],result_str:24,resume_dyn_run:30,reveal:37,review:2,rho02alpha:18,rho0:[9,18],rho0_angular:18,rho0_c:9,rho0_phys:18,rho2sigma:18,rho2theta:18,rho:18,rho_0:[9,18],rho_0_phys:18,rho_:[9,18],rho_crit:9,rhoc:9,rhoc_z:9,rhotild:18,rid:21,righrt:33,right:[2,18,21,23,24,33],ring:[4,37,38],rivero:37,rm:[7,10,18,23,24],rmorgan10:1,robert:1,robust:34,roja:37,role:[31,37],root:[20,21],rot:18,rotat:[15,18,21,23,33,34],rotateimag:33,rotatioanl:34,rotmat:21,routin:[0,3,7,15,18,19,20,24,27,28,33,34],rs:[9,18,23,31],rs_angl:[9,18],rtol:21,rtype:[18,24,34],run:[2,4,20,23,27,29,30,34],run_dypolychord:30,run_nest:30,rxj1131:37,s2:18,s2_:18,s:[7,9,10,11,14,15,18,25,26,31,33,34],s_:18,s_scale:[18,23],sai:18,same:[5,7,10,12,13,14,15,17,18,19,21,23,24,25,27,33,34],sampel:27,sampl:[3,5,6,9,10,11,14,15,18,20,22,24,25,33,34,36,37],sample_bal:33,sample_ball_trunc:33,sampler:[3,5,6,18,34,36],sampler_typ:34,samples_mcmc:24,sampling_numb:[7,11],sampling_util:[6,36],satisfi:[17,20,25,33],savari:37,save:[12,13,19,25,27,29,33,34],save_bool:25,save_cach:25,scalar:33,scale:[4,9,11,12,15,16,18,19,22,23,24,27,32,33,34],scale_bar:24,scale_factor:[12,18],scale_limit:33,scale_max:24,scale_min:24,scale_s:24,scan:37,scheme:18,schmidt:1,schramm:18,schwimmbad:[3,5,29],scienc:37,scientif:0,scikit:3,scipi:[2,3,20,21,33,34],scipy_gaussian:9,scope:29,scratch:34,script:0,sdss:37,se:18,search:[4,15,20,25],search_window:[20,25],sebastian:1,sec:[11,15],second:[9,10,11,15,17,18,20,23,27,31,33,34],section:[2,4,14,18,37],see:[2,7,11,12,13,16,18,19,20,21,23,25,26,27,30,31,32,33,34],seed:[31,34],seek:[4,38],segment:[11,37],select:[0,7,11,13,15,17,20,25,29,33,37],select_best:33,select_kwarg:13,selectbest:33,self:[7,11,15,17,18,19,25,34,37],semi:[18,23,25,31,33],send:[4,18,24,34],sengul:37,sensit:[18,37],separ:[2,11,20,24],sequenc:[3,33,34,37],seri:[3,4,37],serial:29,serialpool:29,sersic:[3,6,13,15,22,33,37],sersic_ellipse_kappa:[6,15],sersic_ellipse_potenti:[6,15],sersic_major_axi:[18,22,23,33],sersic_util:[6,15,23],sersicellips:18,sersicellipsegaussdec:18,sersicellipsekappa:18,sersicellipt:23,sersicutil:[18,23],set:[2,3,4,5,7,10,11,12,13,14,15,16,17,18,19,20,22,23,24,25,26,27,31,32,33,34,37],set_amplitud:25,set_dynam:[15,17,18],set_init_st:34,set_param:[15,22,25,27],set_param_valu:34,set_pixel_s:10,set_save_cach:25,set_stat:[15,17,18],setup:[2,5,34],seven:37,sever:[5,34],sgn:18,shajib:[1,18,37],shallow:33,shan:37,shape:[15,18,19,33,37],shapelet:[3,6,18,20,22,37,38],shapelet_basis_2d:23,shapelet_pot_cartesian:[6,15],shapelet_pot_polar:[6,15],shapelets_polar:[6,22],shapeletset:23,shapeletsetpolar:23,shapeletspolar:23,shapeletspolarexp:23,shapiro:17,shaplet:23,share:[2,13,27,32],sharp:23,sharper:33,sharpli:18,shear1:7,shear2:7,shear:[3,4,6,7,9,12,13,15,19,20,33,37,38],shear_cartesian2polar:33,shear_polar2cartesian:33,shear_strengh:19,shear_strength:19,sheargammapsi:18,shearreduc:18,sheet:[7,18,37],shell:11,shell_ifu_select:11,shell_select:11,shift:[10,18,24,33,34],shift_coordinate_system:10,shift_i:33,shift_x:33,shoot:[20,27],shot:33,should:[0,2,4,11,12,13,15,16,18,19,23,24,28,29,38],show:[29,34],shown:37,shutout:4,si:[6,9,11,15],sibirr:[1,2,4,5,37,38],side:18,sie:[3,6,15],sight:[7,11,15,17,18,37],sigma0:18,sigma2fwhm:33,sigma2rho:18,sigma:[7,10,14,15,18,23,24,28,31,33,34],sigma_0:18,sigma_:18,sigma_bkd:33,sigma_bkg:33,sigma_c:18,sigma_crit:[9,18],sigma_crit_angl:9,sigma_end_mult:18,sigma_funct:18,sigma_i:18,sigma_kwarg:34,sigma_list:[14,33],sigma_r2:11,sigma_r:11,sigma_s2:11,sigma_s2_project:11,sigma_s2_r:11,sigma_scal:[30,34],sigma_start:27,sigma_start_mult:18,sigma_v:[7,31],sigma_v_measur:7,sigma_x:18,sign:[4,7,15,17,18,21,35],signal:[0,33,37],signatur:37,signific:[5,14],sim_api:[6,36],simapi:[25,31],simien:18,similar:20,simon:[1,29],simpl:[4,18,38],simplex:[19,27,34],simplex_n_iter:19,simplifi:[2,3,14,21],simul:[0,3,4,12,13,23,27,31,38],simulate_simpl:33,simulation_util:[6,36],simulationapi:[3,6,22,36],simultan:[13,33],sin:18,sinc:29,singh:37,singl:[3,4,7,9,11,12,15,16,18,20,23,24,25,26,29,33,34,37,38],single_band_multi_model:[6,12],single_gaussian:15,single_plan:[6,36],singleband:31,singlebandmultimodel:13,singleplan:15,singular:[18,21],sinusoid:18,sis_mst2stretch:18,sis_sigma_v2theta_:9,sis_theta_e2sigma_v:9,sis_trunc:[6,15],six:[2,37],size:[7,9,10,11,12,13,14,15,18,19,20,24,25,27,33,34,37],size_scal:15,skew:33,skew_normal_distribut:33,skewgaussian:33,skitlearn:3,sklearn:3,skw:33,sky:[3,9,11,17,18,19,23,25,26,31,37],sky_bright:[31,33],skypi:[2,4,38],skypyproject:2,sl:0,slac:37,slice:[3,14,16,18],slit:[0,7,11,37],slit_select:11,slit_starlet:12,slitless:37,slitromomi:37,slitronomi:[0,3,12,33,37],slop:11,slope:[7,11,18,19,23],slow:12,slower:18,slsprinkler:[0,37],sluse:1,small:[2,14,15,18,37],smaller:[12,14,33],smerick:1,smooth:[15,18,22,23,24,33],smoothing_2nd:15,smoothing_3rd:15,smoothing_scal:24,sne:0,so:[0,10,12,13,14,18,20,27,33],sobel:33,soften:18,softwar:[2,18],solar:[9,37],soliton:[9,18],solut:[7,11,12,13,14,18,20,21,27,33],solv:[4,7,9,11,12,13,20,21,25,26,27,28,37,38],solvequadeq:21,solver2point:[6,15],solver4point:[6,15],solver:[3,6,7,11,12,13,15,25,26,27,33],solver_typ:[15,20,27],solverflatlcdm:9,some:[4,11,18,20,21,22,24,34,37],sonnenfeld:7,sort:[20,25,27,33],sort_arrival_tim:20,sort_image_index:33,sourc:[0,3,4,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,37,38],source_add:[12,24,33],source_add_fix:34,source_amp:26,source_amplitud:[25,26],source_deflection_scaling_list:33,source_fwhm_parsec:15,source_grid_offset:27,source_i:[15,19,20,31],source_light_model:15,source_light_model_list:[31,33],source_marg:[12,13,24,27,28],source_model:12,source_model_class:[12,31],source_plane_chi_squar:19,source_plot:24,source_posit:[6,25],source_position_likelihood:[27,28],source_position_plot:24,source_position_sigma:[27,28],source_position_toler:[27,28],source_redshift_list:[22,31,33],source_redshift_sampling_index:27,source_remove_fix:34,source_s:27,source_sigma:15,source_surface_bright:12,source_x:[15,19,20,31],sourcemodel:12,sourcepos_i:[20,24,33],sourcepos_x:[20,24,33],sourceposit:26,space:[7,11,14,15,21,24,30,33,34,37],spars:0,spatio:37,speagl:30,speak:37,special:[4,5,12,17,20,27,28,34],special_add_fix:34,special_param:[6,36],special_remove_fix:34,specialparam:27,specif:[0,4,5,7,11,12,13,17,18,19,23,24,25,27,29,31,33,34],specifi:[5,11,12,13,15,16,17,19,24,25,26,27,29,31,33,34],spectra:11,spectral:[7,11],spectro:11,spectrograph:[11,37],spectroscopi:37,spectrum:[33,37],speed:[4,5,14,15,16,25,33],spemd:[3,6,15],spemd_smooth:[3,18],spemp:18,spep:[6,15],sphere:[11,15,18],spheric:[7,11,15,18,23,33],spheroid:37,sphinx:2,spl:18,splcore:[6,15],split:[3,12,19,23,33],split_kernel:33,spp2stretch:18,spp:[6,15],spread:[10,12,27,34],spreadsheet:32,sprinkler:0,sqrt:[10,11,14,18,23,24,31,33],squar:[3,10,12,13,15,18,22,23,31,33,34],stabel:[11,34],stabil:[3,33],stabl:[2,3,11,23],stable_cut:23,stack:[33,34],stack_imag:33,stacking_method:34,stacking_opt:34,stamp:0,stand:[4,38],standard:[5,18,33],standardiz:37,star:[26,33,34,37],star_cutout_list:34,start:[11,15,17,20,27,29,33,34],start_from_backup:[27,34],start_scal:15,stat:30,state:[27,33,34],statement:[18,28,34],statist:[31,37],std:[32,33],steep:[3,18],stellar:[7,11,37],step:[2,11,14,17,23,24,33,34],step_siz:15,still:[18,26],stochast:20,stop:[12,17,20],store:34,straight:[7,15,17],strateg:37,strategi:[0,14,37],stream:37,strength:[18,19,33],stretch2sie_mst:18,stretch2sis_mst:18,stretch2spp:18,stretch:[7,15,18,24],stretch_scal:24,stride:37,string:[15,22,24,27,31,33,34],strong:[0,4,18,37],strongli:[0,2,37],structur:[4,17,18],studi:37,stuff:19,style:[2,24],sub:[3,7,14,18,25,33,34,37],subaru:37,subclump:[4,38],subdirectori:2,subgrid:[3,7,33,34],subgrid_kernel:33,subgrid_r:[7,33],subgridkernelconvolut:14,subhalo:37,submodul:[2,6,36],subpackag:[4,36],subsampl:[3,33],subsequ:34,subset:[7,13,14,25,31,33,34],substructur:[0,4,7,38],subtl:24,subtract:[15,18,23,24,31,34],subtract_from_data_plot:24,success:15,sudo:5,suffici:[18,34],suggest:[4,18,35],sugggest:18,sum:[7,12,13,18,23,31,33],summari:24,superclass:29,supermass:37,supernova:37,superposit:[11,12,13],supersampl:[10,14,33],supersampled_index:14,supersampling_convolut:14,supersampling_factor:[10,14,33,34],supersampling_index:14,supersampling_kernel_s:[14,33],suppli:20,support:[2,3,5,11,13,15,16,20,27,29,31,33],suppress_fastel:18,suprim:37,sure:[0,2,4,5,7,10,15,24],surfac:[0,9,10,11,12,13,14,15,18,22,23,24,27,31,33,37],surface_bright:22,surface_brightness_smooth:33,survei:37,suyu:[11,15,18,23],swagnercarena:1,swarm:[19,27,34],sy:18,sydnei:1,symmetri:[11,18,33,34],symmetry_averag:33,sympi:11,synchron:37,syntax:[3,31],system:[0,3,4,5,10,12,18,19,24,29,33,34,37,38],systemat:37,t:[4,15,18,29,31],t_ij:17,t_ij_end:17,t_ij_start:17,t_xy:9,t_z_stop:17,take:[7,18,24,34],taken:[21,29],tan_diff:15,tangenti:[15,18,24],tangential_averag:15,tangential_stretch:[18,24],task:29,tau0:33,tau0_index_list:33,tau:12,td_cosmographi:[6,36],tdcosmo:37,tdcosmographi:7,tdlmc_f160w:32,techniqu:[0,5,37],telescop:[4,37],tem:18,templat:[2,3,18],tempor:37,temporari:[11,34],tend:15,tension:37,tensor:[15,23],teodori:[1,37],term:[10,12,14,15,18,19,28,31,33,34],tessor:[1,3,18],test:[2,3,4,18,24,27,29,37],test_interpol:18,test_lensmodel:[5,18],test_profil:18,testguid:2,text:[18,24,34],text_descript:24,th:[15,21,33],than:[15,16,18,20,23,26,28,34],thei:[2,24,27,31,34],them:[0,2,11,12,29,31,34],theori:4,therefor:[15,31,33],thereof:[7,11],thermal:37,theta2rho:18,theta:[11,18,21,33],theta_:[7,9,18,23,31],theta_c:[9,18],theta_e_phi:20,theta_e_sub:18,theta_i:17,theta_x:17,thi:[0,2,4,5,7,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,31,33,34,35,37],thick:18,third:[15,18,23,33,37],thoma:1,those:[7,11,16,18,24,25,26,27,31,33,34],thread:[3,19,27,29,34],threadcount:[19,27,34],threat:27,three:[11,18,19,37],threshold:24,through:[4,5,11,15,17,18,19,21,27,28,34,37,38],thu:18,tick:24,tight:11,tile:15,time:[0,2,3,4,5,7,9,10,15,17,18,19,20,23,24,27,28,31,33,37,38],time_delai:7,time_delay2fermat_pot:9,time_delay_likelihood:[6,27],time_delay_unit:9,time_delays_measur:28,time_delays_uncertainti:28,timedelaylikelihood:28,titl:2,title_fmt:24,tnfw:[3,6,15],tnfw_ellips:3,to_vary_index:19,toba:37,todo:[18,24,28,33],togeth:[24,34],tol:15,tol_simplex_func:19,tol_sourc:19,toler:[11,15,20,21,25],too:[7,11,34],tool:[0,4,37,38],top:[2,7,24,31,37],toru:15,total:[7,9,15,18,19,23,24,30,31,33],total_flux:[18,22,23],toward:[15,37],tox:[3,5],trace:[3,4,12,15,16,17,19,20,25,26,27,38],track:15,trade:34,train:[0,37],transform:[7,10,18,25,27,33],transform_angle2pix:10,transform_e1e2_product_averag:33,transform_e1e2_square_averag:33,transform_fg:18,transform_kappa_ext:7,transform_pix2angl:[10,14],transit:[18,23],translat:[7,18,19,22,25,31],transpos:[14,28],transvers:[9,17],transverse_distance_start_stop:17,travel:[17,20],treu:37,triangl:15,triplechameleon:[18,23],troubl:[5,24],trujillo:23,trunc:18,truncat:[10,11,14,18,23,31,33,37],tupl:[15,18,21,27,29,33],turn:[7,18],twice:37,two:[0,4,7,11,12,13,14,15,18,20,21,23,27,33,37],txt:29,type:[3,6,7,11,12,15,18,20,24,25,27,29,31,33,34,37],typic:2,u2:18,u:[18,30],ueland:1,ufig:11,ui:18,uldm:[3,6,9,15],uldm_angular2phi:9,uldm_mphys2angular:9,ultra:9,ultralight:37,ultraviolet:37,un:[12,34],uncertainti:[0,3,7,12,13,19,24,28,34,37],unconvolv:[12,14,24],uncorrel:[27,31],under:[4,7,16],underneath:11,undersampl:33,unfortun:21,unhappi:37,unifi:37,uniform2unit:33,uniform:[6,10,18,22,30,33,34,37],uninstal:2,union:37,uniqu:2,unit2uniform:33,unit:[2,4,7,9,10,11,15,16,17,18,20,22,23,24,30,31,32,33,34,38],uniti:18,univers:[4,9,23,37],unlens:[6,25,31],unless:34,until:[15,34],unweight:11,up:[0,4,5,7,14,18,23,25,27,33,35,37],updat:[0,2,3,10,11,12,17,20,25,26,27,31,33,34],updata_cach:10,update_data:[10,12,34],update_fix:34,update_it:34,update_kwargs_model:27,update_lens_model:[25,26],update_lens_sc:27,update_limit:34,update_linear:25,update_linear_kwarg:12,update_manag:[6,36],update_multi_band:34,update_observ:31,update_opt:34,update_param_st:34,update_param_valu:34,update_pixel_kwarg:12,update_pixelbased_map:12,update_psf:[12,34],update_search_window:25,update_set:34,update_solv:20,update_source_redshift:17,update_st:34,updatemanag:34,upper:[27,33,34],upper_limit:33,upper_limit_default:[18,23],upper_sigma:33,upper_start:27,upperlimit:[27,34],upstream:2,us:[0,2,4,5,7,9,10,11,12,13,14,15,18,19,20,22,23,24,25,26,27,28,29,31,33,34,35,37,38],usag:[2,4,5,18],use_dil:29,use_largest_eigenvalu:15,use_mpi:30,use_pool:30,use_scipy_wofz:18,user:[2,4,5,19,20,31,34,35,38],usp:32,usual:[17,20],util:[2,6,15,36,37],v5:3,v:[18,37],v_max:24,v_min:24,v_sigma:9,valid:[11,34],valu:[7,9,10,11,12,14,15,18,19,20,21,23,24,25,26,27,29,30,31,33,34,37],value1:34,value2:34,valueerror:33,van:[1,18,37],vari:[11,19],variability_func:31,variabl:[3,11,17,18,25,27,31,37],varianc:[12,13,24,31,33,34],variat:13,variou:[0,3,4,10,11,14,33,34,38],varma:37,varsigma:18,vector:[3,12,27],veloc:[7,9,11,27,31],velocity_dispers:7,velocity_dispersion_analyt:7,velocity_dispersion_dimension_less:7,velocity_dispersion_map:7,velocity_dispersion_map_dimension_less:7,velocity_util:[6,36],ven:18,verbos:[7,19,20,27,28,34],veri:[11,18,33],verison:21,versatil:[0,37],version:[0,2,3,4,5,12,29,33,37,38],vi:32,via:[4,11,35],view:[24,37],vii:37,virial:18,virtual:[2,5],virtualenvwrapp:5,vision:37,vlbi:37,vmax:33,vmin:33,volum:[11,23],vortex:15,vs:34,vyver:[1,37],w:[24,30,33],w_:18,w_c1:[18,23],w_c2:[18,23],w_c3:[18,23],w_c:[18,23],w_f_approx:18,w_t1:[18,23],w_t2:[18,23],w_t3:[18,23],w_t:[18,23],wa:4,wagner:[1,37],wai:[0,2,24,37],wait_timeout:29,walker:[27,33,34],walkerratio:34,walkser:27,wang:37,want:[11,13,15,18,19],warm:37,warn:[2,7,12,15,34],wave:[0,4],wavelet:37,we:[2,4,5,11,18,33,37,38],weak:[23,37],webb:37,weight:[11,12,13,24,33,34],welcom:4,well:[10,11,15,22,23,28,31,33,34,37],welschen:1,wemp:1,wfc3:37,wgd:37,what:[7,24],whatev:15,when:[2,4,5,7,9,10,12,14,18,19,20,25,26,27,29,31,33,34,37],whenev:[0,37],where:[2,4,7,11,14,15,16,17,18,19,23,24,27,33,34],wheter:12,whether:[11,12,13,15,17,18,19,20,25,27,28,33],which:[5,7,9,15,18,19,20,23,25,26,27,29,33,34],white:37,whose:18,wht_list:33,wht_map:33,wide:37,widt:33,width:[10,11,12,20,23,24,31,34],width_inn:11,width_out:11,width_scal:[30,34],wiki:[21,33],wikipedia:[21,33],wild:37,william:29,willott:37,window:[7,15,19,20,23,25],window_s:15,wise:37,with_amp:[12,25],with_caust:24,with_centroid:24,with_converg:24,within:[0,7,9,11,15,18,20,23,26,29,33,34],without:[3,7,12,14,15,17,18,24,26,29,31,33,34,37],wl:12,won:1,wong:37,word:[18,19],work:[2,4,15,18,20,29,33,34],worker:29,workflow:[3,6,36],wors:34,would:[0,2,21,29],wrapper:[0,30,31,33,37],write:[0,2],written:2,www:2,x0:24,x1:[18,21,23,33],x2:[18,21,23,27,33],x3:21,x:[2,7,9,10,11,12,13,15,17,18,20,21,23,24,25,26,27,30,31,33,34],x_0:33,x_1:33,x_2:33,x_:18,x_at_radec_0:33,x_c:18,x_center:[20,25],x_coord:33,x_grid:[12,13,15,18,33,34],x_imag:[15,19,20],x_in:33,x_map:33,x_min:[20,33],x_out:33,x_po:[15,20,26,33,34],x_shift:10,x_sourc:15,x_true:33,xa:21,xb:21,xcoord:33,xdg_config_hom:5,xi:7,xiii:37,ximg:33,xref:33,xtol:[20,21],xu:18,xuheng:1,xy:[19,33],xy_at_radec_0:10,y0:[18,24],y1:[21,33],y2:[18,21,33],y3:21,y:[10,11,12,13,15,17,18,20,21,23,24,25,26,33,34,37],y_0:33,y_1:33,y_2:33,y_:18,y_at_radec_0:33,y_c:18,y_center:[20,25],y_coord:33,y_grid:[12,13,15,18,33,34],y_imag:[15,19,20],y_in:33,y_map:33,y_min:[20,33],y_out:33,y_po:[15,20,26,33,34],y_shift:10,y_sourc:15,y_true:33,yaml:[5,8,33],yang:[1,37],ycoord:33,year:37,yellow:24,yet:24,yimg:33,ylilan:1,you:[0,2,4,5,11,13,15,18,19,24,27,31,33,34,35,37,38],your:[0,2,5,7,10,11,27,37],yref:33,z:[9,11,17,18,37],z_:9,z_d:9,z_end:17,z_interp_stop:[15,17],z_len:[7,9,15,18,19,31,33],z_observ:9,z_sourc:[7,9,15,16,17,18,19,31,33],z_source_convent:[15,17,31,33],z_start:17,z_stop:17,zaghloul:18,zero:[11,14,18,22,23,31,33,34],zeropoint:[31,33],zhang:37,zhiyuan:1,zhu:37,zoom:15,zoom_sourc:15,ztf:3},titles:["Affiliated packages","Credits","Contributing to lenstronomy","History","lenstronomy - gravitational lensing software package","Installation","lenstronomy package","lenstronomy.Analysis package","lenstronomy.Conf package","lenstronomy.Cosmo package","lenstronomy.Data package","lenstronomy.GalKin package","lenstronomy.ImSim package","lenstronomy.ImSim.MultiBand package","lenstronomy.ImSim.Numerics package","lenstronomy.LensModel package","lenstronomy.LensModel.LightConeSim package","lenstronomy.LensModel.MultiPlane package","lenstronomy.LensModel.Profiles package","lenstronomy.LensModel.QuadOptimizer package","lenstronomy.LensModel.Solver package","lenstronomy.LensModel.Util package","lenstronomy.LightModel package","lenstronomy.LightModel.Profiles package","lenstronomy.Plots package","lenstronomy.PointSource package","lenstronomy.PointSource.Types package","lenstronomy.Sampling package","lenstronomy.Sampling.Likelihoods package","lenstronomy.Sampling.Pool package","lenstronomy.Sampling.Samplers package","lenstronomy.SimulationAPI package","lenstronomy.SimulationAPI.ObservationConfig package","lenstronomy.Util package","lenstronomy.Workflow package","Mailing list","lenstronomy","Published work with lenstronomy","Usage"],titleterms:{"0":3,"01":3,"02":3,"03":3,"04":3,"05":3,"06":3,"07":3,"08":3,"09":3,"1":3,"10":3,"11":3,"12":3,"13":3,"15":3,"16":3,"17":3,"18":3,"19":3,"2":3,"20":3,"2018":3,"2019":3,"2020":3,"2022":3,"21":3,"22":3,"23":3,"25":3,"26":3,"27":3,"29":3,"3":3,"30":3,"31":3,"4":3,"5":3,"6":3,"7":3,"8":3,"9":3,"public":37,adaptive_numer:14,affili:[0,4],alignment_match:34,alphabet:1,analysi:7,analysis_util:33,analytic_kinemat:11,anisotropi:11,apertur:11,aperture_typ:11,arc_perturb:18,attribut:4,automat:37,background:9,base_nested_sampl:30,base_p:26,base_profil:18,chain_plot:24,chameleon:[18,23],channel:4,check:5,class_creat:33,cnfw:18,cnfw_ellips:18,code:2,conda:5,conf:8,config_load:8,const_mag:18,constant:[33,37],constant_shift:18,content:[4,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34],contribut:[2,4],contributor:1,converg:18,convergence_integr:15,convolut:14,coord_transform:10,core:37,coreburkert:18,cored_dens:18,cored_density_2:18,cored_density_exp:18,cored_density_mst:18,correl:33,cosmo:[9,11],cosmo_solv:9,credit:1,curved_arc_const:18,curved_arc_sis_mst:18,curved_arc_spp:18,curved_arc_spt:18,curved_arc_tan_diff:18,dark:37,data:10,data_api:31,data_util:33,de:32,de_len:12,decomposit:37,demonstr:4,derivative_util:33,develop:1,dipol:18,dynesty_sampl:30,ellipsoid:23,elliptical_density_slic:18,epl:18,epl_numba:18,epl_util:21,euclid:32,evolut:37,exampl:[4,38],fastel:5,feedback:4,fitting_sequ:34,flexion:18,flexionfg:18,forg:5,format:37,from:5,galaxi:37,galkin:11,galkin_model:11,gauss_decomposit:18,gaussian:23,gaussian_ellipse_kappa:18,gaussian_ellipse_potenti:18,gaussian_kappa:18,gaussian_potenti:18,get:[4,38],github:2,gravit:[4,37],grid:14,guidelin:[0,2],hernquist:[18,23],hernquist_ellips:18,hessian:18,histori:3,host:37,hst:32,hubbl:37,image2source_map:12,image_likelihood:28,image_linear_solv:12,image_model:12,image_util:33,imaging_data:10,imsim:[12,13,14],instal:[4,5],interpol:[18,23],joint_linear:13,kde_likelihood:9,kei:1,kernel_util:33,kinematics_api:7,larg:37,lcdm:9,lead:1,len:37,lens:[4,37],lens_cosmo:9,lens_equation_solv:20,lens_model:15,lens_model_extens:15,lens_param:15,lens_plot:24,lens_profil:7,lensed_posit:26,lensmodel:[15,16,17,18,19,20,21],lenstronomi:[2,4,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,36,37],light2mass:7,light_con:16,light_model:22,light_param:22,light_profil:[7,11],lightconesim:16,lightmodel:[22,23],likelihood:[27,28],list:[4,35],lsst:32,mail:[4,35],mask_util:33,matter:37,measur:37,methodolog:37,model:37,model_api:31,model_band_plot:24,model_plot:24,modul:[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34],moffat:23,movi:4,mpi:5,multi_data_bas:13,multi_gauss_expans:33,multi_gaussian_kappa:18,multi_linear:13,multi_plan:17,multi_plane_bas:17,multi_plane_fast:19,multiband:13,multinest_sampl:30,multiplan:17,multipol:18,multiprocess:29,nfw:18,nfw_ellips:18,nfw_mass_concentr:18,nfw_param:9,nfw_vir_trunc:18,nie:[18,23],nie_potenti:18,notebook:[4,38],numba:5,numba_convolut:14,numba_util:33,numer:14,numeric_kinemat:11,numerical_deflect:18,observ:11,observation_api:31,observation_constructor:31,observationconfig:32,optim:19,other:37,p_jaff:[18,23],p_jaffe_ellips:18,packag:[0,4,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34],paper:37,param_manag:19,param_util:33,paramet:27,partial_imag:14,pemd:18,plot:24,plot_util:24,point_mass:18,point_sourc:25,point_source_cach:25,point_source_param:25,point_source_rend:14,point_source_vari:31,pointsourc:[25,26],polychord_sampl:30,pool:29,position_likelihood:28,power_law:23,prior_likelihood:28,prob_dens:33,product:37,profil:[18,23],profile_integr:15,profile_list_bas:15,psf:[10,11],psf_fit:34,publish:37,pypi:5,quadoptim:19,quasar:37,reconstruct:4,relat:37,requir:5,run:5,sampl:[27,28,29,30],sampler:[27,30],sampling_util:33,scale:37,search:37,sersic:[18,23],sersic_ellipse_kappa:18,sersic_ellipse_potenti:18,sersic_util:18,shapelet:[4,23],shapelet_pot_cartesian:18,shapelet_pot_polar:18,shapelets_polar:23,shear:18,si:18,sie:18,sim_api:31,simul:37,simulation_util:33,simulationapi:[31,32],single_band_multi_model:13,single_plan:15,sis_trunc:18,slack:4,softwar:[4,37],solver2point:20,solver4point:20,solver:20,source_posit:26,special_param:27,spemd:18,spep:18,splcore:18,spp:18,start:[4,38],structur:37,submodul:[7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34],subpackag:[6,12,15,22,25,27,31],substructur:37,td_cosmographi:7,test:5,theori:37,time_delay_likelihood:28,tnfw:18,type:26,uldm:18,uniform:23,unlens:26,update_manag:34,usag:38,util:[21,33],velocity_util:11,wave:37,work:37,workflow:[2,34]}}) \ No newline at end of file diff --git a/docs/_build/html/usage.html b/docs/_build/html/usage.html deleted file mode 100644 index 69c4bff9c..000000000 --- a/docs/_build/html/usage.html +++ /dev/null @@ -1,154 +0,0 @@ - - - - - - - - - Usage — lenstronomy 1.10.3 documentation - - - - - - - - - - - - - - - -
-
- -
- -
-
- - - - \ No newline at end of file diff --git a/lenstronomy/LightModel/Profiles/shapelets_polar.py b/lenstronomy/LightModel/Profiles/shapelets_polar.py index 9dc8a4f8f..1482cc80c 100644 --- a/lenstronomy/LightModel/Profiles/shapelets_polar.py +++ b/lenstronomy/LightModel/Profiles/shapelets_polar.py @@ -16,6 +16,7 @@ class ShapeletsPolar(object): 2D polar Shapelets, see Massey & Refregier 2005 """ param_names = ['amp', 'beta', 'n', 'm', 'center_x', 'center_y'] + param_names_latex = {r'$I_0$', r'$\beta$', r'$n$', r'$m$', r'$x_0$', r'$y_0$'} lower_limit_default = {'amp': 0, 'beta': 0, 'n': 0, 'm': 0, 'center_x': -100, 'center_y': -100} upper_limit_default = {'amp': 100, 'beta': 100, 'n': 150, 'm': 150, 'center_x': 100, 'center_y': 100} diff --git a/lenstronomy/LightModel/Profiles/starlets.py b/lenstronomy/LightModel/Profiles/starlets.py index 8ec5af699..35dfbdf69 100644 --- a/lenstronomy/LightModel/Profiles/starlets.py +++ b/lenstronomy/LightModel/Profiles/starlets.py @@ -20,6 +20,7 @@ class SLIT_Starlets(object): Based on Starck et al. : https://ui.adsabs.harvard.edu/abs/2007ITIP...16..297S/abstract """ param_names = ['amp', 'n_scales', 'n_pixels', 'scale', 'center_x', 'center_y'] + param_names_latex = {r'$I_0$', r'$n_{\rm scales}$', r'$n_{\rm pix}$', r'scale', r'$x_0$', r'$y_0$'} lower_limit_default = {'amp': [0], 'n_scales': 2, 'n_pixels': 5, 'center_x': -1000, 'center_y': -1000, 'scale': 0.000000001} upper_limit_default = {'amp': [1e8], 'n_scales': 20, 'n_pixels': 1e10, 'center_x': 1000, 'center_y': 1000, 'scale': 10000000000} diff --git a/lenstronomy/LightModel/Profiles/uniform.py b/lenstronomy/LightModel/Profiles/uniform.py index 6cb812841..8bf8c0722 100644 --- a/lenstronomy/LightModel/Profiles/uniform.py +++ b/lenstronomy/LightModel/Profiles/uniform.py @@ -9,6 +9,7 @@ class Uniform(object): name for profile: 'UNIFORM' """ param_names = ['amp'] + param_names_latex = {r'$I_0$'} lower_limit_default = {'amp': -100} upper_limit_default = {'amp': 100} diff --git a/lenstronomy/LightModel/light_param.py b/lenstronomy/LightModel/light_param.py index 5a4f202ab..ae2f30ae5 100644 --- a/lenstronomy/LightModel/light_param.py +++ b/lenstronomy/LightModel/light_param.py @@ -143,9 +143,9 @@ def set_params(self, kwargs_list): args.append(kwargs[name]) return args - def num_param(self): + def num_param(self, latex_style=False): """ - + :param latex_style: boolena; if True, returns latex strings for plotting :return: int, list of strings with param names """ num = 0 diff --git a/lenstronomy/LightModel/linear_basis.py b/lenstronomy/LightModel/linear_basis.py index b36e2f0cf..606664cd7 100644 --- a/lenstronomy/LightModel/linear_basis.py +++ b/lenstronomy/LightModel/linear_basis.py @@ -24,7 +24,7 @@ def __init__(self, **kwargs): def param_name_list(self): """ returns the list of all parameter names - + :param latex_style: boolean; if True returns latex strings for plotting where available :return: list of list of strings (for each light model separately) """ name_list = [] @@ -32,6 +32,21 @@ def param_name_list(self): name_list.append(func.param_names) return name_list + @property + def param_name_list_latex(self): + """ + returns the list of all parameter names + :param latex_style: boolean; if True returns latex strings for plotting where available + :return: list of list of strings (for each light model separately) + """ + name_list = [] + for i, func in enumerate(self.func_list): + if hasattr(func, 'param_names_latex'): + name_list.append(func.param_names_latex) + else: + name_list.append(func.param_names) + return name_list + def functions_split(self, x, y, kwargs_list, k=None): """ split model in different components diff --git a/test/test_LightModel/test_light_model.py b/test/test_LightModel/test_light_model.py index ca9043187..fb84ade33 100644 --- a/test/test_LightModel/test_light_model.py +++ b/test/test_LightModel/test_light_model.py @@ -67,6 +67,11 @@ def test_param_name_list(self): param_name_list = self.LightModel.param_name_list assert len(self.light_model_list) == len(param_name_list) + def test_param_name_list_latex(self): + param_name_list = self.LightModel.param_name_list_latex + assert len(self.light_model_list) == len(param_name_list) + + def test_num_param_linear(self): num = self.LightModel.num_param_linear(self.kwargs, list_return=False) assert num == 19