简体   繁体   English

带有scipy.signal.savgol_filter的False ValueError

[英]False ValueError with scipy.signal.savgol_filter

I am confused. 我很困惑。 I have 21 files that have been generated by the same process and I am filtering them all using savitzky-golay filter with the same parameters. 我有21个文件是通过相同的过程生成的,我正在使用具有相同参数的savitzky-golay过滤器过滤所有文件。 It works normally for some files, but at some point, I receive the ValueError: array must not contain infs or NaNs . 它对于某些文件正常工作,但是在某些时候,我收到ValueError: array must not contain infs or NaNs The problem is, I checked the file and there aren't any infs or NaNs! 问题是,我检查了文件,没有任何infs或NaN!

print "nan", df.isnull().sum()
print "inf", np.isinf(df).sum()

gives

nan x        0
T          0
std_T      0
sterr_T    0
dtype: int64
inf x        0
T          0
std_T      0
sterr_T    0
dtype: int64

So the problem may be in implementation of the filter? 那么问题可能出在过滤器的实现上? Could this result from for example the choice of window length or polyorder relative to the length or step of the data? 例如,是否可以根据相对于数据长度或步长的窗口长度或多阶选择来得出结果?

Complete traceback: 完整的回溯:

Traceback (most recent call last):

  File "<ipython-input-7-40b33049ef41>", line 1, in <module>
    runfile('D:/data/scripts/DailyProfiles_Gradients.py', wdir='D:/data/DFDP2/DFDP2B/DTS/DTS_scripts')

  File "C:\Users\me\AppData\Local\Continuum\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 714, in runfile
    execfile(filename, namespace)

  File "C:\Users\me\AppData\Local\Continuum\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 74, in execfile
    exec(compile(scripttext, filename, 'exec'), glob, loc)

  File "D:/data/scripts/DailyProfiles_Gradients.py", line 142, in <module>
    grad = gradient(y, x, scale,PO)

  File "D:/data/scripts/DailyProfiles_Gradients.py", line 76, in Tgradient
    smoothed=savgol_filter(list(x), scale, PO, deriv=1, delta=dy[0])

  File "C:\Users\me\AppData\Local\Continuum\Anaconda2\lib\site-packages\scipy\signal\_savitzky_golay.py", line 337, in savgol_filter
    coeffs = savgol_coeffs(window_length, polyorder, deriv=deriv, delta=delta)

  File "C:\Users\me\AppData\Local\Continuum\Anaconda2\lib\site-packages\scipy\signal\_savitzky_golay.py", line 140, in savgol_coeffs
    coeffs, _, _, _ = lstsq(A, y)

  File "C:\Users\me\AppData\Local\Continuum\Anaconda2\lib\site-packages\scipy\linalg\basic.py", line 822, in lstsq
    b1 = _asarray_validated(b, check_finite=check_finite)

  File "C:\Users\me\AppData\Local\Continuum\Anaconda2\lib\site-packages\scipy\_lib\_util.py", line 187, in _asarray_validated
    a = toarray(a)

  File "C:\Users\me\AppData\Local\Continuum\Anaconda2\lib\site-packages\numpy\lib\function_base.py", line 1033, in asarray_chkfinite
    "array must not contain infs or NaNs")

ValueError: array must not contain infs or NaNs

This problem is rather specific to the data and method and I have not been able to produce a minimum reproducible working example. 这个问题是特定于数据和方法的,我无法提供最小的可重现的工作示例。 I am not asking for fixing my code, I am just asking for some brainstorming: What aspects have I not checked yet that might be causing the error? 我不是要修改我的代码,而是要集思广益: 我尚未检查哪些方面可能导致该错误? What should the function parameters look like, other than that the window length must be an odd number greater than the polyorder? 除了窗口长度必须是大于多阶的奇数之外,函数参数应该是什么样?

I am grateful for the discussion that has arisen, it helped, eventually. 我对所引起的讨论最终有所帮助表示感谢。

I can reproduce the error ValueError: array must not contain infs or NaNs if delta is extremely small (eg delta=1e-310 ). 我可以重现错误ValueError: array must not contain infs or NaNs如果delta非常小(例如, delta=1e-310 ),则ValueError: array must not contain infs or NaNs Check your code and data to ensure that the values that you pass for delta are reasonable. 检查您的代码和数据,以确保传递给delta的值是合理的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 内置函数scipy.signal.savgol_filter返回错误 - Built-in function scipy.signal.savgol_filter returns error 使用 SciPy savgol_filter 生成平滑的音频信号 - Using SciPy savgol_filter to generate smooth audio signal 使用 SciPy 的 signal.savgol_filter 计算的 Savitzky-Golay 导数需要缩放吗? - Savitzky-Golay derivatives, computed with SciPy's signal.savgol_filter need to be scaled? 使用scipy.signal库中的savgol_filter平滑Python上的在线数据 - Smoothing online data on Python with savgol_filter from scipy.signal library 来自 scipy.signal 库的 savgol_filter,得到生成的多项式 function? - savgol_filter from scipy.signal library, get the resulting polinormial function? 有些人对scipy.signal中savgol_filter函数的参数有疑问 - Some doubts about the parameters of the savgol_filter function from scipy.signal 使用 scipy.signal.lfilter 时,实现巴特沃斯带通滤波器遇到:“ValueError: object of too small depth for desired array”错误 - Implementing Butterworth bandpass filter running into: "ValueError: object of too small depth for desired array" error when using scipy.signal.lfilter Savgol 过滤 dataframe 列 - Savgol filter over dataframe columns python中的scipy.signal.bspline,过滤还是插值? - scipy.signal.bspline in python ,filter or interpolate? 在 Python scipy 中创建自定义信号滤波器 - Create a custom signal filter in Python scipy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM