{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Listen to the merger converted to audio ###" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "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)\n", "Requirement already satisfied: lalsuite in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (6.70)\n", "Requirement already satisfied: ligo-common in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (1.0.3)\n", "Requirement already satisfied: numpy>=1.16.0 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (1.19.0)\n", "Requirement already satisfied: Mako>=1.0.1 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (1.1.3)\n", "Requirement already satisfied: cython>=0.29 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (0.29.20)\n", "Requirement already satisfied: decorator>=3.4.2 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (4.4.2)\n", "Requirement already satisfied: matplotlib>=1.5.1 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (3.2.2)\n", "Requirement already satisfied: pillow in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (7.1.2)\n", "Requirement already satisfied: h5py>=2.5 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (2.10.0)\n", "Requirement already satisfied: jinja2 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (2.11.2)\n", "Requirement already satisfied: mpld3>=0.3 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (0.5.1)\n", "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)\n", "Requirement already satisfied: emcee==2.2.1 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (2.2.1)\n", "Requirement already satisfied: requests>=1.2.1 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (2.24.0)\n", "Requirement already satisfied: beautifulsoup4>=4.6.0 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (4.9.1)\n", "Requirement already satisfied: six>=1.10.0 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (1.15.0)\n", "Requirement already satisfied: ligo-segments in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (1.2.0)\n", "Requirement already satisfied: tqdm in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (4.46.1)\n", "Requirement already satisfied: gwdatafind in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (1.0.4)\n", "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)\n", "Requirement already satisfied: scipy>=0.16.0 in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from pycbc) (1.5.0)\n", "Requirement already satisfied: python-dateutil in /home/ahnitz/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages (from lalsuite) (2.8.1)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n", "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)\n" ] } ], "source": [ "import sys\n", "!{sys.executable} -m pip install pycbc ligo-common --no-cache-dir" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "--2020-06-27 14:23:29-- https://losc.ligo.org/s/events/GW150914/H-H1_LOSC_4_V2-1126259446-32.gwf\n", "Resolving losc.ligo.org (losc.ligo.org)... 131.215.113.73\n", "Connecting to losc.ligo.org (losc.ligo.org)|131.215.113.73|:443... connected.\n", "HTTP request sent, awaiting response... 302 Found\n", "Location: https://www.gw-openscience.org/s/events/GW150914/H-H1_LOSC_4_V2-1126259446-32.gwf [following]\n", "--2020-06-27 14:23:30-- https://www.gw-openscience.org/s/events/GW150914/H-H1_LOSC_4_V2-1126259446-32.gwf\n", "Resolving www.gw-openscience.org (www.gw-openscience.org)... 131.215.113.73\n", "Connecting to www.gw-openscience.org (www.gw-openscience.org)|131.215.113.73|:443... connected.\n", "HTTP request sent, awaiting response... 200 OK\n", "Length: 1029288 (1005K)\n", "Saving to: ‘H-H1_LOSC_4_V2-1126259446-32.gwf’\n", "\n", "H-H1_LOSC_4_V2-1126 100%[===================>] 1005K 613KB/s in 1.6s \n", "\n", "2020-06-27 14:23:33 (613 KB/s) - ‘H-H1_LOSC_4_V2-1126259446-32.gwf’ saved [1029288/1029288]\n", "\n" ] } ], "source": [ "#Set up the libraries we need and download the data\n", "!wget https://losc.ligo.org/s/events/GW150914/H-H1_LOSC_4_V2-1126259446-32.gwf" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "ename": "error", "evalue": "required argument is not an integer", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31merror\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 27\u001b[0m \u001b[0;31m#Take slice around signal\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 28\u001b[0m \u001b[0msmooth\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msmooth\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msmooth\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m//\u001b[0m\u001b[0;36m2\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0;36m1500\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msmooth\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m//\u001b[0m\u001b[0;36m2\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m3000\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 29\u001b[0;31m \u001b[0msmooth\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msave_to_wav\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'gw150914_h1_chirp.wav'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32m~/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages/PyCBC-9rc6331-py3.7-linux-x86_64.egg/pycbc/types/timeseries.py\u001b[0m in \u001b[0;36msave_to_wav\u001b[0;34m(self, file_name)\u001b[0m\n\u001b[1;32m 452\u001b[0m \"\"\"\n\u001b[1;32m 453\u001b[0m \u001b[0mscaled\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_numpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mint16\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnumpy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mabs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0;36m32767\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 454\u001b[0;31m \u001b[0mwrite_wav\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfile_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msample_rate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mscaled\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 455\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 456\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mpsd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msegment_duration\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/projects/PyCBC-Tutorials/env/lib/python3.7/site-packages/scipy/io/wavfile.py\u001b[0m in \u001b[0;36mwrite\u001b[0;34m(filename, rate, data)\u001b[0m\n\u001b[1;32m 697\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 698\u001b[0m fmt_chunk_data = struct.pack(' 699\u001b[0;31m bytes_per_second, block_align, bit_depth)\n\u001b[0m\u001b[1;32m 700\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mdkind\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'i'\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0mdkind\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'u'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 701\u001b[0m \u001b[0;31m# add cbSize field for non-PCM files\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31merror\u001b[0m: required argument is not an integer" ] } ], "source": [ "from pycbc.frame import read_frame\n", "from pycbc.filter import highpass_fir, lowpass_fir\n", "from pycbc.psd import welch, interpolate\n", "from pycbc.types import TimeSeries\n", "\n", "# Read data and remove low frequency content\n", "fname = 'H-H1_LOSC_4_V2-1126259446-32.gwf'\n", "h1 = highpass_fir(read_frame(fname, 'H1:LOSC-STRAIN'), 15.0, 8)\n", "\n", "# estimate the noise spectrum and whiten\n", "psd = interpolate(welch(h1), 1.0 / 32)\n", "white_strain = (h1.to_frequencyseries() / psd ** 0.5 * psd.delta_f).to_timeseries()\n", "\n", "# remove some of the high and low frequencies\n", "smooth = highpass_fir(white_strain, 25, 8)\n", "smooth = lowpass_fir(white_strain, 250, 8)\n", "\n", "# slow the data down by a factor of 4\n", "smooth = TimeSeries(smooth, delta_t=smooth.delta_t*4)\n", "\n", "#strech out and shift the frequency upwards by 300 Hz to aid human hearing\n", "frequency_shift = 300.0\n", "fdata = smooth.to_frequencyseries()\n", "fdata.roll(int(frequency_shift / fdata.delta_f))\n", "smooth = fdata.to_timeseries()\n", "\n", "#Take slice around signal\n", "smooth = smooth[len(smooth)//2 - 1500:len(smooth)//2 + 3000]\n", "smooth.save_to_wav('gw150914_h1_chirp.wav')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Downlod your audio file ###\n", " 1. If using JupyterLab, your file should show up in the sidebar\n", " 2. Select and download gw150914_h1_chirp.wav" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.4" } }, "nbformat": 4, "nbformat_minor": 2 }