[segyio] 312/376: Add 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 7a662920de4511665a55662170c08278d93e35f3
Author: Jørgen Kvalsvik <jokva at statoil.com>
Date:   Thu Jun 22 16:00:18 2017 +0200

    Add segyio.tools.rotation
    
    Add the function `segyio.tools.rotation` that finds the rotation,
    defined as the angle between the line between the first and last trace
    on the first line and the axis given by increasing CDP-Y coordinates.
---
 python/segyio/_segyio.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 python/segyio/tools.py  | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+)

diff --git a/python/segyio/_segyio.c b/python/segyio/_segyio.c
index ea63528..a0caf87 100644
--- a/python/segyio/_segyio.c
+++ b/python/segyio/_segyio.c
@@ -1171,6 +1171,52 @@ static PyObject * py_format(PyObject *self, PyObject *args) {
     return out;
 }
 
+static PyObject* py_rotation(PyObject *self, PyObject* args) {
+    PyObject* file = NULL;
+    int line_length;
+    int stride;
+    int offsets;
+    PyObject* linenos;
+    long trace0;
+    int trace_bsize;
+
+    PyArg_ParseTuple( args, "OiiiOli", &file,
+                                       &line_length,
+                                       &stride,
+                                       &offsets,
+                                       &linenos,
+                                       &trace0,
+                                       &trace_bsize );
+
+    segy_file* fp = get_FILE_pointer_from_capsule( file );
+    if( PyErr_Occurred() ) { return NULL; }
+
+    if ( !PyObject_CheckBuffer( linenos ) ) {
+        PyErr_SetString(PyExc_TypeError, "The linenos object is not a correct buffer object");
+        return NULL;
+    }
+
+    Py_buffer buffer;
+    PyObject_GetBuffer(linenos, &buffer, PyBUF_FORMAT | PyBUF_C_CONTIGUOUS);
+    int linenos_sz = PyObject_Length( linenos );
+
+    errno = 0;
+    float rotation;
+    int err = segy_rotation_cw( fp, line_length,
+                                    stride,
+                                    offsets,
+                                    (const int*)buffer.buf,
+                                    linenos_sz,
+                                    &rotation,
+                                    trace0,
+                                    trace_bsize );
+    int errn = errno;
+    PyBuffer_Release( &buffer );
+
+    if( err != 0 ) return py_handle_segy_error_with_index_and_name( err, errn, 0, "Inline" );
+    return PyFloat_FromDouble( rotation );
+}
+
 
 /*  define functions in module */
 static PyMethodDef SegyMethods[] = {
@@ -1210,6 +1256,7 @@ static PyMethodDef SegyMethods[] = {
         {"depth_slice",        (PyCFunction) py_read_depth_slice,   METH_VARARGS, "Read a depth slice."},
         {"get_dt",             (PyCFunction) py_get_dt,             METH_VARARGS, "Read dt from file."},
         {"native",             (PyCFunction) py_format,             METH_VARARGS, "Convert to native float."},
+        {"rotation",           (PyCFunction) py_rotation,           METH_VARARGS, "Find survey clock-wise rotation in radians"},
         {NULL, NULL, 0, NULL}
 };
 
diff --git a/python/segyio/tools.py b/python/segyio/tools.py
index d5ac9a2..81059fa 100644
--- a/python/segyio/tools.py
+++ b/python/segyio/tools.py
@@ -140,3 +140,50 @@ def cube(f):
     smps = len(f.samples)
     dims = (fast, slow, smps) if offs == 1 else (fast, slow, offs, smps)
     return f.trace.raw[:].reshape(dims)
+
+def rotation(f, line = 'fast'):
+    """ Find rotation of the survey
+
+    Since v1.2
+
+    Find the clock-wise rotation and origin of `line` as (rot,cdp-x,cdp-y)
+
+    The clock-wise rotation is defined as the angle in radians between line
+    given by the first and last trace of the first line and the axis that gives
+    increasing CDP-Y, in the direction that gives increasing CDP-X.
+
+    By default, the first line is the 'fast' direction, which is inlines if the
+    file is inline sorted, and crossline if it's crossline sorted. `line`
+    should be any of 'fast', 'slow', 'iline', and 'xline'.
+
+    :type f: SegyFile
+    :type line: str
+    :rtype (float, int, int)
+    """
+
+    if f.unstructured:
+        raise ValueError("Rotation requires a structured file")
+
+    lines = { 'fast': f.fast,
+              'slow': f.slow,
+              'iline': f.iline,
+              'xline': f.xline,
+            }
+
+    if line not in lines:
+        error = "Unknown line '%s'" % line
+        solution = "Must be any of: " % ' '.join(lines.keys())
+        raise ValueError('%s. %s' % (error, solution))
+
+    l = lines[line]
+    origin = f.header[0][segyio.su.cdpx, segyio.su.cdpy]
+    cdpx, cdpy = origin[segyio.su.cdpx], origin[segyio.su.cdpy]
+
+    rot = segyio._segyio.rotation(f.xfd,
+                                  l.len,
+                                  l.stride,
+                                  len(f.offsets),
+                                  l.lines,
+                                  f._tr0,
+                                  f._bsz)
+    return rot, cdpx, cdpy

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