def refine_center(image, calibrated_center, pixel_size, phi_steps, max_peaks,
                  thresh, window_size,
                  nx=None, min_x=None, max_x=None):
    """
    Refines the location of the center of the beam.

    This relies on being able to see the whole powder pattern.

    Parameters
    ----------
    image : ndarray
        The image

    calibrated_center : tuple
        (row, column) the estimated center

    pixel_size : tuple
        (pixel_height, pixel_width)

    phi_steps : int
        How many regions to split the ring into, should be >10

    max_peaks : int
        Number of rings to look it

    thresh : float
        Fraction of maximum peak height

    window_size : int, optional
        The window size to use (in bins) to use when refining peaks

    nx : int, optional
        Number of bins to use for radial binning

    min_x : float, optional
        The minimum radius to use for radial binning

    max_x : float, optional
        The maximum radius to use for radial binning

    Returns
    -------
    calibrated_center : tuple
        The refined calibrated center.
    """
    if nx is None:
        nx = int(np.mean(image.shape) * 2)

    phi = angle_grid(calibrated_center, image.shape, pixel_size).ravel()
    r = radial_grid(calibrated_center, image.shape, pixel_size).ravel()
    I = image.ravel()

    phi_steps = np.linspace(-np.pi, np.pi, phi_steps, endpoint=True)
    out = deque()
    for phi_start, phi_end in pairwise(phi_steps):
        mask = (phi <= phi_end) * (phi > phi_start)
        out.append(bin_1D(r[mask], I[mask],
                          nx=nx, min_x=min_x, max_x=max_x))
    out = list(out)

    ring_trace = []
    for bins, b_sum, b_count in out:
        mask = b_sum > 10
        avg = b_sum[mask] / b_count[mask]
        bin_centers = bin_edges_to_centers(bins)[mask]

        cands = scipy.signal.argrelmax(avg, order=window_size)[0]
        # filter local maximums by size
        cands = filter_peak_height(avg, cands, thresh*np.max(avg),
                                   window=window_size)
        ring_trace.append(bin_centers[cands[:max_peaks]])

    tr_len = [len(rt) for rt in ring_trace]
    mm = np.min(tr_len)
    ring_trace = np.vstack([rt[:mm] for rt in ring_trace]).T

    mean_dr = np.mean(ring_trace - np.mean(ring_trace, axis=1, keepdims=True),
                      axis=0)

    phi_centers = bin_edges_to_centers(phi_steps)

    delta = np.mean(np.diff(phi_centers))
    # this is doing just one term of a Fourier series
    # note that we have to convert _back_ to pixels from real units
    # TODO do this with better integration/handle repeat better
    col_shift = (np.sum(np.sin(phi_centers) * mean_dr) *
                 delta / (np.pi * pixel_size[1]))
    row_shift = (np.sum(np.cos(phi_centers) * mean_dr) *
                 delta / (np.pi * pixel_size[0]))

    return tuple(np.array(calibrated_center) +
                 np.array([row_shift, col_shift]))
dataset/ETHPy150Open scikit-beam/scikit-beam/skbeam/core/calibration.py/refine_center/original