Skip to content

Commit af3cf70

Browse files
authored
Convert dir to axis (#310)
* feature: axis keyword and deprecate dir in basicoperators * feature: axis keyword and deprecate in smoothing and derivative * minor: Always use 2.0 instead of 2.0.0 * minor: Add spaces around markup blocks * minor: Finished editing smoothing & derivatives block * minor: remove whitespace * feature: axis/axes keywords and deprecate dir/nodir in Convolve operators * feature: axis for Diagonal and Interp * feature: axis for FFTs and Shift * chore: 2.0 -> 2.0.0 * minor: same pywt checking as DWT1D * minor: dir-> axis * feature: dir/dirs -> axis/axes in DWT operators * chore: Remove the leftover dir(s) * minor * chore: is deprecated -> will be deprecated * minor: remove useless "else" * minor: fix merge problems * chore: prepare for merge with upstream * docs: Document `dir` to `axis` migration * minor: simplify code for Sum * bugfix: minor bug in cupy code for Restriction * docs: Improve dir/dirs/nodir migration guide * chore: axis=-1 where it was missed * minor: Remove any reference to dir/dirs/nodir * docs: Fix dir/dirs/nodir migration guide
1 parent 435eef7 commit af3cf70

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+802
-703
lines changed

MIGRATION_V1_V2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ should be used as a checklist when converting a piece of code using PyLops from
88
- Several operators have deprecated `N` as a keyword. To migrate, pass only `dims` if both `N` and `dims` are currently
99
being passed. If only `N` is being passed, ensure it is being passed as a value and not a keyword argument (e.g.,
1010
change `Flip(N=100)` to `Flip(100)`).
11+
- `dir`, `dirs` and `nodir` have been deprecated in favor of `axis` and `axes`. When previously `nodir` was used, you must now provide the directions along which the operator is applied through `axes`. The default value for `axis` and `axes` are chosen to be -1 and (-2, -1), respectively, whereas the default `dir` and `dirs` was 0 and (0, 1), respectively. Be careful to check all operators where `dir`, `dirs` and `nodir` was not provided explicitly.
1112
- `utils.dottest`: Change `tol` into `rtol`. Absolute tolerance is now also supported via the keyword `atol`.
1213
When calling it with purely positional arguments, note that after `rtol` comes now first `atol` before `complexflag`.
1314
When using `raiseerror=True` it now emits an `AttributeError` instead of a `ValueError`.

examples/plot_causalintegration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@
112112
t = np.arange(nt) * dt + ot
113113
x = np.outer(np.sin(t), np.ones(nx))
114114

115-
Cop = pylops.CausalIntegration((nt, nx), sampling=dt, dir=0, halfcurrent=True)
115+
Cop = pylops.CausalIntegration(dims=(nt, nx), sampling=dt, axis=0, halfcurrent=True)
116116

117117
y = Cop * x.ravel()
118118
y = y.reshape(nt, nx)
119119
yn = y + np.random.normal(0, 4e-1, y.shape)
120120

121121
# Numerical derivative
122-
Dop = pylops.FirstDerivative((nt, nx), dir=0, sampling=dt)
122+
Dop = pylops.FirstDerivative(dims=(nt, nx), axis=0, sampling=dt)
123123
xder = Dop * yn.ravel()
124124
xder = xder.reshape(nt, nx)
125125

examples/plot_convolve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
offset = [1, 2, 1]
144144

145145
Cop = pylops.signalprocessing.ConvolveND(
146-
nx * ny * nz, h=h, offset=offset, dims=[ny, nx, nz], dirs=[0, 1, 2], dtype="float32"
146+
dims=(ny, nx, nz), h=h, offset=offset, axes=(0, 1, 2), dtype="float32"
147147
)
148148
y = Cop * x.ravel()
149149
xinv = lsqr(Cop, y, damp=0, iter_lim=300, show=0)[0]

examples/plot_derivative.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
A = np.zeros((nx, ny))
8484
A[nx // 2, ny // 2] = 1.0
8585

86-
D1op = pylops.FirstDerivative((nx, ny), dir=0, dtype="float64")
86+
D1op = pylops.FirstDerivative((nx, ny), axis=0, dtype="float64")
8787
B = np.reshape(D1op * A.ravel(), (nx, ny))
8888

8989
fig, axs = plt.subplots(1, 2, figsize=(10, 3))
@@ -106,7 +106,7 @@
106106
A = np.zeros((nx, ny))
107107
A[nx // 2, ny // 2] = 1.0
108108

109-
D2op = pylops.SecondDerivative((nx, ny), dir=0, dtype="float64")
109+
D2op = pylops.SecondDerivative(dims=(nx, ny), axis=0, dtype="float64")
110110
B = np.reshape(D2op * A.ravel(), (nx, ny))
111111

112112
fig, axs = plt.subplots(1, 2, figsize=(10, 3))
@@ -126,8 +126,8 @@
126126

127127
###############################################################################
128128
# We can also apply the second derivative to the second direction of
129-
# our data (``dir=1``)
130-
D2op = pylops.SecondDerivative((nx, ny), dir=1, dtype="float64")
129+
# our data (``axis=1``)
130+
D2op = pylops.SecondDerivative(dims=(nx, ny), axis=1, dtype="float64")
131131
B = np.reshape(D2op * np.ndarray.flatten(A), (nx, ny))
132132

133133
fig, axs = plt.subplots(1, 2, figsize=(10, 3))

examples/plot_diagonal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595

9696
# 1st dim
9797
d = np.arange(nx)
98-
Dop = pylops.Diagonal(d, dims=(nx, ny), dir=0)
98+
Dop = pylops.Diagonal(d, dims=(nx, ny), axis=0)
9999

100100
y = Dop * x.ravel()
101101
y1 = Dop.H * x.ravel()
@@ -105,7 +105,7 @@
105105

106106
# 2nd dim
107107
d = np.arange(ny)
108-
Dop = pylops.Diagonal(d, dims=(nx, ny), dir=1)
108+
Dop = pylops.Diagonal(d, dims=(nx, ny), axis=1)
109109

110110
y = Dop * x.ravel()
111111
y1 = Dop.H * x.ravel()

examples/plot_fft.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
nfft = 2 ** 10
7575
d = np.outer(np.sin(2 * np.pi * f0 * t), np.arange(nx) + 1)
7676

77-
FFTop = pylops.signalprocessing.FFT(dims=(nt, nx), dir=0, nfft=nfft, sampling=dt)
77+
FFTop = pylops.signalprocessing.FFT(dims=(nt, nx), axis=0, nfft=nfft, sampling=dt)
7878
D = FFTop * d.ravel()
7979

8080
# Adjoint = inverse for FFT

examples/plot_flip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
# first flip the model along the first axis and then along the second axis
4141
nt, nx = 10, 5
4242
x = np.outer(np.arange(nt), np.ones(nx))
43-
Fop = pylops.Flip((nt, nx), dir=0)
43+
Fop = pylops.Flip((nt, nx), axis=0)
4444
y = Fop * x.ravel()
4545
xadj = Fop.H * y.ravel()
4646
y = y.reshape(nt, nx)
@@ -64,7 +64,7 @@
6464

6565

6666
x = np.outer(np.ones(nt), np.arange(nx))
67-
Fop = pylops.Flip((nt, nx), dir=1)
67+
Fop = pylops.Flip(dims=(nt, nx), axis=1)
6868
y = Fop * x.ravel()
6969
xadj = Fop.H * y.ravel()
7070
y = y.reshape(nt, nx)

examples/plot_restriction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
nxsub = int(np.round(nx * perc_subsampling))
9696
iava = np.sort(np.random.permutation(np.arange(nx))[:nxsub])
9797

98-
Rop = pylops.Restriction((nx, nt), iava, dir=0, dtype="float64")
98+
Rop = pylops.Restriction((nx, nt), iava, axis=0, dtype="float64")
9999
y = (Rop * x.ravel()).reshape(nxsub, nt)
100100
ymask = Rop.mask(x)
101101

examples/plot_roll.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
ny, nx = 10, 5
3838
x = np.arange(ny * nx).reshape(ny, nx)
3939

40-
Rop = pylops.Roll((ny, nx), dir=1, shift=-2)
40+
Rop = pylops.Roll(dims=(ny, nx), axis=1, shift=-2)
4141

4242
y = Rop * x.ravel()
4343
xadj = Rop.H * y

examples/plot_shift.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@
5252

5353
shift = 10.5 * dt
5454

55-
# 1st dir
55+
# 1st axis
5656
wav2d = np.outer(wav, np.ones(10))
5757
Op = pylops.signalprocessing.Shift(
58-
(nt, 10), shift, dir=0, sampling=dt, real=True, dtype=np.float64
58+
(nt, 10), shift, axis=0, sampling=dt, real=True, dtype=np.float64
5959
)
6060
wav2dshift = (Op * wav2d.ravel()).reshape(nt, 10)
6161
wav2dshiftback = (Op.H * wav2dshift.ravel()).reshape(nt, 10)
@@ -72,10 +72,10 @@
7272
axs[2].axis("tight")
7373
fig.tight_layout()
7474

75-
# 2nd dir
75+
# 2nd axis
7676
wav2d = np.outer(wav, np.ones(10)).T
7777
Op = pylops.signalprocessing.Shift(
78-
(10, nt), shift, dir=1, sampling=dt, real=True, dtype=np.float64
78+
(10, nt), shift, axis=1, sampling=dt, real=True, dtype=np.float64
7979
)
8080
wav2dshift = (Op * wav2d.ravel()).reshape(10, nt)
8181
wav2dshiftback = (Op.H * wav2dshift.ravel()).reshape(10, nt)

0 commit comments

Comments
 (0)