From fc86179c39950b09ccf0572075be4a9cc964cba6 Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Sat, 18 Jul 2015 16:09:50 +0200 Subject: [PATCH] [closes #145], [addresses #146] this commit introduces the handling of picks as obspy event objects --- pylot/core/read/data.py | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/pylot/core/read/data.py b/pylot/core/read/data.py index cd24eccd..fcd33226 100644 --- a/pylot/core/read/data.py +++ b/pylot/core/read/data.py @@ -5,7 +5,7 @@ import os from obspy.core import read, Stream, UTCDateTime from obspy import readEvents, read_inventory -from obspy.core.event import Event, Catalog, ResourceIdentifier +from obspy.core.event import Event, ResourceIdentifier, Pick, WaveformStreamID from pylot.core.read.io import readPILOTEvent from pylot.core.util.utils import fnConstructor, getGlobalTimes @@ -46,6 +46,7 @@ class Data(object): else: # create an empty Event object self.newevent = True self.evtdata = Event() + self.getEvtData().picks = [] self.wforiginal = None self.cuttimes = None self.dirty = False @@ -160,27 +161,47 @@ class Data(object): def applyPicks(picks): firstonset = None - for phase in picks: - onset = picks[phase]['epp'] - if firstonset is None or firstonset > onset: - firstonset = onset + for station, onsets in picks.items(): + print 'Reading picks on station %s' % station + for label, phase in onsets.items(): + onset = phase['mpp'] + epp = phase['epp'] + lpp = phase['lpp'] + error = phase['spe'] + pick = Pick() + pick.time = onset + pick.time_errors.lower_uncertainty = onset - epp + pick.time_errors.upper_uncertainty = lpp - onset + pick.time_errors.uncertainty = error + pick.phase_hint = label + pick.waveform_id = WaveformStreamID(station_code=station) + self.getEvtData().picks.append(pick) + try: + polarity = phase['fm'] + except KeyError, e: + print 'No polarity information found for %s' % phase + if firstonset is None or firstonset > onset: + firstonset = onset if 'smi:local' in self.getID(): fonset_str = firstonset.strftime('%Y_%m_%d_%H_%M_%S') - ID = ResourceIdentifier(fonset_str) + ID = ResourceIdentifier('event/' + fonset_str) ID.convertIDToQuakeMLURI(authority_id=authority_id) + self.getEvtData().resource_id = ID def applyArrivals(arrivals): pass + def applyEvent(event): pass - applydata = {'pick':applyPicks, - 'arrival':applyArrivals, - 'event':applyEvent} + applydata = {'pick': applyPicks, + 'arrival': applyArrivals, + 'event': applyEvent} applydata[type](data) + class GenericDataStructure(object): ''' GenericDataBase type holds all information about the current data-