151
151
('fill' , np .uint16 )]
152
152
subhdr_dtype = np .dtype (subheader_dtd )
153
153
154
-
155
-
154
+ # Ecat Data Types
155
+ _dtdefs = ( # code, name, equivalent dtype
156
+ (1 , 'ECAT7_BYTE' , np .uint8 ),
157
+ (2 , 'ECAT7_VAXI2' , np .int16 ),
158
+ (3 , 'ECAT7_VAXI4' , np .float32 ),
159
+ (4 , 'ECAT7_VAXR4' , np .float32 ),
160
+ (5 , 'ECAT7_IEEER4' , np .float32 ),
161
+ (6 , 'ECAT7_SUNI2' , np .uint16 ),
162
+ (7 , 'ECAT7_SUNI4' , np .int32 ))
163
+ data_type_codes = make_dt_codes (_dtdefs )
164
+
165
+
166
+ # Matrix File Types
167
+ ft_defs = ( # code, name
168
+ (0 , 'ECAT7_UNKNOWN' ),
169
+ (1 , 'ECAT7_2DSCAN' ),
170
+ (2 , 'ECAT7_IMAGE16' ),
171
+ (3 , 'ECAT7_ATTEN' ),
172
+ (4 , 'ECAT7_2DNORM' ),
173
+ (5 , 'ECAT7_POLARMAP' ),
174
+ (6 , 'ECAT7_VOLUME8' ),
175
+ (7 , 'ECAT7_VOLUME16' ),
176
+ (8 , 'ECAT7_PROJ' ),
177
+ (9 , 'ECAT7_PROJ16' ),
178
+ (10 , 'ECAT7_IMAGE8' ),
179
+ (11 , 'ECAT7_3DSCAN' ),
180
+ (12 , 'ECAT7_3DSCAN8' ),
181
+ (13 , 'ECAT7_3DNORM' ),
182
+ (14 , 'ECAT7_3DSCANFIT' ))
156
183
157
184
class EcatHeader (object ):
158
185
"""Class for basic Ecat PET header
@@ -171,6 +198,7 @@ class EcatHeader(object):
171
198
"""
172
199
173
200
_dtype = hdr_dtype
201
+ _ft_defs = ft_defs
174
202
175
203
def __init__ (self ,
176
204
fileobj = None ,
@@ -317,6 +345,15 @@ def __setitem__(self, item, value):
317
345
'''
318
346
self ._header_data [item ] = value
319
347
348
+ def get_filetype (self ):
349
+ """ gets type of ECAT Matrix File from
350
+ code stored in header"""
351
+ ft_codes = dict (self ._ft_defs )
352
+ code = self ._header_data ['file_type' ].item ()
353
+ if not ft_codes .has_key (code ):
354
+ raise KeyError ('Ecat Filetype CODE %d not recognized' % code )
355
+ return ft_codes [code ]
356
+
320
357
def __iter__ (self ):
321
358
return iter (self .keys ())
322
359
@@ -338,9 +375,10 @@ class EcatMlist(object):
338
375
def __init__ (self ,fileobj , hdr ):
339
376
""" gets list of frames and subheaders in pet file
340
377
341
- Parameteres
378
+ Parameters
342
379
-----------
343
- fileobj : ECAT file <filename>.v
380
+ fileobj : ECAT file <filename>.v fileholder or file object
381
+ with read, seek methods
344
382
345
383
Returns
346
384
-------
@@ -389,15 +427,29 @@ def get_mlist(self, fileobj):
389
427
390
428
def get_frame_order (self ):
391
429
"""Returns the order of the frames in the file
430
+ Useful as sometimes Frames are not stored in the file in
431
+ chronological order, and can be used to extract frames
432
+ in correct order
392
433
393
434
Returns
394
435
-------
436
+ id_dict: dict mapping frame number -> [mlist_row, mlist_id]
395
437
396
- frame_dict: dict mapping mlist id -> frame number
397
-
398
- id_dict: dict mapping frame number -> mlist id
438
+ (where mlist id is value in the first column of the mlist matrix )
399
439
400
- (where mlist id is in the first column of the mlist matrix )
440
+ Examples
441
+ --------
442
+ >>> img = ecat.load('singleframe.v')
443
+ >>> mlist = img._mlist
444
+ >>> mlist.get_frame_order()
445
+ {0: [0, 16842758.0]}
446
+ >>> img2 = ecat.load('multiframe.v')
447
+ >>> mlist2 = img2._mlist
448
+ >>> mlist2.get_frame_order()
449
+ {0: [0, 16842754.0],
450
+ 1: [1, 16842755.0],
451
+ 2: [2, 16842756.0],
452
+ 3: [3, 16842757.0]}
401
453
"""
402
454
mlist = self ._mlist
403
455
ind = mlist [:,0 ] > 0
@@ -412,14 +464,26 @@ def get_frame_order(self):
412
464
413
465
return id_dict
414
466
415
-
416
-
417
-
418
467
class EcatSubHeader (object ):
419
- """parses the subheaders in the ecat (.v) file """
468
+
420
469
_subhdrdtype = subhdr_dtype
470
+ _data_type_codes = data_type_codes
421
471
422
472
def __init__ (self , hdr , mlist , fileobj ):
473
+ """parses the subheaders in the ecat (.v) file
474
+ there is one subheader for each frame in the ecat file
475
+
476
+ Parameters
477
+ -----------
478
+ hdr : EcatHeader
479
+
480
+ mlist : EcatMlist
481
+
482
+ fileobj : ECAT file <filename>.v fileholder or file object
483
+ with read, seek methods
484
+
485
+
486
+ """
423
487
self ._header = hdr
424
488
self .endianness = hdr .endianness
425
489
self ._mlist = mlist
@@ -511,13 +575,8 @@ def get_zooms(self,frame=0):
511
575
512
576
513
577
def _get_data_dtype (self , frame ):
514
- dt = self .subheaders [frame ]['data_type' ]
515
- if dt == 5 :
516
- return np .dtype ('float' )
517
- elif dt == 6 :
518
- return np .dtype ('ushort' )
519
- else :
520
- return None
578
+ dtcode = self .subheaders [frame ]['data_type' ].item ()
579
+ return self ._data_type_codes .dtype [dtcode ]
521
580
522
581
def _get_frame_offset (self , frame = 0 ):
523
582
mlist = self ._mlist ._mlist
0 commit comments