{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":71549,"databundleVersionId":8561470,"sourceType":"competition"},{"sourceId":9378297,"sourceType":"datasetVersion","datasetId":5689011},{"sourceId":8740526,"sourceType":"datasetVersion","datasetId":5247666}],"dockerImageVersionId":31089,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing,CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\n\nbase_path = \"/kaggle/input/rsna-2024-lumbar-spine-degenerative-classification\"\ntest_path = os.path.join(base_path, \"test_images\")\n\nimport pandas as pd\ndf = pd.read_csv(base_path+\"/train_series_descriptions.csv\")\nstirs=df.query(\"series_description=='Sagittal T2/STIR'\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-23T12:16:42.763691Z","iopub.execute_input":"2025-07-23T12:16:42.764057Z","iopub.status.idle":"2025-07-23T12:16:42.821081Z","shell.execute_reply.started":"2025-07-23T12:16:42.764015Z","shell.execute_reply":"2025-07-23T12:16:42.819744Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"stirs","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-23T12:16:48.071829Z","iopub.execute_input":"2025-07-23T12:16:48.072162Z","iopub.status.idle":"2025-07-23T12:16:48.098449Z","shell.execute_reply.started":"2025-07-23T12:16:48.072137Z","shell.execute_reply":"2025-07-23T12:16:48.097426Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nimport shutil\nimport tqdm\nimport time\nimport pandas as pd\n\n# Assuming stirs is your dataframe with ['study_id', 'series_id']\n# Example: stirs = pd.DataFrame([[\"44036939\", \"2828203845\"], [\"4018853\", \"238948394\"]])\n\ndef downloader(x, y, z=\"8.dcm\"):\n    src_path = f\"/kaggle/input/rsna-2024-lumbar-spine-degenerative-classification/train_images/{x}/{y}/{z}\"\n    dst_folder = f\"/kaggle/working/GGHADID/{x}\"\n    dst_path = os.path.join(dst_folder, z)\n\n    if not os.path.exists(src_path):\n        print(f\"❌ File not found: {src_path}\")\n        return\n\n    os.makedirs(dst_folder, exist_ok=True)\n    shutil.copy(src_path, dst_path)\n    print(f\"✅ Copied {z} to {dst_folder}\")\n\n# Run the downloader\nfor i in tqdm.tqdm(range(len(stirs))):\n    study_id = str(stirs.iloc[i, 0])\n    series_id = str(stirs.iloc[i, 1])\n    downloader(study_id, series_id)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-23T12:18:25.125913Z","iopub.execute_input":"2025-07-23T12:18:25.126264Z","iopub.status.idle":"2025-07-23T12:19:12.028225Z","shell.execute_reply.started":"2025-07-23T12:18:25.126241Z","shell.execute_reply":"2025-07-23T12:19:12.027242Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import shutil\n\nshutil.make_archive('/kaggle/working/GGHADID_zip', 'zip', '/kaggle/working/GGHADID')\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-07-23T12:20:15.243230Z","iopub.execute_input":"2025-07-23T12:20:15.244114Z","iopub.status.idle":"2025-07-23T12:20:46.216361Z","shell.execute_reply.started":"2025-07-23T12:20:15.244081Z","shell.execute_reply":"2025-07-23T12:20:46.215154Z"}},"outputs":[],"execution_count":null}]}