From 553bb9990b0ed3d887d661072313f9842c6e59c5 Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Mon, 1 Dec 2014 12:45:20 +0100 Subject: [PATCH] loading data by initialization of a Data object (not working yet) --- pylot/core/read/data.py | 45 +++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/pylot/core/read/data.py b/pylot/core/read/data.py index b11aea34..db6b898c 100644 --- a/pylot/core/read/data.py +++ b/pylot/core/read/data.py @@ -4,6 +4,7 @@ import os from PySide.QtGui import QMessageBox from obspy.core import (read, Stream) +from obspy import readEvents from obspy.core.event import (Event, Catalog) from pylot.core.util import fnConstructor @@ -24,37 +25,37 @@ class Data(object): loaded event. Container object holding, e.g. phase arrivals, etc. ''' - def __init__(self, parent=None, wfdata=None, evtdata=None): - if wfdata is not None and isinstance(wfdata, Stream): - self.wfdata = wfdata - elif wfdata is not None: - try: - self.wfdata = read(wfdata) - except IOError, e: - msg = 'An I/O error occured while loading data!' - inform = 'Variable wfdata will be empty.' - details = '{0}'.format(e) - if parent is not None: - warnio = QMessageBox(parent=parent) - warnio.setText(msg) - warnio.setDetailedText(details) - warnio.setInformativeText(inform) - warnio.setStandarButtons(QMessageBox.Ok) - warnio.setIcon(QMessageBox.Warning) - else: - print msg, '\n', details - self.wfdata = Stream() + def __init__(self, parent=None, evtdata=None): + try: + self.wfdata = read() + except IOError, e: + msg = 'An I/O error occured while loading data!' + inform = 'Variable wfdata will be empty.' + details = '{0}'.format(e) + if parent is not None: + warnio = QMessageBox(parent=parent) + warnio.setText(msg) + warnio.setDetailedText(details) + warnio.setInformativeText(inform) + warnio.setStandarButtons(QMessageBox.Ok) + warnio.setIcon(QMessageBox.Warning) + else: + print msg, '\n', details + self.wfdata = Stream() else: self.wfdata = Stream() if evtdata is not None and isinstance(evtdata, Event): self.evtdata = evtdata - else: + elif evtdata is not None: + cat = readEvents(evtdata) + self.evtdata = cat[0] + else: # create an empty Event object self.evtdata = Event() def exportEvent(self, fnout=None, evtformat='QUAKEML'): if fnout is None: - fnout = self.event.resource_id.__str__().split('/')[-1] + fnout = self.evtdata.getEventID() # handle forbidden filenames especially on windows systems fnout = fnConstructor(fnout)