Converting .wav into a Mini-SEED format file

Hi there,

I am currently working on audio files (.wav) with recordings of earthquakes. I am new in ObsPy and I would like to know if it is possible to convert a .wav into a Mini-SEED format file.
With the obspy.io.wav package is possible to read and convert Mini-SEED in WAV file format. However, I did not find any function in this package doing the reverse.
Any suggestion will be greatly appreciated!

Thank you!
Best, Mary

Should work just the same…

from obspy import read

st = read('my_file.wav')
st.write('my_file.mseed', format='MSEED')

Thank you very much!
That’s work!
Best, Marianna.

Hi there,

I have a new problem with this file conversion. What I am using to open these miniSEEDs after conversion is the program SEISAN, which needs integer numbers and the encoding STEIM2 (11 ).

I found this post in the forum which explains a bit the issue, but it does not solve it for me:

I tried:

  1. Using line stat before write command:
    ST.stat.mseed = {‘encoding’: ‘STEIM2’, ‘byteorder’: ‘>’}
    ST.write(‘Eq89.mseed’, format=‘MSEED’, encoding=11)

I got in the first line this error:
AttributeError: ‘Stream’ object has no attribute ‘stat’

  1. Using directly command: ST.write(‘Eq89.mseed’, format=‘MSEED’, encoding=11)
    I get this other error:
    Exception:
    Wrong dtype for Stream[0].data for encoding INT32.
    Please change the dtype of your data or use an appropriate
    encoding. See the obspy.io.mseed documentation for more
    information.

Any help will be very much appreciated!
Thank you!
Best, Marianna.

  1. You shouldn’t need the first line, specifying the encoding in the write command should be enough.

  2. STEIM are compression algorithms working on integer data. So if for whatever reason your obspy stream/traces have float data, you can not directly write it, you would have to manually convert the data to integers. As far as I can see wav stores integer data, so not sure why your data is float. Any processing steps like filtering etc usually converts data to float though.

Hi megies,
Thank you for your quick reply.

Yes, indeed, I had to manually convert my .wav files and assign dtype=np.int32. I do not why I have my data as float, after that I read my .wav file, anyway, after the conversion, I have now “Array of int32” with integer numbers.

So now, if I run:
ST.write(“myfile.mseed”, format=‘MSEED’)
I can correctly open the miniSEED in SEISAN.

If I print the stats of that I get:
mseed: AttribDict({‘dataquality’: ‘D’, ‘number_of_records’: 1153, ‘encoding’: ‘STEIM2’, ‘byteorder’: ‘>’, ‘record_length’: 4096, ‘filesize’: 4722688})

With the actual encoding I need, without having to state it in the ST.write function.

I hope that this will help, those who are going to have file conversion issues.
Thank you!