geost.accessor.GeostFrame.segmentize_by_gradient#
- GeostFrame.segmentize_by_gradient(column: str, threshold: float, use_mid_depth: bool = True) Series[source]#
Segmentize the data based on gradient changes in a column. A segment is made up of consecutive rows where the gradient of
columnis below a specifiedthresholdand a new segment begins when the threshold is exceeded. Each segment gets a unique number.- Parameters:
column (str) – Column to determine the segments from.
threshold (float) – Minimum gradient change to create a new segment.
use_mid_depth (bool, optional) – Use mid depth for gradient calculation. The default is True.
- Returns:
Series with segment numbers which can be added as a column to the DataFrame.
- Return type:
pd.Series
Examples
Suppose we have a DataFrame with a “resistance” in MPa for each layer. We want to create segments of consecutive rows where the resistance does not change more than 0.5 MPa per meters. First, we calculate the gradient of the “resistance” column so we can use this to inspect the result of
segmentize_by_gradient:>>> import geost >>> df = geost.pandas_dataframe( ... { ... "nr": ["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"], ... "surface": [0.2, 0.2, 0.2, 0.2, 0.2, 0.3, 0.3, 0.3, 0.3, 0.3], ... "top": [0.0, 0.8, 1.5, 2.5, 3.7, 0.0, 0.6, 1.2, 2.5, 3.1], ... "bottom": [0.8, 1.5, 2.5, 3.7, 4.2, 0.6, 1.2, 2.5, 3.1, 3.9], ... "resistance": [0.25, 0.95, 0.19, 0.18, 0.35, 0.23, 0.67, 0.12, 0.9, 0.86], ... } ... ) >>> df["gradient"] = df.gst.calculate_gradient("resistance") >>> df nr surface top bottom resistance gradient 0 A 0.2 0.0 0.8 0.25 0.000000 1 A 0.2 0.8 1.5 0.95 0.933333 2 A 0.2 1.5 2.5 0.19 -0.894118 3 A 0.2 2.5 3.7 0.18 -0.009091 4 A 0.2 3.7 4.2 0.35 0.200000 5 B 0.3 0.0 0.6 0.23 0.000000 6 B 0.3 0.6 1.2 0.67 0.733333 7 B 0.3 1.2 2.5 0.12 -0.578947 8 B 0.3 2.5 3.1 0.90 0.821053 9 B 0.3 3.1 3.9 0.86 -0.057143
We can create the segment column with the threshold 0.5 and add it as a column to the DataFrame:
>>> df["segment"] = df.gst.segmentize_by_gradient("resistance", 0.5) >>> df nr surface top bottom resistance gradient segment 0 A 0.2 0.0 0.8 0.25 0.000000 1 1 A 0.2 0.8 1.5 0.95 0.933333 2 2 A 0.2 1.5 2.5 0.19 -0.894118 3 3 A 0.2 2.5 3.7 0.18 -0.009091 3 4 A 0.2 3.7 4.2 0.35 0.200000 3 5 B 0.3 0.0 0.6 0.23 0.000000 4 6 B 0.3 0.6 1.2 0.67 0.733333 5 7 B 0.3 1.2 2.5 0.12 -0.578947 6 8 B 0.3 2.5 3.1 0.90 0.821053 7 9 B 0.3 3.1 3.9 0.86 -0.057143 7