首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否有一个R包来解析地球物理"Log标准“文件(.las文件)?

是否有一个R包来解析地球物理"Log标准“文件(.las文件)?
EN

Stack Overflow用户
提问于 2012-10-09 16:16:11
回答 4查看 4.8K关注 0票数 8

是否有一个R包可以读取.las文件,即斯伦贝谢Log Ascii标准文件?

它应该能够读取las 2.0文件。

请注意:

  • 我不是在这里谈论激光雷达.las文件。
  • 我指的是地球物理测井文件(不是用于计算机应用程序、恶魔之类的日志文件)。

在互联网上搜索R、Las和Logfiles会给我带来太多的红鲱鱼。

评论中提供的最新情况:

我还在考虑使用R语言绑定的脚本或API。

到目前为止,我发现了以下脚本:

  • las2witsml -红宝石脚本
  • Text-LAS-Parser-0.01 - perl脚本

然而,到目前为止,所有这些脚本在我看来还不太成熟。

斯伦贝谢还提供了一个免费的软件包“日志数据工具箱,但它只能在Windows下运行,并且可能与非英语版本的Windows有兼容性问题(如果我没记错的话)。

堪萨斯地质调查局有一个复杂java小程序,但是对于大型.las输入文件来说,它有点迟缓。

有一个ruby项目和一个python项目。另外,请参阅此链接获得一组不错的las文件。

EN

回答 4

Stack Overflow用户

发布于 2015-10-28 15:36:13

回答我自己的问题:

现在有一个python库,拉西奥,它运行得很好。它可以是从R呼叫,也可以通过system2()函数实现;输出可以被提取到R数据结构中。另一种可能是将lasfile对象序列化为JSON,保存为文件并从R重新导入,也许我会用代码示例扩展这个答案,但我现在没有时间。

  • 拉西奥 on github
  • lasio实例 -笔记本底部的图解
票数 4
EN

Stack Overflow用户

发布于 2020-01-02 19:13:47

2021年答复:

拉索尔斯

紫罗兰醇是github上的一个R包,用于读取Log标准v2.0文件。

它还提供了基本的绘图,并写入las文件格式。

要从r命令行安装(也可以通过其他方式安装):

代码语言:javascript
复制
devtools::install_github("Gitmaxwell/lastools")

要加载lastools,请读取las文件并在R中显示内容:

代码语言:javascript
复制
library(lastools)
las_file <- "your-sample.las"
las <- read_las(las_file)
print(las)

拉萨

拉萨 (在测试版测试中,2021年早期),Lasr主要设计用于高速、大批量地导入LAS文件。

从r命令行安装:

代码语言:javascript
复制
if (!require('devtools')) install.packages('devtools')
library(devtools)
install_github('https://github.com/donald-keighley/lasr')

加载lasr,读取和显示las文件内容的示例:

代码语言:javascript
复制
library(lasr)
las = read.las(system.file("extdata", "las_3_cwls.las", package = "lasr"))

#Display the WELL section
head(las$well, 10)
票数 3
EN

Stack Overflow用户

发布于 2016-06-13 17:27:56

我做了我的个人(适合我的目的)使用一个良好的日志las2文件阅读器。它有两个步骤: 1.创建要读取和附加的*.las文件列表;2.读取*.las文件的数量并附加到单个数据框架中。这两种代码都在2016年用标准商业软件包创建的一组*.las文件上进行了测试--在R3.2.4(64位)下的Windows10中。

代码-1用于读取和创建运行代码-2的*.las文件的简单文件列表

代码语言:javascript
复制
# Read the file having list of well-log LAS files
# Create a R-Object [wellname, path, filename] for LAS reader
# Create filelist from DOS prompt dir *.las > filelist.dat
# G Srikanth 29-May-2016
#
library(stringr)
defaultworkdir <- readline("What is the file path? ")
setwd(defaultworkdir)
welllistfile <- readline("What is the well list file? ")
listfilelines <- readLines(con = welllistfile, skipNul = TRUE)
#
#      search for "Directory of " to get the LAS data folder = lasfolder
#      search for "File(s)" to get the number of files = nlasfiles, linenumber
#      the data file names are before the "Files(s)" line = lasfilenames() char vector of length nlasfiles
#
oneline <- listfilelines[grep("Directory of ",listfilelines)]
lasfilepath <- sub(" Directory of ","",oneline)
oneline <- listfilelines[grep(" File",listfilelines)]
# modified from http://stackoverflow.com/questions/2261079/how-to-trim-leading-and-trailing-whitespace-in-r
numberoflasfiles <- as.numeric(word(sub("^\\s+", "", oneline),1))

# file names occur from - to in the DOS list read-in
fromline <- as.numeric(grep(" File",listfilelines)) -numberoflasfiles

# extract the last word from the fromline - numberoflasfiles times and load into suitable data structure
#     tail(strsplit(oneline,split=" ")[[1]],1)   --- taken from 
#     http://stackoverflow.com/questions/17658216/extract-last-word-in-string-in-r

lasfile <- c(1:numberoflasfiles)
for (n in 1 : numberoflasfiles) 
{
  oneline <- listfilelines[fromline]
  lasfile[n] <- tail(strsplit(oneline,split=" ")[[1]],1)
  fromline=fromline+1
}
# print (lasfile)
rm(fromline)
lasfile<- paste(lasfilepath,"\\",lasfile,sep="")
# print(lasfile)
# temp <- readLines(con=lasfile[1], skipNul = TRUE) 
#
save(lasfile,file="lasfiles.Rdat")

代码-2读取多个*.las文件并构造单个数据框架。

代码语言:javascript
复制
# Read the list of lasfiles to read
# open each las file and get data

# G Srikanth 29 May 2016

#                                                   install.packages("data.table")
# 1. set working directory and read the file list
library(stringr)
library(data.table)
defaultworkdir <- readline("What is the file path? ")
setwd(defaultworkdir)
lasfilelist <- readline("What is the well list file? ")
load(lasfilelist)
welllogdata <- data.frame()

#     load("lasfiles.Rdat")    name of saved file
#     determine number of well files
nwells <- length(lasfile)
uwi<-c(1:nwells)
# 2. Main read loop for each well las file in directory
for (wellno in 1:nwells)
{
  # 2a. Get uwi
  # 2b. Get curve names
  # 2c. Read the curve data

  # LAS files have all the headers within first 100 lines
  # read 100 lines into a vector
  headerlines <- readLines(con = lasfile[wellno], n=100L, ok=TRUE, skipNul = TRUE)
  # extract uwi  NOTE - many las files write only proper well name and not UWI. in such case replace UWI with WELL in next line
    oneline <- headerlines[grep(" UWI",headerlines)]
    # remove multiple spaces with gsub() extract 3rd word with word()
    #     ref: http://rfunction.com/archives/2354
    uwi[wellno]<-word(gsub("\\s+"," ",str_trim(oneline)),3)
  # extract curve information and data location
    #locate ~A  in the headerlines. This has the log names.
    oneline <- headerlines[grep("~A",headerlines)]# line having curves names
    oneline <- gsub("\\s+"," ",str_trim(oneline)) # trim leading trailing and extra blanks
    ncurves <- str_count(oneline, " ")
    # ncurves <- str_count(gsub("\\s+"," ",str_trim(headerlines[grep("~A",headerlines)]))," ")
    # The next record in data file is numeric las data.
    dataline <- as.numeric(grep("~A",headerlines)+1)
    curvenameline <- as.numeric(grep("~A",headerlines)- ncurves) 
    # curve names start at curvenameline and contine for ncurves. The first word in each line is curve name
    logname <- c(1:ncurves)
    for (nc in 1:ncurves)
    {
      logname[nc] <- word(gsub("\\s+"," ",str_trim(headerlines[curvenameline+(nc-1)])),1)
    }
  # read the data matrix from the line - dataline in the well las file
    # null value used in the las file
    lasnull <- word(gsub("\\s+"," ",str_trim(headerlines[grep(" NULL",headerlines)])),3)
    temp<- read.table(lasfile[wellno], header=F, na.strings=lasnull, skip=dataline-1, col.names = logname)
    temp <- merge(temp,uwi[wellno])
    names(temp) <- c(logname,"uwi")
  # concatenate this data into a single data-frame. use the lognames to merge.
    if (wellno == 1) welldata <- temp else welldata <- rbind.fill(welldata, temp)    #rbind doesnt merge with different names, Thanks to stackoverflow!
        # to clean the logname vector between files
    rm(logname)
}
save(welldata,"welldata.Rdat")

希望它有用!

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12804203

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档