[update] canvas finally working again
This commit is contained in:
parent
c83671f140
commit
726544bf3b
@ -614,10 +614,18 @@ class PylotCanvas(FigureCanvas):
|
|||||||
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
|
|
||||||
#self.updateWidget(xlabel, ylabel, title)
|
|
||||||
|
|
||||||
self.limits = {'x': (-np.inf, np.inf),
|
# initialize panning attributes
|
||||||
|
self.press = None
|
||||||
|
self.xpress = None
|
||||||
|
self.ypress = None
|
||||||
|
self.cur_xlim = None
|
||||||
|
self.cur_ylim = None
|
||||||
|
|
||||||
|
self.limits = {}
|
||||||
|
|
||||||
|
for ax in self.axes:
|
||||||
|
self.limits[ax] = {'x': (-np.inf, np.inf),
|
||||||
'y': (-np.inf, np.inf)}
|
'y': (-np.inf, np.inf)}
|
||||||
|
|
||||||
if connect_events:
|
if connect_events:
|
||||||
@ -628,23 +636,124 @@ class PylotCanvas(FigureCanvas):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def panPress(self, gui_event):
|
||||||
|
ax_check = False
|
||||||
|
for ax in self.axes:
|
||||||
|
if gui_event.inaxes == ax:
|
||||||
|
ax_check = True
|
||||||
|
break
|
||||||
|
if not ax_check: return
|
||||||
|
self.cur_xlim = ax.get_xlim()
|
||||||
|
self.cur_ylim = ax.get_ylim()
|
||||||
|
self.press = gui_event.xdata, gui_event.ydata
|
||||||
|
self.xpress, self.ypress = self.press
|
||||||
|
|
||||||
|
def panMotion(self, gui_event):
|
||||||
|
if self.press is None: return
|
||||||
|
ax_check = False
|
||||||
|
for ax in self.axes:
|
||||||
|
if gui_event.inaxes == ax:
|
||||||
|
ax_check = True
|
||||||
|
break
|
||||||
|
if not ax_check: return
|
||||||
|
dx = gui_event.xdata - self.xpress
|
||||||
|
dy = gui_event.ydata - self.ypress
|
||||||
|
self.cur_xlim -= dx
|
||||||
|
self.cur_ylim -= dy
|
||||||
|
ax.set_xlim(self.cur_xlim)
|
||||||
|
ax.set_ylim(self.cur_ylim)
|
||||||
|
ax.figure.canvas.draw()
|
||||||
|
|
||||||
|
def panRelease(self, gui_event):
|
||||||
|
self.press = None
|
||||||
|
self.figure.canvas.draw()
|
||||||
|
|
||||||
|
def scrollZoom(self, gui_event, factor=2.):
|
||||||
|
if not gui_event.xdata or not gui_event.ydata:
|
||||||
|
return
|
||||||
|
ax_check = False
|
||||||
|
for ax in self.axes:
|
||||||
|
if gui_event.inaxes == ax:
|
||||||
|
ax_check = True
|
||||||
|
break
|
||||||
|
if not ax_check: 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(ax))
|
||||||
|
new_ylim = gui_event.ydata - \
|
||||||
|
scale_factor * (gui_event.ydata - self.getYLims(ax))
|
||||||
|
|
||||||
|
new_xlim.sort()
|
||||||
|
global_x = self.getGlobalLimits(ax, 'x')
|
||||||
|
global_y = self.getGlobalLimits(ax, '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.setXLims(ax, new_xlim)
|
||||||
|
self.setYLims(ax, new_ylim)
|
||||||
|
self.draw()
|
||||||
|
|
||||||
def connectEvents(self):
|
def connectEvents(self):
|
||||||
self.cidscroll = self.connectScrollEvent(self.scrollZoom)
|
self.cidscroll = self.connectScrollEvent(self.scrollZoom)
|
||||||
|
self.cidpress = self.connectPressEvent(self.panPress)
|
||||||
|
self.cidmotion = self.connectMotionEvent(self.panMotion)
|
||||||
|
self.cidrelease = self.connectReleaseEvent(self.panRelease)
|
||||||
|
|
||||||
def disconnectEvents(self):
|
def disconnectEvents(self):
|
||||||
self.mpl_disconnect(self.cidscroll)
|
self.disconnectScrollEvent()
|
||||||
|
self.disconnectMotionEvent()
|
||||||
|
self.disconnectPressEvent()
|
||||||
|
self.disconnectReleaseEvent()
|
||||||
|
|
||||||
|
def disconnectPressEvent(self):
|
||||||
|
self.mpl_disconnect(self.cidpress)
|
||||||
|
self.cidpress = None
|
||||||
|
|
||||||
|
def connectPressEvent(self, slot):
|
||||||
|
return self.mpl_connect('button_press_event', slot)
|
||||||
|
|
||||||
|
def disconnectMotionEvent(self):
|
||||||
|
self.mpl_disconnect(self.cidmotion)
|
||||||
|
self.cidmotion = None
|
||||||
|
|
||||||
|
def connectMotionEvent(self, slot):
|
||||||
|
return self.mpl_connect('motion_notify_event', slot)
|
||||||
|
|
||||||
|
def disconnectReleaseEvent(self):
|
||||||
|
self.mpl_disconnect(self.cidrelease)
|
||||||
|
self.cidrelease = None
|
||||||
|
|
||||||
|
def connectReleaseEvent(self, slot):
|
||||||
|
return self.mpl_connect('button_release_event', slot)
|
||||||
|
|
||||||
|
def disconnectScrollEvent(self):
|
||||||
|
self.mpl_disconnect(self.cidscroll)
|
||||||
self.cidscroll = None
|
self.cidscroll = None
|
||||||
|
|
||||||
|
def connectScrollEvent(self, slot):
|
||||||
|
return self.mpl_connect('scroll_event', slot)
|
||||||
|
|
||||||
def getPlotDict(self):
|
def getPlotDict(self):
|
||||||
return self.plotdict
|
return self.plotdict
|
||||||
|
|
||||||
def setPlotDict(self, key, value):
|
def setPlotDict(self, key, value):
|
||||||
self.plotdict[key] = value
|
self.plotdict[key] = value
|
||||||
|
|
||||||
def connectScrollEvent(self, slot):
|
|
||||||
return self.mpl_connect('scroll_event', slot)
|
|
||||||
|
|
||||||
def clearPlotDict(self):
|
def clearPlotDict(self):
|
||||||
self.plotdict = dict()
|
self.plotdict = dict()
|
||||||
|
|
||||||
@ -657,7 +766,9 @@ class PylotCanvas(FigureCanvas):
|
|||||||
def plotWFData(self, wfdata, title=None, zoomx=None, zoomy=None,
|
def plotWFData(self, wfdata, title=None, zoomx=None, zoomy=None,
|
||||||
noiselevel=None, scaleddata=False, mapping=True,
|
noiselevel=None, scaleddata=False, mapping=True,
|
||||||
component='*', nth_sample=1, iniPick=None, verbosity=0):
|
component='*', nth_sample=1, iniPick=None, verbosity=0):
|
||||||
self.getAxes().cla()
|
ax = self.axes[0]
|
||||||
|
ax.cla()
|
||||||
|
|
||||||
self.clearPlotDict()
|
self.clearPlotDict()
|
||||||
wfstart, wfend = full_range(wfdata)
|
wfstart, wfend = full_range(wfdata)
|
||||||
nmax = 0
|
nmax = 0
|
||||||
@ -704,58 +815,54 @@ class PylotCanvas(FigureCanvas):
|
|||||||
trace.normalize(np.max(np.abs(trace.data)) * 2)
|
trace.normalize(np.max(np.abs(trace.data)) * 2)
|
||||||
times = [time for index, time in enumerate(time_ax) if not index % nth_sample]
|
times = [time for index, time in enumerate(time_ax) if not index % nth_sample]
|
||||||
data = [datum + n for index, datum in enumerate(trace.data) if not index % nth_sample]
|
data = [datum + n for index, datum in enumerate(trace.data) if not index % nth_sample]
|
||||||
self.getAxes().plot(times, data, 'k', linewidth=0.7)
|
ax.plot(times, data, 'k', linewidth=0.7)
|
||||||
if noiselevel is not None:
|
if noiselevel is not None:
|
||||||
for level in noiselevel:
|
for level in noiselevel:
|
||||||
self.getAxes().plot([time_ax[0], time_ax[-1]],
|
ax.plot([time_ax[0], time_ax[-1]],
|
||||||
[level, level], '--k')
|
[level, level], '--k')
|
||||||
|
self.setPlotDict(n, (station, channel, network))
|
||||||
if iniPick:
|
if iniPick:
|
||||||
ax = self.getAxes()
|
|
||||||
ax.vlines(iniPick, ax.get_ylim()[0], ax.get_ylim()[1],
|
ax.vlines(iniPick, ax.get_ylim()[0], ax.get_ylim()[1],
|
||||||
colors='m', linestyles='dashed',
|
colors='m', linestyles='dashed',
|
||||||
linewidth=2)
|
linewidth=2)
|
||||||
self.setPlotDict(n, (station, channel, network))
|
|
||||||
xlabel = 'seconds since {0}'.format(wfstart)
|
xlabel = 'seconds since {0}'.format(wfstart)
|
||||||
ylabel = ''
|
ylabel = ''
|
||||||
self.updateWidget(xlabel, ylabel, title)
|
self.updateWidget(xlabel, ylabel, title)
|
||||||
self.setXLims([0, wfend - wfstart])
|
self.setXLims(ax, [0, wfend - wfstart])
|
||||||
self.setYLims([-0.5, nmax + 0.5])
|
self.setYLims(ax, [-0.5, nmax + 0.5])
|
||||||
if zoomx is not None:
|
if zoomx is not None:
|
||||||
self.setXLims(zoomx)
|
self.setXLims(ax, zoomx)
|
||||||
if zoomy is not None:
|
if zoomy is not None:
|
||||||
self.setYLims(zoomy)
|
self.setYLims(ax, zoomy)
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def getAxes(self):
|
def getXLims(self, ax):
|
||||||
return self.axes[0]
|
return ax.get_xlim()
|
||||||
|
|
||||||
def getXLims(self):
|
def getYLims(self, ax):
|
||||||
return self.getAxes().get_xlim()
|
return ax.get_ylim()
|
||||||
|
|
||||||
def getYLims(self):
|
def setXLims(self, ax, lims):
|
||||||
return self.getAxes().get_ylim()
|
ax.set_xlim(lims)
|
||||||
|
|
||||||
def setXLims(self, lims):
|
def setYLims(self, ax, lims):
|
||||||
self.getAxes().set_xlim(lims)
|
ax.set_ylim(lims)
|
||||||
|
|
||||||
def setYLims(self, lims):
|
|
||||||
self.getAxes().set_ylim(lims)
|
|
||||||
|
|
||||||
def setYTickLabels(self, pos, labels):
|
def setYTickLabels(self, pos, labels):
|
||||||
self.getAxes().set_yticks(list(pos))
|
self.axes[0].set_yticks(list(pos))
|
||||||
self.getAxes().set_yticklabels(labels)
|
self.axes[0].set_yticklabels(labels)
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def updateXLabel(self, text):
|
def updateXLabel(self, text):
|
||||||
self.getAxes().set_xlabel(text)
|
self.axes[0].set_xlabel(text)
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def updateYLabel(self, text):
|
def updateYLabel(self, text):
|
||||||
self.getAxes().set_ylabel(text)
|
self.axes[0].set_ylabel(text)
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def updateTitle(self, text):
|
def updateTitle(self, text):
|
||||||
self.getAxes().set_title(text, verticalalignment='bottom')
|
self.axes[0].set_title(text, verticalalignment='bottom')
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def updateWidget(self, xlabel, ylabel, title):
|
def updateWidget(self, xlabel, ylabel, title):
|
||||||
@ -764,67 +871,40 @@ class PylotCanvas(FigureCanvas):
|
|||||||
self.updateTitle(title)
|
self.updateTitle(title)
|
||||||
|
|
||||||
def insertLabel(self, pos, text):
|
def insertLabel(self, pos, text):
|
||||||
pos = pos / max(self.getAxes().ylim)
|
pos = pos / max(self.axes[0].ylim)
|
||||||
axann = self.getAxes().annotate(text, xy=(.03, pos),
|
axann = self.axes[0].annotate(text, xy=(.03, pos),
|
||||||
xycoords='axes fraction')
|
xycoords='axes fraction')
|
||||||
axann.set_bbox(dict(facecolor='lightgrey', alpha=.6))
|
axann.set_bbox(dict(facecolor='lightgrey', alpha=.6))
|
||||||
|
|
||||||
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.setXLims(new_xlim)
|
|
||||||
self.setYLims(new_ylim)
|
|
||||||
self.draw()
|
|
||||||
|
|
||||||
def setZoomBorders2content(self):
|
def setZoomBorders2content(self):
|
||||||
if not self.axes:
|
if not self.axes:
|
||||||
return
|
return
|
||||||
xlims = self.getXLims()
|
for ax in self.limits.keys():
|
||||||
ylims = self.getYLims()
|
xlims = self.getXLims(ax)
|
||||||
|
ylims = self.getYLims(ax)
|
||||||
|
|
||||||
self.limits = {'x': xlims,
|
self.limits[ax] = {'x': xlims,
|
||||||
'y': ylims}
|
'y': ylims}
|
||||||
|
|
||||||
for ax, limit in self.limits.items():
|
for axis, limit in self.limits[ax].items():
|
||||||
self.setGlobalLimits(ax, limit)
|
self.setGlobalLimits(ax, axis, limit)
|
||||||
|
|
||||||
def updateCurrentLimits(self):
|
def updateCurrentLimits(self):
|
||||||
self.setXLims(self.getXLims())
|
for ax in self.limits.keys():
|
||||||
self.setYLims(self.getYLims())
|
self.setXLims(ax, self.getXLims(ax))
|
||||||
|
self.setYLims(ax, self.getYLims(ax))
|
||||||
|
|
||||||
def getGlobalLimits(self, axis):
|
def getGlobalLimits(self, ax, axis):
|
||||||
return self.limits[axis]
|
return self.limits[ax][axis]
|
||||||
|
|
||||||
def setGlobalLimits(self, axis, limits):
|
def setGlobalLimits(self, ax, axis, limits):
|
||||||
self.limits[axis] = limits
|
self.limits[ax][axis] = limits
|
||||||
|
|
||||||
|
def resetZoom(self):
|
||||||
|
for ax in self.figure.axes:
|
||||||
|
self.setXLims(ax, self.getGlobalLimits(ax, 'x'))
|
||||||
|
self.setYLims(ax, self.getGlobalLimits(ax, 'y'))
|
||||||
|
self.draw()
|
||||||
|
|
||||||
|
|
||||||
class PhaseDefaults(QtGui.QDialog):
|
class PhaseDefaults(QtGui.QDialog):
|
||||||
@ -960,20 +1040,22 @@ 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 = PylotCanvas(parent=self, connect_events=False, multicursor=True)
|
self.multicompfig = PylotCanvas(parent=self, multicursor=True)
|
||||||
self.phaseplot = PhasePlotWidget(self)
|
self.phaseplot = PhasePlotWidget(self)
|
||||||
self.phaseplot.hide()
|
self.phaseplot.hide()
|
||||||
|
|
||||||
# setup ui
|
|
||||||
self.setupUi()
|
|
||||||
|
|
||||||
# plot data
|
# plot data
|
||||||
self.getPlotWidget().plotWFData(wfdata=self.getWFData(),
|
self.multicompfig.plotWFData(wfdata=self.getWFData(),
|
||||||
title=self.getStation())
|
title=self.getStation())
|
||||||
|
|
||||||
self.getPlotWidget().setZoomBorders2content()
|
self.multicompfig.setZoomBorders2content()
|
||||||
|
|
||||||
self.updateCurrentLimits()
|
self.multicompfig.updateCurrentLimits()
|
||||||
|
|
||||||
|
self.connectScrollEvent()
|
||||||
|
|
||||||
|
# setup ui
|
||||||
|
self.setupUi()
|
||||||
|
|
||||||
# set plot labels
|
# set plot labels
|
||||||
self.setPlotLabels()
|
self.setPlotLabels()
|
||||||
@ -981,11 +1063,6 @@ class PickDlg(QDialog):
|
|||||||
# draw picks if present
|
# draw picks if present
|
||||||
self.drawAllPicks()
|
self.drawAllPicks()
|
||||||
|
|
||||||
# connect button press event to an action
|
|
||||||
self.connectEvents()
|
|
||||||
self.cidscroll_arr = self.connectScrollEvent(self.refreshArrivalsText)
|
|
||||||
self.cidscroll_ph = self.connectScrollEvent(self.refreshPhaseText)
|
|
||||||
|
|
||||||
# init expected picks using obspy Taup
|
# init expected picks using obspy Taup
|
||||||
try:
|
try:
|
||||||
if self.parent().metadata:
|
if self.parent().metadata:
|
||||||
@ -1013,7 +1090,7 @@ class PickDlg(QDialog):
|
|||||||
self.addPickPhases(menuBar)
|
self.addPickPhases(menuBar)
|
||||||
|
|
||||||
# create matplotlib toolbar to inherit functionality
|
# create matplotlib toolbar to inherit functionality
|
||||||
self.figToolBar = NavigationToolbar2QT(self.getPlotWidget(), self)
|
self.figToolBar = NavigationToolbar2QT(self.multicompfig, self)
|
||||||
self.figToolBar.hide()
|
self.figToolBar.hide()
|
||||||
|
|
||||||
# create icons
|
# create icons
|
||||||
@ -1037,7 +1114,7 @@ class PickDlg(QDialog):
|
|||||||
tip='Zoom into waveform',
|
tip='Zoom into waveform',
|
||||||
checkable=True)
|
checkable=True)
|
||||||
self.resetZoomAction = createAction(parent=self, text='Home',
|
self.resetZoomAction = createAction(parent=self, text='Home',
|
||||||
slot=self.resetZoom, icon=home_icon,
|
slot=self.multicompfig.resetZoom, icon=home_icon,
|
||||||
tip='Reset zoom to original limits')
|
tip='Reset zoom to original limits')
|
||||||
self.resetPicksAction = createAction(parent=self, text='Delete Picks',
|
self.resetPicksAction = createAction(parent=self, text='Delete Picks',
|
||||||
slot=self.delPicks, icon=del_icon,
|
slot=self.delPicks, icon=del_icon,
|
||||||
@ -1184,11 +1261,11 @@ class PickDlg(QDialog):
|
|||||||
def drawArrivals(self, textOnly=False):
|
def drawArrivals(self, textOnly=False):
|
||||||
if not self.arrivals:
|
if not self.arrivals:
|
||||||
return
|
return
|
||||||
ax = self.getPlotWidget().axes
|
ax = self.multicompfig.axes[0]
|
||||||
if not textOnly:
|
if not textOnly:
|
||||||
ylims = self.getGlobalLimits('y')
|
ylims = self.getGlobalLimits('y')
|
||||||
else:
|
else:
|
||||||
ylims = self.getPlotWidget().getYLims()
|
ylims = self.multicompfig.getYLims(ax)
|
||||||
stime = self.getStartTime()
|
stime = self.getStartTime()
|
||||||
source_origin = self.parent().get_current_event().origins[0]
|
source_origin = self.parent().get_current_event().origins[0]
|
||||||
source_time = source_origin.time
|
source_time = source_origin.time
|
||||||
@ -1268,45 +1345,16 @@ class PickDlg(QDialog):
|
|||||||
if phaseIndex == 0:
|
if phaseIndex == 0:
|
||||||
picksMenu.addSeparator()
|
picksMenu.addSeparator()
|
||||||
|
|
||||||
def disconnectPressEvent(self):
|
|
||||||
widget = self.getPlotWidget()
|
|
||||||
widget.mpl_disconnect(self.cidpress)
|
|
||||||
self.cidpress = None
|
|
||||||
|
|
||||||
def connectPressEvent(self, slot):
|
|
||||||
widget = self.getPlotWidget()
|
|
||||||
return widget.mpl_connect('button_press_event', slot)
|
|
||||||
|
|
||||||
def disconnectScrollEvent(self):
|
def disconnectScrollEvent(self):
|
||||||
widget = self.getPlotWidget()
|
widget = self.multicompfig
|
||||||
widget.mpl_disconnect(self.cidscroll)
|
|
||||||
widget.mpl_disconnect(self.cidscroll_arr)
|
widget.mpl_disconnect(self.cidscroll_arr)
|
||||||
widget.mpl_disconnect(self.cidscroll_ph)
|
widget.mpl_disconnect(self.cidscroll_ph)
|
||||||
self.cidscroll = None
|
|
||||||
self.cidscroll_arr = None
|
self.cidscroll_arr = None
|
||||||
self.cidscroll_ph = None
|
self.cidscroll_ph = None
|
||||||
|
|
||||||
def connectScrollEvent(self, slot):
|
def connectScrollEvent(self):
|
||||||
widget = self.getPlotWidget()
|
self.cidscroll_arr = self.multicompfig.connectScrollEvent(self.refreshArrivalsText)
|
||||||
return widget.mpl_connect('scroll_event', slot)
|
self.cidscroll_ph = self.multicompfig.connectScrollEvent(self.refreshPhaseText)
|
||||||
|
|
||||||
def disconnectMotionEvent(self):
|
|
||||||
widget = self.getPlotWidget()
|
|
||||||
widget.mpl_disconnect(self.cidmotion)
|
|
||||||
self.cidmotion = None
|
|
||||||
|
|
||||||
def connectMotionEvent(self, slot):
|
|
||||||
widget = self.getPlotWidget()
|
|
||||||
return widget.mpl_connect('motion_notify_event', slot)
|
|
||||||
|
|
||||||
def disconnectReleaseEvent(self):
|
|
||||||
widget = self.getPlotWidget()
|
|
||||||
widget.mpl_disconnect(self.cidrelease)
|
|
||||||
self.cidrelease = None
|
|
||||||
|
|
||||||
def connectReleaseEvent(self, slot):
|
|
||||||
widget = self.getPlotWidget()
|
|
||||||
return widget.mpl_connect('button_release_event', slot)
|
|
||||||
|
|
||||||
def disable_ar_buttons(self):
|
def disable_ar_buttons(self):
|
||||||
self.enable_ar_buttons(False)
|
self.enable_ar_buttons(False)
|
||||||
@ -1355,13 +1403,11 @@ class PickDlg(QDialog):
|
|||||||
|
|
||||||
def init_p_pick(self):
|
def init_p_pick(self):
|
||||||
self.set_button_color(self.p_button, 'yellow')
|
self.set_button_color(self.p_button, 'yellow')
|
||||||
self.updateCurrentLimits()
|
|
||||||
self.activatePicking()
|
self.activatePicking()
|
||||||
self.currentPhase = str(self.p_button.text())
|
self.currentPhase = str(self.p_button.text())
|
||||||
|
|
||||||
def init_s_pick(self):
|
def init_s_pick(self):
|
||||||
self.set_button_color(self.s_button, 'yellow')
|
self.set_button_color(self.s_button, 'yellow')
|
||||||
self.updateCurrentLimits()
|
|
||||||
self.activatePicking()
|
self.activatePicking()
|
||||||
self.currentPhase = str(self.s_button.text())
|
self.currentPhase = str(self.s_button.text())
|
||||||
|
|
||||||
@ -1394,7 +1440,7 @@ class PickDlg(QDialog):
|
|||||||
self.currentPhase = None
|
self.currentPhase = None
|
||||||
self.reset_p_button()
|
self.reset_p_button()
|
||||||
self.reset_s_button()
|
self.reset_s_button()
|
||||||
self.getPlotWidget().plotWFData(wfdata=self.getWFData(),
|
self.multicompfig.plotWFData(wfdata=self.getWFData(),
|
||||||
title=self.getStation())
|
title=self.getStation())
|
||||||
self.drawAllPicks()
|
self.drawAllPicks()
|
||||||
self.drawArrivals()
|
self.drawArrivals()
|
||||||
@ -1403,20 +1449,20 @@ class PickDlg(QDialog):
|
|||||||
self.deactivatePicking()
|
self.deactivatePicking()
|
||||||
|
|
||||||
def activatePicking(self):
|
def activatePicking(self):
|
||||||
|
self.resetZoom()
|
||||||
if self.zoomAction.isChecked():
|
if self.zoomAction.isChecked():
|
||||||
self.zoomAction.trigger()
|
self.zoomAction.trigger()
|
||||||
self.disconnectReleaseEvent()
|
self.multicompfig.disconnectEvents()
|
||||||
self.disconnectScrollEvent()
|
self.disconnectScrollEvent()
|
||||||
self.disconnectMotionEvent()
|
self.cidpress = self.multicompfig.connectPressEvent(self.setIniPick)
|
||||||
self.disconnectPressEvent()
|
|
||||||
self.cidpress = self.connectPressEvent(self.setIniPick)
|
|
||||||
self.filterWFData()
|
self.filterWFData()
|
||||||
self.pick_block = self.togglePickBlocker()
|
#self.pick_block = self.togglePickBlocker()
|
||||||
self.disconnect_pick_delete()
|
self.disconnect_pick_delete()
|
||||||
|
|
||||||
def deactivatePicking(self):
|
def deactivatePicking(self):
|
||||||
self.disconnectPressEvent()
|
self.disconnectPressEvent()
|
||||||
self.connectEvents()
|
self.connectScrollEvent()
|
||||||
|
self.multicompfig.connectEvents()
|
||||||
self.connect_pick_delete()
|
self.connect_pick_delete()
|
||||||
|
|
||||||
def getParameter(self):
|
def getParameter(self):
|
||||||
@ -1436,14 +1482,11 @@ class PickDlg(QDialog):
|
|||||||
return self.network + '.' + self.station
|
return self.network + '.' + self.station
|
||||||
return self.station
|
return self.station
|
||||||
|
|
||||||
def getPlotWidget(self):
|
|
||||||
return self.multicompfig
|
|
||||||
|
|
||||||
def getChannelID(self, key):
|
def getChannelID(self, key):
|
||||||
return self.getPlotWidget().getPlotDict()[int(key)][1]
|
return self.multicompfig.getPlotDict()[int(key)][1]
|
||||||
|
|
||||||
def getTraceID(self, channels):
|
def getTraceID(self, channels):
|
||||||
plotDict = self.getPlotWidget().getPlotDict()
|
plotDict = self.multicompfig.getPlotDict()
|
||||||
traceIDs = []
|
traceIDs = []
|
||||||
for channel in channels:
|
for channel in channels:
|
||||||
channel = channel.upper()
|
channel = channel.upper()
|
||||||
@ -1475,11 +1518,7 @@ class PickDlg(QDialog):
|
|||||||
self.cur_ylim = limits
|
self.cur_ylim = limits
|
||||||
|
|
||||||
def getGlobalLimits(self, axis):
|
def getGlobalLimits(self, axis):
|
||||||
return self.getPlotWidget().getGlobalLimits(axis)
|
return self.multicompfig.getGlobalLimits(axis)
|
||||||
|
|
||||||
def updateCurrentLimits(self):
|
|
||||||
self.setXLims(self.getPlotWidget().getXLims())
|
|
||||||
self.setYLims(self.getPlotWidget().getYLims())
|
|
||||||
|
|
||||||
def getWFData(self):
|
def getWFData(self):
|
||||||
return self.data
|
return self.data
|
||||||
@ -1528,11 +1567,9 @@ class PickDlg(QDialog):
|
|||||||
channel = self.getChannelID(trace_number)
|
channel = self.getChannelID(trace_number)
|
||||||
wfdata = self.selectWFData(channel)
|
wfdata = self.selectWFData(channel)
|
||||||
|
|
||||||
self.disconnectScrollEvent()
|
self.multicompfig.disconnectEvents()
|
||||||
self.disconnectPressEvent()
|
self.disconnectPressEvent()
|
||||||
self.disconnectReleaseEvent()
|
self.cidpress = self.multicompfig.connectPressEvent(self.setPick)
|
||||||
self.disconnectMotionEvent()
|
|
||||||
self.cidpress = self.connectPressEvent(self.setPick)
|
|
||||||
|
|
||||||
if self.getPhaseID(self.currentPhase) == 'P':
|
if self.getPhaseID(self.currentPhase) == 'P':
|
||||||
self.set_button_color(self.p_button, 'green')
|
self.set_button_color(self.p_button, 'green')
|
||||||
@ -1600,7 +1637,7 @@ class PickDlg(QDialog):
|
|||||||
self.setXLims([ini_pick - x_res, ini_pick + x_res])
|
self.setXLims([ini_pick - x_res, ini_pick + x_res])
|
||||||
self.setYLims(np.array([-noiselevel * 3.5, noiselevel * 3.5]) +
|
self.setYLims(np.array([-noiselevel * 3.5, noiselevel * 3.5]) +
|
||||||
trace_number)
|
trace_number)
|
||||||
self.getPlotWidget().plotWFData(wfdata=data,
|
self.multicompfig.plotWFData(wfdata=data,
|
||||||
title=self.getStation() +
|
title=self.getStation() +
|
||||||
' picking mode',
|
' picking mode',
|
||||||
zoomx=self.getXLims(),
|
zoomx=self.getXLims(),
|
||||||
@ -1668,7 +1705,7 @@ class PickDlg(QDialog):
|
|||||||
noiselevels = [trace + 1 / (2.5 * 2) for trace in traces] + \
|
noiselevels = [trace + 1 / (2.5 * 2) for trace in traces] + \
|
||||||
[trace - 1 / (2.5 * 2) for trace in traces]
|
[trace - 1 / (2.5 * 2) for trace in traces]
|
||||||
|
|
||||||
self.getPlotWidget().plotWFData(wfdata=data,
|
self.multicompfig.plotWFData(wfdata=data,
|
||||||
title=self.getStation() +
|
title=self.getStation() +
|
||||||
' picking mode',
|
' picking mode',
|
||||||
zoomx=self.getXLims(),
|
zoomx=self.getXLims(),
|
||||||
@ -1682,7 +1719,7 @@ class PickDlg(QDialog):
|
|||||||
parameter = self.parameter
|
parameter = self.parameter
|
||||||
|
|
||||||
# get axes limits
|
# get axes limits
|
||||||
self.updateCurrentLimits()
|
self.multicompfig.updateCurrentLimits()
|
||||||
|
|
||||||
# setting pick
|
# setting pick
|
||||||
pick = gui_event.xdata # get pick time relative to the traces timeaxis not to the global
|
pick = gui_event.xdata # get pick time relative to the traces timeaxis not to the global
|
||||||
@ -1760,10 +1797,14 @@ class PickDlg(QDialog):
|
|||||||
self.disconnectPressEvent()
|
self.disconnectPressEvent()
|
||||||
self.enable_ar_buttons()
|
self.enable_ar_buttons()
|
||||||
self.zoomAction.setEnabled(True)
|
self.zoomAction.setEnabled(True)
|
||||||
self.pick_block = self.togglePickBlocker()
|
#self.pick_block = self.togglePickBlocker()
|
||||||
self.leave_picking_mode()
|
self.leave_picking_mode()
|
||||||
self.setDirty(True)
|
self.setDirty(True)
|
||||||
|
|
||||||
|
def disconnectPressEvent(self):
|
||||||
|
self.multicompfig.mpl_disconnect(self.cidpress)
|
||||||
|
self.cidpress = None
|
||||||
|
|
||||||
def drawAllPicks(self):
|
def drawAllPicks(self):
|
||||||
self.removePhaseText()
|
self.removePhaseText()
|
||||||
self.drawPicks(picktype='manual')
|
self.drawPicks(picktype='manual')
|
||||||
@ -1771,11 +1812,11 @@ class PickDlg(QDialog):
|
|||||||
|
|
||||||
def drawPicks(self, phase=None, picktype='manual', textOnly=False):
|
def drawPicks(self, phase=None, picktype='manual', textOnly=False):
|
||||||
# plotting picks
|
# plotting picks
|
||||||
ax = self.getPlotWidget().axes
|
ax = self.multicompfig.axes[0]
|
||||||
if not textOnly:
|
if not textOnly:
|
||||||
ylims = self.getPlotWidget().getGlobalLimits('y')
|
ylims = self.multicompfig.getGlobalLimits(ax, 'y')
|
||||||
else:
|
else:
|
||||||
ylims = self.getPlotWidget().getYLims()
|
ylims = ax.get_ylim()
|
||||||
if self.getPicks(picktype):
|
if self.getPicks(picktype):
|
||||||
if phase is not None and not phase == 'SPt':
|
if phase is not None and not phase == 'SPt':
|
||||||
if (type(self.getPicks(picktype)[phase]) is dict
|
if (type(self.getPicks(picktype)[phase]) is dict
|
||||||
@ -1842,11 +1883,11 @@ class PickDlg(QDialog):
|
|||||||
ax.legend(loc=1)
|
ax.legend(loc=1)
|
||||||
|
|
||||||
def connect_pick_delete(self):
|
def connect_pick_delete(self):
|
||||||
self.cidpick = self.getPlotWidget().mpl_connect('pick_event', self.onpick_delete)
|
self.cidpick = self.multicompfig.mpl_connect('pick_event', self.onpick_delete)
|
||||||
|
|
||||||
def disconnect_pick_delete(self):
|
def disconnect_pick_delete(self):
|
||||||
if hasattr(self, 'cidpick'):
|
if hasattr(self, 'cidpick'):
|
||||||
self.getPlotWidget().mpl_disconnect(self.cidpick)
|
self.multicompfig.mpl_disconnect(self.cidpick)
|
||||||
|
|
||||||
def onpick_delete(self, event):
|
def onpick_delete(self, event):
|
||||||
if not event.mouseevent.button == 3:
|
if not event.mouseevent.button == 3:
|
||||||
@ -1897,43 +1938,15 @@ class PickDlg(QDialog):
|
|||||||
self.removePhaseText()
|
self.removePhaseText()
|
||||||
self.drawPhaseText()
|
self.drawPhaseText()
|
||||||
|
|
||||||
def panPress(self, gui_event):
|
|
||||||
ax = self.getPlotWidget().axes[0]
|
|
||||||
if gui_event.inaxes != ax: return
|
|
||||||
self.cur_xlim = ax.get_xlim()
|
|
||||||
self.cur_ylim = ax.get_ylim()
|
|
||||||
self.press = gui_event.xdata, gui_event.ydata
|
|
||||||
self.xpress, self.ypress = self.press
|
|
||||||
|
|
||||||
def panRelease(self, gui_event):
|
|
||||||
figure = self.getPlotWidget().figure
|
|
||||||
self.press = None
|
|
||||||
self.refreshPhaseText()
|
|
||||||
self.refreshArrivalsText()
|
|
||||||
figure.canvas.draw()
|
|
||||||
|
|
||||||
def panMotion(self, gui_event):
|
|
||||||
if self.press is None: return
|
|
||||||
ax = self.getPlotWidget().axes[0]
|
|
||||||
if gui_event.inaxes != ax: return
|
|
||||||
dx = gui_event.xdata - self.xpress
|
|
||||||
dy = gui_event.ydata - self.ypress
|
|
||||||
self.cur_xlim -= dx
|
|
||||||
self.cur_ylim -= dy
|
|
||||||
ax.set_xlim(self.cur_xlim)
|
|
||||||
ax.set_ylim(self.cur_ylim)
|
|
||||||
|
|
||||||
ax.figure.canvas.draw()
|
|
||||||
|
|
||||||
def togglePickBlocker(self):
|
def togglePickBlocker(self):
|
||||||
return not self.pick_block
|
return not self.pick_block
|
||||||
|
|
||||||
def filterWFData(self):
|
def filterWFData(self):
|
||||||
if self.pick_block:
|
if self.pick_block:
|
||||||
return
|
return
|
||||||
self.updateCurrentLimits()
|
self.multicompfig.updateCurrentLimits()
|
||||||
data = self.getWFData().copy()
|
data = self.getWFData().copy()
|
||||||
old_title = self.getPlotWidget().getAxes().get_title()
|
old_title = self.multicompfig.axes[0].get_title()
|
||||||
title = None
|
title = None
|
||||||
phase = self.currentPhase
|
phase = self.currentPhase
|
||||||
filtoptions = None
|
filtoptions = None
|
||||||
@ -1956,7 +1969,7 @@ class PickDlg(QDialog):
|
|||||||
title = old_title.replace(', filtered)', ')')
|
title = old_title.replace(', filtered)', ')')
|
||||||
if title is None:
|
if title is None:
|
||||||
title = old_title
|
title = old_title
|
||||||
self.getPlotWidget().plotWFData(wfdata=data, title=title,
|
self.multicompfig.plotWFData(wfdata=data, title=title,
|
||||||
zoomx=self.getXLims(),
|
zoomx=self.getXLims(),
|
||||||
zoomy=self.getYLims())
|
zoomy=self.getYLims())
|
||||||
self.setPlotLabels()
|
self.setPlotLabels()
|
||||||
@ -1964,52 +1977,45 @@ class PickDlg(QDialog):
|
|||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def resetPlot(self):
|
def resetPlot(self):
|
||||||
self.updateCurrentLimits()
|
self.resetZoom()
|
||||||
data = self.getWFData().copy()
|
data = self.getWFData().copy()
|
||||||
title = self.getPlotWidget().getAxes().get_title()
|
title = self.multicompfig.axes[0].get_title()
|
||||||
self.getPlotWidget().plotWFData(wfdata=data, title=title,
|
self.multicompfig.plotWFData(wfdata=data, title=title,
|
||||||
zoomx=self.getXLims(),
|
zoomx=self.getXLims(),
|
||||||
zoomy=self.getYLims())
|
zoomy=self.getYLims())
|
||||||
self.setPlotLabels()
|
self.setPlotLabels()
|
||||||
self.drawAllPicks()
|
self.drawAllPicks()
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
|
def resetZoom(self):
|
||||||
|
ax = self.multicompfig.axes[0]
|
||||||
|
self.setXLims(self.multicompfig.getGlobalLimits(ax, 'x'))
|
||||||
|
self.setYLims(self.multicompfig.getGlobalLimits(ax, 'y'))
|
||||||
|
|
||||||
def setPlotLabels(self):
|
def setPlotLabels(self):
|
||||||
|
|
||||||
# get channel labels
|
# get channel labels
|
||||||
pos = self.getPlotWidget().getPlotDict().keys()
|
pos = self.multicompfig.getPlotDict().keys()
|
||||||
labels = [self.getPlotWidget().getPlotDict()[key][1] for key in pos]
|
labels = [self.multicompfig.getPlotDict()[key][1] for key in pos]
|
||||||
|
|
||||||
|
ax = self.multicompfig.figure.axes[0]
|
||||||
|
|
||||||
# set channel labels
|
# set channel labels
|
||||||
self.getPlotWidget().setYTickLabels(pos, labels)
|
self.multicompfig.setYTickLabels(pos, labels)
|
||||||
self.getPlotWidget().setXLims(self.getXLims())
|
self.multicompfig.setXLims(ax, self.getXLims())
|
||||||
self.getPlotWidget().setYLims(self.getYLims())
|
self.multicompfig.setYLims(ax, 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)
|
||||||
elif self.zoomAction.isChecked():
|
elif self.zoomAction.isChecked():
|
||||||
self.disconnectPressEvent()
|
self.multicompfig.disconnectEvents()
|
||||||
self.disconnectMotionEvent()
|
|
||||||
self.disconnectReleaseEvent()
|
|
||||||
self.disconnectScrollEvent()
|
|
||||||
self.figToolBar.zoom()
|
self.figToolBar.zoom()
|
||||||
else:
|
else:
|
||||||
self.figToolBar.zoom()
|
self.figToolBar.zoom()
|
||||||
|
|
||||||
def resetZoom(self):
|
|
||||||
self.getPlotWidget().setXLims(self.getGlobalLimits('x'))
|
|
||||||
self.getPlotWidget().setYLims(self.getGlobalLimits('y'))
|
|
||||||
self.draw()
|
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
self.getPlotWidget().draw()
|
self.multicompfig.draw()
|
||||||
|
|
||||||
def apply(self):
|
def apply(self):
|
||||||
picks = self.getPicks()
|
picks = self.getPicks()
|
||||||
|
Loading…
Reference in New Issue
Block a user