{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":84969,"databundleVersionId":10033515,"sourceType":"competition"}],"dockerImageVersionId":30786,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# CZII Data 3D View","metadata":{}},{"cell_type":"markdown","source":"https://www.kaggle.com/code/stpeteishii/czii-zarr-image-view\n\nhttps://www.kaggle.com/code/stpeteishii/czii-data-3d-view","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport numpy as np\nimport os","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def display_tree(root_dir, indent=\"\"):\n    print(indent + os.path.basename(root_dir) + \"/\")\n    indent += \"    \"\n    \n    try:\n        for item in os.listdir(root_dir):\n            item_path = os.path.join(root_dir, item)\n            if os.path.isdir(item_path):\n                display_tree(item_path, indent)\n            else:\n                print(indent + item)\n                \n    except PermissionError:\n        print(indent + \"[Access Denied]\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-08T04:37:05.876844Z","iopub.execute_input":"2024-11-08T04:37:05.877337Z","iopub.status.idle":"2024-11-08T04:37:05.886573Z","shell.execute_reply.started":"2024-11-08T04:37:05.87729Z","shell.execute_reply":"2024-11-08T04:37:05.885306Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"dir0=\"/kaggle/input/czii-cryo-et-object-identification/train/overlay/ExperimentRuns/TS_5_4\"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"display_tree(dir0)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-08T04:37:05.888869Z","iopub.execute_input":"2024-11-08T04:37:05.889323Z","iopub.status.idle":"2024-11-08T04:37:05.920257Z","shell.execute_reply.started":"2024-11-08T04:37:05.889266Z","shell.execute_reply":"2024-11-08T04:37:05.918831Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"paths=[]\nfor dirname, _, filenames in os.walk(dir0):\n    for filename in filenames:\n        paths+=[(os.path.join(dirname, filename))]\nprint(paths)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-08T04:37:05.922533Z","iopub.execute_input":"2024-11-08T04:37:05.922969Z","iopub.status.idle":"2024-11-08T04:37:05.932411Z","shell.execute_reply.started":"2024-11-08T04:37:05.922926Z","shell.execute_reply":"2024-11-08T04:37:05.931064Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import json\n\ndef load_from_json(file_path):\n    with open(file_path, 'r', encoding='utf-8') as f:\n        data = json.load(f)\n    return data","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-08T04:37:05.952722Z","iopub.execute_input":"2024-11-08T04:37:05.95315Z","iopub.status.idle":"2024-11-08T04:37:05.962418Z","shell.execute_reply.started":"2024-11-08T04:37:05.953108Z","shell.execute_reply":"2024-11-08T04:37:05.961245Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from collections import defaultdict\ncnt = defaultdict(int)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-08T04:37:05.964622Z","iopub.execute_input":"2024-11-08T04:37:05.965056Z","iopub.status.idle":"2024-11-08T04:37:05.971Z","shell.execute_reply.started":"2024-11-08T04:37:05.964993Z","shell.execute_reply":"2024-11-08T04:37:05.969714Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"L=[]\nfor i,path in enumerate(paths):\n    data=load_from_json(path)\n    cnt[i]=data['pickable_object_name']\n    X=[]\n    Y=[]\n    Z=[]\n    for datai in data['points']:\n        xyz=datai['location']\n        X+=[xyz['x']]\n        Y+=[xyz['y']]\n        Z+=[xyz['z']]\n    L+=[(i,X,Y,Z)]\n\nprint(cnt)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-08T04:37:06.002938Z","iopub.execute_input":"2024-11-08T04:37:06.003408Z","iopub.status.idle":"2024-11-08T04:37:06.021514Z","shell.execute_reply.started":"2024-11-08T04:37:06.003363Z","shell.execute_reply":"2024-11-08T04:37:06.020413Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fig = plt.figure(figsize=(13,13))\nax = fig.add_subplot(111, projection='3d')\n\nfor data in L:\n    i, X, Y, Z = data  \n    scatter = ax.scatter(X, Y, Z, c=[i]*len(X), vmin=0, vmax=5, cmap='viridis', label=cnt[i]) \n\nax.set_xlabel('X Label')\nax.set_ylabel('Y Label')\nax.set_zlabel('Z Label')\ncbar = fig.colorbar(scatter, ax=ax)\ncbar.set_label('Label')\nax.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-08T04:37:06.024083Z","iopub.execute_input":"2024-11-08T04:37:06.024511Z","iopub.status.idle":"2024-11-08T04:37:06.540351Z","shell.execute_reply.started":"2024-11-08T04:37:06.024468Z","shell.execute_reply":"2024-11-08T04:37:06.539105Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}