ler.image_properties

Submodules

Package Contents

Classes

ImageProperties

Class to find the image properties of a lensed event. Image properties include image positions, magnifications, time delays, etc.

Functions

solve_lens_equation(lens_parameters)

Function to solve the lens equation (min_image = 2)

interpolator_from_pickle(param_dict_given, directory, ...)

Function to decide which interpolator to use.

cubic_spline_interpolator(xnew, coefficients, x)

Function to interpolate using cubic spline.

axis_ratio_rayleigh(sigma[, q_min, q_max])

Function to sample axis ratio from rayleigh distribution with given velocity dispersion.

solve_lens_equation(lens_parameters)

Function to solve the lens equation (min_image = 2)

ler.image_properties.solve_lens_equation(lens_parameters)[source]

Function to solve the lens equation (min_image = 2)

Parameters:
lens_parameterslist

a list of parameters lens_parameters[0] = min_images : minimum number of images lens_parameters[1] = e1 : ellipticity lens_parameters[2] = e2 : ellipticity lens_parameters[3] = gamma : power-law index lens_parameters[4] = gamma1 : shear lens_parameters[5] = gamma2 : shear lens_parameters[6] = zl : redshift of the lens lens_parameters[7] = zs : redshift of the source lens_parameters[8] = einstein_radius : Einstein radius lens_parameters[9] = iteration : iteration number lens_parameters[10:] = lens_model_list : numpy array of lens models

Returns:
x_sourcefloat

x position of the source in the source plane

y_sourcefloat

y position of the source in the source plane

x0_image_positionfloat

x position of the images in the source plane

x1_image_positionfloat

y position of the images in the source plane

magnificationsfloat

magnification of the images

time_delaysfloat

time-delay of the images

nImagesint

number of images

determinantfloat

determinant of the hessian matrix

tracefloat

trace of the hessian matrix

iterationint

iteration number

Examples

>>> from ler.image_properties.multiprocessing_routine import solve_lens_equation
>>> import numpy as np
>>> from multiprocessing import Pool
>>> # lens parameters input contains 12 parameters [e1, e2, gamma, gamma1, gamma2, zl, zs, einstein_radius, iteration, lens_model_list]
>>> lens_parameters1 = np.array([2, 0.024069457093642648, -0.016002190961948142, 1.8945414936459974, 0.10117465203892329, 0.09600089396968613, 0.2503743800068136, 0.9418211055453296, 2.5055790287104725e-06, 0, 'EPL_NUMBA', 'SHEAR'], dtype=object)
>>> lens_parameters2 = np.array([2, -0.04030088581646998, -0.01419438113690042, 2.0068239327017, 0.08482718989370612, -0.015393332086560785, 1.0952303138971118, 2.5534097159384417, 1.0125570159563301e-06, 1, 'EPL_NUMBA', 'SHEAR'], dtype=object)
>>> input_arguments = np.vstack((lens_parameters1, lens_parameters2))
>>> # solve the lens equation for each set of lens parameters
>>> with Pool(2) as p:
...     result = p.map(solve_lens_equation1, input_arguments)
>>> # result is a list of tuples
>>> # each tuple contains the output parameters of the function
>>> # each output parameter contains x_source, y_source, x0_image_position, x1_image_position, magnifications, time_delays, nImages, determinant, trace, iteration
>>> print(f"magnification of images with lens parameters 'lens_parameters1' is {result[0][6]}")
magnification of images with lens parameters 'lens_parameters1' is [ 2.18973765 -1.27542831]
ler.image_properties.interpolator_from_pickle(param_dict_given, directory, sub_directory, name, x, pdf_func=None, y=None, conditioned_y=None, dimension=1, category='pdf', create_new=False)[source]

Function to decide which interpolator to use.

Parameters:
param_dict_givendict

dictionary of parameters.

directorystr

directory to store the interpolator.

sub_directorystr

sub-directory to store the interpolator.

namestr

name of the interpolator.

xnumpy.ndarray

x values.

pdf_funcfunction

function to calculate the pdf of x given y.

ynumpy.ndarray

y values.

conditioned_ynumpy.ndarray

conditioned y values.

dimensionint

dimension of the interpolator. Default is 1.

categorystr

category of the function. Default is “pdf”.

create_newbool

if True, create a new interpolator. Default is False.

Returns:
interpolatorfunction

interpolator function.

ler.image_properties.cubic_spline_interpolator(xnew, coefficients, x)[source]

Function to interpolate using cubic spline.

Parameters:
xnewnumpy.ndarray

new x values.

coefficientsnumpy.ndarray

coefficients of the cubic spline.

xnumpy.ndarray

x values.

Returns:
resultnumpy.ndarray

interpolated values.

class ler.image_properties.ImageProperties(npool=4, z_min=0.0, z_max=10, n_min_images=2, n_max_images=4, geocent_time_min=1126259462.4, geocent_time_max=1126259462.4 + 365 * 24 * 3600 * 20, lens_model_list=['EPL_NUMBA', 'SHEAR'], cosmology=None, spin_zero=True, spin_precession=False, directory='./interpolator_pickle', create_new_interpolator=False)[source]

Class to find the image properties of a lensed event. Image properties include image positions, magnifications, time delays, etc.

Parameters:
npoolint

number of processes to use default: 4

z_minfloat

minimum redshift to consider default: 0.0

z_maxfloat

maximum redshift to consider default: 10.0

n_min_imagesint

minimum number of images to consider default: 2

n_max_imagesint

maximum number of images to consider default: 4

geocent_time_minfloat

minimum geocent time to consider default: 1126259462.4 , which is the GPS time of the first GW detection

geocent_time_maxfloat

maximum geocent time to consider default: 1126259462.4+365*24*3600*100 , which is the GPS time of the first GW detection + 100 years. Some time delays can be very large.

lens_model_listlist

list of lens models default: [‘EPL_NUMBA’, ‘SHEAR’]

cosmologyastropy.cosmology

cosmology default: None/astropy.cosmology.LambdaCDM(H0=70, Om0=0.3, Ode0=0.7)

spin_zerobool

whether to assume spin zero or not default: True

spin_precessionbool

whether to assume spin precession or not default: False

directorystr

directory to save the interpolator pickle files default: “./interpolator_pickle”

create_new_interpolatordict

dictionary to create new interpolator pickle files default: dict(Dl_to_z=dict(create_new=False, resolution=500))

Examples

>>> from ler.image_properties import ImageProperties
>>> image_properties = ImageProperties()
>>> lens_parameters = dict(zs=2.0, zl=0.5, gamma1=0.0, gamma2=0.0, e1=0.0, e2=0.0, gamma=2.0, theta_E=1.0)
>>> lens_parameters = image_properties.image_properties(lens_parameters)
>>> print(lens_parameters.keys())

Instance Attributes

ImageProperties has the following instance attributes:

Atrributes

Type

npool

int

z_min

float

z_max

float

n_min_images

int

n_max_images

int

geocent_time_min

float

geocent_time_max

float

lens_model_list

list

cosmo

astropy.cosmology

spin_zero

bool

spin_precession

bool

directory

str

create_new_interpolator

dict

image_properties(lens_parameters)[source]

Function to get the image properties e.g. image positions, magnifications, time delays, etc.

Parameters:
lens_parametersdict

dictionary of lens parameters e.g. lens_parameters.keys() = [‘zs’, ‘zl’, ‘gamma1’, ‘gamma2’, ‘e1’, ‘e2’, ‘gamma’, ‘theta_E’]

Returns:
lens_parametersdict

dictionary of lens parameters and image properties e.g. lens_parameters contains the following keys:

lens related=>[‘zs’: source redshift, ‘zl’: lens redshift, ‘gamma1’: shear component in the x-direction, ‘gamma2’: shear component in the y-direction, ‘e1’: ellipticity component in the x-direction, ‘e2’: ellipticity component in the y-direction, ‘gamma’: spectral index of the mass density distribution, ‘theta_E’: einstein radius in radian]

source related=>[‘mass_1’: mass in detector frame (mass1>mass2), ‘mass_2’: mass in detector frame, ‘mass_1_source’:mass in source frame, ‘mass_2_source’:mass source frame, ‘luminosity_distance’: luminosity distance, ‘theta_jn’: inclination angle, ‘psi’: polarization angle, ‘phase’: coalesence phase, ‘geocent_time’: coalensence GPS time at geocenter, ‘ra’: right ascension, ‘dec’: declination, ‘a_1’: spin magnitude of the more massive black hole, ‘a2’: spin magnitude of the less massive black hole, ‘tilt_1’: tilt angle of the more massive black hole, ‘tilt_2’: tilt angle of the less massive black hole, ‘phi_12’: azimuthal angle between the two spins, ‘phi_jl’: azimuthal angle between the total angular momentum and the orbital angular momentum]

image related=>[‘x_source’: source position in the x-direction, ‘y_source’: source position in the y-direction, ‘x0_image_position’: image position in the x-direction, ‘x1_image_position’: image position in the y-direction, ‘magnifications’: magnifications, ‘time_delays’: time delays, ‘n_images’: number of images formed, ‘determinant’: determinants, ‘trace’: traces, ‘iteration’: to keep track of the iteration number

get_lensed_snrs(lensed_param, list_of_detectors=None, snr_calculator=None, pdet_calculator=None)[source]

Function to calculate the signal to noise ratio for each image in each event.

Parameters:
snr_calculatorfunction

snr function, as describe in the GWRATES class.

list_of_detectorslist

list of detectors e.g. [‘H1’, ‘L1’, ‘V1’]

lensed_paramdict

dictionary containing the both already lensed source paramters and image parameters. e.g. lensed_param.keys() = [‘mass_1’, ‘mass_2’, ‘zs’, ‘luminosity_distance’, ‘theta_jn’, ‘psi’, ‘phi’, ‘ra’, ‘dec’, ‘geocent_time’, ‘phase’, ‘a_1’, ‘a2’, ‘tilt_1’, ‘tilt_2’, ‘phi_12’, ‘phi_jl’, ‘magnifications’, ‘time_delays’]

n_max_imagesint

maximum number of images to consider default: 4

Returns:
snrsdict

signal to noise ratio for each image in each event. (dictionary containing ‘H1’, ‘L1’, …, and ‘optimal_snr_net’, which is the network snr, for each image as an array with dimensions (number_of_lensed_events,n_max_images) )

ler.image_properties.axis_ratio_rayleigh(sigma, q_min=0.2, q_max=1.0)[source]

Function to sample axis ratio from rayleigh distribution with given velocity dispersion.

Parameters:
sigmafloat: array

velocity dispersion of the lens galaxy

Returns:
qfloat: array

axis ratio of the lens galaxy

ler.image_properties.solve_lens_equation(lens_parameters)[source]

Function to solve the lens equation (min_image = 2)

Parameters:
lens_parameterslist

a list of parameters lens_parameters[0] = min_images : minimum number of images lens_parameters[1] = e1 : ellipticity lens_parameters[2] = e2 : ellipticity lens_parameters[3] = gamma : power-law index lens_parameters[4] = gamma1 : shear lens_parameters[5] = gamma2 : shear lens_parameters[6] = zl : redshift of the lens lens_parameters[7] = zs : redshift of the source lens_parameters[8] = einstein_radius : Einstein radius lens_parameters[9] = iteration : iteration number lens_parameters[10:] = lens_model_list : numpy array of lens models

Returns:
x_sourcefloat

x position of the source in the source plane

y_sourcefloat

y position of the source in the source plane

x0_image_positionfloat

x position of the images in the source plane

x1_image_positionfloat

y position of the images in the source plane

magnificationsfloat

magnification of the images

time_delaysfloat

time-delay of the images

nImagesint

number of images

determinantfloat

determinant of the hessian matrix

tracefloat

trace of the hessian matrix

iterationint

iteration number

Examples

>>> from ler.image_properties.multiprocessing_routine import solve_lens_equation
>>> import numpy as np
>>> from multiprocessing import Pool
>>> # lens parameters input contains 12 parameters [e1, e2, gamma, gamma1, gamma2, zl, zs, einstein_radius, iteration, lens_model_list]
>>> lens_parameters1 = np.array([2, 0.024069457093642648, -0.016002190961948142, 1.8945414936459974, 0.10117465203892329, 0.09600089396968613, 0.2503743800068136, 0.9418211055453296, 2.5055790287104725e-06, 0, 'EPL_NUMBA', 'SHEAR'], dtype=object)
>>> lens_parameters2 = np.array([2, -0.04030088581646998, -0.01419438113690042, 2.0068239327017, 0.08482718989370612, -0.015393332086560785, 1.0952303138971118, 2.5534097159384417, 1.0125570159563301e-06, 1, 'EPL_NUMBA', 'SHEAR'], dtype=object)
>>> input_arguments = np.vstack((lens_parameters1, lens_parameters2))
>>> # solve the lens equation for each set of lens parameters
>>> with Pool(2) as p:
...     result = p.map(solve_lens_equation1, input_arguments)
>>> # result is a list of tuples
>>> # each tuple contains the output parameters of the function
>>> # each output parameter contains x_source, y_source, x0_image_position, x1_image_position, magnifications, time_delays, nImages, determinant, trace, iteration
>>> print(f"magnification of images with lens parameters 'lens_parameters1' is {result[0][6]}")
magnification of images with lens parameters 'lens_parameters1' is [ 2.18973765 -1.27542831]