Handling Big Volume of Petroleum Well Log Data with a Boosted Time-Efficiency on Python | by Yohanes Nuwara | Towards Data Science

This is a story of a geophysicist who has been already getting tired of handling the big volume of well log data with manual input in most commercial software out there. Who feels the same I feel? However, I successfully developed a way to get out of this tiring routine of manual input barely using programming skills with Python. Here I would like to share a tutorial with you. I will assume you are familiar with geology, geophysics, petroleum engineering, and all things related to geoscience. However, if you’re not familiar with it, it’s very OK, I’m very glad to introduce you to the daily activities we are working with. Python is, to be honest, a very flexible yet very powerful language for open-source computation.
In the petroleum industry, well log data is a very valuable source of data to interpret the image of the subsurface deep down the earth and get more information about what is inside the rocks: if you’re lucky enough, you will find oil. Kidding anyway! The business of finding oil took so many years. The key is, time-efficiency. Being time-efficient, mainly during the stage of exploration, means a lot to the future of the business. When a field has been already producing for decades, well log data never comes in a single or little volume. It can be 50, 100, or even 500 oil and gas wells. It’s surely very huge because lots of wells have been drilled. One well log data contains measurement data of the rocks, for instance, density, sonic velocity, gamma-ray, resistivity, and countless more. Thus, in total, a big volume of 46 well data may take up about 120 MB! Well log data commonly comes in LAS format (the format which I will entirely use in this tutorial).
To me personally, most commercial software that I knew so far has a time-efficiency limitation in the way we have to repeatedly and manually input all the detailed information about each well log data that we input. This can be tedious and cumbersome if we have a big volume of data.
Imagine how much time we will spend just for manually input and check for the units of the data! Then I found using Python very engaging!
Open your Python and firstly import the “three musketeers” of Python libraries; numpy, matplotlib, and pandas. The reason why I name them the “three musketeers” is that they just can’t stand alone since any basic computation in Python needs numpy and matplotlib, and data needs pandas.
import numpy as npimport matplotlib.pyplot as pltimport pandas as pd
Now go to your folder that contains your multiple well log data in LAS format. Copy the path of the folder, specify the path in Python, and paste the path on it.
import syssys.path.append('...')
Now is the fun part! You will read all the files. Import glob and import the files.
import globimport osfile_path = "/content/drive/My Drive/Colab Notebooks/well_logs"read_files = glob.glob(os.path.join(file_path, "*.las"))read_files
If it is successful, the path and file name of your multiple well log data will appear. If you read 100 well log data, it will appear as a very long list!
Since you will be interested only the filenames (without the folder path) which is the well names, for instance from the example above, only 660810-B-1BH and not the entire /content/drive/My Drive/Colab Notebooks/well_logs/660810-B-1BH.las, you can sort the unwanted file path names out and you will get only the well names.
well_names = []for files in read_files:   files = os.path.splitext(os.path.basename(files))[0]   well_names.append(files)print(well_names)
This will give you the well names
Investigate how much data you have.
print(len(well_names))
For instance, you have 45 well data. Since Python starts indexing from 0, not from 1, it means the first well name 660810-B-1BH and the last well, are respectively called by:
print(well_names[0])print(well_names[44]) # 45 wells minus one
In Python and any programming language, you almost always call something by index.
The formula of Python indexing is always: starts from zero, something minus one.
Now you already have the well names, it’s time read all the LAS data. You will use a very specific library dedicated to read LAS files, called lasio. Lasio is one of the available brilliant libraries to read LAS files, in fact you may also build a program from scratch yourself! However, lasio is enough for time-efficiency. This is the most important point that I would like to highlight, that you are able to import all the files simultaneously, even 100 files at a click, an action that you can barely do using some commercial software. During the import process, you don’t need to focus on manually check and input the appropriate units. Time for acting!
Install lasio first. I assume you may have been already very familiar with how to install a library. You may code a bit pip install, or a lot easier you may browse the libraries and import it in one of Python IDE called PyCharm.
pip install lasio
After being successfully installed, import it and write only 4 lines of code to read LAS files using lasio. But you have to be patient since it takes a relatively long time. The time it takes depends on how much well log data you import, however for estimation reading 50 well log will take no more than 30 seconds.
lases = []for files in read_files:   las = lasio.read(files)   lases.append(las)
The process of importing is in the same order as it reads the well names from start to end. During the process of importing, you may encounter a warning that says:
In my experience, it is normal, so everything is OK.
Congratulations! You have imported a very big volume of well log data in just no more than 5 minutes in total.
It’s time to see what your data looks like. Please remember that in our previous discussion, well names can be called by index. For instance, we call the index 19.
# type the numbers from 0 to max number of wells in the wellnames[...]find = well_names[19]# print the name of the searched wellprint("Well name:", find)
If index 19 is called, it will print the name of the 20th well name. Please again remember the rule of thumb above: index is something minus one.
The above code works just like a catalog. Now write the following code to see what’s inside the 20th well log data.
id_ = np.int64(np.where(wellnames==find)).item()print("Data available:", lases[id_].keys())# check more detailsprint("Detail about data:")print(lases[id_].curves)
It will print two things: the available measurement data in the well log, and the details (acronyms, units) of the well log data.
It tells you what data is available. Here the data available are: DEPTH, TVD, TVDSS, GR, KLOGH, NPHI, PHIF, RHOB, SW, and VSH. What are these? These are the acronyms (or so-called mnemonic) for rock measurement types, for instance GR stands for Gamma Ray, KLOGH for permeability, NPHI for neutron porosity, RHOB for density, and SW for water saturation. Each of these measurements has specific units that you have to notice.
This piece of information is very important, a lot more important than the content itself. This piece of information is what we see in the file header.
Now finally comes the last part of our tutorial. We will be very desired to visualize the well log. Input the desired measurement type in the data_view variable. For instance, we are interested to see the density log or RHOB data. Input RHOB. We will use matplotlib.
# peek or overviewing the well log# which data you want to see???data_view = 'RHOB' # input the measurement type which data you want                    # to seeprint("Data", data_view, "of well:", find)plt.figure(figsize=(5,10))plt.plot((lases[id_][data_view]), (lases[id_]['DEPTH']))plt.xlabel(data_view); plt.ylabel("Depth (m)")plt.grid(True)plt.gca().invert_yaxis()
The visualization just prints out the following:
Congratulations, this is the end of our tutorial!
If you still crave for more beautiful visualization of the above well log data, I have a wonderful recipe!
But since this tutorial does not cover on this matter, I will save it for later and write another tutorial if you are craving this.
First of all, you have learned how to import multiple well log data files; 50, 100, 200 files, or more, in no more than 5 minutes. You have already beaten the average time you take to manually input in commercial software. Secondly, you have learned how to catalog the files by indexing the data. There are 50, 100, 200 well names that you surely don’t want to call name by name, therefore indexing is a better way. Last but not least, you have learned how to print out the details of the data (header) and visualize the data.
In the long run, all I can say is that Python is very amazing for handling big data that beat the average time it takes to handle the same amount of data in common software. If you feel you can beat me in time by writing a more efficient code, contact me and please let me know!
Reach my GitHub: github.com/yohanesnuwara
Reach my email: ign.nuwara97@gmail.com
Reach my LinkedIn: https://www.linkedin.com/in/yohanes-nuwara-5492b4118/