7
7
>>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
8
8
>>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data'))
9
9
>>> os.chdir(datadir)
10
-
11
10
"""
12
11
from __future__ import print_function , division , unicode_literals , absolute_import
13
- from builtins import open
12
+ from io import open
14
13
15
14
import os .path as op
16
15
import nibabel as nb
@@ -55,10 +54,11 @@ def read_mrtrix_tracks(in_file, as_generator=True):
55
54
56
55
57
56
def read_mrtrix_header (in_file ):
58
- fileobj = open (in_file , 'r ' )
57
+ fileobj = open (in_file , 'rb ' )
59
58
header = {}
60
59
iflogger .info ('Reading header data...' )
61
60
for line in fileobj :
61
+ line = line .decode ()
62
62
if line == 'END\n ' :
63
63
iflogger .info ('Reached the end of the header!' )
64
64
break
@@ -78,7 +78,7 @@ def read_mrtrix_header(in_file):
78
78
def read_mrtrix_streamlines (in_file , header , as_generator = True ):
79
79
offset = header ['offset' ]
80
80
stream_count = header ['count' ]
81
- fileobj = open (in_file , 'r ' )
81
+ fileobj = open (in_file , 'rb ' )
82
82
fileobj .seek (offset )
83
83
endianness = native_code
84
84
f4dt = np .dtype (endianness + 'f4' )
@@ -138,9 +138,14 @@ def track_gen(track_points):
138
138
if n_streams == stream_count :
139
139
iflogger .info ('100% : {n} tracks read' .format (n = n_streams ))
140
140
raise StopIteration
141
- if n_streams % int (stream_count / 100 ) == 0 :
142
- percent = int (float (n_streams ) / float (stream_count ) * 100 )
143
- 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 ))
144
149
track_points , nonfinite_list = points_per_track (offset )
145
150
fileobj .seek (offset )
146
151
streamlines = track_gen (track_points )
@@ -166,10 +171,8 @@ class MRTrix2TrackVis(BaseInterface):
166
171
"""
167
172
Converts MRtrix (.tck) tract files into TrackVis (.trk) format
168
173
using functions from dipy
169
-
170
174
Example
171
175
-------
172
-
173
176
>>> import nipype.interfaces.mrtrix as mrt
174
177
>>> tck2trk = mrt.MRTrix2TrackVis()
175
178
>>> tck2trk.inputs.in_file = 'dwi_CSD_tracked.tck'
0 commit comments