pylot/autoPyLoT.py

127 lines
4.7 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import argparse
import glob
import matplotlib.pyplot as plt
from obspy.core import read
from pylot.core.util import _getVersionString
from pylot.core.read import Data, AutoPickParameter
from pylot.core.pick.run_autopicking import run_autopicking
from pylot.core.util.structure import DATASTRUCTURE
__version__ = _getVersionString()
#METHOD = {'HOS':HOScf, 'AIC':AICcf}
def autoPyLoT(inputfile):
'''
Determine phase onsets automatically utilizing the automatic picking
algorithm by Kueperkoch et al. 2011.
:param inputfile: path to the input file containing all parameter
information for automatic picking (for formatting details, see.
`~pylot.core.read.input.AutoPickParameter`
:type inputfile: str
:return:
.. rubric:: Example
'''
# reading parameter file
parameter = AutoPickParameter(inputfile)
data = Data()
# getting information on data structure
if parameter.hasParam('datastructure'):
datastructure = DATASTRUCTURE[parameter.getParam('datastructure')]()
dsfields = {'root':parameter.getParam('rootpath'),
'dpath':parameter.getParam('datapath'),
'dbase':parameter.getParam('database')}
2015-05-20 09:59:06 +02:00
exf = ['root', 'dpath', 'dbase']
if parameter.hasParam('eventID'):
dsfields['eventID'] = parameter.getParam('eventID')
exf.append('eventID')
datastructure.modifyFields(**dsfields)
2015-05-20 09:59:06 +02:00
datastructure.setExpandFields(exf)
# get streams
# read each event in database
datapath = datastructure.expandDataPath()
2015-05-20 09:59:06 +02:00
if not parameter.hasParam('eventID'):
for event in [events for events in glob.glob(os.path.join(datapath, '*')) if os.path.isdir(events)]:
data.setWFData(glob.glob(os.path.join(datapath, event, '*')))
print 'Working on event %s' %event
print data
wfdat = data.getWFData() # all available streams
##########################################################
# !automated picking starts here!
procstats = []
for i in range(len(wfdat)):
stationID = wfdat[i].stats.station
#check if station has already been processed
if stationID not in procstats:
procstats.append(stationID)
#find corresponding streams
statdat = wfdat.select(station=stationID)
run_autopicking(statdat, parameter)
2015-06-02 13:42:44 +02:00
print '------------------------------------------'
print '-----Finished event %s!-----' % event
print '------------------------------------------'
#for single event processing
2015-05-20 09:59:06 +02:00
else:
2015-06-02 13:43:39 +02:00
data.setWFData(glob.glob(os.path.join(datapath, parameter.getParam('eventID'), '*')))
print 'Working on event ', parameter.getParam('eventID')
2015-05-20 10:56:53 +02:00
print data
wfdat = data.getWFData() # all available streams
##########################################################
# !automated picking starts here!
procstats = []
for i in range(len(wfdat)):
stationID = wfdat[i].stats.station
#check if station has already been processed
if stationID not in procstats:
procstats.append(stationID)
#find corresponding streams
statdat = wfdat.select(station=stationID)
run_autopicking(statdat, parameter)
2015-06-02 13:42:44 +02:00
print '------------------------------------------'
print '-------Finished event %s!-------' % parameter.getParam('eventID')
print '------------------------------------------'
if __name__ == "__main__":
# parse arguments
parser = argparse.ArgumentParser(
description='''autoPyLoT automatically picks phase onset times using higher order statistics,
autoregressive prediction and AIC''')
parser.add_argument('-i', '-I', '--inputfile', type=str,
action='store',
help='''full path to the file containing the input
parameters for autoPyLoT''',
default=os.path.join(os.path.expanduser('~'), '.pylot',
'autoPyLoT.in')
)
parser.add_argument('-v', '-V', '--version', action='version',
version='autoPyLoT ' + __version__,
help='show version information and exit')
cla = parser.parse_args()
autoPyLoT(str(cla.inputfile))