diff --git a/QtPyLoT.py b/QtPyLoT.py index d1e6cf35..0d209017 100755 --- a/QtPyLoT.py +++ b/QtPyLoT.py @@ -912,6 +912,7 @@ class MainWindow(QMainWindow): self.refreshTabs() def refreshTabs(self): + plotted=False if self._eventChanged[0] or self._eventChanged[1]: event = self.getCurrentEvent() if not event.picks: @@ -927,20 +928,25 @@ class MainWindow(QMainWindow): if len(self.project.eventlist) > 0: if self._eventChanged[0]: self.newWFplot() + plotted=True if self.tabs.currentIndex() == 1: if self._eventChanged[1]: self.refresh_array_map() + if not plotted and self._eventChanged[0]: + self.newWFplot(False) if self.tabs.currentIndex() == 2: self.init_event_table() - def newWFplot(self): - self.loadWaveformDataThread() - self._eventChanged[0] = False + def newWFplot(self, plot=True): + self.loadWaveformDataThread(plot) + if plot: + self._eventChanged[0] = False - def loadWaveformDataThread(self): + def loadWaveformDataThread(self, plot=True): wfd_thread = Thread(self, self.loadWaveformData, progressText='Reading data input...') - wfd_thread.finished.connect(self.plotWaveformDataThread) + if plot: + wfd_thread.finished.connect(self.plotWaveformDataThread) wfd_thread.start() def loadWaveformData(self): @@ -1845,12 +1851,6 @@ class Event(object): self._testEvent = False self._refEvent = False - def addPicks(self, picks): - self.picks = picks - - def addAutopicks(self, autopicks): - self.autopicks = autopicks - def addNotes(self, notes): self.notes = notes @@ -1871,26 +1871,38 @@ class Event(object): self._testEvent = bool if bool: self._refEvent = False + def addPicks(self, picks): + for station in picks: + self.picks[station] = picks[station] + + def addAutopicks(self, autopicks): + for station in autopicks: + self.autopicks[station] = autopicks[station] + def setPick(self, station, pick): - self.picks[station] = pick + if pick: + self.picks[station] = pick def setPicks(self, picks): self.picks = picks def getPick(self, station): - return self.picks[station] + if station in self.picks.keys(): + return self.picks[station] def getPicks(self): return self.picks def setAutopick(self, station, autopick): - self.autopicks[station] = autopick + if autopick: + self.autopicks[station] = autopick def setAutopicks(self, autopicks): self.autopicks = autopicks def getAutopick(self, station): - return self.autopicks[station] + if station in self.autopicks.keys(): + return self.autopicks[station] def getAutopicks(self): return self.autopicks diff --git a/pylot/RELEASE-VERSION b/pylot/RELEASE-VERSION index 1834d1e2..9b24c362 100644 --- a/pylot/RELEASE-VERSION +++ b/pylot/RELEASE-VERSION @@ -1 +1 @@ -ba58-dirty +55bc-dirty diff --git a/pylot/core/util/map_projection.py b/pylot/core/util/map_projection.py index 6f506b8d..1c6e06cf 100644 --- a/pylot/core/util/map_projection.py +++ b/pylot/core/util/map_projection.py @@ -50,22 +50,29 @@ class map_projection(QtGui.QWidget): station=station, picks=self._parent.getCurrentEvent().getPick(station), autopicks=self._parent.getCurrentEvent().getAutopick(station)) - pyl_mw = self._parent - if pickDlg.exec_(): - pyl_mw.setDirty(True) - pyl_mw.update_status('picks accepted ({0})'.format(station)) - replot = pyl_mw.getCurrentEvent().setPick(station, pickDlg.getPicks()) - if replot: - pyl_mw.plotWaveformData() - pyl_mw.drawPicks() - pyl_mw.draw() - else: - pyl_mw.drawPicks(station) - pyl_mw.draw() - else: - pyl_mw.update_status('picks discarded ({0})'.format(station)) except Exception as e: - print('Could not generate Plot for station {st}.\n{er}'.format(st=station, er=e)) + message = 'Could not generate Plot for station {st}.\n{er}'.format(st=station, er=e) + self._warn(message) + print(message, e) + pyl_mw = self._parent + #try: + if pickDlg.exec_(): + pyl_mw.setDirty(True) + pyl_mw.update_status('picks accepted ({0})'.format(station)) + replot = pyl_mw.getCurrentEvent().setPick(station, pickDlg.getPicks()) + if replot: + pyl_mw.plotWaveformData() + pyl_mw.drawPicks() + pyl_mw.draw() + else: + pyl_mw.drawPicks(station) + pyl_mw.draw() + else: + pyl_mw.update_status('picks discarded ({0})'.format(station)) + # except Exception as e: + # message = 'Could not save picks for station {st}.\n{er}'.format(st=station, er=e) + # self._warn(message) + # print(message, e) def connectSignals(self): self.comboBox_phase.currentIndexChanged.connect(self._refresh_drawings) @@ -92,9 +99,9 @@ class map_projection(QtGui.QWidget): self.comboBox_phase.insertItem(0, 'P') self.comboBox_phase.insertItem(1, 'S') - # self.comboBox_am = QtGui.QComboBox() - # self.comboBox_am.insertItem(0, 'auto') - # self.comboBox_am.insertItem(1, 'manual') + self.comboBox_am = QtGui.QComboBox() + self.comboBox_am.insertItem(0, 'auto') + self.comboBox_am.insertItem(1, 'manual') self.top_row.addWidget(QtGui.QLabel('Select a phase: ')) self.top_row.addWidget(self.comboBox_phase) @@ -134,9 +141,13 @@ class map_projection(QtGui.QWidget): def get_picks_rel(picks): picks_rel=[] - minp = min(picks) + picks_utc = [] for pick in picks: if type(pick) is obspy.core.utcdatetime.UTCDateTime: + picks_utc.append(pick) + minp = min(picks_utc) + for pick in picks: + if type(pick) is obspy.core.utcdatetime.UTCDateTime: pick -= minp picks_rel.append(pick) return picks_rel @@ -148,9 +159,8 @@ class map_projection(QtGui.QWidget): def remove_nan_picks(picks): picks_no_nan=[] for pick in picks: - if pick: - if not np.isnan(pick): - picks_no_nan.append(pick) + if not np.isnan(pick): + picks_no_nan.append(pick) return picks_no_nan self.picks_no_nan = remove_nan_picks(self.picks_rel) @@ -225,8 +235,19 @@ class map_projection(QtGui.QWidget): self.cid = self.canvas.mpl_connect('pick_event', self.onpick) def scatter_picked_stations(self): - self.sc_picked = self.basemap.scatter(self.lon_no_nan, self.lat_no_nan, s=50, facecolor='white', - c=self.picks_no_nan, latlon=True, zorder=11, label='Picked') + lon = self.lon_no_nan + lat = self.lat_no_nan + + #workaround because of an issue with latlon transformation of arrays with len <3 + if len(lon) <= 2 and len(lat) <= 2: + self.sc_picked = self.basemap.scatter(lon[0], lat[0], s=50, facecolor='white', + c=self.picks_no_nan[0], latlon=True, zorder=11, label='Picked') + if len(lon) == 2 and len(lat) == 2: + self.sc_picked = self.basemap.scatter(lon[1], lat[1], s=50, facecolor='white', + c=self.picks_no_nan[1], latlon=True, zorder=11) + else: + self.sc_picked = self.basemap.scatter(lon, lat, s=50, facecolor='white', + c=self.picks_no_nan, latlon=True, zorder=11, label='Picked') def annotate_ax(self): self.annotations=[] @@ -254,8 +275,9 @@ class map_projection(QtGui.QWidget): self.init_picks() self.init_picks_active() self.init_stations_active() - self.init_picksgrid() - self.draw_contour_filled() + if len(self.picks_no_nan) >= 3: + self.init_picksgrid() + self.draw_contour_filled() self.scatter_all_stations() if self.picks_dict: self.scatter_picked_stations() @@ -297,4 +319,9 @@ class map_projection(QtGui.QWidget): for annotation in self.annotations: annotation.remove() + def _warn(self, message): + self.qmb = QtGui.QMessageBox(QtGui.QMessageBox.Icon.Warning, + 'Warning', message) + self.qmb.show() + diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index d062ac60..f588230a 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -693,6 +693,7 @@ class PickDlg(QDialog): # finally layout the entire dialog self.setLayout(_outerlayout) + self.resize(1280, 720) def disconnectPressEvent(self): widget = self.getPlotWidget() @@ -1390,8 +1391,12 @@ class TuneAutopicker(QWidget): if not station in stations: stations.append(str(station)) stations.sort() + model = self.stationBox.model() for station in stations: - self.stationBox.addItem(str(station)) + item = QtGui.QStandardItem(str(station)) + if station in self.get_current_event().picks: + item.setBackground(QtGui.QColor(200, 210, 230, 255)) + model.appendRow(item) def init_figure_tabs(self): self.figure_tabs = QtGui.QTabWidget() @@ -1415,8 +1420,11 @@ class TuneAutopicker(QWidget): def add_buttons(self): self.pick_button = QtGui.QPushButton('Pick Trace') self.pick_button.clicked.connect(self.call_picker) + self.close_button = QtGui.QPushButton('Close') + self.close_button.clicked.connect(self.hide) self.trace_layout.addWidget(self.pick_button) self.trace_layout.setStretch(0, 1) + self.parameter_layout.addWidget(self.close_button) def add_log(self): self.listWidget = QtGui.QListWidget() @@ -1467,7 +1475,8 @@ class TuneAutopicker(QWidget): embedded=True) pickDlg.update_picks.connect(self.picks_from_pickdlg) pickDlg.update_picks.connect(self.parent.fill_eventbox) - pickDlg.update_picks.connect(self.fill_eventbox) + pickDlg.update_picks.connect(self.fill_eventbox) + pickDlg.update_picks.connect(self.fill_stationbox) self.pickDlg = QtGui.QWidget() hl = QtGui.QHBoxLayout() self.pickDlg.setLayout(hl)