当前位置: 首页>>代码示例>>Python>>正文


Python signal.convolve方法代码示例

本文整理汇总了Python中scipy.signal.convolve方法的典型用法代码示例。如果您正苦于以下问题:Python signal.convolve方法的具体用法?Python signal.convolve怎么用?Python signal.convolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.signal的用法示例。


在下文中一共展示了signal.convolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: comp_induce_potential

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import convolve [as 别名]
def comp_induce_potential(self):
        """
            Compute the induce potential corresponding to the density change
            calculated in get_spatial_density
        """

        from scipy.signal import convolve

        Nx, Ny, Nz = self.mesh[0].size, self.mesh[1].size, self.mesh[2].size

        grid = np.zeros((Nx, Ny, Nz), dtype = np.float64)
        factor = self.dr[0]*self.dr[1]*self.dr[2]/(np.sqrt(2*np.pi)**3)

        libnao.comp_spatial_grid_pot(
            self.dr.ctypes.data_as(POINTER(c_double)), 
            self.mesh[0].ctypes.data_as(POINTER(c_double)),
            self.mesh[1].ctypes.data_as(POINTER(c_double)),
            self.mesh[2].ctypes.data_as(POINTER(c_double)),
            grid.ctypes.data_as(POINTER(c_double)),
            c_int(Nx), c_int(Ny), c_int(Nz))

        return convolve(grid, self.dn_spatial, mode="same", method="fft")*factor 
开发者ID:pyscf,项目名称:pyscf,代码行数:24,代码来源:m_comp_spatial_distributions.py

示例2: convolve2d

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import convolve [as 别名]
def convolve2d(in1, in2, mode='full'):
    """
        note only support H * W * N * 1 convolve 2d
    """
    in1 = in1.transpose(2, 3, 0, 1) # to N * C * H * W
    in2 = in2.transpose(2, 3, 0, 1)
    out_c, _, kh, kw = in2.shape
    n, _, h, w = in1.shape

    if mode == 'full':
        ph, pw = kh-1, kw-1
        out_h, out_w = h-kh+1+ph*2, w-kw+1+pw*2# TODO
    elif mode == 'valid':
        ph, pw = 0, 0
        out_h, out_w = h-kh+1, w-kw+1 # TODO
    else:
        raise NotImplementedError

    y = cp.empty((n, out_c, out_h, out_w), dtype=in1.dtype)

    col = im2col_gpu(in1, kh, kw, 1, 1, ph, pw)
    y = cp.tensordot(
            col, in2, ((1, 2, 3), (1, 2, 3))).astype(in1.dtype, copy=False)
    y = cp.rollaxis(y, 3, 1)
    return y.transpose(2, 3, 0, 1) 
开发者ID:StrangerZhang,项目名称:pyECO,代码行数:27,代码来源:cuda_tools.py

示例3: test_valid_mode2

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import convolve [as 别名]
def test_valid_mode2(self):
        # See gh-5897
        a = [1, 2, 3, 6, 5, 3]
        b = [2, 3, 4, 5, 3, 4, 2, 2, 1]
        expected = [70, 78, 73, 65]

        out = convolve(a, b, 'valid')
        assert_array_equal(out, expected)

        out = convolve(b, a, 'valid')
        assert_array_equal(out, expected)

        a = [1 + 5j, 2 - 1j, 3 + 0j]
        b = [2 - 3j, 1 + 0j]
        expected = [2 - 3j, 8 - 10j]

        out = convolve(a, b, 'valid')
        assert_array_equal(out, expected)

        out = convolve(b, a, 'valid')
        assert_array_equal(out, expected) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:23,代码来源:test_signaltools.py

示例4: sample

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import convolve [as 别名]
def sample(self, x_instrument, wl_hi, rdn_hi):
        """Apply instrument sampling to a radiance spectrum, returning predicted measurement."""

        if self.calibration_fixed and all((self.wl_init - wl_hi) < wl_tol):
            return rdn_hi
        wl, fwhm = self.calibration(x_instrument)
        if rdn_hi.ndim == 1:
            return resample_spectrum(rdn_hi, wl_hi, wl, fwhm)
        else:
            resamp = []
            # The "fast resample" option approximates a complete resampling
            # by a convolution with a uniform FWHM.
            if self.fast_resample:
                for i, r in enumerate(rdn_hi):
                    ssrf = spectral_response_function(np.arange(-10, 11), 0, fwhm[0])
                    blur = convolve(r, ssrf, mode='same')
                    resamp.append(interp1d(wl_hi, blur)(wl))
            else:
                for i, r in enumerate(rdn_hi):
                    r2 = resample_spectrum(r, wl_hi, wl, fwhm)
                    resamp.append(r2)
            return np.array(resamp) 
开发者ID:isofit,项目名称:isofit,代码行数:24,代码来源:instrument.py

示例5: test_convolve_generalization

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import convolve [as 别名]
def test_convolve_generalization():
        ag_convolve = autograd.scipy.signal.convolve
        A_35 = R(3, 5)
        A_34 = R(3, 4)
        A_342 = R(3, 4, 2)
        A_2543 = R(2, 5, 4, 3)
        A_24232 = R(2, 4, 2, 3, 2)

        for mode in ['valid', 'full']:
            assert npo.allclose(ag_convolve(A_35,      A_34, axes=([1], [0]), mode=mode)[1, 2],
                                sp_convolve(A_35[1,:], A_34[:, 2], mode))
            assert npo.allclose(ag_convolve(A_35, A_34, axes=([],[]), dot_axes=([0], [0]), mode=mode),
                                npo.tensordot(A_35, A_34, axes=([0], [0])))
            assert npo.allclose(ag_convolve(A_35, A_342, axes=([1],[2]),
                                            dot_axes=([0], [0]), mode=mode)[2],
                                sum([sp_convolve(A_35[i, :], A_342[i, 2, :], mode)
                                    for i in range(3)]))
            assert npo.allclose(ag_convolve(A_2543, A_24232, axes=([1, 2],[2, 4]),
                                            dot_axes=([0, 3], [0, 3]), mode=mode)[2],
                                sum([sum([sp_convolve(A_2543[i, :, :, j],
                                                    A_24232[i, 2, :, j, :], mode)
                                        for i in range(2)]) for j in range(3)])) 
开发者ID:HIPS,项目名称:autograd,代码行数:24,代码来源:test_scipy.py

示例6: comp_induce_field

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import convolve [as 别名]
def comp_induce_field(self):
        """
            Compute the induce Electric field corresponding to the density change
            calculated in get_spatial_density
        """
        
        from scipy.signal import convolve

        Nx, Ny, Nz = self.mesh[0].size, self.mesh[1].size, self.mesh[2].size

        Efield = np.zeros((3, Nx, Ny, Nz), dtype = np.complex64)
        grid = np.zeros((Nx, Ny, Nz), dtype = np.float64)
        factor = self.dr[0]*self.dr[1]*self.dr[2]/(np.sqrt(2*np.pi)**3)

        for xyz in range(3):
            grid.fill(0.0)
            libnao.comp_spatial_grid(
                self.dr.ctypes.data_as(POINTER(c_double)), 
                self.mesh[0].ctypes.data_as(POINTER(c_double)),
                self.mesh[1].ctypes.data_as(POINTER(c_double)),
                self.mesh[2].ctypes.data_as(POINTER(c_double)),
                c_int(xyz+1), 
                grid.ctypes.data_as(POINTER(c_double)),
                c_int(Nx), c_int(Ny), c_int(Nz))

            Efield[xyz, :, :, :] = convolve(grid, self.dn_spatial, 
                                            mode="same", method="fft")*factor

        return Efield 
开发者ID:pyscf,项目名称:pyscf,代码行数:31,代码来源:m_comp_spatial_distributions.py

示例7: _smooth

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import convolve [as 别名]
def _smooth(data, sd):
    from scipy.signal import gaussian
    from scipy.signal import convolve
    n_bins = data.shape[0]
    w = n_bins - 1 if n_bins % 2 == 0 else n_bins
    window = gaussian(w, std=sd)
    for j in range(data.shape[1]):
        data[:, j] = convolve(data[:, j], window, mode='same', method='auto')
    return data 
开发者ID:int-brain-lab,项目名称:ibllib,代码行数:11,代码来源:cca.py

示例8: velocity_smoothed

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import convolve [as 别名]
def velocity_smoothed(pos, freq, smooth_size=0.03):
    """
    Compute wheel velocity from uniformly sampled wheel data

    Parameters
    ----------
    pos : array_like
        Array of wheel positions
    smooth_size : float
        Size of Gaussian smoothing window in seconds
    freq : float
        Sampling frequency of the data

    Returns
    -------
    vel : np.ndarray
        Array of velocity values
    acc : np.ndarray
        Array of acceleration values
    """
    # Define our smoothing window with an area of 1 so the units won't be changed
    stdSamps = np.round(smooth_size * freq)  # Standard deviation relative to sampling frequency
    N = stdSamps * 6  # Number of points in the Gaussian
    gauss_std = (N - 1) / 6  # @fixme magic number everywhere!
    win = gaussian(N, gauss_std)
    win = win / win.sum()  # Normalize amplitude

    # Convolve and multiply by sampling frequency to restore original units
    vel = np.insert(convolve(np.diff(pos), win, mode='same'), 0, 0) * freq
    acc = np.insert(convolve(np.diff(vel), win, mode='same'), 0, 0) * freq

    return vel, acc 
开发者ID:int-brain-lab,项目名称:ibllib,代码行数:34,代码来源:wheel.py

示例9: test_direct2D

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import convolve [as 别名]
def test_direct2D():
    """Check consistency of analytical 2D Green's function with FD modelling
    """
    inputdata = np.load(inputfile2d)

    # Receivers
    r = inputdata['r']
    nr = r.shape[1]

    # Virtual points
    vs = inputdata['vs']

    # Time axis
    t = inputdata['t']
    dt, nt = t[1] - t[0], len(t)

    # FD GF
    G0FD = inputdata['G0sub']
    wav = inputdata['wav']
    wav_c = np.argmax(wav)

    G0FD = np.apply_along_axis(convolve, 0, G0FD, wav, mode='full')
    G0FD = G0FD[wav_c:][:nt]

    # Analytic GF
    trav = np.sqrt((vs[0] - r[0]) ** 2 + (vs[1] - r[1]) ** 2) / vel
    G0ana = directwave(wav, trav, nt, dt, nfft=nt, derivative=False)

    # Differentiate to get same response as in FD modelling
    G0ana = np.diff(G0ana, axis=0)
    G0ana = np.vstack([G0ana, np.zeros(nr)])

    assert_array_almost_equal(G0FD / np.max(np.abs(G0FD)),
                              G0ana / np.max(np.abs(G0ana)), decimal=1) 
开发者ID:equinor,项目名称:pylops,代码行数:36,代码来源:test_directwave.py

示例10: test_direct3D

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import convolve [as 别名]
def test_direct3D():
    """Check consistency of analytical 3D Green's function with FD modelling
    """
    inputdata = np.load(inputfile3d)

    # Receivers
    r = inputdata['r']
    nr = r.shape[0]

    # Virtual points
    vs = inputdata['vs']

    # Time axis
    t = inputdata['t']
    dt, nt = t[1] - t[0], len(t)

    # FD GF
    G0FD = inputdata['G0'][:, :nr]
    wav = inputdata['wav']
    wav_c = np.argmax(wav)

    G0FD = np.apply_along_axis(convolve, 0, G0FD, wav, mode='full')
    G0FD = G0FD[wav_c:][:nt]

    # Analytic GF
    dist = np.sqrt((vs[0] - r[:, 0]) ** 2 +
                   (vs[1] - r[:, 1]) ** 2 +
                   (vs[2] - r[:, 2]) ** 2)
    trav = dist / vel
    G0ana = directwave(wav, trav, nt, dt, nfft=nt, dist=dist,
                       kind='3d', derivative=False)

    # Differentiate to get same response as in FD modelling
    G0ana = np.diff(G0ana, axis=0)
    G0ana = np.vstack([G0ana, np.zeros(nr)])

    assert_array_almost_equal(G0FD / np.max(np.abs(G0FD)),
                              G0ana / np.max(np.abs(G0ana)), decimal=1) 
开发者ID:equinor,项目名称:pylops,代码行数:40,代码来源:test_directwave.py

示例11: _matvec

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import convolve [as 别名]
def _matvec(self, x):
        x = np.reshape(x, self.dims)
        y = convolve(x, self.h, mode='same', method=self.method)
        y = y.ravel()
        return y 
开发者ID:equinor,项目名称:pylops,代码行数:7,代码来源:ConvolveND.py

示例12: __call__

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import convolve [as 别名]
def __call__(self, pkg):
        pkg = format_package(pkg)
        wav = pkg['chunk']
        # sample an ir_file
        ir_file = self.sample_IR()
        IR, p_max = self.load_IR(ir_file, self.ir_fmt)
        IR = IR.astype(np.float32)
        wav = wav.data.numpy().reshape(-1)
        Ex = np.dot(wav, wav)
        wav = wav.astype(np.float32).reshape(-1)
        # wav = wav / np.max(np.abs(wav))
        # rev = signal.fftconvolve(wav, IR, mode='full')
        rev = signal.convolve(wav, IR, mode='full').reshape(-1)
        Er = np.dot(rev, rev)
        # rev = rev / np.max(np.abs(rev))
        # IR delay compensation
        rev = self.shift(rev, -p_max)
        if Er > 0:
            Eratio = np.sqrt(Ex / Er) 
        else:
            Eratio = 1.0
            #rev = rev / np.max(np.abs(rev))

        # Trim rev signal to match clean length
        rev = rev[:wav.shape[0]]
        rev = Eratio * rev
        rev = torch.FloatTensor(rev)
        if self.report:
            if 'report' not in pkg:
                pkg['report'] = {}
            pkg['report']['ir_file'] = ir_file
        pkg['chunk'] = rev
        return pkg 
开发者ID:santi-pdp,项目名称:pase,代码行数:35,代码来源:transforms.py

示例13: fftconvolve_old

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import convolve [as 别名]
def fftconvolve_old(in1, in2, in3=None, mode="full"):
    """Convolve two N-dimensional arrays using FFT. See convolve.

    copied from scipy.signal.signaltools, but here used to try out inverse filter
    doesn't work or I can't get it to work

     2010-10-23:
    looks ok to me for 1d,
    from results below with padded data array (fftp)
    but it doesn't work for multidimensional inverse filter (fftn)
    original signal.fftconvolve also uses fftn

    """
    s1 = array(in1.shape)
    s2 = array(in2.shape)
    complex_result = (np.issubdtype(in1.dtype, np.complex) or
                      np.issubdtype(in2.dtype, np.complex))
    size = s1+s2-1

    # Always use 2**n-sized FFT
    fsize = 2**np.ceil(np.log2(size))
    IN1 = fftn(in1,fsize)
    #IN1 *= fftn(in2,fsize) #JP: this looks like the only change I made
    IN1 /= fftn(in2,fsize)  # use inverse filter
    # note the inverse is elementwise not matrix inverse
    # is this correct, NO  doesn't seem to work for VARMA
    fslice = tuple([slice(0, int(sz)) for sz in size])
    ret = ifftn(IN1)[fslice].copy()
    del IN1
    if not complex_result:
        ret = ret.real
    if mode == "full":
        return ret
    elif mode == "same":
        if product(s1,axis=0) > product(s2,axis=0):
            osize = s1
        else:
            osize = s2
        return _centered(ret,osize)
    elif mode == "valid":
        return _centered(ret,abs(s2-s1)+1) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:43,代码来源:try_var_convolve.py

示例14: test_basic

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import convolve [as 别名]
def test_basic(self):
        a = [3,4,5,6,5,4]
        b = [1,2,3]
        c = convolve(a,b)
        assert_array_equal(c,array([3,10,22,28,32,32,23,12])) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,代码来源:test_signaltools.py

示例15: test_complex

# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import convolve [as 别名]
def test_complex(self):
        x = array([1+1j, 2+1j, 3+1j])
        y = array([1+1j, 2+1j])
        z = convolve(x, y)
        assert_array_equal(z, array([2j, 2+6j, 5+8j, 5+5j])) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,代码来源:test_signaltools.py


注:本文中的scipy.signal.convolve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。