[refs #200] now merging picks without destroyed reference resource IDs
This commit is contained in:
parent
81640d30f9
commit
d98ecea18a
22
QtPyLoT.py
22
QtPyLoT.py
@ -40,6 +40,7 @@ import numpy as np
|
||||
import subprocess
|
||||
from obspy import UTCDateTime
|
||||
|
||||
from pylot.core.analysis.magnitude import calcsourcespec, calcMoMw
|
||||
from pylot.core.io.data import Data
|
||||
from pylot.core.io.inputs import FilterOptions, AutoPickParameter
|
||||
from pylot.core.pick.autopick import autopickevent
|
||||
@ -945,16 +946,31 @@ class MainWindow(QMainWindow):
|
||||
os.remove(phasepath)
|
||||
|
||||
self.getData().applyEVTData(lt.read_location(locpath), type='event')
|
||||
self.calc_magnitude()
|
||||
|
||||
def calc_magnitude(self):
|
||||
e = self.getData().getEvtData()
|
||||
settings = QSettings()
|
||||
if e.origins:
|
||||
o = e.origins[0]
|
||||
mags = dict()
|
||||
for a in o.arrivals:
|
||||
pid = a.pick_id
|
||||
pick = pid.get_referred_object()
|
||||
station = self.getStationID(pick.waveform_id.station_code)
|
||||
pick = a.pick_id.get_referred_object()
|
||||
station = pick.waveform_id.station_code
|
||||
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
|
||||
return mag
|
||||
else:
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user