{"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":"# 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\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\n# 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\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\nadd Codeadd Markdown","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"code","source":"import os","metadata":{"execution":{"iopub.status.busy":"2021-07-22T07:02:06.058419Z","iopub.execute_input":"2021-07-22T07:02:06.058760Z","iopub.status.idle":"2021-07-22T07:02:06.064314Z","shell.execute_reply.started":"2021-07-22T07:02:06.058731Z","shell.execute_reply":"2021-07-22T07:02:06.063470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pydicom\nimport pandas as pd\nimport re\nimport numpy as np\nfrom glob import glob\nimport matplotlib.pyplot as plt\n\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2021-07-22T07:02:00.538612Z","iopub.execute_input":"2021-07-22T07:02:00.538977Z","iopub.status.idle":"2021-07-22T07:02:00.901142Z","shell.execute_reply.started":"2021-07-22T07:02:00.538945Z","shell.execute_reply":"2021-07-22T07:02:00.900199Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_dir='../input/rsna-miccai-brain-tumor-radiogenomic-classification/train/'\npatients=sorted(os.listdir(data_dir))\nlabels_df=pd.read_csv('../input/rsna-miccai-brain-tumor-radiogenomic-classification/train_labels.csv')\n\nlabels_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-07-22T07:02:09.494388Z","iopub.execute_input":"2021-07-22T07:02:09.494712Z","iopub.status.idle":"2021-07-22T07:02:09.579093Z","shell.execute_reply.started":"2021-07-22T07:02:09.494685Z","shell.execute_reply":"2021-07-22T07:02:09.578153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"patients[1]\n#labels_df[labels_df['BraTS21ID']==688]","metadata":{"execution":{"iopub.status.busy":"2021-07-22T07:02:12.900563Z","iopub.execute_input":"2021-07-22T07:02:12.900951Z","iopub.status.idle":"2021-07-22T07:02:12.907121Z","shell.execute_reply.started":"2021-07-22T07:02:12.900919Z","shell.execute_reply":"2021-07-22T07:02:12.906160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image=[]\nfor brats21id in patients[:5]:\n    mgmt_value=labels_df[labels_df['BraTS21ID']==3]['MGMT_value'].iloc[0]\n    path = data_dir+brats21id\n    \n    for _,sub_paths in enumerate(glob(path+'/*')):\n        \n        # Remember: To remove all the slices with pixel_arrays all 0\n        slices=[pydicom.dcmread(sub_paths+'/'+s) for s in os.listdir(sub_paths)]\n        slices=sorted(slices,key=lambda x: int(x.InstanceNumber))\n        \n        image.append(slices)\n        #print(sub_paths)\n        #print(len(slices),slices[0].pixel_array.shape)","metadata":{"execution":{"iopub.status.busy":"2021-07-22T07:19:04.243749Z","iopub.execute_input":"2021-07-22T07:19:04.244294Z","iopub.status.idle":"2021-07-22T07:19:13.201567Z","shell.execute_reply.started":"2021-07-22T07:19:04.244250Z","shell.execute_reply":"2021-07-22T07:19:13.200574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig=plt.figure(figsize=(6,6))\nplt.axis='off'\nplt.title('MGMT-value'+' = 0')\nplt.imshow(image[3][200].pixel_array,cmap='bone')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-07-22T07:21:47.066180Z","iopub.execute_input":"2021-07-22T07:21:47.066600Z","iopub.status.idle":"2021-07-22T07:21:47.287742Z","shell.execute_reply.started":"2021-07-22T07:21:47.066564Z","shell.execute_reply":"2021-07-22T07:21:47.286090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}