wellcast quickstart¶
Author: Olaf Yunus Laitinen Imanov (ORCID 0009-0006-5184-0810)
Affiliation: Department of Mathematics and Statistics, University of Helsinki
License: Mozilla Public License 2.0 (MPL-2.0), Copyright (c) 2026 Olaf Yunus Laitinen Imanov
A tour of the main workflow on a synthetic field: load data, check its quality, look at a well, fit a decline curve and flag anomalies. Everything runs on simulated data, so no files are needed.
# Install wellcast when it is not available yet (for example on Google Colab).
import importlib.util
from IPython import get_ipython
if importlib.util.find_spec("wellcast") is None:
get_ipython().run_line_magic(
"pip",
'install -q "wellcast[all]==0.1.0"',
)
1. A synthetic field¶
make_synthetic_field simulates five producers and one water injector for five years of daily data. The physics is simple but consistent (Arps decline, IPR, choke equation, water breakthrough, shut-ins), and every anomaly it injects is labelled, so the analysis can be checked against the truth.
import wellcast
from wellcast import plotting
field = wellcast.make_synthetic_field(n_wells=5, years=5, seed=42)
production = field.production
production.head()
| well | oil_rate | gas_rate | water_rate | water_inj_rate | whp | wht | bhp | bht | choke | on_stream_hours | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| date | |||||||||||
| 2020-01-17 | P-01 | 1835.435628 | 1454.105790 | 0.0 | NaN | 979.447905 | 168.762167 | 3486.540205 | 202.727373 | 32.0 | 24.0 |
| 2020-01-18 | P-01 | 1800.723538 | 1417.582767 | 0.0 | NaN | 980.282058 | 169.760191 | 3493.552516 | 202.533161 | 32.0 | 24.0 |
| 2020-01-19 | P-01 | 1716.087456 | 1466.026880 | 0.0 | NaN | 969.734927 | 167.007731 | 3493.628446 | 203.167426 | 32.0 | 24.0 |
| 2020-01-20 | P-01 | 1794.202894 | 1383.469662 | 0.0 | NaN | 975.247882 | 168.449241 | 3487.302647 | 201.726935 | 32.0 | 24.0 |
| 2020-01-21 | P-01 | 1800.021171 | 1342.528801 | 0.0 | NaN | 973.002592 | 168.239056 | 3505.981208 | 202.887278 | 32.0 | 24.0 |
field.wells[["type", "qi", "di", "b", "bubble_point", "breakthrough_date"]]
| type | qi | di | b | bubble_point | breakthrough_date | |
|---|---|---|---|---|---|---|
| well | ||||||
| P-01 | producer | 1770.541972 | 0.822229 | 0.718421 | 2715.261460 | 2022-11-30 |
| P-02 | producer | 1509.167340 | 0.728443 | 0.485133 | 1942.977662 | 2023-02-13 |
| P-03 | producer | 1433.916011 | 0.423983 | 0.339741 | 2380.149604 | 2023-03-29 |
| P-04 | producer | 2038.249905 | 0.836591 | 0.515697 | 2778.515460 | 2022-06-09 |
| P-05 | producer | 2049.233406 | 0.445919 | 0.780637 | 2017.277760 | 2021-07-26 |
| I-01 | injector | NaN | NaN | NaN | NaN | NaT |
2. Data quality¶
qc_report counts missing values, negative values, flatlines (frozen gauges) and physically impossible values per well and column. Columns a well never measures, such as the oil rate of an injector, show up as 100 percent missing.
report = wellcast.qc_report(production)
report[report["missing"] < report["n"]].head(12)
| well | column | n | missing | missing_pct | negative | flatline | impossible | |
|---|---|---|---|---|---|---|---|---|
| 3 | I-01 | water_inj_rate | 1694 | 0 | 0.0 | 0 | 0.0 | 0.0 |
| 4 | I-01 | whp | 1694 | 0 | 0.0 | 0 | 0.0 | 0.0 |
| 5 | I-01 | wht | 1694 | 0 | 0.0 | 0 | 0.0 | 0.0 |
| 6 | I-01 | bhp | 1694 | 0 | 0.0 | 0 | 0.0 | 0.0 |
| 9 | I-01 | on_stream_hours | 1694 | 0 | 0.0 | 0 | NaN | 0.0 |
| 10 | P-01 | oil_rate | 1810 | 0 | 0.0 | 0 | 0.0 | 0.0 |
| 11 | P-01 | gas_rate | 1810 | 0 | 0.0 | 0 | 0.0 | 0.0 |
| 12 | P-01 | water_rate | 1810 | 0 | 0.0 | 0 | 0.0 | 0.0 |
| 14 | P-01 | whp | 1810 | 0 | 0.0 | 0 | 0.0 | 0.0 |
| 15 | P-01 | wht | 1810 | 0 | 0.0 | 0 | 0.0 | 0.0 |
| 16 | P-01 | bhp | 1810 | 0 | 0.0 | 0 | 17.0 | 0.0 |
| 17 | P-01 | bht | 1810 | 0 | 0.0 | 0 | 0.0 | 0.0 |
3. Production history¶
Rates and pressures are drawn in two panels that share the time axis. Fluids keep fixed colors and dash patterns in every wellcast chart.
plotting.production_history(production, "P-01")
4. Decline curve and EUR¶
DeclineModel fits exponential, harmonic and hyperbolic Arps models and keeps the one with the lowest AIC. A residual bootstrap gives P90 (low), P50 and P10 (high) estimates.
rates = production.loc[production["well"] == "P-01", "oil_rate"]
model = wellcast.DeclineModel().fit(rates).bootstrap(200)
print(model)
model.eur_quantiles(econ_limit=20.0).round(0)
DeclineModel(exponential, qi=2039, di=0.6798/yr, b=0)
p90 1077475.0 p50 1084963.0 p10 1092161.0 Name: eur, dtype: float64
model.plot(rates, econ_limit=20.0)
5. Anomalies¶
Physical rules and an Isolation Forest flag suspicious periods. The synthetic labels show what was injected.
from wellcast.diagnostics import detect_anomalies
anomalies = detect_anomalies(production, method="rules")
anomalies.head(10)
| well | start | end | n_rows | detector | |
|---|---|---|---|---|---|
| 0 | P-01 | 2021-05-03 | 2021-05-04 | 2 | dropout_whp |
| 1 | P-01 | 2023-05-31 | 2023-06-16 | 17 | flatline_bhp |
| 2 | P-01 | 2024-03-03 | 2024-03-03 | 1 | spike_oil_rate |
| 3 | P-02 | 2021-06-04 | 2021-06-04 | 1 | spike_oil_rate |
| 4 | P-02 | 2021-10-01 | 2021-10-05 | 5 | dropout_whp |
| 5 | P-02 | 2024-07-31 | 2024-08-15 | 16 | flatline_bhp |
| 6 | P-03 | 2022-12-27 | 2023-01-14 | 19 | flatline_bhp |
| 7 | P-03 | 2024-07-12 | 2024-07-13 | 2 | dropout_whp |
| 8 | P-03 | 2024-09-09 | 2024-09-09 | 1 | spike_oil_rate |
| 9 | P-04 | 2022-11-12 | 2022-11-28 | 17 | flatline_bhp |
plotting.anomaly_overlay(production, anomalies, "bhp", "P-01")
Next steps¶
02_decline_curve_analysis.ipynb: decline models, model selection and uncertainty.03_virtual_flow_metering.ipynb: predicting bottomhole pressure with machine learning.wellcast appopens the interactive Streamlit app.