|
a |
|
b/Preprocessing Medical Data Pipeline/createDirectories.py |
|
|
1 |
import os |
|
|
2 |
import shutil |
|
|
3 |
|
|
|
4 |
def createDirectoriesfunc(): |
|
|
5 |
def make_if_dont_exist(folder_path,overwrite): |
|
|
6 |
""" |
|
|
7 |
creates a folder if it does not exists |
|
|
8 |
input: |
|
|
9 |
folder_path : relative path of the folder which needs to be created |
|
|
10 |
over_write :(default: False) if True overwrite the existing folder |
|
|
11 |
""" |
|
|
12 |
if os.path.exists(folder_path): |
|
|
13 |
|
|
|
14 |
if not overwrite: |
|
|
15 |
print(f"{folder_path} exists.") |
|
|
16 |
else: |
|
|
17 |
print(f"{folder_path} overwritten") |
|
|
18 |
shutil.rmtree(folder_path) |
|
|
19 |
os.makedirs(folder_path) |
|
|
20 |
|
|
|
21 |
else: |
|
|
22 |
os.makedirs(folder_path) |
|
|
23 |
print(f"{folder_path} created!") |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
base_directory = 'D:/MRI - Tairawhiti (User POV)' |
|
|
28 |
new_folder_name = ['nnUNet Data', 'Raw NIFITI Segmentation Masks (3D Slicer Output)', 'Pre-Trained Models (Google Colab)', 'Model Code', 'Raw DICOM MRI Scans', 'Patient Segmentation Tasks (Google Colab)'] |
|
|
29 |
overwrite = False |
|
|
30 |
for new_fname in new_folder_name: |
|
|
31 |
folder_path = os.path.join(base_directory, new_fname) |
|
|
32 |
make_if_dont_exist(folder_path, overwrite) |
|
|
33 |
|
|
|
34 |
|
|
|
35 |
base_directory = 'D:/MRI - Tairawhiti (User POV)/nnUNet Data' |
|
|
36 |
new_folder_name = ['masks', 'multiclass_masks', 'scans'] |
|
|
37 |
for new_fname in new_folder_name: |
|
|
38 |
folder_path = os.path.join(base_directory, new_fname) |
|
|
39 |
make_if_dont_exist(folder_path, overwrite) |
|
|
40 |
|
|
|
41 |
|
|
|
42 |
base_directory = 'D:/MRI - Tairawhiti (User POV)/nnUNet Data/masks' |
|
|
43 |
new_folder_name = ['FEMUR', 'FIBULA', 'TIBIA', 'PELVIS'] |
|
|
44 |
for new_fname in new_folder_name: |
|
|
45 |
folder_path = os.path.join(base_directory, new_fname) |
|
|
46 |
make_if_dont_exist(folder_path, overwrite) |