Package mvpa :: Package atlases :: Module warehouse

[hide private]
[frames] | no frames]

# Source Code for Module mvpa.atlases.warehouse

      1  # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
      2  # vi: set ft=python sts=4 ts=4 sw=4 et:
      3  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
      4  #
      5  #   See COPYING file distributed along with the PyMVPA package for the
      6  #   copyright and license terms.
      7  #
      8  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
      9  """Collection of the known atlases"""
     10
     11  import os
     12
     13  from mvpa.atlases.base import *
     14  from mvpa.atlases.fsl import *
     15
     16
     17  KNOWN_ATLAS_FAMILIES = {
     18      'pymvpa': (["talairach", "talairach-dist"],
     19                 r"/usr/share/rumba/atlases/data/%(name)s_atlas.xml"),
     20      'fsl': (["HarvardOxford-Cortical", "HarvardOxford-Subcortical",
     21               "JHU-tracts", "Juelich", "MNI", "Thalamus"],
     22              r"/usr/share/fsl/data/atlases/%(name)s.xml")
     23      # XXX make use of FSLDIR
     24      }
     25
     26  # map to go from the name to the path
     27  KNOWN_ATLASES = dict(reduce(lambda x,y:x+[(yy,y[1]) for yy in y[0]],
     28                               KNOWN_ATLAS_FAMILIES.values(), []))
     29
     30
     31 -def Atlas(filename=None, name=None, *args, **kwargs):
     32      """A convinience factory for the atlases
     33      """
     34      if filename is None:
     35          if name is None:
     36              raise ValueError, \
     37                    "Please provide either path or name of the atlas to be used"
     38          atlaspath = KNOWN_ATLASES[name]
     39          filename = atlaspath % ( {'name': name} )
     40          if not os.path.exists(filename):
     41              raise IOError, \
     42                    "File %s for atlas %s was not found" % (filename, name)
     43      else:
     44          if name is not None:
     45              raise ValueError, "Provide only filename or name"
     46
     47      try:
     48          tempAtlas = XMLBasedAtlas(filename=filename, *args, **kwargs)
     49          version = tempAtlas.version
     50          atlas_source = None
     51          for cls in [PyMVPAAtlas, FSLAtlas]:
     52              if cls._checkVersion(version):
     53                  atlas_source = cls.source
     54                  break
     55          if atlas_source is None:
     56              if __debug__: debug('ATL_', "Unknown atlas " + filename)
     57              return tempAtlas
     58
     59          atlasTypes = {
     60              'PyMVPA': {"Label" : LabelsAtlas,
     61                         "Reference": ReferencesAtlas},
     62              'FSL': {"Label" : FSLLabelsAtlas,
     63                      "Probabalistic": FSLProbabilisticAtlas}
     64              }[atlas_source]
     65          atlasType = tempAtlas.header.type.text
     66          if atlasTypes.has_key(atlasType):
     67              if __debug__: debug('ATL_', "Creating %s Atlas" % atlasType)
     68              return atlasTypes[atlasType](filename=filename, *args, **kwargs)
     69              #return ReferencesAtlas(filename)
     70          else:
     71              printdebug("Unknown %s type '%s' of atlas in %s." " Known are %s" %
     72                         (atlas_source, atlasType, filename,
     73                          atlasTypes.keys()), 2)
     74              return tempAtlas
     75      except XMLAtlasException, e:
     76          print "File %s is not a valid XML based atlas due to %s" \
     77                % (filename, `e`)
     78          raise e
     79
     80
     81  if __name__ == '__main__':
     82      from mvpa.base import verbose
     83      verbose.level = 10
     84      for name in [
     85          #'data/talairach_atlas.xml',
     86          '/usr/share/fsl/data/atlases/HarvardOxford-Cortical.xml',
     87          '/usr/share/fsl/data/atlases/HarvardOxford-Subcortical.xml'
     88          ]:
     89          atlas = Atlas(name)
     90          #print isinstance(atlas.atlas, objectify.ObjectifiedElement)
     91          #print atlas.header.images.imagefile.get('offset')
     92          #print atlas.labelVoxel( (0, -7, 20) )
     93          #print atlas[ 0, 0, 0 ]
     94          print atlas[ -63, -12, 22 ]
     95          #print atlas[ 0, -7, 20, [1,2,3] ]
     96          #print atlas[ (0, -7, 20), 1:2 ]
     97          #print atlas[ (0, -7, 20) ]
     98          #print atlas[ (0, -7, 20), : ]
     99          #   print atlas.getLabels(0)
    100