[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

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,9 +2720,11 @@ class MainWindow(QMainWindow):
return
# plotting picks
plotID = self.getStationID(station)
if plotID is None:
plotIDs = self.getStationIDs(station)
if not plotIDs:
return
for plotID in plotIDs:
ylims = np.array([-.5, +.5]) + plotID
stat_picks = self.getPicks(type=picktype)[station]

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):