sixty-north / segpy

A Python package for reading and writing SEG Y files.
Other
99 stars 54 forks source link

How to read latitude/longitude or xcoordinate/ycoordinate information?? #90

Open SoumiC opened 5 years ago

SoumiC commented 5 years ago

Hi, I need to know how to read latitude/longitude or xcoordinate/ycoordinate information from a .sgy file instead of inline/xline? I need to know the field names for extraction.

Thank you. Regards, Soumi

rob-smallshire commented 5 years ago
for inline_xline in segy_reader.inline_xline_numbers():
    index = segy_reader.trace_index(inline_xline)
    header = segy_reader.trace_header(index)
    # Do something with the header e.g. print it to look at the field names and values
    # You'll need to identify which fields contain the coordinate you're looking for
    print(header)
keerthigajee commented 5 years ago

Hi, I am trying to read x and y coordinates from seg file using given code but, it showing this error : EOFError: Trace header truncated when reading from position 3600 with packer BijectiveHeaderPacker(TraceHeaderRev1), how to rectify this issue and I need to know the field names for trace header..

Thank you, Regards, keerthi.

rob-smallshire commented 5 years ago

@keerthigajee It's difficult to say what the problem is unless you can share your SEG-Y file in some way. You can see the header field names in the code here https://github.com/sixty-north/segpy/blob/d39b89ca089f6353f32f2aca5e4689fc2ab2cb65/segpy/trace_header.py#L257

adclose commented 5 years ago

So I'm having the same issue I believe it may have something to do with the size of the trace header.

I get this when I simply try to see the header "segydata.trace_header(0) Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.4\helpers\pydev_pydevd_bundle\pydevd_exec2.py", line 3, in Exec exec(exp, global_vars, local_vars) File "", line 1, in File "C:\Users\Aaron\AppData\Local\Programs\Python\Python36\lib\site-packages\segpy\reader.py", line 514, in trace_header trace_header = read_trace_header(self._fh, header_packer, pos) File "C:\Users\Aaron\AppData\Local\Programs\Python\Python36\lib\site-packages\segpy\toolkit.py", line 457, in read_trace_header "{} with packer {!r}".format(pos, trace_header_packer)) from e EOFError: Trace header truncated when reading from position 3600 with packer BijectiveHeaderPacker(TraceHeaderRev1)"

Mine is in a 2D data file with what looks like non standard cdp_x and cdp_y bit locations but I'm not sure that is the issue.

Also is there a way to easily override the offset for those fields so that it will read the traces correctly?

adclose commented 5 years ago

After a lot of tracking down, I found an issue between the segy file I had and the format for the trace header, this may be related to the original problem and my not.

solution for me was to edit the trace_header.py to say

class Correlated(IntEnum): """Correlated: 0 = UNKNOWN,1 = no, 2 = yes.""" UNKNOWN = 0 NO = 1 YES = 2

Seems like sometimes segy files include 0 for this field

InnoKaleid commented 5 years ago

Hi,

I also run into the same issue: EOFError: Trace header truncated when reading from position 3600 with packer BijectiveHeaderPacker(TraceHeaderRev1).

I am trying to (1) read in a 2D seismic segy using create_reader [create_reader(segy_in_file, dimensionality=2)] and then (2) write it out into a new segy file using write_segy [write_segy(segy_out_file, seg_y_dataset, endian='>')]. The read-in step is fine while the error message occurs during the write-out step.

I zip the public segy file and attach it here. 3X_75_PR.zip. I was wondering if someone can help me with it?

Kindest regards,

John

rob-smallshire commented 5 years ago

I’m on vacation currently. I’ll take a look next week.

On Sat, 20 Apr 2019 at 18:19, InnoKaleid notifications@github.com wrote:

Hi,

I also run into the same issue: EOFError: Trace header truncated when reading from position 3600 with packer BijectiveHeaderPacker(TraceHeaderRev1).

I am trying to (1) read in a 2D seismic segy using create_reader [create_reader(segy_in_file, dimensionality=2)] and then (2) write it out into a new segy file using write_segy [write_segy(segy_out_file, seg_y_dataset, endian='>')]. The read-in step is fine while the error message occurs during the write-out step.

I zip the public segy file and attach it here. 3X_75_PR.zip https://github.com/sixty-north/segpy/files/3100354/3X_75_PR.zip. I was wondering if someone can help me with it?

Kindest regards,

John

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/sixty-north/segpy/issues/90#issuecomment-485139875, or mute the thread https://github.com/notifications/unsubscribe-auth/AAH65KN46ACGTDRYRL6UWSTPRM7ADANCNFSM4GSK2U3A .

InnoKaleid commented 5 years ago

Hi rob-smallshire,

Thank you and have a great vacation.

John

adclose commented 5 years ago

@InnoKaleid This is my test code that should solve your problem but you will need to need to replace the trace_header.py in the package with the attached

trace_header.zip

Best of Luck Aaron

` from segpy.reader import create_reader import numpy as np

def getpoint(segydata, i, j = None):

if j is None:
    header = segydata.trace_header(segydata.trace_index(i))
else:
    header = segydata.trace_header(segydata.trace_index([i, j]))

if header.cdp_x != 0:
    x = header.cdp_x
    y = header.cdp_y
else:
    x = (header.source_x + header.group_x) / 2
    y = (header.source_y + header.group_y) / 2

point = np.array([x,y])

if (header.xy_scalar >= 0):
    scale = header.xy_scalar
else:
    scale = 1 / np.abs(header.xy_scalar)

point = point * scale

return point

filePath = "tmp/3X_75_PR.SGY"

fileHandle = open(filePath, 'rb') segyData = create_reader(fileHandle)

imax = max(segyData.cdp_numbers()) imin = min(segyData.cdp_numbers())

for i in np.arange(imin, imax, 10): point = getpoint(segyData, i) if i == imin: points = np.array([point]) else: points = np.append(points, [point], axis=0)

print(points)

`

InnoKaleid commented 5 years ago

Hi Aaron,

Thank you for your help. It seems work well and have a great weekend.

John

adclose commented 5 years ago

John No problem hope this helps.. I could have abstracted the answer a bit better but glad it works.. I’ve been using the library a lot this week so just pulled pieces of some of my working code.

InnoKaleid commented 5 years ago

Hi Aaron,

Thank you very much and your answer is very helpful. Happy Easter!

John

pktrigg commented 5 years ago

Hi, I too have the same error: EOFError: Trace header truncated when reading from position 3600 with packer BijectiveHeaderPacker(TraceHeaderRev1)

any thoughts how this can be fixed in the pip distro module?

adclose commented 5 years ago

my fork should work for this.

Aaron

satyajitchiku commented 4 years ago

what is the use of progress in the reader and writer module and how to use it ????

SoumiC commented 4 years ago

Hello @rob-smallshire, In case of 3D files, x-coordinates and y-coordinates fields are valid? or these are valid only for 2D seismic files?

I tried to check the field names, but the EOFError issue persists. "EOFError: Trace header truncated when reading from position 3600 with packer BijectiveHeaderPacker(TraceHeaderRev1)".

What to do with a 3D seismic file if x, y co-ordinates are required?

Kindly help!.

Regards, Soumi

adclose commented 4 years ago

The EOF error is pretty common. You might try my fork and see if that runs for you. Aaron