[segyio] 153/376: Merge pull request #70 from jokva/consider-1-by-m-files-sorted-on-m
Jørgen Kvalsvik
jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:24 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 6bfeac059b87f9b09e9689107d1c5e643ec2d5b0
Merge: 3a76c36 b496f67
Author: Jean-Paul <jepebe at users.noreply.github.com>
Date: Tue Dec 6 14:11:57 2016 +0100
Merge pull request #70 from jokva/consider-1-by-m-files-sorted-on-m
Consider 1xM files sorted on M
examples/make-ps-file.py | 4 +--
python/segyio/_segyio.c | 6 ++++-
src/segyio/segy.c | 63 +++++++++++++++++++++++++++++++----------------
tests/CMakeLists.txt | 11 ++++++---
tests/test-data/1x1.sgy | Bin 0 -> 4720 bytes
tests/test-data/1xN.sgy | Bin 0 -> 10320 bytes
tests/test-data/Mx1.sgy | Bin 0 -> 10320 bytes
tests/test_segy.py | 13 ++++++++++
8 files changed, 69 insertions(+), 28 deletions(-)
diff --cc tests/test_segy.py
index 31b05fc,4f2e411..c32a367
--- a/tests/test_segy.py
+++ b/tests/test_segy.py
@@@ -470,199 -502,200 +473,209 @@@ class TestSegy(TestCase)
with segyio.open(self.filename, "r", 189, 2) as f:
pass
+ def test_wonky_dimensions(self):
+ with segyio.open(self.fileMx1) as f:
+ pass
+
+ with segyio.open(self.file1xN) as f:
+ pass
+
+ with segyio.open(self.file1x1) as f:
+ pass
+
def test_create_sgy(self):
- dstfile = self.filename.replace(".sgy", "-created.sgy")
+ with TestContext("create_sgy") as context:
+ context.copy_file(self.filename)
+ src_file = "small.sgy"
+ dst_file = "small_created.sgy"
+ with segyio.open(src_file, "r") as src:
+ spec = segyio.spec()
+ spec.format = int(src.format)
+ spec.sorting = int(src.sorting)
+ spec.samples = src.samples
+ spec.ilines = src.ilines
+ spec.xlines = src.xlines
- with segyio.open(self.filename, "r") as src:
- spec = segyio.spec()
- spec.format = int(src.format)
- spec.sorting = int(src.sorting)
- spec.samples = src.samples
- spec.ilines = src.ilines
- spec.xlines = src.xlines
-
- with segyio.create(dstfile, spec) as dst:
- dst.text[0] = src.text[0]
- dst.bin = src.bin
+ with segyio.create(dst_file, spec) as dst:
+ dst.text[0] = src.text[0]
+ dst.bin = src.bin
- # copy all headers
- dst.header = src.header
+ # copy all headers
+ dst.header = src.header
- for i, srctr in enumerate(src.trace):
- dst.trace[i] = srctr
+ for i, srctr in enumerate(src.trace):
+ dst.trace[i] = srctr
- dst.trace = src.trace
+ dst.trace = src.trace
- # this doesn't work yet, some restructuring is necessary
- # if it turns out to be a desired feature it's rather easy to do
- #for dsth, srch in zip(dst.header, src.header):
- # dsth = srch
+ # this doesn't work yet, some restructuring is necessary
+ # if it turns out to be a desired feature it's rather easy to do
+ #for dsth, srch in zip(dst.header, src.header):
+ # dsth = srch
- #for dsttr, srctr in zip(dst.trace, src.trace):
- # dsttr = srctr
+ #for dsttr, srctr in zip(dst.trace, src.trace):
+ # dsttr = srctr
- self.assertTrue(filecmp.cmp(self.filename, dstfile))
+ self.assertTrue(filecmp.cmp(src_file, dst_file))
def test_create_sgy_shorter_traces(self):
- dstfile = self.filename.replace(".sgy", "-shorter.sgy")
+ with TestContext("create_sgy_shorter_traces") as context:
+ context.copy_file(self.filename)
+ src_file = "small.sgy"
+ dst_file = "small_created_shorter.sgy"
+
+ with segyio.open(src_file, "r") as src:
+ spec = segyio.spec()
+ spec.format = int(src.format)
+ spec.sorting = int(src.sorting)
+ spec.samples = 20 # reduces samples per trace
+ spec.ilines = src.ilines
+ spec.xlines = src.xlines
+
+ with segyio.create(dst_file, spec) as dst:
+ for i, srch in enumerate(src.header):
+ dst.header[i] = srch
+ d = { TraceField.INLINE_3D: srch[TraceField.INLINE_3D] + 100 }
+ dst.header[i] = d
+
+ for lineno in dst.ilines:
+ dst.iline[lineno] = src.iline[lineno]
+
+ # alternative form using left-hand-side slices
+ dst.iline[2:4] = src.iline
+
+ for lineno in dst.xlines:
+ dst.xline[lineno] = src.xline[lineno]
+
+ with segyio.open(dst_file, "r") as dst:
+ self.assertEqual(20, dst.samples)
+ self.assertEqual([x + 100 for x in src.ilines], list(dst.ilines))
- with segyio.open(self.filename, "r") as src:
+ def test_create_from_naught(self):
+ with TestContext("create_from_naught") as context:
+ fname = "mk.sgy"
spec = segyio.spec()
- spec.format = int(src.format)
- spec.sorting = int(src.sorting)
- spec.samples = 20 # reduces samples per trace
- spec.ilines = src.ilines
- spec.xlines = src.xlines
+ spec.format = 5
+ spec.sorting = 2
+ spec.samples = 150
+ spec.ilines = range(1, 11)
+ spec.xlines = range(1, 6)
- with segyio.create(dstfile, spec) as dst:
- for i, srch in enumerate(src.header):
- dst.header[i] = srch
- d = { TraceField.INLINE_3D: srch[TraceField.INLINE_3D] + 100 }
- dst.header[i] = d
+ with segyio.create(fname, spec) as dst:
+ tr = np.arange( start = 1.000, stop = 1.151, step = 0.001, dtype = np.single)
- for lineno in dst.ilines:
- dst.iline[lineno] = src.iline[lineno]
+ for i in range( len( dst.trace ) ):
+ dst.trace[i] = tr
+ tr += 1.000
- # alternative form using left-hand-side slices
- dst.iline[2:4] = src.iline
+ for il in spec.ilines:
+ dst.header.iline[il] = { TraceField.INLINE_3D: il }
- for lineno in dst.xlines:
- dst.xline[lineno] = src.xline[lineno]
+ for xl in spec.xlines:
+ dst.header.xline[xl] = { TraceField.CROSSLINE_3D: xl }
- with segyio.open(dstfile, "r") as dst:
- self.assertEqual(20, dst.samples)
- self.assertEqual([x + 100 for x in src.ilines], list(dst.ilines))
+ # Set header field 'offset' to 1 in all headers
+ dst.header = { TraceField.offset: 1 }
- def test_create_from_naught(self):
- fname = "test-data/mk.sgy"
- spec = segyio.spec()
- spec.format = 5
- spec.sorting = 2
- spec.samples = 150
- spec.ilines = range(1, 11)
- spec.xlines = range(1, 6)
-
- with segyio.create(fname, spec) as dst:
- tr = np.arange( start = 1.000, stop = 1.151, step = 0.001, dtype = np.single)
-
- for i in range( len( dst.trace ) ):
- dst.trace[i] = tr
- tr += 1.000
-
- for il in spec.ilines:
- dst.header.iline[il] = { TraceField.INLINE_3D: il }
-
- for xl in spec.xlines:
- dst.header.xline[xl] = { TraceField.CROSSLINE_3D: xl }
-
- # Set header field 'offset' to 1 in all headers
- dst.header = { TraceField.offset: 1 }
-
- with segyio.open(fname, "r") as f:
- self.assertAlmostEqual(1, f.trace[0][0], places = 4)
- self.assertAlmostEqual(1.001, f.trace[0][1], places = 4)
- self.assertAlmostEqual(1.149, f.trace[0][-1], places = 4)
- self.assertAlmostEqual(50.100, f.trace[-1][100], places = 4)
- self.assertEqual(f.header[0][TraceField.offset], f.header[1][TraceField.offset])
- self.assertEqual(1, f.header[1][TraceField.offset])
+ with segyio.open(fname, "r") as f:
+ self.assertAlmostEqual(1, f.trace[0][0], places = 4)
+ self.assertAlmostEqual(1.001, f.trace[0][1], places = 4)
+ self.assertAlmostEqual(1.149, f.trace[0][-1], places = 4)
+ self.assertAlmostEqual(50.100, f.trace[-1][100], places = 4)
+ self.assertEqual(f.header[0][TraceField.offset], f.header[1][TraceField.offset])
+ self.assertEqual(1, f.header[1][TraceField.offset])
def test_create_from_naught_prestack(self):
- fname = "test-data/mk-ps.sgy"
- spec = segyio.spec()
- spec.format = 5
- spec.sorting = 2
- spec.samples = 7
- spec.ilines = range(1, 4)
- spec.xlines = range(1, 3)
- spec.offsets = range(1, 6)
-
- cube_size = len(spec.ilines) * len(spec.xlines)
-
- with segyio.create(fname, spec) as dst:
- arr = np.arange( start = 0.000,
- stop = 0.007,
- step = 0.001,
- dtype = np.single)
-
- arr = np.concatenate([[arr + 0.01], [arr + 0.02]], axis = 0)
- lines = [arr + i for i in spec.ilines]
- cube = [(off * 100) + line for line in lines for off in spec.offsets]
-
- dst.iline[:,:] = cube
-
- for of in spec.offsets:
- for il in spec.ilines:
- dst.header.iline[il,of] = { TraceField.INLINE_3D: il,
- TraceField.offset: of
- }
- for xl in spec.xlines:
- dst.header.xline[xl,of] = { TraceField.CROSSLINE_3D: xl }
-
- with segyio.open(fname, "r") as f:
- self.assertAlmostEqual(101.010, f.trace[0][0], places = 4)
- self.assertAlmostEqual(101.011, f.trace[0][1], places = 4)
- self.assertAlmostEqual(101.016, f.trace[0][-1], places = 4)
- self.assertAlmostEqual(503.025, f.trace[-1][5], places = 4)
- self.assertNotEqual(f.header[0][TraceField.offset], f.header[1][TraceField.offset])
- self.assertEqual(1, f.header[0][TraceField.offset])
- self.assertEqual(2, f.header[1][TraceField.offset])
-
- for x, y in zip(f.iline[:,:], cube):
- self.assertListEqual(list(x.flatten()), list(y.flatten()))
+ with TestContext("create_from_naught_prestack") as context:
+ fname = "mk-ps.sgy"
+ spec = segyio.spec()
+ spec.format = 5
+ spec.sorting = 2
+ spec.samples = 7
+ spec.ilines = range(1, 4)
+ spec.xlines = range(1, 3)
+ spec.offsets = range(1, 6)
+
+ cube_size = len(spec.ilines) * len(spec.xlines)
+
+ with segyio.create(fname, spec) as dst:
+ arr = np.arange( start = 0.000,
+ stop = 0.007,
+ step = 0.001,
+ dtype = np.single)
+
+ arr = np.concatenate([[arr + 0.01], [arr + 0.02]], axis = 0)
+ lines = [arr + i for i in spec.ilines]
+ cube = [(off * 100) + line for line in lines for off in spec.offsets]
+
+ dst.iline[:,:] = cube
+
+ for of in spec.offsets:
+ for il in spec.ilines:
+ dst.header.iline[il,of] = { TraceField.INLINE_3D: il,
+ TraceField.offset: of
+ }
+ for xl in spec.xlines:
+ dst.header.xline[xl,of] = { TraceField.CROSSLINE_3D: xl }
+
+ with segyio.open(fname, "r") as f:
+ self.assertAlmostEqual(101.010, f.trace[0][0], places = 4)
+ self.assertAlmostEqual(101.011, f.trace[0][1], places = 4)
+ self.assertAlmostEqual(101.016, f.trace[0][-1], places = 4)
+ self.assertAlmostEqual(503.025, f.trace[-1][5], places = 4)
+ self.assertNotEqual(f.header[0][TraceField.offset], f.header[1][TraceField.offset])
+ self.assertEqual(1, f.header[0][TraceField.offset])
+ self.assertEqual(2, f.header[1][TraceField.offset])
+
+ for x, y in zip(f.iline[:,:], cube):
+ self.assertListEqual(list(x.flatten()), list(y.flatten()))
def test_create_write_lines(self):
- fname = "test-data/mklines.sgy"
+ fname = "mklines.sgy"
- mklines(fname)
+ with TestContext("create_write_lines") as context:
+ mklines(fname)
- with segyio.open(fname, "r") as f:
- self.assertAlmostEqual(1, f.iline[1][0][0], places = 4)
- self.assertAlmostEqual(2.004, f.iline[2][0][4], places = 4)
- self.assertAlmostEqual(2.014, f.iline[2][1][4], places = 4)
- self.assertAlmostEqual(8.043, f.iline[8][4][3], places = 4)
+ with segyio.open(fname, "r") as f:
+ self.assertAlmostEqual(1, f.iline[1][0][0], places = 4)
+ self.assertAlmostEqual(2.004, f.iline[2][0][4], places = 4)
+ self.assertAlmostEqual(2.014, f.iline[2][1][4], places = 4)
+ self.assertAlmostEqual(8.043, f.iline[8][4][3], places = 4)
def test_create_sgy_skip_lines(self):
- fname = "test-data/lines.sgy"
- dstfile = fname.replace(".sgy", "-halved.sgy")
-
- mklines(fname)
-
- with segyio.open(fname, "r") as src:
- spec = segyio.spec()
- spec.format = int(src.format)
- spec.sorting = int(src.sorting)
- spec.samples = src.samples
- spec.ilines = src.ilines[::2]
- spec.xlines = src.xlines[::2]
-
- with segyio.create(dstfile, spec) as dst:
- # use the inline headers as base
- dst.header.iline = src.header.iline[::2]
- # then update crossline numbers from the crossline headers
- for xl in dst.xlines:
- f = next(src.header.xline[xl])[TraceField.CROSSLINE_3D]
- dst.header.xline[xl] = { TraceField.CROSSLINE_3D: f }
-
- # but we override the last xline to be 6, not 5
- dst.header.xline[5] = { TraceField.CROSSLINE_3D: 6 }
- dst.iline = src.iline[::2]
-
- with segyio.open(dstfile, "r") as f:
- self.assertListEqual(list(f.ilines), list(spec.ilines))
- self.assertListEqual(list(f.xlines), [1, 3, 6])
- self.assertAlmostEqual(1, f.iline[1][0][0], places = 4)
- self.assertAlmostEqual(3.004, f.iline[3][0][4], places = 4)
- self.assertAlmostEqual(3.014, f.iline[3][1][4], places = 4)
- self.assertAlmostEqual(7.023, f.iline[7][2][3], places = 4)
+ fname = "lines.sgy"
+ dstfile = "lines-halved.sgy"
+
+ with TestContext("create_sgy_skip_lines") as context:
+ mklines(fname)
+
+ with segyio.open(fname, "r") as src:
+ spec = segyio.spec()
+ spec.format = int(src.format)
+ spec.sorting = int(src.sorting)
+ spec.samples = src.samples
+ spec.ilines = src.ilines[::2]
+ spec.xlines = src.xlines[::2]
+
+ with segyio.create(dstfile, spec) as dst:
+ # use the inline headers as base
+ dst.header.iline = src.header.iline[::2]
+ # then update crossline numbers from the crossline headers
+ for xl in dst.xlines:
+ f = next(src.header.xline[xl])[TraceField.CROSSLINE_3D]
+ dst.header.xline[xl] = { TraceField.CROSSLINE_3D: f }
+
+ # but we override the last xline to be 6, not 5
+ dst.header.xline[5] = { TraceField.CROSSLINE_3D: 6 }
+ dst.iline = src.iline[::2]
+
+ with segyio.open(dstfile, "r") as f:
+ self.assertListEqual(list(f.ilines), list(spec.ilines))
+ self.assertListEqual(list(f.xlines), [1, 3, 6])
+ self.assertAlmostEqual(1, f.iline[1][0][0], places = 4)
+ self.assertAlmostEqual(3.004, f.iline[3][0][4], places = 4)
+ self.assertAlmostEqual(3.014, f.iline[3][1][4], places = 4)
+ self.assertAlmostEqual(7.023, f.iline[7][2][3], places = 4)
def test_segyio_types(self):
with segyio.open(self.filename, "r") as f:
--
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