{"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":30804,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Working In Progress\n\n# IMPORTANT NOTE \n\nI'm not a domain expert so take this as shared learning exercise that will certanly contain errors.","metadata":{"execution":{"iopub.status.busy":"2024-12-13T21:56:31.158119Z","iopub.execute_input":"2024-12-13T21:56:31.158544Z","iopub.status.idle":"2024-12-13T21:56:31.165174Z","shell.execute_reply.started":"2024-12-13T21:56:31.158503Z","shell.execute_reply":"2024-12-13T21:56:31.163836Z"}}},{"cell_type":"code","source":"def ls(path):#\n    for path in path.iterdir():\n        if path.is_dir():\n            print('📁', path,)\n        elif path.is_file():\n            print('📄', path)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-14T08:57:15.242990Z","iopub.execute_input":"2024-12-14T08:57:15.243462Z","iopub.status.idle":"2024-12-14T08:57:15.280539Z","shell.execute_reply.started":"2024-12-14T08:57:15.243415Z","shell.execute_reply":"2024-12-14T08:57:15.279191Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\n\ndata_folder = Path('/kaggle/input/czii-cryo-et-object-identification/')\nworking_folder = Path('/kaggle/working')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T08:57:15.282842Z","iopub.execute_input":"2024-12-14T08:57:15.283373Z","iopub.status.idle":"2024-12-14T08:57:15.289788Z","shell.execute_reply.started":"2024-12-14T08:57:15.283322Z","shell.execute_reply":"2024-12-14T08:57:15.288439Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ls(data_folder)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T08:57:15.291261Z","iopub.execute_input":"2024-12-14T08:57:15.291639Z","iopub.status.idle":"2024-12-14T08:57:15.307703Z","shell.execute_reply.started":"2024-12-14T08:57:15.291565Z","shell.execute_reply":"2024-12-14T08:57:15.306275Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Sample Sumission","metadata":{"execution":{"iopub.status.busy":"2024-12-13T21:29:54.303010Z","iopub.execute_input":"2024-12-13T21:29:54.303394Z","iopub.status.idle":"2024-12-13T21:29:54.308308Z","shell.execute_reply.started":"2024-12-13T21:29:54.303358Z","shell.execute_reply":"2024-12-13T21:29:54.307294Z"}}},{"cell_type":"code","source":"import pandas as pd ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T08:57:15.310016Z","iopub.execute_input":"2024-12-14T08:57:15.310389Z","iopub.status.idle":"2024-12-14T08:57:16.681793Z","shell.execute_reply.started":"2024-12-14T08:57:15.310350Z","shell.execute_reply":"2024-12-14T08:57:16.680413Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = pd.read_csv(data_folder / 'sample_submission.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T08:57:16.683759Z","iopub.execute_input":"2024-12-14T08:57:16.684433Z","iopub.status.idle":"2024-12-14T08:57:16.705178Z","shell.execute_reply.started":"2024-12-14T08:57:16.684364Z","shell.execute_reply":"2024-12-14T08:57:16.703631Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.head(3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T08:57:16.707177Z","iopub.execute_input":"2024-12-14T08:57:16.707696Z","iopub.status.idle":"2024-12-14T08:57:16.736976Z","shell.execute_reply.started":"2024-12-14T08:57:16.707642Z","shell.execute_reply":"2024-12-14T08:57:16.735624Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Train Folder","metadata":{"execution":{"iopub.status.busy":"2024-12-13T21:31:27.718511Z","iopub.execute_input":"2024-12-13T21:31:27.718970Z","iopub.status.idle":"2024-12-13T21:31:27.723782Z","shell.execute_reply.started":"2024-12-13T21:31:27.718930Z","shell.execute_reply":"2024-12-13T21:31:27.722611Z"}}},{"cell_type":"code","source":"ls(data_folder / 'train')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T08:57:16.738645Z","iopub.execute_input":"2024-12-14T08:57:16.739128Z","iopub.status.idle":"2024-12-14T08:57:16.748260Z","shell.execute_reply.started":"2024-12-14T08:57:16.739079Z","shell.execute_reply":"2024-12-14T08:57:16.746110Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Static folder  ","metadata":{"execution":{"iopub.status.busy":"2024-12-13T21:31:51.703375Z","iopub.execute_input":"2024-12-13T21:31:51.703744Z","iopub.status.idle":"2024-12-13T21:31:51.708580Z","shell.execute_reply.started":"2024-12-13T21:31:51.703711Z","shell.execute_reply":"2024-12-13T21:31:51.707502Z"}}},{"cell_type":"code","source":"ls(data_folder / 'train' / 'static')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T08:57:16.750194Z","iopub.execute_input":"2024-12-14T08:57:16.750807Z","iopub.status.idle":"2024-12-14T08:57:16.766085Z","shell.execute_reply.started":"2024-12-14T08:57:16.750763Z","shell.execute_reply":"2024-12-14T08:57:16.764679Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"### ExperimentRuns folder","metadata":{"execution":{"iopub.status.busy":"2024-12-13T21:32:32.447074Z","iopub.execute_input":"2024-12-13T21:32:32.447595Z","iopub.status.idle":"2024-12-13T21:32:32.452978Z","shell.execute_reply.started":"2024-12-13T21:32:32.447544Z","shell.execute_reply":"2024-12-13T21:32:32.451689Z"}}},{"cell_type":"code","source":"ls(data_folder / 'train' / 'static' / 'ExperimentRuns' )","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T08:57:16.769969Z","iopub.execute_input":"2024-12-14T08:57:16.771212Z","iopub.status.idle":"2024-12-14T08:57:16.786604Z","shell.execute_reply.started":"2024-12-14T08:57:16.771155Z","shell.execute_reply":"2024-12-14T08:57:16.785149Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"So each experiment seam to have an Id which corrispnd to the ide we have looked above for the `sample_submission.csv`","metadata":{}},{"cell_type":"markdown","source":"#### TS_86_3 folder","metadata":{"execution":{"iopub.status.busy":"2024-12-13T21:33:07.678168Z","iopub.execute_input":"2024-12-13T21:33:07.678555Z","iopub.status.idle":"2024-12-13T21:33:07.683317Z","shell.execute_reply.started":"2024-12-13T21:33:07.678520Z","shell.execute_reply":"2024-12-13T21:33:07.682054Z"}}},{"cell_type":"code","source":"ls(data_folder / 'train' / 'static' / 'ExperimentRuns' /  'TS_86_3')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T08:57:16.788541Z","iopub.execute_input":"2024-12-14T08:57:16.789072Z","iopub.status.idle":"2024-12-14T08:57:16.798178Z","shell.execute_reply.started":"2024-12-14T08:57:16.789015Z","shell.execute_reply":"2024-12-14T08:57:16.796588Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ls(data_folder / 'train' / 'static' / 'ExperimentRuns' /  'TS_86_3' / 'VoxelSpacing10.000')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T08:57:16.799877Z","iopub.execute_input":"2024-12-14T08:57:16.800357Z","iopub.status.idle":"2024-12-14T08:57:16.814805Z","shell.execute_reply.started":"2024-12-14T08:57:16.800307Z","shell.execute_reply":"2024-12-14T08:57:16.813510Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Each experiment have a sub folder which name have 3 part\n\n- Voxel\n- Spacing\n- 10.000\n\n  In this folder we have 4 subfolder\n\n  -  isonetcorrected.zarr\n  -  ctfdeconvolved.zarr\n  -  wbp.zarr\n  -  denoised.zarr\n\n All the 4 folder  end with `zarr` \n\n","metadata":{}},{"cell_type":"code","source":"ls(data_folder / 'train' / 'static' / 'ExperimentRuns' /  'TS_86_3' / 'VoxelSpacing10.000' / 'isonetcorrected.zarr')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T08:57:16.816238Z","iopub.execute_input":"2024-12-14T08:57:16.816714Z","iopub.status.idle":"2024-12-14T08:57:16.838717Z","shell.execute_reply.started":"2024-12-14T08:57:16.816662Z","shell.execute_reply":"2024-12-14T08:57:16.837347Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"> Zarr is an open standard for storing large multidimensional array data. It specifies a protocol and data format, and is designed to be \"cloud ready\" including random access, by dividing data into subsets referred to as chunks\n\nfrom Wikipedia","metadata":{"execution":{"iopub.status.busy":"2024-12-14T08:57:16.840387Z","iopub.execute_input":"2024-12-14T08:57:16.840827Z","iopub.status.idle":"2024-12-14T08:57:16.863506Z","shell.execute_reply.started":"2024-12-14T08:57:16.840790Z","shell.execute_reply":"2024-12-14T08:57:16.861365Z"}}},{"cell_type":"markdown","source":"The data tab say that \n\nThis are 4 filtered versions of the tomograms. \n\nit also say that wbp stay for weighted back projection \n\nAnd that in the test set we will just found the `denoised.zarr` folder\n","metadata":{}},{"cell_type":"markdown","source":"**What is a tomogram ?**\n\n> A two-dimensional image produced by tomography, representing a slice or section through a three-dimensional object. \n\nWiktionary","metadata":{"execution":{"iopub.status.busy":"2024-12-13T21:46:08.174481Z","iopub.execute_input":"2024-12-13T21:46:08.175400Z","iopub.status.idle":"2024-12-13T21:46:08.180300Z","shell.execute_reply.started":"2024-12-13T21:46:08.175353Z","shell.execute_reply":"2024-12-13T21:46:08.179323Z"}}},{"cell_type":"markdown","source":"In this case they talk about 3D tomogram so we need to undertand what is the meaning here,\nif they mean that is a slice of 3D or a 3D slice of what. ","metadata":{}},{"cell_type":"markdown","source":"> Tomography is imaging by sections or sectioning that uses any kind of penetrating wave.\n> \n> .. is derived from Ancient Greek τόμος tomos, \"slice, section\" and γράφω graphō\n\nWikiepdia\n\n","metadata":{"execution":{"iopub.status.busy":"2024-12-13T21:47:47.065779Z","iopub.execute_input":"2024-12-13T21:47:47.067013Z","iopub.status.idle":"2024-12-13T21:47:47.073569Z","shell.execute_reply.started":"2024-12-13T21:47:47.066965Z","shell.execute_reply":"2024-12-13T21:47:47.072056Z"}}},{"cell_type":"code","source":"#!pip install \"copick[all]\"","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T08:57:16.864861Z","iopub.status.idle":"2024-12-14T08:57:16.865259Z","shell.execute_reply.started":"2024-12-14T08:57:16.865078Z","shell.execute_reply":"2024-12-14T08:57:16.865098Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!pip install zarr","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T09:07:29.959826Z","iopub.execute_input":"2024-12-14T09:07:29.960276Z","iopub.status.idle":"2024-12-14T09:07:46.847109Z","shell.execute_reply.started":"2024-12-14T09:07:29.960239Z","shell.execute_reply":"2024-12-14T09:07:46.845710Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"by looking at [1] here how we could expect one of this folder ","metadata":{}},{"cell_type":"code","source":"import zarr\nvol = zarr.open(data_folder / 'train' / 'static' / 'ExperimentRuns' /  'TS_86_3' / 'VoxelSpacing10.000' / 'isonetcorrected.zarr', mode='r')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T09:16:03.391766Z","iopub.execute_input":"2024-12-14T09:16:03.392177Z","iopub.status.idle":"2024-12-14T09:16:03.410764Z","shell.execute_reply.started":"2024-12-14T09:16:03.392142Z","shell.execute_reply":"2024-12-14T09:16:03.409131Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"It seam ","metadata":{}},{"cell_type":"code","source":"vol[0]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T09:16:04.327334Z","iopub.execute_input":"2024-12-14T09:16:04.327765Z","iopub.status.idle":"2024-12-14T09:16:04.343236Z","shell.execute_reply.started":"2024-12-14T09:16:04.327728Z","shell.execute_reply":"2024-12-14T09:16:04.341733Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"vol[1]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T09:16:05.103713Z","iopub.execute_input":"2024-12-14T09:16:05.104105Z","iopub.status.idle":"2024-12-14T09:16:05.119848Z","shell.execute_reply.started":"2024-12-14T09:16:05.104065Z","shell.execute_reply":"2024-12-14T09:16:05.118435Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"It seam there are two version, and reading at [1] seam they represent the same images but the first sema the more detailed versions.\nSo the first dimension seam represent the number of images while the second and therid the dimention of the image.","metadata":{}},{"cell_type":"markdown","source":"So the following should be (no at all sure yet) a 2d slide of the first image in 315x315 resulution","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt \n\nplt.imshow(vol[1][0])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T09:22:45.263831Z","iopub.execute_input":"2024-12-14T09:22:45.264300Z","iopub.status.idle":"2024-12-14T09:22:45.921257Z","shell.execute_reply.started":"2024-12-14T09:22:45.264263Z","shell.execute_reply":"2024-12-14T09:22:45.919817Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"By looking at [2] it make more clear what this could repreent.\nIn this notebook the author try to visualize the experiment TS_6_4","metadata":{}},{"cell_type":"markdown","source":"Also the author help understanding the 4 version of th image with a visulization ","metadata":{}},{"cell_type":"code","source":"fig = plt.figure(figsize=(10,10))\nax = plt.subplot(2, 2, 1)\nplt.xticks([])\nplt.yticks([])\nplt.title('Denoised')\nvol = zarr.open(data_folder / 'train' / 'static' / 'ExperimentRuns' /  'TS_86_3' / 'VoxelSpacing10.000' / 'denoised.zarr', mode='r')\nplt.imshow(vol[0][62], cmap='gray')\nax = plt.subplot(2, 2, 2)\nplt.xticks([])\nplt.yticks([])\nplt.title('IsoNet Corrected')\nvol = zarr.open(data_folder / 'train' / 'static' / 'ExperimentRuns' /  'TS_86_3' / 'VoxelSpacing10.000' / 'isonetcorrected.zarr', mode='r')\nplt.imshow(vol[0][62], cmap='gray')\nax = plt.subplot(2, 2, 3)\nplt.xticks([])\nplt.yticks([])\nplt.title('CTF Deconvolved')\nvol = zarr.open(data_folder / 'train' / 'static' / 'ExperimentRuns' /  'TS_86_3' / 'VoxelSpacing10.000' / 'wbp.zarr', mode='r')\nplt.imshow(vol[0][62], cmap='gray')\nax = plt.subplot(2, 2, 4)\nplt.xticks([])\nplt.yticks([])\nplt.title('Weighted Back Projection')\nvol = zarr.open(data_folder / 'train' / 'static' / 'ExperimentRuns' /  'TS_86_3' / 'VoxelSpacing10.000' / 'isonetcorrected.zarr', mode='r')\n_ = plt.imshow(vol[0][62], cmap='gray')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-14T09:32:38.451293Z","iopub.execute_input":"2024-12-14T09:32:38.451751Z","iopub.status.idle":"2024-12-14T09:32:49.325594Z","shell.execute_reply.started":"2024-12-14T09:32:38.451712Z","shell.execute_reply":"2024-12-14T09:32:49.324455Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Notebookgraphy\n\n[1] https://www.kaggle.com/code/itsuki9180/czii-making-datasets-for-yolo\n\n[2] https://www.kaggle.com/code/davidlist/experiment-ts-6-4-visualization","metadata":{"execution":{"iopub.status.busy":"2024-12-14T09:07:48.936658Z","iopub.execute_input":"2024-12-14T09:07:48.937077Z","iopub.status.idle":"2024-12-14T09:07:48.946045Z","shell.execute_reply.started":"2024-12-14T09:07:48.937040Z","shell.execute_reply":"2024-12-14T09:07:48.944392Z"}}},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}