ler.gw_source_population.cbc_source_parameter_distribution
Module for sampling compact binary coalescence (CBC) source parameters.
This module provides the CBCSourceParameterDistribution class for generating
complete sets of intrinsic and extrinsic gravitational wave parameters for
compact binary sources (BBH, BNS, NSBH). It includes mass distributions,
spin parameters, sky positions, and other parameters needed for GW analysis.
Inheritance hierarchy:
- Usage:
Basic workflow example:
>>> from ler.gw_source_population import CBCSourceParameterDistribution >>> cbc = CBCSourceParameterDistribution(event_type='BBH') >>> params = cbc.sample_gw_parameters(size=1000) >>> print(list(params.keys()))
Module Contents
Classes
Class for sampling compact binary coalescence source parameters. |
Attributes
- class ler.gw_source_population.cbc_source_parameter_distribution.CBCSourceParameterDistribution(z_min=0.0, z_max=10.0, event_type='BBH', source_priors=None, source_priors_params=None, cosmology=None, spin_zero=False, spin_precession=False, directory='./interpolator_json', create_new_interpolator=False)[source]
Bases:
ler.gw_source_population.cbc_source_redshift_distribution.CBCSourceRedshiftDistributionClass for sampling compact binary coalescence source parameters.
This class generates complete sets of intrinsic and extrinsic gravitational wave parameters for compact binary sources including masses, spins, sky positions, and orbital parameters. It supports BBH, BNS, NSBH, and primordial black hole populations with configurable prior distributions.
Key Features:
Multiple mass distribution models (PowerLaw+Gaussian, lognormal, bimodal)
Configurable spin priors (zero, aligned, precessing)
Isotropic sky position and orientation sampling
Built-in support for population III and primordial black holes
- Parameters:
- z_min
float Minimum redshift of the source population.
default: 0.0
- z_max
float Maximum redshift of the source population.
default: 10.0
- event_type
str Type of compact binary event to generate.
Options:
‘BBH’: Binary black hole (Population I/II)
‘BNS’: Binary neutron star
‘NSBH’: Neutron star-black hole
‘BBH_popIII’: Population III binary black hole
‘BBH_primordial’: Primordial binary black hole
default: ‘BBH’
- source_priors
dictorNone Dictionary of prior sampler functions for each parameter.
If None, uses default priors based on event_type.
default: None
- source_priors_params
dictorNone Dictionary of parameters for each prior sampler function.
If None, uses default parameters based on event_type.
default: None
- cosmology
astropy.cosmologyorNone Cosmology to use 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)
- 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
- directory
str Directory to store interpolator JSON files.
default: ‘./interpolator_json’
- create_new_interpolator
dictorbool Configuration for creating new interpolators.
If bool, applies to all interpolators.
default: False
- z_min
Examples
>>> from ler.gw_source_population import CBCSourceParameterDistribution >>> cbc = CBCSourceParameterDistribution(event_type='BBH') >>> params = cbc.sample_gw_parameters(size=1000) >>> print(list(params.keys()))
Instance Methods
CBCSourceParameterDistribution has the following methods:
Instance Attributes
CBCSourceParameterDistribution has the following attributes:
Attribute
Type
Unit
Description
floatMinimum redshift of source population
floatMaximum redshift of source population
astropy.cosmologyCosmology for distance calculations
boolWhether to ignore spin parameters
boolWhether to use precessing spins
strDirectory for interpolator files
gw_param_samplersdictDictionary of parameter sampler functions
gw_param_samplers_paramsdictDictionary of sampler function parameters
dictAvailable prior distributions
callableSampler for source frame masses
callableSampler for source redshift
callableSampler for geocentric time
callableSampler for right ascension
callableSampler for declination
callableSampler for coalescence phase
callableSampler for polarization angle
callableSampler for inclination angle
callableSampler for spin1 magnitude
callableSampler for spin2 magnitude
callableSampler for tilt1 angle
callableSampler for tilt2 angle
callableSampler for phi_12 angle
callableSampler for phi_jl angle
- property zs[source]
Class object (of FunctionConditioning) for source redshift, with rvs/sampler as callback. Can also be a user defined callable sampler.
The class object contains the following attribute methods:
rvs: returns random samples from the redshift distribution
pdf: returns the probability density function of the redshift distribution
function: returns the redshift distribution function.
- Returns:
- zs
numpy.ndarray Array of redshift values.
- zs
- property source_frame_masses[source]
Class object (of FunctionConditioning) for source frame masses, with rvs/sampler as callback. Can also be a user defined callable sampler.
The class object contains the following attribute methods:
rvs: returns random samples from the density profile slope distribution
- Returns:
- mass_1_source
numpy.ndarray Array of mass_1_source values in solar masses.
- mass_2_source
numpy.ndarray Array of mass_2_source values in solar masses.
- mass_1_source
Examples
>>> from ler.gw_source_population import CBCSourceParameterDistribution >>> cbc_source_param_dist = CBCSourceParameterDistribution() >>> cbc_source_param_dist.source_frame_masses(size=10)
- property geocent_time[source]
Class object (of FunctionConditioning) for geocentric time, with rvs/sampler as callback. Can also be a user defined callable sampler.
The class object contains the following attribute methods:
rvs: returns random samples from the geocentric time distribution
pdf: returns the probability density function of the geocentric time distribution
function: returns the geocentric time distribution function.
- Returns:
- geocent_time
numpy.ndarray Array of geocentric time values.
- geocent_time
- property ra[source]
Class object (of FunctionConditioning) for right ascension, with rvs/sampler as callback. Can also be a user defined callable sampler.
The class object contains the following attribute methods:
rvs: returns random samples from the right ascension distribution
pdf: returns the probability density function of the right ascension distribution
function: returns the right ascension distribution function.
- Returns:
- ra
numpy.ndarray Array of right ascension values.
- ra
- property dec[source]
Class object (of FunctionConditioning) for declination, with rvs/sampler as callback. Can also be a user defined callable sampler.
The class object contains the following attribute methods:
rvs: returns random samples from the declination distribution
pdf: returns the probability density function of the declination distribution
function: returns the declination distribution function.
- Returns:
- dec
numpy.ndarray Array of declination values.
- dec
- property phase[source]
Class object (of FunctionConditioning) for coalescence phase, with rvs/sampler as callback. Can also be a user defined callable sampler.
The class object contains the following attribute methods:
rvs: returns random samples from the coalescence phase distribution
pdf: returns the probability density function of the coalescence phase distribution
function: returns the coalescence phase distribution function.
- Returns:
- phase
numpy.ndarray Array of coalescence phase values.
- phase
- property psi[source]
Class object (of FunctionConditioning) for polarization angle, with rvs/sampler as callback. Can also be a user defined callable sampler.
The class object contains the following attribute methods:
rvs: returns random samples from the polarization angle distribution
pdf: returns the probability density function of the polarization angle distribution
function: returns the polarization angle distribution function.
- Returns:
- geocent_time
numpy.ndarray Array of polarization angle values.
- geocent_time
- property theta_jn[source]
Class object (of FunctionConditioning) for inclination angle, with rvs/sampler as callback. Can also be a user defined callable sampler.
The class object contains the following attribute methods:
rvs: returns random samples from the inclination angle distribution
pdf: returns the probability density function of the inclination angle distribution
function: returns the inclination angle distribution function.
- Returns:
- theta_jn
numpy.ndarray Array of inclination angle values, i.e. the angle between the line of sight and the orbital angular momentum (rad).
- theta_jn
- property a_1[source]
Class object (of FunctionConditioning) for spin1 magnitude, with rvs/sampler as callback. Can also be a user defined callable sampler.
The class object contains the following attribute methods:
rvs: returns random samples from the spin1 magnitude distribution
pdf: returns the probability density function of the spin1 magnitude distribution
function: returns the spin1 magnitude distribution function.
- Returns:
- a_1
numpy.ndarray Array of spin magnitude values for the primary body.
- a_1
- property a_2[source]
Class object (of FunctionConditioning) for spin2 magnitude, with rvs/sampler as callback. Can also be a user defined callable sampler.
The class object contains the following attribute methods:
rvs: returns random samples from the spin2 magnitude distribution
pdf: returns the probability density function of the spin2 magnitude distribution
function: returns the spin2 magnitude distribution function.
- Returns:
- a_2
numpy.ndarray Array of spin magnitude values for the secondary body.
- a_2
- property tilt_1[source]
Class object (of FunctionConditioning) for tilt1 angle, with rvs/sampler as callback. Can also be a user defined callable sampler.
The class object contains the following attribute methods:
rvs: returns random samples from the tilt1 angle distribution
pdf: returns the probability density function of the tilt1 angle distribution
function: returns the tilt1 angle distribution function.
- Returns:
- tilt_1
numpy.ndarray Array of the spin tilt angle of the primary body, i.e. the angle between the spin vector and the orbital angular momentum for the primary body (rad).
- tilt_1
- property tilt_2[source]
Class object (of FunctionConditioning) for tilt2 angle, with rvs/sampler as callback. Can also be a user defined callable sampler.
The class object contains the following attribute methods:
rvs: returns random samples from the tilt2 angle distribution
pdf: returns the probability density function of the tilt2 angle distribution
function: returns the tilt2 angle distribution function.
- Returns:
- tilt_2
numpy.ndarray Array of the spin tilt angle of the secondary body, i.e. the angle between the spin vector and the orbital angular momentum for the secondary body (rad).
- tilt_2
- property phi_12[source]
Class object (of FunctionConditioning) for phi_12 angle, with rvs/sampler as callback. Can also be a user defined callable sampler.
The class object contains the following attribute methods:
rvs: returns random samples from the phi_12 angle distribution
pdf: returns the probability density function of the phi_12 angle distribution
function: returns the phi_12 angle distribution function.
- Returns:
- phi_12
numpy.ndarray Array of the spin tilt angle between the two spins, i.e., angle between the projections of the two spins onto the orbital plane (rad).
- phi_12
- property phi_jl[source]
Class object (of FunctionConditioning) for phi_jl angle, with rvs/sampler as callback. Can also be a user defined callable sampler.
The class object contains the following attribute methods:
rvs: returns random samples from the phi_jl angle distribution
pdf: returns the probability density function of the phi_jl angle distribution
function: returns the phi_jl angle distribution function.
- Returns:
- phi_jl
numpy.ndarray Array of the angle values between the orientation of the total angular momentum around the orbital angular momentum (rad).
- phi_jl
- property available_gw_prior[source]
Dictionary of all available prior distributions and their parameters.
This is a dynamically generated dictionary containing available samplers for each GW parameter type and their default parameter values.
- Returns:
- available_gw_prior
dict Nested dictionary organized by parameter type (e.g., ‘source_frame_masses’,
‘geocent_time’, etc.) with sampler names and default parameters.
- available_gw_prior
- source_priors_params = 'None'[source]
dictDictionary of prior sampler functions’ input parameters.
- directory = "'./interpolator_json'"[source]
Directory path for storing interpolator JSON files.
- Returns:
- directory
str Path to the interpolator storage directory.
default: ‘./interpolator_json’
- directory
- sample_gw_parameters(size=1000, param=None)[source]
Sample all gravitational wave parameters for compact binaries.
Generates a complete set of intrinsic and extrinsic parameters including masses, redshift, luminosity distance, sky position, orientation, and optionally spin parameters.
- Parameters:
- size
int Number of samples to draw.
default: 1000
- param
dictorNone Dictionary of fixed parameter values.
Parameters in this dict will not be sampled.
default: None
- size
- Returns:
- gw_parameters
dict Dictionary of sampled GW parameters. The included parameters and their units are as follows (for default settings):
Parameter
Units
Description
zs
redshift of the source
geocent_time
s
GPS time of coalescence
ra
rad
right ascension
dec
rad
declination
phase
rad
phase of GW at reference frequency
psi
rad
polarization angle
theta_jn
rad
inclination angle
a_1
spin_1 of the compact binary
a_2
spin_2 of the compact binary
luminosity_distance
Mpc
luminosity distance
mass_1_source
Msun
mass_1 of the compact binary (source frame)
mass_2_source
Msun
mass_2 of the compact binary (source frame)
mass_1
Msun
mass_1 of the compact binary (detector frame)
mass_2
Msun
mass_2 of the compact binary (detector frame)
- gw_parameters
Examples
>>> from ler.gw_source_population import CBCSourceParameterDistribution >>> cbc = CBCSourceParameterDistribution() >>> params = cbc.sample_gw_parameters(size=1000) >>> print(list(params.keys()))
- binary_masses_BBH_powerlaw_gaussian(size, get_attribute=False, **kwargs)[source]
Sample source masses with PowerLaw+PEAK model for Population I/II BBH.
Implements the mass distribution model from LIGO-Virgo population analyses combining a power-law with a Gaussian peak component.
- Parameters:
- size
int Number of samples to draw.
- get_attribute
bool If True, return the sampler object instead of samples.
default: False
- **kwargs
dict Model parameters:
mminbh: Minimum BH mass (Msun), default: 4.98
mmaxbh: Maximum BH mass (Msun), default: 112.5
alpha: Power-law spectral index, default: 3.78
mu_g: Gaussian peak mean (Msun), default: 32.27
sigma_g: Gaussian peak width (Msun), default: 3.88
lambda_peak: Fraction in Gaussian component, default: 0.03
delta_m: Low-mass tapering range (Msun), default: 4.8
beta: Mass ratio power-law index, default: 0.81
- size
- Returns:
- mass_1_source
numpy.ndarray Array of primary masses in source frame (Msun).
- mass_2_source
numpy.ndarray Array of secondary masses in source frame (Msun).
- mass_1_source
Examples
>>> from ler.gw_source_population import CBCSourceParameterDistribution >>> cbc = CBCSourceParameterDistribution() >>> m1_src, m2_src = cbc.binary_masses_BBH_powerlaw_gaussian(size=1000)
- binary_masses_BBH_popIII_lognormal(size, get_attribute=False, **kwargs)[source]
Sample source masses for Population III BBH from lognormal distribution.
Based on Eqn. 1 and 4 of Ng et al. 2022 for Population III black holes.
- Parameters:
- size
int Number of samples to draw.
- get_attribute
bool If True, return the sampler object instead of samples.
default: False
- **kwargs
dict Model parameters:
m_min: Minimum BH mass (Msun), default: 5.0
m_max: Maximum BH mass (Msun), default: 150.0
Mc: Central mass scale (Msun), default: 30.0
sigma: Distribution width, default: 0.3
- size
- Returns:
- mass_1_source
numpy.ndarray Array of primary masses in source frame (Msun).
- mass_2_source
numpy.ndarray Array of secondary masses in source frame (Msun).
- mass_1_source
Examples
>>> from ler.gw_source_population import CBCSourceParameterDistribution >>> cbc = CBCSourceParameterDistribution(event_type='BBH_popIII') >>> m1_src, m2_src = cbc.binary_masses_BBH_popIII_lognormal(size=1000)
- binary_masses_BBH_primordial_lognormal(size, get_attribute=False, **kwargs)[source]
Sample source masses for primordial BBH from lognormal distribution.
Based on Eqn. 1 and 4 of Ng et al. 2022 for primordial black holes.
- Parameters:
- size
int Number of samples to draw.
- get_attribute
bool If True, return the sampler object instead of samples.
default: False
- **kwargs
dict Model parameters:
m_min: Minimum BH mass (Msun), default: 1.0
m_max: Maximum BH mass (Msun), default: 100.0
Mc: Central mass scale (Msun), default: 20.0
sigma: Distribution width, default: 0.3
- size
- Returns:
- mass_1_source
numpy.ndarray Array of primary masses in source frame (Msun).
- mass_2_source
numpy.ndarray Array of secondary masses in source frame (Msun).
- mass_1_source
- binary_masses_NSBH_broken_powerlaw(size, get_attribute=False, **kwargs)[source]
Sample source masses for NSBH from broken power-law distribution.
Uses gwcosmo-style broken power-law for black hole mass and power-law for neutron star mass.
- Parameters:
- size
int Number of samples to draw.
- get_attribute
bool If True, return the sampler object instead of samples.
default: False
- **kwargs
dict Model parameters:
mminbh: Minimum BH mass (Msun), default: 26
mmaxbh: Maximum BH mass (Msun), default: 125
alpha_1: Primary power-law index, default: 6.75
alpha_2: Secondary power-law index, default: 6.75
b: Break point, default: 0.5
delta_m: Tapering range (Msun), default: 5
mminns: Minimum NS mass (Msun), default: 1.0
mmaxns: Maximum NS mass (Msun), default: 3.0
alphans: NS mass power-law index, default: 0.0
- size
- Returns:
- mass_1_source
numpy.ndarray Array of BH masses in source frame (Msun).
- mass_2_source
numpy.ndarray Array of NS masses in source frame (Msun).
- mass_1_source
Examples
>>> from ler.gw_source_population import CBCSourceParameterDistribution >>> cbc = CBCSourceParameterDistribution(event_type='NSBH') >>> m1_src, m2_src = cbc.binary_masses_NSBH_broken_powerlaw(size=1000)
- binary_masses_uniform(size, get_attribute=False, **kwargs)[source]
Sample source masses from uniform distribution.
- Parameters:
- size
int Number of samples to draw.
- get_attribute
bool If True, return the sampler object instead of samples.
default: False
- **kwargs
dict Model parameters:
m_min: Minimum mass (Msun), default: 1.0
m_max: Maximum mass (Msun), default: 3.0
- size
- Returns:
- mass_1_source
numpy.ndarray Array of primary masses in source frame (Msun).
- mass_2_source
numpy.ndarray Array of secondary masses in source frame (Msun).
- mass_1_source
Examples
>>> from ler.gw_source_population import CBCSourceParameterDistribution >>> cbc = CBCSourceParameterDistribution() >>> m1_src, m2_src = cbc.binary_masses_uniform(size=1000)
- binary_masses_BNS_bimodal(size, get_attribute=False, **kwargs)[source]
Sample BNS masses from bimodal Gaussian distribution.
Based on Will M. Farr et al. 2020 Eqn. 6 for neutron star mass distribution combining two Gaussian peaks.
- Parameters:
- size
int Number of samples to draw.
- get_attribute
bool If True, return the sampler object instead of samples.
default: False
- **kwargs
dict Model parameters:
w: Weight of left peak, default: 0.643
muL: Mean of left peak (Msun), default: 1.352
sigmaL: Width of left peak (Msun), default: 0.08
muR: Mean of right peak (Msun), default: 1.88
sigmaR: Width of right peak (Msun), default: 0.3
mmin: Minimum mass (Msun), default: 1.0
mmax: Maximum mass (Msun), default: 2.3
- size
- Returns:
- mass_1_source
numpy.ndarray Array of primary masses in source frame (Msun).
- mass_2_source
numpy.ndarray Array of secondary masses in source frame (Msun).
- mass_1_source
Examples
>>> from ler.gw_source_population import CBCSourceParameterDistribution >>> cbc = CBCSourceParameterDistribution(event_type='BNS') >>> m1_src, m2_src = cbc.binary_masses_BNS_bimodal(size=1000)
- constant_values_n_size(size=100, get_attribute=False, **kwargs)[source]
Return array of constant values.
- Parameters:
- size
int Number of values to return.
default: 100
- get_attribute
bool If True, return the sampler object instead of samples.
default: False
- **kwargs
dict Model parameters:
value: Constant value to return, default: 0.0
- size
- Returns:
- values
numpy.ndarray Array of constant values.
- values
- sampler_uniform(size, get_attribute=False, **kwargs)[source]
Sample values from uniform distribution.
- Parameters:
- size
int Number of samples to draw.
- get_attribute
bool If True, return the sampler object instead of samples.
default: False
- **kwargs
dict Model parameters:
xmin: Minimum value, default: 0.0
xmax: Maximum value, default: 1.0
- size
- Returns:
- values
numpy.ndarray Array of uniformly distributed values in range [xmin, xmax].
- values
- sampler_cosine(size, get_attribute=False, **kwargs)[source]
Sample from cosine distribution for declination.
Samples values in range [-pi/2, pi/2] following a cosine distribution, appropriate for isotropic sky position declination.
- Parameters:
- size
int Number of samples to draw.
- get_attribute
bool If True, return the sampler object instead of samples.
default: False
- size
- Returns:
- values
numpy.ndarray Array of values in range [-pi/2, pi/2] (rad).
- values
- sampler_sine(size, get_attribute=False, **kwargs)[source]
Sample from sine distribution for inclination angles.
Samples values in range [0, pi] following a sine distribution, appropriate for isotropic orientation angles.
- Parameters:
- size
int Number of samples to draw.
- get_attribute
bool If True, return the sampler object instead of samples.
default: False
- size
- Returns:
- values
numpy.ndarray Array of values in range [0, pi] (rad).
- values