{"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":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import json\nimport pandas as pd\nfrom pathlib import Path","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-11-16T05:56:30.659027Z","iopub.execute_input":"2024-11-16T05:56:30.659426Z","iopub.status.idle":"2024-11-16T05:56:31.706057Z","shell.execute_reply.started":"2024-11-16T05:56:30.659385Z","shell.execute_reply":"2024-11-16T05:56:31.704807Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"input_dir = Path(\"/kaggle/input/czii-cryo-et-object-identification/train/overlay/ExperimentRuns\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-16T05:56:31.708538Z","iopub.execute_input":"2024-11-16T05:56:31.709513Z","iopub.status.idle":"2024-11-16T05:56:31.715007Z","shell.execute_reply.started":"2024-11-16T05:56:31.709446Z","shell.execute_reply":"2024-11-16T05:56:31.713704Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_list = []\nfor experiment_dir_path in input_dir.glob(\"*\"):\n    for annotation_path in experiment_dir_path.glob(\"Picks/*.json\"):\n        with open(annotation_path, 'r') as file:\n            annotation = json.load(file)\n            run_name = annotation[\"run_name\"]\n            particle_type = annotation[\"pickable_object_name\"]\n            for point in annotation[\"points\"]:\n                df_list.append({\n                    \"experiment\": run_name,\n                    \"particle_type\": particle_type,\n                    \"x\": point[\"location\"][\"x\"],\n                    \"y\": point[\"location\"][\"y\"],\n                    \"z\": point[\"location\"][\"z\"]\n                })","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-16T05:56:31.716325Z","iopub.execute_input":"2024-11-16T05:56:31.716785Z","iopub.status.idle":"2024-11-16T05:56:31.917992Z","shell.execute_reply.started":"2024-11-16T05:56:31.716717Z","shell.execute_reply":"2024-11-16T05:56:31.916724Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = pd.DataFrame(df_list)\ndf.to_csv(\"train.csv\", index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-16T05:56:31.920536Z","iopub.execute_input":"2024-11-16T05:56:31.921511Z","iopub.status.idle":"2024-11-16T05:56:31.950245Z","shell.execute_reply.started":"2024-11-16T05:56:31.921458Z","shell.execute_reply":"2024-11-16T05:56:31.949110Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-16T05:56:31.954208Z","iopub.execute_input":"2024-11-16T05:56:31.954563Z","iopub.status.idle":"2024-11-16T05:56:31.987929Z","shell.execute_reply.started":"2024-11-16T05:56:31.954525Z","shell.execute_reply":"2024-11-16T05:56:31.986789Z"}},"outputs":[],"execution_count":null}]}