当前位置: 首页>>代码示例>>Python>>正文


Python Utility.split_list方法代码示例

本文整理汇总了Python中utility.Utility.split_list方法的典型用法代码示例。如果您正苦于以下问题:Python Utility.split_list方法的具体用法?Python Utility.split_list怎么用?Python Utility.split_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utility.Utility的用法示例。


在下文中一共展示了Utility.split_list方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: loop

# 需要导入模块: from utility import Utility [as 别名]
# 或者: from utility.Utility import split_list [as 别名]
  def loop( fibers_file, volume, lh_mesh_file, rh_mesh_file, neighbors, singleThread=False ):

    # load trk file
    s = nibabel.trackvis.read( fibers_file )
    tracks = s[0]

    # load meshes
    lh_verts, lh_faces = nibabel.freesurfer.read_geometry( lh_mesh_file )
    rh_verts, rh_faces = nibabel.freesurfer.read_geometry( rh_mesh_file )

    # load volume and get qForm matrix
    _image = nibabel.load( volume )
    qForm = _image.get_header().get_qform()
    qFormM = numpy.matrix( qForm )

    #
    # THREADED COMPONENT
    #
    if singleThread:
      numberOfThreads = 1
    else:
      numberOfThreads = 1#3#multiprocessing.cpu_count()

    print 'Splitting master into ' + str( numberOfThreads ) + ' pieces..'

    splittedOutputTracks = Utility.split_list( tracks[:], numberOfThreads )

    # list of threads
    t = [None] * numberOfThreads

    # list of alive flags
    a = [None] * numberOfThreads

    # list of matrix tempFiles
    mf = [None] * numberOfThreads


    for n in xrange( numberOfThreads ):

      # mark thread as alive
      a[n] = True

      # also create a temp file for the hdf5 file
      matrix_file = tempfile.mkstemp( '.h5', 'fyborg' )[1]

      mf[n] = matrix_file

      t[n] = Process( target=LooperWithMatrix._looper_, args=( splittedOutputTracks[n][:], lh_mesh_file, rh_mesh_file, int(neighbors), qFormM, matrix_file, n + 1 ) )
      print "Starting Thread-" + str( n + 1 ) + "..."
      t[n].start()

    allDone = False

    while not allDone:

      time.sleep( 1 )

      for n in xrange( numberOfThreads ):

        a[n] = t[n].is_alive()

      if not any( a ):
        # if no thread is alive
        allDone = True

    #
    # END OF THREADED COMPONENT
    #
    print "All Threads done!"
    #print mf

    return mf
开发者ID:FNNDSC,项目名称:F3000,代码行数:74,代码来源:looper_with_matrix.py

示例2: loop

# 需要导入模块: from utility import Utility [as 别名]
# 或者: from utility.Utility import split_list [as 别名]
 def loop(fibers_file, fibers_output_file, actions, singleThread=False):
 
   # load trk file
   s = nibabel.trackvis.read( fibers_file )
   tracks = s[0]
   origHeader = s[1]
   tracksHeader = numpy.copy( s[1] )
   numberOfScalars = origHeader['n_scalars']
   scalars = origHeader['scalar_name'].tolist()
   numberOfTracks = origHeader['n_count']
 
   # grab the scalarNames
   scalarNames = []
   for a in actions:
     if a.scalarName() != _actions.FyAction.NoScalar:
       scalarNames.append( a.scalarName() )
 
   # increase the number of scalars
   tracksHeader['n_scalars'] += len( scalarNames )
 
   # .. attach the new scalar names
   for i in range( len( scalarNames ) ):
     tracksHeader['scalar_name'][numberOfScalars + i] = scalarNames[i]
 
   #
   # THREADED COMPONENT
   #
   if singleThread:
     numberOfThreads = 1
   else:
     numberOfThreads = multiprocessing.cpu_count()
     
   print 'Splitting master into ' + str( numberOfThreads ) + ' pieces..' 
   
   splittedOutputTracks = Utility.split_list( tracks[:], numberOfThreads )
 
   # list of threads
   t = [None] * numberOfThreads
 
   # list of alive flags
   a = [None] * numberOfThreads
 
   # list of tempFiles
   f = [None] * numberOfThreads
 
   for n in xrange( numberOfThreads ):
     # configure actions
     __actions = []
     for act in actions:
       __actions.append( act )
 
     # mark thread as alive
     a[n] = True
     # fire the thread and give it a filename based on the number
     tmpFile = tempfile.mkstemp( '.trk', 'fyborg' )[1]
     f[n] = tmpFile
     t[n] = Process( target=Looper._looper_, args=( splittedOutputTracks[n][:], tracksHeader, tmpFile, __actions, n + 1 ) )
     print "Starting Thread-" + str( n + 1 ) + "..." 
     t[n].start()
 
   allDone = False
 
   while not allDone:
 
     time.sleep( 1 )
 
     for n in xrange( numberOfThreads ):
 
       a[n] = t[n].is_alive()
 
     if not any( a ):
       # if no thread is alive
       allDone = True
 
   #
   # END OF THREADED COMPONENT
   #
   print "All Threads done!" 
 
   #
   # Merging stage
   #
   print "Merging tracks..", f
 
   outputTracks = []
   # now read all the created tempFiles and merge'em to one
   for tmpFileNo in xrange( 0, len( f ) ):
     tTracks = nibabel.trackvis.read( f[tmpFileNo] )
 
     # add them
     outputTracks.extend( tTracks[0] )
 
   print "Merging done!" 
 
   nibabel.trackvis.write( fibers_output_file, outputTracks, tracksHeader )
 
   print "All done!" 
开发者ID:FNNDSC,项目名称:F3000,代码行数:99,代码来源:looper.py


注:本文中的utility.Utility.split_list方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。