Fixed eventlist not working after locating twice

Changed exception when less then 2 horizontals are found to warning
This commit is contained in:
Jeldrik Gaal 2021-03-29 16:05:50 +02:00
parent 21453159b7
commit 217fa330c1
6 changed files with 27 additions and 25 deletions

View File

@ -1492,12 +1492,11 @@ class MainWindow(QMainWindow):
:param outformats: str/list of output formats :param outformats: str/list of output formats
:return: :return:
''' '''
if not event: if not event:
event = self.get_current_event() event = self.get_current_event()
if not type(outformats) == list: if not type(outformats) == list:
outformats = [outformats] outformats = [outformats]
def getSavePath(event, directory, outformats):
def getSavePath(event, directory, outformats):
if not directory: if not directory:
title = 'Save event data as {} to directory ...'.format(outformats) title = 'Save event data as {} to directory ...'.format(outformats)
directory = QFileDialog.getExistingDirectory(self, directory = QFileDialog.getExistingDirectory(self,
@ -1515,13 +1514,13 @@ class MainWindow(QMainWindow):
uppererrorP = self._inputs['timeerrorsP'] uppererrorP = self._inputs['timeerrorsP']
uppererrorS = self._inputs['timeerrorsS'] uppererrorS = self._inputs['timeerrorsS']
# Inserted to prevent Bug in Eventlist
self.get_data().setEvtData(event)
try: try:
self.get_data().applyEVTData(event, typ='event') # getPicks()) self.get_data().applyEVTData(event, typ='event') # getPicks())
except OverwriteError: except OverwriteError:
self.get_data().resetPicks() self.get_data().resetPicks()
return self.saveData(event, directory, outformats) return self.saveData(event, directory, outformats)
fcheck = ['auto', 'manual', 'origins', 'magnitude'] fcheck = ['auto', 'manual', 'origins', 'magnitude']
saved_as = str() saved_as = str()
@ -1537,7 +1536,6 @@ class MainWindow(QMainWindow):
msg = 'Event {} saved as {} in format(s) {}'.format(event.pylot_id, fbasename, saved_as.strip()) msg = 'Event {} saved as {} in format(s) {}'.format(event.pylot_id, fbasename, saved_as.strip())
self.update_status(msg) self.update_status(msg)
print(msg) print(msg)
event.dirty = False event.dirty = False
self.fill_eventbox() self.fill_eventbox()
return True return True
@ -3012,12 +3010,11 @@ class MainWindow(QMainWindow):
self.locate_event() self.locate_event()
ctrfile = os.path.join(locroot, 'run', parameter['ctrfile']) ctrfile = os.path.join(locroot, 'run', parameter['ctrfile'])
ttt = parameter['ttpatter'] ttt = parameter['ttpatter']
outfile = parameter['outpatter'] outfile = parameter['outpatter']
eventname = self.get_current_event_name() eventname = self.get_current_event_name()
obsdir = os.path.join(self._inputs['rootpath'], self._inputs['datapath'], self._inputs['database'], eventname) obsdir = os.path.join(self._inputs['rootpath'], self._inputs['datapath'], self._inputs['database'], eventname)
self.saveData(event=self.get_current_event(), directory=obsdir, outformats='.obs') self.saveData(event=self.get_current_event(), directory=obsdir, outformats='.obs')
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')
@ -3028,7 +3025,6 @@ class MainWindow(QMainWindow):
print(e.message) print(e.message)
# finally: # finally:
# os.remove(phasefile) # os.remove(phasefile)
self.get_data().applyEVTData(lt.read_location(locpath), typ='event') self.get_data().applyEVTData(lt.read_location(locpath), typ='event')
for event in self.calc_magnitude(): for event in self.calc_magnitude():
self.get_data().applyEVTData(event, typ='event') self.get_data().applyEVTData(event, typ='event')
@ -3210,7 +3206,7 @@ class MainWindow(QMainWindow):
# iterate through eventlist and generate items for table rows # iterate through eventlist and generate items for table rows
self.project._table = [] self.project._table = []
for index, event in enumerate(eventlist): for index, event in enumerate(eventlist):
phaseErrors = {'P': self._inputs['timeerrorsP'], phaseErrors = {'P': self._inputs['timeerrorsP'],
'S': self._inputs['timeerrorsS']} 'S': self._inputs['timeerrorsS']}
@ -3751,7 +3747,7 @@ class Project(object):
self.search_eventfile_info() self.search_eventfile_info()
def remove_event(self, event): def remove_event(self, event):
self.eventlist.remove(event) self.eventlist.remove(event)
def remove_event_by_id(self, eventID): def remove_event_by_id(self, eventID):
for event in self.eventlist: for event in self.eventlist:
@ -3760,7 +3756,7 @@ class Project(object):
break break
def read_eventfile_info(self, filename, separator=','): def read_eventfile_info(self, filename, separator=','):
''' '''
Try to read event information from file (:param:filename) comparing specific event datetimes. Try to read event information from file (:param:filename) comparing specific event datetimes.
File structure (each row): event, date, time, magnitude, latitude, longitude, depth File structure (each row): event, date, time, magnitude, latitude, longitude, depth
separated by :param:separator each. separated by :param:separator each.

View File

@ -221,11 +221,16 @@ class LocalMagnitude(Magnitude):
power = [np.power(tr.data, 2) for tr in st if tr.stats.channel[-1] not power = [np.power(tr.data, 2) for tr in st if tr.stats.channel[-1] not
in 'Z3'] in 'Z3']
if len(power) != 2: # checking horizontal count and calculating power_sum accordingly
raise ValueError('Wood-Anderson amplitude defintion only valid for ' if len(power) == 1:
'two horizontals: {0} given'.format(len(power))) print ('WARNING: Only one horizontal found for station {0}.'.format(st[0].stats.station))
power_sum = power[0] + power[1] power_sum = power[0]
# elif len(power) == 2:
power_sum = power[0] + power[1]
else:
raise ValueError('Wood-Anderson aomplitude defintion only valid for'
' up to two horizontals: {0} given'.format(len(power)))
sqH = np.sqrt(power_sum) sqH = np.sqrt(power_sum)
# get time array # get time array

View File

@ -21,7 +21,6 @@ from pylot.core.util.obspyDMT_interface import qml_from_obspyDMT
from pylot.core.util.utils import fnConstructor, full_range, check4rotated, \ from pylot.core.util.utils import fnConstructor, full_range, check4rotated, \
check4gapsAndMerge, trim_station_components check4gapsAndMerge, trim_station_components
class Data(object): class Data(object):
""" """
Data container with attributes wfdata holding ~obspy.core.stream. Data container with attributes wfdata holding ~obspy.core.stream.
@ -258,7 +257,7 @@ class Data(object):
can be a str or a list of strings of ['manual', 'auto', 'origin', 'magnitude'] can be a str or a list of strings of ['manual', 'auto', 'origin', 'magnitude']
""" """
from pylot.core.util.defaults import OUTPUTFORMATS from pylot.core.util.defaults import OUTPUTFORMATS
if not type(fcheck) == list: if not type(fcheck) == list:
fcheck = [fcheck] fcheck = [fcheck]
@ -276,7 +275,7 @@ class Data(object):
# check for already existing xml-file # check for already existing xml-file
if fnext == '.xml': if fnext == '.xml':
if os.path.isfile(fnout + fnext): if os.path.isfile(fnout + fnext):
print("xml-file already exists! Check content ...") print("xml-file already exists! Check content ...")
cat = read_events(fnout + fnext) cat = read_events(fnout + fnext)
if len(cat) > 1: if len(cat) > 1:
raise IOError('Ambigious event information in file {}'.format(fnout + fnext)) raise IOError('Ambigious event information in file {}'.format(fnout + fnext))
@ -288,7 +287,9 @@ class Data(object):
return return
self.checkEvent(event, fcheck) self.checkEvent(event, fcheck)
self.setEvtData(event) self.setEvtData(event)
self.get_evt_data().write(fnout + fnext, format=evtformat) self.get_evt_data().write(fnout + fnext, format=evtformat)
# try exporting event # try exporting event
else: else:
evtdata_org = self.get_evt_data() evtdata_org = self.get_evt_data()

View File

@ -805,7 +805,7 @@ def writephases(arrivals, fformat, filename, parameter=None, eventinfo=None):
return return
stime = eventsource['time'] stime = eventsource['time']
event = parameter.get('eventID') event = parameter.get('eventID')
hddID = event.split('.')[0][1:5] hddID = event.split('.')[0][1:5]
# write header # write header
fid.write('# %d %d %d %d %d %5.2f %7.4f +%6.4f %7.4f %4.2f 0.1 0.5 %4.2f %s\n' % ( fid.write('# %d %d %d %d %d %5.2f %7.4f +%6.4f %7.4f %4.2f 0.1 0.5 %4.2f %s\n' % (
stime.year, stime.month, stime.day, stime.hour, stime.minute, stime.second, stime.year, stime.month, stime.day, stime.hour, stime.minute, stime.second,

View File

@ -81,7 +81,6 @@ def locate(fnin, parameter=None):
:param fnin: external program name :param fnin: external program name
:return: None :return: None
""" """
exe_path = which('NLLoc', parameter) exe_path = which('NLLoc', parameter)
if exe_path is None: if exe_path is None:
raise NLLocError('NonLinLoc executable not found; check your ' raise NLLocError('NonLinLoc executable not found; check your '

View File

@ -53,7 +53,7 @@ def which(program, parameter):
settings = QSettings() settings = QSettings()
for key in settings.allKeys(): for key in settings.allKeys():
if 'binPath' in key: if 'binPath' in key:
os.environ['PATH'] += ':{0}'.format(settings.value(key)) os.environ['PATH'] += ':{0}'.format(settings.value(key))
nllocpath = ":" + parameter.get('nllocbin') nllocpath = ":" + parameter.get('nllocbin')
os.environ['PATH'] += nllocpath os.environ['PATH'] += nllocpath
except Exception as e: except Exception as e:
@ -73,7 +73,7 @@ def which(program, parameter):
return program return program
else: else:
for path in os.environ["PATH"].split(os.pathsep): for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program) exe_file = os.path.join(path, program)
for candidate in ext_candidates(exe_file): for candidate in ext_candidates(exe_file):
if is_exe(candidate): if is_exe(candidate):
return candidate return candidate
@ -100,4 +100,5 @@ def make_pen(picktype, phase, key, quality):
rgba = pick_color(picktype, phase, quality) rgba = pick_color(picktype, phase, quality)
linestyle, width = pick_linestyle_pg(picktype, key) linestyle, width = pick_linestyle_pg(picktype, key)
pen = pg.mkPen(rgba, width=width, style=linestyle) pen = pg.mkPen(rgba, width=width, style=linestyle)
return pen return pen