Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question about fourier transform #103

Open
dragonyanglong opened this issue May 21, 2024 · 3 comments
Open

question about fourier transform #103

dragonyanglong opened this issue May 21, 2024 · 3 comments

Comments

@dragonyanglong
Copy link

Dear @rayosborn , while using nexpy for 3D-dPDF analysis, I have a question about the fourier transform applied in the nxreduce step.

https://github.com/rayosborn/nxrefine/blob/6de6d28a3f63bd95ae7d67c58f455cae0e233d04/src/nxrefine/nxreduce.py#L2230

        fft = np.real(scipy.fft.fftshift(
            scipy.fft.fftn(scipy.fft.fftshift(symm_data[:-1, :-1, :-1]),
                           workers=self.process_count)))

Question 1: why the last slice of data is cropped? symm_data[:-1, :-1, :-1] instead of symm_data?

Question 2: why using fftshift twice? I thought we usually use scipy.fft.ifftshift(scipy.fft.fftn(scipy.fft.fftshift))?
I made some quick tests, and the following sequences give different results, which one would be correct?

  • scipy.fft.fftshift(scipy.fft.fftn(scipy.fft.fftshift(data)))
  • scipy.fft.ifftshift(scipy.fft.fftn(scipy.fft.ifftshift(data)))
  • scipy.fft.ifftshift(scipy.fft.fftn(scipy.fft.fftshift(data)))
  • scipy.fft.fftshift(scipy.fft.fftn(scipy.fft.ifftshift(data)))

Thanks!

@krogstad
Copy link
Collaborator

krogstad commented May 21, 2024 via email

@dragonyanglong
Copy link
Author

dragonyanglong commented May 23, 2024

Dear Matt,

Thanks so much for your detailed response. I did some further testing. I use the real experimental data collected at beamline, and tested even/odd and fftshift/iffshit. The result is attached. We found that:

When the input data shape is even number like (200, 200, 200), the results of fftshift(fftn(fftshift(data)))) and fftshift(fftn(ifftshift(data)))) are the same.
When the input data shape are odd numbers like (201, 201, 201), the results are different.

I think we usually do shift and inverse shift together when implementing Fourier transform, but here in nxreduce, we do shift twice, no inverse shift. So that's why I opened this issue.

Thanks Matt.

Best,
Long

image

@krogstad
Copy link
Collaborator

krogstad commented May 23, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants