def stack_pages(pages, memmap=False, tempdir=None, *args, **kwargs):
 if (len(pages) == 0):
  raise ValueError('no pages')
 if (len(pages) == 1):
  return pages[0].asarray(memmap=memmap, *args, **kwargs)
 data0 = pages[0].asarray(*args, **kwargs)
 shape = ((len(pages),) + data0.shape)
 if memmap:
  with tempfile.NamedTemporaryFile(dir=tempdir) as fh:
   data = numpy.memmap(fh, dtype=data0.dtype, shape=shape)
 else:
  data = numpy.empty(shape, dtype=data0.dtype)
 data[0] = data0
 if memmap:
  data.flush()
 del data0
 for (i, page) in enumerate(pages[1:]):
  data[(i + 1)] = page.asarray(*args, **kwargs)
  if memmap:
   data.flush()
 return data

def stack_pages ( pages , memmap = False , tempdir = None , * args , ** kwargs ) : if ( len ( pages ) == 0 ) : raise ValueError ( 'no pages' ) if ( len ( pages ) == 1 ) : return pages [ 0 ] . asarray ( memmap = memmap , * args , ** kwargs ) data0 = pages [ 0 ] . asarray ( * args , ** kwargs ) shape = ( ( len ( pages ) , ) + data0 . shape ) if memmap : with tempfile . NamedTemporaryFile ( dir = tempdir ) as fh : data = numpy . memmap ( fh , dtype = data0 . dtype , shape = shape ) else : data = numpy . empty ( shape , dtype = data0 . dtype ) data [ 0 ] = data0 if memmap : data . flush ( ) del data0 for ( i , page ) in enumerate ( pages [ 1 : ] ) : data [ ( i + 1 ) ] = page . asarray ( * args , ** kwargs ) if memmap : data . flush ( ) return data
read data from sequence of tiffpage and stack them vertically .