[add] new flexible linestyles and colors pyqtgraph

This commit is contained in:
Marcel Paffrath 2017-08-14 16:15:42 +02:00
parent 9edabc6aef
commit 37373864ce
2 changed files with 113 additions and 27 deletions

View File

@ -73,7 +73,7 @@ from pylot.core.util.errors import FormatError, DatastructureError, \
from pylot.core.util.connection import checkurl
from pylot.core.util.dataprocessing import read_metadata, restitute_data
from pylot.core.util.utils import fnConstructor, getLogin, \
full_range, readFilterInformation, trim_station_components, check4gaps
full_range, readFilterInformation, trim_station_components, check4gaps, make_pen
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, \
@ -1941,16 +1941,7 @@ class MainWindow(QMainWindow):
else:
ax = self.getPlotWidget().axes
ylims = np.array([-.5, +.5]) + plotID
if self.pg:
dashed = QtCore.Qt.DashLine
dotted = QtCore.Qt.DotLine
phase_col = {
'P': (pg.mkPen('c'), pg.mkPen((0, 255, 255, 100), style=dashed), pg.mkPen('b', style=dashed),
pg.mkPen('b', style=dotted)),
'S': (pg.mkPen('m'), pg.mkPen((255, 0, 255, 100), style=dashed), pg.mkPen('r', style=dashed),
pg.mkPen('r', style=dotted))
}
else:
if not self.pg:
phase_col = {
'P': ('c', 'c--', 'b-', 'bv', 'b^', 'b'),
'S': ('m', 'm--', 'r-', 'rv', 'r^', 'r')
@ -1970,7 +1961,8 @@ class MainWindow(QMainWindow):
elif phase[0] == 'S':
quality = getQualityfromUncertainty(picks['spe'], self._inputs['timeerrorsS'])
colors = phase_col[phase[0].upper()]
if not self.pg:
colors = phase_col[phase[0].upper()]
mpp = picks['mpp'] - stime
if picks['epp'] and picks['lpp']:
@ -1987,27 +1979,36 @@ class MainWindow(QMainWindow):
if self.pg:
if picktype == 'manual':
if picks['epp'] and picks['lpp']:
pen = make_pen(picktype, phase[0], 'epp', quality)
pw.plot([epp, epp], ylims,
alpha=.25, pen=colors[0], name='EPP')
alpha=.25, pen=pen, name='EPP')
pen = make_pen(picktype, phase[0], 'lpp', quality)
pw.plot([lpp, lpp], ylims,
alpha=.25, pen=colors[0], name='LPP')
alpha=.25, pen=pen, name='LPP')
if spe:
spe_l = pg.PlotDataItem([mpp - spe, mpp - spe], ylims, pen=colors[1],
name='{}-SPE'.format(phase))
spe_r = pg.PlotDataItem([mpp + spe, mpp + spe], ylims, pen=colors[1])
pw.addItem(spe_l)
pw.addItem(spe_r)
try:
fill = pg.FillBetweenItem(spe_l, spe_r, brush=colors[1].brush())
fb = pw.addItem(fill)
except:
print('Warning: drawPicks: Could not create fill for symmetric pick error.')
pw.plot([mpp, mpp], ylims, pen=colors[2], name='{}-Pick'.format(phase))
# pen = make_pen(picktype, phase[0], 'spe', quality)
# spe_l = pg.PlotDataItem([mpp - spe, mpp - spe], ylims, pen=pen,
# name='{}-SPE'.format(phase))
# spe_r = pg.PlotDataItem([mpp + spe, mpp + spe], ylims, pen=pen)
# pw.addItem(spe_l)
# pw.addItem(spe_r)
# try:
# color = pen.color()
# color.setAlpha(100.)
# brush = pen.brush()
# brush.setColor(color)
# fill = pg.FillBetweenItem(spe_l, spe_r, brush=brush)
# fb = pw.addItem(fill)
# except:
# print('Warning: drawPicks: Could not create fill for symmetric pick error.')
pen = make_pen(picktype, phase[0], 'mpp', quality)
pw.plot([mpp, mpp], ylims, pen=pen, name='{}-Pick'.format(phase))
else:
pw.plot([mpp, mpp], ylims, pen=colors[0], name='{}-Pick (NO PICKERROR)'.format(phase))
pw.plot([mpp, mpp], ylims, pen=pen, name='{}-Pick (NO PICKERROR)'.format(phase))
elif picktype == 'auto':
if quality < 4:
pw.plot([mpp, mpp], ylims, pen=colors[3])
pen = make_pen(picktype, phase[0], 'mpp', quality)
pw.plot([mpp, mpp], ylims, pen=pen)
else:
raise TypeError('Unknown picktype {0}'.format(picktype))
else:

View File

@ -12,6 +12,13 @@ from obspy import UTCDateTime, read
from pylot.core.io.inputs import PylotParameter
from scipy.interpolate import splrep, splev
from PySide import QtCore, QtGui
try:
import pyqtgraph as pg
except Exception as e:
print('QtPyLoT: Could not import pyqtgraph. {}'.format(e))
pg = None
def _pickle_method(m):
if m.im_self is None:
@ -456,6 +463,84 @@ def find_horizontals(data):
return rval
def make_pen(picktype, phase, key, quality):
if pg:
rgba = pick_color(picktype, phase, quality)
linestyle, width = pick_linestyle(picktype, key)
pen = pg.mkPen(rgba, width=width, style=linestyle)
return pen
def pick_color(picktype, phase, quality=0):
min_quality = 3
bpc = base_phase_colors(picktype, phase)
rgba = bpc['rgba']
modifier = bpc['modifier']
intensity = 255.*quality/min_quality
rgba = modify_rgba(rgba, modifier, intensity)
return rgba
def pick_linestyle(picktype, key):
linestyles_manu = {'mpp': (QtCore.Qt.SolidLine, 3.),
'epp': (QtCore.Qt.DashLine, 1.),
'lpp': (QtCore.Qt.DashLine, 1.),
'spe': (QtCore.Qt.DashLine, 1.)}
linestyles_auto = {'mpp': (QtCore.Qt.DotLine, 3.),
'epp': (QtCore.Qt.DashDotDotLine, 1.),
'lpp': (QtCore.Qt.DashDotDotLine, 1.),
'spe': (QtCore.Qt.DashDotDotLine, 1.)}
linestyles = {'manual': linestyles_manu,
'auto': linestyles_auto}
return linestyles[picktype][key]
def modify_rgba(rgba, modifier, intensity):
rgba = list(rgba)
index = {'r': 0,
'g': 1,
'b': 2}
val = rgba[index[modifier]] + intensity
if val > 255.:
val = 255.
elif val < 0.:
val = 0
rgba[index[modifier]] = val
return tuple(rgba)
def base_phase_colors(picktype, phase):
phases = {
'manual':
{
'P':
{
'rgba': (0, 0, 255, 255),
'modifier': 'g'
},
'S':
{
'rgba': (255, 0, 0, 255),
'modifier': 'b'
}
},
'auto':
{
'P':
{
'rgba': (140, 0, 255, 255),
'modifier': 'g'
},
'S':
{
'rgba': (255, 140, 0, 255),
'modifier': 'b'
}
}
}
return phases[picktype][phase]
def remove_underscores(data):
"""
takes a `obspy.core.stream.Stream` object and removes all underscores