Input templates¶
Only a well log is required. Four optional geology tables add formations, lithology intervals and coded-lithology labels. Each ships with Petrophys: copy one, replace its synthetic rows, and read it with the function listed here.
Template |
Holds |
Read with |
|---|---|---|
|
Formation tops (point picks) |
|
|
Formation intervals (top and bottom) |
|
|
Rock names by depth interval |
|
|
Codebook of a lithology code curve |
|
import pandas as pd
import petrophys as pp
pp.list_samples("templates")
['formation_intervals_template',
'formation_tops_template',
'lithology_codes_template',
'lithology_intervals_template']
Download:
formation tops,
formation intervals,
lithology intervals,
lithology codes.
In Python, pp.sample("<template name>") gives the installed copy’s path.
What the tables add¶
Attached to a well, formation and lithology tables become the tops and the
lithology track. The bundled 30/6-5 files follow the same templates. Their
lithology table is formation-scale, one lithology per formation: the whole
Brent Group is sandstone in it, while the LAS file’s own lithology log
(LITHOLOGY_GEOLINK) shows the Ness coals, silts and shaly beds.
well = pp.read(
pp.sample("30_6-5"),
formations=pp.sample("formations_30_6-5"),
formation_options={"rank": "formation"},
lithology=pp.sample("lithology_30_6-5"),
)
pp.plot(well, top=2550, bottom=3150,
tracks=["LITHOLOGY", "GAMMA / HOLE", "RESISTIVITY", "DENSITY / NEUTRON"])
Rules for every file¶
Rule |
Detail |
|---|---|
Format |
CSV (UTF-8, commas, decimal points), TSV, Excel |
Layout |
One header row; no title rows, merged cells or units inside numeric cells |
Template rows |
Synthetic examples, not picks for any well: replace them all |
Excel workbooks |
Several worksheets need |
Several wells in one table |
Add a |
Other column names |
Common aliases match case-insensitively; map the rest with |
Depth metadata |
Optional |
Formations¶
Tops are point picks; intervals add a bottom_depth for thickness and summaries.
pd.read_csv(pp.sample("formation_tops_template"))
| formation_name | top_depth | |
|---|---|---|
| 0 | Formation_A | 1000.0 |
| 1 | Formation_B | 1050.0 |
| 2 | Formation_C | 1120.0 |
pd.read_csv(pp.sample("formation_intervals_template"))
| formation_name | top_depth | bottom_depth | |
|---|---|---|---|
| 0 | Formation_A | 1000.0 | 1050.0 |
| 1 | Formation_B | 1050.0 | 1120.0 |
| 2 | Formation_C | 1120.0 | 1200.0 |
The reader maps vendor headers and infers the rank from NPD-style names:
vendor = pd.DataFrame({"Surface": ["Ness Fm.", "Etive Fm."],
"MD": [2841.0, 2865.0], "Base MD": [2865.0, 2958.0]})
pp.read_formations(vendor, columns={"formation_name": "Surface", "top_depth": "MD",
"bottom_depth": "Base MD"})
| formation_name | top_depth | bottom_depth | rank | |
|---|---|---|---|---|
| 0 | Ness Fm. | 2841.0 | 2865.0 | formation |
| 1 | Etive Fm. | 2865.0 | 2958.0 | formation |
A last bottom is never invented. Give terminal_depth to turn tops into
intervals:
from petrophys.model import FormationTops
tops = pp.read_formations(pp.sample("formation_tops_template"))
intervals = FormationTops.from_dataframe(tops, terminal_depth=1200.0).to_dataframe()
intervals[["name", "top_depth", "bottom_depth", "thickness"]]
| name | top_depth | bottom_depth | thickness | |
|---|---|---|---|---|
| 0 | Formation_A | 1000.0 | 1050.0 | 50.0 |
| 1 | Formation_B | 1050.0 | 1120.0 | 70.0 |
| 2 | Formation_C | 1120.0 | 1200.0 | 80.0 |
Rule |
Behaviour |
|---|---|
Required columns |
|
Optional columns |
|
Header aliases |
|
Missing name, non-finite depth, |
Error naming the row |
Groups and formations mixed |
Kept, with their |
Nested levels in summaries |
Totals use the union of covered samples, so nesting never double counts |
Adjacent intervals |
|
Lithology intervals¶
One rock name per depth interval. Custom names are kept as written.
pd.read_csv(pp.sample("lithology_intervals_template"))
| top | bottom | lithology | |
|---|---|---|---|
| 0 | 1000.0 | 1025.0 | Shale |
| 1 | 1025.0 | 1050.0 | Sandstone |
| 2 | 1050.0 | 1120.0 | Limestone |
| 3 | 1120.0 | 1200.0 | Shale |
Extra vendor columns are rejected unless you map the columns you want; the report lists what was ignored:
vendor = pd.DataFrame({"FROM": [1000.0, 1025.0], "TO": [1025.0, 1050.0],
"ROCK": ["Shale", "Sandstone"], "Comment": ["cuttings", "core"]})
from petrophys.io import read_lithology_intervals
lithology = read_lithology_intervals(vendor, columns={"top": "FROM", "bottom": "TO", "lithology": "ROCK"})
lithology
| top | bottom | lithology | |
|---|---|---|---|
| 0 | 1000.0 | 1025.0 | Shale |
| 1 | 1025.0 | 1050.0 | Sandstone |
lithology.attrs["import_report"]["ignored_columns"]
['Comment']
Rule |
Behaviour |
|---|---|
Required columns |
|
Rock names |
Kept as written; known names get the plot’s colours and patterns |
Lithology group |
Read from the name’s main rock word: abbreviations ( |
Overlaps, zero or reversed intervals, empty names |
Error naming the row |
Gaps |
Left unfilled |
Mixtures (several percentages at one depth) |
Not accepted; keep them as separate data |
Precedence |
Attached intervals override lithology embedded in the LAS, in plots and |
Lithology codes¶
A codebook names the codes of a lithology code curve already in the LAS. It is not an interval file.
pp.interpret reads one code curve per well: the curve you name
(pp.interpret(well, lithology="FACIES"), the lithology_curve setting),
else LITHOLOGY_GEOLINK, else the first curve under a lithology-code name
(LITHOLOGY, LITHOFACIES, FACIES, LITH_CODE, ROCK_TYPE, …) whose values pass the code checks: 20 or more finite samples,
whole numbers from 0 to 99 with at most 50 distinct values, and half or more of
the samples codes of the built-in lithology code table (Kingdom nomenclature).
Other curves whose names contain LITH or FACIES are not read. Whatever the
curve is called, its codes are decoded with that built-in table, and a warning
says so for a curve other than LITHOLOGY_GEOLINK. When the curve holds other codes, pass its codebook as
the lithology_codes setting, most simply a CSV or Excel file of code and
rock name: pp.interpret(well, lithology_codes="my_codes.xlsx"). A mapping
{1: "Shale", 2: "Sst"} or a DataFrame also works. Each code’s group then
comes from its rock name, as for lithology intervals, and a warning lists
codes whose name is no recognized rock. The
“geolink” calculation profile
(calculation profiles) keeps the eval package’s
search unless lithology_curve is set.
pd.read_csv(pp.sample("lithology_codes_template"))
| code | lithology | |
|---|---|---|
| 0 | 1 | Sandstone |
| 1 | 2 | Shale |
| 2 | 3 | Limestone |
from petrophys.io import read_lithology_codes
read_lithology_codes(pp.sample("lithology_codes_template"))
{1: 'Sandstone', 2: 'Shale', 3: 'Limestone'}
A Kingdom codebook names each code twice, by rock (Attribute) and by family
(Lithology Attribute); label_column picks one:
kingdom = pd.DataFrame({"Abbreviation": ["SS", "SH", "LS"],
"Attribute": ["Sandstone", "Shale", "Limestone"],
"Lithology Attribute": ["Clastic", "Clastic", "Carbonate"]})
read_lithology_codes(kingdom)
DataQualityWarning: Lithology codebook contains different Attribute and Lithology
Attribute labels; using 'Attribute'. Pass label_column explicitly to choose another
grouping.
{'SS': 'Sandstone', 'SH': 'Shale', 'LS': 'Limestone'}
read_lithology_codes(kingdom, label_column="Lithology Attribute")
{'SS': 'Clastic', 'SH': 'Clastic', 'LS': 'Carbonate'}
Rule |
Behaviour |
|---|---|
Layouts |
|
|
|
Duplicate codes, empty labels |
Error |
Codes |
Vendor-specific; the template’s assignments are only examples |
Use |
|
LAS metadata and embedded core data¶
No separate well-parameter or core-measurement template is required. The workflow reads supported parameters such as Rw, its reference temperature, BHT, TD, Archie coefficients and zoned values from LAS metadata. Explicit Python settings take precedence, and documented defaults are used when a value is absent. The mud and formation-water parameters, and the settings they stand in for:
LAS parameter |
Setting |
How it is read |
|---|---|---|
|
|
Rw in ohm.m at RWT; without RWT, at the formation temperature |
|
|
|
|
|
|
|
|
Mud-filtrate chlorides in mg/l (values in ppm, kppm or % are converted). Without an Rmf, Rmf comes from the NaCl equivalent, Cl x 58.44/35.45, divided by the brine density |
|
|
BHT is taken as the static formation temperature at TD, with no correction for mud circulation. |
|
|
Geothermal gradient (degC/100 m, degC/km or degF/100 ft; without a unit, degC/100 m up to 10, else degC/km), from |
|
|
An oil-based-mud flag: |
|
|
Mud-filtrate salinity (units converted) |
|
|
meq/100 g; a value labelled meq/g is multiplied by 100, and a value under 1 gets a warning, as meq/g values look like that |
|
|
Bound-water resistivity, ohm.m; Dual Water runs only with it |
|
|
The neutron reading and the density of shale give the clay porosity; PNSH alone is not used |
The other header parameters the workflow reads, each standing in for the setting of the same meaning when you leave that setting unset:
LAS parameter |
Setting |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
net-pay cutoffs |
|
|
|
|
|
|
The last three set one value each of a setting that takes a mapping
(Workflows): a header value fills the keys you leave out, so with
bad_hole={"cali": 2.0} passed and BADHOLE_DRHO in the header, both are
used. The “geolink” calculation profile does not read them. In the header:
BADHOLE_CALI.in 2.0 : Caliper washout threshold, CALI - BS
PERM_A. 0.1 : Permeability equation coefficient
QUARTZ_RHOB.g/cc 2.65 : Quartz density endpoint
Any of these with a _Z1, _Z2, … suffix, together with TOP_Z1/BOT_Z1
(and so on) giving the zone’s depths, applies inside that zone only, for
example RW_Z1, M_Z1 or SAL_Z2. A header zone value ranks below the
settings you pass: with rw set, RW_Z1 is not used, and a warning says so.
To give zone values yourself, pass them as zones (see Workflows).
There is no separate settings or zone file: give settings in Python
(pp.interpret(well, rw=...) or a DynamicWorkflowConfig), or as LAS header
parameters as above. petrophys-context reads them from the LAS headers.
Header temperatures labelled degC or K are converted; unlabelled ones are read as degF. The “geolink” calculation profile (calculation profiles) reads CLFL as NaCl salinity in ppm, ignores MFST and MST, and takes PNSH as the clay porosity.
lithology_domain defaults to clastic. Set it to carbonate for carbonate
wells (pp.interpret(well, lithology="carbonate")): calcite and dolomite are
then solved from bulk density, with clay from VCL, so the split depends on the
pore-fluid density rho_fl (1.0 g/cm3 unless you set it for your brine). For the COSTA field wells,
carbonate_calibration="costa" applies the field calibration instead (illite
from GR, and a 1.1 g/cm3 brine for porosity and minerals unless you set
rho_fl). Set auto when deliberate domain inference is
wanted. A COSTA well with the field calibration:
carbonate = pp.interpret(pp.read(pp.sample("HW-3")), lithology="carbonate",
carbonate_calibration="costa")
carbonate.config.lithology_domain, carbonate.config.carbonate_calibration
('carbonate', 'costa')
In LAS metadata, use PP_DOMAIN or LITHOLOGY_DOMAIN. On the command line,
use --lithology-domain carbonate. Existing LAS core curves such as PHIC,
KH_CORE, SWC, SOC and GDEN are standardized in place on the
interpreted copy. Log-derived saturation remains the primary SW result;
core saturation is supporting evidence, not an automatic replacement.
The GR equation can also be declared in the LAS parameter section. For example:
GR_METHOD. steiber : Gamma-ray clay-volume transform
GR_MIN.API 20 : Clean-rock gamma-ray endpoint
GR_MAX.API 100 : Shale gamma-ray endpoint
GR_METHOD accepts linear, larionov_tertiary, larionov_older, steiber (the Stieber transform; stieber is read too)
and clavier; linear is the default. The workflow trace and context
notes record the equation and the endpoints actually applied. These settings
are read per well, including when --lithology-domain is supplied. Explicit
Python settings override the LAS values.
GR baselines you set (gr_min/gr_max, GR_MIN/GR_MAX in the header, or
per zone GR_MIN_Z1 with TOP_Z1/BOT_Z1) are used as given. Left unset,
pp.interpret picks the finite GR 5th/95th percentiles (as does
GR_MIN/GR_MAX set to auto), and VclModule/calculate_vcl used on their
own pick the log minimum/maximum. Those picks are then bounded:
GRclean = min(pick, 20) and GRshale = max(pick, 100). The bound guards a
nearly flat GR, a section with no real shale or no real clean rock, where the
picks would stretch the gamma-ray index across noise (the COSTA files read
5-14 API at P5 and 20-70 API at P95). It is not a rule of the method: clean rock that is itself
radioactive, such as the feldspathic and lithic Taranaki sands (Cheal-1 reads
about 86 API in its Mount Messenger sands), is read as clay under it. A clean
pick above 30 API that the bound lowers raises a warning; set gr_min from a
known clean sand there, per zone where it changes. The trace records the picks
and what the bound moved (gr_bounded).
GR_MIN.API auto : Calculate clean endpoint from GR P5
GR_MAX.API auto : Calculate shale endpoint from GR P95
PHIE_CUTOFF.v/v 0.08 : Explicit net-reservoir porosity cutoff
VCL_CUTOFF, PHIE_CUTOFF and SW_CUTOFF are optional LAS parameters for
explicit cutoffs. Leaving them absent retains the workflow defaults;
supplying PHIE_CUTOFF makes that value apply to every lithology in the well.
When external lithology intervals are selected, context grouping and lithology summaries use their labels. Gaps stay unclassified even if a different LAS lithology curve is present. A formation’s descriptive majority lithology should only be supplied as calculation lithology when that interpretation is intended.
Core saturation units¶
SWC, SOC, SGC and their aliases are converted to fractions when a well is
standardized, interpreted or plotted. The bundled 30/6-5 LAS labels SWC as a
fraction but stores percentages:
from petrophys.preprocessing.standardization import standardize_core_saturation
stored = pp.read(pp.sample("30_6-5"))["SWC"]
normalized = standardize_core_saturation(stored)
pd.DataFrame({"as stored": stored.describe(), "normalized": normalized.describe()})
| as stored | normalized | |
|---|---|---|
| count | 74.000000 | 74.000000 |
| null_count | 22102.000000 | 22102.000000 |
| min | 13.700000 | 0.137000 |
| max | 84.600000 | 0.846000 |
| mean | 48.239189 | 0.482392 |
| std | 15.787626 | 0.157876 |
| median | 47.350000 | 0.473500 |
| p25 | 36.550000 | 0.365500 |
| p75 | 60.125000 | 0.601250 |
The conversion is recorded on the curve:
normalized.metadata.custom["core_saturation_normalization"]
{'original_unit': 'frac',
'source_unit': None,
'target_unit': 'v/v',
'factor': 0.01,
'reason': 'inferred_percent',
'masked_count': 0,
'warnings': ["SWC: inferred percent core saturation despite unit 'frac'; divided by 100 to v/v. Verify source units."]}
Case |
Result |
|---|---|
Declared percent unit |
Divided by 100, even values below 1 |
No unit, or a fraction label on percent-like values |
Percent inferred when at least two samples lie between 1 and 100, at least 80% of positive samples exceed 1, and their median is at least 2; a warning says so |
A single outlier or a strongly mixed scale |
Not rescaled; implausible values are masked with a warning, never clipped |
Percentages all below 1 with no unit |
Cannot be told apart from fractions: confirm, then pass |
Already normalized |
Not divided again |
Opt out |
|
A unit correction does not make core saturation equivalent to log-derived water saturation.
Use the optional geology together¶
The petrophys-context command reads a LAS plus either or both optional
geology tables; see Context export.
petrophys-context well.las well_context.json \
--formations formation_intervals.csv --lithology lithology_intervals.csv
What to ask your data provider for¶
Item |
Used for |
|---|---|
Well identifier and the exact LAS used |
Matching every table to the well |
Depth unit, reference (MD, TVD, TVDSS) and datum (RKB, ground level, sea level) |
Depth checks |
Core-to-log depth shift |
Placing plugs on the log |
Tops or top/base intervals, their rank, and the source and version of the picks |
Formation summaries |
Lithology source (core, cuttings or interpretation) and its codebook |
The lithology track and matrix choice |
Core saturation fluid, units and laboratory basis |
Core saturation units |
Keep rich vendor exports as the source of record and derive these small tables from them. Common sources map as follows:
Source |
Layout |
How to use it |
|---|---|---|
Well, marker name and measured depth |
Select the well; map the marker and depth columns |
|
Top, base and a keyword linked to a dictionary |
Lithology intervals plus a codebook |
|
XML intervals with ranks and percentage mixtures |
Not read directly; export categorical intervals |
|
mMD RKB tops with coincident group and formation picks |
Keep the hierarchy in a |
Go deeper¶
Attach these tables to your logs and check their depths.
Ranks, nested groups and per-formation summaries.
Core porosity and permeability used to calibrate the logs.