2

I working with seismic data using obspy and I want to get a spectrogram for my data. When I apply the spectrogram function to the initial data everything works fine.

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

However when I slice and interpolate the data

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

tr2.interpolate(sampling_rate=sr)  

*point is some arbitrary point in my data

*initial sampling rate is 124.99

and then perform the spectrogram

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

I get the following error:

*** ValueError: noverlap must be less than n

Why is this happening?

mtrw
  • 34,200
  • 7
  • 63
  • 71
arisAbCy
  • 71
  • 7

1 Answers1

2

After some digging, I managed to figure out what the problem was. After interpolating the seismic wave I had a problem with the length of overlap in FFT. By looking at the documentation of the spectrogram from scipy and 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)

The 1000 npts of my seismic trace and the 256/8=32 window of FFT caused the problem.

This raises the error in the source code

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

where n is the number of data points in each window.

So the number of data points in each window was larger than number of overlap between adjacent windows.

The wlen=10 solved my issue. So the code is now as follows:

tr2.spectrogram(log=True, title='Spectrogram'),wlen=10)
arisAbCy
  • 71
  • 7