import glob import os.path import re import math class LASParse: def __init__(self, filename, outputFilename): self.pointsToRemove=9 if(not os.path.exists(filename)): raise "Filename: %s does not exist" % filename self.re = re.compile("^\s+([-+]?[0-9]*\.?[0-9]+)\s+([-+]?[0-9]*\.?[0-9]+)\s+([-+]?[0-9]*\.?[0-9]+)\s+([-+]?[0-9]*\.?[0-9]+)\s+([-+]?[0-9]*\.?[0-9]+)\s+([-+]?[0-9]*\.?[0-9]+)\s+([-+]?[0-9]*\.?[0-9]+)", re.VERBOSE) self.fd = open(filename, 'r') self.outFd = open(outputFilename, 'a') # write a header self.outFd.write("# depth time mincal calx caly incl azim btem\n") def removeFilter(self, n): return n[0] def parseFile(self): data = [] for line in self.fd: m = self.re.match(line) if(m): # valid LAS data line tmp = [1] for entry in line.split(): tmp.append(float(entry)) data.append(tmp) # okay, so by now we have loaded all of the data from the las file into memory # no go through it and filter out any data that has a negative caliper reading # and the POINTSTOREMOVE from in front of and after each negative range numLines = len(data) index=0 filteredData = [] for line in data: if line[3]<0 or line[4]<0 or line[3]>1200 or line[4]>1200: line[0]=0 else: # search up to points to remove points before and after this point beforePoints = max(0,index-self.pointsToRemove) afterPoints = min(numLines, index+self.pointsToRemove) for tmpIndex in range(beforePoints, index): if data[tmpIndex][3]<0 or data[tmpIndex][4]<0: line[0]=0 for tmpIndex in range(index, afterPoints): if data[tmpIndex][3]<0 or data[tmpIndex][4]<0: line[0]=0 filteredData.append(line) index=index+1 data=[] filteredData = filter(self.removeFilter, filteredData) # okay, now we have removed all of the negative data.. rescale the calipers for line in filteredData: depth = line[1] time = line[2] calx = line[3]/1000.0 caly = line[4]/1000.0 incl = line[5] azim = line[6] btem = line[7] mincal = min(calx,caly) self.outFd.write("%f %f %f %f %f %f %f %f\n" % ( depth, time, mincal, calx, caly, incl, azim, btem)) self.outFd.close() self.fd.close() if __name__=="__main__": files = glob.glob("*.LAS") files.sort() print "LAS Files: %s" % files for file in files: a = LASParse(file, 'logger.out') a.parseFile()