File size: 2,156 Bytes
3120fa9
9435739
faf3b5a
d21da4f
2abae3a
 
2c24e9f
 
faf3b5a
ac935be
faf3b5a
d21da4f
331dce4
8a35a57
331dce4
d21da4f
331dce4
d21da4f
331dce4
8a35a57
331dce4
362a9f8
331dce4
188227a
9435739
 
 
5f6ee91
 
 
 
b953767
 
 
 
 
188227a
 
 
8a35a57
188227a
 
2abae3a
9435739
 
 
faf3b5a
 
 
d21da4f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import sys
import os
import warnings
import argparse


os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'  # due to this: https://github.com/tensorflow/tensorflow/issues/35029
warnings.filterwarnings('ignore', '.*output shape of zoom.*')  # mute some warnings


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-i', '--input', type=str, nargs='?',
                    help="set path of which image(s) to use.")
    parser.add_argument('-o', '--output', type=str, nargs='?',
                    help="set path to store the output.")
    parser.add_argument('-c', '--cpu', action='store_true',
                    help="force using the CPU even if a GPU is available.")
    parser.add_argument('-v', '--verbose', action='store_true',
                    help="enable verbose.")
    parser.add_argument('-vs', '--vessels', action='store_true',
                    help="segment vessels.")
    parser.add_argument('-e', '--extension', type=str, default=".nii",
                    help="define the output extension. (default: .nii)")
    ret = parser.parse_args(sys.argv[1:])
    print(ret)

    if ret.input is None:
        raise ValueError("Please, provide an input.")
    if ret.output is None:
        raise ValueError("Please, provide an output.")

    # fix paths
    ret.input = ret.input.replace("\\", "/")
    ret.output = ret.output.replace("\\", "/")

    if not os.path.isdir(ret.input) and not ret.input.endswith(".nii") and not ret.input.endswith(".nii.gz"):
        raise ValueError("Input path provided is not in the supported '.nii' or '.nii.gz' formats or a directory.")
    if ret.output.endswith(".nii") or ret.output.endswith(".nii.gz") or "." in ret.output.split("/")[-1]:
        raise ValueError("Output path provided is not a directory or a name (remove *.nii format from name).")
    if ret.extension not in [".nii", ".nii.gz"]:
        raise ValueError("Extension not supported. Expected: .nii or .nii.gz")

    # finally, import run_analysis method with relevant imports and run analysis
    from .utils.run import run_analysis
    run_analysis(*vars(ret).values())


if __name__ == "__main__":
    main()