[change] Event class now bases on ObsPy Event class which should be more efficient in future, origin time will be read from notes file if possible
This commit is contained in:
		
							parent
							
								
									410fe18390
								
							
						
					
					
						commit
						7bb2d54f6e
					
				
							
								
								
									
										27
									
								
								QtPyLoT.py
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								QtPyLoT.py
									
									
									
									
									
								
							@ -41,6 +41,8 @@ from PySide.QtGui import QMainWindow, QInputDialog, QIcon, QFileDialog, \
 | 
			
		||||
    QTreeView, QComboBox, QTabWidget, QPushButton, QGridLayout
 | 
			
		||||
import numpy as np
 | 
			
		||||
from obspy import UTCDateTime
 | 
			
		||||
from obspy.core.event import Event as ObsPyEvent
 | 
			
		||||
from obspy.core.event import Origin
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    import pyqtgraph as pg
 | 
			
		||||
@ -752,8 +754,8 @@ class MainWindow(QMainWindow):
 | 
			
		||||
        '''
 | 
			
		||||
        if not eventbox:
 | 
			
		||||
            eventbox = self.eventBox
 | 
			
		||||
        index = eventbox.currentIndex()
 | 
			
		||||
        return eventbox.itemData(index)
 | 
			
		||||
        path = eventbox.currentText()
 | 
			
		||||
        return self.project.getEventFromPath(path)
 | 
			
		||||
 | 
			
		||||
    def get_current_event_path(self, eventbox=None):
 | 
			
		||||
        '''
 | 
			
		||||
@ -953,7 +955,8 @@ class MainWindow(QMainWindow):
 | 
			
		||||
                           '{} unequal {}.'
 | 
			
		||||
                           .format(event.path, self.eventBox.itemText(id)))
 | 
			
		||||
                raise ValueError(message)
 | 
			
		||||
            eventBox.setItemData(id, event)
 | 
			
		||||
            #not working with obspy events
 | 
			
		||||
            #eventBox.setItemData(id, event)
 | 
			
		||||
        eventBox.setCurrentIndex(index)
 | 
			
		||||
        self.refreshRefTestButtons()
 | 
			
		||||
 | 
			
		||||
@ -2468,11 +2471,13 @@ class Project(object):
 | 
			
		||||
        return project
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
class Event(object):
 | 
			
		||||
class Event(ObsPyEvent):
 | 
			
		||||
    '''
 | 
			
		||||
    Pickable class containing information on a single event.
 | 
			
		||||
    Pickable class derived from ~obspy.core.event.Event containing information on a single event.
 | 
			
		||||
    '''
 | 
			
		||||
    def __init__(self, path):
 | 
			
		||||
        # initialize super class
 | 
			
		||||
        super(Event, self).__init__()
 | 
			
		||||
        self.path = path
 | 
			
		||||
        self.database = path.split('/')[-2]
 | 
			
		||||
        self.datapath = path.split('/')[-3]
 | 
			
		||||
@ -2482,10 +2487,7 @@ class Event(object):
 | 
			
		||||
        self.notes = ''
 | 
			
		||||
        self._testEvent = False
 | 
			
		||||
        self._refEvent = False
 | 
			
		||||
        try:
 | 
			
		||||
        self.get_notes()
 | 
			
		||||
        except:
 | 
			
		||||
            pass
 | 
			
		||||
 | 
			
		||||
    def get_notes_path(self):
 | 
			
		||||
        notesfile = os.path.join(self.path, 'notes.txt')
 | 
			
		||||
@ -2495,8 +2497,15 @@ class Event(object):
 | 
			
		||||
        notesfile = self.get_notes_path()
 | 
			
		||||
        if os.path.isfile(notesfile):
 | 
			
		||||
            with open(notesfile) as infile:
 | 
			
		||||
                text = '[eventInfo: '+str(infile.readlines()[0].split('\n')[0])+']'
 | 
			
		||||
                path = str(infile.readlines()[0].split('\n')[0])
 | 
			
		||||
                text = '[eventInfo: '+path+']'
 | 
			
		||||
                self.addNotes(text)
 | 
			
		||||
                try:
 | 
			
		||||
                    datetime = UTCDateTime(path.split('/')[-1])
 | 
			
		||||
                    origin = Origin(time=datetime, latitude=0, longitude=0)
 | 
			
		||||
                    self.origins.append(origin)
 | 
			
		||||
                except:
 | 
			
		||||
                    pass
 | 
			
		||||
 | 
			
		||||
    def addNotes(self, notes):
 | 
			
		||||
        self.notes = str(notes)
 | 
			
		||||
 | 
			
		||||
@ -1 +1 @@
 | 
			
		||||
8e8b-dirty
 | 
			
		||||
410fe-dirty
 | 
			
		||||
 | 
			
		||||
@ -1687,8 +1687,8 @@ class TuneAutopicker(QWidget):
 | 
			
		||||
        self.listWidget.scrollToBottom()
 | 
			
		||||
        
 | 
			
		||||
    def get_current_event(self):
 | 
			
		||||
        index = self.eventBox.currentIndex()
 | 
			
		||||
        return self.eventBox.itemData(index)
 | 
			
		||||
        path = self.eventBox.currentText()
 | 
			
		||||
        return self.parent.project.getEventFromPath(path)
 | 
			
		||||
        
 | 
			
		||||
    def get_current_event_name(self):
 | 
			
		||||
        return self.eventBox.currentText().split('/')[-1]
 | 
			
		||||
@ -1855,6 +1855,9 @@ class TuneAutopicker(QWidget):
 | 
			
		||||
        self.init_tab_names()
 | 
			
		||||
 | 
			
		||||
    def fill_eventbox(self):
 | 
			
		||||
        project = self.parent.project
 | 
			
		||||
        if not project:
 | 
			
		||||
            return
 | 
			
		||||
        # update own list
 | 
			
		||||
        self.parent.fill_eventbox(eventBox=self.eventBox, select_events='ref')
 | 
			
		||||
        index_start = self.parent.eventBox.currentIndex()
 | 
			
		||||
@ -1862,10 +1865,13 @@ class TuneAutopicker(QWidget):
 | 
			
		||||
        if index == -1:
 | 
			
		||||
            index += 1
 | 
			
		||||
        nevents = self.eventBox.model().rowCount()
 | 
			
		||||
        if self.eventBox.itemData(index).isTestEvent():
 | 
			
		||||
        path = self.eventBox.itemText(index)
 | 
			
		||||
        if project.getEventFromPath(path).isTestEvent():
 | 
			
		||||
            for index in range(nevents):
 | 
			
		||||
                if not self.eventBox.itemData(index).isTestEvent():
 | 
			
		||||
                path = self.eventBox.itemText(index)                
 | 
			
		||||
                if not project.getEventFromPath(index).isTestEvent():
 | 
			
		||||
                    break
 | 
			
		||||
                #in case all events are marked as test events
 | 
			
		||||
                elif index == nevents - 1:
 | 
			
		||||
                    index = -1
 | 
			
		||||
        self.eventBox.setCurrentIndex(index)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user