opticspy / lightpipes

LightPipes for Python, "Pure Python version"
https://opticspy.github.io/lightpipes/
BSD 3-Clause "New" or "Revised" License
227 stars 52 forks source link

LensFarfield in lenses.py but not in __init__.py and documentation #75

Open kicklop opened 1 year ago

kicklop commented 1 year ago

I found a function LensFarfield in lenses.py, but I got the error NameError: name 'LensFarfield' is not defined, when I tried to call it. It also is not in the documentation.

I added LensFarfield into the all list in init.py and was able to call the function.

FredvanGoor commented 1 year ago

This command is still in a development state. That is why it is not available. Please check for correctness and report.

kicklop commented 1 year ago

I checked the LensFarfield function against Goodman's Introduction to Fourier Optics, where the equation for field propagate to the focal plane of the lens is this: $Uf(u, v)= \frac{\exp \left[j \frac{k}{2 f}\left(u^2+v^2\right)\right]}{j \lambda f} \times \int{-\infty}^{\infty} \int_{-\infty}^{\infty} U_l(x, y) \exp \left[-j \frac{2 \pi}{\lambda f}(x u+y v)\right] d x d y.$

The scaling of the size of the Field in the LensFarfield function is correct. However, element in front of the Fourier transform is omitted.

EDIT: The field should also be ifftshifted before doing fft2. EDIT2: Missed constant phase factor (exp(jkf))

The function should look like this:

def LensFarfield(Fin, f ):
    Fout = Field.copy(Fin)
    dx = Fout.dx
    lam = Fout.lam
    L_prime = lam * f / dx
    focusfield = _np.fft.fftshift(_np.fft.fft2(_np.fft.ifftshift(Fout.field))) #added ifftshift
    Fout.field = focusfield / (1j*lam*f) *  _np.exp(1j*k*f) #changed line
    Fout.siz = L_prime
    Fout = Lens(Fout, -f) #new line
    Fout._IsGauss=False
    return Fout