functions.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:decode 作者: deshima-dev 项目源码 文件源码
def savgol_filter(array, win=2001, polyn=3, iteration=1, threshold=1):
    """Apply scipy.signal.savgol_filter iteratively.

    Args:
        array (decode.array): Decode array which will be filtered.
        win (int): Length of window.
        polyn (int): Order of polynominal function.
        iteration (int): The number of iterations.
        threshold (float): Threshold above which the data will be used as signals
            in units of sigma.

    Returns:
        fitted (decode.array): Fitted results.
    """
    logger = getLogger('decode.models.savgol_filter')
    logger.warning('Do not use this function. We recommend you to use dc.models.pca instead.')
    logger.info('win polyn iteration threshold')
    logger.info('{} {} {} {}'.format(win, polyn, iteration, threshold))
    ### 1st estimation
    array    = array.copy()
    fitted   = signal.savgol_filter(array, win, polyn, axis=0)
    filtered = array - fitted
    ### nth iteration
    for i in range(iteration):
        sigma  = filtered.std(axis=0)
        mask   = (filtered >= threshold * sigma)
        masked = np.ma.array(filtered, mask=mask)
        ### mask?????????threshold * sigma????????
        filled = masked.filled(threshold * sigma)
        ### fitted data???????????????savgol_filter????
        clipped  = filled + fitted
        fitted   = signal.savgol_filter(clipped, win, polyn, axis=0)
        filtered = array - fitted

    return fitted
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号