00 - Orientation and Setup¶
Part A - Foundations - Petrophys Curriculum
Welcome. This is the first lesson of the petrophys teaching curriculum. By the end of it you will know what the library is for, how to reach the well-log data that ships inside it, and where each later lesson fits into the bigger picture.
No prior experience with petrophys is assumed - only a working knowledge of basic petrophysics (gamma ray, density, neutron, resistivity, porosity, water saturation).
Learning goals¶
Understand what petrophys is: an open Python library for well-log analysis and formation evaluation, reached through a small front door (
pp.read,pp.plot,pp.interpret).Discover the bundled sample data with
pp.list_samples(...)and resolve a file withpp.sample(...).Take a guided tour of the two main teaching datasets:
GeoLink - North Sea clastic wells (primary teaching well 30/6-5, sample name
30_6-5).COSTA - 17 carbonate wells (
HW-3 ... HW-32); each file covers only the Kharaib-2 reservoir interval.
Read the curriculum roadmap (quickstart and own-data pages, Parts A and B) so you know where you are going.
Know honestly what this curriculum does not cover so you set the right expectations.
Why this matters¶
Formation evaluation is the discipline of turning raw borehole measurements into answers a subsurface team can act on: How much rock is reservoir? How porous is it? How much of the pore space is hydrocarbon rather than water?
The workflow always starts the same way - get the data in, and understand it -
before any physics is applied. This lesson is that starting point. Everything later
(clay volume, porosity, saturation, permeability, net pay, lithology solving) builds on
the Well and Curve objects you will meet here.
Prerequisites and kernel setup¶
Use a Python kernel in which Petrophys is installed. Create a virtual environment, install the package with the tutorials extra (Jupyter kernel support), and register the kernel. Run these commands in a terminal, not in the notebook.
Linux / macOS
python3 -m venv .venv
source .venv/bin/activate
python -m pip install "petrophys[tutorials]"
python -m ipykernel install --user --name petrophys
Windows (PowerShell)
py -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install "petrophys[tutorials]"
python -m ipykernel install --user --name petrophys
To work from a source checkout instead, run python -m pip install -e ".[tutorials]" from the repository root in place of the PyPI install.
Then select the petrophys kernel in your notebook editor. The small LAS examples are bundled with the package. Optional lessons need extras: petrophys[ml] for curve imputation, petrophys[dlis] for native DLIS files and petrophys[mcp] for the MCP server. The next cell imports Petrophys and shows the installed version.
import petrophys as pp
pp.__version__
'3.0.0'
Start with a plot, not an interpretation¶
LAS alone is enough. Formations and lithology are optional, and plotting does not calculate missing SW. pp.plot takes a well file directly; top and bottom set the depth window, here 2800-3000 m around the Brent Group of 30/6-5. The later scientific lessons explain each method; the Quickstart and Your own data pages of the documentation teach the short user-facing workflow.
first_plot = pp.plot(pp.sample("30_6-5"), top=2800, bottom=3000)
first_plot.warnings
[repository]\src\petrophys\preprocessing\standardization\curve_standardizer.py:851: UserWarning: SWC: inferred percent core saturation despite unit 'frac'; divided by 100 to v/v. Verify source units.
standardize_core_saturation(new_curve, inplace=True)
[repository]\src\petrophys\preprocessing\standardization\curve_standardizer.py:851: UserWarning: SOC: inferred percent core saturation despite unit 'frac'; divided by 100 to v/v. Verify source units.
standardize_core_saturation(new_curve, inplace=True)
["SWC: inferred percent core saturation despite unit 'frac'; divided by 100 to v/v. Verify source units.",
"SOC: inferred percent core saturation despite unit 'frac'; divided by 100 to v/v. Verify source units."]
The plot cell prints two diagnostics, and both come from the bundled file itself: 30/6-5 stores core water saturation (SWC) and core oil saturation (SOC) in percent although its LAS header labels them frac. Petrophys detects this, converts display copies to fractions and asks you to verify the source units; both messages are kept in first_plot.warnings. The file on disk is unchanged. The viewer draws SOC as “So Core” dots in the saturation track, on a 0-1 scale that puts each point where 1 - So falls on the Sw scale; pp.interpret (lesson 06) reports the same two curves when it reads the core data. Lesson 02 shows the evidence behind the conversion and how to declare units explicitly.
1. What is petrophys?¶
petrophys is a Python library for well-log analysis and formation evaluation. It covers the path from a raw LAS/DLIS file to interpreted reservoir properties, and groups its functionality into focused sub-packages. A high-level tour:
Module |
Purpose |
|---|---|
|
Front door: |
|
Format-specific readers and writers ( |
|
Core data model: the |
|
Quality control: standardization, bad-hole, value-range, normalization |
|
Shale/clay volume from GR, SP, neutron-density |
|
Porosity, saturation, permeability, cementation |
|
Multi-mineral solving |
|
Net pay, BVW, rock-quality index, flow units |
|
Hydrocarbon pore volume, OOIP/OGIP, zone summaries |
|
The dynamic workflow behind |
|
Log viewers, triple-combo, crossplots, Pickett plots |
|
Structured context export for reports and LLMs (lesson 19) |
|
MCP server that lets LLM agents drive Petrophys (lesson 20) |
We will meet many of these across the curriculum. The important idea for a start is that
every one of them consumes the same Well object - so learning to load and inspect
a well (Part A) unlocks everything else.
2. Accessing bundled data¶
Two functions are all you need to reach the sample data:
pp.list_samples(kind=None)- returns the names of the bundled samples, all of them or one kind:'logs'(well logs: the GeoLink North Sea wells, the COSTA carbonate wells, a Kansas Geological Survey well, the Cheal-1 and Tuhua-7 wells of Taranaki, New Zealand, and two Teapot Dome wells, Wyoming),'nmr'(Daydream 1 CMR logs and NMR tables),'pressure'(formation-pressure tests),'core'(core measurements and capillary-pressure data),'geology'(formation tops and lithology intervals) and'templates'(blank input templates for your own data). A collection name such as'geolink'or'costa'also works.pp.sample(name)- returns the full path of that bundled file on your machine. Feed a well-log path straight intopp.read(...)orpp.plot(...).
Because the data lives inside the installed package, this works on any machine with no setup - no downloads, no credentials, no path juggling.
pp.list_samples("logs")
['1046123714',
'15_9-14',
'16_7-1',
'25_5-1',
'30_6-5',
'HW-10',
'HW-24',
'HW-25',
'HW-26',
'HW-27',
'HW-28',
'HW-29',
'HW-3',
'HW-30',
'HW-31',
'HW-32',
'HW-4',
'HW-5',
'HW-6',
'HW-7',
'HW-8',
'HW-9',
'cheal-1',
'ede_01_composite',
'teapot_17-wx-21',
'teapot_44-mdx-10',
'tuhua-7']
pp.list_samples("geolink"), pp.list_samples("costa")
(['15_9-14', '16_7-1', '25_5-1', '30_6-5'],
['HW-10',
'HW-24',
'HW-25',
'HW-26',
'HW-27',
'HW-28',
'HW-29',
'HW-3',
'HW-30',
'HW-31',
'HW-32',
'HW-4',
'HW-5',
'HW-6',
'HW-7',
'HW-8',
'HW-9'])
3. Tour - dataset one: GeoLink (North Sea clastics)¶
The GeoLink wells are siliciclastic (sand/shale) wells from the Norwegian North Sea. Our primary teaching well is 30/6-5 from the Oseberg Øst field: it is unusually rich, carrying not just the standard triple-combo logs but also core porosity/permeability measurements and a supplied lithology track - ideal for teaching. Its reservoir is the Brent Group, 2841-2958 m (Ness and Etive formations), so many later lessons zoom into that depth window.
pp.read loads the file into a Well, and info() describes its header, depth range and
curves.
w_geo = pp.read(pp.sample("30_6-5"))
print(w_geo.info())
Well: 30/6-5
UWI: 30/6-5
Field: OSEBERG ØST
Depth range: 176.61 - 3556.08 m
Step: 0.1524 m
Number of curves: 20
Number of samples: 22176
Curves:
LITHOLOGY_GEOLINK: _, 10732 valid
CALI: in, 22084 valid
DRHO: g/cm3, 17421 valid
NPHI: m3/m3, 17421 valid
RHOB: g/cm3, 22171 valid
PEF: b/e, 2569 valid
GR: gAPI, 22176 valid
DTC: us/ft, 22081 valid
DTE: us/ft, 22081 valid
RDEP: ohm.m, 22171 valid
SP: mV, 22169 valid
RSHA: ohm.m, 22079 valid
RMED: ohm.m, 22171 valid
BS: in, 22176 valid
PHIC: v/v, 200 valid
GDEN: g/c3, 200 valid
KH_CORE: mD, 198 valid
KV_CORE: mD, 198 valid
SWC: frac, 74 valid
SOC: frac, 44 valid
Notice a few things about 30_6-5:
Depth is in metres (
m) - a European convention - sampled every 0.1524 m (half a foot).Alongside the classic logs (
GR,RHOB,NPHI,PEF,DTC, resistivitiesRDEP,RMED,RSHA,SP) it carriesCALI(caliper) andBS(bit size), which we will use for bad-hole detection in lesson 02.It has core data:
KH_CORE/KV_CORE(horizontal/vertical permeability),PHIC(core porosity), plusSWC/SOC. Core-calibrated wells are gold for benchmarking log-derived answers. The counts of valid samples show how sparse they are: 200PHICplugs against 22176 log samples.It even ships a supplied
LITHOLOGY_GEOLINKtrack.
4. Tour - dataset two: COSTA (carbonate)¶
The COSTA dataset is a public carbonate reservoir benchmark; Petrophys bundles 17 of
its wells (HW-3 through HW-32). Carbonate petrophysics differs from clastics
(complex pore systems, different lithology solving, Archie parameters a, m, n
that vary with texture), so having carbonate wells lets the curriculum contrast the
two rock types.
Each COSTA LAS file covers only the Kharaib-2 reservoir interval, not the whole
well: the logged depth range is the Kharaib-2 reservoir zone. The bundled formations_costa table
records that interval for every well. The files are leaner and more uniform than
30/6-5 - a realistic multi-well set for teaching normalization across a field. Let
us load HW-3 and look up its interval.
w_car = pp.read(pp.sample("HW-3"))
print(w_car.info())
Well: HW-3
UWI: HW-3
Field: COSTA
Depth range: 7805 - 8020 ft
Step: 0.5 ft
Number of curves: 8
Number of samples: 431
Curves:
GR: gAPI, 431 valid
RHOB: g/cm3, 431 valid
NPHI: ft3/ft3, 431 valid
DT: us/ft, 356 valid
PHIE_CC: ft3/ft3, 351 valid
RT: ohm.m, 431 valid
SW_INPUT: v/v, 321 valid
PERM_CC: mD, 355 valid
pp.read_formations(pp.sample("formations_costa"), well=w_car)
| formation_name | top_depth | bottom_depth | lithology | rank | well | depth_unit | |
|---|---|---|---|---|---|---|---|
| 0 | KHARAIB-2 | 7805.0 | 8020.0 | Carbonate | formation | HW-3 | ft |
Contrast with the GeoLink well:
Depth here is in feet (
ft), as is usual in North America and the Middle East. Mixed depth units across datasets is exactly why unit awareness (lesson 02) matters.The file spans 7805-8020 ft because it holds only the Kharaib-2 interval, the same range as its row in
formations_costa; the 30/6-5 file spans the whole logged well.The COSTA curve set is compact:
GR,RHOB,NPHI,DT(sonic),RT(true resistivity), plus the interpretation-input curvesPHIE_CC(core-corrected effective porosity),PERM_CC(core-corrected permeability) andSW_INPUT(the source water saturation). These are continuous log curves supplied with the dataset, not core-plug measurements.No caliper/bit-size here - so bad-hole detection (lesson 02) will be demonstrated on the GeoLink well, and normalization on the COSTA wells.
5. A first look at the logs¶
To make the two wells concrete, here is the gamma-ray log from each, plotted against
depth (log convention: depth increasing downward). curves=["GR"] draws only that
curve. GR distinguishes clean reservoir (low GR) from shale/clay (high GR). The 30/6-5
plot covers 2800-3000 m around the Brent Group, the HW-3 plot its whole Kharaib-2 file.
Both use the same 0-150 API scale, and the difference is striking: the Brent sands read
about 20-40 API between shales above 100 API, while the Kharaib-2 carbonate stays below
about 30 API throughout. That contrast is real lithology, not a tool artifact.
Multi-well normalization (lesson 02) solves a different problem: correcting
well-to-well calibration bias between wells of the same field.
pp.plot(w_geo, curves=["GR"], top=2800, bottom=3000, figsize=(4, 9))
pp.plot(w_car, curves=["GR"], figsize=(4, 9));
[repository]\src\petrophys\preprocessing\standardization\curve_standardizer.py:851: UserWarning: SWC: inferred percent core saturation despite unit 'frac'; divided by 100 to v/v. Verify source units.
standardize_core_saturation(new_curve, inplace=True)
[repository]\src\petrophys\preprocessing\standardization\curve_standardizer.py:851: UserWarning: SOC: inferred percent core saturation despite unit 'frac'; divided by 100 to v/v. Verify source units.
standardize_core_saturation(new_curve, inplace=True)
6. Curriculum roadmap¶
Two short pages of the documentation sit in front of the lessons:
Quickstart - read, plot and interpret one bundled well with the front-door API, then inspect the decisions.
Your own data - LAS, CSV/TSV and Excel inputs, optional formation and lithology tables, depth metadata and diagnostics.
The lessons are split into two parts.
Part A - Foundations & Core Science (you are here)¶
# |
Lesson |
What you learn |
|---|---|---|
00 |
Orientation and setup |
This lesson: purpose, data, roadmap |
01 |
Loading and inspecting data |
The |
02 |
QA/QC and standardization |
Conditioning: aliases, units, bad-hole, normalization |
03 |
Clay volume |
Vcl from GR (linear/Larionov/Stieber/Clavier), SP, neutron-density |
04 |
Porosity |
Density/neutron/sonic; total vs effective; hydrocarbon correction |
05 |
Lithology and mineral solver |
N-D/PEF crossplots; 2- and 3-mineral least-squares solving |
06 |
Formation water and environment |
Rw (SP/salinity), Rmf, temperature profile, invasion |
07 |
Water saturation |
Archie + shaly-sand models; Pickett m/n; model selection |
08 |
Permeability |
Timur/Coates; core poro-perm calibration |
09 |
Reservoir quality and net pay |
RQI/FZI/flow units; BVW/MHI; net pay; HCPV/OOIP/OGIP |
Part B - Integrated & Advanced Workflows¶
Building on the foundations from Part A, Part B covers the integrated and specialist workflows:
# |
Lesson |
What you learn |
|---|---|---|
10 |
Dynamic workflow (glass box) |
Auto method selection, the ordered workflow steps (listed below), step traces, overrides |
11 |
Formation and interval analysis |
Tops, zones/subzones, per-interval and formation summaries |
12 |
Core calibration and digital core |
Core-to-log calibration; digital-core facies, XRF, geomechanics |
13 |
ML curve imputation |
Rebuild missing curve samples from the other logs with |
14 |
NMR petrophysics |
T2 bins; SDR and Coates permeability; BVI/FFI |
15 |
Capillary pressure and saturation-height |
J-function, Brooks-Corey fitting, Pc-height conversion |
16 |
Borehole image (FMI) |
Pads to oriented image, equalization, azimuthal coverage |
17 |
Visualization masterclass |
XML templates, adaptive viewer, crossplots, batch export |
18 |
Multiwell field study |
COSTA 17-well batch, normalization, portfolio summary |
19 |
LLM context generation |
Export structured, size-limited context from interpreted wells |
20 |
Petrophys for LLM agents (MCP) |
Drive loading, interpretation, summaries and plots from an MCP client |
21 |
Custom workflows |
Build, validate and save your own reusable |
Each lesson consumes exactly the Well object you learn to build here in Part A.
The dynamic workflow behind pp.interpret is organized as an ordered catalogue of
steps. Each run records which steps executed and which were skipped, with a reason,
so the catalogue is not a promise that every step runs on every well:
import pandas as pd
from petrophys.workflow import workflow_steps
pd.set_option("display.max_colwidth", None) # show each description in full
pd.DataFrame(workflow_steps())
| name | description | |
|---|---|---|
| 0 | normalization | Canonical curve aliases and units; implausible-value screening |
| 1 | temperature | Formation temperature profile from BHT or a gradient |
| 2 | bad_hole | Washout and density-correction quality flags |
| 3 | spectral_gamma | Not run by pp.interpret; call petrophys.interpretation.geochemistry.interpret_spectral_gamma directly |
| 4 | elemental_spectroscopy | Not run by pp.interpret; call petrophys.interpretation.geochemistry.interpret_elemental_spectroscopy directly |
| 5 | vclay | Clay volume (VCL) from gamma ray, SP and neutron-density |
| 6 | rcl | Clay resistivity from shale intervals |
| 7 | rmf | Mud-filtrate resistivity at formation temperature |
| 8 | hc_correction | Neutron-density hydrocarbon correction (opt-in) |
| 9 | porosity | Density, neutron, sonic, total (PHIT) and effective (PHIE) porosity |
| 10 | lithology | Mineral volumes: clastic multi-mineral or carbonate solve |
| 11 | porosity_refinement | Not run by pp.interpret; porosity is computed once, in the porosity step |
| 12 | core_correction | Porosity and permeability calibrated to core data |
| 13 | rw | Formation water resistivity at formation temperature |
| 14 | invasion | Invasion profile from shallow and deep resistivity |
| 15 | saturation | Water (SW) and flushed-zone (SXO) saturation |
| 16 | permeability | Core-calibrated or empirical permeability (PERM) |
| 17 | rock_quality | Reservoir quality index (RQI), flow zone indicator (FZI) |
| 18 | bvw | Bulk volume water |
| 19 | mhi | Moveable hydrocarbon index |
| 20 | net_pay | Net rock, net reservoir and net pay flags |
7. What this curriculum does not cover¶
To set honest expectations, the curriculum focuses on wireline log analysis and formation evaluation. The following are outside its scope:
Seismic and AVO - no seismic inversion, amplitude-versus-offset, or rock-physics-to-seismic tie.
Geomechanics - beyond limited digital-core mechanical properties, no full wellbore stability / stress modelling.
Unconventionals / TOC - no organic-richness (total organic carbon) or source-rock workflows.
4D (time-lapse) - no repeat-survey / production monitoring.
Monte-Carlo uncertainty - results in these lessons are deterministic. The library has a Monte-Carlo propagator (
petrophys.evaluation.monte_carlo, shown in the analysis-tools page of the documentation), but no lesson teaches it.
Knowing the boundary is part of using any tool responsibly.
Pitfalls and good habits¶
Mind the depth unit. GeoLink is in metres, COSTA in feet. Always read
w.depth_unitbefore comparing depths or thicknesses across wells.Know what interval a file covers. 30/6-5 spans the whole logged well; each COSTA file spans only the Kharaib-2 reservoir interval.
Use
sample()for paths, never hard-code them. The bundled data path differs by machine;pp.sample(name)resolves it for you.Non-ASCII header fields happen. Header text such as the Oseberg Øst field name can carry non-ASCII characters; keep that in mind when you export headers to systems that expect plain ASCII.
Read warnings. A diagnostic such as the SWC percent-versus-fraction message is a finding about the data, not noise to hide.
Core curves are precious. When a well carries core measurements (
*_CORE,PHIC), use them to validate your log-derived answers.*_CCcurves are core-corrected log curves: useful, but not independent core data.
Recap¶
petrophys is a well-log / formation-evaluation library; every sub-package consumes the same
Wellobject, andpp.read,pp.plotandpp.interpretare the front door.pp.list_samples(...)lists the bundled samples (LAS and DLIS logs, CSV and Excel tables);pp.sample(name)gives the file path to feedpp.read(...)orpp.plot(...), andwell.info()prints what a well holds.Two main teaching datasets: GeoLink North Sea clastics (primary well 30/6-5, metres, core-rich, Brent Group 2841-2958 m) and COSTA carbonates (
HW-3 ... HW-32, feet, each file only the Kharaib-2 interval).The curriculum starts with the quickstart and own-data pages, then runs Part A (lessons 00-09: loading and QA/QC through saturation, permeability and net pay) and Part B (lessons 10-21: integrated workflows, specialist data, multiwell studies, LLM integration and custom workflows).
Seismic/AVO, full geomechanics, unconventionals/TOC and 4D are outside the curriculum, and no lesson teaches Monte-Carlo uncertainty.
Start with read/plot; add
pp.interpretonly when ready to review its assumptions and trace. It works on a copy of the well.
Try it yourself¶
Exercise 1. Load a second COSTA well (e.g.
HW-10) and a second GeoLink well (e.g.25_5-1) and callinfo()on each. Do all COSTA wells share the same curve set? Does the Kharaib-2 interval sit at the same depth in every COSTA well?Exercise 2. For any well, list which curves contain the substring
COREorCC(core measurements, or log curves corrected to core). Which of the two datasets carries actual core-plug measurements?
Hint: pp.read takes a list of files, e.g.
pp.read([pp.sample(name) for name in pp.list_samples("costa")]).
What’s next¶
Continue with 01_loading_and_inspecting_data.ipynb, where we open up the Well and
Curve objects properly: headers, per-curve statistics, DataFrame export, depth slicing,
and the difference between the curve sets of a clastic and a carbonate well.