IMAGE is happening this week in Houston! I’m not presently there, but I will be speaking today (August 27th) at the RMS-SEPM luncheon in Denver. If you can’t make it to Houston and are still looking for some geoscience fun, come check out my talk! I’ll be sharing some geochem work that my colleagues and I did a while back at Great Western (now Chevron) and some of the struggles I’m having with the geomechanics I think could be indicated in the data.
In the upcoming weeks, I’ll work to summarize and bring you all the good stuff from IMAGE. This week, however, I continue on my streak of data analytics tools (yes…Excel does count as a DAT), and dive into “getting started with Python.” Let’s go!
Sarah Compton
Editor, Enspired
When to Script Data Treatments
Gorodenkoff/ Shutterstock.com
Last week, I gave some Excel tips that would simplify and hopefully speed up common workflows for geoscientists in our data analyses, but there are many other tools available to you.
Python is one such tool, and while it merits significantly more than a brief newsletter can provide, my goal here will be to arm you with some tools to get you started.
In the simplest terms, Python is a programming language. There are obviously more details and features to it than that, but when boiled down to its basic form, that’s what it is.
There are several reasons to step out of Excel and into Python. The list I’m about to cover is by no means extensive, and there are a lot of people doing much cooler and more sophisticated things with Python. That being said…
I turn to Python when I need:
Automation. While you can automate workflows in Excel, I’ve found Python easier to learn than VBA, even with the record Macro tool. Why spend five minutes manually copying and pasting from one file to another when I can spend two days writing a script to do it? 😂 If it’s a workflow I use regularly, the long-term efficiency that the script provides is worth it.
Changing the same thing repeatedly. Maybe I have a vendor whose pneumonic for a log freaks Petra out. I know I always need to change it, but I don’t want to manually change it every time I get a file from them. I can script that.
Pulling data out. I might want to extract specific data from a large set of different files. Rather than go into each file and manually pull out that data, I can write a script to search on keywords or columns and move the desired data into one file.
Putting data in. Different software requires data to be in certain formats to import. Rather than manually transform the data, I’d write a script to convert my data into the format my software wants. I’d also do this if I needed to import a large dataset, such as a bulk import of directional surveys into Geographix.
Analyzing data. This one can be tricky and is dependent upon what I want to do and what funds I have available. I more frequently find myself turning to Excel to make visuals these days, but for hardcore analytics, I’d still turn to Python or maybe R (I like to think of R as basically a free version of Matlab). I can run various algorithms and make plots right there fairly easily.
You will make mistakes. As an old colleague of mine can attest, there will be a learning curve, and you will make a mistake…like importing a directional survey into the tops of the database that then must be deleted (still sorry about that, Geoff!). Generally, though, I’ve found scripting worth it. You should give it a try!
A message from NVIDIA
Panel Discusses AI Transforming Energy
Learn how ExxonMobil, Shell, SLB, and Petrobras are using AI and HPC—powered by NVIDIA—to enhance energy exploration and production, reduce operational emissions, and accelerate CCUS development.
Now that you know in which cases you’d move from Excel to Python, let’s help you get started.
Python.org While there are many sites you can go to for python information, this is a great place to start. The name says it all.
You must pick an IDE: Interactive Development Environment.
This is like choosing between Petra or Geographix for your geologic work.
Though it can seem like there are 85,000 options, and users are very passionate about their particular IDE, it really doesn’t matter what you pick. Simply starting matters more.
I went with Spyder at first. PyCharm is also a popular option. If you’re unsure, you can test code snippets in different online environments.
You might hit a hiccup during install. There might be a question about which Python version you want to install or questions about environments. If there’s a default option, choose that, otherwise…
Google everything. I’ve said this before in another newsletter: Googling basically makes you a professional developer. Your favorite generative AI (e.g. ChatGPT) is also a great option.
If you’re going to ask questions in various forums such as Reddit or Github, questions should generally follow a format of, “Here’s a snippet of code I wrote to perform (whatever task you’re wanting). Here’s the error I get/here’s what happens when I run it. What’s wrong with it?” It is the internet, but generally, people will be happy to help out a beginner.
👍 If you enjoyed this edition of Enspired, consider supporting AAPG's brand of newsletters by forwarding to a friend or colleague and signing up for our other newsletters here.
➡️ Was this email forwarded to you? Sign up for Enspired here.
AAPG thanks our advertisers for their support. Sponsorship has no influence on editorial content. If you're interested in supporting AAPG digital products, reach out to Melissa Roberts.