obspy.imaging.spectrogram - output data

Hi there,

Does anybody know how to output the data from the obspy function spectrogram (not only as an image file)?

Description of work flow:

1.read in one seismic trace (SEGY format) - OK

  1. calculate and plot the spectrogram using obspy.imaging.spectrogram - OK

  2. output the image of the spectrogram as a PNG file - OK

  3. output the data points, as floating numbers - NOT POSSIBLE ??

My code is the following:
st=obspy.read(\seismic\trace.segy)
st_spec=st.spectrogram(log=True, wlen=0.02, samp_rate=32000, per_lap=0.9, outfile=“st_spec_image”)
st_spec.write(‘st_spec_data’, format=‘SEGY’)

type(st)

output:obspy.core.stream.Stream

type(st_spec)

output:list

The error message, is the following:

Hi Guro,

there currently is no option to get the values out (in a canonical way).
But you can have a look at the executed code, you can just do the
spectrogram calculation yourself:

https://github.com/obspy/obspy/blob/460ce3f5f4139ad52499f6dc4236bdfc9d7e6505/obspy/imaging/spectrogram.py#L102-L130

Stream.spectrogram hands you back a list of figures, not a Stream
object, that's why the write operation failed. The function is mainly
intended for a quick visualization, so I don't think will will ever add
returning values of the spectrogram.

best,
Tobias

Hi Tobas,

Thank you! I will have a look at the code :slight_smile:

Please let me explain the purpose of my request a bit more in detail.

I am a geophysicist working on the Illinois Basin-Decatur Project, which is an integrated bioenergy carbon capture and geological storage project. The spectrogram images using the Python software look very nice. What we would like to do with them, for the purpose of 4D seismic data analysis, is to create 4D difference plots by subtracting one spectrogram from another. It would therefore be nice if the data output from obspy.imaging.spectrogram could easily be retrieved. Please let me know if you would consider implementing output of data in the spectrogram-function, it would be very much appreciated.

Kind regards,
Guro