[bugfix] regard location ID in PyLoT! (WIP)

This commit is contained in:
Marcel Paffrath 2018-08-06 16:03:54 +02:00
parent 34891d3dc1
commit a2af6b44f3
2 changed files with 143 additions and 135 deletions

212
PyLoT.py
View File

@ -1566,12 +1566,13 @@ class MainWindow(QMainWindow):
return statID
def getStationID(self, station):
def getStationIDs(self, station):
wfIDs = []
for wfID in self.getPlotWidget().getPlotDict().keys():
actual_station = self.getPlotWidget().getPlotDict()[wfID][0]
actual_station = self.getPlotWidget().getPlotDict()[wfID].split('.')[1]
if station == actual_station:
return wfID
return None
wfIDs.append(wfID)
return wfIDs
def getStime(self):
if self.get_data():
@ -1915,7 +1916,7 @@ class MainWindow(QMainWindow):
plotWidget = self.getPlotWidget()
plotDict = plotWidget.getPlotDict()
pos = plotDict.keys()
labels = [plotDict[n][2] + '.' + plotDict[n][0] for n in pos]
labels = ['{}.{}'.format(*plotDict[n].split('.')[:-2]) for n in pos]
plotWidget.setYTickLabels(pos, labels)
try:
plotWidget.figure.tight_layout()
@ -2233,15 +2234,19 @@ class MainWindow(QMainWindow):
def getSeismicPhase(self):
return self.seismicPhase
def getTraceID(self, wfID):
plot_dict = self.getPlotWidget().getPlotDict()
return plot_dict.get(wfID)
def getStationName(self, wfID):
plot_dict = self.getPlotWidget().getPlotDict()
if wfID in plot_dict.keys():
return plot_dict[wfID][0]
return plot_dict[wfID].split('.')[1]
def getNetworkName(self, wfID):
plot_dict = self.getPlotWidget().getPlotDict()
if wfID in plot_dict.keys():
return plot_dict[wfID][2]
return plot_dict[wfID].split('.')[0]
def alterPhase(self):
pass
@ -2308,38 +2313,38 @@ class MainWindow(QMainWindow):
network = self.getNetworkName(wfID)
station = self.getStationName(wfID)
seed_id = self.getTraceID(wfID)
if button == 1:
self.pickDialog(wfID, network, station)
self.pickDialog(wfID, seed_id)
elif button == 4:
self.toggle_station_color(wfID, network, station)
def toggle_station_color(self, wfID, network, station):
def toggle_station_color(self, wfID, network, station, location):
black_pen = pg.mkPen((0, 0, 0))
red_pen = pg.mkPen((200, 50, 50))
line_item = self.dataPlot.plotWidget.getPlotItem().listDataItems()[wfID - 1]
current_pen = line_item.opts['pen']
nwst = '{}.{}'.format(network, station)
nsl = '{}.{}.{}'.format(network, station, location)
if current_pen == black_pen:
line_item.setPen(red_pen)
if not nwst in self.stations_highlighted:
self.stations_highlighted.append(nwst)
if not nsl in self.stations_highlighted:
self.stations_highlighted.append(nsl)
else:
line_item.setPen(black_pen)
if nwst in self.stations_highlighted:
self.stations_highlighted.pop(self.stations_highlighted.index(nwst))
if nsl in self.stations_highlighted:
self.stations_highlighted.pop(self.stations_highlighted.index(nsl))
def highlight_stations(self):
for wfID, value in self.getPlotWidget().getPlotDict().items():
station, channel, network = value
nwst = '{}.{}'.format(network, station)
if nwst in self.stations_highlighted:
self.toggle_station_color(wfID, network, station)
station, channel, location, network = value.split('.')
nsl = '{}.{}.{}'.format(network, station, location)
if nsl in self.stations_highlighted:
self.toggle_station_color(wfID, network, station, location)
def pickDialog(self, wfID, network=None, station=None):
if not network:
network = self.getNetworkName(wfID)
if not station:
station = self.getStationName(wfID)
def pickDialog(self, wfID, seed_id=None):
if not seed_id:
seed_id = self.getTraceID(wfID)
network, station, location = seed_id.split('.')[:3]
if not station or not network:
return
self.update_status('picking on station {0}'.format(station))
@ -2349,6 +2354,7 @@ class MainWindow(QMainWindow):
pickDlg = PickDlg(self, parameter=self._inputs,
data=data.select(station=station),
station=station, network=network,
location=location,
picks=self.getPicksOnStation(station, 'manual'),
autopicks=self.getPicksOnStation(station, 'auto'),
metadata=self.metadata, event=event,
@ -2714,93 +2720,95 @@ class MainWindow(QMainWindow):
return
# plotting picks
plotID = self.getStationID(station)
if plotID is None:
plotIDs = self.getStationIDs(station)
if not plotIDs:
return
ylims = np.array([-.5, +.5]) + plotID
stat_picks = self.getPicks(type=picktype)[station]
settings = QSettings()
for plotID in plotIDs:
ylims = np.array([-.5, +.5]) + plotID
for phase in stat_picks:
if phase == 'SPt': continue # wadati SP time
picks = stat_picks[phase]
if type(stat_picks[phase]) is not dict and type(stat_picks[phase]) is not AttribDict:
return
stat_picks = self.getPicks(type=picktype)[station]
settings = QSettings()
phaseID = self.getPhaseID(phase)
# get quality classes
if phaseID == 'P':
quality = getQualityFromUncertainty(picks['spe'], self._inputs['timeerrorsP'])
elif phaseID == 'S':
quality = getQualityFromUncertainty(picks['spe'], self._inputs['timeerrorsS'])
for phase in stat_picks:
if phase == 'SPt': continue # wadati SP time
picks = stat_picks[phase]
if type(stat_picks[phase]) is not dict and type(stat_picks[phase]) is not AttribDict:
return
# quality = getPickQuality(self.get_data().getWFData(),
# stat_picks, self._inputs, phaseID,
# compclass)
phaseID = self.getPhaseID(phase)
# get quality classes
if phaseID == 'P':
quality = getQualityFromUncertainty(picks['spe'], self._inputs['timeerrorsP'])
elif phaseID == 'S':
quality = getQualityFromUncertainty(picks['spe'], self._inputs['timeerrorsS'])
mpp = picks['mpp'] - stime
if picks['epp'] and picks['lpp']:
epp = picks['epp'] - stime
lpp = picks['lpp'] - stime
else:
epp = None
lpp = None
spe = picks['spe']
# quality = getPickQuality(self.get_data().getWFData(),
# stat_picks, self._inputs, phaseID,
# compclass)
if self.pg:
if spe:
if picks['epp'] and picks['lpp']:
pen = make_pen(picktype, phaseID, 'epp', quality)
self.drawnPicks[picktype][station].append(pw.plot([epp, epp], ylims,
alpha=.25, pen=pen, name='EPP'))
pen = make_pen(picktype, phaseID, 'lpp', quality)
self.drawnPicks[picktype][station].append(pw.plot([lpp, lpp], ylims,
alpha=.25, pen=pen, name='LPP'))
pen = make_pen(picktype, phaseID, '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)
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)
self.drawnPicks[picktype][station].append(fill)
except:
print('Warning: drawPicks: Could not create fill for symmetric pick error.')
pen = make_pen(picktype, phaseID, 'mpp', quality)
self.drawnPicks[picktype][station].append(
pw.plot([mpp, mpp], ylims, pen=pen, name='{}-Pick'.format(phase)))
else:
if picktype == 'manual':
linestyle_mpp, width_mpp = pick_linestyle_plt(picktype, 'mpp')
color = pick_color_plt(picktype, self.getPhaseID(phase), quality)
if picks['epp'] and picks['lpp']:
ax.fill_between([epp, lpp], ylims[0], ylims[1],
alpha=.25, color=color, label='EPP, LPP')
if spe:
linestyle_spe, width_spe = pick_linestyle_plt(picktype, 'spe')
ax.plot([mpp - spe, mpp - spe], ylims, color=color, linestyle=linestyle_spe,
linewidth=width_spe, label='{}-SPE'.format(phase))
ax.plot([mpp + spe, mpp + spe], ylims, color=color, linestyle=linestyle_spe,
linewidth=width_spe)
ax.plot([mpp, mpp], ylims, color=color, linestyle=linestyle_mpp, linewidth=width_mpp,
label='{}-Pick (quality: {})'.format(phase, quality), picker=5)
else:
ax.plot([mpp, mpp], ylims, color=color, linestyle=linestyle_mpp, linewidth=width_mpp,
label='{}-Pick (NO PICKERROR)'.format(phase), picker=5)
elif picktype == 'auto':
color = pick_color_plt(picktype, phase, quality)
linestyle_mpp, width_mpp = pick_linestyle_plt(picktype, 'mpp')
ax.plot(mpp, ylims[1], color=color, marker='v')
ax.plot(mpp, ylims[0], color=color, marker='^')
ax.vlines(mpp, ylims[0], ylims[1], color=color, linestyle=linestyle_mpp, linewidth=width_mpp,
picker=5, label='{}-Autopick (quality: {})'.format(phase, quality))
mpp = picks['mpp'] - stime
if picks['epp'] and picks['lpp']:
epp = picks['epp'] - stime
lpp = picks['lpp'] - stime
else:
raise TypeError('Unknown picktype {0}'.format(picktype))
epp = None
lpp = None
spe = picks['spe']
if self.pg:
if spe:
if picks['epp'] and picks['lpp']:
pen = make_pen(picktype, phaseID, 'epp', quality)
self.drawnPicks[picktype][station].append(pw.plot([epp, epp], ylims,
alpha=.25, pen=pen, name='EPP'))
pen = make_pen(picktype, phaseID, 'lpp', quality)
self.drawnPicks[picktype][station].append(pw.plot([lpp, lpp], ylims,
alpha=.25, pen=pen, name='LPP'))
pen = make_pen(picktype, phaseID, '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)
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)
self.drawnPicks[picktype][station].append(fill)
except:
print('Warning: drawPicks: Could not create fill for symmetric pick error.')
pen = make_pen(picktype, phaseID, 'mpp', quality)
self.drawnPicks[picktype][station].append(
pw.plot([mpp, mpp], ylims, pen=pen, name='{}-Pick'.format(phase)))
else:
if picktype == 'manual':
linestyle_mpp, width_mpp = pick_linestyle_plt(picktype, 'mpp')
color = pick_color_plt(picktype, self.getPhaseID(phase), quality)
if picks['epp'] and picks['lpp']:
ax.fill_between([epp, lpp], ylims[0], ylims[1],
alpha=.25, color=color, label='EPP, LPP')
if spe:
linestyle_spe, width_spe = pick_linestyle_plt(picktype, 'spe')
ax.plot([mpp - spe, mpp - spe], ylims, color=color, linestyle=linestyle_spe,
linewidth=width_spe, label='{}-SPE'.format(phase))
ax.plot([mpp + spe, mpp + spe], ylims, color=color, linestyle=linestyle_spe,
linewidth=width_spe)
ax.plot([mpp, mpp], ylims, color=color, linestyle=linestyle_mpp, linewidth=width_mpp,
label='{}-Pick (quality: {})'.format(phase, quality), picker=5)
else:
ax.plot([mpp, mpp], ylims, color=color, linestyle=linestyle_mpp, linewidth=width_mpp,
label='{}-Pick (NO PICKERROR)'.format(phase), picker=5)
elif picktype == 'auto':
color = pick_color_plt(picktype, phase, quality)
linestyle_mpp, width_mpp = pick_linestyle_plt(picktype, 'mpp')
ax.plot(mpp, ylims[1], color=color, marker='v')
ax.plot(mpp, ylims[0], color=color, marker='^')
ax.vlines(mpp, ylims[0], ylims[1], color=color, linestyle=linestyle_mpp, linewidth=width_mpp,
picker=5, label='{}-Autopick (quality: {})'.format(phase, quality))
else:
raise TypeError('Unknown picktype {0}'.format(picktype))
def locate_event(self):
"""

View File

@ -631,7 +631,7 @@ class WaveformWidgetPG(QtGui.QWidget):
x, y, = (mousePoint.x(), mousePoint.y())
# if x > 0:# and index < len(data1):
wfID = self.orig_parent.getWFID(y)
station = self.orig_parent.getStationName(wfID)
station = self.orig_parent.getTraceID(wfID)
abstime = self.wfstart + x
if self.orig_parent.get_current_event():
self.status_label.setText("station = {}, T = {}, t = {} [s]".format(station, abstime, x))
@ -737,26 +737,27 @@ class WaveformWidgetPG(QtGui.QWidget):
st_select, gaps = merge_stream(st_select)
# list containing tuples of network, station, channel (for sorting)
nsc = []
nslc = []
for trace in st_select:
nsc.append((trace.stats.network, trace.stats.station, trace.stats.channel))
nsc.sort()
nsc.reverse()
nslc.append(trace.get_id())#(trace.stats.network, trace.stats.station, trace.stats.location trace.stats.channel))
nslc.sort()
nslc.reverse()
plots = []
try:
self.plotWidget.getPlotItem().vb.setLimits(xMin=float(0),
xMax=float(self.wfend - self.wfstart),
yMin=.5,
yMax=len(nsc) + .5)
yMax=len(nslc) + .5)
except:
print('Warning: Could not set zoom limits')
for n, (network, station, channel) in enumerate(nsc):
for n, seed_id in enumerate(nslc):
n += 1
st = st_select.select(network=network, station=station, channel=channel)
network, station, location, channel = seed_id.split('.')
st = st_select.select(id=seed_id)
trace = st[0].copy()
st_syn = wfsyn.select(network=network, station=station, channel=channel)
st_syn = wfsyn.select(id=seed_id)
if st_syn:
trace_syn = st_syn[0].copy()
else:
@ -797,7 +798,7 @@ class WaveformWidgetPG(QtGui.QWidget):
if not index % nth_sample] if st_syn else [])
plots.append((times, trace.data,
times_syn, trace_syn.data))
self.setPlotDict(n, (station, channel, network))
self.setPlotDict(n, seed_id)
self.xlabel = 'seconds since {0}'.format(self.wfstart)
self.ylabel = ''
self.setXLims([0, self.wfend - self.wfstart])
@ -1237,20 +1238,21 @@ class PylotCanvas(FigureCanvas):
print(merged_station)
# list containing tuples of network, station, channel and plot position (for sorting)
nsc = []
nslc = []
for plot_pos, trace in enumerate(st_select):
if not trace.stats.channel[-1] in ['Z', 'N', 'E', '1', '2', '3']:
print('Warning: Unrecognized channel {}'.format(trace.stats.channel))
continue
nsc.append((trace.stats.network, trace.stats.station, trace.stats.channel))
nsc.sort()
nsc.reverse()
nslc.append(trace.get_id())
nslc.sort()
nslc.reverse()
style = self.orig_parent._style
linecolor = style['linecolor']['rgba_mpl']
for n, (network, station, channel) in enumerate(nsc):
st = st_select.select(network=network, station=station, channel=channel)
for n, seed_id in enumerate(nslc):
network, station, location, channel = seed_id.split('.')
st = st_select.select(id=seed_id)
trace = st[0].copy()
if mapping:
n = plot_positions[trace.stats.channel]
@ -1283,7 +1285,7 @@ class PylotCanvas(FigureCanvas):
[n + level, n + level],
color=linecolor,
linestyle='dashed')
self.setPlotDict(n, (station, channel, network))
self.setPlotDict(n, seed_id)
if plot_additional and additional_channel:
compare_stream = wfdata.select(channel=additional_channel)
if compare_stream:
@ -1471,7 +1473,7 @@ class PhaseDefaults(QtGui.QDialog):
class PickDlg(QDialog):
update_picks = QtCore.Signal(dict)
def __init__(self, parent=None, data=None, station=None, network=None, picks=None,
def __init__(self, parent=None, data=None, station=None, network=None, location=None, picks=None,
autopicks=None, rotate=False, parameter=None, embedded=False, metadata=None,
event=None, filteroptions=None, model='iasp91', wftype=None):
super(PickDlg, self).__init__(parent, 1)
@ -1483,6 +1485,7 @@ class PickDlg(QDialog):
self._embedded = embedded
self.station = station
self.network = network
self.location = location
self.rotate = rotate
self.metadata = metadata
self.wftype = wftype
@ -2127,22 +2130,21 @@ class PickDlg(QDialog):
return self.components
def getStation(self):
if self.network and self.station:
return self.network + '.' + self.station
return self.station
return self.network + '.' + self.station + '.' + self.location
def getChannelID(self, key):
if key < 0: key = 0
return self.multicompfig.getPlotDict()[int(key)][1]
return self.multicompfig.getPlotDict()[int(key)].split('.')[-1]
def getTraceID(self, channels):
plotDict = self.multicompfig.getPlotDict()
traceIDs = []
for channel in channels:
channel = channel.upper()
for traceID, channelID in plotDict.items():
for seed_id in plotDict.items():
channelID = seed_id.split('.')[-1]
if channelID[1].upper().endswith(channel):
traceIDs.append(traceID)
traceIDs.append(seed_id)
return traceIDs
def getUser(self):
@ -2845,10 +2847,9 @@ class PickDlg(QDialog):
self.multicompfig.connectEvents()
def setPlotLabels(self):
# get channel labels
pos = self.multicompfig.getPlotDict().keys()
labels = [self.multicompfig.getPlotDict()[key][1] for key in pos]
labels = [self.multicompfig.getPlotDict()[key].split('.')[-1] for key in pos]
ax = self.multicompfig.figure.axes[0]
@ -3300,10 +3301,7 @@ class TuneAutopicker(QWidget):
print('Warning: Could not read file {} as a stream object: {}'.format(filename, e))
continue
for trace in st:
network = trace.stats.network
station = trace.stats.station
location = trace.stats.location
station_id = '{}.{}.{}'.format(network, station, location)
station_id = trace.get_id()
if not station_id in self.station_ids:
self.station_ids[station_id] = []
self.station_ids[station_id].append(filename)
@ -3417,14 +3415,15 @@ class TuneAutopicker(QWidget):
self.pdlg_widget = None
return
self.load_wf_data()
station = self.get_current_station()
network, station, location, channel = self.get_current_station_id()
wfdata = self.data.getWFData()
metadata = self.parent().metadata
event = self.get_current_event()
filteroptions = self.parent().filteroptions
wftype = self.wftype if self.obspy_dmt else ''
self.pickDlg = PickDlg(self.parent(), data=wfdata.select(station=station).copy(),
station=station, parameter=self.parameter,
station=station, network=network,
location=location, parameter=self.parameter,
picks=self.get_current_event_picks(station),
autopicks=self.get_current_event_autopicks(station),
metadata=metadata, event=event, filteroptions=filteroptions,
@ -3441,6 +3440,7 @@ class TuneAutopicker(QWidget):
hl.addWidget(self.pickDlg)
def picks_from_pickdlg(self, picks=None):
seed_id = self.get_current_station_id()
station = self.get_current_station()
replot = self.parent().addPicks(station, picks)
self.get_current_event().setPick(station, picks)
@ -3449,7 +3449,7 @@ class TuneAutopicker(QWidget):
self.parent().plotWaveformDataThread()
self.parent().drawPicks()
else:
self.parent().drawPicks(station)
self.parent().drawPicks(seed_id)
self.parent().draw()
def clear_plotitem(self, plotitem):