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


Python filters.convolve1d方法代码示例

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


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

示例1: smooth1d

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import convolve1d [as 别名]
def smooth1d(array, window_size=None, kernel='gaussian'):
    """Apply a centered window smoothing to a 1D array.

    Parameters
    ----------
    array : ndarray
        the array to apply the smoothing to
    window_size : int
        the size of the smoothing window
    kernel : str
        the type of smoothing (`gaussian`, `mean`)

    Returns
    -------
    the smoothed array (same dim as input)
    """

    # some defaults
    if window_size is None:
        if len(array) >= 9:
            window_size = 9
        elif len(array) >= 7:
            window_size = 7
        elif len(array) >= 5:
            window_size = 5
        elif len(array) >= 3:
            window_size = 3

    if window_size % 2 == 0:
        raise ValueError('Window should be an odd number.')

    if isinstance(kernel, str):
        if kernel == 'gaussian':
            kernel = gaussian(window_size, 1)
        elif kernel == 'mean':
            kernel = np.ones(window_size)
        else:
            raise NotImplementedError('Kernel: ' + kernel)
    kernel = kernel / np.asarray(kernel).sum()
    return filters.convolve1d(array, kernel, mode='mirror') 
开发者ID:OGGM,项目名称:oggm,代码行数:42,代码来源:_funcs.py

示例2: temporal_feature_smoothing

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import convolve1d [as 别名]
def temporal_feature_smoothing(video_features, kernel):
    #simple 1d convolution assuming that input is time x words x descriptors
    return convolve1d(video_features, weights = kernel, axis = 0) 
开发者ID:VisionLearningGroup,项目名称:caption-guided-saliency,代码行数:5,代码来源:visualization.py

示例3: convolve

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import convolve1d [as 别名]
def convolve(sequence, rule, **kwds):
    """Wrapper around scipy.ndimage.convolve1d that allows complex input."""
    dtype = np.result_type(float, np.ravel(sequence)[0])
    seq = np.asarray(sequence, dtype=dtype)
    if np.iscomplexobj(seq):
        return (convolve1d(seq.real, rule, **kwds) + 1j * convolve1d(seq.imag, rule, **kwds))
    return convolve1d(seq, rule, **kwds) 
开发者ID:pbrod,项目名称:numdifftools,代码行数:9,代码来源:extrapolation.py

示例4: h__foragingData

# 需要导入模块: from scipy.ndimage import filters [as 别名]
# 或者: from scipy.ndimage.filters import convolve1d [as 别名]
def h__foragingData(self, fps, nose_bend_angle_d, min_win_size):
        """
        Compute the foraging amplitude and angular speed.

        Parameters
        ----------
        fps :
        nose_bend_angle_d : [n_frames x 1]
        min_win_size : (scalar)

        Returns
        ---------------------------------------
        amplitudes : [1 x n_frames]
        speeds : [1 x n_frames]

        Notes
        ---------------------------------------
        Formerly [amps,speeds] = h__foragingData(nose_bend_angle_d,
                                                 min_win_size, fps)

        """
        if min_win_size > 0:
            # Clean up the signal with a gaussian filter.
            gauss_filter = utils.gausswin(2 * min_win_size + 1) / min_win_size
            nose_bend_angle_d = filters.convolve1d(nose_bend_angle_d,
                                                   gauss_filter,
                                                   cval=0,
                                                   mode='constant')

            # Remove partial data frames ...
            nose_bend_angle_d[:min_win_size] = np.NaN
            nose_bend_angle_d[-min_win_size:] = np.NaN

        # Calculate amplitudes
        amplitudes = self.h__getAmplitudes(nose_bend_angle_d)
        assert(np.shape(nose_bend_angle_d) == np.shape(amplitudes))

        # Calculate angular speed
        # Compute the speed centered between the back and front foraging movements.
        #
        # TODO: fix the below comments to conform to 0-based indexing
        # I believe I've fixed the code already.  - @MichaelCurrie
        #  1     2    3
        # d1    d2     d1 = 2 - 1,   d2 = 3 - 2
        #     x        assign to x, avg of d1 and d2

        #???? - why multiply and not divide by fps????

        d_data = np.diff(nose_bend_angle_d) * fps
        speeds = np.empty(amplitudes.size) * np.NaN
        # This will leave the first and last frame's speed as NaN:
        speeds[1:-1] = (d_data[:-1] + d_data[1:]) / 2

        # Propagate NaN for speeds to amplitudes
        amplitudes[np.isnan(speeds)] = np.NaN

        return amplitudes, speeds 
开发者ID:ver228,项目名称:tierpsy-tracker,代码行数:59,代码来源:locomotion_bends.py


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