{"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":"# modified codes from https://www.kaggle.com/shilpagopal/rsna-exploratory-data-analysis-wip","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-08-03T08:33:33.242204Z","iopub.execute_input":"2021-08-03T08:33:33.242659Z","iopub.status.idle":"2021-08-03T08:33:33.666949Z","shell.execute_reply.started":"2021-08-03T08:33:33.242563Z","shell.execute_reply":"2021-08-03T08:33:33.665947Z"}}},{"cell_type":"markdown","source":"https://dicom.innolitics.com/ciods/rt-dose/image-plane/00200037","metadata":{}},{"cell_type":"markdown","source":"# EDA\n## Goal: preparing adequate dicom data","metadata":{}},{"cell_type":"markdown","source":"## Importing packages","metadata":{}},{"cell_type":"code","source":"import os\nimport pydicom","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"PATH = \"../input/rsna-miccai-brain-tumor-radiogenomic-classification\"","metadata":{"execution":{"iopub.status.busy":"2021-08-03T08:33:33.862076Z","iopub.execute_input":"2021-08-03T08:33:33.862428Z","iopub.status.idle":"2021-08-03T08:33:33.86707Z","shell.execute_reply.started":"2021-08-03T08:33:33.862391Z","shell.execute_reply":"2021-08-03T08:33:33.865991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"id_list = os.listdir(PATH+\"/train\")\n\nprint(\"Numbers of ID in train dir: \", len(id_list))","metadata":{"execution":{"iopub.status.busy":"2021-08-03T08:33:34.404289Z","iopub.execute_input":"2021-08-03T08:33:34.404634Z","iopub.status.idle":"2021-08-03T08:33:34.440854Z","shell.execute_reply.started":"2021-08-03T08:33:34.404605Z","shell.execute_reply":"2021-08-03T08:33:34.440101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dict_list = {}\ndict_list2 = {}","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"id_list[0]","metadata":{"execution":{"iopub.status.busy":"2021-08-03T08:33:35.071955Z","iopub.execute_input":"2021-08-03T08:33:35.072465Z","iopub.status.idle":"2021-08-03T08:33:35.080965Z","shell.execute_reply.started":"2021-08-03T08:33:35.072433Z","shell.execute_reply":"2021-08-03T08:33:35.079965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# PATH+'/train/'+os.listdir(PATH+'/train')[0]","metadata":{"execution":{"iopub.status.busy":"2021-08-03T08:33:37.334005Z","iopub.execute_input":"2021-08-03T08:33:37.334352Z","iopub.status.idle":"2021-08-03T08:33:37.342327Z","shell.execute_reply.started":"2021-08-03T08:33:37.334322Z","shell.execute_reply":"2021-08-03T08:33:37.341264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Get number of files in the train set","metadata":{}},{"cell_type":"code","source":"for i in id_list:\n    tmp_path = PATH+'/train/'+i\n    sub_list = os.listdir(tmp_path) #\"FLAIR\", \"T1w\", \"T1wCE\", \"T2w\"\n    sub_dict = {}\n    sum = 0\n    for j in sub_list:\n        tmp_tmp_path = tmp_path+\"/\"+j\n        len_list = len(os.listdir(tmp_tmp_path))\n        sub_dict[j] = len_list\n        sum += len_list\n        sub_dict[\"sum\"] = sum\n    dict_list[str(i)] = sub_dict","metadata":{"execution":{"iopub.status.busy":"2021-08-03T08:33:40.755206Z","iopub.execute_input":"2021-08-03T08:33:40.755558Z","iopub.status.idle":"2021-08-03T08:34:41.178875Z","shell.execute_reply.started":"2021-08-03T08:33:40.755529Z","shell.execute_reply":"2021-08-03T08:34:41.177908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Get orientation of images grouped by sequences\n\n## Correct the deviation of ImageOrientationPatient tags","metadata":{}},{"cell_type":"code","source":"for i in id_list:\n    tmp_path = PATH+\"/train/\"+i\n    sub_list = os.listdir(tmp_path) #\"FLAIR\", \"T1w\", \"T1wCE\", \"T2w\"\n    sub_dict_position = {}\n    for j in sub_list:\n        rt = \"unknown\"\n        tmp_tmp_path = tmp_path+\"/\"+j\n        (x1,y1,_,x2,y2,_) = pydicom.dcmread(tmp_tmp_path+'/'+os.listdir(tmp_tmp_path)[0]).ImageOrientationPatient\n        \n    \n        if (x1<1 and x1>0.7) and (y1<0.7 and y1>-0.7) and (x2<0.7 and x2>-0.7) and (y2<0.7 and y2>-0.7):\n            rt = 'coronal'\n        if (x1<1 and x1>0.7) and (y1<0.7 and y1>-0.7) and (x2<0.7 and x2>-0.7) and (y2<1 and y2>0.7): # (1,0,0,1):\n            rt = 'axial'\n        if (x1<0.7 and x1>-0.7) and (y1<1 and y1>0.7) and (x2<0.7 and x2>-0.7) and (y2<0.7 and y2>-0.7):\n            rt = 'sagittal'\n        \n#         if (x1,y1,x2,y2) == (1,0,0,0):# \n#             rt = 'coronal'\n#         if (x1,y1,x2,y2) == (1,0,0,1):\n#             rt = 'axial'\n#         if (x1,y1,x2,y2) == (0,1,0,0):\n#             rt = 'sagittal'\n        sub_dict_position[j] = rt\n    dict_list2[str(i)] = sub_dict_position","metadata":{"execution":{"iopub.status.busy":"2021-08-03T08:48:03.200189Z","iopub.execute_input":"2021-08-03T08:48:03.200683Z","iopub.status.idle":"2021-08-03T08:48:26.14682Z","shell.execute_reply.started":"2021-08-03T08:48:03.200638Z","shell.execute_reply":"2021-08-03T08:48:26.145909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for key in dict_list.keys():\n    print(key, \" : \", dict_list[key])","metadata":{"execution":{"iopub.status.busy":"2021-08-03T08:48:31.842242Z","iopub.execute_input":"2021-08-03T08:48:31.842959Z","iopub.status.idle":"2021-08-03T08:48:32.051587Z","shell.execute_reply.started":"2021-08-03T08:48:31.842919Z","shell.execute_reply":"2021-08-03T08:48:32.050443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for key in dict_list2.keys():\n    print(key, \" : \", dict_list2[key])","metadata":{"execution":{"iopub.status.busy":"2021-08-03T08:48:39.924105Z","iopub.execute_input":"2021-08-03T08:48:39.924472Z","iopub.status.idle":"2021-08-03T08:48:40.141626Z","shell.execute_reply.started":"2021-08-03T08:48:39.924442Z","shell.execute_reply":"2021-08-03T08:48:40.140374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# ??? train/00058/FLAIR images ??? (x1, y1, x2, y2) = (1, 0, 1, 0) ???? axial","metadata":{}}]}