[updates] first usage of PylotCanvas for other fig
This commit is contained in:
parent
3cfd2371fc
commit
1bbb686778
10
QtPyLoT.py
10
QtPyLoT.py
@ -78,7 +78,7 @@ from pylot.core.util.utils import fnConstructor, getLogin, \
|
|||||||
from pylot.core.util.event import Event
|
from pylot.core.util.event import Event
|
||||||
from pylot.core.io.location import create_creation_info, create_event
|
from pylot.core.io.location import create_creation_info, create_event
|
||||||
from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \
|
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
|
getDataType, ComparisonWidget, TuneAutopicker, PylotParaBox, AutoPickDlg, CanvasWidget, AutoPickWidget
|
||||||
from pylot.core.util.map_projection import map_projection
|
from pylot.core.util.map_projection import map_projection
|
||||||
from pylot.core.util.structure import DATASTRUCTURE
|
from pylot.core.util.structure import DATASTRUCTURE
|
||||||
@ -619,8 +619,8 @@ class MainWindow(QMainWindow):
|
|||||||
self.disconnectWFplotEvents()
|
self.disconnectWFplotEvents()
|
||||||
if str(settings.value('pyqtgraphic')) == 'false' or not pg:
|
if str(settings.value('pyqtgraphic')) == 'false' or not pg:
|
||||||
self.pg = False
|
self.pg = False
|
||||||
self.dataPlot = WaveformWidget(parent=self, xlabel=xlab, ylabel=None,
|
self.dataPlot = PylotCanvas(parent=self, connect_events=False)
|
||||||
title=plottitle)
|
self.dataPlot.updateWidget(xlab, None, plottitle)
|
||||||
else:
|
else:
|
||||||
self.pg = True
|
self.pg = True
|
||||||
self.dataPlot = WaveformWidgetPG(parent=self, xlabel=xlab, ylabel=None,
|
self.dataPlot = WaveformWidgetPG(parent=self, xlabel=xlab, ylabel=None,
|
||||||
@ -1853,7 +1853,7 @@ class MainWindow(QMainWindow):
|
|||||||
def init_canvas_dict(self):
|
def init_canvas_dict(self):
|
||||||
self.canvas_dict = {}
|
self.canvas_dict = {}
|
||||||
for key in self.fig_keys:
|
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):
|
def init_fig_dict_wadatijack(self, eventIDs):
|
||||||
self.fig_dict_wadatijack = {}
|
self.fig_dict_wadatijack = {}
|
||||||
@ -1872,7 +1872,7 @@ class MainWindow(QMainWindow):
|
|||||||
for eventID in self.fig_dict_wadatijack.keys():
|
for eventID in self.fig_dict_wadatijack.keys():
|
||||||
self.canvas_dict_wadatijack[eventID] = {}
|
self.canvas_dict_wadatijack[eventID] = {}
|
||||||
for key in self.fig_keys_wadatijack:
|
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):
|
def tune_autopicker(self):
|
||||||
'''
|
'''
|
||||||
|
@ -264,8 +264,11 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
|
|||||||
print(wfdat)
|
print(wfdat)
|
||||||
##########################################################
|
##########################################################
|
||||||
# !automated picking starts here!
|
# !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,
|
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)
|
ncores=ncores, metadata=metadata, origin=data.get_evt_data().origins)
|
||||||
##########################################################
|
##########################################################
|
||||||
# locating
|
# locating
|
||||||
|
@ -593,34 +593,46 @@ class WaveformWidgetPG(QtGui.QWidget):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class WaveformWidget(FigureCanvas):
|
class PylotCanvas(FigureCanvas):
|
||||||
def __init__(self, parent=None, xlabel='x', ylabel='y', title='Title'):
|
def __init__(self, figure=None, parent=None, connect_events=True):
|
||||||
|
|
||||||
self._parent = parent
|
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))
|
self.figure.set_facecolor((.92, .92, .92))
|
||||||
# attribute plotdict is a dictionary connecting position and a name
|
# attribute plotdict is a dictionary connecting position and a name
|
||||||
self.plotdict = dict()
|
self.plotdict = dict()
|
||||||
# create axes
|
|
||||||
self.axes = self.figure.add_subplot(111)
|
|
||||||
# initialize super class
|
# initialize super class
|
||||||
super(WaveformWidget, self).__init__(self.figure)
|
super(PylotCanvas, self).__init__(self.figure)
|
||||||
# add an cursor for station selection
|
# add a cursor for station selection
|
||||||
self.multiCursor = MultiCursor(self.figure.canvas, (self.axes,),
|
self.multiCursor = MultiCursor(self.figure.canvas, (self.axes,),
|
||||||
horizOn=True, useblit=True,
|
horizOn=True, useblit=True,
|
||||||
color='m', lw=1)
|
color='m', lw=1)
|
||||||
# update labels of the entire widget
|
# update labels of the entire widget
|
||||||
self.updateWidget(xlabel, ylabel, title)
|
#self.updateWidget(xlabel, ylabel, title)
|
||||||
|
|
||||||
self.limits = {'x': None,
|
self.limits = {'x': (-np.inf, np.inf),
|
||||||
'y': None}
|
'y': (-np.inf, np.inf)}
|
||||||
|
|
||||||
|
if connect_events:
|
||||||
|
self.connectEvents()
|
||||||
|
|
||||||
self.cidscroll = self.connectScrollEvent(self.scrollZoom)
|
|
||||||
try:
|
try:
|
||||||
self.figure.tight_layout()
|
self.figure.tight_layout()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def connectEvents(self):
|
||||||
|
self.cidscroll = self.connectScrollEvent(self.scrollZoom)
|
||||||
|
|
||||||
|
def disconnectEvents(self):
|
||||||
|
self.mpl_disconnect(self.cidscroll)
|
||||||
|
|
||||||
|
self.cidscroll = None
|
||||||
|
|
||||||
def getPlotDict(self):
|
def getPlotDict(self):
|
||||||
return self.plotdict
|
return self.plotdict
|
||||||
|
|
||||||
@ -789,6 +801,16 @@ class WaveformWidget(FigureCanvas):
|
|||||||
self.setYLims(new_ylim)
|
self.setYLims(new_ylim)
|
||||||
self.draw()
|
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):
|
def updateCurrentLimits(self):
|
||||||
self.setXLims(self.getXLims())
|
self.setXLims(self.getXLims())
|
||||||
self.setYLims(self.getYLims())
|
self.setYLims(self.getYLims())
|
||||||
@ -933,7 +955,7 @@ class PickDlg(QDialog):
|
|||||||
self.stime, self.etime = full_range(self.getWFData())
|
self.stime, self.etime = full_range(self.getWFData())
|
||||||
|
|
||||||
# initialize plotting widget
|
# initialize plotting widget
|
||||||
self.multicompfig = WaveformWidget(self)
|
self.multicompfig = PylotCanvas(parent=self, connect_events=False)
|
||||||
self.phaseplot = PhasePlotWidget(self)
|
self.phaseplot = PhasePlotWidget(self)
|
||||||
self.phaseplot.hide()
|
self.phaseplot.hide()
|
||||||
|
|
||||||
@ -944,14 +966,7 @@ class PickDlg(QDialog):
|
|||||||
self.getPlotWidget().plotWFData(wfdata=self.getWFData(),
|
self.getPlotWidget().plotWFData(wfdata=self.getWFData(),
|
||||||
title=self.getStation())
|
title=self.getStation())
|
||||||
|
|
||||||
xlims = self.getPlotWidget().getXLims()
|
self.getPlotWidget().setZoomBorders2content()
|
||||||
ylims = self.getPlotWidget().getYLims()
|
|
||||||
|
|
||||||
self.limits = {'x': xlims,
|
|
||||||
'y': ylims}
|
|
||||||
|
|
||||||
for ax, limit in self.limits.items():
|
|
||||||
self.getPlotWidget().setGlobalLimits(ax, limit)
|
|
||||||
|
|
||||||
self.updateCurrentLimits()
|
self.updateCurrentLimits()
|
||||||
|
|
||||||
@ -962,10 +977,7 @@ class PickDlg(QDialog):
|
|||||||
self.drawAllPicks()
|
self.drawAllPicks()
|
||||||
|
|
||||||
# connect button press event to an action
|
# connect button press event to an action
|
||||||
self.cidpress = self.connectPressEvent(self.panPress)
|
self.connectEvents()
|
||||||
self.cidmotion = self.connectMotionEvent(self.panMotion)
|
|
||||||
self.cidrelease = self.connectReleaseEvent(self.panRelease)
|
|
||||||
self.cidscroll = self.connectScrollEvent(self.multicompfig.scrollZoom)
|
|
||||||
self.cidscroll_arr = self.connectScrollEvent(self.refreshArrivalsText)
|
self.cidscroll_arr = self.connectScrollEvent(self.refreshArrivalsText)
|
||||||
self.cidscroll_ph = self.connectScrollEvent(self.refreshPhaseText)
|
self.cidscroll_ph = self.connectScrollEvent(self.refreshPhaseText)
|
||||||
|
|
||||||
@ -1399,10 +1411,7 @@ class PickDlg(QDialog):
|
|||||||
|
|
||||||
def deactivatePicking(self):
|
def deactivatePicking(self):
|
||||||
self.disconnectPressEvent()
|
self.disconnectPressEvent()
|
||||||
self.cidpress = self.connectPressEvent(self.panPress)
|
self.connectEvents()
|
||||||
self.cidmotion = self.connectMotionEvent(self.panMotion)
|
|
||||||
self.cidrelease = self.connectReleaseEvent(self.panRelease)
|
|
||||||
self.cidscroll = self.connectScrollEvent(self.scrollZoom)
|
|
||||||
self.connect_pick_delete()
|
self.connect_pick_delete()
|
||||||
|
|
||||||
def getParameter(self):
|
def getParameter(self):
|
||||||
@ -1461,7 +1470,7 @@ class PickDlg(QDialog):
|
|||||||
self.cur_ylim = limits
|
self.cur_ylim = limits
|
||||||
|
|
||||||
def getGlobalLimits(self, axis):
|
def getGlobalLimits(self, axis):
|
||||||
return self.limits[axis]
|
return self.getPlotWidget().getGlobalLimits(axis)
|
||||||
|
|
||||||
def updateCurrentLimits(self):
|
def updateCurrentLimits(self):
|
||||||
self.setXLims(self.getPlotWidget().getXLims())
|
self.setXLims(self.getPlotWidget().getXLims())
|
||||||
@ -1759,7 +1768,7 @@ class PickDlg(QDialog):
|
|||||||
# plotting picks
|
# plotting picks
|
||||||
ax = self.getPlotWidget().axes
|
ax = self.getPlotWidget().axes
|
||||||
if not textOnly:
|
if not textOnly:
|
||||||
ylims = self.getGlobalLimits('y')
|
ylims = self.getPlotWidget().getGlobalLimits('y')
|
||||||
else:
|
else:
|
||||||
ylims = self.getPlotWidget().getYLims()
|
ylims = self.getPlotWidget().getYLims()
|
||||||
if self.getPicks(picktype):
|
if self.getPicks(picktype):
|
||||||
@ -1971,6 +1980,12 @@ class PickDlg(QDialog):
|
|||||||
self.getPlotWidget().setXLims(self.getXLims())
|
self.getPlotWidget().setXLims(self.getXLims())
|
||||||
self.getPlotWidget().setYLims(self.getYLims())
|
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):
|
def zoom(self):
|
||||||
if self.zoomAction.isChecked() and self.pick_block:
|
if self.zoomAction.isChecked() and self.pick_block:
|
||||||
self.zoomAction.setChecked(False)
|
self.zoomAction.setChecked(False)
|
||||||
@ -1982,47 +1997,6 @@ class PickDlg(QDialog):
|
|||||||
self.figToolBar.zoom()
|
self.figToolBar.zoom()
|
||||||
else:
|
else:
|
||||||
self.figToolBar.zoom()
|
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):
|
def resetZoom(self):
|
||||||
self.getPlotWidget().setXLims(self.getGlobalLimits('x'))
|
self.getPlotWidget().setXLims(self.getGlobalLimits('x'))
|
||||||
@ -2080,9 +2054,11 @@ class CanvasWidget(QWidget):
|
|||||||
|
|
||||||
def __init__(self, parent, canvas):
|
def __init__(self, parent, canvas):
|
||||||
QtGui.QWidget.__init__(self, parent)#, 1)
|
QtGui.QWidget.__init__(self, parent)#, 1)
|
||||||
|
canvas = canvas
|
||||||
self.main_layout = QtGui.QVBoxLayout()
|
self.main_layout = QtGui.QVBoxLayout()
|
||||||
self.setLayout(self.main_layout)
|
self.setLayout(self.main_layout)
|
||||||
self.main_layout.addWidget(canvas)
|
self.main_layout.addWidget(canvas)
|
||||||
|
canvas.setZoomBorders2content()
|
||||||
|
|
||||||
|
|
||||||
class AutoPickWidget(QWidget):
|
class AutoPickWidget(QWidget):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user