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

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

View File

@ -40,6 +40,7 @@ import numpy as np
import subprocess import subprocess
from obspy import UTCDateTime from obspy import UTCDateTime
from pylot.core.analysis.magnitude import calcsourcespec, calcMoMw
from pylot.core.io.data import Data from pylot.core.io.data import Data
from pylot.core.io.inputs import FilterOptions, AutoPickParameter from pylot.core.io.inputs import FilterOptions, AutoPickParameter
from pylot.core.pick.autopick import autopickevent from pylot.core.pick.autopick import autopickevent
@ -945,16 +946,31 @@ class MainWindow(QMainWindow):
os.remove(phasepath) os.remove(phasepath)
self.getData().applyEVTData(lt.read_location(locpath), type='event') self.getData().applyEVTData(lt.read_location(locpath), type='event')
self.calc_magnitude()
def calc_magnitude(self): def calc_magnitude(self):
e = self.getData().getEvtData() e = self.getData().getEvtData()
settings = QSettings()
if e.origins: if e.origins:
o = e.origins[0] o = e.origins[0]
mags = dict()
for a in o.arrivals: for a in o.arrivals:
pid = a.pick_id pick = a.pick_id.get_referred_object()
pick = pid.get_referred_object() station = pick.waveform_id.station_code
station = self.getStationID(pick.waveform_id.station_code)
wf = self.getData().getWFData().select(station=station) wf = self.getData().getWFData().select(station=station)
onset = pick.time
fninv = settings.value("inventoryFile", None)
if fninv is None:
fninv = QFileDialog.getOpenFileName()
ans = QMessageBox.question(self, self.tr("Make default..."),
self.tr("New inventory filename set.\n" + \
"Do you want to make it the default value?"),
QMessageBox.Yes | QMessageBox.No,
QMessageBox.No)
print(ans)
settings.setValue("inventoryFile", fninv)
#w0, fc = calcsourcespec(wf, onset, )
#mags[station] =
mag = None mag = None
return mag return mag
else: else:

View File

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

View File

@ -527,3 +527,26 @@ def writephases(arrivals, fformat, filename):
Ao)) Ao))
fid.close() 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