|
57 | 57 | }, |
58 | 58 | { |
59 | 59 | "cell_type": "code", |
60 | | - "execution_count": 5, |
| 60 | + "execution_count": 1, |
61 | 61 | "metadata": {}, |
62 | 62 | "outputs": [ |
63 | 63 | { |
64 | 64 | "name": "stdout", |
65 | 65 | "output_type": "stream", |
66 | 66 | "text": [ |
67 | | - "Requirement already satisfied: brainles_preprocessing in /home/florian/miniconda3/envs/aurora_tutorial/lib/python3.10/site-packages (0.0.23)\n", |
68 | | - "Requirement already satisfied: brats_toolkit in /home/florian/.local/lib/python3.10/site-packages (1.0.11)\n", |
| 67 | + "Requirement already satisfied: brainles_preprocessing in /home/florian/miniconda3/envs/aurora_tutorial/lib/python3.10/site-packages (0.0.24)\n", |
69 | 68 | "Requirement already satisfied: auxiliary in /home/florian/miniconda3/envs/aurora_tutorial/lib/python3.10/site-packages (0.0.40)\n", |
70 | 69 | "Requirement already satisfied: BrainLes-HD-BET>=0.0.5 in /home/florian/miniconda3/envs/aurora_tutorial/lib/python3.10/site-packages (from brainles_preprocessing) (0.0.5)\n", |
71 | 70 | "Requirement already satisfied: nibabel<4.0.0,>=3.2.1 in /home/florian/miniconda3/envs/aurora_tutorial/lib/python3.10/site-packages (from brainles_preprocessing) (3.2.2)\n", |
|
75 | 74 | "Requirement already satisfied: rich<14.0.0,>=13.6.0 in /home/florian/.local/lib/python3.10/site-packages (from brainles_preprocessing) (13.7.0)\n", |
76 | 75 | "Requirement already satisfied: tqdm<5.0.0,>=4.64.1 in /home/florian/miniconda3/envs/aurora_tutorial/lib/python3.10/site-packages (from brainles_preprocessing) (4.66.1)\n", |
77 | 76 | "Requirement already satisfied: ttictoc<0.6.0,>=0.5.6 in /home/florian/miniconda3/envs/aurora_tutorial/lib/python3.10/site-packages (from brainles_preprocessing) (0.5.6)\n", |
78 | | - "Requirement already satisfied: SimpleITK<3.0.0,>=2.3.1 in /home/florian/.local/lib/python3.10/site-packages (from brats_toolkit) (2.3.1)\n", |
79 | | - "Requirement already satisfied: python-engineio<4.0.0,>=3.14.2 in /home/florian/.local/lib/python3.10/site-packages (from brats_toolkit) (3.14.2)\n", |
80 | | - "Requirement already satisfied: python-socketio<5.0.0,>=4.6.1 in /home/florian/.local/lib/python3.10/site-packages (from brats_toolkit) (4.6.1)\n", |
81 | | - "Requirement already satisfied: requests<3.0.0,>=2.24.0 in /home/florian/miniconda3/envs/aurora_tutorial/lib/python3.10/site-packages (from brats_toolkit) (2.31.0)\n", |
82 | 77 | "Requirement already satisfied: pillow>=10.0.0 in /home/florian/miniconda3/envs/aurora_tutorial/lib/python3.10/site-packages (from auxiliary) (10.2.0)\n", |
83 | 78 | "Requirement already satisfied: tifffile>=2023.8.25 in /home/florian/.local/lib/python3.10/site-packages (from auxiliary) (2023.12.9)\n", |
84 | 79 | "Requirement already satisfied: torch>=0.4.1 in /home/florian/.local/lib/python3.10/site-packages (from BrainLes-HD-BET>=0.0.5->brainles_preprocessing) (2.1.2)\n", |
85 | 80 | "Requirement already satisfied: scikit-image>=0.21.0 in /home/florian/.local/lib/python3.10/site-packages (from BrainLes-HD-BET>=0.0.5->brainles_preprocessing) (0.22.0)\n", |
| 81 | + "Requirement already satisfied: SimpleITK>=2.2.1 in /home/florian/.local/lib/python3.10/site-packages (from BrainLes-HD-BET>=0.0.5->brainles_preprocessing) (2.3.1)\n", |
86 | 82 | "Requirement already satisfied: packaging>=14.3 in /home/florian/.local/lib/python3.10/site-packages (from nibabel<4.0.0,>=3.2.1->brainles_preprocessing) (23.2)\n", |
87 | 83 | "Requirement already satisfied: setuptools in /home/florian/miniconda3/envs/aurora_tutorial/lib/python3.10/site-packages (from nibabel<4.0.0,>=3.2.1->brainles_preprocessing) (68.2.2)\n", |
88 | | - "Requirement already satisfied: six>=1.9.0 in /home/florian/miniconda3/envs/aurora_tutorial/lib/python3.10/site-packages (from python-engineio<4.0.0,>=3.14.2->brats_toolkit) (1.16.0)\n", |
89 | | - "Requirement already satisfied: charset-normalizer<4,>=2 in /home/florian/miniconda3/envs/aurora_tutorial/lib/python3.10/site-packages (from requests<3.0.0,>=2.24.0->brats_toolkit) (3.3.2)\n", |
90 | | - "Requirement already satisfied: idna<4,>=2.5 in /home/florian/miniconda3/envs/aurora_tutorial/lib/python3.10/site-packages (from requests<3.0.0,>=2.24.0->brats_toolkit) (3.6)\n", |
91 | | - "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/florian/miniconda3/envs/aurora_tutorial/lib/python3.10/site-packages (from requests<3.0.0,>=2.24.0->brats_toolkit) (2.2.0)\n", |
92 | | - "Requirement already satisfied: certifi>=2017.4.17 in /home/florian/miniconda3/envs/aurora_tutorial/lib/python3.10/site-packages (from requests<3.0.0,>=2.24.0->brats_toolkit) (2024.2.2)\n", |
93 | 84 | "Requirement already satisfied: markdown-it-py>=2.2.0 in /home/florian/.local/lib/python3.10/site-packages (from rich<14.0.0,>=13.6.0->brainles_preprocessing) (3.0.0)\n", |
94 | 85 | "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /home/florian/.local/lib/python3.10/site-packages (from rich<14.0.0,>=13.6.0->brainles_preprocessing) (2.17.2)\n", |
95 | 86 | "Requirement already satisfied: mdurl~=0.1 in /home/florian/.local/lib/python3.10/site-packages (from markdown-it-py>=2.2.0->rich<14.0.0,>=13.6.0->brainles_preprocessing) (0.1.2)\n", |
|
127 | 118 | "Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in /home/florian/miniconda3/envs/aurora_tutorial/lib/python3.10/site-packages (from matplotlib) (3.1.1)\n", |
128 | 119 | "Requirement already satisfied: python-dateutil>=2.1 in /home/florian/miniconda3/envs/aurora_tutorial/lib/python3.10/site-packages (from matplotlib) (2.8.2)\n", |
129 | 120 | "Requirement already satisfied: six>=1.5 in /home/florian/miniconda3/envs/aurora_tutorial/lib/python3.10/site-packages (from python-dateutil>=2.1->matplotlib) (1.16.0)\n", |
130 | | - "Note: you may need to restart the kernel to use updated packages.\n", |
131 | | - "The autoreload extension is already loaded. To reload it, use:\n", |
132 | | - " %reload_ext autoreload\n" |
| 121 | + "Note: you may need to restart the kernel to use updated packages.\n" |
133 | 122 | ] |
134 | 123 | } |
135 | 124 | ], |
|
153 | 142 | }, |
154 | 143 | { |
155 | 144 | "cell_type": "code", |
156 | | - "execution_count": 6, |
| 145 | + "execution_count": 2, |
157 | 146 | "metadata": {}, |
158 | 147 | "outputs": [], |
159 | 148 | "source": [ |
|
164 | 153 | }, |
165 | 154 | { |
166 | 155 | "cell_type": "code", |
167 | | - "execution_count": 7, |
| 156 | + "execution_count": 3, |
168 | 157 | "metadata": {}, |
169 | 158 | "outputs": [], |
170 | 159 | "source": [ |
|
174 | 163 | }, |
175 | 164 | { |
176 | 165 | "cell_type": "code", |
177 | | - "execution_count": 8, |
| 166 | + "execution_count": 4, |
178 | 167 | "metadata": {}, |
179 | 168 | "outputs": [], |
180 | 169 | "source": [ |
|
228 | 217 | }, |
229 | 218 | { |
230 | 219 | "cell_type": "code", |
231 | | - "execution_count": 15, |
| 220 | + "execution_count": 5, |
232 | 221 | "metadata": {}, |
233 | 222 | "outputs": [], |
234 | 223 | "source": [ |
|
240 | 229 | "\n", |
241 | 230 | "from brainles_preprocessing.brain_extraction import HDBetExtractor\n", |
242 | 231 | "from brainles_preprocessing.modality import Modality\n", |
243 | | - "from brainles_preprocessing.preprocessor import Preprocessor, PreprocessorGPU\n", |
| 232 | + "from brainles_preprocessing.preprocessor import Preprocessor\n", |
244 | 233 | "from brainles_preprocessing.registration import NiftyRegRegistrator\n", |
245 | 234 | "\n", |
246 | 235 | "\n", |
247 | | - "def preprocess(inputDir):\n", |
| 236 | + "def preprocess_exam_in_brats_style(inputDir: str) -> None:\n", |
| 237 | + " \"\"\"\n", |
| 238 | + " Perform BRATS (Brain Tumor Segmentation) style preprocessing on MRI exam data.\n", |
| 239 | + "\n", |
| 240 | + " Args:\n", |
| 241 | + " inputDir (str): Path to the directory containing raw MRI files for an exam.\n", |
| 242 | + "\n", |
| 243 | + " Raises:\n", |
| 244 | + " Exception: If any error occurs during the preprocessing.\n", |
| 245 | + "\n", |
| 246 | + " Example:\n", |
| 247 | + " brat_style_preprocess_exam(\"/path/to/exam_directory\")\n", |
| 248 | + "\n", |
| 249 | + " This function preprocesses MRI exam data following the BRATS style, which includes the following steps:\n", |
| 250 | + " 1. Normalization using a percentile normalizer.\n", |
| 251 | + " 2. Registration and correction using NiftyReg.\n", |
| 252 | + " 3. Brain extraction using HDBet.\n", |
| 253 | + "\n", |
| 254 | + " The processed data is saved in a structured directory within the input directory.\n", |
| 255 | + "\n", |
| 256 | + " Args:\n", |
| 257 | + " inputDir (str): Path to the directory containing raw MRI files for an exam.\n", |
| 258 | + "\n", |
| 259 | + " Returns:\n", |
| 260 | + " None\n", |
| 261 | + " \"\"\"\n", |
248 | 262 | " inputDir = turbopath(inputDir)\n", |
249 | 263 | " try:\n", |
250 | 264 | " print(\"*** start ***\")\n", |
|
350 | 364 | " moving_modalities=moving_modalities,\n", |
351 | 365 | " registrator=NiftyRegRegistrator(),\n", |
352 | 366 | " brain_extractor=HDBetExtractor(),\n", |
353 | | - " # temp_folder=\"tempo\",\n", |
354 | | - " limit_cuda_visible_devices=\"1\",\n", |
| 367 | + " # optional: we provide a temporary directory as a sandbox for the preprocessin\n", |
| 368 | + " temp_folder=\"temporary_directory\",\n", |
| 369 | + " limit_cuda_visible_devices=\"0\",\n", |
355 | 370 | " )\n", |
356 | 371 | "\n", |
357 | 372 | " preprocessor.run(\n", |
|
379 | 394 | }, |
380 | 395 | { |
381 | 396 | "cell_type": "code", |
382 | | - "execution_count": 16, |
| 397 | + "execution_count": 6, |
383 | 398 | "metadata": {}, |
384 | 399 | "outputs": [ |
385 | 400 | { |
|
452 | 467 | "\n", |
453 | 468 | "for exam in tqdm(exams):\n", |
454 | 469 | " print(\"processing:\", exam)\n", |
455 | | - " brat_style_preprocess_exam(exam)" |
| 470 | + " preprocess_exam_in_brats_style(exam)" |
456 | 471 | ] |
457 | 472 | } |
458 | 473 | ], |
|
0 commit comments