-
Notifications
You must be signed in to change notification settings - Fork 6
Implement MPIFFT2D and MPIFFTND #195
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
Open
rohanbabbar04
wants to merge
12
commits into
PyLops:main
Choose a base branch
from
rohanbabbar04:fft
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1ebf46d
Implement MPIFFT2D and MPIFFTND
rohanbabbar04 074489c
Update GA to include fftw libraries
rohanbabbar04 a7743ca
Fallback to dims if dimsd does not exist
rohanbabbar04 13d35a8
Add __truediv__
rohanbabbar04 de364da
Add example and fftshifts
rohanbabbar04 bcdd74f
Add FFTND and FFT2D to docs
rohanbabbar04 c3253de
Use assert_array_allmost_equal and minor changes
rohanbabbar04 7b7e892
Add optional dependencies and update code for self.real
rohanbabbar04 f87b5b7
Add scale_real_fft and set subcomm_axis=0
rohanbabbar04 4d76502
Update documentation
rohanbabbar04 d78311b
Minor change in plot_ffts.py
rohanbabbar04 887dad6
Update notes section
rohanbabbar04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
mrava87 marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,5 +21,6 @@ dependencies: | |
| - nbsphinx | ||
| - pydata-sphinx-theme | ||
| - flake8 | ||
| - mpi4py-fft | ||
| - pip: | ||
| - sphinx-gallery | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| """ | ||
| Fourier Transform | ||
| ================= | ||
| This example shows how to use the :py:class:`pylops_mpi.signalprocessing.MPIFFT2D` | ||
| and :py:class:`pylops_mpi.signalprocessing.MPIFFTND` operators to apply the Fourier | ||
| Transform to the model and the inverse Fourier Transform to the data. | ||
| """ | ||
|
|
||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
|
|
||
| import pylops_mpi | ||
|
|
||
| plt.close("all") | ||
|
|
||
| ############################################################################### | ||
| # We start by applying the two dimensional MPI-distributed FFT to a | ||
| # two-dimensional signal using :py:class:`pylops_mpi.signalprocessing.MPIFFT2D`. | ||
| # The input signal is a :py:class:`pylops_mpi.DistributedArray` which is | ||
| # distributed across MPI ranks before applying the transform. | ||
|
|
||
| dt, dx = 0.005, 5 | ||
| nt, nx = 2**7, 2**8 | ||
| t = np.arange(nt) * dt | ||
| x = np.arange(nx) * dx | ||
| f0 = 10 | ||
|
|
||
| d = np.outer(np.sin(2 * np.pi * f0 * t), np.arange(nx) + 1) | ||
| dist = pylops_mpi.DistributedArray.to_dist(x=d.ravel()) | ||
|
mrava87 marked this conversation as resolved.
|
||
|
|
||
| FFTop = pylops_mpi.signalprocessing.MPIFFT2D( | ||
| dims=(nt, nx), sampling=(dt, dx) | ||
| ) | ||
|
|
||
| D = FFTop * dist | ||
|
|
||
| dinv = FFTop.H * D | ||
| dinv = np.real(dinv.asarray()).reshape(nt, nx) | ||
|
|
||
| D_2d = D.asarray().reshape(nt, nx) | ||
|
|
||
| fig, axs = plt.subplots(2, 2, figsize=(10, 6)) | ||
|
|
||
| axs[0][0].imshow(d, vmin=-100, vmax=100, cmap="bwr") | ||
| axs[0][0].set_title("Signal") | ||
| axs[0][0].axis("tight") | ||
|
|
||
| axs[0][1].imshow( | ||
| np.abs(np.fft.fftshift(D_2d, axes=1)[:nt // 2, :]), cmap="bwr" | ||
| ) | ||
| axs[0][1].set_title("Fourier Transform") | ||
| axs[0][1].axis("tight") | ||
|
|
||
| axs[1][0].imshow(dinv, vmin=-100, vmax=100, cmap="bwr") | ||
| axs[1][0].set_title("Inverted") | ||
| axs[1][0].axis("tight") | ||
|
|
||
| axs[1][1].imshow(d - dinv, vmin=-100, vmax=100, cmap="bwr") | ||
| axs[1][1].set_title("Error") | ||
| axs[1][1].axis("tight") | ||
|
|
||
| fig.tight_layout() | ||
|
|
||
| ############################################################################### | ||
| # We can also apply the three dimensional MPI-distributed FFT to a | ||
| # three-dimensional signal using :py:class:`pylops_mpi.signalprocessing.MPIFFTND`. | ||
|
|
||
| dt, dx, dy = 0.005, 5, 3 | ||
| nt, nx, ny = 2**7, 2**6, 13 | ||
| t = np.arange(nt) * dt | ||
| x = np.arange(nx) * dx | ||
| y = np.arange(ny) * dy | ||
| f0 = 10 | ||
|
|
||
| d = np.outer(np.sin(2 * np.pi * f0 * t), np.arange(nx) + 1) | ||
| d = np.tile(d[:, :, np.newaxis], [1, 1, ny]) | ||
| dist = pylops_mpi.DistributedArray.to_dist(x=d.ravel()) | ||
|
|
||
| FFTop = pylops_mpi.signalprocessing.MPIFFTND( | ||
| dims=(nt, nx, ny), | ||
| sampling=(dt, dx, dy) | ||
| ) | ||
|
|
||
| D = FFTop * dist | ||
| dinv = FFTop.H * D | ||
| dinv = np.real(dinv.asarray()).reshape(nt, nx, ny) | ||
| D_3d = D.asarray().reshape(nt, nx, ny) # shape matches dims now | ||
|
|
||
| fig, axs = plt.subplots(2, 2, figsize=(10, 6)) | ||
|
|
||
| axs[0][0].imshow(d[:, :, ny // 2], vmin=-20, vmax=20, cmap="bwr") | ||
| axs[0][0].set_title("Signal") | ||
| axs[0][0].axis("tight") | ||
| axs[0][1].imshow( | ||
| np.abs(np.fft.fftshift(D_3d, axes=1)[:nx // 2, :, ny // 2]), | ||
| cmap="bwr" | ||
| ) | ||
| axs[0][1].set_title("Fourier Transform") | ||
| axs[0][1].axis("tight") | ||
|
|
||
| axs[1][0].imshow(dinv[:, :, ny // 2], vmin=-20, vmax=20, cmap="bwr") | ||
| axs[1][0].set_title("Inverted") | ||
| axs[1][0].axis("tight") | ||
|
|
||
| axs[1][1].imshow(d[:, :, ny // 2] - dinv[:, :, ny // 2], vmin=-20, vmax=20, cmap="bwr") | ||
| axs[1][1].set_title("Error") | ||
| axs[1][1].axis("tight") | ||
|
|
||
| fig.tight_layout() | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.