[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 return statID
def getStationID(self, station): def getStationIDs(self, station):
wfIDs = []
for wfID in self.getPlotWidget().getPlotDict().keys(): 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: if station == actual_station:
return wfID wfIDs.append(wfID)
return None return wfIDs
def getStime(self): def getStime(self):
if self.get_data(): if self.get_data():
@ -1915,7 +1916,7 @@ class MainWindow(QMainWindow):
plotWidget = self.getPlotWidget() plotWidget = self.getPlotWidget()
plotDict = plotWidget.getPlotDict() plotDict = plotWidget.getPlotDict()
pos = plotDict.keys() 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) plotWidget.setYTickLabels(pos, labels)
try: try:
plotWidget.figure.tight_layout() plotWidget.figure.tight_layout()
@ -2233,15 +2234,19 @@ class MainWindow(QMainWindow):
def getSeismicPhase(self): def getSeismicPhase(self):
return self.seismicPhase return self.seismicPhase
def getTraceID(self, wfID):
plot_dict = self.getPlotWidget().getPlotDict()
return plot_dict.get(wfID)
def getStationName(self, wfID): def getStationName(self, wfID):
plot_dict = self.getPlotWidget().getPlotDict() plot_dict = self.getPlotWidget().getPlotDict()
if wfID in plot_dict.keys(): if wfID in plot_dict.keys():
return plot_dict[wfID][0] return plot_dict[wfID].split('.')[1]
def getNetworkName(self, wfID): def getNetworkName(self, wfID):
plot_dict = self.getPlotWidget().getPlotDict() plot_dict = self.getPlotWidget().getPlotDict()
if wfID in plot_dict.keys(): if wfID in plot_dict.keys():
return plot_dict[wfID][2] return plot_dict[wfID].split('.')[0]
def alterPhase(self): def alterPhase(self):
pass pass
@ -2308,38 +2313,38 @@ class MainWindow(QMainWindow):
network = self.getNetworkName(wfID) network = self.getNetworkName(wfID)
station = self.getStationName(wfID) station = self.getStationName(wfID)
seed_id = self.getTraceID(wfID)
if button == 1: if button == 1:
self.pickDialog(wfID, network, station) self.pickDialog(wfID, seed_id)
elif button == 4: elif button == 4:
self.toggle_station_color(wfID, network, station) 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)) black_pen = pg.mkPen((0, 0, 0))
red_pen = pg.mkPen((200, 50, 50)) red_pen = pg.mkPen((200, 50, 50))
line_item = self.dataPlot.plotWidget.getPlotItem().listDataItems()[wfID - 1] line_item = self.dataPlot.plotWidget.getPlotItem().listDataItems()[wfID - 1]
current_pen = line_item.opts['pen'] current_pen = line_item.opts['pen']
nwst = '{}.{}'.format(network, station) nsl = '{}.{}.{}'.format(network, station, location)
if current_pen == black_pen: if current_pen == black_pen:
line_item.setPen(red_pen) line_item.setPen(red_pen)
if not nwst in self.stations_highlighted: if not nsl in self.stations_highlighted:
self.stations_highlighted.append(nwst) self.stations_highlighted.append(nsl)
else: else:
line_item.setPen(black_pen) line_item.setPen(black_pen)
if nwst in self.stations_highlighted: if nsl in self.stations_highlighted:
self.stations_highlighted.pop(self.stations_highlighted.index(nwst)) self.stations_highlighted.pop(self.stations_highlighted.index(nsl))
def highlight_stations(self): def highlight_stations(self):
for wfID, value in self.getPlotWidget().getPlotDict().items(): for wfID, value in self.getPlotWidget().getPlotDict().items():
station, channel, network = value station, channel, location, network = value.split('.')
nwst = '{}.{}'.format(network, station) nsl = '{}.{}.{}'.format(network, station, location)
if nwst in self.stations_highlighted: if nsl in self.stations_highlighted:
self.toggle_station_color(wfID, network, station) self.toggle_station_color(wfID, network, station, location)
def pickDialog(self, wfID, network=None, station=None): def pickDialog(self, wfID, seed_id=None):
if not network: if not seed_id:
network = self.getNetworkName(wfID) seed_id = self.getTraceID(wfID)
if not station: network, station, location = seed_id.split('.')[:3]
station = self.getStationName(wfID)
if not station or not network: if not station or not network:
return return
self.update_status('picking on station {0}'.format(station)) self.update_status('picking on station {0}'.format(station))
@ -2349,6 +2354,7 @@ class MainWindow(QMainWindow):
pickDlg = PickDlg(self, parameter=self._inputs, pickDlg = PickDlg(self, parameter=self._inputs,
data=data.select(station=station), data=data.select(station=station),
station=station, network=network, station=station, network=network,
location=location,
picks=self.getPicksOnStation(station, 'manual'), picks=self.getPicksOnStation(station, 'manual'),
autopicks=self.getPicksOnStation(station, 'auto'), autopicks=self.getPicksOnStation(station, 'auto'),
metadata=self.metadata, event=event, metadata=self.metadata, event=event,
@ -2714,9 +2720,11 @@ class MainWindow(QMainWindow):
return return
# plotting picks # plotting picks
plotID = self.getStationID(station) plotIDs = self.getStationIDs(station)
if plotID is None: if not plotIDs:
return return
for plotID in plotIDs:
ylims = np.array([-.5, +.5]) + plotID ylims = np.array([-.5, +.5]) + plotID
stat_picks = self.getPicks(type=picktype)[station] stat_picks = self.getPicks(type=picktype)[station]

View File

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