-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_green_info.py
74 lines (69 loc) · 2.57 KB
/
read_green_info.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
73
74
import os
import numpy as np
from pygrnwang.utils import get_number_in_line
def read_green_info_spgrn2020(path_greenfunc: str, green_depth: float) -> dict:
"""
read GreenInfo.dat
:param path_greenfunc:
:param green_depth: unit km
:return: {
"time_window": time_window, type float, unit s
"sampling_interval": sampling_interval, type float, unit s
"samples_num": int(samples_num), type int
"dist_list": dist_list, type list, unit km
}
"""
with open(
os.path.join(path_greenfunc, "GreenInfo%.1f.dat" % green_depth), "r"
) as fr:
lines = fr.readlines()
[time_window, sampling_interval, samples_num] = get_number_in_line(lines[6])
number_of_distance = get_number_in_line(lines[9])[0]
dist_list = []
for i in range(int(np.ceil(number_of_distance / 5))):
temp = get_number_in_line(lines[10 + i])
for item in temp:
dist_list.append(item)
return {
"time_window": time_window,
"sampling_interval": sampling_interval,
"samples_num": int(samples_num),
"dist_list": dist_list,
}
def read_green_info_qseis06(path_greenfunc: str, green_depth: float) -> dict:
"""
read GreenInfo.dat
:param path_greenfunc:
:param green_depth: unit km
:return: {
"time_window": time_window, type float, unit s
"sampling_interval": sampling_interval, type float, unit s
"samples_num": int(samples_num), type int
"dist_range": [dist_min, dist_max], type list, unit deg
"delta_dist": delta_dist, type float, unit deg
"N_dist": len(dist_list), type int
"N_dist_group": type int
}
"""
with open(
os.path.join(path_greenfunc, "GreenInfo%.1f.dat" % green_depth), "r"
) as fr:
lines = fr.readlines()
time_window = get_number_in_line(lines[1])[0]
sampling_num = int(get_number_in_line(lines[2])[0])
sampling_interval = get_number_in_line(lines[3])[0]
dist_range = get_number_in_line(lines[4])
delta_dist = get_number_in_line(lines[5])[0]
N_dist = int(get_number_in_line(lines[6])[0])
N_dist_group = int(get_number_in_line(lines[7])[0])
N_each_group = int(get_number_in_line(lines[8])[0])
return {
"time_window": time_window,
"sampling_num": sampling_num,
"sampling_interval": sampling_interval,
"dist_range": dist_range,
"delta_dist": delta_dist,
"N_dist": N_dist,
"N_dist_group": N_dist_group,
"N_each_group": N_each_group,
}