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,25 +340,24 @@ class MainWindow(QMainWindow):
def loadData(self, fname=None): def loadData(self, fname=None):
if fname is None: if fname is None:
try: action = self.sender()
self.data = Data(self, evtdata=self.fname) if isinstance(action, QAction):
except AttributeError: if action.data() is None:
action = self.sender() filt = "Supported event formats (*.mat *.qml *.xml *.kor *.evt)"
if isinstance(action, QAction): caption = "Open an event file"
if action.data() is None: fname = QFileDialog().getOpenFileName(self,
filt = "Supported event formats (*.mat *.qml *.xml *.kor *.evt)" caption=caption,
caption = "Open an event file" filter=filt)
fname = QFileDialog().getOpenFileName(self, self.setFileName(fname[0])
caption=caption, else:
filter=filt) self.setFileName(unicode(action.data().toString()))
self.fname = fname[0] if not self.okToContinue():
else: return
self.fname = unicode(action.data().toString())
if not self.okToContinue():
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):
""" """