Skip to content

Commit

Permalink
minor: added verb to *_design methods and few other small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrava87 committed May 22, 2024
1 parent af5d8ae commit 4c82d21
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 84 deletions.
44 changes: 23 additions & 21 deletions pylops/signalprocessing/patch2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def patch2d_design(
nwin: Tuple[int, int],
nover: Tuple[int, int],
nop: Tuple[int, int],
verb: bool = True,
) -> Tuple[
Tuple[int, int],
Tuple[int, int],
Expand All @@ -51,6 +52,9 @@ def patch2d_design(
Number of samples of overlapping part of window.
nop : :obj:`tuple`
Size of model in the transformed domain.
verb : :obj:`bool`, optional
Verbosity flag. If ``verb==True``, print the data
and model windows start-end indices
Returns
-------
Expand Down Expand Up @@ -79,21 +83,22 @@ def patch2d_design(
mwins_inends = ((mwin0_ins, mwin0_ends), (mwin1_ins, mwin1_ends))

# print information about patching
logging.warning("%d-%d windows required...", nwins0, nwins1)
logging.warning(
"data wins - start:%s, end:%s / start:%s, end:%s",
dwin0_ins,
dwin0_ends,
dwin1_ins,
dwin1_ends,
)
logging.warning(
"model wins - start:%s, end:%s / start:%s, end:%s",
mwin0_ins,
mwin0_ends,
mwin1_ins,
mwin1_ends,
)
if verb:
logging.warning("%d-%d windows required...", nwins0, nwins1)
logging.warning(
"data wins - start:%s, end:%s / start:%s, end:%s",
dwin0_ins,
dwin0_ends,
dwin1_ins,
dwin1_ends,
)
logging.warning(
"model wins - start:%s, end:%s / start:%s, end:%s",
mwin0_ins,
mwin0_ends,
mwin1_ins,
mwin1_ends,
)
return nwins, dims, mwins_inends, dwins_inends


Expand Down Expand Up @@ -276,10 +281,7 @@ def __init__(
self.taps = np.vstack(taps).reshape(3, 3, nwin[0], nwin[1])

# define scalings
if scalings is None:
self.scalings = [1.0] * nwins
else:
self.scalings = scalings
self.scalings = [1.0] * nwins if scalings is None else scalings

# check if operator is applied to all windows simultaneously
self.simOp = False
Expand Down Expand Up @@ -318,7 +320,7 @@ def _apply_taper(self, ywins, iwin0, iwin1):
ywins[iwin0, iwin1] = self.taps[1, 1] * ywins[iwin0, iwin1]
return ywins

@reshaped()
@reshaped
def _matvec_savetaper(self, x: NDArray) -> NDArray:
ncp = get_array_module(x)
if self.tapertype is not None:
Expand Down Expand Up @@ -365,7 +367,7 @@ def _rmatvec_savetaper(self, x: NDArray) -> NDArray:
).reshape(self.dims[2], self.dims[3])
return y

@reshaped()
@reshaped
def _matvec_nosavetaper(self, x: NDArray) -> NDArray:
ncp = get_array_module(x)
if self.tapertype is not None:
Expand Down
54 changes: 28 additions & 26 deletions pylops/signalprocessing/patch3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def patch3d_design(
nwin: Tuple[int, int, int],
nover: Tuple[int, int, int],
nop: Tuple[int, int, int],
verb: bool = True,
) -> Tuple[
Tuple[int, int, int],
Tuple[int, int, int],
Expand All @@ -51,6 +52,9 @@ def patch3d_design(
Number of samples of overlapping part of window.
nop : :obj:`tuple`
Size of model in the transformed domain.
verb : :obj:`bool`, optional
Verbosity flag. If ``verb==True``, print the data
and model windows start-end indices
Returns
-------
Expand Down Expand Up @@ -90,25 +94,26 @@ def patch3d_design(
)

# print information about patching
logging.warning("%d-%d-%d windows required...", nwins0, nwins1, nwins2)
logging.warning(
"data wins - start:%s, end:%s / start:%s, end:%s / start:%s, end:%s",
dwin0_ins,
dwin0_ends,
dwin1_ins,
dwin1_ends,
dwin2_ins,
dwin2_ends,
)
logging.warning(
"model wins - start:%s, end:%s / start:%s, end:%s / start:%s, end:%s",
mwin0_ins,
mwin0_ends,
mwin1_ins,
mwin1_ends,
mwin2_ins,
mwin2_ends,
)
if verb:
logging.warning("%d-%d-%d windows required...", nwins0, nwins1, nwins2)
logging.warning(
"data wins - start:%s, end:%s / start:%s, end:%s / start:%s, end:%s",
dwin0_ins,
dwin0_ends,
dwin1_ins,
dwin1_ends,
dwin2_ins,
dwin2_ends,
)
logging.warning(
"model wins - start:%s, end:%s / start:%s, end:%s / start:%s, end:%s",
mwin0_ins,
mwin0_ends,
mwin1_ins,
mwin1_ends,
mwin2_ins,
mwin2_ends,
)
return nwins, dims, mwins_inends, dwins_inends


Expand Down Expand Up @@ -485,10 +490,7 @@ def __init__(
self.taps[-1, -1, -1] = taprightbottomback

# define scalings
if scalings is None:
self.scalings = [1.0] * nwins
else:
self.scalings = scalings
self.scalings = [1.0] * nwins if scalings is None else scalings

# check if operator is applied to all windows simultaneously
self.simOp = False
Expand Down Expand Up @@ -576,7 +578,7 @@ def _apply_taper(self, ywins, iwin0, iwin1, iwin2):
ywins[iwin0, iwin1, iwin2] = self.taps[1, 1, 1] * ywins[iwin0, iwin1, iwin2]
return ywins

@reshaped()
@reshaped
def _matvec_savetaper(self, x: NDArray) -> NDArray:
ncp = get_array_module(x)
if self.tapertype is not None:
Expand Down Expand Up @@ -630,7 +632,7 @@ def _rmatvec_savetaper(self, x: NDArray) -> NDArray:
).reshape(self.dims[3], self.dims[4], self.dims[5])
return y

@reshaped()
@reshaped
def _matvec_nosavetaper(self, x: NDArray) -> NDArray:
ncp = get_array_module(x)
if self.tapertype is not None:
Expand Down Expand Up @@ -727,7 +729,7 @@ def _matvec_nosavetaper(self, x: NDArray) -> NDArray:
] += xxwin
return y

@reshaped()
@reshaped
def _rmatvec_nosavetaper(self, x: NDArray) -> NDArray:
ncp = get_array_module(x)
ncp_sliding_window_view = get_sliding_window_view(x)
Expand Down
27 changes: 16 additions & 11 deletions pylops/signalprocessing/sliding1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def sliding1d_design(
nwin: int,
nover: int,
nop: int,
verb: bool = True,
) -> Tuple[int, int, Tuple[NDArray, NDArray], Tuple[NDArray, NDArray]]:
"""Design Sliding1D operator
Expand All @@ -46,6 +47,9 @@ def sliding1d_design(
Number of samples of overlapping part of window.
nop : :obj:`tuple`
Size of model in the transformed domain.
verb : :obj:`bool`, optional
Verbosity flag. If ``verb==True``, print the data
and model windows start-end indices
Returns
-------
Expand All @@ -70,17 +74,18 @@ def sliding1d_design(
mwins_inends = (mwin_ins, mwin_ends)

# print information about patching
logging.warning("%d windows required...", nwins)
logging.warning(
"data wins - start:%s, end:%s",
dwin_ins,
dwin_ends,
)
logging.warning(
"model wins - start:%s, end:%s",
mwin_ins,
mwin_ends,
)
if verb:
logging.warning("%d windows required...", nwins)
logging.warning(
"data wins - start:%s, end:%s",
dwin_ins,
dwin_ends,
)
logging.warning(
"model wins - start:%s, end:%s",
mwin_ins,
mwin_ends,
)
return nwins, dim, mwins_inends, dwins_inends


Expand Down
27 changes: 16 additions & 11 deletions pylops/signalprocessing/sliding2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def sliding2d_design(
nwin: int,
nover: int,
nop: Tuple[int, int],
verb: bool = True,
) -> Tuple[int, Tuple[int, int], Tuple[NDArray, NDArray], Tuple[NDArray, NDArray]]:
"""Design Sliding2D operator
Expand All @@ -78,6 +79,9 @@ def sliding2d_design(
Number of samples of overlapping part of window.
nop : :obj:`tuple`
Size of model in the transformed domain.
verb : :obj:`bool`, optional
Verbosity flag. If ``verb==True``, print the data
and model windows start-end indices
Returns
-------
Expand All @@ -102,17 +106,18 @@ def sliding2d_design(
mwins_inends = (mwin_ins, mwin_ends)

# print information about patching
logging.warning("%d windows required...", nwins)
logging.warning(
"data wins - start:%s, end:%s",
dwin_ins,
dwin_ends,
)
logging.warning(
"model wins - start:%s, end:%s",
mwin_ins,
mwin_ends,
)
if verb:
logging.warning("%d windows required...", nwins)
logging.warning(
"data wins - start:%s, end:%s",
dwin_ins,
dwin_ends,
)
logging.warning(
"model wins - start:%s, end:%s",
mwin_ins,
mwin_ends,
)
return nwins, dims, mwins_inends, dwins_inends


Expand Down
35 changes: 20 additions & 15 deletions pylops/signalprocessing/sliding3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def sliding3d_design(
nwin: Tuple[int, int],
nover: Tuple[int, int],
nop: Tuple[int, int, int],
verb: bool = True,
) -> Tuple[
Tuple[int, int],
Tuple[int, int, int],
Expand All @@ -51,6 +52,9 @@ def sliding3d_design(
Number of samples of overlapping part of window.
nop : :obj:`tuple`
Size of model in the transformed domain.
verb : :obj:`bool`, optional
Verbosity flag. If ``verb==True``, print the data
and model windows start-end indices
Returns
-------
Expand Down Expand Up @@ -79,21 +83,22 @@ def sliding3d_design(
mwins_inends = ((mwin0_ins, mwin0_ends), (mwin1_ins, mwin1_ends))

# print information about patching
logging.warning("%d-%d windows required...", nwins0, nwins1)
logging.warning(
"data wins - start:%s, end:%s / start:%s, end:%s",
dwin0_ins,
dwin0_ends,
dwin1_ins,
dwin1_ends,
)
logging.warning(
"model wins - start:%s, end:%s / start:%s, end:%s",
mwin0_ins,
mwin0_ends,
mwin1_ins,
mwin1_ends,
)
if verb:
logging.warning("%d-%d windows required...", nwins0, nwins1)
logging.warning(
"data wins - start:%s, end:%s / start:%s, end:%s",
dwin0_ins,
dwin0_ends,
dwin1_ins,
dwin1_ends,
)
logging.warning(
"model wins - start:%s, end:%s / start:%s, end:%s",
mwin0_ins,
mwin0_ends,
mwin1_ins,
mwin1_ends,
)
return nwins, dims, mwins_inends, dwins_inends


Expand Down

0 comments on commit 4c82d21

Please sign in to comment.