[segyio] 95/376: Adding new standalone ColorBarWidget using a new ColorBarPlot

Jørgen Kvalsvik jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:14 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 34692c61162f86c91d109c2c9bfde99c143a68ef
Author: Thorvald Johannessen <thorvjo at statoil.com>
Date:   Thu Nov 3 12:41:18 2016 +0100

    Adding new standalone ColorBarWidget using a new ColorBarPlot
---
 python/segyview/segyiowrapper.py | 10 +++++---
 python/segyview/segyplot.py      | 45 ++++++++++++++++++++++++++++++------
 python/segyview/slicewidget.py   | 50 ++++++++++++++++++++++++++++++++++------
 python/segyview/viewer.py        | 29 +++++++++++++++--------
 4 files changed, 107 insertions(+), 27 deletions(-)

diff --git a/python/segyview/segyiowrapper.py b/python/segyview/segyiowrapper.py
index aad5d9d..d564ec5 100644
--- a/python/segyview/segyiowrapper.py
+++ b/python/segyview/segyiowrapper.py
@@ -41,7 +41,7 @@ class SegyIOWrapper(object):
         self.segy = segy
         self.file_name = file_name
         self.file_activity_monitor = file_activity_monitor
-        self.iline_slices, self.xline_slices, self.depth_slices, self.min_max = None, None, None, None
+        self.iline_slices, self.xline_slices, self.depth_slices, self._min_max = None, None, None, None
 
     @classmethod
     def wrap(cls, segy, file_activity_monitor=None):
@@ -73,7 +73,7 @@ class SegyIOWrapper(object):
         self.iline_slices = SlicesWrapper(self, self.segy.ilines.tolist(), self.segy.iline, read_from_file=True)
         self.xline_slices = SlicesWrapper(self, self.segy.xlines.tolist(), self.segy.xline, read_from_file=True)
         self.depth_slices = SlicesWrapper(self, range(self.segy.samples), self.segy.depth_slice, read_from_file=True)
-        self.min_max = None
+        self._min_max = None
 
     def close(self):
         """
@@ -132,7 +132,7 @@ class SegyIOWrapper(object):
 
         self.iline_slices = SlicesWrapper(self, self.segy.ilines.tolist(), ils, read_from_file=False)
         self.xline_slices = SlicesWrapper(self, self.segy.xlines.tolist(), xls, read_from_file=False)
-        self.min_max = self.identify_min_max(all_traces)
+        self._min_max = self.identify_min_max(all_traces)
         return True
 
     @staticmethod
@@ -170,3 +170,7 @@ class SegyIOWrapper(object):
     @property
     def depth_slice(self):
         return self.depth_slices
+
+    @property
+    def min_max(self):
+        return self._min_max
diff --git a/python/segyview/segyplot.py b/python/segyview/segyplot.py
index 1e46df5..669fc93 100644
--- a/python/segyview/segyplot.py
+++ b/python/segyview/segyplot.py
@@ -1,6 +1,7 @@
 from matplotlib.ticker import FuncFormatter, MaxNLocator
 import matplotlib.patches as patches
 
+import matplotlib
 
 class SegyPlot(object):
 
@@ -25,7 +26,7 @@ class SegyPlot(object):
         self.y_axis_name, self.y_axis_indexes = y_axis_indexes or (None, None)
 
         self.slice_axes = axes
-        self.slice_axes.tick_params(axis='both', labelsize=30)
+        self.slice_axes.tick_params(axis='both', labelsize=8)
 
         if self.x_axis_indexes is not None:
             def x_axis_label_formatter(val, position):
@@ -33,7 +34,7 @@ class SegyPlot(object):
                     return self.x_axis_indexes[int(val)]
                 return ''
 
-            self.slice_axes.set_xlabel(self.x_axis_name, fontsize=40)
+            self.slice_axes.set_xlabel(self.x_axis_name, fontsize=8)
             self.slice_axes.get_xaxis().set_major_formatter(FuncFormatter(x_axis_label_formatter))
             self.slice_axes.get_xaxis().set_major_locator(MaxNLocator(20))  # max 20 ticks are shown
 
@@ -43,7 +44,7 @@ class SegyPlot(object):
                     return self.y_axis_indexes[int(val)]
                 return ''
 
-            self.slice_axes.set_ylabel(self.y_axis_name, fontsize=40)
+            self.slice_axes.set_ylabel(self.y_axis_name, fontsize=8)
             self.slice_axes.get_yaxis().set_major_formatter(FuncFormatter(y_axis_label_formatter))
             self.slice_axes.get_yaxis().set_major_locator(MaxNLocator(10))  # max 20 ticks are shown
 
@@ -64,8 +65,9 @@ class SegyPlot(object):
                     fill=False,
                     alpha=1,
                     color='black',
-                    linestyle='--',
-                    linewidth=2
+                    linestyle='dashed',
+                    linewidth=0.5,
+
                 )
             )
 
@@ -78,8 +80,8 @@ class SegyPlot(object):
                     fill=False,
                     alpha=1,
                     color='black',
-                    linestyle='--',
-                    linewidth=2
+                    linestyle='dashed',
+                    linewidth=0.5
                 )
             )
 
@@ -94,6 +96,12 @@ class SegyPlot(object):
             )
         )
 
+    def set_min_max(self, v_min_max):
+        self.vmin, self.vmax = v_min_max or (None, None)
+        self.im.set_clim(self.vmin,self.vmax)
+
+
+
     def set_colormap(self, cmap):
         self.cmap = cmap
         self.im.set_cmap(cmap)
@@ -116,3 +124,26 @@ class SegyPlot(object):
     def disable_overlay(self):
         self.disabled_overlay.set_visible(False)
 
+class ColorBarPlot(object):
+    def __init__(self, axes, cmap=None, v_min_max=None):
+        print(v_min_max)
+        self.axes = axes
+        self.cmap = cmap
+
+        min, max = v_min_max
+        norm = matplotlib.colors.Normalize(vmin=min, vmax=max)
+
+        self.colorbar = matplotlib.colorbar.ColorbarBase(self.axes, cmap=cmap, norm=norm)
+
+    def set_cmap(self, cmap):
+        self.colorbar.set_cmap(str(cmap))
+        self.colorbar.draw_all()
+
+    def set_min_max(self, min_max):
+        min, max = min_max
+        self.colorbar.set_clim(min, max)
+        self.colorbar.draw_all()
+
+    def mouse_clicked(self, evt):
+        if evt.inaxes is not None:
+            print(evt)
diff --git a/python/segyview/slicewidget.py b/python/segyview/slicewidget.py
index f669f66..69e0bde 100644
--- a/python/segyview/slicewidget.py
+++ b/python/segyview/slicewidget.py
@@ -1,6 +1,6 @@
 from PyQt4 import QtGui, QtCore
 
-from segyplot import SegyPlot
+from segyplot import SegyPlot, ColorBarPlot
 from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
 from matplotlib.figure import Figure
 
@@ -32,9 +32,7 @@ class SliceWidget(QtGui.QWidget):
         self.current_index = 0
 
         # setting up the figure and canvas
-        self.figure = Figure(figsize=(800, 200), dpi=20, facecolor='white')
-
-
+        self.figure = Figure(figsize=(16, 4), dpi=100, facecolor='white')
 
         self.axes = self.figure.add_subplot(111)
 
@@ -71,8 +69,12 @@ class SliceWidget(QtGui.QWidget):
         self.segy_plot.update_image(index)
         self.figure_canvas.draw()
 
-    def set_cmap(self, action):
-        self.segy_plot.set_colormap(str(action))
+    def set_cmap(self, cmap):
+        self.segy_plot.set_colormap(str(cmap))
+        self.figure_canvas.draw()
+
+    def set_min_max(self, min_max):
+        self.segy_plot.set_min_max(min_max)
         self.figure_canvas.draw()
 
     def set_vertical_line_indicator(self, line):
@@ -90,7 +92,6 @@ class SliceWidget(QtGui.QWidget):
         self.overlay.show()
 
 
-
 class Overlay(QtGui.QWidget):
     def __init__(self, parent):
         super(Overlay, self).__init__(parent)
@@ -103,3 +104,38 @@ class Overlay(QtGui.QWidget):
         painter.fillRect(self.rect(), color)
 
 
+class ColorBarWidget(QtGui.QWidget):
+    """
+    Widget displaying a colorbar, with the selected min-max range and colormap
+    """
+    def __init__(self, segyio_wrapper, colormap_monitor=None):
+        super(ColorBarWidget, self).__init__()
+
+        self.swrap = segyio_wrapper
+
+        # setting up the colorbar figure
+        self.colormap_monitor = colormap_monitor
+        self.figure = Figure(figsize=(1, 3), dpi=50, facecolor='white')
+        self.axes = self.figure.add_subplot(111)
+        self.cbar_plt = ColorBarPlot(self.axes, cmap='seismic', v_min_max=self.swrap.min_max)
+        self.figure_canvas = FigureCanvas(self.figure)
+        self.figure_canvas.setParent(self)
+
+        # signals
+        self.colormap_monitor.cmap_changed.connect(self.set_cmap)
+        self.figure_canvas.mpl_connect('button_press_event', self.cbar_plt.mouse_clicked)
+
+        self.colormap_monitor.min_max_changed.connect(self.set_min_max)
+
+        self.layout = QtGui.QVBoxLayout(self)
+        self.layout.addWidget(self.figure_canvas)
+
+
+    def set_cmap(self,value):
+        self.cbar_plt.set_cmap(str(value))
+        self.figure_canvas.draw()
+
+    def set_min_max(self, min_max):
+        self.cbar_plt.set_min_max(min_max)
+        self.figure_canvas.draw()
+
diff --git a/python/segyview/viewer.py b/python/segyview/viewer.py
index 32fad8f..ea7b213 100644
--- a/python/segyview/viewer.py
+++ b/python/segyview/viewer.py
@@ -20,8 +20,9 @@ class LineSelectionMonitor(QtCore.QObject):
         self.depth_changed.emit(new_index)
 
 
-class ColorMapMonitor(QtCore.QObject):
+class SliceViewMonitor(QtCore.QObject):
     cmap_changed = QtCore.pyqtSignal(str)
+    min_max_changed = QtCore.pyqtSignal(object)
 
     def __init__(self, parent=None):
         QtCore.QObject.__init__(self, parent)
@@ -29,6 +30,9 @@ class ColorMapMonitor(QtCore.QObject):
     def colormap_updated(self, value):
         self.cmap_changed.emit(str(value))
 
+    def min_max_updated(self, values):
+        self.min_max_changed.emit(tuple(map(float, values)))
+
 
 class FileActivityMonitor(QtCore.QObject):
     started = QtCore.pyqtSignal()
@@ -36,7 +40,7 @@ class FileActivityMonitor(QtCore.QObject):
     cancelled_operation = False
 
     def __init__(self, parent=None):
-        QtCore.QObject.__init__(self)
+        QtCore.QObject.__init__(self, parent)
         self.cancelled_operation = False
 
     def reset(self):
@@ -88,11 +92,11 @@ class View(object):
 
         self._main_widget = QtGui.QWidget()
         self._line_selection_monitor = LineSelectionMonitor(self._main_widget)
-        self._colormap_monitor = ColorMapMonitor(self._main_widget)
+        self._sliceview_monitor = SliceViewMonitor(self._main_widget)
 
         x_slice_widget, i_slice_widget, depth_slice_widget = initialize_slice_widgets(self._swrap,
                                                                                       self._line_selection_monitor,
-                                                                                      self._colormap_monitor)
+                                                                                      self._sliceview_monitor)
         # layout for the single parent widget
         top_row = QtGui.QHBoxLayout()
         top_row.addWidget(x_slice_widget, 0)
@@ -118,19 +122,19 @@ class View(object):
 
     @property
     def colormap_monitor(self):
-        return self._colormap_monitor
+        return self._sliceview_monitor
 
     @property
     def file_activity_monitor(self):
         return self._file_activity_monitor
 
 
-def initialize_slice_widgets(segyio_wrapper, line_selection_monitor, colormap_monitor):
+def initialize_slice_widgets(segyio_wrapper, line_selection_monitor, sliceview_monitor):
     """
     Given a segio_wrapper, and signal monitors, sliceviewer widgets for all three slices in a segy-cube are created.
     :param segyio_wrapper:
     :param line_selection_monitor:
-    :param colormap_monitor:
+    :param sliceview_monitor:
     :return: three QWidgets for the three segy slices, in x, i and depth slice order.
     """
 
@@ -169,9 +173,14 @@ def initialize_slice_widgets(segyio_wrapper, line_selection_monitor, colormap_mo
     line_selection_monitor.depth_changed.connect(depth_slice_widget.update_image)
 
     # colormap signals
-    colormap_monitor.cmap_changed.connect(x_slice_widget.set_cmap)
-    colormap_monitor.cmap_changed.connect(i_slice_widget.set_cmap)
-    colormap_monitor.cmap_changed.connect(depth_slice_widget.set_cmap)
+    sliceview_monitor.cmap_changed.connect(x_slice_widget.set_cmap)
+    sliceview_monitor.cmap_changed.connect(i_slice_widget.set_cmap)
+    sliceview_monitor.cmap_changed.connect(depth_slice_widget.set_cmap)
+
+    # setting min max thresholds
+    sliceview_monitor.min_max_changed.connect(x_slice_widget.set_min_max)
+    sliceview_monitor.min_max_changed.connect(i_slice_widget.set_min_max)
+    sliceview_monitor.min_max_changed.connect(depth_slice_widget.set_min_max)
 
     return x_slice_widget, i_slice_widget, depth_slice_widget
 

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