def createAlignedReferenceStack(self): searchstr = "part"+self.params['timestamp']+"_ref0*.xmp" files = glob.glob(searchstr) files.sort() stack = [] reflist = self.readRefDocFile() for i in range(len(files)): fname = files[i] refdict = reflist[i] if refdict['partnum'] != i+1: print i, refdict['partnum'] apDisplay.printError("sorting error in reflist, see neil") refarray = spider.read(fname) xyshift = (refdict['xshift'], refdict['yshift']) alignrefarray = apImage.xmippTransform(refarray, rot=refdict['inplane'], shift=xyshift, mirror=refdict['mirror']) stack.append(alignrefarray) stackarray = numpy.asarray(stack, dtype=numpy.float32) #print stackarray.shape avgstack = "part"+self.params['timestamp']+"_average.hed" apFile.removeStack(avgstack, warn=False) apImagicFile.writeImagic(stackarray, avgstack) ### create a average mrc avgdata = stackarray.mean(0) apImage.arrayToMrc(avgdata, "average.mrc") return
def createAlignedStacks(self, partlist): stackid = self.params['stackid'] stackdata = apStack.getOnlyStackData(stackid) origstackfile = os.path.join(stackdata['path']['path'], stackdata['name']) imagesdict = apImagicFile.readImagic(origstackfile) i = 0 t0 = time.time() apDisplay.printMsg("rotating and shifting particles at "+time.asctime()) alignstack = [] while i < len(partlist): partimg = imagesdict['images'][i] partdict = partlist[i] partnum = i+1 #print partnum, partdict, partimg.shape if partdict['partnum'] != partnum: apDisplay.printError("particle shifting "+str(partnum)+" != "+str(partdict)) xyshift = (partdict['xshift'], partdict['yshift']) alignpartimg = apImage.xmippTransform(partimg, rot=partdict['inplane'], shift=xyshift, mirror=partdict['mirror']) alignstack.append(alignpartimg) i += 1 apDisplay.printMsg("rotate then shift %d particles in %s"%(i,apDisplay.timeString(time.time()-t0))) alignstackarray = numpy.asarray(alignstack) self.alignimagicfile = "alignstack.hed" apImagicFile.writeImagic(alignstackarray, self.alignimagicfile)
def createAlignedStacks(self, partlist): stackid = self.params['stackid'] stackdata = apStack.getOnlyStackData(stackid) origstackfile = os.path.join(stackdata['path']['path'], stackdata['name']) imagesdict = apImagicFile.readImagic(origstackfile) i = 0 t0 = time.time() apDisplay.printMsg("rotating and shifting particles at " + time.asctime()) alignstack = [] while i < len(partlist): partimg = imagesdict['images'][i] partdict = partlist[i] partnum = i + 1 #print partnum, partdict, partimg.shape if partdict['partnum'] != partnum: apDisplay.printError("particle shifting " + str(partnum) + " != " + str(partdict)) xyshift = (partdict['xshift'], partdict['yshift']) alignpartimg = apImage.xmippTransform(partimg, rot=partdict['inplane'], shift=xyshift, mirror=partdict['mirror']) alignstack.append(alignpartimg) i += 1 apDisplay.printMsg("rotate then shift %d particles in %s" % (i, apDisplay.timeString(time.time() - t0))) alignstackarray = numpy.asarray(alignstack) self.alignimagicfile = "alignstack.hed" apImagicFile.writeImagic(alignstackarray, self.alignimagicfile)
def createAlignedStacks(self, partlist, origstackfile): partperiter = min(4096,apImagicFile.getPartSegmentLimit(origstackfile)) numpart = len(partlist) if numpart < partperiter: partperiter = numpart t0 = time.time() imgnum = 0 stacklist = [] apDisplay.printMsg("rotating and shifting particles at "+time.asctime()) while imgnum < len(partlist): index = imgnum % partperiter if imgnum % 100 == 0: sys.stderr.write(".") if index == 0: ### deal with large stacks if imgnum > 0: sys.stderr.write("\n") stackname = "alignstack%d.hed"%(imgnum) apDisplay.printMsg("writing aligned particles to file "+stackname) stacklist.append(stackname) apFile.removeStack(stackname, warn=False) apImagicFile.writeImagic(alignstack, stackname, msg=False) perpart = (time.time()-t0)/imgnum apDisplay.printColor("particle %d of %d :: %s per part :: %s remain"% (imgnum+1, numpart, apDisplay.timeString(perpart), apDisplay.timeString(perpart*(numpart-imgnum))), "blue") alignstack = [] imagesdict = apImagicFile.readImagic(origstackfile, first=imgnum+1, last=imgnum+partperiter, msg=False) ### align particles partimg = imagesdict['images'][index] partdict = partlist[imgnum] partnum = imgnum+1 if partdict['partnum'] != partnum: apDisplay.printError("particle shifting "+str(partnum)+" != "+str(partdict)) xyshift = (partdict['xshift'], partdict['yshift']) alignpartimg = apImage.xmippTransform(partimg, rot=partdict['inplane'], shift=xyshift, mirror=partdict['mirror']) alignstack.append(alignpartimg) imgnum += 1 ### write remaining particle to file sys.stderr.write("\n") stackname = "alignstack%d.hed"%(imgnum) apDisplay.printMsg("writing aligned particles to file "+stackname) stacklist.append(stackname) apImagicFile.writeImagic(alignstack, stackname, msg=False) ### merge stacks alignimagicfile = "alignstack.hed" apFile.removeStack(alignimagicfile, warn=False) apImagicFile.mergeStacks(stacklist, alignimagicfile) #for stackname in stacklist: # emancmd = "proc2d %s %s"%(stackname, alignimagicfile) # apEMAN.executeEmanCmd(emancmd, verbose=False) filepart = apFile.numImagesInStack(alignimagicfile) if filepart != numpart: apDisplay.printError("number aligned particles (%d) not equal number expected particles (%d)"% (filepart, numpart)) for stackname in stacklist: apFile.removeStack(stackname, warn=False) ### summarize apDisplay.printMsg("rotated and shifted %d particles in %s"%(imgnum, apDisplay.timeString(time.time()-t0))) return alignimagicfile