gwforge.GWForge.ifo.reproducible_noise¶
Reproducible coloured Gaussian noise and zero noise, in pure numpy.
Probably equivalent to pycbc.noise.reproduceable (agrees to FFT round-off), but without the PyCBC dependency.
The noise is reproducible in the sense that a given
(seed, GPS time) always yields the same samples, so adjacent requests stitch together seamlessly.
This makes it suitable for generating long observations in chunks.
Attributes¶
Functions¶
|
Return one fixed-length block of white Gaussian samples. |
|
Return white Gaussian noise covering |
|
Crop |
|
Return an all-zero strain series covering |
|
Interpolate a tabulated PSD onto a uniform grid, log-log. |
|
Linearly resample a uniformly sampled series to a new |
|
Coarse-grain a PSD by truncating its inverse ASD's impulse response. |
|
Return Gaussian noise coloured by |
|
Generate noise for a bilby |
Module Contents¶
- gwforge.GWForge.ifo.reproducible_noise.block(seed, sample_rate)[source]¶
Return one fixed-length block of white Gaussian samples.
- Parameters:
seed (int) – Block seed. Reduced modulo
2**32forRandomState.sample_rate (float) – Sampling rate in Hz. Sets the variance to
sample_rate / 2so that the one-sided PSD of the result is unity.
- Returns:
BLOCK_SAMPLESnormally distributed samples.- Return type:
numpy.ndarray
- gwforge.GWForge.ifo.reproducible_noise.normal(start, end, sample_rate=16384, seed=0)[source]¶
Return white Gaussian noise covering
[start, end)in GPS seconds.The samples depend only on
(seed, absolute GPS time): adjacent requests stitch together seamlessly, which is what lets the workflow generate a long observation as independent per-chunk Condor jobs.- Returns:
The samples and the GPS epoch of the first one (which is
start).- Return type:
tuple of (numpy.ndarray, float)
- gwforge.GWForge.ifo.reproducible_noise.time_slice(samples, epoch, sample_rate, start, end)[source]¶
Crop
samples(starting at GPSepoch) to[start, end).- Returns:
The cropped samples and their GPS epoch, which is
start.- Return type:
tuple of (numpy.ndarray, float)
- gwforge.GWForge.ifo.reproducible_noise.zero_noise(start_time, end_time, sample_rate=16384)[source]¶
Return an all-zero strain series covering
[start_time, end_time).Same return contract as
colored_noise(), so callers can switch between the two without special-casing anything.
- gwforge.GWForge.ifo.reproducible_noise.interpolate_psd(frequencies, psd, length, delta_f, low_frequency_cutoff)[source]¶
Interpolate a tabulated PSD onto a uniform grid, log-log.
Port of
pycbc.psd.read.from_numpy_arrays. Interpolation is linear in(log f, log S), which is the right space for noise curves spanning many decades. Bins belowlow_frequency_cutoffare set to zero.- Parameters:
frequencies (array_like) – Tabulated one-sided PSD.
frequenciesmust be ascending and positive.psd (array_like) – Tabulated one-sided PSD.
frequenciesmust be ascending and positive.length (int) – Number of samples in the output (DC to Nyquist inclusive).
delta_f (float) – Frequency resolution of the output in Hz.
low_frequency_cutoff (float) – Bins below this are zeroed.
- Returns:
The PSD on
numpy.arange(length) * delta_f.- Return type:
numpy.ndarray
- gwforge.GWForge.ifo.reproducible_noise._resample(series, delta_f, new_delta_f, length=None)[source]¶
Linearly resample a uniformly sampled series to a new
delta_f.Port of
pycbc.psd.interpolate.
- gwforge.GWForge.ifo.reproducible_noise._inverse_spectrum_truncation(psd, delta_f, max_filter_length, low_frequency_cutoff)[source]¶
Coarse-grain a PSD by truncating its inverse ASD’s impulse response.
Port of
pycbc.psd.estimate.inverse_spectrum_truncationrestricted to the two options GWForge uses:which_spectrum='invasd'andtrunc_method='hann'. See arXiv:gr-qc/0509116 for the method.The goal is to remove the sharp spectral features that would otherwise give the colouring filter an impulse response longer than the data segment.
- gwforge.GWForge.ifo.reproducible_noise.colored_noise(psd, delta_f, start_time, end_time, seed=0, sample_rate=16384, low_frequency_cutoff=1.0, filter_duration=DEFAULT_FILTER_DURATION, scale=1.0)[source]¶
Return Gaussian noise coloured by
psd, covering[start, end).Numerically equivalent to
pycbc.noise.reproduceable.colored_noise(agrees to FFT round-off), including the seed/GPS reproducibility contract described in the module docstring.- Parameters:
psd (array_like) – One-sided PSD sampled uniformly from DC at spacing
delta_f.delta_f (float) – Frequency resolution of
psdin Hz.start_time (float) – GPS bounds of the requested data. The returned series covers
[start_time, end_time).end_time (float) – GPS bounds of the requested data. The returned series covers
[start_time, end_time).seed (int) – Noise seed. A given
(seed, GPS time)always yields the same samples.sample_rate (float) – Output sampling rate in Hz. Must be held constant to keep continuity between disjoint spans.
low_frequency_cutoff (float) – The PSD is zeroed below this, so the output carries no power there.
filter_duration (float) – Length in seconds of the colouring filter.
scale (float) – Extra multiplicative factor on the amplitude spectrum.
- Returns:
The coloured samples and their GPS epoch (which is
start_time).- Return type:
tuple of (numpy.ndarray, float)
- gwforge.GWForge.ifo.reproducible_noise.noise_from_interferometer(interferometer, start_time, end_time, seed=0, sample_rate=16384, noise_type='gaussian', low_frequency_cutoff=None, filter_duration=DEFAULT_FILTER_DURATION, psd_delta_f=1.0 / 16)[source]¶
Generate noise for a bilby
Interferometer.The PSD is taken from
interferometer.power_spectral_densityas arrays (frequency_array/psd_array) rather than by re-reading the file. Those arrays are populated no matter how the PSD was supplied – PSD file, ASD file, or raw arrays – so this works for ET (which ships a PSD file) and for every user-suppliedpsd-dictentry, both of which the old file-sniffing path could not handle.- Parameters:
interferometer (bilby.gw.detector.Interferometer) – Detector whose PSD and
minimum_frequencyare used.start_time (float) – GPS bounds of the requested data.
end_time (float) – GPS bounds of the requested data.
seed (int) – Noise seed; ignored for zero noise.
sample_rate (float) – Output sampling rate in Hz.
noise_type (str) –
'gaussian'or'zero'.low_frequency_cutoff (float or None) – Defaults to the interferometer’s
minimum_frequency.filter_duration (float) – Length in seconds of the colouring filter.
psd_delta_f (float) – Resolution the tabulated PSD is interpolated onto before colouring.
- Returns:
The strain samples and their GPS epoch.
- Return type:
tuple of (numpy.ndarray, float)