def align_unwrapped(sino):
    """Align an unwrapped phase array to zero-phase

    All operations are performed in-place.
    """
    samples = []
    if len(sino.shape) == 2:
        # 2D
        # take 1D samples at beginning and end of array
        samples.append(sino[:, 0])
        samples.append(sino[:, 1])
        samples.append(sino[:, 2])
        samples.append(sino[:, -1])
        samples.append(sino[:, -2])

    elif len(sino.shape) == 3:
        # 3D
        # take 1D samples at beginning and end of array
        samples.append(sino[:, 0, 0])
        samples.append(sino[:, 0, -1])
        samples.append(sino[:, -1, 0])
        samples.append(sino[:, -1, -1])
        samples.append(sino[:, 0, 1])

    # find discontinuities in the samples
    steps = np.zeros((len(samples), samples[0].shape[0]))
    for i in range(len(samples)):
        t = np.unwrap(samples[i])
        steps[i] = samples[i] - t

    # if the majority believes so, add a step of PI
    remove = mode(steps, axis=0)[0][0]

    # obtain divmod min
    twopi = 2*np.pi
    minimum = divmod_neg(np.min(sino), twopi)[0]
    remove += minimum*twopi

    for i in range(len(sino)):
        sino[i] -= remove[i]
def align_unwrapped ( sino ) : samples = [ ] if len ( sino . shape ) == 2 : samples . append ( sino [ : , 0 ] ) samples . append ( sino [ : , 1 ] ) samples . append ( sino [ : , 2 ] ) samples . append ( sino [ : , - 1 ] ) samples . append ( sino [ : , - 2 ] ) elif len ( sino . shape ) == 3 : samples . append ( sino [ : , 0 , 0 ] ) samples . append ( sino [ : , 0 , - 1 ] ) samples . append ( sino [ : , - 1 , 0 ] ) samples . append ( sino [ : , - 1 , - 1 ] ) samples . append ( sino [ : , 0 , 1 ] ) steps = np . zeros ( ( len ( samples ) , samples [ 0 ] . shape [ 0 ] ) ) for i in range ( len ( samples ) ) : t = np . unwrap ( samples [ i ] ) steps [ i ] = samples [ i ] - t remove = mode ( steps , axis = 0 ) [ 0 ] [ 0 ] twopi = 2 * np . pi minimum = divmod_neg ( np . min ( sino ) , twopi ) [ 0 ] remove += minimum * twopi for i in range ( len ( sino ) ) : sino [ i ] -= remove [ i ]
Align an unwrapped phase array to zero-phase

    All operations are performed in-place.