Skip to content

Note

Click here to download the full example code

Layered surfaces

A phosphate deposit weathered in place: 251 vertical holes log five horizons from the top, soil (SOIL), aluminous laterite (ALU), oxidized ore (OXI), saprolite (SAP) and fresh rock (ROCK), under topography gridded at 10 m. Each horizon base becomes a surface, the surfaces stack into a layered block model, and vertical distances to them place any sample in its layer.

import sys
from pathlib import Path

HERE = Path(__file__).parent if "__file__" in globals() else Path.cwd()
sys.path.insert(0, str(HERE.parents[1]))
import boitata as bt
import matplotlib.pyplot as plt
import numpy as np
from common import ACCENT, GRAY, HIGHLIGHT, INK, LIGHT, map_axes, save

Topography as a surface

Gridded elevations are a 2D BlockModel with a Z column; grid_surface triangulates them through the block centers. Mesh.vertical_distance is a point's elevation minus the surface's at the same easting and northing: the collars sit on the topography.

data = bt.datasets.phosphate_weathering_profile()
topography = data["topography"]
ground = bt.grid_surface(topography, "Z")
collars = data["collars"]
xyz = np.column_stack([collars["X"], collars["Y"], collars["Z"]])
print(topography)
print(ground)
offset = ground.vertical_distance(xyz)
print(f"collar minus topography: {offset.min():+.2f} to {offset.max():+.2f} m")

fig, ax = plt.subplots(figsize=(7, 5), layout="constrained")
bt.plot.section(topography, "Z", ax=ax, cmap="Greys_r", colorbar=False)
ax.contour(
    topography.grid(topography.x)[0],
    topography.grid(topography.y)[0],
    topography.grid("Z")[0],
    levels=np.arange(1080, 1240, 20),
    colors=INK,
    linewidths=0.4,
)
ax.scatter(xyz[:, 0], xyz[:, 1], s=6, color=HIGHLIGHT, label="Collar")
map_axes(ax, "Topography, 20 m contours, and 251 collars")
ax.legend(loc="upper right")
save(fig, "topography")

Topography, 20 m contours, and 251 collars

Out:

BlockModel  regular, 46,031 blocks
  count   241 × 191 × 1
  size    10 × 10 × 1
  origin  59795, 22045, 0
  bounds  x 59795 to 62205, y 22045 to 23955, z 0 to 1
  column  type     unit  nulls     min    mean     max
  Z       float64            0  1082.8  1165.8  1260.4
Mesh  46,031 vertices, 91,200 triangles, open, 860 boundary edges
  area    4607472.8
  bounds  x 59800 to 62200, y 22050 to 23950, z 1082.8 to 1260.4
collar minus topography: -0.06 to +0.06 m

Horizon bases

Each horizon's base lies at its TO depth along the hole. The contact elevations follow the topography, so the page interpolates the depth below ground instead, by inverse distance on the 10 m grid, and subtracts it from the topography. Each hole logs all five horizons, so the four depths get the same weights in each cell: their order holds and the surfaces never cross.

LAYERS = ["SOIL", "ALU", "OXI", "SAP"]
holes = bt.Drillholes.from_tables(data, intervals=None)
horizons = data["horizons"]
ids, names, to = horizons["HOLE_ID"], horizons["HORIZON"], horizons["TO"]
idw = bt.InverseDistance(bt.Search(radius=400, max_samples=12, min_samples=3))
bases, elevations = {}, {}
for name in LAYERS:
    base = holes.at(list(ids[names == name]), to[names == name])
    depth = -ground.vertical_distance(base)
    elevations[name] = topography["Z"] - idw.fit(base[:, :2], depth).predict(topography)
    bases[name] = bt.grid_surface(topography.with_column("base", elevations[name]), "base")
    print(f"base of {name}: depth {np.median(depth):5.1f} m median, {bases[name]}")

Out:

base of SOIL: depth   3.1 m median, Mesh(42046 vertices, 83359 triangles, open, 731 boundary edges)
base of ALU: depth  23.6 m median, Mesh(42046 vertices, 83359 triangles, open, 731 boundary edges)
base of OXI: depth  50.7 m median, Mesh(42046 vertices, 83359 triangles, open, 731 boundary edges)
base of SAP: depth  73.7 m median, Mesh(42046 vertices, 83359 triangles, open, 731 boundary edges)

The surfaces leave out cells beyond 400 m of a hole. The thickness of a horizon is the vertical distance from its base, at each cell center, up to the surface above it; a cell with no base elevation gets NaN.

above = {"SOIL": ground, "ALU": bases["SOIL"], "OXI": bases["ALU"], "SAP": bases["OXI"]}
fig, axes = plt.subplots(2, 2, figsize=(9, 6), sharex=True, sharey=True, layout="constrained")
for ax, name in zip(axes.flat, LAYERS, strict=True):
    points = np.column_stack([topography.coords[:, :2], elevations[name]])
    thickness = -above[name].vertical_distance(points)
    print(f"{name:>4}: thickness {np.nanmin(thickness):5.1f} to {np.nanmax(thickness):5.1f} m")
    bt.plot.section(topography, thickness, ax=ax, colorbar=False)
    fig.colorbar(ax.collections[0], ax=ax, shrink=0.8, label="m")
    map_axes(ax, f"{name} thickness")
for ax in axes.flat[1::2]:
    ax.set_ylabel("")
save(fig, "thickness")

SOIL thickness, ALU thickness, OXI thickness, SAP thickness

Out:

SOIL: thickness   2.2 to   5.7 m
 ALU: thickness   5.4 to  36.1 m
 OXI: thickness  10.8 to  44.8 m
 SAP: thickness  10.6 to  32.0 m

Samples by layer

A sample belongs to the first layer, from the top, whose base lies below it. At the assay midpoints, the layers from the surfaces match the logged horizons and show where the phosphate is: the oxidized horizon.

assays = bt.Drillholes.from_tables(data).samples()
logged = bt.Drillholes.from_tables(data, intervals="horizons").samples()


def layer(points):
    label = np.full(len(points), "ROCK", dtype=object)
    for name in reversed(LAYERS):
        label[bases[name].vertical_distance(points) > 0] = name
    return label


print(f"horizon midpoints in their logged layer: {np.mean(layer(logged.coords) == logged['HORIZON']):.1%}")
by_layer = layer(assays.coords)
p2o5 = assays["P2O5_PCT"]
for name in [*LAYERS, "ROCK"]:
    print(f"{name:>4}: {np.sum(by_layer == name):5} assays, P2O5 {np.nanmean(p2o5[by_layer == name]):5.2f} %")

height = bases["OXI"].vertical_distance(assays.coords)
fig, ax = plt.subplots(figsize=(5, 5), layout="constrained")
ax.scatter(p2o5, height, s=3, color=GRAY, linewidths=0)
ax.axhline(0, color=HIGHLIGHT, lw=1)
ax.text(ax.get_xlim()[1], 0, "Base of OXI", color=HIGHLIGHT, ha="right", va="bottom")
ax.set(xlabel="P2O5 (%)", ylabel="Height above the base of OXI (m)", title="Phosphate against height")
save(fig, "profile")

Phosphate against height

Out:

horizon midpoints in their logged layer: 100.0%
SOIL:   259 assays, P2O5  1.95 %
 ALU:  1152 assays, P2O5  4.74 %
 OXI:  1533 assays, P2O5 12.52 %
 SAP:  1241 assays, P2O5  8.48 %
ROCK:  1407 assays, P2O5  5.03 %

A layered block model

BlockModel.from_meshes labels sub-cells with the first (mesh, rule, label) domain that holds their center. Listed from the bottom, each horizon lies "below" its base's upper neighbor: fresh rock below the base of SAP, saprolite below the base of OXI, and so on up to soil below the ground; air falls in no domain and drops out. Listed from the top with "above", each horizon lies above its own base, with fresh rock as the fill; the air, above the ground, comes first. Over the drilled area and down to 950 m, on 25 m blocks split into 1 m sub-cells in elevation, both give the same volumes.

grid = ((60000, 22250, 950), (25, 25, 10), (80, 60, 30))
stack = [ground, *(bases[n] for n in LAYERS)]
from_bottom_up = [(mesh, "below", label) for mesh, label in zip(stack[::-1], ["ROCK", *LAYERS[::-1]])]
from_top_down = [(ground, "above", "AIR"), *((bases[n], "above", n) for n in LAYERS)]
from_bottom = bt.BlockModel.from_meshes(*grid, from_bottom_up, subgrid=(1, 1, 10))
from_top = bt.BlockModel.from_meshes(*grid, from_top_down, subgrid=(1, 1, 10), fill="ROCK")
print(from_bottom)
for name in [*LAYERS, "ROCK"]:
    bottom = from_bottom.volumes[from_bottom["domain"] == name].sum()
    top = from_top.volumes[from_top["domain"] == name].sum()
    print(f"{name:>4}: {bottom / 1e6:7.2f} Mm3 from the bottom, {top / 1e6:7.2f} Mm3 from the top")

Out:

BlockModel  sub-blocked, 254,039 sub-blocks in 144,000 blocks
  count   80 × 60 × 30
  size    25 × 25 × 10
  origin  60000, 22250, 950
  bounds  x 60000 to 62000, y 22250 to 23750, z 950 to 1239
  column  type  unit  nulls  values
  domain  str             0  5 unique: ROCK, SAP, OXI, …
SOIL:    9.62 Mm3 from the bottom,    9.69 Mm3 from the top
 ALU:   63.02 Mm3 from the bottom,   63.02 Mm3 from the top
 OXI:   86.59 Mm3 from the bottom,   86.59 Mm3 from the top
 SAP:   68.25 Mm3 from the bottom,   68.25 Mm3 from the top
ROCK:  420.56 Mm3 from the bottom,  420.56 Mm3 from the top

A true-scale east-west section shows the sub-cells following the surfaces:

scheme = bt.Categories([*LAYERS, "ROCK"], colors=["#e0c080", LIGHT, HIGHLIGHT, "#9ebad6", ACCENT])
codes = scheme.encode(from_bottom["domain"])
north = 23000.0
plane = ((0, north, 0), 90, 90)
fig, ax = plt.subplots(figsize=(10, 3.4), layout="constrained")
bt.plot.section(from_bottom, codes, plane=plane, resolution=1.0, scheme=scheme, ax=ax, colorbar=False)
bt.plot.slab(np.empty((0, 3)), plane=plane, thickness=10, meshes=[ground, *bases.values()], color=INK, ax=ax)
ax.set(xlim=(60600, 61400), ylim=(1020, 1200), title=f"Layers at northing {north:.0f} m, true scale")
ax.set_aspect("equal")
bt.plot.category_legend(scheme, ax, loc="upper left", bbox_to_anchor=(1, 1))
save(fig, "section")

Layers at northing 23000 m, true scale

Total running time of the script: ( 0 minutes 14.124 seconds)

Download Python source code: example_08_11.py

Download Jupyter notebook: example_08_11.ipynb

Gallery generated by mkdocs-gallery