Context export¶
An interpreted and reviewed well can be handed to an LLM. A context is a compact JSON summary of an interpreted well, small enough for an LLM, a report generator or a database. It holds no depth-by-depth arrays and is built locally, with no LLM or network call. To let an LLM run the interpretation itself, see LLM agents (MCP).
Choose a workflow¶
Task |
Entry point |
|---|---|
Summarize an interpretation you already ran |
|
Interpret your own well and write one JSON |
|
Generate six category contexts across wells, formations and lithology groups |
|
Reproduce the GeoLink, GeoLink training, COSTA or Danish benchmark |
The collection’s |
Install Petrophys first (Installation); DLIS input also needs the dlis extra.
The same exports run from the command line (From the command line). Geology tables are
optional; their layouts are in Input templates.
One well¶
Without an output path, pp.export_context turns an interpretation result into a JSON-safe dictionary:
import json
import petrophys as pp
well = pp.read(pp.sample("30_6-5"), formations=pp.sample("formations_30_6-5"))
result = pp.interpret(well, rw=0.07, rw_meas_temp="230 degF") # Rw 0.07 ohm.m at 230 degF
context = pp.export_context(result)
Its size in bytes, in all and by top-level key:
len(json.dumps(context)), {key: len(json.dumps(value)) for key, value in context.items()}
(16538,
{'schema_version': 5,
'petrophys_version': 7,
'context_kind': 14,
'well': 6784,
'interpretation': 5221,
'geology': 4363,
'include_raw_traces_in_context': 5})
Key |
Holds |
|---|---|
|
header, depth range, curves with units and valid fraction |
|
status, settings used, key results, net thickness, steps with methods, skip reasons, warnings |
|
attached formations and lithology, with their import reports |
Each attached formation or group is one entry under geology, for example the Brent Group:
next(item for item in context["geology"]["formations"] if item["formation_name"] == "BRENT GP.")
{'formation_name': 'BRENT GP.',
'top_depth': 2841.0,
'bottom_depth': 2958.0,
'lithology': 'Sandstone',
'rank': 'group',
'parent': '',
'depth_unit': 'm'}
Pass a result, not a raw well: a one-well summary runs no calculations, so a well alone gives no computed curves or trace.
Given an output path, pp.export_context writes the same summary to a file:
saved = pp.export_context(result, "30_6-5_context.json")
saved.name, saved.stat().st_size
('30_6-5_context.json', 23020)
Many wells: context packages¶
A package reads a folder of well files, interprets each well and writes one JSON per well, formation and lithology group. LAS is selected by default; use pattern="*.dlis" for DLIS.
Within a formation, a lithology group is a run of consecutive samples with one lithology, taken from the lithology code curve the interpretation read (LITHOLOGY_GEOLINK or another lithology-code curve; see Input templates) or from the lithology intervals it selected.
Packages interpret as clastic unless told otherwise, so carbonate wells need the carbonate setting; COSTA wells also take the field’s mineral calibration, carbonate_calibration="costa", which writes the illite volume VILL. Here are two of the COSTA wells bundled in one folder, chosen with well_names and labelled with their Kharaib-2 tops:
records = pp.export_context(
pp.sample("HW-3").parent, "context", layout="package", well_names=["HW-3", "HW-4"],
formations=pp.sample("formations_costa"),
lithology_domain="carbonate", carbonate_calibration="costa", # settings as for pp.interpret
)
len(records)
168
The run wrote 168 group files, one record each: six category folders beside a
curve_name_mapping.json, and in each the files of every well and formation. The
porosity files of HW-3 hold one lithology group of the Kharaib-2 each:
from pathlib import Path
sorted(path.name for path in Path("context").iterdir())
['curve_name_mapping.json',
'hydrocarbon',
'lithology',
'numerical',
'permeability',
'porosity',
'saturation']
sorted(path.name for path in Path("context/porosity/HW-3/KHARAIB-2").glob("*.json"))
['KHARAIB-2_DOLOMITE_GROUP_1_porosity.json',
'KHARAIB-2_LIMESTONE_GROUP_10_porosity.json',
'KHARAIB-2_LIMESTONE_GROUP_11_porosity.json',
'KHARAIB-2_LIMESTONE_GROUP_1_porosity.json',
'KHARAIB-2_LIMESTONE_GROUP_2_porosity.json',
'KHARAIB-2_LIMESTONE_GROUP_4_porosity.json',
'KHARAIB-2_LIMESTONE_GROUP_5_porosity.json',
'KHARAIB-2_LIMESTONE_GROUP_6_porosity.json',
'KHARAIB-2_LIMESTONE_GROUP_8_porosity.json',
'KHARAIB-2_LIMESTONE_GROUP_9_porosity.json']
Each group file records the interval, the logs used and statistics of every curve. From the first limestone group of HW-3, the interval, the input logs and the statistics of effective porosity:
group = Path("context/porosity/HW-3/KHARAIB-2/KHARAIB-2_LIMESTONE_GROUP_1_porosity.json")
document = json.loads(group.read_text(encoding="utf-8"))
document["formation_info"]
{'name': 'KHARAIB-2',
'min_depth': 7805.0,
'max_depth': 8019.5,
'thickness': 214.5,
'depth_unit': 'ft'}
document["analysis_results"]["input_logs_present"]
['DTC', 'GR', 'NPHI', 'PERM_CC', 'PHIE_CC', 'RDEP', 'RHOB', 'SW_INPUT']
document["analysis_results"]["statistics"]["PHIE_overall"]
{'minimum': 0.1108,
'maximum': 0.3168,
'arithmetic_mean': 0.2224,
'geometric_mean': 0.2163,
'harmonic_mean': 0.2093,
'third_power_average': 0.232,
'median': 0.2267,
'mode': 0.236,
'standard_deviation': 0.0483}
Depths are in the well’s own unit, feet for HW-3: formation_info and analysis_results.lithology_group_info name it in depth_unit, and the bad-hole intervals in analysis_results.BADHOLE_QC_CHECK and the note on KH carry it too.
The statistics are taken after the export’s value-range QC, which sets values outside each curve’s plausible range to null in every group; saturations are clipped to 0-1 and permeability to 0.0001-20000 mD, so tight rock stays in the statistics at the 0.0001 mD floor (the benchmark profiles keep their packages’ rule, which nulls permeability outside that range).
PHI_NORM, RQI, FZI and BVW are then recomputed from the porosity, permeability and saturation that remain, and PHI_Z is set to the recomputed PHI_NORM: each is null wherever the QC removed one of its inputs, so no value computed from a removed sample reaches the statistics.
Layout |
Files |
|---|---|
|
one JSON for one well or result |
|
|
In a package each formation is split into lithology groups, as above. With split_by_lithology=False each formation is one group, <formation>_<category>.json, whose documents give its dominant_lithology. zones= groups the wells by your own intervals in place of the formations, in the same two ways (Workflows).
Published packages¶
Published packages (GeoLink, GeoLink training, COSTA and Danish) are computed by their dataset context profiles from the raw LAS, with the collection’s interpretation parameters, calibration and grouping rules; see Reproducing the benchmark packages for the inputs, commands and checks.
DLIS, CSV and TSV input¶
The package layout reads each file with pp.read, which picks the format from the
extension: LAS, DLIS, CSV or TSV. pattern selects the files (default
"*.las"), and reader_options go to the reader.
DLIS uses the same interpretation and category exporters as LAS. For example,
generate all six categories for the deep Daydream-1 delivery.
integration_fixture() downloads the 173 MB file on
first use and keeps it for later runs:
import petrophys as pp
from petrophys.datasets import integration_fixture
dlis = integration_fixture("daydream1_deep_pex_aps_ppc_ecs.dlis")
records = pp.export_context(
dlis.parent,
"outputs/daydream_context",
layout="package",
pattern="daydream1_deep_pex_aps_ppc_ecs.dlis",
reader_options={"step": 0.1524},
)
The output directory must be new. reader_options are forwarded to pp.read;
DLIS supports options such as channels, logical_file, channel_preference
and step. The example explicitly merges channels onto a 0.1524 m grid;
omitting step uses the reader’s default finest grid, which can be much larger.
The step is expressed in the target depth unit (metres by default).
Pass formations and lithology just as for LAS to supply real formation
and lithology intervals. Without matched tops, the exporter uses WHOLE_WELL;
without lithology information, it records that absence. DLIS alone does not
supply missing geological picks or core measurements.
The corresponding command, given the folder that holds the file
(integration_fixture(...).parent), is:
petrophys-context <folder> outputs/daydream_context_cli \
--layout package \
--pattern daydream1_deep_pex_aps_ppc_ecs.dlis --dlis-step 0.1524
CSV and TSV files hold one well each, with a depth column (DEPTH by
default; reader_options={"depth_column": "MD"} names another). They record
no depth unit, so give it: pattern="*.csv", reader_options={"depth_unit": "m"}
(CLI: --pattern "*.csv" --depth-unit m). They record no curve units or
header parameters either: give the curves in the library’s standard units and
pass values such as rw, rw_meas_temp and bht as settings, which LAS
files would carry in their headers. The published-package profiles
read LAS only.
Class labels¶
The analysis sections of a group file grade properties into classes, for example clay volume into CLEAN_FORMATION, MODERATE_CLAY and SHALY_FORMATION.
Under the default "current" calculations, the classes of clay volume, porosity, permeability, water saturation, BVW, RQI, FZI, MHI, Rxo/Rt and reservoir quality come from one canonical table per property, CLASS_TABLES, so a property gets the same class in every category file of a group.
A sample without a value gets the table’s NO_*_DATA label, never a class:
from petrophys.model import CLASS_TABLES
pd.Series({name: table.describe() for name, table in CLASS_TABLES.items()}).to_frame("classes")
| classes | |
|---|---|
| VCL | CLEAN_FORMATION < 0.25; MODERATE_CLAY >= 0.25 and <= 0.5; SHALY_FORMATION > 0.5 (VCL, v/v); NO_VCL_DATA where VCL is missing. |
| PHI | POOR_POROSITY <= 0.06; FAIR_POROSITY > 0.06 and <= 0.12; GOOD_POROSITY > 0.12 and <= 0.2; EXCELLENT_POROSITY > 0.2 (PHI, v/v); NO_POROSITY_DATA where PHI is missing. |
| PERM | VERY_POOR_PERMEABILITY <= 0.1; POOR_PERMEABILITY > 0.1 and <= 1; FAIR_PERMEABILITY > 1 and <= 10; GOOD_PERMEABILITY > 10 and <= 100; VERY_GOOD_PERMEABILITY > 100 and <= 1000; EXCELLENT_PERMEABILITY > 1000 (PERM, mD); NO_PERMEABILITY_DATA where PERM is missing. |
| SW | EXCELLENT_HC_SATURATION < 0.2; GOOD_HC_SATURATION >= 0.2 and < 0.4; FAIR_HC_SATURATION >= 0.4 and < 0.6; WATER_BEARING >= 0.6 (SW, v/v); NO_SATURATION_DATA where SW is missing. |
| BVW | VERY_LOW_BVW < 0.03; LOW_BVW >= 0.03 and < 0.06; MODERATE_BVW >= 0.06 and < 0.1; HIGH_BVW >= 0.1 (BVW, v/v); NO_BVW_DATA where BVW is missing. |
| RQI | LOW_RQI < 0.5; MODERATE_RQI >= 0.5 and <= 1; HIGH_RQI > 1 (RQI, um); NO_RQI_DATA where RQI is missing. |
| FZI | BELOW_GHE_1 < 0.0938; GHE_1 >= 0.0938 and < 0.1875; GHE_2 >= 0.1875 and < 0.375; GHE_3 >= 0.375 and < 0.75; GHE_4 >= 0.75 and < 1.5; GHE_5 >= 1.5 and < 3; GHE_6 >= 3 and < 6; GHE_7 >= 6 and < 12; GHE_8 >= 12 and < 24; GHE_9 >= 24 and < 48; GHE_10 >= 48 (FZI, um); NO_FZI_DATA where FZI is missing. |
| MHI | HIGH_MOVEABLE_HC < 0.5; MODERATE_MOVEABLE_HC >= 0.5 and < 0.7; LOW_MOVEABLE_HC >= 0.7 and < 0.9; MINIMAL_MOVEABLE_HC >= 0.9 (MHI); NO_MHI_DATA where MHI is missing. |
| RXO_RT | CONDUCTIVE_INVASION < 0.8; MINIMAL_INVASION >= 0.8 and <= 1.2; RESISTIVE_INVASION > 1.2 (RXO_RT); NO_INVASION_DATA where RXO_RT is missing. |
| RESERVOIR_QUALITY | Clastic rock: EXCELLENT_RESERVOIR: effective porosity > 0.15 v/v, permeability > 10 mD and clay volume < 0.25 v/v; GOOD_RESERVOIR: effective porosity > 0.1 v/v, permeability > 1 mD and clay volume < 0.4 v/v; FAIR_RESERVOIR: effective porosity > 0.08 v/v, permeability > 0.1 mD and clay volume < 0.4 v/v. Carbonate rock: EXCELLENT_RESERVOIR: effective porosity > 0.15 v/v, permeability > 10 mD and clay volume < 0.25 v/v; GOOD_RESERVOIR: effective porosity > 0.1 v/v, permeability > 1 mD and clay volume < 0.3 v/v; FAIR_RESERVOIR: effective porosity > 0.045 v/v, permeability > 0.1 mD and clay volume < 0.3 v/v. NON_RESERVOIR: below FAIR_RESERVOIR; NO_QUALITY_DATA where effective porosity, permeability or clay volume is missing. |
Reservoir quality grades effective porosity (PHIE_CC, else PHIE, else PHIT), permeability (PERM_CC, else PERM, PERM_CORE or PERM_TIMUR) and clay volume (VCL, else VCLAY, else VSH) together, with the limits of the lithology family of the group’s lithology.
Core-corrected porosity (PHIE_CC) needs usable paired log and core porosity
(PHIC or CPOR), subject to the calibration’s sample and fit-quality checks.
It does not require core permeability. Core permeability (KH_CORE, CPERM
or a supported alias) is needed for the separate PERM_CC transform. A well
can therefore export PHIE_CC alongside empirical PERM without PERM_CC.
Limestone, chalk, dolomite and marl are carbonate and every other rock takes the clastic family; a compound name goes by its last rock word, so SANDY LIMESTONE is carbonate and CALCAREOUS SHALE clastic.
A sample without lithology takes the family of the lithology domain of the run that interpreted it.
A sample without effective porosity, permeability or clay volume is NO_QUALITY_DATA: it gets no grade, not even NON_RESERVOIR.
From the command line¶
petrophys-context always interprets before exporting. Drop any optional flag whose input you do not have.
petrophys-context well.las well_context.json \
--formations formation_intervals.csv --lithology lithology_intervals.csv
petrophys-context logs outputs/context_run_01 --layout package \
--formations formation_intervals.csv --lithology lithology_intervals.csv \
--lithology-codes lithology_codes.csv --tops-rank formation
Flag |
Use |
|---|---|
|
export only these wells (repeatable) |
|
search nested folders; choose which files to read |
|
override the grouping threshold |
|
an interpretation setting of |
|
compute the published |
|
pick the formation level ( |
|
broad mineral-solving domain: |
|
change the size limits |
|
required for CSV/TSV logs |
|
replace an existing single-well JSON (packages are never overwritten) |
python -m petrophys.reporting.context_cli is equivalent.
The first command in Python, with your own files:
well = pp.read("well.las", formations="formation_intervals.csv",
lithology="lithology_intervals.csv")
result = pp.interpret(well) # reads supported settings and core curves from LAS
pp.export_context(result.raise_for_errors(), "well_context.json")
Multi-well input rules¶
The standardized readers accept CSV, TSV, Excel and DataFrames; Input templates lists the columns.
Input |
Rule |
|---|---|
Matching |
each table row matches a LAS file by the well name in its header, ignoring separators ( |
Tables covering several wells |
need a |
Formations ( |
canonical templates or NPD/SODIR |
Depths |
must share the well’s reference and datum; metres and feet convert, MD-to-TVD does not |
Lithology codes ( |
|
No formations |
the logged interval is analyzed as |
No lithology |
embedded evidence or the mineral solver supplies it |
No core curves in LAS |
core calibration is skipped and recorded in the trace |
Thin groups |
groups thinner than |
Carbonate wells |
set |
Schema and size contracts¶
Contract |
Value |
|---|---|
Single-well schema |
|
Missing numbers |
JSON |
|
1,000,000 UTF-8 bytes per JSON document |
|
No limit by default; set it to cap a package’s total size, ancillary files included |
Too large |
raises |
Existing package folder |
never overwritten |
Failed package run |
staged and validated first, so no partial folder is left |
Package documents |
written directly, not wrapped in a |
Next¶
LLM agents (MCP): let an LLM run the interpretation itself, instead of reading its result.
Tutorial 19 builds a single-well context and a full category package for 30/6-5.