ler.lens_galaxy_population.lens_galaxy_parameter_distribution
Module for lens galaxy parameter distributions.
This module contains the LensGalaxyParameterDistribution class which samples
lens galaxy parameters and source parameters conditioned on the source being
strongly lensed. It handles the distribution of lens parameters such as velocity
dispersion, axis ratio, rotation angle, shear, and density profile slope.
Inheritance hierarchy:
- Usage:
Basic workflow example:
>>> from ler.lens_galaxy_population import LensGalaxyParameterDistribution >>> lens = LensGalaxyParameterDistribution() >>> lensed_params = lens.sample_lens_parameters(size=1000) >>> print(lensed_params.keys())
Copyright (C) 2026 Phurailatpam Hemantakumar. Distributed under MIT License.
Module Contents
Classes
Sample lens galaxy parameters conditioned on strong lensing. |
- class ler.lens_galaxy_population.lens_galaxy_parameter_distribution.LensGalaxyParameterDistribution(npool=4, z_min=0.0, z_max=10.0, cosmology=None, event_type='BBH', 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, buffer_size=1000, **kwargs)[source]
Bases:
ler.gw_source_population.CBCSourceParameterDistribution,ler.image_properties.ImageProperties,ler.lens_galaxy_population.optical_depth.OpticalDepthSample lens galaxy parameters conditioned on strong lensing.
This class handles the distribution of lens galaxy parameters such as velocity dispersion, axis ratio, axis rotation angle, shear, and density profile slope. It samples source parameters conditioned on the source being strongly lensed using cross-section based rejection or importance sampling.
Key Features:
Samples lens parameters using EPL+shear galaxy model
Supports rejection and importance sampling based on cross-section
Computes optical depth weighted source redshift distributions
Integrates with GW source population and image property calculations
- Parameters:
- npool
int Number of processors to use for parallel sampling.
default: 4
- z_min
float Minimum redshift for source and lens populations.
default: 0.0
- z_max
float Maximum redshift for source and lens populations.
default: 10.0
- cosmology
astropy.cosmologyorNone Cosmology object for distance calculations.
default: None (uses FlatLambdaCDM with H0=70, Om0=0.3)
- event_type
str Type of compact binary coalescence event.
Options:
‘BBH’: Binary black hole
‘BNS’: Binary neutron star
‘NSBH’: Neutron star-black hole
default: ‘BBH’
- lens_type
str Type of lens galaxy model to use.
default: ‘epl_shear_galaxy’
- lens_functions
dictorNone Dictionary specifying lens-related functions.
default: None (uses defaults from OpticalDepth)
- lens_functions_params
dictorNone Parameters for lens functions.
default: None
- lens_param_samplers
dictorNone Dictionary specifying lens parameter sampling functions.
default: None (uses defaults from OpticalDepth)
- lens_param_samplers_params
dictorNone Parameters for lens parameter samplers.
default: None
- directory
str Directory for storing interpolator files.
default: ‘./interpolator_json’
- create_new_interpolator
bool If True, recreates interpolators even if files exist.
default: False
- buffer_size
int Buffer size for batch sampling of lens parameters.
default: 1000
- **kwargs
dict Additional keyword arguments passed to parent classes:
- npool
Examples
Basic usage:
>>> from ler.lens_galaxy_population import LensGalaxyParameterDistribution >>> lens = LensGalaxyParameterDistribution() >>> lensed_params = lens.sample_lens_parameters(size=1000) >>> print(lensed_params.keys())
Instance Methods
LensGalaxyParameterDistribution has the following methods:
Instance Attributes
LensGalaxyParameterDistribution has the following attributes:
Attribute
Type
Unit
Description
npoolintNumber of processors for parallel computation
z_minfloatMinimum redshift
z_maxfloatMaximum redshift
cosmoastropy.cosmologyCosmology object for calculations
strType of CBC event (BBH, BNS, NSBH)
directorystrPath to interpolator storage directory
dictDictionary of lens parameter sampler names
dictParameters for lens parameter samplers
dictDictionary of lens function names
floatNormalization constant for lensed source z pdf
- property source_redshift_sl[source]
Function to sample source redshifts conditioned on strong lensing.
- Returns:
- source_redshift_sl
ler.functions.FunctionConditioning Function for sampling source redshifts conditioned on strong lensing.
- source_redshift_sl
- property normalization_pdf_z_lensed[source]
Normalization constant for the lensed source redshift pdf.
This constant is used to normalize the probability distribution
of source redshifts conditioned on strong lensing. It is computed
by integrating the merger rate density times optical depth.
- Returns:
- normalization_pdf_z_lensed
float Normalization constant for lensed redshift distribution.
- normalization_pdf_z_lensed
- property lens_param_samplers[source]
Dictionary of lens parameter sampler function names.
- Returns:
- lens_param_samplers
dict Dictionary mapping parameter names to sampler function names.
Keys include: ‘source_redshift_sl’, ‘lens_redshift’,
‘velocity_dispersion’, ‘axis_ratio’, ‘axis_rotation_angle’,
‘external_shear’, ‘density_profile_slope’.
- lens_param_samplers
- property lens_param_samplers_params[source]
Dictionary of parameters for lens parameter samplers.
- Returns:
- lens_param_samplers_params
dict Dictionary with sampler parameters.
Each key corresponds to a sampler in lens_param_samplers.
- lens_param_samplers_params
- property lens_functions[source]
Dictionary of lens-related function names.
- Returns:
- lens_functions
dict Dictionary mapping function types to function names.
Keys include: ‘param_sampler_type’, ‘cross_section_based_sampler’,
‘optical_depth’, ‘cross_section’.
- lens_functions
- sample_lens_parameters(size=1000)[source]
Sample lens galaxy and source parameters conditioned on strong lensing.
This method samples both lens galaxy parameters (velocity dispersion, axis ratio, shear, etc.) and gravitational wave source parameters, with the source redshift distribution weighted by strong lensing optical depth.
- Parameters:
- size
int Number of lens-source parameter sets to sample.
default: 1000
- size
- Returns:
- lens_parameters
dict Dictionary containing sampled lens and source parameters.
The included parameters and their units are as follows (for default settings):
- lens_parameters
Examples
>>> from ler.lens_galaxy_population import LensGalaxyParameterDistribution >>> lens = LensGalaxyParameterDistribution() >>> params = lens.sample_lens_parameters(size=1000) >>> print(params.keys())
- sample_all_routine_epl_shear_sl(size=1000)[source]
Sample EPL+shear galaxy lens parameters with strong lensing condition.
- Parameters:
- size
int Number of lens parameters to sample.
default: 1000
- size
- Returns:
- lens_parameters
dict Dictionary of sampled lens parameters.
The included parameters and their units are as follows (for default settings):
Parameter
Units
Description
zl
redshift of the lens
zs
redshift of the source
sigma
km s^-1
velocity dispersion
q
axis ratio
theta_E
radian
Einstein radius
phi
rad
axis rotation angle. counter-clockwise from the positive x-axis (RA-like axis) to the major axis of the projected mass distribution.
gamma
density profile slope of EPL galaxy
gamma1
external shear component in the x-direction (RA-like axis)
gamma2
external shear component in the y-direction (Dec-like axis)
- lens_parameters
- strongly_lensed_source_redshift(size, get_attribute=False, **kwargs)[source]
Sample source redshifts conditioned on strong lensing.
- 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
- size
- Returns:
- redshifts
numpy.ndarray Array of source redshifts conditioned on strong lensing.
- redshifts
Examples
>>> from ler.lens_galaxy_population import LensGalaxyParameterDistribution >>> lens = LensGalaxyParameterDistribution() >>> zs = lens.strongly_lensed_source_redshift(size=1000) >>> print(f"strongly lensed source redshift: {zs.mean():.2f}")
- sample_all_routine_epl_shear_intrinsic(size=1000)[source]
Sample EPL+shear galaxy lens parameters from intrinsic distributions.
Samples lens parameters from their intrinsic distributions without applying strong lensing cross-section weighting.
- Parameters:
- size
int Number of lens parameters to sample.
default: 1000
- size
- Returns:
- lens_parameters
dict Dictionary of sampled lens parameters.
The included parameters and their units are as follows (for default settings):
Parameter
Units
Description
zl
redshift of the lens
zs
redshift of the source
sigma
km s^-1
velocity dispersion
q
axis ratio
theta_E
radian
Einstein radius
phi
rad
axis rotation angle. counter-clockwise from the positive x-axis (RA-like axis) to the major axis of the projected mass distribution.
gamma
density profile slope of EPL galaxy
gamma1
external shear component in the x-direction (RA-like axis)
gamma2
external shear component in the y-direction (Dec-like axis)
- lens_parameters