13
13
14
14
from nibabel .affines import apply_affine
15
15
from nibabel .openers import Opener
16
+ from nibabel .py3k import asbytes , asstr
16
17
from nibabel .volumeutils import (native_code , swapped_code )
17
18
18
19
from .compact_list import CompactList
@@ -276,7 +277,7 @@ def write(self, tractogram):
276
277
property_name = k
277
278
if nb_values > 1 :
278
279
# Use the last to bytes of the name to store the nb of values associated to this data_for_streamline.
279
- property_name = k [:18 ].ljust (18 , '\x00 ' ) + '\x00 ' + np .array (nb_values , dtype = np .int8 ).tostring ()
280
+ property_name = asbytes ( k [:18 ].ljust (18 , '\x00 ' )) + b '\x00 ' + np .array (nb_values , dtype = np .int8 ).tostring ()
280
281
281
282
self .header ['property_name' ][i ] = property_name
282
283
@@ -298,7 +299,7 @@ def write(self, tractogram):
298
299
scalar_name = k
299
300
if nb_values > 1 :
300
301
# Use the last to bytes of the name to store the nb of values associated to this data_for_streamline.
301
- scalar_name = k [:18 ].ljust (18 , '\x00 ' ) + '\x00 ' + np .array (nb_values , dtype = np .int8 ).tostring ()
302
+ scalar_name = asbytes ( k [:18 ].ljust (18 , '\x00 ' )) + b '\x00 ' + np .array (nb_values , dtype = np .int8 ).tostring ()
302
303
303
304
self .header ['scalar_name' ][i ] = scalar_name
304
305
@@ -314,7 +315,7 @@ def write(self, tractogram):
314
315
# If the voxel order implied by the affine does not match the voxel
315
316
# order in the TRK header, change the orientation.
316
317
# voxel (affine) -> voxel (header)
317
- header_ornt = self .header [Field .VOXEL_ORDER ]
318
+ header_ornt = asstr ( self .header [Field .VOXEL_ORDER ])
318
319
affine_ornt = "" .join (nib .orientations .aff2axcodes (self .header [Field .VOXEL_TO_RASMM ]))
319
320
header_ornt = nib .orientations .axcodes2ornt (header_ornt )
320
321
affine_ornt = nib .orientations .axcodes2ornt (affine_ornt )
@@ -589,7 +590,7 @@ def load(cls, fileobj, lazy_load=False):
589
590
# If the voxel order implied by the affine does not match the voxel
590
591
# order in the TRK header, change the orientation.
591
592
# voxel (header) -> voxel (affine)
592
- header_ornt = trk_reader .header [Field .VOXEL_ORDER ]
593
+ header_ornt = asstr ( trk_reader .header [Field .VOXEL_ORDER ])
593
594
affine_ornt = "" .join (nib .orientations .aff2axcodes (trk_reader .header [Field .VOXEL_TO_RASMM ]))
594
595
header_ornt = nib .orientations .axcodes2ornt (header_ornt )
595
596
affine_ornt = nib .orientations .axcodes2ornt (affine_ornt )
@@ -601,12 +602,12 @@ def load(cls, fileobj, lazy_load=False):
601
602
# voxel -> rasmm
602
603
affine = np .dot (trk_reader .header [Field .VOXEL_TO_RASMM ], affine )
603
604
604
-
605
605
# Find scalars and properties name
606
606
data_per_point_slice = {}
607
607
if trk_reader .header [Field .NB_SCALARS_PER_POINT ] > 0 :
608
608
cpt = 0
609
609
for scalar_name in trk_reader .header ['scalar_name' ]:
610
+ scalar_name = asstr (scalar_name )
610
611
if len (scalar_name ) == 0 :
611
612
continue
612
613
@@ -626,6 +627,7 @@ def load(cls, fileobj, lazy_load=False):
626
627
if trk_reader .header [Field .NB_PROPERTIES_PER_STREAMLINE ] > 0 :
627
628
cpt = 0
628
629
for property_name in trk_reader .header ['property_name' ]:
630
+ property_name = asstr (property_name )
629
631
if len (property_name ) == 0 :
630
632
continue
631
633
0 commit comments