Added output for hypoDD.

This commit is contained in:
Ludger Küperkoch 2020-07-28 13:08:25 +02:00
parent 1f6a44eeef
commit df6a6c1c71
5 changed files with 35 additions and 14 deletions

View File

@ -200,7 +200,7 @@ class MainWindow(QMainWindow):
settings.setValue('useGuiFilter', False)
if settings.value('output/Format', None) is None:
outformat = QInputDialog.getText(self,
"Enter output format (*.xml, *.cnv, *.obs, *.focmec):",
"Enter output format (*.xml, *.cnv, *.obs, *.focmec, *.pha):",
"Format")
settings.setValue("output/Format", outformat)
if settings.value('autoFilter', None) is None:
@ -1481,7 +1481,7 @@ class MainWindow(QMainWindow):
self.set_fname(self.get_data().getEventFileName(), type)
return self.get_fnames(type)
def saveData(self, event=None, directory=None, outformats=['.xml', '.cnv', '.obs', '.focmec']):
def saveData(self, event=None, directory=None, outformats=['.xml', '.cnv', '.obs', '.focmec', '.pha']):
'''
Save event data to directory with specified output formats.
:param event: PyLoT Event, if not set current event will be used

View File

@ -12,6 +12,7 @@ from PySide.QtGui import QMessageBox
import pylot.core.loc.velest as velest
import pylot.core.loc.focmec as focmec
import pylot.core.loc.hypodd as hypodd
from pylot.core.io.phases import readPILOTEvent, picks_from_picksdict, \
picksdict_from_pilot, merge_picks, PylotParameter
from pylot.core.util.errors import FormatError, OverwriteError
@ -232,22 +233,27 @@ class Data(object):
picks = event.picks
# remove existing picks
for j, pick in reversed(list(enumerate(picks))):
if picktype in str(pick.method_id.id):
picks.pop(j)
checkflag = 1
try:
if picktype in str(pick.method_id.id):
picks.pop(j)
checkflag = 1
except AttributeError as e:
msg = '{}'.format(e)
print(e)
checkflag = 0
if checkflag:
print("Found %s pick(s), remove them and append new picks to catalog." % picktype)
# append new picks
for pick in self.get_evt_data().picks:
if picktype in str(pick.method_id.id):
picks.append(pick)
# append new picks
for pick in self.get_evt_data().picks:
if picktype in str(pick.method_id.id):
picks.append(pick)
def exportEvent(self, fnout, fnext='.xml', fcheck='auto', upperErrors=None):
"""
Export event to file
:param fnout: basename of file
:param fnext: file extension, xml, cnv, obs, focmec
:param fnext: file extensions xml, cnv, obs, focmec, or/and pha
:param fcheck: check and delete existing information
can be a str or a list of strings of ['manual', 'auto', 'origin', 'magnitude']
"""
@ -369,6 +375,15 @@ class Data(object):
except KeyError as e:
raise KeyError('''{0} export format
not implemented: {1}'''.format(evtformat, e))
if fnext == '.pha':
try:
infile = os.path.join(os.path.expanduser('~'), '.pylot', 'pylot.in')
print('Using default input file {}'.format(infile))
parameter = PylotParameter(infile)
hypodd.export(picks_copy, fnout + fnext, parameter, eventinfo=self.get_evt_data())
except KeyError as e:
raise KeyError('''{0} export format
not implemented: {1}'''.format(evtformat, e))
def getComp(self):
"""

View File

@ -291,7 +291,6 @@ def picksdict_from_picks(evt):
phase['filter_id'] = filter_id if filter_id is not None else ''
onsets[pick.phase_hint] = phase.copy()
#picksdict[picker][station] = onsets.copy()
picksdict[station] = onsets.copy()
return picksdict
@ -757,7 +756,7 @@ def writephases(arrivals, fformat, filename, parameter=None, eventinfo=None):
fid.write('%-4sS%d%6.2f\n' % (stat, Sweight, Srt))
fid.close()
elif fformat == 'hypoDD':
elif fformat == 'HYPODD':
print("Writing phases to %s for hypoDD" % filename)
fid = open("%s" % filename, 'w')
# get event information needed for hypoDD-phase file
@ -770,6 +769,12 @@ def writephases(arrivals, fformat, filename, parameter=None, eventinfo=None):
stime.year, stime.month, stime.day, stime.hour, stime.minute, stime.second,
eventsource['latitude'], eventsource['longitude'], eventsource['depth'] / 1000,
eventinfo.magnitudes[0]['mag'], eventsource['quality']['standard_error'], hddID))
# 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:
if arrivals[key].has_key('P'):
# P onsets

View File

@ -25,4 +25,4 @@ def export(picks, fnout, parameter, eventinfo):
:type eventinfo: list object
'''
# write phases to hypoDD-phase file
writephases(picks, 'hypoDD', fnout, parameter, eventinfo)
writephases(picks, 'HYPODD', fnout, parameter, eventinfo)

View File

@ -37,6 +37,7 @@ TIMEERROR_DEFAULTS = os.path.join(os.path.expanduser('~'),
OUTPUTFORMATS = {'.xml': 'QUAKEML',
'.cnv': 'CNV',
'.obs': 'NLLOC_OBS',
'.focmec': 'FOCMEC'}
'.focmec': 'FOCMEC',
'.pha': 'HYPODD'}
LOCTOOLS = dict(nll=nll, hyposat=hyposat, velest=velest, hypo71=hypo71, hypodd=hypodd)