[bugfix] origins object will be created independent to notes.txt,

[update] pycharm code restructuring (accidently)
This commit is contained in:
Marcel Paffrath 2017-07-14 16:25:59 +02:00
parent a017c4deb4
commit 897b915eff

View File

@ -25,6 +25,7 @@ https://www.iconfinder.com/iconsets/flavour
import os import os
import sys import sys
import platform
import argparse import argparse
import matplotlib import matplotlib
@ -41,7 +42,7 @@ from PySide.QtGui import QMainWindow, QInputDialog, QIcon, QFileDialog, \
QTreeView, QComboBox, QTabWidget, QPushButton, QGridLayout QTreeView, QComboBox, QTabWidget, QPushButton, QGridLayout
import numpy as np import numpy as np
from obspy import UTCDateTime from obspy import UTCDateTime
from obspy.core.event import Magnitude from obspy.core.event import Magnitude, Origin
from obspy.core.util import AttribDict from obspy.core.util import AttribDict
try: try:
@ -82,6 +83,7 @@ from pylot.core.util.map_projection import map_projection
from pylot.core.util.structure import DATASTRUCTURE from pylot.core.util.structure import DATASTRUCTURE
from pylot.core.util.thread import AutoPickThread, Thread from pylot.core.util.thread import AutoPickThread, Thread
from pylot.core.util.version import get_git_version as _getVersionString from pylot.core.util.version import get_git_version as _getVersionString
if sys.version_info.major == 3: if sys.version_info.major == 3:
import icons_rc_3 as icons_rc import icons_rc_3 as icons_rc
elif sys.version_info.major == 2: elif sys.version_info.major == 2:
@ -103,7 +105,7 @@ class MainWindow(QMainWindow):
if not infile: if not infile:
infile = os.path.join(os.path.expanduser('~'), '.pylot', 'pylot.in') infile = os.path.join(os.path.expanduser('~'), '.pylot', 'pylot.in')
print('Using default input file {}'.format(infile)) print('Using default input file {}'.format(infile))
if os.path.isfile(infile)== False: if os.path.isfile(infile) == False:
infile = QFileDialog().getOpenFileName(caption='Choose PyLoT-input file') infile = QFileDialog().getOpenFileName(caption='Choose PyLoT-input file')
if not os.path.exists(infile[0]): if not os.path.exists(infile[0]):
QMessageBox.warning(self, "PyLoT Warning", QMessageBox.warning(self, "PyLoT Warning",
@ -225,7 +227,7 @@ class MainWindow(QMainWindow):
self._event_layout.addWidget(self.eventBox) self._event_layout.addWidget(self.eventBox)
self._event_layout.addWidget(self.ref_event_button) self._event_layout.addWidget(self.ref_event_button)
self._event_layout.addWidget(self.test_event_button) self._event_layout.addWidget(self.test_event_button)
self._event_layout.setStretch(1,1) #set stretch of item 1 to 1 self._event_layout.setStretch(1, 1) # set stretch of item 1 to 1
self._main_layout.addLayout(self._event_layout) self._main_layout.addLayout(self._event_layout)
self.eventBox.activated.connect(self.refreshEvents) self.eventBox.activated.connect(self.refreshEvents)
@ -254,7 +256,7 @@ class MainWindow(QMainWindow):
array_tab.setLayout(self.array_layout) array_tab.setLayout(self.array_layout)
events_tab.setLayout(self.events_layout) events_tab.setLayout(self.events_layout)
#add tabs to main tab widget # add tabs to main tab widget
self.tabs.addTab(wf_tab, 'Waveform Plot') self.tabs.addTab(wf_tab, 'Waveform Plot')
self.tabs.addTab(array_tab, 'Array Map') self.tabs.addTab(array_tab, 'Array Map')
self.tabs.addTab(events_tab, 'Eventlist') self.tabs.addTab(events_tab, 'Eventlist')
@ -557,7 +559,7 @@ class MainWindow(QMainWindow):
def init_wfWidget(self): def init_wfWidget(self):
settings = QSettings() settings = QSettings()
xlab = self.startTime.strftime('seconds since %Y/%m/%d %H:%M:%S (%Z)') xlab = self.startTime.strftime('seconds since %Y/%m/%d %H:%M:%S (%Z)')
plottitle = None#"Overview: {0} components ".format(self.getComponent()) plottitle = None # "Overview: {0} components ".format(self.getComponent())
self.disconnectWFplotEvents() self.disconnectWFplotEvents()
if str(settings.value('pyqtgraphic')) == 'false' or not pg: if str(settings.value('pyqtgraphic')) == 'false' or not pg:
self.pg = False self.pg = False
@ -578,9 +580,9 @@ class MainWindow(QMainWindow):
''' '''
self.ref_event_button = QtGui.QPushButton('Ref') self.ref_event_button = QtGui.QPushButton('Ref')
self.test_event_button = QtGui.QPushButton('Test') self.test_event_button = QtGui.QPushButton('Test')
self.ref_event_button.setToolTip('Set manual picks of current '+ self.ref_event_button.setToolTip('Set manual picks of current ' +
'event as reference picks for autopicker tuning.') 'event as reference picks for autopicker tuning.')
self.test_event_button.setToolTip('Set manual picks of current '+ self.test_event_button.setToolTip('Set manual picks of current ' +
'event as test picks for autopicker testing.') 'event as test picks for autopicker testing.')
self.ref_event_button.setCheckable(True) self.ref_event_button.setCheckable(True)
self.test_event_button.setCheckable(True) self.test_event_button.setCheckable(True)
@ -607,12 +609,10 @@ class MainWindow(QMainWindow):
def metadata(self): def metadata(self):
return self._metadata return self._metadata
@metadata.setter @metadata.setter
def metadata(self, value): def metadata(self, value):
self._metadata = value self._metadata = value
def updateFileMenu(self): def updateFileMenu(self):
self.fileMenu.clear() self.fileMenu.clear()
@ -684,16 +684,16 @@ class MainWindow(QMainWindow):
def load_multiple_data(self, type='manual'): def load_multiple_data(self, type='manual'):
if not self.okToContinue(): if not self.okToContinue():
return return
refresh=False refresh = False
events = self.project.eventlist events = self.project.eventlist
fext = '.xml' fext = '.xml'
for event in events: for event in events:
path = event.path path = event.path
eventname = path.split('/')[-1] eventname = path.split('/')[-1]
filename = os.path.join(path, 'PyLoT_'+eventname+fext) filename = os.path.join(path, 'PyLoT_' + eventname + fext)
if os.path.isfile(filename): if os.path.isfile(filename):
self.load_data(filename, draw=False, event=event, overwrite=True) self.load_data(filename, draw=False, event=event, overwrite=True)
refresh=True refresh = True
if not refresh: if not refresh:
return return
if self.get_current_event().pylot_picks: if self.get_current_event().pylot_picks:
@ -711,7 +711,7 @@ class MainWindow(QMainWindow):
if not fname: if not fname:
return return
self.set_fname(fname, type) self.set_fname(fname, type)
#data = dict(auto=self.autodata, manual=self.data) # data = dict(auto=self.autodata, manual=self.data)
if not event: if not event:
event = self.get_current_event() event = self.get_current_event()
data = Data(self, event) data = Data(self, event)
@ -745,7 +745,7 @@ class MainWindow(QMainWindow):
def add_recentfile(self, event): def add_recentfile(self, event):
self.recentfiles.insert(0, event) self.recentfiles.insert(0, event)
def set_button_color(self, button, color = None): def set_button_color(self, button, color=None):
''' '''
Set background color of a button. Set background color of a button.
button: type = QtGui.QAbstractButton button: type = QtGui.QAbstractButton
@ -859,13 +859,23 @@ class MainWindow(QMainWindow):
print('No project found.') print('No project found.')
return return
#get path from first event in list and split them # get path from first event in list and split them
path = eventlist[0] path = eventlist[0]
try: try:
system_name = platform.system()
if system_name in ["Linux", "Darwin"]:
dirs = { dirs = {
'database': path.split('/')[-2], 'database': path.split('/')[-2],
'datapath': path.split('/')[-3], 'datapath': path.split('/')[-3],
'rootpath': '/'+os.path.join(*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)
} }
except Exception as e: except Exception as e:
dirs = { dirs = {
@ -880,15 +890,15 @@ class MainWindow(QMainWindow):
settings.sync() settings.sync()
if not self.project.eventlist: if not self.project.eventlist:
#init parameter object # init parameter object
self.setParameter(show=False) self.setParameter(show=False)
#hide all parameter (show all needed parameter later) # hide all parameter (show all needed parameter later)
self.paraBox.hide_parameter() self.paraBox.hide_parameter()
for directory in dirs.keys(): for directory in dirs.keys():
#set parameter # set parameter
box = self.paraBox.boxes[directory] box = self.paraBox.boxes[directory]
self.paraBox.setValue(box, dirs[directory]) self.paraBox.setValue(box, dirs[directory])
#show needed parameter in box # show needed parameter in box
self.paraBox.show_parameter(directory) self.paraBox.show_parameter(directory)
dirs_box = self.paraBox.get_groupbox_dialog('Directories') dirs_box = self.paraBox.get_groupbox_dialog('Directories')
if not dirs_box.exec_(): if not dirs_box.exec_():
@ -948,8 +958,8 @@ class MainWindow(QMainWindow):
''' '''
if not eventBox: if not eventBox:
eventBox = self.eventBox eventBox = self.eventBox
index=eventBox.currentIndex() index = eventBox.currentIndex()
tv=QtGui.QTableView() tv = QtGui.QTableView()
header = tv.horizontalHeader() header = tv.horizontalHeader()
header.setResizeMode(QtGui.QHeaderView.ResizeToContents) header.setResizeMode(QtGui.QHeaderView.ResizeToContents)
header.setStretchLastSection(True) header.setStretchLastSection(True)
@ -960,12 +970,12 @@ class MainWindow(QMainWindow):
eventBox.setView(tv) eventBox.setView(tv)
eventBox.clear() eventBox.clear()
model = eventBox.model() model = eventBox.model()
plmax=0 plmax = 0
#set maximum length of path string # set maximum length of path string
for event in self.project.eventlist: for event in self.project.eventlist:
pl = len(event.path) pl = len(event.path)
if pl > plmax: if pl > plmax:
plmax=pl plmax = pl
for id, event in enumerate(self.project.eventlist): for id, event in enumerate(self.project.eventlist):
event_path = event.path event_path = event.path
@ -989,8 +999,8 @@ class MainWindow(QMainWindow):
item_nmp.setIcon(self.manupicksicon_small) item_nmp.setIcon(self.manupicksicon_small)
item_nap = QtGui.QStandardItem(str(event_nautopicks)) item_nap = QtGui.QStandardItem(str(event_nautopicks))
item_nap.setIcon(self.autopicksicon_small) item_nap.setIcon(self.autopicksicon_small)
item_ref = QtGui.QStandardItem()#str(event_ref)) item_ref = QtGui.QStandardItem() # str(event_ref))
item_test = QtGui.QStandardItem()#str(event_test)) item_test = QtGui.QStandardItem() # str(event_test))
if event_ref: if event_ref:
item_ref.setBackground(self._colors['ref']) item_ref.setBackground(self._colors['ref'])
if event_test: if event_test:
@ -1020,8 +1030,8 @@ class MainWindow(QMainWindow):
'{} unequal {}.' '{} unequal {}.'
.format(event.path, self.eventBox.itemText(id))) .format(event.path, self.eventBox.itemText(id)))
raise ValueError(message) raise ValueError(message)
#not working with obspy events # not working with obspy events
#eventBox.setItemData(id, event) # eventBox.setItemData(id, event)
eventBox.setCurrentIndex(index) eventBox.setCurrentIndex(index)
self.refreshRefTestButtons() self.refreshRefTestButtons()
@ -1061,20 +1071,20 @@ class MainWindow(QMainWindow):
else: else:
dlgflag = 0 dlgflag = 0
eventname = self.get_current_event_name() eventname = self.get_current_event_name()
filename = 'PyLoT_'+eventname filename = 'PyLoT_' + eventname
outpath = os.path.join(directory, filename) outpath = os.path.join(directory, filename)
title = 'Save pick data ...' title = 'Save pick data ...'
#if not outformat: # if not outformat:
# outformat = settings.value('output/Format') # outformat = settings.value('output/Format')
# outformat = outformat[0:4] # outformat = outformat[0:4]
#else: # else:
# selected_filter = "NonLinLoc observation file (*.obs)" # selected_filter = "NonLinLoc observation file (*.obs)"
# fname = outpath # fname = outpath
#if outformat == '.obs': # if outformat == '.obs':
# file_filter = "NonLinLoc observation file (*.obs)" # file_filter = "NonLinLoc observation file (*.obs)"
#elif outformat == '.cnv': # elif outformat == '.cnv':
# file_filter = "VELEST observation file format (*.cnv)" # file_filter = "VELEST observation file format (*.cnv)"
#elif outformat == '.xml': # elif outformat == '.xml':
file_filter = "(*.xml *.obs *.cnv)" file_filter = "(*.xml *.obs *.cnv)"
if dlgflag == 1: if dlgflag == 1:
@ -1083,10 +1093,10 @@ class MainWindow(QMainWindow):
outpath, outpath,
file_filter) file_filter)
#fbasename, exform = os.path.splitext(fname) # fbasename, exform = os.path.splitext(fname)
fbasename = fname fbasename = fname
exform = ['.obs', '.xml', '.cnv'] exform = ['.obs', '.xml', '.cnv']
#if not exform and selected_filter or not exform in OUTPUTFORMATS: # if not exform and selected_filter or not exform in OUTPUTFORMATS:
# exform = selected_filter.split('*')[1][:-1] # exform = selected_filter.split('*')[1][:-1]
# return fname, exform # return fname, exform
return fbasename, exform return fbasename, exform
@ -1099,7 +1109,7 @@ class MainWindow(QMainWindow):
uppererrorS = self._inputs['timeerrorsS'] uppererrorS = self._inputs['timeerrorsS']
try: try:
self.get_data().applyEVTData(self.get_current_event(), typ='event')#getPicks()) self.get_data().applyEVTData(self.get_current_event(), typ='event') # getPicks())
except OverwriteError: except OverwriteError:
# msgBox = QMessageBox() # msgBox = QMessageBox()
# msgBox.setText("Picks have been modified!") # msgBox.setText("Picks have been modified!")
@ -1138,10 +1148,10 @@ class MainWindow(QMainWindow):
# return False # return False
# export to given path # export to given path
#self.get_data().exportEvent(fbasename, exform, upperErrors=[uppererrorP[3], uppererrorS[3]]) # self.get_data().exportEvent(fbasename, exform, upperErrors=[uppererrorP[3], uppererrorS[3]])
self.get_data().exportEvent(fbasename, exform[0], upperErrors=[uppererrorP[3], uppererrorS[3]]) self.get_data().exportEvent(fbasename, exform[0], upperErrors=[uppererrorP[3], uppererrorS[3]])
self.get_data().exportEvent(fbasename, exform[1], upperErrors=[uppererrorP[3], uppererrorS[3]]) self.get_data().exportEvent(fbasename, exform[1], upperErrors=[uppererrorP[3], uppererrorS[3]])
#self.get_data().exportEvent(fbasename, exform[2], upperErrors=[uppererrorP[3], uppererrorS[3]]) # self.get_data().exportEvent(fbasename, exform[2], upperErrors=[uppererrorP[3], uppererrorS[3]])
# all files save (ui clean) # all files save (ui clean)
self.update_status('Picks saved as %s, %s, and %s' % (fbasename + exform[0], fbasename + exform[1], self.update_status('Picks saved as %s, %s, and %s' % (fbasename + exform[0], fbasename + exform[1],
fbasename + exform[2])) fbasename + exform[2]))
@ -1222,7 +1232,8 @@ class MainWindow(QMainWindow):
def okToContinue(self): def okToContinue(self):
if self.dirty: if self.dirty:
qmb = QMessageBox(self, icon=QMessageBox.Question, text='Do you wish to save changes in the current project?') qmb = QMessageBox(self, icon=QMessageBox.Question,
text='Do you wish to save changes in the current project?')
qmb.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel) qmb.setStandardButtons(QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel)
qmb.setDefaultButton(QMessageBox.Save) qmb.setDefaultButton(QMessageBox.Save)
ret = qmb.exec_() ret = qmb.exec_()
@ -1299,7 +1310,7 @@ class MainWindow(QMainWindow):
# Loading an existing project from array_tab leads to two calls of newWF # 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 # which will read in data input twice. Therefore current tab is changed to 0
# in loadProject before calling this function. # in loadProject before calling this function.
plotted=False plotted = False
# only refresh first/second tab when an event was changed. # only refresh first/second tab when an event was changed.
if self._eventChanged[0] or self._eventChanged[1]: if self._eventChanged[0] or self._eventChanged[1]:
event = self.get_current_event() event = self.get_current_event()
@ -1321,7 +1332,7 @@ class MainWindow(QMainWindow):
if len(self.project.eventlist) > 0: if len(self.project.eventlist) > 0:
self.newWF() self.newWF()
# keep track whether event was already plotted # keep track whether event was already plotted
plotted=True plotted = True
# if current tab is array_map-tab and the data in this tab was not yet refreshed # if current tab is array_map-tab and the data in this tab was not yet refreshed
if self.tabs.currentIndex() == 1: if self.tabs.currentIndex() == 1:
if self._eventChanged[1]: if self._eventChanged[1]:
@ -1442,7 +1453,7 @@ class MainWindow(QMainWindow):
plotWidget = self.getPlotWidget() plotWidget = self.getPlotWidget()
plotDict = plotWidget.getPlotDict() plotDict = plotWidget.getPlotDict()
pos = plotDict.keys() pos = plotDict.keys()
labels = [plotDict[n][2]+'.'+plotDict[n][0] for n in pos] labels = [plotDict[n][2] + '.' + plotDict[n][0] for n in pos]
plotWidget.setYTickLabels(pos, labels) plotWidget.setYTickLabels(pos, labels)
try: try:
plotWidget.figure.tight_layout() plotWidget.figure.tight_layout()
@ -1516,13 +1527,14 @@ class MainWindow(QMainWindow):
# wfst += self.get_data().getWFData().select(component=alter_comp) # wfst += self.get_data().getWFData().select(component=alter_comp)
plotWidget = self.getPlotWidget() plotWidget = self.getPlotWidget()
self.adjustPlotHeight() self.adjustPlotHeight()
plots = plotWidget.plotWFData(wfdata=wfst, title=title, mapping=False, component=comp, nth_sample=int(nth_sample)) plots = plotWidget.plotWFData(wfdata=wfst, title=title, mapping=False, component=comp,
nth_sample=int(nth_sample))
return plots return plots
def adjustPlotHeight(self): def adjustPlotHeight(self):
if self.pg: if self.pg:
return return
height_need = len(self.data.getWFData())*self.height_factor height_need = len(self.data.getWFData()) * self.height_factor
plotWidget = self.getPlotWidget() plotWidget = self.getPlotWidget()
if self.tabs.widget(0).frameSize().height() < height_need: if self.tabs.widget(0).frameSize().height() < height_need:
plotWidget.setMinimumHeight(height_need) plotWidget.setMinimumHeight(height_need)
@ -1598,7 +1610,7 @@ class MainWindow(QMainWindow):
def getFilters(self): def getFilters(self):
return self.filteroptions return self.filteroptions
def setFilterOptions(self, filterOptions):#, seismicPhase=None): def setFilterOptions(self, filterOptions): # , seismicPhase=None):
# if seismicPhase is None: # if seismicPhase is None:
# self.getFilterOptions()[self.getSeismicPhase()] = filterOptions # self.getFilterOptions()[self.getSeismicPhase()] = filterOptions
# else: # else:
@ -1691,12 +1703,12 @@ class MainWindow(QMainWindow):
if vbar.maximum(): if vbar.maximum():
vbar.setValue(vbar.value() + up_down[button]) vbar.setValue(vbar.value() + up_down[button])
if self._ctrl: if self._ctrl:
factor = {'up': 5./4., factor = {'up': 5. / 4.,
'down': 4./5.} 'down': 4. / 5.}
self.height_factor *= factor[button] self.height_factor *= factor[button]
self.adjustPlotHeight() self.adjustPlotHeight()
if self._shift: if self._shift:
factor = {'up': 1./2., factor = {'up': 1. / 2.,
'down': 2.} 'down': 2.}
xlims = self.dataPlot.getXLims() xlims = self.dataPlot.getXLims()
xdiff = xlims[1] - xlims[0] xdiff = xlims[1] - xlims[0]
@ -1839,7 +1851,7 @@ class MainWindow(QMainWindow):
receventid = self.get_current_event_path() receventid = self.get_current_event_path()
self.thread = AutoPickThread(parent=self, self.thread = AutoPickThread(parent=self,
func=autoPyLoT, func=autoPyLoT,
infile = self.infile, infile=self.infile,
fnames=self.fnames, fnames=self.fnames,
eventid=receventid, eventid=receventid,
savepath=self.autosave) savepath=self.autosave)
@ -1858,7 +1870,7 @@ class MainWindow(QMainWindow):
if not stat_picks: if not stat_picks:
rval = False rval = False
else: else:
#set picks (ugly syntax?) # set picks (ugly syntax?)
self.getPicks(type=type)[station] = picks self.getPicks(type=type)[station] = picks
rval = True rval = True
return rval return rval
@ -1917,8 +1929,10 @@ class MainWindow(QMainWindow):
dashed = QtCore.Qt.DashLine dashed = QtCore.Qt.DashLine
dotted = QtCore.Qt.DotLine dotted = QtCore.Qt.DotLine
phase_col = { phase_col = {
'P': (pg.mkPen('c'), pg.mkPen((0, 255, 255, 100), style=dashed), pg.mkPen('b', style=dashed), pg.mkPen('b', style=dotted)), 'P': (pg.mkPen('c'), pg.mkPen((0, 255, 255, 100), style=dashed), pg.mkPen('b', style=dashed),
'S': (pg.mkPen('m'), pg.mkPen((255, 0, 255, 100), style=dashed), pg.mkPen('r', style=dashed), pg.mkPen('r', style=dotted)) 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))
} }
else: else:
phase_col = { phase_col = {
@ -1956,7 +1970,8 @@ class MainWindow(QMainWindow):
pw.plot([lpp, lpp], ylims, pw.plot([lpp, lpp], ylims,
alpha=.25, pen=colors[0], name='LPP') alpha=.25, pen=colors[0], name='LPP')
if spe: if spe:
spe_l = pg.PlotDataItem([mpp - spe, mpp - spe], ylims, pen=colors[1], name='{}-SPE'.format(phase)) spe_l = pg.PlotDataItem([mpp - spe, mpp - spe], ylims, pen=colors[1],
name='{}-SPE'.format(phase))
spe_r = pg.PlotDataItem([mpp + spe, mpp + spe], ylims, pen=colors[1]) spe_r = pg.PlotDataItem([mpp + spe, mpp + spe], ylims, pen=colors[1])
pw.addItem(spe_l) pw.addItem(spe_l)
pw.addItem(spe_r) pw.addItem(spe_r)
@ -2040,7 +2055,7 @@ class MainWindow(QMainWindow):
obsdir = os.path.join(locroot, 'obs') obsdir = os.path.join(locroot, 'obs')
self.saveData(directory=obsdir, outformat='.obs') self.saveData(directory=obsdir, outformat='.obs')
eventname = self.get_current_event_name() eventname = self.get_current_event_name()
filename = 'PyLoT_'+eventname filename = 'PyLoT_' + eventname
locpath = os.path.join(locroot, 'loc', filename) locpath = os.path.join(locroot, 'loc', filename)
phasefile = os.path.join(obsdir, filename + '.obs') phasefile = os.path.join(obsdir, filename + '.obs')
phasepath = os.path.join(locroot, 'obs', phasefile) phasepath = os.path.join(locroot, 'obs', phasefile)
@ -2053,7 +2068,7 @@ class MainWindow(QMainWindow):
os.remove(phasepath) os.remove(phasepath)
self.get_data().applyEVTData(lt.read_location(locpath), typ='event') self.get_data().applyEVTData(lt.read_location(locpath), typ='event')
#self.get_data().applyEVTData(self.calc_magnitude(), typ='event') # self.get_data().applyEVTData(self.calc_magnitude(), typ='event')
def init_array_tab(self): def init_array_tab(self):
''' '''
@ -2108,7 +2123,7 @@ class MainWindow(QMainWindow):
self.am_canvas = FigureCanvas(self.am_figure) self.am_canvas = FigureCanvas(self.am_figure)
self.am_toolbar = NavigationToolbar(self.am_canvas, self) self.am_toolbar = NavigationToolbar(self.am_canvas, self)
self.array_map = map_projection(self) self.array_map = map_projection(self)
#self.array_map_thread() # self.array_map_thread()
self.array_layout.addWidget(self.array_map) self.array_layout.addWidget(self.array_map)
self.tabs.setCurrentIndex(index) self.tabs.setCurrentIndex(index)
self.refresh_array_map() self.refresh_array_map()
@ -2128,8 +2143,8 @@ class MainWindow(QMainWindow):
''' '''
self.array_map = self.amt.data self.array_map = self.amt.data
self.array_layout.addWidget(self.array_map) self.array_layout.addWidget(self.array_map)
#self.tabs.setCurrentIndex(index) # self.tabs.setCurrentIndex(index)
#self.refresh_array_map() # self.refresh_array_map()
def refresh_array_map(self): def refresh_array_map(self):
''' '''
@ -2151,6 +2166,7 @@ class MainWindow(QMainWindow):
''' '''
Build and initiate event table (3rd tab [index=2]) containing information of every event. Build and initiate event table (3rd tab [index=2]) containing information of every event.
''' '''
def set_enabled(item, enabled=True, checkable=False): def set_enabled(item, enabled=True, checkable=False):
# modify item flags depending on case needed # modify item flags depending on case needed
if enabled and not checkable: if enabled and not checkable:
@ -2171,7 +2187,7 @@ class MainWindow(QMainWindow):
table = self.project._table table = self.project._table
event = self.project.getEventFromPath(table[row][0].text()) event = self.project.getEventFromPath(table[row][0].text())
if column == 8 or column == 9: if column == 8 or column == 9:
#toggle checked states (exclusive) # toggle checked states (exclusive)
item_ref = table[row][8] item_ref = table[row][8]
item_test = table[row][9] item_test = table[row][9]
if column == 8 and item_ref.checkState(): if column == 8 and item_ref.checkState():
@ -2186,7 +2202,7 @@ class MainWindow(QMainWindow):
event.setTestEvent(False) event.setTestEvent(False)
self.fill_eventbox() self.fill_eventbox()
elif column == 5: elif column == 5:
#update event notes # update event notes
notes = table[row][5].text() notes = table[row][5].text()
event.addNotes(notes) event.addNotes(notes)
self.fill_eventbox() self.fill_eventbox()
@ -2270,7 +2286,7 @@ class MainWindow(QMainWindow):
else: else:
item_test.setCheckState(QtCore.Qt.Unchecked) item_test.setCheckState(QtCore.Qt.Unchecked)
column=[item_path, item_time, item_lat, item_lon, item_depth, item_mag, column = [item_path, item_time, item_lat, item_lon, item_depth, item_mag,
item_nmp, item_nap, item_ref, item_test, item_notes] item_nmp, item_nap, item_ref, item_test, item_notes]
self.project._table.append(column) self.project._table.append(column)
@ -2352,10 +2368,12 @@ class MainWindow(QMainWindow):
# if not rest_flag: # if not rest_flag:
# raise ProcessingError('Restitution of waveform data failed!') # raise ProcessingError('Restitution of waveform data failed!')
if type == 'ML': if type == 'ML':
local_mag = LocalMagnitude(corr_wf, self.get_data().get_evt_data(), self.inputs.get('sstop'), verbosity = True) local_mag = LocalMagnitude(corr_wf, self.get_data().get_evt_data(), self.inputs.get('sstop'),
verbosity=True)
return local_mag.updated_event() return local_mag.updated_event()
elif type == 'Mw': elif type == 'Mw':
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) 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)
return moment_mag.updated_event() return moment_mag.updated_event()
else: else:
return None return None
@ -2435,7 +2453,7 @@ class MainWindow(QMainWindow):
self.project = Project() self.project = Project()
self.init_events(new=True) self.init_events(new=True)
self.setDirty(False) self.setDirty(False)
self.project.parameter=self._inputs self.project.parameter = self._inputs
self.saveProjectAsAction.setEnabled(True) self.saveProjectAsAction.setEnabled(True)
self.update_status('Created new project...', duration=1000) self.update_status('Created new project...', duration=1000)
return True return True
@ -2477,7 +2495,7 @@ class MainWindow(QMainWindow):
return False return False
if not filename.split('.')[-1] == 'plp': if not filename.split('.')[-1] == 'plp':
filename = fnm[0] + '.plp' filename = fnm[0] + '.plp'
self.project.parameter=self._inputs self.project.parameter = self._inputs
self.project.save(filename) self.project.save(filename)
self.setDirty(False) self.setDirty(False)
self.saveProjectAsAction.setEnabled(True) self.saveProjectAsAction.setEnabled(True)
@ -2494,7 +2512,7 @@ class MainWindow(QMainWindow):
self.setDirty(True) self.setDirty(True)
return False return False
else: else:
self.project.parameter=self._inputs self.project.parameter = self._inputs
self.project.save() self.project.save()
if not self.project.dirty: if not self.project.dirty:
self.update_status('Saved back project to file:\n{}'.format(self.project.location), duration=5000) self.update_status('Saved back project to file:\n{}'.format(self.project.location), duration=5000)
@ -2502,7 +2520,7 @@ class MainWindow(QMainWindow):
return True return True
else: else:
# if still dirty because saving failed # if still dirty because saving failed
qmb = QMessageBox.warning(self,'Could not save project', qmb = QMessageBox.warning(self, 'Could not save project',
'Could not save back to original file.\nChoose new file') 'Could not save back to original file.\nChoose new file')
self.setDirty(True) self.setDirty(True)
return self.saveProjectAs(exists=True) return self.saveProjectAs(exists=True)
@ -2558,6 +2576,7 @@ class Project(object):
''' '''
Pickable class containing information of a QtPyLoT project, like event lists and file locations. Pickable class containing information of a QtPyLoT project, like event lists and file locations.
''' '''
def __init__(self): def __init__(self):
self.eventlist = [] self.eventlist = []
self.location = None self.location = None
@ -2583,7 +2602,7 @@ class Project(object):
self.setDirty() self.setDirty()
else: else:
print('Skipping event with path {}. Already part of project.'.format(event.path)) print('Skipping event with path {}. Already part of project.'.format(event.path))
#self.search_eventfile_info() self.search_eventfile_info()
def read_eventfile_info(self, filename, separator=','): def read_eventfile_info(self, filename, separator=','):
''' '''
@ -2594,14 +2613,14 @@ class Project(object):
infile = open(filename, 'r') infile = open(filename, 'r')
for line in infile.readlines(): for line in infile.readlines():
event, date, time, mag, lat, lon, depth = line.split(separator)[:7] event, date, time, mag, lat, lon, depth = line.split(separator)[:7]
#skip first line # skip first line
try: try:
month, day, year = date.split('/') month, day, year = date.split('/')
except: except:
continue continue
year = int(year) year = int(year)
#hardcoded, if year only consists of 2 digits (e.g. 16 instead of 2016) # hardcoded, if year only consists of 2 digits (e.g. 16 instead of 2016)
if year<100: if year < 100:
year += 2000 year += 2000
datetime = '{}-{}-{}T{}'.format(year, month, day, time) datetime = '{}-{}-{}T{}'.format(year, month, day, time)
try: try:
@ -2610,13 +2629,17 @@ class Project(object):
print(e, datetime, filename) print(e, datetime, filename)
continue continue
for event in self.eventlist: for event in self.eventlist:
if not event.origins: if event.origins:
continue origin = event.origins[0] # should have only one origin
origin = event.origins[0] #should have only one origin
if origin.time == datetime: if origin.time == datetime:
origin.latitude = float(lat) origin.latitude = float(lat)
origin.longitude = float(lon) origin.longitude = float(lon)
origin.depth = float(depth) origin.depth = float(depth)
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, event.magnitudes.append(Magnitude(resource_id=event.resource_id,
mag=float(mag), mag=float(mag),
mag_type='M')) mag_type='M'))
@ -2627,7 +2650,7 @@ class Project(object):
and try to read event info from it and try to read event info from it
''' '''
datapaths = [] datapaths = []
fext='.csv' fext = '.csv'
for event in self.eventlist: for event in self.eventlist:
if not event.datapath in datapaths: if not event.datapath in datapaths:
datapaths.append(event.datapath) datapaths.append(event.datapath)
@ -2704,6 +2727,7 @@ class getExistingDirectories(QFileDialog):
''' '''
File dialog with possibility to select multiple folders. File dialog with possibility to select multiple folders.
''' '''
def __init__(self, *args): def __init__(self, *args):
super(getExistingDirectories, self).__init__(*args) super(getExistingDirectories, self).__init__(*args)
self.setOption(self.DontUseNativeDialog, True) self.setOption(self.DontUseNativeDialog, True)
@ -2717,7 +2741,7 @@ class getExistingDirectories(QFileDialog):
def create_window(): def create_window():
app_created = False app_created = False
app = QCoreApplication.instance() app = QCoreApplication.instance()
#check for existing app (when using ipython) # check for existing app (when using ipython)
if app is None: if app is None:
app = QApplication(sys.argv) app = QApplication(sys.argv)
app_created = True app_created = True
@ -2725,8 +2749,8 @@ def create_window():
app.setOrganizationDomain("rub.de"); app.setOrganizationDomain("rub.de");
app.setApplicationName("RUB"); app.setApplicationName("RUB");
app.references = set() app.references = set()
#app.references.add(window) # app.references.add(window)
#window.show() # window.show()
return app, app_created return app, app_created
@ -2741,7 +2765,7 @@ def main(args=None):
# create the Qt application # create the Qt application
pylot_app, app_created = create_window() pylot_app, app_created = create_window()
#pylot_app = QApplication(sys.argv) # pylot_app = QApplication(sys.argv)
pixmap = QPixmap(":/splash/splash.png") pixmap = QPixmap(":/splash/splash.png")
splash = QSplashScreen(pixmap) splash = QSplashScreen(pixmap)
splash.show() splash.show()