def test_smooth_1d():
for edge in ['m', 'c']:
for N in [20,21]:
# values in [9.0,11.0]
x = rand(N) + 10
mn = 9.0
mx = 11.0
for M in range(18,27):
print "1d", edge, "N=%i, M=%i" %(N,M)
xsm = smooth(x, gaussian(M,2.0), edge=edge)
assert len(xsm) == N
# (N,1) case
xsm2 = smooth(x[:,None], gaussian(M,2.0)[:,None], edge=edge)
assert np.allclose(xsm, xsm2[:,0], atol=1e-14, rtol=1e-12)
# Smoothed signal should not go to zero if edge effects are handled
# properly. Also assert proper normalization (i.e. smoothed signal
# is "in the middle" of the noisy original data).
assert xsm.min() >= mn
assert xsm.max() <= mx
assert mn <= xsm[0] <= mx
assert mn <= xsm[-1] <= mx
# convolution with delta peak produces same data exactly
assert np.allclose(smooth(x, np.array([0.0,1,0]), edge=edge),x, atol=1e-14,
rtol=1e-12)
评论列表
文章目录