def timecutout(self, ch, corner, dim, resolution, timerange):

    # get the size of the image and cube
    [ xcubedim, ycubedim, zcubedim ] = cubedim = self.datasetcfg.cubedim [ resolution ] 

    # Round to the nearest larger cube in all dimensions
    zstart = corner[2]/zcubedim
    ystart = corner[1]/ycubedim
    xstart = corner[0]/xcubedim

    znumcubes = (corner[2]+dim[2]+zcubedim-1)/zcubedim - zstart
    ynumcubes = (corner[1]+dim[1]+ycubedim-1)/ycubedim - ystart
    xnumcubes = (corner[0]+dim[0]+xcubedim-1)/xcubedim - xstart

    # use the requested resolution
    import cube
    incube = Cube.getCube ( cubedim, ch.getChannelType(), ch.getDataType() )
    outcube = Cube.getCube([xnumcubes*xcubedim,ynumcubes*ycubedim,znumcubes*zcubedim], ch.getChannelType(), ch.getDataType(), timerange=timerange)

    # Build a list of indexes to access
    listofidxs = []
    for z in range (znumcubes):
      for y in range (ynumcubes):
        for x in range (xnumcubes):
          mortonidx = ocplib.XYZMorton([x+xstart, y+ystart, z+zstart])
          listofidxs.append(mortonidx)

    # Sort the indexes in Morton order
    listofidxs.sort()

    # xyz offset stored for later use
    lowxyz = ocplib.MortonXYZ(listofidxs[0])

    self.kvio.startTxn()

    try:
      for idx in listofidxs:
        cuboids = self.getTimeCubes(ch, idx, range(timerange[0],timerange[1]), resolution)
        
        # use the batch generator interface
        for idx, timestamp, datastring in cuboids:

          # add the query result cube to the bigger cube
          curxyz = ocplib.MortonXYZ(int(idx))
          offset = [ curxyz[0]-lowxyz[0], curxyz[1]-lowxyz[1], curxyz[2]-lowxyz[2] ]

          if self.NPZ:
            incube.fromNPZ(datastring[:])
          else:
            incube.fromBlosc(datastring[:])
          
          # add it to the output cube
          outcube.addData(incube, offset, timestamp)

    except:
      self.kvio.rollback()
      raise

    self.kvio.commit()

    # need to trim down the array to size only if the dimensions are not the same
    if dim[0] % xcubedim  == 0 and dim[1] % ycubedim  == 0 and dim[2] % zcubedim  == 0 and corner[0] % xcubedim  == 0 and corner[1] % ycubedim  == 0 and corner[2] % zcubedim  == 0:
      pass
    else:
      outcube.trim ( corner[0]%xcubedim,dim[0],corner[1]%ycubedim,dim[1],corner[2]%zcubedim,dim[2] )

    return outcube
Extract a cube of arbitrary size.  Need not be aligned.
dataset/ETHPy150Open neurodata/ndstore/ocpca/ocpcadb.py/OCPCADB.timecutout