import lasio
import datetime
import numpy
import os
import matplotlib.pyplot as plt
%matplotlib inline
Create some fake data, and make some of the values at the bottom NULL (numpy.nan
). Note that of course every curve in a LAS file is recorded against a reference/index, either depth or time, so we create that array too.
depths = numpy.arange(10, 50, 0.5)
fake_curve = numpy.random.random(len(depths))
fake_curve[-10:] = numpy.nan # Add some null values at the bottom
plt.plot(depths, fake_curve)
[<matplotlib.lines.Line2D at 0xafdd2b0>]
Create an empty LASFile object and review its header section
l = lasio.LASFile()
l.header
{'Curves': [], 'Other': '', 'Parameter': [], 'Version': [HeaderItem(mnemonic=VERS, unit=, value=2.0, descr=CWLS log ASCII Standard -VERSION 2.0, original_mnemonic=VERS), HeaderItem(mnemonic=WRAP, unit=, value=NO, descr=One line per depth step, original_mnemonic=WRAP), HeaderItem(mnemonic=DLM, unit=, value=SPACE, descr=Column Data Section Delimiter, original_mnemonic=DLM)], 'Well': [HeaderItem(mnemonic=STRT, unit=m, value=nan, descr=START DEPTH, original_mnemonic=STRT), HeaderItem(mnemonic=STOP, unit=m, value=nan, descr=STOP DEPTH, original_mnemonic=STOP), HeaderItem(mnemonic=STEP, unit=m, value=nan, descr=STEP, original_mnemonic=STEP), HeaderItem(mnemonic=NULL, unit=, value=-9999.25, descr=NULL VALUE, original_mnemonic=NULL), HeaderItem(mnemonic=COMP, unit=, value=, descr=COMPANY, original_mnemonic=COMP), HeaderItem(mnemonic=WELL, unit=, value=, descr=WELL, original_mnemonic=WELL), HeaderItem(mnemonic=FLD, unit=, value=, descr=FIELD, original_mnemonic=FLD), HeaderItem(mnemonic=LOC, unit=, value=, descr=LOCATION, original_mnemonic=LOC), HeaderItem(mnemonic=PROV, unit=, value=, descr=PROVINCE, original_mnemonic=PROV), HeaderItem(mnemonic=CNTY, unit=, value=, descr=COUNTY, original_mnemonic=CNTY), HeaderItem(mnemonic=STAT, unit=, value=, descr=STATE, original_mnemonic=STAT), HeaderItem(mnemonic=CTRY, unit=, value=, descr=COUNTRY, original_mnemonic=CTRY), HeaderItem(mnemonic=SRVC, unit=, value=, descr=SERVICE COMPANY, original_mnemonic=SRVC), HeaderItem(mnemonic=DATE, unit=, value=, descr=DATE, original_mnemonic=DATE), HeaderItem(mnemonic=UWI, unit=, value=, descr=UNIQUE WELL ID, original_mnemonic=UWI), HeaderItem(mnemonic=API, unit=, value=, descr=API NUMBER, original_mnemonic=API)]}
Let's add some information to the header:
First, let's change the date.
l.well.DATE = str(datetime.datetime.today())
Next, let's make a new item in the ~Parameters section for the operator. To do this we need to make a new HeaderItem
:
l.params['ENGI'] = lasio.HeaderItem("ENGI", "", "kinverarity@hotmail.com", "Creator of this file...")
And finally, add some free text to the ~Other section:
l.other = "Example of how to create a LAS file from scratch using lasio"
Add the curves to the LAS file using the add_curve
method:
l.add_curve('DEPT', depths, unit='m')
l.add_curve('FAKE_CURVE', fake_curve, descr='fake curve')
Now let's write out two files: one according to the LAS file specification version 1.2, and one according to 2.0. Note that by default an empty LASFile
object is version 2.0.
fn = "scratch_example_v2.las"
with open(fn, mode="w") as f: # Write LAS file to disk
l.write(f)
and let's see if that worked
with open(fn, mode="r") as f: # Show the result...
print(f.read())
~Version --------------------------------------------------- VERS. 2.0 : CWLS log ASCII Standard -VERSION 2.0 WRAP. NO : One line per depth step DLM . SPACE : Column Data Section Delimiter ~Well ------------------------------------------------------ STRT.m 10.0 : START DEPTH STOP.m 49.5 : STOP DEPTH STEP.m 0.5 : STEP NULL. -9999.25 : NULL VALUE COMP. : COMPANY WELL. : WELL FLD . : FIELD LOC . : LOCATION PROV. : PROVINCE CNTY. : COUNTY STAT. : STATE CTRY. : COUNTRY SRVC. : SERVICE COMPANY DATE. 2016-02-13 16:52:39.445000 : DATE UWI . : UNIQUE WELL ID API . : API NUMBER ~Curves ---------------------------------------------------- DEPT .m : FAKE_CURVE. : fake curve ~Params ---------------------------------------------------- ENGI. kinverarity@hotmail.com : Creator of this file... ~Other ----------------------------------------------------- Example of how to create a LAS file from scratch using lasio ~ASCII ----------------------------------------------------- 10 0.026008 10.5 0.056402 11 0.58473 11.5 0.062889 12 0.063426 12.5 0.38872 13 0.75342 13.5 0.93299 14 0.70876 14.5 0.21405 15 0.948 15.5 0.96069 16 0.95769 16.5 0.47167 17 0.92044 17.5 0.45118 18 0.41889 18.5 0.42029 19 0.30528 19.5 0.15235 20 0.088225 20.5 0.38494 21 0.026402 21.5 0.55415 22 0.33504 22.5 0.27227 23 0.15694 23.5 0.67574 24 0.61331 24.5 0.39824 25 0.12945 25.5 0.14877 26 0.93639 26.5 0.2013 27 0.76118 27.5 0.44274 28 0.0078593 28.5 0.86707 29 0.077415 29.5 0.61982 30 0.92987 30.5 0.4554 31 0.90304 31.5 0.23425 32 0.85763 32.5 0.03689 33 0.53212 33.5 0.48849 34 0.55165 34.5 0.55116 35 0.0071184 35.5 0.16983 36 0.82744 36.5 0.80642 37 0.46575 37.5 0.91243 38 0.72884 38.5 0.94173 39 0.16294 39.5 0.97191 40 0.25037 40.5 0.57772 41 0.40011 41.5 0.63539 42 0.70898 42.5 0.042878 43 0.20613 43.5 0.25082 44 0.75637 44.5 0.87049 45 -9999.25 45.5 -9999.25 46 -9999.25 46.5 -9999.25 47 -9999.25 47.5 -9999.25 48 -9999.25 48.5 -9999.25 49 -9999.25 49.5 -9999.25
plt.plot(l['DEPT'], l['FAKE_CURVE'])
[<matplotlib.lines.Line2D at 0xb4d0a90>]
os.remove(fn)