Using the Kramers-Kronig (Hilbert) transform in Python

I am trying to use the Kramers-Kronig algorithm to transform the real and imaginary contributions to the anomalous scattering factor from a diffraction anomalous fine structure (DAFS) experiment.

I have fit a smooth curve to my experimental data using the lmfit package, and the following function:

def intensity(en, phi, beta, I0=1, slope=0, Ioff=0, fprime=-1, fsec=1):
costerm = np.cos(phi) + beta*fprime
sinterm = np.sin(phi) + beta*fsec
return I0 * (costerm**2 + sinterm**2) + slope*en + Ioff


I have found minimised values of the listed parameters in the function and used them to calculate an initial guess for f' according to:

def f1_guess(f2, I, I0, phi, beta, Ioff):
f1_guess = (1/beta) * (np.sqrt(((I-Ioff)/I0) - (math.sin(phi)+(beta*f2))) - math.cos(phi))
return f1_guess


I am now trying to use the Kramers-Kronig relation to transform this initial f' guess to an f" that can then be put back into the lmfit process to model the intensity, and subsequently calculate the fine structure. I have tried a few things, including the scipy.fftpack, as well as the scipy.integrate and sympy.integrate packages.

The issue I am facing is that I need to calculate the KK transform over a finite energy range, I.E. instead of the following:

I should do something more like the function below, by taking out the known atomic lineshape f"a(E) and integrating over my experimental energy range:

However, I am struggling to distinguish between E' and E (or omega' and omega) - I don't know how they are different from each other - and so I am unsure of how to specify these values in script format in such a way that I can accurately evaluate this integral.

Does anyone know how I might be able to transfer my f' to f", and iterate through my lmfit model until the 4 parameters (I0, Ioff, beta, phi) and the f"/f' fine structure functions stabilise?

Any help would be much appreciated, and also happy to link any relevant papers I have been reading on the topic if desired.