Ejemplo n.º 1
0
 def _chk_sizeof_hdr(hdr, fix=True):
     ret = Report(hdr, HeaderDataError)
     if hdr['sizeof_hdr'] == 348:
         return ret
     ret.problem_msg = 'sizeof_hdr should be 348'
     if fix:
         hdr['sizeof_hdr'] = 348
         ret.fix_msg = 'set sizeof_hdr to 348'
     else:
         ret.level = 30
     return ret
Ejemplo n.º 2
0
 def _chk_pixdims(hdr, fix=True):
     ret = Report(hdr, HeaderDataError)
     if not np.any(hdr['pixdim'][1:4] < 0):
         return ret
     ret.problem_msg = 'pixdim[1,2,3] should be positive'
     if fix:
         hdr['pixdim'][1:4] = np.abs(hdr['pixdim'][1:4])
         ret.fix_msg = 'setting to abs of pixdim values'
     else:
         ret.level = 40
     return ret
Ejemplo n.º 3
0
 def _chk_scale(klass, hdr, fix=True):
     ret = Report(hdr, HeaderDataError)
     scale, offset = hdr.get_slope_inter()
     if not scale is None:
         return ret
     ret.problem_msg = "no valid scaling in scalefactor (=%s) " "or cal / gl fields; scalefactor assumed 1.0" % scale
     if fix:
         hdr["scl_slope"] = 1
         ret.fix_msg = 'setting scalefactor "scl_slope" to 1'
     else:
         ret.level = 30
     return ret
Ejemplo n.º 4
0
 def _chk_scale(hdr, fix=True):
     ret = Report(hdr, HeaderDataError)
     scale = hdr['scl_slope']
     if scale and np.isfinite(scale):
         return ret
     ret.problem_msg = ('scale slope is %s; should !=0 and be finite'
                        % scale)
     if fix:
         hdr['scl_slope'] = 1
         ret.fix_msg = 'setting scalefactor "scale" to 1'
     else:
         ret.level = 30
     return ret
Ejemplo n.º 5
0
 def _chk_origin(hdr, fix=True):
     ret = Report(hdr, HeaderDataError)
     origin = hdr['origin'][0:3]
     dims = hdr['dim'][1:4]
     if (not np.any(origin) or
         (np.all(origin > -dims) and np.all(origin < dims*2))):
         return ret
     ret.problem_msg = 'very large origin values relative to dims'
     if fix:
         ret.fix_msg = 'leaving as set, ignoring for affine'
     else:
         ret.level = 20
     return ret
Ejemplo n.º 6
0
 def _chk_bitpix(klass, hdr, fix=True):
     ret = Report(hdr, HeaderDataError)
     code = int(hdr['datatype'])
     try:
         dt = klass._data_type_codes.dtype[code]
     except KeyError:
         ret.level = 10
         ret.problem_msg = 'no valid datatype to fix bitpix'
         if fix:
             ret.fix_msg = 'no way to fix bitpix'
         return ret
     bitpix = dt.itemsize * 8
     ret = Report(hdr)
     if bitpix == hdr['bitpix']:
         return ret
     ret.problem_msg = 'bitpix does not match datatype'
     if fix:
         hdr['bitpix'] = bitpix # inplace modification
         ret.fix_msg = 'setting bitpix to match datatype'
     else:
         ret.level = 10
     return ret
Ejemplo n.º 7
0
 def _chk_datatype(klass, hdr, fix=True):
     ret = Report(hdr, HeaderDataError)
     code = int(hdr['datatype'])
     try:
         dtype = klass._data_type_codes.dtype[code]
     except KeyError:
         ret.level = 40
         ret.problem_msg = 'data code %d not recognized' % code
     else:
         if dtype.type is np.void:
             ret.level = 40
             ret.problem_msg = 'data code %d not supported' % code
     if fix:
         ret.fix_problem_msg = 'not attempting fix'
     return ret