Skip to content

Commit 29512c7

Browse files
committed
fix: streamlines less than 100
1 parent bb2b08a commit 29512c7

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

nipype/interfaces/mrtrix/convert.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
>>> os.chdir(datadir)
1010
"""
1111
from __future__ import print_function, division, unicode_literals, absolute_import
12-
from builtins import open
12+
from io import open
1313

1414
import os.path as op
1515
import nibabel as nb
@@ -54,10 +54,11 @@ def read_mrtrix_tracks(in_file, as_generator=True):
5454

5555

5656
def read_mrtrix_header(in_file):
57-
fileobj = open(in_file, 'r')
57+
fileobj = open(in_file, 'rb')
5858
header = {}
5959
iflogger.info('Reading header data...')
6060
for line in fileobj:
61+
line = line.decode()
6162
if line == 'END\n':
6263
iflogger.info('Reached the end of the header!')
6364
break
@@ -77,7 +78,7 @@ def read_mrtrix_header(in_file):
7778
def read_mrtrix_streamlines(in_file, header, as_generator=True):
7879
offset = header['offset']
7980
stream_count = header['count']
80-
fileobj = open(in_file, 'r')
81+
fileobj = open(in_file, 'rb')
8182
fileobj.seek(offset)
8283
endianness = native_code
8384
f4dt = np.dtype(endianness + 'f4')
@@ -137,9 +138,14 @@ def track_gen(track_points):
137138
if n_streams == stream_count:
138139
iflogger.info('100% : {n} tracks read'.format(n=n_streams))
139140
raise StopIteration
140-
if n_streams % int(stream_count / 100) == 0:
141-
percent = int(float(n_streams) / float(stream_count) * 100)
142-
iflogger.info('{p}% : {n} tracks read'.format(p=percent, n=n_streams))
141+
try:
142+
if n_streams % int(stream_count / 100) == 0:
143+
percent = int(float(n_streams) / float(stream_count) * 100)
144+
iflogger.info('{p}% : {n} tracks read'.format(p=percent,
145+
n=n_streams))
146+
except ZeroDivisionError:
147+
iflogger.info('{} stream read out of {}'.format(n_streams,
148+
stream_count))
143149
track_points, nonfinite_list = points_per_track(offset)
144150
fileobj.seek(offset)
145151
streamlines = track_gen(track_points)

0 commit comments

Comments
 (0)