Skip to content

Commit 2b88c08

Browse files
authored
Merge pull request #332 from cako/patch-N-dims
Patch `N`/`dims`
2 parents ce20099 + 4728ab7 commit 2b88c08

Some content is hidden

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

47 files changed

+433
-795
lines changed

MIGRATION_V1_V2.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
# Migrating PyLops codes from V1 to V2
1+
# Migrating PyLops code from v1.x to v2.0
22

33
This file is intended to guide users willing to convert their codes from PyLops v1 to PyLops v2.
44

55
In the following we provide a detailed description of all the breaking changes introduced in v2, which
66
should be used as a checklist when converting a piece of code using PyLops from v1 to v2.
77

8-
- XX
9-
- XX
10-
- XX
11-
8+
- Several operators have deprecated `N` as a keyword. To migrate, pass only `dims` if both `N` and `dims` are currently being passed.
9+
If only `N` is being passed, ensure it is being passed as a value and not a keyword argument (e.g., change `Flip(N=100)` to `Flip(100)`).
1210
- `utils.dottest`: The relative tolerance is new set via `rtol` (before `tol`), and absolute tolerance is new supported via the keyword `atol`. When calling it with purely positional arguments, note that after `rtol` comes now first `atol` before `complexflag`. When using `raiseerror=True` it now emits an `AttributeError` instead of a `ValueError`.

examples/plot_causalintegration.py

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

115-
Cop = pylops.CausalIntegration(
116-
nt * nx, dims=(nt, nx), sampling=dt, dir=0, halfcurrent=True
117-
)
115+
Cop = pylops.CausalIntegration((nt, nx), sampling=dt, dir=0, halfcurrent=True)
118116

119117
y = Cop * x.ravel()
120118
y = y.reshape(nt, nx)
121119
yn = y + np.random.normal(0, 4e-1, y.shape)
122120

123121
# Numerical derivative
124-
Dop = pylops.FirstDerivative(nt * nx, dims=(nt, nx), dir=0, sampling=dt)
122+
Dop = pylops.FirstDerivative((nt, nx), dir=0, sampling=dt)
125123
xder = Dop * yn.ravel()
126124
xder = xder.reshape(nt, nx)
127125

examples/plot_convolve.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,9 @@
9292
h = np.ones((nh[0], nh[1]))
9393

9494
Cop = pylops.signalprocessing.Convolve2D(
95-
nt * nx,
95+
(nt, nx),
9696
h=h,
9797
offset=(int(nh[0]) / 2, int(nh[1]) / 2),
98-
dims=(nt, nx),
9998
dtype="float32",
10099
)
101100
y = Cop * x.ravel()

examples/plot_derivative.py

Lines changed: 3 additions & 3 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, dims=(nx, ny), dir=0, dtype="float64")
86+
D1op = pylops.FirstDerivative((nx, ny), dir=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, dims=(nx, ny), dir=0, dtype="float64")
109+
D2op = pylops.SecondDerivative((nx, ny), dir=0, dtype="float64")
110110
B = np.reshape(D2op * A.ravel(), (nx, ny))
111111

112112
fig, axs = plt.subplots(1, 2, figsize=(10, 3))
@@ -127,7 +127,7 @@
127127
###############################################################################
128128
# We can also apply the second derivative to the second direction of
129129
# our data (``dir=1``)
130-
D2op = pylops.SecondDerivative(nx * ny, dims=(nx, ny), dir=1, dtype="float64")
130+
D2op = pylops.SecondDerivative((nx, ny), dir=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_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, dims=(nt, nx), dir=0)
43+
Fop = pylops.Flip((nt, nx), dir=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, dims=(nt, nx), dir=1)
67+
Fop = pylops.Flip((nt, nx), dir=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, dims=(nx, nt), dir=0, dtype="float64")
98+
Rop = pylops.Restriction((nx, nt), iava, dir=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, dims=(ny, nx), dir=1, shift=-2)
40+
Rop = pylops.Roll((ny, nx), dir=1, shift=-2)
4141

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

examples/plot_stacking.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
###############################################################################
2828
# Let's start by defining two second derivatives :py:class:`pylops.SecondDerivative`
2929
# that we will be using in this example.
30-
D2hop = pylops.SecondDerivative(11 * 21, dims=[11, 21], dir=1, dtype="float32")
31-
D2vop = pylops.SecondDerivative(11 * 21, dims=[11, 21], dir=0, dtype="float32")
30+
D2hop = pylops.SecondDerivative((11, 21), dir=1, dtype="float32")
31+
D2vop = pylops.SecondDerivative((11, 21), dir=0, dtype="float32")
3232

3333
###############################################################################
3434
# Chaining of operators represents the simplest concatenation that

examples/plot_symmetrize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
nt, nx = 10, 6
5050
x = np.outer(np.arange(nt), np.ones(nx))
5151

52-
Sop = pylops.Symmetrize(nt * nx, dims=(nt, nx), dir=0)
52+
Sop = pylops.Symmetrize((nt, nx), dir=0)
5353
y = Sop * x.ravel()
5454
xadj = Sop.H * y.ravel()
5555
xinv = Sop / y
@@ -75,7 +75,7 @@
7575

7676

7777
x = np.outer(np.ones(nt), np.arange(nx))
78-
Sop = pylops.Symmetrize(nt * nx, dims=(nt, nx), dir=1)
78+
Sop = pylops.Symmetrize((nt, nx), dir=1)
7979

8080
y = Sop * x.ravel()
8181
xadj = Sop.H * y.ravel()

examples/plot_tvreg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@
148148

149149
Dop = [
150150
pylops.FirstDerivative(
151-
ny * nx, dims=(ny, nx), dir=0, edge=False, kind="backward", dtype=np.complex128
151+
(ny, nx), dir=0, edge=False, kind="backward", dtype=np.complex128
152152
),
153153
pylops.FirstDerivative(
154-
ny * nx, dims=(ny, nx), dir=1, edge=False, kind="backward", dtype=np.complex128
154+
(ny, nx), dir=1, edge=False, kind="backward", dtype=np.complex128
155155
),
156156
]
157157

0 commit comments

Comments
 (0)