def _extract_volume_info(mgz, raise_error=True):
 try:
  import nibabel as nib
 except ImportError:
  return
 header = nib.load(mgz).header
 vol_info = dict()
 version = header['version']
 if (version == 1):
  version = ('%s  # volume info valid' % version)
 else:
  raise ValueError('Volume info invalid.')
 vol_info['valid'] = version
 vol_info['filename'] = mgz
 vol_info['volume'] = header['dims'][:3]
 vol_info['voxelsize'] = header['delta']
 (vol_info['xras'], vol_info['yras'], vol_info['zras']) = header['Mdc'].T
 vol_info['cras'] = header['Pxyz_c']
 return vol_info

def _extract_volume_info ( mgz , raise_error = True ) : try : import nibabel as nib except ImportError : return header = nib . load ( mgz ) . header vol_info = dict ( ) version = header [ 'version' ] if ( version == 1 ) : version = ( '%s  # volume info valid' % version ) else : raise ValueError ( 'Volume info invalid.' ) vol_info [ 'valid' ] = version vol_info [ 'filename' ] = mgz vol_info [ 'volume' ] = header [ 'dims' ] [ : 3 ] vol_info [ 'voxelsize' ] = header [ 'delta' ] ( vol_info [ 'xras' ] , vol_info [ 'yras' ] , vol_info [ 'zras' ] ) = header [ 'Mdc' ] . T vol_info [ 'cras' ] = header [ 'Pxyz_c' ] return vol_info
helper for extracting volume info from a mgz file .