avoid direct manipulation of attributes of an object; use get and set methods instead; new methods added to feature the desired behavior
This commit is contained in:
parent
6d8a17b7e2
commit
c851fa6901
@ -88,7 +88,7 @@ class MPLWidget(FigureCanvas):
|
|||||||
|
|
||||||
def plotWFData(self, wfdata, title=None, zoomx=None, zoomy=None,
|
def plotWFData(self, wfdata, title=None, zoomx=None, zoomy=None,
|
||||||
noiselevel=None):
|
noiselevel=None):
|
||||||
self.axes.cla()
|
self.getAxes().cla()
|
||||||
self.clearPlotDict()
|
self.clearPlotDict()
|
||||||
wfstart = getGlobalTimes(wfdata)[0]
|
wfstart = getGlobalTimes(wfdata)[0]
|
||||||
for n, trace in enumerate(wfdata):
|
for n, trace in enumerate(wfdata):
|
||||||
@ -98,41 +98,54 @@ class MPLWidget(FigureCanvas):
|
|||||||
print(msg)
|
print(msg)
|
||||||
stime = trace.stats.starttime - wfstart
|
stime = trace.stats.starttime - wfstart
|
||||||
time_ax = prepTimeAxis(stime, trace)
|
time_ax = prepTimeAxis(stime, trace)
|
||||||
trace.detrend()
|
trace.normalize(np.max(np.abs(trace.data)) * 2)
|
||||||
trace.detrend('demean')
|
self.getAxes().plot(time_ax, trace.data + n, 'k')
|
||||||
trace.normalize(trace.data.max() * 2)
|
|
||||||
self.axes.plot(time_ax, trace.data + n, 'k')
|
|
||||||
if noiselevel is not None:
|
if noiselevel is not None:
|
||||||
self.axes.plot([time_ax[0], time_ax[-1]],
|
self.getAxes().plot([time_ax[0], time_ax[-1]],
|
||||||
[noiselevel, noiselevel], '--k')
|
[noiselevel[0], noiselevel[0]], '--k')
|
||||||
self.axes.plot([time_ax[0], time_ax[-1]],
|
self.getAxes().plot([time_ax[0], time_ax[-1]],
|
||||||
[-noiselevel, -noiselevel], '--k')
|
[noiselevel[1], noiselevel[1]], '--k')
|
||||||
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.setPlotDict(n, (station, channel))
|
self.setPlotDict(n, (station, channel))
|
||||||
self.axes.autoscale(tight=True)
|
self.axes.autoscale(tight=True)
|
||||||
if zoomx:
|
if zoomx is not None:
|
||||||
self.axes.set_xlim(zoomx)
|
self.setXLims(zoomx)
|
||||||
if zoomy:
|
if zoomy is not None:
|
||||||
self.axes.set_ylim(zoomy)
|
self.setYLims(zoomy)
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
|
def getAxes(self):
|
||||||
|
return self.axes
|
||||||
|
|
||||||
|
def getXLims(self):
|
||||||
|
return self.getAxes().get_xlim()
|
||||||
|
|
||||||
|
def getYLims(self):
|
||||||
|
return self.getAxes().get_ylim()
|
||||||
|
|
||||||
|
def setXLims(self, lims):
|
||||||
|
self.getAxes().set_xlim(lims)
|
||||||
|
|
||||||
|
def setYLims(self, lims):
|
||||||
|
self.getAxes().set_ylim(lims)
|
||||||
|
|
||||||
def setYTickLabels(self, pos, labels):
|
def setYTickLabels(self, pos, labels):
|
||||||
self.axes.set_yticks(pos)
|
self.getAxes().set_yticks(pos)
|
||||||
self.axes.set_yticklabels(labels)
|
self.getAxes().set_yticklabels(labels)
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def updateXLabel(self, text):
|
def updateXLabel(self, text):
|
||||||
self.axes.set_xlabel(text)
|
self.getAxes().set_xlabel(text)
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def updateYLabel(self, text):
|
def updateYLabel(self, text):
|
||||||
self.axes.set_ylabel(text)
|
self.getAxes().set_ylabel(text)
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def updateTitle(self, text):
|
def updateTitle(self, text):
|
||||||
self.axes.set_title(text)
|
self.getAxes().set_title(text)
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def updateWidget(self, xlabel, ylabel, title):
|
def updateWidget(self, xlabel, ylabel, title):
|
||||||
@ -141,8 +154,8 @@ class MPLWidget(FigureCanvas):
|
|||||||
self.updateTitle(title)
|
self.updateTitle(title)
|
||||||
|
|
||||||
def insertLabel(self, pos, text):
|
def insertLabel(self, pos, text):
|
||||||
pos = pos / max(self.axes.ylim)
|
pos = pos / max(self.getAxes().ylim)
|
||||||
axann = self.axes.annotate(text, xy=(.03, pos),
|
axann = self.getAxes().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))
|
||||||
|
|
||||||
@ -160,6 +173,8 @@ class PickDlg(QDialog):
|
|||||||
self.press = None
|
self.press = None
|
||||||
self.xpress = None
|
self.xpress = None
|
||||||
self.ypress = None
|
self.ypress = None
|
||||||
|
self.cur_xlim = None
|
||||||
|
self.cur_ylim = None
|
||||||
|
|
||||||
# set attribute holding data
|
# set attribute holding data
|
||||||
if data is None:
|
if data is None:
|
||||||
@ -182,9 +197,14 @@ class PickDlg(QDialog):
|
|||||||
# plot data
|
# plot data
|
||||||
self.getPlotWidget().plotWFData(wfdata=self.getWFData(),
|
self.getPlotWidget().plotWFData(wfdata=self.getWFData(),
|
||||||
title=self.getStation())
|
title=self.getStation())
|
||||||
self.limits = {'xlims': self.getPlotWidget().axes.get_xlim(),
|
|
||||||
'ylims': self.getPlotWidget().axes.get_ylim()}
|
xlims = self.getPlotWidget().getXLims()
|
||||||
self.apd = self.getWFData()
|
ylims = self.getPlotWidget().getYLims()
|
||||||
|
|
||||||
|
self.limits = {'x': xlims,
|
||||||
|
'y': ylims}
|
||||||
|
|
||||||
|
self.updateCurrentLimits()
|
||||||
|
|
||||||
# set plot labels
|
# set plot labels
|
||||||
|
|
||||||
@ -293,6 +313,7 @@ class PickDlg(QDialog):
|
|||||||
|
|
||||||
def verifyPhaseSelection(self):
|
def verifyPhaseSelection(self):
|
||||||
phase = self.selectPhase.currentText()
|
phase = self.selectPhase.currentText()
|
||||||
|
self.updateCurrentLimits()
|
||||||
if phase:
|
if phase:
|
||||||
self.disconnectReleaseEvent()
|
self.disconnectReleaseEvent()
|
||||||
self.disconnectScrollEvent()
|
self.disconnectScrollEvent()
|
||||||
@ -321,6 +342,25 @@ class PickDlg(QDialog):
|
|||||||
def getChannelID(self, key):
|
def getChannelID(self, key):
|
||||||
return self.getPlotWidget().getPlotDict()[int(key)][1]
|
return self.getPlotWidget().getPlotDict()[int(key)][1]
|
||||||
|
|
||||||
|
def getXLims(self):
|
||||||
|
return self.cur_xlim
|
||||||
|
|
||||||
|
def getYLims(self):
|
||||||
|
return self.cur_ylim
|
||||||
|
|
||||||
|
def setXLims(self, limits):
|
||||||
|
self.cur_xlim = limits
|
||||||
|
|
||||||
|
def setYLims(self, limits):
|
||||||
|
self.cur_ylim = limits
|
||||||
|
|
||||||
|
def getGlobalLimits(self, axis):
|
||||||
|
return self.limits[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
|
||||||
|
|
||||||
@ -394,11 +434,16 @@ class PickDlg(QDialog):
|
|||||||
zoomx = [ini_pick - x_res, ini_pick + x_res]
|
zoomx = [ini_pick - x_res, ini_pick + x_res]
|
||||||
zoomy = [-noiselevel * 1.5, noiselevel * 1.5]
|
zoomy = [-noiselevel * 1.5, noiselevel * 1.5]
|
||||||
self.getPlotWidget().plotWFData(wfdata=wfdata,
|
self.getPlotWidget().plotWFData(wfdata=wfdata,
|
||||||
|
self.setXLims([ini_pick - x_res, ini_pick + x_res])
|
||||||
|
self.setYLims(np.array([-noiselevel * 2.5, noiselevel * 2.5]) +
|
||||||
|
trace_number)
|
||||||
title=self.getStation() +
|
title=self.getStation() +
|
||||||
' picking mode',
|
' picking mode',
|
||||||
zoomx=zoomx,
|
zoomx=zoomx,
|
||||||
zoomy=zoomy,
|
zoomy=zoomy,
|
||||||
noiselevel=noiselevel)
|
noiselevel=noiselevel)
|
||||||
|
zoomx=self.getXLims(),
|
||||||
|
zoomy=self.getYLims(),
|
||||||
|
|
||||||
self.zoomAction.setEnabled(False)
|
self.zoomAction.setEnabled(False)
|
||||||
|
|
||||||
@ -408,6 +453,10 @@ class PickDlg(QDialog):
|
|||||||
self.setPlotLabels()
|
self.setPlotLabels()
|
||||||
|
|
||||||
def setPick(self, gui_event):
|
def setPick(self, gui_event):
|
||||||
|
|
||||||
|
# get axes limits
|
||||||
|
self.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
|
||||||
channel = self.getChannelID(round(gui_event.ydata))
|
channel = self.getChannelID(round(gui_event.ydata))
|
||||||
@ -452,12 +501,15 @@ class PickDlg(QDialog):
|
|||||||
self.disconnectPressEvent()
|
self.disconnectPressEvent()
|
||||||
self.zoomAction.setEnabled(True)
|
self.zoomAction.setEnabled(True)
|
||||||
self.selectPhase.setCurrentIndex(-1)
|
self.selectPhase.setCurrentIndex(-1)
|
||||||
|
self.getPlotWidget().setXLims(self.getXLims())
|
||||||
|
self.getPlotWidget().setYLims(self.getYLims())
|
||||||
|
|
||||||
def drawPicks(self, phase=None):
|
def drawPicks(self, phase=None):
|
||||||
# plotting picks
|
# plotting picks
|
||||||
ax = self.getPlotWidget().axes
|
ax = self.getPlotWidget().axes
|
||||||
|
|
||||||
ylims = ax.get_ylim()
|
ylims = ax.get_ylim()
|
||||||
|
ylims = self.getGlobalLimits('y')
|
||||||
if self.getPicks():
|
if self.getPicks():
|
||||||
if phase is not None:
|
if phase is not None:
|
||||||
picks = self.getPicks()[phase]
|
picks = self.getPicks()[phase]
|
||||||
@ -529,6 +581,8 @@ class PickDlg(QDialog):
|
|||||||
|
|
||||||
# set channel labels
|
# set channel labels
|
||||||
self.getPlotWidget().setYTickLabels(pos, labels)
|
self.getPlotWidget().setYTickLabels(pos, labels)
|
||||||
|
self.getPlotWidget().setXLims(self.getXLims())
|
||||||
|
self.getPlotWidget().setYLims(self.getYLims())
|
||||||
|
|
||||||
def zoom(self):
|
def zoom(self):
|
||||||
if self.zoomAction.isChecked():
|
if self.zoomAction.isChecked():
|
||||||
@ -545,10 +599,7 @@ class PickDlg(QDialog):
|
|||||||
|
|
||||||
def scrollZoom(self, gui_event, factor=2.):
|
def scrollZoom(self, gui_event, factor=2.):
|
||||||
|
|
||||||
widget = self.getPlotWidget()
|
self.updateCurrentLimits()
|
||||||
|
|
||||||
curr_xlim = widget.axes.get_xlim()
|
|
||||||
curr_ylim = widget.axes.get_ylim()
|
|
||||||
|
|
||||||
if gui_event.button == 'up':
|
if gui_event.button == 'up':
|
||||||
scale_factor = 1 / factor
|
scale_factor = 1 / factor
|
||||||
@ -561,20 +612,25 @@ class PickDlg(QDialog):
|
|||||||
print gui_event.button
|
print gui_event.button
|
||||||
|
|
||||||
new_xlim = gui_event.xdata - \
|
new_xlim = gui_event.xdata - \
|
||||||
scale_factor * (gui_event.xdata - curr_xlim)
|
scale_factor * (gui_event.xdata - self.getXLims())
|
||||||
new_ylim = gui_event.ydata - \
|
new_ylim = gui_event.ydata - \
|
||||||
scale_factor * (gui_event.ydata - curr_ylim)
|
scale_factor * (gui_event.ydata - self.getYLims())
|
||||||
|
|
||||||
new_xlim.sort()
|
new_xlim.sort()
|
||||||
new_xlim[0] = max(new_xlim[0], self.limits['xlims'][0])
|
global_x = self.getGlobalLimits('x')
|
||||||
new_xlim[1] = min(new_xlim[1], self.limits['xlims'][1])
|
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.sort()
|
||||||
new_ylim[0] = max(new_ylim[0], self.limits['ylims'][0])
|
new_ylim[0] = max(new_ylim[0], global_y[0])
|
||||||
new_ylim[1] = min(new_ylim[1], self.limits['ylims'][1])
|
new_ylim[1] = min(new_ylim[1], global_y[1])
|
||||||
|
|
||||||
widget.axes.set_xlim(new_xlim)
|
self.getPlotWidget().setXLims(new_xlim)
|
||||||
widget.axes.set_ylim(new_ylim)
|
self.getPlotWidget().setYLims(new_ylim)
|
||||||
widget.draw()
|
self.draw()
|
||||||
|
|
||||||
|
def draw(self):
|
||||||
|
self.getPlotWidget().draw()
|
||||||
|
|
||||||
def apply(self):
|
def apply(self):
|
||||||
picks = self.getPicks()
|
picks = self.getPicks()
|
||||||
|
Loading…
Reference in New Issue
Block a user