sixty-north / segpy

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

segy 3d read error #87

Open Tortoise17 opened 6 years ago

Tortoise17 commented 6 years ago

Dear Respected Brother.

Good afternoon. I am facing error in reading and displaying a file.

Good afternoon. I am facing a problem in 3D segy reading. Can you help me why this error is? Please

ValueError Traceback (most recent call last) ~/.local/lib/python3.5/site-packages/segpy/header.py in set(self, instance, value) 298 try: --> 299 self._instance_data[instance] = self._named_field._value_type(value) 300 except ValueError as e:

~/.local/lib/python3.5/site-packages/segpy/field_types.py in class_new(cls, *args, **kwargs) 13 cls.name, instance, ---> 14 cls.MINIMUM, cls.MAXIMUM)) 15 return instance

ValueError: NNInt16 value 51614 outside range 0 to 32767

The above exception was the direct cause of the following exception:

ValueError Traceback (most recent call last) in () 19 20 f=open(file_near, 'rb') ---> 21 segy = create_reader(f) 22 23 ntraces = segy.num_traces()

~/.local/lib/python3.5/site-packages/segpy/reader.py in create_reader(fh, encoding, binary_reel_header_format, trace_header_format, endian, progress, cache_directory, dimensionality) 151 if reader is None: 152 reader = _make_reader(fh, encoding, binary_reel_header_format, trace_header_format, --> 153 endian, progress_callback, dimensionality) 154 if cache_file_path is not None: 155 _save_reader_to_cache(reader, cache_file_path)

~/.local/lib/python3.5/site-packages/segpy/reader.py in _make_reader(fh, encoding, binary_reel_header_format, trace_header_format, endian, progress, dimensionality) 256 encoding = ASCII 257 textual_reel_header = read_textual_reel_header(fh, encoding) --> 258 binary_reel_header = read_binary_reel_header(fh, binary_reel_header_format, endian=endian) 259 extended_textual_header = read_extended_textual_headers(fh, binary_reel_header, encoding) 260 bps = bytes_per_sample(binary_reel_header)

~/.local/lib/python3.5/site-packages/segpy/toolkit.py in read_binary_reel_header(fh, binary_reel_header_format, endian) 180 header_packer = make_header_packer(binary_reel_header_format, endian) 181 buffer = fh.read(binary_reel_header_format.LENGTH_IN_BYTES) --> 182 reel_header = header_packer.unpack(buffer) 183 return reel_header 184

~/.local/lib/python3.5/site-packages/segpy/packer.py in unpack(self, buffer) 198 str(e).capitalize())) from e 199 else: --> 200 return self._unpack(values) 201 202 @abstractmethod

~/.local/lib/python3.5/site-packages/segpy/packer.py in _unpack(self, values) 222 223 def _unpack(self, values): --> 224 return self._header_format_class(*values) 225 226

~/.local/lib/python3.5/site-packages/segpy/header.py in init(self, *args, **kwargs) 29 """ 30 for keyword, arg in zip(self.ordered_field_names(), args): ---> 31 setattr(self, keyword, arg) 32 33 for keyword, arg in kwargs.items():

~/.local/lib/python3.5/site-packages/segpy/header.py in set(self, instance, value) 300 except ValueError as e: 301 raise ValueError("Assigned value {!r} for {} attribute must be convertible to {}: {}" --> 302 .format(value, self._name, self._named_field._value_type.name, e)) from e 303 304 def delete(self, instance):

ValueError: Assigned value 51614 for ensemble_fold attribute must be convertible to NNInt16: NNInt16 value 51614 outside range 0 to 32767

Please if anyone can help me to resolve this.

Looking forward

rob-smallshire commented 6 years ago

The error message at the bottom tells you what the problem is. The ensemble fold attribute in your SEG-Y binary reel header has a value of 51614, whereas the SEG-Y specification only allows for values in the range 0 to 32767.

From the SEG-Y revision 1 spec, page 3:

"All values in the Binary File Header and the Trace Header are two's complement integers, either two bytes or four bytes long."

At the bottom of page 6 you will see that Ensemble fold is a two-byte value occupying the one-based file offsets 3227 and 3228.

Signed (i.e. two's complement), two-byte integers can only represent positive values in the range 0-32767.

In other words, your SEG-Y data doesn't comply with the SEG-Y specification.

You can work around this with Segpy by providing a custom binary_reel_header_format specification to create_reader(). The easiest way to do that is to subclass segpy.binary_reel_header.BinaryReelHeader to override the definition of ensemble_fold, giving it a different type.

Tortoise17 commented 6 years ago

Dear Sir,

Thank you so much. Can you guide me how and where to write the line in the script? as I am very new in Python. and if you can guide what exactly I should write.?

Tortoise17 commented 6 years ago

what I understood from you is that

inline_number = field( Int32, offset=189, default=0, documentation= """In-line number for 3-D poststack data. If one in-line per SEG Y file is being recorded, this value should be the same for all traces in the file and the same value will be recorded in bytes 3205-3208 of the Binary File Header.""" # TODO: replace bytes with field name )

here I can override..?? Please if you can guide me.. how and what?

rob-smallshire commented 6 years ago

The error you reported mentions nothing about inline_number being a problem. It is the ensemble_fold attribute in your binary reel header which is out of range. The custom_header.py example shows how to override a custom header definition. You should be able to apply the ideas from this to your own code.

Tortoise17 commented 6 years ago

Nice.. should I just put this file there? or replace with header.py?

The inline ranges form 400-3900 and xline 7100-5200

rob-smallshire commented 6 years ago

Neither. You need to read it, understand it, and then apply the same ideas to your own program.

If you need help to actually write your own software which uses Segpy, my consulting company Sixty North can help with that. I'm afraid I don't have the time to provide you with consulting for free through this channel.

Tortoise17 commented 6 years ago

Dear Respected Sir,

Ok., If you can tell me that in SEGPY... is this script reads the file with little endian or bigger endian ? and segy rev 1 or rev 2 or old then rev 1?

On 9 March 2018 at 14:25, Robert Smallshire notifications@github.com wrote:

Neither. You need to read it, understand it, and them apply the same ideas to your own program.

If you need help to actually write your own software which uses Segpy, my consulting company Sixty North can help with that. I'm afraid I don't have the time to provide you with consulting for free through this channel.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sixty-north/segpy/issues/87#issuecomment-371811165, or mute the thread https://github.com/notifications/unsubscribe-auth/Ai5gLMnb4qv_wAv8c3zRuuhMNp6lkm0Fks5tcoLXgaJpZM4SkIIk .

-- Dr. Khawar Ashfaq Ahmed

rob-smallshire commented 6 years ago

By default, Segpy reads in big-endian, the same as the SEG-Y revision 1 standard.

You can override this to force little-endian behaviour by passing the argument endian='<' to the call to create_reader().

Segpy does not yet support SEG-Y revision 2. See #52.

Tortoise17 commented 6 years ago

Dear Respected Sir,

Good afternoon. I hope you are fine. Thank you for little endian guide. I have to ask that is there any example reproduce-able with segy / script available. So, that I can test. I am still not able to understand my Int16 solution :( and I tried custom header. and it also didn't work for me.

If you can help a little.

Greetings

Khawar

On 11 March 2018 at 20:16, Robert Smallshire notifications@github.com wrote:

By default, Segpy reads in big-endian, the same as the SEG-Y revision 1 standard.

You can override this to force little-endian behaviour by passing the argument endian='<' to the call to create_reader().

Segpy does not yet support SEG-Y revision 2. See #52 https://github.com/sixty-north/segpy/issues/52.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sixty-north/segpy/issues/87#issuecomment-372141000, or mute the thread https://github.com/notifications/unsubscribe-auth/Ai5gLETugrT5yfuGYFmwxgEU_b5LWPnVks5tdXgRgaJpZM4SkIIk .

-- Dr. Khawar Ashfaq Ahmed

rob-smallshire commented 6 years ago

I'm sorry. I'm very busy and I really don't have time to help you for free. I've pointed you at examples which use custom headers. The README.rst file shows how to set the endianness.

Please contact my consulting company Sixty North if you or your employer need further assistance and are in a position to pay for it, or to fund improved documentation.

In the meantime, if you need to improve your understanding of Python in general, I recommend taking some courses such as those from Pluralsight.

576dhunu commented 2 years ago

Respected sir/Madam I am getting the following error while trying to make 'create_reader' using segpy.reader.Please help me out in this regards

ValueError Traceback (most recent call last) in () 1 filename='/content/Seismic_data.sgy' 2 with open(filename,'rb') as segy: ----> 3 segy_reader=segpy.reader.create_reader(segy, ) 4 data=np.zeros((segy_reader.num_inlines(),segy_reader.num_trace_samples(1),segy_reader.num_xlines())) 5 for inline_num,xline_num in segy_reader.inline_xline_numbers():

/usr/local/lib/python3.7/dist-packages/segpy/reader.py in create_reader(fh, encoding, binary_reel_header_format, trace_header_format, endian, progress, cache_directory, dimensionality) 126 "SEG Y file {!r} of {} bytes is too short".format( 127 filename_from_handle(fh), --> 128 num_file_bytes)) 129 130 if endian not in {'<', '>'}:

ValueError: SEG Y file '/content/Seismic_data.sgy' of 2220 bytes is too short

rob-smallshire commented 2 years ago

@576dhunu SEG-Y files should have a 3600 byte header before the trace data (3200 text header + 400 byte binary header). The file you're providing is apparently only 2220 bytes long, so isn't longer enough to contain the header, hence: "SEG Y file '/content/Seismic_data.sgy' of 2220 bytes is too short"