{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport h5py\n\nfrom scipy.io import wavfile\n\nimport matplotlib.pyplot as plt\nimport matplotlib.cm as cmap\nimport matplotlib.colors as mpl_colors\nimport seaborn as sns\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2022-10-06T19:26:54.792133Z","iopub.execute_input":"2022-10-06T19:26:54.792632Z","iopub.status.idle":"2022-10-06T19:26:56.306928Z","shell.execute_reply.started":"2022-10-06T19:26:54.792592Z","shell.execute_reply":"2022-10-06T19:26:56.305689Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<center style=\"font-family:verdana;\"><h1 style=\"font-size:200%; padding: 10px; background: #DC143C;\"><b style=\"color:white;\">GW150914 - The First Direct Detection of Gravitational Waves</b></h1></center>","metadata":{}},{"cell_type":"markdown","source":"GW150914 - The First Direct Detection of Gravitational Waves\n\n\"On February 11, 2016, the LIGO Scientific Collaboration and Virgo Collaboration announced the first confirmed observation of gravitational waves from colliding black holes. The gravitational wave signals were observed by the LIGO's twin observatories on September 14, 2015. This confirms a key prediction of Einstein's theory of general relativity and provides the first direct evidence that black holes merge.\"\n\nhttps://www.ligo.org/detections/GW150914.php","metadata":{}},{"cell_type":"markdown","source":"![](https://www.ligo.org/detections/GW150914/gw150914_infographic.png)ligo.org","metadata":{}},{"cell_type":"code","source":"# Other  \nimport librosa\nimport librosa.display\nimport json\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport tensorflow as tf\nfrom matplotlib.pyplot import specgram\nimport pandas as pd\nimport seaborn as sns\nimport glob \nimport os\nfrom tqdm import tqdm\nimport pickle\nimport IPython.display as ipd  # To play sound in the notebook","metadata":{"execution":{"iopub.status.busy":"2022-10-06T19:27:40.227094Z","iopub.execute_input":"2022-10-06T19:27:40.227501Z","iopub.status.idle":"2022-10-06T19:27:47.368383Z","shell.execute_reply.started":"2022-10-06T19:27:40.227467Z","shell.execute_reply":"2022-10-06T19:27:47.36694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Listen to GW150914 in Hanford\n\n\"Here we’ll make a frequency shifted and slowed version of GW150914 as it can be heard in the Hanford data\"\n\nhttps://pycbc.org/pycbc/latest/html/gw150914.html","metadata":{}},{"cell_type":"code","source":"#Codes by Eu Jin Lok https://www.kaggle.com/ejlok1/audio-emotion-part-5-data-augmentation/notebook\n\n# Use one audio file in previous parts again\nfname = '/kaggle/input/cusersmarildownloadsgw150914-h1-chirpwav/gw150914_h1_chirp.wav'  \ndata, sampling_rate = librosa.load(fname)\nplt.figure(figsize=(15, 5))\nlibrosa.display.waveshow(data, sr=sampling_rate)#waveplot doesn't work anymore\n\n# Paly it again to refresh our memory\nipd.Audio(data, rate=sampling_rate)","metadata":{"execution":{"iopub.status.busy":"2022-10-06T19:28:06.043666Z","iopub.execute_input":"2022-10-06T19:28:06.044466Z","iopub.status.idle":"2022-10-06T19:28:08.396388Z","shell.execute_reply.started":"2022-10-06T19:28:06.044417Z","shell.execute_reply":"2022-10-06T19:28:08.395233Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install feature_engine 2>/dev/null 1>&2\n!pip install fastparquet 2>/dev/null 1>&2\n!pip install git+https://github.com/PyFstat/PyFstat@python37 2>/dev/null 1>&2  ","metadata":{"_kg_hide-output":true,"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-10-06T19:59:31.866503Z","iopub.execute_input":"2022-10-06T19:59:31.867057Z","iopub.status.idle":"2022-10-06T20:00:31.785411Z","shell.execute_reply.started":"2022-10-06T19:59:31.867013Z","shell.execute_reply":"2022-10-06T20:00:31.783323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Jose Cáliz https://www.kaggle.com/code/jcaliz/g2net-eda-that-gives-you-insights\n\n# Read file\nfirst_5_files = os.listdir(\n    '../input/g2net-detecting-continuous-gravitational-waves/train/'\n)[:5]\n\nfor filename in first_5_files:\n    f = h5py.File(f'../input/g2net-detecting-continuous-gravitational-waves/train/{filename}', 'r')\n\n    # print dataset name contained in file\n    print(f'Groups in {filename}: ', list(f.keys()))","metadata":{"execution":{"iopub.status.busy":"2022-10-06T19:24:36.718378Z","iopub.execute_input":"2022-10-06T19:24:36.718784Z","iopub.status.idle":"2022-10-06T19:24:36.770538Z","shell.execute_reply.started":"2022-10-06T19:24:36.718748Z","shell.execute_reply":"2022-10-06T19:24:36.769009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code by Jose Cáliz https://www.kaggle.com/code/jcaliz/g2net-eda-that-gives-you-insights\n\nfilename = '5b9f01d0f'\ndset = h5py.File(\n    f'../input/g2net-detecting-continuous-gravitational-waves/train/{filename}.hdf5', 'r'\n)[filename]\n\nprint('Groups/Datasets inside 5b9f01d0f', dset.keys())\n\nfor group in dset.keys():\n    if isinstance(dset[group], h5py._hl.dataset.Dataset):\n        continue\n        \n    print(f'Groups inside {group}', dset[group].keys())","metadata":{"execution":{"iopub.status.busy":"2022-10-06T19:46:51.407891Z","iopub.execute_input":"2022-10-06T19:46:51.408316Z","iopub.status.idle":"2022-10-06T19:46:51.420338Z","shell.execute_reply.started":"2022-10-06T19:46:51.408273Z","shell.execute_reply":"2022-10-06T19:46:51.418794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Save Quentin's snippet below for next time.\n\nClean, to-the point spectograms subplots.\n\nhttps://www.kaggle.com/code/qrendu/plot-spectrograms","metadata":{}},{"cell_type":"code","source":"#Code by Quentin R https://www.kaggle.com/code/qrendu/plot-spectrograms\n\n# function to plot spectrogram given data name\ndef plot_spectrogram(filename, LIGO=\"H1\"):\n  # open file\n  f = h5py.File('/kaggle/input/g2net-detecting-continuous-gravitational-waves/train/'+filename, 'r')\n\n  # read fourier transform coefficients\n  LIGO_SFT = f[filename[:-5]][LIGO]['SFTs']\n  spectrogram = np.absolute(np.array(LIGO_SFT[:]))\n\n  # plot spectrogram\n  fig = plt.figure(num=None, figsize=(30, 4), dpi=80, facecolor='r', edgecolor='k')\n  fig.subplots_adjust(top=0.99, bottom=0.02, left=0.02, right=0.99)\n  plt.imshow(spectrogram, cmap='turbo', aspect='equal', origin ='lower')\n\nfilename_list = ['001121a05.hdf5',\n                 '004f23b2d.hdf5',\n                 '02c478b09.hdf5',\n                 '03189bb3d.hdf5',\n                 '01bcf6533.hdf5']\n\nfor elt in filename_list:\n    plot_spectrogram(elt)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-06T20:11:08.551556Z","iopub.execute_input":"2022-10-06T20:11:08.551979Z","iopub.status.idle":"2022-10-06T20:11:13.256685Z","shell.execute_reply.started":"2022-10-06T20:11:08.551924Z","shell.execute_reply":"2022-10-06T20:11:13.255153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Acknowledgements:\n\nListen to GW150914 https://pycbc.org/pycbc/latest/html/gw150914.html\n\nQuentin R https://www.kaggle.com/code/qrendu/plot-spectrograms\n\nJose Cáliz https://www.kaggle.com/code/jcaliz/g2net-eda-that-gives-you-insights\n\nEu Jin Lok https://www.kaggle.com/ejlok1/audio-emotion-part-5-data-augmentation/notebook","metadata":{}}]}