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: 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/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() diff --git a/pylops/signalprocessing/Radon2D.py b/pylops/signalprocessing/Radon2D.py index 40748d3f..1f5219fc 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 ed55a573..97f668d3 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( 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")