equinor / segyio

Fast Python library for SEGY files.
Other
476 stars 214 forks source link

Reading SU file: trace count inconsistent with file size #427

Closed ke0m closed 4 years ago

ke0m commented 4 years ago

I am having difficulty reading in Seismic Unix (SU) files. I seem to always get the error:

RuntimeError: trace count inconsistent with file size, trace lengths possibly of non-uniform

when reading in a SU file. It can easily be reproduced with the following two examples:

1. Reading in a simple SU file

Using CWP/SU Release 44R14 20 July 2019, I first generate the simplest SU dataset:

suplane > plane.su
surange < plane.su
32 traces:
tracl    1 32 (1 - 32)
tracr    1 32 (1 - 32)
offset   400
ns       64
dt       4000

Then, I attempt to read in the file using segyio:

with segyio.open('plane.su',ignore_geometry=True) as f:
  data = f.trace.raw[:]

Which results in the trace count error. I have tried this by creating the SU file with both big- and little-endian formats (XDR vs native) and also have changed the endian argument in the open function (as suggested in other issues) but I always get the same error.

Note that when I convert this file to SEGY as follows:

segyhdrs < plane.su | segywrite tape=plane.sgy

and then attempt to read in the SEGY file with segyio:

with segyio.open('plane.sgy',ignore_geometry=True) as f:
  data = f.trace.raw[:]

I am able to successfully read in the traces.

2. Reading in the 3X_75_PR.SGY dataset

I have also verified this on the dataset 3X_75_PR.SGY in the segyio-notebooks repository:

segyread tape=3X_75_PR.SGY | segyclean > 3X_75_PR.SU
surange < 3X_75_PR.SU
1592 traces:
tracl    1 1592 (1 - 1592)
tracr    1 1592 (1 - 1592)
fldr     11 65535 (11 - 284)
cdp      1 1592 (1 - 1592)
cdpt     1
trid     1
nvs      1
nhs      1 6 (1 - 1)
duse     1
scalco   1
ns       751
dt       8000
year     16
day      35
hour     8
minute   54
sec      1
timbas   1
trwf     10

And again, using segyio:

with segyio.open('3X_75_PR.SU',ignore_geometry=True) as f:
  data = f.trace.raw[:]

I get the trace count error.

Any help/advice on this issue would be greatly appreciated.

jokva commented 4 years ago

Try segyio.su.open :-----)

https://segyio.readthedocs.io/en/latest/segyio.html#segyio.su.open

ke0m commented 4 years ago

Thank you @jokva for the quick reply. Unfortunately, now trying:

with segyio.su.open('plane.su',ignore_geometry=True) as f:   
    data = f.trace.raw[:]

generates the same error.

jokva commented 4 years ago

Are the SU files in little-endian, maybe? Try passing endian = 'little' to open.

ke0m commented 4 years ago

That did it. Finally, what worked was

with segyio.su.open('plane.su',ignore_geometry=True,endian='little') as f:
  data = f.trace.raw[:] 

One odd thing is that if I convert the SU file to SEGY using (segywrite), it only works if I read the SEGY as big endian. It seems that as part of the conversion from SU to SEGY, it swaps the bytes.

Thanks very much for the help @jokva!

jokva commented 4 years ago

Splendid, glad it worked out!