Skip to content

Commit 932cb59

Browse files
committed
RF - more informative error, moved code out of slightly obscure format-specific method
1 parent eb66ca1 commit 932cb59

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

nibabel/analyze.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,20 +369,24 @@ def from_header(klass, header=None, check=True):
369369
# set any fields etc that are specific to this format (overriden by
370370
# sub-classes)
371371
obj._set_format_specifics()
372+
# Check for unsupported datatypes
373+
orig_code = header.get_data_dtype()
374+
try:
375+
obj.set_data_dtype(orig_code)
376+
except HeaderDataError:
377+
raise HeaderDataError('Input header %s has datatype %s but '
378+
'output header %s does not support it'
379+
% (header.__class__,
380+
header.get_value_label('datatype'),
381+
klass))
372382
if check:
373383
obj.check_fix()
374384
return obj
375385

376386
def _set_format_specifics(self):
377387
''' Utility routine to set format specific header stuff
378-
379-
For analyze headers, we need to check for datatypes that nifti supports
380-
and analyze does not, in order to raise a more polite error
381388
'''
382-
code = int(self._header_data['datatype'])
383-
if not code in self._data_type_codes.value_set():
384-
raise HeaderDataError('Analyze does not support datatype code %d'
385-
% code)
389+
pass
386390

387391
@classmethod
388392
def from_fileobj(klass, fileobj, endianness=None, check=True):

0 commit comments

Comments
 (0)