[change] exportEvent now checks for existing picks of type 'fcheck' in xml file and replaces them with new picks

This commit is contained in:
Marcel Paffrath 2017-07-17 10:55:02 +02:00
parent 90e27f1d08
commit b286290797
2 changed files with 28 additions and 16 deletions

View File

@ -1111,7 +1111,8 @@ class MainWindow(QMainWindow):
# return False # return False
# MP MP changed to suppress unnecessary user prompt # MP MP changed to suppress unnecessary user prompt
try: try:
self.get_data().exportEvent(fbasename, exform, upperErrors=[uppererrorP[3], uppererrorS[3]]) self.get_data().exportEvent(fbasename, exform, fcheck='manual',
upperErrors=[uppererrorP[3], uppererrorS[3]])
except FormatError as e: except FormatError as e:
fbasename, exform = getSavePath(e, directory, outformat) fbasename, exform = getSavePath(e, directory, outformat)
except AttributeError as e: except AttributeError as e:
@ -1134,8 +1135,10 @@ class MainWindow(QMainWindow):
# 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], fcheck='manual',
self.get_data().exportEvent(fbasename, exform[1], upperErrors=[uppererrorP[3], uppererrorS[3]]) upperErrors=[uppererrorP[3], uppererrorS[3]])
self.get_data().exportEvent(fbasename, exform[1], fcheck='manual',
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],

View File

@ -168,23 +168,32 @@ class Data(object):
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_old = read_events(fnout + fnext) cat = read_events(fnout + fnext)
if len(cat) > 1:
raise IOError('Ambigious event information in file {}'.format(fnout + fnext))
if len(cat) < 1:
raise IOError('No event information in file {}'.format(fnout + fnext))
event = cat[0]
if not event.resource_id == self.get_evt_data().resource_id:
raise IOError("Missmatching event resource id's: {} and {}".format(event.resource_id,
self.get_evt_data().resource_id))
checkflag = 0 checkflag = 0
picks = cat_old.events[0].picks picks = event.picks
#remove existing picks
for j, pick in reversed(list(enumerate(picks))): for j, pick in reversed(list(enumerate(picks))):
if pick.method_id.id.split('/')[1] == fcheck: if pick.method_id.id.split('/')[1] == fcheck:
picks.remove(j) picks.pop(j)
print("Found %s pick(s), remove them and append new picks to catalog." % fcheck)
checkflag = 1 checkflag = 1
if checkflag == 1: if checkflag:
event = self.get_evt_data().write(fnout + fnext, format=evtformat) print("Found %s pick(s), remove them and append new picks to catalog." % fcheck)
cat_new = read_events(fnout + fnext)
cat_new.append(cat_old.events[0]) #append new picks
cat_new.write(fnout + fnext, format=evtformat) for pick in self.get_evt_data().picks:
else: if pick.method_id.id.split('/')[1] == fcheck:
self.get_evt_data().write(fnout + fnext, format=evtformat) picks.append(pick)
else:
self.get_evt_data().write(fnout + fnext, format=evtformat) self.setEvtData(event)
self.get_evt_data().write(fnout + fnext, format=evtformat)
# try exporting event via ObsPy # try exporting event via ObsPy
else: else: