pitopt 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pitopt/__init__.py +15 -0
- pitopt/__main__.py +7 -0
- pitopt/cli.py +207 -0
- pitopt/config.py +530 -0
- pitopt/core/__init__.py +1 -0
- pitopt/core/cancel.py +32 -0
- pitopt/core/design.py +475 -0
- pitopt/core/design_detail/__init__.py +5 -0
- pitopt/core/design_detail/angles.py +100 -0
- pitopt/core/design_detail/builder.py +230 -0
- pitopt/core/design_detail/config.py +416 -0
- pitopt/core/design_detail/footprint.py +199 -0
- pitopt/core/design_detail/offset.py +114 -0
- pitopt/core/design_detail/parameters.py +336 -0
- pitopt/core/design_detail/ramp.py +533 -0
- pitopt/core/design_detail/reconcile.py +210 -0
- pitopt/core/design_detail/stack.py +245 -0
- pitopt/core/design_detail/validate.py +198 -0
- pitopt/core/economics.py +245 -0
- pitopt/core/limits.py +136 -0
- pitopt/core/pitsurface.py +108 -0
- pitopt/core/planning.py +223 -0
- pitopt/core/precedence.py +486 -0
- pitopt/core/reblock.py +272 -0
- pitopt/core/reserves.py +339 -0
- pitopt/core/schedule.py +360 -0
- pitopt/core/sensitivity.py +100 -0
- pitopt/core/shells.py +100 -0
- pitopt/core/solver.py +182 -0
- pitopt/core/verify.py +310 -0
- pitopt/io/__init__.py +3 -0
- pitopt/io/blockmodel.py +210 -0
- pitopt/io/console.py +75 -0
- pitopt/io/datasets.py +204 -0
- pitopt/io/datfile.py +93 -0
- pitopt/io/design_export.py +360 -0
- pitopt/io/dxf.py +259 -0
- pitopt/io/excel.py +231 -0
- pitopt/io/pdf.py +376 -0
- pitopt/io/plot.py +66 -0
- pitopt/io/results.py +594 -0
- pitopt/io/viz.py +371 -0
- pitopt/mcp_server.py +632 -0
- pitopt/pipeline.py +1022 -0
- pitopt/provenance.py +62 -0
- pitopt/ui/__init__.py +3 -0
- pitopt/ui/design_service.py +412 -0
- pitopt/ui/mcp_controller.py +509 -0
- pitopt/ui/onboard.py +403 -0
- pitopt/ui/server.py +1145 -0
- pitopt/ui/staging.py +49 -0
- pitopt/ui/static/css/app.css +301 -0
- pitopt/ui/static/css/chat.css +657 -0
- pitopt/ui/static/css/design.css +62 -0
- pitopt/ui/static/fonts/IBMPlexMono-400.woff2 +0 -0
- pitopt/ui/static/fonts/IBMPlexMono-500.woff2 +0 -0
- pitopt/ui/static/fonts/IBMPlexMono-600.woff2 +0 -0
- pitopt/ui/static/fonts/IBMPlexSans-var.woff2 +0 -0
- pitopt/ui/static/fonts/OFL.txt +93 -0
- pitopt/ui/static/i18n/en.json +1229 -0
- pitopt/ui/static/img/design.webp +0 -0
- pitopt/ui/static/img/og-pitopt-2026-11.png +0 -0
- pitopt/ui/static/img/pitbypit.webp +0 -0
- pitopt/ui/static/img/pushback.webp +0 -0
- pitopt/ui/static/img/summary.webp +0 -0
- pitopt/ui/static/img/tutorial-marvin.webp +0 -0
- pitopt/ui/static/index.html +24 -0
- pitopt/ui/static/js/actions.js +4 -0
- pitopt/ui/static/js/app.js +223 -0
- pitopt/ui/static/js/charts.js +279 -0
- pitopt/ui/static/js/chat-panel.js +1210 -0
- pitopt/ui/static/js/commands.js +1025 -0
- pitopt/ui/static/js/csp-boot.js +48 -0
- pitopt/ui/static/js/design/core.js +194 -0
- pitopt/ui/static/js/design/plan.js +105 -0
- pitopt/ui/static/js/design/planview.js +49 -0
- pitopt/ui/static/js/design/section.js +80 -0
- pitopt/ui/static/js/design/three.js +45 -0
- pitopt/ui/static/js/design/ui.js +175 -0
- pitopt/ui/static/js/i18n.js +205 -0
- pitopt/ui/static/js/manage.js +119 -0
- pitopt/ui/static/js/modal.js +16 -0
- pitopt/ui/static/js/run.js +81 -0
- pitopt/ui/static/js/store.js +103 -0
- pitopt/ui/static/js/tutorial-guide.js +140 -0
- pitopt/ui/static/js/util.js +98 -0
- pitopt/ui/static/js/views/blocks.js +106 -0
- pitopt/ui/static/js/views/common.js +37 -0
- pitopt/ui/static/js/views/design_ekspor.js +69 -0
- pitopt/ui/static/js/views/design_generate.js +76 -0
- pitopt/ui/static/js/views/design_penampang.js +72 -0
- pitopt/ui/static/js/views/design_ramp.js +109 -0
- pitopt/ui/static/js/views/design_sektor.js +117 -0
- pitopt/ui/static/js/views/design_sumber.js +75 -0
- pitopt/ui/static/js/views/design_validasi.js +88 -0
- pitopt/ui/static/js/views/misc.js +128 -0
- pitopt/ui/static/js/views/params.js +189 -0
- pitopt/ui/static/js/views/pitbypit.js +65 -0
- pitopt/ui/static/js/views/plan.js +140 -0
- pitopt/ui/static/js/views/summary.js +94 -0
- pitopt/ui/static/js/views/upload.js +503 -0
- pitopt/ui/static/js/views/view3d.js +85 -0
- pitopt/ui/static/js/views/workspace.js +103 -0
- pitopt/ui/static/landing.html +487 -0
- pitopt-1.1.0.dist-info/METADATA +180 -0
- pitopt-1.1.0.dist-info/RECORD +112 -0
- pitopt-1.1.0.dist-info/WHEEL +5 -0
- pitopt-1.1.0.dist-info/entry_points.txt +3 -0
- pitopt-1.1.0.dist-info/licenses/LICENSE +661 -0
- pitopt-1.1.0.dist-info/licenses/NOTICE +19 -0
- pitopt-1.1.0.dist-info/licenses/THIRD_PARTY_NOTICES.md +52 -0
- pitopt-1.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The one entry point: optimiser shell in, detailed design out.
|
|
3
|
+
|
|
4
|
+
blocks + in-pit mask -> anchor outline -> smoothing -> (floor widened)
|
|
5
|
+
-> bench stack -> ramp -> angles -> reconciliation -> validation
|
|
6
|
+
|
|
7
|
+
Nothing here writes a file or touches the raster design; the caller decides
|
|
8
|
+
what to do with the result. Kept short on purpose: each step is its own
|
|
9
|
+
module with its own hand-checked tests, and this only wires them in order.
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import hashlib
|
|
14
|
+
from collections.abc import Callable
|
|
15
|
+
from dataclasses import dataclass, field
|
|
16
|
+
|
|
17
|
+
import numpy as np
|
|
18
|
+
import pandas as pd
|
|
19
|
+
|
|
20
|
+
from ...config import ProjectConfig
|
|
21
|
+
from ..cancel import CancelToken
|
|
22
|
+
from .angles import SectorOSA, sector_osa
|
|
23
|
+
from .footprint import (
|
|
24
|
+
SmoothingRecord,
|
|
25
|
+
band_footprint,
|
|
26
|
+
block_diagonal,
|
|
27
|
+
level_footprint,
|
|
28
|
+
shell_level_areas,
|
|
29
|
+
smooth_outline,
|
|
30
|
+
widen_to_min_width,
|
|
31
|
+
working_width,
|
|
32
|
+
worst_shell_fit,
|
|
33
|
+
)
|
|
34
|
+
from .parameters import (
|
|
35
|
+
SectorGeometry,
|
|
36
|
+
angle_status,
|
|
37
|
+
inter_ramp_angle_deg,
|
|
38
|
+
resolve_sectors,
|
|
39
|
+
stratify_sectors_by_elevation,
|
|
40
|
+
)
|
|
41
|
+
from .ramp import Ramp, build_ramp, size_ramp, wall_tables
|
|
42
|
+
from .reconcile import Reconciliation, reconcile
|
|
43
|
+
from .stack import BenchStack, bench_count, build_bench_stack, build_shell_constrained_stack
|
|
44
|
+
from .validate import Finding, Validation, validate
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@dataclass
|
|
48
|
+
class SectorAngle:
|
|
49
|
+
"""A sector's inter-ramp angle against its allowable value."""
|
|
50
|
+
|
|
51
|
+
name: str
|
|
52
|
+
ira_deg: float
|
|
53
|
+
ira_max_deg: float | None
|
|
54
|
+
status: str
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def margin_deg(self) -> float | None:
|
|
58
|
+
return None if self.ira_max_deg is None else self.ira_max_deg - self.ira_deg
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass
|
|
62
|
+
class DesignDetail:
|
|
63
|
+
stack: BenchStack
|
|
64
|
+
sectors: list[SectorGeometry]
|
|
65
|
+
smoothing: SmoothingRecord
|
|
66
|
+
angles: list[SectorAngle]
|
|
67
|
+
floor_rl: float
|
|
68
|
+
crest_rl: float
|
|
69
|
+
osa: list[SectorOSA] = field(default_factory=list)
|
|
70
|
+
ramp: Ramp | None = None
|
|
71
|
+
floor_width_m: float = 0.0
|
|
72
|
+
floor_widened: bool = False
|
|
73
|
+
reconciliation: Reconciliation | None = None
|
|
74
|
+
validation: Validation | None = None
|
|
75
|
+
shell_sha256: str = ""
|
|
76
|
+
warnings: list[str] = field(default_factory=list)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def shell_fingerprint(blocks: pd.DataFrame, in_pit: np.ndarray) -> str:
|
|
80
|
+
"""A hash of which blocks make up the shell the design was built from: the coordinates of every in-pit
|
|
81
|
+
block, in a fixed order. Two designs with the same fingerprint came from the same shell."""
|
|
82
|
+
shell = blocks.loc[in_pit, ["x", "y", "z"]].round(6).sort_values(["z", "y", "x"])
|
|
83
|
+
return hashlib.sha256(shell.to_numpy(dtype="<f8").tobytes()).hexdigest()
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def floor_width(stack: BenchStack) -> float:
|
|
87
|
+
return working_width(stack.benches[-1].toe)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def build_design(blocks: pd.DataFrame, in_pit: np.ndarray, cfg: ProjectConfig, raster: dict | None = None,
|
|
91
|
+
progress: Callable[[str, dict], None] | None = None, cancel: CancelToken | None = None) -> DesignDetail:
|
|
92
|
+
"""Design the pit whose shell is `blocks[in_pit]`. `raster` is the uniform raster design's reconciliation
|
|
93
|
+
when it was run, carried into the result so both designs can be read side by side.
|
|
94
|
+
|
|
95
|
+
`progress(stage, info)` is told as each stage starts and, for the bench stack, as each bench finishes, so a
|
|
96
|
+
viewer can draw the pit while the rest is computed; `cancel` is checked between stages and between benches."""
|
|
97
|
+
def tell(stage: str, **info) -> None:
|
|
98
|
+
if cancel is not None:
|
|
99
|
+
cancel.check()
|
|
100
|
+
if progress is not None:
|
|
101
|
+
progress(stage, info)
|
|
102
|
+
|
|
103
|
+
design, detail = cfg.design, cfg.design.detail
|
|
104
|
+
if not in_pit.any():
|
|
105
|
+
raise ValueError("there is no pit to design: no block is inside the shell")
|
|
106
|
+
|
|
107
|
+
dz = float(blocks["dz"].iloc[0])
|
|
108
|
+
levels = blocks.loc[in_pit, "z"]
|
|
109
|
+
floor_level, crest_level = float(levels.min()), float(levels.max())
|
|
110
|
+
floor_rl, crest_rl = floor_level - dz / 2.0, crest_level + dz / 2.0
|
|
111
|
+
limits = detail.limits
|
|
112
|
+
|
|
113
|
+
sectors, warnings = resolve_sectors(
|
|
114
|
+
design,
|
|
115
|
+
cfg.slope.overall_angle_deg,
|
|
116
|
+
domain_angles=cfg.slope.domain_angles,
|
|
117
|
+
blocks=blocks,
|
|
118
|
+
in_pit=in_pit,
|
|
119
|
+
)
|
|
120
|
+
h0 = sectors[0].bench_height
|
|
121
|
+
n_total = bench_count(crest_rl, floor_rl, h0)
|
|
122
|
+
if cfg.slope.domain_angles and "domain" in blocks.columns:
|
|
123
|
+
anchor_rl_for_strat = crest_rl if detail.anchor == "crest" else floor_rl
|
|
124
|
+
sectors, strat_notes = stratify_sectors_by_elevation(
|
|
125
|
+
sectors, blocks, in_pit, detail.anchor, anchor_rl_for_strat, floor_rl,
|
|
126
|
+
n_total, design, cfg.slope.overall_angle_deg, cfg.slope.domain_angles,
|
|
127
|
+
)
|
|
128
|
+
warnings += strat_notes
|
|
129
|
+
if detail.anchor == "shell":
|
|
130
|
+
tell("anchor", anchor=detail.anchor, floor_rl=floor_rl, crest_rl=crest_rl)
|
|
131
|
+
h = sectors[0].bench_height
|
|
132
|
+
n = bench_count(crest_rl, floor_rl, h)
|
|
133
|
+
diag = block_diagonal(blocks)
|
|
134
|
+
smoothed_footprints = []
|
|
135
|
+
smoothing_records = []
|
|
136
|
+
for k in range(n):
|
|
137
|
+
raw_k = band_footprint(blocks, in_pit, floor_rl + k * h, floor_rl + (k + 1) * h)
|
|
138
|
+
if k == 0 and raw_k.is_empty:
|
|
139
|
+
raw_k = level_footprint(blocks, in_pit, floor_level)
|
|
140
|
+
smooth_k, rec_k = smooth_outline(raw_k, detail.smoothing, diag)
|
|
141
|
+
smoothed_footprints.append(smooth_k)
|
|
142
|
+
smoothing_records.append(rec_k)
|
|
143
|
+
warnings += rec_k.notes
|
|
144
|
+
smoothing = smoothing_records[0]
|
|
145
|
+
tell("benches", total=n)
|
|
146
|
+
|
|
147
|
+
def bench_done(bench, done):
|
|
148
|
+
if progress is not None:
|
|
149
|
+
progress("bench_done", {"bench": bench, "done": done, "total": n})
|
|
150
|
+
|
|
151
|
+
plain = build_shell_constrained_stack(
|
|
152
|
+
smoothed_footprints, floor_rl, n, sectors, detail, on_bench=bench_done, cancel=cancel
|
|
153
|
+
)
|
|
154
|
+
stack, widened = plain, False
|
|
155
|
+
if limits.widen_floor_to_min_width:
|
|
156
|
+
wide, widened = widen_to_min_width(smoothed_footprints[0], limits.min_mining_width_m)
|
|
157
|
+
if widened:
|
|
158
|
+
stack = build_shell_constrained_stack(
|
|
159
|
+
[wide, *smoothed_footprints[1:]], floor_rl, n, sectors, detail, cancel=cancel
|
|
160
|
+
)
|
|
161
|
+
warnings.append(f"the floor was widened to the {limits.min_mining_width_m:g} m minimum mining width")
|
|
162
|
+
else:
|
|
163
|
+
anchor_level, anchor_rl = (floor_level, floor_rl) if detail.anchor == "floor" else (crest_level, crest_rl)
|
|
164
|
+
tell("anchor", anchor=detail.anchor, floor_rl=floor_rl, crest_rl=crest_rl)
|
|
165
|
+
outline, smoothing = smooth_outline(level_footprint(blocks, in_pit, anchor_level), detail.smoothing,
|
|
166
|
+
block_diagonal(blocks))
|
|
167
|
+
warnings += smoothing.notes
|
|
168
|
+
|
|
169
|
+
n = bench_count(crest_rl, floor_rl, sectors[0].bench_height)
|
|
170
|
+
tell("benches", total=n)
|
|
171
|
+
|
|
172
|
+
def bench_done(bench, done):
|
|
173
|
+
if progress is not None:
|
|
174
|
+
progress("bench_done", {"bench": bench, "done": done, "total": n})
|
|
175
|
+
|
|
176
|
+
plain = build_bench_stack(outline, anchor_rl, n, sectors, detail, on_bench=bench_done, cancel=cancel)
|
|
177
|
+
stack, widened = plain, False
|
|
178
|
+
if detail.anchor == "floor" and limits.widen_floor_to_min_width:
|
|
179
|
+
wide, widened = widen_to_min_width(outline, limits.min_mining_width_m)
|
|
180
|
+
if widened:
|
|
181
|
+
stack = build_bench_stack(wide, anchor_rl, n, sectors, detail, cancel=cancel)
|
|
182
|
+
warnings.append(f"the floor was widened to the {limits.min_mining_width_m:g} m minimum mining width")
|
|
183
|
+
warnings += stack.warnings
|
|
184
|
+
|
|
185
|
+
angles = [SectorAngle(s.name, s.ira_deg, s.ira_max_deg, angle_status(s.ira_deg, s.ira_max_deg, limits.warn_margin_deg))
|
|
186
|
+
for s in sectors]
|
|
187
|
+
|
|
188
|
+
tables = wall_tables(stack, multi_part=detail.ramp.multi_part if detail.ramp.enabled else "strict")
|
|
189
|
+
ramp = None
|
|
190
|
+
if detail.ramp.enabled:
|
|
191
|
+
tell("ramp")
|
|
192
|
+
sizing = size_ramp(detail.ramp)
|
|
193
|
+
ramp = build_ramp(stack, sizing, detail.ramp, tables)
|
|
194
|
+
warnings += ramp.warnings
|
|
195
|
+
osa = sector_osa(stack, ramp, tables[1], tables[2], limits)
|
|
196
|
+
|
|
197
|
+
width = floor_width(stack)
|
|
198
|
+
tell("reconcile")
|
|
199
|
+
recon = reconcile(blocks, in_pit, plain, stack, ramp, limits, raster)
|
|
200
|
+
tell("validate")
|
|
201
|
+
# See validate.py's module docstring (SHAPE_WARN_RATIO / SHAPE_BLOCK_RATIO) for why this is checked at all:
|
|
202
|
+
# the offset construction assumes a shell that is one cone, and a shape that is not one produces a design
|
|
203
|
+
# far smaller than the shell with no parameter that fixes it.
|
|
204
|
+
fit = worst_shell_fit(stack, shell_level_areas(blocks, in_pit), dz)
|
|
205
|
+
checked = validate(stack, angles, osa, ramp, width, recon, limits, fit)
|
|
206
|
+
if cfg.slope.domain_angles:
|
|
207
|
+
if "domain" not in blocks.columns:
|
|
208
|
+
checked.findings.append(Finding(
|
|
209
|
+
"ira", "domain geometry", "BLOKIR",
|
|
210
|
+
"slope.domain_angles is configured, but the block model has no mapped domain column",
|
|
211
|
+
))
|
|
212
|
+
else:
|
|
213
|
+
for s in sectors:
|
|
214
|
+
for j in range(1, len(s.bench_berms)):
|
|
215
|
+
if j % s.berm_every_n != 0:
|
|
216
|
+
continue
|
|
217
|
+
step_ira = inter_ramp_angle_deg(s.bench_height, s.face_angle_deg, s.bench_berms[j], s.berm_every_n)
|
|
218
|
+
lim_j = s.bench_ira_limits[j]
|
|
219
|
+
if step_ira > lim_j + 1e-6:
|
|
220
|
+
checked.findings.append(Finding(
|
|
221
|
+
"ira",
|
|
222
|
+
f"{s.name} (step {j})",
|
|
223
|
+
"BLOKIR",
|
|
224
|
+
f"inter-ramp angle {step_ira:.1f} deg is over the {lim_j:g} deg domain limit at step {j}",
|
|
225
|
+
step_ira,
|
|
226
|
+
lim_j,
|
|
227
|
+
))
|
|
228
|
+
warnings += [f.message for f in checked.problems()]
|
|
229
|
+
return DesignDetail(stack, sectors, smoothing, angles, floor_rl, crest_rl, osa, ramp, width, widened, recon, checked,
|
|
230
|
+
shell_fingerprint(blocks, in_pit), warnings)
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Configuration of the detailed pit design (design.detail, PRD F-DES-6): sectors, berm criteria, crest
|
|
3
|
+
smoothing, the geotechnical limits, the haul road and the grade classes — and the checks that refuse a
|
|
4
|
+
parameter the design cannot defend.
|
|
5
|
+
|
|
6
|
+
Kept with the design engine rather than in pitopt/config.py so the detailed design is one self-contained
|
|
7
|
+
package: pitopt.config composes these into ProjectConfig and re-exports them, and nothing here imports
|
|
8
|
+
anything from the optimiser.
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from dataclasses import dataclass, field
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass
|
|
16
|
+
class BermConfig:
|
|
17
|
+
"""
|
|
18
|
+
How the catch berm width is decided.
|
|
19
|
+
|
|
20
|
+
A berm is not a free parameter: it is the bench width needed to catch
|
|
21
|
+
rockfall from the face above it, so it follows from the bench height
|
|
22
|
+
and the face angle by a published criterion. Letting a user type all
|
|
23
|
+
three invites a combination that is geometrically inconsistent.
|
|
24
|
+
|
|
25
|
+
ritchie the modified Ritchie criterion, W = 0.2 H + 4.5 m — the
|
|
26
|
+
catch-bench rule most Western codes and feasibility
|
|
27
|
+
studies quote. Derived for benches up to about 30 m; above
|
|
28
|
+
that it is extrapolation and the design warns.
|
|
29
|
+
ryan Ryan & Pryor's criterion, W = a H + b. There is no
|
|
30
|
+
industry-agreed pair of coefficients, so there is no
|
|
31
|
+
default: supply them from the geotechnical report or the
|
|
32
|
+
design refuses to run rather than invent a berm.
|
|
33
|
+
slope the width that makes the inter-ramp angle equal
|
|
34
|
+
slope.overall_angle_deg, so the design and the optimiser
|
|
35
|
+
agree on the wall. Reproduces the behaviour of a blank
|
|
36
|
+
design.berm_width.
|
|
37
|
+
manual `width` exactly as given, for a berm dictated by a study.
|
|
38
|
+
"""
|
|
39
|
+
method: str = "ritchie"
|
|
40
|
+
width: float | None = None # manual only
|
|
41
|
+
ryan_a: float | None = None # ryan only — from the geotechnical report
|
|
42
|
+
ryan_b: float | None = None
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass
|
|
46
|
+
class SectorConfig:
|
|
47
|
+
"""
|
|
48
|
+
One azimuth sector of the pit wall, with its own geotechnical
|
|
49
|
+
geometry. Walls fail by structure, and structure has an orientation,
|
|
50
|
+
so a real design varies around the pit rather than applying one angle
|
|
51
|
+
to the whole rim.
|
|
52
|
+
|
|
53
|
+
Every geometry field left unset inherits the corresponding value from
|
|
54
|
+
the parent `design:` block, so a sector can differ in one parameter
|
|
55
|
+
without restating the rest. `azimuth_from`/`azimuth_to` are compass
|
|
56
|
+
bearings in degrees and may wrap through north (315 -> 45).
|
|
57
|
+
"""
|
|
58
|
+
name: str = ""
|
|
59
|
+
azimuth_from: float = 0.0
|
|
60
|
+
azimuth_to: float = 360.0
|
|
61
|
+
bench_height: float | None = None
|
|
62
|
+
face_angle_deg: float | None = None
|
|
63
|
+
berm_every_n_benches: int | None = None
|
|
64
|
+
berm: BermConfig | None = None
|
|
65
|
+
ira_max_deg: float | None = None
|
|
66
|
+
osa_max_deg: float | None = None
|
|
67
|
+
|
|
68
|
+
def __post_init__(self) -> None:
|
|
69
|
+
if isinstance(self.berm, dict):
|
|
70
|
+
self.berm = BermConfig(**self.berm)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@dataclass
|
|
74
|
+
class SmoothingConfig:
|
|
75
|
+
"""
|
|
76
|
+
Crest simplification applied before the walls are offset.
|
|
77
|
+
|
|
78
|
+
A maximum_closure shell is a staircase of whole blocks: its rim steps in
|
|
79
|
+
and out by a block at a time. Offsetting that staircase directly
|
|
80
|
+
reproduces every step as a notch in all fifteen benches, which no
|
|
81
|
+
survey crew could peg and no excavator could dig. Simplifying the rim
|
|
82
|
+
first is what turns an optimisation result into a diggable shape, and
|
|
83
|
+
it is the single stage with the most influence on the answer — so it
|
|
84
|
+
is a visible, recorded parameter, never a hidden clean-up.
|
|
85
|
+
|
|
86
|
+
`tolerance_m` is the Douglas-Peucker band: no simplified point moves
|
|
87
|
+
further than this from the original rim. Unset means one block
|
|
88
|
+
diagonal, the resolution the shell actually carries. `closing_m` fills
|
|
89
|
+
single-block notches before simplifying. `min_area_m2` drops fragments
|
|
90
|
+
too small to mine, and is reported rather than silently discarded.
|
|
91
|
+
"""
|
|
92
|
+
enabled: bool = True
|
|
93
|
+
tolerance_m: float | None = None
|
|
94
|
+
closing_m: float | None = None
|
|
95
|
+
min_area_m2: float | None = None
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@dataclass
|
|
99
|
+
class DesignLimitsConfig:
|
|
100
|
+
"""
|
|
101
|
+
The geotechnical envelope the design is checked against, and the
|
|
102
|
+
minimum geometry a mine can actually work in.
|
|
103
|
+
|
|
104
|
+
These are limits, not inputs: the design is built from bench geometry
|
|
105
|
+
and then measured against them. `warn_margin_deg` is how close to a
|
|
106
|
+
limit counts as a warning rather than a pass — a wall designed 0.1
|
|
107
|
+
degrees inside its limit has no tolerance left for survey error.
|
|
108
|
+
"""
|
|
109
|
+
ira_max_deg: float | None = None
|
|
110
|
+
osa_max_deg: float | None = None
|
|
111
|
+
warn_margin_deg: float = 0.5
|
|
112
|
+
min_mining_width_m: float = 30.0
|
|
113
|
+
# A floor narrower than the minimum mining width cannot be worked. With a
|
|
114
|
+
# floor anchor it is widened to the minimum, and the extra material is
|
|
115
|
+
# reported as its own line of dilution; a crest anchor cannot widen the
|
|
116
|
+
# floor and reports the conflict instead.
|
|
117
|
+
widen_floor_to_min_width: bool = True
|
|
118
|
+
# Tonnage, ore and value of the practical design against the optimiser
|
|
119
|
+
# shell: within warn is OK, within block a warning, beyond it blocked.
|
|
120
|
+
recon_warn_pct: float = 5.0
|
|
121
|
+
recon_block_pct: float = 10.0
|
|
122
|
+
# Difference below which two coordinates are the same point. 1 mm: far
|
|
123
|
+
# finer than any survey, coarse enough that GEOS predicates stay robust.
|
|
124
|
+
tolerance_m: float = 0.001
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@dataclass
|
|
128
|
+
class RampConfig:
|
|
129
|
+
"""
|
|
130
|
+
The haul road. Its width comes from the largest truck, its grade from
|
|
131
|
+
what that truck can pull loaded, and both are equipment facts rather
|
|
132
|
+
than design preferences.
|
|
133
|
+
|
|
134
|
+
Given `truck_width_m`, the running surface is the width the fleet needs
|
|
135
|
+
to pass safely: each lane one truck wide, half a truck of clearance at
|
|
136
|
+
both edges and between lanes, so 1.5 * lanes + 0.5 truck widths (3.5
|
|
137
|
+
for the usual two lanes), plus the safety berm and the drain. A
|
|
138
|
+
`width_m` given as well is used as stated and checked against that
|
|
139
|
+
requirement; a road narrower than the fleet needs is reported, not
|
|
140
|
+
quietly widened. With neither the design refuses, rather than assume
|
|
141
|
+
a fleet.
|
|
142
|
+
|
|
143
|
+
`direction` is the way the road climbs round the pit, seen from above.
|
|
144
|
+
`entry_azimuth_deg` is the bearing at which it leaves the floor; unset,
|
|
145
|
+
the design picks the bearing where the wall is widest and says so.
|
|
146
|
+
A switchback reverses `switchbacks` times, and each hairpin needs a
|
|
147
|
+
platform the truck can turn on: `hairpin_radius_m` comes from the
|
|
148
|
+
truck's turning circle and has no default.
|
|
149
|
+
"""
|
|
150
|
+
enabled: bool = True
|
|
151
|
+
pattern: str = "spiral" # spiral | switchback
|
|
152
|
+
width_m: float | None = None
|
|
153
|
+
truck_width_m: float | None = None
|
|
154
|
+
lanes: int = 2
|
|
155
|
+
safety_berm_m: float = 0.0
|
|
156
|
+
drain_m: float = 0.0
|
|
157
|
+
grade_pct: float = 9.0
|
|
158
|
+
grade_min_pct: float = 8.0
|
|
159
|
+
grade_max_pct: float = 10.0
|
|
160
|
+
direction: str = "clockwise" # clockwise | anticlockwise
|
|
161
|
+
entry_azimuth_deg: float | None = None
|
|
162
|
+
switchbacks: int | None = None # switchback only: how many times the road reverses
|
|
163
|
+
hairpin_radius_m: float | None = None
|
|
164
|
+
multi_part: str = "strict" # strict | primary_lobe
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@dataclass
|
|
168
|
+
class GradeClassConfig:
|
|
169
|
+
"""
|
|
170
|
+
Grade classes for the plan, the sections and the block reconciliation.
|
|
171
|
+
|
|
172
|
+
Commodity-neutral by construction: the column is named and the breaks
|
|
173
|
+
are the project's own numbers in that column's own units, so the same
|
|
174
|
+
code serves a copper porphyry in per cent and a gold deposit in grams
|
|
175
|
+
per tonne. `breaks` are the boundaries between classes, so there is
|
|
176
|
+
always one more name than break.
|
|
177
|
+
"""
|
|
178
|
+
grade_col: str | None = None # unset: the first product's grade column
|
|
179
|
+
breaks: list = field(default_factory=list)
|
|
180
|
+
names: list = field(default_factory=list)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
@dataclass
|
|
184
|
+
class DesignDetailConfig:
|
|
185
|
+
"""
|
|
186
|
+
Detailed pit design: bench polygons, sector geometry, a ramp and the
|
|
187
|
+
validations that say whether the result is buildable (F-DES-6).
|
|
188
|
+
|
|
189
|
+
Off by default. With `enabled: false` nothing here runs and the design
|
|
190
|
+
surfaces are exactly the uniform benched bowl of `design:` above, so
|
|
191
|
+
an existing project keeps the answer it had.
|
|
192
|
+
|
|
193
|
+
`anchor` decides which ring of the optimiser shell the design honours,
|
|
194
|
+
and it is the one choice that changes what the design means:
|
|
195
|
+
|
|
196
|
+
floor the design floor holds the shell's floor and the walls are
|
|
197
|
+
offset outward and upward from it. The ore the optimiser
|
|
198
|
+
paid for stays inside the design, the crest lands where the
|
|
199
|
+
geometry puts it, and the reconciliation measures the waste
|
|
200
|
+
the practical wall adds. This is the usual way to turn an
|
|
201
|
+
optimisation shell into a pit, and it is what `design:`
|
|
202
|
+
already does — so the two agree.
|
|
203
|
+
crest the crest is held and the benches are offset inward and
|
|
204
|
+
downward from it. Use it when the rim is fixed by something
|
|
205
|
+
outside the optimisation — a lease boundary, a river, plant
|
|
206
|
+
infrastructure — and accept that the floor, and the ore in
|
|
207
|
+
it, is what gives way.
|
|
208
|
+
shell each bench's toe honours at least the shell's own footprint at
|
|
209
|
+
that elevation, while still stepping outward from the bench
|
|
210
|
+
below by the catch berm, so the design never overhangs and
|
|
211
|
+
still captures mid-elevation shell bulges.
|
|
212
|
+
|
|
213
|
+
`blend_deg` is the azimuth band either side of a sector boundary over
|
|
214
|
+
which the two sectors' offsets are mixed linearly, so a change of
|
|
215
|
+
geotechnical domain does not appear as a step in the wall.
|
|
216
|
+
"""
|
|
217
|
+
enabled: bool = False
|
|
218
|
+
anchor: str = "floor" # floor | crest | shell
|
|
219
|
+
source: str = "final_shell" # final_shell | pushback
|
|
220
|
+
berm_every_n_benches: int = 1
|
|
221
|
+
join_style: str = "round" # round | mitre
|
|
222
|
+
miter_limit: float = 2.0
|
|
223
|
+
blend_deg: float = 12.0
|
|
224
|
+
berm: BermConfig = field(default_factory=BermConfig)
|
|
225
|
+
sectors: list = field(default_factory=list)
|
|
226
|
+
smoothing: SmoothingConfig = field(default_factory=SmoothingConfig)
|
|
227
|
+
limits: DesignLimitsConfig = field(default_factory=DesignLimitsConfig)
|
|
228
|
+
ramp: RampConfig = field(default_factory=RampConfig)
|
|
229
|
+
grade_classes: GradeClassConfig = field(default_factory=GradeClassConfig)
|
|
230
|
+
|
|
231
|
+
def __post_init__(self) -> None:
|
|
232
|
+
if isinstance(self.berm, dict):
|
|
233
|
+
self.berm = BermConfig(**self.berm)
|
|
234
|
+
if isinstance(self.smoothing, dict):
|
|
235
|
+
self.smoothing = SmoothingConfig(**self.smoothing)
|
|
236
|
+
if isinstance(self.limits, dict):
|
|
237
|
+
self.limits = DesignLimitsConfig(**self.limits)
|
|
238
|
+
if isinstance(self.ramp, dict):
|
|
239
|
+
self.ramp = RampConfig(**self.ramp)
|
|
240
|
+
if isinstance(self.grade_classes, dict):
|
|
241
|
+
self.grade_classes = GradeClassConfig(**self.grade_classes)
|
|
242
|
+
self.sectors = [SectorConfig(**s) if isinstance(s, dict) else s for s in self.sectors]
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def validate_detail(t: DesignDetailConfig, bench_height: float, *, require_ramp_ready: bool = True) -> None:
|
|
246
|
+
"""Everything the detailed design needs before it draws a bench.
|
|
247
|
+
|
|
248
|
+
A parameter it cannot defend is refused here rather than
|
|
249
|
+
substituted, because a berm invented from a missing coefficient
|
|
250
|
+
looks exactly like a berm from the geotechnical report once it is
|
|
251
|
+
in a drawing."""
|
|
252
|
+
if t.anchor not in ("floor", "crest", "shell"):
|
|
253
|
+
raise ValueError("design.detail.anchor must be 'floor', 'crest' or 'shell'")
|
|
254
|
+
if t.source == "pushback":
|
|
255
|
+
raise ValueError("design.detail.source 'pushback' is not implemented yet; use 'final_shell'")
|
|
256
|
+
if t.source != "final_shell":
|
|
257
|
+
raise ValueError("design.detail.source must be 'final_shell'")
|
|
258
|
+
if t.join_style not in ("round", "mitre"):
|
|
259
|
+
raise ValueError("design.detail.join_style must be 'round' or 'mitre'")
|
|
260
|
+
if t.miter_limit <= 0:
|
|
261
|
+
raise ValueError("design.detail.miter_limit must be > 0")
|
|
262
|
+
if t.berm_every_n_benches < 1:
|
|
263
|
+
raise ValueError("design.detail.berm_every_n_benches must be >= 1")
|
|
264
|
+
if not 0 <= t.blend_deg < 90:
|
|
265
|
+
raise ValueError("design.detail.blend_deg must be in [0, 90)")
|
|
266
|
+
|
|
267
|
+
_validate_berm(t.berm, "design.detail.berm")
|
|
268
|
+
for index, s in enumerate(t.sectors):
|
|
269
|
+
where = f"design.detail.sectors[{index}]" + (f" ({s.name})" if s.name else "")
|
|
270
|
+
if s.bench_height is not None and s.bench_height <= 0:
|
|
271
|
+
raise ValueError(f"{where}: bench_height must be > 0")
|
|
272
|
+
if s.bench_height is not None and s.bench_height != bench_height:
|
|
273
|
+
raise ValueError(
|
|
274
|
+
f"{where}: bench_height {s.bench_height:g} differs from design.bench_height {bench_height:g}. "
|
|
275
|
+
"Benches share elevations all round the pit, so a sector cannot have its own height yet"
|
|
276
|
+
)
|
|
277
|
+
arc = (s.azimuth_to - s.azimuth_from) % 360.0 or 360.0
|
|
278
|
+
if len(t.sectors) > 1 and arc < 2 * t.blend_deg:
|
|
279
|
+
raise ValueError(
|
|
280
|
+
f"{where}: spans {arc:g} deg, less than the two blend zones ({2 * t.blend_deg:g} deg) "
|
|
281
|
+
"at its edges; narrow design.detail.blend_deg or widen the sector"
|
|
282
|
+
)
|
|
283
|
+
if s.face_angle_deg is not None and not 0 < s.face_angle_deg < 90:
|
|
284
|
+
raise ValueError(f"{where}: face_angle_deg must be in (0, 90)")
|
|
285
|
+
if s.berm_every_n_benches is not None and s.berm_every_n_benches < 1:
|
|
286
|
+
raise ValueError(f"{where}: berm_every_n_benches must be >= 1")
|
|
287
|
+
for name in ("ira_max_deg", "osa_max_deg"):
|
|
288
|
+
value = getattr(s, name)
|
|
289
|
+
if value is not None and not 0 < value < 90:
|
|
290
|
+
raise ValueError(f"{where}: {name} must be in (0, 90)")
|
|
291
|
+
if s.berm is not None:
|
|
292
|
+
_validate_berm(s.berm, f"{where}.berm")
|
|
293
|
+
for problem in _azimuth_coverage(t.sectors):
|
|
294
|
+
raise ValueError(f"design.detail.sectors: {problem}")
|
|
295
|
+
|
|
296
|
+
m = t.smoothing
|
|
297
|
+
for name in ("tolerance_m", "closing_m", "min_area_m2"):
|
|
298
|
+
value = getattr(m, name)
|
|
299
|
+
if value is not None and value < 0:
|
|
300
|
+
raise ValueError(f"design.detail.smoothing.{name} must be >= 0")
|
|
301
|
+
|
|
302
|
+
limits = t.limits
|
|
303
|
+
for name in ("ira_max_deg", "osa_max_deg"):
|
|
304
|
+
value = getattr(limits, name)
|
|
305
|
+
if value is not None and not 0 < value < 90:
|
|
306
|
+
raise ValueError(f"design.detail.limits.{name} must be in (0, 90)")
|
|
307
|
+
if limits.warn_margin_deg < 0:
|
|
308
|
+
raise ValueError("design.detail.limits.warn_margin_deg must be >= 0")
|
|
309
|
+
if limits.min_mining_width_m <= 0 or limits.tolerance_m <= 0:
|
|
310
|
+
raise ValueError("design.detail.limits: min_mining_width_m and tolerance_m must be > 0")
|
|
311
|
+
if not 0 < limits.recon_warn_pct <= limits.recon_block_pct:
|
|
312
|
+
raise ValueError("design.detail.limits: 0 < recon_warn_pct <= recon_block_pct")
|
|
313
|
+
|
|
314
|
+
r = t.ramp
|
|
315
|
+
if r.enabled:
|
|
316
|
+
if r.pattern not in ("spiral", "switchback"):
|
|
317
|
+
raise ValueError("design.detail.ramp.pattern must be 'spiral' or 'switchback'")
|
|
318
|
+
if require_ramp_ready and r.width_m is None and r.truck_width_m is None:
|
|
319
|
+
raise ValueError(
|
|
320
|
+
"design.detail.ramp needs width_m, or truck_width_m to size it from the fleet"
|
|
321
|
+
)
|
|
322
|
+
if r.width_m is not None and r.width_m <= 0:
|
|
323
|
+
raise ValueError("design.detail.ramp.width_m must be > 0")
|
|
324
|
+
if r.truck_width_m is not None and r.truck_width_m <= 0:
|
|
325
|
+
raise ValueError("design.detail.ramp.truck_width_m must be > 0")
|
|
326
|
+
if r.lanes < 1:
|
|
327
|
+
raise ValueError("design.detail.ramp.lanes must be >= 1")
|
|
328
|
+
if r.safety_berm_m < 0 or r.drain_m < 0:
|
|
329
|
+
raise ValueError("design.detail.ramp: safety_berm_m and drain_m must be >= 0")
|
|
330
|
+
if not 0 < r.grade_min_pct <= r.grade_max_pct:
|
|
331
|
+
raise ValueError("design.detail.ramp: 0 < grade_min_pct <= grade_max_pct")
|
|
332
|
+
if not r.grade_min_pct <= r.grade_pct <= r.grade_max_pct:
|
|
333
|
+
raise ValueError(
|
|
334
|
+
f"design.detail.ramp.grade_pct {r.grade_pct:g}% is outside "
|
|
335
|
+
f"[{r.grade_min_pct:g}%, {r.grade_max_pct:g}%]"
|
|
336
|
+
)
|
|
337
|
+
if r.direction not in ("clockwise", "anticlockwise"):
|
|
338
|
+
raise ValueError("design.detail.ramp.direction must be 'clockwise' or 'anticlockwise'")
|
|
339
|
+
if r.multi_part not in ("strict", "primary_lobe"):
|
|
340
|
+
raise ValueError("design.detail.ramp.multi_part must be 'strict' or 'primary_lobe'")
|
|
341
|
+
if r.entry_azimuth_deg is not None and not 0 <= r.entry_azimuth_deg < 360:
|
|
342
|
+
raise ValueError("design.detail.ramp.entry_azimuth_deg must be in [0, 360)")
|
|
343
|
+
if r.pattern == "switchback":
|
|
344
|
+
if r.switchbacks is not None and r.switchbacks < 1:
|
|
345
|
+
raise ValueError("design.detail.ramp: a switchback needs switchbacks >= 1 (how many times it reverses)")
|
|
346
|
+
if r.hairpin_radius_m is not None and r.hairpin_radius_m <= 0:
|
|
347
|
+
raise ValueError(
|
|
348
|
+
"design.detail.ramp: a switchback needs hairpin_radius_m from the truck's turning circle; "
|
|
349
|
+
"there is no default to assume"
|
|
350
|
+
)
|
|
351
|
+
if require_ramp_ready:
|
|
352
|
+
if r.switchbacks is None:
|
|
353
|
+
raise ValueError("design.detail.ramp: a switchback needs switchbacks >= 1 (how many times it reverses)")
|
|
354
|
+
if r.hairpin_radius_m is None:
|
|
355
|
+
raise ValueError(
|
|
356
|
+
"design.detail.ramp: a switchback needs hairpin_radius_m from the truck's turning circle; "
|
|
357
|
+
"there is no default to assume"
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
g = t.grade_classes
|
|
361
|
+
if g.breaks or g.names:
|
|
362
|
+
if len(g.names) != len(g.breaks) + 1:
|
|
363
|
+
raise ValueError(
|
|
364
|
+
f"design.detail.grade_classes: {len(g.breaks)} breaks need {len(g.breaks) + 1} names, "
|
|
365
|
+
f"got {len(g.names)}"
|
|
366
|
+
)
|
|
367
|
+
if any(b >= a for b, a in zip(g.breaks, g.breaks[1:])):
|
|
368
|
+
raise ValueError("design.detail.grade_classes.breaks must increase")
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
def _validate_berm(berm: BermConfig, where: str) -> None:
|
|
372
|
+
if berm.method not in ("ritchie", "ryan", "slope", "manual"):
|
|
373
|
+
raise ValueError(f"{where}.method must be ritchie, ryan, slope or manual")
|
|
374
|
+
if berm.method == "manual" and (berm.width is None or berm.width < 0):
|
|
375
|
+
raise ValueError(f"{where}.method 'manual' needs width >= 0")
|
|
376
|
+
if berm.method == "ryan" and (berm.ryan_a is None or berm.ryan_b is None):
|
|
377
|
+
raise ValueError(
|
|
378
|
+
f"{where}.method 'ryan' needs ryan_a and ryan_b from the geotechnical report — "
|
|
379
|
+
"there is no industry-agreed default and the design will not invent one"
|
|
380
|
+
)
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def _azimuth_coverage(sectors: list) -> list[str]:
|
|
384
|
+
"""Sectors must tile the full 360 degrees exactly once.
|
|
385
|
+
|
|
386
|
+
A gap leaves part of the rim with no geometry and an overlap leaves it
|
|
387
|
+
with two, and either way some of the wall in the drawing was never
|
|
388
|
+
designed. Cheap to check here, invisible once it is a DXF."""
|
|
389
|
+
if not sectors:
|
|
390
|
+
return []
|
|
391
|
+
spans: list[tuple[float, float, str]] = []
|
|
392
|
+
for index, s in enumerate(sectors):
|
|
393
|
+
label = s.name or f"[{index}]"
|
|
394
|
+
start = s.azimuth_from % 360.0
|
|
395
|
+
length = (s.azimuth_to - s.azimuth_from) % 360.0
|
|
396
|
+
if length == 0:
|
|
397
|
+
length = 360.0 if len(sectors) == 1 else 0.0
|
|
398
|
+
if length <= 0:
|
|
399
|
+
return [f"sector {label} spans no azimuth ({s.azimuth_from:g} to {s.azimuth_to:g})"]
|
|
400
|
+
if start + length <= 360.0:
|
|
401
|
+
spans.append((start, start + length, label))
|
|
402
|
+
else: # wraps through north: two pieces
|
|
403
|
+
spans.append((start, 360.0, label))
|
|
404
|
+
spans.append((0.0, start + length - 360.0, label))
|
|
405
|
+
|
|
406
|
+
spans.sort()
|
|
407
|
+
problems, cursor = [], 0.0
|
|
408
|
+
for start, end, label in spans:
|
|
409
|
+
if start > cursor + 1e-6:
|
|
410
|
+
problems.append(f"azimuth {cursor:g} to {start:g} deg is not covered by any sector")
|
|
411
|
+
elif start < cursor - 1e-6:
|
|
412
|
+
problems.append(f"sector {label} overlaps another between {start:g} and {cursor:g} deg")
|
|
413
|
+
cursor = max(cursor, end)
|
|
414
|
+
if cursor < 360.0 - 1e-6:
|
|
415
|
+
problems.append(f"azimuth {cursor:g} to 360 deg is not covered by any sector")
|
|
416
|
+
return problems
|