We will be using the PyCBC library, which is used to study gravitational-wave data, find astrophysical sources due to compact binary mergers, and study their parameters. These are some of the same tools that the LIGO and Virgo collaborations use to find gravitational waves in LIGO/Virgo data
In this tutorial we will walk through how to get information about the catalog of binary mergers programmatically, and also how to read in detector strain data around each event, or from the full open data set released for LIGO's first observing run.
import sys
!{sys.executable} -m pip install pycbc ligo-common --no-cache-dir
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. Requirement already satisfied: pycbc in /home/ahnitz/projects/env/lib/python2.7/site-packages/PyCBC-50d4a7-py2.7-linux-x86_64.egg (50d4a7) Requirement already satisfied: lalsuite in /home/ahnitz/projects/env/lib/python2.7/site-packages (6.49) Requirement already satisfied: ligo-common in /home/ahnitz/projects/env/lib/python2.7/site-packages (1.0.3) Requirement already satisfied: numpy>=1.16.0 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pycbc) (1.16.6) Requirement already satisfied: Mako>=1.0.1 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pycbc) (1.0.7) Requirement already satisfied: cython>=0.29 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pycbc) (0.29.14) Requirement already satisfied: decorator>=3.4.2 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pycbc) (4.3.0) Requirement already satisfied: matplotlib>=1.5.1 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pycbc) (2.2.4) Requirement already satisfied: pillow in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pycbc) (5.2.0) Requirement already satisfied: h5py>=2.5 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pycbc) (2.8.0) Requirement already satisfied: jinja2 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pycbc) (2.8.1) Requirement already satisfied: mpld3>=0.3 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pycbc) (0.3) Requirement already satisfied: lscsoft-glue>=1.59.3 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pycbc) (1.59.3) Requirement already satisfied: emcee==2.2.1 in /home/ahnitz/projects/env/lib/python2.7/site-packages/emcee-2.2.1-py2.7.egg (from pycbc) (2.2.1) Requirement already satisfied: requests>=1.2.1 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pycbc) (2.18.4) Requirement already satisfied: beautifulsoup4>=4.6.0 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pycbc) (4.6.1) Requirement already satisfied: six>=1.10.0 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pycbc) (1.11.0) Requirement already satisfied: ligo-segments in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pycbc) (1.2.0) Requirement already satisfied: tqdm in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pycbc) (4.31.1) Requirement already satisfied: astropy<3.0.0,>=2.0.3 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pycbc) (2.0.8) Requirement already satisfied: scipy<1.3.0,>=0.16.0 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pycbc) (1.1.0) Requirement already satisfied: python-dateutil in /home/ahnitz/projects/env/lib/python2.7/site-packages (from lalsuite) (2.7.3) Requirement already satisfied: MarkupSafe>=0.9.2 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from Mako>=1.0.1->pycbc) (1.0) Requirement already satisfied: subprocess32 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from matplotlib>=1.5.1->pycbc) (3.5.2) Requirement already satisfied: cycler>=0.10 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from matplotlib>=1.5.1->pycbc) (0.10.0) Requirement already satisfied: backports.functools-lru-cache in /home/ahnitz/projects/env/lib/python2.7/site-packages (from matplotlib>=1.5.1->pycbc) (1.5) Requirement already satisfied: pytz in /home/ahnitz/projects/env/lib/python2.7/site-packages (from matplotlib>=1.5.1->pycbc) (2018.5) Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from matplotlib>=1.5.1->pycbc) (2.2.0) Requirement already satisfied: kiwisolver>=1.0.1 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from matplotlib>=1.5.1->pycbc) (1.0.1) Requirement already satisfied: pyOpenSSL in /home/ahnitz/projects/env/lib/python2.7/site-packages (from lscsoft-glue>=1.59.3->pycbc) (16.2.0) Requirement already satisfied: urllib3<1.23,>=1.21.1 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from requests>=1.2.1->pycbc) (1.22) Requirement already satisfied: idna<2.7,>=2.5 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from requests>=1.2.1->pycbc) (2.6) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from requests>=1.2.1->pycbc) (3.0.4) Requirement already satisfied: certifi>=2017.4.17 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from requests>=1.2.1->pycbc) (2018.4.16) Requirement already satisfied: pytest>=2.8 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from astropy<3.0.0,>=2.0.3->pycbc) (3.7.1) Requirement already satisfied: setuptools in /home/ahnitz/projects/env/lib/python2.7/site-packages (from kiwisolver>=1.0.1->matplotlib>=1.5.1->pycbc) (42.0.1) Requirement already satisfied: cryptography>=1.3.4 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pyOpenSSL->lscsoft-glue>=1.59.3->pycbc) (2.3) Requirement already satisfied: atomicwrites>=1.0 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pytest>=2.8->astropy<3.0.0,>=2.0.3->pycbc) (1.1.5) Requirement already satisfied: more-itertools>=4.0.0 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pytest>=2.8->astropy<3.0.0,>=2.0.3->pycbc) (4.3.0) Requirement already satisfied: pluggy>=0.7 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pytest>=2.8->astropy<3.0.0,>=2.0.3->pycbc) (0.7.1) Requirement already satisfied: attrs>=17.4.0 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pytest>=2.8->astropy<3.0.0,>=2.0.3->pycbc) (18.1.0) Requirement already satisfied: pathlib2>=2.2.0; python_version < "3.6" in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pytest>=2.8->astropy<3.0.0,>=2.0.3->pycbc) (2.3.2) Requirement already satisfied: py>=1.5.0 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pytest>=2.8->astropy<3.0.0,>=2.0.3->pycbc) (1.5.4) Requirement already satisfied: funcsigs; python_version < "3.0" in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pytest>=2.8->astropy<3.0.0,>=2.0.3->pycbc) (1.0.2) Requirement already satisfied: enum34; python_version < "3" in /home/ahnitz/projects/env/lib/python2.7/site-packages (from cryptography>=1.3.4->pyOpenSSL->lscsoft-glue>=1.59.3->pycbc) (1.1.6) Requirement already satisfied: cffi!=1.11.3,>=1.7 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from cryptography>=1.3.4->pyOpenSSL->lscsoft-glue>=1.59.3->pycbc) (1.11.5) Requirement already satisfied: asn1crypto>=0.21.0 in /home/ahnitz/projects/env/lib/python2.7/site-packages (from cryptography>=1.3.4->pyOpenSSL->lscsoft-glue>=1.59.3->pycbc) (0.24.0) Requirement already satisfied: ipaddress; python_version < "3" in /home/ahnitz/projects/env/lib/python2.7/site-packages (from cryptography>=1.3.4->pyOpenSSL->lscsoft-glue>=1.59.3->pycbc) (1.0.22) Requirement already satisfied: scandir; python_version < "3.5" in /home/ahnitz/projects/env/lib/python2.7/site-packages (from pathlib2>=2.2.0; python_version < "3.6"->pytest>=2.8->astropy<3.0.0,>=2.0.3->pycbc) (1.8) Requirement already satisfied: pycparser in /home/ahnitz/projects/env/lib/python2.7/site-packages (from cffi!=1.11.3,>=1.7->cryptography>=1.3.4->pyOpenSSL->lscsoft-glue>=1.59.3->pycbc) (2.18) WARNING: You are using pip version 19.1, however version 20.0.2 is available. You should consider upgrading via the 'pip install --upgrade pip' command.
from pycbc import catalog
### List the mergers in the catalog
for merger_name in catalog.Catalog():
print(merger_name)
GW151012 GW170608 GW170729 GW150914 GW151226 GW170814 GW170817 GW170104 GW170809 GW170818 GW170823
One can also retrieve some of the basic parameters of each source from the catalog directly as follows. Note that all parameters are given in the source frame. This means that they include the effect of redshift.
# Either from the catalog as a whole
c = catalog.Catalog()
mchirp = c.median1d('mchirp')
print(mchirp)
# or from a specific merger
m = catalog.Merger("GW170817")
mchirp_gw170817 = m.median1d('mchirp')
print('GW170817: {}'.format(mchirp_gw170817))
# print parameters that can be read
print(m.data.keys())
[15.2 7.9 35.7 28.6 8.9 24.2 1.186 21.5 25. 26.7 29.3 ] GW170817: 1.186 [u'files', u'distance', u'a_final', u'mass1', u'tc', u'far_gstlal', u'far_pycbc', u'mass2', u'mchirp', u'snr_gstlal', u'redshift', u'far_cwb', u'utctime', u'L_peak', u'sky_size', u'mfinal', u'E_rad', u'chi_eff', u'snr_pycbc', u'snr_cwb']
By default the above interface returns parameters in the source frame. Due to cosmological redshift, gravitational-waves are stretched as they travel. This causes the observed waveform to be different in the detector frame. This corresponds to an observed change in the mass parameters (for example). However, the relationship is fairly straighforward.
m = catalog.Merger('GW150914')
source_mchirp = m.median1d('mchirp')
redshift = m.median1d('redshift')
det_mchirp = source_mchirp * (1 + redshift)
print('Chirp Mass of GW150914')
print('Source Frame: {} Solar Masses'.format(source_mchirp))
print('Detector Frame: {} Solar Masses'.format(det_mchirp))
Chirp Mass of GW150914 Source Frame: 28.6 Solar Masses Detector Frame: 31.174 Solar Masses
In this section, we will look into how to read detector data from the LIGO and Virgo instruments using the PyCBC API. It is possible to both get data around specific events, and also from the full data sets which have been released which cover the S5/S6/O1 LIGO observing runs. Data will be returned as pycbc TimeSeries objects.
One can directly retrieve data around a specific even. Typically this data is centered on the event, though restrictions may apply which have not allowed this. This method by default gets the smallest version of the dataset. If additional data or specific versions are required, please see the following two additional ways to access data.
%matplotlib inline
import pylab
m = catalog.Merger("GW150914")
# Get the time series data around GW150914 from Hanford
# 'ts_han' is a pycbc.types.TimeSeries object which contains
# gravitational-wave strain in this instance and has metadata
# such as the start time, and sample rate.
ts_han = m.strain('H1')
# And now livingston
ts_liv = m.strain('L1')
# We can see how much data was returned and its boundaries
# Note: All times are given in seconds since the GPS time epoch
print("Duration: {}s Start: {} End: {}".format(ts_han.duration,
int(ts_han.start_time),
int(ts_han.end_time)))
# We can directly plot the time series as follows
pylab.plot(ts_han.sample_times, ts_han)
pylab.ylabel('Strain')
pylab.xlabel('Time (s)')
pylab.show()
Duration: 32.0s Start: 1126259447 End: 1126259479
In this section we show how to read data from the bulk data release by LIGO. This currently covers the periods of teh S5, S6, and O1 analyses.
from pycbc.frame import query_and_read_frame
# Retrieve the approximate time of the merger
m = catalog.Merger("GW150914")
start = m.time - 32
end = m.time + 32
# Get 64 seconds of data roughly around GW150914
# The start / end time may be any in the publicly available data sets.
ts = query_and_read_frame('LOSC', 'H1:LOSC-STRAIN', start, end)
# If we wanted to retreive data from the Livingston detector
# we'd use the following command instead
# ts = query_and_read_frame('LOSC', 'L1:LOSC-STRAIN', start, end)
print("Returned {}s of data at {}Hz".format(ts.duration, ts.sample_rate))
Returned 64.0s of data at 4096Hz
If you store LIGO data on your own computer then you can directly read in the data as follows.
# We'll first download some data for this demonstration
!curl -O -J -L https://losc.ligo.org/s/events/LVT151012/H-H1_LOSC_4_V2-1128678884-32.gwf
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 266 100 266 0 0 310 0 --:--:-- --:--:-- --:--:-- 309 100 1004k 100 1004k 0 0 322k 0 0:00:03 0:00:03 --:--:-- 576k
from pycbc.frame import read_frame
# Read the data directly from the Gravitational-Wave Frame (GWF) file.
file_name = "H-H1_LOSC_4_V2-1128678884-32.gwf"
# LOSC bulk data typically uses the same convention for internal channels names
# Strain is typically IFO:LOSC-STRAIN, where IFO can be H1/L1/V1.
channel_name = "H1:LOSC-STRAIN"
start = 1128678884
end = start + 32
ts = read_frame(file_name, channel_name, start, end)