filtlib.py 文件源码

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

项目:pygeotools 作者: dshean 项目源码 文件源码
def rolling_fltr(dem, f=np.nanmedian, size=3, circular=True):
    """General rolling filter (default operator is median filter)

    Can input any function f

    Efficient for smaller arrays, correclty handles NaN, fills gaps
    """
    dem = malib.checkma(dem)
    newshp = (dem.size, size*size)
    #Force a step size of 1
    t = malib.sliding_window_padded(dem.filled(np.nan), (size, size), (1, 1))
    if circular:
        mask = circular_mask(size)
        t[:,mask] = np.nan
    t = t.reshape(newshp)
    out = f(t, axis=1).reshape(dem.shape)
    out = np.ma.fix_invalid(out).astype(dem.dtype)
    out.set_fill_value(dem.fill_value)
    return out
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号