def findPeak(self, stack):
     if os.path.exists(self.peakfile):
         os.remove(self.peakfile)
     out = open(self.peakfile, "w")
     stackRead = mrc.read(stack)
     number, ydim, xdim = stackRead.shape
     for i in range(number):
         image = stackRead[i, :, :]
         output = peakfinder.findPixelPeak(image, guess=None, limit=None, lpf=None)
         coord = output["pixel peak"]
         out.write("%d	%s	%s\n" % (i, coord[0], coord[1]))
     return out
 def findPeak(self,stack):
         if os.path.exists(self.peakfile):
                 os.remove(self.peakfile)
         out = open(self.peakfile,'w')
         stackRead = mrc.read(stack) 
         number, ydim, xdim = stackRead.shape
         for i in range(number):
                 image = stackRead[i,:,:]
                 output = peakfinder.findPixelPeak(image, guess=None, limit=None, lpf=None)
                 coord = output['pixel peak']
                 out.write('%d   %s      %s\n' %(i,coord[0],coord[1]))
         return out
def alignZeroShiftImages(imgtree,zerotilts):
	"""Align 0 degree images for tilt series where data is collect in two halves"""
	#index for imgtree images are one less than index in zerotilts b/c protomo images start at 1
	im1=imgtree[zerotilts[0]-1]['image']
	im2=imgtree[zerotilts[1]-1]['image']
	print "correlating images",zerotilts[0], "and", zerotilts[1]
	cc=correlator.cross_correlate(im1,im2)
	peak=peakfinder.findPixelPeak(cc)
	#print peak
	newy,newx=shiftPeak(cc,peak)
	print "new origin for image", zerotilts[0], "is", newx, newy
	shifty=cc.shape[0]/2 - newy
	shiftx=cc.shape[1]/2 - newx
	return {'shiftx':shiftx, 'shifty':shifty}
def alignZeroShiftImages(imgtree, zerotilts):
    """Align 0 degree images for tilt series where data is collect in two halves"""
    #index for imgtree images are one less than index in zerotilts b/c protomo images start at 1
    im1 = imgtree[zerotilts[0] - 1]['image']
    im2 = imgtree[zerotilts[1] - 1]['image']
    print "correlating images", zerotilts[0], "and", zerotilts[1]
    cc = correlator.cross_correlate(im1, im2)
    peak = peakfinder.findPixelPeak(cc)
    #print peak
    newy, newx = shiftPeak(cc, peak)
    print "new origin for image", zerotilts[0], "is", newx, newy
    shifty = cc.shape[0] / 2 - newy
    shiftx = cc.shape[1] / 2 - newx
    return {'shiftx': shiftx, 'shifty': shifty}