sage.data.noise.coloured_noise

Filename : coloured_noise.py Description : Short description of the file

Created on 2026-01-19 16:18:07

__author__ = Narenraju Nagarajan __copyright__ = Copyright 2026, Sage __license__ = MIT Licence __version__ = 0.0.1 __maintainer__ = Narenraju Nagarajan __email__ = N/A __status__ = [‘inProgress’, ‘Archived’, ‘inUsage’, ‘Debugging’]

GitHub Repository: NULL

Documentation: NULL

Classes

ColouredNoiseGenerator

Legacy PyCBC-based coloured Gaussian noise generator.

Module Contents

class ColouredNoiseGenerator(psds_dir='')[source]

Legacy PyCBC-based coloured Gaussian noise generator.

Generates noise coloured by real measured PSDs from HDF files (one per detector), matching the “Dataset 3” protocol from MLGWSC-1. For each noise realisation a random PSD is chosen from the precomputed ASD pool for each detector and the corresponding coloured noise is generated via PyCBC’s inverse-spectrum-truncation whitening filter.

Note

This class depends on pycbc and is used only in legacy CPU-based DataLoader pipelines. The GPU-native real-noise path (MemmapNoiseSampler) is preferred for on-the-fly training.

Parameters:

psds_dir (str) – Path to the parent directory containing H1/ and L1/ subdirectories of .hdf PSD files.

psds_dir = ''[source]
psd_options[source]
sample_length = None[source]
delta_f = None[source]
noise_low_freq_cutoff = None[source]
sample_rate = None[source]
precompute_common_params()[source]

Load all configured PSDs from disk and convert each to a complex ASD.

Must be called once after construction before calling generate() or apply(). Results are stored in complex_asds.

psd_to_asd(psd, start_time, end_time, sample_rate=2048.0, low_frequency_cutoff=15.0, filter_duration=128)[source]

Convert a PyCBC FrequencySeries PSD to a complex ASD suitable for colouring white Gaussian noise.

Parameters:
  • psd (pycbc.types.FrequencySeries) – Power spectral density in Hz^-1.

  • start_time (float) – GPS start/end (seconds) used only for sizing the intermediate time-series.

  • end_time (float) – GPS start/end (seconds) used only for sizing the intermediate time-series.

  • sample_rate (float) – Target sample rate (Hz; default 2048.0).

  • low_frequency_cutoff (float) – Below this frequency the PSD is zeroed (Hz; default 15.0).

  • filter_duration (float) – Duration (seconds) of the coloring filter (default 128).

Returns:

Complex ASD (fourth root of the squared-norm PSD).

Return type:

pycbc.types.FrequencySeries

colored_noise(asd, start_time, end_time, seed=42, sample_rate=2048.0, filter_duration=128, det=None)[source]

Create noise from a PSD

Return noise from the chosen PSD. Note that if unique noise is desired a unique seed should be provided.

Parameters:
  • asd (pycbc.types.FrequencySeries) – ASD to color the noise

  • start_time (int) – Start time in GPS seconds to generate noise

  • end_time (int) – End time in GPS seconds to generate noise

  • seed ({None, int}) – The seed to generate the noise.

  • sample_rate ({16384, float}) – The sample rate of the output data. Keep constant if you want to ensure continuity between disjoint time spans.

  • filter_duration ({128, float}) – The duration in seconds of the coloring filter

Returns:

noise – A TimeSeries containing gaussian noise colored by the given psd.

Return type:

TimeSeries

normal(start, end, sample_rate=2048.0, seed=0)[source]

Generate data with a white Gaussian (normal) distribution

Parameters:
  • start_time (int) – Start time in GPS seconds to generate noise

  • end_time (int) – End time in GPS seconds to generate noise

  • sample-rate (float) – Sample rate to generate the data at. Keep constant if you want to ensure continuity between disjoint time spans.

  • seed ({None, int}) – The seed to generate the noise.

Returns:

noise – A TimeSeries containing gaussian noise

Return type:

TimeSeries

choose_asd()[source]

Randomly select one pre-computed ASD per detector (H1, L1).

generate(asd, seed, det)[source]

Generate a single coloured-noise time-series of length sample_length seconds.

Parameters:
  • asd (pycbc.types.FrequencySeries) – Complex ASD used to colour the noise.

  • seed (int) – Random seed for white-noise generation.

  • det (str) – Detector name (unused but kept for interface compatibility).

Returns:

Coloured noise array of shape (sample_length * sample_rate,).

Return type:

numpy.ndarray

apply(special, det_only='')[source]

Generate a batch-size set of two-detector coloured-noise time-series.

Parameters:
  • special (dict) – Must contain "sample_seed" (int) used to generate reproducible random seeds for each detector channel.

  • det_only (str, optional) – If non-empty, generate noise only for this detector (unused in most call sites).

Returns:

noise – Coloured noise for both detectors.

Return type:

numpy.ndarray, shape (batch_size, 2, sample_length_in_num)