Python Series – Introduction

//Python Series – Introduction

Python Series – Introduction


Python Introduction


Written and Edited by Debora Martogi

In today’s digital transformation age, aka the “Industry 4.0”, Subject Matter Experts (SMEs) are encouraged to adapt and learn new tools to help them analyze big data. And when we talk about big data, the first things that came into mind are usually Artificial Intelligence (AI) and Machine Learning (ML). Though these tools can help us provide some correlation or predictions out of the data we provided, SMEs should still take caution in applying these tools. Without intelligent sound judgment, improper implementation of AI could lead to uneconomical decisions. This is why we still need these SMEs, people who understood the concept pretty well.

In this digital transformation age, companies have been looking into candidates who are not only SMEs but also can program. This way, they do not necessarily need to hire software engineers to update their software packages and in-house programs. This is why having a petroleum engineering degree and programming experience could make you ahead in getting into the industry. Some of the popular programming languages used in the industry are Python, C++, Fortran, and  MATLAB. In terms of easiness, learning Python is relatively easy once you are familiar with MATLAB. C++ and Fortran, on the other hand, is the most challenging to learn in my experience. Fortran is one of the oldest programming languages. It is usually needed when companies need to dig into their old programs and perhaps update/ adapt them to a newer programming version. In terms of computational efficiency, generally, the lineup from most efficient to least efficient is Fortran (tie), C++ (tie), Python, and MATLAB. This is since Fortran and C++ are low-level fast languages, while Python and MATLAB are high-level scripting languages. Usually, you will need to build all code script and structure for C++ and Fortran. What’s convenient about Python and MATLAB, there are built-in packages available to perform general engineering computations and scripting (i.e., integral, differential equations, arithmetic, geometric, etc.). Personally, I use MATLAB for plotting and currently shifting into Python to run the algorithm. One disadvantage of MATLAB is users need to pay to access it while free compilers are available for Fortran, C++, and Python. MATLAB is available for free for Texas A&M University students and can be obtained from the TAMU software store. Given the high popularity of knowing Python in the job application lately, we will share several basic tools to analyze petroleum engineering analysis using Python.

Python Starting Guide


Here are a few starting tips to get you started with Python.

  • Python Compiler

 One of the popular Python compilers out there is Anaconda. Anaconda individual edition is free for students, solo practitioners, and researchers. Anaconda is equipped with several basic applications under the home tab. The CMD.exe prompt is similar to the terminal in your PC/laptop. This is where we initialize application (i.e., Spyder, Jupyter, JupyterLab, etc.) updates, install packages for the applications, etc. Spyder, Jupyter Notebook, and IP[y] are some of the applications you could use to write Python scripts. Spyder is recommended for beginner users. Jupyter notebook can also be useful where users can write Live Script (description) as shown on this site.

 

  • Python library

To perform calculations, plot figures, use symbolic terms, etc., we need to call several built-in Python libraries. Several useful ones are numpy (array, arithmetic, basic statistics), Matplotlib (plotting), Pandas (data analysis and manipulation), SciPy (linear algebra, scientific computing), and SymPy (symbolic terms). To call the library, you will need to enter the following command at the beginning of your script or before calling the associated command. The following are several ways of calling a library.

 

Recommended:               import [insert library name] as X

Example: Calculating cos(60)               

 

import numpy as np

answer = np.cos(np.radians(60))

Not recommended:          from [insert library name] import *

Example: Calculating cos(60) 

from numpy import *

Answer = cos(radians(60))

The second approach is not recommended when you are using multiple libraries. Use this approach only if you are using one library throughout the whole script.

 

Following are several cheat sheets links for each library:

Numpy             Matplotlib          Pandas – 1            Pandas – 2           SciPy             SymPy

 

  • Reading data from files

Reading text files in the format of .txt can be done easily through the following command

import numpy as np

np.loadtxt(‘[filename].txt’,usecols=(0,1),unpack=True)

 

  • Finding python resources online (GitHub, google)

There are plenty of Python resources online, which is searchable through google. Complete documentation of Python can be found here, and complete documentation of Spyder can be found here. More information on the GitHub repository will be shared in future articles.

 

Stay tuned for our first article on tackling petroleum engineering analysis using Python in the next 2 weeks. Until then, stay well everyone!


Disclaimer: The Well Log is a non-profit publication aimed “purely” to educate students at Texas A&M University and beyond on information pertinent to the petroleum engineering industry. All articles are written by student volunteers based on information obtained through online sources and SPE publications. If you are the owner of any materials we cited and would like us to remove it from our publications, please contact us at thewelllog@gmail.com.


Sources:

https://pubs.spe.org/en/twa/twa-article-detail/?art=7347

https://pubs.spe.org/en/twa/twa-article-detail/?art=5442

https://docs.spyder-ide.org/current/installation.html

https://www.anaconda.com/pricing

https://data-flair.training/blogs/python-libraries/

https://geo.libretexts.org/Courses/University_of_California_Davis/UCD_GEL_56

https://s3.amazonaws.com/assets.datacamp.com/blog_assets/Numpy_Python_Cheat_Sheet.pdf

https://s3.amazonaws.com/assets.datacamp.com/blog_assets/Python_SciPy_Cheat_Sheet_Linear_Algebra.pdf

https://pandas.pydata.org/Pandas_Cheat_Sheet.pdf

2020-10-27T01:59:59+00:00

Leave A Comment

Welcome Ags!

Welcome to the 2020-2021 academic year. Have a blast!