-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgetamps.py
executable file
·52 lines (43 loc) · 1.92 KB
/
getamps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
#stdlib imports
import sys
import argparse
import glob
import os.path
#third party or local imports
from smtools.trace2xml import amps2xml
from smtools.taiwan import readTaiwan
SUPPORTED_NETWORKS = {'taiwan':'Taiwan Central Weather Bureau'}
def main(args):
if args.listSources:
print('%-15s\t%-40s' % ('Network','Description'))
print('------------------------------------------')
for key,value in SUPPORTED_NETWORKS.items():
print('%-15s\t%-40s' % (key,value))
sys.exit(0)
if args.folder:
outfolder = args.folder
else:
outfolder = os.getcwd()
if not args.inputFolder:
print('Must specify input folder with -i.')
sys.exit(1)
if args.source == 'taiwan':
txtfiles = glob.glob(os.path.join(args.inputFolder,'*.txt'))
for txtfile in txtfiles:
stationlist = readTaiwan(txtfile)
datafile,tag = amps2xml(stationlist,outfolder,'CWB')
print('Created data file %s.' % datafile)
sys.exit(0)
if __name__ == '__main__':
desc = '''Convert peak amplitude data from various sources into ShakeMap XML data file format.'''
parser = argparse.ArgumentParser(description=desc,
formatter_class=argparse.RawDescriptionHelpFormatter,)
parser.add_argument('source',help='Specify strong motion data source.',choices=['taiwan'])
parser.add_argument('-s','-sources',dest='listSources',action='store_true',default=False,
help='Describe various sources for strong motion data')
parser.add_argument('-i','-inputfolder',dest='inputFolder',
help='process files from an input folder.')
parser.add_argument('-f','-folder',dest='folder',help='Specify output station folder destination (defaults to event input folder or current working directory)')
pargs = parser.parse_args()
main(pargs)