redback.simulate_transients.PopulationSynthesizer

class redback.simulate_transients.PopulationSynthesizer(model, prior=None, rate=1e-06, rate_evolution='constant', rate_params=None, cosmology='Planck18', seed=42)[source]

Bases: object

Advanced population synthesis with realistic distributions and selection effects

This class provides survey-agnostic population synthesis with: - Volumetric rate evolution with redshift - Realistic parameter sampling from priors - Optional selection effects and detection efficiency - Cosmology-aware redshift sampling - Rate inference capabilities

__init__(model, prior=None, rate=1e-06, rate_evolution='constant', rate_params=None, cosmology='Planck18', seed=42)[source]

Initialize PopulationSynthesizer

Parameters:
  • model – String corresponding to redback model or callable function

  • prior – bilby.core.prior.PriorDict or string name of prior file If None, will attempt to load default prior for the model

  • rate – Volumetric rate in Gpc^-3 yr^-1 at z=0 (for constant rate) or callable function rate(z) for redshift-dependent rates

  • rate_evolution – String specifying rate evolution model Options: ‘constant’, ‘powerlaw’, ‘sfr_like’, or callable - ‘constant’: R(z) = R0 - ‘powerlaw’: R(z) = R0 * (1+z)^alpha (requires alpha in rate_params) - ‘sfr_like’: R(z) follows star formation rate (Madau & Dickinson 2014)

  • rate_params – Dictionary of parameters for rate evolution (e.g., {‘alpha’: 2.7})

  • cosmology – Cosmology to use (‘Planck18’, ‘Planck15’, etc.) or astropy cosmology object

  • seed – Random seed for reproducibility

__call__(**kwargs)

Call self as a function.

Methods

__init__(model[, prior, rate, ...])

Initialize PopulationSynthesizer

apply_detection_criteria(population, ...)

Apply custom detection criteria to a population

generate_population([n_years, n_events, ...])

Generate population parameters according to volumetric rate and priors

infer_rate(observed_sample[, ...])

Infer volumetric rate from observed sample

simulate_population([n_years, n_events, ...])

Convenience method to generate and optionally filter a transient population

apply_detection_criteria(population, detection_function, **kwargs)[source]

Apply custom detection criteria to a population

This is a flexible post-processing method that allows users to define their own detection logic based on the population parameters.

Parameters:
  • population – pandas DataFrame from generate_population() or TransientPopulation

  • detection_function – Callable that takes (row, **kwargs) and returns bool or float [0,1] - If returns bool: True = detected, False = not detected - If returns float: Interpreted as detection probability, stochastically applied - Function signature: detection_function(row, **kwargs) -> bool or float

  • kwargs – Additional arguments passed to detection_function

Returns:

pandas DataFrame with added ‘detected’ and optionally ‘detection_probability’ columns

generate_population(n_years=10, n_events=None, z_max=None, time_range=None, include_sky_position=True, rate_weighted_redshifts=True)[source]

Generate population parameters according to volumetric rate and priors

This method generates a pure parameter DataFrame that can be passed to any simulation tool (redback SimulateOpticalTransient, custom tools, etc.)

Parameters:
  • n_years – Number of years to observe (used with rate to calculate n_events)

  • n_events – Fixed number of events (overrides n_years if specified)

  • z_max – Maximum redshift (if None, use prior maximum)

  • time_range – Tuple of (start_time_mjd, end_time_mjd) for event times If None, uses (60000, 60000 + n_years*365.25)

  • include_sky_position – Whether to add RA/DEC (isotropic)

  • rate_weighted_redshifts – If True (default), sample redshifts weighted by volumetric rate R(z) * dVc/dz / (1+z). If False, sample directly from prior (useful with bilby.gw.prior.UniformComovingVolume for simple forecasts)

Returns:

pandas DataFrame with all parameters (including redshift, ra, dec, t0_mjd_transient)

infer_rate(observed_sample, efficiency_function=None, z_bins=10, prior_range=(1e-08, 0.0001), method='maximum_likelihood')[source]

Infer volumetric rate from observed sample

This accounts for selection effects via the efficiency function

Parameters:
  • observed_sample – DataFrame or TransientPopulation of observed transients Must have ‘redshift’ column

  • efficiency_function – Callable epsilon(z) giving detection efficiency vs redshift If None, assumes perfect detection (epsilon=1)

  • z_bins – Number of redshift bins for rate estimation

  • prior_range – Tuple of (min, max) for rate prior in Gpc^-3 yr^-1

  • method – ‘maximum_likelihood’ or ‘bayesian’

Returns:

Dictionary with rate estimate and uncertainties

simulate_population(n_years=10, n_events=None, z_max=None, time_range=None, include_selection_effects=False, survey_config=None, include_lightcurves=False, model_kwargs=None, rate_weighted_redshifts=True)[source]

Convenience method to generate and optionally filter a transient population

This is a wrapper around generate_population() and apply_detection_criteria() that returns a TransientPopulation object. For more control, use the individual methods directly.

Parameters:
  • n_years – Number of years to simulate (used to calculate expected events from rate)

  • n_events – Fixed number of events (overrides n_years if specified)

  • z_max – Maximum redshift to sample

  • time_range – Tuple of (start_mjd, end_mjd) for event times

  • include_selection_effects – Whether to apply detection efficiency cuts

  • survey_config – Dictionary with survey parameters for selection effects Example: {‘limiting_mag’: 22.5, ‘bands’: [‘lsstr’], ‘area_sqdeg’: 18000}

  • include_lightcurves – Whether to generate light curves (expensive)

  • model_kwargs – Additional kwargs to pass to model

  • rate_weighted_redshifts – If True (default), sample redshifts weighted by volumetric rate. If False, sample directly from prior

Returns:

TransientPopulation object