ler.lens_galaxy_population.optical_depth
Module for optical depth and lens parameter distribution calculations.
This module provides the OpticalDepth class for computing strong lensing
optical depth, cross-section, sampling velocity dispersion, axis ratio, and other lens galaxy
population parameters. It supports multiple lens models including SIS, SIE,
and EPL + external shear.
Key features:
Optical depth computation for strong gravitational lensing
Velocity dispersion sampling with multiple models
Lens redshift distribution sampling
Cross-section calculations for various lens models
Copyright (C) 2024 Hemantakumar Phurailatpam. Distributed under MIT License.
Module Contents
Classes
Class for computing optical depth and lens galaxy population parameters. |
- class ler.lens_galaxy_population.optical_depth.OpticalDepth(npool=4, z_min=0.0, z_max=10.0, cosmology=None, lens_type='epl_shear_galaxy', lens_functions=None, lens_functions_params=None, lens_param_samplers=None, lens_param_samplers_params=None, directory='./interpolator_json', create_new_interpolator=False, verbose=False)[source]
Class for computing optical depth and lens galaxy population parameters.
This class calculates strong lensing optical depth, velocity dispersion, axis ratio, and other parameters for a lens galaxy population. It supports SIS, SIE, and EPL + external shear lens models with customizable samplers and interpolators for efficient computation.
Key Features:
Multiple lens model support (SIS, SIE, EPL + shear)
Configurable velocity dispersion distributions
Cached interpolators for fast optical depth computation
Flexible parameter sampling with user-defined priors
- Parameters:
- npool
int Number of processors for multiprocessing.
default: 4
- z_min
float Minimum redshift of the lens galaxy population.
default: 0.0
- z_max
float Maximum redshift of the lens galaxy population.
default: 10.0
- cosmology
astropy.cosmologyorNone Cosmology object for distance calculations.
default: LambdaCDM(H0=70, Om0=0.3, Ode0=0.7)
- lens_type
str Type of lens galaxy model.
Options:
‘epl_shear_galaxy’: Elliptical power-law with external shear
‘sie_galaxy’: Singular isothermal ellipsoid
‘sis_galaxy’: Singular isothermal sphere
default: ‘epl_shear_galaxy’
- lens_functions
dictorNone Dictionary with lens-related functions.
default: None (uses defaults for lens_type)
- lens_functions_params
dictorNone Dictionary with parameters for lens-related functions.
default: None
- lens_param_samplers
dictorNone Dictionary of sampler functions for lens parameters.
default: None (uses defaults for lens_type)
- lens_param_samplers_params
dictorNone Dictionary with parameters for the samplers.
default: None
- directory
str Directory where interpolators are saved.
default: ‘./interpolator_json’
- create_new_interpolator
boolordict Whether to create new interpolators.
default: False
- verbose
bool If True, prints additional information.
default: False
- npool
Examples
Basic usage:
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth() >>> tau = od.optical_depth(zs=np.array([1.0, 2.0]))
Instance Methods
OpticalDepth has the following instance methods:
Instance Attributes
OpticalDepth has the following instance attributes:
Attribute
Type
Unit
Description
intNumber of processors for multiprocessing
floatMinimum redshift
floatMaximum redshift
astropy.cosmologyCosmology object
strType of lens galaxy model
strDirectory for interpolator storage
FunctionConditioningOptical depth calculator
FunctionConditioningkm/s
Velocity dispersion sampler
FunctionConditioningAxis ratio sampler
FunctionConditioningrad
Axis rotation angle sampler
FunctionConditioningLens redshift sampler
FunctionConditioningExternal shear sampler
FunctionConditioningDensity profile slope sampler
callablerad²
Cross-section calculator
dictAvailable lens parameter samplers
dictAvailable lens functions
- property lens_type[source]
Type of lens galaxy model.
- Returns:
- lens_type
str Lens type (‘epl_shear_galaxy’, ‘sie_galaxy’, or ‘sis_galaxy’).
- lens_type
- property npool[source]
Number of processors for multiprocessing.
- Returns:
- npool
int Number of parallel processors.
- npool
- property z_min[source]
Minimum redshift of the lens galaxy population.
- Returns:
- z_min
float Minimum redshift.
- z_min
- property z_max[source]
Maximum redshift of the lens galaxy population.
- Returns:
- z_max
float Maximum redshift.
- z_max
- property cosmo[source]
Cosmology object for distance calculations.
- Returns:
- cosmo
astropy.cosmology Cosmology object.
- cosmo
- property directory[source]
Directory for interpolator storage.
- Returns:
- directory
str Path to interpolator JSON files.
- directory
- property velocity_dispersion[source]
Velocity dispersion sampler object.
Returns a
FunctionConditioningobject with methods:rvs(size, zl): Sample velocity dispersion valuespdf(sigma, zl): Get probability densityfunction(sigma, zl): Get number density function
- Returns:
- velocity_dispersion
FunctionConditioning Sampler object for velocity dispersion (km/s).
- velocity_dispersion
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth() >>> sigma = od.velocity_dispersion(size=100, zl=np.ones(100)*0.5)
- property axis_ratio[source]
Axis ratio sampler object.
Returns a
FunctionConditioningobject with methods:rvs(size, sigma): Sample axis ratio valuespdf(q, sigma): Get probability densityfunction(q, sigma): Get distribution function
- Returns:
- axis_ratio
FunctionConditioning Sampler object for axis ratio.
- axis_ratio
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth() >>> q = od.axis_ratio(size=100, sigma=np.ones(100)*200.)
- property axis_rotation_angle[source]
Axis rotation angle sampler object.
Returns a
FunctionConditioningobject with methods:rvs(size): Sample axis rotation anglespdf(phi): Get probability density
- Returns:
- axis_rotation_angle
FunctionConditioning Sampler object for axis rotation angle (rad).
- axis_rotation_angle
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth() >>> phi = od.axis_rotation_angle(size=100)
- property density_profile_slope[source]
Density profile slope sampler object.
Returns a
FunctionConditioningobject with methods:rvs(size): Sample density profile slope valuespdf(gamma): Get probability density
- Returns:
- density_profile_slope
FunctionConditioning Sampler object for density profile slope.
- density_profile_slope
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth() >>> gamma = od.density_profile_slope(size=100)
- property external_shear[source]
External shear sampler object.
Returns a
FunctionConditioningobject with methods:rvs(size): Sample shear components (gamma1, gamma2)pdf(gamma1, gamma2): Get probability density
- Returns:
- external_shear
FunctionConditioning Sampler object for external shear.
- external_shear
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth() >>> gamma1, gamma2 = od.external_shear(size=100)
- property cross_section[source]
Lensing cross-section calculator.
Returns a callable that computes lensing cross-section for individual
lensing events. Input parameters depend on lens type:
EPL+shear: zs, zl, sigma, q, phi, gamma, gamma1, gamma2
SIE: zs, zl, sigma, q
SIS: zs, zl, sigma
- Returns:
- cross_section
callable Cross-section function (rad² units).
- cross_section
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth() >>> cs = od.cross_section(zs=zs, zl=zl, sigma=sigma, ...)
- property lens_redshift[source]
Lens redshift sampler object.
Returns a
FunctionConditioningobject with methods:rvs(size, zs): Sample lens redshifts given source redshiftspdf(zl, zs): Get probability densityfunction(zl, zs): Get effective lensing cross-section
- Returns:
- lens_redshift
FunctionConditioning Sampler object for lens redshift.
- lens_redshift
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth() >>> zl = od.lens_redshift(size=100, zs=np.ones(100)*2.0)
- property density_profile_slope_sl[source]
Density profile slope sampler object (strong lensing conditioned).
Returns a
FunctionConditioningobject with methods:rvs(size): Sample density profile slope valuespdf(gamma): Get probability density
- Returns:
- density_profile_slope_sl
FunctionConditioning Sampler object for density profile slope (strong lensing).
- density_profile_slope_sl
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth() >>> gamma = od.density_profile_slope_sl(size=100)
- property external_shear_sl[source]
External shear sampler object (strong lensing conditioned).
Returns a
FunctionConditioningobject with methods:rvs(size): Sample shear components (gamma1, gamma2)pdf(gamma1, gamma2): Get probability density
- Returns:
- external_shear_sl
FunctionConditioning Sampler object for external shear (strong lensing).
- external_shear_sl
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth() >>> gamma1, gamma2 = od.external_shear_sl(size=100)
- property optical_depth[source]
Strong lensing optical depth calculator.
- Returns:
- optical_depth
FunctionConditioning Function object with .function(zs) method that returns n optical depth for given source redshifts.
- optical_depth
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth() >>> tau = od.optical_depth.function(np.array([1.0, 2.0]))
- property available_lens_samplers[source]
Dictionary of available lens parameter samplers and their default parameters.
- Returns:
- available_lens_samplers
dict Dictionary with sampler names and default parameters.
- available_lens_samplers
- property available_lens_functions[source]
Dictionary of available lens functions and their default parameters.
- Returns:
- available_lens_functions
dict Dictionary with function names and default parameters.
- available_lens_functions
- lens_redshift_strongly_lensed_numerical(size=1000, zs=None, get_attribute=False, **kwargs)[source]
Sample lens redshifts conditioned on strong lensing (numerical method).
This method computes the lens redshift distribution by numerically integrating over the velocity dispersion distribution (galaxy density distribution wrt), cross-section and differential comoving volume.
- Parameters:
- size
int Number of samples to generate. n default: 1000
- zs
numpy.ndarray Source redshifts.
- get_attribute
bool If True, returns the sampler object instead of samples. n default: False
- **kwargs
dict Additional parameters.
- size
- Returns:
- zl
numpy.ndarrayorFunctionConditioning Lens redshift samples or sampler object.
- zl
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth() >>> zl = od.lens_redshift(size=100, zs=np.ones(100)*2.0)
- lens_redshift_strongly_lensed_sis_haris(size, zs, get_attribute=False, **kwargs)[source]
Sample SIS lens redshifts using Haris et al. (2018) distribution.
- Parameters:
- size
int Number of samples to generate.
- zs
numpy.ndarray Source redshifts.
- get_attribute
bool If True, returns the sampler object instead of samples.
default: False
- **kwargs
dict Additional parameters.
- size
- Returns:
- zl
numpy.ndarrayorFunctionConditioning Lens redshift samples or sampler object.
- zl
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth(lens_type='sis_galaxy') >>> zl = od.lens_redshift(size=100, zs=np.ones(100)*2.0)
- velocity_dispersion_gengamma(size, get_attribute=False, **kwargs)[source]
Sample velocity dispersion from generalized gamma distribution.
- Parameters:
- size
int Number of samples to generate.
- get_attribute
bool If True, returns the sampler object instead of samples.
default: False
- **kwargs
dict Additional parameters.
Parameter
Unit
Description
sigma_min
km/s
minimum velocity dispersion
sigma_max
km/s
maximum velocity dispersion
alpha
dimensionless
Power-law index governing the slope of the distribution at low velocities
beta
dimensionless
Exponential parameter determining the sharpness of the high-velocity cutoff
phistar
h^3 Mpc^-3
Normalization constant representing the comoving number density of galaxy
sigmastar
km/s
Characteristic velocity scale marking the “knee” transition in the VDF
- size
- Returns:
- sigma
numpy.ndarrayorFunctionConditioning Velocity dispersion samples (km/s) or sampler object.
- sigma
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth(lens_param_samplers=dict( ... velocity_dispersion="velocity_dispersion_gengamma")) >>> sigma = od.velocity_dispersion(size=100)
- velocity_dispersion_bernardi(size, get_attribute=False, **kwargs)[source]
Sample velocity dispersion from Bernardi et al. (2010) distribution.
Uses inverse transform sampling on the velocity dispersion function.
- Parameters:
- size
int Number of samples to generate.
- get_attribute
bool If True, returns the sampler object instead of samples.
default: False
- **kwargs
dict Additional parameters.
Parameter
Unit
Description
sigma_min
km/s
minimum velocity dispersion
sigma_max
km/s
maximum velocity dispersion
alpha
dimensionless
Power-law index governing the slope of the distribution at low velocities
beta
dimensionless
Exponential parameter determining the sharpness of the high-velocity cutoff
phistar
h^3 Mpc^-3
Normalization constant representing the comoving number density of galaxy
sigmastar
km/s
Characteristic velocity scale marking the “knee” transition in the VDF
- size
- Returns:
- sigma
numpy.ndarrayorFunctionConditioning Velocity dispersion samples (km/s) or sampler object.
- sigma
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth(lens_param_samplers=dict( ... velocity_dispersion="velocity_dispersion_bernardi")) >>> sigma = od.velocity_dispersion(size=100)
- velocity_dispersion_ewoud(size, zl, get_attribute=False, **kwargs)[source]
Sample redshift-dependent velocity dispersion from Wempe et al. (2022).
Uses inverse transform sampling with redshift-dependent velocity dispersion function.
- Parameters:
- size
int Number of samples to generate.
- zl
numpy.ndarray Lens redshifts.
- get_attribute
bool If True, returns the sampler object instead of samples.
default: False
- **kwargs
dict Additional parameters.
Parameter
Unit
Description
sigma_min
km/s
minimum velocity dispersion
sigma_max
km/s
maximum velocity dispersion
alpha
dimensionless
Power-law index governing the slope of the distribution at low velocities
beta
dimensionless
Exponential parameter determining the sharpness of the high-velocity cutoff
phistar
h^3 Mpc^-3
Normalization constant representing the comoving number density of galaxy
sigmastar
km/s
Characteristic velocity scale marking the “knee” transition in the VDF
- size
- Returns:
- sigma
numpy.ndarrayorFunctionConditioning Velocity dispersion samples (km/s) or sampler object.
- sigma
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth() >>> sigma = od.velocity_dispersion(size=100, zl=np.ones(100)*0.5)
- axis_ratio_rayleigh(size, sigma, get_attribute=False, **kwargs)[source]
Sample axis ratio from Rayleigh distribution conditioned on velocity dispersion.
- Parameters:
- size
int Number of samples to generate.
- sigma
numpy.ndarray Velocity dispersion of the lens galaxy (km/s).
- get_attribute
bool If True, returns the sampler object instead of samples.
default: False
- **kwargs
dict Additional parameters (q_min, q_max).
- size
- Returns:
- q
numpy.ndarrayorFunctionConditioning Axis ratio samples or sampler object.
- q
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth(lens_param_samplers=dict(axis_ratio="axis_ratio_rayleigh")) >>> q = od.axis_ratio(size=100, sigma=np.ones(100)*200.)
- axis_ratio_padilla_strauss(size=1000, get_attribute=False, **kwargs)[source]
Sample axis ratio from Padilla & Strauss (2008) distribution.
- Parameters:
- size
int Number of samples to generate.
default: 1000
- get_attribute
bool If True, returns the sampler object instead of samples.
default: False
- **kwargs
dict Additional parameters (q_min, q_max).
- size
- Returns:
- q
numpy.ndarrayorFunctionConditioning Axis ratio samples or sampler object.
- q
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth(lens_param_samplers=dict(axis_ratio="axis_ratio_padilla_strauss")) >>> q = od.axis_ratio(size=100)
- axis_rotation_angle_uniform(size, get_attribute=False, **kwargs)[source]
Sample axis rotation angle from uniform distribution.
- Parameters:
- size
int Number of samples to generate.
- get_attribute
bool If True, returns the sampler object instead of samples.
default: False
- **kwargs
dict Additional parameters (phi_min, phi_max).
- size
- Returns:
- phi
numpy.ndarrayorFunctionConditioning Axis rotation angle samples (rad) or sampler object.
- phi
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth() >>> phi = od.axis_rotation_angle(size=100)
- axis_ratio_uniform(size, get_attribute=False, **kwargs)[source]
Sample axis ratio from uniform distribution.
- Parameters:
- size
int Number of samples to generate.
- get_attribute
bool If True, returns the sampler object instead of samples.
default: False
- **kwargs
dict Additional parameters (q_min, q_max).
- size
- Returns:
- q
numpy.ndarrayorFunctionConditioning Axis ratio samples or sampler object.
- q
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth(lens_param_samplers=dict(axis_ratio="axis_ratio_uniform")) >>> q = od.axis_ratio(size=100)
- external_shear_normal(size, get_attribute=False, **kwargs)[source]
Sample external shear parameters from 2D normal distribution.
- Parameters:
- size
int Number of samples to generate.
- get_attribute
bool If True, returns the sampler object instead of samples.
default: False
- **kwargs
dict Additional parameters (mean, std).
- size
- Returns:
- shear
numpy.ndarrayorFunctionConditioning Array of shape (2, size) with gamma1, gamma2 or sampler object.
- shear
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth() >>> gamma1, gamma2 = od.external_shear(size=100)
- density_profile_slope_normal(size, get_attribute=False, **kwargs)[source]
Sample density profile slope from normal distribution.
- Parameters:
- size
int Number of samples to generate.
- get_attribute
bool If True, returns the sampler object instead of samples.
default: False
- **kwargs
dict Additional parameters (mean, std).
- size
- Returns:
- gamma
numpy.ndarrayorFunctionConditioning Density profile slope samples or sampler object.
- gamma
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth() >>> gamma = od.density_profile_slope(size=100)
- optical_depth_numerical(zs, get_attribute=False, **kwargs)[source]
Helper to compute optical depth numerically by integrating lens redshift.
- Parameters:
- zs
numpy.ndarray Source redshifts.
- get_attribute
bool If True, returns the function object instead of values. n default: False
- **kwargs
dict Additional parameters.
- zs
- Returns:
- tau
numpy.ndarrayorFunctionConditioning Optical depth values or function object.
- tau
- compute_einstein_radii(sigma, zl, zs)[source]
Function to compute the Einstein radii of the lens galaxies
- Parameters:
- sigmafloat
velocity dispersion of the lens galaxy
- zlfloat
lens redshifts
- zsfloat
source redshifts
- Returns:
- theta_Efloat
Einstein radii of the lens galaxies in radians. Multiply by
Examples
>>> from ler.lens_galaxy_population import LensGalaxyParameterDistribution >>> lens = LensGalaxyParameterDistribution() >>> sigma = 200.0 >>> zl = 0.5 >>> zs = 1.0 >>> lens.compute_einstein_radii(sigma, zl, zs)
- optical_depth_sis_analytic(zs, get_attribute=False, **kwargs)[source]
Function to compute the strong lensing optical depth (SIS). LambdaCDM(H0=70, Om0=0.3, Ode0=0.7) was used to derive the following equation. This is the analytic version of optical depth from z=0 to z=zs.
- Parameters:
- zs
numpy.ndarray Source redshifts.
- get_attribute
bool If True, returns the function object instead of values. n default: False
- **kwargs
dict Additional parameters.
- zs
- Returns:
- tau
numpy.ndarrayorFunctionConditioning Optical depth values or function object.
- tau
- cross_section_sis(zs=None, zl=None, sigma=None, get_attribute=False, **kwargs)[source]
Function to compute the SIS cross-section
- Parameters:
- sigmafloat
velocity dispersion of the lens galaxy
- zlfloat
redshift of the lens galaxy
- zsfloat
redshift of the source galaxy
- Returns:
- cross_sectionfloat
SIS cross-section
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth() >>> print(self.cross_section_sis(sigma=200., zl=0.5, zs=1.0))
- cross_section_sie_feixu(zs=None, zl=None, sigma=None, q=None, get_attribute=False, **kwargs)[source]
Function to compute the SIE cross-section from Fei Xu et al. (2021)
- Parameters:
- sigmafloat
velocity dispersion of the lens galaxy
- zlfloat
redshift of the lens galaxy
- zsfloat
redshift of the source galaxy
- Returns:
- cross_sectionfloat
SIE cross-section
Examples
>>> from ler.lens_galaxy_population import OpticalDepth >>> od = OpticalDepth() >>> print(self.cross_section_sie_feixu(sigma=200., zl=0.5, zs=1.0, q=1.0))
- cross_section_epl_shear_numerical(zs, zl, sigma, q, phi, gamma, gamma1, gamma2)[source]
Function to compute the strong lensing cross-section numerically for EPL + external shear lenses.
- Parameters:
- zsnumpy.ndarray
redshift of the source galaxies
- zlnumpy.ndarray
redshift of the lens galaxies
- sigmanumpy.ndarray
velocity dispersion of the lens galaxies
- qnumpy.ndarray
axis ratios of the lens galaxies
- phinumpy.ndarray
axis rotation angles of the lens galaxies in radians
- gammanumpy.ndarray
external shear magnitudes of the lens galaxies
- gamma1numpy.ndarray
external shear component 1 of the lens galaxies
- gamma2numpy.ndarray
external shear component 2 of the lens galaxies
- Returns:
- cross_sectionnumpy.ndarray
strong lensing cross-section of the lens galaxies in square radians
- cross_section_epl_shear_numerical_mp(theta_E, gamma, gamma1, gamma2, q=None, phi=None, e1=None, e2=None, verbose=False, **kwargs)[source]
Function to compute the strong lensing cross-section numerically for EPL + external shear lenses.
- Parameters:
- theta_Enumpy.ndarray
Einstein radii of the lens galaxies in radians
- gammanumpy.ndarray
external shear magnitudes of the lens galaxies
- gamma1numpy.ndarray
external shear component 1 of the lens galaxies
- gamma2numpy.ndarray
external shear component 2 of the lens galaxies
- qnumpy.ndarray
axis ratios of the lens galaxies
- phinumpy.ndarray
axis rotation angles of the lens galaxies in radians
- e1numpy.ndarray
ellipticity component 1 of the lens galaxies
- e2numpy.ndarray
ellipticity component 2 of the lens galaxies
- Returns:
- cross_sectionnumpy.ndarray
strong lensing cross-section of the lens galaxies in square radians