From 0f8b228931e0ba43d83e0a7d1348e611966ae0f1 Mon Sep 17 00:00:00 2001 From: Sebastian Wehling-Benatelli Date: Thu, 5 Nov 2015 09:16:11 +0100 Subject: [PATCH] [new] module "nll" containing utility function to handle NonLinLoc input and output as well as execution of the external program from python --- pylot/core/loc/nll.py | 60 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 pylot/core/loc/nll.py diff --git a/pylot/core/loc/nll.py b/pylot/core/loc/nll.py new file mode 100644 index 00000000..f411906c --- /dev/null +++ b/pylot/core/loc/nll.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import subprocess +from obspy.core.event import readEvents +from pylot.core.pick.utils import writephases + +def picksExport(picks, phasefile): + ''' + Take dictionary and exports picking data to a NLLOC-obs without creating an ObsPy event object. + :param picks: picking data dictionary + :type picks: dict + :param phasefile: complete path to the exporting obs file + :type phasefile: str + ''' + # write phases to NLLoc-phase file + writephases(picks, 'NLLoc', phasefile) + +def modfiyInputFile(fn, root, outpath, phasefile, tttable): + ''' + + :param fn: + :param root: + :param outpath: + :param phasefile: + :param tttable: + :return: + ''' + # For locating the event we have to modify the NLLoc-control file! + # create comment line for NLLoc-control file NLLoc-output file + print ("Modifying NLLoc-control file %s ..." % fn) + nllocout = '%s/loc/%s_%s' % (root, outpath) + locfiles = 'LOCFILES %s NLLOC_OBS %s %s 0' % (phasefile, tttable, nllocout) + + # modification of NLLoc-control file + nllfile = open(fn, 'r') + filedata = nllfile.read() + if filedata.find(locfiles) < 0: + # replace old command + filedata = filedata.replace('LOCFILES', locfiles) + nllfile = open(fn, 'w') + nllfile.write(filedata) + nllfile.close() + +def locate(call, fnin): + ''' + Takes paths to NLLoc executable and input parameter file and starts the location calculation. + :param call: full path to NLLoc executable + :type call: str + :param fnin: full path to input parameter file + :type fnin: str + ''' + # locate the event + subprocess.call([call, fnin]) + +def readLocation(fn): + pass + +if __name__=='__main__': + pass