[segyio] 277/376: Add tools.wrap for textual header formatting

Jørgen Kvalsvik jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:44 UTC 2017


This is an automated email from the git hooks/post-receive script.

jokva-guest pushed a commit to branch debian
in repository segyio.

commit 680b8d9f53ef3d4b2bd440caf3c49c3e50e3881a
Author: Lars Petter Øren Hauge <lpha at statoil.com>
Date:   Wed Apr 19 14:00:15 2017 +0200

    Add tools.wrap for textual header formatting
---
 python/segyio/tools.py | 13 ++++++++++++-
 python/test/tools.py   |  5 +++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/python/segyio/tools.py b/python/segyio/tools.py
index 14f36f6..d6dfd09 100644
--- a/python/segyio/tools.py
+++ b/python/segyio/tools.py
@@ -1,6 +1,6 @@
 import segyio
 import numpy as np
-import itertools as itr
+import textwrap
 
 
 def dt(segyfile, fallback_dt=4000.0):
@@ -52,6 +52,17 @@ def create_text_header(lines):
     rows = ''.join(rows)
     return rows
 
+def wrap(s, width=80):
+    """
+    Formats the text input with newlines given the user specified width for each line
+
+    :type s: str
+    :type width: int
+    :rtype: str
+    """
+    return '\n'.join(textwrap.wrap(str(s), width=width))
+
+
 def native(data,
            format = segyio.SegySampleFormat.IBM_FLOAT_4_BYTE,
            copy = True):
diff --git a/python/test/tools.py b/python/test/tools.py
index f2f2f75..253715a 100644
--- a/python/test/tools.py
+++ b/python/test/tools.py
@@ -59,6 +59,11 @@ class ToolsTest(TestCase):
             line = text_header[line_no * 80: (line_no + 1) * 80]
             self.assertEqual(line, "C{0:>2} {1:76}".format(line_no + 1, ""))
 
+    def test_wrap(self):
+        with segyio.open(self.filename, "r") as f:
+            segyio.tools.wrap(f.text[0])
+            segyio.tools.wrap(f.text[0], 90)
+
     def test_values_text_header_creation(self):
         lines = {i + 1: chr(64 + i) * 76 for i in range(40)}
         text_header = segyio.create_text_header(lines)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/segyio.git



More information about the debian-science-commits mailing list