import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d

array = np.asarray([
    0, 1, 4, 8, 10, 10.5, 10.2, 10, 10, 10, 10, 10, 10.2, 10.5, 10, 7, 3, 1, 0
])
xs = np.linspace(0, len(array)-1, num=len(array), endpoint=True)
linear_factor = 1
xs_linear = np.linspace(0, len(array)-1, num=len(array)*linear_factor, endpoint=True)
y_interp = interp1d(x=xs, y=array, kind="linear", fill_value='extrapolate')
array_linear = y_interp(xs_linear)
center = 8.86
shift = center - round(center)
width = 13.26 * 0.74  # FW * ratio
xs_shifted = xs_linear + shift
plt.plot(xs, array, marker='^', label="Original Profile")
# plt.plot(xs_linear, array_linear, marker='o', label="Interpolated Profile", linestyle="None")
array_shifted = y_interp(xs_shifted)
plt.plot(xs_shifted, array_shifted, marker='x', label="Shifted Profile", linestyle='None')
plt.axvline(x=center, color='r', linestyle='--', label="Beam center")
plt.axvline(x=center-width/2, color='g', linestyle='--', label="Left In-Field Edge")
plt.axvline(x=center+width/2, color='g', linestyle='--', label="Right In-Field Edge")
plt.legend()
plt.grid(True)
plt.show()