# cant read SAC files

**URL:** https://discourse.obspy.org/t/cant-read-sac-files/837
**Category:** Users Mailing List Archive
**Tags:** archive
**Created:** [June 10, 2019, 2:17pm UTC](https://discourse.obspy.org/t/cant-read-sac-files/837 "2019-06-10T14:17:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Blaz\_Vicic](https://discourse.obspy.org/letter_avatar_proxy/v4/letter/b/76d3ee/32.png) [@Blaz\_Vicic](https://discourse.obspy.org/u/Blaz_Vicic)
#### Post date: [June 10, 2019, 2:17pm UTC](https://discourse.obspy.org/t/cant-read-sac-files/837/1 "2019-06-10T14:17:15Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Jonathan\_K\_Maccarthy](https://discourse.obspy.org/user_avatar/discourse.obspy.org/jonathan_k_maccarthy/32/266_2.png) [@Jonathan\_K\_Maccarthy](https://discourse.obspy.org/u/Jonathan_K_Maccarthy)
#### Post date: [June 10, 2019, 5:47pm UTC](https://discourse.obspy.org/t/cant-read-sac-files/837/2 "2019-06-10T17:47:49Z")

</div>

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](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

---

<div class="post-metadata">

### Author: ![Blaz\_Vicic](https://discourse.obspy.org/letter_avatar_proxy/v4/letter/b/76d3ee/32.png) [@Blaz\_Vicic](https://discourse.obspy.org/u/Blaz_Vicic)
#### Post date: [June 11, 2019, 5:47am UTC](https://discourse.obspy.org/t/cant-read-sac-files/837/3 "2019-06-11T05:47:01Z")

</div>

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

---

<div class="post-metadata">

### Author: ![megies](https://discourse.obspy.org/user_avatar/discourse.obspy.org/megies/32/9_2.png) [@megies](https://discourse.obspy.org/u/megies)
#### Post date: [June 11, 2019, 8:54am UTC](https://discourse.obspy.org/t/cant-read-sac-files/837/4 "2019-06-11T08:54:59Z")

</div>

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:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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
