Skip to content

Note

Click here to download the full example code

Checking drill holes

The stacked sulfide lenses as logged: collar, survey (dip positive down, azimuth clockwise from north), assay and lithology tables, with typical data-entry errors planted in them and listed in the docstring of its raw option. You check the tables, repair them and check them again before desurveying anything.

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, save

check_drillholes flags each record of the collar, survey and interval tables: duplicate ids, missing or sentinel values, text in numeric columns, from ≥ to, gaps, overlaps, angles out of range, depths past the collar LENGTH, ids that match a collar only once trimmed and case-folded, holes missing from a table, abrupt survey deviation and holes dipping against the rest. The report lists each flagged check with the holes it hit.

data = bt.datasets.stacked_sulphide_lenses(raw=True)
raw = {
    "collar": data["collars"],
    "survey": data["surveys"],
    "assays": data["assays"],
    "lithology": data["lithology"],
}
for name, table in raw.items():
    print(f"{name:>9}: {table.num_rows:6} rows")


def check(t, show=True):
    flags, summary, details = bt.check_drillholes(
        t["collar"], t["survey"], {"assays": t["assays"], "lithology": t["lithology"]}, max_depth="LENGTH"
    )
    for table, name, rows, holes in zip(
        summary["table"], summary["check"], summary["rows"], summary["holes"]
    ):
        if rows and show:
            ids = t[table]["HOLE_ID"]
            hit = sorted(set(ids[flags[table][name]]))
            listed = ", ".join(repr(h) for h in hit) if len(hit) <= 8 else f"{hit[0]!r} ... {hit[-1]!r}"
            print(f"{table:>9} {name:<12} {rows:4.0f} rows in {holes:3.0f} holes: {listed}")
    return flags, details


flags, details = check(raw)

Out:

   collar:    290 rows
   survey:   4469 rows
   assays:  19151 rows
lithology:   2239 rows
   collar duplicate       2 rows in   2 holes: 'DD0032', 'DD0224'
   collar no_survey       1 rows in   1 holes: 'DD0207'
   collar no_assays      85 rows in  85 holes: 'DD0001' ... 'DD0244'
   survey deviation       2 rows in   1 holes: 'DD0017'
   survey dip_sign       10 rows in   1 holes: 'DD0058'
   survey past_depth      2 rows in   1 holes: 'DD0102'
   survey id_mismatch    14 rows in   1 holes: 'DD0053'
   survey no_collar      17 rows in   1 holes: 'DD0104'
   assays inverted        1 rows in   1 holes: 'DD0123'
   assays gap            13 rows in  11 holes: 'DD0054' ... 'RC0045'
   assays overlap         5 rows in   2 holes: 'DD0109', 'DD0216'
   assays past_depth      4 rows in   1 holes: 'DD0102'
   assays sentinel        5 rows in   1 holes: 'DD0018'
   assays text_values     3 rows in   1 holes: 'DD0231'
   assays id_mismatch    83 rows in   2 holes: 'DD0053', 'dd0145'
   assays no_collar      95 rows in   1 holes: 'DD0104'
lithology gap             1 rows in   1 holes: 'DD0196'
lithology past_depth      1 rows in   1 holes: 'DD0102'
lithology id_mismatch    10 rows in   2 holes: 'DD0053', 'DD0196 '
lithology no_collar       9 rows in   1 holes: 'DD0104'

Each flag points at a planted error, or follows from one:

  • duplicate collars: DD0032 entered twice with different coordinates, DD0224 the same row twice.
  • id_mismatch: 'dd0145' in the assays and 'DD0196 ' in the lithology are ids in the wrong case or with a trailing space. The collar 'DD0053 ' has the trailing space, so its survey, assays and lithology miss it.
  • no_collar: DD0104 has surveys, assays and lithology but no collar.
  • no_survey: DD0207 has no survey.
  • deviation: two stations of DD0017, where the azimuth flips at one station and back at the next.
  • dip_sign: DD0058 has its dips entered negative, pointing up, while the other holes dip down.
  • past_depth: DD0102 has surveys, assays and lithology below its collar LENGTH.
  • inverted: an assay of DD0123 with FROM > TO.
  • overlap: two assays of DD0109 start before the previous one ends, and three of DD0216 are entered twice.
  • gap: two missing samples in DD0054. The rows above leave the gaps in DD0145, DD0123, DD0196 and DD0109. The gaps in the RC holes are unsampled core and real.
  • text_values and sentinel: the reader took the grades as text, because some cells are not numbers. DD0018 holds -99 and -999.
  • no_assays: 85 collars. Only mineralized zones are assayed, so a hole that never logs MS, SMS or STR has no assays by design. One more hides among them.

The details name the value behind each id, dip and text flag, and what it should become:

groups = {}
for table, check_, hole, column, value, suggestion in zip(
    *(details[c] for c in ("table", "check", "hole", "column", "value", "suggestion"))
):
    groups.setdefault((table, check_, hole, column), set()).add(
        f"{value!r} -> {suggestion!r}" if suggestion else repr(value)
    )
for (table, check_, hole, column), values in groups.items():
    values = sorted(values)
    listed = ", ".join(values) if len(values) <= 2 else f"{values[0]} ... {values[-1]} ({len(values)} values)"
    print(f"{table:>9} {check_:<12} {hole!r:9} {column:<7} {listed}")

Out:

   survey dip_sign     'DD0058'  DIP     '-54.32' -> '54.32' ... '-56.73' -> '56.73' (10 values)
   assays text_values  'DD0231'  AU_GPT  '<0.01', 'NS'
   assays text_values  'DD0231'  ZN_PCT  'NS'
   assays text_values  'DD0231'  PB_PCT  'NS'
   assays text_values  'DD0231'  CU_PCT  '<0.01', 'NS'
   assays text_values  'DD0231'  AG_GPT  'NS'
   survey id_mismatch  'DD0053'  HOLE_ID 'DD0053' -> 'DD0053 '
   assays id_mismatch  'DD0053'  HOLE_ID 'DD0053' -> 'DD0053 '
   assays id_mismatch  'dd0145'  HOLE_ID 'dd0145' -> 'DD0145'
lithology id_mismatch  'DD0053'  HOLE_ID 'DD0053' -> 'DD0053 '
lithology id_mismatch  'DD0196 ' HOLE_ID 'DD0196 ' -> 'DD0196'

A hole missing its assays looks like one of the unassayed holes, unless its lithology says it is mineralized:

lith = raw["lithology"]
mineralized = set(lith["HOLE_ID"][np.isin(lith["LITH"], ["MS", "SMS", "STR"])])
print("mineralized, no assays:", sorted(mineralized - set(raw["assays"]["HOLE_ID"])))

Out:

mineralized, no assays: ['DD0076']

Two repairs need a person. You swap the ends of the inverted interval and take DD0102's LENGTH from its deepest survey station, since the survey, assays and lithology agree the hole is longer. After a second check, fix_drillholes resolves the rest with one named rule per check. Two rules are asked for by name: dip_sign="negate" turns DD0058 down, and text_values="half" reads <0.01 as half the detection limit (by default it becomes null, as NS does). The log says what each rule changed: ids are renamed to their collar, the later duplicate collar goes (for DD0032, the second, wrong entry), overlapping assays keep the one that starts first (dropping the twinned re-entries), the two DD0017 stations turned by the flip go, sentinels become null, and the rows of a hole without collar go.

def replace(table, **columns):
    return bt.Table({**{c: table[c] for c in table.column_names}, **columns})


tables = dict(raw)
a, s, c = raw["assays"], raw["survey"], raw["collar"]
swap = a["FROM"] > a["TO"]
tables["assays"] = replace(a, FROM=np.where(swap, a["TO"], a["FROM"]), TO=np.where(swap, a["FROM"], a["TO"]))
deepest = {}
for h, d in zip(s["HOLE_ID"], s["DEPTH"]):
    deepest[h] = max(deepest.get(h, 0.0), d)
tables["collar"] = replace(c, LENGTH=np.maximum(c["LENGTH"], [deepest.get(h, 0.0) for h in c["HOLE_ID"]]))

flags, _ = check(tables, show=False)
fixed, log = bt.fix_drillholes(flags, tables, dip_sign="negate", text_values="half")
for table, name, action, rows in zip(log["table"], log["check"], log["action"], log["rows"]):
    if rows:
        print(f"{action:>10} {rows:3.0f} {table} rows flagged {name}")
print()
flags, _ = check(fixed)

Out:

      drop   2 collar rows flagged duplicate
      drop   2 survey rows flagged deviation
      drop  17 survey rows flagged no_collar
    negate  10 survey rows flagged dip_sign
    rename  14 survey rows flagged id_mismatch
keep_first   5 assays rows flagged overlap
      half   3 assays rows flagged text_values
      null   5 assays rows flagged sentinel
      drop  95 assays rows flagged no_collar
    rename  83 assays rows flagged id_mismatch
      drop   9 lithology rows flagged no_collar
    rename  10 lithology rows flagged id_mismatch

   collar no_survey       1 rows in   1 holes: 'DD0207'
   collar no_assays      85 rows in  85 holes: 'DD0001' ... 'DD0244'
   assays gap            11 rows in   9 holes: 'DD0054' ... 'RC0045'

The rest needs the field records, since no rule can fix it. DD0207 has no survey and would be desurveyed as vertical, DD0076 needs its assays found, and the gaps are the two lost DD0054 samples, the two DD0109 intervals dropped as overlaps and the unsampled RC core. 'DD0053 ' keeps its trailing space, now in every table. DD0058 shows why the dips matter: desurveyed as entered, it climbs out of the ground.

def dd0058(table):
    return table.filter(table["HOLE_ID"] == "DD0058")


collar = dd0058(fixed["collar"])
fig, ax = plt.subplots(figsize=(4, 5.5), layout="constrained")
for name, survey, color in (("As entered", raw["survey"], HIGHLIGHT), ("Fixed", fixed["survey"], ACCENT)):
    path = bt.Drillholes(collar, dd0058(survey)).paths()
    ax.plot(path["x"], path["z"], color=color, lw=1.6, label=name)
ax.axhline(collar["Z"][0], color=GRAY, lw=0.6, ls="--", label="Collar elevation")
ax.set_aspect("equal")
ax.set(title="DD0058, east-west section", xlabel="Easting (m)", ylabel="Elevation (m)")
ax.legend()
save(fig, "dip")

DD0058, east-west section

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

Download Python source code: example_02_01.py

Download Jupyter notebook: example_02_01.ipynb

Gallery generated by mkdocs-gallery