diff --git a/poppy/accel_math.py b/poppy/accel_math.py index 78346893..ff6d8ebf 100644 --- a/poppy/accel_math.py +++ b/poppy/accel_math.py @@ -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) # 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 @@ -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) diff --git a/poppy/tests/test_matrixDFT.py b/poppy/tests/test_matrixDFT.py index db016d88..f1da3a82 100644 --- a/poppy/tests/test_matrixDFT.py +++ b/poppy/tests/test_matrixDFT.py @@ -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))