Skip to content

wellcast.io

io

Read field production data and well logs into standard DataFrames.

Canonical production schema. read_production returns a DataFrame with a DatetimeIndex named date, sorted by well and date, and the columns below. Only well is mandatory; the others are present when the source provides them. Columns that do not match the schema are kept unchanged after the canonical ones.

Column Unit dtype Description
well str Well identifier
oil_rate bbl/d float64 Oil rate at stock-tank conditions
gas_rate Mscf/d float64 Gas rate at standard conditions
water_rate bbl/d float64 Water rate
water_inj_rate bbl/d float64 Water injection rate
gas_inj_rate Mscf/d float64 Gas injection or gas lift rate
whp psi float64 Wellhead (tubing head) pressure
wht degF float64 Wellhead temperature
bhp psi float64 Bottomhole (downhole gauge) pressure
bht degF float64 Bottomhole temperature
choke in/64 float64 Choke bean size
on_stream_hours h float64 Producing hours in the period

ColumnSpec dataclass

ColumnSpec(name: str, unit: str, dtype: str, description: str)

Description of one column in the canonical production schema.

Parameters:

Name Type Description Default
name str

Canonical column name.

required
unit str

Unit symbol understood by wellcast.units.convert, or "-".

required
dtype str

Expected dtype.

required
description str

Human-readable description.

required

standardize_columns

standardize_columns(df: DataFrame, alias_map: Mapping[str, str] | None = None) -> pd.DataFrame

Rename source columns to canonical names.

Parameters:

Name Type Description Default
df DataFrame

Raw table.

required
alias_map mapping of str to str

Extra aliases {source_name: canonical_name}. They take precedence over DEFAULT_ALIASES. Matching ignores case and punctuation.

None

Returns:

Type Description
DataFrame

Copy of df with renamed columns. When two source columns map to the same canonical name, the first one wins and the other keeps its original name.

Examples:

>>> import pandas as pd
>>> raw = pd.DataFrame({"DATEPRD": [], "BORE_OIL_VOL": [], "AVG_WHP_P": []})
>>> list(standardize_columns(raw).columns)
['date', 'oil_rate', 'whp']

read_production

read_production(path: str | PathLike[str], alias_map: Mapping[str, str] | None = None, *, units: Mapping[str, str] | None = None, well: str | None = None, sheet_name: str | int = 0, dayfirst: bool = False) -> pd.DataFrame

Read a CSV or Excel production table into the canonical schema.

Parameters:

Name Type Description Default
path str or path - like

.csv/.txt or .xlsx/.xlsm/.xls file.

required
alias_map mapping of str to str

Extra column aliases {source_name: canonical_name}.

None
units mapping of str to str

Units of canonical columns in the source, for example {"oil_rate": "sm3/d", "whp": "bar"}. Those columns are converted to the canonical units listed in CANONICAL_SCHEMA.

None
well str

Well name to use when the file has no well column.

None
sheet_name str or int

Excel sheet. Default is the first sheet.

0
dayfirst bool

Parse ambiguous dates as day first (31/01/2024).

False

Returns:

Type Description
DataFrame

Table indexed by a DatetimeIndex named date.

Raises:

Type Description
DataValidationError

If the file type is unsupported, no date column is found, dates cannot be parsed, or no well identifier is available.

MissingDependencyError

If an Excel file is read without openpyxl installed.

Examples:

>>> import tempfile, pathlib
>>> from wellcast.io import read_production
>>> tmp = pathlib.Path(tempfile.mkdtemp()) / "prod.csv"
>>> _ = tmp.write_text("DATEPRD,WELL,BORE_OIL_VOL\n2024-01-01,A-1,100\n")
>>> df = read_production(tmp, units={"oil_rate": "m3/d"})
>>> round(float(df["oil_rate"].iloc[0]), 1)
629.0

from_dataframe

from_dataframe(raw: DataFrame, alias_map: Mapping[str, str] | None = None, *, units: Mapping[str, str] | None = None, well: str | None = None, dayfirst: bool = False) -> pd.DataFrame

Convert an in-memory table into the canonical schema.

Same processing as read_production, for data that is already in a DataFrame (for example from a database query or a web upload).

Parameters:

Name Type Description Default
raw DataFrame

Source table with a date column; its index is ignored.

required
alias_map mapping of str to str

Extra column aliases {source_name: canonical_name}.

None
units mapping of str to str

Source units of canonical columns, converted to canonical units.

None
well str

Well name to use when the table has no well column.

None
dayfirst bool

Parse ambiguous dates as day first.

False

Returns:

Type Description
DataFrame

Table indexed by a DatetimeIndex named date, sorted by well and date.

Raises:

Type Description
DataValidationError

If no date column is found, dates cannot be parsed, or no well identifier is available.

Examples:

>>> import pandas as pd
>>> raw = pd.DataFrame({"Date": ["2024-01-02", "2024-01-01"], "Qo": [90, 100]})
>>> from_dataframe(raw, well="A")["oil_rate"].tolist()
[100.0, 90.0]

read_las

read_las(path: str | PathLike[str]) -> pd.DataFrame

Read a LAS well log file into a depth-indexed DataFrame.

Parameters:

Name Type Description Default
path str or path - like

LAS 1.2, 2.0 or 3.0 file.

required

Returns:

Type Description
DataFrame

Curves as columns, indexed by the first (depth) curve. Header items from the ~Well section are stored in df.attrs["well"] and curve units in df.attrs["units"].

Raises:

Type Description
MissingDependencyError

If lasio is not installed.

Examples:

>>> import tempfile, pathlib, numpy as np
>>> import lasio
>>> las = lasio.LASFile()
>>> las.append_curve("DEPT", np.array([1000.0, 1000.5]), unit="ft")
>>> las.append_curve("GR", np.array([45.0, 60.0]), unit="API")
>>> tmp = pathlib.Path(tempfile.mkdtemp()) / "log.las"
>>> las.write(str(tmp))
>>> read_las(tmp)["GR"].tolist()
[45.0, 60.0]