-
Notifications
You must be signed in to change notification settings - Fork 1
/
dcm-plot-vois.py
executable file
·83 lines (59 loc) · 2.17 KB
/
dcm-plot-vois.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
76
77
78
79
80
81
82
83
#!/usr/bin/env python
import nilearn
from nilearn import plotting
from matplotlib.pyplot import cm
import numpy
from numpy import linspace
import sys
HLP_MSG="""
Usage
-----
$ dcm-plot-vois.sh <voi_xyz_1> <voi_xyz_2> .. <voi_xyz_M>
Where:
<voi_xyz_X> is the text file containing the subject-by-subject
coordinates of each voi, as returned by the extract-voi-data.sh
script.
The script will generate a single PNG file, named 'vois.png', with
the position of each individual VOI coordinate marked inside a glass
brain. Each VOI will be marked in a different color.
"""
if __name__ == "__main__":
if len(sys.argv[1:]) == 0:
print(HLP_MSG)
else:
vois = {}
for filename in sys.argv[1:]:
# Opens file and extract MNI coordinates
# ----------------------------------------------------------
f = open(filename, "r")
tokens = [line.split() for line in f.readlines()[1:]]
coords = [x[2:5] for x in tokens]
mni = [[float(y) for y in x] for x in coords]
name = tokens[0][1]
vois[name] = mni
#cols = cm.tab10(linspace(0,1,len(vois.keys())))
#cols = cm.rainbow(linspace(0,1,len(vois.keys())))
cols = cm.brg(linspace(0,1,len(vois.keys())))
# Adds transparency
# ----------------------------------------------------------
for c in cols:
c[3] = 0.7 # Sets alpha
# Plots and saves
# ----------------------------------------------------------
# Calculates the proper size of the marker
L = [len(vois[x]) for x in vois.keys()]
N = numpy.max(L)
msize = 100
if N > 20:
msize = 50
elif N > 50:
msize = 25
elif N > 100:
msize = 10
display=plotting.plot_glass_brain(None)
for i, v in enumerate(sorted(vois.keys())):
display.add_markers(vois[v], marker_color=cols[i],
marker_size=msize, marker="o")
display.savefig("vois.png", dpi=300)
display.close()
# End