The world’s leading publication for data science, AI, and ML professionals.

Visualising Well Paths on 3D Line Plots with Plotly Express

Working With Plotly Express 3D Line Plots

Visualisation is one of the critical tasks we use to understand well log data and the subsurface. This includes viewing data on well log plots, scatter plots and histograms. By doing this, we can gain a solid understanding of our data. However, working with 2D plots is sometimes not enough and we need that extra dimension by going to 3D.

One excellent use case for 3D visualisations within petrophysics and geoscience is to visualise the path of a well.

In the early days of oil and gas exploration, wells were drilled vertically into the subsurface. However, as technology advanced, the industry shifted from vertical to horizontal drilling and eventually to drilling complex well paths facilitated by using the innovation of geosteering.

This evolution in well path geometry underscores the importance of visualising well paths in three dimensions. Doing so allows us to gain a better understanding of how wells have penetrated the geological layers, and to plan future wells to avoid collisions or issues.

Within this article, we will look at how we can take well survey data, which records the position of a well, and display it using a 3D line plot from Plotly Express.

The Data

For this short tutorial, we are going to be using surveys from eight wells located in the Dutch Sector of the North Sea. This data has been sourced from the NLOG.nl website, which provides free-to-use well log data that has been acquired over the past several decades.

These files contain the following columns:

  • MD: Measured Depth (m)
  • INC: Borehole Inclination (degrees)
  • AZI: Borehole Azimuth (degrees)
  • TVD: True Vertical Depth (m)
  • XOFFSET: Position of the well in the X direction (m)
  • YOFFSET: Position of the well in the Y direction (m)

To make data loading easier, the column names in each file are the same.

Full details of the dataset can be found at the end of the article.

Additionally, all of the wells used in this tutorial share the same origin. I will be covering how we can convert the XOFFSET and YOFFSET to grid coordinates in a future article.

Setting Up the Data

First, we need to import a number of libraries. For this article, we will keep it relatively simple by importing pandas – to read our csv data and Plotly Express to create our visualisation and os to allow us to read our directory with the files.

import pandas as pd
import plotly.express as px

import os

We can load the data into Python and Pandas in a few ways.

To simplify things, I have kept the code in long-form to help those new to Python understand what is happening.

First, we need to create an empty list to store our file paths in.

# Create empty list to store file paths
survey_data = []

Next, we will create a variable to store the file path location of our CSV files that contain the survey data.

# Set up the file path location. This can be a relative or absolute path
file_path = 'Data/Notebook 43/'

Finally, we can loop through each file within the file_path directory and check for any files with a .csv extension. Once it finds these files, the full file path is then appended onto the file_path list.

# Loop through each file within the file_path location
for f in os.listdir(file_path):
    # Check for CSV files
    if f.endswith('.csv'):
        # Add CSV file location to the survey_data list
        survey_data.append(f'{file_path}{f}')

survey_data

When we view the survey_data list we get back the following:

['Data/Notebook 43/NLOG - A12-A-01 - Survey.csv',
 'Data/Notebook 43/NLOG - A12-A-06 - Survey.csv',
 'Data/Notebook 43/NLOG - A12-A-07 - Survey.csv',
 'Data/Notebook 43/NLOG - A12-A-02 - Survey.csv',
 'Data/Notebook 43/NLOG - A12-A-05 - Survey.csv',
 'Data/Notebook 43/NLOG - A12-A-07-ST1 - Survey.csv',
 'Data/Notebook 43/NLOG - A12-A-04 - Survey.csv',
 'Data/Notebook 43/NLOG - A12-A-03 - Survey.csv']

Once we have the file paths, we need to combine them into a single pandas dataframe using .concat from pandas and the map function.

df = pd.concat(map(pd.read_csv, survey_data))

When we view the dataframe (df) we will get back the following.

Alternatively, if you are a more advanced Python user and are looking for something more efficient to load multiple files directly into a pandas dataframe, then you can use the following function.

As you can see, it is much more condensed.

# Alternatively:
import glob
df = pd.concat(map(pd.read_csv, glob.glob('Data/Notebook 43/*.csv')))

To confirm that we have all of the wells loaded, we can call upon the WELL column and view the unique values within it.

df['WELL'].unique()

Which returns an array containing 8 wells.:

array(['A12-A-01', 'A12-A-06', 'A12-A-07', 'A12-A-02', 'A12-A-05',
       'A12-A-07-ST1', 'A12-A-04', 'A12-A-03'], dtype=object)

Creating an Interactive Plotly Express 3D Line Plot

For this example, we will use the 3D line plot from Plotly Express rather than using matplotlib’s 3D plot. From my experience, generating and working with 3D plots this way seems quicker, more efficient, and easier.

To create our 3D Line plot with Plotly Express, we first need to create a figure and assign it to px.line_3d().

Within this function, we will pass in our XOFFSET, YOFFSET, TVD and WELL columns.

This will allow us to plot the X, Y and TVD (True Vertical Depth) position of each well, an differentiate them with colour using the WELL column.

fig = px.line_3d(x=df.XOFFSET, 
                 y=df.YOFFSET, 
                 z=df.TVD, 
                 color=df.WELL)
fig.show()

Once we run the above code, we get back the following figure.

It is obvious from the figure that we need to tweak this to get something that is much better.

There are a few issues with this plot that we need to address:

  • the overall figure is small
  • the line widths are very thin
  • the well paths are upside down

We can resolve this with a few tweaks.

First, we will update the layout of the plot and define a width & height parameter.

Then we will update the z-axis, which contains the TVD measurement, and we will set it so the scale is in reverse.

Finally, we can make the lines thicker by using the call to update_traces().

fig = px.line_3d(x=df.XOFFSET, 
                 y=df.YOFFSET, 
                 z=df.TVD, 
                 color=df.WELL)

fig.update_layout(width=800, 
                  height=800,
                  autosize=False,
                  scene={'zaxis':{'autorange':'reversed'}})

fig.update_traces(line={'width':10})

fig.show()

When we run the above code, we get back the following interactive figure.

We can see that our well paths are now orientated correctly, and we have a slightly bigger figure to work with.

Visualising data this way allows us to see where the wells are going and if there are any sidetracks from any of the wells. If we were focusing on planning future wells, we would be able to identify any potential issues early on in the process.

Summary

Visualising well paths is an excellent way to understand where your well is. Not only where it is located in the subsurface but also in relation to other nearby wells.

Within this short tutorial, we have seen how we can utilise Python and the Plotly Express library to visualise multiple well paths on an interactive 3D plot. This allows us to gain a solid understanding of where our wells are located in an easy-to-use way.

Give it a try on your next project.

Data Details

The data used within this tutorial was downloaded from NLOG.nl, which is a website that contains well logging data for the entire Dutch sector of the North Sea. The data is free to download and use. Full details of the data licence can be found here, but a summary of the usage is provided here from the Intellectual Property Rights section:

NLOG.NL does not claim any rights (except domain names, trademark rights, patents and other intellectual property rights) in respect of information provided on or through this website. Users are permitted to copy, to download and to disclose in any way, to distribute or to simplify the information provided on this website without the prior written permission of NLOG.NL or the lawful consent of the entitled party. Users are also permitted to copy, duplicate, process or edit the information and/or layout, provided NLOG.NL is quoted as the source.


Thanks for reading. Before you go, you should definitely subscribe to my content and get my articles in your inbox. You can do that here! Alternatively, you can sign up for my newsletter to get additional content straight into your inbox for free.

Secondly, you can get the full Medium experience and support thousands of other writers and me by signing up for a membership. It only costs you $5 a month, and you have full access to all of the fantastic Medium articles, as well as the chance to make money with your writing.

If you sign up using my link, you will support me directly with a portion of your fee, and it won’t cost you more. If you do so, thank you so much for your support.


Related Articles