geost.accessor.GeostFrame.compute_discretized_fractions#
- GeostFrame.compute_discretized_fractions(column: str, discretization: float | int | list | ndarray | DataFrame, bins: int | float | list | ndarray = None, bin_centers_as_columns: bool = False, relative_to_reference: bool = False) DataFrame[source]#
Calculate the fraction of each categorical value in the specified column within a given depth discretization. For discretizing continuous values, use the bins parameter to define the ranges.
- Parameters:
column (str) – Name of the column containing the values to fractionate per discretized layer.
discretization (float | int | list | np.ndarray | pd.DataFrame) – Definition of discretization layers. When a scalar is provided, it defines a uniform layer thickness. When a sequence is provided, it defines the specific layer boundaries. When a DataFrame is provided, a custom discretization per survey must be provided. Note that in the case of a DataFrame, the result only contains surveys which had corresponding discretization defined.
bins (int | float | list | np.ndarray, optional) – Bin definition. A scalar creates two bins (larger than the scalar and smaller than or equal to the scalar), while a sequence defines internal bin edges and adds open-ended bins at both ends (unless bin_centers_as_columns is True).
bin_centers_as_columns (bool, optional) – If True, use bin centers as output column labels rather than ranges. Will not add open-ended bins at both ends, by default False. Note, if bins is given as a single number or not given, this parameter will be ignored.
relative_to_reference (bool, optional) – If True, interpret depths relative to the reference surface, by default False.
- Returns:
The discretization data with one column per bin containing the fraction of each layer in that bin.
- Return type:
pd.DataFrame
Examples
Calculate lithology fractions in uniform 1-meter layers:
>>> import geost >>> import pandas as pd >>> boreholes = pd.DataFrame( ... { ... "nr": ["A", "A", "B", "B"], ... "surface": [0.2, 0.2, 0.3, 0.3], ... "top": [0.0, 1.0, 0.0, 1.0], ... "bottom": [1.0, 2.0, 1.0, 2.0], ... "lith": ["K", "Z", "K", "V"], ... } ... ) >>> boreholes.gst.compute_discretized_fractions("lith", 1) nr surface top bottom dz K V Z total 0 A 0.2 0.0 1.0 1.0 1.0 NaN NaN 1.0 1 A 0.2 1.0 2.0 1.0 NaN NaN 1.0 1.0 2 B 0.3 0.0 1.0 1.0 1.0 NaN NaN 1.0 3 B 0.3 1.0 2.0 1.0 NaN 1.0 NaN 1.0
Supply explicit layer boundaries instead of a uniform thickness:
>>> discretization = [0.5, 1.0, 2.0] >>> boreholes.gst.compute_discretized_fractions("lith", discretization) nr surface top bottom dz K V Z total 0 A 0.2 0.0 0.5 0.5 1.0 NaN NaN 1.0 1 A 0.2 0.5 1.0 0.5 1.0 NaN NaN 1.0 2 A 0.2 1.0 2.0 1.0 NaN NaN 1.0 1.0 3 B 0.3 0.0 0.5 0.5 1.0 NaN NaN 1.0 4 B 0.3 0.5 1.0 0.5 1.0 NaN NaN 1.0 5 B 0.3 1.0 2.0 1.0 NaN 1.0 NaN 1.0
For continuous values, use bins to calculate fractions per value range:
>>> boreholes["value"] = [0.2, 0.8, 0.4, 0.9] >>> boreholes.gst.compute_discretized_fractions( ... "value", discretization, bins=[0.33, 0.67] ... ) nr surface top bottom dz <=0.33 0.33-0.67 >0.67 total 0 A 0.2 0.0 0.5 0.5 1.0 NaN NaN 1.0 1 A 0.2 0.5 1.0 0.5 1.0 NaN NaN 1.0 2 A 0.2 1.0 2.0 1.0 NaN NaN 1.0 1.0 3 B 0.3 0.0 0.5 0.5 NaN 1.0 NaN 1.0 4 B 0.3 0.5 1.0 0.5 NaN 1.0 NaN 1.0 5 B 0.3 1.0 2.0 1.0 NaN NaN 1.0 1.0
Interpret discretization boundaries relative to the reference surface with relative_to_reference=True:
>>> boreholes.gst.compute_discretized_fractions( ... "lith", [1, 0, -1], relative_to_reference=True ... ) nr surface top bottom dz K V Z total 0 A 0.2 1 0 1 0.2 NaN NaN 0.2 1 A 0.2 0 -1 1 0.8 NaN 0.2 1.0 2 B 0.3 1 0 1 0.3 NaN NaN 0.3 3 B 0.3 0 -1 1 0.7 0.3 NaN 1.0
You can also provide a pandas.DataFrame for survey-specific discretization boundaries. If the discretization contains surface information which differs from the surface levels of the surveys, the layer boundaries of the discretization will be adjusted accordingly and the result contains a surface_correction column. Without surface information in the discretization, the layer boundaries will be applied as-is.
>>> discretization_df = pd.DataFrame( ... { ... "nr": ["A", "A", "A", "B", "B", "B", "B"], ... "surface": [0.4, 0.4, 0.4, 0.2, 0.2, 0.2, 0.2], ... "top": [0, 0.5, 1.0, 0, 0.5, 1.0, 2.0], ... "bottom": [0.5, 1.0, 2.0, 0.5, 1.0, 2.0, 4.0], ... } ... ) >>> result = boreholes.gst.compute_discretized_fractions( ... "lith", discretization_df ... ) >>> result nr surface top bottom surface_correction dz K V Z total 0 A 0.2 0.0 0.3 -0.2 0.3 1.0 NaN NaN 1.0 1 A 0.2 0.3 0.8 -0.2 0.5 1.0 NaN NaN 1.0 2 A 0.2 0.8 1.8 -0.2 1.0 0.2 NaN 0.8 1.0 3 B 0.3 0.0 0.6 0.1 0.6 1.0 NaN NaN 1.0 4 B 0.3 0.6 1.1 0.1 0.5 0.8 0.2 NaN 1.0 5 B 0.3 1.1 2.1 0.1 1.0 NaN 0.9 NaN 0.9