# Converting segy to sac format

**URL:** https://discourse.obspy.org/t/converting-segy-to-sac-format/1988
**Category:** Usage Questions
**Created:** [August 22, 2024, 2:46am UTC](https://discourse.obspy.org/t/converting-segy-to-sac-format/1988 "2024-08-22T02:46:15Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![kozan88](https://discourse.obspy.org/user_avatar/discourse.obspy.org/kozan88/32/661_2.png) [@kozan88](https://discourse.obspy.org/u/kozan88)
#### Post date: [August 22, 2024, 2:46am UTC](https://discourse.obspy.org/t/converting-segy-to-sac-format/1988/1 "2024-08-22T02:46:15Z")

</div>

Hi,  
I have borehole seismic data, with seg-y format.  
I do not know anything about the data structure and header, I just retrieved it from IRIS.  
I want to convert it to SAC, but before, I tried to read it using:

```python
import obspy
import matplotlib.pyplot as plt
segy_file = '20.41.57.0507.1'
try:
    st = obspy.read(segy_file, format='SEGY', endian='>')
except obspy.io.segy.segy.SEGYError:
    print("Big-endian failed, trying little-endian...")
    st = obspy.read(segy_file, format='SEGY', endian='<')
print(st)
st.plot()
st.plot(type="section", orientation="horizontal", scale=0.1, linewidth=0.5, show=True)

```

But I got the error:  
obspy.io.segy.segy.SEGYError: Unable to determine the endianness of the file. Please specify it.  
I attached an event, I would be grateful if you could help with plotting it and convert it to sac format.  
[R072.01.rar](https://discourse.obspy.org/uploads/short-url/feKAiTw03KVQqDlo66r7Rcx90J2.rar) (88.6 KB)

---

<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: [August 23, 2024, 9:09am UTC](https://discourse.obspy.org/t/converting-segy-to-sac-format/1988/2 "2024-08-23T09:09:02Z")

</div>

Wrong name for the option, try using `byteorder`, see docs: [obspy.io.segy.core.\_read\_segy — ObsPy 1.4.1.post0+393.g271569d37b.obspy.master documentation](https://docs.obspy.org/master/packages/autogen/obspy.io.segy.core._read_segy.html#obspy.io.segy.core._read_segy)

---

<div class="post-metadata">

### Author: ![kozan88](https://discourse.obspy.org/user_avatar/discourse.obspy.org/kozan88/32/661_2.png) [@kozan88](https://discourse.obspy.org/u/kozan88)
#### Post date: [August 23, 2024, 6:04pm UTC](https://discourse.obspy.org/t/converting-segy-to-sac-format/1988/3 "2024-08-23T18:04:49Z")

</div>

Thank you for your reply.  
I change the script to:

```python
import obspy
import matplotlib.pyplot as plt
segy_file = '20.41.57.0507.1'
try:
    st = obspy.read(segy_file, format='SEGY', byteorder='>', textual_header_encoding='EBCDIC')
except obspy.io.segy.segy.SEGYError:
    print("Big-endian failed, trying little-endian...")
    st = obspy.read(segy_file, format='SEGY', byteorder='<', textual_header_encoding='EBCDIC')
print(st)
st.plot()
st.plot(type="section", orientation="horizontal", scale=0.1, linewidth=0.5, show=True)

```

And I got the error:  
File “/home/mpsn/.local/lib/python3.8/site-packages/obspy/io/segy/segy.py”, line 213, in \_read\_textual\_header  
textual\_header.decode(‘EBCDIC-CP-BE’).encode(‘ascii’)  
UnicodeEncodeError: ‘ascii’ codec can’t encode character ‘\x97’ in position 3: ordinal not in range(128)

When I tried ASCII I got:  
NotImplementedError: Extended textual headers are not yet supported. Please contact the developers.  
Even when I used none, it did not work.

---

<div class="post-metadata">

### Author: ![kozan88](https://discourse.obspy.org/user_avatar/discourse.obspy.org/kozan88/32/661_2.png) [@kozan88](https://discourse.obspy.org/u/kozan88)
#### Post date: [August 27, 2024, 11:23pm UTC](https://discourse.obspy.org/t/converting-segy-to-sac-format/1988/4 "2024-08-27T23:23:25Z")

</div>

@megies  
Gently reminder .\_.

---

<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: [August 29, 2024, 7:26am UTC](https://discourse.obspy.org/t/converting-segy-to-sac-format/1988/5 "2024-08-29T07:26:03Z")

</div>

Well, I’m sorry but seems like reading files with “extended textual headers” was not implemented. I did not write any of the SEGY routines, so other people would have to step up.

---

<div class="post-metadata">

### Author: ![kozan88](https://discourse.obspy.org/user_avatar/discourse.obspy.org/kozan88/32/661_2.png) [@kozan88](https://discourse.obspy.org/u/kozan88)
#### Post date: [August 30, 2024, 9:57pm UTC](https://discourse.obspy.org/t/converting-segy-to-sac-format/1988/6 "2024-08-30T21:57:02Z")

</div>

@megies  
I just realized that these files are reftek raw data.  
Do you have a script to read and plot the data? It will be helpful

Thank you,

---

<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: [September 2, 2024, 6:43am UTC](https://discourse.obspy.org/t/converting-segy-to-sac-format/1988/7 "2024-09-02T06:43:45Z")

</div>

we can read files written by REFTEK-130 but these files don’t look like that. other formats Reftek might have we don’t have support for
