{"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":"!python -m pip install gwpy\n# !pip install astropy==4.2.1\n!pip install astropy\n!pip install nnAudio\n\n# from google.colab import drive\n# drive.mount('/content/gdrive')\n# import os\n\n# One time ONLY - Installation of Kaggle package\n# !pip install --upgrade --force-reinstall --no-deps kaggle\n\n# TO IMPORT DATA - ONE TIME CODE\n# os.environ['KAGGLE_CONFIG_DIR']='/content/gdrive/MyDrive/Kaggle_Datasets'\n# os.chdir('/content/gdrive/MyDrive/G2Net_Gravitational_Waves')\n# !kaggle competitions download -c g2net-gravitational-wave-detection\n\n#Unzip Data\n# !unzip /content/gdrive/MyDrive/G2Net_Gravitational_Waves/g2net-gravitational-wave-detection.zip","metadata":{"execution":{"iopub.status.busy":"2021-08-26T16:37:56.461708Z","iopub.execute_input":"2021-08-26T16:37:56.462049Z","iopub.status.idle":"2021-08-26T16:38:25.522982Z","shell.execute_reply.started":"2021-08-26T16:37:56.461972Z","shell.execute_reply":"2021-08-26T16:38:25.522054Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport seaborn as sns\nfrom scipy import signal\nfrom gwpy.timeseries import TimeSeries\nfrom gwpy.plot import Plot\nimport numpy as np\nfrom sklearn.preprocessing import MinMaxScaler\nfrom PIL import Image\nfrom glob import glob\nfrom matplotlib import pyplot as plt\nimport random\nfrom colorama import Fore, Back, Style\nplt.style.use('ggplot')\nimport warnings\nwarnings.filterwarnings('ignore')\nfrom sklearn.model_selection import train_test_split\n\nfrom tensorflow.keras.utils import Sequence\n\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense, Dropout, Flatten, Conv1D, MaxPool1D, BatchNormalization\nfrom tensorflow.keras.optimizers import RMSprop, Adam\n\nimport torch\nfrom nnAudio.Spectrogram import CQT1992v2","metadata":{"execution":{"iopub.status.busy":"2021-08-26T16:38:25.524764Z","iopub.execute_input":"2021-08-26T16:38:25.52511Z","iopub.status.idle":"2021-08-26T16:38:34.439565Z","shell.execute_reply.started":"2021-08-26T16:38:25.525074Z","shell.execute_reply":"2021-08-26T16:38:34.438623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Checking the contents of one file\nroot_dir = \"../input/g2net-gravitational-wave-detection/\"\nfile = root_dir + 'train/0/0/0/000a5b6e5c.npy'\ndata = np.load(file)\nprint(data.shape)\nprint(data)\n# print(data[0, :].shape)\n# print(data[1, :].shape)\n# print(data[2, :].shape)\nprint(\"data[0, :] is \", data[0, :])\n# data_1","metadata":{"execution":{"iopub.status.busy":"2021-08-26T16:39:01.671828Z","iopub.execute_input":"2021-08-26T16:39:01.67218Z","iopub.status.idle":"2021-08-26T16:39:01.699203Z","shell.execute_reply.started":"2021-08-26T16:39:01.672128Z","shell.execute_reply":"2021-08-26T16:39:01.698318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# The gwpy's TimeSeries function expects array-like input data array as its first argument\n# and sample_rate : float, Quantity, optional the rate of samples per second (Hertz)\ndef get_tseries_from_file(file_name):\n  t_data = np.load(file_name)\n  tseries1 = TimeSeries(t_data[0,:], sample_rate=2048)\n  tseries2 = TimeSeries(t_data[1,:], sample_rate=2048)\n  tseries3 = TimeSeries(t_data[2,:], sample_rate=2048)\n  return tseries1, tseries2, tseries3\n\n''' Multi-data plots with gwpy.plot\n\nhttps://gwpy.github.io/docs/latest/plot/index.html#multi-data-plots - \n\nGWpy enables trivial generation of plots with multiple datasets. The Plot constructor will accept an arbitrary collection of data objects and will build a figure with the required geometry automatically. By default, a flat set of objects are shown on the same axes: \n\nseparate=True can be given to show each dataset on a separate Axes\n\nThe returned object is a Plot, a sub-class of matplotlib.figure. Figure adapted for GPS time-stamped data. Customisations of the figure or the underlying Axes can be done using standard matplotlib methods. Hence I can use .gca()\n\n.gac() - Get the current Axes instance on the current figure matching the given keyword args, or create one. The plt.gca() function gets the current axes so that you can draw on it directly. \n\nhttps://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.gca.html\n\n'''\n\ndef plot_tseries(t1, t2, t3):\n  plot = Plot(t1, t2, t3, separate=True, sharex=True, figsize=[20, 12])\n  ax = plot.gca()\n  ax.set_xlim(0, 2)\n  ax.set_xlabel('Time [s]')\n  plt.show()\n  \nfile_1 = root_dir + 'train/0/0/0/000a5b6e5c.npy'\n  \ntseries1, tseries2, tseries3 = get_tseries_from_file(file_1)\n\n# Plotting the 3 TimeSeries\nplot_tseries(tseries1, tseries2, tseries3)\n  ","metadata":{"execution":{"iopub.status.busy":"2021-08-26T16:39:08.042086Z","iopub.execute_input":"2021-08-26T16:39:08.042553Z","iopub.status.idle":"2021-08-26T16:39:11.741824Z","shell.execute_reply.started":"2021-08-26T16:39:08.042514Z","shell.execute_reply":"2021-08-26T16:39:11.740992Z"},"trusted":true},"execution_count":null,"outputs":[]}]}