Basic Python For Log Analysis
Basic Python For Log Analysis
Course creator
Manuel David Soto. Geological Eng, UCV (1997). MSc in Geology, University of Texas at Austin (2007).
20 years of experience in operations, exploration and petrophysics. Now in the Petrophysical Specialist team,
Repsol, Madrid.
2
Content of the course
Introduction: Coding, Python and its packages. Installing Python, Jupyter and main libraries.
Session 1: Variables and data types (numeric, Boolean, dictionary, sequences). Arrays. Functions.
Session 2: Flow control. Reading & writing text and image files. Plots & multi plots. Univariate and bivariate analysis.
Session 3: Reading and displaying input logs. Parameter selection (function and mask).
Calculation (formulas), summation & displaying output logs. Typing and regression.
3
Introduction
4
Introduction 1
5
Int 1. Why learn to code?
What is coding?
From: https://grasshopper.app
6
Int 1. Why learn to code?
Most of our jobs are focus on acquire and process data, and
produce reports
7
Int 1. Why learn to code?
8
Int 1. Why learn to code?
https://iseprostorglive.blob.core.windows.net/user-assets/projects/AIhDsT0NGhVzHl2q9duLx3hVBPFfe6aW/assets/mc-
cb5aedfdad8b2301cdaf3efd34de50de.mp4
9
Int 1. Why learn to code?
10
Int 1. Why learn to code?
11
Int 1. Python programming language
• It was initially designed by Guido van Rossum in 1991 and then developed by Python Software Foundation
• It was mainly developed for emphasis on code readability, and its syntax allows programmers to express concepts in fewer lines of code
Advantages
• Readability: Python syntax is clear, making it easy to understand any piece of code.
• Fast learning curve: simple and intuitive syntax means it is easy to learn.
• Open source: Python is free and binaries are distributed by Python foundation.
• Python is safe: As there are no pointers like C, memory is protected, so the user will be able to see all errors and correct them.
• All batteries inside: standard and external libraries give to Python an unlimited power to tackle problems in different disciplines.
12
Int 1. Python programming language
Advantages
From: https://www.tiobe.com/tiobe-index/
13
Python
Int 1. Python programming language
Python libraries
https://docs.python.org/3/library/
https://pypi.org/
https://www.cgtrader.com/ 14
Int 1. Python programming language
Python libraries
https://docs.python.org/3/library/
https://pypi.org/
15
Int 1. Python programming language
Success histories
16
Introduction 2
17
Int 2. Installating Python
Two options
www.Python.org
www.anaconda.com
18
Int 2. Standard Python installation
https://www.Python.org/downloads/
Due to issues with the main libraries (they are not ready for 3.9.1 yet), we are
going to install an older version (3.8.6 for Windows 64 bits), you can get it at:
https://www.python.org/ftp/python/3.8.6/python-3.8.6-amd64.exe
19
Int 2. Standard Python installation
Step 1
Click off: the Install launcher for all users to make the program
only available for your user.
20
Int 2. Standard Python installation
Step 2
21
Int 2. Standard Python installation
Step 3
C:\Python386
22
Int 2. Standard Python installation
Step 4
23
Int 2. Standard Python installation
Step 5
24
Int 2. Standard Python installation
Step 6
C:\Python386\Scripts
and
C:\Python386
25
Int 2. Standard Python installation
Step 7
26
Int 2. Installing external packages
If you have another pip installations, be sure to execute these
pip: makes everything easy for you commands in the right location, such as:
C:\Python386\Scripts
The command pip (package installer for Python) allows the
installation of any package (libraries) available in the Python
community, the command syntax is:
Or in sequential manner:
27
Int 2. Installing external packages
Tutorials
https://learnxinyminutes.com/docs/python/
https://www.stavros.io/tutorials/python/
https://wiki.python.org/moin/BeginnersGuide
https://www.youtube.com/channel/UCxs2IIVXaEHHA4BtTiWZ2mQ/videos
https://pyvideo.org/
29
Introduction 3
30
Int 3. Reproducible research
31
Int 3. Reproducible research
32
Int 3. Jupyter Notebook
33
Int 3. Jupyter Notebook
34
Int 3. Jupyter Notebook link
https://iseprostorglive.blob.core.windows.net/user-assets/projects/AIhDsT0NGhVzHl2q9duLx3hVBPFfe6aW/assets/mc-
6a54e3f64a60e9a7a8cbf2d58713168c.mp4
35
Int 3. Jupyter Notebook
Running Jupyter
This will open a command window (don't close it) as well as the
Jupyter environment on your default web browser.
36
Int 3. Jupyter notebook links
Notebook examples:
https://juPyter-notebook.readthedocs.io/en/stable/examples/Notebook/examples_index.html
Notebooks by area:
https://github.com/juPyter/juPyter/wiki/A-gallery-of-interesting-Jupyter-Notebooks
37
Introduction 4
38
Int 4. Python in the Cloud
There are several services that allow users to run Python code in the Cloud. These services are free for starting
users. The most common services are:
• Binder
• Kaggle kernels
• Google Colaboratory (Colab)
• Microsofft Azure notebooks
• CoCalc
• Datalore
39
Int 4. Google Colaboratory
40
Int 4. Google Colaboratory
https://Colab.research.Google.com/
41
Int 4. Google Colaboratory links
https://iseprostorglive.blob.core.windows.net/user-assets/projects/AIhDsT0NGhVzHl2q9duLx3hVBPFfe6aW/assets/mc-
c41aae8939705703b234e4f8bb389b34.mp4
(Spanish) https://www.youtube.com/watch?v=Vhl91Az-rzo
(English) https://www.youtube.com/watch?v=i-HnvsehuSw
https://towardsdatascience.com/getting-started-with-Google-Colab-f2fff97f594c
42
Conclusions
• Coding is a critical skill to master data analysis within our actual and future jobs.
• Coding expands your data analysis possibilities as well as allows geoscientists to have different perspectives.
• As starting point, let install the Python from the python.org website.
• Google Colaboratory or Microsoft Azure Notebooks are useful, but only for practicing and learning. Do not use confidential
data or codes in these services.
43
Annexes
GeoSci: http://geosci.xyz
Books
https://jakevdp.github.io/WhirlwindTourOfPython/
https://jakevdp.github.io/PythonDataScienceHandbook/
44