FormationTops

petrophys.model.FormationTops

Also available as petrophys.evaluation.intervals.FormationTops

class FormationTops(intervals=None)[source]

Manager for a collection of formation/zone intervals.

Provides loading from CSV (simple, NPD, Danish formats), validation (overlap detection), querying by depth/name, and export to DataFrame/CSV.

Parameters:

intervals (list of Interval, optional) – Initial intervals to manage

Examples

>>> import petrophys as pp
>>> tops = FormationTops.from_csv(pp.sample("formations_30_6-5"))
>>> tops.validate()
[]
>>> tops.get_by_name("BRENT GP.").top_depth
2841.0
>>> [fm.name for fm in tops.get_at_depth(2850.0)]
['BRENT GP.', 'Ness Fm.']

Attributes

intervals

Return list of intervals (copy).

names

Return list of interval names.

Methods

add

Add an interval and re-sort.

clip_to_well

Return a new FormationTops with intervals clipped to well depth range.

filter_by_kind

Return intervals of a specific kind.

find_overlaps

Find overlapping peers, allowing explicitly linked parent containment.

from_csv

Read bounded intervals through the shared geology importer.

from_dataframe

Read a table using the same validation as CSV and plotting.

from_dict

Create from a list of dictionaries.

get_at_depth

Return all intervals containing this depth.

get_by_name

Get first interval matching name (case-insensitive).

get_in_range

Return intervals overlapping with [top, bottom] range.

has_overlaps

Return True if any intervals of the same kind overlap.

remove

Remove first interval matching name.

to_csv

Export intervals to CSV (depths at full precision).

to_dataframe

Convert intervals to a pandas DataFrame.

validate

Validate intervals: check for overlaps within same kind.

classmethod from_csv(
filepath,
well_name=None,
format='auto',
interval_kind=IntervalKind.FORMATION,
*,
terminal_depth=None,
rank=None,
**read_options,
)[source]

Read bounded intervals through the shared geology importer.

Simple, NPD and Danish headers share one validated schema. Top-only files require an explicit terminal_depth to derive intervals; no bottom is invented. Select rank before deriving intervals from hierarchical picks. read_options accepts the read_formations table/depth controls.

Parameters:
Return type:

FormationTops

classmethod from_dict(data, interval_kind=IntervalKind.FORMATION)[source]

Create from a list of dictionaries.

Each dict must have keys: “name”, “top_depth”, “bottom_depth”. Optional keys: “lithology”, “age”, “parent_formation”, “parent_zone”.

Parameters:
Return type:

FormationTops

classmethod from_dataframe(
df,
name_col='name',
top_col='top_depth',
bottom_col='bottom_depth',
lithology_col='lithology',
interval_kind=IntervalKind.FORMATION,
*,
terminal_depth=None,
rank=None,
**read_options,
)[source]

Read a table using the same validation as CSV and plotting.

Parameters:
Return type:

FormationTops

validate()[source]

Validate intervals: check for overlaps within same kind.

Returns:

Validation issues (empty if all OK)

Return type:

list of str

Raises:

ValueError – If overlapping intervals are found

find_overlaps()[source]

Find overlapping peers, allowing explicitly linked parent containment.

Returns:

Descriptions of overlapping pairs (empty if none)

Return type:

list of str

has_overlaps()[source]

Return True if any intervals of the same kind overlap.

Return type:

bool

get_by_name(name)[source]

Get first interval matching name (case-insensitive).

Parameters:

name (str)

Return type:

Interval | None

get_at_depth(depth)[source]

Return all intervals containing this depth.

Parameters:

depth (float)

Return type:

List[Interval]

get_in_range(top, bottom)[source]

Return intervals overlapping with [top, bottom] range.

Parameters:
Return type:

List[Interval]

filter_by_kind(kind)[source]

Return intervals of a specific kind.

Parameters:

kind (IntervalKind)

Return type:

List[Interval]

clip_to_well(well)[source]

Return a new FormationTops with intervals clipped to well depth range.

Intervals completely outside the well range are excluded. Partially overlapping intervals are clipped to well boundaries. Intervals whose metadata["depth_unit"] is the other length unit (“m” or “ft”) than well.depth_unit are converted to the well unit first.

Parameters:

well (Well) – Well object with depth array

Return type:

FormationTops

add(interval)[source]

Add an interval and re-sort.

Parameters:

interval (Interval)

remove(name)[source]

Remove first interval matching name. Returns True if removed.

Parameters:

name (str)

Return type:

bool

to_dataframe()[source]

Convert intervals to a pandas DataFrame.

to_csv(filepath)[source]

Export intervals to CSV (depths at full precision).

Parameters:

filepath (str | Path)

Return type:

None

property intervals: List[Interval]

Return list of intervals (copy).

property names: List[str]

Return list of interval names.