Skip to content

Commit 719aee7

Browse files
author
Félix C. Morency
committed
RF: Fixed EOL and newline to remove useless spaces
1 parent 0e77ba8 commit 719aee7

File tree

1 file changed

+46
-44
lines changed

1 file changed

+46
-44
lines changed

nibabel/ecat.py

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@
2727
('isotope_name', '8S'),
2828
('isotope_halflife', np.float32),
2929
('radiopharmaceutical','32S'),
30-
('gantry_tilt', np.float32),
30+
('gantry_tilt', np.float32),
3131
('gantry_rotation',np.float32),
3232
('bed_elevation',np.float32),
3333
('intrinsic_tilt', np.float32),
34-
('wobble_speed',np.uint16),
34+
('wobble_speed',np.uint16),
3535
('transm_source_type',np.uint16),
36-
('distance_scanned',np.float32),
36+
('distance_scanned',np.float32),
3737
('transaxial_fov',np.float32),
3838
('angular_compression', np.uint16),
3939
('coin_samp_mode',np.uint16),
4040
('axial_samp_mode',np.uint16),
41-
('ecat_calibration_factor',np.float32),
41+
('ecat_calibration_factor',np.float32),
4242
('calibration_unitS', np.uint16),
4343
('calibration_units_type',np.uint16),
4444
('compression_code',np.uint16),
@@ -76,7 +76,7 @@
7676
('well_counter_corr_factor', np.float32),
7777
('data_units', '32S'),
7878
('septa_state',np.uint16),
79-
('fill',np.uint16)
79+
('fill', np.uint16)
8080
]
8181
hdr_dtype = np.dtype(main_header_dtd)
8282

@@ -191,23 +191,23 @@ class EcatHeader(object):
191191
"""Class for basic Ecat PET header
192192
Sub-parts of standard Ecat File
193193
main header
194-
matrix list
195-
which lists the information for each
194+
matrix list
195+
which lists the information for each
196196
frame collected (can have 1 to many frames)
197-
subheaders specific to each frame
197+
subheaders specific to each frame
198198
with possibly-variable sized data blocks
199-
200-
This just reads the main Ecat Header,
201-
it does not load the data
199+
200+
This just reads the main Ecat Header,
201+
it does not load the data
202202
or read the mlist or any sub headers
203203
204204
"""
205205

206206
_dtype = hdr_dtype
207207
_ft_defs = ft_defs
208208
_patient_orient_defs = patient_orient_defs
209-
210-
def __init__(self,
209+
210+
def __init__(self,
211211
fileobj=None,
212212
endianness=None):
213213
"""Initialize Ecat header from file object
@@ -224,20 +224,20 @@ def __init__(self,
224224
if fileobj is None:
225225
self._header_data = self._empty_headerdata(endianness)
226226
return
227-
227+
228228
hdr = np.ndarray(shape=(),
229229
dtype=self._dtype,
230230
buffer=fileobj)
231231
if endianness is None:
232232
endianness = self._guess_endian(hdr)
233-
233+
234234
if endianness != native_code:
235235
dt = self._dtype.newbyteorder(endianness)
236236
hdr = np.ndarray(shape=(),
237237
dtype=dt,
238238
buffer=fileobj)
239239
self._header_data = hdr.copy()
240-
240+
241241
return
242242

243243
def get_header(self):
@@ -271,7 +271,7 @@ def from_fileobj(klass, fileobj, endianness=None):
271271
----------
272272
fileobj : file-like object
273273
Needs to implement ``read`` method
274-
endianness : None or endian code, optional
274+
endianness : None or endian code, optional
275275
Code specifying endianness of data to be read
276276
277277
Returns
@@ -281,7 +281,7 @@ def from_fileobj(klass, fileobj, endianness=None):
281281
282282
Examples
283283
--------
284-
284+
285285
286286
"""
287287
raw_str = fileobj.read(klass._dtype.itemsize)
@@ -296,7 +296,7 @@ def _empty_headerdata(self,endianness=None):
296296
hdr_data = np.zeros((), dtype=dt)
297297
hdr_data['magic_number'] = 'MATRIX72'
298298
hdr_data['sw_version'] = 74
299-
hdr_data['num_frames']= 0
299+
hdr_data['num_frames']= 0
300300
hdr_data['file_type'] = 0 # Unknown
301301
hdr_data['ecat_calibration_factor'] = 1.0 # scale factor
302302
return hdr_data
@@ -305,7 +305,7 @@ def _empty_headerdata(self,endianness=None):
305305
def get_data_dtype(self):
306306
""" Get numpy dtype for data from header"""
307307
raise NotImplementedError("dtype is only valid from subheaders")
308-
308+
309309

310310
def copy(self):
311311
return self.__class__(
@@ -321,7 +321,7 @@ def __eq__(self, other):
321321
return self_bb == other.binaryblock
322322
other_bb = other._header_data.byteswap().tostring()
323323
return self_bb == other_bb
324-
324+
325325
def __ne__(self, other):
326326
''' equality between two headers defined by ``header_data``
327327
@@ -369,14 +369,14 @@ def get_filetype(self):
369369
if not ft_codes.has_key(code):
370370
raise KeyError('Ecat Filetype CODE %d not recognized'%code)
371371
return ft_codes[code]
372-
372+
373373
def __iter__(self):
374374
return iter(self.keys())
375-
375+
376376
def keys(self):
377377
''' Return keys from header data'''
378378
return list(self._dtype.names)
379-
379+
380380
def values(self):
381381
''' Return values from header data'''
382382
data = self._header_data
@@ -385,9 +385,9 @@ def values(self):
385385
def items(self):
386386
''' Return items from header data'''
387387
return zip(self.keys(), self.values())
388-
388+
389389
class EcatMlist(object):
390-
390+
391391
def __init__(self,fileobj, hdr):
392392
""" gets list of frames and subheaders in pet file
393393
@@ -413,21 +413,22 @@ def __init__(self,fileobj, hdr):
413413
def get_mlist(self, fileobj):
414414
fileobj.seek(512)
415415
dat=fileobj.read(128*32)
416-
416+
417417
dt = np.dtype([('matlist',np.int32)])
418418
if not self.hdr.endianness is native_code:
419419
dt = dt.newbyteorder(self.hdr.endianness)
420420
nframes = self.hdr['num_frames']
421421
mlist = np.zeros((nframes,4))
422422
record_count = 0
423423
done = False
424+
424425
while not done: #mats['matlist'][0,1] == 2:
425-
426+
426427
mats = np.recarray(shape=(32,4), dtype=dt, buf=dat)
427428
if not (mats['matlist'][0,0] + mats['matlist'][0,3]) == 31:
428429
mlist = []
429430
return mlist
430-
431+
431432
nrecords = mats['matlist'][0,3]
432433
mlist[record_count:nrecords+record_count,:] = mats['matlist'][1:nrecords+1,:]
433434
record_count+= nrecords
@@ -439,6 +440,7 @@ def get_mlist(self, fileobj):
439440
fileobj.seek(0)
440441
fileobj.seek(tmp*512)
441442
dat = fileobj.read(128*32)
443+
442444
return mlist
443445

444446
def get_frame_order(self):
@@ -465,7 +467,7 @@ def get_frame_order(self):
465467
>>> mlist.get_frame_order()
466468
{0: [0, 16842758.0]}
467469
468-
470+
469471
"""
470472
mlist = self._mlist
471473
ids = mlist[:, 0].copy()
@@ -482,7 +484,7 @@ def get_frame_order(self):
482484
id_dict = {}
483485
for i in range(n_valid):
484486
id_dict[i] = [valid_order[i], ids[valid_order[i]]]
485-
487+
486488
return id_dict
487489

488490
def get_series_framenumbers(self):
@@ -512,8 +514,8 @@ def get_series_framenumbers(self):
512514
>>> mlist.get_series_framenumbers()
513515
{0: 1}
514516
515-
516-
517+
518+
517519
"""
518520
frames_order = self.get_frame_order()
519521
nframes = self.hdr['num_frames']
@@ -527,12 +529,12 @@ def get_series_framenumbers(self):
527529
return frame_dict
528530
except:
529531
raise IOError('Error in header or mlist order unknown')
530-
532+
531533
class EcatSubHeader(object):
532534

533535
_subhdrdtype = subhdr_dtype
534536
_data_type_codes = data_type_codes
535-
537+
536538
def __init__(self, hdr, mlist, fileobj):
537539
"""parses the subheaders in the ecat (.v) file
538540
there is one subheader for each frame in the ecat file
@@ -542,7 +544,7 @@ def __init__(self, hdr, mlist, fileobj):
542544
hdr : EcatHeader
543545
544546
mlist : EcatMlist
545-
547+
546548
fileobj : ECAT file <filename>.v fileholder or file object
547549
with read, seek methods
548550
@@ -583,7 +585,7 @@ def _get_subheaders(self):
583585
buf=tmpdat))
584586
subheaders.append(sh)
585587
return subheaders
586-
588+
587589
def get_shape(self, frame=0):
588590
""" returns shape of given frame"""
589591
subhdr = self.subheaders[frame]
@@ -611,24 +613,24 @@ def _check_affines(self):
611613
for item in i:
612614
if not np.all(first == item):
613615
return False
614-
return True
615-
616+
return True
617+
616618
def get_frame_affine(self,frame=0):
617619
"""returns best affine for given frame of data"""
618620
subhdr = self.subheaders[frame]
619621
x_off = subhdr['x_offset']
620622
y_off = subhdr['y_offset']
621623
z_off = subhdr['z_offset']
622-
624+
623625
zooms = self.get_zooms(frame=frame)
624-
626+
625627
dims = self.get_shape(frame)
626628
# get translations from center of image
627-
origin_offset = (np.array(dims)-1) / 2.0
629+
origin_offset = (np.array(dims)-1) / 2.0
628630
aff = np.diag(zooms)
629631
aff[:3,-1] = -origin_offset * zooms[:-1] + np.array([x_off,y_off,z_off])
630632
return aff
631-
633+
632634
def get_zooms(self,frame=0):
633635
"""returns zooms ...pixdims"""
634636
subhdr = self.subheaders[frame]
@@ -669,7 +671,7 @@ def data_from_fileobj(self, frame=0):
669671
data = raw_data * header['ecat_calibration_factor']
670672
data = data * subhdr['scale_factor']
671673
return data
672-
674+
673675

674676

675677

0 commit comments

Comments
 (0)