[segyio] 118/376: make-ps-file.py; example program for pre-stack

Jørgen Kvalsvik jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:18 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 87775978e634b4590c8a54c5172d94edf6da5a99
Author: Jørgen Kvalsvik <jokva at statoil.com>
Date:   Wed Nov 9 16:23:54 2016 +0100

    make-ps-file.py; example program for pre-stack
    
    The make-ps-file.py program will create a prestack file using more or
    less the same scheme as make-file.py. Also adds one outputted prestack
    file for testing purposes.
---
 README.md                    |   5 ++--
 examples/CMakeLists.txt      |   1 +
 examples/make-ps-file.py     |  60 +++++++++++++++++++++++++++++++++++++++++++
 tests/CMakeLists.txt         |   1 +
 tests/test-data/small-ps.sgy | Bin 0 -> 10320 bytes
 tests/test_segy.py           |  26 +++++++++++++++++++
 6 files changed, 91 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index bdc6c87..9109874 100644
--- a/README.md
+++ b/README.md
@@ -107,10 +107,11 @@ Small SEG Y formatted files are included in the repository for test purposes.
 Phyiscally speaking the data is non-sensical, but it is reproducible by using
 Segyio. The tests file are located in the tests/test-data directory. To
 reproduce the data file, build Segyio and run the test program `make-file.py`
-as such:
+and `make-ps-file.py` as such:
 
 ```
-python examples/make-file.py out.sgy 50 1 6 20 25
+python examples/make-file.py small.sgy 50 1 6 20 25
+python examples/make-ps-file.py small-ps.sgy 10 1 5 1 4 1 3
 ```
 
 If you have have small data files with a free license, feel free to submit it
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index ee72a57..a48d185 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -4,5 +4,6 @@ configure_file(../tests/test-data/small.sgy test-data/small.sgy COPYONLY)
 add_python_example(python.examples.about about.py test-data/small.sgy INLINE_3D CROSSLINE_3D)
 add_python_example(python.examples.write write.py test-data/small.sgy)
 add_python_example(python.examples.makefile make-file.py test-data/large-file.sgy 20 1 20 1 20)
+add_python_example(python.examples.makepsfile make-ps-file.py test-data/small-prestack.sgy 10 1 5 1 4 1 3)
 add_python_example(python.examples.subcube copy-sub-cube.py test-data/small.sgy test-data/copy.sgy)
 add_python_example(python.examples.scan_min_max scan_min_max.py test-data/small.sgy)
diff --git a/examples/make-ps-file.py b/examples/make-ps-file.py
new file mode 100644
index 0000000..21ff9d5
--- /dev/null
+++ b/examples/make-ps-file.py
@@ -0,0 +1,60 @@
+import sys
+import numpy as np
+import segyio
+from itertools import izip as izip
+
+def main():
+    if len(sys.argv) < 9:
+        sys.exit(" ".join( "Usage: {} [file] [samples]",
+                           "[first iline] [last iline]",
+                           "[first xline] [last xline]",
+                           "([first offset] [last offset])"
+                         ).format(sys.argv[0]))
+
+    spec = segyio.spec()
+    filename = sys.argv[1]
+
+# to create a file from nothing, we need to tell segyio about the structure of
+# the file, i.e. its inline numbers, crossline numbers, etc. You can also add
+# more structural information, This is the absolute minimal specification for a
+# N-by-M volume with K offsets volume
+    spec.sorting = 2
+    spec.format = 1
+    spec.samples = int(sys.argv[2])
+    spec.ilines = range(*map(int, sys.argv[3:5]))
+    spec.xlines = range(*map(int, sys.argv[5:7]))
+    spec.offsets = range(*map(int, sys.argv[7:9]))
+    if len(spec.offsets) == 0: spec.offsets = [1]
+
+    with segyio.create(filename, spec) as f:
+        # one inline consists of 50 traces
+        # which in turn consists of 2000 samples
+        start = 0.0
+        step = 0.00001
+        # fill a trace with predictable values: left-of-comma is the inline
+        # number. Immediately right of comma is the crossline number
+        # the rightmost digits is the index of the sample in that trace meaning
+        # looking up an inline's i's jth crosslines' k should be roughly equal
+        # to (offset*100) + i.j0k.
+        trace = np.arange(start = start,
+                          stop  = start + step * spec.samples,
+                          step  = step,
+                          dtype = np.single)
+
+        nx, no = len(spec.xlines), len(spec.offsets)
+        # one inline is N traces concatenated. We fill in the xline number
+        line = np.concatenate([trace + (xl / 100.0) for xl in spec.xlines])
+        line = line.reshape( (nx, spec.samples) )
+
+        for ilindex, ilno in enumerate(spec.ilines):
+            iline = line + ilno
+            for tr, xlno in enumerate(spec.xlines):
+                for offset_index, offset in enumerate(spec.offsets):
+                    ix = (ilindex * nx * no) + (tr * no) + offset_index
+                    f.trace[ix] = iline[tr] + (offset * 100)
+                    f.header[ix] = { segyio.TraceField.INLINE_3D: ilno,
+                                     segyio.TraceField.CROSSLINE_3D: xlno,
+                                     segyio.TraceField.offset: offset }
+
+if __name__ == '__main__':
+    main()
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index be98c05..05a9c88 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,4 +1,5 @@
 configure_file(test-data/small.sgy test-data/small.sgy COPYONLY)
+configure_file(test-data/small-ps.sgy test-data/small-ps.sgy COPYONLY)
 configure_file(test-data/text.sgy  test-data/text.sgy COPYONLY)
 configure_file(test-data/small.sgy test-data/small-traceheader.sgy COPYONLY)
 
diff --git a/tests/test-data/small-ps.sgy b/tests/test-data/small-ps.sgy
new file mode 100644
index 0000000..69264ff
Binary files /dev/null and b/tests/test-data/small-ps.sgy differ
diff --git a/tests/test_segy.py b/tests/test_segy.py
index cd8a5c1..11a3208 100644
--- a/tests/test_segy.py
+++ b/tests/test_segy.py
@@ -47,6 +47,7 @@ class TestSegy(TestCase):
 
     def setUp(self):
         self.filename = "test-data/small.sgy"
+        self.prestack = "test-data/small-ps.sgy"
 
     def test_inline_4(self):
         with segyio.open(self.filename, "r") as f:
@@ -179,6 +180,31 @@ class TestSegy(TestCase):
             for i, trace in enumerate(f.trace[0:6:2, buf]):
                 self.assertTrue(np.array_equal(trace, traces[i]))
 
+    def test_traces_offset(self):
+        with segyio.open(self.prestack, "r") as f:
+
+            self.assertEqual(2, len(f.offsets))
+            self.assertListEqual([1, 2], list(f.offsets))
+
+            # traces are laid out |l1o1 l1o2 l2o1 l2o2...|
+            # where l = iline number and o = offset number
+            # traces are not re-indexed according to offsets
+            # see make-ps-file.py for value formula
+            self.assertAlmostEqual(101.01, f.trace[0][0], places = 4)
+            self.assertAlmostEqual(201.01, f.trace[1][0], places = 4)
+            self.assertAlmostEqual(101.02, f.trace[2][0], places = 4)
+            self.assertAlmostEqual(201.02, f.trace[3][0], places = 4)
+            self.assertAlmostEqual(102.01, f.trace[6][0], places = 4)
+
+    def test_headers_offset(self):
+        with segyio.open(self.prestack, "r") as f:
+            il, xl = TraceField.INLINE_3D, TraceField.CROSSLINE_3D
+            self.assertEqual(f.header[0][il], f.header[1][il])
+            self.assertEqual(f.header[1][il], f.header[2][il])
+
+            self.assertEqual(f.header[0][xl], f.header[1][xl])
+            self.assertNotEqual(f.header[1][xl], f.header[2][xl])
+
     def test_line_generators(self):
         with segyio.open(self.filename, "r") as f:
             for line in f.iline:

-- 
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