segyio
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesesegyio - SEG-Y Seismic Data
segyio - SEG-Y地震数据
Quick Reference
快速参考
python
import segyiopython
import segyioRead
读取
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
with segyio.open('seismic.sgy', 'r') as f:
print(f.tracecount, len(f.samples))
trace0 = f.trace[0] # 单个道,格式为numpy数组
data = segyio.tools.collect(f.trace[:]) # 所有道数据
3D access (specify inline/xline byte locations)
3D访问(指定测线/联络测线的字节位置)
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
with segyio.open('seismic.sgy', 'r', iline=189, xline=193) as f:
inline_100 = f.iline[100] # 二维数组(联络测线 × 采样点)
cube = segyio.tools.cube(f) # 完整3D数据体
Write
写入
spec = segyio.spec()
spec.samples = samples
spec.tracecount = n_traces
with segyio.create('output.sgy', spec) as f:
f.trace[0] = data
undefinedspec = segyio.spec()
spec.samples = samples
spec.tracecount = n_traces
with segyio.create('output.sgy', spec) as f:
f.trace[0] = data
undefinedKey Access Modes
核心访问模式
| Mode | Description |
|---|---|
| Sequential trace access by index |
| Trace header access (dict-like) |
| Inline slice (3D surveys) |
| Crossline slice (3D surveys) |
| Horizontal time/depth slice |
| Text header (3200 bytes) |
| Binary header |
| 模式 | 描述 |
|---|---|
| 通过索引按顺序访问道数据 |
| 访问道头文件(类字典格式) |
| 测线切片(适用于3D勘探数据) |
| 联络测线切片(适用于3D勘探数据) |
| 水平时间/深度切片 |
| 文本头文件(3200字节) |
| 二进制头文件 |
Essential Operations
关键操作
Open and Inspect
打开与检查
python
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}")python
with segyio.open('seismic.sgy', 'r') as f:
print(f"道数量: {f.tracecount}")
print(f"采样点数量: {len(f.samples)}")
print(f"采样间隔: {f.samples[1] - f.samples[0]} 毫秒")
if f.ilines is not None:
print(f"测线范围: {f.ilines}")
print(f"联络测线范围: {f.xlines}")Read Trace Headers
读取道头文件
python
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)[:]python
with segyio.open('seismic.sgy', 'r') as f:
header = f.header[0]
print(header[segyio.TraceField.INLINE_3D])
print(header[segyio.TraceField.CDP_X])
# 获取单个字段的所有值
inlines = f.attributes(segyio.TraceField.INLINE_3D)[:]Read 3D Data
读取3D数据
python
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)python
with segyio.open('seismic.sgy', 'r', iline=189, xline=193) as f:
inline_data = f.iline[100] # 形状: (联络测线数, 采样点数)
xline_data = f.xline[200] # 形状: (测线数, 采样点数)
time_slice = f.depth_slice[250] # 形状: (测线数, 联络测线数)
cube = segyio.tools.cube(f) # 形状: (测线数, 联络测线数, 采样点数)Read Unstructured Data
读取非结构化数据
python
undefinedpython
undefinedFor 2D lines or unsorted data
适用于2D测线或未排序的数据
with segyio.open('seismic.sgy', 'r', ignore_geometry=True) as f:
data = segyio.tools.collect(f.trace[:])
undefinedwith segyio.open('seismic.sgy', 'r', ignore_geometry=True) as f:
data = segyio.tools.collect(f.trace[:])
undefinedCreate New SEG-Y
创建新的SEG-Y文件
python
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,
}python
import numpy as np
spec = segyio.spec()
spec.samples = np.arange(500) * 4 # 4毫秒采样率
spec.tracecount = 100
spec.format = 1 # IBM浮点数
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,
}Modify Existing File
修改现有文件
python
with segyio.open('seismic.sgy', 'r+') as f:
f.trace[0] = f.trace[0] * 2.0
f.header[0][segyio.TraceField.CDP] = 999python
with segyio.open('seismic.sgy', 'r+') as f:
f.trace[0] = f.trace[0] * 2.0
f.header[0][segyio.TraceField.CDP] = 999Data Formats
数据格式
| Code | Format |
|---|---|
| 1 | IBM 4-byte float |
| 2 | 4-byte signed integer |
| 3 | 2-byte signed integer |
| 5 | IEEE 4-byte float |
| 8 | 1-byte signed integer |
| 编码 | 格式 |
|---|---|
| 1 | IBM 4字节浮点数 |
| 2 | 4字节有符号整数 |
| 3 | 2字节有符号整数 |
| 5 | IEEE 4字节浮点数 |
| 8 | 1字节有符号整数 |
When to Use vs Alternatives
适用场景与替代工具对比
| Tool | Best For |
|---|---|
| segyio | Fast SEG-Y I/O, 3D inline/crossline access, header manipulation |
| obspy | Broader seismology: FDSN access, waveform processing, event analysis |
| segysak | xarray-based SEG-Y workflows, NetCDF conversion, labeled dimensions |
Use segyio when you need fast, low-level access to SEG-Y files -- reading
traces, headers, 3D slices, or creating new SEG-Y files programmatically.
Use obspy instead when you need seismological processing beyond file I/O:
instrument response removal, FDSN data fetching, or earthquake analysis.
Use segysak instead when you want xarray integration with labeled
dimensions (inline, crossline, time) and easy conversion to NetCDF/Zarr.
| 工具 | 最佳适用场景 |
|---|---|
| segyio | 快速SEG-Y读写、3D测线/联络测线访问、头文件操作 |
| obspy | 更广泛的地震学应用:FDSN数据访问、波形处理、事件分析 |
| segysak | 基于xarray的SEG-Y工作流、NetCDF格式转换、带标签维度 |
当你需要以下操作时使用segyio:快速的底层SEG-Y文件访问——读取道数据、头文件、3D切片,或以编程方式创建新的SEG-Y文件。
当你需要以下操作时改用obspy:除文件读写外的地震学处理,如仪器响应移除、FDSN数据获取或地震分析。
当你需要以下操作时改用segysak:xarray集成、带标签维度(测线、联络测线、时间)以及便捷的NetCDF/Zarr格式转换。
Common Workflows
常见工作流
Read, inspect, and extract 3D seismic data
读取、检查并提取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- [ ] 使用`segyio.open()`打开文件,指定`iline=`和`xline=`字节位置
- [ ] 检查几何信息:道数量、采样点数量、测线/联络测线范围
- [ ] 读取头文件以验证坐标和勘探元数据
- [ ] 提取目标测线/联络测线切片或完整数据体
- [ ] 根据需要应用振幅缩放或子集提取
- [ ] 将结果写入新SEG-Y文件或导出为numpy数组Common Issues
常见问题
| Issue | Solution |
|---|---|
| Geometry not detected | Specify |
| Can't read 3D slices | Use |
| Wrong inline/xline bytes | Check headers with |
| File not opening | Check file path, permissions, and SEG-Y format validity |
| 问题 | 解决方案 |
|---|---|
| 无法检测几何信息 | 指定 |
| 无法读取3D切片 | 对非结构化数据使用 |
| 测线/联络测线字节错误 | 使用 |
| 文件无法打开 | 检查文件路径、权限和SEG-Y格式有效性 |
References
参考资料
- Trace Header Fields - Complete header field reference (bytes, types)
- Troubleshooting - Common problems and solutions
- 道头文件字段 - 完整的头文件字段参考(字节位置、类型)
- 故障排查 - 常见问题及解决方案
Scripts
脚本
- scripts/inspect_segy.py - Inspect SEG-Y file structure and geometry
- scripts/extract_subset.py - Extract subset of traces or inlines
- scripts/inspect_segy.py - 检查SEG-Y文件结构和几何信息
- scripts/extract_subset.py - 提取道或测线的数据子集