debugged some code fragments while trying to solve the load event data problem

This commit is contained in:
Sebastian Wehling-Benatelli 2015-09-17 17:45:10 +02:00
parent ac7d239b40
commit 7a47594614
3 changed files with 52 additions and 26 deletions

View File

@ -340,9 +340,6 @@ class MainWindow(QMainWindow):
def loadData(self, fname=None): def loadData(self, fname=None):
if fname is None: if fname is None:
try:
self.data = Data(self, evtdata=self.fname)
except AttributeError:
action = self.sender() action = self.sender()
if isinstance(action, QAction): if isinstance(action, QAction):
if action.data() is None: if action.data() is None:
@ -351,14 +348,16 @@ class MainWindow(QMainWindow):
fname = QFileDialog().getOpenFileName(self, fname = QFileDialog().getOpenFileName(self,
caption=caption, caption=caption,
filter=filt) filter=filt)
self.fname = fname[0] self.setFileName(fname[0])
else: else:
self.fname = unicode(action.data().toString()) self.setFileName(unicode(action.data().toString()))
if not self.okToContinue(): if not self.okToContinue():
return return
else: else:
self.fname = fname self.setFileName(fname)
self.data = Data(self, evtdata=self.fname) self.data += Data(self, evtdata=self.getFileName())
self.updatePicks()
self.updateStatus('Event data loaded ...')
def getLastEvent(self): def getLastEvent(self):
return self.recentEvents[0] return self.recentEvents[0]
@ -469,6 +468,9 @@ class MainWindow(QMainWindow):
def getPicks(self): def getPicks(self):
return self.picks return self.picks
def updatePicks(self):
pass
def getPicksOnStation(self, station): def getPicksOnStation(self, station):
try: try:
return self.getPicks()[station] return self.getPicks()[station]

View File

@ -1 +1 @@
c940-dirty ac7d-dirty

View File

@ -33,16 +33,16 @@ class Data(object):
else: else:
self.comp = 'Z' self.comp = 'Z'
self.wfdata = Stream() self.wfdata = Stream()
self.newevent = False self._new = False
if evtdata is not None and isinstance(evtdata, Event): if isinstance(evtdata, Event):
self.evtdata = evtdata self.evtdata = evtdata
elif evtdata is not None and not isinstance(evtdata, dict): elif isinstance(evtdata, dict):
cat = readPILOTEvent(**evtdata)
elif evtdata:
cat = readEvents(evtdata) cat = readEvents(evtdata)
self.evtdata = cat[0] self.evtdata = cat[0]
elif evtdata is not None:
cat = readPILOTEvent(**evtdata)
else: # create an empty Event object else: # create an empty Event object
self.newevent = True self.setNew()
self.evtdata = Event() self.evtdata = Event()
self.getEvtData().picks = [] self.getEvtData().picks = []
self.wforiginal = None self.wforiginal = None
@ -52,6 +52,27 @@ class Data(object):
def __str__(self): def __str__(self):
return str(self.wfdata) return str(self.wfdata)
def __add__(self, other):
assert isinstance(other, Data), "operands must be of same type 'Data'"
if other.isNew() and not self.isNew():
picks_to_add = other.getEvtData().picks
old_picks = self.getEvtData().picks
for pick in picks_to_add:
if pick not in old_picks:
old_picks.append(pick)
elif not other.isNew() and self.isNew():
new = other + self
self.evtdata = new.getEvtData()
elif self.isNew() and other.isNew():
pass
elif self.getEvtData().get('id') == other.getEvtData().get('id'):
other.setNew()
return self + other
else:
raise ValueError("both Data objects have differing "
"unique Event identifiers")
return self
def getPicksStr(self): def getPicksStr(self):
picks_str = '' picks_str = ''
for pick in self.getEvtData().picks: for pick in self.getEvtData().picks:
@ -73,7 +94,10 @@ class Data(object):
:return: :return:
""" """
return self.newevent return self._new
def setNew(self):
self._new = True
def getCutTimes(self): def getCutTimes(self):
""" """