[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:
@ -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()
@ -862,11 +862,21 @@ class MainWindow(QMainWindow):
# 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 = {
'database': '', 'database': '',
@ -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_()
@ -1516,7 +1527,8 @@ 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):
@ -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)
@ -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:
@ -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
@ -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=','):
''' '''
@ -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'))
@ -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)