{"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":"import 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","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.366241Z","iopub.execute_input":"2021-07-11T14:39:34.366727Z","iopub.status.idle":"2021-07-11T14:39:34.376653Z","shell.execute_reply.started":"2021-07-11T14:39:34.366615Z","shell.execute_reply":"2021-07-11T14:39:34.375692Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"source = '/kaggle/input/siim-covid19-detection'\nos.listdir(source)","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.389910Z","iopub.execute_input":"2021-07-11T14:39:34.390155Z","iopub.status.idle":"2021-07-11T14:39:34.398583Z","shell.execute_reply.started":"2021-07-11T14:39:34.390130Z","shell.execute_reply":"2021-07-11T14:39:34.397774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_level = pd.read_csv(f'{source}/train_image_level.csv')\ntrain_study_level = pd.read_csv(f'{source}/train_study_level.csv')\nsample_submission = pd.read_csv(f'{source}/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.419569Z","iopub.execute_input":"2021-07-11T14:39:34.419861Z","iopub.status.idle":"2021-07-11T14:39:34.496130Z","shell.execute_reply.started":"2021-07-11T14:39:34.419835Z","shell.execute_reply":"2021-07-11T14:39:34.495334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_level.info()","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.498251Z","iopub.execute_input":"2021-07-11T14:39:34.498562Z","iopub.status.idle":"2021-07-11T14:39:34.523112Z","shell.execute_reply.started":"2021-07-11T14:39:34.498535Z","shell.execute_reply":"2021-07-11T14:39:34.522310Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_study_level.info()","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.526100Z","iopub.execute_input":"2021-07-11T14:39:34.526357Z","iopub.status.idle":"2021-07-11T14:39:34.540304Z","shell.execute_reply.started":"2021-07-11T14:39:34.526316Z","shell.execute_reply":"2021-07-11T14:39:34.539339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission.info()","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.541658Z","iopub.execute_input":"2021-07-11T14:39:34.541977Z","iopub.status.idle":"2021-07-11T14:39:34.554110Z","shell.execute_reply.started":"2021-07-11T14:39:34.541951Z","shell.execute_reply":"2021-07-11T14:39:34.553105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_level.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.555020Z","iopub.execute_input":"2021-07-11T14:39:34.555277Z","iopub.status.idle":"2021-07-11T14:39:34.570795Z","shell.execute_reply.started":"2021-07-11T14:39:34.555254Z","shell.execute_reply":"2021-07-11T14:39:34.569938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_study_level.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.571832Z","iopub.execute_input":"2021-07-11T14:39:34.572094Z","iopub.status.idle":"2021-07-11T14:39:34.581519Z","shell.execute_reply.started":"2021-07-11T14:39:34.572057Z","shell.execute_reply":"2021-07-11T14:39:34.580794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.582607Z","iopub.execute_input":"2021-07-11T14:39:34.582888Z","iopub.status.idle":"2021-07-11T14:39:34.594523Z","shell.execute_reply.started":"2021-07-11T14:39:34.582855Z","shell.execute_reply":"2021-07-11T14:39:34.593471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_level.shape","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.596067Z","iopub.execute_input":"2021-07-11T14:39:34.596327Z","iopub.status.idle":"2021-07-11T14:39:34.606430Z","shell.execute_reply.started":"2021-07-11T14:39:34.596302Z","shell.execute_reply":"2021-07-11T14:39:34.605713Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_study_level.shape","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.607545Z","iopub.execute_input":"2021-07-11T14:39:34.607797Z","iopub.status.idle":"2021-07-11T14:39:34.614711Z","shell.execute_reply.started":"2021-07-11T14:39:34.607773Z","shell.execute_reply":"2021-07-11T14:39:34.613767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission.shape","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.615790Z","iopub.execute_input":"2021-07-11T14:39:34.616098Z","iopub.status.idle":"2021-07-11T14:39:34.623007Z","shell.execute_reply.started":"2021-07-11T14:39:34.616060Z","shell.execute_reply":"2021-07-11T14:39:34.622300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_study_level.columns","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.624131Z","iopub.execute_input":"2021-07-11T14:39:34.624413Z","iopub.status.idle":"2021-07-11T14:39:34.634330Z","shell.execute_reply.started":"2021-07-11T14:39:34.624387Z","shell.execute_reply":"2021-07-11T14:39:34.633503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_level.columns","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.636467Z","iopub.execute_input":"2021-07-11T14:39:34.636861Z","iopub.status.idle":"2021-07-11T14:39:34.643764Z","shell.execute_reply.started":"2021-07-11T14:39:34.636822Z","shell.execute_reply":"2021-07-11T14:39:34.642995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_level.isna()","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.674525Z","iopub.execute_input":"2021-07-11T14:39:34.674794Z","iopub.status.idle":"2021-07-11T14:39:34.690726Z","shell.execute_reply.started":"2021-07-11T14:39:34.674770Z","shell.execute_reply":"2021-07-11T14:39:34.690066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission.columns","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.691731Z","iopub.execute_input":"2021-07-11T14:39:34.691972Z","iopub.status.idle":"2021-07-11T14:39:34.700790Z","shell.execute_reply.started":"2021-07-11T14:39:34.691948Z","shell.execute_reply":"2021-07-11T14:39:34.699836Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_study_level.isna()","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.704580Z","iopub.execute_input":"2021-07-11T14:39:34.704843Z","iopub.status.idle":"2021-07-11T14:39:34.720873Z","shell.execute_reply.started":"2021-07-11T14:39:34.704818Z","shell.execute_reply":"2021-07-11T14:39:34.719870Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission.isna()","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.734508Z","iopub.execute_input":"2021-07-11T14:39:34.734756Z","iopub.status.idle":"2021-07-11T14:39:34.746518Z","shell.execute_reply.started":"2021-07-11T14:39:34.734733Z","shell.execute_reply":"2021-07-11T14:39:34.745481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_level['boxes']","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.764632Z","iopub.execute_input":"2021-07-11T14:39:34.764892Z","iopub.status.idle":"2021-07-11T14:39:34.771479Z","shell.execute_reply.started":"2021-07-11T14:39:34.764868Z","shell.execute_reply":"2021-07-11T14:39:34.770572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_level['StudyInstanceUID']","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.795244Z","iopub.execute_input":"2021-07-11T14:39:34.795566Z","iopub.status.idle":"2021-07-11T14:39:34.802312Z","shell.execute_reply.started":"2021-07-11T14:39:34.795540Z","shell.execute_reply":"2021-07-11T14:39:34.801435Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Merge study csv to image csv.\ntrain_study_level['StudyInstanceUID'] = train_study_level['id'].apply(lambda x: x.replace('_study', ''))\ntrain_image_level = train_image_level.merge(train_study_level, on='StudyInstanceUID')\nsiim_covid = train_image_level.drop(['id_x','id_y'], axis=1)\nsiim_covid.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.803642Z","iopub.execute_input":"2021-07-11T14:39:34.803949Z","iopub.status.idle":"2021-07-11T14:39:34.835381Z","shell.execute_reply.started":"2021-07-11T14:39:34.803923Z","shell.execute_reply":"2021-07-11T14:39:34.834647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"siim_covid['Negative for Pneumonia'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.839591Z","iopub.execute_input":"2021-07-11T14:39:34.839860Z","iopub.status.idle":"2021-07-11T14:39:34.846008Z","shell.execute_reply.started":"2021-07-11T14:39:34.839837Z","shell.execute_reply":"2021-07-11T14:39:34.845278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"siim_covid['Typical Appearance'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.864965Z","iopub.execute_input":"2021-07-11T14:39:34.865236Z","iopub.status.idle":"2021-07-11T14:39:34.872042Z","shell.execute_reply.started":"2021-07-11T14:39:34.865210Z","shell.execute_reply":"2021-07-11T14:39:34.871197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"siim_covid['Indeterminate Appearance'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.873632Z","iopub.execute_input":"2021-07-11T14:39:34.873942Z","iopub.status.idle":"2021-07-11T14:39:34.883988Z","shell.execute_reply.started":"2021-07-11T14:39:34.873916Z","shell.execute_reply":"2021-07-11T14:39:34.882917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"siim_covid['Atypical Appearance'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:39:34.889701Z","iopub.execute_input":"2021-07-11T14:39:34.890152Z","iopub.status.idle":"2021-07-11T14:39:34.896118Z","shell.execute_reply.started":"2021-07-11T14:39:34.890114Z","shell.execute_reply":"2021-07-11T14:39:34.895453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import glob\nfrom tqdm import tqdm\n# Merge image path to the train_image_level dataframe.\ntrain_dir = '/kaggle/input/siim-covid19-detection/train'\ntest_dir = '/kaggle/input/siim-covid19-detection/test'\n\ntraining_paths = []\n\nfor sid in tqdm(siim_covid['StudyInstanceUID']):\n    training_paths.append(glob.glob(os.path.join(train_dir,sid+\"/*/*\"))[0])\n\nsiim_covid['path'] = training_paths\n\nsiim_covid.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:44:07.951610Z","iopub.execute_input":"2021-07-11T14:44:07.951957Z","iopub.status.idle":"2021-07-11T14:44:30.466943Z","shell.execute_reply.started":"2021-07-11T14:44:07.951929Z","shell.execute_reply":"2021-07-11T14:44:30.466004Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pydicom \nfrom pydicom import dcmread\nimport matplotlib.pyplot as plt\n%matplotlib inline\nlabel_appearance = list(siim_covid.columns)[3:7]\nrow_img = 3\ncol_img = len(label_appearance)\n\nc= 0\ncolor = 'gray'\nds_pos = [0 for p in range(row_img)]\n\nfig,ax = plt.subplots(row_img,col_img, figsize=(25,row_img*4))\n\nfor i in label_appearance:\n    for r in range(row_img):\n        link = siim_covid[siim_covid[i] == 1]['path'].iloc[r]\n        ds_pos[r] = pydicom.dcmread(link).pixel_array\n        ax[r,c].imshow(ds_pos[r], cmap=color)\n        \n      \n    ax[0,c].set_title(i, font='Serif', fontsize=20)\n    c +=1","metadata":{"execution":{"iopub.status.busy":"2021-07-11T14:57:24.522484Z","iopub.execute_input":"2021-07-11T14:57:24.522814Z","iopub.status.idle":"2021-07-11T14:57:37.501602Z","shell.execute_reply.started":"2021-07-11T14:57:24.522788Z","shell.execute_reply":"2021-07-11T14:57:37.500651Z"},"trusted":true},"execution_count":null,"outputs":[]}]}