Skip to content

Commit ab2081b

Browse files
committed
Relegate slicing to is_header, remove _minctest
1 parent a4d2252 commit ab2081b

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

nibabel/minc1.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class MincHeader(Header):
273273
# We don't use the data layout - this just in case we do later
274274
data_layout = 'C'
275275

276-
#
276+
# Number of bytes needed to distinguish Minc1 and Minc2 headers
277277
sniff_size = 4
278278

279279
def data_to_fileobj(self, data, fileobj, rescale=True):
@@ -288,7 +288,7 @@ def data_from_fileobj(self, fileobj):
288288
class Minc1Header(MincHeader):
289289
@classmethod
290290
def is_header(klass, binaryblock):
291-
return binaryblock != b'\211HDF'
291+
return binaryblock[:4] != b'\211HDF'
292292

293293

294294
class Minc1Image(SpatialImage):

nibabel/minc2.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def _get_dimensions(self, var):
7373
# https://en.wikibooks.org/wiki/MINC/Reference/MINC2.0_File_Format_Reference#Associating_HDF5_dataspaces_with_MINC_dimensions
7474
try:
7575
dimorder = var.attrs['dimorder'].decode()
76-
except KeyError: # No specified dimensions
76+
except KeyError: # No specified dimensions
7777
return []
7878
return dimorder.split(',')
7979

@@ -137,7 +137,7 @@ def get_scaled_data(self, sliceobj=()):
137137
class Minc2Header(MincHeader):
138138
@classmethod
139139
def is_header(klass, binaryblock):
140-
return binaryblock == b'\211HDF'
140+
return binaryblock[:4] == b'\211HDF'
141141

142142

143143
class Minc2Image(Minc1Image):
@@ -167,9 +167,5 @@ def from_file_map(klass, file_map):
167167
data = klass.ImageArrayProxy(minc_file)
168168
return klass(data, affine, header, extra=None, file_map=file_map)
169169

170-
@classmethod
171-
def _minctest(klass, binaryblock):
172-
return binaryblock[:4] == b'\211HDF'
173-
174170

175171
load = Minc2Image.load

nibabel/spatialimages.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ def is_image(klass, filename, sniff=None):
910910
sniff_size = np.max([1024, klass.header_class.sniff_size])
911911
with BinOpener(metadata_filename, 'rb') as fobj:
912912
sniff = fobj.read(sniff_size)
913-
return klass.header_class.is_header(sniff[:klass.header_class.sniff_size]), sniff
913+
return klass.header_class.is_header(sniff), sniff
914914
except Exception as e:
915915
# Can happen if: file doesn't exist,
916916
# filesize < necessary sniff size (this happens!)

0 commit comments

Comments
 (0)