Skip to content

Commit

Permalink
rotate nifti files
Browse files Browse the repository at this point in the history
  • Loading branch information
andnp committed Jan 13, 2017
1 parent 07d480d commit 7185db6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
22 changes: 17 additions & 5 deletions init_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
algs = [("tens", "dtidet", "lmax2"), ("detr", "csddet", "lmax8"), ("prob", "csdprob", "lmax8")]

def getSublong(num_str):
sublong = {"001": "pestilli_test", "002": "takemura", "003": "knk", "004": "lmperry"}
sublong = {"0001": "pestilli_test", "0002": "takemura", "0003": "knk", "0004": "lmperry"}
if num_str in sublong:
return sublong[num_str]
else:
Expand Down Expand Up @@ -85,11 +85,23 @@ def getSublong(num_str):
outputs = mapping[dataset]["output"]
copier.copy(inputs[0].format(params[0]), outputs[0].format(subject, subject), dummy = False)
action = "copy"
if inputs[1][:-3] == "mgz":
if inputs[1][-3:] == "mgz":
action = "mri_convert"
copier.copy(inputs[1].format(params[1]), outputs[1].format(subject, subject), action = action, dummy = False)
copier.copy(inputs[2].format(params[2]), outputs[2].format(subject, subject), dummy = False)
copier.copy(inputs[3].format(params[3]), outputs[3].format(subject, subject), dummy = False)

out_str = outputs[1].format(subject, subject)
copier.copy(inputs[1].format(params[1]), out_str, action = action, dummy = False)
if dataset != "hcp7t":
copier.copy(out_str, out_str, action = "rotate", dummy = False)

out_str = outputs[2].format(subject, subject)
copier.copy(inputs[2].format(params[2]), out_str, dummy = False)
if dataset != "hcp7t":
copier.copy(out_str, out_str, action = "rotate", dummy = False)

out_str = outputs[3].format(subject, subject)
copier.copy(inputs[3].format(params[3]), out_str, dummy = False)
if dataset != "hcp7t":
copier.copy(out_str, out_str, action = "rotate", dummy = False)

bvec_in = mapping[dataset]["bval_in"].format(name) + ".bvecs"
bval_in = mapping[dataset]["bval_in"].format(name) + ".bvals"
Expand Down
5 changes: 4 additions & 1 deletion init_recon_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@

copier.copy(in_str, out_str, action = action, dummy = False)

if (dataset == "hcp7t" and files[i][:-10] in masks):
if (dataset != "hcp7t" and files[i][-7:] == ".nii.gz"):
copier.rotate(out_str, out_str, dummy = False)

if (dataset == "hcp7t" and files[i][-10:] in masks):
mask = mapping[dataset]["mask"].format(name)
# for ease, I am overloading the meaning of "anatomy" in the copy function
copier.copy(out_str, out_str, anatomy = mask, action = "mask", dummy = False)
8 changes: 8 additions & 0 deletions utils/copy_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ def mrconvert(infile, outfile, dummy = True):
# call(['module', 'load', 'mrtrix'])
call(['mrconvert', '-force', infile, outfile])

def rotate(infile, outfile, dummy = True):
if dummy:
print 'rotate command print not implemented'
else:
call(['mri_convert', '-iid', '1', '0', '0', infile, outfile])

def mask(infile, outfile, mask, dummy = True):
if dummy:
print ""
Expand Down Expand Up @@ -169,6 +175,8 @@ def copy(in_inter, out_inter, action = "copy", dummy = True, anatomy = ""):
tck2trk(all_in[i], all_out[i], dummy = dummy, anatomy = anatomy)
elif (action == "mask"):
mask(all_in[i], all_out[i], dummy = dummy, mask = anatomy)
elif (action == "rotate"):
rotate(all_in[i], all_out[i], dummy = dummy)
elif (action == "copy"):
if dummy:
print "cp " + all_in[i] + " >> " + all_out[i]
Expand Down

0 comments on commit 7185db6

Please sign in to comment.