Skip to content

Commit

Permalink
Add fft equivalence test
Browse files Browse the repository at this point in the history
  • Loading branch information
samaloney committed May 14, 2024
1 parent 0fa5e1c commit d18d6f6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/58.breaking.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Optional parameters are now keyword only for the :mod:`xrayvision.transform`, :mod:`xrayvision.imaging` and :mod:`xrayvision.visibility` modules.
Remove ``natural`` keyword in favour of ``scheme`` keyword which can be either 'natural' or 'uniform'.
32 changes: 31 additions & 1 deletion xrayvision/tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import numpy as np
import pytest
from astropy.convolution import Gaussian2DKernel
from numpy.testing import assert_allclose, assert_array_equal
from numpy.fft import fft2, fftshift, ifft2, ifftshift
from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_equal
from scipy import signal

from xrayvision.transform import dft_map, generate_uv, generate_xy, idft_map
Expand Down Expand Up @@ -361,3 +362,32 @@ def test_phase_centre_equivalence():
img2 = idft_map(vis_shifted, u=u, v=v, weights=1/u.size, pixel_size=[1, 1] * apu.arcsec/apu.pix,
shape=data.shape*apu.pix, phase_centre=[5, 5]*apu.arcsec)
assert np.allclose(data, img2)


def test_fft_equivalence():
# chose so xy values run from 0 to 2 the same as in fft
shape = (3, 3)
pixel = (1, 1)
center = (1, 1)

data = np.arange(np.prod(shape)).reshape(shape)
uu = generate_uv(shape[0] * apu.pix, phase_centre=center[0] * apu.arcsec,
pixel_size=pixel[0] * apu.arcsec / apu.pix)
vv = generate_uv(shape[1] * apu.pix, phase_centre=center[1] * apu.arcsec,
pixel_size=pixel[1] * apu.arcsec / apu.pix)
u, v = np.meshgrid(uu, vv, indexing='ij')
u = u.flatten()
v = v.flatten()

vis = dft_map(data, u=u, v=v, pixel_size=pixel * apu.arcsec / apu.pix, phase_centre=center * apu.arcsec)

ft = fft2(data)
fts = fftshift(ft)
vis = vis.reshape(3, 3)
# Convention in xrayvison has the minus sign on the forward transform but numpy has it on reverse
vis_conj = np.conjugate(vis)
assert_array_almost_equal(fts, vis_conj)

vis_ft = ifftshift(vis_conj)
img = ifft2(vis_ft)
assert_array_almost_equal(np.real(img), data)

0 comments on commit d18d6f6

Please sign in to comment.