[update]added class for pick qualities window

added QComboBox to pick qualities window to enable user to choose which events to analyze
This commit is contained in:
Jeldrik Gaal 2022-04-04 13:48:36 +02:00
parent aef67407c1
commit 1d5d346cb2
3 changed files with 80 additions and 11 deletions

View File

@ -60,7 +60,7 @@ except ImportError:
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from pylot.core.analysis.magnitude import LocalMagnitude, MomentMagnitude
from pylot.core.analysis.magnitude import LocalMagnitude, MomentMagnitude, calcsourcespec
from pylot.core.io.data import Data
from pylot.core.io.inputs import FilterOptions, PylotParameter
from autoPyLoT import autoPyLoT
@ -83,7 +83,7 @@ from pylot.core.io.location import create_creation_info, create_event
from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \
PylotCanvas, WaveformWidgetPG, PropertiesDlg, HelpForm, createAction, PickDlg, \
ComparisonWidget, TuneAutopicker, PylotParaBox, AutoPickDlg, CanvasWidget, AutoPickWidget, \
CompareEventsWidget, ProgressBarWidget, AddMetadataWidget, SingleTextLineDialog, LogWidget
CompareEventsWidget, ProgressBarWidget, AddMetadataWidget, SingleTextLineDialog, LogWidget, PickQualitiesFromXml
from pylot.core.util.array_map import Array_map
from pylot.core.util.structure import DATASTRUCTURE
from pylot.core.util.thread import Thread, Worker
@ -480,9 +480,9 @@ class MainWindow(QMainWindow):
"automatic pick "
"data.", False)
self.compare_action.setEnabled(False)
self.qualities_action = self.createAction(parent=self, text='Show pick qualitites...',
slot=self.pickQualities, shortcut='Alt+Q',
icon=qualities_icon, tip='Histogram of pick qualities')
self.qualities_action = self.createAction(self, 'Show pick qualitites...',
self.pickQualities, 'Alt+Q',
qualities_icon, 'Histogram of pick qualities')
self.qualities_action.setEnabled(False)
# MP MP not yet implemented, therefore hide:
# LK will be implemented soon, basic script has already (03/2021) been finished
@ -742,6 +742,9 @@ class MainWindow(QMainWindow):
self.setCentralWidget(_widget)
# Need to store PickQualities Window somewhere so it doesnt disappear
self.pickQualitiesWindow = None
def init_wfWidget(self):
xlab = self.startTime.strftime('seconds since %Y/%m/%d %H:%M:%S (%Z)')
plottitle = None # "Overview: {0} components ".format(self.getComponent())
@ -1670,8 +1673,10 @@ class MainWindow(QMainWindow):
def pickQualities(self):
path = self.get_current_event_path()
getQualitiesfromxml(path, self._inputs.get('timeerrorsP'), self._inputs.get('timeerrorsS'), plotflag=1)
return
(_, _, plot) = getQualitiesfromxml(path, self._inputs.get('timeerrorsP'), self._inputs.get('timeerrorsS'),plotflag=1)
self.pickQualitiesWindow = PickQualitiesFromXml(figure=plot, path=self.get_current_event_path(),inputVar=self._inputs)
self.pickQualitiesWindow.showUI()
return
def eventlistXml(self):
path = self._inputs['rootpath'] + '/' + self._inputs['datapath'] + '/' + self._inputs['database']
@ -3999,6 +4004,7 @@ def create_window():
def main(args=None):
project_filename = None
# args.project_filename = 'C:/Shared/AlpArray/alparray_data/project_alparray_test.plp'
# args.project_filename = 'E:/PyLoTProjects/project1.plp'
pylot_infile = None
if args:
if args.project_filename:

View File

@ -1055,7 +1055,7 @@ def merge_picks(event, picks):
return event
def getQualitiesfromxml(path, errorsP, errorsS, plotflag=1, figure=None, verbosity=0):
def getQualitiesfromxml(path, errorsP, errorsS, plotflag=1, figure=None, verbosity=0, xmlnames=[]):
"""
Script to get onset uncertainties from Quakeml.xml files created by PyLoT.
Uncertainties are tranformed into quality classes and visualized via histogram if desired.
@ -1092,7 +1092,8 @@ def getQualitiesfromxml(path, errorsP, errorsS, plotflag=1, figure=None, verbosi
return plot_list, numWeights
# get all xmlfiles in path (maybe this should be changed to one xml file for this function, selectable via GUI?)
xmlnames = glob.glob(os.path.join(path, '*.xml'))
if not xmlnames:
xmlnames = glob.glob(os.path.join(os.path.dirname(path) + "/*/", '*.xml'))
if len(xmlnames) == 0:
print(f'No files found in path {path}.')
return False
@ -1173,6 +1174,7 @@ def getQualitiesfromxml(path, errorsP, errorsS, plotflag=1, figure=None, verbosi
ax.set_title('{0} P-Qualities, {1} S-Qualities'.format(numPweights, numSweights))
if not figure:
fig.show()
#fig.show()
pass
return listP, listS
return listP, listS, fig

View File

@ -8,6 +8,7 @@ Created on Wed Mar 19 11:27:35 2014
import copy
import datetime
import getpass
import glob
import multiprocessing
import os
import subprocess
@ -18,6 +19,8 @@ import traceback
import matplotlib
import numpy as np
from pylot.core.io.phases import getQualitiesfromxml
matplotlib.use('QT5Agg')
from matplotlib.figure import Figure
@ -5556,6 +5559,64 @@ class HelpForm(QDialog):
self.pageLabel.setText(self.webBrowser.title())
class PickQualitiesFromXml(QWidget):
"""
PyLoT widget PickQualitiesFromXml is a QWidget object. It is an UI that enables the user
to create a plot showing the pick qualities in the event selected inside the QComboBox created
by this Widget. The user can also choose to select all Events.
The plot is being shown by a FigureCanvas from matlplotlib.
"""
def __init__(self, parent=None, figure=Figure(), path="", inputVar=None):
super(PickQualitiesFromXml, self).__init__(parent)
self.setWindowTitle("Get pick qualities from xml files")
self.fig = figure
self.chooseBox = QComboBox()
self.path = path
self.inputs = inputVar
self.setupUi()
def setupUi(self):
self.main_layout = QtWidgets.QVBoxLayout()
self.figureC = FigureCanvas(self.fig)
self.chooseBox = self.createComboBox()
if self.chooseBox: self.main_layout.addWidget(self.chooseBox)
self.main_layout.addWidget(self.figureC)
self.setLayout(self.main_layout)
def showUI(self):
self.show()
# Creates a QComboBox and adds all events in the current folder as options. Also gives the option to choose all events
def createComboBox(self):
self.chooseBox.addItems(glob.glob(os.path.join(os.path.dirname(self.path) + "/*/", '*.xml')))
self.chooseBox.addItem("All")
self.chooseBox.currentIndexChanged.connect(self.selectionChanged)
self.chooseBox.setCurrentIndex(self.chooseBox.count() - 1)
return self.chooseBox
# Function that gets called when the user changes the current selection in the QComboBox. Redraws the plot with the new data
def selectionChanged(self):
self.figureC.setParent(None)
if self.chooseBox.currentIndex() == self.chooseBox.count() - 1:
(_, _, plot) = getQualitiesfromxml(self.path, self.inputs.get('timeerrorsP'),
self.inputs.get('timeerrorsS'), plotflag=1)
self.figureC = FigureCanvas(plot)
else:
(_, _, plot) = getQualitiesfromxml(self.path, self.inputs.get('timeerrorsP'),
self.inputs.get('timeerrorsS'), plotflag=1,
xmlnames=[self.chooseBox.currentText()])
self.figureC = FigureCanvas(plot)
self.figureC.draw()
self.main_layout.addWidget(self.figureC)
self.setLayout(self.main_layout)
if __name__ == '__main__':
import doctest