Analysis tools¶
Beyond the specialist measurements, Petrophys has functions for analyses
pp.interpret does not run: gap filling, clay typing, shale distribution,
matrix and water indicators, heterogeneity, zonation, statistics,
uncertainty, invasion, saturation height and pore pressure. Each
takes arrays or a Well and returns plain results; none changes an
interpretation unless you add its output to the well.
Several need data that logs cannot give: core permeability, a free-water level from formation pressures, true vertical depth from a deviation survey, the rig and sea-floor elevations, the service company’s tool responses and your input uncertainties. The first section shows how each gets in.
The examples use the interpreted 30/6-5 well (Brent Group sands at 2841-2958 m), its core plugs and its formation tops. The interpreted curves come out as a table, from which the Brent Group is one query:
import petrophys as pp
result = pp.interpret(pp.sample("30_6-5"), rw=0.070, rw_meas_temp="230.0 degF")
logs = result.well.to_dataframe()
brent = logs.query("2841 <= DEPTH <= 2958")
Getting your data in¶
You have |
Read it with |
Used by |
|---|---|---|
Core analysis table (CSV/Excel) |
Lorenz, Dykstra-Parsons, Winland, Thomas-Stieber end points |
|
Deviation survey (MD, inclination, azimuth) |
|
Saturation height, pore pressure |
Rig and datum elevations |
the LAS header (EKB, EDF, EGL, APD + EPD by LMF), |
TVDSS, Eaton air gap |
Formation-tester pressures |
Free-water level |
|
Tool-response charts |
Invasion inversion |
|
Input uncertainties (Excel) |
Monte Carlo |
Core. read_core finds the columns by name (Depth (m), Por (%),
Kh Kl. (mD), KAIR, Grain density), converts percent and
percent-labelled-as-fraction porosity, darcy and kg/m3, and converts depths
to the well’s unit. Here a Phillips teaching core table is read with its
depth unit stated explicitly (feet); porosity is supplied as a fraction:
from petrophys.io import read_core
core = read_core(pp.sample("phillips_cmr_core"), depth_unit="ft", porosity_unit="v/v", permeability_unit="mD")
core.to_dataframe().head()
DataQualityWarning: Core table: Numeric columns not used: ['CMRP_3ms', 'CMFF', 'BVI']; map any core property with columns={role: header}
| DEPTH | CPOR | CPERM | CMRP_3ms | CMFF | BVI | |
|---|---|---|---|---|---|---|
| 0 | 4481.95 | 0.379162 | 14.231 | 0.314889 | 0.092209 | 0.22268 |
| 1 | 4484.98 | 0.271529 | 1.546 | 0.2925604 | 0.029032 | 0.2635284 |
| 2 | 4488.06 | 0.142920 | 0.039 | 0.1971492 | 0.0112526 | 0.1858966 |
| 3 | 4490.99 | 0.106178 | 0.054 | 0.1619336 | 0.0108326 | 0.151101 |
| 4 | 4494.01 | 0.165877 | 0.048 | 0.1531554 | 0.0114848 | 0.1416706 |
The import report names the column found for each property:
core.metadata["import_report"]["columns"]
{'depth': 'DEPTH', 'permeability': 'Kair', 'porosity': 'Cpor'}
Pressures and the free-water level. Station tables are read with their
datum. Labelled stations give the FWL from the water and hydrocarbon
gradients; unlabelled ones, as in the 35/11-13 MDT file, go through
infer_contacts, which finds an oil gradient over a water gradient and their
intersection:
from petrophys.interpretation.saturation.height import read_formation_pressure
stations = read_formation_pressure(pp.sample("35_11_13_mdt"))
contacts = stations.infer_contacts()
contacts.status, contacts.fwl_depth, contacts.depth_unit, contacts.depth_reference
('interpreted', 3114.704052904744, 'm', 'TVD_MSL')
Every station of the file is used here. Tutorial 15 keeps the 21 tests the file marks as good and finds the contact at 3113.2 m, against 3112.6 m in the well’s report.
When your file is laid out differently. Each reader finds columns and units by name, and every guess can be given instead; a value you give is used as is:
Reader |
Arguments that override what it reads |
|---|---|
|
|
|
|
|
|
|
|
|
one row per input with |
Pretest picking thresholds sit in
MDTPickingConfig, passed
as pick_mdt_pressure(..., config=MDTPickingConfig(max_gap_seconds=2.0));
each field left unset keeps its default (a time gap over 5 s or five sampling
intervals is flagged for review).
Either result goes straight into
fit_saturation_height_from_well(),
which picks the well’s TVDSS curve to match the FWL’s datum.
Elevations. The depth reference’s elevation comes from the header, whichever way the file records it:
from petrophys.io import depth_reference_elevation
{name: depth_reference_elevation(pp.read(pp.sample(name)))
for name in ("daydream1_cmr", "teapot_44-mdx-10")}
{'daydream1_cmr': (291.619995,
{'source': 'APD 291.619995 M + EPD 0.0 (MSL)', 'reference': 'DF'}),
'teapot_44-mdx-10': (5239.0, {'source': 'EKB 5239.0 F', 'reference': 'KB'})}
Surveys, tool responses and uncertainties (no such files are bundled):
well = pp.read("my_well.las", survey="survey.csv") # adds TVD and, with an elevation, TVDSS
well = pp.read("my_well.las", survey="vertical") # declare a vertical hole
tools = read_tool_responses("dll_msfl_chart.csv") # tool, diameter (in/cm), J (0-1 or %), response
inputs = read_uncertainty_table("uncertainties.xlsx") # name, distribution, min/most likely/max or mean/std
A survey table needs MD and inclination (azimuth optional, then constant);
its unit comes from a header such as MD (ft). Tool responses are the
pseudo-geometric factors J(di) read off the vendor’s charts, in a long
table (one row per point) or a wide one (one column per tool).
Curves off depth¶
A delivered file can carry a curve recorded at the wrong depth: a run spliced off depth, a tool string stretched by cable stick-slip, or one tool moved in a merge and its neighbours not. Two curves that respond to the same beds then line up only when one is moved, by an amount that can change with depth.
depth_match() finds that correction at every
depth, by Kerzner’s method (1984) in two passes, as he advises. First the major
shift: the one whose correlations in 10 m windows have the highest median, kept
when that median is at least 0.35 and 0.2 higher than as recorded. Then the
detail, within 2 m of it: the peaks of each window’s correlogram are candidate
shifts, and dynamic programming picks one per depth so that the moved log never
folds, stretches little, and keeps the most correlation; a shift other than the
major one must correlate 0.1 better, the noise of a window. Correlation is the
measure of a match that Le et al. (2019) found best of thirteen.
shift_curves() applies the correction. In COSTA
well HW-3 density and sonic line up with the neutron only when moved 56 ft:
from petrophys.preprocessing import depth_match, shift_curves
hw3 = pp.read(pp.sample("HW-3"))
match = depth_match(hw3, "RHOB", "NPHI", sign="negative")
aligned = shift_curves(hw3, ["RHOB", "DTC"], match)
match
DepthMatch(RHOB to NPHI: shift -56.00 to -56.00 ft, r -0.06 -> 0.40, 11 of 27 windows matched)
sign says how the curves follow each other: "negative" for density against
neutron, which respond to porosity in opposite directions, "positive" for
sonic against neutron, None for either, bed by bed. Match curves that respond
to the same property: density, neutron and sonic to each other, resistivities
to each other, a gamma-ray pass to gamma ray. Curves that respond to different
properties, such as resistivity against gamma ray in a carbonate, correlate too
loosely, and their best match can be wrong.
The check is optional. pp.interpret(well, depth_check=True) matches density,
neutron and sonic to each other and warns when they line up only moved, naming
the curve that disagrees with the other two; the curves stay as recorded until
you move them with shift_curves. On 621 such pairs of 221 wells (the bundled
samples, the GeoLink and COSTA wells), the shift that correlates best raised
the median windowed correlation by less than 0.11 in 95 % of them. The check
warns in 12 of the wells. In five,
two pairs agree on which curve is off: HW-3, 35/11-7, whose neutron lines up
with density and sonic only when moved 1.4 m, and 25/5-4, 31/5-4 S and 31/5-5 R,
whose sonic is 0.5-1.7 m off. In the other seven one pair is off by a few tenths
of a metre to 2 m, in places or throughout, as between the sonic and the
neutron of 30/6-11 below 2335 m. A known splice and stretch put into the 30/6-5 gamma
ray is recovered to within one sample at 90 % of depths, and a curve already
on depth is left where it is.
find_log_depth_shift() measures one shift for
the whole interval.
Gap filling with machine learning¶
pp.impute trains a model on the fly to rebuild a
missing curve from the other logs (it needs the ml extra). The result is added as
<CURVE>_IMPUTED: the measured values where the curve was logged, the predictions
in its gaps.
On the 223 GeoLink North Sea wells, with 80 % of the wells as train_wells and
each curve removed from each of the others that has it (37 to 43 wells) and
rebuilt, R² over the rebuilt samples is 0.74-0.75 for RHOB (mean absolute error
0.082-0.085 g/cm3), 0.39-0.60 for DTC (12.5-14.2 us/ft) and 0.50-0.74 for NPHI
(0.047-0.063 v/v), the range of three random splits of the wells; held or
zero-filled readings are not scored. scripts/evaluate_imputation.py repeats
the measurement on any set of wells. Scores vary from well to well and from one
choice of training wells to another, so check a rebuild against measured data
in your own wells before using it.
pp.impute also writes <CURVE>_PREDICTED, a prediction at every depth, so a
rebuild can be checked where the curve was measured. The check is out-of-fold: the
well is cut into five depth blocks, and each measured sample is predicted by a model
that did not learn from its block (the training wells are always used). A model
judged on samples it learned from looks better than it is. Here the density of the
COSTA well HW-24 is predicted from its other logs and the 16 other COSTA wells:
costa = [name for name in pp.list_samples() if name.startswith("HW-") and name != "HW-24"]
hw24 = pp.impute(pp.sample("HW-24"), "RHOB", train_wells=[pp.sample(name) for name in costa])
hw24["RHOB_PREDICTED"].description
UserWarning: HW-24: RHOB has no missing samples; RHOB_IMPUTED is the measured curve, and RHOB_PREDICTED checks the model against it
'RHOB predicted at every depth; at measured depths by a model that did not learn from that part of the well (5 depth blocks): mean absolute error 0.0346 g/cm3, bias +0.00126 g/cm3, R2 0.89 against 433 measured samples'
Over the 433 measured samples the mean absolute error is 0.0346 g/cm3, with almost no
bias (+0.00016 g/cm3) and R² 0.89. The error is given in the curve’s unit; for
resistivity and permeability, which span decades, it is given in log10 of the curve.
pp.plot draws the prediction over the measured density, in black, in the density track:
pp.plot(hw24, curves=["GR", "RHOB", "RHOB_PREDICTED"])
The prediction follows the dense intervals at the top and base and the porous
limestone between them, apart from short swings: down to 2.25-2.45 g/cm3 at 8384-8389 ft,
where the measured density reads 2.6-2.7; up to 2.6-2.7 at 8392-8395 ft, where it reads
about 2.4; and down to about 2.53 at 8568-8570 ft, where it reads 2.70. In a well with gaps,
RHOB_IMPUTED keeps the measured density and takes the prediction only in the gaps,
where pp.plot draws it in grey.
Matrix and water indicators¶
Apparent water resistivity, apparent matrix parameters (the inputs of the MID and RHOmaa-Umaa plots), the Raymer-Hunt-Gardner sonic transform and Winland R35. Each function takes curves as arrays or table columns.
In clean water-bearing sand, apparent water resistivity (Rwa, Archie solved for Rw at Sw = 1) reads Rw; clay conduction lowers it in shaly rock. Over the clean Statfjord water sand it reads 0.089 ohm.m, somewhat above the 0.067 ohm.m that the interpretation’s Rw (0.07 ohm.m at 230 °F) gives at that temperature; in a water leg, a Rwa well away from Rw questions the Rw or the Archie constants:
from petrophys.interpretation.electrical.rw import apparent_water_resistivity
water = logs.query("3223 <= DEPTH <= 3556 and VCL < 0.15 and PHIE > 0.15")
water.assign(RWA=apparent_water_resistivity(water.RDEP, water.PHIE, a=0.8))[["RWA", "RW"]].median()
RWA 0.089249
RW 0.066657
dtype: float64
Apparent matrix density and slowness, from the apparent porosity of density and neutron together. Quartz reads 2.65 g/cm3 and about 55 us/ft; the Brent Group medians, 2.74 g/cm3 and 62 us/ft, sit above it, where clay and mica in the sands move both:
from petrophys.interpretation.lithology import (
apparent_matrix_density, apparent_matrix_slowness, apparent_total_porosity,
)
phia = apparent_total_porosity(brent.RHOB, brent.NPHI)
brent.assign(RHOMAA=apparent_matrix_density(brent.RHOB, phia),
DTMAA=apparent_matrix_slowness(brent.DTC, phia))[["RHOMAA", "DTMAA"]].median()
RHOMAA 2.738069
DTMAA 61.879773
dtype: float64
Sonic porosity of the Brent Group by the Wyllie time average and by the Raymer-Hunt-Gardner transform, which does not need a compaction correction:
from petrophys.interpretation.porosity import raymer_hunt_gardner, wyllie_time_average
brent.assign(WYLLIE=wyllie_time_average(brent.DTC),
RHG=raymer_hunt_gardner(brent.DTC))[["WYLLIE", "RHG"]].median()
WYLLIE 0.243872
RHG 0.254692
dtype: float64
Winland R35 is the pore-throat radius at 35 % mercury saturation, from core permeability and porosity; it sorts the Brent plugs into pore-throat classes (the three plugs without a permeability get no class, the blank row):
import pandas as pd
from petrophys.evaluation.rock_quality import winland_r35, classify_pore_throat
from petrophys.interpretation.core_analysis import core_data
plugs = core_data(result).filter_by_depth(2841, 2958)
r35 = winland_r35(plugs.permeability, plugs.porosity)
pd.Series(classify_pore_throat(r35)).value_counts()
mega 65
micro 51
macro 46
meso 34
3
nano 1
Name: count, dtype: int64
Shale distribution: Thomas-Stieber¶
Total porosity against shale volume splits shale into laminae, pore-filling (dispersed) and grain-replacing (structural) shale. The end points come from the interval: the clean sand’s porosity (90th percentile where VCL is below 0.1) and the shale’s (median where VCL is above 0.8).
from petrophys.interpretation.clay_volume import thomas_stieber
phi_sand = brent.PHIT[brent.VCL < 0.1].quantile(0.9)
phi_shale = brent.PHIT[brent.VCL > 0.8].median()
thomas_stieber(brent.PHIT, brent.VCL, phi_sand, phi_shale)
ThomasStieberResult(768 samples, mean N/G 0.74, {'outside': 146, 'laminar_dispersed': 492, 'laminar_structural': 130})
Clay typing from Th/K¶
The thorium/potassium ratio of spectral gamma ray separates kaolinite,
mixed-layer clays, illite, micas, glauconite and feldspar (chart bands,
configurable). Here the Daydream 1 HNGS log, a 30 MB file that
integration_fixture downloads on first use.
from petrophys.datasets import integration_fixture
from petrophys.interpretation.geochemistry import clay_typing_from_well
clay_typing_from_well(pp.read(integration_fixture("daydream1_shallow_aps_pex_hngs.las")))
Downloading daydream1_shallow_aps_pex_hngs.las (30 MB) to /home/runner/.cache/petrophys/daydream ...
ClayTypingResult(80471 of 81139 samples typed: illite 11%, mixed_layer 88%)
Heterogeneity: Lorenz and Dykstra-Parsons¶
From core permeability and porosity over one reservoir unit, here the Brent plugs. The Lorenz coefficient runs from 0 (homogeneous) to 1; a Dykstra-Parsons coefficient above about 0.7 marks a very heterogeneous reservoir.
from petrophys.evaluation import dykstra_parsons, lorenz_coefficient
lorenz_coefficient(plugs.permeability, plugs.porosity), dykstra_parsons(plugs.permeability)
(LorenzResult(coefficient 0.705, 197 samples),
DykstraParsonsResult(coefficient=0.969762236463534, k50=17.976696223844506, k84=0.5435750895834921, r_squared=0.9315209069753598, n_samples=197))
Change-point zonation¶
PELT finds where the mean of one or more curves shifts. The default penalty
finds bed-scale changes; max_zones keeps the strongest boundaries. Compare
the result with the formation tops.
from petrophys.evaluation import zone_well
zones = zone_well(result.well, ["GR", "RHOB"], min_thickness=2.0, top=2700, bottom=3600, max_zones=12)
zones.to_dataframe()[["top", "bottom", "GR_mean", "RHOB_mean"]].round(2)
| top | bottom | GR_mean | RHOB_mean | |
|---|---|---|---|---|
| 0 | 2700.05 | 2791.49 | 64.86 | 2.56 |
| 1 | 2791.64 | 2842.09 | 92.73 | 2.53 |
| 2 | 2842.24 | 2891.16 | 55.33 | 2.30 |
| 3 | 2891.31 | 2957.15 | 62.81 | 2.45 |
| 4 | 2957.30 | 3071.14 | 102.92 | 2.57 |
| 5 | 3071.30 | 3121.74 | 67.56 | 2.51 |
| 6 | 3121.89 | 3223.85 | 93.95 | 2.61 |
| 7 | 3224.00 | 3316.20 | 59.98 | 2.44 |
| 8 | 3316.35 | 3489.02 | 84.89 | 2.54 |
| 9 | 3489.18 | 3548.31 | 106.05 | 2.60 |
| 10 | 3548.46 | 3555.32 | 186.95 | 2.57 |
Statistics by zone¶
zone_statistics tabulates any curves over any zones: a tops file, a table,
or a list of intervals.
from petrophys.evaluation.summaries import zone_statistics
stats = zone_statistics(result.well, pp.sample("formations_30_6-5"), ["PHIE", "SW", "VCL"],
rank="formation")
stats.query("zone in ['Ness Fm.', 'Etive Fm.']")[
["zone", "curve", "coverage", "arithmetic_mean", "p10", "p50", "p90"]].round(3)
| zone | curve | coverage | arithmetic_mean | p10 | p50 | p90 | |
|---|---|---|---|---|---|---|---|
| 18 | Ness Fm. | PHIE | 100.0 | 0.145 | 0.081 | 0.149 | 0.205 |
| 19 | Ness Fm. | SW | 100.0 | 0.726 | 0.560 | 0.686 | 1.000 |
| 20 | Ness Fm. | VCL | 100.0 | 0.461 | 0.089 | 0.448 | 0.823 |
| 21 | Etive Fm. | PHIE | 100.0 | 0.124 | 0.000 | 0.145 | 0.233 |
| 22 | Etive Fm. | SW | 100.0 | 0.792 | 0.224 | 1.000 | 1.000 |
| 23 | Etive Fm. | VCL | 100.0 | 0.329 | 0.000 | 0.203 | 0.854 |
Monte Carlo uncertainty¶
Each uncertain input gets a distribution; the calculation runs on every
draw. Here mean Archie Sw of the Etive net reservoir with the operator’s
constants and assumed spreads: Rw within 20 %, m and n between 1.8 and 2.2, and a porosity
calibration error of 0.015 that is the same at every depth
(correlated_depths).
import numpy as np
from petrophys.evaluation import monte_carlo
from petrophys.interpretation.saturation import archie
etive = logs.query("2865 <= DEPTH <= 2958 and NET_RES > 0.5")
rw = etive.RW.median()
def mean_sw(rt, phi, rw, m, n):
sw = archie(rt=rt, rw=rw, phi=np.clip(phi, 0.01, None), a=0.8, m=m, n=n)
return np.nanmean(np.clip(sw, 0, 1), axis=-1)
mc = monte_carlo(mean_sw, {
"rt": etive.RDEP.values, "phi": {"dist": "normal", "mean": etive.PHIE.values, "sd": 0.015},
"rw": ("triangular", 0.8 * rw, rw, 1.2 * rw), "m": ("uniform", 1.8, 2.2), "n": ("uniform", 1.8, 2.2),
}, n=2000, correlated_depths=["phi"])
mc
MonteCarloResult(n=2000, p10 0.6084, p50 0.6753, p90 0.714, mean 0.6676, sd 0.0419)
The rank correlation of each input with the answer shows which one drives the spread:
mc.sensitivity
{'phi': -0.5698437734609433,
'rw': 0.2775897933974483,
'm': 0.7020880275220068,
'n': 0.2703544395886099}
Invasion, saturation height and pore pressure¶
These need inputs the bundled data do not state, so the examples are not run here.
Step-profile invasion inversion solves Rt, Rxo and invasion diameter from
three resistivities (or two and a measured Rxo). Its answer depends on each
tool’s pseudo-geometric factor J(di): take them from the service company’s
charts as ToolResponse
tables. The result carries the range of Rt and di that fits the readings
within their noise, because the step model is often non-unique.
from petrophys.interpretation.electrical.invasion import invert_well_invasion, read_tool_responses
tools = read_tool_responses("dll_chart.csv") # LLS and LLD from your vendor's charts
inv = invert_well_invasion(well, tools, rxo_curve="MSFL", noise=0.03)
inv # summary; RT_INV, DI_INV, RT_INV_LOW/HIGH on the well
readings={"LLD": "RDEP", ...} maps tool names to your curve names.
Empirical saturation-height functions fit log Sw against true vertical height above a known free-water level (power law, Cuddy FOIL, Skelt-Harrison).
from petrophys.interpretation.saturation.height import fit_saturation_height_from_well
well = pp.read("my_well.las", survey="survey.csv") # TVDSS from the survey and header elevation
fwl = read_formation_pressure("mdt.csv").fit_fwl("oil") # FWL on TVDSS
result = pp.interpret(well)
shf = fit_saturation_height_from_well(result.well, fwl, model="skelt_harrison", mask=net_reservoir)
shf.parameters, shf.r_squared, shf.predict(height_above_fwl)
It warns when the function explains little of Sw (a wrong FWL or datum, or several rock types fitted together) or its parameters run to their bounds.
Eaton pore pressure needs the overburden (water depth, air gap and the
density above the logged interval), the hydrostatic water density and a
normal compaction trend fitted on clean shale in a normally pressured
section. It is a shale method: give the shale samples as shale= and the
pressure is computed there, blank elsewhere, and calibration compares each
measured pressure with the shale trend across that depth.
from petrophys.interpretation.pore_pressure import eaton_from_well, fit_normal_compaction_trend
well = pp.read("my_well.las", survey="survey.csv")
shale = well["VCL"].data > 0.6
nct = fit_normal_compaction_trend(tvd, dtc, kind="sonic", mask=shale & normally_pressured, mudline=135)
ppr = eaton_from_well(well, nct, water_depth=110, density_above_log=1.95, shale=shale) # air gap from the header
exponent, misfit = ppr.calibrate(mdt_tvdss, mdt_bar, datum="TVDSS") # fit Eaton's exponent
ppr = eaton_from_well(well, nct, water_depth=110, density_above_log=1.95, shale=shale, exponent=exponent,
add_curves=True)
Offshore the air gap is the depth reference’s elevation above sea level; onshore it is EKB - EGL, and hydrostatic pressure starts at ground level. Calibrate Eaton’s exponent to measured pressures before using the result; calibration stops with an explanation when the measurements fit no positive exponent, as with normally pressured points against a poor trend.
Next¶
Context export: hand the interpreted, reviewed well to an LLM as a compact JSON summary.
Tutorial 13 validates curve imputation in depth, and tutorial 15 covers capillary pressure and saturation height.