-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_bullseyes.py
76 lines (65 loc) · 3.19 KB
/
create_bullseyes.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import argparse
import sys
import os
import getopt
import matplotlib.pyplot as plt
from bullseyes.bullseye_plotting import read_ls_create_agglo, \
create_bullseye_plot, FULL_LABELS, FULL_LABELS_IT, TERR_LABELS,\
prepare_data_fromagglo
from bullseyes.creation_ls_file import creation_ls, write_ls
from nifty_utils.file_utils import split_filename
def main(argv):
parser = argparse.ArgumentParser(description='Create database of local '
'summaries ')
parser.add_argument('-f', dest='filewrite', metavar='file where to write',
type=str, required=True,
help='File where to write result')
parser.add_argument('-type', dest='type', choices=['struct','vasc'],
type=str)
parser.add_argument('-l', dest='layer_file', action='store',
help='Layer image to use', type=str)
parser.add_argument('-o', dest='lobe_file', action='store',
help='Lobar image to use', type=str)
parser.add_argument('-nl', dest='numb_layers', action='store', default=4,
type=int)
parser.add_argument('-p', dest='path_result', action='store',
help='Path where to save the results', type=str,
default=os.getcwd())
parser.add_argument('-ci', dest='corr_it', action='store_true',
help='indicates if we should correct for the '
'infratentorial region')
parser.add_argument('-n', dest='name', action='store', default='',
help='name to use for the saving of the bullseye plot')
try:
args = parser.parse_args(argv)
except getopt.GetoptError:
print('creation_ls_file.py -l <layer_file> -f <filename_write> -o '
'<lobar_file> -s '
'<segmentation_file> ')
sys.exit(2)
if args.type == 'struct':
num_lobes = 9
labels = FULL_LABELS
else:
num_lobes = 7
labels = TERR_LABELS
if args.lobe_file is not None and args.layer_file is not None and \
args.lesion_file is not None:
vol_prob, vol_bin, vol_reg, connect = creation_ls(args.lobe_file,
args.layer_file,
args.lesion_file)
if args.filewrite is None:
[path, basename, _] = split_filename(args.lesion_file)
filewrite = os.path.join(path, 'LocalSummary_'+basename+'.txt')
write_ls(vol_prob, vol_bin, vol_reg, connect, args.filewrite)
if args.filewrite is not None:
les, reg, freq, dist = read_ls_create_agglo(args.filewrite, type='vasc')
freq_full = prepare_data_fromagglo(freq, type_prepa="full",
type_lobes='vasc')
create_bullseye_plot(freq_full, 'YlOrRd', num_layers=args.numb_layers,
num_lobes=num_lobes, vmin=0, vmax=0.25,
labels=labels)
plt.savefig(os.path.join(args.path_result, 'BE_'+args.name+'2.png'))
print("printednow")
if __name__ == "__main__":
main(sys.argv[1:])