关于 segyio
segyio 是用于读取、检查、修改和创建 SEG-Y 地震文件的 Python 库,支持访问道和道头,并可按几何结构读取 3D 测区切片。
主要功能
- 01读取地震道和道头
- 02访问 inline 与 crossline 切片
- 03检查 3D 测区几何结构
- 04创建和修改 SEG-Y 文件
适用场景
- 01提取地震道或 3D 切片
- 02核查测区道头和几何信息
- 03将处理结果写入 SEG-Y
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ steadfastasart/ geoscience-skills --skill segyio安装后在 Claude Code 中输入/segyio确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/header_fields.mdtroubleshooting.mdscripts/extract_subset.pyinspect_segy.py详细介绍
segyio - SEG-Y 地震数据
快速参考
import segyio
# Read
with segyio.open('seismic.sgy', 'r') as f:
print(f.tracecount, len(f.samples))
trace0 = f.trace[0] # Single trace as numpy array
data = segyio.tools.collect(f.trace[:]) # All traces
# 3D access (specify inline/xline byte locations)
with segyio.open('seismic.sgy', 'r', iline=189, xline=193) as f:
inline_100 = f.iline[100] # 2D array (xlines x samples)
cube = segyio.tools.cube(f) # Full 3D cube
# Write
spec = segyio.spec()
spec.samples = samples
spec.tracecount = n_traces
with segyio.create('output.sgy', spec) as f:
f.trace[0] = data
关键访问模式
| 模式 | 描述 |
|---|---|
f.trace[i] | 按索引顺序访问道 |
f.header[i] | 访问道头(类似字典) |
f.iline[n] | 内联切片(3D 测区) |
f.xline[n] | 交叉线切片(3D 测区) |
f.depth_slice[n] | 水平时间/深度切片 |
f.text[0] | 文本头(3200 字节) |
f.bin | 二进制头 |
基本操作
打开并检查
with segyio.open('seismic.sgy', 'r') as f:
print(f"Traces: {f.tracecount}")
print(f"Samples: {len(f.samples)}")
print(f"Sample interval: {f.samples[1] - f.samples[0]} ms")
if f.ilines is not None:
print(f"Inlines: {f.ilines}")
print(f"Crosslines: {f.xlines}")
读取道头
with segyio.open('seismic.sgy', 'r') as f:
header = f.header[0]
print(header[segyio.TraceField.INLINE_3D])
print(header[segyio.TraceField.CDP_X])
# Get all values for one field
inlines = f.attributes(segyio.TraceField.INLINE_3D)[:]
读取 3D 数据
with segyio.open('seismic.sgy', 'r', iline=189, xline=193) as f:
inline_data = f.iline[100] # Shape: (n_xlines, n_samples)
xline_data = f.xline[200] # Shape: (n_ilines, n_samples)
time_slice = f.depth_slice[250] # Shape: (n_ilines, n_xlines)
cube = segyio.tools.cube(f) # Shape: (ilines, xlines, samples)
读取非结构化数据
# For 2D lines or unsorted data
with segyio.open('seismic.sgy', 'r', ignore_geometry=True) as f:
data = segyio.tools.collect(f.trace[:])
创建新的 SEG-Y 文件
import numpy as np
spec = segyio.spec()
spec.samples = np.arange(500) * 4 # 4ms sample rate
spec.tracecount = 100
spec.format = 1 # IBM float
with segyio.create('output.sgy', spec) as f:
for i in range(100):
f.trace[i] = data[i]
f.header[i] = {
segyio.TraceField.TRACE_SEQUENCE_LINE: i + 1,
}
修改现有文件
with segyio.open('seismic.sgy', 'r+') as f:
f.trace[0] = f.trace[0] * 2.0
f.header[0][segyio.TraceField.CDP] = 999
数据格式
| 代码 | 格式 |
|---|---|
| 1 | IBM 4 字节浮点数 |
| 2 | 4 字节有符号整数 |
| 3 | 2 字节有符号整数 |
| 5 | IEEE 4 字节浮点数 |
| 8 | 1 字节有符号整数 |
与其他工具的适用场景比较
| 工具 | 最适用于 |
|---|---|
| segyio | 快速 SEG-Y I/O、3D 内联/交叉线访问、道头操作 |
| obspy | 更广泛的地震学应用:FDSN 访问、波形处理、事件分析 |
| segysak | 基于 xarray 的 SEG-Y 工作流、NetCDF 转换、带标签的维度 |
需要以下功能时使用 segyio:快速、底层地访问 SEG-Y 文件——读取道、道头、3D 切片,或以编程方式创建新的 SEG-Y 文件。
需要以下功能时改用 obspy:超越文件 I/O 的地震学处理,例如去除仪器响应、获取 FDSN 数据或分析地震。
需要以下功能时改用 segysak:希望集成 xarray,使用带标签的维度(内联、交叉线、时间),并轻松转换为 NetCDF/Zarr。
常见工作流
读取、检查并提取 3D 地震数据
- [ ] Open file with `segyio.open()`, specify `iline=` and `xline=` byte positions
- [ ] Inspect geometry: trace count, sample count, inline/crossline ranges
- [ ] Read headers to verify coordinate and survey metadata
- [ ] Extract target inline/crossline slices or full cube
- [ ] Apply amplitude scaling or subset extraction as needed
- [ ] Write results to new SEG-Y or export as numpy arrays
常见问题
| 问题 | 解决方案 |
|---|---|
| 未检测到几何信息 | 指定 iline= 和 xline= 字节位置 |
| 无法读取 3D 切片 | 对非结构化数据使用 ignore_geometry=True |
| 内联/交叉线字节位置错误 | 使用 f.header[0] 检查道头,找到正确的字节位置 |
| 无法打开文件 | 检查文件路径、权限以及 SEG-Y 格式是否有效 |
参考资料
脚本
- scripts/inspect_segy.py - 检查 SEG-Y 文件结构和几何信息
- scripts/extract_subset.py - 提取部分道或内联
评论
支持 Markdown