Skip to content

Commit

Permalink
Merge pull request #226 from matthew-brett/remove-minc-header-data-fetch
Browse files Browse the repository at this point in the history
MRG: fix invalid call to parent in minc classes

Prevent invalid call to the minc header-like class.
  • Loading branch information
matthew-brett committed Mar 4, 2014
2 parents 86f2738 + 7b4d450 commit f7f8b86
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
16 changes: 15 additions & 1 deletion nibabel/minc1.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from .externals.netcdf import netcdf_file

from .spatialimages import SpatialImage
from .spatialimages import Header, SpatialImage
from .fileslice import canonical_slicers

from .deprecated import FutureWarningMixin
Expand Down Expand Up @@ -263,13 +263,27 @@ def __getitem__(self, sliceobj):
return self.minc_file.get_scaled_data(sliceobj)


class MincHeader(Header):
# We don't use the data layout - this just in case we do later
data_layout = 'C'

def data_to_fileobj(self, data, fileobj, rescale=True):
""" See Header class for an implementation we can't use """
raise NotImplementedError

def data_from_fileobj(self, fileobj):
""" See Header class for an implementation we can't use """
raise NotImplementedError


class Minc1Image(SpatialImage):
''' Class for MINC 1 format images
The MINC1 image class uses the default header type, rather than a specific
MINC header type - and reads the relevant information from the MINC file on
load.
'''
header_class = MincHeader
files_types = (('image', '.mnc'),)
_compressed_exts = ('.gz', '.bz2')

Expand Down
25 changes: 24 additions & 1 deletion nibabel/tests/test_minc1.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
import bz2
import warnings
import types
from io import BytesIO

import numpy as np

from .. import load, Nifti1Image
from ..externals.netcdf import netcdf_file
from ..deprecated import ModuleProxy
from .. import minc1
from ..minc1 import Minc1File, Minc1Image
from ..minc1 import Minc1File, Minc1Image, MincHeader

from nose.tools import (assert_true, assert_equal, assert_false, assert_raises)
from numpy.testing import assert_array_equal, assert_array_almost_equal
Expand Down Expand Up @@ -197,5 +198,27 @@ def test_compressed(self):
del img


# Test the Minc header
def test_header_data_io():
bio = BytesIO()
hdr = MincHeader()
arr = np.arange(24).reshape((2, 3, 4))
assert_raises(NotImplementedError, hdr.data_to_fileobj, arr, bio)
assert_raises(NotImplementedError, hdr.data_from_fileobj, bio)


class TestMinc1Image(tsi.TestSpatialImage):
image_class = Minc1Image
eg_images = (pjoin(data_path, 'tiny.mnc'),)
module = minc1

def test_data_to_from_fileobj(self):
# Check data_from_fileobj of header raises an error
for fpath in self.eg_images:
img = self.module.load(fpath)
bio = BytesIO()
arr = np.arange(24).reshape((2, 3, 4))
assert_raises(NotImplementedError,
img.header.data_to_fileobj, arr, bio)
assert_raises(NotImplementedError,
img.header.data_from_fileobj, bio)
2 changes: 2 additions & 0 deletions nibabel/tests/test_minc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ class TestMinc2File(tm2._TestMincFile):

class TestMinc2Image(tm2.TestMinc1Image):
image_class = Minc2Image
eg_images = (pjoin(data_path, 'small.mnc'),)
module = minc2

0 comments on commit f7f8b86

Please sign in to comment.