equinor / segyio

Fast Python library for SEGY files.
Other
476 stars 214 forks source link

Text assignment creates no newline #443

Closed GGDRriedel closed 4 years ago

GGDRriedel commented 4 years ago

I am writing a new text header through

with segyio.open(outfile, "r+",ignore_geometry=True) as out:
    out.text[0]=longtext

where longtext is basically "C01 test\n" + "C02 test\n"....

Mot readers(seisee) do not read the EBCDIC header as lines, but rather as a consecutive string and thus the header is displayed incorrectly as one long line

Did I overlook some option in the reader?

jokva commented 4 years ago

Hi,

The text interface is not really aware of lines at all, so you need to replace the newlines with the appropriate amount of whitespace. Segyio, like seisee apparently, treats the header as one long string.

GGDRriedel commented 4 years ago

It would be nice if it basically reversed the behaviour of segyio.tools.wrap

jokva commented 4 years ago

I can see why that would be useful, but I believe it makes more sense to do it outside of segyio.

>>> text = 'foo\nbar\nbaz\nquux\nplus\n'
>>> ''.join([ln.ljust(80) for ln in text.split()])
'foo                                                                             bar                                                                             baz                                                                             quux                                                                            plus                                                                            '

Now this can be assigned to the header, with the behaviour you'd expect.