-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
755 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ | |
coherence | ||
transfer_function | ||
rayleigh | ||
inject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env python | ||
|
||
|
||
# Copyright (C) Duncan Macleod (2013) | ||
# | ||
# This file is part of GWpy. | ||
# | ||
# GWpy is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# GWpy is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with GWpy. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Inject a known signal into a `FrequencySeries` | ||
It can often be useful to add some known signal to inherently random | ||
or noisy data. For example, one might want to investigate what | ||
would happen if a binary black hole merger signal occured at or near | ||
the time of a glitch. In LIGO data analysis, this procedure is referred | ||
to as an _injection_. | ||
In the example below we will create a stream of random, white Gaussian | ||
noise, then inject a loud, steady sinuosoid. We will do this in the | ||
frequency domain because it is much easier to model a sinusoid there. | ||
""" | ||
|
||
__author__ = "Alex Urban <alexander.urban@ligo.org>" | ||
__currentmodule__ = 'gwpy.timeseries' | ||
|
||
# First, we prepare one second of Gaussian noise: | ||
|
||
from numpy import random | ||
from gwpy.timeseries import TimeSeries | ||
noise = TimeSeries(random.normal(scale=.1, size=1024), sample_rate=1024) | ||
|
||
# To inject a signal in the frequency domain, we need to take an FFT: | ||
|
||
noisefd = noise.fft() | ||
|
||
# We can now easily inject a loud sinusoid of unit amplitude at, say, | ||
# 30 Hz. To do this, we use :meth:`~gwpy.types.series.Series.inject`. | ||
|
||
import numpy | ||
from gwpy.frequencyseries import FrequencySeries | ||
signal = FrequencySeries(numpy.array([1.]), f0=30, df=noisefd.df) | ||
injfd = noisefd.inject(signal) | ||
|
||
# We can then visualize the data before and after injection in the frequency | ||
# domain: | ||
|
||
from gwpy.plotter import FrequencySeriesPlot | ||
plot = FrequencySeriesPlot(numpy.abs(noisefd), numpy.abs(injfd), sep=True, | ||
sharex=True, sharey=True) | ||
plot.show() | ||
|
||
# Finally, for completeness we can visualize the effect before and after | ||
# injection back in the time domain: | ||
|
||
from gwpy.plotter import TimeSeriesPlot | ||
inj = injfd.ifft() | ||
plot = TimeSeriesPlot(noise, inj, sep=True, sharex=True, sharey=True) | ||
plot.show() | ||
|
||
# We can see why sinusoids are easier to inject in the frequency domain: | ||
# they only require adding at a single frequency. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ | |
statevector | ||
qscan | ||
pycbc-snr | ||
inject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env python | ||
|
||
|
||
# Copyright (C) Duncan Macleod (2013) | ||
# | ||
# This file is part of GWpy. | ||
# | ||
# GWpy is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# GWpy is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with GWpy. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Inject a known signal into a `TimeSeries` | ||
It can often be useful to add some known signal to an inherently random | ||
or noisy timeseries. For example, one might want to examine what | ||
would happen if a binary black hole merger signal occured at or near | ||
the time of a glitch. In LIGO data analysis, this procedure is referred | ||
to as an _injection_. | ||
In the example below, we will create a stream of random, white Gaussian | ||
noise, then inject a simulation of GW150914 into it at a known time. | ||
""" | ||
|
||
__author__ = "Alex Urban <alexander.urban@ligo.org>" | ||
__currentmodule__ = 'gwpy.timeseries' | ||
|
||
# First, we prepare one second of Gaussian noise: | ||
|
||
from numpy import random | ||
from gwpy.timeseries import TimeSeries | ||
noise = TimeSeries(random.normal(scale=.1, size=16384), sample_rate=16384) | ||
|
||
# Then we can download a simulation of the GW150914 signal from LOSC: | ||
|
||
from astropy.utils.data import get_readable_fileobj | ||
source = 'https://losc.ligo.org/s/events/GW150914/P150914/' | ||
url = '%s/fig2-unfiltered-waveform-H.txt' % source | ||
with get_readable_fileobj(url) as f: | ||
signal = TimeSeries.read(f, format='txt') | ||
signal.t0 = .5 # make sure this intersects with noise time samples | ||
|
||
# Note, since this simulation cuts off before a certain time, it is | ||
# important to taper its ends to zero to avoid ringing artifacts. | ||
# We can accomplish this using the | ||
# :meth:`~gwpy.timeseries.TimeSeries.taper` method. | ||
|
||
signal = signal.taper() | ||
|
||
# Since the time samples overlap, we can inject this into our noise data | ||
# using :meth:`~gwpy.types.series.Series.inject`: | ||
|
||
data = noise.inject(signal) | ||
|
||
# Finally, we can visualize the full process in the time domain: | ||
|
||
from gwpy.plotter import TimeSeriesPlot | ||
plot = TimeSeriesPlot(noise, signal, data, sep=True, sharex=True, sharey=True) | ||
plot.set_epoch(0) | ||
plot.show() | ||
|
||
# We can clearly see that the loud GW150914-like signal has been layered | ||
# on top of Gaussian noise with the correct amplitude and phase evolution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.