Skip to content

Commit

Permalink
Merge branch 'master' into GDC
Browse files Browse the repository at this point in the history
  • Loading branch information
mcraig-ibme committed Jul 9, 2018
2 parents d203e5f + 4313f0b commit a6d3772
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions python/asl/fslhelpers.py
Expand Up @@ -67,7 +67,7 @@ def __call__(self, args):
p = subprocess.Popen(cmd_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while 1:
retcode = p.poll() #returns None while subprocess is running
line = p.stdout.readline()
line = p.stdout.readline().decode('utf-8')
out += line
if retcode is not None: break
if retcode != 0:
Expand Down Expand Up @@ -144,4 +144,4 @@ def tmpdir(suffix, debug=False):
else:
tmpdir = tempfile.mkdtemp("_%s" % suffix)
print("Using temporary dir: %s" % tmpdir)
return tmpdir
return tmpdir
9 changes: 5 additions & 4 deletions python/asl/fslwrap.py
Expand Up @@ -11,6 +11,7 @@
import errno
import tempfile
import collections
from six import string_types

import nibabel as nib
import numpy as np
Expand Down Expand Up @@ -352,7 +353,7 @@ def run(self, prog, args="", expected=[]):
p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while 1:
retcode = p.poll() # returns None while subprocess is running
stdout_line = p.stdout.readline()
stdout_line = p.stdout.readline().decode('utf-8')
cmd_stdout += stdout_line
self.echo(stdout_line)
if retcode is not None: break
Expand Down Expand Up @@ -507,7 +508,7 @@ def _input_img(self, img):
"""
if isinstance(img, Image):
return img, self.IMAGE
elif isinstance(img, basestring):
elif isinstance(img, string_types):
return Image(img), self.FILENAME
elif isinstance(img, np.ndarray):
tempf = tempfile.NamedTemporaryFile(dir=self.workdir, prefix="fsl", delete=False)
Expand All @@ -526,7 +527,7 @@ def _input_matrix(self, mat):
Note that care is required with Numpy arrays because they have no
orientation or grid information which some FSL programs may require.
"""
if isinstance(mat, basestring):
if isinstance(mat, string_types):
return mat, self.FILENAME
elif isinstance(mat, np.ndarray):
tempf = tempfile.NamedTemporaryFile(dir=self.workdir, prefix="fsl", suffix=".mat", delete=False)
Expand Down Expand Up @@ -703,7 +704,7 @@ def _grab_temp_data(data):
We also remove the temporary path from the image file name
"""
if isinstance(data, collections.Sequence) and not isinstance(data, basestring):
if isinstance(data, collections.Sequence) and not isinstance(data, string_types):
for d in data:
_grab_temp_data(d)
else:
Expand Down
22 changes: 11 additions & 11 deletions python/asl/gui/run_box.py
Expand Up @@ -51,7 +51,7 @@ def run(self):
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while 1:
retcode = p.poll() #returns None while subprocess is running
line = p.stdout.readline()
line = p.stdout.readline().decode('utf-8')
self.write_output(line)
if retcode is not None: break
self.write_output("\nReturn code: %i\n\n" % retcode)
Expand Down Expand Up @@ -82,16 +82,16 @@ class AslRun(wx.Frame):
"""

# The options we need to pass to oxford_asl for various data orderings
order_opts = {"trp" : "--ibf=tis --iaf=diff",
"trp,tc" : "--ibf=tis --iaf=tcb",
"trp,ct" : "--ibf=tis --iaf=ctb",
"rtp" : "--ibf=rpt --iaf=diff",
"rtp,tc" : "--rpt --iaf=tcb",
"rtp,ct" : "--ibf=rpt --iaf=ctb",
"ptr,tc" : "--ibf=tis --iaf=tc",
"ptr,ct" : "--ibf=tis --iaf=ct",
"prt,tc" : "--ibf=rpt --iaf=tc",
"prt,ct" : "--ibf=rpt --iaf=ct"}
order_opts = {"trp" : "--ibf=rpt --iaf=diff",
"trp,tc" : "--ibf=rpt --iaf=tcb",
"trp,ct" : "--ibf=rpt --iaf=ctb",
"rtp" : "--ibf=tis --iaf=diff",
"rtp,tc" : "--ibf=tis --iaf=tcb",
"rtp,ct" : "--ibf=tis --iaf=ctb",
"ptr,tc" : "--ibf=rpt --iaf=tc",
"ptr,ct" : "--ibf=rpt --iaf=ct",
"prt,tc" : "--ibf=tis --iaf=tc",
"prt,ct" : "--ibf=tis --iaf=ct"}

def __init__(self, parent, run_btn, run_label):
wx.Frame.__init__(self, parent, title="Run", size=(600, 400), style=wx.DEFAULT_FRAME_STYLE)
Expand Down
11 changes: 6 additions & 5 deletions python/asl/image.py
Expand Up @@ -7,6 +7,7 @@
import sys
import shutil
from optparse import OptionParser, OptionGroup
from six import string_types

import numpy as np
import nibabel as nib
Expand Down Expand Up @@ -82,7 +83,7 @@ def __init__(self, name, order="prt", ntis=None, tis=None, plds=None, nrpts=None
if ntis is None and tis is None:
raise RuntimeError("Number of TIs not specified")
elif tis is not None:
if isinstance(tis, basestring): tis = [float(ti) for ti in tis.split(",")]
if isinstance(tis, string_types): tis = [float(ti) for ti in tis.split(",")]
ntis = len(tis)
if ntis is not None and len(tis) != ntis:
raise RuntimeError("Number of TIs: %i, but list of %i TIs given" % (ntis, len(tis)))
Expand All @@ -95,14 +96,14 @@ def __init__(self, name, order="prt", ntis=None, tis=None, plds=None, nrpts=None
# Calculate fixed number of repeats
if self.nv % (self.ntc * self.ntis) != 0:
raise RuntimeError("Data contains %i volumes, inconsistent with %i TIs and TC pairs" % (self.nv, self.ntis))
rpts = [self.nv / (self.ntc * self.ntis)] * self.ntis
rpts = [int(self.nv / (self.ntc * self.ntis))] * self.ntis
elif nrpts is not None:
nrpts = int(nrpts)
if nrpts * self.ntis * self.ntc != self.nv:
raise RuntimeError("Data contains %i volumes, inconsistent with %i TIs and %i repeats" % (self.nv, self.ntis, nrpts))
rpts = [nrpts] * self.ntis
else:
if isinstance(rpts, basestring): rpts = [int(rpt) for rpt in rpts.split(",")]
if isinstance(rpts, string_types): rpts = [int(rpt) for rpt in rpts.split(",")]
if len(rpts) != self.ntis:
raise RuntimeError("%i TIs, but only %i variable repeats" % (self.ntis, len(rpts)))
elif sum(rpts) * self.ntc != self.nv:
Expand Down Expand Up @@ -206,13 +207,13 @@ def diff(self):
# Already differenced
output_data = self.data()
else:
output_data = np.zeros(list(self.shape[:3]) + [self.nv/2])
output_data = np.zeros(list(self.shape[:3]) + [int(self.nv/2)])

# Re-order so that TC pairs are together with the tag first
out_order = self.order.replace("p", "").replace("P", "")
reordered = self.reorder("p" + out_order).data()

for t in range(self.nv / 2):
for t in range(int(self.nv / 2)):
tag = 2*t
ctrl = tag+1
output_data[:,:,:,t] = reordered[:,:,:,ctrl] - reordered[:,:,:,tag]
Expand Down

0 comments on commit a6d3772

Please sign in to comment.