{"cells":[{"metadata":{"trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"input_folder = \"../input/osic-pulmonary-fibrosis-progression/\"\ndf = pd.read_csv(input_folder + 'train.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"pd.DataFrame({ \"value count\": df.nunique(), \"mean\": df.mean(), \"std\": df.std(), \"min\": df.min(), \"max\": df.max() })","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plot_grid = [['Weeks', 'FVC', 'Percent'], ['Age', 'Sex', 'SmokingStatus']]\nnrows = len(plot_grid)\nncols = len(plot_grid[0])\nfig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=(20,10))\nfor i in range(nrows):\n  for j in range(ncols):\n    column = plot_grid[i][j]\n    ax = axes[i][j]\n    df[column].hist(ax=ax, bins=40)\n    ax.set_title(column)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df2 = df[['FVC', 'Percent', 'Age']]\n\nplt.matshow(df2.corr())\nplt.xticks(range(len(df2.columns)), df2.columns)\nplt.yticks(range(len(df2.columns)), df2.columns)\nplt.colorbar()\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"patient_id = 'ID00007637202177411956430'\npatient = df[df['Patient'] == patient_id]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax1 = plt.subplots()\n\nax1.scatter(patient['Weeks'], patient['FVC'], marker='x')\nax1.set_ylabel('FVC')\n\nax2 = ax1.twinx()\nax2.scatter(patient['Weeks'], patient['Percent'], marker='+')\nax2.set_ylabel('Percent')\n\nfig.tight_layout()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(20,10))\nax.set_xlabel('Weeks')\nax.set_ylabel('FVC')\nfor patient_id in np.random.choice(df['Patient'].unique(), 10):\n  patient = df[df['Patient'] == patient_id]\n  ax.plot(patient['Weeks'], patient['FVC'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"nrows = 5\nncols = 5\nfig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=(20,20))\npatient_ids = np.random.choice(df['Patient'].unique(), size=(nrows, ncols))\nfor i in range(nrows):\n  for j in range(ncols):\n    patient_id = patient_ids[i][j]\n    ax = axes[i][j]\n    patient = df[df['Patient'] == patient_id]\n    ax.scatter(patient['Weeks'], patient['FVC'])\n    ax.set_ylabel('FVC')\n    ax.set_title(patient_id)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import pydicom\n\nfrom os import listdir\n\npatient_id = 'ID00007637202177411956430'\n\ndicom_folder = input_folder + \"train/\" + patient_id + \"/\"\ndicom_files = listdir(dicom_folder)\ndicom_files.sort(key=lambda file: int(file.split('.')[0]))\n\nncols = 5\nnrows = (len(dicom_files)+1) // ncols\nfig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=(30,30))\nfor i in range(nrows):\n  for j in range(ncols):\n    n = 1 + i*ncols+j\n    if n == len(dicom_files)+1:\n        break\n\n    filename = dicom_folder + str(n) + \".dcm\"\n    img = pydicom.read_file(filename)\n    ax = axes[i][j]\n    ax.imshow(img.pixel_array, cmap='gray') # plt.cm.bone\n    ax.axis('off')\n","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}