181
181
(13 , 'ECAT7_3DNORM' ),
182
182
(14 , 'ECAT7_3DSCANFIT' ))
183
183
184
+ patient_orient_defs = ( #code, description
185
+ (0 , 'ECAT7_Feet_First_Prone' ),
186
+ (1 , 'ECAT7_Head_First_Prone' ),
187
+ (2 , 'ECAT7_Feet_First_Supine' ),
188
+ (3 , 'ECAT7_Head_First_Supine' ),
189
+ (4 , 'ECAT7_Feet_First_Decubitus_Right' ),
190
+ (5 , 'ECAT7_Head_First_Decubitus_Right' ),
191
+ (6 , 'ECAT7_Feet_First_Decubitus_Left' ),
192
+ (7 , 'ECAT7_Head_First_Decubitus_Left' ),
193
+ (8 , 'ECAT7_Unknown_Orientation' ))
194
+
195
+
196
+
184
197
class EcatHeader (object ):
185
198
"""Class for basic Ecat PET header
186
199
Sub-parts of standard Ecat File
@@ -199,6 +212,7 @@ class EcatHeader(object):
199
212
200
213
_dtype = hdr_dtype
201
214
_ft_defs = ft_defs
215
+ _patient_orient_defs = patient_orient_defs
202
216
203
217
def __init__ (self ,
204
218
fileobj = None ,
@@ -345,6 +359,15 @@ def __setitem__(self, item, value):
345
359
'''
346
360
self ._header_data [item ] = value
347
361
362
+ def get_patient_orient (self ):
363
+ """ gets orientation of patient based on code stored
364
+ in header, not always reliable"""
365
+ orient_code = dict (self ._patient_orient_defs )
366
+ code = self ._header_data ['patient_orientation' ].item ()
367
+ if not orient_code .has_key (code ):
368
+ raise KeyError ('Ecat Orientation CODE %d not recognized' % code )
369
+ return orient_code [code ]
370
+
348
371
def get_filetype (self ):
349
372
""" gets type of ECAT Matrix File from
350
373
code stored in header"""
@@ -592,7 +615,8 @@ def raw_data_from_fileobj(self, frame=0):
592
615
fid_obj = self .fileobj
593
616
raw_data = array_from_file (shape , dtype , fid_obj , offset = offset )
594
617
## put data into neurologic orientation
595
- #fid_obj.close()
618
+ ### ASSUME Patient orientation is HFS as patient orientation
619
+ ### is not always set in header
596
620
raw_data = raw_data [::- 1 ,::- 1 ,::- 1 ]
597
621
return raw_data
598
622
@@ -730,10 +754,16 @@ def get_shape(self):
730
754
nframes = self ._subheader .get_nframes ()
731
755
return (x , y , z , nframes )
732
756
757
+ def get_mlist (self ):
758
+ """ get access to the mlist """
759
+ return self ._mlist
760
+
761
+ def get_subheaders (self ):
762
+ """get access to subheaders"""
763
+ return self ._subheader
733
764
734
765
@classmethod
735
766
def from_filespec (klass , filespec ):
736
-
737
767
return klass .from_filename (filespec )
738
768
739
769
@@ -777,18 +807,18 @@ def from_file_map(klass, file_map):
777
807
aff = subheaders .get_frame_affine ()
778
808
img = klass (data , aff , header , subheaders , mlist , extra = None , file_map = file_map )
779
809
return img
780
-
810
+
811
+
812
+ def to_filename (self , filename ):
813
+ """nibabel does not support writing to Ecat filetypes at this time"""
814
+ raise NotImplementedError ('nibabel does not allow saving to Ecat' \
815
+ ' at this time ' )
781
816
782
817
@classmethod
783
818
def from_image (klass , img ):
784
- raise NotImplementedError ("Ecat images must be generated from files" )
785
- orig_hdr = img .get_header ()
786
- return klass (img .get_data (),
787
- img .get_affine (),
788
- img .get_header (),
789
- img .extra )
790
-
791
-
819
+ raise NotImplementedError ("Ecat images can only be generated " \
820
+ "from file objects" )
821
+
792
822
@classmethod
793
823
def load (klass , filespec ):
794
824
return klass .from_filename (filespec )
0 commit comments