def saveCurrentSegmentsAs(self, key, overwrite = False):
                
        print "save current segments as '%s'" %  (key)

        assert self.outputPath
        
        #make sure we have a 'done' overlay
        if self.done is None:
            self.done = numpy.zeros(self._dataItemImage.shape, numpy.uint16)
            self.emit(SIGNAL('doneOverlaysAvailable()'))
        
        if overwrite:
            shutil.rmtree(self.outputPath+'/'+str(key))
            labelsToDelete = copy.deepcopy(self._mapKeysToLabels[key])
            del self._mapKeysToLabels[key]
            for l in labelsToDelete:
                del self._mapLabelsToKeys[l]
            self.__rebuildDone()
            
        elif os.path.exists(self.outputPath+'/'+str(key)):
            raise RuntimeError("trying to overwrite '%s'", self.outputPath+'/'+str(key))
        #create directory to store the segment in     
        path = self.outputPath+'/'+str(key)
        print " - saving to '%s'" % (path),
        os.makedirs(path)
        
        print "segmentation",
        f = h5py.File(path + "/segmentation.h5", 'w')
        f.create_group('volume')
        tmp = self.segmentation[0,:,:,:,0]
        tmp.shape = (1,) + tmp.shape + (1,)
        f.create_dataset('volume/data', data=tmp, dtype = tmp.dtype, chunks=True, compression='gzip')
        f.close(); del f
        
        print "seeds"
        f = h5py.File(path + "/seeds.h5", 'w')
        f.create_group('volume')
        f.create_dataset('volume/data', data=self.seedLabelsVolume._data[:,:,:,:,:], 
                         dtype = self.seedLabelsVolume._data.dtype,
                         chunks=True, compression='gzip')
        f.close(); del f

        #compute connected components on current segmentation
        print " - computing CC of current segments"  
        connectedComponentsComputer = ConnectedComponents()
        prevMaxLabel = numpy.max(self.done)
        print "   - previous number of labels was %d" % (prevMaxLabel)
        cc = connectedComponentsComputer.connect(self.segmentation[0,:,:,:,:], background=set([1]))            
        self.done[:,:,:,:,:] = numpy.where(cc>0, cc+int(prevMaxLabel), self.done)
        
        f = h5py.File(self.outputPath + "/done.h5", 'w')
        f.create_group('volume')
        f.create_dataset('volume/data', data=self.done, dtype=numpy.uint16, chunks=True, compression='gzip')
        f.close()
    
        numCC = numpy.max(cc)
        print "   - there are %d segments to be saved as '%s'" % (numCC, key)
        print " - saving"
        for i in range(prevMaxLabel+1,prevMaxLabel+numCC+1):
            print "   - label %d now known as '%s'" % (i, key)
            self._mapLabelsToKeys[i] = key
            if key not in self._mapKeysToLabels.keys():
                self._mapKeysToLabels[key] = set()
            self._mapKeysToLabels[key].add(i)

        self.__saveMapping()

        self.__reset()
        
        #Clear the segmentation
        #The association with the overlay will be broken,
        #but this is not so bad because the overlay is 'fixed' via
        #the overlaysChanged() notification. This is not nice, but works...
        self.segmentation = None
        
        self.emit(SIGNAL('saveAsPossible(bool)'), False)
        self.emit(SIGNAL('savePossible(bool)'),   False)
        
        self.emit(SIGNAL('overlaysChanged()'))
Adds incomplete KeyRanges to the thread_pool.
dataset/ETHPy150Open ilastik/ilastik-0.5/ilastik/modules/interactive_segmentation/core/interactiveSegmentationModuleMgr.py/InteractiveSegmentationItemModuleMgr.saveCurrentSegmentsAs--crossover with--dataset/ETHPy150Open GoogleCloudPlatform/python-compat-runtime/appengine-compat/exported_appengine_sdk/google/appengine/tools/bulkloader.py/KeyRangeItem._AddUnfinishedRanges