This example shows:
In [1]:
import lasio
print(lasio.__version__)
import datetime
import numpy
import os
import matplotlib.pyplot as plt
%matplotlib inline
In [3]:
depths = numpy.arange(10, 50, 0.5)
synth = numpy.log10(depths) * 10 + numpy.random.random(len(depths))
synth[15:25] = numpy.nan # Add some null values in the middle
In [4]:
plt.plot(depths, synth)
Out[4]:
In [6]:
l = lasio.LASFile()
In [7]:
l.header
Out[7]:
Let's add some information to the header:
First, let's change the date.
Note that when changing the value of a HeaderItem like the well["DATE"] object above, you must be careful to change the value attribute rather than the HeaderItem itself. (This will be made easier in the future.)
In [8]:
l.well["DATE"].value = 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:
In [10]:
# HeaderItem = namedlist("HeaderItem", ["mnemonic", "unit", "value", "descr"])
l.params["ENGI"] = lasio.HeaderItem("ENGI", "", "kinverarity@hotmail.com", "Creator of this file...")
And finally, add some free text to the ~Other section:
In [11]:
l.other = "Example of how to create a LAS file from scratch using las_reader"
In [12]:
l.add_curve("DEPT", depths, unit="m")
l.add_curve("SYNTH", synth, descr="Synthetic data")
In [16]:
fn = "scratch_example_v2.las"
if os.path.exists(fn): # Remove file if it already exists
os.remove(fn)
with open(fn, mode="w") as f: # Write LAS file to disk
l.write(f)
with open(fn, mode="r") as f: # Show the result...
print(f.read())
In [17]:
fn2 = "scratch_example_v1.2.las"
if os.path.exists(fn2): # Remove file if it already exists
os.remove(fn2)
with open(fn2, mode="w") as f: # Write LAS file to disk
l.write(f, version=1.2)
with open(fn2, mode="r") as f: # Show the result...
print(f.read())
In [19]:
l_v12 = lasio.read(fn)
print("Reading in %s" % fn)
print(l_v12.keys())
In [20]:
plt.plot(l_v12["DEPT"], l_v12["SYNTH"])
print(l_v12.well["DATE"])
In [21]:
os.remove(fn)
os.remove(fn2)
In [13]: