
Within the geosciences, Python is becoming increasingly popular and is often recommended as a starting point for anyone interested in learning a programming language. It can be used for research and development, creating custom applications to automate workflows, and it can also be used as an aid when learning geoscience topics.
For example, within petrophysics it can sometimes be difficult to understand how the parameters of the Archie equation can impact the final result. Especially if you are just starting out.
Learning programming is not a new phenomenon within geoscience. It has been common within the oil and gas industry for many geoscience professionals to write their own code or algorithms. Often this would be in earlier languages such as FORTRAN and C. Some of the older professionals still prefer to create their own apps today using these languages. However, they can often be difficult to work with and not very easy to understand for the new programmer.
This is where Python comes in.
It is an excellent language for beginners due to its easy-to-read and easy-to-write nature, and has access to a large amount of open-source libraries. Even ones for multiple geoscience disciplines, including petrophysics. Not only that, there is an abundance of tutorials available freely on the internet.
If you are still not 100% sure on whether it is worth learning Python, I will cover 5 reasons why I think it is a great skill to learn. This is aimed at those who are unsure whether they should start learning Python or where to start, however, it can equally help those who have already started and are interested in learning more.
Easy To Learn and Write
As mentioned above, Python is a great language for beginners, especially those with geoscience and Petrophysical backgrounds.
This is due to its easy-to-read and easy-to-write syntax.
For example, if we wanted to carry out a simple for loop – a loop which iterates over a certain condition and performs an action for each iteration, we would write:
for i in range(5):
print(i)
Which would return:
0
1
2
3
4
If we were do do the same using C++, we would need to write the following:
for(int i = 0; i < 5; i++)
{ std::cout << i << std::endl; }
We can see immediately that it becomes much harder (if you are not a C++ developer) to understand what is happening with the extra syntax and it takes longer to decipher.
One of the key differences between the above code snippets, is that in Python, we do not need to declare what type the variable is. Whereas with C++, we need to declare that i is an integer.
This is thanks to Python being dynamically typed. Meaning that the types for the variables can be worked out at runtime and can even change When the code is running. For example, i could start as an integer and later become a string.
This is great for newcomers, however, to the experienced developer that is used to static typing, it can be a little unsettling.
Research And Development

The process of analysing large well and field datasets can be made simple when using Python. Libraries such as pandas and numpy simplify the process of analysing and working with such data.
Jupyter Notebooks provide an excellent place to develop and expand on ideas. Not only that, they can be used to document your thought process and any equations that you have used and where they have come from. These notebooks can then be shared with your colleagues and even form the basis of a research or conference paper.
When creating code, you may feel that Jupyter Notebooks are a little limiting or start to become convoluted as the number of cells increase. It is at this stage, when I am developing research ideas, that I switch over to writing my code in scripts or a custom library, which can then be called upon multiple times from different locations. One way that helps me speed this process up is by creating an interactive front end. This allows me to create and display key parameters as well as any outputs.
Libraries, like Streamlit, provide a fast and simple way to create a friendly user interface without having to learn HTML, CSS and JavaScript.
With the large number of open source Python libraries the process of research and development can be sped up. Especially, when it comes to advanced data analytics. For example rather than writing a Fast Fourier Transform from scratch, it can easily be imported from X library and then applied to your dataset. Similarly, when it comes to machine learning, you do not need to start from scratch as many of the popular algorithms have already been implemented in libraries such as Scikit-Learn.
Enhancing Your Learning of Geoscience and Petrophysics
When learning a discipline such as Petrophysics, which has numerous equations, it can be helpful to have an environment where you can easily experiment with them and visualise the impacts of changing key parameters.

For example, when starting out in petrophysics, you will learn about the Archie Water Saturation equation. This equation contains numerous parameters such as a (tortuosity exponent), m (cementation exponent) and n (saturation exponent) and it can be difficult to understand how each of these impacts the final water saturation.
One way to help understand their impact is by creating an interactive example in a Jupyter notebook using the following code.
import ipywidgets as widgets
from IPython.display import display
import numpy as np
# Archie's Equation function
def archie_sw(a, PHI, m, Rw, Rt, n):
Sw = ((a / PHI**m) * (Rw / Rt))**(1/n)
return Sw
# Interactive widget
def update_widget(a=1, PHI=0.2, m=2, Rw=0.1, Rt=2, n=2):
Sw = archie_sw(a, PHI, m, Rw, Rt, n)
print(f"Water Saturation (Sw): {Sw:.2f}")
widgets.interact(update_widget,
a=widgets.FloatSlider(value=1, min=0.1, max=5, step=0.1, description='a:'),
PHI=widgets.FloatSlider(value=0.2, min=0.01, max=0.4, step=0.01, description='PHI:'),
m=widgets.FloatSlider(value=2, min=1, max=4, step=0.1, description='m:'),
Rw=widgets.FloatSlider(value=0.1, min=0.01, max=1, step=0.01, description='Rw:'),
Rt=widgets.FloatSlider(value=2, min=1, max=100, step=1, description='Rt:'),
n=widgets.FloatSlider(value=2, min=1, max=4, step=0.1, description='n:'))
This will create the following setup in your Jupyter Notebook, and each time you modify a parameter, the output will update, which in turn will allow you to explore the impact of the different parameters.

This simple example can be further modified and applied to synthetic or even real data to help you get a better understanding of the equation.
Geoscience and Petrophysical Python Libraries
As mentioned above, Python has a wide range of open-source and powerful libraries that can make working with data much easier.
Pandas can be used for loading, storing and analysing data stored within a tabular format.
Matplotlib is great for creating data visualisations. It may appear to generate boring and basic plots at first, but with patience and dedication, it can be manipulated to generate any type of graph that is commonly used within data analytics.
In addition to these libraries, there are numerous libraries that are specific to geoscience and petrophysics, including:
LASIO: A simple yet powerful library for easily loading .las files into a workable Python format.
import lasio
# Load a LAS file
las = lasio.read("example.las")
# Print the header information
print("Well Information:")
print(las.well)
print("nCurve Information:")
print(las.curves)
print("nParameter Information:")
print(las.params)
DLISIO: A library developed by Equinor to simplify the process of loading and exploring complexly structured DLIS files.
import dlisio
# Load a DLIS file
with dlisio.load("example.dlis") as file:
# Assuming there's at least one frame
for d in file:
# Print logical file information
print("Logical File:")
print(d.describe())
# Access and print specific frame information if needed
for frame in d.frames:
print("nFrame Information:")
print(frame.describe())
Welly: A useful library that provides a range of tools to work with well log data, including loading LAS files, quality checking of data, generating well log plots and much more.
from welly import Well
# Load a LAS file using Welly
well = Well.from_las("example.las")
# Display a summary of the well
print(well)
StripLog: A library for generating, processing and analysing subsurface strip logs for stratigraphy and chronostratigraphy.
GemPy: Library for creating complex 3D structural geological models, which can consider geological structures, including faults, folds and unconformities.
Career Development

It is no secret to geoscience professionals that the oil and gas industry goes through various cycles of boom and bust. Through no fault of your own, you may find that your time in your current role has come to an end.
Taking advantage of learning python during the good periods can be beneficial, especially if you are looking to make a career move to a different role or industry. Python is an essential skill for the majority of roles in Data Science and machine learning. Having Python on your CV / resume can not only show prospective employers your skills, but it can also show your commitment to self development and keeping up with the latest technologies.
To further back up this skill on your CV or Resume, it is highly recommended to create a few example projects on a GitHub account. These can then be shown to your prospective employer your application of Python to real-world skills. There are a number of articles out there that go into to detail on how to create a great GitHub profile for prospective employers.
Admittedly, my GitHub profile does have a number of projects that could be better organised. But one that I ensure is is highlighted is my Python and Petrophysics series. This series showcases a number of notebooks that I have built over the last few years that explore various ways Python can be used with Petrophysical datasets. This ranges from creating simple log plots with matplotlib to applying machine learning algorithms to predict missing data.
In addition to looking good on your CV, if you have documented your learning within Jupyter Notebooks in a way that is easy to access, then you have an excellent reference guide for the future.
Summary
Python is a great skill to learn, especially within the Geoscience domain. Not only can it help your day-to-day work, it can also help improve your career options for the future, should you wish to change industry or job. This article has covered a few aspects of why it will be a great benefit to learn.
Additionally, there are already a number of Python open-source libraries out there to help those involved in geoscience within the oil and gas industry and beyond. These are a great starting point when you go beyond the basic course material as these tools can be directly applied to the job or project that you are working on.
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! Also, if you have enjoyed this content and want to show your appreciation, consider giving it a few claps.