geost.base.Collection.aggregate_consecutive_layers#

Collection.aggregate_consecutive_layers(over: str | list[str], agg_funcs: dict = None, keep_original_index: bool = False, inplace: bool = False) → DataFrame[source]#

Aggregate consecutive layers in the data table of a Collection that have the same value in a specified column. The column to use for aggregating layers is typically categorical data, such as lithology or soil type. Any other columns can be aggregated using the provided aggregation functions.

Parameters:
  • over (str | list[str]) – Name or names of the column or columns to check for consecutive identical values. Typically columns holding categorical data.

  • agg_funcs (dict, optional) – Dictionary specifying the aggregation functions to apply to other columns when combining layers. Keys are column names, and values are aggregation functions. These can be e.g. names such as’first’, ‘last’, ‘mean’, etc. or actual functions such as np.sum, np.mean, etc.

  • keep_original_index (bool, optional) – If True, the original index of the data DataFrame is preserved in the resulting DataFrame. If False, the index is reset (recommended). The default is False.

  • inplace (bool, optional) – If True, the combination is applied in place and the original Collection is modified. If False, a new DataFrame with combined layers is returned. The default is False.

Returns:

New DataFrame with consecutive layers combined based on the specified column.

Return type:

pd.DataFrame

Raises:

KeyError – If the specified column does not exist in the DataFrame.

Notes

When you perform this function on discrete data such as CPT’s, the result of the aggregation is layered data defined by top and bottom depths.

Examples

Say we have CPT data which and lithology (column ‘lith’) for each row. We want to aggregate consecutive layers with identical lithology and aggregate the ‘qc’ and ‘fs’ columns by taking the mean:

>>> result = collection.aggregate_consecutive_layers(
...     'lith', {'qc': 'mean', 'fs': 'mean'}
... )