{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","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"}],"dockerImageVersionId":30626,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Load and ploting functions","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2024-01-24T14:45:12.673934Z","iopub.execute_input":"2024-01-24T14:45:12.674347Z","iopub.status.idle":"2024-01-24T14:45:13.143017Z","shell.execute_reply.started":"2024-01-24T14:45:12.674311Z","shell.execute_reply":"2024-01-24T14:45:13.141909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#df = pd.read_parquet('/kaggle/input/hms-harmful-brain-activity-classification/train_spectrograms/1000086677.parquet')\ndf = pd.read_parquet('/kaggle/input/hms-harmful-brain-activity-classification/train_eegs/1000913311.parquet')\ndf","metadata":{"execution":{"iopub.status.busy":"2024-01-24T14:45:13.145012Z","iopub.execute_input":"2024-01-24T14:45:13.145461Z","iopub.status.idle":"2024-01-24T14:45:13.440429Z","shell.execute_reply.started":"2024-01-24T14:45:13.145430Z","shell.execute_reply":"2024-01-24T14:45:13.439499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plotegg(df, smooth=1):\n    fig, ax = plt.subplots(20,sharex=True)\n    for plnr, elect in zip(range(20),df.keys()):\n        color = 'r' if elect == 'EKG' else 'k'\n        ax[plnr].plot(df[elect].rolling(smooth).mean(),color)\n        ax[plnr].grid()\n        ax[plnr].set_ylabel(elect, rotation=45)\n    plt.subplots_adjust(top=1.0,bottom=0.03,left=0.035,right=1.0,hspace=0.0,wspace=0.2)\n    plt.xticks(np.arange(0, 10000, 200),np.arange(0,10000//200))","metadata":{"execution":{"iopub.status.busy":"2024-01-24T14:45:13.441655Z","iopub.execute_input":"2024-01-24T14:45:13.442043Z","iopub.status.idle":"2024-01-24T14:45:13.450247Z","shell.execute_reply.started":"2024-01-24T14:45:13.442009Z","shell.execute_reply":"2024-01-24T14:45:13.449163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plotegg(df,smooth=12)","metadata":{"execution":{"iopub.status.busy":"2024-01-24T14:45:13.452962Z","iopub.execute_input":"2024-01-24T14:45:13.453785Z","iopub.status.idle":"2024-01-24T14:45:22.763507Z","shell.execute_reply.started":"2024-01-24T14:45:13.453720Z","shell.execute_reply":"2024-01-24T14:45:22.759835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"WIP","metadata":{}},{"cell_type":"code","source":"import mne\nimport pandas as pd","metadata":{"execution":{"iopub.status.busy":"2024-01-24T14:45:22.764980Z","iopub.execute_input":"2024-01-24T14:45:22.765806Z","iopub.status.idle":"2024-01-24T14:45:24.578381Z","shell.execute_reply.started":"2024-01-24T14:45:22.765731Z","shell.execute_reply":"2024-01-24T14:45:24.577177Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def read_parquet_into_mne(path,freq=200):\n    df = pd.read_parquet(path)\n    ch_names = list(df.keys())\n    df = df.T\n    ch_types = ([\"eeg\"] * (len(ch_names)-1)) + ['ecg']\n    info = mne.create_info(ch_names, ch_types=ch_types, sfreq=freq)\n    info.set_montage(\"standard_1020\")\n    raw = mne.io.RawArray(df, info, verbose=True)\n    raw.info = info\n    return raw","metadata":{"execution":{"iopub.status.busy":"2024-01-24T14:45:35.071432Z","iopub.execute_input":"2024-01-24T14:45:35.072093Z","iopub.status.idle":"2024-01-24T14:45:35.082162Z","shell.execute_reply.started":"2024-01-24T14:45:35.072039Z","shell.execute_reply":"2024-01-24T14:45:35.081003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"raw = read_parquet_into_mne('/kaggle/input/hms-harmful-brain-activity-classification/train_eegs/1000913311.parquet')","metadata":{"execution":{"iopub.status.busy":"2024-01-24T14:45:37.023044Z","iopub.execute_input":"2024-01-24T14:45:37.023453Z","iopub.status.idle":"2024-01-24T14:45:38.086840Z","shell.execute_reply.started":"2024-01-24T14:45:37.023420Z","shell.execute_reply":"2024-01-24T14:45:38.085775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(raw)","metadata":{"execution":{"iopub.status.busy":"2024-01-24T14:45:39.625872Z","iopub.execute_input":"2024-01-24T14:45:39.626290Z","iopub.status.idle":"2024-01-24T14:45:41.083074Z","shell.execute_reply.started":"2024-01-24T14:45:39.626257Z","shell.execute_reply":"2024-01-24T14:45:41.082110Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"raw.compute_psd(fmax=100).plot(picks=\"data\", exclude=\"bads\")","metadata":{"execution":{"iopub.status.busy":"2024-01-24T14:45:42.833147Z","iopub.execute_input":"2024-01-24T14:45:42.833677Z","iopub.status.idle":"2024-01-24T14:45:44.465164Z","shell.execute_reply.started":"2024-01-24T14:45:42.833632Z","shell.execute_reply":"2024-01-24T14:45:44.464224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Still having problems with this plot!\nraw.plot(duration=1, n_channels=20, scalings='auto')","metadata":{"execution":{"iopub.status.busy":"2024-01-24T14:58:56.726595Z","iopub.execute_input":"2024-01-24T14:58:56.727688Z","iopub.status.idle":"2024-01-24T14:58:58.218086Z","shell.execute_reply.started":"2024-01-24T14:58:56.727630Z","shell.execute_reply":"2024-01-24T14:58:58.216850Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}