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

时间:2012-10-09 16:16:11

标签: r file-format

是否有可以读取.las文件的R包,即Schlumberger Log Ascii standard文件?
它应该能够读取las 2.0文件。

请注意:

  • 我不是在谈论LIDAR .las文件。
  • 我说的是地球物理学 井孔记录文件(不记录计算机应用程序,恶魔等文件)

在互联网上搜索R和Las和Logfiles给了我个人太多的红色鲱鱼。

评论更新:

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

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

但是,到目前为止,所有这些脚本对我来说都不是很成熟。

还有一个免费软件包"Log Data Toolbox"由Schlumberger提供,但它只能在Windows下运行,并且可能与Windows的非英语版本存在兼容性问题(如果我没记错的话)。

堪萨斯地质调查局有一个complex java applet,但对于大型.las输入文件来说有点迟钝。

有一个ruby project和一个python project。另外,请参阅this link以获取一组很好的示例las文件。

4 个答案:

答案 0 :(得分:3)

回答我自己的问题:

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

答案 1 :(得分:3)

2020年答案:

lastools是github上的R包,读取Log Ascii Standard v2.0文件。

它还提供基本的绘图功能,并以las文件格式写出。

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

devtools::install_github("Gitmaxwell/lastools")

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

library(lastools)
las_file <- "your-sample.las"
las <- read_las(las_file)
print(las)

答案 2 :(得分:1)

* .las文件的示例:

…
…
…
#MNEM           .UNIT                  API CODE            :DESCRIPTION
#----            ------          --------------            -----------------------------
DEPT            .ft                                        :                                                        Station Depth
INCL            .deg                                       :                                                        Hole inclination
AZIM            .deg                                       :                                                        Measured Azimuth
#-------------------------------------------------------------
#        DEPT         INCL         AZIM
~ASCII
0.00         0.00         0.00
36.00         0.33       123.98
126.00         0.17       183.28
218.00         0.19       202.04
308.00         0.24       191.24
398.00         0.21       198.60
495.00         0.02       179.55
…
…
…

读取文件时的目标是忽略文件头并仅复制(~ASCII)行之后的数据以及每个列标题 所以我们复制所有文件,逐行搜索直到我们到达(~ASCII)行,然后我们复制它之前的行(标题)和它之后的所有内容(数据),我们删除(~ASCII)行。

请注意,我们会从标题行中删除(#)符号。

最后一步是将数据转换为表,然后将其写为csv文件。

完整的代码:

#remove all variables (cleanup)
rm(list=ls(all=TRUE))
gc()
MWD_filePath="MWD_file.las";
conn=file(MWD_filePath,open="r")
Ascii_txt=readLines(conn);
mwd_txt = 0;

for (i in 1:length(Ascii_txt)){
    if(Ascii_txt[i] == "~ASCII"){
    mwd_txt <- Ascii_txt[(i-1):length(Ascii_txt)]

    # remove (#) from the header line
    substr(mwd_txt[1], 1, 2) <- " ";

    # remove "~ASCII" line
    mwd_txt <- mwd_txt[-2]

    break;
    }

}
close(conn)
#mwd_txt;
mwd <- read.table(header = TRUE, text=mwd_txt);
#head(mwd)

#write the mwd data to file ... in CSV format
mwd_csv_file <- paste(MWD_filePath, ".csv", sep="");
write.csv(mwd, file = mwd_csv_file);

答案 3 :(得分:1)

我已经为我的个人(适合我的目的)使用了一个well log las2文件阅读器。它有两个步骤 1.创建一个* .las文件列表以进行读取和追加 2.读取* .las文件的数量并附加到单个数据框中。 这两个代码都在2016年从标准商业软件包创建的一组* .las文件中进行测试 - 在Windows 10下的R 3.2.4(64位)

Code-1读取并创建* .las文件的简单文件列表以运行Code-2

# 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")

Code-2读取许多* .las文件并构造单个数据帧

# 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")

希望它有用!!