def main():

  parser = argparse.ArgumentParser(description='Ingest the kasthuri11 dataset annotations.')
  parser.add_argument('token', action="store", help='Token for the annotation project.')
  parser.add_argument('path', action="store", help='Directory with annotation PNG files.')

  result = parser.parse_args()

  # Get a list of the files in the directories
  for sl in range (_startslice,_endslice+1,_batchsz):

    newdata = np.zeros ( [ _batchsz, _ytilesz, _xtilesz ], dtype=np.uint32 )
   
    for b in range ( _batchsz ):

      if ( sl + b <= _endslice ):

        filenm = result.path + '/' + _prefix + '{:0>4}'.format(sl+b) + '.png'
        print filenm
        tileimage = Image.open ( filenm, 'r' )
        imgdata = np.asarray ( tileimage )

        newdata[b,:,:]  = kanno_opt.pngto32 ( imgdata )

        # the last z offset that we ingest, if the batch ends before _batchsz
        endz = b

    # Now we have a 1024x1024x16 z-aligned cube.  
    #   Send it to the database.
    url = 'http://openconnecto.me/emca/%s/npdense/%s/%s,%s/%s,%s/%s,%s/' % ( result.token, _resolution, _xoffset, _xoffset+_xtilesz, _yoffset, _yoffset+_ytilesz, sl, sl+endz+1 )

    print url, newdata.shape

    # Encode the voxelist an pickle
    fileobj = cStringIO.StringIO ()
    np.save ( fileobj, newdata )

    cdz = zlib.compress (fileobj.getvalue())

    # Build the post request
    try:
      req = urllib2.Request(url, cdz)
      response = urllib2.urlopen(req)
      the_page = response.read()
    except Exception, e:
      print "Failed ", e
dataset/ETHPy150Open neurodata/ndstore/ingest/nip12/amelioingest.py/main/original