[bugfix] wrong if cause in for loop in read_eventfile_info
[add] function to remove events from project
This commit is contained in:
parent
37875d5c87
commit
60594c97cf
28
QtPyLoT.py
28
QtPyLoT.py
@ -917,6 +917,10 @@ class MainWindow(QMainWindow):
|
||||
self.init_events()
|
||||
self.setDirty(True)
|
||||
|
||||
def removeEvent(self, eventID):
|
||||
self.project.remove_event_by_id(eventID)
|
||||
self.init_events()
|
||||
|
||||
def createEventBox(self):
|
||||
'''
|
||||
Eventbox generator.
|
||||
@ -1308,6 +1312,10 @@ class MainWindow(QMainWindow):
|
||||
# which will read in data input twice. Therefore current tab is changed to 0
|
||||
# in loadProject before calling this function.
|
||||
plotted = False
|
||||
if self.tabs.currentIndex() == 2:
|
||||
self.init_event_table()
|
||||
self.refreshRefTestButtons()
|
||||
|
||||
# only refresh first/second tab when an event was changed.
|
||||
if self._eventChanged[0] or self._eventChanged[1]:
|
||||
event = self.get_current_event()
|
||||
@ -1338,10 +1346,6 @@ class MainWindow(QMainWindow):
|
||||
# newWF(False) = load data without plotting
|
||||
self.newWF(plot=False)
|
||||
|
||||
if self.tabs.currentIndex() == 2:
|
||||
self.init_event_table()
|
||||
self.refreshRefTestButtons()
|
||||
|
||||
def newWF(self, plot=True):
|
||||
'''
|
||||
Load new data and plot if necessary.
|
||||
@ -2599,8 +2603,18 @@ class Project(object):
|
||||
self.setDirty()
|
||||
else:
|
||||
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()
|
||||
|
||||
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=','):
|
||||
'''
|
||||
Try to read event information from file (:param:filename) comparing specific event datetimes.
|
||||
@ -2609,7 +2623,7 @@ class Project(object):
|
||||
'''
|
||||
infile = open(filename, 'r')
|
||||
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
|
||||
try:
|
||||
month, day, year = date.split('/')
|
||||
@ -2626,12 +2640,15 @@ class Project(object):
|
||||
print(e, datetime, filename)
|
||||
continue
|
||||
for event in self.eventlist:
|
||||
if eventID in str(event.resource_id) or event.origins:
|
||||
if event.origins:
|
||||
origin = event.origins[0] # should have only one origin
|
||||
if origin.time == datetime:
|
||||
origin.latitude = float(lat)
|
||||
origin.longitude = float(lon)
|
||||
origin.depth = float(depth)
|
||||
else:
|
||||
continue
|
||||
elif not event.origins:
|
||||
origin = Origin(resource_id=event.resource_id,
|
||||
time=datetime, latitude=float(lat),
|
||||
@ -2640,6 +2657,7 @@ class Project(object):
|
||||
event.magnitudes.append(Magnitude(resource_id=event.resource_id,
|
||||
mag=float(mag),
|
||||
mag_type='M'))
|
||||
break
|
||||
|
||||
def search_eventfile_info(self):
|
||||
'''
|
||||
|
@ -1 +1 @@
|
||||
dbb3-dirty
|
||||
3787-dirty
|
||||
|
@ -5,7 +5,7 @@ import os
|
||||
|
||||
from obspy import UTCDateTime
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user