How to use the pylops.LinearOperator function in pylops

To help you get started, we’ve selected a few pylops examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github equinor / pylops / pytests / test_sliding.py View on Github external
par['ny'] * par['nx'] * par['nt'])))

    Slid = Sliding3D(Op,
                     dims=(par['ny']*par['winsy'],
                           par['nx']*par['winsx'], par['nt']),
                     dimsd=(par['npy'], par['npx'], par['nt']),
                     nwin=(par['nwiny'], par['nwinx']),
                     nover=(par['novery'], par['noverx']),
                     nop=(par['ny'], par['nx']),
                     tapertype=par['tapertype'])
    assert dottest(Slid, par['npy']*par['npx']*par['nt'],
                   par['ny']*par['nx']*par['nt']*par['winsy']*par['winsx'])
    x = np.ones((par['ny']*par['nx']*par['winsy']*par['winsx'], par['nt']))
    y = Slid * x.flatten()

    xinv = LinearOperator(Slid) / y
    assert_array_almost_equal(x.flatten(), xinv)
github equinor / pylops / pylops / signalprocessing / DWT2D.py View on Github external
from math import log, ceil

import numpy as np
from pylops import LinearOperator
from pylops.basicoperators import Pad
from .DWT import _checkwavelet, _adjointwavelet

try:
    import pywt
except ModuleNotFoundError:
    pywt = None

logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.WARNING)


class DWT2D(LinearOperator):
    """Two dimensional Wavelet operator.

    Apply 2D-Wavelet Transform along two directions ``dirs`` of a
    multi-dimensional array of size ``dims``.

    Note that the Wavelet operator is an overload of the ``pywt``
    implementation of the wavelet transform. Refer to
    https://pywavelets.readthedocs.io for a detailed description of the
    input parameters.

    Parameters
    ----------
    dims : :obj:`tuple`
        Number of samples for each dimension
    dirs : :obj:`tuple`, optional
        Direction along which DWT2D is applied.
github equinor / pylops / pylops / basicoperators / Transpose.py View on Github external
import numpy as np
from pylops import LinearOperator


class Transpose(LinearOperator):
    r"""Transpose operator.

    Transpose axes of a multi-dimensional array. This operator works with
    flattened input model (or data), which are however multi-dimensional in
    nature and will be reshaped and treated as such in both forward and adjoint
    modes.

    Parameters
    ----------
    dims : :obj:`tuple`, optional
        Number of samples for each dimension
    axes : :obj:`tuple`, optional
        Direction along which transposition is applied
    dtype : :obj:`str`, optional
        Type of elements in input array
github equinor / pylops / pylops / basicoperators / Identity.py View on Github external
import numpy as np
from pylops import LinearOperator


class Identity(LinearOperator):
    r"""Identity operator.

    Simply move model to data in forward model and viceversa in adjoint mode if
    :math:`M = N`. If :math:`M > N` removes last :math:`M - N` elements from
    model in forward and pads with :math:`0` in adjoint. If :math:`N > M`
    removes last :math:`N - M` elements from data in adjoint and pads with
    :math:`0` in forward.

    Parameters
    ----------
    N : :obj:`int`
        Number of samples in data (and model, if ``M`` is not provided).
    M : :obj:`int`, optional
        Number of samples in model.
    dtype : :obj:`str`, optional
        Type of elements in input array.
github equinor / pylops / pylops / basicoperators / Diagonal.py View on Github external
import numpy as np
from pylops import LinearOperator


class Diagonal(LinearOperator):
    r"""Diagonal operator.

    Applies element-wise multiplication of the input vector with the vector
    ``diag`` in forward and with its complex conjugate in adjoint mode.

    This operator can also broadcast; in this case the input vector is
    reshaped into its dimensions ``dims`` and the element-wise multiplication
    with ``diag`` is perfomed on the direction ``dir``. Note that the
    vector ``diag`` will need to have size equal to ``dims[dir]``.

    Parameters
    ----------
    diag : :obj:`numpy.ndarray`
        Vector to be used for element-wise multiplication.
    dims : :obj:`list`, optional
        Number of samples for each dimension
github equinor / pylops / pylops / basicoperators / HStack.py View on Github external
import numpy as np
from scipy.sparse.linalg.interface import _get_dtype
from scipy.sparse.linalg.interface import LinearOperator as spLinearOperator
from pylops import LinearOperator
from pylops.basicoperators import MatrixMult


class HStack(LinearOperator):
    r"""Horizontal stacking.

    Stack a set of N linear operators horizontally.

    Parameters
    ----------
    ops : :obj:`list`
        Linear operators to be stacked. Alternatively,
        :obj:`numpy.ndarray` or :obj:`scipy.sparse` matrices can be passed
        in place of one or more operators.

    dtype : :obj:`str`, optional
        Type of elements in input array.

    Attributes
    ----------
github equinor / pylops / pylops / signalprocessing / FFT.py View on Github external
try:
    import pyfftw
except ModuleNotFoundError:
    pyfftw = None
    pyfftw_message = 'Pyfftw not installed, use numpy or run ' \
                     '"pip install pyFFTW" or ' \
                     '"conda install -c conda-forge pyfftw".'
except Exception as e:
    pyfftw = None
    pyfftw_message = 'Failed to import pyfftw (error:%s), use numpy.' % e

logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.WARNING)


class _FFT_numpy(LinearOperator):
    """One dimensional Fast-Fourier Transform using numpy
    """
    def __init__(self, dims, dir=0, nfft=None, sampling=1.,
                 real=False, fftshift=False, dtype='complex128'):
        if isinstance(dims, int):
            dims = (dims,)
        if dir > len(dims)-1:
            raise ValueError('dir=%d must be smaller than '
                             'number of dims=%d...' % (dir, len(dims)))
        self.dir = dir
        self.nfft = nfft if nfft is not None else dims[self.dir]
        self.real = real
        self.fftshift = fftshift
        self.f = np.fft.rfftfreq(self.nfft, d=sampling) if real \
                 else np.fft.fftfreq(self.nfft, d=sampling)
        if len(dims) == 1:
github equinor / pylops / pylops / basicoperators / SecondDerivative.py View on Github external
import numpy as np
from pylops import LinearOperator


class SecondDerivative(LinearOperator):
    r"""Second derivative.

    Apply second-order second derivative.

    Parameters
    ----------
    N : :obj:`int`
        Number of samples in model.
    dims : :obj:`tuple`, optional
        Number of samples for each dimension
        (``None`` if only one dimension is available)
    dir : :obj:`int`, optional
        Direction along which smoothing is applied.
    sampling : :obj:`float`, optional
        Sampling step ``dx``.
    edge : :obj:`bool`, optional
github equinor / pylops / pylops / basicoperators / CausalIntegration.py View on Github external
import numpy as np
from pylops import LinearOperator


class CausalIntegration(LinearOperator):
    r"""Causal integration.

    Apply causal integration to a multi-dimensional array along ``dir`` axis.

    Parameters
    ----------
    N : :obj:`int`
        Number of samples in model.
    dims : :obj:`list`, optional
        Number of samples for each dimension
        (``None`` if only one dimension is available)
    dir : :obj:`int`, optional
        Direction along which smoothing is applied.
    sampling : :obj:`float`, optional
        Sampling step ``dx``.
    halfcurrent : :obj:`float`, optional
github equinor / pylops / pylops / basicoperators / FunctionOperator.py View on Github external
from numbers import Integral
from pylops import LinearOperator


class FunctionOperator(LinearOperator):
    r"""Function Operator.

    Simple wrapper to functions for forward `f` and adjoint `fc`
    multiplication.

    Functions :math:`f` and :math:`fc` are such that
    :math:`f:\mathbb{F}^m \to \mathbb{F}^n` and
    :math:`fc:\mathbb{F}^n \to \mathbb{F}^m` where :math:`\mathbb{F}` is
    the appropriate underlying type (e.g., :math:`\mathbb{R}` for real or
    :math:`\mathbb{C}` for complex)

    FunctionOperator can be called in the following ways:
    ``FunctionOperator(f, n)``, ``FunctionOperator(f, n, m)``,
    ``FunctionOperator(f, fc, n)``, and ``FunctionOperator(f, fc, n, m)``.

    The first two methods can only be used for forward modelling and