Reading SEG-Y file

Hi,

I wrote a python code (attached) to read a SEG-Y file (attached) and append some trace headers before converting it to miniSEED format. This code was working few months ago, but now it is flashing error for obspy module. I am exporting readSEGY function on line 50 of the attached code, but it gives me Import ERROR saying that “No module names obspy.segy.segy”. Has there been a recent change in obspy module names. I would appreciate any suggestion in this regard.

Thanks

Abhash Kumar

Geophysicist

National Energy Technology Laboratory

United States

segy2mseed.py (1.78 KB)

20151109054716974.sgy (858 KB)

Hi Abash,

ObsPy 1.0.0 released at the beginning 2016 made a one-time change to the internal structure:

The old imports kept working (together with lots of warnings to make you aware of it) until ObsPy 1.1.0 at which point we completely removed them. So I guess that’s why your code stopped working.

I assume that the function you are looking for it now called obspy.io.segy.core._read_segy

Judging from your code there is no reason for you to use the io.segy internal reading routine but you can just use obspy.read() and let ObsPy figure out which function to call.

Cheers!

Lion

Hi Lion,

I appreciate your suggestion. I disabled line 50 and modified line 51 to include obspy.io.segy.core as per your suggestion, but I am getting similar import error (“No module named obspy.io.segy.core”). Could you possibly modify the necessary line (or lines) that could fix the import error and kindly send me the modified version of my code. I would much appreciate your help.

Thanks

Abhash Kumar

segy2mseed_revised.py (1.79 KB)

Hi Abash,

if you read carefully what Lion replied, you can see that the function you are using was renamed, so instead of

>>> from obspy.io.segy.core import readSEGY

you want

>>> from obspy.io.segy.core import _read_segy

But then again, like Lion told you, you should rather just use the high-level, convenience reading routine instead. In 99% of all cases you want to use that for reading waveform data:

>>> from obspy import read
>>> read('20151109054716974.sgy', format='SEGY',
... unpack_trace_headers=True)
36 Trace(s) in Stream:

Seq. No. in line: 1 | 2015-11-09T05:47:16.000000Z - 2015-11-09T05:47:19.007500Z | 2000.0 Hz, 6016 samples
...
(34 other traces)
...
Seq. No. in line: 36 | 2015-11-09T05:47:16.000000Z - 2015-11-09T05:47:19.007500Z | 2000.0 Hz, 6016 samples

[Use "print(Stream.__str__(extended=True))" to print all Traces]

Any kwargs you add (like "unpack_trace_headers" in this example) will get passed down to the low level reading routine of the corresponding io module (i.e. _read_segy in this case).

cheers,
Tobias

Sorry for my late replay, I just saw your email

sgy2mseed.py (1.35 KB)

Hi Khalil,

I appreciate for sending me the python code. It is very helpful.

Best regards,

Abhash Kumar