def ingest ( self ):
    """Read the stack and ingest"""

    with closing ( ocpcaproj.OCPCAProjectsDB() ) as projdb:
      proj = projdb.loadProject ( self.token )

    with closing ( ocpcadb.OCPCADB (proj) ) as db:

      (startslice, endslice) = proj.datasetcfg.slicerange
      (xcubedim, ycubedim, zcubedim) = cubedims = proj.datasetcfg.cubedim[self.resolution]
      (ximagesz, yimagesz) = proj.datasetcfg.imagesz[self.resolution]
      batchsz = zcubedim

      # Ingest in database aligned slabs in the z dimension
      for sl in range( startslice, endslice, batchsz ):
          
        slab = np.zeros ( [zcubedim, yimagesz, ximagesz], dtype=np.uint8 )

        # over each slice
        for b in range( batchsz ):
            
          #if we are at the end of the space, quit
          if ( sl + b <= endslice ):
              
            filename = '{}dyer15_3_maskimg_{:0>4}.tif'.format(self.path, sl+b)
            #filename = '{}proj_2_{:0>5}.tif'.format(self.path, sl+b)
            #filename = '{}{}_maskimg_{:0>4}.tif'.format(self.path, self.token, sl+b)
            #filename = '{}xbrain_dyer15_slice{:0>4}.tif'.format(self.path, sl+b )
            print filename
            try:
              img = Image.open(filename,'r')
              slab [b,:,:] = np.asarray(img)
            except __HOLE__, e:
              print "Failed to open file %s" % (e)
              img = np.zeros((yimagesz,ximagesz), dtype=np.uint8)
              slab [b,:,:] = img


        for y in range ( 0, yimagesz, ycubedim ):
          for x in range ( 0, ximagesz, xcubedim ):

            zidx = ocplib.XYZMorton ( [ x/xcubedim, y/ycubedim, (sl-startslice)/zcubedim] )
            cubedata = np.zeros ( [zcubedim, ycubedim, xcubedim], dtype=np.uint8 )

            xmin = x 
            ymin = y 
            xmax = ( min(ximagesz-1, x+xcubedim-1) ) + 1
            ymax = ( min(yimagesz-1, y+ycubedim-1) ) + 1
            zmin = 0
            zmax = min(sl+zcubedim,endslice)

            cubedata[0:zmax-zmin,0:ymax-ymin,0:xmax-xmin] = slab[zmin:zmax,ymin:ymax,xmin:xmax]
            cube = imagecube.ImageCube16 ( cubedims )
            cube.zeros()
            cube.data = cubedata
            if np.count_nonzero ( cube.data ) != 0:
              print zidx, ocplib.MortonXYZ(zidx)
              db.putCube ( zidx, self.resolution, cube )
          print "Commiting at x=%s, y=%s, z=%s" % (x,y,sl)
        db.conn.commit()
dataset/ETHPy150Open neurodata/ndstore/ingest/eva/eva15.py/CatmaidIngest.ingest