From 5a43e2ca42e90e875a0ffc18836febb2cf7d799a Mon Sep 17 00:00:00 2001 From: cako Date: Tue, 28 Dec 2021 22:42:23 -0500 Subject: [PATCH 1/2] Reduce warnings considerably --- .pre-commit-config.yaml | 14 +++++++++----- examples/plot_derivative.py | 4 ++-- examples/plot_tvreg.py | 6 +++--- pylops/basicoperators/BlockDiag.py | 4 ++-- pylops/basicoperators/HStack.py | 2 +- pylops/basicoperators/MatrixMult.py | 2 +- pylops/basicoperators/Restriction.py | 2 +- pylops/basicoperators/Spread.py | 4 ++-- pylops/basicoperators/Sum.py | 2 +- pylops/basicoperators/Transpose.py | 6 +++--- pylops/basicoperators/VStack.py | 2 +- pylops/signalprocessing/Bilinear.py | 18 ++++++++++++------ pylops/signalprocessing/ConvolveND.py | 6 +++--- pylops/signalprocessing/Interp.py | 8 ++++---- pylops/signalprocessing/Radon2D.py | 2 +- pylops/signalprocessing/Radon3D.py | 2 +- pylops/signalprocessing/Sliding2D.py | 2 +- pylops/waveeqprocessing/marchenko.py | 4 ++-- pylops/waveeqprocessing/mdd.py | 14 ++++++++++++-- pytests/test_linearoperator.py | 4 ++-- tutorials/ctscan.py | 6 +++--- tutorials/deghosting.py | 2 +- tutorials/realcomplex.py | 2 +- tutorials/wavefielddecomposition.py | 2 +- 24 files changed, 70 insertions(+), 50 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f464cf74..a6d6f8ff 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,9 +13,13 @@ repos: - id: black args: # arguments to configure black - --line-length=88 +# - repo: https://github.com/asottile/seed-isort-config +# rev: v2.2.0 +# hooks: +# - id: seed-isort-config - - repo: https://github.com/pycqa/isort - rev: 5.10.1 - hooks: - - id: isort - name: isort (python) +# - repo: https://github.com/pycqa/isort +# rev: 5.10.1 +# hooks: +# - id: isort +# name: isort (python) diff --git a/examples/plot_derivative.py b/examples/plot_derivative.py index d8f33979..5d11e7ef 100644 --- a/examples/plot_derivative.py +++ b/examples/plot_derivative.py @@ -211,11 +211,11 @@ # derivatives nx, nz = 60, 40 -horlayers = np.cumsum(np.random.uniform(2, 10, 20).astype(np.int)) +horlayers = np.cumsum(np.random.uniform(2, 10, 20).astype(int)) horlayers = horlayers[horlayers < nz // 2] nhorlayers = len(horlayers) -vertlayers = np.cumsum(np.random.uniform(2, 20, 10).astype(np.int)) +vertlayers = np.cumsum(np.random.uniform(2, 20, 10).astype(int)) vertlayers = vertlayers[vertlayers < nx] nvertlayers = len(vertlayers) diff --git a/examples/plot_tvreg.py b/examples/plot_tvreg.py index cdf3de08..99834104 100755 --- a/examples/plot_tvreg.py +++ b/examples/plot_tvreg.py @@ -112,7 +112,7 @@ perc_subsampling = 0.6 nxsub = int(np.round(ny * nx * perc_subsampling)) iava = np.sort(np.random.permutation(np.arange(ny * nx))[:nxsub]) -Rop = pylops.Restriction(ny * nx, iava, dtype=np.complex) +Rop = pylops.Restriction(ny * nx, iava, dtype=np.complex128) Fop = pylops.signalprocessing.FFT2D(dims=(ny, nx)) n = np.random.normal(0, 0.0, (ny, nx)) @@ -148,10 +148,10 @@ Dop = [ pylops.FirstDerivative( - ny * nx, dims=(ny, nx), dir=0, edge=False, kind="backward", dtype=np.complex + ny * nx, dims=(ny, nx), dir=0, edge=False, kind="backward", dtype=np.complex128 ), pylops.FirstDerivative( - ny * nx, dims=(ny, nx), dir=1, edge=False, kind="backward", dtype=np.complex + ny * nx, dims=(ny, nx), dir=1, edge=False, kind="backward", dtype=np.complex128 ), ] diff --git a/pylops/basicoperators/BlockDiag.py b/pylops/basicoperators/BlockDiag.py index 48d2b39c..80cf05fd 100644 --- a/pylops/basicoperators/BlockDiag.py +++ b/pylops/basicoperators/BlockDiag.py @@ -90,8 +90,8 @@ class BlockDiag(LinearOperator): def __init__(self, ops, nproc=1, dtype=None): self.ops = ops - mops = np.zeros(len(ops), dtype=np.int) - nops = np.zeros(len(ops), dtype=np.int) + mops = np.zeros(len(ops), dtype=int) + nops = np.zeros(len(ops), dtype=int) for iop, oper in enumerate(ops): if not isinstance(oper, (LinearOperator, spLinearOperator)): self.ops[iop] = MatrixMult(oper, dtype=oper.dtype) diff --git a/pylops/basicoperators/HStack.py b/pylops/basicoperators/HStack.py index 7e2c09b2..1ecb6f56 100644 --- a/pylops/basicoperators/HStack.py +++ b/pylops/basicoperators/HStack.py @@ -89,7 +89,7 @@ class HStack(LinearOperator): def __init__(self, ops, nproc=1, dtype=None): self.ops = ops - mops = np.zeros(len(ops), dtype=np.int) + mops = np.zeros(len(ops), dtype=int) for iop, oper in enumerate(ops): if not isinstance(oper, (LinearOperator, spLinearOperator)): self.ops[iop] = MatrixMult(oper, dtype=oper.dtype) diff --git a/pylops/basicoperators/MatrixMult.py b/pylops/basicoperators/MatrixMult.py index 28b51186..86df61cb 100644 --- a/pylops/basicoperators/MatrixMult.py +++ b/pylops/basicoperators/MatrixMult.py @@ -54,7 +54,7 @@ def __init__(self, A, dims=None, dtype="float64"): if isinstance(dims, int): dims = (dims,) self.reshape = True - self.dims = np.array(dims, dtype=np.int) + self.dims = np.array(dims, dtype=int) self.reshapedims = [ np.insert([np.prod(self.dims)], 0, self.A.shape[1]), np.insert([np.prod(self.dims)], 0, self.A.shape[0]), diff --git a/pylops/basicoperators/Restriction.py b/pylops/basicoperators/Restriction.py index daf8ff37..89b38926 100644 --- a/pylops/basicoperators/Restriction.py +++ b/pylops/basicoperators/Restriction.py @@ -9,7 +9,7 @@ def _compute_iavamask(dims, dir, iava, ncp): """Compute restriction mask when using cupy arrays""" otherdims = np.array(dims) otherdims = np.delete(otherdims, dir) - iavamask = ncp.zeros(dims[dir], dtype=np.int) + iavamask = ncp.zeros(dims[dir], dtype=int) iavamask[iava] = 1 iavamask = ncp.moveaxis( ncp.broadcast_to(iavamask, list(otherdims) + [dims[dir]]), -1, dir diff --git a/pylops/basicoperators/Spread.py b/pylops/basicoperators/Spread.py index ccb15937..6aefd410 100644 --- a/pylops/basicoperators/Spread.py +++ b/pylops/basicoperators/Spread.py @@ -186,7 +186,7 @@ def _matvec_numpy(self, x): indices = self.fh(ix0, it) mask = np.argwhere(~np.isnan(indices)) if mask.size > 0: - indices = (indices[mask]).astype(np.int) + indices = (indices[mask]).astype(int) if not self.interp: y[mask, indices] += x[ix0, it] else: @@ -210,7 +210,7 @@ def _rmatvec_numpy(self, x): indices = self.fh(ix0, it) mask = np.argwhere(~np.isnan(indices)) if mask.size > 0: - indices = (indices[mask]).astype(np.int) + indices = (indices[mask]).astype(int) if not self.interp: y[ix0, it] = np.sum(x[mask, indices]) else: diff --git a/pylops/basicoperators/Sum.py b/pylops/basicoperators/Sum.py index adca140f..c20af8b1 100644 --- a/pylops/basicoperators/Sum.py +++ b/pylops/basicoperators/Sum.py @@ -55,7 +55,7 @@ def __init__(self, dims, dir, dtype="float64"): self.dims_d = list(dims).copy() self.dims_d.pop(dir) # array of ones with dims of model in dir for np.tile in adjoint mode - self.tile = np.ones(len(dims), dtype=np.int) + self.tile = np.ones(len(dims), dtype=int) self.tile[dir] = self.dims[dir] self.dtype = np.dtype(dtype) self.shape = (np.prod(self.dims_d), np.prod(dims)) diff --git a/pylops/basicoperators/Transpose.py b/pylops/basicoperators/Transpose.py index 1f1542d8..e15f1cbe 100644 --- a/pylops/basicoperators/Transpose.py +++ b/pylops/basicoperators/Transpose.py @@ -55,9 +55,9 @@ def __init__(self, dims, axes, dtype="float64"): raise ValueError("axes must contain each direction once") # find out how axes should be transposed in adjoint mode - self.axesd = np.zeros(ndims, dtype=np.int) - self.dimsd = np.zeros(ndims, dtype=np.int) - self.axesd[self.axes] = np.arange(ndims, dtype=np.int) + self.axesd = np.zeros(ndims, dtype=int) + self.dimsd = np.zeros(ndims, dtype=int) + self.axesd[self.axes] = np.arange(ndims, dtype=int) self.dimsd[self.axesd] = self.dims self.axesd = list(self.axesd) diff --git a/pylops/basicoperators/VStack.py b/pylops/basicoperators/VStack.py index f228764b..3605deab 100644 --- a/pylops/basicoperators/VStack.py +++ b/pylops/basicoperators/VStack.py @@ -89,7 +89,7 @@ class VStack(LinearOperator): def __init__(self, ops, nproc=1, dtype=None): self.ops = ops - nops = np.zeros(len(self.ops), dtype=np.int) + nops = np.zeros(len(self.ops), dtype=int) for iop, oper in enumerate(ops): if not isinstance(oper, (LinearOperator, spLinearOperator)): self.ops[iop] = MatrixMult(oper, dtype=oper.dtype) diff --git a/pylops/signalprocessing/Bilinear.py b/pylops/signalprocessing/Bilinear.py index 67095e34..641bce3b 100644 --- a/pylops/signalprocessing/Bilinear.py +++ b/pylops/signalprocessing/Bilinear.py @@ -88,10 +88,10 @@ def __init__(self, iava, dims, dtype="float64"): self.dimsd = [len(iava[1])] + list(dims[2:]) # find indices and weights - self.iava_t = ncp.floor(iava[0]).astype(np.int) + self.iava_t = ncp.floor(iava[0]).astype(int) self.iava_b = self.iava_t + 1 self.weights_tb = iava[0] - self.iava_t - self.iava_l = ncp.floor(iava[1]).astype(np.int) + self.iava_l = ncp.floor(iava[1]).astype(int) self.iava_r = self.iava_l + 1 self.weights_lr = iava[1] - self.iava_l @@ -123,14 +123,20 @@ def _rmatvec(self, x): y = ncp.zeros(self.dims, dtype=self.dtype) ncp_add_at( y, - [self.iava_t, self.iava_l], + tuple([self.iava_t, self.iava_l]), x * (1 - self.weights_tb) * (1 - self.weights_lr), ) ncp_add_at( - y, [self.iava_t, self.iava_r], x * (1 - self.weights_tb) * self.weights_lr + y, + tuple([self.iava_t, self.iava_r]), + x * (1 - self.weights_tb) * self.weights_lr, + ) + ncp_add_at( + y, + tuple([self.iava_b, self.iava_l]), + x * self.weights_tb * (1 - self.weights_lr), ) ncp_add_at( - y, [self.iava_b, self.iava_l], x * self.weights_tb * (1 - self.weights_lr) + y, tuple([self.iava_b, self.iava_r]), x * self.weights_tb * self.weights_lr ) - ncp_add_at(y, [self.iava_b, self.iava_r], x * self.weights_tb * self.weights_lr) return y.ravel() diff --git a/pylops/signalprocessing/ConvolveND.py b/pylops/signalprocessing/ConvolveND.py index 284fcb86..e2f5a5c4 100644 --- a/pylops/signalprocessing/ConvolveND.py +++ b/pylops/signalprocessing/ConvolveND.py @@ -62,9 +62,9 @@ def __init__( # padding if offset is None: - offset = np.zeros(self.h.ndim, dtype=np.int) + offset = np.zeros(self.h.ndim, dtype=int) else: - offset = np.array(offset, dtype=np.int) + offset = np.array(offset, dtype=int) self.offset = 2 * (self.nh // 2 - offset) pad = [(0, 0) for _ in range(self.h.ndim)] dopad = False @@ -83,7 +83,7 @@ def __init__( # find out which directions are used for convolution and define offsets if len(dims) != len(self.nh): - dimsh = np.ones(len(dims), dtype=np.int) + dimsh = np.ones(len(dims), dtype=int) for idir, dir in enumerate(self.dirs): dimsh[dir] = self.nh[idir] self.h = self.h.reshape(dimsh) diff --git a/pylops/signalprocessing/Interp.py b/pylops/signalprocessing/Interp.py index 192b7f31..6b6f31ef 100644 --- a/pylops/signalprocessing/Interp.py +++ b/pylops/signalprocessing/Interp.py @@ -17,7 +17,7 @@ def _checkunique(iava): def _nearestinterp(M, iava, dims=None, dir=0, dtype="float64"): """Nearest neighbour interpolation.""" - iava = np.round(iava).astype(np.int) + iava = np.round(iava).astype(int) _checkunique(iava) return Restriction(M, iava, dims=dims, dir=dir, dtype=dtype), iava @@ -27,7 +27,7 @@ def _linearinterp(M, iava, dims=None, dir=0, dtype="float64"): ncp = get_array_module(iava) if np.issubdtype(iava.dtype, np.integer): - iava = iava.astype(np.float) + iava = iava.astype(np.float64) if dims is None: lastsample = M dimsd = None @@ -49,7 +49,7 @@ def _linearinterp(M, iava, dims=None, dir=0, dtype="float64"): _checkunique(iava) # find indices and weights - iva_l = ncp.floor(iava).astype(np.int) + iva_l = ncp.floor(iava).astype(int) iva_r = iva_l + 1 weights = iava - iva_l @@ -84,7 +84,7 @@ def _sincinterp(M, iava, dims=None, dir=0, dtype="float64"): # create Transpose operator that brings dir to first dimension if dir > 0: - axes = np.arange(len(dims), dtype=np.int) + axes = np.arange(len(dims), dtype=int) axes = np.roll(axes, -dir) dimsd = list(dims) dimsd[dir] = len(iava) diff --git a/pylops/signalprocessing/Radon2D.py b/pylops/signalprocessing/Radon2D.py index 0a2a5f80..40748d3f 100644 --- a/pylops/signalprocessing/Radon2D.py +++ b/pylops/signalprocessing/Radon2D.py @@ -67,7 +67,7 @@ def _indices_2d(f, x, px, t, nt, interp=True): xscan = (tdecscan >= 0) & (tdecscan < nt) else: xscan = (tdecscan >= 0) & (tdecscan < nt - 1) - tscan = tdecscan[xscan].astype(np.int) + tscan = tdecscan[xscan].astype(int) if interp: dtscan = tdecscan[xscan] - tscan else: diff --git a/pylops/signalprocessing/Radon3D.py b/pylops/signalprocessing/Radon3D.py index c3c78714..ed55a573 100644 --- a/pylops/signalprocessing/Radon3D.py +++ b/pylops/signalprocessing/Radon3D.py @@ -71,7 +71,7 @@ def _indices_3d(f, y, x, py, px, t, nt, interp=True): sscan = (tdecscan >= 0) & (tdecscan < nt) else: sscan = (tdecscan >= 0) & (tdecscan < nt - 1) - tscan = tdecscan[sscan].astype(np.int) + tscan = tdecscan[sscan].astype(int) if interp: dtscan = tdecscan[sscan] - tscan else: diff --git a/pylops/signalprocessing/Sliding2D.py b/pylops/signalprocessing/Sliding2D.py index 368d6d35..6ed9df8c 100644 --- a/pylops/signalprocessing/Sliding2D.py +++ b/pylops/signalprocessing/Sliding2D.py @@ -32,7 +32,7 @@ def _slidingsteps(ntr, nwin, nover): if nwin > ntr: raise ValueError("nwin=%d is bigger than ntr=%d..." % (nwin, ntr)) step = nwin - nover - starts = np.arange(0, ntr - nwin + 1, step, dtype=np.int) + starts = np.arange(0, ntr - nwin + 1, step, dtype=int) ends = starts + nwin return starts, ends diff --git a/pylops/waveeqprocessing/marchenko.py b/pylops/waveeqprocessing/marchenko.py index 24558115..709a9db9 100644 --- a/pylops/waveeqprocessing/marchenko.py +++ b/pylops/waveeqprocessing/marchenko.py @@ -352,7 +352,7 @@ def apply_onepoint( """ # Create window trav_off = trav - self.toff - trav_off = np.round(trav_off / self.dt).astype(np.int) + trav_off = np.round(trav_off / self.dt).astype(int) w = np.zeros((self.nr, self.nt), dtype=self.dtype) for ir in range(self.nr): @@ -561,7 +561,7 @@ def apply_multiplepoints( # Create window trav_off = trav - self.toff - trav_off = np.round(trav_off / self.dt).astype(np.int) + trav_off = np.round(trav_off / self.dt).astype(int) w = np.zeros((self.nr, nvs, self.nt), dtype=self.dtype) for ir in range(self.nr): diff --git a/pylops/waveeqprocessing/mdd.py b/pylops/waveeqprocessing/mdd.py index 4ee32144..6a4d73cc 100644 --- a/pylops/waveeqprocessing/mdd.py +++ b/pylops/waveeqprocessing/mdd.py @@ -93,10 +93,20 @@ def _MDC( logging.warning("nfmax set equal to ceil[(nt+1)/2=%d]" % nfmax) Fop = _FFT( - dims=(nt, nr, nv), dir=0, real=True, fftshift=twosided, dtype=rdtype, **args_FFT + dims=(nt, nr, nv), + dir=0, + real=True, + ifftshift_before=twosided, + dtype=rdtype, + **args_FFT ) F1op = _FFT( - dims=(nt, ns, nv), dir=0, real=True, fftshift=False, dtype=rdtype, **args_FFT1 + dims=(nt, ns, nv), + dir=0, + real=True, + ifftshift_before=False, + dtype=rdtype, + **args_FFT1 ) # create Identity operator to extract only relevant frequencies diff --git a/pytests/test_linearoperator.py b/pytests/test_linearoperator.py index 0aca0603..93a9be8b 100755 --- a/pytests/test_linearoperator.py +++ b/pytests/test_linearoperator.py @@ -126,7 +126,7 @@ def test_eigs(par): def test_conj(par): """Complex conjugation operator""" M = 1j * np.ones((par["ny"], par["nx"])) - Op = MatrixMult(M, dtype=np.complex) + Op = MatrixMult(M, dtype=np.complex128) Opconj = Op.conj() x = np.arange(par["nx"]) + par["imag"] * np.arange(par["nx"]) @@ -170,7 +170,7 @@ def test_realimag(par): M = np.random.normal(0, 1, (par["ny"], par["nx"])) + 1j * np.random.normal( 0, 1, (par["ny"], par["nx"]) ) - Op = MatrixMult(M, dtype=np.complex) + Op = MatrixMult(M, dtype=np.complex128) Opr = Op.toreal() Opi = Op.toimag() diff --git a/tutorials/ctscan.py b/tutorials/ctscan.py index b6b01d01..3f256ec4 100755 --- a/tutorials/ctscan.py +++ b/tutorials/ctscan.py @@ -92,13 +92,13 @@ def radoncurve(x, r, theta): # modelling operator both in a least-squares sense and using TV-reg. Dop = [ pylops.FirstDerivative( - ny * nx, dims=(nx, ny), dir=0, edge=True, kind="backward", dtype=np.float + ny * nx, dims=(nx, ny), dir=0, edge=True, kind="backward", dtype=np.float64 ), pylops.FirstDerivative( - ny * nx, dims=(nx, ny), dir=1, edge=True, kind="backward", dtype=np.float + ny * nx, dims=(nx, ny), dir=1, edge=True, kind="backward", dtype=np.float64 ), ] -D2op = pylops.Laplacian(dims=(nx, ny), edge=True, dtype=np.float) +D2op = pylops.Laplacian(dims=(nx, ny), edge=True, dtype=np.float64) # L2 xinv_sm = pylops.optimization.leastsquares.RegularizedInversion( diff --git a/tutorials/deghosting.py b/tutorials/deghosting.py index 0eef6ab6..8b7f2b15 100755 --- a/tutorials/deghosting.py +++ b/tutorials/deghosting.py @@ -79,7 +79,7 @@ off = 0.035 direct_off = direct + off win = np.zeros((nt, nr)) -iwin = np.round(direct_off / dt).astype(np.int) +iwin = np.round(direct_off / dt).astype(int) for i in range(nr): win[iwin[i] :, i] = 1 diff --git a/tutorials/realcomplex.py b/tutorials/realcomplex.py index a065881d..1cf30b8e 100755 --- a/tutorials/realcomplex.py +++ b/tutorials/realcomplex.py @@ -52,7 +52,7 @@ Ar = np.random.normal(0, 1, (n, n)) Ai = np.random.normal(0, 1, (n, n)) A = Ar + 1j * Ai -Aop = pylops.MatrixMult(A, dtype=np.complex) +Aop = pylops.MatrixMult(A, dtype=np.complex128) y = Aop @ x ############################################################################### diff --git a/tutorials/wavefielddecomposition.py b/tutorials/wavefielddecomposition.py index ad000d28..5ee787b6 100755 --- a/tutorials/wavefielddecomposition.py +++ b/tutorials/wavefielddecomposition.py @@ -66,7 +66,7 @@ # obliquity factor [Kx, F] = np.meshgrid(FFTop.f1, FFTop.f2, indexing="ij") k = F / vel_sep -Kz = np.sqrt((k ** 2 - Kx ** 2).astype(np.complex)) +Kz = np.sqrt((k ** 2 - Kx ** 2).astype(np.complex128)) Kz[np.isnan(Kz)] = 0 OBL = rho_sep * (np.abs(F) / Kz) OBL[Kz == 0] = 0 From a8b947c45fdff234e06f8f3a26e65a8e0ebd0895 Mon Sep 17 00:00:00 2001 From: cako Date: Tue, 28 Dec 2021 22:49:07 -0500 Subject: [PATCH 2/2] Use black profile for isort --- .pre-commit-config.yaml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a6d6f8ff..23bfc594 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,13 +13,10 @@ repos: - id: black args: # arguments to configure black - --line-length=88 -# - repo: https://github.com/asottile/seed-isort-config -# rev: v2.2.0 -# hooks: -# - id: seed-isort-config -# - repo: https://github.com/pycqa/isort -# rev: 5.10.1 -# hooks: -# - id: isort -# name: isort (python) + - repo: https://github.com/pycqa/isort + rev: 5.10.1 + hooks: + - id: isort + name: isort (python) + args: ["--profile", "black", "--filter-files", "--line-length=88"]