ler.image_properties
Submodules
Package Contents
Classes
Class to compute image properties of strongly lensed gravitational wave events. |
Functions
|
Solve the lens equation to find image properties. |
|
Convert position angle and axis ratio to ellipticity components. |
|
Solve the lens equation to find image properties. |
Attributes
- ler.image_properties.solve_lens_equation(lens_parameters)[source]
Solve the lens equation to find image properties.
Uses the analytical solver from lenstronomy to find image positions, magnifications, time delays, and hessian properties for strongly lensed sources. Source positions are sampled from within the caustic region to ensure multiple imaging.
- Parameters:
- lens_parameters
numpy.ndarray Array of lens configuration parameters with the following structure:
[0]: n_min_images - minimum number of images required
[1]: e1 - ellipticity component 1
[2]: e2 - ellipticity component 2
[3]: gamma - power-law slope of mass density
[4]: gamma1 - external shear component 1
[5]: gamma2 - external shear component 2
[6]: zl - lens redshift
[7]: zs - source redshift
[8]: einstein_radius - Einstein radius (units: radians)
[9]: iteration - iteration index for tracking
[10:]: lens_model_list - lens model names (e.g., ‘EPL_NUMBA’, ‘SHEAR’)
- lens_parameters
- Returns:
- x_source
float Source x-position (units: radians).
- y_source
float Source y-position (units: radians).
- x0_image_position
numpy.ndarray Image x-positions (units: radians).
- x1_image_position
numpy.ndarray Image y-positions (units: radians).
- magnifications
numpy.ndarray Magnification factors for each image.
- time_delays
numpy.ndarray Time delays for each image (units: seconds).
- nImages
int Number of images formed.
- determinant
numpy.ndarray Determinant of the lensing Jacobian for each image.
- trace
numpy.ndarray Trace of the lensing Jacobian for each image.
- iteration
int Iteration index passed through for tracking.
- x_source
Examples
>>> from ler.image_properties.multiprocessing_routine import solve_lens_equation >>> import numpy as np >>> from multiprocessing import Pool >>> lens_parameters1 = np.array([2, 0.024, -0.016, 1.89, 0.10, 0.09, 0.25, 0.94, 2.5e-06, 0, 'EPL_NUMBA', 'SHEAR'], dtype=object) >>> lens_parameters2 = np.array([2, -0.040, -0.014, 2.00, 0.08, -0.01, 1.09, 2.55, 1.0e-06, 1, 'EPL_NUMBA', 'SHEAR'], dtype=object) >>> input_arguments = np.vstack((lens_parameters1, lens_parameters2)) >>> with Pool(2) as p: ... result = p.map(solve_lens_equation, input_arguments) >>> print(f"Number of images: {result[0][6]}")
- ler.image_properties.phi_q2_ellipticity(phi, q)[source]
Convert position angle and axis ratio to ellipticity components.
- Parameters:
- phi
numpy.ndarray Position angle of the major axis (radians).
- q
numpy.ndarray Axis ratio (0 < q <= 1).
- phi
- Returns:
- e1
numpy.ndarray First ellipticity component.
- e2
numpy.ndarray Second ellipticity component.
- e1
- class ler.image_properties.ImageProperties(npool=4, n_min_images=2, n_max_images=4, lens_model_list=['EPL_NUMBA', 'SHEAR'], cosmology=None, time_window=365 * 24 * 3600 * 2, spin_zero=True, spin_precession=False, pdet_finder=None, effective_params_in_output=True)[source]
Class to compute image properties of strongly lensed gravitational wave events.
This class solves the lens equation to find image positions, magnifications, time delays, and image types (morse phase) for strongly lensed sources. It uses multiprocessing for efficient computation of large samples.
Key Features:
Solves lens equations using multiprocessing for efficiency
Computes image positions, magnifications, and time delays
Classifies image types using morse phase
Calculates detection probabilities for lensed images
- Parameters:
- npool
int Number of processes for multiprocessing.
default: 4
- n_min_images
int Minimum number of images required for a valid lensing event.
default: 2
- n_max_images
int Maximum number of images to consider per event.
default: 4
- time_window
float Time window for lensed events from min(geocent_time) (units: seconds).
default: 365*24*3600*2 (2 years)
- effective_params_in_output
bool Whether to include effective parameters (effective_phase, effective_ra, effective_dec) in the output.
default: True
- lens_model_list
list List of lens models to use.
default: [‘EPL_NUMBA’, ‘SHEAR’]
- cosmology
astropy.cosmologyorNone Cosmology for distance calculations.
If None, uses default LambdaCDM.
default: LambdaCDM(H0=70, Om0=0.3, Ode0=0.7, Tcmb0=0.0, Neff=3.04, m_nu=None, Ob0=0.0)
- spin_zero
bool If True, spin parameters are set to zero (no spin sampling).
default: False
- spin_precession
bool If True (and spin_zero=False), sample precessing spin parameters.
If False (and spin_zero=False), sample aligned/anti-aligned spins.
default: False
- npool
Examples
Basic usage:
>>> from ler.image_properties import ImageProperties >>> ip = ImageProperties() >>> lens_parameters = dict( ... zs=np.array([2.0]), ... zl=np.array([0.5]), ... gamma1=np.array([0.0]), ... gamma2=np.array([0.0]), ... phi=np.array([0.0]), ... q=np.array([0.8]), ... gamma=np.array([2.0]), ... theta_E=np.array([1.0]) ... ) >>> result = ip.image_properties(lens_parameters) >>> print(result.keys())
Instance Methods
ImageProperties has the following methods:
Method
Description
Compute image properties for lensed events
Compute detection probability for lensed images
Instance Attributes
ImageProperties has the following attributes:
Attribute
Type
Unit
Description
intNumber of multiprocessing workers
intMinimum number of images required
intMaximum number of images per event
floats
Time window for lensed events
boolTo include effective parameters in output
listList of lens models
astropy.cosmologyCosmology for calculations
boolFlag for zero spin assumption
boolFlag for spin precession
callableProbability of detection calculator
listKeys for probability of detection outputs
- property npool
Number of multiprocessing workers.
- Returns:
- npool
int Number of processes for multiprocessing.
default: 4
- npool
- property n_min_images
Minimum number of images required for a valid lensing event.
- Returns:
- n_min_images
int Minimum number of images required.
default: 2
- n_min_images
- property n_max_images
Maximum number of images per event.
- Returns:
- n_max_images
int Maximum number of images to consider per event.
default: 4
- n_max_images
- property lens_model_list
List of lens models to use.
- Returns:
- lens_model_list
list List of lens model names.
default: [‘EPL_NUMBA’, ‘SHEAR’]
- lens_model_list
- property spin_zero
Flag for zero spin assumption.
- Returns:
- spin_zero
bool Whether to assume zero spin for compact objects.
If True, spin parameters are set to zero (no spin sampling).
If False, spin parameters are sampled.
default: False
- spin_zero
- property spin_precession
Flag for spin precession.
- Returns:
- spin_precession
bool Whether to include spin precession effects.
If True (and spin_zero=False), sample precessing spin parameters.
If False (and spin_zero=False), sample aligned/anti-aligned spins.
default: False
- spin_precession
- property time_window
Time window for lensed events.
- Returns:
- time_window
float Time window for lensed events (units: s).
default: 365*24*3600*20 (20 years)
- time_window
- property cosmo
Astropy cosmology object for calculations.
- Returns:
- cosmo
astropy.cosmology Cosmology used for distance calculations.
default: LambdaCDM(H0=70, Om0=0.3, Ode0=0.7, Tcmb0=0.0, Neff=3.04, m_nu=None, Ob0=0.0)
- cosmo
- property pdet_finder
Detection probability finder function.
- Returns:
- pdet_finder
callable Function that calculates detection probability for GW events.
The function signature should be:
pdet_finder(gw_param_dict) -> dictwith key ‘pdet_net’.
- pdet_finder
- property pdet_finder_output_keys
Output keys from the detection probability finder function.
- Returns:
- pdet_finder_output_keys
list List of keys returned by the pdet_finder function.
default: None
- pdet_finder_output_keys
- property effective_params_in_output
Flag to include effective parameters in output.
- Returns:
- effective_params_in_output
bool Whether to include effective parameters in the output of get_lensed_snrs.
default: False
- effective_params_in_output
- image_properties(lens_parameters)[source]
Compute image properties for strongly lensed events.
Solves the lens equation using multiprocessing to find image positions, magnifications, time delays, and image types for each lensing event.
- Parameters:
- lens_parameters
dict Dictionary containing lens and source parameters shown in the table:
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
- Returns:
- lens_parameters
dict Updated dictionary with additional image properties with the following description:
x0_image_positions
radian
x-coordinate (RA-like axis) of the images
x1_image_positions
radian
y-coordinate (Dec-like axis) of the images
magnifications
magnifications
time_delays
time delays
image_type
image type
n_images
number of images
x_source
radian
x-coordinate (RA-like axis) of the source
y_source
radian
y-coordinate (Dec-like axis) of the source
- lens_parameters
- get_lensed_snrs(lensed_param, pdet_finder=None, effective_params_in_output=False)[source]
Compute detection probability for each lensed image.
Calculates the effective luminosity distance, geocent time, and phase for each image accounting for magnification and morse phase, then computes detection probabilities using the provided calculator.
- Parameters:
- lensed_param
dict Dictionary containing lensed source and image parameters given below:
- pdet_finder
callable Function that computes detection probability given GW parameters.
- effective_params_in_output
bool If True, includes effective parameters in output lensed_param.
- lensed_param
- Returns:
- result_dict
dict Dictionary containing:
‘pdet_net’: network detection probability (shape: size x n_max_images)
Individual detector probabilities if pdet_finder outputs them
- lensed_param
dict Updated dictionary with effective parameters shown below:
+----------------------------------+-----------+------------------------------------------------| | Parameter | Units | Description +==================================+===========+================================================+ | effective_luminosity_distance | Mpc | magnification-corrected distance | | | | luminosity_distance / sqrt(|magnifications_i|) | +----------------------------------+-----------+------------------------------------------------| | effective_geocent_time | s | time-delay-corrected GPS time | | | | geocent_time + time_delays_i | +----------------------------------+-----------+------------------------------------------------| | effective_phase | rad | morse-phase-corrected phase | | | | phi - morse_phase_i | +----------------------------------+-----------+------------------------------------------------+ | effective_ra | rad | RA of the image | | | | ra + (x0_image_positions_i - x_source)/cos(dec)| +----------------------------------+-----------+------------------------------------------------+ | effective_dec | rad | Dec of the image | | | | dec + (x1_image_positions_i - y_source) | +----------------------------------+-----------+------------------------------------------------+
- result_dict
- produce_effective_params(lensed_param)[source]
Produce effective parameters for each lensed image.
Calculates the effective luminosity distance, geocent time, phase, RA, and Dec for each image accounting for magnification and morse phase.
- Parameters:
- lensed_param
dict Dictionary containing lensed source and image parameters.
- lensed_param
- Returns:
- lensed_param
dict Updated dictionary with effective parameters shown below:
+----------------------------------+-----------+------------------------------------------------| | Parameter | Units | Description +==================================+===========+================================================+ | effective_luminosity_distance | Mpc | magnification-corrected distance | | | | luminosity_distance / sqrt(|magnifications_i|) | +----------------------------------+-----------+------------------------------------------------| | effective_geocent_time | s | time-delay-corrected GPS time | | | | geocent_time + time_delays_i | +----------------------------------+-----------+------------------------------------------------| | effective_phase | rad | morse-phase-corrected phase | | | | phi - morse_phase_i | +----------------------------------+-----------+------------------------------------------------+ | effective_ra | rad | RA of the image | | | | ra + (x0_image_positions_i - x_source)/cos(dec)| +----------------------------------+-----------+------------------------------------------------+ | effective_dec | rad | Dec of the image | | | | dec + (x1_image_positions_i - y_source) | +----------------------------------+-----------+------------------------------------------------+
- lensed_param
- ler.image_properties.solve_lens_equation(lens_parameters)[source]
Solve the lens equation to find image properties.
Uses the analytical solver from lenstronomy to find image positions, magnifications, time delays, and hessian properties for strongly lensed sources. Source positions are sampled from within the caustic region to ensure multiple imaging.
- Parameters:
- lens_parameters
numpy.ndarray Array of lens configuration parameters with the following structure:
[0]: n_min_images - minimum number of images required
[1]: e1 - ellipticity component 1
[2]: e2 - ellipticity component 2
[3]: gamma - power-law slope of mass density
[4]: gamma1 - external shear component 1
[5]: gamma2 - external shear component 2
[6]: zl - lens redshift
[7]: zs - source redshift
[8]: einstein_radius - Einstein radius (units: radians)
[9]: iteration - iteration index for tracking
[10:]: lens_model_list - lens model names (e.g., ‘EPL_NUMBA’, ‘SHEAR’)
- lens_parameters
- Returns:
- x_source
float Source x-position (units: radians).
- y_source
float Source y-position (units: radians).
- x0_image_position
numpy.ndarray Image x-positions (units: radians).
- x1_image_position
numpy.ndarray Image y-positions (units: radians).
- magnifications
numpy.ndarray Magnification factors for each image.
- time_delays
numpy.ndarray Time delays for each image (units: seconds).
- nImages
int Number of images formed.
- determinant
numpy.ndarray Determinant of the lensing Jacobian for each image.
- trace
numpy.ndarray Trace of the lensing Jacobian for each image.
- iteration
int Iteration index passed through for tracking.
- x_source
Examples
>>> from ler.image_properties.multiprocessing_routine import solve_lens_equation >>> import numpy as np >>> from multiprocessing import Pool >>> lens_parameters1 = np.array([2, 0.024, -0.016, 1.89, 0.10, 0.09, 0.25, 0.94, 2.5e-06, 0, 'EPL_NUMBA', 'SHEAR'], dtype=object) >>> lens_parameters2 = np.array([2, -0.040, -0.014, 2.00, 0.08, -0.01, 1.09, 2.55, 1.0e-06, 1, 'EPL_NUMBA', 'SHEAR'], dtype=object) >>> input_arguments = np.vstack((lens_parameters1, lens_parameters2)) >>> with Pool(2) as p: ... result = p.map(solve_lens_equation, input_arguments) >>> print(f"Number of images: {result[0][6]}")