Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always fftshift+iffshift for Fraunhofer propagation #658

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions poppy/accel_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def fft_2d(wavefront, forward=True, normalization=None, fftshift=True):
_log.debug("using {2} FFT of {0} array, FFT_direction={1}".format(
str(wavefront.shape), 'forward' if forward else 'backward', method))

if (forward) and fftshift: # shift before backwards propagations (using forward FFT)
if fftshift: # shift before backwards propagations (using forward FFT)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very very minor: It would be nice to also update the comment text here to "shift before all propagations" instead of "shift before backwards propagations"

# This needs to be an ifftshift, for machine-precision equivalence to MFT
# as tested by test_MFT_FFT_equivalence_in_OpticalSystem; ifftshift and fftshift are
# precisely equivalent for even-sized arrays but differ by 1 pixel offset for odd-sized
Expand Down Expand Up @@ -287,7 +287,7 @@ def fft_2d(wavefront, forward=True, normalization=None, fftshift=True):
wavefront = do_fft(wavefront)
t2 = time.time()

if (not forward) and fftshift: # shift after forwards propagations (using inverse FFT)
if fftshift: # shift after forwards propagations (using inverse FFT)
# This needs to be a fftshift here, since we use ifftshift above
# See comment above in this function.
wavefront = _fftshift(wavefront)
Expand Down
5 changes: 5 additions & 0 deletions poppy/tests/test_matrixDFT.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,5 +695,10 @@ def test_MFT_FFT_equivalence_in_OpticalSystem(tmpdir, display=False, source_offs
poppy.display_psf_difference(fftpsf, mftpsf, title='Diff FFT-MFT')


# difference of intensities
absdiff = np.abs(np.asarray(mftpsf[0].data - fftpsf[0].data)) # Extra asarray helps with optional GPU support
assert(np.all(absdiff < 1e-10))

# absolute value of difference of complex fields
absdiff_c = np.abs(np.asarray(mftplanes[-1].wavefront - fftplanes[-1].wavefront))
assert(np.all(absdiff_c < 1e-10))