def boxerFrameStack(framestackpath, parttree, outstack, boxsize,framelist): """ boxes the particles and returns them as a list of numpy arrays """ start_frame = framelist[0] nframe = len(framelist) apDisplay.printMsg("boxing %d particles from sum of total %d frames starting from frame %d using mmap" % (len(parttree),nframe,start_frame)) boxedparticles = [] stack = mrc.mmap(framestackpath) for partdict in parttree: x1,x2,y1,y2 = getBoxBoundary(partdict, boxsize) apDisplay.printDebug(' crop range of (x,y)=(%d,%d) to (%d,%d)' % (x1,y1,x2-1,y2-1)) #numpy arrays are rows,cols --> y,x not x,y boxpart = numpy.sum(stack[tuple(framelist),y1:y2,x1:x2],axis=0) boxedparticles.append(boxpart) apImagicFile.writeImagic(boxedparticles, outstack) return True
def _getAllImages(self): startt = time.time() allfiles = glob.glob("*.dwn.mrc") self.imgtree = [] for i, filename in enumerate(allfiles): imagedict = FileImageData() imagedict.dbid = i + 1 imagedict['filename'] = filename[:-8] imagedict['image'] = mrc.mmap(filename) self.imgtree.append(imagedict) precount = len(self.imgtree) apDisplay.printMsg("Found " + str(precount) + " images in " + apDisplay.timeString(time.time() - startt)) ### REMOVE PROCESSED IMAGES apDisplay.printMsg("Remove processed images") self._removeProcessedImages() ### SET IMAGE ORDER if self.params['shuffle'] is True: self.imgtree = self._shuffleTree(self.imgtree) apDisplay.printMsg("Process images shuffled") elif self.params['reverse'] is True: apDisplay.printMsg("Process images new to old") else: # by default images are new to old apDisplay.printMsg("Process images old to new") self.imgtree.reverse() ### LIMIT NUMBER if self.params['limit'] is not None: lim = self.params['limit'] if len(self.imgtree) > lim: apDisplay.printMsg("Limiting number of images to " + str(lim)) self.imgtree = self.imgtree[:lim] if len(self.imgtree) > 0: # Fake apix self.params['apix'] = self.getPixelSize(self.imgtree[0]) self.stats['imagecount'] = len(self.imgtree)
def _getAllImages(self): startt = time.time() allfiles = glob.glob("*.dwn.mrc") self.imgtree = [] for i, filename in enumerate(allfiles): imagedict = FileImageData() imagedict.dbid = i+1 imagedict['filename'] = filename[:-8] imagedict['image'] = mrc.mmap(filename) self.imgtree.append(imagedict) precount = len(self.imgtree) apDisplay.printMsg("Found "+str(precount)+" images in "+apDisplay.timeString(time.time()-startt)) ### REMOVE PROCESSED IMAGES apDisplay.printMsg("Remove processed images") self._removeProcessedImages() ### SET IMAGE ORDER if self.params['shuffle'] is True: self.imgtree = self._shuffleTree(self.imgtree) apDisplay.printMsg("Process images shuffled") elif self.params['reverse'] is True: apDisplay.printMsg("Process images new to old") else: # by default images are new to old apDisplay.printMsg("Process images old to new") self.imgtree.reverse() ### LIMIT NUMBER if self.params['limit'] is not None: lim = self.params['limit'] if len(self.imgtree) > lim: apDisplay.printMsg("Limiting number of images to "+str(lim)) self.imgtree = self.imgtree[:lim] if len(self.imgtree) > 0: # Fake apix self.params['apix'] = self.getPixelSize(self.imgtree[0]) self.stats['imagecount'] = len(self.imgtree)
def readFileData(self, filename): """ takes any file type and returns a list of 2D arrays use memory mapping (mmap) to prevent memory overloads """ #Determine extension if filename.endswith('.mrc') or filename.endswith('.mrcs'): data = mrc.mmap(filename) if len(data.shape) == 2: #convert to 3D self.single = True data.resize((1, data.shape[0], data.shape[1], )) elif filename.endswith('.hed') or filename.endswith('.img'): data = imagic.read(filename) elif filename.endswith('.spi'): ### to be implemented apDisplay.printError("SPIDER is not implemented yet") elif filename.endswith('.hdf'): ### to be implemented apDisplay.printError("HDF is not implemented yet") else: apDisplay.printError("unknown stack type") return data
def memmapMRC(fileref): fullname = os.path.join(fileref.path, fileref.filename) im = mrc.mmap(fullname) return im