[英]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.