Getting Started With Python as a Geoscientist? Here Are 5 Ways You Can Improve Your Code! | by Andy McDonald | Jan, 2024

5 Tips to Help You Get Off to a Better Start When Writing Python Code

Image representing a geoscientist coding. Image generated by DALL-E by the author.

Over the years, I have seen and worked on numerous Python scripts within the geoscience and petrophysics domains. In that time, I have seen (and also written) a variety of coding styles, from well-organised code that is well-documented to everything in a single Python file with little to no organisation. With the latter, it can be difficult to maintain, debug and understand when the code is revisited several months later. The purpose of writing the code will often dictate the style used.

If we are creating a script that may be used once or twice or are working under strict time constraints and pressures, then we may not be able to make things as pretty and organised as we would like. However, if we are creating code that we will use multiple times or are deploying it to other users, and if we have the time, we may want to structure the code or app in a way that will make it suitable for expansion later on. This can save time and headaches when you revisit your code and also avoids the dilemma of forgetting what the code does or was intended to do.

As a geoscientist, coding may not be part of your natural background. However, you may have seen and heard colleagues and friends discussing apps they have created, which has inspired you to give it a go.

In this article, I will share five tips I have learned over the years that have improved my geoscience Python applications. I do this hoping they will also help those venturing into the world of Python and machine learning for the first time.

These tips are also equally applicable to anyone who is not a geoscientist and is just starting out learning Python.

When creating Python apps at the beginning of your journey, it may be convenient and easy to keep all of your code within a single folder. However, as your project begins to grow in size and complexity, it may become difficult to maintain and navigate through your code base.