obspy.io.segy.segy.iread_segy
- iread_segy(file, endian=None, textual_header_encoding=None, unpack_headers=False, headonly=False)[source]
Iteratively read a SEG-Y field and yield single ObsPy Traces.
The function iteratively loops over the whole file and yields single ObsPy Traces. The next Trace will be read after the current loop has finished - this function is thus suitable for reading arbitrarily large SEG-Y files without running into memory problems.
>>> from obspy.core.util import get_example_file >>> filename = get_example_file("00001034.sgy_first_trace") >>> from obspy.io.segy.segy import iread_segy >>> for tr in iread_segy(filename): ... # Each Trace's stats attribute will have references to the file ... # headers and some more information. ... tf = tr.stats.segy.textual_file_header ... bf = tr.stats.segy.binary_file_header ... tfe = tr.stats.segy.textual_file_header_encoding ... de = tr.stats.segy.data_encoding ... e = tr.stats.segy.endian ... # Also do something meaningful with each Trace. ... print(int(tr.data.sum() * 1E9)) -5
- Parameters:
file – Open file like object or a string which will be assumed to be a filename.
endian (str) – String that determines the endianness of the file. Either ‘>’ for big endian or ‘<’ for little endian. If it is None, obspy.io.segy will try to autodetect the endianness. The endianness is always valid for the whole file.
textual_header_encoding – The encoding of the textual header. Either ‘EBCDIC’, ‘ASCII’ or None. If it is None, autodetection will be attempted.
unpack_headers (bool) – Determines whether or not all headers will be unpacked during reading the file. Has a huge impact on the memory usage and the performance. They can be unpacked on-the-fly after being read. Defaults to False.
headonly (bool) – Determines whether or not the actual data records will be read and unpacked. Has a huge impact on memory usage. Data will not be unpackable on-the-fly after reading the file. Defaults to False.