{"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":"markdown","source":"Published on October 07, 2023. By Marília Prata, mpwolke","metadata":{}},{"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 matplotlib.pyplot as plt\nimport seaborn as sns\n\nimport plotly.graph_objs as go\nimport plotly.offline as py\nimport plotly.express as px\n\n#Ignore warnings\nimport warnings\nwarnings.filterwarnings('ignore')\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","execution":{"iopub.status.busy":"2023-10-07T17:05:30.327535Z","iopub.execute_input":"2023-10-07T17:05:30.327969Z","iopub.status.idle":"2023-10-07T17:05:33.809304Z","shell.execute_reply.started":"2023-10-07T17:05:30.327936Z","shell.execute_reply":"2023-10-07T17:05:33.808082Z"},"_kg_hide-output":true,"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#This below took a lot of time to load","metadata":{"_kg_hide-output":true}},{"cell_type":"code","source":"import tarfile\n\ntar = tarfile.open(\"../input/seizure-detection/clips.tar.gz\", \"r:gz\")\nfor member in tar.getmembers():\n     f = tar.extractfile(member)\n     if f is not None:\n         content = f.read()","metadata":{"execution":{"iopub.status.busy":"2023-10-07T17:06:04.232801Z","iopub.execute_input":"2023-10-07T17:06:04.233517Z","iopub.status.idle":"2023-10-07T17:16:18.664105Z","shell.execute_reply.started":"2023-10-07T17:06:04.233468Z","shell.execute_reply":"2023-10-07T17:16:18.661972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tar.getnames()","metadata":{"execution":{"iopub.status.busy":"2023-10-07T17:16:31.368098Z","iopub.execute_input":"2023-10-07T17:16:31.368648Z","iopub.status.idle":"2023-10-07T17:16:31.420262Z","shell.execute_reply.started":"2023-10-07T17:16:31.368589Z","shell.execute_reply":"2023-10-07T17:16:31.419356Z"},"_kg_hide-output":true,"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import scipy.io","metadata":{"execution":{"iopub.status.busy":"2023-10-07T17:26:50.749802Z","iopub.execute_input":"2023-10-07T17:26:50.750322Z","iopub.status.idle":"2023-10-07T17:26:50.824412Z","shell.execute_reply.started":"2023-10-07T17:26:50.750286Z","shell.execute_reply":"2023-10-07T17:26:50.822944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Import to a python dictionary\nmat = scipy.io.loadmat('../input/Volumes/Seagate/seizure_detection/competition_data/clips/Patient_8/Patient_8_ictal_segment_1.mat')","metadata":{"execution":{"iopub.status.busy":"2023-10-07T17:29:00.891680Z","iopub.execute_input":"2023-10-07T17:29:00.892408Z","iopub.status.idle":"2023-10-07T17:29:00.965171Z","shell.execute_reply.started":"2023-10-07T17:29:00.892365Z","shell.execute_reply":"2023-10-07T17:29:00.963526Z"},"_kg_hide-output":true,"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Reading the gz file (clips.tar.gz)","metadata":{}},{"cell_type":"code","source":"#https://stackoverflow.com/questions/39263929/how-can-i-read-tar-gz-file-using-pandas-read-csv-with-gzip-compression-option\n#Answered by Marlon Abeykoon Sep 1, 2016 at 6:30\n\ndf = pd.read_csv('/kaggle/input/seizure-detection/clips.tar.gz', compression='gzip', header=0, sep=' ;', encoding='ISO-8859-2', quotechar='\"')","metadata":{"execution":{"iopub.status.busy":"2023-10-07T17:39:03.062608Z","iopub.execute_input":"2023-10-07T17:39:03.063122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#No more memory. At all.","metadata":{}},{"cell_type":"code","source":"df.head()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tar.getmembers()","metadata":{"execution":{"iopub.status.busy":"2023-10-07T17:16:52.919853Z","iopub.execute_input":"2023-10-07T17:16:52.920249Z","iopub.status.idle":"2023-10-07T17:16:52.946529Z","shell.execute_reply.started":"2023-10-07T17:16:52.920208Z","shell.execute_reply":"2023-10-07T17:16:52.945136Z"},"_kg_hide-output":true,"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tar.list(verbose=True, members=None)","metadata":{"execution":{"iopub.status.busy":"2023-10-07T17:17:21.024278Z","iopub.execute_input":"2023-10-07T17:17:21.024737Z","iopub.status.idle":"2023-10-07T17:17:22.922264Z","shell.execute_reply.started":"2023-10-07T17:17:21.024704Z","shell.execute_reply":"2023-10-07T17:17:22.920477Z"},"_kg_hide-output":true,"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Upgrade to Google Cloud AI Notebooks\n\nOSError: [Errno 28] No space left on device","metadata":{}},{"cell_type":"code","source":"tar.extractall(path=\".\", members=None, numeric_owner=False)","metadata":{"execution":{"iopub.status.busy":"2023-10-07T17:17:59.305030Z","iopub.execute_input":"2023-10-07T17:17:59.306726Z","iopub.status.idle":"2023-10-07T17:21:13.490332Z","shell.execute_reply.started":"2023-10-07T17:17:59.306668Z","shell.execute_reply":"2023-10-07T17:21:13.488617Z"},"_kg_hide-output":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#Another way to open tgz/gz files","metadata":{}},{"cell_type":"code","source":"import  tarfile\ntar = tarfile.open(\"../input/seizure-detection/sample_clip.mat.gz\")\ntar.getmembers()","metadata":{},"execution_count":null,"outputs":[]}]}