Note
Click here to download the full example code
Audit drill holes before modeling¶
A project hands you its drill hole database: collars, downhole surveys, assays and lithology, exported from the
logging software. Every later step (desurveying, compositing, variograms, estimation) trusts these tables. One
wrong dip moves a hole under the wrong lens; one -999 read as a grade drags an ore intercept to zero. You audit
the tables, decide for each problem whether to fix it, drop it or ask the geologist, and check again until no
unexplained flag is left.
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, save
What you'll learn
- The classes of error a drill hole database carries, and which table each one lives in.
- How to sort each flag into fix by rule, fix by hand from evidence, drop, or query the geologist.
- How to prove the audit is finished: a second check where every remaining flag is explained.
Prerequisites: what collar, survey and interval tables hold. Checking drill holes lists every check used here; this page covers the decisions.
The data¶
The stacked sulfide lenses are three dipping polymetallic lenses cut by diamond (DD) and reverse circulation
(RC) holes. raw=True returns the tables as logged, with typical data-entry errors in them.
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, columns {', '.join(table.column_names)}")
Out:
collar: 290 rows, columns HOLE_ID, X, Y, Z, LENGTH, TYPE
survey: 4469 rows, columns HOLE_ID, DEPTH, DIP, AZIMUTH
assays: 19151 rows, columns HOLE_ID, FROM, TO, ZN_PCT, PB_PCT, CU_PCT, AG_GPT, AU_GPT, DENSITY
lithology: 2239 rows, columns HOLE_ID, FROM, TO, LITH
Interval tables (assays, lithology) describe a hole as a stack of FROM-TO pieces measured along the hole from
the collar. Most of their errors break that stack:
Step 1: Run every check at once
check_drillholes takes the collar, the survey and a dict of interval tables and returns three tables:
flags (one boolean column per check, one row per record), a summary (rows and holes hit per check) and
details (the value behind each flag and its suggested replacement). max_depth="LENGTH" names the collar
column holding the hole length.
def check(t):
return bt.check_drillholes(
t["collar"], t["survey"], {"assays": t["assays"], "lithology": t["lithology"]}, max_depth="LENGTH"
)
def hit(flags, t, table, name):
return sorted(set(t[table]["HOLE_ID"][flags[table][name]]))
flags, summary, details = check(raw)
before = {}
print(f"{'table':>9} {'check':<12} {'rows':>5} {'holes':>5} examples")
for table, name, rows in zip(summary["table"], summary["check"], summary["rows"]):
if rows:
holes = hit(flags, raw, table, name)
before[table, name] = int(rows)
listed = ", ".join(repr(h) for h in holes[:4]) + (" ..." if len(holes) > 4 else "")
print(f"{table:>9} {name:<12} {rows:5.0f} {len(holes):5} {listed}")
Out:
table check rows holes examples
collar duplicate 2 2 'DD0032', 'DD0224'
collar no_survey 1 1 'DD0207'
collar no_assays 85 85 'DD0001', 'DD0002', 'DD0003', 'DD0004' ...
survey deviation 2 1 'DD0017'
survey dip_sign 10 1 'DD0058'
survey past_depth 2 1 'DD0102'
survey id_mismatch 14 1 'DD0053'
survey no_collar 17 1 'DD0104'
assays inverted 1 1 'DD0123'
assays gap 13 11 'DD0054', 'DD0109', 'DD0123', 'DD0145' ...
assays overlap 5 2 'DD0109', 'DD0216'
assays past_depth 4 1 'DD0102'
assays sentinel 5 1 'DD0018'
assays text_values 3 1 'DD0231'
assays id_mismatch 83 2 'DD0053', 'dd0145'
assays no_collar 95 1 'DD0104'
lithology gap 1 1 'DD0196'
lithology past_depth 1 1 'DD0102'
lithology id_mismatch 10 2 'DD0053', 'DD0196 '
lithology no_collar 9 1 'DD0104'
Twenty checks fire. The raw count means little: 78 of the 83 id_mismatch assay rows come from one trailing
space, while the two deviation rows are one flipped azimuth that bends DD0017 between its stations at 150 and
210 m. Each flag needs a decision.
Step 2: Look at the evidence behind the ambiguous flags
Four flags have no obvious answer. DD0032 has two collars with different coordinates; DD0102 has
samples below its recorded length; one DD0123 assay is inverted; DD0017 has a survey station whose
azimuth jumps. The other tables of each hole say which entry to trust.
c, s, a, lith = raw["collar"], raw["survey"], raw["assays"], raw["lithology"]
def rows_of(table, hole):
return table["HOLE_ID"] == hole
def deepest(hole):
return {
"survey": s["DEPTH"][rows_of(s, hole)].max(),
"assays": a["TO"][rows_of(a, hole)].max(),
"lithology": lith["TO"][rows_of(lith, hole)].max(),
}
for hole in ("DD0032", "DD0102"):
lengths = c["LENGTH"][rows_of(c, hole)]
ends = ", ".join(f"{k} {v:.2f}" for k, v in deepest(hole).items())
print(f"{hole}: collar LENGTH {', '.join(f'{v:.2f}' for v in lengths)} m; deepest {ends} m")
xy = np.c_[c["X"], c["Y"]][rows_of(c, "DD0032")]
print(f"DD0032 collar entries are {np.hypot(*(xy[1] - xy[0])):.0f} m apart")
inverted = a["FROM"] > a["TO"]
print(f"DD0123 inverted assay: FROM {a['FROM'][inverted][0]} TO {a['TO'][inverted][0]}")
dd0017 = rows_of(s, "DD0017")
print("DD0017 azimuths at 150, 180, 210 m:", s["AZIMUTH"][dd0017][5:8])
top = np.abs(s["DIP"][s["DEPTH"] == 0])
print(f"dip at the collar, all surveyed holes: {top.min():.0f} to {top.max():.0f} degrees")
Out:
DD0032: collar LENGTH 398.05, 284.05 m; deepest survey 398.05, assays 330.00, lithology 398.05 m
DD0102: collar LENGTH 324.18 m; deepest survey 330.51, assays 330.51, lithology 330.51 m
DD0032 collar entries are 225 m apart
DD0123 inverted assay: FROM 436.81 TO 435.25
DD0017 azimuths at 150, 180, 210 m: [299.69 119.66 299.92]
dip at the collar, all surveyed holes: 44 to 87 degrees
The evidence settles each one:
DD0032: its survey, assays and lithology all end at 398.05 m, the length of the first collar entry. The second entry (284.05 m, 225 m away) is wrong; theduplicaterule drops the later entry, which is the right one to drop here.DD0102: three tables agree the hole reaches 330.51 m, past the 324.18 m on the collar. The collar length is the typo; set it to the deepest survey station.DD0123: FROM 436.81, TO 435.25 is a 1.6 m sample with its ends swapped; swap them back.DD0017: 299.69° → 119.66° → 299.92° is a flip of 180° and back, a transcription error. Thedeviationrule drops the two stations the flip touches, and the stations on either side carry the hole.
Pitfall: sentinels read as grades
-999 and -99 mean "no value", but in a numeric column they average like any grade. DD0018 has a
-999 for zinc in the middle of its ore intercept:
dd0018 = rows_of(a, "DD0018") & (a["FROM"] >= 254.92) & (a["TO"] <= 259.42)
zn = np.asarray(a["ZN_PCT"][dd0018], dtype=float)
length = (a["TO"] - a["FROM"])[dd0018]
valid = zn > -99
print(f"DD0018, 254.92-259.42 m, {dd0018.sum()} assays: Zn values {zn}")
print(f" length-weighted Zn with -999 as a number: {np.average(zn, weights=length):.1f} %")
print(f" length-weighted Zn without it: {np.average(zn[valid], weights=length[valid]):.2f} %")
Out:
DD0018, 254.92-259.42 m, 4 assays: Zn values [ 4.347 6.979 -999. 3.037]
length-weighted Zn with -999 as a number: -273.9 %
length-weighted Zn without it: 4.96 %
One sentinel turns a 4.96 % zinc intercept into −273.9 %. A negative grade is easy to spot; a -99 in a column of
values near 100 is not. The readers in boitatá map sentinels to null by default (nodata=); this page reads the raw
tables with nodata=[] to keep the problem visible.
Step 3: Fix by hand what needs evidence
The manual fixes come first, so the rules in step 4 see corrected tables. Each hand fix is one line of code,
so the next person can rerun and review the audit. Trailing spaces are stripped from all
ids here: the collar 'DD0053 ' is the odd one, and a rename rule would copy its space into three tables.
DD0207 is dropped: without a survey it would be desurveyed as vertical, while every surveyed hole on the
project starts at a dip of 44 to 87°.
def replace(table, **columns):
return bt.Table({**{k: table[k] for k in table.column_names}, **columns})
def strip_ids(table):
return replace(table, HOLE_ID=[h.strip() for h in table["HOLE_ID"]])
tables = {name: strip_ids(t) for name, t in raw.items()}
a = tables["assays"]
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"]))
c, s = tables["collar"], tables["survey"]
dd0102 = rows_of(c, "DD0102")
tables["collar"] = replace(c, LENGTH=np.where(dd0102, s["DEPTH"][rows_of(s, "DD0102")].max(), c["LENGTH"]))
tables = {name: t.filter(~rows_of(t, "DD0207")) for name, t in tables.items()}
Step 4: Apply the rules
fix_drillholes takes the flags of the corrected tables and applies one named rule per check. The defaults
drop duplicates, flipped survey stations and rows of holes without a collar, rename ids to their collar
('dd0145' → 'DD0145'), keep the first of two overlapping intervals and set sentinels to null. Two rules are
chosen here: dip_sign="negate" turns DD0058's negative dips down like every other hole, and
text_values="half" reads <0.01 as half the detection limit (NS, not sampled, becomes null). The log
says what each rule did.
flags, _, _ = check(tables)
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:4.0f} {table} rows flagged {name}")
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
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 5 assays rows flagged id_mismatch
drop 9 lithology rows flagged no_collar
Check before you move on
Run the same checks on the fixed tables. What remains must be on a list you can defend, hole by hole; the assertion fails if anything else is flagged.
flags, summary, _ = check(fixed)
after = {(t, n): int(r) for t, n, r in zip(summary["table"], summary["check"], summary["rows"]) if r}
rc_core = {"RC0009", "RC0011", "RC0012", "RC0028", "RC0034", "RC0038", "RC0045"}
accepted = {
("assays", "gap"): rc_core | {"DD0109", "DD0054"},
("collar", "no_assays"): None,
}
for key, rows in after.items():
holes = hit(flags, fixed, *key)
print(
f"{key[0]:>9} {key[1]:<10} {rows:4} rows: {', '.join(holes) if len(holes) <= 8 else f'{len(holes)} holes'}"
)
assert key in accepted, key
assert accepted[key] is None or set(holes) <= accepted[key], (key, holes)
lith = fixed["lithology"]
mineralized = set(lith["HOLE_ID"][np.isin(lith["LITH"], ["MS", "SMS", "STR"])])
unassayed = mineralized & set(hit(flags, fixed, "collar", "no_assays"))
print("no assays but logged mineralized:", sorted(unassayed))
Out:
collar no_assays 85 rows: 85 holes
assays gap 11 rows: 9 holes
no assays but logged mineralized: ['DD0076']
Two checks still fire, and every hole they name is explained. The RC gaps are core that was never
sampled. The DD0054 gaps are two lost samples, and the DD0109 gaps are the two intervals the overlap rule dropped. Of the 85 holes without assays, 84
never log a mineralized unit (MS, SMS, STR) and were not sent to the lab; DD0076 logs ore and has no
assays.
The audit changed the tables as follows:
names = {"collar": "collars", "survey": "surveys", "assays": "assays", "lithology": "lithology"}
print(f"{'table':>9} {'rows before':>12} {'rows after':>11} {'flagged before':>15} {'flagged after':>14}")
for name in names:
flagged_before = sum(v for (t, _), v in before.items() if t == name)
flagged_after = sum(v for (t, _), v in after.items() if t == name)
print(
f"{name:>9} {raw[name].num_rows:12} {fixed[name].num_rows:11} {flagged_before:15} {flagged_after:14}"
)
checks = sorted(before, key=lambda k: before[k])
fig, ax = plt.subplots(figsize=(7, 6), layout="constrained")
y = np.arange(len(checks))
ax.barh(y + 0.2, [before[k] for k in checks], height=0.4, color=GRAY, label="Raw tables")
ax.barh(y - 0.2, [after.get(k, 0) for k in checks], height=0.4, color=ACCENT, label="After the audit")
ax.set_yticks(y, [f"{t}: {n}" for t, n in checks])
ax.set_xscale("symlog", linthresh=1)
ax.set(xlabel="Flagged rows", title="Flags before and after the audit")
ax.legend(loc="lower right")
save(fig, "flags")

Out:
table rows before rows after flagged before flagged after
collar 290 287 88 85
survey 4469 4450 45 0
assays 19151 18973 209 11
lithology 2239 2221 21 0
The decision¶
The fixed tables go on to desurveying and compositing. Five questions go to the geologist; until they are answered, the affected data stay as the table says:
| Hole | Question | Meanwhile |
|---|---|---|
DD0104 |
Where is its collar? 95 assays cannot be placed without one. | Dropped |
DD0207 |
Where is its downhole survey? | Dropped |
DD0076 |
Its lithology logs ore; where are its assays? | Kept, no grades |
DD0109 |
Of the two overlapping sample pairs, which is right? | First of each pair kept |
DD0054 |
Were the two missing samples lost, or never taken? | Left as gaps |
Keep the audit script with the project: rerunning it on the next database export repeats every decision and shows only what is new. Hole traces plots the flagged survey stations in plan and section, and desurvey is the next step.
Total running time of the script: ( 0 minutes 1.030 seconds)
Download Python source code: example_02_02.py