Skip to content

Commit a60a1cf

Browse files
authored
Merge pull request #26 from BrainLesion/better-documentation
Better documentation
2 parents 5bc41bb + 034f583 commit a60a1cf

File tree

8 files changed

+101
-111
lines changed

8 files changed

+101
-111
lines changed

README.md

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,12 @@ The outcome of this processing sequence is a set of 4 NIFTI images, skull-stripp
1212

1313
## Atlas Reference
1414

15-
The atlas employed in our workflow is based on the following publication:
16-
[Link to the Atlas Article](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2915788/)
15+
We use the SRI-24 atlas from this [publication](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2915788/)
1716

1817

1918
## Installation
19+
With a Python 3.10+ environment you can install directly from [pypi.org](https://pypi.org/project/brainles-preprocessing/):
2020

21-
22-
1. **Directly from the GitHub Repository**:
23-
Using pip, you can directly install the preprocessing tool:
24-
25-
```bash
26-
pip install git+https://github.com/BrainLesion/preprocessing.git
27-
```
28-
29-
2. **Clone and Install Locally**:
30-
For a local installation, you can clone the repository and then install it:
31-
32-
```bash
33-
git clone https://github.com/BrainLesion/preprocessing.git
34-
cd preprocessing
35-
pip install .
36-
```
37-
38-
## Directory Reference
39-
40-
`/home/florian/flow/BrainLesion/BrainLes/preprocessing`
21+
```
22+
pip install brainles-preprocessing
23+
```

brainles_preprocessing/brain_extraction/brain_extractor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
# TODO add typing and docs
12
from abc import abstractmethod
23

34
import nibabel as nib
45
import numpy as np
5-
66
from brainles_hd_bet import run_hd_bet
77

88

brainles_preprocessing/modality.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
# todo add typing and docs
12
import os
23
import shutil
34

45
from auxiliary.nifti.io import read_nifti, write_nifti
56
from auxiliary.normalization.normalizer_base import Normalizer
67
from auxiliary.turbopath import turbopath
78

9+
from brainles_preprocessing.registration.registrator import Registrator
10+
811

912
class Modality:
1013
"""
@@ -82,9 +85,9 @@ def normalize(
8285
def register(
8386
self,
8487
registrator,
85-
fixed_image_path,
86-
registration_dir,
87-
moving_image_name,
88+
fixed_image_path: str,
89+
registration_dir: str,
90+
moving_image_name: str,
8891
):
8992
registered = os.path.join(registration_dir, f"{moving_image_name}.nii.gz")
9093
registered_matrix = os.path.join(registration_dir, f"{moving_image_name}.txt")
@@ -120,7 +123,7 @@ def apply_mask(
120123

121124
def transform(
122125
self,
123-
registrator,
126+
registrator: Registrator,
124127
fixed_image_path,
125128
registration_dir,
126129
moving_image_name,

brainles_preprocessing/preprocessor.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
# TODO add typing and documentation
12
import os
23
import shutil
34
import tempfile
45

56
from auxiliary.turbopath import turbopath
67

7-
from .modality import Modality
88
from .brain_extraction.brain_extractor import BrainExtractor
9+
from .modality import Modality
910
from .registration.registrator import Registrator
1011

1112

@@ -14,9 +15,9 @@ def __init__(
1415
self,
1516
center_modality: Modality,
1617
moving_modalities: list[Modality],
17-
registrator,
18-
brain_extractor,
19-
atlas_image_path=turbopath(__file__).parent
18+
registrator: Registrator,
19+
brain_extractor: BrainExtractor,
20+
atlas_image_path: str = turbopath(__file__).parent
2021
+ "/registration/atlas/t1_brats_space.nii",
2122
temp_folder=None,
2223
):
@@ -170,9 +171,9 @@ def __init__(
170171
self,
171172
center_modality: Modality,
172173
moving_modalities: list[Modality],
173-
registrator,
174-
brain_extractor,
175-
atlas_image_path=turbopath(__file__).parent
174+
registrator: Registrator,
175+
brain_extractor: BrainExtractor,
176+
atlas_image_path: str = turbopath(__file__).parent
176177
+ "/registration/atlas/t1_brats_space.nii",
177178
temp_folder=None,
178179
limit_cuda_visible_devices: str = None,

brainles_preprocessing/registration/niftyreg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
# TODO add typing and docs
12
import os
23

34
from auxiliary.runscript import ScriptRunner
45
from auxiliary.turbopath import turbopath
5-
from ttictoc import Timer
66

77
from brainles_preprocessing.registration.registrator import Registrator
88

brainles_preprocessing/registration/registrator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# TODO add typing and docs
12
from abc import ABC, abstractmethod
23

34

example_modality_centric_preprocessor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
# TODO move this to tutorial
2+
# TODO polish this
23
import datetime
34

45
from auxiliary.normalization.percentile_normalizer import PercentileNormalizer
56
from auxiliary.turbopath import turbopath
67
from tqdm import tqdm
78

9+
from brainles_preprocessing.brain_extraction import HDBetExtractor
810
from brainles_preprocessing.modality import Modality
911
from brainles_preprocessing.preprocessor import Preprocessor, PreprocessorGPU
1012
from brainles_preprocessing.registration import NiftyRegRegistrator
11-
from brainles_preprocessing.brain_extraction import HDBetExtractor
1213

1314

1415
def preprocess(inputDir):

example_preprocessing_brats.py

Lines changed: 76 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,76 @@
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

Comments
 (0)