26
26
MAX_NB_NAMED_SCALARS_PER_POINT = 10
27
27
MAX_NB_NAMED_PROPERTIES_PER_STREAMLINE = 10
28
28
29
- # See http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html
30
- header_1_dtd = [(Field .MAGIC_NUMBER , 'S6' ),
31
- (Field .DIMENSIONS , 'h' , 3 ),
32
- (Field .VOXEL_SIZES , 'f4' , 3 ),
33
- (Field .ORIGIN , 'f4' , 3 ),
34
- (Field .NB_SCALARS_PER_POINT , 'h' ),
35
- ('scalar_name' , 'S20' , MAX_NB_NAMED_SCALARS_PER_POINT ),
36
- (Field .NB_PROPERTIES_PER_STREAMLINE , 'h' ),
37
- ('property_name' , 'S20' ,
38
- MAX_NB_NAMED_PROPERTIES_PER_STREAMLINE ),
39
- ('reserved' , 'S508' ),
40
- (Field .VOXEL_ORDER , 'S4' ),
41
- ('pad2' , 'S4' ),
42
- ('image_orientation_patient' , 'f4' , 6 ),
43
- ('pad1' , 'S2' ),
44
- ('invert_x' , 'S1' ),
45
- ('invert_y' , 'S1' ),
46
- ('invert_z' , 'S1' ),
47
- ('swap_xy' , 'S1' ),
48
- ('swap_yz' , 'S1' ),
49
- ('swap_zx' , 'S1' ),
50
- (Field .NB_STREAMLINES , 'i4' ),
51
- ('version' , 'i4' ),
52
- ('hdr_size' , 'i4' ),
53
- ]
54
-
55
- # Version 2 adds a 4x4 matrix giving the affine transformtation going
29
+ # Version 2 adds a 4x4 matrix giving the affine transformation going
56
30
# from voxel coordinates in the referenced 3D voxel matrix, to xyz
57
31
# coordinates (axes L->R, P->A, I->S). If (0 based) value [3, 3] from
58
32
# this matrix is 0, this means the matrix is not recorded.
33
+ # See http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html
59
34
header_2_dtd = [(Field .MAGIC_NUMBER , 'S6' ),
60
35
(Field .DIMENSIONS , 'h' , 3 ),
61
36
(Field .VOXEL_SIZES , 'f4' , 3 ),
83
58
]
84
59
85
60
# Full header numpy dtypes
86
- header_1_dtype = np .dtype (header_1_dtd )
87
61
header_2_dtype = np .dtype (header_2_dtd )
88
62
89
63
@@ -584,8 +558,8 @@ def _read_header(fileobj):
584
558
TrkFile .HEADER_SIZE ))
585
559
586
560
if header_rec ['version' ] == 1 :
587
- header_rec = np . fromstring ( string = header_str ,
588
- dtype = header_1_dtype )
561
+ # There is no 4x4 matrix for voxel to RAS transformation.
562
+ header_rec [ Field . VOXEL_TO_RASMM ] = np . zeros (( 4 , 4 ) )
589
563
elif header_rec ['version' ] == 2 :
590
564
pass # Nothing more to do.
591
565
else :
@@ -724,12 +698,17 @@ def __str__(self):
724
698
hdr_field = getattr (Field , attr )
725
699
if hdr_field in vars :
726
700
vars [attr ] = vars [hdr_field ]
727
- vars ['scalar_names' ] = '\n ' .join ([asstr (s )
728
- for s in vars ['scalar_name' ]
729
- if len (s ) > 0 ])
730
- vars ['property_names' ] = "\n " .join ([asstr (s )
731
- for s in vars ['property_name' ]
732
- if len (s ) > 0 ])
701
+
702
+ nb_scalars = self .header [Field .NB_SCALARS_PER_POINT ]
703
+ scalar_names = [asstr (s )
704
+ for s in vars ['scalar_name' ][:nb_scalars ]
705
+ if len (s ) > 0 ]
706
+ vars ['scalar_names' ] = '\n ' .join (scalar_names )
707
+ nb_properties = self .header [Field .NB_PROPERTIES_PER_STREAMLINE ]
708
+ property_names = [asstr (s )
709
+ for s in vars ['property_name' ][:nb_properties ]
710
+ if len (s ) > 0 ]
711
+ vars ['property_names' ] = "\n " .join (property_names )
733
712
# Make all byte strings into strings
734
713
# Fixes recursion error on Python 3.3
735
714
vars = dict ((k , asstr (v ) if hasattr (v , 'decode' ) else v )
@@ -739,11 +718,11 @@ def __str__(self):
739
718
v.{version}
740
719
dim: {DIMENSIONS}
741
720
voxel_sizes: {VOXEL_SIZES}
742
- orgin : {ORIGIN}
721
+ origin : {ORIGIN}
743
722
nb_scalars: {NB_SCALARS_PER_POINT}
744
- scalar_name :\n {scalar_names}
723
+ scalar_names :\n {scalar_names}
745
724
nb_properties: {NB_PROPERTIES_PER_STREAMLINE}
746
- property_name :\n {property_names}
725
+ property_names :\n {property_names}
747
726
vox_to_world:\n {VOXEL_TO_RASMM}
748
727
voxel_order: {VOXEL_ORDER}
749
728
image_orientation_patient: {image_orientation_patient}
0 commit comments