From 076eab0d8c7b6d06135b14ae22fe76bf5bc98c37 Mon Sep 17 00:00:00 2001 From: mrava87 Date: Wed, 29 Dec 2021 02:27:50 +0300 Subject: [PATCH 1/5] Fix bug in FFT with fftw backend for 1d signals Modified handling of 1d signals in _FFT_fftw which led to an error when passing a single number (of int type) for the dims parameter. --- pylops/signalprocessing/FFT.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pylops/signalprocessing/FFT.py b/pylops/signalprocessing/FFT.py index fe2f733f..a83a4a24 100644 --- a/pylops/signalprocessing/FFT.py +++ b/pylops/signalprocessing/FFT.py @@ -75,7 +75,9 @@ def __init__( if self.fftshift_after: if self.real: warnings.warn( - "Using fftshift_after with real=True. fftshift should only be applied after a complex FFT. This is rarely intended behavior but if it is, ignore this message." + "Using fftshift_after with real=True. fftshift should only be " + "applied after a complex FFT. This is rarely intended behavior " + "but if it is, ignore this message." ) self.f = np.fft.fftshift(self.f) @@ -236,8 +238,10 @@ def __init__( fftshift_after, dtype, ) - if len(dims) == 1: - self.dims = np.array((dims[0],)) + if isinstance(dims, int) or len(dims) == 1: + self.dims = ( + np.array((dims,)) if isinstance(dims, int) else np.array((dims[0],)) + ) self.dims_t = self.dims.copy() self.dims_t[self.dir] = self.nfft self.dims_fft = self.dims.copy() From 3b36ed8b5b34097acd94291c81fb45efb9516f69 Mon Sep 17 00:00:00 2001 From: mrava87 Date: Wed, 29 Dec 2021 02:36:15 +0300 Subject: [PATCH 2/5] Fix bug in Radon2D and Radon3D with centered spatial axes This fixes a bug recently introduced when changing the way spatial axes are handled internally. When choosing centeredh=True, we have now reverted back to creating a brand new axis that is centered instead of using the passed axis. --- pylops/signalprocessing/Radon2D.py | 18 +++++++----------- pylops/signalprocessing/Radon3D.py | 22 +++++++++------------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/pylops/signalprocessing/Radon2D.py b/pylops/signalprocessing/Radon2D.py index 0a2a5f80..6ceccddb 100644 --- a/pylops/signalprocessing/Radon2D.py +++ b/pylops/signalprocessing/Radon2D.py @@ -7,14 +7,9 @@ try: from numba import jit - from ._Radon2D_numba import ( - _create_table_numba, - _hyperbolic_numba, - _indices_2d_numba, - _indices_2d_onthefly_numba, - _linear_numba, - _parabolic_numba, - ) + from ._Radon2D_numba import (_create_table_numba, _hyperbolic_numba, + _indices_2d_numba, _indices_2d_onthefly_numba, + _linear_numba, _parabolic_numba) except ModuleNotFoundError: jit = None @@ -225,9 +220,10 @@ def Radon2D( dh, dt = np.abs(haxis[1] - haxis[0]), np.abs(taxis[1] - taxis[0]) dpx = dh / dt pxaxis = pxaxis * dpx - haxisunitless = haxis // dh - if centeredh: - haxisunitless -= nh // 2 + if not centeredh: + haxisunitless = haxis // dh + else: + haxisunitless = np.arange(nh) - nh // 2 dims = (npx, nt) dimsd = (nh, nt) diff --git a/pylops/signalprocessing/Radon3D.py b/pylops/signalprocessing/Radon3D.py index c3c78714..ee69fbb0 100644 --- a/pylops/signalprocessing/Radon3D.py +++ b/pylops/signalprocessing/Radon3D.py @@ -7,14 +7,9 @@ try: from numba import jit - from ._Radon3D_numba import ( - _create_table_numba, - _hyperbolic_numba, - _indices_3d_numba, - _indices_3d_onthefly_numba, - _linear_numba, - _parabolic_numba, - ) + from ._Radon3D_numba import (_create_table_numba, _hyperbolic_numba, + _indices_3d_numba, _indices_3d_onthefly_numba, + _linear_numba, _parabolic_numba) except ModuleNotFoundError: jit = None @@ -236,13 +231,14 @@ def Radon3D( dt = np.abs(taxis[1] - taxis[0]) dpy = dhy / dt pyaxis = pyaxis * dpy - hyaxisunitless = hyaxis // dhy dpx = dhx / dt pxaxis = pxaxis * dpx - hxaxisunitless = hxaxis // dhx - if centeredh: - hyaxisunitless -= nhy // 2 - hxaxisunitless -= nhx // 2 + if not centeredh: + hyaxisunitless = hyaxis // dhy + hxaxisunitless = hxaxis // dhx + else: + hyaxisunitless = np.arange(nhy) - nhy // 2 + hxaxisunitless = np.arange(nhx) - nhx // 2 # create grid for py and px axis hyaxisunitless, hxaxisunitless = np.meshgrid( From 295c6525de865697c6aec56b7fadb22f7dc12470 Mon Sep 17 00:00:00 2001 From: Carlos da Costa Date: Tue, 28 Dec 2021 22:48:04 -0500 Subject: [PATCH 3/5] Use the black profile for isort This change avoids conflicts between black and isort. --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f464cf74..23bfc594 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,3 +19,4 @@ repos: hooks: - id: isort name: isort (python) + args: ["--profile", "black", "--filter-files", "--line-length=88"] From 9ce712f25252f7167b1ac5e5a974819a730dc99f Mon Sep 17 00:00:00 2001 From: mrava87 Date: Wed, 29 Dec 2021 12:43:56 +0300 Subject: [PATCH 4/5] Change LineWidth to lw in all examples and tutorials This change is required to be able to build the documentation locally using py3.9. Eventually we will also boost the python version on RTD. --- examples/plot_causalintegration.py | 24 ++++++++++++------------ tutorials/solvers.py | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/plot_causalintegration.py b/examples/plot_causalintegration.py index 2320e1fc..902409be 100755 --- a/examples/plot_causalintegration.py +++ b/examples/plot_causalintegration.py @@ -87,14 +87,14 @@ # Visualize data and inversion fig, axs = plt.subplots(1, 2, figsize=(18, 5)) -axs[0].plot(t, y, "k", LineWidth=3, label="data") -axs[0].plot(t, yn, "--g", LineWidth=3, label="noisy data") +axs[0].plot(t, y, "k", lw=3, label="data") +axs[0].plot(t, yn, "--g", lw=3, label="noisy data") axs[0].legend() axs[0].set_title("Causal integration") -axs[1].plot(t, x, "k", LineWidth=8, label="original") -axs[1].plot(t[1:-1], xder[1:-1], "r", LineWidth=3, label="numerical derivative") -axs[1].plot(t, xreg, "g", LineWidth=3, label="regularized") -axs[1].plot(t, xp, "m", LineWidth=3, label="preconditioned") +axs[1].plot(t, x, "k", lw=8, label="original") +axs[1].plot(t[1:-1], xder[1:-1], "r", lw=3, label="numerical derivative") +axs[1].plot(t, xreg, "g", lw=3, label="regularized") +axs[1].plot(t, xp, "m", lw=3, label="preconditioned") axs[1].legend() axs[1].set_title("Inverse causal integration") @@ -163,13 +163,13 @@ # Visualize data and inversion at a chosen xlocation fig, axs = plt.subplots(1, 2, figsize=(18, 5)) -axs[0].plot(t, y[:, nx // 2], "k", LineWidth=3, label="data") -axs[0].plot(t, yn[:, nx // 2], "--g", LineWidth=3, label="noisy data") +axs[0].plot(t, y[:, nx // 2], "k", lw=3, label="data") +axs[0].plot(t, yn[:, nx // 2], "--g", lw=3, label="noisy data") axs[0].legend() axs[0].set_title("Causal integration") -axs[1].plot(t, x[:, nx // 2], "k", LineWidth=8, label="original") -axs[1].plot(t, xder[:, nx // 2], "r", LineWidth=3, label="numerical derivative") -axs[1].plot(t, xreg[:, nx // 2], "g", LineWidth=3, label="regularized") -axs[1].plot(t, xp[:, nx // 2], "m", LineWidth=3, label="preconditioned") +axs[1].plot(t, x[:, nx // 2], "k", lw=8, label="original") +axs[1].plot(t, xder[:, nx // 2], "r", lw=3, label="numerical derivative") +axs[1].plot(t, xreg[:, nx // 2], "g", lw=3, label="regularized") +axs[1].plot(t, xp[:, nx // 2], "m", lw=3, label="preconditioned") axs[1].legend() axs[1].set_title("Inverse causal integration") diff --git a/tutorials/solvers.py b/tutorials/solvers.py index 127cbf88..79b83947 100755 --- a/tutorials/solvers.py +++ b/tutorials/solvers.py @@ -62,10 +62,10 @@ x = FFTop.H * X fig, axs = plt.subplots(2, 1, figsize=(12, 8)) -axs[0].plot(f, np.abs(X), "k", LineWidth=2) +axs[0].plot(f, np.abs(X), "k", lw=2) axs[0].set_xlim(0, 30) axs[0].set_title("Data(frequency domain)") -axs[1].plot(t, x, "k", LineWidth=2) +axs[1].plot(t, x, "k", lw=2) axs[1].set_title("Data(time domain)") axs[1].axis("tight") From 7771fa8a76d1bcc4d382b3f9ea32788cf5133a4d Mon Sep 17 00:00:00 2001 From: mrava87 Date: Wed, 29 Dec 2021 13:06:35 +0300 Subject: [PATCH 5/5] Added installation instructions for pre-commit --- docs/source/installation.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/source/installation.rst b/docs/source/installation.rst index b0e43a0f..9cae6eeb 100755 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -139,6 +139,19 @@ To ensure that everything has been setup correctly, run tests: Make sure no tests fail, this guarantees that the installation has been successfull. +Finally, to ensure consistency in the coding style of our developers we rely on +`pre-commit `_ to perform a series of checks when you are +ready to commit and push some changes. This is accomplished by means of git hooks +that have been configured in the ``.pre-commit-config.yaml`` file. + +In order to setup such hooks in your local repository, run: + +.. code-block:: bash + + >> pre-commit install + +Later on, ``pre-commit`` will automatically run for you and propose additional stylistic changes to your commits. + If using Conda environment, always remember to activate the conda environment every time you open a new *bash* shell by typing: