Obspy光谱图值错误(noverlap必须小于n)

2024-09-30 12:35:17 发布

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

我使用obspy处理地震数据,我想得到数据的光谱图。当我将光谱图函数应用于初始数据时,一切正常

st.spectrogram(log=True, title='BW.RJOB ' + str(st[0].stats.starttime))

但是当我对数据进行切片和插值时

tr = st[0]
sr=4.9999
tr2 = tr.slice(point - 20, point + 180)

tr2.interpolate(sampling_rate=sr)  

*点是我数据中的任意点

*初始采样率为124.99

然后做光谱图

tr2.spectrogram(log=True, title='BW.RJOB ' + str(tr2.stats.starttime))

我得到以下错误:

***ValueError:noverlap必须小于n

为什么会这样


Tags: 数据logtruetitlestats光谱trst
1条回答
网友
1楼 · 发布于 2024-09-30 12:35:17

经过一番挖掘,我终于找出了问题所在。在插值地震波之后,我在FFT中遇到了重叠长度的问题。通过查看scipy和obspy的光谱图文件:

scipy

  • npersegint, optional Length of each segment. Defaults to None, but if window is str or tuple, is set to 256, and if window is array_like, is set to the length of the window.
  • noverlapint, optional Number of points to overlap between segments. If None, noverlap = nperseg // 8. Defaults to None

obspy

  • wlen: Window length for fft in seconds. If this parameter is too small, the calculation will take forever. If None, it defaults to (samp_rate/100.0)

我的地震道的1000 NPT和FFT的256/8=32窗口导致了问题

这会在source code中引发错误

if noverlap >= n:
    raise ValueError('noverlap must be less than n')

其中n是每个窗口中的数据点数量

因此,每个窗口中的数据点数量大于相邻窗口之间的重叠数量

wlen=10解决了我的问题。因此,代码如下所示:

tr2.spectrogram(log=True, title='Spectrogram'),wlen=10)

相关问题 更多 >

    热门问题