Skip to content

Instantly share code, notes, and snippets.

@duncanmmacleod
Last active April 3, 2019 10:57
Show Gist options
  • Save duncanmmacleod/7a662e1217569e4b46071fa92ebc163a to your computer and use it in GitHub Desktop.
Save duncanmmacleod/7a662e1217569e4b46071fa92ebc163a to your computer and use it in GitHub Desktop.
Make a simple plot of the gravitational-wave signal of GW150914 in both LIGO detectors
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# The MIT License (MIT)
# Copyright (c) 2019 Duncan Macleod
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
# OR OTHER DEALINGS IN THE SOFTWARE.
"""Plot filtered LIGO data for GW150914
"""
__author__ = "Duncan Macleod <duncan.macleod@ligo.org>"
__license__ = "MIT"
from matplotlib import pyplot
from gwpy.plot import Plot
from gwpy.signal import filter_design
from gwpy.timeseries import TimeSeries
pyplot.style.use('dark_background')
# get data
lho = TimeSeries.fetch_open_data('H1', 1126259446, 1126259478, cache=True)
llo = TimeSeries.fetch_open_data('L1', 1126259446, 1126259478, cache=True)
# design filter to extract signal
bp = filter_design.bandpass(50, 250, lho.sample_rate)
notches = [filter_design.notch(line, lho.sample_rate) for line in (60,)]
zpk = filter_design.concatenate_zpks(bp, *notches)
# filter data
lhof = lho.filter(zpk, filtfilt=True).crop(1126259462, 1126259462.6)
llof = llo.filter(zpk, filtfilt=True).crop(1126259462, 1126259462.6)
# shift l1 data to account for time-delay and orientation
llof.t0 += 0.0069 * llof.t0.unit
llof *= -1
# plot
plot = Plot(figsize=[12, 4])
ax = plot.gca()
ax.plot(lhof, label='LIGO-Hanford', color='gwpy:ligo-hanford')
ax.plot(llof, label='LIGO-Livingston', color='gwpy:ligo-livingston')
ax.set_xscale('seconds')
ax.set_xlabel('Time (seconds) from 2015-09-14 09:50:45 UTC')
ax.set_ylabel('Amplitude (strain)')
ax.legend(loc='lower right', bbox_to_anchor=(1, 1), frameon=False)
plot.save('3-gw150914.png', dpi=1200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment