关于 lasio
lasio 是用于读取、检查、创建和修改 LAS 测井文件的 Python 库,适合需要直接操作 LAS 数据、头信息及格式转换的工作流程。
主要功能
- 01读取和写入 LAS 文件
- 02访问曲线与头信息
- 03创建和修改测井文件
- 04将曲线数据转换为 DataFrame
- 05处理头信息错误和空值
适用场景
- 01检查曲线和测井头信息
- 02分析前清理空值
- 03创建或编辑 LAS 测井文件
- 04批量处理 LAS 文件或导出 CSV
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ steadfastasart/ geoscience-skills --skill lasio安装后在 Claude Code 中输入/lasio确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/curve_mnemonics.mdfile_structure.mdtroubleshooting.mdscripts/las_to_csv.pymerge_curves.pyvalidate_las.py详细介绍
lasio - LAS 测井文件
快速参考
import lasio
# Read
las = lasio.read("well.las")
# Access data
df = las.df() # DataFrame (depth as index)
gr = las['GR'] # Single curve as numpy array
depth = las['DEPT']
# Well info
well_name = las.well['WELL'].value
uwi = las.well['UWI'].value
# Write
las.write('output.las')
主要类
| 类 | 用途 |
|---|---|
LASFile | 主容器——包含标头、曲线和数据 |
CurveItem | 单条曲线,包含助记符、单位和数据数组 |
HeaderItem | 标头条目(助记符、单位、值、描述) |
基本操作
读取和检查
las = lasio.read("well.las")
print(las.curves.keys()) # Available curves
print(las.well) # Well section headers
print(las.version) # LAS version info
访问曲线数据
# As numpy arrays
gr = las['GR']
depth = las['DEPT']
# With metadata
curve = las.curves['GR']
print(curve.unit, curve.descr) # 'GAPI', 'Gamma Ray'
创建新的 LAS 文件
import numpy as np
las = lasio.LASFile()
las.well['WELL'] = lasio.HeaderItem('WELL', value='Test-1')
las.well['UWI'] = lasio.HeaderItem('UWI', value='12345678901234')
depth = np.arange(1000, 2000, 0.5)
las.append_curve('DEPT', depth, unit='M', descr='Depth')
las.append_curve('GR', gr_data, unit='GAPI', descr='Gamma Ray')
las.write('output.las')
修改现有文件
las = lasio.read("well.las")
las.append_curve('GR_NORM', las['GR'] / 150, unit='V/V')
del las.curves['BAD_CURVE']
las.well['WELL'].value = 'New Name'
las.write('modified.las')
处理有问题的文件
# Ignore header errors
las = lasio.read("messy.las", ignore_header_errors=True)
# Check null value
null_val = las.well['NULL'].value # Usually -999.25
空值处理
LAS 文件使用特定的空值(通常为 -999.25)。务必检查并处理:
import numpy as np
null_val = float(las.well['NULL'].value)
df = las.df().replace(null_val, np.nan)
批量处理
from pathlib import Path
for path in Path('wells/').glob('*.las'):
las = lasio.read(path)
df = las.df()
# Process...
何时使用及替代方案
| 工具 | 最适合的用途 |
|---|---|
| lasio | 直接读写 LAS 文件、修改标头、转换格式 |
| welly | 更高层级的测井分析、曲线处理、多井项目 |
| dlisio | DLIS/RP66 二进制格式文件(非 LAS) |
在以下情况下使用 lasio:需要对 LAS 文件的读写进行底层控制、 需要处理格式错误的文件,或希望以编程方式构建 LAS 文件。
在以下情况下改用 welly:需要进行曲线处理(去尖峰、归一化)、 管理多井项目或处理地层顶界。Welly 内部使用 lasio。
在以下情况下改用 dlisio:数据采用 DLIS 格式。DLIS 文件为二进制格式, 支持多帧数据和阵列测井——lasio 无法读取这些文件。
常见工作流
读取、质控并导出测井数据
- [ ] Read LAS file with `lasio.read()`, handle encoding if needed
- [ ] Inspect curves: `las.curves.keys()` and well headers
- [ ] Replace null values: `df.replace(null_val, np.nan)`
- [ ] Validate depth range and sample interval
- [ ] Check for missing curves or anomalous values
- [ ] Export to DataFrame with `las.df()` or write cleaned LAS
常见问题
| 问题 | 解决方案 |
|---|---|
| 编码错误 | lasio.read(f, encoding='latin-1') |
| 缺少曲线 | 先检查 las.curves.keys() |
| 标头错误 | 使用 ignore_header_errors=True |
| 空值不正确 | 检查 las.well['NULL'].value |
参考资料
脚本
- scripts/validate_las.py - 验证 LAS 文件格式
- scripts/las_to_csv.py - 将 LAS 转换为 CSV
- scripts/merge_curves.py - 合并多个文件中的曲线
评论
支持 Markdown