mrbell / gfft

A generalized FFT for Python that is able to handle data that is defined on an irregular grid.
mrbell.github.com/gfft
GNU General Public License v3.0
13 stars 8 forks source link

Need help on using gfft correctly ... #7

Open mreineck opened 7 years ago

mreineck commented 7 years ago

I can't seem to figure out how gfft is used correctly...

The attached test case has a regular 1D grid with ngrid points; the irregular grid is constructed to be exactly equivalent. Now I loop over all points of the irregular grid, setting point i to 1 and all others to 0, perform an irregular-to-regular gfft, then a regular-to-irregular gfft and plot the absolute value of the resulting array.

I would expect the resulting curves to be identical, except for a shift, and each of them should have a mirror symmetry as well. However that doesn't seem to be the case.

Are my assumptions incorrect, or am I using the library incorrectly?

import numpy as np
import gfft
import matplotlib.pyplot as plt

# number of grid points on both grids
ngrid = 12

# coordinates for the irregular grid
x = np.arange(ngrid*1.)/ngrid - 0.5

# build gfft input
points = [x]
grid = [(1.,ngrid)]

for i in range (0,ngrid):
    # create input array with the ith value set to 1, the rest being zero
    val = np.zeros(ngrid,dtype=np.complex128)
    val[i]=1.
    # I2R transform
    tmp = gfft.gfft(val, points, grid, ftmachine='ifft')
    # R2I transform
    tmp2 = gfft.gfft(tmp, grid, points, ftmachine='fft')
    # plot the absolute value of the result
    plt.plot(np.abs(tmp2))

plt.show()
mselig commented 7 years ago

@mreineck i guess you are right ... at least i cannot see the flaw (1) you should contact @henrikju and/or @mrbell directly (the email on his profile seems accurate) (2) running it with verbose=True might shed some light on the issue as well