When I write data in MSEED format, obspy crash with the following error:
Encountered 2 error(s) during a call to mst_pack():
msr_encode_steim2(…): Unable to represent difference in <= 30 bits
msr_pack(…): Error packing data samples
So I changed encoding option by specifying it to be 3 (which is INT32) not 11 (which is STEIM2), but I still got the above error with STEIM2 error. Do I miss anything while calling Stream.write?
st.write(mseedFileName, format=‘MSEED’, encoding=3, reclen=512)
Any suggestions to use encoding option correctly?
Thanks,
Junli
import numpy as np
from obspy import Trace
x = np.random.randint(-100, 100, 2000, dtype='int32')
x[20] += 2**30 + 20000
tr = Trace(data=x)
tr.write('/tmp/test.mseed', 'MSEED') # this shows the exception you stated above, STEIM compression failing
tr.write('/tmp/testX.mseed', 'MSEED', encoding=3) # this works
# making sure by faking an existing mseed stats entry that states STEIM encoding
tr.stats.mseed = {'dataquality': 'R', 'number_of_records': 2, 'encoding': 'STEIM2', 'byteorder': '>', 'record_length': 4096, 'filesize': 8192}
tr.write('/tmp/testX.mseed', 'MSEED', encoding=3) # this still works
FWIW I usually encounter this error when the data is fully clipped, rail to rail, usually because it went too off level.
So, just guessing, but it sounds like your counts are +/- 2**30 which is probably getting too large to be stored with int32. You could possibly try int64, but more likely the data is not worth saving.