-
Notifications
You must be signed in to change notification settings - Fork 6
/
x_pysurfer.py
64 lines (50 loc) · 1.62 KB
/
x_pysurfer.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
#!/usr/bin/env python
import sys
sys.path.append("/home2/data/Projects/CWAS/share/lib/surfwrap")
import os
from os import path as op
path = op
import numpy as np
import nibabel as nib
from pandas import *
from newsurf import *
# Input Paths (SET THESE)
odir = "XXX"
names = ["name"]
infiles = ["XXX"]
# Color bar
cbarfile = "/home2/data/Projects/CWAS/share/lib/surfwrap/colorbars/spectral-reduced-cb.txt"
cbar = load_colorbar(cbarfile)
# Threshold...combine min and max
tmin = []; tmax = []
for infile in infiles:
lmin, lmax, _ = auto_minmax(infile)
tmin.append(lmin); tmax.append(lmax)
min_use = np.min(tmin)
max_use = np.max(tmax)
sign_use = "pos"
print "min: %.5f" % min_use
print "max: %.5f" % max_use
# Plot
for i,infile in enumerate(infiles):
print "%i: %s" % (i,infile)
name = names[i]
# Vol => Surf
surf_files, surf_data = vol_to_surf(infile)
remove_surfs(surf_files)
for hemi in ["lh","rh"]:
brain = fsaverage(hemi)
## make data be only positive (ignore vertices without data)
#nz_inds = surf_data[hemi].nonzero()
#dat = surf_data[hemi][nz_inds]
#surf_data[hemi][nz_inds] = dat - manual_min
# Viz
# adjust min a bit to ignore vertices without data (=0)
brain = add_overlay(name, brain, surf_data[hemi], cbar,
min_use, max_use, sign_use)
# Save
outprefix = op.join(odir, "%s_surf" % name)
save_imageset(brain, outprefix, hemi)
# Montage
montage(outprefix, compilation='box')
montage(outprefix, compilation='horiz')