LAS files - Python

2.4k Views Asked by At

I'm pretty sure this is a very menial question about LAS files, but I wasn't entirely sure how to google this. For context, I'm trying to create a plot given the information in a LAS file.

import lasio as ls
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

well = ls.read(r'1051325649.las')
df = well.df() 

fig = plt.subplots(figsize=(10,10))

#Set up the plot axes
ax1 = plt.subplot2grid((1,3), (0,0), rowspan=1, colspan = 1) 
ax2 = plt.subplot2grid((1,3), (0,1), rowspan=1, colspan = 1)
ax3 = plt.subplot2grid((1,3), (0,2), rowspan=1, colspan = 1)

ax1.plot("GR", "DEPT", data = df, color = "green") # Call the data from the well dataframe
ax1.set_title("Gamma") # Assign a track title
ax1.set_xlim(0, 200) # Change the limits for the curve being plotted
ax1.set_ylim(400, 1000) # Set the depth range
ax1.grid() # Display the grid

The LAS file pretty much looks like this where I want to create a plot where the far left column "DEPT" should be the X-axis. However, the "DEPT" or depth column isn't able to be made into a format to allow for me to plot it. **Note: there is a GR column on the right not in this picture, so don't worry. Any tips would help greatly.

enter image description here

2

There are 2 best solutions below

0
On

Short answer:

plt.plot expects that both "GR" and "DEPT" are columns in df, however the latter (DEPT) is not a column, it is the index. You can solve it by converting the index in df to a column:

df2 = df.reset_index()
ax1.plot("GR", "DEPT", data = df2, color = "green")
0
On

When reading .las files using lasio library and converting them to pandas dataframe, it automatically sets DEPT as the index for the dataframe.

There are two solutions for this problem:

  1. Use the data as-is:
import matplotlib.pyplot as plt
import lasio

well = lasio.read('filename.las')
well_df = well.df()

plt.plot(well_df.GR, well_df.index)

And well_df.index will be the DEPT values.

  1. Reset the index and use DEPT as a column
import matplotlib.pyplot as plt
import lasio

well = lasio.read('filename.las')
well_df = well.df()

well_df = well_df.reset_index()

plt.plot(well_df.GR, well_df.DEPT)