import sys
!{sys.executable} -m pip install pycbc ligo-common --no-cache-dir
Requirement already satisfied: pycbc in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages/PyCBC-9rc6331-py3.7-linux-x86_64.egg (9rc6331) Requirement already satisfied: lalsuite in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (6.70) Requirement already satisfied: ligo-common in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (1.0.3) Requirement already satisfied: numpy>=1.16.0 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (1.19.0) Requirement already satisfied: Mako>=1.0.1 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (1.1.3) Requirement already satisfied: cython>=0.29 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (0.29.20) Requirement already satisfied: decorator>=3.4.2 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (4.4.2) Requirement already satisfied: matplotlib>=1.5.1 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (3.2.2) Requirement already satisfied: pillow in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (7.1.2) Requirement already satisfied: h5py>=2.5 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (2.10.0) Requirement already satisfied: jinja2 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (2.11.2) Requirement already satisfied: mpld3>=0.3 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (0.5.1) Requirement already satisfied: lscsoft-glue>=1.59.3 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (2.0.0) Requirement already satisfied: emcee==2.2.1 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (2.2.1) Requirement already satisfied: requests>=1.2.1 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (2.24.0) Requirement already satisfied: beautifulsoup4>=4.6.0 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (4.9.1) Requirement already satisfied: six>=1.10.0 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (1.15.0) Requirement already satisfied: ligo-segments in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (1.2.0) Requirement already satisfied: tqdm in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (4.46.1) Requirement already satisfied: gwdatafind in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (1.0.4) Requirement already satisfied: astropy>=2.0.3 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (4.0.1.post1) Requirement already satisfied: scipy>=0.16.0 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (1.5.0) Requirement already satisfied: python-dateutil in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from lalsuite) (2.8.1) Requirement already satisfied: MarkupSafe>=0.9.2 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from Mako>=1.0.1->pycbc) (1.1.1) Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from matplotlib>=1.5.1->pycbc) (2.4.7) Requirement already satisfied: kiwisolver>=1.0.1 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from matplotlib>=1.5.1->pycbc) (1.2.0) Requirement already satisfied: cycler>=0.10 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from matplotlib>=1.5.1->pycbc) (0.10.0) Requirement already satisfied: pyOpenSSL in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from lscsoft-glue>=1.59.3->pycbc) (19.1.0) Requirement already satisfied: chardet<4,>=3.0.2 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from requests>=1.2.1->pycbc) (3.0.4) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from requests>=1.2.1->pycbc) (1.25.9) Requirement already satisfied: certifi>=2017.4.17 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from requests>=1.2.1->pycbc) (2020.6.20) Requirement already satisfied: idna<3,>=2.5 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from requests>=1.2.1->pycbc) (2.9) Requirement already satisfied: soupsieve>1.2 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from beautifulsoup4>=4.6.0->pycbc) (2.0.1) Requirement already satisfied: cryptography>=2.8 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pyOpenSSL->lscsoft-glue>=1.59.3->pycbc) (2.9.2) Requirement already satisfied: cffi!=1.11.3,>=1.8 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from cryptography>=2.8->pyOpenSSL->lscsoft-glue>=1.59.3->pycbc) (1.14.0) Requirement already satisfied: pycparser in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from cffi!=1.11.3,>=1.8->cryptography>=2.8->pyOpenSSL->lscsoft-glue>=1.59.3->pycbc) (2.20)
#Set up the libraries we need and download the data
!wget https://losc.ligo.org/s/events/GW150914/H-H1_LOSC_4_V2-1126259446-32.gwf
--2020-06-27 14:23:29-- https://losc.ligo.org/s/events/GW150914/H-H1_LOSC_4_V2-1126259446-32.gwf Resolving losc.ligo.org (losc.ligo.org)... 131.215.113.73 Connecting to losc.ligo.org (losc.ligo.org)|131.215.113.73|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://www.gw-openscience.org/s/events/GW150914/H-H1_LOSC_4_V2-1126259446-32.gwf [following] --2020-06-27 14:23:30-- https://www.gw-openscience.org/s/events/GW150914/H-H1_LOSC_4_V2-1126259446-32.gwf Resolving www.gw-openscience.org (www.gw-openscience.org)... 131.215.113.73 Connecting to www.gw-openscience.org (www.gw-openscience.org)|131.215.113.73|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 1029288 (1005K) Saving to: ‘H-H1_LOSC_4_V2-1126259446-32.gwf’ H-H1_LOSC_4_V2-1126 100%[===================>] 1005K 613KB/s in 1.6s 2020-06-27 14:23:33 (613 KB/s) - ‘H-H1_LOSC_4_V2-1126259446-32.gwf’ saved [1029288/1029288]
from pycbc.frame import read_frame
from pycbc.filter import highpass_fir, lowpass_fir
from pycbc.psd import welch, interpolate
from pycbc.types import TimeSeries
# Read data and remove low frequency content
fname = 'H-H1_LOSC_4_V2-1126259446-32.gwf'
h1 = highpass_fir(read_frame(fname, 'H1:LOSC-STRAIN'), 15.0, 8)
# estimate the noise spectrum and whiten
psd = interpolate(welch(h1), 1.0 / 32)
white_strain = (h1.to_frequencyseries() / psd ** 0.5 * psd.delta_f).to_timeseries()
# remove some of the high and low frequencies
smooth = highpass_fir(white_strain, 25, 8)
smooth = lowpass_fir(white_strain, 250, 8)
# slow the data down by a factor of 4
smooth = TimeSeries(smooth, delta_t=smooth.delta_t*4)
#strech out and shift the frequency upwards by 300 Hz to aid human hearing
frequency_shift = 300.0
fdata = smooth.to_frequencyseries()
fdata.roll(int(frequency_shift / fdata.delta_f))
smooth = fdata.to_timeseries()
#Take slice around signal
smooth = smooth[len(smooth)//2 - 1500:len(smooth)//2 + 3000]
smooth.save_to_wav('gw150914_h1_chirp.wav')
--------------------------------------------------------------------------- error Traceback (most recent call last) <ipython-input-3-554ec5470193> in <module> 27 #Take slice around signal 28 smooth = smooth[len(smooth)//2 - 1500:len(smooth)//2 + 3000] ---> 29 smooth.save_to_wav('gw150914_h1_chirp.wav') ~/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages/PyCBC-9rc6331-py3.7-linux-x86_64.egg/pycbc/types/timeseries.py in save_to_wav(self, file_name) 452 """ 453 scaled = _numpy.int16(self.numpy()/max(abs(self)) * 32767) --> 454 write_wav(file_name, self.sample_rate, scaled) 455 456 def psd(self, segment_duration, **kwds): ~/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages/scipy/io/wavfile.py in write(filename, rate, data) 697 698 fmt_chunk_data = struct.pack('<HHIIHH', format_tag, channels, fs, --> 699 bytes_per_second, block_align, bit_depth) 700 if not (dkind == 'i' or dkind == 'u'): 701 # add cbSize field for non-PCM files error: required argument is not an integer