pycwb.modules.injection package

Submodules

pycwb.modules.injection.distribution_utils module

class pycwb.modules.injection.distribution_utils.Sine(min, max)[source]

Bases: object

sample(n)[source]
class pycwb.modules.injection.distribution_utils.Uniform(min, max)[source]

Bases: object

sample(n)[source]

pycwb.modules.injection.file_polarizations module

Read external, uniformly sampled plus/cross waveforms for burst injections.

pycwb.modules.injection.file_polarizations.get_td_waveform(*, waveform_files: dict, waveform_sample_rate: float, delta_t: float, waveform_sha256: dict | None = None, hrss: float | None = None, iota: float = 0.0, **kwargs: object) → dict[source]

Return external polarizations with cWB’s sample-rounded source epoch.

waveform_files maps hp and optional hc to one-column text or NumPy files. Missing cross polarization is zero. A positive hrss scales their combined source energy before applying inclination. Omitting it preserves the file amplitude. The file sample rate must match the injection rate; the later conditioning stage uses the normal analysis resampling.

pycwb.modules.injection.fill module

Plan complete rate trials and fit an existing parameter pool to their slots.

class pycwb.modules.injection.fill.InjectionInterval[source]

Bases: TypedDict

Usable analysis interval with scheduling ownership and detector shifts.

duration: float
end: float
job_id: int
shift: list[float]
start: float
class pycwb.modules.injection.fill.InjectionSlot[source]

Bases: TypedDict

One occurrence assigned to a job, trial and absolute GPS time.

gps_time: float
job_id: int
shift: list[float]
trial_idx: int
pycwb.modules.injection.fill.assemble_injection_slots(parameters: Sequence[dict[str, Any]], slots: Sequence[InjectionSlot], *, rng: Generator) → list[dict[str, Any]][source]

Resize the parameter pool and attach fresh scheduling identities.

pycwb.modules.injection.fill.gps_grid_intervals(intervals: Sequence[InjectionInterval], spacing: float, jitter: float) → list[tuple[list[InjectionInterval], NDArray[float64]]][source]

Build the existing GPS grid once per job, including split keep windows.

pycwb.modules.injection.fill.plan_injection_slots(intervals: Sequence[InjectionInterval], rate: float, trials: int, *, jitter: float = 0, alignment: Literal['livetime', 'gps'] = 'livetime', min_slots: int = 0, rng: Generator) → list[InjectionSlot][source]

Fill trials passes, extending full passes to reach min_slots.

GPS alignment retains only jittered anchors inside keep windows. Livetime alignment uses a fixed-spacing grid on the concatenated usable intervals. Very short windows can contain no slots; their rate is never increased.

pycwb.modules.injection.fill.resample_injection_parameters(parameters: Sequence[dict[str, Any]], count: int, *, rng: Generator) → list[dict[str, Any]][source]

Keep the pool and sample additional copies, or downsample without replacement.

pycwb.modules.injection.gwsignal_waveform module

GWSignal-based time-domain waveform generator.

Drop-in replacement for pycbc.waveform.get_td_waveform used as the default waveform generator by pycwb.modules.injection.strain.

The function accepts the same parameter names as pycbc (mass1, mass2, f_lower, coa_phase, delta_t, approximant, …) and translates them to the lalsimulation.gwsignal conventions before calling gwsignal.GenerateTDWaveform.

Returns a dict {'type': 'polarizations', 'hp': TimeSeries, 'hc': TimeSeries} suitable for consumption by generate_strain_from_injection.

pycwb.modules.injection.gwsignal_waveform.get_td_waveform(**kwargs)[source]

Generate time-domain polarisations via GWSignal.

Accepts pycbc-style keyword arguments and returns a dict with 'type': 'polarizations' plus 'hp' and 'hc' as pycwb.types.time_series.TimeSeries objects.

pycwb.modules.injection.inj_generators module

Injection generators for reading strain data from files.

pycwb.modules.injection.inj_generators.compute_central_time(strain)[source]

Compute the central time of the strain data.

pycwb.modules.injection.inj_generators.get_strain_from_file(delta_t, files, allow_resampling=False, **kwargs)[source]

Generate strain by reading it from a file.

The available extensions are: .txt, .npy and .hdf.

Parameters:
  • delta_t (float) – Sampling interval (1 / sample_rate).

  • files (dict) – Mapping of interferometer names to file paths, e.g. {'H1': 'path/to/H1_strain.txt', 'L1': 'path/to/L1_strain.txt'}.

  • allow_resampling (bool, optional) – If True, resample data whose sample rate does not match the target rate. Default is False.

  • **kwargs – Additional injection parameters (gps_time, rescale, distribute, etc.).

Returns:

A dictionary with keys as interferometer names and values as pycwb TimeSeries.

Return type:

dict

pycwb.modules.injection.inj_generators.resample_data(data, factor)[source]

Resample data using a polyphase filter.

Parameters:
  • data (TimeSeries) – The input time series to be resampled.

  • factor (float) – The resampling factor (>1 upsamples, <1 downsamples).

Returns:

The resampled time series.

Return type:

TimeSeries

pycwb.modules.injection.injection module

pycwb.modules.injection.injection.distribute_inj_in_gps_time_by_poisson(injections, rate, start_gps_time, end_gps_time, edge_buffer=0, max_trail=None, shuffle=True)[source]

Distribute injections in GPS time with a Poisson distribution.

Parameters:
  • injections – The list of injections

  • rate – The rate of injections

  • start_gps_time – The start GPS time

  • end_gps_time – The end GPS time

  • edge_buffer – The buffer time at the start and end of the data

  • max_trails – The maximum number of trails for the case of auxiliary injections

pycwb.modules.injection.injection.distribute_inj_in_gps_time_by_rate(injections, rate, jitter, start_gps_time, end_gps_time, edge_buffer=0, shuffle=True, allow_repeat=True)[source]

Distribute injections in GPS time with a given rate and jitter.

Parameters:
  • injections – The list of injections

  • rate – The rate of injections

  • jitter – The jitter of injections

  • start_gps_time – The start GPS time

  • end_gps_time – The end GPS time

  • edge_buffer – The buffer time at the start and end of the data

  • shuffle – Shuffle the injections before distributing in time

  • allow_repeat – Allow repeating the injections if there is not enough time to distribute

pycwb.modules.injection.injection.distribute_inj_in_job_intervals_by_poisson(injections, rate, intervals, max_trail=None, shuffle=True)[source]

Schedule injections as a Poisson process over each trial’s job intervals.

pycwb.modules.injection.injection.distribute_inj_in_job_intervals_by_rate(injections, rate, jitter, intervals, shuffle=True)[source]

Schedule injections at fixed rate over combined job livetime.

If one pass over all intervals cannot hold every injection at the requested rate, the same interval set is reused with increasing trial_idx. Each injection still receives exactly one owning job_id.

pycwb.modules.injection.injection.distribute_inj_on_gps_grid(injections, rate, jitter, intervals)[source]

Schedule a cWB-style absolute GPS grid with independent uniform jitter.

Keep only points inside a usable analysis interval. In particular, do not stretch spacing to fill an interval or clip jitter onto interval endpoints. Repeat the available intervals as trials until the finite input list is used.

pycwb.modules.injection.injection.generate_auxiliary_injection_list_from_config(injection_config, start_gps_time, end_gps_time, n_trials)[source]
pycwb.modules.injection.injection.generate_filled_injections_for_job_segments(injection_config: Mapping[str, Any], job_segments: Sequence[WaveSegment]) → tuple[list[dict[str, Any]], int][source]

Assemble full rate trials from the existing parameter-generator interface.

pycwb.modules.injection.injection.generate_injection_list_from_config_for_job_segments(injection_config, job_segments)[source]

Generate and schedule injections into concrete job/tape intervals.

Each job segment contributes available analysis livetime. Every generated injection is assigned to exactly one job via top-level job_id and shift fields, so shifted jobs add capacity before a new trial_idx is needed instead of receiving duplicate copies of nominal-window injections.

pycwb.modules.injection.par_generator module

pycwb.modules.injection.par_generator.get_injection_list_from_parameters(injection)[source]

Generate the injection list from the injection parameters.

Parameters:

injection (dict) – The injection parameters.

Returns:

The list of injections.

pycwb.modules.injection.par_generator.hrss_scaling(input, targeted_hrss_list)[source]

This function scales the input waveform to the targeted hrss list. The scaling factor is calculated as the ratio of the targeted hrss and the input hrss.

Parameters:
  • input – The input waveform

  • targeted_hrss_list – The list of targeted hrss

Returns:

The scaled waveform

pycwb.modules.injection.par_generator.inc_pol_replicator(par_list, inclinations, polarizations)[source]

This function replicates the parameter list for pairs of inclinations and polarizations.

Parameters:
  • par_list – The list of parameters

  • inclinations – The list of inclinations

  • polarizations – The list of polarizations

Returns:

The replicated list

pycwb.modules.injection.par_generator.repeat(par_list, n_repeat)[source]

This function repeats the parameter list n times.

Parameters:
  • par_list – The list of parameters

  • n_repeat – The number of repeats

Returns:

The repeated list

pycwb.modules.injection.sky_distribution module

Generate and attach injection sky distributions.

pycwb.modules.injection.sky_distribution.distribute_injections_on_sky(injections, sky_locations, shuffle=True, coordsys='icrs')[source]

Attach radian sky coordinates to injection dictionaries.

pycwb.modules.injection.sky_distribution.generate_sky_distribution(sky_distribution_config, n_samples)[source]

Generate two radian coordinate arrays in the configured frame.

pycwb.modules.injection.sky_distribution.sample_uniform_sky_area(phi_center, theta_center, radius, n_samples=1)[source]

Backward-compatible degree API returning (longitude, latitude).

pycwb.modules.injection.snr_energy module

Reference cWB detector::setsim energy for target-SNR injections.

pycwb.modules.injection.snr_energy.cwb_snr_energy(series, gps, half_window, f_low, f_high)[source]

Reproduce the reference centroid, 99.9% crop and packed-FFT cut.

series must already be whitened using the pre-conditioning noise RMS. The frequency-cut loop intentionally preserves the original packed-FFT convention, including its upper loop bound and joint DC/Nyquist handling.

pycwb.modules.injection.snr_scaling module

Scale injections to a target network SNR using clean-data WDM noise.

pycwb.modules.injection.snr_scaling.target_snr_scales(config: Config, segment: WaveSegment, clean_data: Sequence[TimeSeries]) → NDArray[float64][source]

Return per-injection scales; do not contaminate the noise estimate.

Match cWB simulation=5: estimate WDM noise before regression/injection, whiten the signal, and sum detector energies inside iwindow/2. Nearby injections are rejected because a shared window cannot define their SNRs.

pycwb.modules.injection.strain module

Generate simulated detector strain from waveform injection parameters.

pycwb.modules.injection.strain.generate_strain_from_injection(injection: dict, config: Config, sample_rate, ifos) → list[TimeSeries][source]

Generate detector strain from one injection parameter mapping.

pycwb.modules.injection.strain.get_strain_support_from_injection(injection: dict[str, Any], config: Config, sample_rate: float, ifos: Sequence[str], cache: dict[bytes, tuple[float, int, float]], ignore_par: list[str] | tuple[str, ...] | None = None) → list[tuple[float, float]][source]

Return per-IFO (start, end) without allocating projected strain arrays.

cache is a caller-owned, in-memory lookup of relative source epoch, sample count and sample interval. Opt in only for deterministic polarization generators whose support is independent of scheduling fields and the explicitly ignored model parameters. ignore_par=None uses config.injection.cache_waveform_ignore_par; an explicit list replaces it. Distance and all other model parameters are kept by default. Direct-strain generators and generators returning parameter updates are not cached. Nothing is persisted across calls/builds unless the caller reuses it.

pycwb.modules.injection.strain.normalize_waveform_support_ignore_par(ignore_par: list[str] | tuple[str, ...]) → frozenset[str][source]

Validate model-specific exclusions; never drop generator or sample rate.

pycwb.modules.injection.strain.project_to_detector(hp, hc, ra, dec, polarization, detectors, geocent_end_time, ref_ifo='H1')[source]

Project plus/cross polarizations onto a list of detectors.

Parameters:
  • hp (TimeSeries) – Plus and cross polarizations in any supported time-series format.

  • hc (TimeSeries) – Plus and cross polarizations in any supported time-series format.

  • ra (float) – Right ascension and declination in radians.

  • dec (float) – Right ascension and declination in radians.

  • polarization (float) – Polarization angle in radians.

  • detectors (sequence of Detector) – Initialized detector instances, for example config.detectors.

  • geocent_end_time (float) – Geocentric end time added to the epoch of hp and hc.

  • ref_ifo (str, optional) – Unused compatibility argument.

Returns:

Projected strain for each detector.

Return type:

list of pycwb.types.time_series.TimeSeries

pycwb.modules.injection.wf_generator module

pycwb.modules.injection.wf_generator.generate_injection(parameters, generator)[source]

Generate an injection waveform.

Parameters:
  • parameters – The injection parameters

  • generator – The generator function

Returns:

The injection waveform

Module contents

pycwb.modules.injection — Simulated GW signal injection.

Generates and schedules simulated GW signal injections into job segments. Builds injection parameter lists from config, handles sky distribution sampling, time-of-arrival distributions, and assigns injections to specific job segments and trials.