def test_values_text_header_creation(): lines = {i + 1: chr(64 + i) * 76 for i in range(40)} text_header = segyio.create_text_header(lines) for line_no in range(0, 40): line = text_header[line_no * 80: (line_no + 1) * 80] assert line == "C{0:>2} {1:76}".format(line_no + 1, chr(64 + line_no) * 76)
def test_read_text_header(mmap=False): f = _segyio.segyiofd("test-data/small.sgy", "r") if mmap: f.mmap() lines = { 1: "DATE: 2016-09-19", 2: "AN INCREASE IN AMPLITUDE EQUALS AN INCREASE IN ACOUSTIC IMPEDANCE", 3: "Written by libsegyio (python)", 11: "TRACE HEADER POSITION:", 12: " INLINE BYTES 189-193 | OFFSET BYTES 037-041", 13: " CROSSLINE BYTES 193-197 |", 15: "END EBCDIC HEADER" } rows = segyio.create_text_header(lines) rows = bytearray(rows, 'ascii') # mutable array of bytes rows[-1] = 128 # \x80 actual_text_header = bytes(rows) assert f.gettext(0) == actual_text_header with pytest.raises(Exception): _segyio.read_texthdr(None, 0) f.close()
def default_text_header(iline, xline, offset): lines = { 1: "DATE %s" % datetime.date.today().isoformat(), 2: "AN INCREASE IN AMPLITUDE EQUALS AN INCREASE IN ACOUSTIC IMPEDANCE", 3: "Written by libsegyio (python)", 11: "TRACE HEADER POSITION:", 12: " INLINE BYTES %03d-%03d | OFFSET BYTES %03d-%03d" % (iline, iline + 4, int(offset), int(offset) + 4), 13: " CROSSLINE BYTES %03d-%03d |" % (xline, xline + 4), 15: "END EBCDIC HEADER", } rows = segyio.create_text_header(lines) rows = bytearray(rows, 'ascii') # mutable array of bytes rows[-1] = 128 # \x80 -- Unsure if this is really required... return bytes(rows) # immutable array of bytes that is compatible with strings
def setUp(self): self.filename = "test-data/small.sgy" lines = { 1: "DATE: 2016-09-19", 2: "AN INCREASE IN AMPLITUDE EQUALS AN INCREASE IN ACOUSTIC IMPEDANCE", 3: "Written by libsegyio (python)", 11: "TRACE HEADER POSITION:", 12: " INLINE BYTES 189-193 | OFFSET BYTES 037-041", 13: " CROSSLINE BYTES 193-197 |", 15: "END EBCDIC HEADER" } rows = segyio.create_text_header(lines) rows = bytearray(rows, 'ascii') # mutable array of bytes rows[-1] = 128 # \x80 self.ACTUAL_TEXT_HEADER = bytes(rows)
def test_empty_text_header_creation(): text_header = segyio.create_text_header({}) for line_no in range(0, 40): line = text_header[line_no * 80: (line_no + 1) * 80] assert line == "C{0:>2} {1:76}".format(line_no + 1, "")