[Bugfix]: PyLoT is now able to write VELEST-input cnv-file.

This commit is contained in:
Ludger Küperkoch 2020-07-21 16:22:17 +02:00
parent 7617958a1c
commit 003ba76650

View File

@ -15,7 +15,7 @@ from obspy.core.util import AttribDict
from pylot.core.io.inputs import PylotParameter from pylot.core.io.inputs import PylotParameter
from pylot.core.io.location import create_event, \ from pylot.core.io.location import create_event, \
create_magnitude create_magnitude
from pylot.core.pick.utils import select_for_phase from pylot.core.pick.utils import select_for_phase, get_quality_class
from pylot.core.util.utils import getOwner, full_range, four_digits, transformFilterString4Export, \ from pylot.core.util.utils import getOwner, full_range, four_digits, transformFilterString4Export, \
backtransformFilterString backtransformFilterString
@ -232,7 +232,10 @@ def picksdict_from_picks(evt):
for pick in evt.picks: for pick in evt.picks:
phase = {} phase = {}
station = pick.waveform_id.station_code station = pick.waveform_id.station_code
channel = pick.waveform_id.channel_code if pick.waveform_id.channel_code == None:
channel = ''
else:
channel = pick.waveform_id.channel_code
network = pick.waveform_id.network_code network = pick.waveform_id.network_code
mpp = pick.time mpp = pick.time
spe = pick.time_errors.uncertainty spe = pick.time_errors.uncertainty
@ -246,8 +249,11 @@ def picksdict_from_picks(evt):
picker = picker.split('smi:local/')[1] picker = picker.split('smi:local/')[1]
except IndexError: except IndexError:
picker = 'manual' # MP MP TODO maybe improve statement picker = 'manual' # MP MP TODO maybe improve statement
if picker == 'None':
picker = 'manual'
try: try:
onsets = picksdict[picker][station] #onsets = picksdict[picker][station]
onsets = picksdict[station]
except KeyError as e: except KeyError as e:
# print(e) # print(e)
onsets = {} onsets = {}
@ -263,18 +269,29 @@ def picksdict_from_picks(evt):
msg = str(e) + ',\n falling back to symmetric uncertainties' msg = str(e) + ',\n falling back to symmetric uncertainties'
lpp = mpp + spe lpp = mpp + spe
epp = mpp - spe epp = mpp - spe
# get onset weight from uncertainty
infile = os.path.join(os.path.expanduser('~'), '.pylot', 'pylot.in')
print('Using default input file {}'.format(infile))
parameter = PylotParameter(infile)
if pick.phase_hint == 'P':
errors = parameter['timeerrorsP']
elif pick.phase_hint == 'S':
errors = parameter['timeerrorsS']
weight = get_quality_class(spe, errors)
warnings.warn(msg) warnings.warn(msg)
phase['mpp'] = mpp phase['mpp'] = mpp
phase['epp'] = epp phase['epp'] = epp
phase['lpp'] = lpp phase['lpp'] = lpp
phase['spe'] = spe phase['spe'] = spe
phase['weight'] = weight
phase['channel'] = channel phase['channel'] = channel
phase['network'] = network phase['network'] = network
phase['picker'] = picker phase['picker'] = picker
phase['filter_id'] = filter_id if filter_id is not None else '' phase['filter_id'] = filter_id if filter_id is not None else ''
onsets[pick.phase_hint] = phase.copy() onsets[pick.phase_hint] = phase.copy()
picksdict[picker][station] = onsets.copy() #picksdict[picker][station] = onsets.copy()
picksdict[station] = onsets.copy()
return picksdict return picksdict
@ -702,6 +719,12 @@ def writephases(arrivals, fformat, filename, parameter=None, eventinfo=None):
syear, stime.month, stime.day, stime.hour, stime.minute, stime.second, eventsource['latitude'], syear, stime.month, stime.day, stime.hour, stime.minute, stime.second, eventsource['latitude'],
cns, eventsource['longitude'], cew, eventsource['depth'], eventinfo.magnitudes[0]['mag'], ifx)) cns, eventsource['longitude'], cew, eventsource['depth'], eventinfo.magnitudes[0]['mag'], ifx))
n = 0 n = 0
# check whether arrivals are dictionaries (autoPyLoT) or pick object (PyLoT)
if isinstance(arrivals, dict) == False:
# convert pick object (PyLoT) into dictionary
evt = ope.Event(resource_id=eventinfo['resource_id'])
evt.picks = arrivals
arrivals = picksdict_from_picks(evt)
for key in arrivals: for key in arrivals:
# P onsets # P onsets
if arrivals[key].has_key('P'): if arrivals[key].has_key('P'):
@ -930,8 +953,8 @@ def merge_picks(event, picks):
def getQualitiesfromxml(xmlnames, ErrorsP, ErrorsS, plotflag=1): def getQualitiesfromxml(xmlnames, ErrorsP, ErrorsS, plotflag=1):
""" """
Script to get onset uncertainties from Quakeml.xml files created by PyLoT. Script to get onset uncertainties from Quakeml.xml files created by PyLoT.
Uncertainties are tranformed into quality classes and visualized via histogram if desired. Uncertainties are tranformed into quality classes and visualized via histogram if desired.
Ludger Küperkoch, BESTEC GmbH, 07/2017 Ludger Küperkoch, BESTEC GmbH, 07/2017
:param xmlnames: list of xml obspy event files containing picks :param xmlnames: list of xml obspy event files containing picks
:type xmlnames: list :type xmlnames: list
:param ErrorsP: time errors of P waves for the four discrete quality classes :param ErrorsP: time errors of P waves for the four discrete quality classes