cant read SAC files

Dear all

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?

Thank you very much
Blaz

Hi Blaz,

This error relates to the expected versus observed number of bytes: https://github.com/obspy/obspy/blob/master/obspy/io/sac/arrayio.py#L165.

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.

Best,

Jon

Dear Jon,
Thank you very much, but adding "checksize=False” did not work.

I tried to change the format from sac to mseed using sac2mseed (by iris) which seems to be working without any problems so I can read the data now.

Cheers

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, ...).

best,
Tobias