{"cells":[{"metadata":{"trusted":true},"cell_type":"code","source":"scans = !ls /kaggle/input/rsna-str-pulmonary-embolism-detection/train/*/* -d\nlen(scans)\n\nfrom tqdm import tqdm\ncount_min = 10e6\ncount_max = 0\nfor s in tqdm(scans):\n    cnt, = !ls {s}/* | wc -l # this is super-slow.. probably avoiding \"!\" would be a good idea\n    count_min = min(count_min, int(cnt))\n    count_max = max(count_max, int(cnt))\ncount_min, count_max","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"import numpy as np\n\nimport matplotlib\nimport matplotlib.pyplot as plt\n\nimport matplotlib.animation as animation\n\nfrom matplotlib import animation, rc\nfrom pydicom import dcmread\n\n\nrc('animation', html='jshtml')\n\n\ndef read_scan(path):\n    fs = !ls -d {path}/*\n    \n    slices = []\n    for f in fs:\n        ds = dcmread(f)\n        data = ds.pixel_array\n        num = int(ds.InstanceNumber)\n        slices.append((num, data))\n    \n    slices.sort()\n    slices = [s[1] for s in slices]\n    return slices\n\ndef create_animation(ims):\n    ims = ims\n    fps = 30\n    nSeconds = 5\n\n    fig = plt.figure( figsize=(9,9) )\n\n    a = ims[0]\n    im = plt.imshow(a)\n\n    def animate_func(i):\n        im.set_array(ims[i])\n        return [im]\n\n    anim = animation.FuncAnimation(fig, animate_func, frames = len(ims), interval = 1000//24)\n    \n    return anim\n\ns1 = scans[1]\nims = read_scan(s1)\nanim = create_animation(ims)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"anim","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"f,*_ = !ls -d {scans[1]}/*\nmeta = dcmread(f)\nmeta","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"cols = \"pe_present_on_image\tnegative_exam_for_pe\tqa_motion\tqa_contrast\tflow_artifact\trv_lv_ratio_gte_1\trv_lv_ratio_lt_1\tleftsided_pe\tchronic_pe\ttrue_filling_defect_not_pe\trightsided_pe\tacute_and_chronic_pe\tcentral_pe\tindeterminate\".split()\n\n\n\nfig = plt.figure( figsize=(12,12) )\npie = train[cols].sum()\nplt.pie(pie, labels=pie.index)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"PATH = \"../input/rsna-str-pulmonary-embolism-detection/\"\ntrain = pd.read_csv(PATH + \"train.csv\")\nsub = pd.read_csv(PATH + \"sample_submission.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"feats = list(train.columns[3:5])+list(train.columns[8:12])+list(train.columns[13:17])\nfeats","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"means = train[feats].mean().to_dict()\nmeans","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub['label'] = means['negative_exam_for_pe']\nfor feat in means.keys():\n    sub.loc[sub.id.str.contains(feat, regex=False), 'label'] = means[feat]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub.to_csv('submission.csv', index = False, float_format='%.4g')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","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}