def normal(start, end, seed=0): """ 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 nosie seed : {None, int} The seed to generate the noise. Returns -------- noise : TimeSeries A TimeSeries containing gaussian noise """ # This is reproduceable because we used fixed seeds from known values s = int(start / BLOCK_SIZE) e = int(end / BLOCK_SIZE) # The data evenly divides so the last block would be superfluous if end % BLOCK_SIZE == 0: e -= 1 sv = RandomState(seed).randint(-2**50, 2**50) data = numpy.concatenate([block(i + sv) for i in numpy.arange(s, e + 1, 1)]) ts = TimeSeries(data, delta_t=1.0 / SAMPLE_RATE, epoch=start) return ts.time_slice(start, end)
def normal(start, end, seed=0): """ 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 nosie seed : {None, int} The seed to generate the noise. Returns -------- noise : TimeSeries A TimeSeries containing gaussian noise """ # This is reproduceable because we used fixed seeds from known values s = int(start / BLOCK_SIZE) e = int(end / BLOCK_SIZE) # The data evenly divides so the last block would be superfluous if end % BLOCK_SIZE == 0: e -= 1 sv = RandomState(seed).randint(-2**50, 2**50) data = numpy.concatenate( [block(i + sv) for i in numpy.arange(s, e + 1, 1)]) ts = TimeSeries(data, delta_t=1.0 / SAMPLE_RATE, epoch=start) return ts.time_slice(start, end)
def normal(start, end, sample_rate=16384, seed=0): """ 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 : TimeSeries A TimeSeries containing gaussian noise """ # This is reproduceable because we used fixed seeds from known values block_dur = BLOCK_SAMPLES / sample_rate s = int(numpy.floor(start / block_dur)) e = int(numpy.floor(end / block_dur)) # The data evenly divides so the last block would be superfluous if end % block_dur == 0: e -= 1 sv = RandomState(seed).randint(-2**50, 2**50) data = numpy.concatenate( [block(i + sv, sample_rate) for i in numpy.arange(s, e + 1, 1)]) ts = TimeSeries(data, delta_t=1.0 / sample_rate, epoch=(s * block_dur)) return ts.time_slice(start, end)
waveform[merger_index:start_index] = hp signal = noise + waveform pylab.figure(figsize=(10, 5)) pylab.plot(signal.sample_times, signal, label='Waveform + Noise') pylab.plot(waveform.sample_times, waveform, label='Waveform') pylab.legend() pylab.xlabel('Time (s)') pylab.ylabel('Strain') pylab.title('Injected Waveform') zoom_signal = signal.time_slice(merger_time - 0.5, merger_time + 0.5) zoom_waveform = waveform.time_slice(merger_time - 0.5, merger_time + 0.5) pylab.figure(figsize=(10, 5)) pylab.plot(zoom_signal.sample_times, zoom_signal, label='Signal') pylab.plot(zoom_waveform.sample_times, zoom_waveform, label='Waveform') pylab.xlabel('Time (s)') pylab.ylabel('Strain') pylab.title('Zoomed View') pylab.legend() hp.resize(time_duration * f_sample) snr = matched_filter(hp, signal, psd=psd, low_frequency_cutoff=20) pylab.figure(figsize=[10, 4]) pylab.plot(snr.sample_times, abs(snr)) pylab.ylabel('Signal-to-noise') pylab.xlabel('Time (s)')