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)
|
|
|
|
"""
|
2014-01-09 10:43:40 +01:00
|
|
|
|
2017-08-03 09:41:54 +02:00
|
|
|
import argparse
|
2016-01-29 07:21:17 +01:00
|
|
|
import os
|
2017-07-14 16:25:59 +02:00
|
|
|
import platform
|
2017-08-03 09:41:54 +02:00
|
|
|
import sys
|
|
|
|
|
2016-09-23 15:12:04 +02:00
|
|
|
import matplotlib
|
|
|
|
|
2015-07-06 09:51:59 +02:00
|
|
|
matplotlib.use('Qt4Agg')
|
|
|
|
matplotlib.rcParams['backend.qt4'] = 'PySide'
|
2014-12-04 05:13:32 +01:00
|
|
|
|
2017-04-19 15:31:08 +02:00
|
|
|
from PySide import QtGui, QtCore
|
2015-03-11 12:05:52 +01:00
|
|
|
from PySide.QtCore import QCoreApplication, QSettings, Signal, QFile, \
|
2017-04-06 13:16:28 +02:00
|
|
|
QFileInfo, Qt, QSize
|
2015-02-16 10:24:17 +01:00
|
|
|
from PySide.QtGui import QMainWindow, QInputDialog, QIcon, QFileDialog, \
|
2017-04-18 16:24:26 +02:00
|
|
|
QWidget, QHBoxLayout, QVBoxLayout, QStyle, QKeySequence, QLabel, QFrame, QAction, \
|
2015-07-07 14:21:11 +02:00
|
|
|
QDialog, QErrorMessage, QApplication, QPixmap, QMessageBox, QSplashScreen, \
|
2017-04-18 16:24:26 +02:00
|
|
|
QActionGroup, QListWidget, QDockWidget, 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
|
2015-11-18 09:30:32 +01:00
|
|
|
from obspy import UTCDateTime
|
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
|
|
|
|
2017-06-07 17:05:48 +02:00
|
|
|
try:
|
|
|
|
import pyqtgraph as pg
|
2017-06-20 13:22:29 +02:00
|
|
|
except Exception as e:
|
|
|
|
print('QtPyLoT: Could not import pyqtgraph. {}'.format(e))
|
2017-06-07 17:05:48 +02:00
|
|
|
pg = None
|
|
|
|
|
2017-05-11 17:15:20 +02:00
|
|
|
try:
|
|
|
|
from matplotlib.backends.backend_qt4agg import FigureCanvas
|
|
|
|
except ImportError:
|
|
|
|
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
|
2017-07-14 16:25:59 +02:00
|
|
|
from matplotlib.backends.backend_qt4agg 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
|
2017-08-11 16:04:18 +02:00
|
|
|
from pylot.core.pick.utils import symmetrize_error, getQualityfromUncertainty
|
2016-05-03 13:54:59 +02:00
|
|
|
from pylot.core.io.phases import picksdict_from_picks
|
2016-08-25 13:31:51 +02:00
|
|
|
import pylot.core.loc.nll as nll
|
2017-08-07 11:21:20 +02:00
|
|
|
from pylot.core.util.defaults import FILTERDEFAULTS, SetChannelComponents
|
2016-01-29 07:21:17 +01:00
|
|
|
from pylot.core.util.errors import FormatError, 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
|
2016-09-27 15:15:53 +02:00
|
|
|
from pylot.core.util.dataprocessing import read_metadata, restitute_data
|
2017-06-26 12:19:06 +02:00
|
|
|
from pylot.core.util.utils import fnConstructor, getLogin, \
|
2017-08-11 15:15:58 +02:00
|
|
|
full_range, readFilterInformation, trim_station_components, check4gaps
|
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-06-07 17:05:48 +02:00
|
|
|
WaveformWidget, WaveformWidgetPG, PropertiesDlg, HelpForm, createAction, PickDlg, \
|
2017-08-03 11:10:26 +02:00
|
|
|
getDataType, ComparisonDialog, TuneAutopicker, PylotParaBox, AutoPickDlg
|
2017-04-12 16:43:29 +02:00
|
|
|
from pylot.core.util.map_projection import map_projection
|
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-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
|
|
|
|
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()
|
|
|
|
|
2017-05-30 16:09:48 +02:00
|
|
|
def __init__(self, parent=None, infile=None):
|
2014-01-10 05:45:03 +01:00
|
|
|
super(MainWindow, self).__init__(parent)
|
2014-03-13 13:27:34 +01:00
|
|
|
|
2017-04-06 13:16:28 +02:00
|
|
|
# check for default pylot.in-file
|
2017-05-30 16:09:48 +02:00
|
|
|
if not infile:
|
|
|
|
infile = os.path.join(os.path.expanduser('~'), '.pylot', 'pylot.in')
|
|
|
|
print('Using default input file {}'.format(infile))
|
2017-07-14 16:25:59 +02:00
|
|
|
if os.path.isfile(infile) == False:
|
2017-05-04 11:50:28 +02:00
|
|
|
infile = QFileDialog().getOpenFileName(caption='Choose PyLoT-input file')
|
2017-04-10 09:50:53 +02:00
|
|
|
if not os.path.exists(infile[0]):
|
|
|
|
QMessageBox.warning(self, "PyLoT Warning",
|
2017-07-14 16:25:59 +02:00
|
|
|
"No PyLoT-input file declared!")
|
2017-04-10 09:50:53 +02:00
|
|
|
sys.exit(0)
|
2017-04-06 13:16:28 +02:00
|
|
|
self.infile = infile[0]
|
|
|
|
else:
|
2017-07-14 16:25:59 +02:00
|
|
|
self.infile = infile
|
2017-06-22 11:18:55 +02:00
|
|
|
self._inputs = PylotParameter(infile)
|
2017-05-30 10:17:07 +02:00
|
|
|
self._props = None
|
2017-04-10 14:54:47 +02:00
|
|
|
|
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-05-31 17:12:34 +02:00
|
|
|
self.paraBox = None
|
2017-04-18 17:17:46 +02:00
|
|
|
self.array_map = None
|
|
|
|
self._metadata = None
|
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
|
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
|
|
|
|
2017-05-29 16:21:36 +02:00
|
|
|
# default factor for dataplot e.g. enabling/disabling scrollarea
|
|
|
|
self.height_factor = 12
|
|
|
|
|
2017-05-19 10:56:27 +02:00
|
|
|
# default colors for ref/test event
|
|
|
|
self._colors = {
|
|
|
|
'ref': QtGui.QColor(200, 210, 230, 255),
|
|
|
|
'test': QtGui.QColor(200, 230, 200, 255)
|
|
|
|
}
|
|
|
|
|
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()
|
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)
|
|
|
|
|
2014-12-08 10:26:14 +01:00
|
|
|
if settings.value("user/FullName", None) is None:
|
|
|
|
fulluser = QInputDialog.getText(self, "Enter Name:", "Full name")
|
|
|
|
settings.setValue("user/FullName", fulluser)
|
2015-03-04 11:52:04 +01:00
|
|
|
settings.setValue("user/Login", getLogin())
|
2015-03-06 09:03:04 +01:00
|
|
|
if settings.value("agency_id", None) is None:
|
2015-06-11 10:07:21 +02:00
|
|
|
agency = QInputDialog.getText(self,
|
2017-04-06 13:16:28 +02:00
|
|
|
"Enter authority/institution name:",
|
2015-06-11 10:07:21 +02:00
|
|
|
"Authority")
|
2015-03-11 12:05:52 +01:00
|
|
|
settings.setValue("agency_id", agency)
|
2015-02-13 11:17:18 +01:00
|
|
|
self.fnames = None
|
2016-05-31 17:27:59 +02:00
|
|
|
self._stime = None
|
2015-06-23 13:22:30 +02:00
|
|
|
structure_setting = settings.value("data/Structure", "PILOT")
|
|
|
|
self.dataStructure = DATASTRUCTURE[structure_setting]()
|
2014-11-28 11:15:49 +01:00
|
|
|
self.seismicPhase = str(settings.value("phase", "P"))
|
2014-12-08 10:26:14 +01:00
|
|
|
if settings.value("data/dataRoot", None) is None:
|
2015-01-29 08:53:01 +01:00
|
|
|
dirname = QFileDialog().getExistingDirectory(
|
2016-03-30 07:00:31 +02:00
|
|
|
caption='Choose data root ...')
|
2014-12-08 10:26:14 +01:00
|
|
|
settings.setValue("data/dataRoot", dirname)
|
2017-06-02 14:02:08 +02:00
|
|
|
if settings.value('compclass', None) is None:
|
|
|
|
settings.setValue('compclass', SetChannelComponents())
|
2017-06-29 16:35:52 +02:00
|
|
|
if settings.value('output/Format', None) is None:
|
|
|
|
outformat = QInputDialog.getText(self,
|
|
|
|
"Enter output format (*.xml, *.cnv, *.obs):",
|
|
|
|
"Format")
|
|
|
|
settings.setValue("output/Format", outformat)
|
2015-03-06 09:03:04 +01:00
|
|
|
settings.sync()
|
2014-11-28 11:15:49 +01:00
|
|
|
|
2017-06-09 13:23:16 +02:00
|
|
|
# setup UI
|
|
|
|
self.setupUi()
|
|
|
|
|
2017-07-11 16:03:24 +02:00
|
|
|
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'])}
|
2015-11-14 11:46:46 +01:00
|
|
|
self.loc = False
|
2014-03-13 13:27:34 +01:00
|
|
|
|
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
|
|
|
|
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()
|
|
|
|
|
2017-05-19 10:56:27 +02:00
|
|
|
# add event combo box and ref/test buttons
|
2017-04-20 14:03:26 +02:00
|
|
|
self.eventBox = self.createEventBox()
|
2017-04-18 16:24:26 +02:00
|
|
|
self.eventBox.setMaxVisibleItems(30)
|
|
|
|
self.eventBox.setEnabled(False)
|
2017-05-19 10:56:27 +02:00
|
|
|
self.init_ref_test_buttons()
|
2017-04-18 17:17:46 +02:00
|
|
|
self._event_layout = QHBoxLayout()
|
|
|
|
self._event_layout.addWidget(QLabel('Event: '))
|
|
|
|
self._event_layout.addWidget(self.eventBox)
|
2017-05-19 10:56:27 +02:00
|
|
|
self._event_layout.addWidget(self.ref_event_button)
|
|
|
|
self._event_layout.addWidget(self.test_event_button)
|
2017-07-14 16:25:59 +02:00
|
|
|
self._event_layout.setStretch(1, 1) # set stretch of item 1 to 1
|
2017-04-18 17:17:46 +02:00
|
|
|
self._main_layout.addLayout(self._event_layout)
|
2017-04-19 16:05:45 +02:00
|
|
|
self.eventBox.activated.connect(self.refreshEvents)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-05-24 14:12:41 +02:00
|
|
|
# add main tab widget
|
2017-04-18 17:17:46 +02:00
|
|
|
self.tabs = QTabWidget()
|
|
|
|
self._main_layout.addWidget(self.tabs)
|
2017-04-19 15:31:08 +02:00
|
|
|
self.tabs.currentChanged.connect(self.refreshTabs)
|
2015-02-07 09:03:03 +01:00
|
|
|
|
2017-05-24 14:12:41 +02:00
|
|
|
# add scroll area used in case number of traces gets too high
|
|
|
|
self.wf_scroll_area = QtGui.QScrollArea()
|
|
|
|
|
2017-06-09 13:23:16 +02:00
|
|
|
# create central matplotlib figure canvas widget
|
|
|
|
self.pg = pg
|
|
|
|
self.init_wfWidget()
|
|
|
|
|
2017-05-24 14:12:41 +02:00
|
|
|
# init main widgets for main tabs
|
2017-04-20 12:05:34 +02:00
|
|
|
wf_tab = QtGui.QWidget()
|
|
|
|
array_tab = QtGui.QWidget()
|
|
|
|
events_tab = QtGui.QWidget()
|
2017-05-24 14:12:41 +02:00
|
|
|
|
|
|
|
# init main widgets layouts
|
2017-04-20 12:05:34 +02:00
|
|
|
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)
|
2017-05-24 14:12:41 +02:00
|
|
|
|
2017-07-14 16:25:59 +02:00
|
|
|
# add tabs to main tab widget
|
2017-04-20 12:05:34 +02:00
|
|
|
self.tabs.addTab(wf_tab, 'Waveform Plot')
|
|
|
|
self.tabs.addTab(array_tab, 'Array Map')
|
|
|
|
self.tabs.addTab(events_tab, 'Eventlist')
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-05-03 15:16:48 +02:00
|
|
|
self.wf_layout.addWidget(self.wf_scroll_area)
|
|
|
|
self.wf_scroll_area.setWidgetResizable(True)
|
2017-04-19 15:31:08 +02:00
|
|
|
self.init_array_tab()
|
2017-04-20 12:05:34 +02:00
|
|
|
self.init_event_table()
|
|
|
|
self.tabs.setCurrentIndex(0)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
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'))
|
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'))
|
2015-07-07 10:31:39 +02:00
|
|
|
filter_icon = QIcon()
|
|
|
|
filter_icon.addPixmap(QPixmap(':/icons/filter.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'))
|
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-07 16:41:50 +02:00
|
|
|
self.openEventAction = self.createAction(self, "Load event ...",
|
|
|
|
self.load_data,
|
2017-05-31 14:30:06 +02:00
|
|
|
"Ctrl+M",
|
2017-08-07 16:41:50 +02:00
|
|
|
openEventIcon,
|
2017-06-26 14:22:00 +02:00
|
|
|
"Load event information for "
|
2017-05-31 14:30:06 +02:00
|
|
|
"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,
|
2017-05-31 14:30:06 +02:00
|
|
|
"Ctrl+A",
|
2017-08-07 16:41:50 +02:00
|
|
|
openEventsIcon,
|
2017-06-26 14:22:00 +02:00
|
|
|
"Load event data automatically "
|
|
|
|
"for 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,"
|
2017-08-07 16:25:48 +02:00
|
|
|
" source origin and magnitude.")
|
2017-08-07 16:41:50 +02:00
|
|
|
self.disableSaveEventAction()
|
2017-04-10 14:24:39 +02:00
|
|
|
|
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")
|
2015-06-11 10:07:21 +02:00
|
|
|
self.filterAction = self.createAction(self, "&Filter ...",
|
|
|
|
self.filterWaveformData,
|
2015-07-07 10:31:39 +02:00
|
|
|
"Ctrl+F", filter_icon,
|
2015-06-11 10:07:21 +02:00
|
|
|
"""Toggle un-/filtered waveforms
|
2017-05-31 17:12:34 +02:00
|
|
|
to be displayed, according to the
|
|
|
|
desired seismic phase.""", True)
|
2015-03-04 15:40:25 +01:00
|
|
|
filterEditAction = self.createAction(self, "&Filter parameter ...",
|
2015-01-29 08:41:38 +01:00
|
|
|
self.adjustFilterOptions,
|
2017-06-28 17:20:02 +02:00
|
|
|
"Alt+F", filter_icon,
|
2015-01-29 08:41:38 +01:00
|
|
|
"""Adjust filter parameters.""")
|
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)
|
|
|
|
|
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-08-03 11:10:26 +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'
|
2017-08-03 11:10:26 +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'
|
|
|
|
' the complete project on local machine.')
|
|
|
|
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'
|
|
|
|
' the complete project on grid engine.')
|
|
|
|
self.auto_pick_sge.setEnabled(False)
|
|
|
|
|
2017-05-18 11:02:20 +02:00
|
|
|
autoPickActions = (self.auto_tune, self.auto_pick, self.compare_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)
|
2017-04-10 14:24:39 +02:00
|
|
|
self.locateEvent = self.createAction(parent=self, text='locate the event',
|
2017-07-14 16:25:59 +02:00
|
|
|
slot=self.locate_event,
|
|
|
|
shortcut='Alt+Ctrl+L',
|
|
|
|
icon=locate_icon,
|
|
|
|
tip='Locate the event using '
|
|
|
|
'the displayed manual arrivals.')
|
2017-04-10 14:24:39 +02:00
|
|
|
self.locateEvent.setEnabled(False)
|
2015-11-09 08:53:26 +01:00
|
|
|
|
2017-04-10 14:24:39 +02:00
|
|
|
locationToolActions = (self.locateEvent,)
|
2017-08-03 11:10:26 +02:00
|
|
|
|
|
|
|
# add top menu
|
|
|
|
self.fileMenu = self.menuBar().addMenu('&File')
|
|
|
|
self.fileMenuActions = (self.newProjectAction, self.addEventDataAction,
|
|
|
|
self.openProjectAction, self.saveProjectAction,
|
|
|
|
self.saveProjectAsAction,
|
2017-08-07 16:41:50 +02:00
|
|
|
self.openEventAction, self.saveEventAction, None,
|
2017-08-03 11:10:26 +02:00
|
|
|
prefsEventAction, self.parameterAction, quitAction)
|
|
|
|
self.fileMenu.aboutToShow.connect(self.updateFileMenu)
|
|
|
|
self.updateFileMenu()
|
|
|
|
|
|
|
|
self.editMenu = self.menuBar().addMenu('&Edit')
|
|
|
|
editActions = (self.filterAction, filterEditAction, None,
|
|
|
|
self.selectPAction, self.selectSAction, None,
|
|
|
|
printAction)
|
|
|
|
|
|
|
|
self.pickMenu = self.menuBar().addMenu('&Picking')
|
2017-08-03 15:33:28 +02:00
|
|
|
self.autoPickMenu = self.pickMenu.addMenu('Automatic picking')
|
|
|
|
self.autoPickMenu.setEnabled(False)
|
|
|
|
|
2017-08-03 11:10:26 +02:00
|
|
|
pickActions = (self.auto_pick, self.auto_pick_local, self.auto_pick_sge)
|
|
|
|
|
|
|
|
self.helpMenu = self.menuBar().addMenu('&Help')
|
|
|
|
helpActions = (helpAction,)
|
|
|
|
|
|
|
|
fileToolActions = (self.newProjectAction, self.addEventDataAction,
|
|
|
|
self.openProjectAction, self.saveProjectAction,
|
|
|
|
self.saveProjectAsAction)
|
|
|
|
|
|
|
|
|
2017-08-07 16:41:50 +02:00
|
|
|
eventToolActions = (self.openEventAction, self.openEventsAutoAction,
|
|
|
|
self.saveEventAction, self.loadlocationaction,
|
2017-08-03 11:10:26 +02:00
|
|
|
self.loadpilotevent)
|
|
|
|
|
|
|
|
|
|
|
|
fileToolBar = self.addToolBar("FileTools")
|
|
|
|
eventToolBar = self.addToolBar("EventTools")
|
|
|
|
componentToolBar = self.addToolBar("ComponentSelection")
|
|
|
|
autoPickToolBar = self.addToolBar("autoPyLoT")
|
|
|
|
locationToolBar = self.addToolBar("LocationTools")
|
|
|
|
|
|
|
|
fileToolBar.setObjectName("FileTools")
|
|
|
|
eventToolBar.setObjectName("EventTools")
|
|
|
|
componentToolBar.setObjectName("PhaseTools")
|
|
|
|
autoPickToolBar.setObjectName('autopickTools')
|
2015-11-09 08:53:26 +01:00
|
|
|
locationToolBar.setObjectName("LocationTools")
|
2017-08-03 11:10:26 +02:00
|
|
|
|
|
|
|
self.addActions(self.editMenu, editActions)
|
2017-08-03 15:33:28 +02:00
|
|
|
self.addActions(self.autoPickMenu, pickActions)
|
2017-08-03 11:10:26 +02:00
|
|
|
self.addActions(self.helpMenu, helpActions)
|
|
|
|
|
|
|
|
self.addActions(fileToolBar, fileToolActions)
|
|
|
|
self.addActions(eventToolBar, eventToolActions)
|
|
|
|
self.addActions(componentToolBar, componentActions)
|
|
|
|
self.addActions(autoPickToolBar, autoPickActions)
|
2015-11-09 08:53:26 +01:00
|
|
|
self.addActions(locationToolBar, locationToolActions)
|
|
|
|
|
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):
|
|
|
|
settings = QSettings()
|
|
|
|
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()
|
|
|
|
if str(settings.value('pyqtgraphic')) == 'false' or not pg:
|
|
|
|
self.pg = False
|
|
|
|
self.dataPlot = WaveformWidget(parent=self, xlabel=xlab, ylabel=None,
|
|
|
|
title=plottitle)
|
|
|
|
else:
|
|
|
|
self.pg = True
|
|
|
|
self.dataPlot = WaveformWidgetPG(parent=self, xlabel=xlab, ylabel=None,
|
|
|
|
title=plottitle)
|
|
|
|
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-05-19 10:56:27 +02:00
|
|
|
self.ref_event_button = QtGui.QPushButton('Ref')
|
|
|
|
self.test_event_button = QtGui.QPushButton('Test')
|
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)
|
|
|
|
self.set_button_color(self.ref_event_button, self._colors['ref'])
|
2017-07-14 16:25:59 +02:00
|
|
|
self.set_button_color(self.test_event_button, self._colors['test'])
|
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
|
2017-07-14 16:25:59 +02:00
|
|
|
|
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
|
|
|
|
2016-09-22 14:12:24 +02:00
|
|
|
@property
|
|
|
|
def metadata(self):
|
|
|
|
return self._metadata
|
|
|
|
|
|
|
|
@metadata.setter
|
|
|
|
def metadata(self, value):
|
|
|
|
self._metadata = value
|
|
|
|
|
2014-12-01 12:37:52 +01:00
|
|
|
def updateFileMenu(self):
|
|
|
|
|
|
|
|
self.fileMenu.clear()
|
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 = QSettings()
|
|
|
|
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])
|
|
|
|
|
2016-09-08 15:31:23 +02:00
|
|
|
@property
|
|
|
|
def inputs(self):
|
|
|
|
return self._inputs
|
|
|
|
|
2015-07-18 16:11:20 +02:00
|
|
|
def getRoot(self):
|
|
|
|
settings = QSettings()
|
|
|
|
return settings.value("data/dataRoot")
|
|
|
|
|
2016-05-27 11:25:47 +02:00
|
|
|
def load_autopicks(self, fname=None):
|
|
|
|
self.load_data(fname, type='auto')
|
|
|
|
|
|
|
|
def load_loc(self, fname=None):
|
2016-06-02 09:39:01 +02:00
|
|
|
type = getDataType(self)
|
|
|
|
self.load_data(fname, type=type, 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-06-02 09:39:01 +02:00
|
|
|
type = getDataType(self)
|
2016-05-27 11:25:47 +02:00
|
|
|
|
|
|
|
fname_dict = dict(phasfn=fn_phases, locfn=fn_loc)
|
|
|
|
self.load_data(fname_dict, type=type)
|
|
|
|
|
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
|
|
|
|
fext = '.xml'
|
|
|
|
for event in events:
|
|
|
|
path = event.path
|
2017-08-07 11:21:20 +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()
|
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))
|
2017-06-27 15:06:28 +02:00
|
|
|
data += data_new
|
|
|
|
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
|
2017-08-09 14:15:50 +02:00
|
|
|
print('Loading event info from file {}.'.format(fname))
|
2016-06-02 09:39:01 +02:00
|
|
|
if not loc:
|
2017-08-09 14:15:50 +02:00
|
|
|
self.updatePicks(type='auto', event=event)
|
|
|
|
self.updatePicks(type='manual', 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-07-14 16:25:59 +02:00
|
|
|
def set_button_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:
|
|
|
|
palette = button.palette()
|
|
|
|
role = button.backgroundRole()
|
|
|
|
palette.setColor(role, color)
|
|
|
|
button.setPalette(palette)
|
|
|
|
button.setAutoFillBackground(True)
|
|
|
|
elif type(color) == str or not color:
|
2017-07-14 16:25:59 +02:00
|
|
|
button.setStyleSheet("background-color: {}".format(color))
|
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.
|
|
|
|
'''
|
2017-04-18 16:24:26 +02:00
|
|
|
if self.dataStructure:
|
2017-05-19 10:56:27 +02:00
|
|
|
directory = self.get_current_event_path(eventbox)
|
2017-06-19 16:30:39 +02:00
|
|
|
if not directory:
|
|
|
|
return
|
2017-05-15 12:03:53 +02:00
|
|
|
fnames = [os.path.join(directory, f) for f in os.listdir(directory)]
|
2017-04-18 16:24:26 +02:00
|
|
|
else:
|
|
|
|
raise DatastructureError('not specified')
|
2017-05-15 12:03:53 +02:00
|
|
|
return fnames
|
|
|
|
|
2017-05-24 14:12:41 +02:00
|
|
|
def get_current_event(self, eventbox=None):
|
|
|
|
'''
|
|
|
|
Return event (type QtPylot.Event) currently selected in eventbox.
|
|
|
|
'''
|
2017-05-16 13:41:35 +02:00
|
|
|
if not eventbox:
|
|
|
|
eventbox = self.eventBox
|
2017-06-23 12:04:26 +02:00
|
|
|
path = eventbox.currentText()
|
|
|
|
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
|
|
|
'''
|
|
|
|
Return event path of event (type QtPylot.Event) currently selected in eventbox.
|
|
|
|
'''
|
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):
|
|
|
|
'''
|
|
|
|
Return event path of event (type QtPylot.Event) currently selected in eventbox.
|
|
|
|
'''
|
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_():
|
|
|
|
eventlist = ed.selectedFiles()
|
|
|
|
# select only folders that start with 'e', containin two dots and have length 12
|
|
|
|
eventlist = [item for item in eventlist if item.split('/')[-1].startswith('e')
|
|
|
|
and len(item.split('/')[-1].split('.')) == 3
|
|
|
|
and len(item.split('/')[-1]) == 12]
|
2017-06-21 11:43:01 +02:00
|
|
|
if not eventlist:
|
|
|
|
print('No events found! Expected structure for event folders: [evID.DOY.YR]')
|
|
|
|
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
|
|
|
|
2017-04-20 14:03:26 +02:00
|
|
|
def createEventBox(self):
|
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()
|
|
|
|
if len(self.project.eventlist) == 0:
|
|
|
|
print('No events to init.')
|
2017-04-19 15:31:08 +02:00
|
|
|
self.clearWaveformDataPlot()
|
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
|
|
|
|
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-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
|
|
|
|
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
|
|
|
|
event_npicks = 0
|
|
|
|
event_nautopicks = 0
|
2017-06-26 12:19:06 +02:00
|
|
|
if event.pylot_picks:
|
|
|
|
event_npicks = len(event.pylot_picks)
|
|
|
|
if event.pylot_autopicks:
|
|
|
|
event_nautopicks = len(event.pylot_autopicks)
|
2017-04-20 14:03:26 +02:00
|
|
|
event_ref = event.isRefEvent()
|
|
|
|
event_test = event.isTestEvent()
|
|
|
|
|
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
|
|
|
|
|
|
|
item_path = QtGui.QStandardItem('{path:{plen}}'.format(path=event_path, plen=plmax))
|
|
|
|
item_nmp = QtGui.QStandardItem(str(event_npicks))
|
|
|
|
item_nmp.setIcon(self.manupicksicon_small)
|
|
|
|
item_nap = QtGui.QStandardItem(str(event_nautopicks))
|
|
|
|
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-05-19 10:56:27 +02:00
|
|
|
item_ref.setBackground(self._colors['ref'])
|
2017-04-20 14:03:26 +02:00
|
|
|
if event_test:
|
2017-05-19 10:56:27 +02:00
|
|
|
item_test.setBackground(self._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)
|
|
|
|
itemlist = [item_path, item_nmp, item_nap, item_ref, item_test, item_notes]
|
2017-05-12 15:37:57 +02:00
|
|
|
if event_test and select_events == 'ref':
|
|
|
|
for item in itemlist:
|
|
|
|
item.setEnabled(False)
|
2017-04-21 15:46:57 +02:00
|
|
|
model.appendRow(itemlist)
|
2017-05-19 09:23:02 +02:00
|
|
|
if not event.path == self.eventBox.itemText(id).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
|
|
|
|
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
|
|
|
|
2017-08-07 16:45:20 +02:00
|
|
|
def saveData(self, event=None, directory=None, outformats=['.xml', '.cnv']):
|
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:
|
|
|
|
'''
|
|
|
|
if not event:
|
|
|
|
event = self.get_current_event()
|
2017-08-07 16:53:21 +02:00
|
|
|
if not type(outformats) == list:
|
|
|
|
outformats = [outformats]
|
2015-08-31 13:37:18 +02:00
|
|
|
|
2017-08-07 16:25:48 +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']
|
|
|
|
|
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)
|
|
|
|
|
2017-07-17 11:50:51 +02:00
|
|
|
fcheck = ['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:
|
|
|
|
print('WARNING: Format: {} not yet implemented'.format(outformat)) #MP MP TODO: .obs export (event.copy)
|
|
|
|
|
|
|
|
msg = 'Event {} saved as {} in format(s) {}'.format(event.pylot_id, fbasename, saved_as.strip())
|
|
|
|
self.update_status(msg)
|
|
|
|
print(msg)
|
|
|
|
|
2014-12-08 10:26:14 +01:00
|
|
|
return True
|
2014-11-28 11:15:49 +01:00
|
|
|
|
2017-08-07 16:25:48 +02:00
|
|
|
def exportAllEvents(self, outformats=['.xml']):
|
|
|
|
for event in self.project.eventlist:
|
|
|
|
self.get_data().setEvtData(event)
|
|
|
|
self.saveData(event, event.path, outformats)
|
|
|
|
|
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):
|
|
|
|
if self.check4Comparison():
|
2016-06-07 13:51:03 +02:00
|
|
|
co = Comparison(auto=self.getPicks('auto'), manu=self.getPicks())
|
|
|
|
compare_dlg = ComparisonDialog(co, self)
|
|
|
|
compare_dlg.exec_()
|
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
|
|
|
|
2015-07-07 10:39:01 +02:00
|
|
|
def getStationID(self, station):
|
|
|
|
for wfID in self.getPlotWidget().getPlotDict().keys():
|
|
|
|
actual_station = self.getPlotWidget().getPlotDict()[wfID][0]
|
|
|
|
if station == actual_station:
|
|
|
|
return wfID
|
|
|
|
return None
|
|
|
|
|
2016-05-31 17:27:59 +02:00
|
|
|
def getStime(self):
|
|
|
|
return self._stime
|
|
|
|
|
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.fill_eventbox()
|
|
|
|
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)
|
|
|
|
self.fill_eventbox()
|
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
|
|
|
|
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]
|
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.
|
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]:
|
|
|
|
# newWF(False) = load data without plotting
|
|
|
|
self.newWF(plot=False)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-05-24 14:12:41 +02:00
|
|
|
def newWF(self, plot=True):
|
|
|
|
'''
|
|
|
|
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:
|
2017-07-14 11:09:18 +02:00
|
|
|
self.wfd_thread = Thread(self, self.loadWaveformData,
|
2017-07-14 16:25:59 +02:00
|
|
|
progressText='Reading data input...')
|
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
|
|
|
|
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
|
2017-05-24 14:12:41 +02:00
|
|
|
self.fnames = self.getWFFnames_from_eventbox()
|
2017-05-15 12:03:53 +02:00
|
|
|
self.data.setWFData(self.fnames)
|
2017-08-11 15:15:58 +02:00
|
|
|
wfdat = self.data.getWFData() # all available streams
|
|
|
|
check4gaps(wfdat)
|
|
|
|
# trim station components to same start value
|
|
|
|
trim_station_components(wfdat, trim_start=True, trim_end=False)
|
2016-09-19 11:42:52 +02:00
|
|
|
self._stime = full_range(self.get_data().getWFData())[0]
|
2017-04-18 16:24:26 +02:00
|
|
|
|
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()
|
|
|
|
plots = self.wfp_thread.data
|
|
|
|
for times, data in plots:
|
|
|
|
self.dataPlot.plotWidget.getPlotItem().plot(times, data, pen='k')
|
|
|
|
self.dataPlot.reinitMoveProxy()
|
|
|
|
self.dataPlot.plotWidget.showAxis('left')
|
2017-07-14 16:25:59 +02:00
|
|
|
self.dataPlot.plotWidget.showAxis('bottom')
|
|
|
|
|
2017-04-18 16:24:26 +02:00
|
|
|
def finishWaveformDataPlot(self):
|
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-07-14 16:25:59 +02:00
|
|
|
self._max_xlims = self.dataPlot.getXLims()
|
2017-06-08 16:14:37 +02:00
|
|
|
plotWidget = self.getPlotWidget()
|
|
|
|
plotDict = plotWidget.getPlotDict()
|
|
|
|
pos = plotDict.keys()
|
2017-07-14 16:25:59 +02:00
|
|
|
labels = [plotDict[n][2] + '.' + plotDict[n][0] 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-30 11:04:49 +02:00
|
|
|
self.locateEvent.setEnabled(True)
|
2017-06-26 12:19:06 +02:00
|
|
|
if event.pylot_autopicks:
|
2017-04-19 16:51:19 +02:00
|
|
|
self.drawPicks(picktype='auto')
|
2017-05-11 08:33:08 +02:00
|
|
|
self.compare_action.setEnabled(True)
|
2017-04-18 16:24:26 +02:00
|
|
|
self.draw()
|
2015-01-29 08:48:25 +01:00
|
|
|
|
2017-04-19 15:31:08 +02:00
|
|
|
def clearWaveformDataPlot(self):
|
|
|
|
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-21 13:24:45 +02:00
|
|
|
self.dataPlot.plotWidget.hideAxis('bottom')
|
2017-07-14 16:25:59 +02:00
|
|
|
self.dataPlot.plotWidget.hideAxis('left')
|
2017-06-07 17:05:48 +02:00
|
|
|
else:
|
2017-07-14 16:25:59 +02:00
|
|
|
self.dataPlot.getAxes().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)
|
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
|
|
|
|
2017-04-18 16:24:26 +02:00
|
|
|
def plotWaveformDataThread(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Open a modal thread to plot current waveform data.
|
|
|
|
'''
|
2017-06-08 16:14:37 +02:00
|
|
|
self.clearWaveformDataPlot()
|
|
|
|
self.wfp_thread = Thread(self, self.plotWaveformData,
|
|
|
|
progressText='Plotting waveform data...')
|
|
|
|
self.wfp_thread.finished.connect(self.finishWaveformDataPlot)
|
|
|
|
self.wfp_thread.start()
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2015-02-17 13:17:01 +01:00
|
|
|
def plotWaveformData(self):
|
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()
|
|
|
|
# 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()
|
|
|
|
plots = plotWidget.plotWFData(wfdata=wfst, title=title, mapping=False, component=comp,
|
|
|
|
nth_sample=int(nth_sample))
|
2017-06-08 16:14:37 +02:00
|
|
|
return plots
|
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
|
|
|
|
2015-02-17 13:17:01 +01:00
|
|
|
def filterWaveformData(self):
|
2016-09-02 14:21:59 +02:00
|
|
|
if self.get_data():
|
2015-10-30 08:39:51 +01:00
|
|
|
if self.getFilterOptions() and self.filterAction.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)
|
2015-10-30 08:39:51 +01:00
|
|
|
elif self.filterAction.isChecked():
|
|
|
|
self.adjustFilterOptions()
|
2015-02-20 08:38:26 +01:00
|
|
|
else:
|
2016-09-02 14:21:59 +02:00
|
|
|
self.get_data().resetWFData()
|
2017-05-31 16:25:46 +02:00
|
|
|
self.plotWaveformDataThread()
|
2016-03-29 12:09:26 +02:00
|
|
|
self.drawPicks()
|
2016-05-31 17:27:59 +02:00
|
|
|
self.draw()
|
2014-11-28 11:15:49 +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)
|
2015-10-31 00:07:24 +01:00
|
|
|
if self.filterAction.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()
|
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
|
|
|
|
2014-03-28 05:25:46 +01:00
|
|
|
def updateFilterOptions(self):
|
2014-10-27 12:04:01 +01:00
|
|
|
try:
|
2015-03-01 10:31:49 +01:00
|
|
|
settings = QSettings()
|
2015-06-11 10:07:21 +02:00
|
|
|
if settings.value("filterdefaults",
|
|
|
|
None) is None and not self.getFilters():
|
2015-09-25 15:06:59 +02:00
|
|
|
for key, value in FILTERDEFAULTS.items():
|
2015-03-01 10:31:49 +01:00
|
|
|
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)
|
2015-09-25 15:06:59 +02:00
|
|
|
except Exception as e:
|
2016-09-02 14:21:59 +02:00
|
|
|
self.update_status('Error ...')
|
2014-11-28 11:15:49 +01:00
|
|
|
emsg = QErrorMessage(self)
|
|
|
|
emsg.showMessage('Error: {0}'.format(e))
|
2014-10-27 12:04:01 +01:00
|
|
|
else:
|
2016-09-02 14:21:59 +02:00
|
|
|
self.update_status('Filter loaded ... '
|
2017-07-14 16:25:59 +02:00
|
|
|
'[{0}: {1} Hz]'.format(
|
2016-03-30 07:00:31 +02:00
|
|
|
self.getFilterOptions().getFilterType(),
|
|
|
|
self.getFilterOptions().getFreq()))
|
2015-02-20 08:38:26 +01:00
|
|
|
if self.filterAction.isChecked():
|
|
|
|
self.filterWaveformData()
|
2014-03-28 22:26:15 +01:00
|
|
|
|
2014-11-13 11:27:52 +01:00
|
|
|
def getSeismicPhase(self):
|
|
|
|
return self.seismicPhase
|
|
|
|
|
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():
|
|
|
|
return plot_dict[wfID][0]
|
2015-03-09 11:21:33 +01:00
|
|
|
|
2017-06-30 13:56:59 +02:00
|
|
|
def getNetworkName(self, wfID):
|
|
|
|
plot_dict = self.getPlotWidget().getPlotDict()
|
|
|
|
if wfID in plot_dict.keys():
|
|
|
|
return plot_dict[wfID][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.}
|
|
|
|
xlims = self.dataPlot.getXLims()
|
|
|
|
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]
|
|
|
|
self.dataPlot.setXLims((xl, xr))
|
|
|
|
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:
|
|
|
|
if not gui_event.button() == 1:
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
if not gui_event.button == 1:
|
|
|
|
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-06-21 15:20:36 +02:00
|
|
|
self.pickDialog(wfID)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-06-21 15:20:36 +02:00
|
|
|
def pickDialog(self, wfID, nextStation=False):
|
2015-03-09 11:21:33 +01:00
|
|
|
station = self.getStationName(wfID)
|
2017-06-30 13:56:59 +02:00
|
|
|
network = self.getNetworkName(wfID)
|
2017-06-08 14:09:01 +02:00
|
|
|
if not station:
|
|
|
|
return
|
2016-09-02 14:21:59 +02:00
|
|
|
self.update_status('picking on station {0}'.format(station))
|
|
|
|
data = self.get_data().getWFData()
|
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,
|
2017-04-10 15:06:30 +02:00
|
|
|
picks=self.getPicksOnStation(station, 'manual'),
|
|
|
|
autopicks=self.getPicksOnStation(station, 'auto'))
|
2017-06-21 15:20:36 +02:00
|
|
|
pickDlg.nextStation.setChecked(nextStation)
|
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))
|
|
|
|
replot = self.addPicks(station, pickDlg.getPicks())
|
|
|
|
self.get_current_event().setPick(station, pickDlg.getPicks())
|
2017-08-07 16:41:50 +02:00
|
|
|
self.enableSaveEventAction()
|
2017-06-21 15:20:36 +02:00
|
|
|
if replot:
|
|
|
|
self.plotWaveformDataThread()
|
|
|
|
self.drawPicks()
|
|
|
|
self.draw()
|
|
|
|
else:
|
|
|
|
self.drawPicks(station)
|
|
|
|
self.draw()
|
|
|
|
if pickDlg.nextStation.isChecked():
|
|
|
|
self.pickDialog(wfID - 1, nextStation=pickDlg.nextStation.isChecked())
|
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():
|
2017-04-10 14:43:11 +02:00
|
|
|
self.locateEvent.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
|
|
|
|
2015-11-26 05:17:26 +01:00
|
|
|
def addListItem(self, text):
|
|
|
|
self.listWidget.addItem(text)
|
|
|
|
self.listWidget.scrollToBottom()
|
|
|
|
|
2017-05-11 17:15:20 +02:00
|
|
|
def tune_autopicker(self):
|
2017-05-24 14:12:41 +02:00
|
|
|
'''
|
|
|
|
Initiates TuneAutopicker widget use to interactively
|
|
|
|
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
|
2017-05-12 11:03:41 +02:00
|
|
|
self.fig_dict = {}
|
|
|
|
self.canvas_dict = {}
|
|
|
|
self.fig_keys = [
|
|
|
|
'mainFig',
|
|
|
|
'aicFig',
|
|
|
|
'slength',
|
|
|
|
'checkZ4s',
|
|
|
|
'refPpick',
|
|
|
|
'el_Ppick',
|
|
|
|
'fm_picker',
|
|
|
|
'el_S1pick',
|
|
|
|
'el_S2pick',
|
|
|
|
'refSpick',
|
2017-07-14 16:25:59 +02:00
|
|
|
'aicARHfig',
|
2017-05-12 11:03:41 +02:00
|
|
|
]
|
|
|
|
for key in self.fig_keys:
|
|
|
|
fig = Figure()
|
|
|
|
self.fig_dict[key] = fig
|
2017-05-11 17:15:20 +02:00
|
|
|
|
2017-08-11 15:15:58 +02:00
|
|
|
#if not self.tap:
|
|
|
|
# init TuneAutopicker object
|
|
|
|
self.tap = TuneAutopicker(self)
|
|
|
|
# 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)
|
|
|
|
#else:
|
|
|
|
# self.update_autopicker()
|
|
|
|
# self.tap.fill_eventbox()
|
2017-05-12 15:37:57 +02:00
|
|
|
self.tap.show()
|
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-05-19 13:53:58 +02:00
|
|
|
for key in self.fig_keys:
|
2017-05-12 11:03:41 +02:00
|
|
|
self.canvas_dict[key] = FigureCanvas(self.fig_dict[key])
|
2017-05-16 13:41:35 +02:00
|
|
|
self.tap.fill_tabs(picked=True)
|
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-07 16:49:56 +02:00
|
|
|
event = self.get_current_event()
|
|
|
|
self.saveData(event, event.path, outformats=['.xml'])
|
2015-11-26 05:17:26 +01:00
|
|
|
self.listWidget = QListWidget()
|
2015-07-18 16:11:20 +02:00
|
|
|
self.setDirty(True)
|
2015-11-30 09:55:33 +01:00
|
|
|
self.logDockWidget = QDockWidget("AutoPickLog", self)
|
|
|
|
self.logDockWidget.setObjectName("LogDockWidget")
|
2016-05-27 11:25:47 +02:00
|
|
|
self.logDockWidget.setAllowedAreas(
|
|
|
|
Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea)
|
2015-11-30 09:55:33 +01:00
|
|
|
self.logDockWidget.setWidget(self.listWidget)
|
|
|
|
self.addDockWidget(Qt.LeftDockWidgetArea, self.logDockWidget)
|
2017-07-31 13:43:06 +02:00
|
|
|
# self.addListItem('Loading default values from PyLoT-input file %s'
|
|
|
|
# % self.infile)
|
|
|
|
|
2017-07-31 17:00:19 +02:00
|
|
|
args = {'parameter': self._inputs,
|
|
|
|
'station': 'all',
|
|
|
|
'fnames': 'None',
|
2017-08-03 09:41:54 +02:00
|
|
|
'eventid': self.get_current_event_path(),
|
2017-07-31 17:00:19 +02:00
|
|
|
'iplot': 0,
|
|
|
|
'fig_dict': None,
|
|
|
|
'locflag': 0}
|
|
|
|
|
|
|
|
self.mp_thread = QtCore.QThreadPool()
|
|
|
|
self.mp_worker = Worker(autoPyLoT, args, redirect_stdout=True)
|
|
|
|
self.mp_thread.start(self.mp_worker)
|
|
|
|
|
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-03 09:41:54 +02:00
|
|
|
# self.mp_thread.finished.connect(self.finalizeAutoPick)
|
2015-12-01 05:03:55 +01:00
|
|
|
|
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()
|
|
|
|
|
2015-12-01 05:03:55 +01:00
|
|
|
def finalizeAutoPick(self):
|
|
|
|
self.drawPicks(picktype='auto')
|
2016-05-31 17:27:59 +02:00
|
|
|
self.draw()
|
2017-07-31 13:43:06 +02:00
|
|
|
self.mp_thread.quit()
|
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-07-18 14:34:09 +02:00
|
|
|
if not stat_picks and picks:
|
2017-06-19 10:37:24 +02:00
|
|
|
rval = False
|
|
|
|
else:
|
2017-07-14 16:25:59 +02:00
|
|
|
rval = True
|
2017-07-18 14:34:09 +02:00
|
|
|
# set picks (ugly syntax?)
|
|
|
|
self.getPicks(type=type)[station] = picks
|
2017-06-19 10:37:24 +02:00
|
|
|
return rval
|
2017-06-19 10:30:08 +02:00
|
|
|
# if not stat_picks:
|
|
|
|
# stat_picks = picks
|
|
|
|
# else:
|
|
|
|
# msgBox = QMessageBox(self)
|
|
|
|
# msgBox.setText("The picks for station {0} have been "
|
|
|
|
# "changed.".format(station))
|
|
|
|
# msgBox.setDetailedText("Old picks:\n"
|
|
|
|
# "{old_picks}\n\n"
|
|
|
|
# "New picks:\n"
|
|
|
|
# "{new_picks}".format(old_picks=stat_picks,
|
|
|
|
# new_picks=picks))
|
|
|
|
# msgBox.setInformativeText("Do you want to save your changes?")
|
|
|
|
# msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Cancel)
|
|
|
|
# msgBox.setDefaultButton(QMessageBox.Save)
|
|
|
|
# ret = msgBox.exec_()
|
|
|
|
# if ret == QMessageBox.Save:
|
|
|
|
# stat_picks = picks
|
|
|
|
# rval = True
|
|
|
|
# elif ret == QMessageBox.Cancel:
|
|
|
|
# pass
|
|
|
|
# else:
|
|
|
|
# raise Exception('FATAL: Should never occur!')
|
|
|
|
# MP MP prompt redundant because new picks have to be accepted in the first place closing PickDlg
|
2015-07-07 10:37:54 +02:00
|
|
|
|
2017-06-22 16:30:22 +02:00
|
|
|
def updatePicks(self, type='manual', event=None):
|
|
|
|
if not event:
|
|
|
|
event = self.get_current_event()
|
2017-08-09 14:15:50 +02:00
|
|
|
picksdict = picksdict_from_picks(evt=self.get_data().get_evt_data())
|
2016-03-29 10:30:45 +02:00
|
|
|
if type == 'manual':
|
2017-08-09 14:15:50 +02:00
|
|
|
event.addPicks(picksdict['manual'])
|
|
|
|
#event.picks.update(picks) MP MP idea
|
2016-03-29 10:30:45 +02:00
|
|
|
elif type == 'auto':
|
2017-08-09 14:15:50 +02:00
|
|
|
event.addAutopicks(picksdict['auto'])
|
2016-06-06 14:10:46 +02:00
|
|
|
self.check4Comparison()
|
2015-09-03 13:21:46 +02:00
|
|
|
|
2017-08-09 14:15:50 +02:00
|
|
|
def drawPicks(self, station=None, picktype=None):
|
|
|
|
# if picktype not specified, draw both
|
|
|
|
if not picktype:
|
|
|
|
self.drawPicks(station, 'manual')
|
|
|
|
self.drawPicks(station, 'auto')
|
|
|
|
return
|
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):
|
|
|
|
self.drawPicks(station, picktype=picktype)
|
2015-07-07 10:39:01 +02:00
|
|
|
return
|
|
|
|
# plotting picks
|
|
|
|
plotID = self.getStationID(station)
|
2017-04-20 15:28:43 +02:00
|
|
|
if plotID is None:
|
2016-09-08 15:29:37 +02:00
|
|
|
return
|
2017-06-09 13:23:16 +02:00
|
|
|
if self.pg:
|
2017-06-08 14:09:01 +02:00
|
|
|
pw = self.getPlotWidget().plotWidget
|
|
|
|
else:
|
|
|
|
ax = self.getPlotWidget().axes
|
2015-07-07 10:39:01 +02:00
|
|
|
ylims = np.array([-.5, +.5]) + plotID
|
2017-07-14 16:25:59 +02:00
|
|
|
if self.pg:
|
2017-06-08 14:09:01 +02:00
|
|
|
dashed = QtCore.Qt.DashLine
|
|
|
|
dotted = QtCore.Qt.DotLine
|
|
|
|
phase_col = {
|
2017-07-14 16:25:59 +02:00
|
|
|
'P': (pg.mkPen('c'), pg.mkPen((0, 255, 255, 100), style=dashed), pg.mkPen('b', style=dashed),
|
|
|
|
pg.mkPen('b', style=dotted)),
|
|
|
|
'S': (pg.mkPen('m'), pg.mkPen((255, 0, 255, 100), style=dashed), pg.mkPen('r', style=dashed),
|
|
|
|
pg.mkPen('r', style=dotted))
|
2017-06-08 14:09:01 +02:00
|
|
|
}
|
|
|
|
else:
|
|
|
|
phase_col = {
|
|
|
|
'P': ('c', 'c--', 'b-', 'bv', 'b^', 'b'),
|
|
|
|
'S': ('m', 'm--', 'r-', 'rv', 'r^', 'r')
|
|
|
|
}
|
2015-07-07 10:39:01 +02:00
|
|
|
|
2015-11-30 09:50:47 +01:00
|
|
|
stat_picks = self.getPicks(type=picktype)[station]
|
2016-05-31 17:27:59 +02:00
|
|
|
stime = self.getStime()
|
|
|
|
|
2015-07-07 10:39:01 +02:00
|
|
|
for phase in stat_picks:
|
|
|
|
picks = stat_picks[phase]
|
2017-06-23 14:56:56 +02:00
|
|
|
if type(stat_picks[phase]) is not dict and type(stat_picks[phase]) is not AttribDict:
|
2015-11-30 09:50:47 +01:00
|
|
|
return
|
2017-08-11 16:04:18 +02:00
|
|
|
|
|
|
|
# get quality classes
|
|
|
|
if phase[0] == 'P':
|
|
|
|
quality = getQualityfromUncertainty(picks['spe'], self._inputs['timeerrorsP'])
|
|
|
|
elif phase[0] == 'S':
|
|
|
|
quality = getQualityfromUncertainty(picks['spe'], self._inputs['timeerrorsS'])
|
|
|
|
|
2015-07-07 10:39:01 +02:00
|
|
|
colors = phase_col[phase[0].upper()]
|
|
|
|
|
2015-07-13 06:39:25 +02:00
|
|
|
mpp = picks['mpp'] - stime
|
2017-06-01 15:25:43 +02:00
|
|
|
if picks['epp'] and picks['lpp']:
|
|
|
|
epp = picks['epp'] - stime
|
|
|
|
lpp = picks['lpp'] - stime
|
2017-07-14 15:26:39 +02:00
|
|
|
else:
|
|
|
|
epp = None
|
|
|
|
lpp = None
|
2015-07-07 10:39:01 +02:00
|
|
|
spe = picks['spe']
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-06-01 15:25:43 +02:00
|
|
|
if not spe and epp and lpp:
|
2016-09-21 14:12:58 +02:00
|
|
|
spe = symmetrize_error(mpp - epp, lpp - mpp)
|
2015-07-07 10:39:01 +02:00
|
|
|
|
2017-06-09 13:23:16 +02:00
|
|
|
if self.pg:
|
2017-06-08 14:09:01 +02:00
|
|
|
if picktype == 'manual':
|
|
|
|
if picks['epp'] and picks['lpp']:
|
|
|
|
pw.plot([epp, epp], ylims,
|
|
|
|
alpha=.25, pen=colors[0], name='EPP')
|
|
|
|
pw.plot([lpp, lpp], ylims,
|
|
|
|
alpha=.25, pen=colors[0], name='LPP')
|
|
|
|
if spe:
|
2017-07-14 16:25:59 +02:00
|
|
|
spe_l = pg.PlotDataItem([mpp - spe, mpp - spe], ylims, pen=colors[1],
|
|
|
|
name='{}-SPE'.format(phase))
|
2017-06-08 14:09:01 +02:00
|
|
|
spe_r = pg.PlotDataItem([mpp + spe, mpp + spe], ylims, pen=colors[1])
|
|
|
|
pw.addItem(spe_l)
|
|
|
|
pw.addItem(spe_r)
|
|
|
|
try:
|
|
|
|
fill = pg.FillBetweenItem(spe_l, spe_r, brush=colors[1].brush())
|
|
|
|
fb = pw.addItem(fill)
|
|
|
|
except:
|
2017-06-08 16:58:44 +02:00
|
|
|
print('Warning: drawPicks: Could not create fill for symmetric pick error.')
|
2017-06-08 14:09:01 +02:00
|
|
|
pw.plot([mpp, mpp], ylims, pen=colors[2], name='{}-Pick'.format(phase))
|
|
|
|
else:
|
|
|
|
pw.plot([mpp, mpp], ylims, pen=colors[0], name='{}-Pick (NO PICKERROR)'.format(phase))
|
|
|
|
elif picktype == 'auto':
|
2017-08-11 16:04:18 +02:00
|
|
|
if quality < 4:
|
|
|
|
pw.plot([mpp, mpp], ylims, pen=colors[3])
|
2017-06-01 15:25:43 +02:00
|
|
|
else:
|
2017-06-08 14:09:01 +02:00
|
|
|
raise TypeError('Unknown picktype {0}'.format(picktype))
|
2015-11-30 09:50:47 +01:00
|
|
|
else:
|
2017-06-08 14:09:01 +02:00
|
|
|
if picktype == 'manual':
|
|
|
|
if picks['epp'] and picks['lpp']:
|
|
|
|
ax.fill_between([epp, lpp], ylims[0], ylims[1],
|
|
|
|
alpha=.25, color=colors[0], label='EPP, LPP')
|
|
|
|
if spe:
|
|
|
|
ax.plot([mpp - spe, mpp - spe], ylims, colors[1], label='{}-SPE'.format(phase))
|
|
|
|
ax.plot([mpp + spe, mpp + spe], ylims, colors[1])
|
|
|
|
ax.plot([mpp, mpp], ylims, colors[2], label='{}-Pick'.format(phase))
|
|
|
|
else:
|
|
|
|
ax.plot([mpp, mpp], ylims, colors[6], label='{}-Pick (NO PICKERROR)'.format(phase))
|
|
|
|
elif picktype == 'auto':
|
2017-08-11 16:04:18 +02:00
|
|
|
if quality < 4:
|
|
|
|
ax.plot(mpp, ylims[1], colors[3],
|
|
|
|
mpp, ylims[0], colors[4])
|
|
|
|
ax.vlines(mpp, ylims[0], ylims[1], colors[5], linestyles='dotted')
|
2017-06-08 14:09:01 +02:00
|
|
|
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
|
2015-11-13 14:05:29 +01:00
|
|
|
settings = QSettings()
|
2016-08-25 13:31:51 +02:00
|
|
|
# get location tool hook
|
2015-11-13 14:05:29 +01:00
|
|
|
loctool = settings.value("loc/tool", "nll")
|
2016-08-25 13:31:51 +02:00
|
|
|
lt = locateTool[loctool]
|
|
|
|
# get working directory
|
|
|
|
locroot = settings.value("{0}/rootPath".format(loctool), None)
|
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
|
|
|
|
2016-08-25 13:31:51 +02:00
|
|
|
infile = settings.value("{0}/inputFile".format(loctool), None)
|
2016-08-26 14:36:33 +02:00
|
|
|
|
|
|
|
if not infile:
|
|
|
|
caption = 'Select {0} input file'.format(loctool)
|
|
|
|
filt = "Supported file formats" \
|
|
|
|
" (*.in *.ini *.conf *.cfg)"
|
|
|
|
ans = QFileDialog().getOpenFileName(self, caption=caption,
|
|
|
|
filter=filt, dir=locroot)
|
2016-09-08 15:28:40 +02:00
|
|
|
if ans[0]:
|
|
|
|
infile = ans[0]
|
|
|
|
else:
|
|
|
|
QMessageBox.information(self,
|
|
|
|
self.tr('No infile selected'),
|
|
|
|
self.tr('Inputfile necessary for localization.'))
|
|
|
|
return
|
2016-08-26 14:36:33 +02:00
|
|
|
settings.setValue("{0}/inputFile".format(loctool), infile)
|
|
|
|
settings.sync()
|
2016-08-29 15:52:58 +02:00
|
|
|
if loctool == 'nll':
|
|
|
|
ttt = settings.value("{0}/travelTimeTables", None)
|
|
|
|
ok = False
|
|
|
|
if ttt is None:
|
|
|
|
while not ok:
|
|
|
|
text, ok = QInputDialog.getText(self, 'Pattern for travel time tables',
|
|
|
|
'Base name of travel time tables',
|
|
|
|
echo=QLineEdit.Normal,
|
|
|
|
text="ttime")
|
|
|
|
ttt = text
|
|
|
|
|
|
|
|
outfile = settings.value("{0}/outputFile".format(loctool),
|
|
|
|
os.path.split(os.tempnam())[-1])
|
2017-06-30 17:20:18 +02:00
|
|
|
obsdir = os.path.join(locroot, 'obs')
|
2017-08-07 16:25:48 +02:00
|
|
|
self.saveData(event=self.get_current_event(), directory=obsdir, outformat='.obs')
|
2017-06-30 17:20:18 +02:00
|
|
|
eventname = self.get_current_event_name()
|
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')
|
2016-08-26 14:36:33 +02:00
|
|
|
phasepath = os.path.join(locroot, 'obs', phasefile)
|
2017-06-30 17:20:18 +02:00
|
|
|
lt.modify_inputs(infile, locroot, filename, phasefile, ttt)
|
2016-08-25 21:32:41 +02:00
|
|
|
try:
|
|
|
|
lt.locate(infile)
|
|
|
|
except RuntimeError as e:
|
|
|
|
print(e.message)
|
|
|
|
finally:
|
|
|
|
os.remove(phasepath)
|
|
|
|
|
2017-06-26 12:19:06 +02:00
|
|
|
self.get_data().applyEVTData(lt.read_location(locpath), typ='event')
|
2017-07-14 16:25:59 +02:00
|
|
|
# self.get_data().applyEVTData(self.calc_magnitude(), 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)
|
|
|
|
grid_layout.setRowStretch(3, 1)
|
|
|
|
|
|
|
|
label = QLabel('No inventory set...')
|
|
|
|
new_inv_button = QPushButton('Set &inventory file')
|
|
|
|
new_inv_button.clicked.connect(self.get_metadata)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-04-19 15:31:08 +02:00
|
|
|
grid_layout.addWidget(label, 1, 1)
|
|
|
|
grid_layout.addWidget(new_inv_button, 2, 1)
|
|
|
|
|
2017-05-22 15:34:07 +02:00
|
|
|
self.metadata = None
|
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)
|
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:
|
|
|
|
self.get_metadata()
|
|
|
|
if not self.metadata:
|
|
|
|
return
|
2017-05-11 17:15:20 +02:00
|
|
|
self.am_figure = Figure()
|
|
|
|
self.am_canvas = FigureCanvas(self.am_figure)
|
|
|
|
self.am_toolbar = NavigationToolbar(self.am_canvas, self)
|
2017-04-19 16:05:45 +02:00
|
|
|
self.array_map = map_projection(self)
|
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-05-11 17:15:20 +02:00
|
|
|
self.amt = Thread(self, self.array_map.init_map, arg=None, progressText='Generating map...')
|
|
|
|
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-05-19 10:56:27 +02:00
|
|
|
self.array_map.refresh_drawings(self.get_current_event().getPicks())
|
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
|
|
|
|
event = self.project.getEventFromPath(table[row][1].text())
|
|
|
|
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
|
2017-08-07 12:03:15 +02:00
|
|
|
event = self.project.getEventFromPath(table[row][1].text())
|
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
|
|
|
|
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
|
|
|
|
self.event_table = QtGui.QTableWidget()
|
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))
|
2017-07-18 16:07:08 +02:00
|
|
|
self.event_table.setHorizontalHeaderLabels(['',
|
|
|
|
'Event',
|
2017-06-23 14:56:56 +02:00
|
|
|
'Time',
|
|
|
|
'Lat',
|
|
|
|
'Lon',
|
|
|
|
'Depth',
|
|
|
|
'Mag',
|
|
|
|
'[N] MP',
|
|
|
|
'[N] AP',
|
|
|
|
'Tuning Set',
|
|
|
|
'Test Set',
|
|
|
|
'Notes'])
|
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 = []
|
|
|
|
for index, event in enumerate(eventlist):
|
2017-04-21 15:46:57 +02:00
|
|
|
event_npicks = 0
|
|
|
|
event_nautopicks = 0
|
2017-06-26 12:19:06 +02:00
|
|
|
if event.pylot_picks:
|
|
|
|
event_npicks = len(event.pylot_picks)
|
|
|
|
if event.pylot_autopicks:
|
|
|
|
event_nautopicks = len(event.pylot_autopicks)
|
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()
|
2017-07-14 16:25:59 +02:00
|
|
|
item_mag = QtGui.QTableWidgetItem()
|
2017-04-21 15:46:57 +02:00
|
|
|
item_nmp = QtGui.QTableWidgetItem(str(event_npicks))
|
|
|
|
item_nmp.setIcon(self.manupicksicon_small)
|
|
|
|
item_nap = QtGui.QTableWidgetItem(str(event_nautopicks))
|
|
|
|
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
|
|
|
|
2017-07-18 16:07:08 +02:00
|
|
|
# manipulate items
|
2017-05-19 10:56:27 +02:00
|
|
|
item_ref.setBackground(self._colors['ref'])
|
|
|
|
item_test.setBackground(self._colors['test'])
|
2017-04-20 12:05:34 +02:00
|
|
|
item_path.setText(event.path)
|
2017-06-23 14:56:56 +02:00
|
|
|
if hasattr(event, 'origins'):
|
|
|
|
if event.origins:
|
|
|
|
origin = event.origins[0]
|
|
|
|
item_time.setText(str(origin.time).split('.')[0])
|
|
|
|
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:
|
|
|
|
magnitude = event.magnitudes[0]
|
|
|
|
item_mag.setText(str(magnitude.mag))
|
|
|
|
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
|
|
|
|
2017-07-18 16:07:08 +02:00
|
|
|
column = [item_delete, item_path, item_time, item_lat, item_lon, item_depth, item_mag,
|
2017-07-14 16:25:59 +02:00
|
|
|
item_nmp, item_nap, item_ref, item_test, item_notes]
|
2017-04-20 12:05:34 +02:00
|
|
|
self.project._table.append(column)
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-04-19 15:31:08 +02:00
|
|
|
def read_metadata_thread(self, fninv):
|
|
|
|
self.rm_thread = Thread(self, read_metadata, arg=fninv, progressText='Reading metadata...')
|
|
|
|
self.rm_thread.finished.connect(self.set_metadata)
|
|
|
|
self.rm_thread.start()
|
|
|
|
|
|
|
|
def set_metadata(self):
|
2017-06-06 15:28:43 +02:00
|
|
|
settings = QSettings()
|
2017-04-19 15:31:08 +02:00
|
|
|
self.metadata = self.rm_thread.data
|
2017-06-06 15:28:43 +02:00
|
|
|
if settings.value('saveMetadata'):
|
|
|
|
self.project.metadata = self.rm_thread.data
|
|
|
|
self.project.inv_path = settings.value("inventoryFile")
|
2017-04-19 15:31:08 +02:00
|
|
|
self.init_array_map()
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-04-12 16:43:29 +02:00
|
|
|
def get_metadata(self):
|
2016-09-28 14:37:24 +02:00
|
|
|
def set_inv(settings):
|
2016-09-23 15:12:04 +02:00
|
|
|
fninv, _ = QFileDialog.getOpenFileName(self, self.tr(
|
|
|
|
"Select inventory..."), self.tr("Select file"))
|
2016-09-28 14:37:24 +02:00
|
|
|
if not fninv:
|
|
|
|
return False
|
2016-09-23 15:12:04 +02:00
|
|
|
ans = QMessageBox.question(self, self.tr("Make default..."),
|
|
|
|
self.tr(
|
|
|
|
"New inventory filename set.\n" + \
|
|
|
|
"Do you want to make it the default value?"),
|
|
|
|
QMessageBox.Yes | QMessageBox.No,
|
|
|
|
QMessageBox.No)
|
|
|
|
if ans == QMessageBox.Yes:
|
|
|
|
settings.setValue("inventoryFile", fninv)
|
|
|
|
settings.sync()
|
2017-04-19 15:31:08 +02:00
|
|
|
self.read_metadata_thread(fninv)
|
2016-09-28 14:37:24 +02:00
|
|
|
return True
|
2017-04-19 16:05:45 +02:00
|
|
|
|
2017-06-06 15:28:43 +02:00
|
|
|
settings = QSettings()
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-04-19 16:05:45 +02:00
|
|
|
if hasattr(self.project, 'metadata'):
|
|
|
|
self.metadata = self.project.metadata
|
|
|
|
return True
|
2017-07-19 10:11:26 +02:00
|
|
|
if hasattr(self.project, 'inv_path'):
|
2017-06-06 15:28:43 +02:00
|
|
|
settings.setValue("inventoryFile", self.project.inv_path)
|
2016-09-28 14:37:24 +02:00
|
|
|
|
2017-06-06 15:28:43 +02:00
|
|
|
fninv = settings.value("inventoryFile", None)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2016-09-28 14:37:24 +02:00
|
|
|
if fninv is None and not self.metadata:
|
|
|
|
if not set_inv(settings):
|
|
|
|
return None
|
|
|
|
elif fninv is not None and not self.metadata:
|
2017-07-19 10:11:26 +02:00
|
|
|
if not hasattr(self.project, 'inv_path'):
|
2017-06-06 15:28:43 +02:00
|
|
|
ans = QMessageBox.question(self, self.tr("Use default metadata..."),
|
|
|
|
self.tr(
|
|
|
|
"Do you want to use the default value for metadata?"),
|
|
|
|
QMessageBox.Yes | QMessageBox.No,
|
|
|
|
QMessageBox.Yes)
|
|
|
|
if ans == QMessageBox.No:
|
|
|
|
if not set_inv(settings):
|
|
|
|
return None
|
2017-07-07 11:43:58 +02:00
|
|
|
self.read_metadata_thread(fninv)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-04-12 16:43:29 +02:00
|
|
|
def calc_magnitude(self, type='ML'):
|
|
|
|
self.get_metadata()
|
|
|
|
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()
|
2017-04-06 15:37:54 +02:00
|
|
|
corr_wf = restitute_data(wf_copy, *self.metadata)
|
|
|
|
# if not rest_flag:
|
|
|
|
# raise ProcessingError('Restitution of waveform data failed!')
|
2016-09-22 11:39:07 +02:00
|
|
|
if type == 'ML':
|
2017-07-14 16:25:59 +02:00
|
|
|
local_mag = LocalMagnitude(corr_wf, self.get_data().get_evt_data(), self.inputs.get('sstop'),
|
|
|
|
verbosity=True)
|
2016-09-29 12:08:59 +02:00
|
|
|
return local_mag.updated_event()
|
2016-09-22 11:39:07 +02:00
|
|
|
elif type == 'Mw':
|
2017-07-14 16:25:59 +02:00
|
|
|
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)
|
2016-09-29 12:08:59 +02:00
|
|
|
return moment_mag.updated_event()
|
2016-09-02 14:21:59 +02:00
|
|
|
else:
|
|
|
|
return None
|
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
|
|
|
|
2016-06-06 14:10:46 +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
|
|
|
|
|
|
|
|
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:
|
|
|
|
dlg = QFileDialog()
|
|
|
|
fnm = dlg.getOpenFileName(self, 'Open project file...', filter='Pylot project (*.plp)')
|
2017-05-29 11:31:09 +02:00
|
|
|
if not fnm:
|
|
|
|
return
|
|
|
|
fnm = fnm[0]
|
|
|
|
if fnm:
|
|
|
|
self.project = Project.load(fnm)
|
2017-06-06 16:30:27 +02:00
|
|
|
if hasattr(self.project, 'parameter'):
|
|
|
|
if self.project.parameter:
|
|
|
|
self._inputs = self.project.parameter
|
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)
|
2017-05-31 11:48:16 +02:00
|
|
|
self.setDirty(False)
|
2017-06-06 16:30:27 +02:00
|
|
|
if hasattr(self.project, 'metadata'):
|
|
|
|
if self.project.metadata:
|
|
|
|
self.init_array_map(index=0)
|
|
|
|
return
|
2017-07-19 10:11:26 +02:00
|
|
|
if hasattr(self.project, 'inv_path'):
|
|
|
|
self.init_array_map(index=0)
|
|
|
|
return
|
|
|
|
|
2017-06-06 16:30:27 +02:00
|
|
|
self.init_array_tab()
|
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.
|
|
|
|
'''
|
|
|
|
dlg = QFileDialog()
|
|
|
|
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
|
2017-06-21 13:24:45 +02:00
|
|
|
self.project.save(filename)
|
|
|
|
self.setDirty(False)
|
|
|
|
self.saveProjectAsAction.setEnabled(True)
|
2017-08-07 16:33:45 +02:00
|
|
|
self.exportAllEvents()
|
2017-06-21 13:24:45 +02:00
|
|
|
self.update_status('Saved new project to {}'.format(filename), duration=5000)
|
|
|
|
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:
|
2017-07-14 16:25:59 +02:00
|
|
|
self.project.parameter = self._inputs
|
2017-04-19 16:05:45 +02:00
|
|
|
self.project.save()
|
2017-08-07 16:33:45 +02:00
|
|
|
self.exportAllEvents()
|
2017-04-18 16:24:26 +02:00
|
|
|
if not self.project.dirty:
|
2017-06-21 13:24:45 +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
|
|
|
self.setDirty(False)
|
|
|
|
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()
|
|
|
|
|
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
|
|
|
|
|
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-06-22 11:18:55 +02:00
|
|
|
self.paraBox = PylotParaBox(self._inputs)
|
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
|
|
|
|
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)
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2017-05-29 18:03:31 +02:00
|
|
|
if self._props.exec_():
|
2017-06-09 13:23:16 +02:00
|
|
|
self.init_wfWidget()
|
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():
|
2015-01-29 08:53:01 +01:00
|
|
|
form = HelpForm(
|
2016-03-30 07:00:31 +02:00
|
|
|
'https://ariadne.geophysik.ruhr-uni-bochum.de/trac/PyLoT/wiki')
|
2014-06-11 15:19:37 +02:00
|
|
|
else:
|
|
|
|
form = HelpForm(':/help.html')
|
|
|
|
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):
|
|
|
|
'''
|
|
|
|
Pickable class containing information of a QtPyLoT project, like event lists and file locations.
|
|
|
|
'''
|
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):
|
|
|
|
self.eventlist.remove(event)
|
|
|
|
|
|
|
|
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=','):
|
|
|
|
'''
|
|
|
|
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.
|
|
|
|
'''
|
|
|
|
infile = open(filename, 'r')
|
|
|
|
for line in infile.readlines():
|
2017-07-18 15:27:52 +02:00
|
|
|
eventID, date, time, mag, lat, lon, depth = line.split(separator)[:7]
|
2017-07-14 16:25:59 +02:00
|
|
|
# skip first line
|
2017-06-23 14:14:42 +02:00
|
|
|
try:
|
|
|
|
month, day, year = date.split('/')
|
|
|
|
except:
|
|
|
|
continue
|
|
|
|
year = int(year)
|
2017-07-14 16:25:59 +02:00
|
|
|
# hardcoded, if year only consists of 2 digits (e.g. 16 instead of 2016)
|
|
|
|
if year < 100:
|
2017-06-23 14:14:42 +02:00
|
|
|
year += 2000
|
2017-07-14 16:25:59 +02:00
|
|
|
datetime = '{}-{}-{}T{}'.format(year, month, day, time)
|
2017-06-23 14:14:42 +02:00
|
|
|
try:
|
|
|
|
datetime = UTCDateTime(datetime)
|
|
|
|
except Exception as e:
|
|
|
|
print(e, datetime, filename)
|
|
|
|
continue
|
|
|
|
for event in self.eventlist:
|
2017-07-18 15:27:52 +02:00
|
|
|
if eventID in str(event.resource_id) or 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)
|
|
|
|
for filename in os.listdir(datapath):
|
2017-06-23 14:56:56 +02:00
|
|
|
filename = os.path.join(datapath, filename)
|
|
|
|
if os.path.isfile(filename) and filename.endswith(fext):
|
2017-06-23 14:14:42 +02:00
|
|
|
try:
|
|
|
|
self.read_eventfile_info(filename)
|
|
|
|
except Exception as e:
|
|
|
|
print('Failed on reading eventfile info from file {}: {}'.format(filename, e))
|
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-06-14 16:22:26 +02:00
|
|
|
app.setOrganizationName("QtPyLoT");
|
|
|
|
app.setOrganizationDomain("rub.de");
|
|
|
|
app.setApplicationName("RUB");
|
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-07-14 16:25:59 +02:00
|
|
|
|
2017-05-29 11:31:09 +02:00
|
|
|
def main(args=None):
|
2017-05-30 16:09:48 +02:00
|
|
|
project_filename = None
|
|
|
|
pylot_infile = None
|
|
|
|
if args:
|
|
|
|
if args.project_filename:
|
|
|
|
project_filename = args.project_filename
|
|
|
|
if args.input_filename:
|
|
|
|
pylot_infile = args.input_filename
|
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
|
2017-05-30 16:09:48 +02:00
|
|
|
pylot_form = MainWindow(infile=pylot_infile)
|
2017-04-06 13:16:28 +02:00
|
|
|
icon = QIcon()
|
|
|
|
pylot_form.setWindowIcon(icon)
|
|
|
|
pylot_form.setIconSize(QSize(60, 60))
|
2017-07-14 16:25:59 +02:00
|
|
|
|
2015-09-18 09:54:29 +02:00
|
|
|
splash.showMessage('Loading. Please wait ...')
|
|
|
|
pylot_app.processEvents()
|
|
|
|
|
2014-03-28 22:26:15 +01:00
|
|
|
# set Application Information
|
2017-04-06 13:16:28 +02:00
|
|
|
pylot_app.setOrganizationName("Ruhr-University Bochum / BESTEC")
|
2014-03-28 22:26:15 +01:00
|
|
|
pylot_app.setOrganizationDomain("rub.de")
|
2015-09-18 09:54:29 +02:00
|
|
|
pylot_app.processEvents()
|
2014-03-28 22:26:15 +01:00
|
|
|
pylot_app.setApplicationName("PyLoT")
|
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
|
|
|
|
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)
|
2017-05-29 11:31:09 +02:00
|
|
|
args = parser.parse_args()
|
|
|
|
sys.exit(main(args))
|