pycwb.modules.data_conditioning package

Submodules

pycwb.modules.data_conditioning.data_conditioning module

Segment-level regression and whitening for one or several detectors.

pycwb.modules.data_conditioning.data_conditioning.condition_strain(config, strain)[source]

Return (conditioned TimeSeries, NoiseRMSMap) for one detector segment.

pycwb.modules.data_conditioning.data_conditioning.condition_strains(config, strains)[source]

Regress and whiten a segment’s detector strains.

Returns two tuples: conditioned TimeSeries objects and their NoiseRMSMap anchor maps, in detector order. Regressions finish for all detectors before whitening starts, preserving the established execution order. Detector parallelism belongs to the caller; regression may parallelize its TF layers.

pycwb.modules.data_conditioning.data_conditioning.data_conditioning(*args: Any, **kwargs: Any) → Any

Deprecated alias for condition_strains; removed in pycwb 1.2.0.

pycwb.modules.data_conditioning.data_conditioning.data_conditioning_single(*args: Any, **kwargs: Any) → Any

Deprecated alias for condition_strain; removed in pycwb 1.2.0.

pycwb.modules.data_conditioning.injection_whitening module

Pure-Python whitening of injection strain using a pre-computed nRMS map.

pycwb.modules.data_conditioning.injection_whitening.whiten_injection_strain(config, strain, noise_rms)[source]

Whiten signal-only injection strain using a pre-computed noise RMS map.

This uses the wdm_wavelet Python library for the wavelet transform.

Parameters:
  • config (Config) – Configuration object (must expose l_white/l_high, WDM_beta_order, WDM_precision, fLow, fHigh).

  • strain (pycwb.types.time_series.TimeSeries or gwpy.TimeSeries) – Signal-only injection strain for a single detector.

  • noise_rms (wdm_wavelet.types.time_frequency_map.TimeFrequencyMap) – Per-frequency noise RMS, as returned by whiten_wavelet(). Its data array has shape (n_freq, K+1) (anchor columns spanning the segment).

Returns:

(whitened_injection_strain, unwhitened_injection_strain) matching the interface expected by get_INJ_waveform().

Return type:

tuple[TimeFrequencySeries, TimeFrequencySeries]

pycwb.modules.data_conditioning.noise module

Whitening-noise anchors and cWB detector::setrms pixel lookup.

Optional variability corrections are delegated to conditioning_plugins.

pycwb.modules.data_conditioning.noise.lookup_pixel_noise_rms(frequencies, detector_indices, layers, rates, noise_maps)[source]

Return float64 (n_pixels, n_detectors) RMS without a dense TF-time cache.

pycwb.modules.data_conditioning.noise.make_noise_rms_map(tf_map, anchors, edge_length)[source]

Preserve the anchor lattice used by WSeries::white / wavearray::white.

pycwb.modules.data_conditioning.noise_variability module

Single-band, post-whitening noise-variability correction.

The default center/width (32/32 Hz), four-second linear-prediction filter, 0.6-second multiplicity correlation, and 0.125-second initial delay reproduce cWB’s O3a recipe. Other parameter values use the same numerical construction; their suitability for a search requires separate scientific validation.

Frequency bands are exact interior WDM layers. A correction returns both the reconstructed strain and its single-band noise-normalization map; downstream pixel RMS must consume the latter. Independent corrections cannot be stacked without defining how their normalization maps compose.

pycwb.modules.data_conditioning.noise_variability.correct_noise_variability(strain: Any, edge_seconds: float, *, frequency_hz: float = 32.0, bandwidth_hz: float = 32.0, filter_seconds: float = 4.0, correlation_seconds: float = 0.6, correlation_delay_seconds: float = 0.125) → tuple[TimeSeries, TimeFrequencyMap][source]

Correct one frequency band of already whitened strain.

Parameters use Hz and seconds. The affected band is [frequency_hz - bandwidth_hz/2, frequency_hz + bandwidth_hz/2]. Its center must be an integer multiple of its width, and the sample rate must make sample_rate/(2*bandwidth_hz) an integer. DC and Nyquist layers are unsupported. Input length must be divisible by that WDM decimation factor so coefficient timing is exact. Invalid parameters fail before a transform.

Returns a new TimeSeries and a positive, float32, single-band TimeFrequencyMap carrying the correction factors. Sample count, start, and cadence are preserved; the original strain is unchanged.

pycwb.modules.data_conditioning.noise_variability.correct_variability_layer(layer: ArrayLike, rate: float, edge_seconds: float, *, filter_seconds: float = 4.0, correlation_seconds: float = 0.6, correlation_delay_seconds: float = 0.125) → tuple[ndarray, ndarray][source]

Correct one WDM amplitude envelope and return its normalization factors.

rate is the coefficient sampling rate in Hz, and every duration is in seconds. The linear-prediction order rounds to the nearest sample, the correlation window truncates, and its initial delay rounds, preserving the O3a recipe at 64 Hz. Real or complex coefficients keep their phase/sign. The input array is never modified. Scratch edges cover bins whose reference normalization remains identity; only the interior is used for analysis.

pycwb.modules.data_conditioning.noise_variability.lpr_filter(data: ndarray, rate: float, edge: float, filter_seconds: float = 4.0) → ndarray[source]

Symmetric cWB linear prediction, with the reference right-tail rejection.

pycwb.modules.data_conditioning.parallel module

Parallel native detector conditioning with explicit scheduling options.

Runs in the job (parent) process before lag workers exist. Each detector is conditioned by the unchanged native condition_strain on the CPU JAX device; only the per-detector scheduling changes.

pycwb.modules.data_conditioning.parallel.condition_strains(config: Config, strains: list[Any], *, workers: int = 1, validate: bool = False) → tuple[Any, ...][source]

Condition every detector strain, in parallel threads when requested.

Parameters:
  • config (Config) – Search configuration.

  • strains (list) – One input strain per detector, as accepted by the native functions.

  • workers (int) – Maximum concurrent reads or detector tasks; positive, defaults to one.

  • validate (bool) – Also run the serial reference and compare exact outputs.

Returns:

Same layout as the native data_conditioning return, i.e. one tuple per product with a per-detector entry each.

Return type:

tuple

Raises:
  • ValueError – If workers is not a positive integer.

  • AssertionError – If validation is enabled and the parallel result differs from serial.

pycwb.modules.data_conditioning.preparation module

Explicit post-whitening noise-variability correction and gating preparation.

This runner consumes whitened strains and their noise RMS maps once per trial, before lag processing. Noise-variability correction changes amplitudes and the noise variation model; cWB gating records GPS selection exclusions while preserving strain.

pycwb.modules.data_conditioning.preparation.apply_gating(context: HookContext, result: ConditioningResult, settings: dict[str, Any]) → ConditioningResult[source]

Add cWB GPS pixel-selection exclusions without replacing strain/noise.

pycwb.modules.data_conditioning.preparation.apply_noise_variability(context: HookContext, result: ConditioningResult, settings: dict[str, Any]) → ConditioningResult[source]

Apply resolved noise-variability settings; defaults use the O3a recipe.

pycwb.modules.data_conditioning.preparation.prepare_conditioned_data(config: Any, segment: Any, strains: Sequence[Any], noise_rms: Sequence[Any]) → ConditioningResult[source]

Apply noise-variability correction then cWB gating to already whitened products.

Empty or disabled settings preserve the original strain/noise objects. Correction uses the noise_variability block; no module path from the configuration is imported or executed.

pycwb.modules.data_conditioning.preparation.save_preparation_diagnostics(result: ConditioningResult, directory: str | Path) → None[source]

Save correction/gating provenance and per-detector variation arrays.

pycwb.modules.data_conditioning.psd_correction module

Pure-Python PSD variability correction using wdm_wavelet.

pycwb.modules.data_conditioning.psd_correction.apply_psd_correction(config, h, high_frequency_threshold: float = 513.0, layer_rate: float = 32.0, smooth_seconds: float = 6.0)[source]

Apply cWB-like PSD variability correction in pure Python.

Parameters:
  • config (Config) – Configuration object with segEdge, WDM_beta_order, WDM_precision.

  • h (pycwb.types.time_series.TimeSeries | gwpy.timeseries.TimeSeries) – Input conditioned/whitened strain.

  • high_frequency_threshold (float, optional) – Minimum frequency (Hz) used to build PSD variability envelope.

  • layer_rate (float, optional) – Target WDM layer rate used in the original plugin (R=32).

  • smooth_seconds (float, optional) – Smoothing scale in seconds for envelope cleaning.

Returns:

Corrected time-domain strain.

Return type:

pycwb.types.time_series.TimeSeries

pycwb.modules.data_conditioning.psd_correction.psd_correction_python(*args: Any, **kwargs: Any) → Any

Deprecated alias for apply_psd_correction; removed in pycwb 1.2.0.

pycwb.modules.data_conditioning.regression module

Configure WDM regression and dispatch to the selected numerical backend.

Both engines preserve the self-witness LPE path, release amplitude cap, full-sample statistics, and quadrature reconstruction conventions.

pycwb.modules.data_conditioning.regression.apply_regression(config, h)[source]

Clean data with native regression using the selected Numba or JAX backend.

This follows the cWB LPE regression path used in regression.py:

target TF map + self-witness (“target”), then setFilter/setMatrix/solve/apply.

Notes

  • Numba is the default per-layer backend; JAX is separately selectable.

  • Numerical kernels live in regression_numba.py and regression_jax.py.

pycwb.modules.data_conditioning.regression.apply_regression_jax(config, strain)[source]

Apply regression with JAX without mutating the caller’s execution profile.

pycwb.modules.data_conditioning.regression.regression_python(*args: Any, **kwargs: Any) → Any

Deprecated alias for apply_regression; removed in pycwb 1.2.0.

pycwb.modules.data_conditioning.regression_jax module

JAX regression kernels, batched across selected WDM frequency layers.

Used by regression.apply_regression for JAX layer processing. This module owns the JIT kernels rather than re-exporting them through the public dispatcher.

pycwb.modules.data_conditioning.regression_jax.regression_jax(*args: Any, **kwargs: Any) → Any

Deprecated alias for regression.apply_regression_jax; removed in pycwb 1.2.0.

pycwb.modules.data_conditioning.regression_numba module

Numba regression kernels; arithmetic follows the cWB LPE regression path.

The dispatcher imports this backend only when Numba is selected. Availability is reported by _NUMBA_AVAILABLE.

pycwb.modules.data_conditioning.resampling module

Reference cWB SNR-mode injection resampling, separate from noise/SNR estimation.

pycwb.modules.data_conditioning.resampling.meyer_downsample(values: ArrayLike, levels: int) → NDArray[float64][source]

Return cWB Meyer(1024) low-pass layers with periodic boundaries.

Each layer preserves wavelet energy normalization (sqrt(2) for DC). ForwardFWT’s default odd parity starts the 1024 taps at sample -511.

pycwb.modules.data_conditioning.resampling.resample_snr_injection(strain: TimeSeries, config: Config) → TimeSeries[source]

Meyer-resample final SNR-scaled strain; do not use for estimating its SNR.

pycwb.modules.data_conditioning.resampling.uses_target_snr_resampling(injections: Sequence[dict]) → bool[source]

Select separate Meyer resampling for target-SNR injection trials.

pycwb.modules.data_conditioning.whitening module

Pure-Python whitening without ROOT dependencies.

pycwb.modules.data_conditioning.whitening.whiten_wavelet(config, h, *, apply_bandpass=True)[source]

Noise whitening via WDM (pure-Python implementation).

Returns:

(conditioned_strain, nRMS_tf_map).

Return type:

tuple[pycwb.types.time_series.TimeSeries, NoiseRMSMap]

pycwb.modules.data_conditioning.whitening.whitening_python(*args: Any, **kwargs: Any) → Any

Deprecated alias for whiten_wavelet; removed in pycwb 1.2.0.

pycwb.modules.data_conditioning.whitening_common module

Shared cWB frequency-bin masking for whitening-noise maps.

Wavelet and MESA noise estimators remain separate; this helper only replaces out-of-band rows with the requested constant, preserving cWB bin boundaries.

pycwb.modules.data_conditioning.whitening_mesa module

Pure-Python MESA whitening without ROOT dependencies.

This version produces output compatible with whiten_wavelet() from whitening.py, using the same anchor-point batching logic as cWB’s white() mode=0.

pycwb.modules.data_conditioning.whitening_mesa.planck_taper_window(n_samples, eps=0.15)[source]

Generate a Planck-taper window.

Parameters:
  • n_samples (int) – Number of samples

  • eps (float) – Taper fraction (default 0.15)

Returns:

Window array

Return type:

np.ndarray

pycwb.modules.data_conditioning.whitening_mesa.reindex_psds(psds, f)[source]

Uses Isolation Forest to exclude PSDs with large deviation from median.

Parameters:
  • psds (np.ndarray) – Array of shape (N_segments, N_frequencies) containing PSDs

  • f (np.ndarray) – Array of sampling frequencies

Returns:

Reindexed PSDs

Return type:

np.ndarray

pycwb.modules.data_conditioning.whitening_mesa.rolling_median(psds, half_size)[source]

Smooths the PSDs estimates with a rolling median filter.

Parameters:
  • psds (np.ndarray) – Array of shape (N_segments, N_frequencies) containing all PSDs

  • half_size (int) – Half size of the rolling median window

Returns:

Smoothed PSDs

Return type:

np.ndarray

pycwb.modules.data_conditioning.whitening_mesa.whiten_mesa(config, h)[source]

Pure-Python MESA whitening.

Returns:

(conditioned_strain, nRMS_tf_map) compatible with whiten_wavelet.

Return type:

tuple[pycwb.types.time_series.TimeSeries, NoiseRMSMap]

pycwb.modules.data_conditioning.whitening_mesa.whitening_mesa_python(*args: Any, **kwargs: Any) → Any

Deprecated alias for whiten_mesa; removed in pycwb 1.2.0.

Module contents

Native segment-level regression, whitening, and noise-map preparation.

The workflow applies resampling.py before regression and whitening. Condition each detector segment before lag processing; use signal-only injection whitening with an existing noise map. The MESA entry point is loaded on demand to keep its dependencies optional.