[segyio] 133/376: __repr__

Jørgen Kvalsvik jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:20 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 dcbc9a5c859a8d219e680094b786d9a45158e614
Author: Jørgen Kvalsvik <jokva at statoil.com>
Date:   Mon Nov 21 15:59:15 2016 +0100

    __repr__
    
    Basic __repr__ support.
---
 python/segyio/__init__.py   | 3 +++
 python/segyio/_field.py     | 9 ++++++++-
 python/segyio/_header.py    | 3 +++
 python/segyio/_line.py      | 3 +++
 python/segyio/_raw_trace.py | 2 ++
 python/segyio/_trace.py     | 3 +++
 python/segyio/segy.py       | 7 +++++++
 7 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/python/segyio/__init__.py b/python/segyio/__init__.py
index 23545d1..1a4edd4 100644
--- a/python/segyio/__init__.py
+++ b/python/segyio/__init__.py
@@ -52,6 +52,9 @@ class Enum(object):
                 return k
         return "Unknown Enum"
 
+    def __repr__(self):
+        return str(self)
+
     def __hash__(self):
         return hash(self._value)
 
diff --git a/python/segyio/_field.py b/python/segyio/_field.py
index 145d5fb..b6a0f01 100644
--- a/python/segyio/_field.py
+++ b/python/segyio/_field.py
@@ -78,4 +78,11 @@ class Field:
         def wr(buf, traceno):
             segyio._segyio.write_traceheader(segy.xfd, traceno, buf, segy._tr0, segy._bsz)
 
-        return Field(buf, traceno=traceno, write=wr, field_type=TraceField)
\ No newline at end of file
+        return Field(buf, traceno=traceno, write=wr, field_type=TraceField)
+
+    def __repr__(self):
+        def assigned(x):
+            return x != BinField.Unassigned1 and x != BinField.Unassigned2
+
+        fields = filter(assigned, self._field_type.enums())
+        return self[fields].__repr__()
diff --git a/python/segyio/_header.py b/python/segyio/_header.py
index e800d3f..7b7d467 100644
--- a/python/segyio/_header.py
+++ b/python/segyio/_header.py
@@ -44,6 +44,9 @@ class Header(object):
     def __iter__(self):
         return self[:]
 
+    def __repr__(self):
+        return "Header(traces = {})".format(self.segy.samples)
+
     def readfn(self, t0, length, stride, buf):
         def gen():
             start = t0
diff --git a/python/segyio/_line.py b/python/segyio/_line.py
index 938239d..71adf96 100644
--- a/python/segyio/_line.py
+++ b/python/segyio/_line.py
@@ -29,6 +29,9 @@ class Line:
         self.readfn = readfn
         self.writefn = writefn
 
+    def __repr__(self):
+        return "Line(direction = {}, length = {})".format(self.name, self.len)
+
     def _index(self, lineno, offset):
         """ :rtype: int"""
         offs = self.segy.offsets
diff --git a/python/segyio/_raw_trace.py b/python/segyio/_raw_trace.py
index b93503c..d745300 100644
--- a/python/segyio/_raw_trace.py
+++ b/python/segyio/_raw_trace.py
@@ -17,3 +17,5 @@ class RawTrace(object):
 
         return self.trace._readtr(index, buf)
 
+    def __repr__(self):
+        return self.trace.__repr__() + ".raw"
diff --git a/python/segyio/_trace.py b/python/segyio/_trace.py
index 3ad1459..ae71d6d 100644
--- a/python/segyio/_trace.py
+++ b/python/segyio/_trace.py
@@ -62,6 +62,9 @@ class Trace:
     def __iter__(self):
         return self[:]
 
+    def __repr__(self):
+        return "Trace(traces = {}, samples = {})".format(len(self), self._file.samples)
+
     def _trace_buffer(self, buf=None):
         samples = self._file.samples
 
diff --git a/python/segyio/segy.py b/python/segyio/segy.py
index 90218bc..b630cb5 100644
--- a/python/segyio/segy.py
+++ b/python/segyio/segy.py
@@ -60,6 +60,10 @@ class SegyFile(object):
 
         super(SegyFile, self).__init__()
 
+    def __repr__(self):
+        return "SegyFile('{}', '{}', iline = {}, xline = {})".format(
+                        self._filename, self._mode, self._il, self._xl)
+
     def __enter__(self):
         """Internal.
         :rtype: segyio.segy.SegyFile
@@ -788,6 +792,9 @@ class SegyFile(object):
 
                 _segyio.write_textheader(self.xfd, index, val)
 
+            def __repr__(inner):
+                return "Text(external_headers = {})".format(self.ext_headers)
+
         return TextHeader()
 
     @property

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