Enabled writing for FOCMEC output.

This commit is contained in:
Ludger Küperkoch 2020-07-23 16:51:05 +02:00
parent 003ba76650
commit c7d8569105
4 changed files with 25 additions and 7 deletions

View File

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

View File

@ -11,8 +11,9 @@ from obspy.io.sac import SacIOError
from PySide.QtGui import QMessageBox from PySide.QtGui import QMessageBox
import pylot.core.loc.velest as velest import pylot.core.loc.velest as velest
import pylot.core.loc.focmec as focmec
from pylot.core.io.phases import readPILOTEvent, picks_from_picksdict, \ from pylot.core.io.phases import readPILOTEvent, picks_from_picksdict, \
picksdict_from_pilot, merge_picks picksdict_from_pilot, merge_picks, PylotParameter
from pylot.core.util.errors import FormatError, OverwriteError from pylot.core.util.errors import FormatError, OverwriteError
from pylot.core.util.event import Event from pylot.core.util.event import Event
from pylot.core.util.obspyDMT_interface import qml_from_obspyDMT from pylot.core.util.obspyDMT_interface import qml_from_obspyDMT
@ -246,7 +247,7 @@ class Data(object):
""" """
Export event to file Export event to file
:param fnout: basename of file :param fnout: basename of file
:param fnext: file extension, xml, cnv, obs :param fnext: file extension, xml, cnv, obs, focmec
:param fcheck: check and delete existing information :param fcheck: check and delete existing information
can be a str or a list of strings of ['manual', 'auto', 'origin', 'magnitude'] can be a str or a list of strings of ['manual', 'auto', 'origin', 'magnitude']
""" """
@ -359,6 +360,15 @@ class Data(object):
except KeyError as e: except KeyError as e:
raise KeyError('''{0} export format raise KeyError('''{0} export format
not implemented: {1}'''.format(evtformat, e)) not implemented: {1}'''.format(evtformat, e))
if fnext == '.focmec':
try:
infile = os.path.join(os.path.expanduser('~'), '.pylot', 'pylot.in')
print('Using default input file {}'.format(infile))
parameter = PylotParameter(infile)
focmec.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): def getComp(self):
""" """

View File

@ -287,6 +287,7 @@ def picksdict_from_picks(evt):
phase['channel'] = channel phase['channel'] = channel
phase['network'] = network phase['network'] = network
phase['picker'] = picker phase['picker'] = picker
phase['fm'] = 'N'
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()
@ -481,7 +482,7 @@ def writephases(arrivals, fformat, filename, parameter=None, eventinfo=None):
Function of methods to write phases to the following standard file Function of methods to write phases to the following standard file
formats used for locating earthquakes: formats used for locating earthquakes:
HYPO71, NLLoc, VELEST, HYPOSAT, and hypoDD HYPO71, NLLoc, VELEST, HYPOSAT, FOCMEC, and hypoDD
:param arrivals:dictionary containing all phase information including :param arrivals:dictionary containing all phase information including
station ID, phase, first motion, weight (uncertainty), ... station ID, phase, first motion, weight (uncertainty), ...
@ -489,7 +490,7 @@ def writephases(arrivals, fformat, filename, parameter=None, eventinfo=None):
:param fformat: chosen file format (location routine), :param fformat: chosen file format (location routine),
choose between NLLoc, HYPO71, HYPOSAT, VELEST, choose between NLLoc, HYPO71, HYPOSAT, VELEST,
HYPOINVERSE, and hypoDD HYPOINVERSE, FOCMEC, and hypoDD
:type fformat: str :type fformat: str
:param filename: full path and name of phase file :param filename: full path and name of phase file
@ -799,6 +800,12 @@ def writephases(arrivals, fformat, filename, parameter=None, eventinfo=None):
eventsource['depth'] / 1000, eventsource['depth'] / 1000,
eventinfo.magnitudes[0]['mag'])) eventinfo.magnitudes[0]['mag']))
picks = eventinfo.picks picks = eventinfo.picks
# 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:
if arrivals[key].has_key('P'): if arrivals[key].has_key('P'):
if arrivals[key]['P']['weight'] < 4 and arrivals[key]['P']['fm'] is not None: if arrivals[key]['P']['weight'] < 4 and arrivals[key]['P']['fm'] is not None:

View File

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