[change] phase/expected phase arrivals text position now stays readable around pickDlg axes

This commit is contained in:
Marcel Paffrath 2017-07-10 15:39:44 +02:00
parent d966b87eba
commit e0926c6b20

View File

@ -738,6 +738,9 @@ class PickDlg(QDialog):
self.rotate = rotate self.rotate = rotate
self.components = 'ZNE' self.components = 'ZNE'
self.currentPhase = None self.currentPhase = None
self.phaseText = []
self.arrivals = []
self.arrivalsText = []
settings = QSettings() settings = QSettings()
pylot_user = getpass.getuser() pylot_user = getpass.getuser()
self._user = settings.value('user/Login', pylot_user) self._user = settings.value('user/Login', pylot_user)
@ -957,19 +960,38 @@ class PickDlg(QDialog):
phases = [phase.strip() for phase in phases] phases = [phase.strip() for phase in phases]
return phases return phases
def drawArrivals(self): def drawArrivals(self, textOnly=False):
if not self.arrivals: if not self.arrivals:
return return
ax = self.getPlotWidget().axes ax = self.getPlotWidget().axes
if not textOnly:
ylims = self.getGlobalLimits('y') ylims = self.getGlobalLimits('y')
else:
ylims = self.getPlotWidget().getYLims()
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
for arrival in self.arrivals: for arrival in self.arrivals:
arrival_time_abs = source_time + arrival.time arrival_time_abs = source_time + arrival.time
time_rel = arrival_time_abs - stime time_rel = arrival_time_abs - stime
if not textOnly:
ax.plot([time_rel, time_rel], ylims, '0.3', linestyle='dashed') ax.plot([time_rel, time_rel], ylims, '0.3', linestyle='dashed')
ax.text(time_rel, ylims[0], arrival.name, color='0.5') self.arrivalsText.append(ax.text(time_rel, ylims[0], arrival.name, color='0.5'))
def drawArrivalsText(self):
return self.drawArrivals(True)
def refreshArrivalsText(self):
self.removeArrivalsText()
self.drawArrivalsText()
def removeArrivalsText(self):
for textItem in self.arrivalsText:
try:
textItem.remove()
except:
pass
self.arrivalsText = []
def addPickPhases(self, menuBar): def addPickPhases(self, menuBar):
settings = QtCore.QSettings() settings = QtCore.QSettings()
@ -1497,13 +1519,17 @@ class PickDlg(QDialog):
self.leave_picking_mode() self.leave_picking_mode()
def drawAllPicks(self): def drawAllPicks(self):
self.removePhaseText()
self.drawPicks(picktype='manual') self.drawPicks(picktype='manual')
self.drawPicks(picktype='auto') self.drawPicks(picktype='auto')
def drawPicks(self, phase=None, picktype='manual'): def drawPicks(self, phase=None, picktype='manual', textOnly=False):
# plotting picks # plotting picks
ax = self.getPlotWidget().axes ax = self.getPlotWidget().axes
if not textOnly:
ylims = self.getGlobalLimits('y') ylims = self.getGlobalLimits('y')
else:
ylims = self.getPlotWidget().getYLims()
phase_col = { phase_col = {
'P': ('c', 'c--', 'b-', 'bv', 'b^', 'b', 'c:'), 'P': ('c', 'c--', 'b-', 'bv', 'b^', 'b', 'c:'),
'S': ('m', 'm--', 'r-', 'rv', 'r^', 'r', 'm:') 'S': ('m', 'm--', 'r-', 'rv', 'r^', 'r', 'm:')
@ -1516,7 +1542,7 @@ class PickDlg(QDialog):
colors = phase_col[phase[0].upper()] colors = phase_col[phase[0].upper()]
elif phase is None: elif phase is None:
for phase in self.getPicks(picktype): for phase in self.getPicks(picktype):
self.drawPicks(phase, picktype) self.drawPicks(phase, picktype, textOnly)
return return
else: else:
return return
@ -1524,12 +1550,13 @@ class PickDlg(QDialog):
return return
mpp = picks['mpp'] - self.getStartTime() mpp = picks['mpp'] - self.getStartTime()
if picks['epp'] and picks['lpp']: if picks['epp'] and picks['lpp'] and not textOnly:
epp = picks['epp'] - self.getStartTime() epp = picks['epp'] - self.getStartTime()
lpp = picks['lpp'] - self.getStartTime() lpp = picks['lpp'] - self.getStartTime()
spe = picks['spe'] spe = picks['spe']
if picktype == 'manual': if picktype == 'manual':
if not textOnly:
if picks['epp'] and picks['lpp']: if picks['epp'] and picks['lpp']:
ax.fill_between([epp, lpp], ylims[0], ylims[1], ax.fill_between([epp, lpp], ylims[0], ylims[1],
alpha=.25, color=colors[0], label='EPP, LPP') alpha=.25, color=colors[0], label='EPP, LPP')
@ -1539,16 +1566,31 @@ class PickDlg(QDialog):
ax.plot([mpp, mpp], ylims, colors[2], label='{}-Pick'.format(phase)) ax.plot([mpp, mpp], ylims, colors[2], label='{}-Pick'.format(phase))
else: else:
ax.plot([mpp, mpp], ylims, colors[6], label='{}-Pick (NO PICKERROR)'.format(phase)) ax.plot([mpp, mpp], ylims, colors[6], label='{}-Pick (NO PICKERROR)'.format(phase))
ax.text(mpp, ylims[1], phase) # append phase text (if textOnly: draw with current ylims)
self.phaseText.append(ax.text(mpp, ylims[1], phase))
elif picktype == 'auto': elif picktype == 'auto':
ax.plot(mpp, ylims[1], colors[3], ax.plot(mpp, ylims[1], colors[3],
mpp, ylims[0], colors[4]) mpp, ylims[0], colors[4])
ax.vlines(mpp, ylims[0], ylims[1], colors[5], linestyles='dotted') ax.vlines(mpp, ylims[0], ylims[1], colors[5], linestyles='dotted')
else: else:
raise TypeError('Unknown picktype {0}'.format(picktype)) raise TypeError('Unknown picktype {0}'.format(picktype))
ax.legend() ax.legend()
def drawPhaseText(self):
return self.drawPicks(picktype='manual', textOnly=True)
def removePhaseText(self):
for textItem in self.phaseText:
try:
textItem.remove()
except:
pass
self.phaseText = []
def refreshPhaseText(self):
self.removePhaseText()
self.drawPhaseText()
def panPress(self, gui_event): def panPress(self, gui_event):
ax = self.getPlotWidget().axes ax = self.getPlotWidget().axes
@ -1561,6 +1603,8 @@ class PickDlg(QDialog):
def panRelease(self, gui_event): def panRelease(self, gui_event):
ax = self.getPlotWidget().axes ax = self.getPlotWidget().axes
self.press = None self.press = None
self.refreshPhaseText()
self.refreshArrivalsText()
ax.figure.canvas.draw() ax.figure.canvas.draw()
def panMotion(self, gui_event): def panMotion(self, gui_event):
@ -1682,6 +1726,8 @@ class PickDlg(QDialog):
self.getPlotWidget().setXLims(new_xlim) self.getPlotWidget().setXLims(new_xlim)
self.getPlotWidget().setYLims(new_ylim) self.getPlotWidget().setYLims(new_ylim)
self.refreshArrivalsText()
self.refreshPhaseText()
self.draw() self.draw()
def resetZoom(self): def resetZoom(self):