[segyio] 151/376: Handle sorting for Mx1, 1xN and 1x1 files.
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 b496f67d9235a4065c5316e53f149f32fc386da1
Author: Jørgen Kvalsvik <jokva at statoil.com>
Date: Mon Dec 5 16:18:10 2016 +0100
Handle sorting for Mx1, 1xN and 1x1 files.
Files with 1-dimensions would sometimes break because line direction is
non-sensical. This patch defines 1-dimension files as if they were MxN
sorted on the non-1 direction, i.e. a file with 1 inline and 1500
crosslines is considered crossline sorted.
---
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 ++++++++++
7 files changed, 67 insertions(+), 26 deletions(-)
diff --git a/python/segyio/_segyio.c b/python/segyio/_segyio.c
index 91ca173..a274071 100644
--- a/python/segyio/_segyio.c
+++ b/python/segyio/_segyio.c
@@ -612,7 +612,11 @@ static PyObject *py_init_metrics(PyObject *self, PyObject *args) {
return PyErr_Format(PyExc_RuntimeError, "Unable to determine sorting. File may be corrupt.");
}
- error = segy_count_lines(p_FILE, field, offset_count, l1out, l2out, trace0, trace_bsize);
+ if( trace_count != offset_count ) {
+ error = segy_count_lines(p_FILE, field, offset_count, l1out, l2out, trace0, trace_bsize);
+ } else {
+ il_count = xl_count = 1;
+ }
if (error != 0) {
return py_handle_segy_error_with_fields(error, errno, il_field, xl_field, 2);
diff --git a/src/segyio/segy.c b/src/segyio/segy.c
index 09a4904..8b14ed9 100644
--- a/src/segyio/segy.c
+++ b/src/segyio/segy.c
@@ -736,6 +736,10 @@ int segy_sorting( segy_file* fp,
segy_get_field( traceheader, xl, &xl0 );
segy_get_field( traceheader, offset, &off0 );
+ size_t traces_size_t;
+ err = segy_traces( fp, &traces_size_t, trace0, trace_bsize );
+ if( err != 0 ) return err;
+ const int traces = traces_size_t;
int traceno = 1;
do {
@@ -746,11 +750,24 @@ int segy_sorting( segy_file* fp,
segy_get_field( traceheader, xl, &xl1 );
segy_get_field( traceheader, offset, &off1 );
++traceno;
- } while( off0 != off1 );
+ } while( off0 != off1 && traceno < traces );
+
+ /*
+ * sometimes files come with Mx1, 1xN or even 1x1 geometries. When this is
+ * the case we look at the last trace and compare it to the first. If these
+ * numbers match we define the sorting direction as the non-1 dimension
+ */
+ err = segy_traceheader( fp, traces - 1, traceheader, trace0, trace_bsize );
+ if( err != SEGY_OK ) return err;
+
+ int il_last, xl_last;
+ segy_get_field( traceheader, il, &il_last );
+ segy_get_field( traceheader, xl, &xl_last );
- // todo: Should expect at least xline, inline or offset to change by one?
- if ( il0 == il1 ) *sorting = INLINE_SORTING;
- else if( xl0 == xl1 ) *sorting = CROSSLINE_SORTING;
+ if ( il0 == il_last ) *sorting = CROSSLINE_SORTING;
+ else if( xl0 == xl_last ) *sorting = INLINE_SORTING;
+ else if( il0 == il1 ) *sorting = INLINE_SORTING;
+ else if( xl0 == xl1 ) *sorting = CROSSLINE_SORTING;
else return SEGY_INVALID_SORTING;
return SEGY_OK;
@@ -774,29 +791,33 @@ int segy_offsets( segy_file* fp,
char header[ SEGY_TRACE_HEADER_SIZE ];
unsigned int offsets = 0;
- do {
- err = segy_traceheader( fp, offsets, header, trace0, trace_bsize );
- if( err != 0 ) return err;
+ if( traces == 1 ) {
+ *out = 1;
+ return SEGY_OK;
+ }
- /*
- * check that field value is sane, so that we don't have to check
- * segy_get_field's error
- */
- if( field_size[ il ] == 0 || field_size[ xl ] == 0 )
- return SEGY_INVALID_FIELD;
+ /*
+ * check that field value is sane, so that we don't have to check
+ * segy_get_field's error
+ */
+ if( field_size[ il ] == 0 || field_size[ xl ] == 0 )
+ return SEGY_INVALID_FIELD;
- segy_get_field( header, il, &il0 );
- segy_get_field( header, xl, &xl0 );
+ err = segy_traceheader( fp, 0, header, trace0, trace_bsize );
+ segy_get_field( header, il, &il0 );
+ segy_get_field( header, xl, &xl0 );
+
+ do {
+ ++offsets;
+
+ if( offsets == traces ) break;
- err = segy_traceheader( fp, offsets + 1, header, trace0, trace_bsize );
+ err = segy_traceheader( fp, offsets, header, trace0, trace_bsize );
if( err != 0 ) return err;
+
segy_get_field( header, il, &il1 );
segy_get_field( header, xl, &xl1 );
-
- ++offsets;
- } while( il0 == il1 && xl0 == xl1 && offsets < traces );
-
- if( offsets >= traces ) return SEGY_INVALID_OFFSETS;
+ } while( il0 == il1 && xl0 == xl1 );
*out = offsets;
return SEGY_OK;
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 37d7aa3..7998317 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,7 +1,10 @@
-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)
+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)
+configure_file(test-data/Mx1.sgy test-data/Mx1.sgy COPYONLY)
+configure_file(test-data/1xN.sgy test-data/1xN.sgy COPYONLY)
+configure_file(test-data/1x1.sgy test-data/1x1.sgy COPYONLY)
add_segyio_test(utils test_utils.c)
add_segyio_test(segy test_segy.c)
diff --git a/tests/test-data/1x1.sgy b/tests/test-data/1x1.sgy
new file mode 100644
index 0000000..2982b35
Binary files /dev/null and b/tests/test-data/1x1.sgy differ
diff --git a/tests/test-data/1xN.sgy b/tests/test-data/1xN.sgy
new file mode 100644
index 0000000..fbf0221
Binary files /dev/null and b/tests/test-data/1xN.sgy differ
diff --git a/tests/test-data/Mx1.sgy b/tests/test-data/Mx1.sgy
new file mode 100644
index 0000000..9f44dd9
Binary files /dev/null and b/tests/test-data/Mx1.sgy differ
diff --git a/tests/test_segy.py b/tests/test_segy.py
index 0eeaa8c..4f2e411 100644
--- a/tests/test_segy.py
+++ b/tests/test_segy.py
@@ -53,6 +53,9 @@ class TestSegy(TestCase):
def setUp(self):
self.filename = "test-data/small.sgy"
self.prestack = "test-data/small-ps.sgy"
+ self.fileMx1 = "test-data/Mx1.sgy"
+ self.file1xN = "test-data/1xN.sgy"
+ self.file1x1 = "test-data/1x1.sgy"
def test_inline_4(self):
with segyio.open(self.filename, "r") as f:
@@ -499,6 +502,16 @@ 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")
--
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