Escolar Documentos
Profissional Documentos
Cultura Documentos
py
Saved: 03/02/15 1:18:37 PM
1
2
3
Page 1 of 3
Printed For: Cyberoam Training
4
5
6
@author: admin
"""
7
8
9
10
11
12
13
14
15
16
17
18
19
20
'''
import
import
import
import
obspy.taup.taup as t
obspy.core.util.geodetics as l
csv as c
math as m
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
/Users/jm/Desktop/phase_arrival/phasedata.py
Saved: 03/02/15 1:18:37 PM
49
50
Page 2 of 3
Printed For: Cyberoam Training
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
for i in stations:
sta=stations[i]
station_lat=decimal_degree(sta['lat_degree'],sta['lat_min'],0.0)
station_lon=decimal_degree(sta['lon_degree'],sta['lon_min'],0.0)
station_alt=float(sta['altitude'])/1000
for i in earthquakes:
eq=earthquakes[i]
eq_name=eq['Year']+"/"+eq['Month']+"/"+eq['Date']+"/"+eq['Hour']+"
year=int(eq['Year'])
month=int(eq['Month'])
date=int(eq['Date'])
hour=int(eq['Hour'])
minute=int(eq['Minute'])
second=round(float(eq['Second']),1)
isecond=int(m.modf(second)[1])
fsecond=int(round((m.modf(second)[0]),1)*10)
hour2=hour+minute/60+second/60
magnitude=int(eq['Magnitude'])
earthquake_lat=round(float(eq['Latitude']),3)
ilatitude=int(m.modf(earthquake_lat)[1])
flatitude=int(round((m.modf(earthquake_lat)[0]),3)*1000)
earthquake_lon=round(float(eq['Longitude']),3)
ilongitude=int(m.modf(earthquake_lon)[1])
flongitude=int(round((m.modf(earthquake_lon)[0]),3)*1000)
depth=round(float(eq['Depth'])+station_alt,1)
idepth=int(m.modf(depth)[1])
fdepth=int(round((m.modf(depth)[0]),1)*10)
delta=l.locations2degrees(station_lat,station_lon,earthquake_lat,e
tt=t.getTravelTimes(delta,depth,model='ak135')
#
l2="\n {:d} %2d%2d %02d%2d %02.1f L %4.3f %4.3f %3.1f TES 1 %
#
print(l2)
l2=" {:4s} {:>2s}{:>2s} {:>2s}{:>2s} {:>02d}.{:1d} L {:03d}.{:<3d}
.format (eq['Year'],eq['Month'],eq['Date'],eq['Hour'],eq['Minute']
isecond,fsecond,ilatitude,flatitude,ilongitude,flongitude,idepth,f
header=" STAT SP IPHASW D HRMM SECON CODA AMPLIT PERI AZIMU VELO A
header2=" GAP=252
5.40
12.5
16.5 0.0 0.1398E+03
print("\n")
print(l2)
print(header2)
print(header)
94
95
96
/Users/jm/Desktop/phase_arrival/phasedata.py
Saved: 03/02/15 1:18:37 PM
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
Page 3 of 3
Printed For: Cyberoam Training
tmp={}
tmp['earth_quake']=eq_name
tmp['phase_name']=ph['phase_name']
tmp['arrival_time']=ph['time']
tmp['station_code']=sta['station_code']
tmp['delta']=delta
tmp['depth']=depth
tmp['hour']=eq['Hour']
tmp['minute']=eq['Minute']
tmp['second']=eq['Second']
tmp['latitude']=earthquake_lat
tmp['longitude']=earthquake_lon
print(" {:4s}
{:>3s} " .format (sta['station_code'],ph['
travel_times[iid]=tmp
iid=iid+1
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
print(" 2012 1 1 0037 12.4 L 24.227 94.575 15.0 TES 1 0.1 3.4LTES
# STAT SP IPHASW D HRMM SECON CODA AMPLIT PERI AZIMU VELO AIN AR TRES W
# JNVA2SZ EPb
21 8 21.01
#Write the result to csv file
with open('phase_arrival.csv', 'w') as f:
for i in travel_times:
if i==0:
w = c.DictWriter(f, travel_times[i].keys())
w.writeheader()
w.writerow(travel_times[i])
else:
w.writerow(travel_times[i])