[segyio] 313/376: Add test for segyio.tools.rotation
Jørgen Kvalsvik
jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:51 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 e5e5184f2f3c52f5f3781fa94adc08363f1877f2
Author: Jørgen Kvalsvik <jokva at statoil.com>
Date: Thu Jun 22 16:00:43 2017 +0200
Add test for segyio.tools.rotation
In order to test rotation, create a series of 8 files all with the first
line in a given quadrant or parallel to an axis. The example program
make-rotated-copies.py was used to generate the files.
---
README.md | 5 +-
python/CMakeLists.txt | 1 +
python/examples/make-rotated-copies.py | 94 +++++++++++++++++++++++++++++++++
python/test/tools.py | 28 ++++++++++
test-data/acute-small.sgy | Bin 0 -> 14600 bytes
test-data/inv-acute-small.sgy | Bin 0 -> 14600 bytes
test-data/left-small.sgy | Bin 0 -> 14600 bytes
test-data/normal-small.sgy | Bin 0 -> 14600 bytes
test-data/obtuse-small.sgy | Bin 0 -> 14600 bytes
test-data/reflex-small.sgy | Bin 0 -> 14600 bytes
test-data/right-small.sgy | Bin 0 -> 14600 bytes
test-data/straight-small.sgy | Bin 0 -> 14600 bytes
12 files changed, 126 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 49380e6..d490472 100644
--- a/README.md
+++ b/README.md
@@ -125,12 +125,13 @@ demos in this
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`
-and `make-ps-file.py` as such:
+reproduce the data file, build Segyio and run the test program `make-file.py`,
+`make-ps-file.py`, and `make-rotated-copies.py` as such:
```
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
+python examples/make-rotated-copies.py small.sgy
```
If you have have small data files with a free license, feel free to submit it
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index 8c878df..02df26e 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -89,4 +89,5 @@ add_python_example(pysegyio python.example.write examples/write.py test-
add_python_example(pysegyio python.example.makefile examples/make-file.py test-data/large-file.sgy 20 1 20 1 20)
add_python_example(pysegyio python.example.makepsfile examples/make-ps-file.py test-data/small-prestack.sgy 10 1 5 1 4 1 3)
add_python_example(pysegyio python.example.subcube examples/copy-sub-cube.py test-data/small.sgy test-data/copy.sgy)
+add_python_example(pysegyio python.example.rotate examples/make-rotated-copies.py test-data/small.sgy)
add_python_example(pysegyio python.example.scan_min_max examples/scan_min_max.py test-data/small.sgy)
diff --git a/python/examples/make-rotated-copies.py b/python/examples/make-rotated-copies.py
new file mode 100644
index 0000000..18a9326
--- /dev/null
+++ b/python/examples/make-rotated-copies.py
@@ -0,0 +1,94 @@
+import sys
+import os
+import shutil
+import itertools as itr
+import segyio
+import segyio.su as su
+
+def product(f):
+ return itr.product(range(len(f.ilines)), range(len(f.xlines)))
+
+def pathjoin(prefix, path):
+ dir, base = os.path.split(path)
+ return os.path.join(dir, '-'.join((prefix, base)))
+
+# this program copies the source-file and creates eight copies, each with a
+# modified set of CDP-X and CDP-Y coordinates, rotating the field around the
+# north (increasing CDP-Y) axis.
+def main():
+ if len(sys.argv) < 2:
+ sys.exit("Usage: {} [source-file] [destination-file]".format(sys.argv[0]))
+
+ srcfile = sys.argv[1]
+ dstfile = sys.argv[2] if len(sys.argv) > 2 else srcfile
+
+ for pre in ['normal', 'acute', 'right', 'obtuse', 'straight', 'reflex', 'left', 'inv-acute']:
+ fname = pathjoin(pre, dstfile)
+ shutil.copyfile(srcfile, fname)
+
+ with segyio.open(srcfile) as src, segyio.open(fname, 'r+') as dst:
+ for i in range(1 + src.ext_headers):
+ dst.text[i] = src.text[i]
+
+ dst.bin = src.bin
+ dst.trace = src.trace
+ dst.header = src.header
+
+ with segyio.open(pathjoin('normal', dstfile), 'r+') as dst:
+ for i, (x, y) in enumerate(product(src)):
+ trh = dst.header[i]
+ trh[su.cdpx] = x
+ trh[su.cdpy] = y
+ trh[su.scalco] = 10
+
+ with segyio.open(pathjoin('acute', dstfile), 'r+') as dst:
+ for i, (x, y) in enumerate(product(src)):
+ trh = dst.header[y + x * len(src.ilines)]
+ trh[su.cdpx] = x + y
+ trh[su.cdpy] = (100 - x) + y
+ trh[su.scalco] = -10
+
+ with segyio.open(pathjoin('right', dstfile), 'r+') as dst:
+ for i, (x, y) in enumerate(product(src)):
+ trh = dst.header[i]
+ trh[su.cdpx] = y
+ trh[su.cdpy] = 100 - x
+ trh[su.scalco] = 1
+
+ with segyio.open(pathjoin('obtuse', dstfile), 'r+') as dst:
+ for i, (x, y) in enumerate(product(src)):
+ trh = dst.header[i]
+ trh[su.cdpx] = (100 - x) + y
+ trh[su.cdpy] = (100 - x) - y
+ trh[su.scalco] = 2
+
+ with segyio.open(pathjoin('straight', dstfile), 'r+') as dst:
+ for i, (x, y) in enumerate(product(src)):
+ trh = dst.header[i]
+ trh[su.cdpx] = 100 - x
+ trh[su.cdpy] = 100 - y
+ trh[su.scalco] = -7
+
+ with segyio.open(pathjoin('reflex', dstfile), 'r+') as dst:
+ for i, (x, y) in enumerate(product(src)):
+ trh = dst.header[i]
+ trh[su.cdpx] = 100 - (x + y)
+ trh[su.cdpy] = 100 + (x - y)
+ trh[su.scalco] = 7
+
+ with segyio.open(pathjoin('left', dstfile), 'r+') as dst:
+ for i, (x, y) in enumerate(product(src)):
+ trh = dst.header[i]
+ trh[su.cdpx] = 100 - y
+ trh[su.cdpy] = x
+ trh[su.scalco] = 21
+
+ with segyio.open(pathjoin('inv-acute', dstfile), 'r+') as dst:
+ for i, (x, y) in enumerate(product(src)):
+ trh = dst.header[i]
+ trh[su.cdpx] = 100 + x - y
+ trh[su.cdpy] = x + y
+ trh[su.scalco] = 100
+
+if __name__ == '__main__':
+ main()
diff --git a/python/test/tools.py b/python/test/tools.py
index 253715a..415aa3f 100644
--- a/python/test/tools.py
+++ b/python/test/tools.py
@@ -1,5 +1,7 @@
+from __future__ import division
from unittest import TestCase
+import math
from segyio import BinField
from segyio import TraceField
import numpy as np
@@ -99,3 +101,29 @@ class ToolsTest(TestCase):
dims = (len(f.ilines), len(f.xlines), len(f.offsets), len(f.samples))
x = segyio.tools.collect(f.trace[:]).reshape(dims)
self.assertTrue(np.all(x == segyio.tools.cube(f)))
+
+ def test_unstructured_rotation(self):
+ with self.assertRaises(ValueError):
+ with segyio.open(self.filename, ignore_geometry = True) as f:
+ segyio.tools.rotation(f)
+
+ def test_rotation(self):
+ names = ['normal', 'acute', 'right', 'obtuse',
+ 'straight', 'reflex', 'left', 'inv-acute']
+ angles = [0.000, 0.785, 1.571, 2.356,
+ 3.142, 3.927, 4.712, 5.498]
+ rights = [1.571, 2.356, 3.142, 3.927,
+ 4.712, 5.498, 0.000, 0.785 ]
+
+ def rotation(x, **kwargs): return segyio.tools.rotation(x, **kwargs)[0]
+ close = self.assertAlmostEqual
+
+ for name, angle, right in zip(names, angles, rights):
+ src = self.filename.replace('/', '/' + name + '-')
+
+ with segyio.open(src) as f:
+ close(angle, rotation(f), places = 3)
+ close(angle, rotation(f, line = 'fast'), places = 3)
+ close(angle, rotation(f, line = 'iline'), places = 3)
+ close(right, rotation(f, line = 'slow'), places = 3)
+ close(right, rotation(f, line = 'xline'), places = 3)
diff --git a/test-data/acute-small.sgy b/test-data/acute-small.sgy
new file mode 100644
index 0000000..0e0faeb
Binary files /dev/null and b/test-data/acute-small.sgy differ
diff --git a/test-data/inv-acute-small.sgy b/test-data/inv-acute-small.sgy
new file mode 100644
index 0000000..c01de07
Binary files /dev/null and b/test-data/inv-acute-small.sgy differ
diff --git a/test-data/left-small.sgy b/test-data/left-small.sgy
new file mode 100644
index 0000000..5769e91
Binary files /dev/null and b/test-data/left-small.sgy differ
diff --git a/test-data/normal-small.sgy b/test-data/normal-small.sgy
new file mode 100644
index 0000000..f8cd0e7
Binary files /dev/null and b/test-data/normal-small.sgy differ
diff --git a/test-data/obtuse-small.sgy b/test-data/obtuse-small.sgy
new file mode 100644
index 0000000..cbcf6db
Binary files /dev/null and b/test-data/obtuse-small.sgy differ
diff --git a/test-data/reflex-small.sgy b/test-data/reflex-small.sgy
new file mode 100644
index 0000000..83f9b4c
Binary files /dev/null and b/test-data/reflex-small.sgy differ
diff --git a/test-data/right-small.sgy b/test-data/right-small.sgy
new file mode 100644
index 0000000..96f05a7
Binary files /dev/null and b/test-data/right-small.sgy differ
diff --git a/test-data/straight-small.sgy b/test-data/straight-small.sgy
new file mode 100644
index 0000000..8a59ce7
Binary files /dev/null and b/test-data/straight-small.sgy differ
--
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