{"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)\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\n# for 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","execution":{"iopub.status.busy":"2022-12-02T16:58:27.32642Z","iopub.execute_input":"2022-12-02T16:58:27.326871Z","iopub.status.idle":"2022-12-02T16:58:27.332934Z","shell.execute_reply.started":"2022-12-02T16:58:27.326835Z","shell.execute_reply":"2022-12-02T16:58:27.331894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import h5py\nfrom glob import glob\nfrom pathlib import Path","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:27.84618Z","iopub.execute_input":"2022-12-02T16:58:27.846638Z","iopub.status.idle":"2022-12-02T16:58:27.885343Z","shell.execute_reply.started":"2022-12-02T16:58:27.846598Z","shell.execute_reply":"2022-12-02T16:58:27.883951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport matplotlib as mpl","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:28.054227Z","iopub.execute_input":"2022-12-02T16:58:28.05467Z","iopub.status.idle":"2022-12-02T16:58:28.060484Z","shell.execute_reply.started":"2022-12-02T16:58:28.054632Z","shell.execute_reply":"2022-12-02T16:58:28.059022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from pathlib import Path\nimport shutil\n\n# Providing the folder path\norigin = '/kaggle/input/g2net-detecting-continuous-gravitational-waves/train/'\n#origin=Path(origin)\n# target = '../working/train/'\n# temp='../temp/'\n# if not os.path.exists(temp):\n#     os.mkdir(temp)\n# if not os.path.exists(target):\n#     os.mkdir(target)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:28.281245Z","iopub.execute_input":"2022-12-02T16:58:28.282676Z","iopub.status.idle":"2022-12-02T16:58:28.289159Z","shell.execute_reply.started":"2022-12-02T16:58:28.282625Z","shell.execute_reply":"2022-12-02T16:58:28.288039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count = 0\nfor root, folders, filenames in os.walk('/kaggle/input'):\n   print(root, folders)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:28.458206Z","iopub.execute_input":"2022-12-02T16:58:28.458691Z","iopub.status.idle":"2022-12-02T16:58:34.825282Z","shell.execute_reply.started":"2022-12-02T16:58:28.45865Z","shell.execute_reply":"2022-12-02T16:58:34.824058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Fetching the list of all the files\n# files = os.listdir(origin)\n\n# # Fetching all the files to directory\n# for file_name in files:\n#     shutil.copy(origin+file_name, target+file_name)\n# print(\"Files are copied successfully\")|","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:34.827031Z","iopub.execute_input":"2022-12-02T16:58:34.828083Z","iopub.status.idle":"2022-12-02T16:58:34.831826Z","shell.execute_reply.started":"2022-12-02T16:58:34.828044Z","shell.execute_reply":"2022-12-02T16:58:34.830781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=pd.read_csv(\"/kaggle/input/g2net-detecting-continuous-gravitational-waves/train_labels.csv\")\nlen(train)\n","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:34.833116Z","iopub.execute_input":"2022-12-02T16:58:34.833789Z","iopub.status.idle":"2022-12-02T16:58:34.865836Z","shell.execute_reply.started":"2022-12-02T16:58:34.833753Z","shell.execute_reply":"2022-12-02T16:58:34.864629Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:34.868243Z","iopub.execute_input":"2022-12-02T16:58:34.869081Z","iopub.status.idle":"2022-12-02T16:58:34.891661Z","shell.execute_reply.started":"2022-12-02T16:58:34.869042Z","shell.execute_reply":"2022-12-02T16:58:34.889973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['cale_fisier']='/kaggle/input/g2net-detecting-continuous-gravitational-waves/train/'+train['id']+'.hdf5'","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:34.893439Z","iopub.execute_input":"2022-12-02T16:58:34.893945Z","iopub.status.idle":"2022-12-02T16:58:34.904912Z","shell.execute_reply.started":"2022-12-02T16:58:34.893899Z","shell.execute_reply":"2022-12-02T16:58:34.903135Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#train['cale_fisier']=train['target'].apply(x:'/kaggle/input/g2net-detecting-continuous-gravitational-waves/'+train['id']+'.hdf5' if x=1.0 else '/kaggle/input/g2net-detecting-continuous-gravitational-waves/'+train['id']+'.hdf5')\n","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:34.906468Z","iopub.execute_input":"2022-12-02T16:58:34.907307Z","iopub.status.idle":"2022-12-02T16:58:34.918228Z","shell.execute_reply.started":"2022-12-02T16:58:34.907266Z","shell.execute_reply":"2022-12-02T16:58:34.917065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.cale_fisier[555]","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:34.919801Z","iopub.execute_input":"2022-12-02T16:58:34.920347Z","iopub.status.idle":"2022-12-02T16:58:34.936037Z","shell.execute_reply.started":"2022-12-02T16:58:34.920309Z","shell.execute_reply":"2022-12-02T16:58:34.934513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### g2netgaussian-noise-dataset","metadata":{}},{"cell_type":"code","source":"dataset_number='GS1'\nadd_on = '/kaggle/input/g2netgaussian-noise-dataset/noise/'\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=0\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:34.937423Z","iopub.execute_input":"2022-12-02T16:58:34.938057Z","iopub.status.idle":"2022-12-02T16:58:34.962804Z","shell.execute_reply.started":"2022-12-02T16:58:34.937873Z","shell.execute_reply":"2022-12-02T16:58:34.961501Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_number='GS1'\nadd_on = '/kaggle/input/g2netgaussian-noise-dataset/signal/'\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=1\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:34.964258Z","iopub.execute_input":"2022-12-02T16:58:34.964769Z","iopub.status.idle":"2022-12-02T16:58:34.982736Z","shell.execute_reply.started":"2022-12-02T16:58:34.964725Z","shell.execute_reply":"2022-12-02T16:58:34.980893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['id']=train['id'].str.replace('.hdf5', '')","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:34.987864Z","iopub.execute_input":"2022-12-02T16:58:34.988877Z","iopub.status.idle":"2022-12-02T16:58:34.998155Z","shell.execute_reply.started":"2022-12-02T16:58:34.988831Z","shell.execute_reply":"2022-12-02T16:58:34.996867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### g2netnonstationary-dataset","metadata":{}},{"cell_type":"code","source":"print(os.listdir(\"../input\"))","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:34.999848Z","iopub.execute_input":"2022-12-02T16:58:35.0022Z","iopub.status.idle":"2022-12-02T16:58:35.017992Z","shell.execute_reply.started":"2022-12-02T16:58:35.002118Z","shell.execute_reply":"2022-12-02T16:58:35.016263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_number='GS2'\nadd_on = '/kaggle/input/g2netnonstationary-dataset/signal/'\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=1\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:35.019632Z","iopub.execute_input":"2022-12-02T16:58:35.020052Z","iopub.status.idle":"2022-12-02T16:58:35.04063Z","shell.execute_reply.started":"2022-12-02T16:58:35.020016Z","shell.execute_reply":"2022-12-02T16:58:35.039508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_number='GS2'\nadd_on = \"/kaggle/input/g2netnonstationary-dataset/noise/\"\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=0\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:35.042191Z","iopub.execute_input":"2022-12-02T16:58:35.042599Z","iopub.status.idle":"2022-12-02T16:58:35.060127Z","shell.execute_reply.started":"2022-12-02T16:58:35.042536Z","shell.execute_reply":"2022-12-02T16:58:35.058528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### g2net-datasetnarrowartifacts","metadata":{}},{"cell_type":"code","source":"dataset_number='GS3'\nadd_on = '/kaggle/input/g2net-datasetnarrowartifacts/noise/'\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=0\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:35.062483Z","iopub.execute_input":"2022-12-02T16:58:35.06418Z","iopub.status.idle":"2022-12-02T16:58:35.083258Z","shell.execute_reply.started":"2022-12-02T16:58:35.06413Z","shell.execute_reply":"2022-12-02T16:58:35.082095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### addon-g2netnonstationary-dataset","metadata":{}},{"cell_type":"code","source":"dataset_number='GS4'\nadd_on = \"/kaggle/input/addon-g2netnonstationary-dataset/noise/\"\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=0\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:35.085173Z","iopub.execute_input":"2022-12-02T16:58:35.085831Z","iopub.status.idle":"2022-12-02T16:58:35.098133Z","shell.execute_reply.started":"2022-12-02T16:58:35.085796Z","shell.execute_reply":"2022-12-02T16:58:35.097165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_number='GS4'\nadd_on = \"/kaggle/input/addon-g2netnonstationary-dataset/signal/\"\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=1\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:35.100036Z","iopub.execute_input":"2022-12-02T16:58:35.100756Z","iopub.status.idle":"2022-12-02T16:58:35.114971Z","shell.execute_reply.started":"2022-12-02T16:58:35.100717Z","shell.execute_reply":"2022-12-02T16:58:35.113621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### addon-g2netgaussian-noise-dataset","metadata":{}},{"cell_type":"code","source":"dataset_number='GS5'\nadd_on = \"/kaggle/input/addon-g2netgaussian-noise-dataset/noise/\"\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=0\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:35.335841Z","iopub.execute_input":"2022-12-02T16:58:35.336633Z","iopub.status.idle":"2022-12-02T16:58:35.349576Z","shell.execute_reply.started":"2022-12-02T16:58:35.336595Z","shell.execute_reply":"2022-12-02T16:58:35.348099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_number='GS5'\nadd_on = \"/kaggle/input/addon-g2netgaussian-noise-dataset/signal/\"\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=1\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:35.781334Z","iopub.execute_input":"2022-12-02T16:58:35.782046Z","iopub.status.idle":"2022-12-02T16:58:35.793805Z","shell.execute_reply.started":"2022-12-02T16:58:35.782009Z","shell.execute_reply":"2022-12-02T16:58:35.792676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### add-on-narrow-instrumental-artifacts","metadata":{}},{"cell_type":"code","source":"dataset_number='GS5'\nadd_on = \"/kaggle/input/add-on-narrow-instrumental-artifacts-g2net-dataset/noise/\"\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=0\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:36.615622Z","iopub.execute_input":"2022-12-02T16:58:36.615991Z","iopub.status.idle":"2022-12-02T16:58:36.62888Z","shell.execute_reply.started":"2022-12-02T16:58:36.615962Z","shell.execute_reply":"2022-12-02T16:58:36.627485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 2nd-addon-g2netgaussian-noise-dataset\n\n","metadata":{}},{"cell_type":"code","source":"dataset_number='GS6'\nadd_on = \"/kaggle/input/2nd-addon-g2netgaussian-noise-dataset/noise/\"\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=0\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:37.405672Z","iopub.execute_input":"2022-12-02T16:58:37.406083Z","iopub.status.idle":"2022-12-02T16:58:37.42022Z","shell.execute_reply.started":"2022-12-02T16:58:37.406041Z","shell.execute_reply":"2022-12-02T16:58:37.418853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_number='GS6'\nadd_on = \"/kaggle/input/2nd-addon-g2netgaussian-noise-dataset/signal/\"\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=1\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:37.929248Z","iopub.execute_input":"2022-12-02T16:58:37.929671Z","iopub.status.idle":"2022-12-02T16:58:37.942294Z","shell.execute_reply.started":"2022-12-02T16:58:37.929637Z","shell.execute_reply":"2022-12-02T16:58:37.941033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 3rdaddon-g2netgaussian-noise-dataset","metadata":{}},{"cell_type":"code","source":"dataset_number='GS7'\nadd_on = \"/kaggle/input/3rdaddon-g2netgaussian-noise-dataset/noise/\"\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=0\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:41.726383Z","iopub.execute_input":"2022-12-02T16:58:41.727331Z","iopub.status.idle":"2022-12-02T16:58:41.741488Z","shell.execute_reply.started":"2022-12-02T16:58:41.727293Z","shell.execute_reply":"2022-12-02T16:58:41.740263Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_number='GS7'\nadd_on = \"/kaggle/input/3rdaddon-g2netgaussian-noise-dataset/signal/\"\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=1\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:42.446868Z","iopub.execute_input":"2022-12-02T16:58:42.447265Z","iopub.status.idle":"2022-12-02T16:58:42.460282Z","shell.execute_reply.started":"2022-12-02T16:58:42.447233Z","shell.execute_reply":"2022-12-02T16:58:42.459067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### ND-ADDon G2Net-Non-stationary Dataset","metadata":{}},{"cell_type":"code","source":"dataset_number='GS8'\nadd_on = \"/kaggle/input/ndaddon-g2netnonstationary-dataset/noise/\"\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=0\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:43.410091Z","iopub.execute_input":"2022-12-02T16:58:43.410536Z","iopub.status.idle":"2022-12-02T16:58:43.423464Z","shell.execute_reply.started":"2022-12-02T16:58:43.4105Z","shell.execute_reply":"2022-12-02T16:58:43.422262Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_number='GS8'\nadd_on = \"/kaggle/input/ndaddon-g2netnonstationary-dataset/signal/\"\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=1\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:43.933132Z","iopub.execute_input":"2022-12-02T16:58:43.934742Z","iopub.status.idle":"2022-12-02T16:58:43.948457Z","shell.execute_reply.started":"2022-12-02T16:58:43.934684Z","shell.execute_reply":"2022-12-02T16:58:43.94751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 2ndgeneratinglowsnrgravitywaves","metadata":{}},{"cell_type":"code","source":"dataset_number='GS9'\nadd_on = \"/kaggle/input/2ndgeneratinglowsnrgravitywaves/noise/\"\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=0\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_number='GS9'\nadd_on = \"/kaggle/input/2ndgeneratinglowsnrgravitywaves/signal/\"\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=1\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### generatinglowsnrgravitywaves","metadata":{}},{"cell_type":"code","source":"dataset_number='GS10'\nadd_on = \"/kaggle/input/generatinglowsnrgravitywaves/noise/\"\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=0\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_number='GS10'\nadd_on = \"/kaggle/input/generatinglowsnrgravitywaves/signal/\"\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=1\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### generatinglowsnrnonstationarygravitywaves\n\n","metadata":{}},{"cell_type":"code","source":"dataset_number='GS10'\nadd_on = \"/kaggle/input/generatinglowsnrnonstationarygravitywaves/noise/\"\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=0\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset_number='GS10'\nadd_on = \"/kaggle/input/generatinglowsnrnonstationarygravitywaves/signal/\"\nfiles_add_on = os.listdir(add_on)\ndf_add=pd.DataFrame()   \ndf_add=pd.DataFrame(files_add_on)\ndf_add=df_add.rename(columns={0: \"id\"})\ndf_add['target']=1\ndf_add['cale_fisier']=add_on+df_add.id\ntrain=pd.concat([train, df_add])\ntrain=train.reset_index(drop=True)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['id']=train['id'].str.replace('.hdf5', '')","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:44.900633Z","iopub.execute_input":"2022-12-02T16:58:44.901885Z","iopub.status.idle":"2022-12-02T16:58:44.914982Z","shell.execute_reply.started":"2022-12-02T16:58:44.901843Z","shell.execute_reply":"2022-12-02T16:58:44.912961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:45.334213Z","iopub.execute_input":"2022-12-02T16:58:45.334712Z","iopub.status.idle":"2022-12-02T16:58:45.342911Z","shell.execute_reply.started":"2022-12-02T16:58:45.334672Z","shell.execute_reply":"2022-12-02T16:58:45.341361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.describe()","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:58:53.853161Z","iopub.execute_input":"2022-12-02T16:58:53.853593Z","iopub.status.idle":"2022-12-02T16:58:53.874609Z","shell.execute_reply.started":"2022-12-02T16:58:53.853559Z","shell.execute_reply":"2022-12-02T16:58:53.873599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Utils","metadata":{}},{"cell_type":"code","source":"# Utility to read hdf5 file\ndef read_data(file: Path):\n    with h5py.File(file, \"r\") as f:\n        file=Path(file)\n        filename = file.stem\n        f = f[filename]\n        h1 = f[\"H1\"]\n        l1 = f[\"L1\"]\n        #freq_hz = list(f[\"frequency_Hz\"])\n        ###\n        h1_stft = h1[\"SFTs\"][()]\n        ###\n        #h1_timestamp = h1[\"timestamps_GPS\"][()]\n        h1_timestamp =1\n        # H2 data\n        l1_stft = l1[\"SFTs\"][()]\n        #l1_timestamp = l1[\"timestamps_GPS\"][()]\n        l1_timestamp =2\n        return {\n            \"H1\": [h1_stft, h1_timestamp],\n            \"L1\": [l1_stft, l1_timestamp],\n            #\"freq_hz\": freq_hz\n        }","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:57:25.903031Z","iopub.status.idle":"2022-12-02T16:57:25.903778Z","shell.execute_reply.started":"2022-12-02T16:57:25.903425Z","shell.execute_reply":"2022-12-02T16:57:25.903453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# from sklearn import preprocessing as normal\n# min_max_scaler = normal.MinMaxScaler()\n# #normalizedData = min_max_scaler.fit_transform(data)\n# def normalize(spect):\n#         mean = np.mean(np.ravel(spect))\n#         std = np.std(np.ravel(spect))\n#         if std != 0:\n#             spect = spect -mean\n#             spect = spect / std\n#         return spect\n\n\n# def power_spectrogram_train(h1_sft,cale,z,ind):\n#     #matplotlib.rcParams['image.cmap'] = 'viridis'\n#     img = np.empty((1,SHAPE_2[0],SHAPE_1[0]), dtype=np.float32)\n#     a=h1_sft[:, :SHAPE_1[0]*SHAPE_1[1]] * 1e22\n#     p = 2*(a.real**2 + a.imag**2)/(1800 * 1e24** 2) \n#     p = a.real**2 + a.imag**2  # power\n#     p /= np.mean(p)  # normalize\n#     p = np.mean(p.reshape(360, SHAPE_1[0],SHAPE_1[1]), axis=2)\n#     img[0] = p\n#     img=img[0]\n#     img=((img)/img.mean()).astype(np.float32)\n#     numefisier=ind+z+\"train_power.jpg\"\n#     file_path_1 = os.path.join(cale,numefisier)\n#     #matplotlib.rcParams['image.cmap'] = 'viridis'\n#     matplotlib.image.imsave( file_path_1, img,cmap=paleta_culori)\n# def power_spectrogram(h1_sft,l1_sft):\n#     i=0\n#     img = np.empty((2,360,360), dtype=np.float32)\n#     for elem in [h1_sft,l1_sft]:\n#     #matplotlib.rcParams['image.cmap'] = 'viridis'\n        \n#         a=elem[:, :4320] * 1e22\n#         p = 2*(a.real**2 + a.imag**2)/(1800 * 1e24** 2) \n#         p = a.real**2 + a.imag**2  # power\n#         p /= np.mean(p)  # normalize\n#         p = np.mean(p.reshape(360, 360,12), axis=2)\n#         img[i] = p\n#         img[i]=((img[i])/img[i].mean()).astype(np.float32)\n        \n# #         plt.figure(figsize=(30,30))\n# #         plt.imshow(img[i])\n#         i=i+1\n#         return img\n# def power_spectrogram1(h1_sft,l1_sft):\n#     i=0\n#     img = np.empty((3,360,360), dtype=np.float32)\n#     for elem in [h1_sft,l1_sft]:\n#     #matplotlib.rcParams['image.cmap'] = 'viridis'\n#         if len(elem[1])<4320:\n#             print(\"skipped one\")\n#         else:\n#             a=elem[:, :4320]* 1e22\n#             p = 2*(a.real**2 + a.imag**2)/(1800 * 1e24** 2) \n#             p = a.real**2 + a.imag**2  # power\n#             #p /= np.mean(p)  # normalize\n#             #p=normalize(p)\n#             p = np.mean(p.reshape(360, 360,12), axis=2)\n#             p = p/np.linalg.norm(p)\n#             img[i] = p*255\n#             #img[i]=((img[i])/img[i].mean()).astype(np.float32)\n\n#     #         plt.figure(figsize=(30,30))\n#     #         plt.imshow(img[i])\n\n#             i=i+1\n#         #img[2] = np.zeros([360,360],dtype=np.uint8)\n#         #img[2] = (img[0]-img[1])/2 ## corect\n#     img[2] =(img[0]+img[1])/2\n#     img[2]=img[2]/np.linalg.norm(img[2])\n#     #img[2].fill(255) # or img[:] = 255\n# #     plt.figure(figsize=(30,30))\n# #     plt.imshow(img[2])\n#     return img\n# #     img=((img)/img.mean()).astype(np.float32)\n# #     numefisier=ind+z+\"train_power.jpg\"\n# #     file_path_1 = os.path.join(cale,numefisier)\n# #     #matplotlib.rcParams['image.cmap'] = 'viridis'\n# #     matplotlib.image.imsave( file_path_1, img,cmap=paleta_culori)\n# def power_spectrogram1short(h1_sft,l1_sft):\n#     i=0\n#     img = np.empty((3,360,360), dtype=np.float32)\n#     for elem in [h1_sft,l1_sft]:\n#     #matplotlib.rcParams['image.cmap'] = 'viridis'\n        \n#         a=elem[:, :3960]* 1e22\n#         p = 2*(a.real**2 + a.imag**2)/(1800 * 1e24** 2) \n#         p = a.real**2 + a.imag**2  # power\n#         #p /= np.mean(p)  # normalize\n#         #p=normalize(p)\n#         p = np.mean(p.reshape(360, 360,11), axis=2)\n#         p = p/np.linalg.norm(p)\n#         img[i] = p*255\n#         #img[i]=((img[i])/img[i].mean()).astype(np.float32)\n        \n# #         plt.figure(figsize=(30,30))\n# #         plt.imshow(img[i])\n    \n#         i=i+1\n#     #img[2] = np.zeros([360,360],dtype=np.uint8)\n#     #img[2] = (img[0]-img[1])/2 ## corect\n#     img[2] =(img[0]+img[1])/2\n#     img[2]=img[2]/np.linalg.norm(img[2])\n#     #img[2].fill(255) # or img[:] = 255\n# #     plt.figure(figsize=(30,30))\n# #     plt.imshow(img[2])\n#     return img\n# #     img=((img)/img.mean()).astype(np.float32)\n# #     numefisier=ind+z+\"train_power.jpg\"\n# #     file_path_1 = os.path.join(cale,numefisier)\n# #     #matplotlib.rcParams['image.cmap'] = 'viridis'\n# #     matplotlib.image.imsave( file_path_1, img,cmap=paleta_culori)\n# def power_spectrogram3(h1_sft,l1_sft):\n#     i=0\n#     img = np.empty((3,360,360), dtype=np.float32)\n\n#     #matplotlib.rcParams['image.cmap'] = 'viridis' \n#     a=h1_sft[:, :4320]\n#     p = 2*(a.real**2 + a.imag**2)#/(1800 * 1e24** 2) \n#     p = a.real**2 + a.imag**2  # power\n#     #p /= np.mean(p)  # normalize\n#     p=normalize(p)\n#     p = np.mean(p.reshape(360, 360,12), axis=2)\n#     img[0] = p*255\n#     #img[i]=((img[i])/img[i].mean()).astype(np.float32)\n# #     plt.figure(figsize=(20,20))\n# #     plt.imshow(img[0])\n    \n#     a=l1_sft[:, :4320]\n#     p = 2*(a.real**2 + a.imag**2)#/(1800 * 1e24** 2) \n#     p = a.real**2 + a.imag**2  # power\n#     #p /= np.mean(p)  # normalize\n#     p=normalize(p)\n#     p = np.mean(p.reshape(360, 360,12), axis=2)\n#     img[1] = p*255\n#     #img[i]=((img[i])/img[i].mean()).astype(np.float32)\n#     plt.figure(figsize=(20,20))\n#     plt.imshow(img[1])\n#     b=h1_sft[:, :4320]\n#     p=((a.real+b.real)/2)**2 + ((a.imag+b.imag)/2)**2-((a.real-b.real)/2)**2 + ((a.imag-b.imag)/2)**2\n#     #img[2] = np.zeros([360,360],dtype=np.uint8)\n#     p = np.mean(p.reshape(360, 360,12), axis=2)\n#     img[2] = p*255\n#     #img[2].fill(255) # or img[:] = 255\n# #     plt.figure(figsize=(20,20))\n# #     plt.imshow(img[2])\n#     return img\n# #     img=((img)/img.mean()).astype(np.float32)\n# #     numefisier=ind+z+\"train_power.jpg\"\n# #     file_path_1 = os.path.join(cale,numefisier)\n# #     #matplotlib.rcParams['image.cmap'] = 'viridis'\n# #     matplotlib.image.imsave( file_path_1, img,cmap=paleta_culori)\n# def power_spectrogram2(h1_sft,l1_sft):\n#     i=0\n#     img = np.empty((3,360,360), dtype=np.float32)\n#     for elem in [h1_sft,l1_sft]:\n#     #matplotlib.rcParams['image.cmap'] = 'viridis'\n       \n#         a=elem[:, :4320] * 1e22\n\n#         p = 2*(a.real**2 + a.imag**2)/(1800 * 1e24** 2) \n#         p = a.real**2 + a.imag**2  # power\n#         p /= np.mean(p)  # normalize\n#         p = np.mean(p.reshape(360, 360,12), axis=2)\n#         img[i] = p\n#         img[i]=((img[i])/img[i].mean()).astype(np.float32)\n        \n#         plt.figure(figsize=(10,50))\n#         plt.imshow(img[i])\n    \n#         i=i+1\n#     img[2] = (img[0]+img[1])\n#     xxx=img.reshape(360,360,3)\n#     plt.figure(figsize=(10,50))\n#     plt.imshow(xxx)\n#     return img\n\n\n# #     img=((img)/img.mean()).astype(np.float32)\n# #     numefisier=ind+z+\"train_power.jpg\"\n# #     file_path_1 = os.path.join(cale,numefisier)\n# #     #matplotlib.rcParams['image.cmap'] = 'viridis'\n# #     matplotlib.image.imsave( file_path_1, img,cmap=paleta_culori)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:59:03.569239Z","iopub.execute_input":"2022-12-02T16:59:03.569701Z","iopub.status.idle":"2022-12-02T16:59:03.606432Z","shell.execute_reply.started":"2022-12-02T16:59:03.569665Z","shell.execute_reply":"2022-12-02T16:59:03.605299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp_df=train[train.target==1]","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:59:04.615005Z","iopub.execute_input":"2022-12-02T16:59:04.615876Z","iopub.status.idle":"2022-12-02T16:59:04.622036Z","shell.execute_reply.started":"2022-12-02T16:59:04.615835Z","shell.execute_reply":"2022-12-02T16:59:04.620952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp_df=temp_df.sample(frac=1)\ntemp_df=temp_df.reset_index()","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:59:10.226586Z","iopub.execute_input":"2022-12-02T16:59:10.22749Z","iopub.status.idle":"2022-12-02T16:59:10.236103Z","shell.execute_reply.started":"2022-12-02T16:59:10.22744Z","shell.execute_reply":"2022-12-02T16:59:10.23474Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train[train[\"target\"] >= 0]","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:59:10.584822Z","iopub.execute_input":"2022-12-02T16:59:10.585694Z","iopub.status.idle":"2022-12-02T16:59:10.592754Z","shell.execute_reply.started":"2022-12-02T16:59:10.58565Z","shell.execute_reply":"2022-12-02T16:59:10.591432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp_df.head(20)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:59:11.114119Z","iopub.execute_input":"2022-12-02T16:59:11.114647Z","iopub.status.idle":"2022-12-02T16:59:11.13113Z","shell.execute_reply.started":"2022-12-02T16:59:11.114593Z","shell.execute_reply":"2022-12-02T16:59:11.129567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#a1=temp_df.cale_fisier[2223]\n\ndef plot_amplitude_spectrogram(timestamps, frequency, fourier_data):\n    \n    ax = plt.subplot(1, 2, 1)\n    ax.set(xlabel=\"SFT index\", ylabel=\"Frequency [Hz]\")\n    time_in_days = (timestamps - timestamps[0]) / 3600 / 24\n    ax.set_title(\"SFT amplitude\")\n    c = ax.pcolorfast(\n        time_in_days, frequency, np.absolute(fourier_data)[:-1, :-1], norm=colors.Normalize()\n    )\n    \n    ax = plt.subplot(1, 2, 2)\n    \n    noise_levels = np.std(np.absolute(fourier_data).astype(np.float64), axis=0)\n    \n    ax.plot(noise_levels)\n    ax.set_title('SFT Amplitude STDDEV')\n    ","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:59:15.222671Z","iopub.execute_input":"2022-12-02T16:59:15.22311Z","iopub.status.idle":"2022-12-02T16:59:15.232805Z","shell.execute_reply.started":"2022-12-02T16:59:15.223075Z","shell.execute_reply":"2022-12-02T16:59:15.231291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#read_data(temp_df.cale_fisier[0])['H1']","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:59:16.112157Z","iopub.execute_input":"2022-12-02T16:59:16.112554Z","iopub.status.idle":"2022-12-02T16:59:16.117438Z","shell.execute_reply.started":"2022-12-02T16:59:16.112507Z","shell.execute_reply":"2022-12-02T16:59:16.115974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:59:16.398829Z","iopub.execute_input":"2022-12-02T16:59:16.399221Z","iopub.status.idle":"2022-12-02T16:59:16.403708Z","shell.execute_reply.started":"2022-12-02T16:59:16.39919Z","shell.execute_reply":"2022-12-02T16:59:16.402929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def read_data_c(file):\n    file = Path(file)\n    with h5py.File(file, \"r\") as f:\n        filename = file.stem\n        f = f[filename]\n        h1 = f[\"H1\"]\n        l1 = f[\"L1\"]\n        freq_hz = f[\"frequency_Hz\"]\n        \n        h1_stft = h1[\"SFTs\"][()]\n        h1_timestamp = h1[\"timestamps_GPS\"][()]\n        # H2 data\n        l1_stft = l1[\"SFTs\"][()]\n        l1_timestamp = l1[\"timestamps_GPS\"][()]\n        \n        return [h1_stft, h1_timestamp],            [l1_stft, l1_timestamp], np.array(freq_hz)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:59:16.822945Z","iopub.execute_input":"2022-12-02T16:59:16.823621Z","iopub.status.idle":"2022-12-02T16:59:16.830041Z","shell.execute_reply.started":"2022-12-02T16:59:16.823584Z","shell.execute_reply":"2022-12-02T16:59:16.829257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:59:17.812769Z","iopub.execute_input":"2022-12-02T16:59:17.813438Z","iopub.status.idle":"2022-12-02T16:59:17.828409Z","shell.execute_reply.started":"2022-12-02T16:59:17.813399Z","shell.execute_reply":"2022-12-02T16:59:17.827018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from matplotlib import colors","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:59:18.518773Z","iopub.execute_input":"2022-12-02T16:59:18.519343Z","iopub.status.idle":"2022-12-02T16:59:18.526788Z","shell.execute_reply.started":"2022-12-02T16:59:18.519299Z","shell.execute_reply":"2022-12-02T16:59:18.524911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i, (_, r) in enumerate(temp_df.head(15).iterrows()):\n    \n    (h1_sfts, h1_ts), (l1_sfts, l1_ts), freq = read_data_c(r.cale_fisier)\n    print(r.cale_fisier)\n    plt.figure(figsize=(15, 7))\n    plt.suptitle(f'Generated test sample: {os.path.basename(r.cale_fisier)}')\n    plot_amplitude_spectrogram(\n        h1_ts, np.array(freq), h1_sfts\n    )\n    plt.savefig(r.id)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T16:59:18.931812Z","iopub.execute_input":"2022-12-02T16:59:18.9323Z","iopub.status.idle":"2022-12-02T16:59:36.157715Z","shell.execute_reply.started":"2022-12-02T16:59:18.932261Z","shell.execute_reply":"2022-12-02T16:59:36.156525Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_amplitude_spectrogram2( fourier_data,fourier_data2):\n    \n    ax = plt.subplot(1, 2, 1)\n#     ax.set(xlabel=\"SFT index\", ylabel=\"Frequency [Hz]\")\n#     time_in_days = (timestamps - timestamps[0]) / 3600 / 24\n    ax.set_title(\"SFT amplitude\")\n    c = ax.pcolorfast(\n        np.arange(fourier_data.shape[1]),np.arange(fourier_data.shape[0]), np.absolute(fourier_data)[:-1, :-1], norm=colors.Normalize()\n    )\n    \n    ax = plt.subplot(1, 2, 2)\n    c = ax.pcolorfast(\n       np.arange(fourier_data2.shape[1]),np.arange(fourier_data2.shape[0]), np.absolute(fourier_data2)[:-1, :-1], norm=colors.Normalize()\n    )\n    #ax.plot(noise_levels)\n    ax.set_title('SFT Amplitude STDDEV')","metadata":{"execution":{"iopub.status.busy":"2022-12-02T17:21:11.773422Z","iopub.execute_input":"2022-12-02T17:21:11.773889Z","iopub.status.idle":"2022-12-02T17:21:11.784088Z","shell.execute_reply.started":"2022-12-02T17:21:11.773841Z","shell.execute_reply":"2022-12-02T17:21:11.781665Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(h1_sfts.shape)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T17:20:53.621451Z","iopub.execute_input":"2022-12-02T17:20:53.622645Z","iopub.status.idle":"2022-12-02T17:20:53.628023Z","shell.execute_reply.started":"2022-12-02T17:20:53.622603Z","shell.execute_reply":"2022-12-02T17:20:53.626928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_amplitude_spectrogram2(h1_sfts,l1_sfts)","metadata":{"execution":{"iopub.status.busy":"2022-12-02T17:21:16.394399Z","iopub.execute_input":"2022-12-02T17:21:16.394881Z","iopub.status.idle":"2022-12-02T17:21:16.82935Z","shell.execute_reply.started":"2022-12-02T17:21:16.394845Z","shell.execute_reply":"2022-12-02T17:21:16.82851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import scale\nfrom numpy import moveaxis\n\ndef power_spectrogram(h1_sft,l1_sft):\n    i=0\n    \n    img = np.empty((3,360,360), dtype=np.float32)\n    try:\n        a=h1_sft[:360, :4320]\n        p = a.real**2 + a.imag**2\n        p /= np.mean(p)  # normalize\n        try:\n            p = np.mean(p.reshape(360, 360,12), axis=2)\n        except:\n            a=h1_sft[:360, :3960]\n            p = a.real**2 + a.imag**2\n            p /= np.mean(p)  # normalize\n            p = np.mean(p.reshape(360, 360,12), axis=2)\n        #normalized=(255*(p - np.min(p))/np.ptp(p)).astype(int)\n\n    #     normalized=(255*(p - np.min(p))/np.ptp(p)).astype(int)\n        img[0]= p*255\n        a=l1_sft[:360, :4320]\n        p = a.real**2 + a.imag**2\n        p /= np.mean(p)  # normalize\n        try:\n            p = np.mean(p.reshape(360, 360,12), axis=2)\n        except:\n            a=l1_sft[:360, :3960]\n            p = a.real**2 + a.imag**2\n            p /= np.mean(p)  # normalize\n            p = np.mean(p.reshape(360, 360,12), axis=2)\n\n        #normalized=(255*(p - np.min(p))/np.ptp(p)).astype(int)\n        img[1]= p*255\n        #img[1]= p\n        img[2]=np.mean( np.array([ img[0], img[1] ]), axis=0 )\n        #return np.asarray([img[0],img[1]]).astype('float32')\n    except:\n        print(\"empty image\")\n    return img\n\ndef power_spectrogram128(h1_sft,l1_sft):\n    i=0\n    img = np.empty((3,360,128), dtype=np.float32)\n    try:\n        a=h1_sft[:360, :4096]\n        p = a.real**2 + a.imag**2\n        p /= np.mean(p)  # normalize\n        try:\n            p = np.mean(p.reshape(360, 128,32), axis=2)\n        except:\n            a=h1_sft[:360, :3968]\n            p = a.real**2 + a.imag**2\n            p /= np.mean(p)  # normalize\n            p = np.mean(p.reshape(360, 128,31), axis=2)\n        img[0]= p*255\n        a=l1_sft[:360, :4096]\n        p = a.real**2 + a.imag**2\n        p /= np.mean(p)  # normalize\n        try:\n            p = np.mean(p.reshape(360, 128,32), axis=2)\n        except:\n            a=l1_sft[:360, :3968]\n            p = a.real**2 + a.imag**2\n            p /= np.mean(p)  # normalize\n            p = np.mean(p.reshape(360, 128,31), axis=2)\n        img[1]= p*255\n        img[2]=np.mean( np.array([ img[0], img[1] ]), axis=0 )\n        img = np.moveaxis(img, 0, -1)\n        img = (img - img.min())\n        img = img * (255 / img.max())\n        img = img.astype(np.uint8)\n    except:\n        print(\"empty image\")\n    return img\n\n\n\ndef power_spectrogram360(h1_sft,l1_sft):\n    i=0\n    img = np.empty((3,360,360), dtype=np.float32)\n    try:\n        a=h1_sft[:360, :4320]\n        p = a.real**2 + a.imag**2\n        p /= np.mean(p)  # normalize\n        try:\n            p = np.mean(p.reshape(360, 360,12), axis=2)\n        except:\n            a=h1_sft[:360, :3960]\n            p = a.real**2 + a.imag**2\n            p /= np.mean(p)  # normalize\n            p = np.mean(p.reshape(360, 360,11), axis=2)\n        img[0]= p*255\n        a=l1_sft[:360, :4320]\n        p = a.real**2 + a.imag**2\n        p /= np.mean(p)  # normalize\n        try:\n            p = np.mean(p.reshape(360, 360,12), axis=2)\n        except:\n            a=l1_sft[:360, :3960]\n            p = a.real**2 + a.imag**2\n            p /= np.mean(p)  # normalize\n            p = np.mean(p.reshape(360, 360,11), axis=2)\n        img[1]= p*255\n        img[2]=np.mean( np.array([ img[0], img[1] ]), axis=0 )\n        img = np.moveaxis(img, 0, -1)\n        img = (img - img.min())\n        img = img * (255 / img.max())\n        img = img.astype(np.uint8)\n    except:\n        print(\"empty image\")\n    return img\n\ndef power_spectrogram64(h1_sft,l1_sft):\n    i=0\n    img = np.empty((3,360,64), dtype=np.float32)\n    try:\n        a=h1_sft[:360, :4096]\n        p = a.real**2 + a.imag**2\n        p /= np.mean(p)  # normalize\n        try:\n            p = np.mean(p.reshape(360, 64,64), axis=2)\n        except:\n            a=h1_sft[:360, :3968]\n            p = a.real**2 + a.imag**2\n            p /= np.mean(p)  # normalize\n            p = np.mean(p.reshape(360, 64,62), axis=2)\n        img[0]= p*255\n        a=l1_sft[:360, :4096]\n        p = a.real**2 + a.imag**2\n        p /= np.mean(p)  # normalize\n        try:\n            p = np.mean(p.reshape(360, 64,64), axis=2)\n        except:\n            a=l1_sft[:360, :3968]\n            p = a.real**2 + a.imag**2\n            p /= np.mean(p)  # normalize\n            p = np.mean(p.reshape(360, 64,62), axis=2)\n        img[1]= p*255\n        img[2]=np.mean( np.array([ img[0], img[1] ]), axis=0 )\n        img = np.moveaxis(img, 0, -1)\n        img = (img - img.min())\n        img = img * (255 / img.max())\n        img = img.astype(np.uint8)\n    except:\n        print(\"empty image\")\n    return img","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:30:25.572546Z","iopub.execute_input":"2022-12-01T21:30:25.572844Z","iopub.status.idle":"2022-12-01T21:30:25.594481Z","shell.execute_reply.started":"2022-12-01T21:30:25.572818Z","shell.execute_reply":"2022-12-01T21:30:25.592928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"temp=train.sample(20)","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:30:25.596255Z","iopub.execute_input":"2022-12-01T21:30:25.596795Z","iopub.status.idle":"2022-12-01T21:30:25.61039Z","shell.execute_reply.started":"2022-12-01T21:30:25.596761Z","shell.execute_reply":"2022-12-01T21:30:25.609002Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()\ntrain=train.sample(frac=1)\ntrain=train.reset_index()","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:30:25.612559Z","iopub.execute_input":"2022-12-01T21:30:25.612909Z","iopub.status.idle":"2022-12-01T21:30:25.625881Z","shell.execute_reply.started":"2022-12-01T21:30:25.61284Z","shell.execute_reply":"2022-12-01T21:30:25.624242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ntrain_path = '/kaggle/working/train/'\ntest_path='/kaggle/working/test/'\nnoise_path='/kaggle/working/train/noise/'\nsignal_path='/kaggle/working/train/signal/'\nif not os.path.exists(train_path):\n    os.mkdir(train_path)\nif not os.path.exists(noise_path):\n    os.mkdir(noise_path)#\nif not os.path.exists(signal_path):\n    os.mkdir(signal_path)\nif not os.path.exists(test_path):\n    os.mkdir(test_path)","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:30:25.627462Z","iopub.execute_input":"2022-12-01T21:30:25.627755Z","iopub.status.idle":"2022-12-01T21:30:25.638053Z","shell.execute_reply.started":"2022-12-01T21:30:25.627728Z","shell.execute_reply":"2022-12-01T21:30:25.636412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 360x128 dataset\n","metadata":{}},{"cell_type":"code","source":"width128 = '/kaggle/working/width128/'\nif not os.path.exists(width128):\n    os.mkdir(width128)\ntrain_path128 = '/kaggle/working/width128/train/'\ntest_path128='/kaggle/working/width128/test/'\nnoise_path128='/kaggle/working/width128/train/noise/'\nsignal_path128='/kaggle/working/width128/train/signal/'\nif not os.path.exists(train_path128):\n    os.mkdir(train_path128)\nif not os.path.exists(noise_path128):\n    os.mkdir(noise_path128)#\nif not os.path.exists(signal_path128):\n    os.mkdir(signal_path128)\nif not os.path.exists(test_path128):\n    os.mkdir(test_path128)","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:30:25.639692Z","iopub.execute_input":"2022-12-01T21:30:25.640094Z","iopub.status.idle":"2022-12-01T21:30:25.650962Z","shell.execute_reply.started":"2022-12-01T21:30:25.64006Z","shell.execute_reply":"2022-12-01T21:30:25.650154Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"360x360 PNG","metadata":{}},{"cell_type":"code","source":"width360 = '/kaggle/working/width360/'\nif not os.path.exists(width360):\n    os.mkdir(width360)\ntrain_path360 = '/kaggle/working/width360/train/'\ntest_path360='/kaggle/working/width360/test/'\nnoise_path360='/kaggle/working/width360/train/noise/'\nsignal_path360='/kaggle/working/width360/train/signal/'\nif not os.path.exists(train_path360):\n    os.mkdir(train_path360)\nif not os.path.exists(noise_path360):\n    os.mkdir(noise_path360)#\nif not os.path.exists(signal_path360):\n    os.mkdir(signal_path360)\nif not os.path.exists(test_path360):\n    os.mkdir(test_path360)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"widthextrem64 = '/kaggle/working/widthextrem64/'\nif not os.path.exists(widthextrem64):\n    os.mkdir(widthextrem64)\ntrain_pathextrem64 = '/kaggle/working/widthextrem64/train/'\ntest_pathextrem64='/kaggle/working/widthextrem64/test/'\nnoise_pathextrem64='/kaggle/working/widthextrem64/train/noise/'\nsignal_pathextrem64='/kaggle/working/widthextrem64/train/signal/'\nif not os.path.exists(train_pathextrem64):\n    os.mkdir(train_pathextrem64)\nif not os.path.exists(noise_pathextrem64):\n    os.mkdir(noise_pathextrem64)#\nif not os.path.exists(signal_pathextrem64):\n    os.mkdir(signal_pathextrem64)\nif not os.path.exists(test_pathextrem64):\n    os.mkdir(test_pathextrem64)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:31:11.517636Z","iopub.execute_input":"2022-12-01T21:31:11.517997Z","iopub.status.idle":"2022-12-01T21:31:11.534147Z","shell.execute_reply.started":"2022-12-01T21:31:11.517971Z","shell.execute_reply":"2022-12-01T21:31:11.532907Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:30:25.651893Z","iopub.execute_input":"2022-12-01T21:30:25.652614Z","iopub.status.idle":"2022-12-01T21:30:25.897609Z","shell.execute_reply.started":"2022-12-01T21:30:25.652585Z","shell.execute_reply":"2022-12-01T21:30:25.896492Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.utils import save_img\nfrom tensorflow.keras.utils import img_to_array,array_to_img\ni=0\nerori=[]\nnumpy_var=[]\nfile_names=[]\n# for index, row in train[:10].iterrows():\nfor index, row in train.iterrows():\n    try:\n        print(i)\n        variabila=i\n        eticheta=row['target']\n        print(\"target:\",row['target'], row['cale_fisier'])\n        calea=row['cale_fisier']\n        (h1_sfts, h1_ts), (l1_sfts, l1_ts), freq=read_data_c(calea)\n    #     print(\"Shape H1, L1:\",h1_sfts.shape,l1_sfts.shape)\n        numpy_var=power_spectrogram(h1_sfts,l1_sfts)\n        #numpy_var=numpy_var.reshape(360,360,3)\n\n        filename=\"sintetic_train{}.jpg\".format(variabila)\n        if row['target']==1:\n            filepath='/kaggle/working/train/signal/'+filename\n        elif row['target']==0:\n            filepath='/kaggle/working/train/noise/'+filename\n        else:\n            print('wrong label')\n        file_names.append([filepath,filename,row['target']])\n        save_img(filepath, numpy_var, data_format=\"channels_first\", file_format=None, scale=True)\n        \n##        Cv2 PNG\n        filenamepng=\"sintetic_train{}.png\".format(variabila)\n        cv2image=power_spectrogram128(h1_sfts,l1_sfts)\n        print(cv2image.shape)\n        if row['target']==1:\n            filepathCV='/kaggle/working/width128/train/signal/'+filenamepng\n        else:\n            filepathCV='/kaggle/working/width128/train/noise/'+filenamepng\n        cv2.imwrite(filepathCV, cv2image, [cv2.IMWRITE_PNG_COMPRESSION, 1])\n#         cvimg=np.moveaxis(numpy_var, 0, -1)\n#         print(cvimg.shape)\n##        Cv2 JPG\n        filenamepng=\"sintetic_train{}.jpg\".format(variabila)\n        cv2image=power_spectrogram360(h1_sfts,l1_sfts)\n        print(cv2image.shape)\n        if row['target']==1:\n            filepathCV='/kaggle/working/width360/train/signal/'+filenamepng\n        else:\n            filepathCV='/kaggle/working/width360/train/noise/'+filenamepng\n#         cv2.imwrite(filepathCV, cv2image, [cv2.IMWRITE_PNG_COMPRESSION, 1])\n#         cvimg=np.moveaxis(numpy_var, 0, -1)\n#         print(cvimg.shape)\n        cv2.imwrite(filepathCV, cv2image, [int(cv2.IMWRITE_JPEG_QUALITY), 100])\n        \n#####################\n##        Cv2 JPG\n        filenamepng=\"sintetic_train{}.jpg\".format(variabila)\n        cv2image=power_spectrogram64(h1_sfts,l1_sfts)\n        print(cv2image.shape)\n        if row['target']==1:\n            filepathCV='/kaggle/working/widthextrem64/train/signal/'+filenamepng\n        else:\n            filepathCV='/kaggle/working/widthextrem64/train/noise/'+filenamepng\n#         cv2.imwrite(filepathCV, cv2image, [cv2.IMWRITE_PNG_COMPRESSION, 1])\n#         cvimg=np.moveaxis(numpy_var, 0, -1)\n#         print(cvimg.shape)\n        cv2.imwrite(filepathCV, cv2image, [int(cv2.IMWRITE_JPEG_QUALITY), 100])\n    except:\n        print(row['target'], row['cale_fisier'])\n        erori.append(row['cale_fisier'])\n    i=i+1\n#file_names","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:31:18.118661Z","iopub.execute_input":"2022-12-01T21:31:18.119087Z","iopub.status.idle":"2022-12-01T21:31:22.12828Z","shell.execute_reply.started":"2022-12-01T21:31:18.119051Z","shell.execute_reply":"2022-12-01T21:31:22.126641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cv2image.shape","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:31:25.49297Z","iopub.execute_input":"2022-12-01T21:31:25.494173Z","iopub.status.idle":"2022-12-01T21:31:25.502427Z","shell.execute_reply.started":"2022-12-01T21:31:25.494123Z","shell.execute_reply":"2022-12-01T21:31:25.501335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(cv2image)","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:31:28.041823Z","iopub.execute_input":"2022-12-01T21:31:28.04221Z","iopub.status.idle":"2022-12-01T21:31:28.187814Z","shell.execute_reply.started":"2022-12-01T21:31:28.042182Z","shell.execute_reply":"2022-12-01T21:31:28.186868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# #cvimg=np.rollaxis(numpy_var, 3, 1)  \n# cv2.imwrite(\"test.png\",  cvimg, [cv2.IMWRITE_PNG_COMPRESSION, 0])","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:28:06.120786Z","iopub.status.idle":"2022-12-01T21:28:06.121206Z","shell.execute_reply.started":"2022-12-01T21:28:06.121011Z","shell.execute_reply":"2022-12-01T21:28:06.121031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"erori=pd.DataFrame(erori)\nerori.to_csv(\"erori.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:31:30.967912Z","iopub.execute_input":"2022-12-01T21:31:30.968299Z","iopub.status.idle":"2022-12-01T21:31:30.976639Z","shell.execute_reply.started":"2022-12-01T21:31:30.968267Z","shell.execute_reply":"2022-12-01T21:31:30.975429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"training_df=pd.DataFrame(file_names)\ntraining_df=training_df.rename(columns={0: \"calea\", 1: \"nume\", 2: \"target\"})\ntraining_df['id']=training_df['nume'].str.replace('.png','')\ntraining_df.head()\ntraining_df.to_csv('training.csv')","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:31:33.185679Z","iopub.execute_input":"2022-12-01T21:31:33.186843Z","iopub.status.idle":"2022-12-01T21:31:33.196939Z","shell.execute_reply.started":"2022-12-01T21:31:33.186788Z","shell.execute_reply":"2022-12-01T21:31:33.19575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ROOT_DIR = '../input/g2net-detecting-continuous-gravitational-waves'\nos.path.isdir(ROOT_DIR)","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:31:36.170675Z","iopub.execute_input":"2022-12-01T21:31:36.171043Z","iopub.status.idle":"2022-12-01T21:31:36.178834Z","shell.execute_reply.started":"2022-12-01T21:31:36.171013Z","shell.execute_reply":"2022-12-01T21:31:36.177146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = pd.read_csv('../input/g2net-detecting-continuous-gravitational-waves/sample_submission.csv')\ntest_files = glob(f\"{ROOT_DIR}/test/*.hdf5\")","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:31:37.179683Z","iopub.execute_input":"2022-12-01T21:31:37.180335Z","iopub.status.idle":"2022-12-01T21:31:37.217946Z","shell.execute_reply.started":"2022-12-01T21:31:37.180296Z","shell.execute_reply":"2022-12-01T21:31:37.216932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_names=[]\n# for filename in test_files[:10]:\nfor filename in test_files:\n    (h1_sfts, h1_ts), (l1_sfts, l1_ts), freq=read_data_c(filename)\n    fisier= Path(filename).stem\n    print(fisier)\n#     print(\"Shape H1, L1:\",h1_sfts.shape,l1_sfts.shape)\n#     print(\"Shape H1, L1:\",h1_sfts.shape,l1_sfts.shape)\n    numpy_var=power_spectrogram(h1_sfts,l1_sfts)\n    #numpy_var=numpy_var.reshape(360,360,3)\n    \n    filename=fisier+\".jpg\"\n    filepath='/kaggle/working/test/'+filename\n    test_names.append([filepath, fisier])\n    save_img(filepath, numpy_var, data_format=\"channels_first\", file_format=None, scale=True)\n##        Cv2 PNG\n    filenamepng=fisier+\".png\"\n    cv2image=power_spectrogram128(h1_sfts,l1_sfts)\n    print(cv2image.shape)\n\n    filepathCV='/kaggle/working/width128/test/'+filenamepng\n\n    cv2.imwrite(filepathCV, cv2image, [cv2.IMWRITE_PNG_COMPRESSION, 1])\n#         cvimg=np.moveaxis(numpy_var, 0, -1)\n#         print(cvimg.shape)\n##        Cv2 JPG\n    filenamepng=fisier+\".jpg\"\n    cv2image=power_spectrogram360(h1_sfts,l1_sfts)\n    print(cv2image.shape)\n    filepathCV='/kaggle/working/width360/test/'+filenamepng\n    cv2.imwrite(filepathCV, cv2image, [int(cv2.IMWRITE_JPEG_QUALITY), 100])\n#######\n#         cvimg=np.moveaxis(numpy_var, 0, -1)\n#         print(cvimg.shape)\n##        Cv2 JPG\n    filenamepng=fisier+\".jpg\"\n    cv2image=power_spectrogram64(h1_sfts,l1_sfts)\n    print(cv2image.shape)\n    filepathCV='/kaggle/working/widthextrem64/test/'+filenamepng\n    cv2.imwrite(filepathCV, cv2image, [int(cv2.IMWRITE_JPEG_QUALITY), 100])\n\n    i=i+1\n\ntest_names","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:31:37.907604Z","iopub.execute_input":"2022-12-01T21:31:37.907988Z","iopub.status.idle":"2022-12-01T21:31:40.817575Z","shell.execute_reply.started":"2022-12-01T21:31:37.907958Z","shell.execute_reply":"2022-12-01T21:31:40.816672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_files=pd.DataFrame(test_names)\ntest_files.to_csv(\"test_files.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:31:46.001059Z","iopub.execute_input":"2022-12-01T21:31:46.001435Z","iopub.status.idle":"2022-12-01T21:31:46.00907Z","shell.execute_reply.started":"2022-12-01T21:31:46.001403Z","shell.execute_reply":"2022-12-01T21:31:46.007672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"https://www.kaggle.com/code/markwijkhuizen/generating-continuous-gravitational-wave-sign-pub/notebook","metadata":{}},{"cell_type":"code","source":"df_add.head()","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:31:54.527477Z","iopub.execute_input":"2022-12-01T21:31:54.527915Z","iopub.status.idle":"2022-12-01T21:31:54.543923Z","shell.execute_reply.started":"2022-12-01T21:31:54.527883Z","shell.execute_reply":"2022-12-01T21:31:54.543122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"PyWavelets is open source wavelet transform software for Python. It combines a simple high level interface with low\nlevel C and Cython performance.\nPyWavelets is very easy to use and get started with. Just install the package, open the Python interactive shell and\ntype:\n","metadata":{}},{"cell_type":"code","source":"import pywt","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:31:58.305422Z","iopub.execute_input":"2022-12-01T21:31:58.305788Z","iopub.status.idle":"2022-12-01T21:31:58.382767Z","shell.execute_reply.started":"2022-12-01T21:31:58.30576Z","shell.execute_reply":"2022-12-01T21:31:58.381405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"coeffs2 = pywt.dwt2(cv2image, 'bior1.3')\ntitles = ['Approximation', ' Horizontal detail',\n'Vertical detail', 'Diagonal detail']\n\nLL, (LH, HL, HH) = coeffs2\nfig = plt.figure(figsize=(22, 6))\nfor i, a in enumerate([LL, LH, HL, HH]):\n    ax = fig.add_subplot(1, 4, i + 1)\n    ax.imshow(a, interpolation=\"nearest\", cmap=plt.cm.gray)\n    ax.set_title(titles[i], fontsize=10)\n    ax.set_xticks([])\n    ax.set_yticks([])\nfig.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-01T22:29:10.162733Z","iopub.execute_input":"2022-12-01T22:29:10.163082Z","iopub.status.idle":"2022-12-01T22:29:10.406323Z","shell.execute_reply.started":"2022-12-01T22:29:10.163058Z","shell.execute_reply":"2022-12-01T22:29:10.405538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"HH","metadata":{"execution":{"iopub.status.busy":"2022-12-01T22:37:02.546804Z","iopub.execute_input":"2022-12-01T22:37:02.547158Z","iopub.status.idle":"2022-12-01T22:37:02.557119Z","shell.execute_reply.started":"2022-12-01T22:37:02.547131Z","shell.execute_reply":"2022-12-01T22:37:02.555727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# #imaginea=cv2.imread(\"/kaggle/working/SignalwGausian_Noise190.png\")\n# plt.imshow(cv2image)\n","metadata":{"execution":{"iopub.status.busy":"2022-12-01T22:17:42.599745Z","iopub.execute_input":"2022-12-01T22:17:42.600117Z","iopub.status.idle":"2022-12-01T22:17:42.744672Z","shell.execute_reply.started":"2022-12-01T22:17:42.600087Z","shell.execute_reply":"2022-12-01T22:17:42.743762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !pip install -qq git+https://github.com/PyFstat/PyFstat@python37","metadata":{"execution":{"iopub.status.busy":"2022-12-01T21:28:06.132671Z","iopub.status.idle":"2022-12-01T21:28:06.13303Z","shell.execute_reply.started":"2022-12-01T21:28:06.132847Z","shell.execute_reply":"2022-12-01T21:28:06.132876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_spectrogram(filename, LIGO=\"H1\"):\n  # open file\n    f = h5py.File(filename, 'r')\n\n  # read fourier transform coefficients\n    (h1_sfts, h1_ts), (l1_sfts, l1_ts), freq=read_data_c(filename)\n    print('ok',r.id)\n    spectrogram = np.absolute(np.array(h1_sfts))\n    savefilename=r.id+'.png'\n    print(savefilename)\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    fig.savefig(savefilename, bbox_inches='tight', pad_inches=0)\n    plt.imshow(spectrogram, cmap='turbo', aspect='equal', origin ='lower')","metadata":{"execution":{"iopub.status.busy":"2022-12-01T22:14:18.272556Z","iopub.execute_input":"2022-12-01T22:14:18.27293Z","iopub.status.idle":"2022-12-01T22:14:18.280608Z","shell.execute_reply.started":"2022-12-01T22:14:18.272898Z","shell.execute_reply":"2022-12-01T22:14:18.279504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_spectrogram(\"/kaggle/input/addon-g2netnonstationary-dataset/signal/NonStationary_NoiseAndSignal_0.hdf5\", LIGO=\"H1\")\n","metadata":{"execution":{"iopub.status.busy":"2022-12-01T22:15:14.545292Z","iopub.execute_input":"2022-12-01T22:15:14.545618Z","iopub.status.idle":"2022-12-01T22:15:16.225897Z","shell.execute_reply.started":"2022-12-01T22:15:14.545593Z","shell.execute_reply":"2022-12-01T22:15:16.22489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_spectrogram(\"/kaggle/input/addon-g2netnonstationary-dataset/signal/NonStationary_NoiseAndSignal_1.hdf5\", LIGO=\"H1\")","metadata":{"execution":{"iopub.status.busy":"2022-12-01T22:15:29.007209Z","iopub.execute_input":"2022-12-01T22:15:29.007558Z","iopub.status.idle":"2022-12-01T22:15:29.968096Z","shell.execute_reply.started":"2022-12-01T22:15:29.007531Z","shell.execute_reply":"2022-12-01T22:15:29.96694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# imaginea=cv2.imread(\"/kaggle/working/SignalwGausian_Noise76,png.png\")\n# plt.imshow(imaginea)\n","metadata":{"execution":{"iopub.status.busy":"2022-12-01T22:28:27.949393Z","iopub.execute_input":"2022-12-01T22:28:27.949769Z","iopub.status.idle":"2022-12-01T22:28:28.187575Z","shell.execute_reply.started":"2022-12-01T22:28:27.949738Z","shell.execute_reply":"2022-12-01T22:28:28.186888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# coeffs2 = pywt.dwt2(imaginea, 'bior1.3')\n# titles = ['Approximation', ' Horizontal detail',\n# 'Vertical detail', 'Diagonal detail']\n\n# LL, (LH, HL, HH) = coeffs2\n# fig = plt.figure(figsize=(22, 6))\n# for i, a in enumerate([LL, LH, HL, HH]):\n#     ax = fig.add_subplot(1, 4, i + 1)\n#     ax.imshow(a, interpolation=\"nearest\", cmap=plt.cm.gray)\n#     ax.set_title(titles[i], fontsize=10)\n#     ax.set_xticks([])\n#     ax.set_yticks([])\n# fig.tight_layout()\n# plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-12-01T22:28:52.354366Z","iopub.execute_input":"2022-12-01T22:28:52.354694Z","iopub.status.idle":"2022-12-01T22:28:52.716643Z","shell.execute_reply.started":"2022-12-01T22:28:52.354668Z","shell.execute_reply":"2022-12-01T22:28:52.715784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"https://pywavelets.readthedocs.io/_/downloads/en/v1.0.0/pdf/\n\nhttps://ataspinar.com/2018/12/21/a-guide-for-using-the-wavelet-transform-in-machine-learning/","metadata":{}},{"cell_type":"code","source":"# (cA, cD) = pywt.dwt([1,2,3,4,5,6], 'db2', 'smooth')\n# cA\n# cD","metadata":{"execution":{"iopub.status.busy":"2022-12-01T22:33:52.170342Z","iopub.execute_input":"2022-12-01T22:33:52.170689Z","iopub.status.idle":"2022-12-01T22:33:52.176897Z","shell.execute_reply.started":"2022-12-01T22:33:52.170663Z","shell.execute_reply":"2022-12-01T22:33:52.176097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# data = h1_sfts.real\n# coeffs = pywt.dwt2(data, 'haar')\n# cA, (cH, cV, cD) = coeffs\n# # cA\n# # array([[ 2., 2.],\n# # [ 2., 2.]])\n# # >>> cV\n# # array([[ 0., 0.],\n# # [ 0., 0.]]\n# cD","metadata":{"execution":{"iopub.status.busy":"2022-12-01T22:25:04.716661Z","iopub.execute_input":"2022-12-01T22:25:04.717023Z","iopub.status.idle":"2022-12-01T22:25:04.736206Z","shell.execute_reply.started":"2022-12-01T22:25:04.716993Z","shell.execute_reply":"2022-12-01T22:25:04.735176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# for i, a in enumerate([cA, cH, cV, cD]):\n#     ax = fig.add_subplot(1, 4, i + 1)\n#     ax.imshow(a, interpolation=\"nearest\", cmap=plt.cm.gray)\n#     ax.set_title(titles[i], fontsize=10)\n#     ax.set_xticks([])\n#     ax.set_yticks([])","metadata":{"execution":{"iopub.status.busy":"2022-12-01T22:24:29.799616Z","iopub.execute_input":"2022-12-01T22:24:29.799973Z","iopub.status.idle":"2022-12-01T22:24:29.8692Z","shell.execute_reply.started":"2022-12-01T22:24:29.799947Z","shell.execute_reply":"2022-12-01T22:24:29.867762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}