-
Notifications
You must be signed in to change notification settings - Fork 2
/
specfem_helper.py
44 lines (36 loc) · 1.08 KB
/
specfem_helper.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
# python specfem_util_test.py
import obspy
import wfdiff.specfem_helper as sh
import shutil
import os
event_file = '../CMTSOLUTION'
stations_file = '../STATIONS'
specfem_wf = './*semd'
#-----------------------------------------------------------------
# Read CMTSOLUTION file
cat = obspy.read_events(event_file)
event = cat[0]
eid = event.origins[0].time.strftime("%Y%m%d%H%M%S%f")[:-3]
# Read specfem station file as pandas dataframe
stn = sh.read_specfem_stations_file(stations_file)
# Read specfem files
st = sh.read_specfem_files(specfem_wf)
# Add backazimuth. Needed for rotation
st = sh.add_event_station_info(st, event, stn)
# Add sac metadata
st = sh.add_event_station_sac_header(st, event, stn)
st.resample(50)
# Rotate to RTZ
print('---> Rotating to RTZ')
st.rotate('NE->RT')
# save RTZ as sac
RTZ_dir = eid +'_RTZ'
sh.save_as_sac(st, RTZ_dir)
#TODO:Check this part of code to decide if keep or delete it
#files = os.listdir()
#for file in files:
# a = file[:-4]
# b = a[-1]
# c = 'Mtt'
# print(a[:-3]+'.'+b+'.'+c+'.sac')
# shutil.move(file, a[:-3]+'.'+b+'.'+c+'.sac')