-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5-run_HypoInverse.py
More file actions
executable file
·224 lines (200 loc) · 9.77 KB
/
5-run_HypoInverse.py
File metadata and controls
executable file
·224 lines (200 loc) · 9.77 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import obspy
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import subprocess
import glob
from obspy import read, UTCDateTime
import os
import json
import math
import yaml
from pathlib import Path
import shutil
import re
import argparse
def create_station_file(cfgs):
real_sta_file_path = cfgs['REAL']['save_sta']
real_sta_file = open(real_sta_file_path, 'r')
hypo_sta_file_path = cfgs['HypoInverse']['save_sta']
hypo_sta_file = open(hypo_sta_file_path, 'w')
for line in real_sta_file.readlines():
splits = line.split(' ')
lat = '{:.5f}'.format(float(splits[1]))
lon = '{:.5f}'.format(float(splits[0]))
code = splits[2]+'.'+splits[3]
ele = '{:.2f}'.format(float(splits[-1])*1000.0)
pad = '-1'
hypo_line = '\t'.join([code,lat,lon,ele,pad]) + '\n'
hypo_sta_file.write(hypo_line)
real_sta_file.close()
hypo_sta_file.close()
return
def create_pha_file(cfgs):
# real_event_dict_path = cfgs['REAL']['seqt_catalog_dir'] + cfgs['HypoInverse']['seqt_event_dict']
# real_event_dict = np.load(real_event_dict_path,allow_pickle=True )[()]
#
# hypo_pha_file_path = cfgs['HypoInverse']['save_pha_eqt']
# hypo_pha_file = open(hypo_pha_file_path,'w')
#
# for e_key in real_event_dict.keys():
# ot = str(real_event_dict[e_key]['REAL_TIME'])
# lat = '{:5f}'.format(real_event_dict[e_key]['REAL_LAT'])
# lon = '{:5f}'.format(real_event_dict[e_key]['REAL_LON'])
# dep = '{:5f}'.format(real_event_dict[e_key]['REAL_DEP'])
# mag = '1.0'
# # create event line
# event_line = ','.join([ot,lat,lon,dep,mag]) + '\n'
# hypo_pha_file.write(event_line)
#
# temp_pick_dict = dict()
# for pick_info in real_event_dict[e_key]['Picks']:
# code = pick_info[0]
# pick_type = pick_info[1]
# pick_time = pick_info[2]
#
# if code in temp_pick_dict.keys():
# temp_pick_dict[code][pick_type] = pick_time
# else:
# temp_pick_dict[code] = dict()
# temp_pick_dict[code]['P'] = -1
# temp_pick_dict[code]['S'] = -1
# temp_pick_dict[code][pick_type] = pick_time
#
# for pick_key in temp_pick_dict.keys():
# net = pick_key.split('.')[0]
# sta = pick_key.split('.')[1]
# tp = str(temp_pick_dict[pick_key]['P'])
# ts = str(temp_pick_dict[pick_key]['S'])
# pick_line = ','.join([net,sta,tp,ts]) + ',-1,-1,-1\n'
# hypo_pha_file.write(pick_line)
#
# hypo_pha_file.close()
real_event_dict_path = cfgs['REAL']['seqt_catalog_dir'] + cfgs['HypoInverse']['seqt_event_dict']
real_event_dict = np.load(real_event_dict_path,allow_pickle=True )[()]
hypo_pha_file_path = cfgs['HypoInverse']['save_pha_seqt']
hypo_pha_file = open(hypo_pha_file_path,'w')
for e_key in real_event_dict.keys():
ot = str(real_event_dict[e_key]['REAL_TIME'])
lat = '{:5f}'.format(real_event_dict[e_key]['REAL_LAT'])
lon = '{:5f}'.format(real_event_dict[e_key]['REAL_LON'])
dep = '{:5f}'.format(real_event_dict[e_key]['REAL_DEP'])
mag = '1.0'
# create event line
event_line = ','.join([ot,lat,lon,dep,mag]) + '\n'
hypo_pha_file.write(event_line)
temp_pick_dict = dict()
for pick_info in real_event_dict[e_key]['Picks']:
code = pick_info[0]
pick_type = pick_info[1]
pick_time = pick_info[2]
if code in temp_pick_dict.keys():
temp_pick_dict[code][pick_type] = pick_time
else:
temp_pick_dict[code] = dict()
temp_pick_dict[code]['P'] = -1
temp_pick_dict[code]['S'] = -1
temp_pick_dict[code][pick_type] = pick_time
for pick_key in temp_pick_dict.keys():
net = pick_key.split('.')[0]
sta = pick_key.split('.')[1]
tp = str(temp_pick_dict[pick_key]['P'])
ts = str(temp_pick_dict[pick_key]['S'])
pick_line = ','.join([net,sta,tp,ts]) + ',-1,-1,-1\n'
hypo_pha_file.write(pick_line)
hypo_pha_file.close()
# real_event_dict_path = cfgs['REAL']['picknet_catalog_dir'] + cfgs['HypoInverse']['picknet_event_dict']
# real_event_dict = np.load(real_event_dict_path,allow_pickle=True )[()]
#
# hypo_pha_file_path = cfgs['HypoInverse']['save_pha_picknet']
# hypo_pha_file = open(hypo_pha_file_path,'w')
#
# for e_key in real_event_dict.keys():
# ot = str(real_event_dict[e_key]['REAL_TIME'])
# lat = '{:5f}'.format(real_event_dict[e_key]['REAL_LAT'])
# lon = '{:5f}'.format(real_event_dict[e_key]['REAL_LON'])
# dep = '{:5f}'.format(real_event_dict[e_key]['REAL_DEP'])
# mag = '1.0'
# # create event line
# event_line = ','.join([ot,lat,lon,dep,mag]) + '\n'
# hypo_pha_file.write(event_line)
#
# temp_pick_dict = dict()
# for pick_info in real_event_dict[e_key]['Picks']:
# code = pick_info[0]
# pick_type = pick_info[1]
# pick_time = pick_info[2]
#
# if code in temp_pick_dict.keys():
# temp_pick_dict[code][pick_type] = pick_time
# else:
# temp_pick_dict[code] = dict()
# temp_pick_dict[code]['P'] = -1
# temp_pick_dict[code]['S'] = -1
# temp_pick_dict[code][pick_type] = pick_time
#
# for pick_key in temp_pick_dict.keys():
# net = pick_key.split('.')[0]
# sta = pick_key.split('.')[1]
# tp = str(temp_pick_dict[pick_key]['P'])
# ts = str(temp_pick_dict[pick_key]['S'])
# pick_line = ','.join([net,sta,tp,ts]) + ',-1,-1,-1\n'
# hypo_pha_file.write(pick_line)
#
# hypo_pha_file.close()
return
if __name__ == '__main__':
# parser = argparse.ArgumentParser(description='00_data_download')
# parser.add_argument('--config-file', dest='config_file',
# type=str, help='Configuration file path',default='./Configuration_Parameters.yaml')
# args = parser.parse_args()
# cfgs = yaml.load(open(args.config_file,'r'),Loader=yaml.SafeLoader)
parser = argparse.ArgumentParser(description='5-run_HypoInverse')
parser.add_argument('--config-file', dest='config_file', type=str, help='Configuration file path',
default='./Configuration_Parameters.json')
args = parser.parse_args()
with open(args.config_file, 'r') as f:
cfgs = json.load(f)
task_dir = './' + cfgs['Project'] + '/'
# task_dir = './' + cfgs['Project'] + '/'
os.chdir(task_dir)
create_station_file(cfgs)
create_pha_file(cfgs)
#
# os.rename(cfgs['HypoInverse']['save_sta'], '../HypoInverse_scripts/input/HYPO.sta')
# os.rename(cfgs['HypoInverse']['save_pha_eqt'], '../HypoInverse_scripts/input/HYPO.pha')
# os.chdir('../HypoInverse_scripts')
# subprocess.call(['python', 'run_hyp.py'])
#
# hypo_output = os.system('python run_hyp.py')
# print('STATUS: {}'.format(hypo_output))
# os.chdir('..')
# os.chdir(task_dir)
# os.rename( '../HypoInverse_scripts/output/example.ctlg', '{}/eqt_hypoInverse.ctlg'.format(cfgs['REAL']['eqt_catalog_dir']))
# os.rename( '../HypoInverse_scripts/output/example.pha','{}/eqt_hypoInverse.pha'.format(cfgs['REAL']['eqt_catalog_dir']))
# os.rename( '../HypoInverse_scripts/output/example.sum','{}/eqt_hypoInverse.sum'.format(cfgs['REAL']['eqt_catalog_dir']))
# os.rename( '../HypoInverse_scripts/output/example_good.csv','{}/eqt_hypoInverse.good'.format(cfgs['REAL']['eqt_catalog_dir']))
# os.rename( '../HypoInverse_scripts/output/example_bad.csv','./{}/eqt_hypoInverse.bad'.format(cfgs['REAL']['eqt_catalog_dir']))
os.rename(cfgs['HypoInverse']['save_pha_seqt'], '../HypoInverse_scripts/input/HYPO.pha')
os.chdir('../HypoInverse_scripts')
# subprocess.run(['python', './run_hyp.py'], )
hypo_output = os.system('python run_hyp.py')
print('STATUS: {}'.format(hypo_output))
os.chdir('..')
os.chdir(task_dir)
os.rename( '../HypoInverse_scripts/output/example.ctlg', '{}/seqt_hypoInverse.ctlg'.format(cfgs['REAL']['seqt_catalog_dir']))
os.rename( '../HypoInverse_scripts/output/example.pha','{}/seqt_hypoInverse.pha'.format(cfgs['REAL']['seqt_catalog_dir']))
os.rename( '../HypoInverse_scripts/output/example.sum','{}/seqt_hypoInverse.sum'.format(cfgs['REAL']['seqt_catalog_dir']))
os.rename( '../HypoInverse_scripts/output/example_good.csv','{}/seqt_hypoInverse.good'.format(cfgs['REAL']['seqt_catalog_dir']))
os.rename( '../HypoInverse_scripts/output/example_bad.csv','{}/seqt_hypoInverse.bad'.format(cfgs['REAL']['seqt_catalog_dir']))
# os.rename(cfgs['HypoInverse']['save_pha_picknet'], '../HypoInverse_scripts/input/HYPO.pha')
# os.chdir('../HypoInverse_scripts')
# hypo_output = os.system('python run_hyp.py')
# print('STATUS: {}'.format(hypo_output))
# os.chdir('..')
# os.chdir(task_dir)
# os.rename( '../HypoInverse_scripts/output/example.ctlg', '{}/picknet_hypoInverse.ctlg'.format(cfgs['REAL']['picknet_catalog_dir']))
# os.rename( '../HypoInverse_scripts/output/example.pha','{}/picknet_hypoInverse.pha'.format(cfgs['REAL']['picknet_catalog_dir']))
# os.rename( '../HypoInverse_scripts/output/example.sum','{}/picknet_hypoInverse.sum'.format(cfgs['REAL']['picknet_catalog_dir']))
# os.rename( '../HypoInverse_scripts/output/example_good.csv','{}/picknet_hypoInverse.good'.format(cfgs['REAL']['picknet_catalog_dir']))
# os.rename( '../HypoInverse_scripts/output/example_bad.csv','{}/picknet_hypoInverse.bad'.format(cfgs['REAL']['picknet_catalog_dir']))