Skip to content

Commit caabbe6

Browse files
author
cindeem
committed
NF more tests fix issue in endian in tinypet.v
1 parent eb4f390 commit caabbe6

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

nibabel/ecat.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def _guess_endian(self, hdr):
229229
return native_code
230230

231231
@classmethod
232-
def from_fileobj(klass, fileobj, endianness=None,check=False):
232+
def from_fileobj(klass, fileobj, endianness=None):
233233
"""Return /read header with given or guessed endian code
234234
235235
Parameters
@@ -250,7 +250,7 @@ def from_fileobj(klass, fileobj, endianness=None,check=False):
250250
251251
"""
252252
raw_str = fileobj.read(klass._dtype.itemsize)
253-
return klass(raw_str, endianness, check)
253+
return klass(raw_str, endianness)
254254

255255
def _empty_headerdata(self,endianness=None):
256256
"""Return header data for empty header with given endianness"""
@@ -275,8 +275,8 @@ def get_data_dtype(self):
275275
def copy(self):
276276
return self.__class__(
277277
self.binaryblock,
278-
self.endianness,
279-
check=False)
278+
self.endianness)
279+
280280

281281
def __eq__(self, other):
282282
""" checks for equality between two headers"""
@@ -424,9 +424,9 @@ def __init__(self, hdr, mlist, fileobj):
424424
self.endianness = hdr.endianness
425425
self._mlist = mlist
426426
self.fileobj = fileobj
427-
self.subheaders = self.get_subheaders()
427+
self.subheaders = self._get_subheaders()
428428

429-
def get_subheaders(self):
429+
def _get_subheaders(self):
430430
"""retreive all subheaders and return list of subheader recarrays
431431
"""
432432
subheaders = []
@@ -522,7 +522,7 @@ def get_data_dtype(self, frame):
522522
def get_frame_offset(self, frame=0):
523523
mlist = self._mlist._mlist
524524
offset = mlist[frame][1] * 512
525-
return offset
525+
return int(offset)
526526

527527
def raw_data_from_fileobj(self, frame=0):
528528
dtype = self.get_data_dtype(frame)

nibabel/tests/data/tinypet.v

0 Bytes
Binary file not shown.

nibabel/tests/test_ecat.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,45 @@ def test_endianness(self):
6464
fid.close()
6565
yield assert_true(hdr.endianness == '<')
6666
yield assert_true(newhdr.endianness == '>')
67+
68+
class TestEcatMlist(ParametricTestCase):
69+
header_class = EcatHeader
70+
mlist_class = EcatMlist
71+
example_file = ecat_file
72+
73+
def test_mlist(self):
74+
fid = open(self.example_file, 'rb')
75+
hdr = self.header_class.from_fileobj(fid)
76+
mlist = self.mlist_class(fid, hdr)
77+
fid.seek(0)
78+
fid.seek(512)
79+
dat=fid.read(128*32)
80+
dt = np.dtype([('matlist',np.int32)])
81+
dt = dt.newbyteorder('>')
82+
mats = np.recarray(shape=(32,4), dtype=dt, buf=dat)
83+
fid.close()
84+
yield assert_true(mats['matlist'][0,0] + mats['matlist'][0,3] == 31)
85+
yield assert_true(mlist.get_frame_order()[0][0] == 0)
86+
yield assert_true(mlist.get_frame_order()[0][1] == 16842758.0)
87+
88+
class TestEcatSubHeader(ParametricTestCase):
89+
header_class = EcatHeader
90+
mlist_class = EcatMlist
91+
subhdr_class = EcatSubHeader
92+
example_file = ecat_file
93+
fid = open(example_file, 'rb')
94+
hdr = header_class.from_fileobj(fid)
95+
mlist = mlist_class(fid, hdr)
96+
subhdr = subhdr_class(hdr, mlist, fid)
97+
fid.close()
98+
99+
def test_subheader_size(self):
100+
yield assert_equal(self.subhdr_class._subhdrdtype.itemsize, 242)
101+
102+
def test_subheader(self):
103+
yield assert_equal(self.subhdr.get_shape() , (10,10,3))
104+
yield assert_equal(self.subhdr.get_nframes() , 1)
105+
yield assert_equal(self.subhdr.get_nframes(),
106+
len(self.subhdr.subheaders))
107+
yield assert_equal(self.subhdr._check_affines(), True)
108+

0 commit comments

Comments
 (0)