python 读取.sgy地震文件到三维ndarray矩阵,(全网仅此一份)

比较着急,直接上代码,已经封装为函数,直接就能用

import segyio


def load_data_from_sgy(sgy_path):
    '''
    读取sgy为3维矩阵
    Args:
        sgy_path: sgy路径

    Returns:
        ndarray三维矩阵对象

    '''
    three_dimensional_list = list()
    with segyio.open(sgy_path, mode="r+",
                     strict=True,
                     ignore_geometry=False) as sgy_file:
        x_len = len(sgy_file.xlines)
        i_len = len(sgy_file.ilines)
        front_elevation = []  # 正看
        for i in range(len(sgy_file.trace)):
            front_elevation.append(sgy_file.trace[i])
            if not (i + 1) % x_len:
                three_dimensional_list.append(front_elevation)
                front_elevation = list()

    # 转为矩阵
    three_dimensional_array = np.array(three_dimensional_list)
    return three_dimensional_array

data = load_data_from_sgy('data/seismic.sgy')

你可能感兴趣的:(python,python)