[bugfix] wrong if cause in for loop in read_eventfile_info

[add] function to remove events from project
This commit is contained in:
Marcel Paffrath 2017-07-18 15:27:52 +02:00
parent 37875d5c87
commit 60594c97cf
3 changed files with 39 additions and 21 deletions

View File

@ -917,6 +917,10 @@ class MainWindow(QMainWindow):
self.init_events() self.init_events()
self.setDirty(True) self.setDirty(True)
def removeEvent(self, eventID):
self.project.remove_event_by_id(eventID)
self.init_events()
def createEventBox(self): def createEventBox(self):
''' '''
Eventbox generator. Eventbox generator.
@ -1308,6 +1312,10 @@ class MainWindow(QMainWindow):
# 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
if self.tabs.currentIndex() == 2:
self.init_event_table()
self.refreshRefTestButtons()
# 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()
@ -1338,10 +1346,6 @@ class MainWindow(QMainWindow):
# newWF(False) = load data without plotting # newWF(False) = load data without plotting
self.newWF(plot=False) self.newWF(plot=False)
if self.tabs.currentIndex() == 2:
self.init_event_table()
self.refreshRefTestButtons()
def newWF(self, plot=True): def newWF(self, plot=True):
''' '''
Load new data and plot if necessary. Load new data and plot if necessary.
@ -2599,8 +2603,18 @@ 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.eventlist.sort(key=lambda x: x.pylot_id)
self.search_eventfile_info() self.search_eventfile_info()
def remove_event(self, event):
self.eventlist.remove(event)
def remove_event_by_id(self, eventID):
for event in self.eventlist:
if eventID in str(event.resource_id):
self.remove_event(event)
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.
@ -2609,7 +2623,7 @@ 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] eventID, 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('/')
@ -2626,12 +2640,15 @@ class Project(object):
print(e, datetime, filename) print(e, datetime, filename)
continue continue
for event in self.eventlist: for event in self.eventlist:
if eventID in str(event.resource_id) or event.origins:
if event.origins: if event.origins:
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)
else:
continue
elif not event.origins: elif not event.origins:
origin = Origin(resource_id=event.resource_id, origin = Origin(resource_id=event.resource_id,
time=datetime, latitude=float(lat), time=datetime, latitude=float(lat),
@ -2640,6 +2657,7 @@ class Project(object):
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'))
break
def search_eventfile_info(self): def search_eventfile_info(self):
''' '''

View File

@ -1 +1 @@
dbb3-dirty 3787-dirty

View File

@ -5,7 +5,7 @@ import os
from obspy import UTCDateTime from obspy import UTCDateTime
from obspy.core.event import Event as ObsPyEvent from obspy.core.event import Event as ObsPyEvent
from obspy.core.event import Origin, Magnitude, ResourceIdentifier from obspy.core.event import Origin, ResourceIdentifier
from pylot.core.io.phases import picks_from_picksdict from pylot.core.io.phases import picks_from_picksdict