-
Notifications
You must be signed in to change notification settings - Fork 4
/
mrtrix_grad.py
executable file
·45 lines (33 loc) · 1.03 KB
/
mrtrix_grad.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
#!/usr/bin/python
import sys
import numpy as np
from optparse import OptionParser
def run(options, args):
bvec = np.loadtxt(options.bvec)
bval = np.loadtxt(options.bval)
if bvec.shape[0] < bvec.shape[1]:
bvec = bvec.transpose()
grad = np.column_stack((bvec, bval))
print "original"
print grad
# invert GE grad axis for mrtrix
if options.invert:
grad[:,0] *= -1
# print grad[:,1]
grad[:,1] *= -1
print "corrected"
print "------------------------------"
print grad
np.savetxt(options.out, grad, fmt="%10.6f")
if __name__ == '__main__':
parser = OptionParser(usage="Usage: %prog [options] <subject_dir>")
parser.add_option("-v", "--bvec", dest="bvec")
parser.add_option("-a", "--bval", dest="bval")
parser.add_option("-f", "--invert_off", action="store_false", dest="invert", default=True)
parser.add_option("-o", "--out", dest="out", default="grad.txt")
(options, args) = parser.parse_args()
if not options.bvec or not options.bval :
parser.print_help()
sys.exit(2)
else:
run(options, args)