2014-03-13 13:27:34 +01:00
|
|
|
#!/usr/bin/env python
|
2014-03-31 12:57:08 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
PyLoT: Main program
|
|
|
|
===================
|
|
|
|
PyLoT is a seismic data processing software capable of picking seismic
|
|
|
|
phases (symmetric and asymmetric error assignment), exporting these to
|
|
|
|
several common phase data formats and post process the data, e.g. locating
|
|
|
|
events, via external localization software.
|
|
|
|
Additionally PyLoT is meant as an interface to autoPyLoT which can
|
|
|
|
automatically pick seismic phases, if the parameters have properly been
|
|
|
|
chosen for the particular data set.
|
|
|
|
|
2014-11-28 09:19:16 +01:00
|
|
|
Some icons are out of a free of charge icon set, which can be found here:
|
|
|
|
https://www.iconfinder.com/iconsets/flavour
|
|
|
|
|
2017-04-10 09:50:53 +02:00
|
|
|
:authors:
|
2017-04-27 10:42:31 +02:00
|
|
|
Sebastian Wehling-Benatelli / Ludger Küperkoch / Marcel Paffrath
|
2014-03-31 12:57:08 +02:00
|
|
|
:copyright:
|
|
|
|
The PyLoT Development Team (https://ariadne.geophysik.rub.de/trac/PyLoT)
|
|
|
|
:license:
|
|
|
|
GNU Lesser General Public License, Version 3
|
|
|
|
(http://www.gnu.org/copyleft/lesser.html)
|
|
|
|
"""
|
2020-07-30 13:55:56 +02:00
|
|
|
|
2017-08-03 09:41:54 +02:00
|
|
|
import argparse
|
2018-08-16 17:34:05 +02:00
|
|
|
import matplotlib
|
2016-01-29 07:21:17 +01:00
|
|
|
import os
|
2017-07-14 16:25:59 +02:00
|
|
|
import platform
|
2019-06-24 15:02:07 +02:00
|
|
|
import shutil
|
2017-08-03 09:41:54 +02:00
|
|
|
import sys
|
|
|
|
|
2020-01-14 13:57:12 +01:00
|
|
|
import traceback
|
|
|
|
|
2019-05-29 15:58:37 +02:00
|
|
|
import json
|
|
|
|
from datetime import datetime
|
|
|
|
|
2021-03-30 08:28:31 +02:00
|
|
|
matplotlib.use('Qt5Agg')
|
2018-07-24 15:20:00 +02:00
|
|
|
matplotlib.rcParams['savefig.dpi'] = 300
|
|
|
|
|
2021-03-30 08:28:31 +02:00
|
|
|
from PySide2 import QtGui, QtCore, QtWidgets
|
|
|
|
from PySide2.QtCore import QCoreApplication, QSettings, Signal, QFile, \
|
2017-04-06 13:16:28 +02:00
|
|
|
QFileInfo, Qt, QSize
|
2021-03-30 08:28:31 +02:00
|
|
|
from PySide2.QtGui import QIcon, QKeySequence, QPixmap
|
|
|
|
from PySide2.QtWidgets import QMainWindow, QInputDialog, QFileDialog, \
|
|
|
|
QWidget, QHBoxLayout, QVBoxLayout, QStyle, QLabel, QFrame, QAction, \
|
|
|
|
QDialog, QErrorMessage, QApplication, QMessageBox, QSplashScreen, \
|
|
|
|
QActionGroup, QListWidget, QLineEdit, QListView, QAbstractItemView, \
|
2017-04-19 15:31:08 +02:00
|
|
|
QTreeView, QComboBox, QTabWidget, QPushButton, QGridLayout
|
2015-07-07 10:39:51 +02:00
|
|
|
import numpy as np
|
2019-10-24 10:12:00 +02:00
|
|
|
from obspy import UTCDateTime, Stream
|
2017-07-14 16:25:59 +02:00
|
|
|
from obspy.core.event import Magnitude, Origin
|
2017-06-23 14:56:56 +02:00
|
|
|
from obspy.core.util import AttribDict
|
2015-02-16 10:24:17 +01:00
|
|
|
|
2018-04-04 14:57:54 +02:00
|
|
|
from pylot.core.util.obspyDMT_interface import check_obspydmt_structure
|
|
|
|
|
2018-07-17 10:06:03 +02:00
|
|
|
import pyqtgraph as pg
|
2017-06-07 17:05:48 +02:00
|
|
|
|
2017-05-11 17:15:20 +02:00
|
|
|
try:
|
2021-03-30 08:28:31 +02:00
|
|
|
from matplotlib.backends.backend_qt5agg import FigureCanvas
|
2017-05-11 17:15:20 +02:00
|
|
|
except ImportError:
|
2021-03-30 08:28:31 +02:00
|
|
|
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
|
|
|
|
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
|
2017-05-11 17:15:20 +02:00
|
|
|
from matplotlib.figure import Figure
|
|
|
|
|
2017-06-21 15:41:12 +02:00
|
|
|
from pylot.core.analysis.magnitude import LocalMagnitude, MomentMagnitude
|
2016-05-01 21:10:30 +02:00
|
|
|
from pylot.core.io.data import Data
|
2017-06-22 11:18:55 +02:00
|
|
|
from pylot.core.io.inputs import FilterOptions, PylotParameter
|
2017-04-06 13:16:28 +02:00
|
|
|
from autoPyLoT import autoPyLoT
|
2016-06-07 13:51:03 +02:00
|
|
|
from pylot.core.pick.compare import Comparison
|
2018-08-03 11:55:13 +02:00
|
|
|
from pylot.core.pick.utils import symmetrize_error, getQualityFromUncertainty, getPickQuality, get_quality_class
|
2019-12-17 13:50:54 +01:00
|
|
|
from pylot.core.io.phases import picksdict_from_picks, picks_from_picksdict
|
2016-08-25 13:31:51 +02:00
|
|
|
import pylot.core.loc.nll as nll
|
2017-09-18 10:41:27 +02:00
|
|
|
from pylot.core.util.errors import DatastructureError, \
|
2017-08-03 09:41:54 +02:00
|
|
|
OverwriteError
|
2015-07-10 09:22:58 +02:00
|
|
|
from pylot.core.util.connection import checkurl
|
2018-07-17 16:04:20 +02:00
|
|
|
from pylot.core.util.dataprocessing import Metadata, restitute_data
|
2017-06-26 12:19:06 +02:00
|
|
|
from pylot.core.util.utils import fnConstructor, getLogin, \
|
2020-01-14 14:03:13 +01:00
|
|
|
full_range, readFilterInformation, pick_color_plt, \
|
2018-08-16 17:34:05 +02:00
|
|
|
pick_linestyle_plt, identifyPhaseID, excludeQualityClasses, \
|
|
|
|
transform_colors_mpl, transform_colors_mpl_str, getAutoFilteroptions, check_all_obspy, \
|
2019-12-17 16:24:32 +01:00
|
|
|
check_all_pylot, get_Bool, get_None, SetChannelComponents
|
2020-01-14 14:03:13 +01:00
|
|
|
from pylot.core.util.gui import make_pen
|
2017-06-26 12:19:06 +02:00
|
|
|
from pylot.core.util.event import Event
|
2016-05-20 14:46:10 +02:00
|
|
|
from pylot.core.io.location import create_creation_info, create_event
|
2016-01-29 07:21:17 +01:00
|
|
|
from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \
|
2017-08-23 14:45:46 +02:00
|
|
|
PylotCanvas, WaveformWidgetPG, PropertiesDlg, HelpForm, createAction, PickDlg, \
|
2018-08-16 17:34:05 +02:00
|
|
|
ComparisonWidget, TuneAutopicker, PylotParaBox, AutoPickDlg, CanvasWidget, AutoPickWidget, \
|
2019-07-01 17:24:06 +02:00
|
|
|
CompareEventsWidget, ProgressBarWidget, AddMetadataWidget, SingleTextLineDialog
|
2021-03-30 08:28:31 +02:00
|
|
|
#from pylot.core.util.array_map import Array_map
|
2015-02-13 11:12:47 +01:00
|
|
|
from pylot.core.util.structure import DATASTRUCTURE
|
2017-08-03 09:41:54 +02:00
|
|
|
from pylot.core.util.thread import Thread, Worker
|
2015-07-10 09:22:58 +02:00
|
|
|
from pylot.core.util.version import get_git_version as _getVersionString
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-09-07 16:07:43 +02:00
|
|
|
from pylot.styles import style_settings
|
|
|
|
|
2017-07-14 09:51:43 +02:00
|
|
|
if sys.version_info.major == 3:
|
|
|
|
import icons_rc_3 as icons_rc
|
|
|
|
elif sys.version_info.major == 2:
|
|
|
|
import icons_rc_2 as icons_rc
|
|
|
|
else:
|
|
|
|
raise ImportError('Could not determine python version.')
|
2015-02-16 10:24:17 +01:00
|
|
|
|
2018-08-16 17:34:05 +02:00
|
|
|
# workaround to prevent PyCharm from deleting icons_rc import when optimizing imports
|
|
|
|
icons_rc = icons_rc
|
|
|
|
|
2016-08-25 13:31:51 +02:00
|
|
|
locateTool = dict(nll=nll)
|
2015-06-11 10:07:21 +02:00
|
|
|
|
2016-01-29 07:21:17 +01:00
|
|
|
|
2014-01-10 05:45:03 +01:00
|
|
|
class MainWindow(QMainWindow):
|
2015-09-18 09:54:29 +02:00
|
|
|
__version__ = _getVersionString()
|
2014-12-08 10:26:14 +01:00
|
|
|
closing = Signal()
|
|
|
|
|
2020-07-16 12:35:18 +02:00
|
|
|
def __init__(self, parent=None, infile=None, reset_qsettings=False):
|
2014-01-10 05:45:03 +01:00
|
|
|
super(MainWindow, self).__init__(parent)
|
2014-03-13 13:27:34 +01:00
|
|
|
|
2018-07-10 13:56:17 +02:00
|
|
|
self.init_config_files(infile)
|
|
|
|
|
2017-05-30 10:17:07 +02:00
|
|
|
self._props = None
|
2017-04-10 14:54:47 +02:00
|
|
|
|
2019-04-04 11:48:44 +02:00
|
|
|
self.gain = 1.
|
|
|
|
|
2017-06-21 13:24:45 +02:00
|
|
|
self.dirty = False
|
2017-04-20 12:05:34 +02:00
|
|
|
self.project = Project()
|
2017-06-21 13:24:45 +02:00
|
|
|
self.project.parameter = self._inputs
|
2017-05-11 17:15:20 +02:00
|
|
|
self.tap = None
|
2017-09-18 14:44:18 +02:00
|
|
|
self.apw = None
|
2017-05-31 17:12:34 +02:00
|
|
|
self.paraBox = None
|
2017-04-18 17:17:46 +02:00
|
|
|
self.array_map = None
|
2018-08-06 09:19:30 +02:00
|
|
|
self._metadata = Metadata(verbosity=0)
|
2017-04-20 17:06:36 +02:00
|
|
|
self._eventChanged = [False, False]
|
2017-08-03 11:10:26 +02:00
|
|
|
self.apd_local = None
|
|
|
|
self.apd_sge = None
|
2018-04-20 14:53:15 +02:00
|
|
|
self.stations_highlighted = []
|
2018-06-19 10:35:34 +02:00
|
|
|
self.obspy_dmt = False
|
2018-06-21 14:23:52 +02:00
|
|
|
self.nextStation = False
|
2017-04-18 17:17:46 +02:00
|
|
|
|
2017-04-19 15:31:08 +02:00
|
|
|
self.poS_id = None
|
|
|
|
self.ae_id = None
|
2017-05-22 10:53:20 +02:00
|
|
|
self.scroll_id = None
|
2017-07-14 16:25:59 +02:00
|
|
|
self._ctrl = False # control key pressed
|
|
|
|
self._shift = False # shift key pressed
|
2017-04-19 15:31:08 +02:00
|
|
|
|
2018-07-17 09:42:13 +02:00
|
|
|
self.drawnPicks = {'auto': {},
|
|
|
|
'manual': {}}
|
|
|
|
|
2017-05-29 16:21:36 +02:00
|
|
|
# default factor for dataplot e.g. enabling/disabling scrollarea
|
|
|
|
self.height_factor = 12
|
2018-04-19 13:38:17 +02:00
|
|
|
self.plot_method = 'normal'
|
2017-05-29 16:21:36 +02:00
|
|
|
|
2017-04-10 14:24:39 +02:00
|
|
|
# UI has to be set up before(!) children widgets are about to show up
|
2015-03-04 11:52:04 +01:00
|
|
|
self.createAction = createAction
|
2016-09-08 14:02:21 +02:00
|
|
|
# read settings
|
2014-11-28 11:15:49 +01:00
|
|
|
settings = QSettings()
|
2020-07-16 12:35:18 +02:00
|
|
|
if reset_qsettings:
|
|
|
|
settings.clear()
|
2017-04-10 14:24:39 +02:00
|
|
|
self.recentfiles = settings.value("data/recentEvents", [])
|
|
|
|
self.dispComponent = str(settings.value("plotting/dispComponent", "Z"))
|
2017-04-19 15:31:08 +02:00
|
|
|
|
|
|
|
# initialize event data
|
|
|
|
if self.recentfiles:
|
|
|
|
lastEvent = self.getLastEvent()
|
|
|
|
self.data = Data(self, lastEvent)
|
|
|
|
else:
|
|
|
|
self.data = Data(self)
|
2017-06-26 17:41:08 +02:00
|
|
|
self.data._new = False
|
2017-04-19 15:31:08 +02:00
|
|
|
self.autodata = Data(self)
|
|
|
|
|
2018-08-16 16:21:28 +02:00
|
|
|
self.fnames = None
|
|
|
|
self._stime = None
|
|
|
|
|
2019-05-29 15:58:37 +02:00
|
|
|
# track deleted picks for logging
|
|
|
|
self.deleted_picks = {}
|
|
|
|
|
2019-07-01 17:24:06 +02:00
|
|
|
# headers for event table
|
2020-09-28 15:11:23 +02:00
|
|
|
self.table_headers = ['', 'Event', 'Time', 'Lat', 'Lon', 'Depth', 'Ml', 'Mw', '[N] MP', '[N] AP', 'Tuning Set',
|
2019-07-01 17:24:06 +02:00
|
|
|
'Test Set', 'Notes']
|
|
|
|
|
2018-08-01 13:49:01 +02:00
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
if settings.value("user/FullName", None) is None:
|
|
|
|
fulluser = QInputDialog.getText(self, "Enter Name:", "Full name")
|
|
|
|
settings.setValue("user/FullName", fulluser)
|
|
|
|
settings.setValue("user/Login", getLogin())
|
|
|
|
if settings.value("agency_id", None) is None:
|
|
|
|
agency = QInputDialog.getText(self,
|
|
|
|
"Enter authority/institution name:",
|
|
|
|
"Authority")
|
|
|
|
settings.setValue("agency_id", agency)
|
2018-08-16 16:21:28 +02:00
|
|
|
structure_setting = settings.value("data/Structure", "PILOT")
|
|
|
|
if not structure_setting:
|
|
|
|
structure_setting = 'PILOT'
|
|
|
|
self.dataStructure = DATASTRUCTURE[structure_setting]()
|
|
|
|
self.seismicPhase = str(settings.value("phase", "P"))
|
|
|
|
if settings.value("data/dataRoot", None) is None:
|
|
|
|
dirname = QFileDialog().getExistingDirectory(
|
|
|
|
caption='Choose data root ...')
|
|
|
|
settings.setValue("data/dataRoot", dirname)
|
|
|
|
if settings.value('useGuiFilter') is None:
|
|
|
|
settings.setValue('useGuiFilter', False)
|
|
|
|
if settings.value('output/Format', None) is None:
|
|
|
|
outformat = QInputDialog.getText(self,
|
2020-10-15 10:02:02 +02:00
|
|
|
"Enter output format (*.xml, *.cnv, *.obs, *_focmec.in, *.pha):",
|
2018-08-16 16:21:28 +02:00
|
|
|
"Format")
|
|
|
|
settings.setValue("output/Format", outformat)
|
|
|
|
if settings.value('autoFilter', None) is None:
|
|
|
|
settings.setValue('autoFilter', True)
|
|
|
|
settings.sync()
|
2018-08-01 13:49:01 +02:00
|
|
|
break
|
|
|
|
except Exception as e:
|
|
|
|
qmb = QMessageBox(self, icon=QMessageBox.Question,
|
|
|
|
text='Could not init application settings: {}.'
|
|
|
|
'Do you want to reset application settings?'.format(e),
|
|
|
|
windowTitle='PyLoT - Init QSettings warning')
|
|
|
|
qmb.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
|
|
|
|
qmb.setDefaultButton(QMessageBox.No)
|
|
|
|
ret = qmb.exec_()
|
|
|
|
if ret == qmb.Yes:
|
|
|
|
settings.clear()
|
|
|
|
else:
|
|
|
|
sys.exit()
|
|
|
|
print('Settings cleared!')
|
|
|
|
|
2017-06-09 13:23:16 +02:00
|
|
|
# setup UI
|
|
|
|
self.setupUi()
|
|
|
|
|
2018-02-22 11:28:46 +01:00
|
|
|
self.updateFilteroptions()
|
|
|
|
|
2015-11-14 11:46:46 +01:00
|
|
|
self.loc = False
|
2014-03-13 13:27:34 +01:00
|
|
|
|
2018-07-10 13:56:17 +02:00
|
|
|
def init_config_files(self, infile):
|
|
|
|
pylot_config_dir = os.path.join(os.path.expanduser('~'), '.pylot')
|
|
|
|
if not os.path.exists(pylot_config_dir):
|
|
|
|
os.mkdir(pylot_config_dir)
|
|
|
|
|
|
|
|
self._inputs = PylotParameter(infile)
|
|
|
|
if not infile:
|
|
|
|
self._inputs.reset_defaults()
|
|
|
|
# check for default pylot.in-file
|
|
|
|
infile = os.path.join(pylot_config_dir, '.pylot.in')
|
|
|
|
print('Using default input file {}'.format(infile))
|
|
|
|
self._inputs.export2File(infile)
|
|
|
|
self.infile = infile
|
|
|
|
|
2015-02-17 13:17:01 +01:00
|
|
|
def setupUi(self):
|
2014-11-26 08:46:16 +01:00
|
|
|
try:
|
2015-01-29 08:53:01 +01:00
|
|
|
self.startTime = min(
|
2016-03-30 07:00:31 +02:00
|
|
|
[tr.stats.starttime for tr in self.data.wfdata])
|
2014-11-26 08:46:16 +01:00
|
|
|
except:
|
|
|
|
self.startTime = UTCDateTime()
|
2014-03-28 05:25:46 +01:00
|
|
|
|
2017-09-06 18:02:09 +02:00
|
|
|
self.init_styles()
|
|
|
|
|
2015-04-02 18:36:21 +02:00
|
|
|
pylot_icon = QIcon()
|
2015-07-07 11:21:06 +02:00
|
|
|
pylot_icon.addPixmap(QPixmap(':/icons/pylot.png'))
|
2015-04-02 18:36:21 +02:00
|
|
|
|
2015-03-01 10:31:49 +01:00
|
|
|
self.setWindowTitle("PyLoT - do seismic processing the python way")
|
2015-04-02 18:36:21 +02:00
|
|
|
self.setWindowIcon(pylot_icon)
|
2015-01-29 08:41:38 +01:00
|
|
|
|
|
|
|
_widget = QWidget()
|
2017-04-18 17:17:46 +02:00
|
|
|
self._main_layout = QVBoxLayout()
|
|
|
|
|
2015-01-29 08:41:38 +01:00
|
|
|
quitIcon = self.style().standardIcon(QStyle.SP_MediaStop)
|
|
|
|
helpIcon = self.style().standardIcon(QStyle.SP_DialogHelpButton)
|
2017-04-18 16:24:26 +02:00
|
|
|
newFolderIcon = self.style().standardIcon(QStyle.SP_FileDialogNewFolder)
|
2017-08-03 09:41:54 +02:00
|
|
|
|
2015-04-02 18:36:21 +02:00
|
|
|
# create resource icons
|
2017-06-29 15:02:50 +02:00
|
|
|
newIcon = QIcon()
|
|
|
|
newIcon.addPixmap(QPixmap(':/icons/newfile.png'))
|
2017-06-28 16:25:14 +02:00
|
|
|
addIcon = QIcon()
|
|
|
|
addIcon.addPixmap(QPixmap(':/icons/add.png'))
|
|
|
|
saveIcon = QIcon()
|
|
|
|
saveIcon.addPixmap(QPixmap(':/icons/save.png'))
|
|
|
|
saveasIcon = QIcon()
|
|
|
|
saveasIcon.addPixmap(QPixmap(':/icons/saveas.png'))
|
|
|
|
saveProjectIcon = QIcon()
|
|
|
|
saveProjectIcon.addPixmap(QPixmap(':/icons/saveproject.png'))
|
|
|
|
saveProjectAsIcon = QIcon()
|
|
|
|
saveProjectAsIcon.addPixmap(QPixmap(':/icons/saveprojectas.png'))
|
|
|
|
openIcon = QIcon()
|
|
|
|
openIcon.addPixmap(QPixmap(':/icons/openfile.png'))
|
|
|
|
openProjectIcon = QIcon()
|
|
|
|
openProjectIcon.addPixmap(QPixmap(':/icons/openproject.png'))
|
|
|
|
openLocIcon = QIcon()
|
|
|
|
openLocIcon.addPixmap(QPixmap(':/icons/openloc.png'))
|
|
|
|
openEventIcon = QIcon()
|
|
|
|
openEventIcon.addPixmap(QPixmap(':/icons/openpick.png'))
|
|
|
|
openEventsIcon = QIcon()
|
|
|
|
openEventsIcon.addPixmap(QPixmap(':/icons/openpicks.png'))
|
|
|
|
saveEventsIcon = QIcon()
|
|
|
|
saveEventsIcon.addPixmap(QPixmap(':/icons/savepicks.png'))
|
2017-06-28 17:20:02 +02:00
|
|
|
prefIcon = QIcon()
|
|
|
|
prefIcon.addPixmap(QPixmap(':/icons/preferences.png'))
|
|
|
|
paraIcon = QIcon()
|
|
|
|
paraIcon.addPixmap(QPixmap(':/icons/parameter.png'))
|
2019-12-17 13:50:54 +01:00
|
|
|
deleteIcon = QIcon()
|
|
|
|
deleteIcon.addPixmap(QPixmap(':/icons/delete.png'))
|
2017-08-18 11:32:45 +02:00
|
|
|
self.inventoryIcon = QIcon()
|
|
|
|
self.inventoryIcon.addPixmap(QPixmap(':/icons/inventory.png'))
|
|
|
|
self.mapIcon = QIcon()
|
|
|
|
self.mapIcon.addPixmap(QPixmap(':/icons/map.png'))
|
2017-04-21 15:46:57 +02:00
|
|
|
self.autopicksicon_small = QIcon()
|
2017-04-27 10:42:31 +02:00
|
|
|
self.autopicksicon_small.addPixmap(QPixmap(':/icons/autopicksicon_small.png'))
|
2017-04-21 15:46:57 +02:00
|
|
|
self.manupicksicon_small = QIcon()
|
2017-07-14 16:25:59 +02:00
|
|
|
self.manupicksicon_small.addPixmap(QPixmap(':/icons/manupicksicon_small.png'))
|
2017-04-06 13:16:28 +02:00
|
|
|
loadpiloticon = QIcon()
|
|
|
|
loadpiloticon.addPixmap(QPixmap(':/icons/Matlab_PILOT_icon.png'))
|
2015-04-02 18:36:21 +02:00
|
|
|
p_icon = QIcon()
|
2015-07-07 10:31:39 +02:00
|
|
|
p_icon.addPixmap(QPixmap(':/icons/key_P.png'))
|
2015-04-02 18:36:21 +02:00
|
|
|
s_icon = QIcon()
|
2015-07-07 10:31:39 +02:00
|
|
|
s_icon.addPixmap(QPixmap(':/icons/key_S.png'))
|
2015-04-02 18:36:21 +02:00
|
|
|
print_icon = QIcon()
|
|
|
|
print_icon.addPixmap(QPixmap(':/icons/printer.png'))
|
2017-12-21 13:13:44 +01:00
|
|
|
self.filter_icon = QIcon()
|
|
|
|
self.filter_icon.addPixmap(QPixmap(':/icons/filter.png'))
|
2018-01-12 10:07:14 +01:00
|
|
|
self.filter_icon_p = QIcon()
|
|
|
|
self.filter_icon_p.addPixmap(QPixmap(':/icons/filter_p.png'))
|
|
|
|
self.filter_icon_s = QIcon()
|
|
|
|
self.filter_icon_s.addPixmap(QPixmap(':/icons/filter_s.png'))
|
2015-07-07 14:21:11 +02:00
|
|
|
z_icon = QIcon()
|
2015-07-09 11:37:03 +02:00
|
|
|
z_icon.addPixmap(QPixmap(':/icons/key_Z.png'))
|
2015-07-07 14:21:11 +02:00
|
|
|
n_icon = QIcon()
|
2015-07-09 11:37:03 +02:00
|
|
|
n_icon.addPixmap(QPixmap(':/icons/key_N.png'))
|
2015-07-07 14:21:11 +02:00
|
|
|
e_icon = QIcon()
|
2015-07-09 11:37:03 +02:00
|
|
|
e_icon.addPixmap(QPixmap(':/icons/key_E.png'))
|
2017-05-18 11:02:20 +02:00
|
|
|
autotune_icon = QIcon()
|
2017-06-28 16:25:14 +02:00
|
|
|
autotune_icon.addPixmap(QPixmap(':/icons/tune.png'))
|
2017-05-18 11:02:20 +02:00
|
|
|
autopylot_icon = QIcon()
|
|
|
|
autopylot_icon.addPixmap(QPixmap(':/icons/autopylot_button'))
|
2015-11-09 08:53:26 +01:00
|
|
|
locate_icon = QIcon()
|
2017-04-06 13:16:28 +02:00
|
|
|
locate_icon.addPixmap(QPixmap(':/icons/locate_button.png'))
|
2016-06-06 14:10:46 +02:00
|
|
|
compare_icon = QIcon()
|
2017-04-06 13:16:28 +02:00
|
|
|
compare_icon.addPixmap(QPixmap(':/icons/compare_button.png'))
|
2018-01-30 16:16:41 +01:00
|
|
|
qualities_icon = QIcon()
|
|
|
|
qualities_icon.addPixmap(QPixmap(':/icons/pick_qualities_button.png'))
|
2017-04-18 16:24:26 +02:00
|
|
|
self.newProjectAction = self.createAction(self, "&New project ...",
|
2017-05-31 14:30:06 +02:00
|
|
|
self.createNewProject,
|
|
|
|
QKeySequence.New, newIcon,
|
|
|
|
"Create a new Project.")
|
|
|
|
self.openProjectAction = self.createAction(self, "&Open project ...",
|
2017-04-18 16:24:26 +02:00
|
|
|
self.loadProject,
|
|
|
|
QKeySequence.Open,
|
2017-06-28 16:25:14 +02:00
|
|
|
openProjectIcon,
|
2017-04-18 16:24:26 +02:00
|
|
|
"Load project file")
|
2017-05-31 14:30:06 +02:00
|
|
|
self.saveProjectAction = self.createAction(self, "&Save project ...",
|
2017-04-18 16:24:26 +02:00
|
|
|
self.saveProject,
|
|
|
|
QKeySequence.Save,
|
2017-04-28 13:42:57 +02:00
|
|
|
saveProjectIcon,
|
2017-04-18 16:24:26 +02:00
|
|
|
"Save project file")
|
2017-04-28 13:47:24 +02:00
|
|
|
self.saveProjectAction.setEnabled(False)
|
2017-05-31 14:30:06 +02:00
|
|
|
self.saveProjectAsAction = self.createAction(self, "Save project as ...",
|
|
|
|
self.saveProjectAs,
|
|
|
|
QKeySequence.SaveAs,
|
2017-06-28 16:25:14 +02:00
|
|
|
saveProjectAsIcon,
|
2017-05-31 14:30:06 +02:00
|
|
|
"Save project file as...")
|
|
|
|
self.saveProjectAsAction.setEnabled(False)
|
2017-04-18 16:24:26 +02:00
|
|
|
# newEventAction = self.createAction(self, "&New event ...",
|
|
|
|
# self.createNewEvent,
|
|
|
|
# QKeySequence.New, newIcon,
|
|
|
|
# "Create a new event.")
|
2017-08-15 16:36:14 +02:00
|
|
|
self.openEventAction = self.createAction(self, "Load event information...",
|
2017-08-07 16:41:50 +02:00
|
|
|
self.load_data,
|
2018-07-16 14:21:41 +02:00
|
|
|
"Ctrl+M",
|
2017-08-07 16:41:50 +02:00
|
|
|
openEventIcon,
|
2018-07-16 14:21:41 +02:00
|
|
|
"Load event information for "
|
|
|
|
"the displayed event.")
|
2017-08-07 16:41:50 +02:00
|
|
|
self.openEventAction.setEnabled(False)
|
|
|
|
self.openEventAction.setData(None)
|
2017-04-10 14:24:39 +02:00
|
|
|
|
2017-08-07 16:41:50 +02:00
|
|
|
self.openEventsAutoAction = self.createAction(self, "Load event information &automatically ... ",
|
|
|
|
self.load_multiple_data,
|
2018-07-16 14:21:41 +02:00
|
|
|
"Ctrl+A",
|
2017-08-07 16:41:50 +02:00
|
|
|
openEventsIcon,
|
2018-07-16 14:21:41 +02:00
|
|
|
"Load event data automatically "
|
|
|
|
"for all events.")
|
2017-08-07 16:41:50 +02:00
|
|
|
self.openEventsAutoAction.setEnabled(False)
|
|
|
|
self.openEventsAutoAction.setData(None)
|
2016-05-27 11:25:47 +02:00
|
|
|
|
2017-04-28 13:56:28 +02:00
|
|
|
self.loadlocationaction = self.createAction(self, "Load &location ...",
|
2017-05-31 14:30:06 +02:00
|
|
|
self.load_loc, "Ctrl+L",
|
2017-06-28 16:25:14 +02:00
|
|
|
openLocIcon,
|
2017-05-31 14:30:06 +02:00
|
|
|
"Load location information on "
|
|
|
|
"the displayed event.")
|
2017-04-28 13:56:28 +02:00
|
|
|
self.loadlocationaction.setEnabled(False)
|
2017-04-10 14:24:39 +02:00
|
|
|
self.loadpilotevent = self.createAction(self, "Load PILOT &event ...",
|
2017-05-31 14:30:06 +02:00
|
|
|
self.load_pilotevent, None,
|
2017-04-19 16:05:45 +02:00
|
|
|
loadpiloticon,
|
|
|
|
"Load PILOT event from information "
|
|
|
|
"MatLab binary collections (created"
|
|
|
|
" in former MatLab based version).")
|
2017-04-10 14:24:39 +02:00
|
|
|
self.loadpilotevent.setEnabled(False)
|
|
|
|
|
2017-08-07 16:41:50 +02:00
|
|
|
self.saveEventAction = self.createAction(self, "Save &event information ...",
|
|
|
|
self.saveData, "Ctrl+P",
|
|
|
|
saveEventsIcon, "Save event pick data,"
|
2018-07-16 14:21:41 +02:00
|
|
|
" source origin and magnitude.")
|
2017-08-07 16:41:50 +02:00
|
|
|
self.disableSaveEventAction()
|
2017-04-10 14:24:39 +02:00
|
|
|
|
2019-07-01 17:24:06 +02:00
|
|
|
self.exportProjectTableAction = self.createAction(self, "Export Project table...",
|
|
|
|
self.exportProjectTableDialogs, None,
|
|
|
|
None, "Export Project table (csv)")
|
|
|
|
|
2017-04-18 16:24:26 +02:00
|
|
|
self.addEventDataAction = self.createAction(self, "Add &events ...",
|
|
|
|
self.add_events,
|
2017-06-28 16:25:14 +02:00
|
|
|
"Ctrl+E", addIcon,
|
2017-04-18 16:24:26 +02:00
|
|
|
"Add event data")
|
2015-03-11 12:05:52 +01:00
|
|
|
prefsEventAction = self.createAction(self, "Preferences",
|
|
|
|
self.PyLoTprefs,
|
2015-01-29 08:41:38 +01:00
|
|
|
QKeySequence.Preferences,
|
2017-06-28 17:20:02 +02:00
|
|
|
prefIcon,
|
2015-01-29 08:41:38 +01:00
|
|
|
"Edit PyLoT app preferences.")
|
2015-03-04 15:40:25 +01:00
|
|
|
quitAction = self.createAction(self, "&Quit",
|
2015-01-29 08:41:38 +01:00
|
|
|
QCoreApplication.instance().quit,
|
|
|
|
QKeySequence.Close, quitIcon,
|
|
|
|
"Close event and quit PyLoT")
|
2017-06-21 11:43:01 +02:00
|
|
|
self.parameterAction = self.createAction(self, "Parameter",
|
|
|
|
self.setParameter,
|
2017-06-28 17:20:02 +02:00
|
|
|
None, paraIcon,
|
2017-06-21 11:43:01 +02:00
|
|
|
"Modify Parameter")
|
2019-12-17 13:50:54 +01:00
|
|
|
self.deleteAutopicksAction = self.createAction(self, "Delete Autopicks",
|
2021-03-30 08:28:31 +02:00
|
|
|
self.deleteAllAutopicks,
|
|
|
|
None, deleteIcon,
|
|
|
|
"Delete all automatic picks from Project.")
|
2018-01-12 10:07:14 +01:00
|
|
|
self.filterActionP = createAction(parent=self, text='Apply P Filter',
|
|
|
|
slot=self.filterP,
|
|
|
|
icon=self.filter_icon_p,
|
|
|
|
tip='Toggle filtered/original'
|
|
|
|
' waveforms',
|
|
|
|
checkable=True,
|
2018-01-12 10:10:51 +01:00
|
|
|
shortcut='P')
|
2018-01-12 10:07:14 +01:00
|
|
|
self.filterActionS = createAction(parent=self, text='Apply S Filter',
|
|
|
|
slot=self.filterS,
|
|
|
|
icon=self.filter_icon_s,
|
|
|
|
tip='Toggle filtered/original'
|
|
|
|
' waveforms',
|
|
|
|
checkable=True,
|
2018-01-12 10:10:51 +01:00
|
|
|
shortcut='S')
|
2015-03-04 15:40:25 +01:00
|
|
|
filterEditAction = self.createAction(self, "&Filter parameter ...",
|
2015-01-29 08:41:38 +01:00
|
|
|
self.adjustFilterOptions,
|
2018-01-12 10:10:51 +01:00
|
|
|
"Ctrl+F", self.filter_icon,
|
2015-01-29 08:41:38 +01:00
|
|
|
"""Adjust filter parameters.""")
|
2018-07-19 11:50:29 +02:00
|
|
|
self.inventoryAction = self.createAction(self, "Manage &Inventories ...",
|
2018-07-23 16:03:15 +02:00
|
|
|
self.add_metadata,
|
2018-07-16 14:21:41 +02:00
|
|
|
"Ctrl+I", self.inventoryIcon,
|
2018-07-19 11:50:29 +02:00
|
|
|
"""Manage metadata for current project""",
|
2018-07-16 14:21:41 +02:00
|
|
|
False)
|
2017-08-17 10:46:06 +02:00
|
|
|
self.initMapAction = self.createAction(self, "Init array map ...",
|
2018-07-16 14:21:41 +02:00
|
|
|
self.init_array_map,
|
|
|
|
"Ctrl+M", self.mapIcon,
|
|
|
|
"""Initialize array map with current metadata""",
|
|
|
|
False)
|
2017-08-17 10:46:06 +02:00
|
|
|
self.initMapAction.setEnabled(False)
|
2015-06-11 10:07:21 +02:00
|
|
|
self.selectPAction = self.createAction(self, "&P", self.alterPhase,
|
|
|
|
"Alt+P",
|
|
|
|
p_icon,
|
|
|
|
"Toggle P phase.", True)
|
|
|
|
self.selectSAction = self.createAction(self, "&S", self.alterPhase,
|
|
|
|
"Alt+S",
|
|
|
|
s_icon,
|
|
|
|
"Toggle S phase", True)
|
2016-06-06 14:10:46 +02:00
|
|
|
self.compare_action = self.createAction(self, "&Compare picks...",
|
|
|
|
self.comparePicks, "Alt+C",
|
|
|
|
compare_icon, "Comparison of "
|
|
|
|
"manual and "
|
|
|
|
"automatic pick "
|
|
|
|
"data.", False)
|
2017-04-10 14:24:39 +02:00
|
|
|
self.compare_action.setEnabled(False)
|
2018-07-16 14:21:41 +02:00
|
|
|
self.qualities_action = self.createAction(parent=self, text='Show pick qualitites...',
|
|
|
|
slot=self.pickQualities, shortcut='Alt+Q',
|
|
|
|
icon=qualities_icon, tip='Histogram of pick qualities')
|
2018-01-30 16:16:41 +01:00
|
|
|
self.qualities_action.setEnabled(False)
|
2018-08-03 11:16:08 +02:00
|
|
|
# MP MP not yet implemented, therefore hide:
|
|
|
|
self.qualities_action.setVisible(False)
|
2017-04-10 14:24:39 +02:00
|
|
|
|
2015-03-04 15:40:25 +01:00
|
|
|
printAction = self.createAction(self, "&Print event ...",
|
2016-09-02 14:21:59 +02:00
|
|
|
self.show_event_information, QKeySequence.Print,
|
2015-04-02 18:36:21 +02:00
|
|
|
print_icon,
|
2017-04-06 13:16:28 +02:00
|
|
|
"Print waveform section.")
|
2015-03-04 15:40:25 +01:00
|
|
|
helpAction = self.createAction(self, "&Help ...", self.helpHelp,
|
2015-01-29 08:41:38 +01:00
|
|
|
QKeySequence.HelpContents, helpIcon,
|
|
|
|
"""Show either the documentation
|
|
|
|
homepage (internet connection available),
|
|
|
|
or shipped documentation files.""")
|
2015-02-23 14:47:38 +01:00
|
|
|
|
2015-10-30 08:37:00 +01:00
|
|
|
# phaseToolBar = self.addToolBar("PhaseTools")
|
|
|
|
# phaseToolActions = (self.selectPAction, self.selectSAction)
|
|
|
|
# phaseToolBar.setObjectName("PhaseTools")
|
|
|
|
# self.addActions(phaseToolBar, phaseToolActions)
|
2015-01-29 08:41:38 +01:00
|
|
|
|
2015-07-07 14:21:11 +02:00
|
|
|
# create button group for component selection
|
|
|
|
|
|
|
|
componentGroup = QActionGroup(self)
|
|
|
|
componentGroup.setExclusive(True)
|
|
|
|
|
2017-04-10 14:24:39 +02:00
|
|
|
self.z_action = self.createAction(parent=componentGroup, text='Z',
|
2017-07-14 16:25:59 +02:00
|
|
|
slot=self.plotZ, shortcut='Alt+Z',
|
|
|
|
icon=z_icon, tip='Display the vertical (Z)'
|
|
|
|
' component.',
|
|
|
|
checkable=True)
|
2017-04-10 14:24:39 +02:00
|
|
|
self.z_action.setChecked(True)
|
|
|
|
self.z_action.setEnabled(False)
|
2015-07-07 14:21:11 +02:00
|
|
|
|
2017-04-10 14:24:39 +02:00
|
|
|
self.n_action = self.createAction(parent=componentGroup, text='N',
|
2017-07-14 16:25:59 +02:00
|
|
|
slot=self.plotN, shortcut='Alt+N',
|
|
|
|
icon=n_icon,
|
|
|
|
tip='Display the north-south (N) '
|
|
|
|
'component.', checkable=True)
|
2017-04-10 14:24:39 +02:00
|
|
|
self.n_action.setEnabled(False)
|
2015-07-07 14:21:11 +02:00
|
|
|
|
2017-04-10 14:24:39 +02:00
|
|
|
self.e_action = self.createAction(parent=componentGroup, text='E',
|
2017-07-14 16:25:59 +02:00
|
|
|
slot=self.plotE, shortcut='Alt+E',
|
|
|
|
icon=e_icon,
|
|
|
|
tip='Display the east-west (E) component.',
|
|
|
|
checkable=True)
|
2017-04-10 14:24:39 +02:00
|
|
|
self.e_action.setEnabled(False)
|
2015-07-07 14:21:11 +02:00
|
|
|
|
2017-04-10 14:24:39 +02:00
|
|
|
componentActions = (self.z_action, self.n_action, self.e_action)
|
2015-07-07 14:21:11 +02:00
|
|
|
|
2017-05-18 11:02:20 +02:00
|
|
|
self.auto_tune = self.createAction(parent=self, text='autoTune',
|
2017-05-11 17:15:20 +02:00
|
|
|
slot=self.tune_autopicker, shortcut='Alt+Ctrl+A',
|
2017-05-18 11:02:20 +02:00
|
|
|
icon=autotune_icon, tip='Tune autopicking algorithm.')
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-05-18 10:31:59 +02:00
|
|
|
self.auto_tune.setEnabled(False)
|
2015-07-09 11:37:03 +02:00
|
|
|
|
2017-08-03 15:33:28 +02:00
|
|
|
self.auto_pick = self.createAction(parent=self, text='Current event',
|
2017-07-14 16:25:59 +02:00
|
|
|
slot=self.autoPick, shortcut='Alt+Ctrl+A',
|
|
|
|
icon=autopylot_icon, tip='Automatically pick'
|
2018-07-16 14:21:41 +02:00
|
|
|
' the displayed waveforms.')
|
2017-05-18 11:02:20 +02:00
|
|
|
self.auto_pick.setEnabled(False)
|
|
|
|
|
2017-08-03 15:33:28 +02:00
|
|
|
self.auto_pick_local = self.createAction(parent=self, text='Whole project (local machine)...',
|
2017-08-03 11:10:26 +02:00
|
|
|
slot=self.autoPickProject, shortcut=None,
|
|
|
|
icon=self.autopicksicon_small, tip='Automatically pick'
|
2018-07-16 14:21:41 +02:00
|
|
|
' the complete project on local machine.')
|
2017-08-03 11:10:26 +02:00
|
|
|
self.auto_pick_local.setEnabled(False)
|
|
|
|
|
2017-08-03 15:33:28 +02:00
|
|
|
self.auto_pick_sge = self.createAction(parent=self, text='Whole project (grid engine)...',
|
2017-08-03 11:10:26 +02:00
|
|
|
slot=self.autoPickProjectSGE, shortcut=None,
|
|
|
|
icon=self.autopicksicon_small, tip='Automatically pick'
|
2018-07-16 14:21:41 +02:00
|
|
|
' the complete project on grid engine.')
|
2017-08-03 11:10:26 +02:00
|
|
|
self.auto_pick_sge.setEnabled(False)
|
|
|
|
|
2018-01-30 16:16:41 +01:00
|
|
|
pickActions = (self.auto_tune, self.auto_pick, self.compare_action, self.qualities_action)
|
2015-07-09 11:37:03 +02:00
|
|
|
|
2015-04-02 18:48:06 +02:00
|
|
|
# pickToolBar = self.addToolBar("PickTools")
|
|
|
|
# pickToolActions = (selectStation, )
|
|
|
|
# pickToolBar.setObjectName("PickTools")
|
|
|
|
# self.addActions(pickToolBar, pickToolActions)
|
2018-07-24 14:33:38 +02:00
|
|
|
self.locateEventAction = self.createAction(parent=self, text='locate the event',
|
|
|
|
slot=self.locate_event,
|
|
|
|
shortcut='Alt+Ctrl+L',
|
|
|
|
icon=locate_icon,
|
|
|
|
tip='Locate the event using '
|
2021-03-30 08:28:31 +02:00
|
|
|
'the displayed manual arrivals.')
|
2018-07-24 14:33:38 +02:00
|
|
|
self.locateEventAction.setEnabled(False)
|
2015-11-09 08:53:26 +01:00
|
|
|
|
2018-07-24 14:33:38 +02:00
|
|
|
locationToolActions = (self.locateEventAction,)
|
2017-08-03 11:10:26 +02:00
|
|
|
|
|
|
|
# add top menu
|
|
|
|
self.fileMenu = self.menuBar().addMenu('&File')
|
2017-08-15 16:36:14 +02:00
|
|
|
self.fileMenuActions = (self.newProjectAction,
|
2017-08-03 11:10:26 +02:00
|
|
|
self.openProjectAction, self.saveProjectAction,
|
2017-08-15 16:36:14 +02:00
|
|
|
self.saveProjectAsAction, None,
|
|
|
|
self.addEventDataAction,
|
2017-08-07 16:41:50 +02:00
|
|
|
self.openEventAction, self.saveEventAction, None,
|
2019-07-01 17:24:06 +02:00
|
|
|
self.exportProjectTableAction, None,
|
2017-08-15 16:28:38 +02:00
|
|
|
quitAction)
|
2017-08-03 11:10:26 +02:00
|
|
|
self.fileMenu.aboutToShow.connect(self.updateFileMenu)
|
|
|
|
self.updateFileMenu()
|
|
|
|
|
|
|
|
self.editMenu = self.menuBar().addMenu('&Edit')
|
2018-08-14 14:21:32 +02:00
|
|
|
|
2018-01-12 10:07:14 +01:00
|
|
|
editActions = (self.filterActionP, self.filterActionS, filterEditAction, None,
|
2018-07-16 14:21:41 +02:00
|
|
|
# self.selectPAction, self.selectSAction, None,
|
2017-08-17 10:46:06 +02:00
|
|
|
self.inventoryAction, self.initMapAction, None,
|
2017-08-15 16:28:38 +02:00
|
|
|
prefsEventAction)
|
2018-07-16 14:21:41 +02:00
|
|
|
# printAction) #TODO: print event?
|
2017-08-03 11:10:26 +02:00
|
|
|
|
2019-12-17 13:50:54 +01:00
|
|
|
pickMenuActions = (self.parameterAction, self.deleteAutopicksAction)
|
2017-08-03 11:10:26 +02:00
|
|
|
self.pickMenu = self.menuBar().addMenu('&Picking')
|
2017-08-18 11:32:45 +02:00
|
|
|
self.autoPickMenu = self.pickMenu.addMenu(self.autopicksicon_small, 'Automatic picking')
|
2017-08-03 15:33:28 +02:00
|
|
|
self.autoPickMenu.setEnabled(False)
|
|
|
|
|
2017-08-15 16:28:38 +02:00
|
|
|
autoPickActions = (self.auto_pick, self.auto_pick_local, self.auto_pick_sge)
|
2017-08-03 11:10:26 +02:00
|
|
|
|
|
|
|
self.helpMenu = self.menuBar().addMenu('&Help')
|
|
|
|
helpActions = (helpAction,)
|
|
|
|
|
2017-08-15 16:36:14 +02:00
|
|
|
fileToolActions = (self.newProjectAction,
|
2017-08-03 11:10:26 +02:00
|
|
|
self.openProjectAction, self.saveProjectAction,
|
|
|
|
self.saveProjectAsAction)
|
|
|
|
|
2017-08-15 16:36:14 +02:00
|
|
|
eventToolActions = (self.addEventDataAction,
|
|
|
|
self.openEventAction, self.openEventsAutoAction,
|
2017-08-07 16:41:50 +02:00
|
|
|
self.saveEventAction, self.loadlocationaction,
|
2017-08-03 11:10:26 +02:00
|
|
|
self.loadpilotevent)
|
|
|
|
|
2017-08-18 14:53:35 +02:00
|
|
|
toolbars_keys = [
|
|
|
|
"FileTools",
|
|
|
|
"EventTools",
|
|
|
|
"ComponentSelection",
|
|
|
|
"autoPyLoT",
|
|
|
|
"LocationTools"
|
|
|
|
]
|
|
|
|
|
|
|
|
toolbars = {}
|
|
|
|
|
|
|
|
for name in toolbars_keys:
|
|
|
|
toolbars[name] = self.addToolBar(name)
|
|
|
|
toolbars[name].setObjectName(name)
|
|
|
|
toolbars[name].setMovable(False)
|
2017-08-03 11:10:26 +02:00
|
|
|
|
|
|
|
self.addActions(self.editMenu, editActions)
|
2017-08-15 16:32:02 +02:00
|
|
|
self.addActions(self.autoPickMenu, autoPickActions)
|
2017-08-15 16:28:38 +02:00
|
|
|
self.addActions(self.pickMenu, pickMenuActions)
|
2017-08-03 11:10:26 +02:00
|
|
|
self.addActions(self.helpMenu, helpActions)
|
|
|
|
|
2017-08-18 14:53:35 +02:00
|
|
|
self.addActions(toolbars["FileTools"], fileToolActions)
|
|
|
|
self.addActions(toolbars["EventTools"], eventToolActions)
|
|
|
|
self.addActions(toolbars["ComponentSelection"], componentActions)
|
|
|
|
self.addActions(toolbars["autoPyLoT"], pickActions)
|
|
|
|
self.addActions(toolbars["LocationTools"], locationToolActions)
|
2015-11-09 08:53:26 +01:00
|
|
|
|
2017-09-07 16:07:43 +02:00
|
|
|
# init pyqtgraph
|
|
|
|
self.pg = pg
|
|
|
|
|
|
|
|
# init style
|
2017-09-11 13:27:32 +02:00
|
|
|
settings = QSettings()
|
|
|
|
style = settings.value('style')
|
|
|
|
self.set_style(style)
|
2017-08-17 10:46:06 +02:00
|
|
|
|
2018-01-10 16:54:26 +01:00
|
|
|
# add event combo box, forward, backward and ref/test buttons
|
2017-08-17 10:46:06 +02:00
|
|
|
self.eventBox = self.createEventBox()
|
|
|
|
self.eventBox.setMaxVisibleItems(30)
|
|
|
|
self.eventBox.setEnabled(False)
|
2018-01-10 16:54:26 +01:00
|
|
|
self.previous_button = QPushButton('<')
|
|
|
|
self.next_button = QPushButton('>')
|
2017-08-17 10:46:06 +02:00
|
|
|
self.init_ref_test_buttons()
|
|
|
|
self._event_layout = QHBoxLayout()
|
|
|
|
self._event_layout.addWidget(QLabel('Event: '))
|
|
|
|
self._event_layout.addWidget(self.eventBox)
|
2018-01-10 16:54:26 +01:00
|
|
|
self._event_layout.addWidget(self.previous_button)
|
|
|
|
self._event_layout.addWidget(self.next_button)
|
2017-08-17 10:46:06 +02:00
|
|
|
self._event_layout.addWidget(self.ref_event_button)
|
|
|
|
self._event_layout.addWidget(self.test_event_button)
|
|
|
|
self._event_layout.setStretch(1, 1) # set stretch of item 1 to 1
|
|
|
|
self._main_layout.addLayout(self._event_layout)
|
|
|
|
self.eventBox.activated.connect(self.refreshEvents)
|
|
|
|
|
2018-01-10 16:54:26 +01:00
|
|
|
self.previous_button.clicked.connect(self.previous_event)
|
|
|
|
self.next_button.clicked.connect(self.next_event)
|
|
|
|
self.previous_button.setEnabled(False)
|
|
|
|
self.next_button.setEnabled(False)
|
|
|
|
|
2017-08-17 10:46:06 +02:00
|
|
|
# add main tab widget
|
2017-09-06 18:02:09 +02:00
|
|
|
self.tabs = QTabWidget(self)
|
2017-08-17 10:46:06 +02:00
|
|
|
self._main_layout.addWidget(self.tabs)
|
|
|
|
self.tabs.currentChanged.connect(self.refreshTabs)
|
|
|
|
|
2017-09-18 14:57:48 +02:00
|
|
|
# add progressbar
|
2018-07-18 11:13:29 +02:00
|
|
|
self.mainProgressBarWidget = ProgressBarWidget(self)
|
2017-09-18 14:57:48 +02:00
|
|
|
self._main_layout.addWidget(self.mainProgressBarWidget)
|
|
|
|
|
2017-08-17 10:46:06 +02:00
|
|
|
# add scroll area used in case number of traces gets too high
|
2017-09-06 18:02:09 +02:00
|
|
|
self.wf_scroll_area = QtGui.QScrollArea(self)
|
2018-04-27 10:45:20 +02:00
|
|
|
self.wf_scroll_area.setVisible(False)
|
|
|
|
self.no_data_label = QLabel('No Data')
|
|
|
|
self.no_data_label.setStyleSheet('color: red')
|
|
|
|
self.no_data_label.setAlignment(Qt.AlignCenter)
|
2017-08-17 10:46:06 +02:00
|
|
|
|
|
|
|
# create central matplotlib figure canvas widget
|
|
|
|
self.init_wfWidget()
|
|
|
|
|
|
|
|
# init main widgets for main tabs
|
2017-09-06 18:02:09 +02:00
|
|
|
wf_tab = QtGui.QWidget(self)
|
|
|
|
array_tab = QtGui.QWidget(self)
|
|
|
|
events_tab = QtGui.QWidget(self)
|
2017-08-17 10:46:06 +02:00
|
|
|
|
|
|
|
# init main widgets layouts
|
|
|
|
self.wf_layout = QtGui.QVBoxLayout()
|
|
|
|
self.array_layout = QtGui.QVBoxLayout()
|
|
|
|
self.events_layout = QtGui.QVBoxLayout()
|
|
|
|
wf_tab.setLayout(self.wf_layout)
|
|
|
|
array_tab.setLayout(self.array_layout)
|
|
|
|
events_tab.setLayout(self.events_layout)
|
|
|
|
|
2018-06-14 16:17:06 +02:00
|
|
|
# tighten up layouts inside tabs
|
|
|
|
for layout in [self.wf_layout, self.array_layout, self.events_layout]:
|
|
|
|
layout.setSpacing(0)
|
|
|
|
layout.setContentsMargins(0, 0, 0, 0)
|
|
|
|
|
2017-08-17 10:46:06 +02:00
|
|
|
# add tabs to main tab widget
|
|
|
|
self.tabs.addTab(wf_tab, 'Waveform Plot')
|
|
|
|
self.tabs.addTab(array_tab, 'Array Map')
|
|
|
|
self.tabs.addTab(events_tab, 'Eventlist')
|
|
|
|
|
2018-04-27 10:45:20 +02:00
|
|
|
self.wf_layout.addWidget(self.no_data_label)
|
2017-08-17 10:46:06 +02:00
|
|
|
self.wf_layout.addWidget(self.wf_scroll_area)
|
|
|
|
self.wf_scroll_area.setWidgetResizable(True)
|
|
|
|
self.init_array_tab()
|
|
|
|
self.init_event_table()
|
|
|
|
self.tabs.setCurrentIndex(0)
|
|
|
|
|
2015-01-29 08:41:38 +01:00
|
|
|
self.eventLabel = QLabel()
|
|
|
|
self.eventLabel.setFrameStyle(QFrame.StyledPanel | QFrame.Sunken)
|
|
|
|
status = self.statusBar()
|
|
|
|
status.setSizeGripEnabled(False)
|
|
|
|
status.addPermanentWidget(self.eventLabel)
|
|
|
|
status.showMessage("Ready", 500)
|
|
|
|
|
2017-04-18 17:17:46 +02:00
|
|
|
_widget.setLayout(self._main_layout)
|
2015-03-11 12:05:52 +01:00
|
|
|
_widget.showFullScreen()
|
2014-10-27 11:57:34 +01:00
|
|
|
|
2015-03-11 12:05:52 +01:00
|
|
|
self.setCentralWidget(_widget)
|
2014-11-27 10:13:17 +01:00
|
|
|
|
2017-06-09 13:23:16 +02:00
|
|
|
def init_wfWidget(self):
|
|
|
|
xlab = self.startTime.strftime('seconds since %Y/%m/%d %H:%M:%S (%Z)')
|
2017-07-14 16:25:59 +02:00
|
|
|
plottitle = None # "Overview: {0} components ".format(self.getComponent())
|
2017-06-09 13:23:16 +02:00
|
|
|
self.disconnectWFplotEvents()
|
2018-08-01 13:49:01 +02:00
|
|
|
self.pg = pg
|
|
|
|
self.dataPlot = WaveformWidgetPG(parent=self,
|
|
|
|
title=plottitle)
|
2017-06-09 13:23:16 +02:00
|
|
|
self.dataPlot.setCursor(Qt.CrossCursor)
|
|
|
|
self.wf_scroll_area.setWidget(self.dataPlot)
|
|
|
|
if self.get_current_event():
|
|
|
|
self.plotWaveformDataThread()
|
|
|
|
|
2017-05-19 10:56:27 +02:00
|
|
|
def init_ref_test_buttons(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Initiate/create buttons for assigning events containing manual picks to reference or test set.
|
|
|
|
'''
|
2017-09-13 14:44:56 +02:00
|
|
|
self.ref_event_button = QtGui.QPushButton('Tune')
|
2017-05-19 10:56:27 +02:00
|
|
|
self.test_event_button = QtGui.QPushButton('Test')
|
2018-01-10 16:54:26 +01:00
|
|
|
self.ref_event_button.setMinimumWidth(100)
|
|
|
|
self.test_event_button.setMinimumWidth(100)
|
2017-07-14 16:25:59 +02:00
|
|
|
self.ref_event_button.setToolTip('Set manual picks of current ' +
|
2017-05-19 10:56:27 +02:00
|
|
|
'event as reference picks for autopicker tuning.')
|
2017-07-14 16:25:59 +02:00
|
|
|
self.test_event_button.setToolTip('Set manual picks of current ' +
|
2017-05-19 10:56:27 +02:00
|
|
|
'event as test picks for autopicker testing.')
|
|
|
|
self.ref_event_button.setCheckable(True)
|
|
|
|
self.test_event_button.setCheckable(True)
|
2017-09-07 16:07:43 +02:00
|
|
|
self.set_button_border_color(self.ref_event_button, self._style['ref']['rgba'])
|
|
|
|
self.set_button_border_color(self.test_event_button, self._style['test']['rgba'])
|
2017-05-19 10:56:27 +02:00
|
|
|
self.ref_event_button.clicked.connect(self.toggleRef)
|
|
|
|
self.test_event_button.clicked.connect(self.toggleTest)
|
|
|
|
self.ref_event_button.setEnabled(False)
|
2017-07-14 16:25:59 +02:00
|
|
|
self.test_event_button.setEnabled(False)
|
2016-09-22 14:12:24 +02:00
|
|
|
|
2017-05-31 10:56:45 +02:00
|
|
|
def keyPressEvent(self, event):
|
|
|
|
if event.key() == QtCore.Qt.Key.Key_Control:
|
|
|
|
self._ctrl = True
|
2017-05-31 13:45:48 +02:00
|
|
|
if event.key() == QtCore.Qt.Key.Key_Shift:
|
|
|
|
self._shift = True
|
2019-04-04 11:48:44 +02:00
|
|
|
if event.key() == QtCore.Qt.Key.Key_Plus:
|
|
|
|
self.increase_gain()
|
|
|
|
if event.key() == QtCore.Qt.Key.Key_Minus:
|
|
|
|
self.decrease_gain()
|
|
|
|
if event.key() == QtCore.Qt.Key.Key_R:
|
|
|
|
self.reset_gain()
|
|
|
|
|
2017-05-31 10:56:45 +02:00
|
|
|
def keyReleaseEvent(self, event):
|
|
|
|
if event.key() == QtCore.Qt.Key.Key_Control:
|
|
|
|
self._ctrl = False
|
2017-05-31 13:45:48 +02:00
|
|
|
if event.key() == QtCore.Qt.Key.Key_Shift:
|
|
|
|
self._shift = False
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2019-04-04 11:48:44 +02:00
|
|
|
def increase_gain(self, factor=1.3):
|
|
|
|
self.modify_gain('+', factor)
|
|
|
|
|
|
|
|
def decrease_gain(self, factor=1.3):
|
|
|
|
self.modify_gain('-', factor)
|
|
|
|
|
|
|
|
def reset_gain(self):
|
|
|
|
self.gain = 1
|
|
|
|
self.plotWaveformDataThread(filter=False)
|
|
|
|
|
|
|
|
def modify_gain(self, direction, factor):
|
|
|
|
assert (direction in ['+', '-']), 'unknown direction'
|
|
|
|
if self._ctrl:
|
2021-03-30 08:28:31 +02:00
|
|
|
factor = factor ** 3
|
2019-04-04 11:48:44 +02:00
|
|
|
if direction == '+':
|
|
|
|
self.gain *= factor
|
|
|
|
elif direction == '-':
|
|
|
|
self.gain /= factor
|
|
|
|
self.plotWaveformDataThread(filter=False)
|
|
|
|
|
2017-09-06 18:02:09 +02:00
|
|
|
def init_styles(self):
|
|
|
|
self._styles = {}
|
2017-09-07 16:51:56 +02:00
|
|
|
styles = ['default', 'dark', 'bright']
|
2017-09-07 16:07:43 +02:00
|
|
|
stylecolors = style_settings.stylecolors
|
2017-09-06 18:02:09 +02:00
|
|
|
for style in styles:
|
2017-09-07 16:07:43 +02:00
|
|
|
if style in stylecolors.keys():
|
|
|
|
self._styles[style] = stylecolors[style]
|
2017-09-06 18:02:09 +02:00
|
|
|
|
2017-09-07 16:07:43 +02:00
|
|
|
self._phasecolors = style_settings.phasecolors
|
2017-09-15 14:47:05 +02:00
|
|
|
styles_dir = os.path.dirname(style_settings.__file__)
|
2017-09-06 18:02:09 +02:00
|
|
|
|
2017-09-07 16:07:43 +02:00
|
|
|
for style, stylecolors in self._styles.items():
|
|
|
|
stylesheet = stylecolors['stylesheet']['filename']
|
|
|
|
if stylesheet:
|
2017-09-15 14:47:05 +02:00
|
|
|
stylesheet_file = open(os.path.join(styles_dir, stylesheet), 'r')
|
2017-09-07 16:07:43 +02:00
|
|
|
stylesheet = stylesheet_file.read()
|
|
|
|
stylesheet_file.close()
|
|
|
|
else:
|
|
|
|
stylesheet = self.styleSheet()
|
2017-09-06 18:02:09 +02:00
|
|
|
|
2017-09-07 16:07:43 +02:00
|
|
|
bg_color = stylecolors['background']['rgba']
|
|
|
|
line_color = stylecolors['linecolor']['rgba']
|
|
|
|
multcursor_color = stylecolors['multicursor']['rgba']
|
|
|
|
|
|
|
|
# transform to 0-1 values for mpl and update dict
|
|
|
|
stylecolors['background']['rgba_mpl'] = transform_colors_mpl(bg_color)
|
|
|
|
stylecolors['linecolor']['rgba_mpl'] = transform_colors_mpl(line_color)
|
|
|
|
multcursor_color = stylecolors['multicursor']['rgba_mpl'] = transform_colors_mpl(multcursor_color)
|
|
|
|
|
|
|
|
stylecolors['stylesheet'] = stylesheet
|
|
|
|
|
2017-09-11 13:27:32 +02:00
|
|
|
def set_style(self, stylename=None):
|
|
|
|
if not stylename:
|
|
|
|
stylename = 'default'
|
2017-09-06 18:02:09 +02:00
|
|
|
if not stylename in self._styles:
|
|
|
|
qmb = QMessageBox.warning(self, 'Could not find style',
|
2017-09-07 16:07:43 +02:00
|
|
|
'Could not find style with name {}. Using default.'.format(stylename))
|
2017-09-11 13:27:32 +02:00
|
|
|
self.set_style('default')
|
2017-09-06 18:02:09 +02:00
|
|
|
return
|
2017-09-07 16:07:43 +02:00
|
|
|
|
2017-09-06 18:02:09 +02:00
|
|
|
style = self._styles[stylename]
|
2017-09-07 16:07:43 +02:00
|
|
|
self._style = style
|
2017-09-11 16:06:25 +02:00
|
|
|
self._stylename = stylename
|
2017-09-06 18:02:09 +02:00
|
|
|
self.setStyleSheet(style['stylesheet'])
|
|
|
|
|
2017-09-07 16:07:43 +02:00
|
|
|
# colors for ref/test event
|
|
|
|
self._ref_test_colors = {
|
|
|
|
'ref': QtGui.QColor(*style['ref']['rgba']),
|
|
|
|
'test': QtGui.QColor(*style['test']['rgba']),
|
|
|
|
}
|
2017-09-06 18:34:59 +02:00
|
|
|
|
2017-09-07 16:07:43 +02:00
|
|
|
# plot colors
|
|
|
|
bg_color = style['background']['rgba']
|
|
|
|
bg_color_mpl_na = transform_colors_mpl_str(bg_color, no_alpha=True)
|
|
|
|
line_color = style['linecolor']['rgba']
|
|
|
|
line_color_mpl_na = transform_colors_mpl_str(line_color, no_alpha=True)
|
|
|
|
|
|
|
|
for param in matplotlib.rcParams:
|
|
|
|
if 'color' in param and matplotlib.rcParams[param] in ['k', 'black']:
|
|
|
|
matplotlib.rcParams[param] = line_color_mpl_na
|
|
|
|
|
|
|
|
matplotlib.rc('axes',
|
|
|
|
edgecolor=line_color_mpl_na,
|
|
|
|
facecolor=bg_color_mpl_na,
|
|
|
|
labelcolor=line_color_mpl_na)
|
|
|
|
matplotlib.rc('xtick',
|
|
|
|
color=line_color_mpl_na)
|
|
|
|
matplotlib.rc('ytick',
|
|
|
|
color=line_color_mpl_na)
|
|
|
|
matplotlib.rc('figure',
|
|
|
|
facecolor=bg_color_mpl_na)
|
2017-09-06 18:34:59 +02:00
|
|
|
|
2017-09-06 18:02:09 +02:00
|
|
|
if self.pg:
|
2017-09-07 16:07:43 +02:00
|
|
|
pg.setConfigOption('background', bg_color)
|
|
|
|
pg.setConfigOption('foreground', line_color)
|
2017-09-06 18:02:09 +02:00
|
|
|
|
2017-09-11 13:27:32 +02:00
|
|
|
settings = QSettings()
|
|
|
|
settings.setValue('style', stylename)
|
|
|
|
settings.sync()
|
|
|
|
|
2016-09-22 14:12:24 +02:00
|
|
|
@property
|
|
|
|
def metadata(self):
|
|
|
|
return self._metadata
|
|
|
|
|
|
|
|
@metadata.setter
|
|
|
|
def metadata(self, value):
|
|
|
|
self._metadata = value
|
|
|
|
|
2018-02-22 11:28:46 +01:00
|
|
|
def updateFilteroptions(self):
|
|
|
|
filter_info = readFilterInformation(self._inputs)
|
|
|
|
p_filter = filter_info['P']
|
|
|
|
s_filter = filter_info['S']
|
|
|
|
self.filteroptions = {'P': FilterOptions(p_filter['filtertype'],
|
|
|
|
p_filter['freq'],
|
|
|
|
p_filter['order']),
|
|
|
|
'S': FilterOptions(s_filter['filtertype'],
|
|
|
|
s_filter['freq'],
|
|
|
|
s_filter['order'])}
|
|
|
|
|
2014-12-01 12:37:52 +01:00
|
|
|
def updateFileMenu(self):
|
2018-08-14 14:21:32 +02:00
|
|
|
settings = QSettings()
|
2014-12-01 12:37:52 +01:00
|
|
|
self.fileMenu.clear()
|
2018-08-14 14:21:32 +02:00
|
|
|
self.recentProjectsMenu = self.fileMenu.addMenu('Recent Projects')
|
2015-01-20 13:44:35 +01:00
|
|
|
for action in self.fileMenuActions[:-1]:
|
|
|
|
if action is None:
|
|
|
|
self.fileMenu.addSeparator()
|
|
|
|
else:
|
|
|
|
self.fileMenu.addAction(action)
|
|
|
|
try:
|
2015-02-13 11:15:48 +01:00
|
|
|
current = self.data.getID()
|
2015-01-20 13:44:35 +01:00
|
|
|
except AttributeError:
|
|
|
|
current = None
|
2014-12-01 12:37:52 +01:00
|
|
|
recentEvents = []
|
2016-05-27 11:25:47 +02:00
|
|
|
for eventID in self.recentfiles:
|
2014-12-01 12:37:52 +01:00
|
|
|
fname = fnConstructor(eventID)
|
|
|
|
if eventID != current and QFile.exists(fname):
|
|
|
|
recentEvents.append(eventID)
|
2015-02-13 11:16:20 +01:00
|
|
|
recentEvents.reverse()
|
2016-05-27 11:25:47 +02:00
|
|
|
self.recentfiles = recentEvents[0:5]
|
2015-02-13 11:16:20 +01:00
|
|
|
settings.setValue()
|
2014-12-01 12:37:52 +01:00
|
|
|
if recentEvents:
|
|
|
|
for i, eventID in enumerate(recentEvents):
|
|
|
|
fname = fnConstructor(eventID)
|
2015-07-07 10:31:39 +02:00
|
|
|
action = QAction(self.windowIcon(),
|
2014-12-01 12:37:52 +01:00
|
|
|
"&{0} {1}".format(i + 1,
|
|
|
|
QFileInfo(fname).fileName()),
|
|
|
|
self)
|
|
|
|
action.setData(fname)
|
2015-02-16 10:28:28 +01:00
|
|
|
self.connect(action, Signal("triggered()"),
|
2016-05-27 11:25:47 +02:00
|
|
|
self.load_data)
|
2014-12-01 12:37:52 +01:00
|
|
|
self.fileMenu.addAction(action)
|
|
|
|
self.fileMenu.addSeparator()
|
|
|
|
self.fileMenu.addAction(self.fileMenuActions[-1])
|
|
|
|
|
2018-08-14 14:21:32 +02:00
|
|
|
# add recent projects
|
|
|
|
recentProjects = settings.value('recentProjects', [])
|
2018-08-15 15:39:43 +02:00
|
|
|
if not type(recentProjects) == list:
|
|
|
|
recentProjects = [recentProjects]
|
2018-08-14 14:21:32 +02:00
|
|
|
for project in reversed(recentProjects):
|
|
|
|
action = self.createAction(self, project,
|
2018-08-15 15:39:43 +02:00
|
|
|
lambda fnm=project: self.loadProject(fnm),
|
|
|
|
None, None)
|
2018-08-14 14:21:32 +02:00
|
|
|
|
|
|
|
self.recentProjectsMenu.addAction(action)
|
|
|
|
|
2016-09-08 15:31:23 +02:00
|
|
|
@property
|
|
|
|
def inputs(self):
|
|
|
|
return self._inputs
|
|
|
|
|
2018-07-16 14:09:06 +02:00
|
|
|
@staticmethod
|
|
|
|
def getRoot():
|
2015-07-18 16:11:20 +02:00
|
|
|
settings = QSettings()
|
|
|
|
return settings.value("data/dataRoot")
|
|
|
|
|
2016-05-27 11:25:47 +02:00
|
|
|
def load_loc(self, fname=None):
|
2017-09-18 10:41:27 +02:00
|
|
|
self.load_data(fname, loc=True)
|
2016-05-27 11:25:47 +02:00
|
|
|
|
|
|
|
def load_pilotevent(self):
|
2016-06-02 09:39:01 +02:00
|
|
|
filt = "PILOT location files (*LOC*.mat)"
|
2016-05-31 17:36:00 +02:00
|
|
|
caption = "Select PILOT location file"
|
2016-05-27 11:25:47 +02:00
|
|
|
fn_loc = QFileDialog().getOpenFileName(self, caption=caption,
|
2017-07-14 16:25:59 +02:00
|
|
|
filter=filt, dir=self.getRoot())
|
2016-05-27 12:53:34 +02:00
|
|
|
fn_loc = fn_loc[0]
|
|
|
|
loc_dir = os.path.split(fn_loc)[0]
|
2016-06-02 09:39:01 +02:00
|
|
|
filt = "PILOT phases files (*PHASES*.mat)"
|
2016-05-27 11:25:47 +02:00
|
|
|
caption = "Select PILOT phases file"
|
|
|
|
fn_phases = QFileDialog().getOpenFileName(self, caption=caption,
|
2017-07-14 16:25:59 +02:00
|
|
|
filter=filt, dir=loc_dir)
|
2016-05-27 12:53:34 +02:00
|
|
|
fn_phases = fn_phases[0]
|
2016-03-29 11:26:08 +02:00
|
|
|
|
2016-05-27 11:25:47 +02:00
|
|
|
fname_dict = dict(phasfn=fn_phases, locfn=fn_loc)
|
2017-09-18 10:41:27 +02:00
|
|
|
self.load_data(fname_dict)
|
2016-05-27 11:25:47 +02:00
|
|
|
|
2017-08-09 14:15:50 +02:00
|
|
|
def load_multiple_data(self):
|
2015-09-03 13:21:46 +02:00
|
|
|
if not self.okToContinue():
|
2015-09-18 09:54:29 +02:00
|
|
|
return
|
2017-07-14 16:25:59 +02:00
|
|
|
refresh = False
|
2017-06-22 16:30:22 +02:00
|
|
|
events = self.project.eventlist
|
2019-07-01 17:24:06 +02:00
|
|
|
sld = SingleTextLineDialog(label='Specify file extension: ', default_text='.xml')
|
|
|
|
if not sld.exec_():
|
2019-05-29 10:37:16 +02:00
|
|
|
return
|
2019-07-01 17:24:06 +02:00
|
|
|
fext = sld.lineEdit.text()
|
2021-03-30 08:28:31 +02:00
|
|
|
# fext = '.xml'
|
2017-06-22 16:30:22 +02:00
|
|
|
for event in events:
|
|
|
|
path = event.path
|
2018-07-16 14:21:41 +02:00
|
|
|
eventname = path.split('/')[-1] # or event.pylot_id
|
2017-07-14 16:25:59 +02:00
|
|
|
filename = os.path.join(path, 'PyLoT_' + eventname + fext)
|
2017-06-22 16:30:22 +02:00
|
|
|
if os.path.isfile(filename):
|
|
|
|
self.load_data(filename, draw=False, event=event, overwrite=True)
|
2017-07-14 16:25:59 +02:00
|
|
|
refresh = True
|
2017-06-22 16:30:22 +02:00
|
|
|
if not refresh:
|
|
|
|
return
|
2017-06-26 12:19:06 +02:00
|
|
|
if self.get_current_event().pylot_picks:
|
2017-06-27 13:54:13 +02:00
|
|
|
self.refreshEvents()
|
2018-07-16 13:51:18 +02:00
|
|
|
self.fill_eventbox()
|
2017-06-22 16:30:22 +02:00
|
|
|
self.setDirty(True)
|
|
|
|
|
2017-08-09 14:15:50 +02:00
|
|
|
def load_data(self, fname=None, loc=False, draw=True, event=None, overwrite=False):
|
2017-06-22 16:30:22 +02:00
|
|
|
if not overwrite:
|
|
|
|
if not self.okToContinue():
|
|
|
|
return
|
2014-12-01 12:37:52 +01:00
|
|
|
if fname is None:
|
2015-09-17 17:45:10 +02:00
|
|
|
action = self.sender()
|
|
|
|
if isinstance(action, QAction):
|
2016-05-27 11:25:47 +02:00
|
|
|
fname = self.filename_from_action(action)
|
2017-06-26 14:10:40 +02:00
|
|
|
if not fname:
|
|
|
|
return
|
2017-06-27 13:54:13 +02:00
|
|
|
if not event:
|
|
|
|
event = self.get_current_event()
|
|
|
|
data = Data(self, event)
|
2017-06-27 15:06:28 +02:00
|
|
|
try:
|
2017-07-14 13:30:54 +02:00
|
|
|
data_new = Data(self, evtdata=str(fname))
|
2019-08-23 11:30:16 +02:00
|
|
|
# MP MP commented because adding several picks might cause inconsistencies
|
2019-03-12 15:14:00 +01:00
|
|
|
data = data_new
|
2021-03-30 08:28:31 +02:00
|
|
|
# data += data_new
|
2017-06-27 15:06:28 +02:00
|
|
|
except ValueError:
|
|
|
|
qmb = QMessageBox(self, icon=QMessageBox.Question,
|
|
|
|
text='Warning: Missmatch in event identifiers {} and {}. Continue?'.format(
|
|
|
|
data_new.get_evt_data().resource_id,
|
|
|
|
data.get_evt_data().resource_id),
|
|
|
|
windowTitle='PyLoT - Load data warning')
|
|
|
|
qmb.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
|
|
|
|
qmb.setDefaultButton(QMessageBox.No)
|
|
|
|
ret = qmb.exec_()
|
|
|
|
if ret == qmb.Yes:
|
|
|
|
data_new.setNew()
|
|
|
|
data += data_new
|
|
|
|
else:
|
|
|
|
return
|
|
|
|
|
2017-06-27 13:54:13 +02:00
|
|
|
self.data = data
|
2018-07-12 16:36:56 +02:00
|
|
|
message = 'Loading event info from file {}.'.format(fname)
|
|
|
|
print(message)
|
|
|
|
self.update_status(message)
|
2016-06-02 09:39:01 +02:00
|
|
|
if not loc:
|
2019-08-23 11:30:16 +02:00
|
|
|
self.updatePicks(event=event)
|
2017-06-22 16:30:22 +02:00
|
|
|
if draw:
|
2017-08-09 14:15:50 +02:00
|
|
|
if self.get_current_event().pylot_picks or self.get_current_event().pylot_autopicks:
|
2017-06-27 13:54:13 +02:00
|
|
|
self.refreshEvents()
|
2017-06-22 16:30:22 +02:00
|
|
|
self.setDirty(True)
|
2014-11-26 08:46:16 +01:00
|
|
|
|
2016-05-27 11:25:47 +02:00
|
|
|
def add_recentfile(self, event):
|
|
|
|
self.recentfiles.insert(0, event)
|
2015-08-31 13:37:18 +02:00
|
|
|
|
2017-09-07 16:07:43 +02:00
|
|
|
def set_button_border_color(self, button, color=None):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Set background color of a button.
|
|
|
|
button: type = QtGui.QAbstractButton
|
|
|
|
color: type = QtGui.QColor or type = str (RGBA)
|
|
|
|
'''
|
2017-05-19 10:56:27 +02:00
|
|
|
if type(color) == QtGui.QColor:
|
2017-09-07 16:07:43 +02:00
|
|
|
button.setStyleSheet({'QPushButton{background-color:transparent}'})
|
2017-05-19 10:56:27 +02:00
|
|
|
palette = button.palette()
|
|
|
|
role = button.backgroundRole()
|
|
|
|
palette.setColor(role, color)
|
|
|
|
button.setPalette(palette)
|
|
|
|
button.setAutoFillBackground(True)
|
2017-09-07 16:07:43 +02:00
|
|
|
elif type(color) == str:
|
|
|
|
button.setStyleSheet('QPushButton{border-color: %s}'
|
2018-07-16 14:21:41 +02:00
|
|
|
'QPushButton:checked{background-color: rgba%s}' % (color, color))
|
2017-09-07 16:07:43 +02:00
|
|
|
elif type(color) == tuple:
|
|
|
|
button.setStyleSheet('QPushButton{border-color: rgba%s}'
|
|
|
|
'QPushButton:checked{background-color: rgba%s}' % (str(color), str(color)))
|
|
|
|
elif not color:
|
|
|
|
button.setStyleSheet(self.orig_parent._style['stylesheet'])
|
2017-05-19 10:56:27 +02:00
|
|
|
|
2015-01-22 16:41:52 +01:00
|
|
|
def getWFFnames(self):
|
2015-01-26 21:11:53 +01:00
|
|
|
try:
|
2016-09-02 14:21:59 +02:00
|
|
|
evt = self.get_data().get_evt_data()
|
2017-06-26 12:19:06 +02:00
|
|
|
if evt.pylot_picks:
|
|
|
|
for pick in evt.pylot_picks:
|
2015-01-29 08:48:25 +01:00
|
|
|
try:
|
|
|
|
if pick.waveform_id is not None:
|
|
|
|
fname = pick.waveform_id.getSEEDstring()
|
|
|
|
if fname not in self.fnames:
|
|
|
|
self.fnames.append(fname)
|
|
|
|
except:
|
|
|
|
continue
|
2015-01-26 21:11:53 +01:00
|
|
|
else:
|
|
|
|
if self.dataStructure:
|
|
|
|
searchPath = self.dataStructure.expandDataPath()
|
2015-02-17 13:17:01 +01:00
|
|
|
fnames = QFileDialog.getOpenFileNames(self,
|
2015-06-11 10:07:21 +02:00
|
|
|
"Select waveform "
|
|
|
|
"files:",
|
|
|
|
dir=searchPath)
|
2015-02-20 08:37:21 +01:00
|
|
|
self.fnames = fnames[0]
|
2015-02-13 11:19:10 +01:00
|
|
|
|
2015-01-29 08:48:25 +01:00
|
|
|
else:
|
2015-02-17 13:17:01 +01:00
|
|
|
raise DatastructureError('not specified')
|
2016-03-22 10:49:06 +01:00
|
|
|
if not self.fnames:
|
|
|
|
return None
|
2015-01-29 08:48:25 +01:00
|
|
|
return self.fnames
|
2015-09-25 15:06:59 +02:00
|
|
|
except DatastructureError as e:
|
|
|
|
print(e)
|
2017-05-30 10:17:07 +02:00
|
|
|
if not self._props:
|
|
|
|
self._props = PropertiesDlg(self, infile=self.infile)
|
|
|
|
|
2017-05-29 18:03:31 +02:00
|
|
|
if self._props.exec_() == QDialog.Accepted:
|
2015-01-29 08:48:25 +01:00
|
|
|
return self.getWFFnames()
|
|
|
|
else:
|
|
|
|
return
|
2015-01-22 16:41:52 +01:00
|
|
|
|
2017-05-24 14:12:41 +02:00
|
|
|
def getWFFnames_from_eventbox(self, eventbox=None):
|
|
|
|
'''
|
|
|
|
Return waveform filenames from event in eventbox.
|
|
|
|
'''
|
2018-04-04 14:57:54 +02:00
|
|
|
# TODO: add dataStructure class for obspyDMT here, this is just a workaround!
|
|
|
|
eventpath = self.get_current_event_path(eventbox)
|
|
|
|
basepath = eventpath.split(os.path.basename(eventpath))[0]
|
2017-04-18 16:24:26 +02:00
|
|
|
if self.dataStructure:
|
2018-04-05 15:33:40 +02:00
|
|
|
if not eventpath:
|
2017-06-19 16:30:39 +02:00
|
|
|
return
|
2018-04-05 15:33:40 +02:00
|
|
|
fnames = [os.path.join(eventpath, f) for f in os.listdir(eventpath)]
|
2017-04-18 16:24:26 +02:00
|
|
|
else:
|
|
|
|
raise DatastructureError('not specified')
|
2017-05-15 12:03:53 +02:00
|
|
|
return fnames
|
|
|
|
|
2018-07-16 14:09:06 +02:00
|
|
|
@staticmethod
|
|
|
|
def getPhaseID(phase):
|
2017-08-21 14:59:28 +02:00
|
|
|
return identifyPhaseID(phase)
|
2017-08-15 10:02:46 +02:00
|
|
|
|
2017-05-24 14:12:41 +02:00
|
|
|
def get_current_event(self, eventbox=None):
|
|
|
|
'''
|
2017-09-21 15:36:17 +02:00
|
|
|
Return event (type PyLoT.Event) currently selected in eventbox.
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
2017-05-16 13:41:35 +02:00
|
|
|
if not eventbox:
|
|
|
|
eventbox = self.eventBox
|
2018-07-31 09:41:48 +02:00
|
|
|
path = eventbox.currentText().split('*')[0]
|
2017-06-23 12:04:26 +02:00
|
|
|
return self.project.getEventFromPath(path)
|
2017-05-15 12:03:53 +02:00
|
|
|
|
2017-05-19 10:56:27 +02:00
|
|
|
def get_current_event_path(self, eventbox=None):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
2017-09-21 15:36:17 +02:00
|
|
|
Return event path of event (type PyLoT.Event) currently selected in eventbox.
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
2017-06-19 16:30:39 +02:00
|
|
|
event = self.get_current_event(eventbox)
|
|
|
|
if event:
|
|
|
|
return event.path
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-06-19 11:28:11 +02:00
|
|
|
def get_current_event_name(self, eventbox=None):
|
|
|
|
'''
|
2017-09-21 15:36:17 +02:00
|
|
|
Return event path of event (type PyLoT.Event) currently selected in eventbox.
|
2017-06-19 11:28:11 +02:00
|
|
|
'''
|
2017-06-19 16:30:39 +02:00
|
|
|
path = self.get_current_event_path(eventbox)
|
|
|
|
if path:
|
|
|
|
return path.split('/')[-1]
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-05-15 12:03:53 +02:00
|
|
|
def getLastEvent(self):
|
|
|
|
return self.recentfiles[0]
|
2017-04-18 16:24:26 +02:00
|
|
|
|
|
|
|
def add_events(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Creates and adds events by user selection of event folders to GUI.
|
|
|
|
'''
|
2017-04-18 16:24:26 +02:00
|
|
|
if not self.project:
|
2017-06-21 13:24:45 +02:00
|
|
|
self.createNewProject()
|
2017-04-18 16:24:26 +02:00
|
|
|
ed = getExistingDirectories(self, 'Select event directories...')
|
|
|
|
if ed.exec_():
|
2019-04-03 15:08:36 +02:00
|
|
|
eventlist = [event for event in ed.selectedFiles() if not event.endswith('EVENTS-INFO')]
|
2018-04-04 14:57:54 +02:00
|
|
|
basepath = eventlist[0].split(os.path.basename(eventlist[0]))[0]
|
2019-03-06 11:25:58 +01:00
|
|
|
# small hack: if a file "eventlist.txt" is found in the basepath use only those events specified inside
|
|
|
|
eventlist_file = os.path.join(basepath, 'eventlist.txt')
|
|
|
|
if os.path.isfile(eventlist_file):
|
|
|
|
with open(eventlist_file, 'r') as infile:
|
2021-03-30 08:28:31 +02:00
|
|
|
eventlist_subset = [os.path.join(basepath, filename.split('\n')[0]) for filename in
|
|
|
|
infile.readlines()]
|
2019-03-06 11:25:58 +01:00
|
|
|
msg = 'Found file "eventlist.txt" in database path. WILL ONLY USE SELECTED EVENTS out of {} events ' \
|
|
|
|
'contained in this subset'
|
|
|
|
print(msg.format(len(eventlist_subset)))
|
|
|
|
eventlist = [eventname for eventname in eventlist if eventname in eventlist_subset]
|
2018-04-04 14:57:54 +02:00
|
|
|
if check_obspydmt_structure(basepath):
|
2018-07-11 09:41:58 +02:00
|
|
|
print('Recognized obspyDMT structure in selected files. Settings Datastructure to ObspyDMT')
|
|
|
|
self.dataStructure = DATASTRUCTURE['obspyDMT']()
|
2018-04-04 14:57:54 +02:00
|
|
|
eventlist = check_all_obspy(eventlist)
|
|
|
|
else:
|
2018-07-17 16:04:20 +02:00
|
|
|
print('Setting Datastructure to PILOT')
|
2018-07-11 09:41:58 +02:00
|
|
|
self.dataStructure = DATASTRUCTURE['PILOT']()
|
2018-04-04 14:57:54 +02:00
|
|
|
eventlist = check_all_pylot(eventlist)
|
2017-06-21 11:43:01 +02:00
|
|
|
if not eventlist:
|
2017-11-23 11:37:04 +01:00
|
|
|
print('No events found! Expected structure for event folders: [eEVID.DOY.YR],\n'
|
2018-04-04 14:57:54 +02:00
|
|
|
' e.g. eventID=1, doy=2, yr=2016: e0001.002.16 or obspyDMT database')
|
2017-06-21 11:43:01 +02:00
|
|
|
return
|
2017-04-18 16:24:26 +02:00
|
|
|
else:
|
|
|
|
return
|
|
|
|
if not self.project:
|
|
|
|
print('No project found.')
|
|
|
|
return
|
2017-07-14 16:25:59 +02:00
|
|
|
|
|
|
|
# get path from first event in list and split them
|
2017-06-21 11:43:01 +02:00
|
|
|
path = eventlist[0]
|
|
|
|
try:
|
2017-07-14 16:25:59 +02:00
|
|
|
system_name = platform.system()
|
|
|
|
if system_name in ["Linux", "Darwin"]:
|
|
|
|
dirs = {
|
|
|
|
'database': path.split('/')[-2],
|
|
|
|
'datapath': path.split('/')[-3],
|
|
|
|
'rootpath': '/' + os.path.join(*path.split('/')[:-3])
|
|
|
|
}
|
|
|
|
elif system_name == "Windows":
|
|
|
|
rootpath = path.split('/')[:-3]
|
|
|
|
rootpath[0] += '/'
|
|
|
|
dirs = {
|
|
|
|
'database': path.split('/')[-2],
|
|
|
|
'datapath': path.split('/')[-3],
|
|
|
|
'rootpath': os.path.join(*rootpath)
|
|
|
|
}
|
2017-06-21 11:43:01 +02:00
|
|
|
except Exception as e:
|
|
|
|
dirs = {
|
2017-06-21 13:24:45 +02:00
|
|
|
'database': '',
|
|
|
|
'datapath': '',
|
2017-06-21 11:43:01 +02:00
|
|
|
'rootpath': ''
|
2017-07-14 16:25:59 +02:00
|
|
|
}
|
2017-06-21 11:43:01 +02:00
|
|
|
print('Warning: Could not automatically init folder structure. ({})'.format(e))
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-06-26 18:02:07 +02:00
|
|
|
settings = QSettings()
|
|
|
|
settings.setValue("data/dataRoot", dirs['rootpath'])
|
|
|
|
settings.sync()
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-06-21 11:43:01 +02:00
|
|
|
if not self.project.eventlist:
|
2017-07-14 16:25:59 +02:00
|
|
|
# init parameter object
|
2017-06-21 11:43:01 +02:00
|
|
|
self.setParameter(show=False)
|
2017-07-14 16:25:59 +02:00
|
|
|
# hide all parameter (show all needed parameter later)
|
2017-06-21 11:43:01 +02:00
|
|
|
self.paraBox.hide_parameter()
|
|
|
|
for directory in dirs.keys():
|
2017-07-14 16:25:59 +02:00
|
|
|
# set parameter
|
2017-06-21 11:43:01 +02:00
|
|
|
box = self.paraBox.boxes[directory]
|
|
|
|
self.paraBox.setValue(box, dirs[directory])
|
2017-07-14 16:25:59 +02:00
|
|
|
# show needed parameter in box
|
2017-06-21 11:43:01 +02:00
|
|
|
self.paraBox.show_parameter(directory)
|
2017-06-22 11:03:24 +02:00
|
|
|
dirs_box = self.paraBox.get_groupbox_dialog('Directories')
|
2017-06-21 11:43:01 +02:00
|
|
|
if not dirs_box.exec_():
|
|
|
|
return
|
2017-06-21 13:24:45 +02:00
|
|
|
self.project.rootpath = dirs['rootpath']
|
|
|
|
else:
|
|
|
|
if hasattr(self.project, 'rootpath'):
|
|
|
|
if not self.project.rootpath == dirs['rootpath']:
|
|
|
|
QMessageBox.warning(self, "PyLoT Warning",
|
|
|
|
'Rootpath missmatch to current project!')
|
|
|
|
return
|
|
|
|
else:
|
2017-07-14 16:25:59 +02:00
|
|
|
self.project.rootpath = dirs['rootpath']
|
|
|
|
|
2017-04-18 16:24:26 +02:00
|
|
|
self.project.add_eventlist(eventlist)
|
|
|
|
self.init_events()
|
2017-05-31 10:56:45 +02:00
|
|
|
self.setDirty(True)
|
2017-04-18 16:24:26 +02:00
|
|
|
|
2017-07-18 16:07:08 +02:00
|
|
|
def remove_event(self, event):
|
|
|
|
qmb = QMessageBox(self, icon=QMessageBox.Question,
|
|
|
|
text='Are you sure you want to delete event {}?'.format(event.pylot_id))
|
|
|
|
qmb.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
|
|
|
|
qmb.setDefaultButton(QMessageBox.Yes)
|
|
|
|
ret = qmb.exec_()
|
|
|
|
if not ret == qmb.Yes:
|
|
|
|
return
|
|
|
|
self.project.remove_event(event)
|
|
|
|
self.init_events(True)
|
2017-07-18 15:27:52 +02:00
|
|
|
|
2018-07-16 14:09:06 +02:00
|
|
|
@staticmethod
|
|
|
|
def createEventBox():
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Eventbox generator.
|
|
|
|
'''
|
2017-04-20 14:03:26 +02:00
|
|
|
qcb = QComboBox()
|
|
|
|
palette = qcb.palette()
|
2017-05-12 15:37:57 +02:00
|
|
|
# change highlight color:
|
|
|
|
# palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Highlight,
|
|
|
|
# QtGui.QBrush(QtGui.QColor(0,0,127,127)))
|
|
|
|
# palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Highlight,
|
|
|
|
# QtGui.QBrush(QtGui.QColor(0,0,127,127)))
|
2017-04-20 14:03:26 +02:00
|
|
|
qcb.setPalette(palette)
|
|
|
|
return qcb
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-04-18 16:24:26 +02:00
|
|
|
def init_events(self, new=False):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Initiate GUI widgets in case of changed or newly added events.
|
|
|
|
'''
|
2017-04-18 16:24:26 +02:00
|
|
|
nitems = self.eventBox.count()
|
2018-03-05 17:45:07 +01:00
|
|
|
is_data = self.data_check()
|
|
|
|
if len(self.project.eventlist) == 0 or not is_data:
|
2017-04-18 16:24:26 +02:00
|
|
|
print('No events to init.')
|
2017-04-19 15:31:08 +02:00
|
|
|
self.clearWaveformDataPlot()
|
2018-03-05 17:45:07 +01:00
|
|
|
if not is_data:
|
|
|
|
new_path, modifypath = self.user_modify_path('Event folders not found! ')
|
|
|
|
if modifypath:
|
|
|
|
self.modify_project_path(new_path)
|
|
|
|
self.init_events(True)
|
|
|
|
self.setDirty(True)
|
2017-04-18 16:24:26 +02:00
|
|
|
return
|
|
|
|
self.eventBox.setEnabled(True)
|
2017-05-31 15:41:25 +02:00
|
|
|
self.fill_eventbox()
|
2017-04-18 16:24:26 +02:00
|
|
|
if new:
|
|
|
|
self.eventBox.setCurrentIndex(0)
|
|
|
|
else:
|
|
|
|
self.eventBox.setCurrentIndex(nitems)
|
2017-04-19 16:05:45 +02:00
|
|
|
self.refreshEvents()
|
2017-04-20 12:05:34 +02:00
|
|
|
tabindex = self.tabs.currentIndex()
|
2017-04-18 16:24:26 +02:00
|
|
|
|
2018-03-05 17:45:07 +01:00
|
|
|
def user_modify_path(self, reason=''):
|
|
|
|
dialog = QtGui.QInputDialog(parent=self)
|
|
|
|
new_path, executed = dialog.getText(self, 'Change Project rootpath',
|
2018-07-16 14:21:41 +02:00
|
|
|
'{}Rename project path {}:'.format(reason, self.project.rootpath))
|
2018-03-05 17:45:07 +01:00
|
|
|
return new_path, executed
|
|
|
|
|
2018-03-05 16:51:06 +01:00
|
|
|
def data_check(self):
|
|
|
|
paths_exist = [os.path.exists(event.path) for event in self.project.eventlist]
|
|
|
|
if all(paths_exist):
|
|
|
|
return True
|
2020-07-16 12:35:18 +02:00
|
|
|
elif not any(paths_exist):
|
|
|
|
return False
|
2018-03-05 16:51:06 +01:00
|
|
|
else:
|
|
|
|
info_str = ''
|
2021-01-14 14:04:50 +01:00
|
|
|
new_eventlist = []
|
2021-01-14 10:13:51 +01:00
|
|
|
i = 0
|
2018-03-05 16:51:06 +01:00
|
|
|
for event, path_exists in zip(self.project.eventlist, paths_exist):
|
2020-07-16 12:35:18 +02:00
|
|
|
if not path_exists:
|
|
|
|
info_str += '\n{} exists: {}'.format(event.path, path_exists)
|
2021-01-14 10:13:51 +01:00
|
|
|
else:
|
2021-01-14 14:04:50 +01:00
|
|
|
new_eventlist.append(self.project.eventlist[i])
|
|
|
|
i += 1
|
|
|
|
if len(new_eventlist) > 0:
|
|
|
|
# adopt changes in event listings
|
|
|
|
self.project.eventlist = new_eventlist
|
2018-03-05 16:51:06 +01:00
|
|
|
print('Unable to find certain event paths:{}'.format(info_str))
|
2021-01-14 10:13:51 +01:00
|
|
|
print("Removed these event paths from project eventlist!")
|
2020-07-16 12:35:18 +02:00
|
|
|
return True
|
2018-03-05 16:51:06 +01:00
|
|
|
|
2018-03-05 17:45:07 +01:00
|
|
|
def modify_project_path(self, new_rootpath):
|
|
|
|
self.project.rootpath = new_rootpath
|
|
|
|
for event in self.project.eventlist:
|
|
|
|
event.rootpath = new_rootpath
|
|
|
|
event.path = os.path.join(event.rootpath, event.datapath, event.database, event.pylot_id)
|
|
|
|
event.path = event.path.replace('\\', '/')
|
|
|
|
event.path = event.path.replace('//', '/')
|
|
|
|
|
2017-05-31 15:41:25 +02:00
|
|
|
def fill_eventbox(self, event=None, eventBox=None, select_events='all'):
|
2017-05-12 15:37:57 +02:00
|
|
|
'''
|
2017-05-24 14:12:41 +02:00
|
|
|
(Re)fill the selected eventBox (type = QtGui.QComboBox).
|
|
|
|
|
2017-05-12 15:37:57 +02:00
|
|
|
:param: select_events, can be 'all', 'ref'
|
|
|
|
:type: str
|
|
|
|
'''
|
2017-08-22 16:43:09 +02:00
|
|
|
|
|
|
|
# if pick widget is open, refresh tooltips as well
|
2017-09-18 14:44:18 +02:00
|
|
|
if self.apw:
|
2017-08-22 16:43:09 +02:00
|
|
|
self.apw.refresh_tooltips()
|
2017-08-31 14:31:33 +02:00
|
|
|
if hasattr(self, 'cmpw'):
|
|
|
|
self.cmpw.refresh_tooltips()
|
2017-08-22 16:43:09 +02:00
|
|
|
|
2017-05-16 17:26:42 +02:00
|
|
|
if not eventBox:
|
|
|
|
eventBox = self.eventBox
|
2017-07-14 16:25:59 +02:00
|
|
|
index = eventBox.currentIndex()
|
|
|
|
tv = QtGui.QTableView()
|
2017-04-21 15:46:57 +02:00
|
|
|
header = tv.horizontalHeader()
|
|
|
|
header.setResizeMode(QtGui.QHeaderView.ResizeToContents)
|
|
|
|
header.setStretchLastSection(True)
|
|
|
|
header.hide()
|
|
|
|
tv.verticalHeader().hide()
|
|
|
|
tv.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2018-06-19 11:28:41 +02:00
|
|
|
current_event = self.get_current_event()
|
|
|
|
|
2017-05-12 15:37:57 +02:00
|
|
|
eventBox.setView(tv)
|
|
|
|
eventBox.clear()
|
|
|
|
model = eventBox.model()
|
2017-07-14 16:25:59 +02:00
|
|
|
plmax = 0
|
|
|
|
# set maximum length of path string
|
2017-04-21 15:46:57 +02:00
|
|
|
for event in self.project.eventlist:
|
|
|
|
pl = len(event.path)
|
|
|
|
if pl > plmax:
|
2017-07-14 16:25:59 +02:00
|
|
|
plmax = pl
|
2017-04-21 15:46:57 +02:00
|
|
|
|
2017-05-16 14:20:32 +02:00
|
|
|
for id, event in enumerate(self.project.eventlist):
|
2017-04-20 14:03:26 +02:00
|
|
|
event_path = event.path
|
2017-08-22 11:53:19 +02:00
|
|
|
phaseErrors = {'P': self._inputs['timeerrorsP'],
|
|
|
|
'S': self._inputs['timeerrorsS']}
|
|
|
|
|
|
|
|
ma_props = {'manual': event.pylot_picks,
|
|
|
|
'auto': event.pylot_autopicks}
|
|
|
|
ma_count = {'manual': 0,
|
|
|
|
'auto': 0}
|
2018-07-16 13:51:18 +02:00
|
|
|
ma_count_total = {'manual': 0,
|
|
|
|
'auto': 0}
|
2017-08-22 11:53:19 +02:00
|
|
|
|
|
|
|
for ma in ma_props.keys():
|
|
|
|
if ma_props[ma]:
|
|
|
|
for picks in ma_props[ma].values():
|
|
|
|
for phasename, pick in picks.items():
|
2017-08-23 11:51:59 +02:00
|
|
|
if not type(pick) in [dict, AttribDict]:
|
|
|
|
continue
|
2018-07-16 17:56:17 +02:00
|
|
|
if pick.get('spe'):
|
2017-08-22 11:53:19 +02:00
|
|
|
ma_count[ma] += 1
|
2018-07-16 13:51:18 +02:00
|
|
|
ma_count_total[ma] += 1
|
2017-08-22 11:53:19 +02:00
|
|
|
|
2017-04-20 14:03:26 +02:00
|
|
|
event_ref = event.isRefEvent()
|
|
|
|
event_test = event.isTestEvent()
|
|
|
|
|
2020-10-07 10:37:41 +02:00
|
|
|
time = lat = lon = depth = localmag = momentmag = None
|
2018-04-24 15:37:15 +02:00
|
|
|
if len(event.origins) == 1:
|
|
|
|
origin = event.origins[0]
|
2018-07-16 14:21:41 +02:00
|
|
|
time = origin.time + 0 # add 0 because there was an exception for time = 0s
|
2018-04-24 15:37:15 +02:00
|
|
|
lat = origin.latitude
|
|
|
|
lon = origin.longitude
|
|
|
|
depth = origin.depth
|
2021-02-01 16:03:23 +01:00
|
|
|
if len(event.magnitudes) > 1:
|
2020-09-28 15:11:23 +02:00
|
|
|
moment_magnitude = event.magnitudes[0]
|
|
|
|
local_magnitude = event.magnitudes[1]
|
|
|
|
localmag = '%4.1f' % local_magnitude.mag
|
2021-03-30 08:28:31 +02:00
|
|
|
momentmag = '%4.1f' % moment_magnitude.mag
|
2018-04-24 15:37:15 +02:00
|
|
|
|
2017-05-16 13:41:35 +02:00
|
|
|
# text = '{path:{plen}} | manual: [{p:3d}] | auto: [{a:3d}]'
|
|
|
|
# text = text.format(path=event_path,
|
|
|
|
# plen=plmax,
|
|
|
|
# p=event_npicks,
|
|
|
|
# a=event_nautopicks)
|
2017-04-21 15:46:57 +02:00
|
|
|
|
2018-07-31 09:41:48 +02:00
|
|
|
event_str = '{path:{plen}}'.format(path=event_path, plen=plmax)
|
|
|
|
if event.dirty:
|
|
|
|
event_str += '*'
|
|
|
|
item_path = QtGui.QStandardItem(event_str)
|
2018-04-24 15:37:15 +02:00
|
|
|
item_time = QtGui.QStandardItem('{}'.format(time))
|
|
|
|
item_lat = QtGui.QStandardItem('{}'.format(lat))
|
|
|
|
item_lon = QtGui.QStandardItem('{}'.format(lon))
|
|
|
|
item_depth = QtGui.QStandardItem('{}'.format(depth))
|
2020-09-28 15:11:23 +02:00
|
|
|
item_localmag = QtGui.QStandardItem('{}'.format(localmag))
|
|
|
|
item_momentmag = QtGui.QStandardItem('{}'.format(momentmag))
|
2018-07-16 13:51:18 +02:00
|
|
|
item_nmp = QtGui.QStandardItem('{}({})'.format(ma_count['manual'], ma_count_total['manual']))
|
2017-04-21 15:46:57 +02:00
|
|
|
item_nmp.setIcon(self.manupicksicon_small)
|
2018-07-16 13:51:18 +02:00
|
|
|
item_nap = QtGui.QStandardItem('{}({})'.format(ma_count['auto'], ma_count_total['auto']))
|
2017-04-21 15:46:57 +02:00
|
|
|
item_nap.setIcon(self.autopicksicon_small)
|
2017-07-14 16:25:59 +02:00
|
|
|
item_ref = QtGui.QStandardItem() # str(event_ref))
|
|
|
|
item_test = QtGui.QStandardItem() # str(event_test))
|
2017-04-20 14:03:26 +02:00
|
|
|
if event_ref:
|
2017-09-07 16:07:43 +02:00
|
|
|
item_ref.setBackground(self._ref_test_colors['ref'])
|
2017-04-20 14:03:26 +02:00
|
|
|
if event_test:
|
2017-09-07 16:07:43 +02:00
|
|
|
item_test.setBackground(self._ref_test_colors['test'])
|
2017-04-21 15:46:57 +02:00
|
|
|
item_notes = QtGui.QStandardItem(event.notes)
|
|
|
|
|
|
|
|
openIcon = self.style().standardIcon(QStyle.SP_DirOpenIcon)
|
|
|
|
item_path.setIcon(openIcon)
|
|
|
|
# if ref: set different color e.g.
|
|
|
|
# if event_ref:
|
2017-05-19 10:56:27 +02:00
|
|
|
# item.setBackground(self._colors['ref'])
|
2017-04-21 15:46:57 +02:00
|
|
|
# if event_test:
|
2017-05-19 10:56:27 +02:00
|
|
|
# itemt.setBackground(self._colors['test'])
|
2017-04-21 15:46:57 +02:00
|
|
|
# item.setForeground(QtGui.QColor('black'))
|
|
|
|
# font = item.font()
|
|
|
|
# font.setPointSize(10)
|
|
|
|
# item.setFont(font)
|
|
|
|
# item2.setForeground(QtGui.QColor('black'))
|
|
|
|
# item2.setFont(font)
|
2018-04-24 15:37:15 +02:00
|
|
|
itemlist = [item_path, item_time, item_lat, item_lon, item_depth,
|
2020-09-28 15:11:23 +02:00
|
|
|
item_localmag, item_momentmag, item_nmp, item_nap, item_ref, item_test, item_notes]
|
2018-04-24 15:37:15 +02:00
|
|
|
for item in itemlist:
|
|
|
|
item.setTextAlignment(Qt.AlignCenter)
|
2018-04-25 13:48:06 +02:00
|
|
|
if event_test and select_events == 'ref' or self.isEmpty(event_path):
|
2017-05-12 15:37:57 +02:00
|
|
|
for item in itemlist:
|
|
|
|
item.setEnabled(False)
|
2018-06-19 11:28:41 +02:00
|
|
|
|
2018-07-16 14:21:41 +02:00
|
|
|
# item color
|
2018-06-19 11:28:41 +02:00
|
|
|
self.setItemColor(itemlist, id, event, current_event)
|
|
|
|
|
2017-04-21 15:46:57 +02:00
|
|
|
model.appendRow(itemlist)
|
2018-07-31 09:41:48 +02:00
|
|
|
if not event.path == self.eventBox.itemText(id).split('*')[0].strip():
|
2017-05-16 13:41:35 +02:00
|
|
|
message = ('Path missmatch creating eventbox.\n'
|
|
|
|
'{} unequal {}.'
|
2017-05-16 14:20:32 +02:00
|
|
|
.format(event.path, self.eventBox.itemText(id)))
|
2017-05-16 13:41:35 +02:00
|
|
|
raise ValueError(message)
|
2017-07-14 16:25:59 +02:00
|
|
|
# not working with obspy events
|
|
|
|
# eventBox.setItemData(id, event)
|
2017-05-12 15:37:57 +02:00
|
|
|
eventBox.setCurrentIndex(index)
|
2017-05-19 10:56:27 +02:00
|
|
|
self.refreshRefTestButtons()
|
2017-04-20 14:03:26 +02:00
|
|
|
|
2018-04-25 13:48:06 +02:00
|
|
|
def isEmpty(self, event_path):
|
|
|
|
wf_stat = {True: 'processed',
|
|
|
|
False: 'raw',
|
|
|
|
None: None}
|
|
|
|
|
2018-04-25 14:01:05 +02:00
|
|
|
# self.data.processed is only None for PyLoT datastructure, else True or False
|
2018-04-25 13:48:06 +02:00
|
|
|
wf_dir = wf_stat[self.data.processed]
|
|
|
|
if wf_dir is not None:
|
2018-04-25 14:04:31 +02:00
|
|
|
wf_path = os.path.join(event_path, wf_dir)
|
|
|
|
if wf_dir is 'processed' and not os.path.exists(wf_path):
|
|
|
|
wf_path = os.path.join(event_path, 'raw')
|
|
|
|
else:
|
|
|
|
wf_path = event_path
|
|
|
|
if not os.path.exists(wf_path):
|
|
|
|
return True
|
|
|
|
return not bool(os.listdir(wf_path))
|
2018-04-25 13:48:06 +02:00
|
|
|
|
2016-05-27 11:25:47 +02:00
|
|
|
def filename_from_action(self, action):
|
|
|
|
if action.data() is None:
|
|
|
|
filt = "Supported file formats" \
|
|
|
|
" (*.mat *.qml *.xml *.kor *.evt)"
|
|
|
|
caption = "Open an event file"
|
2016-06-02 09:39:01 +02:00
|
|
|
fname = QFileDialog().getOpenFileName(self, caption=caption,
|
|
|
|
filter=filt,
|
2017-06-26 14:08:17 +02:00
|
|
|
dir=self.get_current_event_path())
|
2016-05-27 11:25:47 +02:00
|
|
|
fname = fname[0]
|
|
|
|
else:
|
|
|
|
fname = str(action.data().toString())
|
|
|
|
return fname
|
|
|
|
|
2016-09-08 09:54:43 +02:00
|
|
|
def getEventFileName(self, type='manual'):
|
|
|
|
if self.get_fnames(type) is None:
|
|
|
|
self.set_fname(self.get_data().getEventFileName(), type)
|
|
|
|
return self.get_fnames(type)
|
2015-07-18 16:11:20 +02:00
|
|
|
|
2020-10-15 10:02:02 +02:00
|
|
|
def saveData(self, event=None, directory=None, outformats=['.xml', '.cnv', '.obs', '_focmec.in', '.pha']):
|
2017-08-07 16:25:48 +02:00
|
|
|
'''
|
|
|
|
Save event data to directory with specified output formats.
|
|
|
|
:param event: PyLoT Event, if not set current event will be used
|
|
|
|
:param directory: output directory, if not set default event path will be used
|
2017-08-07 16:53:21 +02:00
|
|
|
:param outformats: str/list of output formats
|
2017-08-07 16:25:48 +02:00
|
|
|
:return:
|
|
|
|
'''
|
2021-03-30 16:39:44 +02:00
|
|
|
if not event:
|
2017-08-07 16:25:48 +02:00
|
|
|
event = self.get_current_event()
|
2017-08-07 16:53:21 +02:00
|
|
|
if not type(outformats) == list:
|
|
|
|
outformats = [outformats]
|
2021-03-30 08:28:31 +02:00
|
|
|
|
2021-03-30 16:39:44 +02:00
|
|
|
def getSavePath(event, directory, outformats):
|
2017-06-30 17:20:18 +02:00
|
|
|
if not directory:
|
2017-08-07 16:25:48 +02:00
|
|
|
title = 'Save event data as {} to directory ...'.format(outformats)
|
|
|
|
directory = QFileDialog.getExistingDirectory(self,
|
|
|
|
title,
|
|
|
|
event.path)
|
2017-06-30 17:20:18 +02:00
|
|
|
else:
|
2017-08-07 16:25:48 +02:00
|
|
|
directory = event.path
|
2015-08-31 13:37:18 +02:00
|
|
|
|
2017-08-07 16:25:48 +02:00
|
|
|
filename = 'PyLoT_' + event.pylot_id
|
|
|
|
eventfn = os.path.join(directory, filename)
|
2015-08-31 13:37:18 +02:00
|
|
|
|
2017-08-07 16:25:48 +02:00
|
|
|
return eventfn
|
|
|
|
|
|
|
|
fbasename = getSavePath(event, directory, outformats)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-07-11 16:23:23 +02:00
|
|
|
uppererrorP = self._inputs['timeerrorsP']
|
|
|
|
uppererrorS = self._inputs['timeerrorsS']
|
2021-03-30 16:39:44 +02:00
|
|
|
# Inserted to prevent Bug in Eventlist
|
|
|
|
self.get_data().setEvtData(event)
|
2017-06-20 16:23:54 +02:00
|
|
|
try:
|
2017-08-07 16:25:48 +02:00
|
|
|
self.get_data().applyEVTData(event, typ='event') # getPicks())
|
2017-06-20 16:23:54 +02:00
|
|
|
except OverwriteError:
|
2017-07-14 16:25:59 +02:00
|
|
|
self.get_data().resetPicks()
|
2017-08-07 16:25:48 +02:00
|
|
|
return self.saveData(event, directory, outformats)
|
2018-07-10 11:01:34 +02:00
|
|
|
fcheck = ['auto', 'manual', 'origins', 'magnitude']
|
2017-08-07 16:25:48 +02:00
|
|
|
|
|
|
|
saved_as = str()
|
|
|
|
for outformat in outformats:
|
|
|
|
try:
|
|
|
|
self.get_data().exportEvent(fbasename, outformat, fcheck=fcheck,
|
|
|
|
upperErrors=[uppererrorP[3], uppererrorS[3]])
|
|
|
|
saved_as += str(outformat) + ' '
|
|
|
|
except TypeError:
|
2018-07-16 14:21:41 +02:00
|
|
|
print('WARNING: Format: {} not yet implemented'.format(outformat))
|
2017-08-17 15:38:13 +02:00
|
|
|
self.get_data().setEvtData(event)
|
2017-08-07 16:25:48 +02:00
|
|
|
|
|
|
|
msg = 'Event {} saved as {} in format(s) {}'.format(event.pylot_id, fbasename, saved_as.strip())
|
|
|
|
self.update_status(msg)
|
|
|
|
print(msg)
|
2018-07-31 09:41:48 +02:00
|
|
|
event.dirty = False
|
|
|
|
self.fill_eventbox()
|
2014-12-08 10:26:14 +01:00
|
|
|
return True
|
2014-11-28 11:15:49 +01:00
|
|
|
|
2018-07-17 10:53:37 +02:00
|
|
|
def exportEvents(self, outformats=['.xml'], events='all'):
|
|
|
|
if events == 'all':
|
|
|
|
events = self.project.eventlist
|
|
|
|
assert type(events) == list, 'Wrong input type: {}'.format(type(events))
|
|
|
|
for event in events:
|
2018-07-31 09:41:48 +02:00
|
|
|
if not event.dirty:
|
|
|
|
continue
|
2017-08-07 16:25:48 +02:00
|
|
|
self.get_data().setEvtData(event)
|
2019-05-29 15:58:37 +02:00
|
|
|
# save deleted picks to json file
|
|
|
|
try:
|
|
|
|
self.dump_deleted_picks(event.path)
|
|
|
|
except Exception as e:
|
|
|
|
print('WARNING! Could not save information on deleted picks {}. Reason: {}'.format(event.path, e))
|
2020-01-14 13:57:12 +01:00
|
|
|
print(traceback.format_exc())
|
2018-06-27 14:20:11 +02:00
|
|
|
try:
|
|
|
|
self.saveData(event, event.path, outformats)
|
2018-07-31 09:41:48 +02:00
|
|
|
event.dirty = False
|
2018-06-27 14:20:11 +02:00
|
|
|
except Exception as e:
|
|
|
|
print('WARNING! Could not save event {}. Reason: {}'.format(event.path, e))
|
2018-07-31 09:41:48 +02:00
|
|
|
self.fill_eventbox()
|
2017-08-07 16:25:48 +02:00
|
|
|
|
2017-08-07 16:41:50 +02:00
|
|
|
def enableSaveEventAction(self):
|
|
|
|
self.saveEventAction.setEnabled(True)
|
2017-05-31 15:41:25 +02:00
|
|
|
|
2017-08-07 16:41:50 +02:00
|
|
|
def disableSaveEventAction(self):
|
|
|
|
self.saveEventAction.setEnabled(False)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-04-06 13:16:28 +02:00
|
|
|
def getinfile(self):
|
|
|
|
return self.infile
|
|
|
|
|
2015-02-07 09:03:03 +01:00
|
|
|
def getComponent(self):
|
|
|
|
return self.dispComponent
|
2014-03-28 22:26:15 +01:00
|
|
|
|
2015-07-07 14:21:11 +02:00
|
|
|
def setComponent(self, component):
|
|
|
|
self.dispComponent = component
|
|
|
|
|
2017-08-09 14:15:50 +02:00
|
|
|
def get_data(self):
|
2014-11-13 11:27:52 +01:00
|
|
|
return self.data
|
|
|
|
|
2015-11-30 09:50:47 +01:00
|
|
|
def getPicks(self, type='manual'):
|
2017-05-31 15:41:25 +02:00
|
|
|
if type == 'manual':
|
|
|
|
return self.get_current_event().getPicks()
|
|
|
|
if type == 'auto':
|
|
|
|
return self.get_current_event().getAutopicks()
|
2015-07-07 10:32:56 +02:00
|
|
|
|
2015-11-30 09:50:47 +01:00
|
|
|
def getPicksOnStation(self, station, type='manual'):
|
2015-07-07 10:32:56 +02:00
|
|
|
try:
|
2015-11-30 09:50:47 +01:00
|
|
|
return self.getPicks(type)[station]
|
2015-07-07 10:32:56 +02:00
|
|
|
except KeyError:
|
|
|
|
return None
|
|
|
|
|
2016-06-06 14:10:46 +02:00
|
|
|
def comparePicks(self):
|
2017-08-31 11:16:13 +02:00
|
|
|
comparisons = {}
|
|
|
|
eventdict = {}
|
|
|
|
for event in self.project.eventlist:
|
|
|
|
if not self.comparable[event.pylot_id]:
|
|
|
|
continue
|
|
|
|
autopicks = excludeQualityClasses(event.getAutopicks(), [4],
|
2017-08-21 15:33:19 +02:00
|
|
|
self._inputs['timeerrorsP'], self._inputs['timeerrorsS'])
|
2017-08-31 11:16:13 +02:00
|
|
|
manupicks = excludeQualityClasses(event.getPicks(), [4],
|
2017-08-21 15:33:19 +02:00
|
|
|
self._inputs['timeerrorsP'], self._inputs['timeerrorsS'])
|
|
|
|
co = Comparison(auto=autopicks, manu=manupicks)
|
2017-08-31 11:16:13 +02:00
|
|
|
comparisons[event.pylot_id] = co
|
|
|
|
eventdict[event.pylot_id] = event
|
|
|
|
if len(eventdict) < 1:
|
|
|
|
return
|
2017-08-31 14:31:33 +02:00
|
|
|
|
|
|
|
# init event selection options for autopick
|
2018-07-16 14:21:41 +02:00
|
|
|
self.compareoptions = [('tune events', self.get_ref_events, self._style['ref']['rgba']),
|
|
|
|
('test events', self.get_test_events, self._style['test']['rgba']),
|
|
|
|
('all (picked) events', self.get_manu_picked_events, None)]
|
2017-08-31 14:31:33 +02:00
|
|
|
|
|
|
|
self.cmpw = CompareEventsWidget(self, self.compareoptions, eventdict, comparisons)
|
|
|
|
self.cmpw.start.connect(self.compareMulti)
|
|
|
|
self.cmpw.refresh_tooltips()
|
|
|
|
self.cmpw.show()
|
|
|
|
|
2018-01-30 16:16:41 +01:00
|
|
|
def pickQualities(self):
|
|
|
|
return
|
|
|
|
|
2017-08-31 14:31:33 +02:00
|
|
|
def compareMulti(self):
|
2017-09-18 10:41:27 +02:00
|
|
|
if not self.compareoptions:
|
|
|
|
return
|
2017-09-12 12:09:59 +02:00
|
|
|
for key, func, color in self.compareoptions:
|
2017-08-31 14:31:33 +02:00
|
|
|
if self.cmpw.rb_dict[key].isChecked():
|
|
|
|
# if radio button is checked break for loop and use func
|
|
|
|
break
|
|
|
|
eventlist = func()
|
|
|
|
# use only events comparable
|
|
|
|
eventlist_overlap = [event for event in eventlist if self.comparable[event.pylot_id]]
|
|
|
|
compare_widget = self.buildMultiCompareWidget(eventlist_overlap)
|
|
|
|
compare_widget.show()
|
|
|
|
|
|
|
|
def buildMultiCompareWidget(self, eventlist):
|
|
|
|
global_comparison = Comparison(eventlist=eventlist)
|
|
|
|
compare_widget = ComparisonWidget(global_comparison, self)
|
2017-09-12 13:30:51 +02:00
|
|
|
for events_name, rb in self.cmpw.rb_dict.items():
|
|
|
|
if rb.isChecked():
|
|
|
|
break
|
|
|
|
compare_widget.setWindowTitle('Histograms for {}'.format(events_name))
|
2017-08-31 14:31:33 +02:00
|
|
|
compare_widget.hideToolbar()
|
|
|
|
compare_widget.setHistboxChecked(True)
|
|
|
|
return compare_widget
|
2016-06-06 14:10:46 +02:00
|
|
|
|
2015-03-04 11:52:04 +01:00
|
|
|
def getPlotWidget(self):
|
2017-04-19 15:31:08 +02:00
|
|
|
return self.dataPlot
|
2014-11-13 11:27:52 +01:00
|
|
|
|
2015-06-11 10:07:21 +02:00
|
|
|
@staticmethod
|
2017-06-08 14:09:01 +02:00
|
|
|
def getWFID(ycoord):
|
2016-05-31 15:53:23 +02:00
|
|
|
try:
|
|
|
|
statID = int(round(ycoord))
|
|
|
|
except TypeError as e:
|
|
|
|
if 'a float is required' in e.message:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
raise e
|
2015-03-11 12:05:52 +01:00
|
|
|
|
|
|
|
return statID
|
2015-03-09 11:21:33 +01:00
|
|
|
|
2018-08-06 16:03:54 +02:00
|
|
|
def getStationIDs(self, station):
|
|
|
|
wfIDs = []
|
2015-07-07 10:39:01 +02:00
|
|
|
for wfID in self.getPlotWidget().getPlotDict().keys():
|
2018-08-06 16:03:54 +02:00
|
|
|
actual_station = self.getPlotWidget().getPlotDict()[wfID].split('.')[1]
|
2015-07-07 10:39:01 +02:00
|
|
|
if station == actual_station:
|
2018-08-06 16:03:54 +02:00
|
|
|
wfIDs.append(wfID)
|
|
|
|
return wfIDs
|
2015-07-07 10:39:01 +02:00
|
|
|
|
2016-05-31 17:27:59 +02:00
|
|
|
def getStime(self):
|
2018-01-12 10:07:14 +01:00
|
|
|
if self.get_data():
|
|
|
|
return full_range(self.get_data().getWFData())[0]
|
2016-05-31 17:27:59 +02:00
|
|
|
|
2015-02-23 14:38:26 +01:00
|
|
|
def addActions(self, target, actions):
|
2015-01-22 16:41:52 +01:00
|
|
|
for action in actions:
|
2015-01-20 13:48:19 +01:00
|
|
|
if action is None:
|
2015-02-23 14:38:26 +01:00
|
|
|
target.addSeparator()
|
2015-01-20 13:48:19 +01:00
|
|
|
else:
|
2015-02-23 14:38:26 +01:00
|
|
|
target.addAction(action)
|
2015-01-20 13:48:19 +01:00
|
|
|
|
2014-12-01 12:41:13 +01:00
|
|
|
def okToContinue(self):
|
|
|
|
if self.dirty:
|
2017-07-14 16:25:59 +02:00
|
|
|
qmb = QMessageBox(self, icon=QMessageBox.Question,
|
|
|
|
text='Do you wish to save changes in the current project?')
|
2017-05-31 11:48:16 +02:00
|
|
|
qmb.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel)
|
|
|
|
qmb.setDefaultButton(QMessageBox.Save)
|
|
|
|
ret = qmb.exec_()
|
|
|
|
if ret == qmb.Save:
|
|
|
|
return self.saveProject()
|
|
|
|
elif ret == qmb.Cancel:
|
|
|
|
return False
|
2014-12-01 12:41:13 +01:00
|
|
|
return True
|
2014-03-28 05:25:46 +01:00
|
|
|
|
2017-05-19 10:56:27 +02:00
|
|
|
def enableRefTestButtons(self, bool):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Enable/disable reference and test event selection buttons.
|
|
|
|
'''
|
2017-07-14 16:25:59 +02:00
|
|
|
self.ref_event_button.setEnabled(bool)
|
2017-05-19 10:56:27 +02:00
|
|
|
self.test_event_button.setEnabled(bool)
|
|
|
|
|
|
|
|
def refreshRefTestButtons(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Refresh state of reference and test event selection buttons depending on current event.
|
|
|
|
'''
|
2017-05-19 10:56:27 +02:00
|
|
|
event = self.get_current_event()
|
|
|
|
if event:
|
|
|
|
self.ref_event_button.setChecked(event.isRefEvent())
|
|
|
|
self.test_event_button.setChecked(event.isTestEvent())
|
2017-06-26 12:19:06 +02:00
|
|
|
self.enableRefTestButtons(bool(self.get_current_event().pylot_picks))
|
2017-05-19 10:56:27 +02:00
|
|
|
return
|
|
|
|
self.ref_event_button.setChecked(False)
|
|
|
|
self.test_event_button.setChecked(False)
|
2017-05-24 14:12:41 +02:00
|
|
|
self.enableRefTestButtons(False)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-05-19 10:56:27 +02:00
|
|
|
def toggleRef(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Toggle ref/test buttons when reference button gets clicked.
|
|
|
|
'''
|
2017-05-19 10:56:27 +02:00
|
|
|
ref = self.ref_event_button.isChecked()
|
|
|
|
self.test_event_button.setChecked(False)
|
|
|
|
self.get_current_event().setTestEvent(False)
|
|
|
|
self.get_current_event().setRefEvent(ref)
|
|
|
|
self.refreshTabs()
|
|
|
|
if self.tap:
|
|
|
|
self.tap.fill_eventbox()
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-05-19 10:56:27 +02:00
|
|
|
def toggleTest(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Toggle ref/test buttons when test button gets clicked.
|
|
|
|
'''
|
2017-05-19 10:56:27 +02:00
|
|
|
test = self.test_event_button.isChecked()
|
|
|
|
self.ref_event_button.setChecked(False)
|
|
|
|
self.get_current_event().setRefEvent(False)
|
|
|
|
self.get_current_event().setTestEvent(test)
|
2017-07-14 16:25:59 +02:00
|
|
|
self.refreshTabs()
|
2017-05-19 10:56:27 +02:00
|
|
|
if self.tap:
|
|
|
|
self.tap.fill_eventbox()
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2018-01-10 16:54:26 +01:00
|
|
|
def checkEventButtons(self):
|
|
|
|
if self.eventBox.currentIndex() == 0:
|
|
|
|
prev_state = False
|
|
|
|
else:
|
|
|
|
prev_state = True
|
|
|
|
if self.eventBox.currentIndex() == len(self.project.eventlist) - 1:
|
|
|
|
next_state = False
|
|
|
|
else:
|
|
|
|
next_state = True
|
|
|
|
self.previous_button.setEnabled(prev_state)
|
|
|
|
self.next_button.setEnabled(next_state)
|
|
|
|
|
|
|
|
def previous_event(self):
|
|
|
|
self.eventBox.setCurrentIndex(self.eventBox.currentIndex() - 1)
|
|
|
|
self.eventBox.activated.emit(-1)
|
|
|
|
|
|
|
|
def next_event(self):
|
|
|
|
self.eventBox.setCurrentIndex(self.eventBox.currentIndex() + 1)
|
|
|
|
self.eventBox.activated.emit(+1)
|
|
|
|
|
2017-04-19 16:05:45 +02:00
|
|
|
def refreshEvents(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Refresh GUI when events get changed.
|
|
|
|
'''
|
|
|
|
# Attribute _eventChanged refers to change in first _eventChanged[0]
|
|
|
|
# and second _eventChanged[1] main tabs.
|
|
|
|
# E.g. plotting is not necessary when changing event in second tab and
|
|
|
|
# array_map refresh is not necessary when changing event in waveform plot tab,
|
|
|
|
# but gets necessary when switching from one to another after changing an event.
|
2017-04-20 17:06:36 +02:00
|
|
|
self._eventChanged = [True, True]
|
2018-01-10 16:54:26 +01:00
|
|
|
self.checkEventButtons()
|
2017-04-19 16:05:45 +02:00
|
|
|
self.refreshTabs()
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-04-19 15:31:08 +02:00
|
|
|
def refreshTabs(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Refresh main tabs depending on change of the current event in first/second tab.
|
|
|
|
'''
|
|
|
|
# Logical problem appearing somewhere when calling this function:
|
|
|
|
# Loading an existing project from array_tab leads to two calls of newWF
|
|
|
|
# which will read in data input twice. Therefore current tab is changed to 0
|
|
|
|
# in loadProject before calling this function.
|
2020-01-14 13:57:12 +01:00
|
|
|
self.fill_eventbox()
|
2017-07-14 16:25:59 +02:00
|
|
|
plotted = False
|
2017-07-18 15:27:52 +02:00
|
|
|
if self.tabs.currentIndex() == 2:
|
|
|
|
self.init_event_table()
|
|
|
|
self.refreshRefTestButtons()
|
2017-08-03 09:41:54 +02:00
|
|
|
|
2017-05-24 14:12:41 +02:00
|
|
|
# only refresh first/second tab when an event was changed.
|
2017-04-20 17:06:36 +02:00
|
|
|
if self._eventChanged[0] or self._eventChanged[1]:
|
2017-05-19 10:56:27 +02:00
|
|
|
event = self.get_current_event()
|
2017-06-06 15:51:06 +02:00
|
|
|
if not event:
|
|
|
|
return
|
2017-05-24 14:12:41 +02:00
|
|
|
# if current tab is waveformPlot-tab and the data in this tab was not yet refreshed
|
|
|
|
if self.tabs.currentIndex() == 0:
|
|
|
|
if self._eventChanged[0]:
|
2017-04-20 17:06:36 +02:00
|
|
|
if hasattr(self.project, 'eventlist'):
|
|
|
|
if len(self.project.eventlist) > 0:
|
2017-05-24 14:12:41 +02:00
|
|
|
self.newWF()
|
|
|
|
# keep track whether event was already plotted
|
2017-07-14 16:25:59 +02:00
|
|
|
plotted = True
|
2017-05-24 14:12:41 +02:00
|
|
|
# if current tab is array_map-tab and the data in this tab was not yet refreshed
|
|
|
|
if self.tabs.currentIndex() == 1:
|
|
|
|
if self._eventChanged[1]:
|
|
|
|
self.refresh_array_map()
|
|
|
|
if not plotted and self._eventChanged[0]:
|
2018-06-08 14:18:28 +02:00
|
|
|
# newWF(plot=False) = load data without plotting
|
2017-05-24 14:12:41 +02:00
|
|
|
self.newWF(plot=False)
|
2019-03-06 11:25:58 +01:00
|
|
|
self.update_obspy_dmt()
|
|
|
|
self.refresh_array_map()
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2018-06-08 14:18:28 +02:00
|
|
|
def newWF(self, event=None, plot=True):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Load new data and plot if necessary.
|
|
|
|
'''
|
2017-05-29 16:21:36 +02:00
|
|
|
self.loadWaveformDataThread(plot=plot)
|
2017-05-17 13:25:41 +02:00
|
|
|
if plot:
|
|
|
|
self._eventChanged[0] = False
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-05-29 16:21:36 +02:00
|
|
|
def loadWaveformDataThread(self, plot=True, load=True):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
2017-05-29 16:21:36 +02:00
|
|
|
Generates a modal thread to load waveform data and
|
|
|
|
call modal plot thread method when finished.
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
2017-05-29 16:21:36 +02:00
|
|
|
if load:
|
2018-06-08 15:01:05 +02:00
|
|
|
self.prepareLoadWaveformData()
|
2017-07-14 11:09:18 +02:00
|
|
|
self.wfd_thread = Thread(self, self.loadWaveformData,
|
2017-09-18 14:57:48 +02:00
|
|
|
progressText='Reading data input...',
|
|
|
|
pb_widget=self.mainProgressBarWidget)
|
2017-05-29 16:21:36 +02:00
|
|
|
if load and plot:
|
2017-07-14 11:09:18 +02:00
|
|
|
self.wfd_thread.finished.connect(self.plotWaveformDataThread)
|
2017-05-29 16:21:36 +02:00
|
|
|
|
|
|
|
if load:
|
2017-07-14 11:09:18 +02:00
|
|
|
self.wfd_thread.start()
|
2017-05-29 16:21:36 +02:00
|
|
|
|
|
|
|
if plot and not load:
|
|
|
|
self.plotWaveformDataThread()
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2018-06-08 15:01:05 +02:00
|
|
|
def prepareLoadWaveformData(self):
|
|
|
|
self.fnames = self.getWFFnames_from_eventbox()
|
|
|
|
self.fnames_syn = []
|
|
|
|
eventpath = self.get_current_event_path()
|
|
|
|
basepath = eventpath.split(os.path.basename(eventpath))[0]
|
2018-06-19 10:35:34 +02:00
|
|
|
self.obspy_dmt = check_obspydmt_structure(basepath)
|
|
|
|
self.dataPlot.activateObspyDMToptions(self.obspy_dmt)
|
|
|
|
if self.obspy_dmt:
|
2018-06-08 15:01:05 +02:00
|
|
|
self.prepareObspyDMT_data(eventpath)
|
|
|
|
|
2015-02-16 10:27:32 +01:00
|
|
|
def loadWaveformData(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Load waveform data corresponding to current selected event.
|
|
|
|
'''
|
2017-04-18 16:24:26 +02:00
|
|
|
# if self.fnames and self.okToContinue():
|
|
|
|
# self.setDirty(True)
|
|
|
|
# ans = self.data.setWFData(self.fnames)
|
|
|
|
# elif self.fnames is None and self.okToContinue():
|
|
|
|
# ans = self.data.setWFData(self.getWFFnames())
|
|
|
|
# else:
|
|
|
|
# ans = False
|
2018-06-08 14:18:28 +02:00
|
|
|
|
2019-12-17 16:24:32 +01:00
|
|
|
settings = QSettings()
|
|
|
|
curr_event = self.get_current_event()
|
|
|
|
if len(curr_event.origins) > 0:
|
|
|
|
origin_time = curr_event.origins[0].time
|
|
|
|
tstart = settings.value('tstart') if get_None(settings.value('tstart')) else 0
|
|
|
|
tstop = settings.value('tstop') if get_None(settings.value('tstop')) else 0
|
2019-12-17 16:54:07 +01:00
|
|
|
tstart = origin_time + float(tstart)
|
|
|
|
tstop = origin_time + float(tstop)
|
2019-12-17 16:24:32 +01:00
|
|
|
else:
|
|
|
|
tstart = None
|
|
|
|
tstop = None
|
|
|
|
|
2018-01-12 10:07:14 +01:00
|
|
|
self.data.setWFData(self.fnames,
|
2018-06-08 14:18:28 +02:00
|
|
|
self.fnames_syn,
|
2018-01-12 10:07:14 +01:00
|
|
|
checkRotated=True,
|
2019-12-17 16:24:32 +01:00
|
|
|
metadata=self.metadata,
|
|
|
|
tstart=tstart,
|
2021-03-30 08:28:31 +02:00
|
|
|
tstop=tstop, )
|
2018-06-08 14:18:28 +02:00
|
|
|
|
|
|
|
def prepareObspyDMT_data(self, eventpath):
|
2018-06-08 15:01:05 +02:00
|
|
|
qcbox_processed = self.dataPlot.qcombo_processed
|
2018-06-08 14:27:43 +02:00
|
|
|
qcheckb_syn = self.dataPlot.syn_checkbox
|
2018-06-08 14:18:28 +02:00
|
|
|
qcbox_processed.setEnabled(False)
|
2018-06-08 14:27:43 +02:00
|
|
|
qcheckb_syn.setEnabled(False)
|
2018-06-08 14:18:28 +02:00
|
|
|
for fpath in os.listdir(eventpath):
|
|
|
|
fpath = fpath.split('/')[-1]
|
|
|
|
if 'syngine' in fpath:
|
|
|
|
eventpath_syn = os.path.join(eventpath, fpath)
|
2018-06-08 14:27:43 +02:00
|
|
|
qcheckb_syn.setEnabled(True)
|
|
|
|
if self.dataPlot.syn_checkbox.isChecked():
|
|
|
|
self.fnames_syn = [os.path.join(eventpath_syn, filename) for filename in os.listdir(eventpath_syn)]
|
2018-06-08 14:18:28 +02:00
|
|
|
if 'processed' in fpath:
|
|
|
|
qcbox_processed.setEnabled(True)
|
2018-06-08 15:01:05 +02:00
|
|
|
if qcbox_processed.isEnabled():
|
|
|
|
wftype = qcbox_processed.currentText()
|
|
|
|
else:
|
|
|
|
wftype = 'raw'
|
|
|
|
qcbox_processed.setCurrentIndex(qcbox_processed.findText(wftype))
|
2018-06-08 14:18:28 +02:00
|
|
|
eventpath_dmt = os.path.join(eventpath, wftype)
|
|
|
|
self.fnames = [os.path.join(eventpath_dmt, filename) for filename in os.listdir(eventpath_dmt)]
|
|
|
|
|
|
|
|
# def setWFstatus(self):
|
|
|
|
# '''
|
|
|
|
# show status of current data, can be either 'raw' or 'processed'
|
|
|
|
# :param status:
|
|
|
|
# :return:
|
|
|
|
# '''
|
|
|
|
# status = self.data.processed
|
|
|
|
# wf_stat_color = {True: 'green',
|
|
|
|
# False: 'black',
|
|
|
|
# None: None}
|
|
|
|
# wf_stat = {True: 'processed',
|
|
|
|
# False: 'raw',
|
|
|
|
# None: None}
|
|
|
|
# self.dataPlot.setQCboxItem(wf_stat[status])
|
2018-04-23 17:00:09 +02:00
|
|
|
|
2018-04-05 16:02:53 +02:00
|
|
|
def check_plot_quantity(self):
|
2018-04-06 14:35:24 +02:00
|
|
|
"""
|
|
|
|
Check the amount of samples to be plotted and ask user to reduce the amount if it is too large.
|
|
|
|
:rtype: None
|
|
|
|
"""
|
2018-04-05 16:02:53 +02:00
|
|
|
settings = QSettings()
|
2018-04-13 10:56:52 +02:00
|
|
|
nth_sample = int(settings.value("nth_sample")) if settings.value("nth_sample") else 1
|
|
|
|
npts_max = 1e7
|
2018-04-05 16:02:53 +02:00
|
|
|
npts = self.get_npts_to_plot()
|
2019-04-04 11:48:44 +02:00
|
|
|
if npts == 0:
|
|
|
|
return False
|
2018-07-16 14:21:41 +02:00
|
|
|
npts2plot = npts / nth_sample
|
2018-04-05 16:02:53 +02:00
|
|
|
if npts2plot < npts_max:
|
2018-04-18 16:44:33 +02:00
|
|
|
settings.setValue('large_dataset', False)
|
|
|
|
else:
|
|
|
|
settings.setValue('large_dataset', True)
|
|
|
|
self.update_status('Dataset is very large. Using fast plotting method (MIN/MAX)', 10000)
|
|
|
|
settings.sync()
|
2019-04-04 11:48:44 +02:00
|
|
|
return True
|
2018-04-18 16:21:57 +02:00
|
|
|
# nth_sample_new = int(np.ceil(npts/npts_max))
|
|
|
|
# message = "You are about to plot a huge dataset with {npts} datapoints. With a current setting of " \
|
|
|
|
# "nth_sample = {nth_sample} a total of {npts2plot} points will be plotted which is more " \
|
|
|
|
# "than the maximum setting of {npts_max}. " \
|
|
|
|
# "PyLoT recommends to raise nth_sample from {nth_sample} to {nth_sample_new}. Do you want "\
|
|
|
|
# "to change nth_sample to {nth_sample_new} now?"
|
|
|
|
#
|
|
|
|
# ans = QMessageBox.question(self, self.tr("Optimize plot performance..."),
|
|
|
|
# self.tr(message.format(npts=npts,
|
|
|
|
# nth_sample=nth_sample,
|
|
|
|
# npts_max=npts_max,
|
|
|
|
# nth_sample_new=nth_sample_new,
|
|
|
|
# npts2plot=npts2plot)),
|
|
|
|
# QMessageBox.Yes | QMessageBox.No,
|
|
|
|
# QMessageBox.Yes)
|
|
|
|
# if ans == QMessageBox.Yes:
|
|
|
|
# settings.setValue("nth_sample", nth_sample_new)
|
|
|
|
# settings.sync()
|
2018-04-05 16:02:53 +02:00
|
|
|
|
|
|
|
def get_npts_to_plot(self):
|
2019-04-04 11:48:44 +02:00
|
|
|
if not hasattr(self.data, 'wfdata'):
|
|
|
|
return 0
|
2018-04-05 16:02:53 +02:00
|
|
|
return sum(trace.stats.npts for trace in self.data.getWFData())
|
|
|
|
|
2017-04-19 15:31:08 +02:00
|
|
|
def connectWFplotEvents(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Connect signals refering to WF-Dataplot (select station, tutor_user, scrolling)
|
|
|
|
'''
|
2017-06-07 17:05:48 +02:00
|
|
|
if self.pg:
|
2017-06-08 14:09:01 +02:00
|
|
|
self.connect_pg()
|
2017-06-07 17:05:48 +02:00
|
|
|
else:
|
|
|
|
self.connect_mpl()
|
|
|
|
|
2017-06-08 14:09:01 +02:00
|
|
|
def connect_pg(self):
|
2017-06-08 16:14:37 +02:00
|
|
|
self.poS_id = self.dataPlot.plotWidget.scene().sigMouseClicked.connect(self.pickOnStation)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-06-07 17:05:48 +02:00
|
|
|
def connect_mpl(self):
|
2017-04-19 15:31:08 +02:00
|
|
|
if not self.poS_id:
|
|
|
|
self.poS_id = self.dataPlot.mpl_connect('button_press_event',
|
|
|
|
self.pickOnStation)
|
|
|
|
if not self.ae_id:
|
|
|
|
self.ae_id = self.dataPlot.mpl_connect('axes_enter_event',
|
|
|
|
lambda event: self.tutor_user())
|
|
|
|
|
2017-05-22 10:53:20 +02:00
|
|
|
if not self.scroll_id:
|
|
|
|
self.scroll_id = self.dataPlot.mpl_connect('scroll_event',
|
|
|
|
self.scrollPlot)
|
|
|
|
|
2017-04-19 15:31:08 +02:00
|
|
|
def disconnectWFplotEvents(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Disconnect all signals refering to WF-Dataplot (select station, tutor_user, scrolling)
|
|
|
|
'''
|
2017-06-07 17:05:48 +02:00
|
|
|
if self.pg:
|
2017-06-08 14:09:01 +02:00
|
|
|
self.disconnect_pg()
|
2017-06-07 17:05:48 +02:00
|
|
|
else:
|
|
|
|
self.disconnect_mpl()
|
|
|
|
|
2017-06-08 14:09:01 +02:00
|
|
|
def disconnect_pg(self):
|
|
|
|
if self.poS_id:
|
2017-06-12 10:42:44 +02:00
|
|
|
try:
|
|
|
|
self.dataPlot.plotWidget.scene().sigMouseClicked.disconnect()
|
|
|
|
except:
|
|
|
|
pass
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-06-07 17:05:48 +02:00
|
|
|
def disconnect_mpl(self):
|
2017-04-19 15:31:08 +02:00
|
|
|
if self.poS_id:
|
|
|
|
self.dataPlot.mpl_disconnect(self.poS_id)
|
|
|
|
if self.ae_id:
|
|
|
|
self.dataPlot.mpl_disconnect(self.ae_id)
|
2017-05-22 10:53:20 +02:00
|
|
|
if self.scroll_id:
|
2017-05-30 11:45:53 +02:00
|
|
|
self.dataPlot.mpl_disconnect(self.scroll_id)
|
2017-04-19 15:31:08 +02:00
|
|
|
self.poS_id = None
|
|
|
|
self.ae_id = None
|
2017-05-22 10:53:20 +02:00
|
|
|
self.scroll_id = None
|
2017-04-19 15:31:08 +02:00
|
|
|
|
2017-06-08 16:58:44 +02:00
|
|
|
def finish_pg_plot(self):
|
|
|
|
self.getPlotWidget().updateWidget()
|
2018-04-19 16:51:29 +02:00
|
|
|
plots, gaps = self.wfp_thread.data
|
2018-04-26 16:40:46 +02:00
|
|
|
# do not show plot if no data are given
|
2018-04-27 10:45:20 +02:00
|
|
|
self.wf_scroll_area.setVisible(len(plots) > 0)
|
|
|
|
self.no_data_label.setVisible(not len(plots) > 0)
|
2018-04-05 15:33:40 +02:00
|
|
|
for times, data, times_syn, data_syn in plots:
|
2017-09-07 16:51:56 +02:00
|
|
|
self.dataPlot.plotWidget.getPlotItem().plot(times, data,
|
|
|
|
pen=self.dataPlot.pen_linecolor)
|
2018-04-18 16:01:39 +02:00
|
|
|
if len(data_syn) > 0:
|
2018-04-05 15:33:40 +02:00
|
|
|
self.dataPlot.plotWidget.getPlotItem().plot(times_syn, data_syn,
|
|
|
|
pen=self.dataPlot.pen_linecolor_syn)
|
2017-06-08 16:58:44 +02:00
|
|
|
self.dataPlot.reinitMoveProxy()
|
2018-04-20 14:53:15 +02:00
|
|
|
self.highlight_stations()
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-04-18 16:24:26 +02:00
|
|
|
def finishWaveformDataPlot(self):
|
2017-08-31 11:16:13 +02:00
|
|
|
self.comparable = self.checkEvents4comparison()
|
2017-06-08 16:14:37 +02:00
|
|
|
if self.pg:
|
2017-06-08 16:58:44 +02:00
|
|
|
self.finish_pg_plot()
|
|
|
|
else:
|
2017-10-20 11:00:52 +02:00
|
|
|
self._max_xlims = self.dataPlot.getXLims(self.dataPlot.axes[0])
|
2017-06-08 16:14:37 +02:00
|
|
|
plotWidget = self.getPlotWidget()
|
|
|
|
plotDict = plotWidget.getPlotDict()
|
|
|
|
pos = plotDict.keys()
|
2018-08-06 16:03:54 +02:00
|
|
|
labels = ['{}.{}'.format(*plotDict[n].split('.')[:-2]) for n in pos]
|
2017-06-08 16:14:37 +02:00
|
|
|
plotWidget.setYTickLabels(pos, labels)
|
|
|
|
try:
|
|
|
|
plotWidget.figure.tight_layout()
|
|
|
|
except:
|
|
|
|
pass
|
2017-04-19 15:31:08 +02:00
|
|
|
self.connectWFplotEvents()
|
2017-04-28 13:56:28 +02:00
|
|
|
self.loadlocationaction.setEnabled(True)
|
2017-05-18 10:31:59 +02:00
|
|
|
self.auto_tune.setEnabled(True)
|
2017-05-18 11:02:20 +02:00
|
|
|
self.auto_pick.setEnabled(True)
|
2017-08-03 11:10:26 +02:00
|
|
|
self.auto_pick_local.setEnabled(True)
|
|
|
|
self.auto_pick_sge.setEnabled(True)
|
2017-08-03 15:33:28 +02:00
|
|
|
self.autoPickMenu.setEnabled(True)
|
2017-04-10 14:24:39 +02:00
|
|
|
self.z_action.setEnabled(True)
|
|
|
|
self.e_action.setEnabled(True)
|
|
|
|
self.n_action.setEnabled(True)
|
2017-08-07 16:41:50 +02:00
|
|
|
self.openEventAction.setEnabled(True)
|
|
|
|
self.openEventsAutoAction.setEnabled(True)
|
2017-04-10 14:24:39 +02:00
|
|
|
self.loadpilotevent.setEnabled(True)
|
2017-08-07 16:44:45 +02:00
|
|
|
self.enableSaveEventAction()
|
2017-05-19 10:56:27 +02:00
|
|
|
event = self.get_current_event()
|
2017-06-26 12:19:06 +02:00
|
|
|
if event.pylot_picks:
|
2017-04-19 16:51:19 +02:00
|
|
|
self.drawPicks(picktype='manual')
|
2017-06-26 12:19:06 +02:00
|
|
|
if event.pylot_autopicks:
|
2017-04-19 16:51:19 +02:00
|
|
|
self.drawPicks(picktype='auto')
|
2019-10-24 10:12:00 +02:00
|
|
|
if event.pylot_picks or event.pylot_autopicks:
|
|
|
|
self.locateEventAction.setEnabled(True)
|
2018-01-30 16:16:41 +01:00
|
|
|
self.qualities_action.setEnabled(True)
|
2017-08-31 11:16:13 +02:00
|
|
|
if True in self.comparable.values():
|
|
|
|
self.compare_action.setEnabled(True)
|
2017-04-18 16:24:26 +02:00
|
|
|
self.draw()
|
2019-03-06 11:25:58 +01:00
|
|
|
# TODO: Quick and dirty, improve this later
|
|
|
|
self.update_obspy_dmt()
|
|
|
|
|
|
|
|
def update_obspy_dmt(self):
|
2019-04-01 10:55:38 +02:00
|
|
|
self.metadata.clear_inventory()
|
2018-07-17 16:04:20 +02:00
|
|
|
if self.obspy_dmt:
|
2018-07-23 16:03:15 +02:00
|
|
|
invpath = os.path.join(self.get_current_event_path(), 'resp')
|
|
|
|
if not invpath in self.metadata.inventories:
|
2021-03-30 08:28:31 +02:00
|
|
|
self.metadata.add_inventory(invpath, obspy_dmt_inv=True)
|
2018-07-23 16:03:15 +02:00
|
|
|
# check if directory is empty
|
|
|
|
if os.listdir(invpath):
|
|
|
|
self.init_map_button.setEnabled(True)
|
|
|
|
self.initMapAction.setEnabled(True)
|
2015-01-29 08:48:25 +01:00
|
|
|
|
2018-07-16 14:09:06 +02:00
|
|
|
@staticmethod
|
|
|
|
def checkEvent4comparison(event):
|
2017-08-31 11:16:13 +02:00
|
|
|
if event.pylot_picks and event.pylot_autopicks:
|
|
|
|
for station in event.pylot_picks:
|
|
|
|
if station in event.pylot_autopicks:
|
2017-09-15 13:17:40 +02:00
|
|
|
try:
|
|
|
|
autopick_p = event.pylot_autopicks[station]['P']['spe']
|
|
|
|
except KeyError:
|
|
|
|
autopick_p = None
|
|
|
|
try:
|
|
|
|
manupick_p = event.pylot_picks[station]['P']['spe']
|
|
|
|
except KeyError:
|
|
|
|
manupick_p = None
|
|
|
|
try:
|
|
|
|
autopick_s = event.pylot_autopicks[station]['S']['spe']
|
|
|
|
except KeyError:
|
|
|
|
autopick_s = None
|
|
|
|
try:
|
|
|
|
manupick_s = event.pylot_picks[station]['S']['spe']
|
|
|
|
except KeyError:
|
|
|
|
manupick_s = None
|
2017-08-31 11:16:13 +02:00
|
|
|
if autopick_p and manupick_p:
|
|
|
|
return True
|
|
|
|
elif autopick_s and manupick_s:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def checkEvents4comparison(self):
|
|
|
|
# init dict to keep track whether event can be compared
|
|
|
|
comparable = {}
|
|
|
|
for event in self.project.eventlist:
|
|
|
|
comparable[event.pylot_id] = self.checkEvent4comparison(event)
|
|
|
|
return comparable
|
|
|
|
|
2018-04-27 10:45:20 +02:00
|
|
|
def clearWaveformDataPlot(self, refresh_plot=False):
|
2017-04-19 15:31:08 +02:00
|
|
|
self.disconnectWFplotEvents()
|
2017-06-07 17:05:48 +02:00
|
|
|
if self.pg:
|
2017-06-08 16:14:37 +02:00
|
|
|
self.dataPlot.plotWidget.getPlotItem().clear()
|
2017-06-07 17:05:48 +02:00
|
|
|
else:
|
2017-10-20 10:57:00 +02:00
|
|
|
for ax in self.dataPlot.axes:
|
|
|
|
ax.cla()
|
2017-04-28 16:01:31 +02:00
|
|
|
self.loadlocationaction.setEnabled(False)
|
2017-05-18 10:31:59 +02:00
|
|
|
self.auto_tune.setEnabled(False)
|
2017-05-18 11:02:20 +02:00
|
|
|
self.auto_pick.setEnabled(False)
|
2017-08-03 11:10:26 +02:00
|
|
|
self.auto_pick_local.setEnabled(False)
|
|
|
|
self.auto_pick_sge.setEnabled(False)
|
2017-08-03 15:33:28 +02:00
|
|
|
self.autoPickMenu.setEnabled(False)
|
2017-04-19 15:31:08 +02:00
|
|
|
self.z_action.setEnabled(False)
|
|
|
|
self.e_action.setEnabled(False)
|
|
|
|
self.n_action.setEnabled(False)
|
2017-08-07 16:41:50 +02:00
|
|
|
self.openEventAction.setEnabled(False)
|
|
|
|
self.openEventsAutoAction.setEnabled(False)
|
2017-04-19 15:31:08 +02:00
|
|
|
self.loadpilotevent.setEnabled(False)
|
2018-07-24 14:32:15 +02:00
|
|
|
self.compare_action.setEnabled(False)
|
|
|
|
self.qualities_action.setEnabled(False)
|
2018-07-24 14:33:38 +02:00
|
|
|
self.locateEventAction.setEnabled(False)
|
2018-04-27 10:45:20 +02:00
|
|
|
if not refresh_plot:
|
|
|
|
self.wf_scroll_area.setVisible(False)
|
|
|
|
self.no_data_label.setVisible(True)
|
2017-08-07 16:41:50 +02:00
|
|
|
self.disableSaveEventAction()
|
2017-04-19 15:31:08 +02:00
|
|
|
self.draw()
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2018-01-12 10:07:14 +01:00
|
|
|
def plotWaveformDataThread(self, filter=True):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Open a modal thread to plot current waveform data.
|
|
|
|
'''
|
2019-04-04 11:48:44 +02:00
|
|
|
if self.check_plot_quantity() == False:
|
|
|
|
print('Nothing to plot.')
|
|
|
|
return
|
2018-04-27 10:45:20 +02:00
|
|
|
self.clearWaveformDataPlot(refresh_plot=True)
|
2017-06-08 16:14:37 +02:00
|
|
|
self.wfp_thread = Thread(self, self.plotWaveformData,
|
2018-01-12 10:07:14 +01:00
|
|
|
arg=filter,
|
2017-09-18 14:57:48 +02:00
|
|
|
progressText='Plotting waveform data...',
|
|
|
|
pb_widget=self.mainProgressBarWidget)
|
2017-06-08 16:14:37 +02:00
|
|
|
self.wfp_thread.finished.connect(self.finishWaveformDataPlot)
|
|
|
|
self.wfp_thread.start()
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2018-01-12 10:07:14 +01:00
|
|
|
def plotWaveformData(self, filter=True):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Plot waveform data to current plotWidget.
|
|
|
|
'''
|
2017-05-29 18:03:31 +02:00
|
|
|
settings = QSettings()
|
|
|
|
nth_sample = settings.value('nth_sample')
|
|
|
|
if not nth_sample:
|
|
|
|
nth_sample = 1
|
2015-03-29 08:07:46 +02:00
|
|
|
zne_text = {'Z': 'vertical', 'N': 'north-south', 'E': 'east-west'}
|
|
|
|
comp = self.getComponent()
|
2015-09-25 15:06:59 +02:00
|
|
|
title = 'section: {0} components'.format(zne_text[comp])
|
2017-05-30 16:09:48 +02:00
|
|
|
wfst = self.get_data().getWFData()
|
2018-04-05 15:33:40 +02:00
|
|
|
wfsyn = self.get_data().getSynWFData()
|
2018-01-12 10:07:14 +01:00
|
|
|
if self.filterActionP.isChecked() and filter:
|
|
|
|
self.filterWaveformData(plot=False, phase='P')
|
|
|
|
elif self.filterActionS.isChecked() and filter:
|
|
|
|
self.filterWaveformData(plot=False, phase='S')
|
2017-05-30 16:09:48 +02:00
|
|
|
# wfst = self.get_data().getWFData().select(component=comp)
|
|
|
|
# wfst += self.get_data().getWFData().select(component=alter_comp)
|
2017-05-03 15:16:48 +02:00
|
|
|
plotWidget = self.getPlotWidget()
|
2017-07-14 16:25:59 +02:00
|
|
|
self.adjustPlotHeight()
|
2019-06-24 15:04:40 +02:00
|
|
|
if get_Bool(settings.value('large_dataset')) == True:
|
2018-04-19 13:38:17 +02:00
|
|
|
self.plot_method = 'fast'
|
2018-04-18 16:44:33 +02:00
|
|
|
else:
|
2018-04-19 13:38:17 +02:00
|
|
|
self.plot_method = 'normal'
|
2018-04-23 13:33:05 +02:00
|
|
|
rval = plotWidget.plotWFData(wfdata=wfst, wfsyn=wfsyn, title=title, mapping=False, component=comp,
|
2019-04-04 11:48:44 +02:00
|
|
|
nth_sample=int(nth_sample), method=self.plot_method, gain=self.gain)
|
2018-04-23 13:33:05 +02:00
|
|
|
plots, gaps = rval if rval else ([], [])
|
2018-04-19 16:51:29 +02:00
|
|
|
return plots, gaps
|
2014-03-19 12:24:41 +01:00
|
|
|
|
2017-05-29 16:21:36 +02:00
|
|
|
def adjustPlotHeight(self):
|
2017-06-08 14:09:01 +02:00
|
|
|
if self.pg:
|
|
|
|
return
|
2017-07-14 16:25:59 +02:00
|
|
|
height_need = len(self.data.getWFData()) * self.height_factor
|
2017-05-29 16:21:36 +02:00
|
|
|
plotWidget = self.getPlotWidget()
|
|
|
|
if self.tabs.widget(0).frameSize().height() < height_need:
|
|
|
|
plotWidget.setMinimumHeight(height_need)
|
|
|
|
else:
|
|
|
|
plotWidget.setMinimumHeight(0)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2015-07-07 14:21:11 +02:00
|
|
|
def plotZ(self):
|
|
|
|
self.setComponent('Z')
|
2017-04-18 16:24:26 +02:00
|
|
|
self.plotWaveformDataThread()
|
2017-06-08 16:14:37 +02:00
|
|
|
# self.drawPicks()
|
|
|
|
# self.draw()
|
2015-07-07 14:21:11 +02:00
|
|
|
|
|
|
|
def plotN(self):
|
|
|
|
self.setComponent('N')
|
2017-04-18 16:24:26 +02:00
|
|
|
self.plotWaveformDataThread()
|
2017-06-08 16:14:37 +02:00
|
|
|
# self.drawPicks()
|
|
|
|
# self.draw()
|
2015-07-07 14:21:11 +02:00
|
|
|
|
|
|
|
def plotE(self):
|
|
|
|
self.setComponent('E')
|
2017-04-18 16:24:26 +02:00
|
|
|
self.plotWaveformDataThread()
|
2017-06-08 16:14:37 +02:00
|
|
|
# self.drawPicks()
|
|
|
|
# self.draw()
|
2015-07-07 14:21:11 +02:00
|
|
|
|
2015-10-31 00:07:24 +01:00
|
|
|
def pushFilterWF(self, param_args):
|
2016-09-02 14:21:59 +02:00
|
|
|
self.get_data().filterWFData(param_args)
|
2015-10-31 00:07:24 +01:00
|
|
|
|
2018-01-12 10:07:14 +01:00
|
|
|
def filterP(self):
|
|
|
|
self.filterActionS.setChecked(False)
|
|
|
|
if self.filterActionP.isChecked():
|
|
|
|
self.filterWaveformData(phase='P')
|
|
|
|
else:
|
|
|
|
self.resetWFData()
|
|
|
|
|
|
|
|
def filterS(self):
|
|
|
|
self.filterActionP.setChecked(False)
|
|
|
|
if self.filterActionS.isChecked():
|
|
|
|
self.filterWaveformData(phase='S')
|
|
|
|
else:
|
|
|
|
self.resetWFData()
|
|
|
|
|
|
|
|
def resetWFData(self):
|
|
|
|
self.get_data().resetWFData()
|
|
|
|
self.plotWaveformDataThread()
|
|
|
|
|
|
|
|
def filterWaveformData(self, plot=True, phase=None):
|
2018-01-12 10:15:30 +01:00
|
|
|
if not self.get_current_event():
|
|
|
|
return
|
|
|
|
|
2016-09-02 14:21:59 +02:00
|
|
|
if self.get_data():
|
2018-01-12 10:07:14 +01:00
|
|
|
if not phase:
|
|
|
|
if self.filterActionP.isChecked():
|
|
|
|
phase = 'P'
|
|
|
|
elif self.filterActionS.isChecked():
|
|
|
|
phase = 'S'
|
|
|
|
if self.getFilterOptions():
|
2018-07-16 14:21:41 +02:00
|
|
|
if (phase == 'P' and self.filterActionP.isChecked()) or (
|
|
|
|
phase == 'S' and self.filterActionS.isChecked()):
|
2018-01-12 10:07:14 +01:00
|
|
|
kwargs = self.getFilterOptions()[phase].parseFilterOptions()
|
|
|
|
self.pushFilterWF(kwargs)
|
|
|
|
else:
|
|
|
|
self.get_data().resetWFData()
|
|
|
|
elif self.filterActionP.isChecked() or self.filterActionS.isChecked():
|
2015-10-30 08:39:51 +01:00
|
|
|
self.adjustFilterOptions()
|
2015-02-20 08:38:26 +01:00
|
|
|
else:
|
2016-09-02 14:21:59 +02:00
|
|
|
self.get_data().resetWFData()
|
2018-01-12 10:07:14 +01:00
|
|
|
if plot:
|
|
|
|
self.plotWaveformDataThread(filter=False)
|
2018-07-16 14:21:41 +02:00
|
|
|
# self.drawPicks()
|
|
|
|
# self.draw()
|
2014-11-28 11:15:49 +01:00
|
|
|
|
2018-02-22 16:03:11 +01:00
|
|
|
def getAutoFilteroptions(self, phase):
|
|
|
|
return getAutoFilteroptions(phase, self._inputs)
|
2018-02-22 10:05:57 +01:00
|
|
|
|
2014-11-06 15:07:05 +01:00
|
|
|
def adjustFilterOptions(self):
|
2017-07-04 16:37:05 +02:00
|
|
|
fstring = "Filter Options"
|
2017-07-11 16:03:24 +02:00
|
|
|
self.filterDlg = FilterOptionsDialog(titleString=fstring,
|
|
|
|
parent=self)
|
|
|
|
if self.filterDlg.exec_():
|
|
|
|
filteroptions = self.filterDlg.getFilterOptions()
|
2015-03-05 14:52:34 +01:00
|
|
|
self.setFilterOptions(filteroptions)
|
2018-01-12 10:07:14 +01:00
|
|
|
if self.filterActionP.isChecked() or self.filterActionS.isChecked():
|
2017-07-11 16:22:22 +02:00
|
|
|
kwargs = self.getFilterOptions()[self.getSeismicPhase()].parseFilterOptions()
|
2015-10-31 00:07:24 +01:00
|
|
|
self.pushFilterWF(kwargs)
|
2017-05-31 16:25:46 +02:00
|
|
|
self.plotWaveformDataThread()
|
2018-01-10 16:08:28 +01:00
|
|
|
return True
|
2014-11-13 11:27:52 +01:00
|
|
|
|
2017-07-11 16:03:24 +02:00
|
|
|
def checkFilterOptions(self):
|
|
|
|
fstring = "Filter Options"
|
|
|
|
self.filterDlg = FilterOptionsDialog(titleString=fstring,
|
|
|
|
parent=self)
|
|
|
|
filteroptions = self.filterDlg.getFilterOptions()
|
2017-07-12 16:24:23 +02:00
|
|
|
self.setFilterOptions(filteroptions)
|
|
|
|
filterP = filteroptions['P']
|
|
|
|
filterS = filteroptions['S']
|
|
|
|
minP, maxP = filterP.getFreq()
|
|
|
|
minS, maxS = filterS.getFreq()
|
|
|
|
self.paraBox.params_to_gui()
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2014-11-13 11:27:52 +01:00
|
|
|
def getFilterOptions(self):
|
2017-07-04 16:37:05 +02:00
|
|
|
return self.filteroptions
|
|
|
|
# try:
|
|
|
|
# return self.filteroptions[self.getSeismicPhase()]
|
|
|
|
# except AttributeError as e:
|
|
|
|
# print(e)
|
|
|
|
# return FilterOptions(None, None, None)
|
2015-03-01 10:31:49 +01:00
|
|
|
|
|
|
|
def getFilters(self):
|
2014-11-13 11:27:52 +01:00
|
|
|
return self.filteroptions
|
|
|
|
|
2017-07-14 16:25:59 +02:00
|
|
|
def setFilterOptions(self, filterOptions): # , seismicPhase=None):
|
2017-07-04 16:37:05 +02:00
|
|
|
# if seismicPhase is None:
|
|
|
|
# self.getFilterOptions()[self.getSeismicPhase()] = filterOptions
|
|
|
|
# else:
|
|
|
|
# self.getFilterOptions()[seismicPhase] = filterOptions
|
|
|
|
self.filterOptions = filterOptions
|
|
|
|
filterP = filterOptions['P']
|
|
|
|
filterS = filterOptions['S']
|
|
|
|
minP, maxP = filterP.getFreq()
|
|
|
|
minS, maxS = filterS.getFreq()
|
|
|
|
self._inputs.setParamKV('minfreq', (minP, minS))
|
|
|
|
self._inputs.setParamKV('maxfreq', (maxP, maxS))
|
|
|
|
self._inputs.setParamKV('filter_order', (filterP.getOrder(), filterS.getOrder()))
|
|
|
|
self._inputs.setParamKV('filter_type', (filterP.getFilterType(), filterS.getFilterType()))
|
2015-03-01 10:31:49 +01:00
|
|
|
|
2017-07-04 14:39:10 +02:00
|
|
|
def filterOptionsFromParameter(self):
|
2017-07-04 16:37:05 +02:00
|
|
|
minP, minS = self._inputs['minfreq']
|
|
|
|
maxP, maxS = self._inputs['maxfreq']
|
|
|
|
orderP, orderS = self._inputs['filter_order']
|
|
|
|
typeP, typeS = self._inputs['filter_type']
|
2017-07-11 16:03:24 +02:00
|
|
|
|
2017-07-04 16:37:05 +02:00
|
|
|
filterP = self.getFilterOptions()['P']
|
|
|
|
filterP.setFreq([minP, maxP])
|
|
|
|
filterP.setOrder(orderP)
|
|
|
|
filterP.setFilterType(typeP)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-07-04 16:37:05 +02:00
|
|
|
filterS = self.getFilterOptions()['S']
|
|
|
|
filterS.setFreq([minS, maxS])
|
|
|
|
filterS.setOrder(orderS)
|
|
|
|
filterS.setFilterType(typeS)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-07-11 16:03:24 +02:00
|
|
|
self.checkFilterOptions()
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-09-18 10:41:27 +02:00
|
|
|
# def updateFilterOptions(self):
|
|
|
|
# try:
|
|
|
|
# settings = QSettings()
|
|
|
|
# if settings.value("filterdefaults",
|
|
|
|
# None) is None and not self.getFilters():
|
|
|
|
# for key, value in FILTERDEFAULTS.items():
|
|
|
|
# self.setFilterOptions(FilterOptions(**value), key)
|
|
|
|
# elif settings.value("filterdefaults", None) is not None:
|
|
|
|
# for key, value in settings.value("filterdefaults"):
|
|
|
|
# self.setFilterOptions(FilterOptions(**value), key)
|
|
|
|
# except Exception as e:
|
|
|
|
# self.update_status('Error ...')
|
|
|
|
# emsg = QErrorMessage(self)
|
|
|
|
# emsg.showMessage('Error: {0}'.format(e))
|
|
|
|
# else:
|
|
|
|
# self.update_status('Filter loaded ... '
|
|
|
|
# '[{0}: {1} Hz]'.format(
|
|
|
|
# self.getFilterOptions().getFilterType(),
|
|
|
|
# self.getFilterOptions().getFreq()))
|
2018-01-12 10:07:14 +01:00
|
|
|
# if self.filterActionP.isChecked() or self.filterActionS.isChecked():
|
2017-09-18 10:41:27 +02:00
|
|
|
# self.filterWaveformData()
|
2014-03-28 22:26:15 +01:00
|
|
|
|
2014-11-13 11:27:52 +01:00
|
|
|
def getSeismicPhase(self):
|
|
|
|
return self.seismicPhase
|
|
|
|
|
2018-08-06 16:03:54 +02:00
|
|
|
def getTraceID(self, wfID):
|
|
|
|
plot_dict = self.getPlotWidget().getPlotDict()
|
|
|
|
return plot_dict.get(wfID)
|
|
|
|
|
2019-02-21 10:17:51 +01:00
|
|
|
def getNetworkName(self, wfID):
|
|
|
|
plot_dict = self.getPlotWidget().getPlotDict()
|
|
|
|
if wfID in plot_dict.keys():
|
|
|
|
return plot_dict[wfID].split('.')[0]
|
|
|
|
|
2015-03-09 11:21:33 +01:00
|
|
|
def getStationName(self, wfID):
|
2017-06-08 14:09:01 +02:00
|
|
|
plot_dict = self.getPlotWidget().getPlotDict()
|
|
|
|
if wfID in plot_dict.keys():
|
2018-08-06 16:03:54 +02:00
|
|
|
return plot_dict[wfID].split('.')[1]
|
2015-03-09 11:21:33 +01:00
|
|
|
|
2019-02-21 10:17:51 +01:00
|
|
|
def getLocationName(self, wfID):
|
2017-06-30 13:56:59 +02:00
|
|
|
plot_dict = self.getPlotWidget().getPlotDict()
|
|
|
|
if wfID in plot_dict.keys():
|
2019-02-21 10:17:51 +01:00
|
|
|
return plot_dict[wfID].split('.')[2]
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2014-11-28 11:15:49 +01:00
|
|
|
def alterPhase(self):
|
|
|
|
pass
|
|
|
|
|
2014-11-13 11:27:52 +01:00
|
|
|
def setSeismicPhase(self, phase):
|
2014-11-28 09:19:16 +01:00
|
|
|
self.seismicPhase = self.seismicPhaseButtonGroup.getValue()
|
2016-09-02 14:21:59 +02:00
|
|
|
self.update_status('Seismic phase changed to '
|
2017-07-14 16:25:59 +02:00
|
|
|
'{0}'.format(self.getSeismicPhase()))
|
2014-11-13 11:27:52 +01:00
|
|
|
|
2017-05-22 10:53:20 +02:00
|
|
|
def scrollPlot(self, gui_event):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Function connected to mouse wheel scrolling inside WFdataPlot.
|
|
|
|
Only used if amount of traces exceeds a certain limit creating
|
|
|
|
a scroll area.
|
|
|
|
'''
|
2017-05-22 10:53:20 +02:00
|
|
|
button = gui_event.button
|
2017-05-31 13:45:48 +02:00
|
|
|
x, y = gui_event.xdata, gui_event.ydata
|
2017-05-22 10:53:20 +02:00
|
|
|
if not button == 'up' and not button == 'down':
|
|
|
|
return
|
2017-05-31 13:45:48 +02:00
|
|
|
if not self._ctrl and not self._shift:
|
|
|
|
vbar = self.wf_scroll_area.verticalScrollBar()
|
|
|
|
up_down = {'up': -60,
|
|
|
|
'down': 60}
|
|
|
|
if vbar.maximum():
|
|
|
|
vbar.setValue(vbar.value() + up_down[button])
|
|
|
|
if self._ctrl:
|
2017-07-14 16:25:59 +02:00
|
|
|
factor = {'up': 5. / 4.,
|
|
|
|
'down': 4. / 5.}
|
2017-05-31 13:45:48 +02:00
|
|
|
self.height_factor *= factor[button]
|
|
|
|
self.adjustPlotHeight()
|
|
|
|
if self._shift:
|
2017-07-14 16:25:59 +02:00
|
|
|
factor = {'up': 1. / 2.,
|
2017-05-31 13:45:48 +02:00
|
|
|
'down': 2.}
|
2018-01-17 10:30:38 +01:00
|
|
|
xlims = self.dataPlot.getXLims(self.dataPlot.axes[0])
|
2017-05-31 13:45:48 +02:00
|
|
|
xdiff = xlims[1] - xlims[0]
|
|
|
|
xdiff *= factor[button]
|
|
|
|
xl = x - 0.5 * xdiff
|
|
|
|
xr = x + 0.5 * xdiff
|
|
|
|
if xl < self._max_xlims[0]:
|
|
|
|
xl = self._max_xlims[0]
|
|
|
|
if xr > self._max_xlims[1]:
|
|
|
|
xr = self._max_xlims[1]
|
2018-01-17 10:30:38 +01:00
|
|
|
self.dataPlot.setXLims(self.dataPlot.axes[0], (xl, xr))
|
2017-05-31 13:45:48 +02:00
|
|
|
self.dataPlot.draw()
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2015-04-02 18:48:06 +02:00
|
|
|
def pickOnStation(self, gui_event):
|
2017-06-08 14:09:01 +02:00
|
|
|
if self.pg:
|
2018-04-20 14:53:15 +02:00
|
|
|
button = gui_event.button()
|
|
|
|
if not button in [1, 4]:
|
2017-06-08 14:09:01 +02:00
|
|
|
return
|
|
|
|
else:
|
2018-04-20 14:53:15 +02:00
|
|
|
button = gui_event.button
|
|
|
|
if not button == 1:
|
2017-06-08 14:09:01 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
if self.pg:
|
|
|
|
ycoord = self.dataPlot.plotWidget.getPlotItem().vb.mapSceneToView(gui_event.scenePos()).y()
|
|
|
|
else:
|
|
|
|
ycoord = gui_event.ydata
|
|
|
|
|
|
|
|
wfID = self.getWFID(ycoord)
|
2015-03-09 11:21:33 +01:00
|
|
|
|
2016-06-10 09:01:37 +02:00
|
|
|
if wfID is None: return
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-06-30 13:56:59 +02:00
|
|
|
network = self.getNetworkName(wfID)
|
2018-04-20 14:53:15 +02:00
|
|
|
station = self.getStationName(wfID)
|
2019-02-21 10:17:51 +01:00
|
|
|
location = self.getLocationName(wfID)
|
2018-08-06 16:03:54 +02:00
|
|
|
seed_id = self.getTraceID(wfID)
|
2018-04-20 14:53:15 +02:00
|
|
|
if button == 1:
|
2018-08-06 16:03:54 +02:00
|
|
|
self.pickDialog(wfID, seed_id)
|
2018-04-20 14:53:15 +02:00
|
|
|
elif button == 4:
|
2019-02-21 10:17:51 +01:00
|
|
|
self.toggle_station_color(wfID, network, station, location)
|
2018-04-20 14:53:15 +02:00
|
|
|
|
2018-08-06 16:03:54 +02:00
|
|
|
def toggle_station_color(self, wfID, network, station, location):
|
2018-04-20 14:53:15 +02:00
|
|
|
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']
|
2018-08-06 16:03:54 +02:00
|
|
|
nsl = '{}.{}.{}'.format(network, station, location)
|
2018-04-20 14:53:15 +02:00
|
|
|
if current_pen == black_pen:
|
|
|
|
line_item.setPen(red_pen)
|
2018-08-06 16:03:54 +02:00
|
|
|
if not nsl in self.stations_highlighted:
|
|
|
|
self.stations_highlighted.append(nsl)
|
2018-04-20 14:53:15 +02:00
|
|
|
else:
|
|
|
|
line_item.setPen(black_pen)
|
2018-08-06 16:03:54 +02:00
|
|
|
if nsl in self.stations_highlighted:
|
|
|
|
self.stations_highlighted.pop(self.stations_highlighted.index(nsl))
|
2018-04-20 14:53:15 +02:00
|
|
|
|
|
|
|
def highlight_stations(self):
|
|
|
|
for wfID, value in self.getPlotWidget().getPlotDict().items():
|
2018-08-06 16:03:54 +02:00
|
|
|
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, seed_id=None):
|
|
|
|
if not seed_id:
|
|
|
|
seed_id = self.getTraceID(wfID)
|
2020-09-16 16:16:53 +02:00
|
|
|
try:
|
2021-03-30 08:28:31 +02:00
|
|
|
network, station, location = seed_id.split('.')[:3]
|
2020-09-16 16:16:53 +02:00
|
|
|
except:
|
|
|
|
print("Warning! No network, station, and location info available!")
|
2017-06-08 14:09:01 +02:00
|
|
|
return
|
2016-09-02 14:21:59 +02:00
|
|
|
self.update_status('picking on station {0}'.format(station))
|
2018-01-09 11:44:22 +01:00
|
|
|
data = self.get_data().getOriginalWFData().copy()
|
2017-08-30 10:51:20 +02:00
|
|
|
event = self.get_current_event()
|
2018-06-20 13:49:27 +02:00
|
|
|
wftype = self.dataPlot.qcombo_processed.currentText() if self.obspy_dmt else None
|
2017-07-14 16:25:59 +02:00
|
|
|
pickDlg = PickDlg(self, parameter=self._inputs,
|
2017-04-06 13:16:28 +02:00
|
|
|
data=data.select(station=station),
|
2017-06-30 13:56:59 +02:00
|
|
|
station=station, network=network,
|
2018-08-06 16:03:54 +02:00
|
|
|
location=location,
|
2017-04-10 15:06:30 +02:00
|
|
|
picks=self.getPicksOnStation(station, 'manual'),
|
2017-08-30 10:51:20 +02:00
|
|
|
autopicks=self.getPicksOnStation(station, 'auto'),
|
|
|
|
metadata=self.metadata, event=event,
|
2018-06-20 13:49:27 +02:00
|
|
|
filteroptions=self.filteroptions, wftype=wftype)
|
2019-02-27 09:46:37 +01:00
|
|
|
if self.filterActionP.isChecked():
|
|
|
|
pickDlg.currentPhase = "P"
|
|
|
|
pickDlg.filterWFData()
|
|
|
|
elif self.filterActionS.isChecked():
|
|
|
|
pickDlg.currentPhase = "S"
|
2018-01-09 11:44:22 +01:00
|
|
|
pickDlg.filterWFData()
|
2018-06-21 14:23:52 +02:00
|
|
|
pickDlg.nextStation.setChecked(self.nextStation)
|
|
|
|
pickDlg.nextStation.stateChanged.connect(self.toggle_next_station)
|
2015-03-29 08:07:46 +02:00
|
|
|
if pickDlg.exec_():
|
2017-07-18 14:34:09 +02:00
|
|
|
if pickDlg._dirty:
|
2017-06-21 15:20:36 +02:00
|
|
|
self.setDirty(True)
|
|
|
|
self.update_status('picks accepted ({0})'.format(station))
|
2018-07-17 09:42:13 +02:00
|
|
|
self.addPicks(station, pickDlg.getPicks(picktype='manual'), type='manual')
|
|
|
|
self.addPicks(station, pickDlg.getPicks(picktype='auto'), type='auto')
|
2019-05-29 15:58:37 +02:00
|
|
|
if pickDlg.removed_picks:
|
|
|
|
self.log_deleted_picks(pickDlg.removed_picks)
|
2017-08-07 16:41:50 +02:00
|
|
|
self.enableSaveEventAction()
|
2018-07-17 09:42:13 +02:00
|
|
|
self.comparable = self.checkEvents4comparison()
|
|
|
|
if True in self.comparable.values():
|
|
|
|
self.compare_action.setEnabled(True)
|
|
|
|
self.drawPicks(station)
|
|
|
|
self.draw()
|
2018-06-21 14:23:52 +02:00
|
|
|
if self.nextStation:
|
|
|
|
self.pickDialog(wfID - 1)
|
2015-03-29 08:07:46 +02:00
|
|
|
else:
|
2016-09-02 14:21:59 +02:00
|
|
|
self.update_status('picks discarded ({0})'.format(station))
|
|
|
|
if not self.get_loc_flag() and self.check4Loc():
|
2018-07-24 14:33:38 +02:00
|
|
|
self.locateEventAction.setEnabled(True)
|
2016-09-02 14:21:59 +02:00
|
|
|
self.set_loc_flag(True)
|
|
|
|
elif self.get_loc_flag() and not self.check4Loc():
|
|
|
|
self.set_loc_flag(False)
|
2015-03-12 13:59:29 +01:00
|
|
|
|
2018-06-21 14:23:52 +02:00
|
|
|
def toggle_next_station(self, signal):
|
|
|
|
self.nextStation = bool(signal)
|
|
|
|
|
2015-11-26 05:17:26 +01:00
|
|
|
def addListItem(self, text):
|
2018-07-04 16:48:14 +02:00
|
|
|
textlist = text.split('\n')
|
|
|
|
for text in textlist:
|
|
|
|
self.listWidget.addItem(text)
|
2015-11-26 05:17:26 +01:00
|
|
|
self.listWidget.scrollToBottom()
|
|
|
|
|
2017-08-21 17:19:08 +02:00
|
|
|
def init_fig_dict(self):
|
2017-05-12 11:03:41 +02:00
|
|
|
self.fig_dict = {}
|
|
|
|
self.fig_keys = [
|
|
|
|
'mainFig',
|
|
|
|
'aicFig',
|
|
|
|
'slength',
|
|
|
|
'checkZ4s',
|
|
|
|
'refPpick',
|
|
|
|
'el_Ppick',
|
|
|
|
'fm_picker',
|
|
|
|
'el_S1pick',
|
|
|
|
'el_S2pick',
|
|
|
|
'refSpick',
|
2017-09-08 17:01:36 +02:00
|
|
|
'aicARHfig',
|
|
|
|
'plot_style'
|
2017-05-12 11:03:41 +02:00
|
|
|
]
|
|
|
|
for key in self.fig_keys:
|
2017-09-08 17:01:36 +02:00
|
|
|
if key == 'plot_style':
|
|
|
|
fig = self._style
|
|
|
|
else:
|
|
|
|
fig = Figure()
|
2017-05-12 11:03:41 +02:00
|
|
|
self.fig_dict[key] = fig
|
2017-05-11 17:15:20 +02:00
|
|
|
|
2017-08-21 17:19:08 +02:00
|
|
|
def init_canvas_dict(self):
|
|
|
|
self.canvas_dict = {}
|
|
|
|
for key in self.fig_keys:
|
2017-09-08 17:01:36 +02:00
|
|
|
if not key == 'plot_style':
|
|
|
|
self.canvas_dict[key] = PylotCanvas(self.fig_dict[key], parent=self)
|
2017-08-21 17:19:08 +02:00
|
|
|
|
2017-08-22 16:43:09 +02:00
|
|
|
def init_fig_dict_wadatijack(self, eventIDs):
|
|
|
|
self.fig_dict_wadatijack = {}
|
|
|
|
self.fig_keys_wadatijack = [
|
|
|
|
'jackknife',
|
2017-09-08 17:01:36 +02:00
|
|
|
'wadati',
|
|
|
|
'plot_style'
|
2017-08-22 16:43:09 +02:00
|
|
|
]
|
|
|
|
for eventID in eventIDs:
|
|
|
|
self.fig_dict_wadatijack[eventID] = {}
|
|
|
|
for key in self.fig_keys_wadatijack:
|
2017-09-08 17:01:36 +02:00
|
|
|
if key == 'plot_style':
|
|
|
|
fig = self._style
|
|
|
|
else:
|
|
|
|
fig = Figure()
|
2017-08-22 16:43:09 +02:00
|
|
|
self.fig_dict_wadatijack[eventID][key] = fig
|
|
|
|
|
|
|
|
def init_canvas_dict_wadatijack(self):
|
|
|
|
self.canvas_dict_wadatijack = {}
|
|
|
|
for eventID in self.fig_dict_wadatijack.keys():
|
|
|
|
self.canvas_dict_wadatijack[eventID] = {}
|
|
|
|
for key in self.fig_keys_wadatijack:
|
2017-09-08 17:01:36 +02:00
|
|
|
if not key == 'plot_style':
|
|
|
|
self.canvas_dict_wadatijack[eventID][key] = PylotCanvas(self.fig_dict_wadatijack[eventID][key],
|
|
|
|
parent=self)
|
2017-08-22 16:43:09 +02:00
|
|
|
|
2017-08-21 17:19:08 +02:00
|
|
|
def tune_autopicker(self):
|
|
|
|
'''
|
2018-06-05 15:07:06 +02:00
|
|
|
Initiates TuneAutopicker widget used to interactively
|
2017-08-21 17:19:08 +02:00
|
|
|
tune parameters for autopicking algorithm.
|
|
|
|
'''
|
|
|
|
# figures and canvas have to be iniated from the main GUI
|
|
|
|
# thread to prevent handling of QPixmap objects outside of
|
|
|
|
# the main thread
|
|
|
|
self.init_fig_dict()
|
2018-07-16 14:21:41 +02:00
|
|
|
# if not self.tap:
|
2017-08-11 15:15:58 +02:00
|
|
|
# init TuneAutopicker object
|
2018-06-20 13:49:27 +02:00
|
|
|
self.tap = TuneAutopicker(self, self.obspy_dmt)
|
2017-08-11 15:15:58 +02:00
|
|
|
# first call of update to init tabs with empty canvas
|
|
|
|
self.update_autopicker()
|
|
|
|
# connect update signal of TuneAutopicker with update function
|
|
|
|
# creating and filling figure canvas
|
|
|
|
self.tap.update.connect(self.update_autopicker)
|
|
|
|
self.tap.figure_tabs.setCurrentIndex(0)
|
2018-07-16 14:21:41 +02:00
|
|
|
# else:
|
2017-08-11 15:15:58 +02:00
|
|
|
# self.update_autopicker()
|
|
|
|
# self.tap.fill_eventbox()
|
2018-07-19 11:50:29 +02:00
|
|
|
self.tap.showMaximized()
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-05-12 11:03:41 +02:00
|
|
|
def update_autopicker(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Create and fill TuneAutopicker tabs with figure canvas.
|
|
|
|
'''
|
2017-08-21 17:19:08 +02:00
|
|
|
self.init_canvas_dict()
|
2017-05-16 13:41:35 +02:00
|
|
|
self.tap.fill_tabs(picked=True)
|
2017-08-24 11:35:53 +02:00
|
|
|
for canvas in self.canvas_dict.values():
|
|
|
|
canvas.setZoomBorders2content()
|
2017-09-20 11:03:30 +02:00
|
|
|
if self.tap.pylot_picks:
|
|
|
|
station = self.tap.get_current_station()
|
2018-07-25 10:46:20 +02:00
|
|
|
p_pick = self.tap.pylot_picks[station].get('P')
|
|
|
|
if p_pick:
|
|
|
|
self.tap.pickDlg.autopicks['P_tuning'] = p_pick
|
|
|
|
self.tap.pickDlg.drawPicks(phase='P_tuning', picktype='auto', picks=p_pick)
|
|
|
|
s_pick = self.tap.pylot_picks[station].get('S')
|
|
|
|
if s_pick:
|
|
|
|
self.tap.pickDlg.autopicks['S_tuning'] = s_pick
|
|
|
|
self.tap.pickDlg.drawPicks(phase='S_tuning', picktype='auto', picks=s_pick)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2015-07-09 11:37:03 +02:00
|
|
|
def autoPick(self):
|
2017-08-07 13:35:05 +02:00
|
|
|
autosave = self.get_current_event_path()
|
|
|
|
if not os.path.exists(autosave):
|
2017-07-14 16:25:59 +02:00
|
|
|
QMessageBox.warning(self, "PyLoT Warning",
|
|
|
|
"No autoPyLoT output declared!")
|
|
|
|
return
|
2017-08-22 16:43:09 +02:00
|
|
|
|
2017-09-18 14:44:18 +02:00
|
|
|
if not self.apw:
|
|
|
|
# init event selection options for autopick
|
2018-07-16 14:21:41 +02:00
|
|
|
self.pickoptions = [('current event', self.get_current_event, None),
|
|
|
|
('tune events', self.get_ref_events, self._style['ref']['rgba']),
|
2021-03-30 08:28:31 +02:00
|
|
|
('test events', self.get_test_events, self._style['test']['rgba']), ]
|
|
|
|
# ('all (picked) events', self.get_manu_picked_events, None),
|
|
|
|
# ('all events', self.get_all_events, None)]
|
2017-08-22 16:43:09 +02:00
|
|
|
|
2017-09-18 14:44:18 +02:00
|
|
|
self.listWidget = QListWidget()
|
|
|
|
self.setDirty(True)
|
|
|
|
self.apw = AutoPickWidget(self, self.pickoptions)
|
|
|
|
self.apw.insert_log_widget(self.listWidget)
|
|
|
|
self.apw.refresh_tooltips()
|
2017-08-22 16:43:09 +02:00
|
|
|
|
2017-09-18 14:44:18 +02:00
|
|
|
self.apw.start.connect(self.start_autopick)
|
2017-08-22 16:43:09 +02:00
|
|
|
self.apw.show()
|
2017-08-21 17:19:08 +02:00
|
|
|
|
2017-08-22 16:43:09 +02:00
|
|
|
def start_autopick(self):
|
2017-09-18 10:41:27 +02:00
|
|
|
if not self.pickoptions:
|
|
|
|
return
|
2017-09-12 14:10:15 +02:00
|
|
|
for key, func, _ in self.pickoptions:
|
2017-08-22 16:43:09 +02:00
|
|
|
if self.apw.rb_dict[key].isChecked():
|
|
|
|
# if radio button is checked break for loop and use func
|
|
|
|
break
|
|
|
|
|
|
|
|
events = func()
|
|
|
|
if not type(events) == list:
|
|
|
|
events = [events]
|
|
|
|
eventPaths = self.get_event_paths(events)
|
|
|
|
eventIDs = self.get_event_ids(events)
|
|
|
|
|
|
|
|
self.init_fig_dict_wadatijack(eventIDs)
|
|
|
|
|
|
|
|
if not eventPaths:
|
|
|
|
self.addListItem("No events found for '{}'".format(key))
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
self.addListItem("Picking the following events ({}):".format(key))
|
|
|
|
for eventID in eventPaths:
|
|
|
|
self.addListItem(str(eventID))
|
|
|
|
|
|
|
|
self.apw.enable(False)
|
|
|
|
|
|
|
|
# export current picks etc.
|
2018-07-17 10:53:37 +02:00
|
|
|
self.exportEvents(['.xml'], events=events)
|
2017-08-22 16:43:09 +02:00
|
|
|
|
2018-06-21 13:24:24 +02:00
|
|
|
wfpath = self.dataPlot.qcombo_processed.currentText() if self.obspy_dmt else ''
|
2017-08-22 16:43:09 +02:00
|
|
|
# define arguments for picker
|
2017-07-31 17:00:19 +02:00
|
|
|
args = {'parameter': self._inputs,
|
|
|
|
'station': 'all',
|
|
|
|
'fnames': 'None',
|
2017-08-22 16:43:09 +02:00
|
|
|
'eventid': eventPaths,
|
2017-07-31 17:00:19 +02:00
|
|
|
'iplot': 0,
|
2017-08-22 16:43:09 +02:00
|
|
|
'fig_dict': None,
|
|
|
|
'fig_dict_wadatijack': self.fig_dict_wadatijack,
|
2018-06-21 13:24:24 +02:00
|
|
|
'savexml': False,
|
|
|
|
'obspyDMT_wfpath': wfpath}
|
2017-08-22 16:43:09 +02:00
|
|
|
# init pick thread
|
2017-07-31 17:00:19 +02:00
|
|
|
self.mp_thread = QtCore.QThreadPool()
|
|
|
|
self.mp_worker = Worker(autoPyLoT, args, redirect_stdout=True)
|
|
|
|
|
2017-07-31 13:43:06 +02:00
|
|
|
self.addListItem(str(self._inputs))
|
|
|
|
|
2017-07-31 17:00:19 +02:00
|
|
|
self.mp_worker.signals.message.connect(self.addListItem)
|
2017-08-16 10:03:10 +02:00
|
|
|
self.mp_worker.signals.result.connect(self.finalizeAutoPick)
|
2018-06-05 14:24:00 +02:00
|
|
|
self.mp_worker.signals.finished.connect(self.enableAutoPickWidget)
|
2015-12-01 05:03:55 +01:00
|
|
|
|
2017-08-22 16:43:09 +02:00
|
|
|
self.mp_thread.start(self.mp_worker)
|
|
|
|
|
2017-08-03 11:10:26 +02:00
|
|
|
def autoPickProject(self):
|
|
|
|
if not self.apd_local:
|
|
|
|
self.apd_local = AutoPickDlg(self, sge=False)
|
|
|
|
self.apd_local.show()
|
|
|
|
|
|
|
|
def autoPickProjectSGE(self):
|
|
|
|
if not self.apd_sge:
|
|
|
|
self.apd_sge = AutoPickDlg(self, sge=True)
|
|
|
|
self.apd_sge.show()
|
|
|
|
|
2017-08-16 10:03:10 +02:00
|
|
|
def finalizeAutoPick(self, result):
|
|
|
|
if result:
|
2017-08-22 16:43:09 +02:00
|
|
|
self.init_canvas_dict_wadatijack()
|
|
|
|
for eventID in result.keys():
|
|
|
|
event = self.get_event_from_id(eventID)
|
|
|
|
if not event:
|
|
|
|
continue
|
|
|
|
event.addAutopicks(result[eventID])
|
2017-08-23 11:51:59 +02:00
|
|
|
jkw = CanvasWidget(self, self.canvas_dict_wadatijack[eventID]['jackknife'])
|
|
|
|
wdw = CanvasWidget(self, self.canvas_dict_wadatijack[eventID]['wadati'])
|
2017-08-23 10:25:46 +02:00
|
|
|
self.apw.add_plot_widget(jkw, 'Jackknife', eventID)
|
2017-08-23 11:51:59 +02:00
|
|
|
self.apw.add_plot_widget(wdw, 'Wadati', eventID)
|
2017-08-23 10:25:46 +02:00
|
|
|
self.apw.update_plots()
|
2017-08-16 10:03:10 +02:00
|
|
|
self.drawPicks(picktype='auto')
|
|
|
|
self.draw()
|
2017-08-22 16:43:09 +02:00
|
|
|
|
2018-06-05 14:24:00 +02:00
|
|
|
def enableAutoPickWidget(self, event=None):
|
|
|
|
self.apw.enable(True)
|
|
|
|
|
2017-08-22 16:43:09 +02:00
|
|
|
def get_event_from_id(self, eventID):
|
|
|
|
for event in self.project.eventlist:
|
|
|
|
if event.pylot_id == eventID:
|
|
|
|
return event
|
|
|
|
|
2018-07-16 14:09:06 +02:00
|
|
|
@staticmethod
|
|
|
|
def get_event_paths(eventlist):
|
2017-08-22 16:43:09 +02:00
|
|
|
eventPaths = []
|
|
|
|
for event in eventlist:
|
|
|
|
eventPaths.append(event.path)
|
|
|
|
return eventPaths
|
|
|
|
|
2018-07-16 14:09:06 +02:00
|
|
|
@staticmethod
|
|
|
|
def get_event_ids(eventlist):
|
2017-08-22 16:43:09 +02:00
|
|
|
eventIDs = []
|
|
|
|
for event in eventlist:
|
|
|
|
eventIDs.append(event.pylot_id)
|
|
|
|
return eventIDs
|
|
|
|
|
|
|
|
def get_all_events(self):
|
|
|
|
return self.project.eventlist
|
|
|
|
|
|
|
|
def get_ref_events(self):
|
|
|
|
events = []
|
|
|
|
for event in self.project.eventlist:
|
|
|
|
if event.isRefEvent():
|
|
|
|
events.append(event)
|
|
|
|
return events
|
|
|
|
|
|
|
|
def get_test_events(self):
|
|
|
|
events = []
|
|
|
|
for event in self.project.eventlist:
|
|
|
|
if event.isTestEvent():
|
|
|
|
events.append(event)
|
|
|
|
return events
|
|
|
|
|
|
|
|
def get_manu_picked_events(self):
|
|
|
|
events = []
|
|
|
|
for event in self.project.eventlist:
|
|
|
|
if len(event.pylot_picks) > 0:
|
|
|
|
events.append(event)
|
|
|
|
return events
|
2015-07-09 11:37:03 +02:00
|
|
|
|
2015-11-30 09:50:47 +01:00
|
|
|
def addPicks(self, station, picks, type='manual'):
|
2017-06-19 10:37:24 +02:00
|
|
|
stat_picks = self.getPicksOnStation(station, type)
|
2017-08-15 14:54:13 +02:00
|
|
|
if not stat_picks:
|
2017-06-19 10:37:24 +02:00
|
|
|
rval = False
|
|
|
|
else:
|
2017-07-14 16:25:59 +02:00
|
|
|
rval = True
|
2017-08-15 14:54:13 +02:00
|
|
|
event = self.get_current_event()
|
|
|
|
# create dictionary switch
|
|
|
|
automanu = {'manual': event.setPick,
|
|
|
|
'auto': event.setAutopick}
|
|
|
|
# dictionary consisting of set station only
|
|
|
|
automanu[type](station=station, pick=picks)
|
2017-06-19 10:37:24 +02:00
|
|
|
return rval
|
2019-05-29 15:58:37 +02:00
|
|
|
|
|
|
|
def deletePicks(self, station, deleted_pick, type):
|
|
|
|
deleted_pick['station'] = station
|
|
|
|
self.addPicks(station, {}, type=type)
|
|
|
|
self.log_deleted_picks([deleted_pick])
|
|
|
|
|
|
|
|
def log_deleted_picks(self, deleted_picks, event_path=None):
|
|
|
|
''' Log deleted picks to list self.deleted_picks '''
|
|
|
|
if not event_path:
|
|
|
|
event_path = self.get_current_event_path()
|
|
|
|
for deleted_pick in deleted_picks:
|
|
|
|
deleted_pick = dict(deleted_pick)
|
|
|
|
if not event_path in self.deleted_picks.keys():
|
|
|
|
self.deleted_picks[event_path] = []
|
|
|
|
for key, value in deleted_pick.items():
|
|
|
|
if type(value) == UTCDateTime:
|
|
|
|
deleted_pick[key] = str(value)
|
|
|
|
deleted_pick['deletion_logtime'] = str(datetime.now())
|
|
|
|
self.deleted_picks[event_path].append(deleted_pick)
|
|
|
|
|
|
|
|
def dump_deleted_picks(self, event_path):
|
|
|
|
''' Save deleted picks to json file for event in event_path. Load old file before and merge'''
|
2019-06-24 15:02:07 +02:00
|
|
|
try:
|
|
|
|
deleted_picks_from_file = self.load_deleted_picks(event_path)
|
|
|
|
except Exception as e:
|
|
|
|
msg = 'WARNING! Deleted picks file could not be loaded: {}' \
|
|
|
|
' Check deleted picks file in path {} before continuing'
|
|
|
|
print(msg.format(e, event_path))
|
|
|
|
self.safetyCopy(event_path)
|
2020-01-14 13:57:12 +01:00
|
|
|
deleted_picks_event = self.deleted_picks.get(event_path)
|
|
|
|
if deleted_picks_event is None:
|
|
|
|
return
|
2019-05-29 15:58:37 +02:00
|
|
|
|
|
|
|
for pick in deleted_picks_from_file:
|
|
|
|
if not pick in deleted_picks_event:
|
|
|
|
deleted_picks_event.append(pick)
|
|
|
|
|
|
|
|
# if there are no picks to save
|
|
|
|
if not deleted_picks_event:
|
|
|
|
return
|
|
|
|
|
|
|
|
fpath = self.get_deleted_picks_fpath(event_path)
|
|
|
|
with open(fpath, 'w') as outfile:
|
2019-06-24 15:02:07 +02:00
|
|
|
json.dump(deleted_picks_event, outfile)
|
2019-05-29 15:58:37 +02:00
|
|
|
|
|
|
|
# clear entry for this event
|
|
|
|
self.deleted_picks[event_path] = []
|
|
|
|
|
2019-06-24 15:02:07 +02:00
|
|
|
def safetyCopy(self, event_path):
|
|
|
|
fpath = self.get_deleted_picks_fpath(event_path)
|
2021-03-30 08:28:31 +02:00
|
|
|
fpath_new = fpath.split('.json')[0] + '_copy_{}.json'.format(datetime.now()).replace(' ', '_')
|
2019-06-24 15:02:07 +02:00
|
|
|
shutil.move(fpath, fpath_new)
|
|
|
|
|
2019-05-29 15:58:37 +02:00
|
|
|
def load_deleted_picks(self, event_path):
|
|
|
|
''' Load a list with deleted picks for event in event_path from file '''
|
|
|
|
fpath = self.get_deleted_picks_fpath(event_path)
|
|
|
|
if not os.path.isfile(fpath):
|
|
|
|
return []
|
|
|
|
with open(fpath, 'r') as infile:
|
|
|
|
deleted_picks = json.load(infile)
|
|
|
|
return deleted_picks
|
|
|
|
|
|
|
|
def get_deleted_picks_fpath(self, event_path):
|
|
|
|
return os.path.join(event_path, 'deleted_picks.json')
|
2015-07-07 10:37:54 +02:00
|
|
|
|
2019-08-23 11:30:16 +02:00
|
|
|
def updatePicks(self, event=None):
|
2017-06-22 16:30:22 +02:00
|
|
|
if not event:
|
|
|
|
event = self.get_current_event()
|
2019-08-23 11:30:16 +02:00
|
|
|
event.pylot_picks = {}
|
|
|
|
event.pylot_autopicks = {}
|
2017-08-09 14:15:50 +02:00
|
|
|
picksdict = picksdict_from_picks(evt=self.get_data().get_evt_data())
|
2019-08-23 11:30:16 +02:00
|
|
|
event.addPicks(picksdict['manual'])
|
2020-07-30 13:27:38 +02:00
|
|
|
if picksdict['auto'] == {}:
|
|
|
|
event.addAutopicks(picksdict)
|
|
|
|
else:
|
|
|
|
event.addAutopicks(picksdict['auto'])
|
|
|
|
|
2018-07-10 11:13:41 +02:00
|
|
|
def drawPicks(self, station=None, picktype=None, stime=None):
|
2017-08-09 14:15:50 +02:00
|
|
|
# if picktype not specified, draw both
|
2018-07-10 11:13:41 +02:00
|
|
|
if not stime:
|
|
|
|
stime = self.getStime()
|
|
|
|
|
2017-08-09 14:15:50 +02:00
|
|
|
if not picktype:
|
2018-07-10 11:13:41 +02:00
|
|
|
self.drawPicks(station, 'manual', stime)
|
|
|
|
self.drawPicks(station, 'auto', stime)
|
2017-08-09 14:15:50 +02:00
|
|
|
return
|
2017-08-14 11:38:31 +02:00
|
|
|
|
2018-07-17 09:42:13 +02:00
|
|
|
if not picktype in ['manual', 'auto']:
|
|
|
|
raise TypeError('Unknown picktype {0}'.format(picktype))
|
|
|
|
|
2015-07-07 10:39:01 +02:00
|
|
|
# if picks to draw not specified, draw all picks available
|
|
|
|
if not station:
|
2015-11-30 09:50:47 +01:00
|
|
|
for station in self.getPicks(type=picktype):
|
2018-07-10 11:13:41 +02:00
|
|
|
self.drawPicks(station, picktype=picktype, stime=stime)
|
2015-07-07 10:39:01 +02:00
|
|
|
return
|
2017-08-14 11:38:31 +02:00
|
|
|
|
2018-07-18 14:12:59 +02:00
|
|
|
if self.pg:
|
|
|
|
pw = self.getPlotWidget().plotWidget
|
|
|
|
else:
|
|
|
|
ax = self.getPlotWidget().axes[0]
|
|
|
|
|
|
|
|
if station in self.drawnPicks[picktype].keys():
|
|
|
|
for item in self.drawnPicks[picktype][station]:
|
|
|
|
pw.removeItem(item)
|
|
|
|
self.drawnPicks[picktype][station] = []
|
|
|
|
|
2017-08-14 11:38:31 +02:00
|
|
|
# check for station key in dictionary, else return
|
|
|
|
if not station in self.getPicks(type=picktype):
|
|
|
|
return
|
|
|
|
|
2015-07-07 10:39:01 +02:00
|
|
|
# plotting picks
|
2018-08-06 16:03:54 +02:00
|
|
|
plotIDs = self.getStationIDs(station)
|
|
|
|
if not plotIDs:
|
2016-09-08 15:29:37 +02:00
|
|
|
return
|
2015-07-07 10:39:01 +02:00
|
|
|
|
2018-08-06 16:03:54 +02:00
|
|
|
for plotID in plotIDs:
|
|
|
|
ylims = np.array([-.5, +.5]) + plotID
|
2016-05-31 17:27:59 +02:00
|
|
|
|
2018-08-06 16:03:54 +02:00
|
|
|
stat_picks = self.getPicks(type=picktype)[station]
|
|
|
|
settings = QSettings()
|
2017-08-11 16:04:18 +02:00
|
|
|
|
2018-08-06 16:03:54 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
phaseID = self.getPhaseID(phase)
|
|
|
|
# get quality classes
|
2021-03-30 08:28:31 +02:00
|
|
|
if phaseID == 'P':
|
2018-08-06 16:03:54 +02:00
|
|
|
quality = getQualityFromUncertainty(picks['spe'], self._inputs['timeerrorsP'])
|
|
|
|
elif phaseID == 'S':
|
|
|
|
quality = getQualityFromUncertainty(picks['spe'], self._inputs['timeerrorsS'])
|
|
|
|
|
|
|
|
# quality = getPickQuality(self.get_data().getWFData(),
|
|
|
|
# stat_picks, self._inputs, phaseID,
|
|
|
|
# compclass)
|
|
|
|
|
2019-04-18 11:21:56 +02:00
|
|
|
if not picks['mpp']: continue
|
|
|
|
|
2018-08-06 16:03:54 +02:00
|
|
|
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']
|
|
|
|
|
|
|
|
if self.pg:
|
2017-06-08 14:09:01 +02:00
|
|
|
if spe:
|
2018-08-06 16:03:54 +02:00
|
|
|
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)
|
2019-03-22 10:42:16 +01:00
|
|
|
# Ugly fix: spe_l/r.curve.path is initialized to None and can't be accessed, causing the
|
|
|
|
# Warning: drawPicks: Could not create fill for symmetric pick error
|
|
|
|
# this generates them
|
|
|
|
spe_l.curve.shape()
|
|
|
|
spe_r.curve.shape()
|
2018-08-06 16:03:54 +02:00
|
|
|
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)))
|
2017-06-08 14:09:01 +02:00
|
|
|
else:
|
2018-08-06 16:03:54 +02:00
|
|
|
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))
|
2015-07-07 10:39:01 +02:00
|
|
|
|
2016-08-31 12:16:48 +02:00
|
|
|
def locate_event(self):
|
2016-08-25 21:32:41 +02:00
|
|
|
"""
|
|
|
|
locate event using the manually picked phases
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
if not self.okToContinue():
|
|
|
|
return
|
2018-06-28 15:22:40 +02:00
|
|
|
parameter = self._inputs
|
|
|
|
loctool = 'nll'
|
2016-08-25 13:31:51 +02:00
|
|
|
lt = locateTool[loctool]
|
|
|
|
# get working directory
|
2018-06-28 15:22:40 +02:00
|
|
|
locroot = parameter['nllocroot']
|
2016-08-26 10:48:16 +02:00
|
|
|
if locroot is None:
|
|
|
|
self.PyLoTprefs()
|
2016-08-31 12:16:48 +02:00
|
|
|
self.locate_event()
|
2016-08-26 14:36:33 +02:00
|
|
|
|
2018-06-28 15:59:13 +02:00
|
|
|
ctrfile = os.path.join(locroot, 'run', parameter['ctrfile'])
|
2018-06-28 15:22:40 +02:00
|
|
|
ttt = parameter['ttpatter']
|
|
|
|
outfile = parameter['outpatter']
|
2017-06-30 17:20:18 +02:00
|
|
|
eventname = self.get_current_event_name()
|
2017-08-14 15:09:49 +02:00
|
|
|
obsdir = os.path.join(self._inputs['rootpath'], self._inputs['datapath'], self._inputs['database'], eventname)
|
2021-03-30 16:39:44 +02:00
|
|
|
self.saveData(event=self.get_current_event(), directory=obsdir, outformats='.obs')
|
2017-07-14 16:25:59 +02:00
|
|
|
filename = 'PyLoT_' + eventname
|
2017-06-30 17:20:18 +02:00
|
|
|
locpath = os.path.join(locroot, 'loc', filename)
|
|
|
|
phasefile = os.path.join(obsdir, filename + '.obs')
|
2018-06-28 15:22:40 +02:00
|
|
|
lt.modify_inputs(ctrfile, locroot, filename, phasefile, ttt)
|
2016-08-25 21:32:41 +02:00
|
|
|
try:
|
2018-06-28 15:22:40 +02:00
|
|
|
lt.locate(ctrfile)
|
2016-08-25 21:32:41 +02:00
|
|
|
except RuntimeError as e:
|
|
|
|
print(e.message)
|
2018-07-16 14:21:41 +02:00
|
|
|
# finally:
|
2017-08-14 15:09:49 +02:00
|
|
|
# os.remove(phasefile)
|
2017-06-26 12:19:06 +02:00
|
|
|
self.get_data().applyEVTData(lt.read_location(locpath), typ='event')
|
2019-10-24 10:12:00 +02:00
|
|
|
for event in self.calc_magnitude():
|
|
|
|
self.get_data().applyEVTData(event, typ='event')
|
2016-09-02 14:21:59 +02:00
|
|
|
|
2017-04-19 15:31:08 +02:00
|
|
|
def init_array_tab(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Init second main tab if neither metadata nor
|
|
|
|
array map are given. A button will be show calling self.get_metadata.
|
|
|
|
'''
|
2017-05-22 15:34:07 +02:00
|
|
|
if hasattr(self, 'metadata_widget'):
|
|
|
|
if self.metadata_widget:
|
|
|
|
self.metadata_widget.setParent(None)
|
|
|
|
self.array_layout.removeWidget(self.metadata_widget)
|
|
|
|
if hasattr(self, 'array_map'):
|
|
|
|
if self.array_map:
|
2017-07-14 16:25:59 +02:00
|
|
|
self.array_map.setParent(None)
|
2017-05-22 15:34:07 +02:00
|
|
|
self.array_layout.removeWidget(self.array_map)
|
2017-04-20 12:05:34 +02:00
|
|
|
self.metadata_widget = QWidget(self)
|
2017-04-19 15:31:08 +02:00
|
|
|
grid_layout = QGridLayout()
|
|
|
|
grid_layout.setColumnStretch(0, 1)
|
|
|
|
grid_layout.setColumnStretch(2, 1)
|
|
|
|
grid_layout.setRowStretch(0, 1)
|
2017-08-17 10:46:06 +02:00
|
|
|
grid_layout.setRowStretch(4, 1)
|
2017-04-19 15:31:08 +02:00
|
|
|
|
2017-08-17 10:46:06 +02:00
|
|
|
self.inventory_label = QLabel('No inventory set...')
|
|
|
|
# init inventory button
|
2018-07-19 11:50:29 +02:00
|
|
|
self.new_inv_button = QPushButton('Manage inventory files')
|
2017-08-18 11:32:45 +02:00
|
|
|
self.new_inv_button.setIcon(self.inventoryIcon)
|
2017-08-17 10:46:06 +02:00
|
|
|
self.new_inv_button.clicked.connect(self.inventoryAction.trigger)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-08-17 10:46:06 +02:00
|
|
|
self.init_map_button = QPushButton('Init array map')
|
2017-08-18 11:32:45 +02:00
|
|
|
self.init_map_button.setIcon(self.mapIcon)
|
2017-08-17 10:46:06 +02:00
|
|
|
self.init_map_button.clicked.connect(self.initMapAction.trigger)
|
|
|
|
self.init_map_button.setEnabled(False)
|
|
|
|
|
|
|
|
grid_layout.addWidget(self.inventory_label, 1, 1)
|
|
|
|
grid_layout.addWidget(self.new_inv_button, 2, 1)
|
|
|
|
grid_layout.addWidget(self.init_map_button, 3, 1)
|
2017-04-19 15:31:08 +02:00
|
|
|
|
2017-04-20 12:05:34 +02:00
|
|
|
self.metadata_widget.setLayout(grid_layout)
|
|
|
|
self.array_layout.addWidget(self.metadata_widget)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-04-19 16:05:45 +02:00
|
|
|
def init_array_map(self, index=1):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Try to init array map widget. If no metadata are given,
|
|
|
|
self.get_metadata will be called.
|
|
|
|
'''
|
2017-05-03 11:28:43 +02:00
|
|
|
self.tabs.setCurrentIndex(1)
|
2018-12-07 11:19:54 +01:00
|
|
|
# if there is no metadata (invetories is an empty list), just initialize the default empty tab
|
|
|
|
if not self.metadata.inventories:
|
|
|
|
self.init_array_tab()
|
|
|
|
return
|
2017-05-10 16:28:07 +02:00
|
|
|
if hasattr(self, 'metadata_widget'):
|
|
|
|
if self.metadata_widget:
|
|
|
|
self.metadata_widget.setParent(None)
|
|
|
|
self.array_layout.removeWidget(self.metadata_widget)
|
|
|
|
if hasattr(self, 'array_map'):
|
|
|
|
if self.array_map:
|
2017-07-14 16:25:59 +02:00
|
|
|
self.array_map.setParent(None)
|
2017-05-10 16:28:07 +02:00
|
|
|
self.array_layout.removeWidget(self.array_map)
|
2017-07-19 10:11:26 +02:00
|
|
|
elif not self.array_map:
|
2017-08-17 10:46:06 +02:00
|
|
|
self.init_metadata()
|
2017-07-19 10:11:26 +02:00
|
|
|
if not self.metadata:
|
|
|
|
return
|
2019-09-05 17:19:40 +02:00
|
|
|
self.array_map = Array_map(self, self.metadata)
|
2017-07-14 16:25:59 +02:00
|
|
|
# self.array_map_thread()
|
2017-04-20 12:05:34 +02:00
|
|
|
self.array_layout.addWidget(self.array_map)
|
2017-04-19 16:05:45 +02:00
|
|
|
self.tabs.setCurrentIndex(index)
|
2017-04-20 17:06:36 +02:00
|
|
|
self.refresh_array_map()
|
2017-05-11 17:15:20 +02:00
|
|
|
|
|
|
|
def array_map_thread(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Start modal thread to init the array_map object.
|
|
|
|
'''
|
|
|
|
# Note: basemap generation freezes GUI but cannot be threaded as it generates a Pixmap.
|
2017-09-18 14:57:48 +02:00
|
|
|
self.amt = Thread(self, self.array_map.init_map, arg=None, progressText='Generating map...',
|
|
|
|
pb_widget=self.mainProgressBarWidget)
|
2017-05-11 17:15:20 +02:00
|
|
|
self.amt.finished.connect(self.finish_array_map)
|
|
|
|
self.amt.start()
|
|
|
|
|
|
|
|
def finish_array_map(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Add array_map to GUI tab when array_map_thread has finished.
|
|
|
|
'''
|
2017-05-11 17:15:20 +02:00
|
|
|
self.array_map = self.amt.data
|
|
|
|
self.array_layout.addWidget(self.array_map)
|
2017-07-14 16:25:59 +02:00
|
|
|
# self.tabs.setCurrentIndex(index)
|
|
|
|
# self.refresh_array_map()
|
|
|
|
|
2017-04-19 15:31:08 +02:00
|
|
|
def refresh_array_map(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Refresh array map when current event is changed.
|
|
|
|
'''
|
2017-04-18 17:17:46 +02:00
|
|
|
if not self.array_map:
|
|
|
|
return
|
2017-04-19 15:31:08 +02:00
|
|
|
# refresh with new picks here!!!
|
2017-06-23 15:40:13 +02:00
|
|
|
event = self.get_current_event()
|
|
|
|
if hasattr(event, 'origins'):
|
|
|
|
if event.origins:
|
|
|
|
lat = event.origins[0].latitude
|
|
|
|
lon = event.origins[0].longitude
|
|
|
|
self.array_map.eventLoc = (lat, lon)
|
2017-08-17 10:46:06 +02:00
|
|
|
if self.get_current_event():
|
2018-06-13 17:01:05 +02:00
|
|
|
self.array_map.refresh_drawings(self.get_current_event().getPicks(),
|
2018-07-16 14:21:41 +02:00
|
|
|
self.get_current_event().getAutopicks(), )
|
2017-04-20 17:06:36 +02:00
|
|
|
self._eventChanged[1] = False
|
2017-04-19 15:31:08 +02:00
|
|
|
|
2017-05-12 15:37:57 +02:00
|
|
|
def init_event_table(self, tabindex=2):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Build and initiate event table (3rd tab [index=2]) containing information of every event.
|
|
|
|
'''
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-08-07 12:14:54 +02:00
|
|
|
def set_enabled(item, selectable=True, checkable=False):
|
2017-05-24 14:12:41 +02:00
|
|
|
# modify item flags depending on case needed
|
2017-08-07 12:14:54 +02:00
|
|
|
if selectable and not checkable:
|
2017-04-20 12:05:34 +02:00
|
|
|
item.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable)
|
2017-08-07 12:14:54 +02:00
|
|
|
elif selectable and checkable:
|
2017-07-14 16:25:59 +02:00
|
|
|
item.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsSelectable)
|
2017-04-20 12:05:34 +02:00
|
|
|
else:
|
2017-08-07 12:14:54 +02:00
|
|
|
item.setFlags(QtCore.Qt.ItemIsEnabled)
|
2017-04-20 12:05:34 +02:00
|
|
|
|
|
|
|
if self.project:
|
|
|
|
eventlist = self.project.eventlist
|
|
|
|
else:
|
|
|
|
eventlist = []
|
|
|
|
|
2017-08-07 12:14:54 +02:00
|
|
|
def cell_clicked(row=None, column=None):
|
|
|
|
table = self.project._table
|
2019-02-28 16:39:53 +01:00
|
|
|
event = self.project.getEventFromPath(table[row][1].text().split('*')[0])
|
2017-08-07 12:14:54 +02:00
|
|
|
if column == 0:
|
|
|
|
self.remove_event(event)
|
|
|
|
|
2017-04-20 12:05:34 +02:00
|
|
|
def cell_changed(row=None, column=None):
|
2017-05-24 14:12:41 +02:00
|
|
|
# connected to cell changes in event table
|
|
|
|
# changes attributes of the corresponding event
|
2017-04-20 12:05:34 +02:00
|
|
|
table = self.project._table
|
2019-02-28 16:39:53 +01:00
|
|
|
event = self.project.getEventFromPath(table[row][1].text().split('*')[0])
|
2017-07-18 16:07:08 +02:00
|
|
|
if column == 9 or column == 10:
|
2017-07-14 16:25:59 +02:00
|
|
|
# toggle checked states (exclusive)
|
2017-07-18 16:07:08 +02:00
|
|
|
item_ref = table[row][9]
|
|
|
|
item_test = table[row][10]
|
|
|
|
if column == 9 and item_ref.checkState():
|
2017-04-20 12:05:34 +02:00
|
|
|
item_test.setCheckState(QtCore.Qt.Unchecked)
|
|
|
|
event.setRefEvent(True)
|
2017-07-18 16:07:08 +02:00
|
|
|
elif column == 9 and not item_ref.checkState():
|
2017-07-14 16:25:59 +02:00
|
|
|
event.setRefEvent(False)
|
2017-07-18 16:07:08 +02:00
|
|
|
elif column == 10 and item_test.checkState():
|
2017-04-20 12:05:34 +02:00
|
|
|
item_ref.setCheckState(QtCore.Qt.Unchecked)
|
|
|
|
event.setTestEvent(True)
|
2017-07-18 16:07:08 +02:00
|
|
|
elif column == 10 and not item_test.checkState():
|
2017-04-20 14:03:26 +02:00
|
|
|
event.setTestEvent(False)
|
2017-05-31 15:41:25 +02:00
|
|
|
self.fill_eventbox()
|
2017-07-18 16:07:08 +02:00
|
|
|
elif column == 11:
|
2017-07-14 16:25:59 +02:00
|
|
|
# update event notes
|
2017-07-18 16:07:08 +02:00
|
|
|
notes = table[row][11].text()
|
2017-04-20 12:05:34 +02:00
|
|
|
event.addNotes(notes)
|
2017-05-31 15:41:25 +02:00
|
|
|
self.fill_eventbox()
|
2017-04-20 12:05:34 +02:00
|
|
|
|
2019-03-06 14:52:23 +01:00
|
|
|
event.dirty = True
|
|
|
|
self.setDirty(True)
|
|
|
|
|
2018-04-26 16:19:12 +02:00
|
|
|
current_event = self.get_current_event()
|
2019-07-01 17:24:06 +02:00
|
|
|
scroll_item = None
|
2018-04-26 16:19:12 +02:00
|
|
|
|
2017-07-18 16:07:08 +02:00
|
|
|
# generate delete icon
|
|
|
|
del_icon = QIcon()
|
|
|
|
del_icon.addPixmap(QPixmap(':/icons/delete.png'))
|
2017-07-31 13:43:06 +02:00
|
|
|
|
2017-05-24 14:12:41 +02:00
|
|
|
# remove old table
|
|
|
|
if hasattr(self, 'event_table'):
|
|
|
|
self.event_table.setParent(None)
|
|
|
|
self.events_layout.removeWidget(self.event_table)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-05-24 14:12:41 +02:00
|
|
|
# init new qtable
|
2017-09-06 18:02:09 +02:00
|
|
|
self.event_table = QtGui.QTableWidget(self)
|
2017-07-18 16:07:08 +02:00
|
|
|
self.event_table.setColumnCount(12)
|
2017-05-24 14:12:41 +02:00
|
|
|
self.event_table.setRowCount(len(eventlist))
|
2019-07-01 17:24:06 +02:00
|
|
|
self.event_table.setHorizontalHeaderLabels(self.table_headers)
|
2017-04-20 12:05:34 +02:00
|
|
|
|
2017-05-24 14:12:41 +02:00
|
|
|
# iterate through eventlist and generate items for table rows
|
2017-04-20 12:05:34 +02:00
|
|
|
self.project._table = []
|
2021-03-30 08:28:31 +02:00
|
|
|
for index, event in enumerate(eventlist):
|
2017-08-22 11:53:19 +02:00
|
|
|
phaseErrors = {'P': self._inputs['timeerrorsP'],
|
|
|
|
'S': self._inputs['timeerrorsS']}
|
|
|
|
|
|
|
|
ma_props = {'manual': event.pylot_picks,
|
|
|
|
'auto': event.pylot_autopicks}
|
|
|
|
ma_count = {'manual': 0,
|
|
|
|
'auto': 0}
|
2018-07-16 13:51:18 +02:00
|
|
|
ma_count_total = {'manual': 0,
|
|
|
|
'auto': 0}
|
2017-08-22 11:53:19 +02:00
|
|
|
|
|
|
|
for ma in ma_props.keys():
|
|
|
|
if ma_props[ma]:
|
|
|
|
for picks in ma_props[ma].values():
|
|
|
|
for phasename, pick in picks.items():
|
2017-08-23 11:51:59 +02:00
|
|
|
if not type(pick) in [dict, AttribDict]:
|
|
|
|
continue
|
2018-07-16 17:56:17 +02:00
|
|
|
if pick.get('spe'):
|
2017-08-22 11:53:19 +02:00
|
|
|
ma_count[ma] += 1
|
2018-07-16 13:51:18 +02:00
|
|
|
ma_count_total[ma] += 1
|
2017-07-18 16:07:08 +02:00
|
|
|
|
|
|
|
# init table items for current row
|
2017-08-07 12:14:54 +02:00
|
|
|
item_delete = QtGui.QTableWidgetItem()
|
2017-07-18 16:07:08 +02:00
|
|
|
item_delete.setIcon(del_icon)
|
2017-04-20 12:05:34 +02:00
|
|
|
item_path = QtGui.QTableWidgetItem()
|
2017-06-23 14:56:56 +02:00
|
|
|
item_time = QtGui.QTableWidgetItem()
|
|
|
|
item_lat = QtGui.QTableWidgetItem()
|
|
|
|
item_lon = QtGui.QTableWidgetItem()
|
|
|
|
item_depth = QtGui.QTableWidgetItem()
|
2020-09-28 15:11:23 +02:00
|
|
|
item_momentmag = QtGui.QTableWidgetItem()
|
|
|
|
item_localmag = QtGui.QTableWidgetItem()
|
2018-07-16 13:51:18 +02:00
|
|
|
item_nmp = QtGui.QTableWidgetItem('{}({})'.format(ma_count['manual'], ma_count_total['manual']))
|
2017-04-21 15:46:57 +02:00
|
|
|
item_nmp.setIcon(self.manupicksicon_small)
|
2018-07-16 13:51:18 +02:00
|
|
|
item_nap = QtGui.QTableWidgetItem('{}({})'.format(ma_count['auto'], ma_count_total['auto']))
|
2017-04-21 15:46:57 +02:00
|
|
|
item_nap.setIcon(self.autopicksicon_small)
|
2017-04-20 12:05:34 +02:00
|
|
|
item_ref = QtGui.QTableWidgetItem()
|
|
|
|
item_test = QtGui.QTableWidgetItem()
|
2017-04-20 14:03:26 +02:00
|
|
|
item_notes = QtGui.QTableWidgetItem()
|
2017-04-21 15:46:57 +02:00
|
|
|
|
2018-07-31 09:41:48 +02:00
|
|
|
event_str = event.path
|
|
|
|
if event.dirty:
|
|
|
|
event_str += '*'
|
|
|
|
|
|
|
|
item_path.setText(event_str)
|
2017-06-23 14:56:56 +02:00
|
|
|
if hasattr(event, 'origins'):
|
|
|
|
if event.origins:
|
|
|
|
origin = event.origins[0]
|
2018-07-16 14:21:41 +02:00
|
|
|
item_time.setText(str(origin.time + 0).split('.')[0]) # +0 as workaround in case time=0s
|
2017-06-23 14:56:56 +02:00
|
|
|
item_lon.setText(str(origin.longitude))
|
|
|
|
item_lat.setText(str(origin.latitude))
|
|
|
|
item_depth.setText(str(origin.depth))
|
|
|
|
if hasattr(event, 'magnitudes'):
|
|
|
|
if event.magnitudes:
|
2020-09-28 15:11:23 +02:00
|
|
|
moment_magnitude = event.magnitudes[0]
|
|
|
|
moment_magnitude.mag = '%4.1f' % moment_magnitude.mag
|
|
|
|
local_magnitude = event.magnitudes[1]
|
|
|
|
local_magnitude.mag = '%4.1f' % local_magnitude.mag
|
|
|
|
item_momentmag.setText(str(moment_magnitude.mag))
|
|
|
|
item_localmag.setText(str(local_magnitude.mag))
|
2017-06-23 14:56:56 +02:00
|
|
|
item_notes.setText(event.notes)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-04-21 15:46:57 +02:00
|
|
|
set_enabled(item_path, True, False)
|
|
|
|
set_enabled(item_nmp, True, False)
|
|
|
|
set_enabled(item_nap, True, False)
|
2017-08-07 12:14:54 +02:00
|
|
|
set_enabled(item_delete, False, False)
|
2017-06-26 12:19:06 +02:00
|
|
|
if event.pylot_picks:
|
2017-04-20 12:05:34 +02:00
|
|
|
set_enabled(item_ref, True, True)
|
|
|
|
set_enabled(item_test, True, True)
|
|
|
|
else:
|
|
|
|
set_enabled(item_ref, False, True)
|
|
|
|
set_enabled(item_test, False, True)
|
|
|
|
|
|
|
|
if event.isRefEvent():
|
|
|
|
item_ref.setCheckState(QtCore.Qt.Checked)
|
|
|
|
else:
|
|
|
|
item_ref.setCheckState(QtCore.Qt.Unchecked)
|
|
|
|
if event.isTestEvent():
|
|
|
|
item_test.setCheckState(QtCore.Qt.Checked)
|
|
|
|
else:
|
|
|
|
item_test.setCheckState(QtCore.Qt.Unchecked)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2020-09-28 15:11:23 +02:00
|
|
|
row = [item_delete, item_path, item_time, item_lat, item_lon, item_depth, item_localmag,
|
2021-03-30 08:28:31 +02:00
|
|
|
item_momentmag, item_nmp, item_nap, item_ref, item_test, item_notes]
|
2020-01-14 13:57:12 +01:00
|
|
|
self.project._table.append(row)
|
2017-04-20 12:05:34 +02:00
|
|
|
|
2020-01-14 13:57:12 +01:00
|
|
|
self.setItemColor(row, index, event, current_event)
|
2018-04-26 16:19:12 +02:00
|
|
|
|
2019-07-01 17:24:06 +02:00
|
|
|
if event == current_event:
|
|
|
|
scroll_item = item_path
|
|
|
|
|
2018-04-26 16:19:12 +02:00
|
|
|
# manipulate items
|
|
|
|
item_ref.setBackground(self._ref_test_colors['ref'])
|
|
|
|
item_test.setBackground(self._ref_test_colors['test'])
|
|
|
|
|
2017-04-20 12:05:34 +02:00
|
|
|
for r_index, row in enumerate(self.project._table):
|
|
|
|
for c_index, item in enumerate(row):
|
2017-07-18 16:07:08 +02:00
|
|
|
if type(item) == QtGui.QTableWidgetItem:
|
|
|
|
self.event_table.setItem(r_index, c_index, item)
|
|
|
|
elif type(item) in [QtGui.QWidget, QtGui.QPushButton]:
|
2017-08-03 09:41:54 +02:00
|
|
|
self.event_table.setCellWidget(r_index, c_index, item)
|
2017-04-20 12:05:34 +02:00
|
|
|
|
2017-05-24 14:12:41 +02:00
|
|
|
header = self.event_table.horizontalHeader()
|
2017-04-20 12:05:34 +02:00
|
|
|
header.setResizeMode(QtGui.QHeaderView.ResizeToContents)
|
|
|
|
header.setStretchLastSection(True)
|
2017-05-24 14:12:41 +02:00
|
|
|
self.event_table.cellChanged[int, int].connect(cell_changed)
|
2017-08-07 12:14:54 +02:00
|
|
|
self.event_table.cellClicked[int, int].connect(cell_clicked)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-05-24 14:12:41 +02:00
|
|
|
self.events_layout.addWidget(self.event_table)
|
2017-05-12 15:37:57 +02:00
|
|
|
self.tabs.setCurrentIndex(tabindex)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2019-07-01 17:24:06 +02:00
|
|
|
self.event_table.scrollToItem(scroll_item)
|
|
|
|
|
|
|
|
def exportProjectTableDialogs(self):
|
|
|
|
if not self.project or not self.project._table:
|
|
|
|
QMessageBox.warning(self, 'Nothing to export', 'No project or no project table to export yet!')
|
|
|
|
return
|
|
|
|
|
|
|
|
sld = SingleTextLineDialog(label='Specify separator (do not use within notes!): ', default_text=';')
|
|
|
|
if not sld.exec_():
|
|
|
|
return
|
|
|
|
separator = sld.lineEdit.text()
|
|
|
|
|
|
|
|
fd = QtGui.QFileDialog()
|
|
|
|
fname = fd.getSaveFileName(self, 'Browse for file.',
|
|
|
|
filter='Table (*.csv)')[0]
|
|
|
|
if not fname: return
|
|
|
|
|
|
|
|
if not fname.endswith('.csv'):
|
|
|
|
fname += '.csv'
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.exportProjectTable(fname, separator)
|
|
|
|
except Exception as e:
|
|
|
|
QMessageBox.warning(self, 'Could not save file',
|
|
|
|
'Could not save file {}.'.format(fname))
|
|
|
|
return
|
|
|
|
|
|
|
|
def exportProjectTable(self, filename, separator=';'):
|
|
|
|
with open(filename, 'w') as outfile:
|
|
|
|
for header in self.table_headers[1:12]:
|
|
|
|
outfile.write('{}{}'.format(header, separator))
|
|
|
|
outfile.write('\n')
|
|
|
|
|
|
|
|
for row in self.project._table:
|
|
|
|
row = row[1:12]
|
|
|
|
event, time, lat, lon, depth, mag, nmp, nap, tune, test, notes = row
|
|
|
|
row_str = ''
|
|
|
|
for index in range(len(row)):
|
2021-03-30 08:28:31 +02:00
|
|
|
row_str += '{}' + '{}'.format(separator)
|
2019-07-01 17:24:06 +02:00
|
|
|
|
|
|
|
row_str = row_str.format(event.text(), time.text(), lat.text(), lon.text(), depth.text(), mag.text(),
|
|
|
|
nmp.text(), nap.text(), bool(tune.checkState()), bool(test.checkState()),
|
|
|
|
notes.text())
|
|
|
|
outfile.write(row_str + '\n')
|
|
|
|
|
|
|
|
message = 'Wrote table to file: {}'.format(filename)
|
|
|
|
print(message)
|
|
|
|
self.update_status(message)
|
|
|
|
|
2018-06-19 11:28:41 +02:00
|
|
|
def setItemColor(self, item_list, index, event, current_event):
|
|
|
|
def set_background_color(items, color):
|
|
|
|
for item in items:
|
|
|
|
item.setBackground(color)
|
|
|
|
|
|
|
|
def set_foreground_color(items, color):
|
|
|
|
for item in items:
|
|
|
|
item.setForeground(color)
|
|
|
|
|
|
|
|
if index % 2:
|
|
|
|
set_background_color(item_list, QtGui.QColor(*(245, 245, 245, 255)))
|
|
|
|
|
|
|
|
if self.isEmpty(event.path):
|
|
|
|
set_foreground_color(item_list, QtGui.QColor(*(180, 180, 180, 255)))
|
|
|
|
|
|
|
|
if event == current_event:
|
|
|
|
set_background_color(item_list, QtGui.QColor(*(0, 143, 143, 255)))
|
|
|
|
|
2017-04-19 15:31:08 +02:00
|
|
|
def set_metadata(self):
|
2018-07-23 14:54:53 +02:00
|
|
|
self.project.inventories = self.metadata.inventories
|
|
|
|
if self.metadata.inventories:
|
|
|
|
self.init_map_button.setEnabled(True)
|
|
|
|
self.initMapAction.setEnabled(True)
|
|
|
|
self.inventory_label.setText('Inventory set!')
|
|
|
|
self.setDirty(True)
|
2019-02-27 09:46:37 +01:00
|
|
|
if not self.metadata.inventories:
|
|
|
|
self.init_map_button.setEnabled(False)
|
|
|
|
self.initMapAction.setEnabled(False)
|
|
|
|
self.inventory_label.setText("No inventory set...")
|
2021-03-30 08:28:31 +02:00
|
|
|
# self.setDirty(False)
|
2017-08-17 10:46:06 +02:00
|
|
|
|
2018-07-23 16:03:15 +02:00
|
|
|
def add_metadata(self):
|
2018-07-23 14:54:53 +02:00
|
|
|
self.add_metadata_widget = AddMetadataWidget(self, metadata=self.metadata)
|
2018-10-18 13:02:09 +02:00
|
|
|
self.add_metadata_widget.accept_button.clicked.connect(self.set_metadata)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-09-18 16:12:02 +02:00
|
|
|
def init_metadata(self, new=False, ask_default=True):
|
2018-07-23 14:54:53 +02:00
|
|
|
if hasattr(self.project, 'inventories'):
|
2018-08-06 09:19:30 +02:00
|
|
|
self.metadata = Metadata(verbosity=0)
|
2018-07-23 14:54:53 +02:00
|
|
|
for inventory in self.project.inventories:
|
|
|
|
self.metadata.add_inventory(inventory)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2019-09-09 16:23:34 +02:00
|
|
|
def calc_magnitude(self):
|
2017-08-17 10:46:06 +02:00
|
|
|
self.init_metadata()
|
2017-04-12 16:43:29 +02:00
|
|
|
if not self.metadata:
|
|
|
|
return None
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2016-09-27 15:15:53 +02:00
|
|
|
wf_copy = self.get_data().getWFData().copy()
|
2019-10-24 10:12:00 +02:00
|
|
|
|
|
|
|
wf_select = Stream()
|
2019-09-11 12:13:53 +02:00
|
|
|
# restitute only picked traces
|
2019-10-24 10:12:00 +02:00
|
|
|
for station in np.unique(self.getPicks('manual').keys() + self.getPicks('auto').keys()):
|
|
|
|
wf_select += wf_copy.select(station=station)
|
|
|
|
|
|
|
|
corr_wf = restitute_data(wf_select, self.metadata)
|
|
|
|
# calculate moment magnitude
|
|
|
|
moment_mag = MomentMagnitude(corr_wf, self.get_data().get_evt_data(), self.inputs.get('vp'),
|
|
|
|
self.inputs.get('Qp'), self.inputs.get('rho'), verbosity=True)
|
2019-10-28 16:51:04 +01:00
|
|
|
moment_mag.updated_event()
|
|
|
|
event_moment_mag = moment_mag.net_magnitude()
|
2019-10-25 16:16:07 +02:00
|
|
|
if event_moment_mag is not None:
|
|
|
|
print("Network moment magnitude: %4.1f" % event_moment_mag.mag)
|
|
|
|
|
2019-10-24 10:12:00 +02:00
|
|
|
# calculate local magnitude
|
|
|
|
local_mag = LocalMagnitude(corr_wf, self.get_data().get_evt_data(), self.inputs.get('sstop'),
|
|
|
|
self.inputs.get('WAscaling'), verbosity=True)
|
|
|
|
|
|
|
|
magscaling = self.inputs.get('magscaling')
|
|
|
|
event_loc_mag = local_mag.updated_event(magscaling)
|
|
|
|
net_ml = local_mag.net_magnitude(magscaling)
|
|
|
|
if net_ml:
|
|
|
|
print("Network local magnitude: %4.1f" % net_ml.mag)
|
|
|
|
if magscaling is None:
|
|
|
|
scaling = False
|
2020-07-27 16:55:19 +02:00
|
|
|
elif magscaling[0] == 0.0 and magscaling[1] == 0.0:
|
2019-10-24 10:12:00 +02:00
|
|
|
scaling = False
|
|
|
|
else:
|
|
|
|
scaling = True
|
|
|
|
if scaling:
|
|
|
|
print("Network local magnitude scaled with:")
|
|
|
|
print("%f * Ml + %f" % (magscaling[0], magscaling[1]))
|
|
|
|
|
2019-10-25 16:16:07 +02:00
|
|
|
return event_loc_mag, event_moment_mag
|
2014-12-08 10:26:14 +01:00
|
|
|
|
2015-11-06 08:20:08 +01:00
|
|
|
def check4Loc(self):
|
2017-04-10 14:43:11 +02:00
|
|
|
return self.picksNum() >= 4
|
2015-11-06 08:20:08 +01:00
|
|
|
|
2017-08-31 11:16:13 +02:00
|
|
|
# def check4Comparison(self):
|
|
|
|
# mpicks = self.getPicks()
|
|
|
|
# apicks = self.getPicks('auto')
|
|
|
|
# for station, phases in mpicks.items():
|
|
|
|
# try:
|
|
|
|
# aphases = apicks[station]
|
|
|
|
# for phase in phases.keys():
|
|
|
|
# if phase in aphases.keys():
|
|
|
|
# return True
|
|
|
|
# except KeyError:
|
|
|
|
# continue
|
|
|
|
# return False
|
2016-06-06 14:10:46 +02:00
|
|
|
|
|
|
|
def picksNum(self, type='manual'):
|
2015-11-06 08:20:08 +01:00
|
|
|
num = 0
|
2016-06-06 14:10:46 +02:00
|
|
|
for phases in self.getPicks(type).values():
|
2015-11-06 08:20:08 +01:00
|
|
|
num += len(phases)
|
|
|
|
return num
|
|
|
|
|
2016-09-02 14:21:59 +02:00
|
|
|
def get_loc_flag(self):
|
2015-11-06 15:40:21 +01:00
|
|
|
return self.loc
|
|
|
|
|
2016-09-02 14:21:59 +02:00
|
|
|
def set_loc_flag(self, value):
|
2015-11-06 15:40:21 +01:00
|
|
|
self.loc = value
|
2015-11-06 08:20:08 +01:00
|
|
|
|
2016-09-02 14:21:59 +02:00
|
|
|
def check_loc_plt(self):
|
|
|
|
evt = self.get_data().get_evt_data()
|
|
|
|
if evt.origins and evt.magnitudes:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def update_status(self, message, duration=5000):
|
2015-11-09 08:53:26 +01:00
|
|
|
self.statusBar().showMessage(message, duration)
|
2016-09-02 14:21:59 +02:00
|
|
|
if self.get_data() is not None:
|
2017-06-06 15:51:06 +02:00
|
|
|
if not self.get_current_event() or not self.project.location:
|
2017-07-14 16:25:59 +02:00
|
|
|
self.setWindowTitle("PyLoT - New project [*]")
|
2017-06-06 15:51:06 +02:00
|
|
|
elif self.get_current_event():
|
2017-06-06 16:30:27 +02:00
|
|
|
self.setWindowTitle("PyLoT - {} [*]".format(self.project.location))
|
2015-11-09 08:53:26 +01:00
|
|
|
else:
|
|
|
|
self.setWindowTitle(
|
2016-03-30 07:00:31 +02:00
|
|
|
"PyLoT - seismic processing the python way[*]")
|
2015-11-09 08:53:26 +01:00
|
|
|
self.setWindowModified(self.dirty)
|
|
|
|
|
2016-09-02 14:21:59 +02:00
|
|
|
def tutor_user(self):
|
2017-05-31 13:45:48 +02:00
|
|
|
trace_pick = ' select trace to pick on station ...'
|
|
|
|
strg_key = ' - [CTRL + mousewheel] vertical spacing'
|
|
|
|
shift_key = ' - [SHIFT + mousewheel] horizontal zoom'
|
|
|
|
message = trace_pick + strg_key + shift_key
|
|
|
|
self.update_status(message, 10000)
|
2015-07-07 10:45:42 +02:00
|
|
|
|
2016-09-02 14:21:59 +02:00
|
|
|
def show_event_information(self):
|
2014-11-28 11:15:49 +01:00
|
|
|
pass
|
|
|
|
|
2015-01-22 16:41:52 +01:00
|
|
|
def createNewEvent(self):
|
|
|
|
if self.okToContinue():
|
|
|
|
new = NewEventDlg()
|
2015-01-23 10:21:34 +01:00
|
|
|
if new.exec_() != QDialog.Rejected:
|
2015-01-22 16:41:52 +01:00
|
|
|
evtpar = new.getValues()
|
2016-05-20 14:46:10 +02:00
|
|
|
cinfo = create_creation_info(agency_id=self.agency)
|
|
|
|
event = create_event(evtpar['origintime'], cinfo)
|
2015-06-11 10:12:50 +02:00
|
|
|
self.data = Data(self, evtdata=event)
|
2015-07-18 16:11:20 +02:00
|
|
|
self.setDirty(True)
|
2015-01-22 16:41:52 +01:00
|
|
|
|
2017-06-21 13:24:45 +02:00
|
|
|
def createNewProject(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Create new project file.
|
|
|
|
'''
|
2017-06-21 13:24:45 +02:00
|
|
|
if not self.okToContinue():
|
|
|
|
return
|
|
|
|
self.project = Project()
|
|
|
|
self.init_events(new=True)
|
2017-05-31 14:30:06 +02:00
|
|
|
self.setDirty(False)
|
2017-07-14 16:25:59 +02:00
|
|
|
self.project.parameter = self._inputs
|
2017-06-20 16:30:13 +02:00
|
|
|
self.saveProjectAsAction.setEnabled(True)
|
2017-06-21 13:24:45 +02:00
|
|
|
self.update_status('Created new project...', duration=1000)
|
2017-05-31 14:30:06 +02:00
|
|
|
return True
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-05-24 15:28:52 +02:00
|
|
|
def loadProject(self, fnm=None):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Load an existing project file.
|
|
|
|
'''
|
2017-05-31 11:48:16 +02:00
|
|
|
if not self.okToContinue():
|
|
|
|
return
|
2017-05-24 15:28:52 +02:00
|
|
|
if not fnm:
|
2017-09-06 18:02:09 +02:00
|
|
|
dlg = QFileDialog(parent=self)
|
2018-08-15 15:51:41 +02:00
|
|
|
fnm = dlg.getOpenFileName(self, 'Open project file...', filter='Pylot project (*.plp)')[0]
|
2017-05-29 11:31:09 +02:00
|
|
|
if not fnm:
|
|
|
|
return
|
2018-08-15 15:51:41 +02:00
|
|
|
if not os.path.exists(fnm):
|
|
|
|
QMessageBox.warning(self, 'Could not open file',
|
|
|
|
'Could not open project file {}. File does not exist.'.format(fnm))
|
|
|
|
return
|
2017-05-29 11:31:09 +02:00
|
|
|
if fnm:
|
|
|
|
self.project = Project.load(fnm)
|
2017-06-06 16:30:27 +02:00
|
|
|
if hasattr(self.project, 'parameter'):
|
|
|
|
if self.project.parameter:
|
2019-10-28 16:32:34 +01:00
|
|
|
# do this step to update default parameter on older PyLoT projects
|
|
|
|
self.project.parameter.reinit_default_parameters()
|
|
|
|
|
2017-06-06 16:30:27 +02:00
|
|
|
self._inputs = self.project.parameter
|
2018-02-22 11:28:46 +01:00
|
|
|
self.updateFilteroptions()
|
2018-07-31 09:41:48 +02:00
|
|
|
# added for backwards compatibility with older events not having a 'dirty' attribute
|
|
|
|
for event in self.project.eventlist:
|
|
|
|
if not hasattr(event, 'dirty'):
|
|
|
|
event.dirty = False
|
2017-07-14 16:25:59 +02:00
|
|
|
self.tabs.setCurrentIndex(0) # implemented to prevent double-loading of waveform data
|
2017-04-18 16:24:26 +02:00
|
|
|
self.init_events(new=True)
|
2018-07-23 14:54:53 +02:00
|
|
|
self.init_metadata()
|
2017-07-19 10:11:26 +02:00
|
|
|
|
2018-08-15 15:39:43 +02:00
|
|
|
message = 'Opened project file {}.'.format(fnm)
|
|
|
|
print(message)
|
|
|
|
self.update_status(message)
|
|
|
|
|
2017-06-06 16:30:27 +02:00
|
|
|
self.init_array_tab()
|
2018-08-03 09:33:37 +02:00
|
|
|
self.set_metadata()
|
2018-08-14 14:21:32 +02:00
|
|
|
self.add2recentProjects(fnm)
|
2019-02-28 16:20:21 +01:00
|
|
|
self.setDirty(False)
|
2018-08-14 14:21:32 +02:00
|
|
|
|
|
|
|
def add2recentProjects(self, fnm):
|
|
|
|
settings = QtCore.QSettings()
|
|
|
|
recent = settings.value('recentProjects', [])
|
|
|
|
if not type(recent) == list:
|
|
|
|
recent = [recent]
|
2018-08-15 15:39:43 +02:00
|
|
|
if not fnm in recent:
|
|
|
|
recent.append(fnm)
|
2018-08-14 14:21:32 +02:00
|
|
|
new_recent = recent[-5:]
|
|
|
|
settings.setValue('recentProjects', new_recent)
|
2018-08-15 15:39:43 +02:00
|
|
|
settings.sync()
|
2017-04-18 16:24:26 +02:00
|
|
|
|
2017-06-21 13:24:45 +02:00
|
|
|
def saveProjectAs(self, exists=False):
|
|
|
|
'''
|
|
|
|
Save back project to new pickle file.
|
|
|
|
'''
|
2019-04-01 10:55:38 +02:00
|
|
|
self.metadata.clear_inventory()
|
2017-09-06 18:02:09 +02:00
|
|
|
dlg = QFileDialog(self)
|
2017-06-21 13:24:45 +02:00
|
|
|
fnm = dlg.getSaveFileName(self, 'Create a new project file...', filter='Pylot project (*.plp)')
|
|
|
|
filename = fnm[0]
|
|
|
|
if not len(fnm[0]):
|
|
|
|
return False
|
|
|
|
if not filename.split('.')[-1] == 'plp':
|
|
|
|
filename = fnm[0] + '.plp'
|
2017-07-14 16:25:59 +02:00
|
|
|
self.project.parameter = self._inputs
|
2020-07-16 12:35:18 +02:00
|
|
|
settings = QSettings()
|
|
|
|
autosaveXML = get_Bool(settings.value('autosaveXML', True))
|
|
|
|
if autosaveXML:
|
|
|
|
self.exportEvents()
|
2017-06-21 13:24:45 +02:00
|
|
|
self.project.save(filename)
|
|
|
|
self.setDirty(False)
|
|
|
|
self.saveProjectAsAction.setEnabled(True)
|
|
|
|
self.update_status('Saved new project to {}'.format(filename), duration=5000)
|
2018-08-15 15:51:41 +02:00
|
|
|
self.add2recentProjects(filename)
|
2019-04-01 10:55:38 +02:00
|
|
|
self.update_obspy_dmt()
|
2017-06-21 13:24:45 +02:00
|
|
|
return True
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-05-29 11:56:22 +02:00
|
|
|
def saveProject(self, new=False):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Save back project to pickle file.
|
|
|
|
'''
|
2017-05-29 11:56:22 +02:00
|
|
|
if self.project and not new:
|
2017-04-19 16:05:45 +02:00
|
|
|
if not self.project.location:
|
2017-06-21 13:24:45 +02:00
|
|
|
if not self.saveProjectAs(exists=True):
|
2017-05-29 11:56:22 +02:00
|
|
|
self.setDirty(True)
|
|
|
|
return False
|
2017-04-19 16:05:45 +02:00
|
|
|
else:
|
2019-04-01 10:55:38 +02:00
|
|
|
self.metadata.clear_inventory()
|
2017-07-14 16:25:59 +02:00
|
|
|
self.project.parameter = self._inputs
|
2020-07-16 12:35:18 +02:00
|
|
|
settings = QSettings()
|
|
|
|
autosaveXML = get_Bool(settings.value('autosaveXML', True))
|
|
|
|
if autosaveXML:
|
|
|
|
self.exportEvents()
|
2018-07-31 09:41:48 +02:00
|
|
|
self.project.save()
|
2019-04-01 10:55:38 +02:00
|
|
|
self.update_obspy_dmt()
|
2017-04-18 16:24:26 +02:00
|
|
|
if not self.project.dirty:
|
2017-05-29 11:56:22 +02:00
|
|
|
self.setDirty(False)
|
2018-07-31 09:41:48 +02:00
|
|
|
self.update_status('Saved back project to file:\n{}'.format(self.project.location), duration=5000)
|
2017-05-29 11:56:22 +02:00
|
|
|
return True
|
2017-04-18 16:24:26 +02:00
|
|
|
else:
|
|
|
|
# if still dirty because saving failed
|
2017-07-14 16:25:59 +02:00
|
|
|
qmb = QMessageBox.warning(self, 'Could not save project',
|
2017-05-29 11:56:22 +02:00
|
|
|
'Could not save back to original file.\nChoose new file')
|
|
|
|
self.setDirty(True)
|
2017-06-21 13:24:45 +02:00
|
|
|
return self.saveProjectAs(exists=True)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2015-07-07 10:39:01 +02:00
|
|
|
def draw(self):
|
2017-05-31 15:41:25 +02:00
|
|
|
self.fill_eventbox()
|
2015-07-07 10:39:01 +02:00
|
|
|
self.getPlotWidget().draw()
|
2018-04-19 13:38:17 +02:00
|
|
|
if self.plot_method == 'fast':
|
2018-06-19 11:03:43 +02:00
|
|
|
self.dataPlot.setPermText(1, ' MIN/MAX plot ', color='red')
|
2018-04-19 13:38:17 +02:00
|
|
|
else:
|
2018-06-19 11:03:43 +02:00
|
|
|
self.dataPlot.setPermText(1)
|
2019-04-04 11:48:44 +02:00
|
|
|
self.dataPlot.setPermText(0, '| Number of traces: {} | Gain: {}'.format(len(self.getPlotWidget().getPlotDict()),
|
2021-03-30 08:28:31 +02:00
|
|
|
self.gain))
|
2018-06-19 11:03:43 +02:00
|
|
|
|
2017-06-06 16:30:27 +02:00
|
|
|
def _setDirty(self):
|
|
|
|
self.setDirty(True)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2015-07-18 16:11:20 +02:00
|
|
|
def setDirty(self, value):
|
2017-06-28 16:25:14 +02:00
|
|
|
self.saveProjectAction.setEnabled(value)
|
2017-06-20 16:30:13 +02:00
|
|
|
self.saveProjectAsAction.setEnabled(True)
|
2017-05-29 13:49:34 +02:00
|
|
|
self.project.setDirty(value)
|
2015-07-18 16:11:20 +02:00
|
|
|
self.dirty = value
|
2018-07-31 09:41:48 +02:00
|
|
|
self.fill_eventbox()
|
2015-07-18 16:11:20 +02:00
|
|
|
|
2014-12-08 10:26:14 +01:00
|
|
|
def closeEvent(self, event):
|
|
|
|
if self.okToContinue():
|
2017-05-31 11:48:16 +02:00
|
|
|
event.accept()
|
|
|
|
else:
|
|
|
|
event.ignore()
|
|
|
|
# self.closing.emit()
|
|
|
|
# QMainWindow.closeEvent(self, event)
|
2014-11-28 11:15:49 +01:00
|
|
|
|
2017-06-21 11:43:01 +02:00
|
|
|
def setParameter(self, show=True):
|
2017-05-31 17:12:34 +02:00
|
|
|
if not self.paraBox:
|
2017-09-07 16:07:43 +02:00
|
|
|
self.paraBox = PylotParaBox(self._inputs, parent=self, windowflag=1)
|
2017-07-11 16:03:24 +02:00
|
|
|
self.paraBox.accepted.connect(self._setDirty)
|
|
|
|
self.paraBox.accepted.connect(self.filterOptionsFromParameter)
|
2017-06-21 11:43:01 +02:00
|
|
|
if show:
|
2017-07-06 17:22:23 +02:00
|
|
|
self.paraBox.params_to_gui()
|
2017-06-21 11:43:01 +02:00
|
|
|
self.paraBox.show()
|
2017-07-04 14:39:10 +02:00
|
|
|
|
2019-12-17 13:50:54 +01:00
|
|
|
def deleteAllAutopicks(self):
|
|
|
|
qmb = QMessageBox(self, icon=QMessageBox.Question,
|
|
|
|
text='Are you sure you want to delete all automatic picks?')
|
|
|
|
qmb.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
|
|
|
|
qmb.setDefaultButton(QMessageBox.Yes)
|
|
|
|
ret = qmb.exec_()
|
|
|
|
if not ret == qmb.Yes:
|
|
|
|
return
|
|
|
|
for event in self.project.eventlist:
|
|
|
|
event.pylot_autopicks = {}
|
|
|
|
for index, pick in reversed(list(enumerate(event.picks))):
|
|
|
|
if pick.method_id.id.endswith('auto'):
|
|
|
|
event.picks.pop(index)
|
2020-01-14 13:57:12 +01:00
|
|
|
self.plotWaveformDataThread()
|
|
|
|
self.refreshTabs()
|
2019-12-17 13:50:54 +01:00
|
|
|
|
2014-12-17 06:33:34 +01:00
|
|
|
def PyLoTprefs(self):
|
2017-05-30 10:17:07 +02:00
|
|
|
if not self._props:
|
2017-07-19 15:12:01 +02:00
|
|
|
self._props = PropertiesDlg(self, infile=self.infile,
|
|
|
|
inputs=self._inputs)
|
2019-12-17 16:24:32 +01:00
|
|
|
else:
|
|
|
|
self._props.setDirty(False)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-05-29 18:03:31 +02:00
|
|
|
if self._props.exec_():
|
2019-12-17 16:24:32 +01:00
|
|
|
if self._props.dirty == 1:
|
|
|
|
if self.get_current_event():
|
|
|
|
self.plotWaveformDataThread()
|
|
|
|
elif self._props.dirty == 2:
|
|
|
|
self.refreshEvents()
|
2014-12-17 06:33:34 +01:00
|
|
|
return
|
|
|
|
|
2014-03-28 22:26:15 +01:00
|
|
|
def helpHelp(self):
|
2014-06-11 15:19:37 +02:00
|
|
|
if checkurl():
|
2017-09-21 13:30:05 +02:00
|
|
|
form = HelpForm(self,
|
2018-07-16 14:21:41 +02:00
|
|
|
'https://ariadne.geophysik.ruhr-uni-bochum.de/trac/PyLoT/wiki')
|
2014-06-11 15:19:37 +02:00
|
|
|
else:
|
2017-09-21 13:30:05 +02:00
|
|
|
form = HelpForm(self, ':/help.html')
|
2014-06-11 15:19:37 +02:00
|
|
|
form.show()
|
2014-03-28 22:26:15 +01:00
|
|
|
|
2014-01-10 05:45:03 +01:00
|
|
|
|
2017-04-18 16:24:26 +02:00
|
|
|
class Project(object):
|
|
|
|
'''
|
2017-09-21 15:36:17 +02:00
|
|
|
Pickable class containing information of a PyLoT project, like event lists and file locations.
|
2017-04-18 16:24:26 +02:00
|
|
|
'''
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-04-18 16:24:26 +02:00
|
|
|
def __init__(self):
|
|
|
|
self.eventlist = []
|
|
|
|
self.location = None
|
2017-06-21 13:24:45 +02:00
|
|
|
self.rootpath = None
|
2017-04-18 16:24:26 +02:00
|
|
|
self.dirty = False
|
2017-06-06 16:30:27 +02:00
|
|
|
self.parameter = None
|
2017-04-20 12:05:34 +02:00
|
|
|
self._table = None
|
2017-04-18 16:24:26 +02:00
|
|
|
|
|
|
|
def add_eventlist(self, eventlist):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Add events from an eventlist containing paths to event directories.
|
|
|
|
Will skip existing paths.
|
|
|
|
'''
|
2017-04-18 16:24:26 +02:00
|
|
|
if len(eventlist) == 0:
|
|
|
|
return
|
|
|
|
for item in eventlist:
|
2017-04-19 16:51:19 +02:00
|
|
|
event = Event(item)
|
2017-06-21 13:24:45 +02:00
|
|
|
event.rootpath = self.parameter['rootpath']
|
|
|
|
event.database = self.parameter['database']
|
|
|
|
event.datapath = self.parameter['datapath']
|
2017-05-15 17:21:22 +02:00
|
|
|
if not event.path in self.getPaths():
|
2017-04-19 16:51:19 +02:00
|
|
|
self.eventlist.append(event)
|
2017-05-29 13:49:34 +02:00
|
|
|
self.setDirty()
|
2017-05-15 17:21:22 +02:00
|
|
|
else:
|
|
|
|
print('Skipping event with path {}. Already part of project.'.format(event.path))
|
2017-07-18 15:27:52 +02:00
|
|
|
self.eventlist.sort(key=lambda x: x.pylot_id)
|
2017-06-23 14:14:42 +02:00
|
|
|
self.search_eventfile_info()
|
|
|
|
|
2017-07-18 15:27:52 +02:00
|
|
|
def remove_event(self, event):
|
2021-03-30 16:39:44 +02:00
|
|
|
self.eventlist.remove(event)
|
2017-07-18 15:27:52 +02:00
|
|
|
|
|
|
|
def remove_event_by_id(self, eventID):
|
|
|
|
for event in self.eventlist:
|
|
|
|
if eventID in str(event.resource_id):
|
|
|
|
self.remove_event(event)
|
|
|
|
break
|
2017-08-03 09:41:54 +02:00
|
|
|
|
2017-06-23 14:14:42 +02:00
|
|
|
def read_eventfile_info(self, filename, separator=','):
|
2021-03-30 16:39:44 +02:00
|
|
|
'''
|
2021-03-30 08:28:31 +02:00
|
|
|
Try to read event information from file (:param:filename) comparing specific event datetimes.
|
|
|
|
File structure (each row): event, date, time, magnitude, latitude, longitude, depth
|
|
|
|
separated by :param:separator each.
|
|
|
|
'''
|
2018-11-30 11:20:47 +01:00
|
|
|
with open(filename, 'r') as infile:
|
|
|
|
for line in infile.readlines():
|
|
|
|
eventID, date, time, mag, lat, lon, depth = line.split(separator)[:7]
|
|
|
|
# skip first line
|
|
|
|
try:
|
|
|
|
day, month, year = date.split('/')
|
|
|
|
except:
|
|
|
|
continue
|
|
|
|
year = int(year)
|
|
|
|
# hardcoded, if year only consists of 2 digits (e.g. 16 instead of 2016)
|
|
|
|
if year < 100:
|
|
|
|
year += 2000
|
|
|
|
datetime = '{}-{}-{}T{}'.format(year, month, day, time)
|
|
|
|
try:
|
|
|
|
datetime = UTCDateTime(datetime)
|
|
|
|
except Exception as e:
|
|
|
|
print(e, datetime, filename)
|
|
|
|
continue
|
|
|
|
for event in self.eventlist:
|
|
|
|
if eventID in str(event.resource_id) or eventID in event.origins:
|
|
|
|
if event.origins:
|
|
|
|
origin = event.origins[0] # should have only one origin
|
|
|
|
if origin.time == datetime:
|
|
|
|
origin.latitude = float(lat)
|
|
|
|
origin.longitude = float(lon)
|
|
|
|
origin.depth = float(depth)
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
elif not event.origins:
|
|
|
|
origin = Origin(resource_id=event.resource_id,
|
|
|
|
time=datetime, latitude=float(lat),
|
|
|
|
longitude=float(lon), depth=float(depth))
|
|
|
|
event.origins.append(origin)
|
|
|
|
event.magnitudes.append(Magnitude(resource_id=event.resource_id,
|
|
|
|
mag=float(mag),
|
|
|
|
mag_type='M'))
|
|
|
|
break
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-06-23 14:14:42 +02:00
|
|
|
def search_eventfile_info(self):
|
|
|
|
'''
|
|
|
|
Search all datapaths in rootpath for filenames with given file extension fext
|
|
|
|
and try to read event info from it
|
|
|
|
'''
|
|
|
|
datapaths = []
|
2017-07-14 16:25:59 +02:00
|
|
|
fext = '.csv'
|
2017-06-23 14:14:42 +02:00
|
|
|
for event in self.eventlist:
|
|
|
|
if not event.datapath in datapaths:
|
|
|
|
datapaths.append(event.datapath)
|
|
|
|
for datapath in datapaths:
|
|
|
|
datapath = os.path.join(self.rootpath, datapath)
|
2020-09-22 10:30:48 +02:00
|
|
|
if os.path.isdir(datapath):
|
|
|
|
for filename in os.listdir(datapath):
|
|
|
|
filename = os.path.join(datapath, filename)
|
|
|
|
if os.path.isfile(filename) and filename.endswith(fext):
|
|
|
|
try:
|
|
|
|
self.read_eventfile_info(filename)
|
|
|
|
except Exception as e:
|
|
|
|
print('Failed on reading eventfile info from file {}: {}'.format(filename, e))
|
|
|
|
else:
|
|
|
|
print("Directory %s does not exist!" % datapath)
|
2017-04-18 16:24:26 +02:00
|
|
|
|
2017-05-15 17:21:22 +02:00
|
|
|
def getPaths(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Returns paths (eventlist) of all events saved in the project.
|
|
|
|
'''
|
2017-05-15 17:21:22 +02:00
|
|
|
paths = []
|
|
|
|
for event in self.eventlist:
|
|
|
|
paths.append(event.path)
|
|
|
|
return paths
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-05-29 13:49:34 +02:00
|
|
|
def setDirty(self, value=True):
|
|
|
|
self.dirty = value
|
2017-04-18 16:24:26 +02:00
|
|
|
|
2017-04-20 12:05:34 +02:00
|
|
|
def getEventFromPath(self, path):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Search for an event in the project by event path.
|
|
|
|
'''
|
2017-04-20 12:05:34 +02:00
|
|
|
for event in self.eventlist:
|
|
|
|
if event.path == path:
|
|
|
|
return event
|
|
|
|
|
2017-04-18 16:24:26 +02:00
|
|
|
def save(self, filename=None):
|
|
|
|
'''
|
|
|
|
Save PyLoT Project to a file.
|
|
|
|
Can be loaded by using project.load(filename).
|
|
|
|
'''
|
|
|
|
try:
|
|
|
|
import cPickle
|
|
|
|
except ImportError:
|
|
|
|
import _pickle as cPickle
|
|
|
|
|
|
|
|
if filename:
|
|
|
|
self.location = filename
|
|
|
|
else:
|
|
|
|
filename = self.location
|
|
|
|
|
|
|
|
try:
|
|
|
|
outfile = open(filename, 'wb')
|
|
|
|
cPickle.dump(self, outfile, -1)
|
2017-05-29 13:49:34 +02:00
|
|
|
self.setDirty(False)
|
2017-04-18 16:24:26 +02:00
|
|
|
except Exception as e:
|
|
|
|
print('Could not pickle PyLoT project. Reason: {}'.format(e))
|
|
|
|
self.setDirty()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def load(filename):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Load project from filename.
|
|
|
|
'''
|
2017-04-18 16:24:26 +02:00
|
|
|
try:
|
|
|
|
import cPickle
|
|
|
|
except ImportError:
|
|
|
|
import _pickle as cPickle
|
|
|
|
infile = open(filename, 'rb')
|
|
|
|
project = cPickle.load(infile)
|
2017-05-29 11:34:22 +02:00
|
|
|
project.location = filename
|
2017-04-18 16:24:26 +02:00
|
|
|
print('Loaded %s' % filename)
|
|
|
|
return project
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-04-18 16:24:26 +02:00
|
|
|
|
|
|
|
class getExistingDirectories(QFileDialog):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
File dialog with possibility to select multiple folders.
|
|
|
|
'''
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-04-18 16:24:26 +02:00
|
|
|
def __init__(self, *args):
|
|
|
|
super(getExistingDirectories, self).__init__(*args)
|
|
|
|
self.setOption(self.DontUseNativeDialog, True)
|
2017-05-02 12:13:55 +02:00
|
|
|
self.setOption(self.ReadOnly, True)
|
2017-04-18 16:24:26 +02:00
|
|
|
self.setFileMode(self.Directory)
|
|
|
|
self.setOption(self.ShowDirsOnly, True)
|
|
|
|
self.findChildren(QListView)[0].setSelectionMode(QAbstractItemView.ExtendedSelection)
|
|
|
|
self.findChildren(QTreeView)[0].setSelectionMode(QAbstractItemView.ExtendedSelection)
|
|
|
|
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-04-10 13:32:53 +02:00
|
|
|
def create_window():
|
|
|
|
app_created = False
|
|
|
|
app = QCoreApplication.instance()
|
2017-07-14 16:25:59 +02:00
|
|
|
# check for existing app (when using ipython)
|
2017-04-10 13:32:53 +02:00
|
|
|
if app is None:
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
app_created = True
|
2017-09-11 12:18:30 +02:00
|
|
|
# set aplication/organization name, domain (important to do this BEFORE setupUI is called for correct QSettings)
|
|
|
|
app.setOrganizationName("Ruhr-University Bochum / BESTEC")
|
2017-09-18 10:41:27 +02:00
|
|
|
app.setOrganizationDomain("rub.de")
|
|
|
|
app.setApplicationName("PyLoT")
|
2017-04-10 13:32:53 +02:00
|
|
|
app.references = set()
|
2017-07-14 16:25:59 +02:00
|
|
|
# app.references.add(window)
|
|
|
|
# window.show()
|
2017-04-10 13:32:53 +02:00
|
|
|
return app, app_created
|
|
|
|
|
2017-09-11 13:27:32 +02:00
|
|
|
|
2017-05-29 11:31:09 +02:00
|
|
|
def main(args=None):
|
2017-09-08 15:50:08 +02:00
|
|
|
project_filename = None
|
2018-07-16 14:21:41 +02:00
|
|
|
# args.project_filename = 'C:/Shared/AlpArray/alparray_data/project_alparray_test.plp'
|
2017-05-30 16:09:48 +02:00
|
|
|
pylot_infile = None
|
|
|
|
if args:
|
|
|
|
if args.project_filename:
|
|
|
|
project_filename = args.project_filename
|
|
|
|
if args.input_filename:
|
|
|
|
pylot_infile = args.input_filename
|
2020-07-16 12:35:18 +02:00
|
|
|
reset_qsettings = args.reset_qsettings
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2014-11-06 15:07:05 +01:00
|
|
|
# create the Qt application
|
2017-04-10 13:32:53 +02:00
|
|
|
pylot_app, app_created = create_window()
|
2017-07-14 16:25:59 +02:00
|
|
|
# pylot_app = QApplication(sys.argv)
|
2015-07-07 12:14:18 +02:00
|
|
|
pixmap = QPixmap(":/splash/splash.png")
|
|
|
|
splash = QSplashScreen(pixmap)
|
|
|
|
splash.show()
|
2015-04-02 18:36:21 +02:00
|
|
|
|
|
|
|
app_icon = QIcon()
|
2015-07-07 11:21:06 +02:00
|
|
|
app_icon.addPixmap(QPixmap(':/icons/pylot.png'))
|
2014-01-09 10:43:40 +01:00
|
|
|
|
2015-09-18 09:54:29 +02:00
|
|
|
# create the main window
|
2020-07-16 12:35:18 +02:00
|
|
|
pylot_form = MainWindow(infile=pylot_infile, reset_qsettings=reset_qsettings)
|
2017-09-12 16:37:26 +02:00
|
|
|
pylot_form.setWindowIcon(app_icon)
|
2017-04-06 13:16:28 +02:00
|
|
|
pylot_form.setIconSize(QSize(60, 60))
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-09-11 12:18:30 +02:00
|
|
|
# set other App information
|
2015-09-18 09:54:29 +02:00
|
|
|
pylot_app.setApplicationVersion(pylot_form.__version__)
|
2015-04-02 18:36:21 +02:00
|
|
|
pylot_app.setWindowIcon(app_icon)
|
2015-07-07 12:14:18 +02:00
|
|
|
pylot_app.processEvents()
|
2014-01-09 10:43:40 +01:00
|
|
|
|
2017-09-11 12:18:30 +02:00
|
|
|
splash.showMessage('Loading. Please wait ...')
|
|
|
|
pylot_app.processEvents()
|
|
|
|
|
2014-03-13 13:27:34 +01:00
|
|
|
# Show main window and run the app
|
2015-06-25 10:25:08 +02:00
|
|
|
pylot_form.showMaximized()
|
2015-09-18 09:54:29 +02:00
|
|
|
pylot_app.processEvents()
|
|
|
|
|
2015-07-07 12:14:18 +02:00
|
|
|
splash.finish(pylot_form)
|
2017-05-29 11:31:09 +02:00
|
|
|
|
2017-05-30 16:09:48 +02:00
|
|
|
if project_filename:
|
|
|
|
pylot_form.loadProject(args.project_filename)
|
2017-05-29 11:31:09 +02:00
|
|
|
|
2017-04-10 13:32:53 +02:00
|
|
|
if app_created:
|
|
|
|
pylot_app.exec_()
|
2017-04-10 14:01:08 +02:00
|
|
|
else:
|
|
|
|
return pylot_form
|
2014-03-28 22:26:15 +01:00
|
|
|
|
2015-01-29 08:53:01 +01:00
|
|
|
|
2014-04-11 19:39:29 +02:00
|
|
|
if __name__ == "__main__":
|
2017-05-29 11:31:09 +02:00
|
|
|
parser = argparse.ArgumentParser(description='Welcome to PyLoT.')
|
|
|
|
parser.add_argument('-p', dest='project_filename', help='load project file',
|
|
|
|
default=None)
|
2017-05-30 16:09:48 +02:00
|
|
|
parser.add_argument('-in', dest='input_filename', help='set pylot input file',
|
|
|
|
default=None)
|
2020-07-16 12:35:18 +02:00
|
|
|
parser.add_argument('--reset_qsettings', default=False, action='store_true',
|
|
|
|
help='reset qsettings (debug option)')
|
2017-05-29 11:31:09 +02:00
|
|
|
args = parser.parse_args()
|
|
|
|
sys.exit(main(args))
|