[refs #200] now merging picks without destroyed reference resource IDs

This commit is contained in:
2016-09-01 14:21:25 +02:00
parent 81640d30f9
commit d98ecea18a
3 changed files with 45 additions and 6 deletions

View File

@@ -10,7 +10,7 @@ from obspy.core.event import Event
from obspy.io.xseed import Parser
from pylot.core.io.phases import readPILOTEvent, picks_from_picksdict, \
picksdict_from_pilot
picksdict_from_pilot, merge_picks
from pylot.core.util.errors import FormatError, OverwriteError
from pylot.core.util.utils import fnConstructor, getGlobalTimes
@@ -454,9 +454,9 @@ class Data(object):
if not self.isNew():
self.setEvtData(event)
else:
# prevent overwriting uncertainty information
# prevent overwriting original pick information
picks = copy.deepcopy(self.getEvtData().picks)
event.picks = picks
event = merge_picks(event, picks)
# apply event information from location
self.getEvtData().update(event)

View File

@@ -527,3 +527,26 @@ def writephases(arrivals, fformat, filename):
Ao))
fid.close()
def merge_picks(event, picks):
"""
takes an event object and a list of picks and searches for matching
entries by comparing station name and phase_hint and overwrites the time
and time_errors value of the event picks' with those from the picks
without changing the resource identifiers
:param event: `obspy.core.event.Event` object (e.g. from NLLoc output)
:param picks: list of `obspy.core.event.Pick` objects containing the
original time and time_errors values
:return: merged `obspy.core.event.Event` object
"""
for pick in picks:
time = pick.time
err = pick.time_errors
phase = pick.phase_hint
station = pick.waveform_id.station_code
for p in event.picks:
if p.waveform_id.station_code == station and p.phase_hint == phase:
p.time, p.time_errors = time, err
del time, err, phase, station
return event