ler.utils.plots

This module contains functions to plot the results.

Module Contents

Functions

param_plot([param_name, param_dict, plot_label, ...])

Function to plot the distribution of the GW source parameters.

relative_mu_dt_unlensed(param[, size, randomize])

Function to generate relative magnification vs time delay difference for unlensed samples.

relative_mu_dt_lensed(lensed_param[, pdet_threshold, ...])

Function to classify the lensed images wrt to the morse phase difference.

mu_vs_dt_plot(x_array, y_array[, xscale, yscale, ...])

Function to generate 2D KDE and plot the relative magnification vs time delay difference for lensed samples.

ler.utils.plots.param_plot(param_name='zs', param_dict='./gw_params.json', plot_label='zs', param_min=None, param_max=None, kde=True, kde_bandwidth=0.2, histogram=True, histogram_bins=30)[source]

Function to plot the distribution of the GW source parameters.

Parameters:
param_namestr

name of the parameter to plot. default param_name = ‘zs’.

param_dictdict or str

dictionary of GW source parameters or json file name. default param_dict = ‘./gw_params.json’.

param_xlabelstr

x-axis label. default param_xlabel = ‘source redshift’.

param_ylabelstr

y-axis label. default param_ylabel = ‘probability density’.

param_minfloat

minimum value of the parameter. default param_min = None.

param_maxfloat

maximum value of the parameter. default param_max = None.

figsizetuple

figure size. default figsize = (4, 4).

kdebool

if True, kde will be plotted. default kde = True.

kde_bandwidthfloat

bandwidth for kde. default kde_bandwidth = 0.2.

histogrambool

if True, histogram will be plotted. default histogram = True.

histogram_binsint

number of bins for histogram. default histogram_bins = 30.

Examples

>>> import matplotlib.pyplot as plt
>>> from ler.utils import param_plot
>>> from ler.rates import LeR
>>> ler = LeR(verbose=False)
>>> param = ler.unlensed_cbc_statistics();
>>> rate, param_detectable = ler.unlensed_rate()
>>> plt.figure(figsize=(6, 4))
>>> param_plot(param_name='zs', param_dict=param, plot_label='all events')
>>> param_plot(param_name='zs', param_dict=param_detectable, plot_label='detectable events')
>>> plt.xlabel('source redshift')
>>> plt.ylabel('probability density')
>>> plt.title('source redshift distribution')
>>> plt.grid(alpha=0.5)
>>> plt.savefig('source_redshift_distribution.png')
ler.utils.plots.relative_mu_dt_unlensed(param, size=100, randomize=True)[source]

Function to generate relative magnification vs time delay difference for unlensed samples.

Parameters:
paramdict

dictionary of unlensed GW source parameters. unlensed_param.keys() = [‘m1’, ‘m2’, ‘z’, ‘snr’, ‘theta_jn’, ‘ra’, ‘dec’, ‘psi’, ‘phase’, ‘geocent_time’]

sizeint

number of samples. default size = 100.

randomizebool

if True, it will randomize the samples. default randomize = True.

Returns:
dmufloat.array

relative magnification: abs(mu2/mu1) or abs(dl1/dl2)**2.

dtfloat.array

relative time delay: abs(t1-t2) in days.

ler.utils.plots.relative_mu_dt_lensed(lensed_param, pdet_threshold=[0.5, 0.5], classification_type='morse_phase')[source]

Function to classify the lensed images wrt to the morse phase difference.

Parameters:
lensed_paramdict

dictionary of lensed GW source parameters. lensed_param.keys() = [‘x_source’, ‘y_source’, ‘x0_image_position’, ‘x1_image_position’, ‘magnifications’, ‘time_delays’, ‘pdet_net’, ‘image_type’]

pdet_thresholdlist

threshold for pdet_net to consider the image as detectable. default pdet_threshold = [0.5, 0.5].

classification_typestr

type of classification to be done. default classification_type = ‘morse_phase’. other options: ‘arrival_time’.

Returns:
dict
dictionary containing the relative magnification and time delay difference for the classified images.
if classification_type = ‘morse_phase’:
{

“dt_rel0”: np.array of relative time delay difference for images with morse phase difference = 0, “mu_rel0”: np.array of relative magnification for images with morse phase difference = 0, “dt_rel90”: np.array of relative time delay difference for images with morse phase difference = 90, “mu_rel90”: np.array of relative magnification for images with morse phase difference = 90,

}

if classification_type = ‘arrival_time’:
{

“dt_12”: np.array of relative time delay difference for image 1 and image 2, “mu_12”: np.array of relative magnification for image 1 and image 2, “dt_13”: np.array of relative time delay difference for image 1 and image 3, “mu_13”: np.array of relative magnification for image 1 and image 3, “dt_14”: np.array of relative time delay difference for image 1 and image 4, “mu_14”: np.array of relative magnification for image 1 and image 4, “dt_23”: np.array of relative time delay difference for image 2 and image 3, “mu_23”: np.array of relative magnification for image 2 and image 3, “dt_24”: np.array of relative time delay difference for image 2 and image 4, “mu_24”: np.array of relative magnification for image 2 and image 4, “dt_34”: np.array of relative time delay difference for image 3 and image 4, “mu_34”: np.array of relative magnification for image 3 and image 4,

}

ler.utils.plots.mu_vs_dt_plot(x_array, y_array, xscale='log10', yscale='log10', alpha=0.6, extent=None, contour_levels=[10, 40, 68, 95], colors=['blue', 'blue', 'blue', 'blue', 'blue'])[source]

Function to generate 2D KDE and plot the relative magnification vs time delay difference for lensed samples.

Parameters:
x_arrayfloat.array

x array.

y_arrayfloat.array

y array.

xscalestr

x-axis scale. default xscale = ‘log10’. other options: ‘log’, None.

yscalestr

y-axis scale. default yscale = ‘log10’. other options: ‘log’, None.

alphafloat

transparency of the contour plot. default alpha = 0.6.

extentlist

extent of the plot. default extent = None. It will consider the full range of x_array and y_array.

contour_levelslist

levels for contour plot. default contour_levels = [10, 40, 68, 95].

colorsstr

colors for contour plot. default colors = [‘blue’, ‘blue’, ‘blue’, ‘blue’, ‘blue’].

Examples

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from ler.utils import param_plot, mu_vs_dt_plot, get_param_from_json, relative_mu_dt_unlensed, relative_mu_dt_lensed
>>> # get the parameters. For data generation, refer to the 'LeR complete example' in the documentation.
>>> unlensed_param = get_param_from_json('ler_data/unlensed_param.json')
>>> unlensed_param_detectable = get_param_from_json('ler_data/unlensed_param_detectable.json')
>>> lensed_param = get_param_from_json('ler_data/lensed_param.json')
>>> lensed_param_detectable = get_param_from_json('ler_data/lensed_param_detectable.json')
>>> # get the relative mu and dt
>>> ans = relative_mu_dt_lensed(lensed_param_detectable)
>>> dmu, dt = relative_mu_dt_unlensed(unlensed_param_detectable, size=1000, randomize=True)
>>> # plot
>>> plt.figure(figsize=(4, 4))
>>> mu_vs_dt_plot(ans['dt_rel90'], ans['mu_rel90'], colors='b')
>>> mu_vs_dt_plot(ans['dt_rel0'], ans['mu_rel0'], colors='g')
>>> mu_vs_dt_plot(dt, dmu, colors='r')
>>> # Create proxy artists for legend
>>> proxy1 = plt.Line2D([0], [0], linestyle='-', color='b', label=r'Lensed ($\Delta \phi=90$)')
>>> proxy2 = plt.Line2D([0], [0], linestyle='-', color='g', label=r'Lensed ($\Delta \phi=0$)')
>>> proxy3 = plt.Line2D([0], [0], linestyle='-', color='r', label=r'Unlensed')
>>> plt.legend(handles=[proxy1, proxy2, proxy3], loc='upper left')
>>> plt.xlim(-5, 2.5)
>>> plt.ylim(-2.5, 2.5)
>>> plt.grid(alpha=0.4)
>>> plt.show()