地震数据.dat文件转.sgy文件
最近接触了地震去噪任务,需要使用dat文件和sgy文件,所以常会遇到两者的转换,现将代码板书如下:
import numpy as np
import segyio
import os
if __name__ == '__main__':
source_file = '' # 源文件路径
save_dir = '' # 文件保存目录
trace_n = # 数据总道数
sample_n = # 数据采样点数
sample_interval = # 数据采样率
paoc_arr = np.fromfile(source_file, dtype=np.float32).reshape(-1, sample_n)
spec = segyio.spec()
spec.samples = np.linspace(0.0, (sample_n - 1) * sample_interval, sample_n)
spec.format = 5
spec.tracecount = trace_n
if not os.path.exists(save_dir):
os.mkdir(save_dir)
with segyio.create(os.path.join(save_dir, 'saved-file.sgy'), spec) as f:
data = paoc_arr
f.trace = data
print('saved saved-file.sgy')
# save .dat file,
# 转回dat文件检测是否转换正确
# arr = np.zeros((trace_n, sample_n), dtype=np.float32)
# i = 0
# for tra in f.trace:
# arr[i, :] = tra
# i += 1
# arr = arr.reshape(-1)
# with open(os.path.join(save_dir, 'saved-file.dat'), 'wb') as f_dat:
# f_dat.write(arr)
# print('saved dat file')