# Petrophys > Python library for petrophysical well-log interpretation: reads LAS, DLIS and CSV logs and computes clay volume, porosity, water saturation, permeability, rock quality and net pay with a traceable, input-aware workflow. Every step records its method, inputs, outputs and parameters; every skipped step records why. Key facts for code generation: - Front door: `import petrophys as pp`; `well = pp.read(path)`; `result = pp.interpret(well, rw=0.07, rw_meas_temp_f=230)`; `pp.plot(result, top=top, bottom=bottom)`. The top-level names are `read`, `interpret`, `plot`, `impute`, `export_context`, `read_formations`, `sample`, `list_samples`, `Well`, `DynamicWorkflowConfig` and `__version__`; everything else is imported from its package. - `pp.read(path, *, formations=None, lithology=None, **reader_options)` reads LAS/DLIS/CSV/TSV/Excel; CSV, TSV and Excel logs need `depth_unit="m"` or `"ft"` among the reader options unless the depth header gives the unit (`DEPTH (m)`). - `pp.impute(well, "RHOB", train_wells=None, output=None)` rebuilds a curve's missing samples from the other logs (needs the `ml` extra): it adds `RHOB_IMPUTED` (measured values kept) and the check curve `RHOB_PREDICTED`, whose `description` gives the out-of-fold error. - `pp.interpret(well, config=None, *, formations=None, lithology=None, output=None, inplace=False, **settings)` returns `DynamicWorkflowResult` (`from petrophys.workflow import DynamicWorkflowResult`); it works on a copy, and `output=` writes the interpreted LAS. Settings are `pp.DynamicWorkflowConfig` fields (units in names: `bht_f` degF, `td_ft` feet; resistivities ohm.m). Invalid values raise `ValueError` listing accepted values. - Formation water resistivity `rw` (ohm.m) usually cannot be derived from logs: ask for it instead of assuming, and pass its temperature `rw_meas_temp_f` (degF); without it Rw is taken at the well's median formation temperature, with a warning in `result.warnings`. - Result: `result.status`, `result.well` (interpreted curves: VCL, PHIT, PHIE, SW, SXO, PERM, RQI, NET_ROCK, NET_RES, NET_PAY), `result.config` (settings used), `result.specific_steps_skipped` (reasons), `result.warnings`, `result.to_trace_dict()`, `result.to_json(path)`, `result.to_las(path)`, `result.raise_for_errors()`. - `well.describe()` and `result.summary(top=None, bottom=None)` return compact JSON-serializable overviews (curves and units; status, settings used, key statistics, net thickness, skip reasons, warnings). `result.formation_summary()` returns a pandas table of net pay and averages per formation (formations attached with `pp.read(path, formations=...)` or passed as `formations=`). - Mineral model: `pp.interpret(well, lithology="clastic" | "carbonate" | "auto")` (the `lithology_domain` setting). `lithology=` also takes per-depth lithology intervals (a `top,bottom,lithology` table, as in `pp.read`) or the name of the well's lithology code curve. The carbonate domain solves calcite and dolomite from RHOB with clay from VCL and pore-fluid density `rho_fl`; pass `carbonate_calibration="costa"` for the COSTA field wells. - Lithology code curve: `pp.interpret` reads one per-sample code curve, the one `lithology=` names (e.g. `lithology="FACIES"`), else `LITHOLOGY_GEOLINK`, else the first curve under a lithology-code name (`LITHOLOGY`, `LITHOFACIES`, `FACIES`, `LITH_CODE`, `ROCK_TYPE`, ...) whose values are lithology codes. Its codes are always decoded with the GeoLink/Kingdom table, and a warning names any other curve; if it holds other codes, pass `lithology_source="computed"` or lithology intervals. - Saturation: `sw_model="auto"` (default) picks Archie or a shaly-sand model per sample by clay volume. `"dual_water"` needs a measured bound-water resistivity `rwb` and `"waxman_smits"` needs `cec` (meq/100 g) and `b_coeff`; neither is estimated, so ask for them. With `mud_type="OBM"` no SXO or MHI is computed and Rw is not taken from the SP or Rxo/Rt. - Net-pay flags are cutoff screening, not confirmed hydrocarbons. Unset cutoffs follow each sample's lithology family (clastic VCL < 0.40, PHIE > 0.08, SW < 0.60; carbonate VCL < 0.30, PHIE > 0.045, SW < 0.70); evaporite, coal, halite recognized on the logs and bad-hole samples are never net reservoir or net pay. One Rw serves the whole well, so shallow sections with fresher water and no lithology code can still be flagged as marginal pay: report a reservoir window (`result.summary(top=..., bottom=...)`) or per-formation results (`result.formation_summary()`), not whole-well totals. - Bad hole: no bit size is assumed. `BAD_HOLE` = 1 where CALI exceeds the bit size by more than 1.5 in or the bit is over 17.5 in, tested only where a bit size is known (BS curve, else a 3-36 in header value), or where |DRHO| > 0.15 g/cm3. Without a bit size only DRHO can flag bad hole, and a warning says where. - Classes: `from petrophys.model import CLASS_TABLES` holds one canonical table per property (VCL, PHI, PERM, SW, BVW, RQI, FZI, MHI, RXO_RT, RESERVOIR_QUALITY); `CLASS_TABLES["VCL"].classify(values)` labels each sample, a missing value as `NO_VCL_DATA`. `CLASS_TABLES["RESERVOIR_QUALITY"].classify(phie, perm, vcl, family)` grades with the limits of the lithology family (`"clastic"` or `"carbonate"`). The diagnostics analyzers and `petrophys.workflow.run_comprehensive_analysis` take `lithology_family` and grade as clastic without it. - Invasion: `INVASION_RATIO` (Rxo/Rt) reads RXO first, then RSHA and RESS, then RMED/RESM as a proxy; `petrophys.interpretation.electrical.invasion.InvasionModule` defaults to `rxo_curve="RXO"`. - `pp.export_context(result)` returns a JSON-ready summary dict; `pp.export_context(result, path)` writes it. Context packages (`pp.export_context(folder, out_dir, layout="package", formations=..., lithology=...)`) write the six category contexts per well and group: each formation (or each zone, with `zones=`) split into lithology groups, or one group each with `split_by_lithology=False`; `formation_info.depth_unit` gives the unit of its depths, and PHI_NORM, RQI, FZI, BVW and PHI_Z are recomputed after the export's value-range QC. - `calculation_profile`: `"current"` (default) is the maintained interpretation; `"geolink"` keeps the calculations of the GeoLink eval context package so it can be regenerated exactly. Use `"geolink"` only for that. - `petrophys.workflow.config_schema()` lists every setting with type, default, description and accepted values; `petrophys.workflow.workflow_steps()` lists the steps. - Data problems give a `petrophys.exceptions.DataQualityWarning` (e.g. a curve in the wrong unit). - Sample data: `pp.list_samples()`, `pp.sample("30_6-5")`. - Custom workflows: `from petrophys.workflow import Workflow, steps, workflow_step`; `wf = Workflow("name", [steps.clay_volume(method="gr"), steps.porosity(method="density"), steps.formation_water(rw=0.07, rw_temp_f=230), steps.saturation(model="archie"), steps.net_pay(vcl_cutoff=0.35, phie_cutoff=0.1, sw_cutoff=0.6)])` (`steps.net_pay` leaves evaporite, coal, halite and bad-hole samples out unless `exclude_non_reservoir=False`); `wf.check(well)`; `run = wf.run(well)` (strict; `strict=False` records `run.steps_skipped`); `wf.run_many(folder).summary_table()`; `wf.save(path)` / `Workflow.load(path)`. Own steps: `@workflow_step(requires=[...], produces={"X": "unit"})` on `def f(well, **params)` returning `{name: array}`. - `petrophys.evaluation.summarize_pay` and `calculate_net_pay` recompute flags with one cutoff set and no exclusions; summarize an interpretation's own flags with `result.summary()` or `result.formation_summary()`. - MCP server for LLM clients: `pip install "petrophys[mcp]"`, run `petrophys-mcp --root `; `petrophys-mcp serve --calculation-profile geolink` (or `PETROPHYS_CALCULATION_PROFILE=geolink`) pins an evaluation harness to the eval package's calculations. ## Docs - [Installation](https://welllogbench.com/petrophys/docs/installation): pip install, optional extras - [Quickstart](https://welllogbench.com/petrophys/docs/quickstart): read, interpret, inspect the trace, plot, export - [Own data](https://welllogbench.com/petrophys/docs/own_data): CSV/Excel logs, formations, lithology, units and datums - [What Petrophys can do](https://welllogbench.com/petrophys/docs/capabilities): map of every capability, the call that starts it and the page that covers it - [Workflows](https://welllogbench.com/petrophys/docs/workflows): workflow steps, routing, zoned and batch runs; reviewing an interpretation (checklist, net-pay flags, sample-data limitations) - [Custom workflows](https://welllogbench.com/petrophys/docs/custom_workflows): build, check, save and run your own workflows - [Visualization and reporting](https://welllogbench.com/petrophys/docs/visualization_reporting): plots, exports, delivery packages - [Specialist data](https://welllogbench.com/petrophys/docs/specialist_data): NMR, spectral gamma, core calibration, saturation-height, borehole images - [Analysis tools](https://welllogbench.com/petrophys/docs/analysis_tools): gap filling, clay typing, heterogeneity, zonation, Monte Carlo, invasion, pore pressure - [Context export](https://welllogbench.com/petrophys/docs/context): compact JSON summaries of interpreted wells for LLMs - [LLM agents (MCP)](https://welllogbench.com/petrophys/docs/mcp): MCP server setup, tools, resources and prompts - [Input templates](https://welllogbench.com/petrophys/docs/input_templates): formation and lithology file formats - [Terms and curves](https://welllogbench.com/petrophys/docs/glossary): terms and every output curve; argument names per interface - [Reproducing the benchmark packages](https://welllogbench.com/petrophys/docs/benchmark_context): dataset context profiles for the GeoLink, GeoLink training, COSTA and Danish packages ## API - [API reference](https://welllogbench.com/petrophys/docs/api/): every public module, grouped by area - [pp namespace](https://welllogbench.com/petrophys/docs/api/namespace): every name in `import petrophys as pp` - [Interpretation settings](https://welllogbench.com/petrophys/docs/api/settings): every `pp.interpret` keyword with its default - [Front door](https://welllogbench.com/petrophys/docs/api/reference/front-door): [pp.read](https://welllogbench.com/petrophys/docs/api/reference/petrophys.api.read), [pp.interpret](https://welllogbench.com/petrophys/docs/api/reference/petrophys.api.interpret), [pp.plot](https://welllogbench.com/petrophys/docs/api/reference/petrophys.api.plot) - [DynamicWorkflowConfig](https://welllogbench.com/petrophys/docs/api/reference/petrophys.workflow.DynamicWorkflowConfig) and [DynamicWorkflowResult](https://welllogbench.com/petrophys/docs/api/reference/petrophys.workflow.DynamicWorkflowResult): settings and result of `pp.interpret` - [Custom workflows and built-in steps](https://welllogbench.com/petrophys/docs/api/reference/petrophys.workflow.custom): `petrophys.workflow.Workflow`, `petrophys.workflow.workflow_step`, `petrophys.workflow.steps` - API areas: [data model and I/O](https://welllogbench.com/petrophys/docs/api/reference/data-io), [preprocessing](https://welllogbench.com/petrophys/docs/api/reference/preprocessing), [interpretation](https://welllogbench.com/petrophys/docs/api/reference/interpretation), [evaluation](https://welllogbench.com/petrophys/docs/api/reference/evaluation), [workflows](https://welllogbench.com/petrophys/docs/api/reference/workflows), [visualization](https://welllogbench.com/petrophys/docs/api/reference/visualization), [reporting and LLM agents](https://welllogbench.com/petrophys/docs/api/reference/reporting) ## Optional - [Tutorials](https://welllogbench.com/petrophys/docs/tutorials/): executed notebooks from basics to field studies - [Release notes](https://welllogbench.com/petrophys/docs/changelog)