Skip to content

Commit 3b9f8c4

Browse files
committed
BF+TST - fix indentation error for ecat proxy
Ecat proxy was returning None after first read
1 parent d7ea9e1 commit 3b9f8c4

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

nibabel/ecat.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,7 @@ def __array__(self):
657657
frame_mapping = self._subheader._mlist.get_frame_order()
658658
for i in sorted(frame_mapping):
659659
self._data[:,:,:,i] = self._subheader.data_from_fileobj(frame_mapping[i][0])
660-
return self._data
661-
662-
660+
return self._data
663661

664662
def __init__(self, data, affine, header,
665663
subheader, mlist ,
@@ -672,7 +670,6 @@ def __init__(self, data, affine, header,
672670
673671
Parameters
674672
----------
675-
676673
data : None or array-like
677674
image data
678675
affine : None or (4,4) array-like
@@ -690,7 +687,6 @@ def __init__(self, data, affine, header,
690687
file_map : mapping, optional
691688
mapping giving file information for this image format
692689
693-
694690
Examples
695691
--------
696692
>>> import os
@@ -705,7 +701,6 @@ def __init__(self, data, affine, header,
705701
>>> data4d = img.get_data()
706702
>>> data4d.shape
707703
(10, 10, 3, 1)
708-
709704
"""
710705
self._subheader = subheader
711706
self._mlist = mlist
@@ -729,30 +724,26 @@ def __init__(self, data, affine, header,
729724
def _set_header(self, header):
730725
self._header = header
731726

732-
733727
def get_data(self):
734728
"""returns scaled data for all frames in a numpy array
735729
returns as a 4D array """
736730
if self._data is None:
737731
raise ImageDataError('No data in this image')
738-
return np.asanyarray(self._data)
739-
732+
return np.asanyarray(self._data)
740733

741734
def get_affine(self):
742735
if not self._subheader._check_affines():
743736
warnings.warn('Affines different across frames, loading affine from FIRST frame',
744737
UserWarning )
745738
return self._affine
746-
747-
739+
748740
def get_frame_affine(self, frame):
749741
"""returns 4X4 affine"""
750-
751742
return self._subheader.get_affine(frame=frame)
752743

753744
def get_frame(self,frame):
754745
return self._subheader.data_from_fileobj(frame)
755-
746+
756747
def get_data_dtype(self,frame):
757748
subhdr = self._subheader
758749
dt = subhdr._get_data_dtype(frame)
@@ -771,7 +762,7 @@ def get_mlist(self):
771762
def get_subheaders(self):
772763
"""get access to subheaders"""
773764
return self._subheader
774-
765+
775766
@classmethod
776767
def from_filespec(klass, filespec):
777768
return klass.from_filename(filespec)
@@ -786,8 +777,6 @@ def _get_fileholders(file_map):
786777
-------
787778
header : file holding header data
788779
image : file holding image data
789-
790-
791780
"""
792781
return file_map['header'], file_map['image']
793782

@@ -798,7 +787,7 @@ def from_file_map(klass, file_map):
798787
hdr_file, img_file = klass._get_fileholders(file_map)
799788
#note header and image are in same file
800789
hdr_fid = hdr_file.get_prepare_fileobj(mode = 'rb')
801-
header = klass._header.from_fileobj(hdr_fid)
790+
header = klass._header.from_fileobj(hdr_fid)
802791
hdr_copy = header.copy()
803792
### LOAD MLIST
804793
mlist = klass._mlist(hdr_fid, hdr_copy)
@@ -818,17 +807,16 @@ def from_file_map(klass, file_map):
818807
img = klass(data, aff, header, subheaders, mlist, extra=None, file_map = file_map)
819808
return img
820809

821-
822810
def to_filename(self, filename):
823811
"""nibabel does not support writing to Ecat filetypes at this time"""
824812
raise NotImplementedError('nibabel does not allow saving to Ecat'\
825813
' at this time ')
826-
814+
827815
@classmethod
828816
def from_image(klass, img):
829817
raise NotImplementedError("Ecat images can only be generated "\
830818
"from file objects")
831-
819+
832820
@classmethod
833821
def load(klass, filespec):
834822
return klass.from_filename(filespec)

nibabel/tests/test_ecat.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,17 @@ def test_mlist(self):
103103
assert_true(mats['matlist'][0,0] + mats['matlist'][0,3] == 31)
104104
assert_true(mlist.get_frame_order()[0][0] == 0)
105105
assert_true(mlist.get_frame_order()[0][1] == 16842758.0)
106-
106+
107+
107108
class TestEcatSubHeader(TestCase):
108109
header_class = EcatHeader
109110
mlist_class = EcatMlist
110111
subhdr_class = EcatSubHeader
111-
example_file = ecat_file
112+
example_file = ecat_file
112113
fid = open(example_file, 'rb')
113114
hdr = header_class.from_fileobj(fid)
114-
mlist = mlist_class(fid, hdr)
115+
mlist = mlist_class(fid, hdr)
115116
subhdr = subhdr_class(hdr, mlist, fid)
116-
117117

118118
def test_subheader_size(self):
119119
assert_equal(self.subhdr_class._subhdrdtype.itemsize, 242)
@@ -134,7 +134,6 @@ def test_subheader(self):
134134
assert_equal(dat.shape, self.subhdr.get_shape())
135135
scale_factor = self.subhdr.subheaders[0]['scale_factor']
136136
assert_equal(self.subhdr.subheaders[0]['scale_factor'].item(),1.0)
137-
138137
ecat_calib_factor = self.hdr['ecat_calibration_factor']
139138
assert_equal(ecat_calib_factor, 25007614.0)
140139
scaled_dat = self.subhdr.data_from_fileobj()
@@ -161,5 +160,16 @@ def test_data(self):
161160
assert_equal(dat.shape, self.img.shape)
162161
frame = self.img.get_frame(0)
163162
assert_array_equal(frame, dat[:,:,:,0])
164-
165-
163+
164+
def test_array_proxy(self):
165+
# Get the cached data copy
166+
dat = self.img.get_data()
167+
# Make a new one to test arrayproxy
168+
img = self.image_class.load(self.example_file)
169+
# Maybe we will promote _data to public, but I know this looks bad
170+
secret_data = img._data
171+
data2 = np.array(secret_data)
172+
assert_array_equal(data2, dat)
173+
# Check it rereads
174+
data3 = np.array(secret_data)
175+
assert_array_equal(data3, dat)

0 commit comments

Comments
 (0)