平均不均匀采样的d

2024-10-06 06:57:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我的数据包括到地面的径向距离,每隔d_theta均匀取样。我想对它做高斯平滑处理,但是要使平滑窗口的大小在x上是一个常数,而不是一个恒定的点数。这样做的好方法是什么?在

我做了一个函数来做它,但是它很慢,我甚至还没有加入计算边缘的部分。在

如果这有助于更快地完成,我想你可以假设地板是平的,然后用它来计算采样点的数量,而不是使用实际的x值。在

以下是我目前所做的尝试:

bs = [gaussian(2*n-1,n/2) for n in range (1,500)] #bring the computation of the
bs = [b/b.sum() for b in bs]                      #gaussian outside to speed it up

def uneven_gauss_smoothing(xvals,yvals,sigma):
    newy = []
    for i, xval in enumerate (xvals):

        #find how big the window should be to have the chosen sigma 
        #(or .5*sigma, whatever):
        wheres = np.where(xvals> xval + sigma )[0]
        iright = wheres[0] -i if len(wheres) else 100 
        if i - iright < 0 : 
            newy.append(0)          #not implemented yet
            continue
        if i + iright >= len(xvals):
            newy.append(0)          #not implemented
            continue
        else:
            #weighted average with gaussian curve:
            newy.append((yvals[i-iright:i+iright+1]*bs[iright]).sum())
    return np.array(newy)

抱歉,这有点混乱——调试是如此令人难以置信的令人沮丧,以至于我最终使用了第一个解决方案(通常是一个很难阅读的解决方案)来解决突然出现的一些问题。但它的作用是有限的。在


Tags: thetoinforifbsgaussiansigma