-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_sgy.py
87 lines (73 loc) · 2.64 KB
/
read_sgy.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
75
76
77
78
79
80
81
82
83
84
85
86
import glob
from obspy import read
import obspy
import utm
import pandas as pd
data_folder = "./Data"
coord = pd.read_csv("Data/coordinates.csv",header=0)
sgy_files = list(glob.iglob(data_folder+"/*.sgy"))
for sgy_file in sgy_files:
print(sgy_file)
node = sgy_file.split("_")[7]
lon,lat=coord[coord.NODE==node].LONGITUDE.iloc[0],coord[coord.NODE==node].LATITUDE.iloc[0]
st = read(sgy_file,format="SEGY",unpack_trace_headers=True)
rec_ind = sgy_files.index(sgy_file)
start_dates = []
for i in range(len(st)):
tr = st[i]
start_dates.append(tr.stats.starttime.date.strftime(format="%Y-%m-%d"))
start_dates=set(start_dates)
#start_dates.remove('2024-09-20')
merge_dict = {}
for start_date in start_dates:
merge_dict[start_date] = []
'''
for i in range(len(st)):
tr = st[i]
tr.decimate(10, strict_length=False, no_filter=True)
date = tr.stats.starttime.date.strftime(format="%Y-%m-%d")
if date in merge_dict.keys():
merge_dict[date].append(i)
full_date_time = tr.stats.starttime.strftime(format="%Y-%m-%dT%H:%M:%S.%f")
min_wise_sac_file = data_folder+"/min_wise/"+"rec_"+str(rec_ind+1)+"_"+full_date_time+".sac"
tr.data = (10**4)*tr.data
stream = obspy.core.stream.Stream(traces=tr)
stream.write(min_wise_sac_file,format="SAC")
stream = read(min_wise_sac_file,format="SAC")
stream[0].stats.sac.stla,stream[0].stats.sac.stlo = lat,lon
stream.detrend("demean")
stream.detrend("linear")
stream.taper(max_percentage=0.1,type="cosine")
stream.write(min_wise_sac_file,format="SAC")
'''
for i in range(len(st)):
tr = st[i]
#tr.decimate(10, strict_length=False, no_filter=True)
date = tr.stats.starttime.date.strftime(format="%Y-%m-%d")
if date in merge_dict.keys():
merge_dict[date].append(i)
trs = []
for start_date in merge_dict.keys():
indices = merge_dict[start_date]
tr = st[indices[0]]
for i in range(1,len(indices)):
tr += st[indices[i]]
tr.decimate(10, strict_length=False, no_filter=True)
trs.append(tr)
print(tr)
stream = obspy.core.stream.Stream(traces=tr)
sac_file = data_folder+"/day_wise/"+"rec_"+str(rec_ind+1)+"_"+start_date+".sac"
stream.write(sac_file, format='SAC')
stream = read(sac_file,format="SAC")
stream[0].stats.sac.stla,stream[0].stats.sac.stlo = lat,lon
stream.detrend("demean")
stream.detrend("linear")
stream.taper(max_percentage=0.1,type="cosine")
stream.write(sac_file,format="SAC")
#new_tr = trs[0]
#for j in range(1,len(trs)):
# new_tr = new_tr + trs[j]
#combined_stream = obspy.core.stream.Stream(traces=new_tr)
#combined_sac_name = data_folder+"/"+"rec_"+str(rec_ind+1)+".sac"
#combined_stream.write(combined_sac_name, format='SAC')
#break