the line
idx = np.linspace(0, slice_smoothed.shape[0], n_output_cells)
should be modified to
idx = np.linspace(0, slice_smoothed.shape[0]-1, n_output_cells)
otherwise the idx is longer than output_slice, and when executing
output_slice = smoothing.interpolate2d(slice_smoothed, idx, idx, order=order)
output slice repeats the end values at the beginning
the line idx = np.linspace(0, slice_smoothed.shape[0], n_output_cells) should be modified to idx = np.linspace(0, slice_smoothed.shape[0]-1, n_output_cells)
otherwise the idx is longer than output_slice, and when executing output_slice = smoothing.interpolate2d(slice_smoothed, idx, idx, order=order) output slice repeats the end values at the beginning