def from_array(a, mode=None, info={}):
 info = dict(info)
 bitdepth = None
 try:
  if mode.startswith('L'):
   gotmode = 'L'
   mode = mode[1:]
  elif mode.startswith('RGB'):
   gotmode = 'RGB'
   mode = mode[3:]
  else:
   raise Error()
  if mode.startswith('A'):
   gotmode += 'A'
   mode = mode[1:]
  while mode.startswith(';'):
   mode = mode[1:]
  if mode:
   try:
    bitdepth = int(mode)
   except (TypeError, ValueError):
    raise Error()
 except Error:
  raise Error("mode string should be 'RGB' or 'L;16' or similar.")
 mode = gotmode
 if bitdepth:
  if (info.get('bitdepth') and (bitdepth != info['bitdepth'])):
   raise Error(('mode bitdepth (%d) should match info bitdepth (%d).' % (bitdepth, info['bitdepth'])))
  info['bitdepth'] = bitdepth
 if ('size' in info):
  for (dimension, axis) in [('width', 0), ('height', 1)]:
   if (dimension in info):
    if (info[dimension] != info['size'][axis]):
     raise Error(("info[%r] should match info['size'][%r]." % (dimension, axis)))
  (info['width'], info['height']) = info['size']
 if ('height' not in info):
  try:
   l = len(a)
  except TypeError:
   raise Error("len(a) does not work, supply info['height'] instead.")
  info['height'] = l
 if ('greyscale' in info):
  if (bool(info['greyscale']) != ('L' in mode)):
   raise Error("info['greyscale'] should match mode.")
 info['greyscale'] = ('L' in mode)
 if ('alpha' in info):
  if (bool(info['alpha']) != ('A' in mode)):
   raise Error("info['alpha'] should match mode.")
 info['alpha'] = ('A' in mode)
 planes = len(mode)
 if ('planes' in info):
  if (info['planes'] != planes):
   raise Error("info['planes'] should match mode.")
 (a, t) = itertools.tee(a)
 row = t.next()
 del t
 try:
  row[0][0]
  threed = True
  testelement = row[0]
 except (IndexError, TypeError):
  threed = False
  testelement = row
 if ('width' not in info):
  if threed:
   width = len(row)
  else:
   width = (len(row) // planes)
  info['width'] = width
 assert (not threed)
 if ('bitdepth' not in info):
  try:
   dtype = testelement.dtype
  except AttributeError:
   try:
    bitdepth = (8 * testelement.itemsize)
   except AttributeError:
    bitdepth = 8
  else:
   if (dtype.kind == 'b'):
    bitdepth = 1
   else:
    bitdepth = (8 * dtype.itemsize)
  info['bitdepth'] = bitdepth
 for thing in 'width height bitdepth greyscale alpha'.split():
  assert (thing in info)
 return Image(a, info)

def from_array ( a , mode = None , info = { } ) : info = dict ( info ) bitdepth = None try : if mode . startswith ( 'L' ) : gotmode = 'L' mode = mode [ 1 : ] elif mode . startswith ( 'RGB' ) : gotmode = 'RGB' mode = mode [ 3 : ] else : raise Error ( ) if mode . startswith ( 'A' ) : gotmode += 'A' mode = mode [ 1 : ] while mode . startswith ( ';' ) : mode = mode [ 1 : ] if mode : try : bitdepth = int ( mode ) except ( TypeError , ValueError ) : raise Error ( ) except Error : raise Error ( "mode string should be 'RGB' or 'L;16' or similar." ) mode = gotmode if bitdepth : if ( info . get ( 'bitdepth' ) and ( bitdepth != info [ 'bitdepth' ] ) ) : raise Error ( ( 'mode bitdepth (%d) should match info bitdepth (%d).' % ( bitdepth , info [ 'bitdepth' ] ) ) ) info [ 'bitdepth' ] = bitdepth if ( 'size' in info ) : for ( dimension , axis ) in [ ( 'width' , 0 ) , ( 'height' , 1 ) ] : if ( dimension in info ) : if ( info [ dimension ] != info [ 'size' ] [ axis ] ) : raise Error ( ( "info[%r] should match info['size'][%r]." % ( dimension , axis ) ) ) ( info [ 'width' ] , info [ 'height' ] ) = info [ 'size' ] if ( 'height' not in info ) : try : l = len ( a ) except TypeError : raise Error ( "len(a) does not work, supply info['height'] instead." ) info [ 'height' ] = l if ( 'greyscale' in info ) : if ( bool ( info [ 'greyscale' ] ) != ( 'L' in mode ) ) : raise Error ( "info['greyscale'] should match mode." ) info [ 'greyscale' ] = ( 'L' in mode ) if ( 'alpha' in info ) : if ( bool ( info [ 'alpha' ] ) != ( 'A' in mode ) ) : raise Error ( "info['alpha'] should match mode." ) info [ 'alpha' ] = ( 'A' in mode ) planes = len ( mode ) if ( 'planes' in info ) : if ( info [ 'planes' ] != planes ) : raise Error ( "info['planes'] should match mode." ) ( a , t ) = itertools . tee ( a ) row = t . next ( ) del t try : row [ 0 ] [ 0 ] threed = True testelement = row [ 0 ] except ( IndexError , TypeError ) : threed = False testelement = row if ( 'width' not in info ) : if threed : width = len ( row ) else : width = ( len ( row ) // planes ) info [ 'width' ] = width assert ( not threed ) if ( 'bitdepth' not in info ) : try : dtype = testelement . dtype except AttributeError : try : bitdepth = ( 8 * testelement . itemsize ) except AttributeError : bitdepth = 8 else : if ( dtype . kind == 'b' ) : bitdepth = 1 else : bitdepth = ( 8 * dtype . itemsize ) info [ 'bitdepth' ] = bitdepth for thing in 'width height bitdepth greyscale alpha' . split ( ) : assert ( thing in info ) return Image ( a , info )
create dask array from something that looks like an array input must have a .