[updates] first usage of PylotCanvas for other fig

This commit is contained in:
Marcel Paffrath 2017-08-23 14:45:46 +02:00
parent 3cfd2371fc
commit 1bbb686778
3 changed files with 56 additions and 77 deletions

View File

@ -78,7 +78,7 @@ from pylot.core.util.utils import fnConstructor, getLogin, \
from pylot.core.util.event import Event
from pylot.core.io.location import create_creation_info, create_event
from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \
WaveformWidget, WaveformWidgetPG, PropertiesDlg, HelpForm, createAction, PickDlg, \
PylotCanvas, WaveformWidgetPG, PropertiesDlg, HelpForm, createAction, PickDlg, \
getDataType, ComparisonWidget, TuneAutopicker, PylotParaBox, AutoPickDlg, CanvasWidget, AutoPickWidget
from pylot.core.util.map_projection import map_projection
from pylot.core.util.structure import DATASTRUCTURE
@ -619,8 +619,8 @@ class MainWindow(QMainWindow):
self.disconnectWFplotEvents()
if str(settings.value('pyqtgraphic')) == 'false' or not pg:
self.pg = False
self.dataPlot = WaveformWidget(parent=self, xlabel=xlab, ylabel=None,
title=plottitle)
self.dataPlot = PylotCanvas(parent=self, connect_events=False)
self.dataPlot.updateWidget(xlab, None, plottitle)
else:
self.pg = True
self.dataPlot = WaveformWidgetPG(parent=self, xlabel=xlab, ylabel=None,
@ -1853,7 +1853,7 @@ class MainWindow(QMainWindow):
def init_canvas_dict(self):
self.canvas_dict = {}
for key in self.fig_keys:
self.canvas_dict[key] = FigureCanvas(self.fig_dict[key])
self.canvas_dict[key] = PylotCanvas(self.fig_dict[key])
def init_fig_dict_wadatijack(self, eventIDs):
self.fig_dict_wadatijack = {}
@ -1872,7 +1872,7 @@ class MainWindow(QMainWindow):
for eventID in self.fig_dict_wadatijack.keys():
self.canvas_dict_wadatijack[eventID] = {}
for key in self.fig_keys_wadatijack:
self.canvas_dict_wadatijack[eventID][key] = FigureCanvas(self.fig_dict_wadatijack[eventID][key])
self.canvas_dict_wadatijack[eventID][key] = PylotCanvas(self.fig_dict_wadatijack[eventID][key])
def tune_autopicker(self):
'''

View File

@ -264,8 +264,11 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
print(wfdat)
##########################################################
# !automated picking starts here!
fdwj = None
if fig_dict_wadatijack:
fdwj = fig_dict_wadatijack[evID]
picks = autopickevent(wfdat, parameter, iplot=iplot, fig_dict=fig_dict,
fig_dict_wadatijack=fig_dict_wadatijack[evID],
fig_dict_wadatijack=fdwj,
ncores=ncores, metadata=metadata, origin=data.get_evt_data().origins)
##########################################################
# locating

View File

@ -593,34 +593,46 @@ class WaveformWidgetPG(QtGui.QWidget):
pass
class WaveformWidget(FigureCanvas):
def __init__(self, parent=None, xlabel='x', ylabel='y', title='Title'):
class PylotCanvas(FigureCanvas):
def __init__(self, figure=None, parent=None, connect_events=True):
self._parent = parent
self.figure = Figure()
if not figure:
figure = Figure()
# create axes
self.axes = figure.add_subplot(111)
self.figure = figure
self.figure.set_facecolor((.92, .92, .92))
# attribute plotdict is a dictionary connecting position and a name
self.plotdict = dict()
# create axes
self.axes = self.figure.add_subplot(111)
# initialize super class
super(WaveformWidget, self).__init__(self.figure)
# add an cursor for station selection
super(PylotCanvas, self).__init__(self.figure)
# add a cursor for station selection
self.multiCursor = MultiCursor(self.figure.canvas, (self.axes,),
horizOn=True, useblit=True,
color='m', lw=1)
# update labels of the entire widget
self.updateWidget(xlabel, ylabel, title)
#self.updateWidget(xlabel, ylabel, title)
self.limits = {'x': None,
'y': None}
self.limits = {'x': (-np.inf, np.inf),
'y': (-np.inf, np.inf)}
if connect_events:
self.connectEvents()
self.cidscroll = self.connectScrollEvent(self.scrollZoom)
try:
self.figure.tight_layout()
except:
pass
def connectEvents(self):
self.cidscroll = self.connectScrollEvent(self.scrollZoom)
def disconnectEvents(self):
self.mpl_disconnect(self.cidscroll)
self.cidscroll = None
def getPlotDict(self):
return self.plotdict
@ -789,6 +801,16 @@ class WaveformWidget(FigureCanvas):
self.setYLims(new_ylim)
self.draw()
def setZoomBorders2content(self):
xlims = self.getXLims()
ylims = self.getYLims()
self.limits = {'x': xlims,
'y': ylims}
for ax, limit in self.limits.items():
self.setGlobalLimits(ax, limit)
def updateCurrentLimits(self):
self.setXLims(self.getXLims())
self.setYLims(self.getYLims())
@ -933,7 +955,7 @@ class PickDlg(QDialog):
self.stime, self.etime = full_range(self.getWFData())
# initialize plotting widget
self.multicompfig = WaveformWidget(self)
self.multicompfig = PylotCanvas(parent=self, connect_events=False)
self.phaseplot = PhasePlotWidget(self)
self.phaseplot.hide()
@ -944,14 +966,7 @@ class PickDlg(QDialog):
self.getPlotWidget().plotWFData(wfdata=self.getWFData(),
title=self.getStation())
xlims = self.getPlotWidget().getXLims()
ylims = self.getPlotWidget().getYLims()
self.limits = {'x': xlims,
'y': ylims}
for ax, limit in self.limits.items():
self.getPlotWidget().setGlobalLimits(ax, limit)
self.getPlotWidget().setZoomBorders2content()
self.updateCurrentLimits()
@ -962,10 +977,7 @@ class PickDlg(QDialog):
self.drawAllPicks()
# connect button press event to an action
self.cidpress = self.connectPressEvent(self.panPress)
self.cidmotion = self.connectMotionEvent(self.panMotion)
self.cidrelease = self.connectReleaseEvent(self.panRelease)
self.cidscroll = self.connectScrollEvent(self.multicompfig.scrollZoom)
self.connectEvents()
self.cidscroll_arr = self.connectScrollEvent(self.refreshArrivalsText)
self.cidscroll_ph = self.connectScrollEvent(self.refreshPhaseText)
@ -1399,10 +1411,7 @@ class PickDlg(QDialog):
def deactivatePicking(self):
self.disconnectPressEvent()
self.cidpress = self.connectPressEvent(self.panPress)
self.cidmotion = self.connectMotionEvent(self.panMotion)
self.cidrelease = self.connectReleaseEvent(self.panRelease)
self.cidscroll = self.connectScrollEvent(self.scrollZoom)
self.connectEvents()
self.connect_pick_delete()
def getParameter(self):
@ -1461,7 +1470,7 @@ class PickDlg(QDialog):
self.cur_ylim = limits
def getGlobalLimits(self, axis):
return self.limits[axis]
return self.getPlotWidget().getGlobalLimits(axis)
def updateCurrentLimits(self):
self.setXLims(self.getPlotWidget().getXLims())
@ -1759,7 +1768,7 @@ class PickDlg(QDialog):
# plotting picks
ax = self.getPlotWidget().axes
if not textOnly:
ylims = self.getGlobalLimits('y')
ylims = self.getPlotWidget().getGlobalLimits('y')
else:
ylims = self.getPlotWidget().getYLims()
if self.getPicks(picktype):
@ -1971,6 +1980,12 @@ class PickDlg(QDialog):
self.getPlotWidget().setXLims(self.getXLims())
self.getPlotWidget().setYLims(self.getYLims())
def connectEvents(self):
self.cidpress = self.connectPressEvent(self.panPress)
self.cidmotion = self.connectMotionEvent(self.panMotion)
self.cidrelease = self.connectReleaseEvent(self.panRelease)
self.cidscroll = self.connectScrollEvent(self.multicompfig.scrollZoom)
def zoom(self):
if self.zoomAction.isChecked() and self.pick_block:
self.zoomAction.setChecked(False)
@ -1982,47 +1997,6 @@ class PickDlg(QDialog):
self.figToolBar.zoom()
else:
self.figToolBar.zoom()
self.cidpress = self.connectPressEvent(self.panPress)
self.cidmotion = self.connectMotionEvent(self.panMotion)
self.cidrelease = self.connectReleaseEvent(self.panRelease)
self.cidscroll = self.connectScrollEvent(self.scrollZoom)
def scrollZoom(self, gui_event, factor=2.):
if not gui_event.xdata or not gui_event.ydata:
return
self.updateCurrentLimits()
if gui_event.button == 'up':
scale_factor = 1 / factor
elif gui_event.button == 'down':
# deal with zoom out
scale_factor = factor
else:
# deal with something that should never happen
scale_factor = 1
print(gui_event.button)
new_xlim = gui_event.xdata - \
scale_factor * (gui_event.xdata - self.getXLims())
new_ylim = gui_event.ydata - \
scale_factor * (gui_event.ydata - self.getYLims())
new_xlim.sort()
global_x = self.getGlobalLimits('x')
global_y = self.getGlobalLimits('y')
new_xlim[0] = max(new_xlim[0], global_x[0])
new_xlim[1] = min(new_xlim[1], global_x[1])
new_ylim.sort()
new_ylim[0] = max(new_ylim[0], global_y[0])
new_ylim[1] = min(new_ylim[1], global_y[1])
self.getPlotWidget().setXLims(new_xlim)
self.getPlotWidget().setYLims(new_ylim)
self.refreshArrivalsText()
self.refreshPhaseText()
self.draw()
def resetZoom(self):
self.getPlotWidget().setXLims(self.getGlobalLimits('x'))
@ -2080,9 +2054,11 @@ class CanvasWidget(QWidget):
def __init__(self, parent, canvas):
QtGui.QWidget.__init__(self, parent)#, 1)
canvas = canvas
self.main_layout = QtGui.QVBoxLayout()
self.setLayout(self.main_layout)
self.main_layout.addWidget(canvas)
canvas.setZoomBorders2content()
class AutoPickWidget(QWidget):