code: def center_kernel(kernel, iterations=20):
      
      kernel = kernel_norm(kernel)
      nx, ny = np.shape(kernel)
      if nx %2 == 0:
          raise ValueError("kernel needs odd number of pixels")
      # make coordinate grid of kernel
      x_grid, y_grid = util.make_grid(nx, deltapix=1, left_lower=False)
      # compute 1st moments to get light weighted center
      x_w = np.sum(kernel * util.array2image(x_grid))
      y_w = np.sum(kernel * util.array2image(y_grid))
      # de-shift kernel
      kernel_centered = de_shift_kernel(kernel, shift_x=-x_w, shift_y=-y_w, iterations=iterations)
      return kernel_norm(kernel_centered)
docs: given a kernel that might not be perfectly centered, this routine computes its light weighted center and then
      moves the center in an iterative process such that it is centered
  
      :param kernel: 2d array (odd numbers)
      :param iterations: int, number of iterations
      :return: centered kernel