Skip to content

Commit 2b55e29

Browse files
committed
RF+TST: test PARREC array proxy API; add slicing
Add `__getitem__` placeholder method for PARRECArrayProxy, to fulfill required API, and test with API validators.
1 parent 981db47 commit 2b55e29

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

nibabel/parrec.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,9 @@ def __array__(self):
561561
scalings=self._slice_scaling,
562562
mmap=self._mmap)
563563

564+
def __getitem__(self, slicer):
565+
return np.asanyarray(self)[slicer]
566+
564567

565568
class PARRECHeader(Header):
566569
"""PAR/REC header"""

nibabel/tests/test_proxy_api.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from ..optpkg import optional_package
4949
h5py, have_h5py, _ = optional_package('h5py')
5050
from .. import ecat
51+
from .. import parrec
5152

5253
from ..arrayproxy import ArrayProxy, is_proxy
5354

@@ -63,6 +64,8 @@
6364

6465
from .test_api_validators import ValidateAPI
6566

67+
from .test_parrec import EG_PAR, EG_REC
68+
6669
def _some_slicers(shape):
6770
ndim = len(shape)
6871
slicers = np.eye(ndim).astype(np.int).astype(object)
@@ -368,3 +371,19 @@ def eg_func():
368371

369372
def validate_header_isolated(self, pmaker, params):
370373
raise SkipTest('ECAT header does not support dtype get')
374+
375+
376+
class TestPARRECAPI(_TestProxyAPI):
377+
378+
def obj_params(self):
379+
img = parrec.load(EG_PAR)
380+
arr_out = img.get_data()
381+
def eg_func():
382+
img = parrec.load(EG_PAR)
383+
prox = parrec.PARRECArrayProxy(EG_REC, img.header, 'dv')
384+
fobj = open(EG_REC, 'rb')
385+
return prox, fobj, img.header
386+
yield (eg_func,
387+
dict(shape = (64, 64, 9, 3),
388+
dtype_out=np.float64,
389+
arr_out=arr_out))

0 commit comments

Comments
 (0)