def alignZeroShiftImages(imagedata1,imagedata2,bin):
        """Align start-angle images for tilt series where data is collect in two halves"""
        no_wx=True
        bin = int(bin)
        if not no_wx:
                # Tilt correlator needs wx which is not available on the cluster
                # This method is consistent with the rest of leginonxcorr and will
                # revert correction channels is needed even though it is likely
                # unnecessary
                fakenode = node.Node('fake',imagedata1['session'])
                correlator = tiltcorrelator.Correlator(fakenode, 0, bin,lpf=1.5)
                for imagedata in (imagedata1,imagedata2):
                        correlator.correlate(imagedata, tiltcorrection=True, channel=None)
                peak = correlator.getShift(False)
                fakenode.die()
        else:
                # phase correlation
                array1 = imagedata1['image']
                array2 = imagedata2['image']
                if bin != 1:
                        array1 = imagefun.bin(array1, bin)
                        array2 = imagefun.bin(array2, bin)
                shift = simpleCorrelation(array1,array2)
                peak = {'x':-shift[1]*bin,'y':shift[0]*bin}
                
        # x (row) shift on image coordinate is of opposite sign
        return {'shiftx':-peak['x'], 'shifty':peak['y']}
def getCorrelationPeak(correlator, bin, tiltseries, tilt, imagedata,allpeaks,second_group):
        peak = getPredictionPeakForImage(imagedata)
        start = tiltseries['tilt start']
        if tilt < start:
                peak['x']=-peak['x']
                peak['y']=-peak['y']
        if tilt < tiltseries['tilt start']+0.01 and tilt > tiltseries['tilt start']-0.01:
                correlator.correlate(imagedata, tiltcorrection=True, channel=None)
                if second_group:
                        allpeaks = [{'x':0.0,'y':0.0}]
                        peak = correlator.getShift(False)
                        if tiltseries['tilt step'] > 0:
                                return (-peak['x']/bin,peak['y']/bin),allpeaks,second_group
                        else:
                                return (peak['x']/bin,-peak['y']/bin),allpeaks,second_group
                else:
                        second_group = True
                        return None,allpeaks,second_group
        allpeaks.append(peak)
        return {'x':(peak['x']-allpeaks[-2]['x'])/bin, 'y':-(peak['y']-allpeaks[-2]['y'])/bin},allpeaks,second_group
def getCorrelationPeak(correlator, bin, tiltseries, tilt, imagedata, allpeaks, second_group):
    peak = getPredictionPeakForImage(imagedata)
    start = tiltseries["tilt start"]
    if tilt < start:
        peak["x"] = -peak["x"]
        peak["y"] = -peak["y"]
    if tilt < tiltseries["tilt start"] + 0.01 and tilt > tiltseries["tilt start"] - 0.01:
        correlator.correlate(imagedata, tiltcorrection=True, channel=None)
        if second_group:
            allpeaks = [{"x": 0.0, "y": 0.0}]
            peak = correlator.getShift(False)
            if tiltseries["tilt step"] > 0:
                return (-peak["x"] / bin, peak["y"] / bin), allpeaks, second_group
            else:
                return (peak["x"] / bin, -peak["y"] / bin), allpeaks, second_group
        else:
            second_group = True
            return None, allpeaks, second_group
    allpeaks.append(peak)
    return (
        {"x": (peak["x"] - allpeaks[-2]["x"]) / bin, "y": -(peak["y"] - allpeaks[-2]["y"]) / bin},
        allpeaks,
        second_group,
    )