|
1 | | -# TODO move this to tutorial |
2 | | -import datetime |
3 | | - |
4 | | -from auxiliary.turbopath import turbopath |
5 | | -from tqdm import tqdm |
6 | | - |
7 | | -from brainles_preprocessing.brats import preprocess_brats_style_t1_centric |
8 | | - |
9 | | - |
10 | | -def preprocess(inputDir): |
11 | | - inputDir = turbopath(inputDir) |
12 | | - try: |
13 | | - print("*** start ***") |
14 | | - |
15 | | - # where are the raw mr files? |
16 | | - btk_raw_dir = turbopath(inputDir) |
17 | | - |
18 | | - # is the exam already processed? |
19 | | - brainles_dir = turbopath(inputDir) + "/" + inputDir.name + "_brainles" |
20 | | - prep_dir = brainles_dir + "/preprocessed" |
21 | | - |
22 | | - # if not os.path.exists(prep_dir): |
23 | | - # if os.path.exists(prep_dir): |
24 | | - t1_file = btk_raw_dir.files("*t1.nii.gz") |
25 | | - t1c_file = btk_raw_dir.files("*t1c.nii.gz") |
26 | | - t2_file = btk_raw_dir.files("*t2.nii.gz") |
27 | | - flair_file = btk_raw_dir.files("*fla.nii.gz") |
28 | | - |
29 | | - if len(t1_file) == len(t1c_file) == len(t2_file) == len(flair_file) == 1: |
30 | | - print(t1_file) |
31 | | - print(t1c_file) |
32 | | - print(t2_file) |
33 | | - print(flair_file) |
34 | | - |
35 | | - t1File = t1_file[0] |
36 | | - t1cFile = t1c_file[0] |
37 | | - t2File = t2_file[0] |
38 | | - flaFile = flair_file[0] |
39 | | - |
40 | | - # execute it |
41 | | - preprocess_brats_style_t1_centric( |
42 | | - input_t1=t1File, |
43 | | - output_t1=prep_dir + "/" + inputDir.name + "_t1.nii.gz", |
44 | | - input_t1c=t1cFile, |
45 | | - output_t1c=prep_dir + "/" + inputDir.name + "_t1c.nii.gz", |
46 | | - input_t2=t2File, |
47 | | - output_t2=prep_dir + "/" + inputDir.name + "_t2.nii.gz", |
48 | | - input_flair=flaFile, |
49 | | - output_flair=prep_dir + "/" + inputDir.name + "_fla.nii.gz", |
50 | | - bet_mode="gpu", |
51 | | - limit_cuda_visible_devices="0", |
52 | | - temporary_directory="tempo/" + inputDir.name, |
53 | | - keep_coregistration=brainles_dir + "/co-registration", |
54 | | - keep_atlas_registration=brainles_dir + "/atlas-registration", |
55 | | - keep_brainextraction=brainles_dir + "/brain-extraction", |
56 | | - ) |
57 | | - |
58 | | - except Exception as e: |
59 | | - print("error: " + str(e)) |
60 | | - print("conversion error for:", inputDir) |
61 | | - |
62 | | - time = str(datetime.datetime.now().time()) |
63 | | - |
64 | | - print("** finished:", inputDir.name, "at:", time) |
65 | | - |
66 | | - |
67 | | -### *** GOGOGO *** ### |
68 | | -if __name__ == "__main__": |
69 | | - EXAMPLE_DATA_DIR = turbopath("example_data") |
70 | | - |
71 | | - exams = EXAMPLE_DATA_DIR.dirs() |
72 | | - |
73 | | - for exam in tqdm(exams): |
74 | | - print(exam) |
75 | | - preprocess(exam) |
| 1 | +# TODO non-functional atm |
| 2 | +# # TODO move this to tutorial |
| 3 | +# import datetime |
| 4 | + |
| 5 | +# from auxiliary.turbopath import turbopath |
| 6 | +# from tqdm import tqdm |
| 7 | + |
| 8 | +# from brainles_preprocessing.brats import preprocess_brats_style_t1_centric |
| 9 | + |
| 10 | + |
| 11 | +# def preprocess(inputDir): |
| 12 | +# inputDir = turbopath(inputDir) |
| 13 | +# try: |
| 14 | +# print("*** start ***") |
| 15 | + |
| 16 | +# # where are the raw mr files? |
| 17 | +# btk_raw_dir = turbopath(inputDir) |
| 18 | + |
| 19 | +# # is the exam already processed? |
| 20 | +# brainles_dir = turbopath(inputDir) + "/" + inputDir.name + "_brainles" |
| 21 | +# prep_dir = brainles_dir + "/preprocessed" |
| 22 | + |
| 23 | +# # if not os.path.exists(prep_dir): |
| 24 | +# # if os.path.exists(prep_dir): |
| 25 | +# t1_file = btk_raw_dir.files("*t1.nii.gz") |
| 26 | +# t1c_file = btk_raw_dir.files("*t1c.nii.gz") |
| 27 | +# t2_file = btk_raw_dir.files("*t2.nii.gz") |
| 28 | +# flair_file = btk_raw_dir.files("*fla.nii.gz") |
| 29 | + |
| 30 | +# if len(t1_file) == len(t1c_file) == len(t2_file) == len(flair_file) == 1: |
| 31 | +# print(t1_file) |
| 32 | +# print(t1c_file) |
| 33 | +# print(t2_file) |
| 34 | +# print(flair_file) |
| 35 | + |
| 36 | +# t1File = t1_file[0] |
| 37 | +# t1cFile = t1c_file[0] |
| 38 | +# t2File = t2_file[0] |
| 39 | +# flaFile = flair_file[0] |
| 40 | + |
| 41 | +# # execute it |
| 42 | +# preprocess_brats_style_t1_centric( |
| 43 | +# input_t1=t1File, |
| 44 | +# output_t1=prep_dir + "/" + inputDir.name + "_t1.nii.gz", |
| 45 | +# input_t1c=t1cFile, |
| 46 | +# output_t1c=prep_dir + "/" + inputDir.name + "_t1c.nii.gz", |
| 47 | +# input_t2=t2File, |
| 48 | +# output_t2=prep_dir + "/" + inputDir.name + "_t2.nii.gz", |
| 49 | +# input_flair=flaFile, |
| 50 | +# output_flair=prep_dir + "/" + inputDir.name + "_fla.nii.gz", |
| 51 | +# bet_mode="gpu", |
| 52 | +# limit_cuda_visible_devices="0", |
| 53 | +# temporary_directory="tempo/" + inputDir.name, |
| 54 | +# keep_coregistration=brainles_dir + "/co-registration", |
| 55 | +# keep_atlas_registration=brainles_dir + "/atlas-registration", |
| 56 | +# keep_brainextraction=brainles_dir + "/brain-extraction", |
| 57 | +# ) |
| 58 | + |
| 59 | +# except Exception as e: |
| 60 | +# print("error: " + str(e)) |
| 61 | +# print("conversion error for:", inputDir) |
| 62 | + |
| 63 | +# time = str(datetime.datetime.now().time()) |
| 64 | + |
| 65 | +# print("** finished:", inputDir.name, "at:", time) |
| 66 | + |
| 67 | + |
| 68 | +# ### *** GOGOGO *** ### |
| 69 | +# if __name__ == "__main__": |
| 70 | +# EXAMPLE_DATA_DIR = turbopath("example_data") |
| 71 | + |
| 72 | +# exams = EXAMPLE_DATA_DIR.dirs() |
| 73 | + |
| 74 | +# for exam in tqdm(exams): |
| 75 | +# print(exam) |
| 76 | +# preprocess(exam) |
0 commit comments