-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcompile_WA_eqSource_data.py
72 lines (59 loc) · 2.49 KB
/
compile_WA_eqSource_data.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 13 15:33:56 2015
@author: tallen
"""
from os import path, listdir
evdatafile = 'WA.event_pars.txt'
lines = open(evdatafile).readlines()
events = []
for line in lines:
dat = line.strip().split()
evdict = {'date': dat[0], 'hhmm': dat[1], 'lon': float(dat[2]), \
'lat': float(dat[3]), 'dep': float(dat[4]), \
'mw': float(dat[6])}
evdict['evid'] = evdict['date'].replace('-','') + evdict['hhmm']
events.append(evdict)
''' now look for stns used '''
# parse eqSource event dat files
recs = []
for event in events:
evdatfile = path.join('..','..','eqSource','Events',event['evid'][0:4],event['evid'][4:6], \
event['evid'][6:8] + '_' + event['evid'][8:] + '.dat')
# now read event data file
evlines = open(evdatfile).readlines()
# now get sites used
readsites = False
for el in evlines:
if el.startswith('\n'):
readsites = False
# get sites here
if readsites == True:
stndat = el.strip().split()
if stndat[0].endswith('A') or stndat[0].endswith('V'):
rec = {'evid': event['evid'], 'stn': stndat[0][0:-1], \
'rawstn': stndat[0], 'rhyp': float(stndat[1])}
else:
rec = {'evid': event['evid'], 'stn': stndat[0], \
'rawstn': stndat[0], 'rhyp': float(stndat[1])}
recs.append(rec)
if el.startswith('Site'):
readsites = True
''' now look for files in waves folder '''
for rec in recs:
# look in path for file
evpath = path.join('..','..','eqSource','Waves',rec['evid'][0:4],rec['evid'][4:6], \
rec['evid'][6:8] + '_' + rec['evid'][8:])
files = listdir(evpath)
for f in files:
if f.find(rec['stn']) >= 0:
if f.endswith('.txt') or f.endswith('.G') or f.endswith('.S'):
rec['wavpath'] = path.join('..','..','eqSource','Waves',rec['evid'][0:4], \
rec['evid'][4:6],rec['evid'][6:8] + '_' + rec['evid'][8:],f)
''' now parse data files '''
from readwaves import return_data
for i, rec in enumerate(recs):
# check file format
allsta, recs[i]['comps'], allrecdate, allsec, recs[i]['sps'], recs[i]['data'], \
recs[i]['nsamp'], fmt = return_data(rec['wavpath'])
print fmt