Skip to content

Commit 10c59b6

Browse files
author
Eoghan O'Connell
committed
tests: ensure old and new uses of fft algorithms are consistent
1 parent da0f046 commit 10c59b6

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

tests/test_fourier_base.py

+32-1
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,44 @@ def test_scale_to_filter_qlsi():
183183
assert np.allclose(phase_scaled.mean(), 0.1257080793074251, atol=1e-6)
184184

185185

186+
def test_fft_dimensionality_consistency():
187+
"""Compare using fft algorithms on 2d and 3d data."""
188+
image_3d = np.arange(1000).reshape(10, 10, 10)
189+
image_2d = image_3d[0].copy()
190+
191+
# fft with shift
192+
fft_3d = np.fft.fftshift(np.fft.fft2(image_3d, axes=(-2, -1)),
193+
axes=(-2, -1))
194+
fft_2d = np.fft.fftshift(np.fft.fft2(image_2d)) # old qpretrieve
195+
assert fft_3d.shape == (10, 10, 10)
196+
assert fft_2d.shape == (10, 10)
197+
assert np.allclose(fft_3d[0], fft_2d, rtol=0, atol=1e-8)
198+
199+
# ifftshift
200+
fft_3d_shifted = np.fft.ifftshift(fft_3d, axes=(-2, -1))
201+
fft_2d_shifted = np.fft.ifftshift(fft_2d) # old qpretrieve
202+
assert fft_3d_shifted.shape == (10, 10, 10)
203+
assert fft_2d_shifted.shape == (10, 10)
204+
assert np.allclose(fft_3d_shifted[0], fft_2d_shifted, rtol=0, atol=1e-8)
205+
206+
# ifft
207+
ifft_3d_shifted = np.fft.ifft2(fft_3d_shifted, axes=(-2, -1))
208+
ifft_2d_shifted = np.fft.ifft2(fft_2d_shifted) # old qpretrieve
209+
assert ifft_3d_shifted.shape == (10, 10, 10)
210+
assert ifft_2d_shifted.shape == (10, 10)
211+
assert np.allclose(ifft_3d_shifted[0], ifft_2d_shifted, rtol=0, atol=1e-8)
212+
213+
assert np.allclose(ifft_3d_shifted.real, image_3d, rtol=0, atol=1e-8)
214+
assert np.allclose(ifft_2d_shifted.real, image_2d, rtol=0, atol=1e-8)
215+
216+
186217
def test_fft_comparison_FFTFilter():
187218
image = np.arange(1000).reshape(10, 10, 10)
188219
ff_np = fourier.FFTFilterNumpy(image, subtract_mean=False, padding=False)
189220
ff_tw = fourier.FFTFilterPyFFTW(image, subtract_mean=False, padding=False)
190221
assert ff_np.fft_origin.shape == ff_tw.fft_origin.shape == (10, 10, 10)
191222

192-
assert np.allclose(ff_np.fft_origin, ff_np.fft_origin, rtol=0, atol=1e-8)
223+
assert np.allclose(ff_np.fft_origin, ff_tw.fft_origin, rtol=0, atol=1e-8)
193224
assert np.allclose(
194225
np.fft.ifft2(np.fft.ifftshift(ff_np.fft_origin, axes=(-2, -1))).real,
195226
np.fft.ifft2(np.fft.ifftshift(ff_tw.fft_origin, axes=(-2, -1))).real,

0 commit comments

Comments
 (0)