Workshop: Loading Ogbon-1 in Python
Learning objectives
- Load the book's learning set from its CSV file in Python and read its 14 columns
- Tell the columns a model may read, the tool's logs, from the truth it learns
- Select one well, read one row and summarise one column
- Group a column by well, and find the number to beat
One Table, a Row for Each Half Foot
The book's learning set is one file, mlgeo-core/data/ogbon-learning-set.csv on this site: 10809 rows, one for each half foot of the nine wells, in 14 columns. Two say where the row is (well, depth_ft); six are the logs the book's own tool model records (GR_API, RHOB_gcc, NPHI_vv, DT_usft, RT_ohmm, PEF_be); and six are the generator's truth (lith, zone, pay, PHI_vv, SW_vv, K_md). Each name carries its unit. A model reads the logs and learns the truth. This workshop loads the file and reads it three ways, as the figure does: a row, a column down a well, and a column grouped by well.
The Data
The file is the book's own synthetic data: Ogbon-1, the Petrophysics book's well, and Ogbon-2 to Ogbon-9, the book's own hypothetical appraisal wells, 1201 rows each, one every 0.5 ft. Its comment lines at the top say so and name each unit, and pandas skips them. The logs are printed to stated precisions, gamma ray to two decimals, density to four, resistivity to four significant figures, so the numbers below are of the file's own digits. Pay is the Petrophysics book's net-pay rule on the truth, and K_md is 0 outside the reservoir rock.
Each step below gives its code and then what the book's kernel gives for the same computation on the same file.
Step 1: Load the File
Read It Once
One call reads the whole set; the comment lines are skipped. Every workshop in the book reads the file this way. Offline, download the file once and pass its local path in place of the URL.
import numpy as np
import pandas as pd
URL = "https://ogbonlab.com/mlgeo-core/data/ogbon-learning-set.csv"
df = pd.read_csv(URL, comment="#")
print(df.shape)
print(list(df.columns))
The book's kernel gives (10809, 14), and the columns well, depth_ft, GR_API, RHOB_gcc, NPHI_vv, DT_usft, RT_ohmm, PEF_be, lith, zone, pay, PHI_vv, SW_vv and K_md.
Step 2: What a Model May Read
Logs and Labels
Split the columns by what they are. A tool records the logs in any well; the truth is what the generator knows and a model must learn. A model that reads the truth reads the answer.
LOGS = ["GR_API", "RHOB_gcc", "NPHI_vv", "DT_usft",
"RT_ohmm", "PEF_be"]
TRUTH = ["lith", "zone", "pay", "PHI_vv", "SW_vv",
"K_md"]
X = df[LOGS]
y = df["pay"]
dz = df["depth_ft"].diff().iloc[1]
print(X.shape, y.sum(), y.sum() * dz)
The book's kernel gives (10809, 6), 5667 samples of pay and 2833.5 ft of it.
Step 3: One Well, One Row
Select, Then Locate
A boolean mask keeps one well's rows; iloc picks a row by its place.
og1 = df[df["well"] == "Ogbon-1"]
print(len(og1))
print(og1.iloc[700])
The book's kernel gives 1201 rows, and the 701st, Ogbon-1 at 6150.00 ft: GR_API 22.75, RHOB_gcc 2.1887, NPHI_vv 0.2567, DT_usft 92.40, RT_ohmm 7.536 and PEF_be 1.653; sandstone in the main sand, pay 1, PHI_vv 0.2556, SW_vv 0.2917 and K_md 655.2. It is the default row of the figure's plate (a).
Step 4: Summarise a Column
Mean, Range, Median
A mean says where a column sits; set beside the median it says whether a few large values pull it.
gr = og1["GR_API"]
print(gr.agg(["mean", "min", "max"]).round(2))
rt = og1["RT_ohmm"]
print(rt.agg(["mean", "median"]).round(3))
The book's kernel gives gamma ray a mean of 58.65 API, from 4.47 to 137.16, and resistivity a mean of 21.424 ohm.m against a median of 2.664 ohm.m: the oil sand's high readings pull the mean far above the middle of the well.
Step 5: Plot the Logs
Depth Down, Resistivity on a Log Axis
Logs are drawn against depth, increasing downward. Resistivity spans decades, so it goes on a log axis.
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 2, sharey=True)
ax[0].plot(og1["GR_API"], og1["depth_ft"])
ax[0].set_xlabel("GR (API)")
ax[1].semilogx(og1["RT_ohmm"], og1["depth_ft"])
ax[1].set_xlabel("RT (ohm.m)")
ax[0].set_ylabel("Depth (ft)")
ax[0].invert_yaxis()
plt.show()
The book's kernel gives the picture of the figure's plate (b): resistivity from 0.3812 to 161.2 ohm.m down Ogbon-1, more than two decades.
Step 6: Group by Well
One Number per Well
The mean of a 0 or 1 column is its share of ones, so the mean of pay by well is each well's share of pay.
by_well = df.groupby("well", sort=False)
print(by_well["pay"].mean().round(3))
print(round(df["pay"].mean(), 3))
The book's kernel gives 0.461 for Ogbon-1; 0.643, 0.642, 0.599, 0.643, 0.578 and 0.545 for Ogbon-2 to Ogbon-7; 0.000 for Ogbon-8; 0.609 for Ogbon-9; and 0.524 over the nine wells, the number to beat of Section 1.1.
What the File Is Not
The file is clean by construction: no cell is empty, every log of a well is on the same depths, and no borehole is washed out. Real well data have all three faults, and Chapter 12 builds the pipeline that makes a table like this one. It is also kind: every well carries Ogbon-1's beds, and one tool model logs them all.