I have a bunch of SAC files which I want to work with.
I can easily read them with SAC, but when trying to open with obspy, I get the following problem:
obspy.io.sac.util.SacIOError: Actual and theoretical file size are inconsistent.
Actual/Theoretical: 10075832/10075432
Check that headers are consistent with time series.
Is there a simple solution and what exactly does that mean?
The SAC module expects 632 header bytes + 4*npts data bytes, and raises this error if that condition is false. The file appears to have 400 extra bytes. I don’t know why the SAC program is able to read it, or what it does with the extra bytes, but I think this check can be disabled with the “checksize=False” keyword into the “read” function.
You can still read that file in ObsPy by manually cutting off extra bytes at the end:
import io
with open('myfile.sac', 'rb') as fh:
data = fh.read()
data = data[:10075432]
bio = io.BytesIO(data)
st = read(bio)
If this affects many files, though, and is a systematic issue, you might want to look into why this is happening (i.e. where the data comes from, what program/digitizer is writing the data, ...).