{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":59093,"databundleVersionId":7469972,"sourceType":"competition"},{"sourceId":7680946,"sourceType":"datasetVersion","datasetId":4476546}],"dockerImageVersionId":30646,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd, numpy as np, os\nimport matplotlib.pyplot as plt, gc\nimport seaborn as sns\n\nfrom glob import glob\n\ntuh = pd.read_csv('/kaggle/input/hms-hba-tuh-tusz-seizures/seizures.csv')\nprint(tuh.shape)\ndisplay(tuh)","metadata":{"execution":{"iopub.status.busy":"2024-03-23T07:34:17.659873Z","iopub.execute_input":"2024-03-23T07:34:17.660225Z","iopub.status.idle":"2024-03-23T07:34:20.310179Z","shell.execute_reply.started":"2024-03-23T07:34:17.660197Z","shell.execute_reply":"2024-03-23T07:34:20.309205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"VER=2\n\nPATH = '/kaggle/input/hms-hba-tuh-tusz-seizures/eeg_raw/'\n\nfiles= glob(f'{PATH}*.parquet')\n\nfiles_id = []\n\nfor file in files:\n    id = file.split('/')[-1].split('.')[0]\n    files_id.append(id) \n    \ntuh = tuh[tuh['id'].isin(files_id)]\ntuh.shape[0]","metadata":{"execution":{"iopub.status.busy":"2024-03-23T07:34:20.311832Z","iopub.execute_input":"2024-03-23T07:34:20.312144Z","iopub.status.idle":"2024-03-23T07:34:20.597434Z","shell.execute_reply.started":"2024-03-23T07:34:20.312118Z","shell.execute_reply":"2024-03-23T07:34:20.596458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"drop = tuh['missing_data'] == 0\n\ntuh = tuh.loc[~drop]\nprint(f'There are {len(tuh)} train data')","metadata":{"execution":{"iopub.status.busy":"2024-03-23T07:34:20.600568Z","iopub.execute_input":"2024-03-23T07:34:20.601020Z","iopub.status.idle":"2024-03-23T07:34:20.612175Z","shell.execute_reply.started":"2024-03-23T07:34:20.600982Z","shell.execute_reply":"2024-03-23T07:34:20.611289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tuh = tuh.drop(columns=['path','reference_type','group','session','class_code','directory','event_time','EKG','processed','missing_data'])","metadata":{"execution":{"iopub.status.busy":"2024-03-23T07:34:20.614516Z","iopub.execute_input":"2024-03-23T07:34:20.617446Z","iopub.status.idle":"2024-03-23T07:34:20.625508Z","shell.execute_reply.started":"2024-03-23T07:34:20.617411Z","shell.execute_reply":"2024-03-23T07:34:20.624398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tuh.rename(columns={'id':'eeg_id'}, inplace=True)\ntuh.rename(columns={'start_time':'min', 'stop_time':'max'}, inplace=True)\n\n\ntmp = tuh['eeg_id'].values\ntuh['spec_id'] = tmp\n\ntmp = np.zeros((len(tuh),6))\nTARGETS = ['seizure_vote', 'lpd_vote','gpd_vote','lrda_vote','grda_vote','other_vote']\ntuh[TARGETS] = tmp\n\ntuh['target'] = 'Seizure'\n\nprint(tuh.shape)\ntuh.head()","metadata":{"execution":{"iopub.status.busy":"2024-03-23T07:34:20.627208Z","iopub.execute_input":"2024-03-23T07:34:20.627945Z","iopub.status.idle":"2024-03-23T07:34:20.655772Z","shell.execute_reply.started":"2024-03-23T07:34:20.627905Z","shell.execute_reply":"2024-03-23T07:34:20.654701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"PATH = \"/kaggle/input/hms-hba-tuh-tusz-seizures/eeg_10min_spec/\"\n\nEEG_ID = tuh['eeg_id'].unique()\nspectrograms = {}\n\nfor i, eeg_id in enumerate(EEG_ID): \n    if (i%100==0)&(i!=0): print(i,', ', end='')\n    \n    specs = pd.read_parquet(f'{PATH}{eeg_id}.parquet')\n    spectrograms[eeg_id] = specs.iloc[:,1:].values\n    \nnp.save('tuh_specs',spectrograms)    ","metadata":{"execution":{"iopub.status.busy":"2024-03-23T07:34:20.656941Z","iopub.execute_input":"2024-03-23T07:34:20.657249Z","iopub.status.idle":"2024-03-23T07:34:32.042000Z","shell.execute_reply.started":"2024-03-23T07:34:20.657223Z","shell.execute_reply":"2024-03-23T07:34:32.040507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tuh.to_csv('tuh.csv')","metadata":{"execution":{"iopub.status.busy":"2024-03-23T07:34:32.042750Z","iopub.status.idle":"2024-03-23T07:34:32.043093Z","shell.execute_reply.started":"2024-03-23T07:34:32.042927Z","shell.execute_reply":"2024-03-23T07:34:32.042941Z"},"trusted":true},"execution_count":null,"outputs":[]}]}