[segyio] 148/376: Created a tool for making textual headers
Jørgen Kvalsvik
jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:23 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 5a570f96de3bdfb92274c19573f7dc430cfb5904
Author: Jean-Paul Balabanian <jepebe at users.noreply.github.com>
Date: Mon Dec 5 15:32:16 2016 +0100
Created a tool for making textual headers
---
python/segyio/__init__.py | 2 +-
python/segyio/create.py | 10 +---------
python/segyio/tools.py | 22 ++++++++++++++++++++++
tests/test_tools.py | 16 +++++++++++++++-
4 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/python/segyio/__init__.py b/python/segyio/__init__.py
index 556bb4c..cd7a93a 100644
--- a/python/segyio/__init__.py
+++ b/python/segyio/__init__.py
@@ -86,7 +86,7 @@ from .binfield import BinField
from .open import open
from .create import create
from .segy import SegyFile, spec
-from .tools import dt, sample_indexes
+from .tools import dt, sample_indexes, create_text_header
__version__ = '1.0.4'
__copyright__ = 'Copyright 2016, Statoil ASA'
diff --git a/python/segyio/create.py b/python/segyio/create.py
index d3fadfb..29a5a67 100644
--- a/python/segyio/create.py
+++ b/python/segyio/create.py
@@ -14,15 +14,7 @@ def default_text_header(iline, xline, offset):
13: " CROSSLINE BYTES %03d-%03d |" % (xline, xline + 4),
15: "END EBCDIC HEADER",
}
- rows = []
- for line_no in range(1, 41):
- line = ""
- if line_no in lines:
- line = lines[line_no]
- row = "C{0:>2} {1:76}".format(line_no, line)
- rows.append(row)
-
- rows = ''.join(rows)
+ 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
diff --git a/python/segyio/tools.py b/python/segyio/tools.py
index 1d92803..8d66405 100644
--- a/python/segyio/tools.py
+++ b/python/segyio/tools.py
@@ -28,3 +28,25 @@ def sample_indexes(segyfile, t0=0.0, dt_override=None):
dt_override = dt(segyfile)
return [t0 + t * dt_override for t in range(segyfile.samples)]
+
+
+def create_text_header(lines):
+ """
+ Will create a "correct" SEG-Y textual header.
+ Every line will be prefixed with C## and there are 40 lines.
+ The input must be a dictionary with the line number[1-40] as a key.
+ The value for each key should be up to 76 character long string.
+
+ :type lines: dict[int, str]
+ :rtype: str
+ """
+ rows = []
+ for line_no in range(1, 41):
+ line = ""
+ if line_no in lines:
+ line = lines[line_no]
+ row = "C{0:>2} {1:76}".format(line_no, line)
+ rows.append(row)
+
+ rows = ''.join(rows)
+ return rows
\ No newline at end of file
diff --git a/tests/test_tools.py b/tests/test_tools.py
index 92130f0..f762c91 100644
--- a/tests/test_tools.py
+++ b/tests/test_tools.py
@@ -37,7 +37,7 @@ class ToolsTest(TestCase):
f.bin[BinField.Interval] = dt_us
f.header[0][TraceField.TRACE_SAMPLE_INTERVAL] = dt_us
f.flush()
- np.testing.assert_almost_equal(segyio.dt(f), dt_us/1000)
+ np.testing.assert_almost_equal(segyio.dt(f), dt_us / 1000)
def test_sample_indexes(self):
with segyio.open(self.filename, "r") as f:
@@ -50,3 +50,17 @@ class ToolsTest(TestCase):
indexes = segyio.sample_indexes(f, t0=1.5, dt_override=3.21)
self.assertListEqual(indexes, [1.5 + t * 3.21 for t in range(f.samples)])
+ def test_empty_text_header_creation(self):
+ text_header = segyio.create_text_header({})
+
+ for line_no in range(0, 40):
+ line = text_header[line_no * 80: (line_no + 1) * 80]
+ self.assertEqual(line, "C{0:>2} {1:76}".format(line_no + 1, ""))
+
+ 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)
+
+ for line_no in range(0, 40):
+ line = text_header[line_no * 80: (line_no + 1) * 80]
+ self.assertEqual(line, "C{0:>2} {1:76}".format(line_no + 1, chr(64 + line_no) * 76))
--
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