-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_tpts_table.py
53 lines (46 loc) · 1.62 KB
/
read_tpts_table.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
import os
import struct
from pygrnwang.utils import find_nearest_dichotomy
def read_tpts_table(path_greenfunc: str, dist_in_km: float, green_info: dict) -> dict:
"""
:param path_greenfunc:
:param dist_in_km:
:param green_info:
:return: {
"p_onset": tp_onset,
"p_takeoff": tp_takeoff,
"p_slowness": tp_slowness,
"s_onset": ts_onset,
"s_takeoff": ts_takeoff,
"s_slowness": ts_slowness
}
"""
# {green_function_distance,
# {onset [s], takeoff [deg], slowness [s/m]}}
dist_green_num = find_nearest_dichotomy(dist_in_km, green_info["dist_list"])[1]
# print(green_info['dist_list'][dist_green_num])
start_count = 4 + dist_green_num * 12
def seek_time_table(start_count_in, phase):
if phase == "P":
fname = "tptable.dat"
elif phase == "S":
fname = "tstable.dat"
else:
raise ValueError("phase must be P or S")
fr = open(os.path.join(path_greenfunc, fname), "rb")
fr.seek(start_count_in)
t_onset = struct.unpack("f", fr.read(4))[0]
t_takeoff = struct.unpack("f", fr.read(4))[0]
t_slowness = struct.unpack("f", fr.read(4))[0]
fr.close()
return [t_onset, t_takeoff, t_slowness]
[tp_onset, tp_takeoff, tp_slowness] = seek_time_table(start_count, "P")
[ts_onset, ts_takeoff, ts_slowness] = seek_time_table(start_count, "S")
return {
"p_onset": tp_onset,
"p_takeoff": tp_takeoff,
"p_slowness": tp_slowness,
"s_onset": ts_onset,
"s_takeoff": ts_takeoff,
"s_slowness": ts_slowness,
}