def test_nufft_ndft(self): n = 5 w = np.exp(-1j * 2 * np.pi / n) coord = np.array([[-2], [0], [0.1]]) w2 = w**-2 w1 = w**0.1 A = np.array([[w2**-2, w2**-1, 1, w2, w2**2], [1, 1, 1, 1, 1], [w1**-2, w1**-1, 1, w1, w1**2]]) / n**0.5 for i in range(n): input = np.zeros(n, np.complex) input[i] = 1 npt.assert_allclose(A[:, i], fourier.nufft(input, coord), atol=0.01, rtol=0.01) n = 6 w = np.exp(-1j * 2 * np.pi / n) coord = np.array([[-2], [0], [0.1]]) w2 = w**-2 w1 = w**0.1 A = np.array([[w2**-3, w2**-2, w2**-1, 1, w2, w2**2], [ 1, 1, 1, 1, 1, 1 ], [w1**-3, w1**-2, w1**-1, 1, w1, w1**2]]) / n**0.5 for i in range(n): input = np.zeros(n, np.complex) input[i] = 1 npt.assert_allclose(A[:, i], fourier.nufft(input, coord), atol=0.01, rtol=0.01)
def test_nufft(self): # Check deltas ishape = [3] input = np.array([0, 1, 0], np.complex) # delta coord = np.array([[-1], [0], [1]], np.float) npt.assert_allclose(fourier.nufft(input, coord), np.array([1.0, 1.0, 1.0]) / (3**0.5), atol=0.01, rtol=0.01) ishape = [4] input = np.array([0, 0, 1, 0], np.complex) # delta coord = np.array([[-2], [-1], [0], [1]], np.float) npt.assert_allclose(fourier.nufft(input, coord), np.array([1.0, 1.0, 1.0, 1.0]) / (4**0.5), atol=0.01, rtol=0.01) ishape = [5] input = np.array([0, 0, 1, 0, 0], np.complex) # delta coord = np.array([[-2], [-1], [0], [1], [2]], np.float) npt.assert_allclose(fourier.nufft(input, coord), np.ones(5) / (5**0.5), atol=0.01, rtol=0.01) # Check shifted delta ishape = [3] input = np.array([0, 0, 1], np.complex) # shifted delta coord = np.array([[-1], [0], [1]], np.float) w = np.exp(-1j * 2.0 * np.pi / 3.0) npt.assert_allclose(fourier.nufft(input, coord), np.array([w.conjugate(), 1.0, w]) / (3**0.5), atol=0.01, rtol=0.01) ishape = [4] input = np.array([0, 0, 0, 1], np.complex) # delta coord = np.array([[-2], [-1], [0], [1]], np.float) w = np.exp(-1j * 2.0 * np.pi / 4.0) npt.assert_allclose(fourier.nufft(input, coord), np.array([w.conjugate()**2, w.conjugate(), 1.0, w]) / (4**0.5), atol=0.01, rtol=0.01)
def _apply(self, input): return fourier.nufft(input, self.coord, oversamp=self.oversamp, width=self.width, n=self.n)
def _apply(self, input): device = backend.get_device(input) with device: coord = backend.to_device(self.coord, device) return fourier.nufft( input, coord, oversamp=self.oversamp, width=self.width)
def test_nufft_nd(self): for ndim in range(3): input = np.array([[0], [1], [0]], np.complex) coord = np.array([[-1, 0], [0, 0], [1, 0]], np.float) npt.assert_allclose(fourier.nufft(input, coord), np.array([1.0, 1.0, 1.0]) / 3**0.5, atol=0.01, rtol=0.01)
def test_nufft_normal(self): # Check delta oshape = [3] input = np.array([0.0, 1.0, 0.0], dtype=np.complex) coord = np.array([[-1], [0], [1]], np.float) npt.assert_allclose(fourier.nufft_adjoint(fourier.nufft(input, coord), coord, oshape), np.array([0, 1, 0]), atol=0.01, rtol=0.01) # Check delta scale oshape = [3] input = np.array([0.0, 1.0, 0.0], dtype=np.complex) coord = np.array([[-1], [-0.5], [0], [0.5], [1]], np.float) npt.assert_allclose(fourier.nufft_adjoint(fourier.nufft(input, coord), coord, oshape)[len(input) // 2], 5 / 3, atol=0.01, rtol=0.01)