Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions pylops/avo/avo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
from typing import List, Optional, Tuple, Union

import numpy as np
import numpy.typing as npt
from numpy import cos, sin, tan

from pylops import LinearOperator
from pylops.utils._internal import _value_or_sized_to_tuple
from pylops.utils.backend import get_array_module
from pylops.utils.decorators import reshaped
from pylops.utils.typing import DTypeLike, NDArray
from pylops.utils.typing import DTypeLike, NDArray, Tavolinearization


def zoeppritz_scattering(
Expand All @@ -29,7 +28,7 @@ def zoeppritz_scattering(
vp0: float,
vs0: float,
rho0: float,
theta1: Union[float, npt.ArrayLike],
theta1: Union[float, NDArray],
) -> NDArray:
r"""Zoeppritz solution.

Expand Down Expand Up @@ -250,12 +249,12 @@ def zoeppritz_pp(


def approx_zoeppritz_pp(
vp1: Union[List, Tuple, npt.ArrayLike],
vs1: Union[List, Tuple, npt.ArrayLike],
rho1: Union[List, Tuple, npt.ArrayLike],
vp0: Union[List, Tuple, npt.ArrayLike],
vs0: Union[List, Tuple, npt.ArrayLike],
rho0: Union[List, Tuple, npt.ArrayLike],
vp1: Union[List, Tuple, NDArray],
vs1: Union[List, Tuple, NDArray],
rho1: Union[List, Tuple, NDArray],
vp0: Union[List, Tuple, NDArray],
vs0: Union[List, Tuple, NDArray],
rho0: Union[List, Tuple, NDArray],
theta1: Union[float, NDArray],
) -> NDArray:
"""PP reflection coefficient from the approximate Zoeppritz equation.
Expand Down Expand Up @@ -335,7 +334,7 @@ def approx_zoeppritz_pp(


def akirichards(
theta: npt.ArrayLike,
theta: NDArray,
vsvp: Union[float, NDArray],
n: int = 1,
) -> Tuple[NDArray, NDArray, NDArray]:
Expand Down Expand Up @@ -409,7 +408,7 @@ def akirichards(


def fatti(
theta: npt.ArrayLike,
theta: NDArray,
vsvp: Union[float, NDArray],
n: int = 1,
) -> Tuple[NDArray, NDArray, NDArray]:
Expand Down Expand Up @@ -485,7 +484,7 @@ def fatti(


def ps(
theta: npt.ArrayLike,
theta: NDArray,
vsvp: Union[float, NDArray],
n: int = 1,
) -> Tuple[NDArray, NDArray, NDArray]:
Expand Down Expand Up @@ -650,7 +649,7 @@ def __init__(
vsvp: Union[float, NDArray] = 0.5,
nt0: int = 1,
spatdims: Optional[Union[int, Tuple[int]]] = None,
linearization: str = "akirich",
linearization: Tavolinearization = "akirich",
dtype: DTypeLike = "float64",
name: str = "A",
) -> None:
Expand Down
11 changes: 5 additions & 6 deletions pylops/avo/poststack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
"PoststackInversion",
]

from typing import Optional, Tuple, Union
from typing import Literal, Optional, Tuple, Union

import numpy as np
import numpy.typing as npt
from scipy.sparse.linalg import lsqr

from pylops import (
Expand Down Expand Up @@ -136,12 +135,12 @@ def _PoststackLinearModelling(


def PoststackLinearModelling(
wav: npt.ArrayLike,
wav: NDArray,
nt0: int,
spatdims: Optional[Union[int, ShapeLike]] = None,
explicit: bool = False,
sparse: bool = False,
kind: str = "centered",
kind: Literal["centered", "forward"] = "centered",
name: Optional[str] = None,
) -> LinearOperator:
r"""Post-stack linearized seismic modelling operator.
Expand Down Expand Up @@ -173,7 +172,7 @@ def PoststackLinearModelling(
Create a sparse matrix (``True``) or dense (``False``) when
``explicit=True``
kind : :obj:`str`, optional
Derivative kind (``forward`` or ``centered``).
Derivative kind (``centered`` or ``forward``).
name : :obj:`str`, optional
.. versionadded:: 2.0.0

Expand Down Expand Up @@ -224,7 +223,7 @@ def PoststackLinearModelling(

def PoststackInversion(
data: NDArray,
wav: npt.ArrayLike,
wav: NDArray,
m0: Optional[NDArray] = None,
explicit: bool = False,
simultaneous: bool = False,
Expand Down
18 changes: 9 additions & 9 deletions pylops/avo/prestack.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"PrestackInversion",
]

from typing import Optional, Tuple, Union
from typing import Callable, List, Literal, Optional, Tuple, Union

import numpy as np
from scipy.sparse.linalg import lsqr
Expand Down Expand Up @@ -33,7 +33,7 @@
inplace_set,
)
from pylops.utils.signalprocessing import convmtx
from pylops.utils.typing import NDArray, ShapeLike
from pylops.utils.typing import NDArray, ShapeLike, Tavolinearization

_linearizations = {"akirich": 3, "fatti": 3, "ps": 3}

Expand All @@ -44,9 +44,9 @@ def PrestackLinearModelling(
vsvp: Union[float, NDArray] = 0.5,
nt0: int = 1,
spatdims: Optional[Union[int, ShapeLike]] = None,
linearization: str = "akirich",
linearization: Tavolinearization = "akirich",
explicit: bool = False,
kind: str = "centered",
kind: Literal["centered", "forward"] = "centered",
name: Optional[str] = None,
) -> LinearOperator:
r"""Pre-stack linearized seismic modelling operator.
Expand Down Expand Up @@ -90,7 +90,7 @@ def PrestackLinearModelling(
or a ``MatrixMult`` linear operator with dense matrix
(``True``, preferred for small data)
kind : :obj:`str`, optional
Derivative kind (``forward`` or ``centered``).
Derivative kind (``centered`` or ``forward``).
name : :obj:`str`, optional
.. versionadded:: 2.0.0

Expand Down Expand Up @@ -228,7 +228,7 @@ def PrestackWaveletModelling(
nwav: int,
wavc: Optional[int] = None,
vsvp: Union[float, NDArray] = 0.5,
linearization: str = "akirich",
linearization: Union[Tavolinearization, Callable] = "akirich",
name: Optional[str] = None,
) -> LinearOperator:
r"""Pre-stack linearized seismic modelling operator for wavelet.
Expand Down Expand Up @@ -357,15 +357,15 @@ def PrestackInversion(
theta: NDArray,
wav: NDArray,
m0: Optional[NDArray] = None,
linearization: str = "akirich",
linearization: Union[Tavolinearization, List[Tavolinearization]] = "akirich",
explicit: bool = False,
simultaneous: bool = False,
epsI: Optional[float] = None,
epsR: Optional[float] = None,
dottest: bool = False,
returnres: bool = False,
epsRL1: Optional[float] = None,
kind: str = "centered",
kind: Literal["centered", "forward"] = "centered",
vsvp: Union[float, NDArray] = 0.5,
**kwargs_solver
) -> Union[NDArray, Tuple[NDArray, NDArray]]:
Expand Down Expand Up @@ -421,7 +421,7 @@ def PrestackInversion(
epsRL1 : :obj:`float`, optional
Damping factor for additional blockiness regularization term
kind : :obj:`str`, optional
Derivative kind (``forward`` or ``centered``).
Derivative kind (``centered`` or ``forward``).
vsvp : :obj:`float` or :obj:`numpy.ndarray`
:math:`V_S/V_P` ratio (constant or time/depth variant)
**kwargs_solver
Expand Down
4 changes: 2 additions & 2 deletions pylops/basicoperators/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pylops import LinearOperator
from pylops.basicoperators import HStack, VStack
from pylops.utils.typing import DTypeLike, NDArray
from pylops.utils.typing import DTypeLike, NDArray, Tparallel_kind


class _Block(LinearOperator):
Expand Down Expand Up @@ -154,7 +154,7 @@ def __init__(
ops: Iterable[Iterable[LinearOperator]],
nproc: int = 1,
forceflat: bool = None,
parallel_kind: str = "multiproc",
parallel_kind: Tparallel_kind = "multiproc",
dtype: Optional[DTypeLike] = None,
):
super().__init__(
Expand Down
8 changes: 4 additions & 4 deletions pylops/basicoperators/blockdiag.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from pylops import LinearOperator
from pylops.basicoperators import MatrixMult
from pylops.utils.backend import get_array_module, get_module, inplace_set
from pylops.utils.typing import DTypeLike, NDArray
from pylops.utils.typing import DTypeLike, NDArray, Tinoutengine, Tparallel_kind


def _matvec_rmatvec_map(op, x: NDArray) -> NDArray:
Expand Down Expand Up @@ -142,9 +142,9 @@ def __init__(
self,
ops: Sequence[LinearOperator],
nproc: int = 1,
forceflat: bool = None,
inoutengine: Optional[tuple] = None,
parallel_kind: str = "multiproc",
forceflat: Optional[bool] = None,
inoutengine: Optional[Tinoutengine] = None,
parallel_kind: Tparallel_kind = "multiproc",
dtype: Optional[DTypeLike] = None,
) -> None:
if parallel_kind not in ["multiproc", "multithread"]:
Expand Down
4 changes: 2 additions & 2 deletions pylops/basicoperators/causalintegration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__all__ = ["CausalIntegration"]

from typing import Union
from typing import Literal, Union

import numpy as np

Expand Down Expand Up @@ -101,7 +101,7 @@ def __init__(
dims: Union[int, InputDimsLike],
axis: int = -1,
sampling: float = 1,
kind: str = "full",
kind: Literal["full", "half", "trapezoidal"] = "full",
removefirst: bool = False,
dtype: DTypeLike = "float64",
name: str = "C",
Expand Down
33 changes: 24 additions & 9 deletions pylops/basicoperators/directionalderivative.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pylops import LinearOperator
from pylops.basicoperators import Diagonal, Gradient, Sum
from pylops.utils.typing import DTypeLike, InputDimsLike, NDArray
from pylops.utils.typing import DTypeLike, InputDimsLike, NDArray, Tderivkind


class FirstDirectionalDerivative(LinearOperator):
Expand Down Expand Up @@ -79,7 +79,7 @@ def __init__(
v: NDArray,
sampling: int = 1,
edge: bool = False,
kind: str = "centered",
kind: Tderivkind = "centered",
dtype: DTypeLike = "float64",
name: str = "F",
):
Expand All @@ -88,7 +88,12 @@ def __init__(
self.kind = kind
self.v = v
Op = self._calc_first_ddop(
dims=dims, sampling=sampling, edge=edge, kind=kind, dtype=dtype, v=v
dims=dims,
v=v,
sampling=sampling,
edge=edge,
kind=kind,
dtype=dtype,
)
super().__init__(Op=Op, name=name)

Expand All @@ -104,7 +109,7 @@ def _calc_first_ddop(
v: NDArray,
sampling: int,
edge: bool,
kind: str,
kind: Tderivkind,
dtype: DTypeLike,
):
Gop = Gradient(dims, sampling=sampling, edge=edge, kind=kind, dtype=dtype)
Expand Down Expand Up @@ -138,6 +143,10 @@ class SecondDirectionalDerivative(LinearOperator):
edge : :obj:`bool`, optional
Use reduced order derivative at edges (``True``) or
ignore them (``False``).
kind : :obj:`str`, optional
.. versionadded:: 2.7.0

Derivative kind (``forward``, ``centered``, or ``backward``).
dtype : :obj:`str`, optional
Type of elements in input array.

Expand Down Expand Up @@ -177,15 +186,16 @@ def __init__(
v: NDArray,
sampling: int = 1,
edge: bool = False,
kind: Tderivkind = "centered",
dtype: DTypeLike = "float64",
name: str = "S",
):
self.dims = dims
self.v = v
self.sampling = sampling
self.edge = edge
self.kind = kind
self.v = v
Op = self._calc_second_ddop(
dims=dims, v=v, sampling=sampling, edge=edge, dtype=dtype
dims=dims, v=v, sampling=sampling, edge=edge, kind=kind, dtype=dtype
)
super().__init__(Op=Op, name=name)

Expand All @@ -197,10 +207,15 @@ def _rmatvec(self, x: NDArray) -> NDArray:

@staticmethod
def _calc_second_ddop(
dims: InputDimsLike, v: NDArray, sampling: int, edge: bool, dtype: DTypeLike
dims: InputDimsLike,
v: NDArray,
sampling: int,
edge: bool,
kind: Tderivkind,
dtype: DTypeLike,
):
Dop = FirstDirectionalDerivative(
dims=dims, v=v, sampling=sampling, edge=edge, dtype=dtype
dims=dims, v=v, sampling=sampling, edge=edge, kind=kind, dtype=dtype
)
ddop = -Dop.H * Dop
return ddop
4 changes: 2 additions & 2 deletions pylops/basicoperators/firstderivative.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
inplace_set,
)
from pylops.utils.decorators import reshaped
from pylops.utils.typing import DTypeLike, InputDimsLike, NDArray
from pylops.utils.typing import DTypeLike, InputDimsLike, NDArray, Tderivkind


class FirstDerivative(LinearOperator):
Expand Down Expand Up @@ -94,7 +94,7 @@ def __init__(
dims: Union[int, InputDimsLike],
axis: int = -1,
sampling: float = 1.0,
kind: str = "centered",
kind: Tderivkind = "centered",
edge: bool = False,
order: int = 3,
dtype: DTypeLike = "float64",
Expand Down
4 changes: 2 additions & 2 deletions pylops/basicoperators/gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pylops import LinearOperator
from pylops.basicoperators import FirstDerivative, VStack
from pylops.utils._internal import _value_or_sized_to_tuple
from pylops.utils.typing import DTypeLike, InputDimsLike, NDArray
from pylops.utils.typing import DTypeLike, InputDimsLike, NDArray, Tderivkind


class Gradient(LinearOperator):
Expand Down Expand Up @@ -81,7 +81,7 @@ def __init__(
dims: Union[int, InputDimsLike],
sampling: int = 1,
edge: bool = False,
kind: str = "centered",
kind: Tderivkind = "centered",
dtype: DTypeLike = "float64",
name: str = "G",
):
Expand Down
Loading