[segyio] 142/376: Read dt in python. Closes #62
Jørgen Kvalsvik
jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:22 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 9f45658baab9a400a2c472012935c77da2a38ba0
Author: Kjell W. Kongsvik <kwko at statoil.com>
Date: Fri Nov 18 15:12:11 2016 +0100
Read dt in python. Closes #62
---
python/segyio/CMakeLists.txt | 1 +
python/segyio/__init__.py | 1 +
python/segyio/_segyio.c | 20 ++++++++++++++++++++
python/segyio/segy.py | 2 +-
python/segyio/tools.py | 7 +++++++
src/segyio/segy.c | 6 ++----
src/segyio/segy.h | 1 +
tests/test_segy.py | 2 ++
8 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/python/segyio/CMakeLists.txt b/python/segyio/CMakeLists.txt
index a75737f..32621d8 100644
--- a/python/segyio/CMakeLists.txt
+++ b/python/segyio/CMakeLists.txt
@@ -9,6 +9,7 @@ set(PYTHON_SOURCES
tracefield.py
binfield.py
open.py
+ tools.py
create.py
segysampleformat.py
tracesortingformat.py)
diff --git a/python/segyio/__init__.py b/python/segyio/__init__.py
index 1a4edd4..3d48b24 100644
--- a/python/segyio/__init__.py
+++ b/python/segyio/__init__.py
@@ -86,6 +86,7 @@ from .binfield import BinField
from .open import open
from .create import create
from .segy import SegyFile, spec
+from .tools import get_dt
__version__ = '1.0.4'
__copyright__ = 'Copyright 2016, Statoil ASA'
diff --git a/python/segyio/_segyio.c b/python/segyio/_segyio.c
index 83a372a..1294aba 100644
--- a/python/segyio/_segyio.c
+++ b/python/segyio/_segyio.c
@@ -502,6 +502,25 @@ static PyObject *py_trace_bsize(PyObject *self, PyObject *args) {
return Py_BuildValue("I", byte_count);
}
+static PyObject *py_get_dt(PyObject *self, PyObject *args) {
+ errno = 0;
+
+ PyObject *file_capsule = NULL;
+ PyArg_ParseTuple(args, "O", &file_capsule);
+ segy_file *p_FILE = get_FILE_pointer_from_capsule(file_capsule);
+
+ if (PyErr_Occurred()) { return NULL; }
+
+ float dt;
+ int error = segy_sample_interval(p_FILE, &dt);
+ if (error != 0) { return py_handle_segy_error(error, errno); }
+
+ PyObject *dict = PyDict_New();
+ PyDict_SetItemString(dict, "dt", Py_BuildValue("f", dt));
+
+ return Py_BuildValue("O", dict);
+}
+
static PyObject *py_init_line_metrics(PyObject *self, PyObject *args) {
errno = 0;
@@ -1033,6 +1052,7 @@ static PyMethodDef SegyMethods[] = {
{"write_trace", (PyCFunction) py_write_trace, METH_VARARGS, "Write trace data."},
{"read_line", (PyCFunction) py_read_line, METH_VARARGS, "Read a xline/iline from file."},
{"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."},
{NULL, NULL, 0, NULL}
};
diff --git a/python/segyio/segy.py b/python/segyio/segy.py
index d74f61b..f56192f 100644
--- a/python/segyio/segy.py
+++ b/python/segyio/segy.py
@@ -33,7 +33,7 @@ except ImportError: # will be 3.x series
class SegyFile(object):
- def __init__(self, filename, mode, iline=189, xline=193, t0=1111.0):
+ def __init__(self, filename, mode, iline=189, xline=193):
"""
Constructor, internal.
"""
diff --git a/python/segyio/tools.py b/python/segyio/tools.py
new file mode 100644
index 0000000..093f462
--- /dev/null
+++ b/python/segyio/tools.py
@@ -0,0 +1,7 @@
+import segyio
+
+
+def get_dt(file):
+ dt = segyio._segyio.get_dt(file.xfd)
+
+ return dt['dt']
diff --git a/src/segyio/segy.c b/src/segyio/segy.c
index 6c76d47..bed09c8 100644
--- a/src/segyio/segy.c
+++ b/src/segyio/segy.c
@@ -639,7 +639,7 @@ int segy_traces( segy_file* fp,
return SEGY_OK;
}
-static int segy_sample_interval( segy_file* fp, double* dt) {
+int segy_sample_interval( segy_file* fp, float* dt) {
char bin_header[ SEGY_BINARY_HEADER_SIZE ];
char trace_header[SEGY_TRACE_HEADER_SIZE];
@@ -673,10 +673,8 @@ static int segy_sample_interval( segy_file* fp, double* dt) {
fprintf(stderr, "Trace sampling rate in SEGY header and trace header set to 0.0. Will default to 4 ms.\n");
*dt = 4.0;
} else if (binary_header_dt == 0.0) {
- fprintf(stderr, "Trace sampling rate in SEGY header set to 0.0. Will use trace sampling rate of: %f\n", trace_header_dt);
*dt = trace_header_dt;
} else if (trace_header_dt == 0.0) {
- fprintf(stderr, "Trace sampling rate in trace header set to 0.0. Will use SEGY header sampling rate of: %f\n", binary_header_dt);
*dt = binary_header_dt;
} else if (trace_header_dt != binary_header_dt) {
fprintf(stderr, "Trace sampling rate in SEGY header and trace header are not equal. Will use SEGY header sampling rate of: %f\n",
@@ -690,7 +688,7 @@ static int segy_sample_interval( segy_file* fp, double* dt) {
int segy_sample_indexes( segy_file* fp, double* buf, double t0, size_t count) {
- double dt;
+ float dt;
int err = segy_sample_interval(fp, &dt);
if (err != 0) {
return err;
diff --git a/src/segyio/segy.h b/src/segyio/segy.h
index 3beceb0..326579a 100644
--- a/src/segyio/segy.h
+++ b/src/segyio/segy.h
@@ -45,6 +45,7 @@ unsigned int segy_binheader_size();
int segy_binheader( segy_file*, char* buf );
int segy_write_binheader( segy_file*, const char* buf );
unsigned int segy_samples( const char* binheader );
+int segy_sample_interval( segy_file*, float* dt);
/* exception: the int returned is an enum, SEGY_SORTING, not an error code */
int segy_format( const char* binheader );
int segy_get_field( const char* traceheader, int field, int32_t* f );
diff --git a/tests/test_segy.py b/tests/test_segy.py
index 17beea4..26e3b04 100644
--- a/tests/test_segy.py
+++ b/tests/test_segy.py
@@ -165,6 +165,8 @@ class TestSegy(TestCase):
self.assertEqual(25, f.tracecount)
self.assertEqual(len(f.trace), f.tracecount)
self.assertEqual(50, f.samples)
+ dt = segyio.get_dt(f)
+ self.assertEqual(4, dt)
def test_traces_slicing(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