移位插值未提供预期的行为 [英] Shift interpolation does not give expected behaviour

查看:133
本文介绍了移位插值未提供预期的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 scipy时. ndimage.interpolation.shift 使用周期性边界处理(mode = 'wrap')沿一个轴移动numpy数据数组,我得到了意外的行为.该例程尝试强制第一个像素(index 0)与最后一个像素(index N-1)相同,而不是最后一个加一个(index N)".

When using scipy.ndimage.interpolation.shift to shift a numpy data array along one axis with periodic boundary treatment (mode = 'wrap'), I get an unexpected behavior. The routine tries to force the first pixel (index 0) to be identical to the last one (index N-1) instead of the "last plus one (index N)".

最小示例:

# module import
import numpy as np
from scipy.ndimage.interpolation import shift
import matplotlib.pyplot as plt

# print scipy.__version__
# 0.18.1

a = range(10)

plt.figure(figsize=(16,12))

for i, shift_pix in enumerate(range(10)):
    # shift the data via spline interpolation
    b = shift(a, shift=shift_pix, mode='wrap')

    # plotting the data
    plt.subplot(5,2,i+1)
    plt.plot(a, marker='o', label='data')
    plt.plot(np.roll(a, shift_pix), marker='o', label='data, roll')
    plt.plot(b, marker='o',label='shifted data')
    if i == 0:
        plt.legend(loc=4,fontsize=12)
    plt.ylim(-1,10)
    ax = plt.gca()
    ax.text(0.10,0.80,'shift %d pix' % i, transform=ax.transAxes)

蓝线:移位前的数据
绿线:预期的换档行为
红线: scipy.ndimage.interpolation.shift

Blue line: data before the shift
Green line: expected shift behavior
Red line: actual shift output of scipy.ndimage.interpolation.shift

在调用函数或使用mode = 'wrap'理解函数时是否存在一些错误?当前结果与相关 scipy教程页面,并从另一个

Is there some error in how I call the function or how I understand its behavior with mode = 'wrap'? The current results are in contrast to the mode parameter description from the related scipy tutorial page and from another StackOverflow post. Is there an off-by-one-error in the code?

使用的Scipy版本为0.18.1,分布在anaconda-2.2.0中

Scipy version used is 0.18.1, distributed in anaconda-2.2.0

推荐答案

值得注意的是,此行为似乎是一个错误,如本SciPy问题中所述: https://github.com/scipy/scipy/issues/2640

It is worth noting that this behavior appears to be a bug, as noted in this SciPy issue: https://github.com/scipy/scipy/issues/2640

该问题似乎会影响除mode='mirror'之外的scipy.ndimage中的所有mode外推.

The issue appears to effect every extrapolation mode in scipy.ndimage other than mode='mirror'.

这篇关于移位插值未提供预期的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆