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
pitopt/core/design.py
ADDED
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pit design geometry: from the optimiser's floor to a benched pit.
|
|
3
|
+
|
|
4
|
+
The optimiser returns a block-stepped shell. A pit is built to
|
|
5
|
+
geotechnical geometry instead — bench height, bench face angle and berm
|
|
6
|
+
width — whose overall effect is the overall slope angle:
|
|
7
|
+
|
|
8
|
+
overall = atan( H / (H / tan(face) + berm) )
|
|
9
|
+
|
|
10
|
+
Two surfaces come out of that geometry, and they answer different
|
|
11
|
+
questions:
|
|
12
|
+
|
|
13
|
+
pit shell the excavation itself: the floor, with benched walls
|
|
14
|
+
rising from it. Where the walls would climb above
|
|
15
|
+
ground they are simply not cut off, so the shape is the
|
|
16
|
+
full bowl regardless of topography. This is the pit as a
|
|
17
|
+
design object.
|
|
18
|
+
|
|
19
|
+
face position the same bowl clipped by topography — the ground surface
|
|
20
|
+
that actually exists once the pit (or a period, or a
|
|
21
|
+
pushback) has been mined. This is what survey measures
|
|
22
|
+
and what goes into a mine plan.
|
|
23
|
+
|
|
24
|
+
Both are computed on a fine grid by a benched-cone dilation of the floor,
|
|
25
|
+
evaluated exactly with one distance transform per floor level:
|
|
26
|
+
|
|
27
|
+
shell(x) = min over mined floor points p of floor(p) + g(|x - p|)
|
|
28
|
+
|
|
29
|
+
where g is the benched wall profile — rising one bench height over the
|
|
30
|
+
face run, flat across the berm, repeated. Every point on a wall therefore
|
|
31
|
+
sits exactly on the design profile from the nearest part of the floor, so
|
|
32
|
+
the walls are benched and never steeper than the design slope.
|
|
33
|
+
|
|
34
|
+
Designing the walls moves material relative to the optimiser shell (the
|
|
35
|
+
block steps are replaced by a continuous benched wall), so the design is
|
|
36
|
+
reconciled against the shell: tonnes, value and the difference between
|
|
37
|
+
them. A design within a few percent of its shell is the usual target.
|
|
38
|
+
"""
|
|
39
|
+
from __future__ import annotations
|
|
40
|
+
|
|
41
|
+
import math
|
|
42
|
+
from collections import Counter
|
|
43
|
+
from dataclasses import dataclass
|
|
44
|
+
from typing import Callable
|
|
45
|
+
|
|
46
|
+
import numpy as np
|
|
47
|
+
import pandas as pd
|
|
48
|
+
from scipy import ndimage
|
|
49
|
+
from scipy.interpolate import RegularGridInterpolator
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@dataclass
|
|
53
|
+
class BenchGeometry:
|
|
54
|
+
bench_height: float
|
|
55
|
+
face_angle_deg: float
|
|
56
|
+
berm_width: float
|
|
57
|
+
|
|
58
|
+
@property
|
|
59
|
+
def face_run(self) -> float:
|
|
60
|
+
return self.bench_height / math.tan(math.radians(self.face_angle_deg))
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def bench_run(self) -> float:
|
|
64
|
+
return self.face_run + self.berm_width
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def overall_angle_deg(self) -> float:
|
|
68
|
+
return math.degrees(math.atan2(self.bench_height, self.bench_run))
|
|
69
|
+
|
|
70
|
+
def rise(self, distance: np.ndarray) -> np.ndarray:
|
|
71
|
+
"""Height of the benched wall at horizontal distance from its toe."""
|
|
72
|
+
n = np.floor(distance / self.bench_run)
|
|
73
|
+
remainder = distance - n * self.bench_run
|
|
74
|
+
tan_face = math.tan(math.radians(self.face_angle_deg))
|
|
75
|
+
return n * self.bench_height + np.minimum(self.bench_height, remainder * tan_face)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def bench_geometry(overall_angle_deg: float, bench_height: float, face_angle_deg: float, berm_width: float | None) -> BenchGeometry:
|
|
79
|
+
"""Bench geometry from its parts. With no berm given, the berm is the
|
|
80
|
+
width that makes the benches honour the overall slope angle."""
|
|
81
|
+
if berm_width is None:
|
|
82
|
+
run = bench_height / math.tan(math.radians(overall_angle_deg))
|
|
83
|
+
face = bench_height / math.tan(math.radians(face_angle_deg))
|
|
84
|
+
if run < face:
|
|
85
|
+
raise ValueError(
|
|
86
|
+
f"bench face angle {face_angle_deg} deg is flatter than the overall slope {overall_angle_deg} deg"
|
|
87
|
+
)
|
|
88
|
+
berm_width = run - face
|
|
89
|
+
return BenchGeometry(bench_height, face_angle_deg, berm_width)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def domain_geometries(
|
|
93
|
+
overall_angle_deg: float,
|
|
94
|
+
bench_height: float,
|
|
95
|
+
face_angle_deg: float,
|
|
96
|
+
berm_width: float | None,
|
|
97
|
+
domain_angles: dict | None = None,
|
|
98
|
+
) -> dict[object, BenchGeometry]:
|
|
99
|
+
"""Per-domain BenchGeometry table from slope.domain_angles."""
|
|
100
|
+
if not domain_angles:
|
|
101
|
+
return {}
|
|
102
|
+
result = {}
|
|
103
|
+
for dom, angle in domain_angles.items():
|
|
104
|
+
geom = bench_geometry(float(angle), bench_height, face_angle_deg, berm_width)
|
|
105
|
+
if geom.overall_angle_deg > float(angle) + 1e-9:
|
|
106
|
+
raise ValueError(
|
|
107
|
+
f"berm width {geom.berm_width:g} m makes domain {dom!r} wall {geom.overall_angle_deg:.3f} deg, "
|
|
108
|
+
f"steeper than its configured {float(angle):g} deg limit"
|
|
109
|
+
)
|
|
110
|
+
result[dom] = geom
|
|
111
|
+
return result
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
@dataclass
|
|
115
|
+
class DesignGrid:
|
|
116
|
+
xs: np.ndarray
|
|
117
|
+
ys: np.ndarray
|
|
118
|
+
topo: np.ndarray
|
|
119
|
+
cell_i: np.ndarray # block grid column (gi) of every fine node, -1 outside
|
|
120
|
+
cell_j: np.ndarray
|
|
121
|
+
centre_topo: dict[tuple[int, int], float] | None = None
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def design_grid(blocks: pd.DataFrame, elevation: Callable | None, cell: float) -> DesignGrid:
|
|
125
|
+
dx, dy, dz = (float(blocks[c].iloc[0]) for c in ("dx", "dy", "dz"))
|
|
126
|
+
x0, y0 = float(blocks["x"].min()), float(blocks["y"].min())
|
|
127
|
+
gi0, gj0 = int(blocks["gi"].min()), int(blocks["gj"].min())
|
|
128
|
+
xs = np.arange(x0 - dx / 2 + cell / 2, float(blocks["x"].max()) + dx / 2, cell)
|
|
129
|
+
ys = np.arange(y0 - dy / 2 + cell / 2, float(blocks["y"].max()) + dy / 2, cell)
|
|
130
|
+
|
|
131
|
+
ci = (np.round((xs - x0) / dx).astype(int) + gi0)
|
|
132
|
+
cj = (np.round((ys - y0) / dy).astype(int) + gj0)
|
|
133
|
+
|
|
134
|
+
centre_topo: dict[tuple[int, int], float] | None = None
|
|
135
|
+
if elevation is not None:
|
|
136
|
+
mx, my = np.meshgrid(xs, ys, indexing="ij")
|
|
137
|
+
topo = np.asarray(elevation(mx.ravel(), my.ravel()), dtype=float).reshape(mx.shape)
|
|
138
|
+
ui, uj = np.unique(ci), np.unique(cj)
|
|
139
|
+
cmx, cmy = np.meshgrid(x0 + (ui - gi0) * dx, y0 + (uj - gj0) * dy, indexing="ij")
|
|
140
|
+
c_vals = np.asarray(elevation(cmx.ravel(), cmy.ravel()), dtype=float).reshape(cmx.shape)
|
|
141
|
+
centre_topo = {
|
|
142
|
+
(int(gi), int(gj)): float(c_vals[a, b])
|
|
143
|
+
for a, gi in enumerate(ui)
|
|
144
|
+
for b, gj in enumerate(uj)
|
|
145
|
+
}
|
|
146
|
+
else:
|
|
147
|
+
tops = blocks.groupby(["gi", "gj"])["z"].max() + dz / 2.0
|
|
148
|
+
lookup = np.full((blocks["gi"].max() - gi0 + 1, blocks["gj"].max() - gj0 + 1), np.nan)
|
|
149
|
+
lookup[tops.index.get_level_values(0) - gi0, tops.index.get_level_values(1) - gj0] = tops.to_numpy()
|
|
150
|
+
topo = lookup[np.clip(ci - gi0, 0, lookup.shape[0] - 1)][:, np.clip(cj - gj0, 0, lookup.shape[1] - 1)]
|
|
151
|
+
return DesignGrid(xs, ys, topo, ci, cj, centre_topo)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _floor_raster(blocks: pd.DataFrame, mined: np.ndarray, grid: DesignGrid) -> np.ndarray:
|
|
155
|
+
"""Floor elevation of the mined columns, painted onto the fine grid."""
|
|
156
|
+
dz = float(blocks["dz"].iloc[0])
|
|
157
|
+
gi0, gj0 = int(blocks["gi"].min()), int(blocks["gj"].min())
|
|
158
|
+
floors = blocks[mined].groupby(["gi", "gj"])["z"].min() - dz / 2.0
|
|
159
|
+
lookup = np.full((blocks["gi"].max() - gi0 + 1, blocks["gj"].max() - gj0 + 1), np.inf)
|
|
160
|
+
lookup[floors.index.get_level_values(0) - gi0, floors.index.get_level_values(1) - gj0] = floors.to_numpy()
|
|
161
|
+
ii = np.clip(grid.cell_i - gi0, 0, lookup.shape[0] - 1)
|
|
162
|
+
jj = np.clip(grid.cell_j - gj0, 0, lookup.shape[1] - 1)
|
|
163
|
+
raster = lookup[ii][:, jj]
|
|
164
|
+
outside_i = (grid.cell_i < gi0) | (grid.cell_i - gi0 >= lookup.shape[0])
|
|
165
|
+
outside_j = (grid.cell_j < gj0) | (grid.cell_j - gj0 >= lookup.shape[1])
|
|
166
|
+
raster[outside_i, :] = np.inf
|
|
167
|
+
raster[:, outside_j] = np.inf
|
|
168
|
+
return raster
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _floor_domain_raster(
|
|
172
|
+
blocks: pd.DataFrame, mined: np.ndarray, grid: DesignGrid, dom_to_idx: dict[object, int],
|
|
173
|
+
) -> np.ndarray:
|
|
174
|
+
"""Integer domain index (-1 for unmapped/outside) of the lowest mined block in each column."""
|
|
175
|
+
gi0, gj0 = int(blocks["gi"].min()), int(blocks["gj"].min())
|
|
176
|
+
mined_df = blocks[mined]
|
|
177
|
+
floor_idx = mined_df.groupby(["gi", "gj"])["z"].idxmin()
|
|
178
|
+
floor_blocks = mined_df.loc[floor_idx]
|
|
179
|
+
ni = int(blocks["gi"].max()) - gi0 + 1
|
|
180
|
+
nj = int(blocks["gj"].max()) - gj0 + 1
|
|
181
|
+
lookup = np.full((ni, nj), -1, dtype=int)
|
|
182
|
+
mapped = np.array([dom_to_idx.get(d, -1) for d in floor_blocks["domain"]], dtype=int)
|
|
183
|
+
lookup[floor_blocks["gi"].to_numpy(dtype=int) - gi0, floor_blocks["gj"].to_numpy(dtype=int) - gj0] = mapped
|
|
184
|
+
ii = np.clip(grid.cell_i - gi0, 0, ni - 1)
|
|
185
|
+
jj = np.clip(grid.cell_j - gj0, 0, nj - 1)
|
|
186
|
+
raster = lookup[ii][:, jj]
|
|
187
|
+
outside_i = (grid.cell_i < gi0) | (grid.cell_i - gi0 >= ni)
|
|
188
|
+
outside_j = (grid.cell_j < gj0) | (grid.cell_j - gj0 >= nj)
|
|
189
|
+
raster[outside_i, :] = -1
|
|
190
|
+
raster[:, outside_j] = -1
|
|
191
|
+
return raster
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def _stratified_domain_profile(
|
|
195
|
+
blocks: pd.DataFrame,
|
|
196
|
+
domain_model: pd.DataFrame,
|
|
197
|
+
grid: DesignGrid,
|
|
198
|
+
domain_geometries: dict[object, BenchGeometry],
|
|
199
|
+
default_geometry: BenchGeometry,
|
|
200
|
+
) -> tuple[np.ndarray, np.ndarray, list[BenchGeometry], float]:
|
|
201
|
+
"""Index a conservative model-wide elevation envelope once.
|
|
202
|
+
|
|
203
|
+
Block domains are active only over their vertical cell interval, clipped at
|
|
204
|
+
the local topography. Coverage is checked continuously in every XY column.
|
|
205
|
+
The returned intervals are atomic z bands whose geometry is the flattest
|
|
206
|
+
configured domain present in any covered column in that band. Domain names
|
|
207
|
+
absent from the explicit table use the caller's explicit overall geometry.
|
|
208
|
+
"""
|
|
209
|
+
if not np.isfinite(grid.topo).all():
|
|
210
|
+
raise ValueError("stratified domain design requires finite topography across the design grid")
|
|
211
|
+
dx, dy, dz = (float(blocks[c].iloc[0]) for c in ("dx", "dy", "dz"))
|
|
212
|
+
model_dx, model_dy, model_dz = (float(domain_model[c].iloc[0]) for c in ("dx", "dy", "dz"))
|
|
213
|
+
if not np.allclose((dx, dy, dz), (model_dx, model_dy, model_dz), rtol=0.0, atol=1e-8):
|
|
214
|
+
raise ValueError("domain model block dimensions do not match the designed block model")
|
|
215
|
+
|
|
216
|
+
grid_top: dict[tuple[int, int], float] = {}
|
|
217
|
+
i_values, j_values = np.unique(grid.cell_i), np.unique(grid.cell_j)
|
|
218
|
+
for gi in i_values:
|
|
219
|
+
xi = grid.cell_i == gi
|
|
220
|
+
for gj in j_values:
|
|
221
|
+
yj = grid.cell_j == gj
|
|
222
|
+
samples = grid.topo[np.ix_(xi, yj)]
|
|
223
|
+
if samples.size:
|
|
224
|
+
grid_top[(int(gi), int(gj))] = float(np.max(samples))
|
|
225
|
+
if not grid_top:
|
|
226
|
+
raise ValueError("stratified domain design has no mapped XY columns")
|
|
227
|
+
|
|
228
|
+
# Re-index the full source model against the clipped design grid by block centres.
|
|
229
|
+
# Clipping air must not shift or remove geological cells used by the wall model.
|
|
230
|
+
gi0, gj0 = int(blocks["gi"].min()), int(blocks["gj"].min())
|
|
231
|
+
x0 = float(blocks.loc[blocks["gi"] == gi0, "x"].min())
|
|
232
|
+
y0 = float(blocks.loc[blocks["gj"] == gj0, "y"].min())
|
|
233
|
+
grid_cols = list(grid_top)
|
|
234
|
+
if grid.centre_topo is not None and all(col in grid.centre_topo for col in grid_cols):
|
|
235
|
+
grid_centre_top = {col: grid.centre_topo[col] for col in grid_cols}
|
|
236
|
+
else:
|
|
237
|
+
topo_interp = RegularGridInterpolator((grid.xs, grid.ys), grid.topo, bounds_error=False, fill_value=None)
|
|
238
|
+
centres = np.array([[x0 + (gi - gi0) * dx, y0 + (gj - gj0) * dy] for gi, gj in grid_cols], dtype=float)
|
|
239
|
+
grid_centre_top = {col: float(val) for col, val in zip(grid_cols, topo_interp(centres))}
|
|
240
|
+
model = domain_model.copy()
|
|
241
|
+
mi = np.rint((model["x"].to_numpy(dtype=float) - x0) / dx).astype(int) + gi0
|
|
242
|
+
mj = np.rint((model["y"].to_numpy(dtype=float) - y0) / dy).astype(int) + gj0
|
|
243
|
+
if (np.any(np.abs(model["x"].to_numpy(dtype=float) - (x0 + (mi - gi0) * dx)) > 1e-5)
|
|
244
|
+
or np.any(np.abs(model["y"].to_numpy(dtype=float) - (y0 + (mj - gj0) * dy)) > 1e-5)):
|
|
245
|
+
raise ValueError("domain model block centres are not aligned with the designed block grid")
|
|
246
|
+
model["_gi"], model["_gj"] = mi, mj
|
|
247
|
+
model = model.loc[
|
|
248
|
+
pd.MultiIndex.from_arrays([model["_gi"], model["_gj"]]).isin(grid_top)
|
|
249
|
+
]
|
|
250
|
+
if model.empty:
|
|
251
|
+
raise ValueError("domain model has no columns inside the designed grid")
|
|
252
|
+
|
|
253
|
+
model_bottom = float((model["z"] - dz / 2.0).min())
|
|
254
|
+
events: list[tuple[float, object, int]] = []
|
|
255
|
+
groups = model.groupby(["_gi", "_gj"], sort=False)
|
|
256
|
+
present = set(groups.groups)
|
|
257
|
+
absent = [col for col, top in grid_top.items() if top > model_bottom and col not in present]
|
|
258
|
+
if absent:
|
|
259
|
+
raise ValueError(f"domain model has no data for required XY columns {absent[:3]}")
|
|
260
|
+
|
|
261
|
+
for col, rows in groups:
|
|
262
|
+
topo_rl = grid_top[(int(col[0]), int(col[1]))]
|
|
263
|
+
if topo_rl <= model_bottom:
|
|
264
|
+
continue
|
|
265
|
+
rows = rows.sort_values("z")
|
|
266
|
+
lo = rows["z"].to_numpy(dtype=float) - dz / 2.0
|
|
267
|
+
hi = np.minimum(rows["z"].to_numpy(dtype=float) + dz / 2.0, topo_rl)
|
|
268
|
+
domains = rows["domain"].to_numpy()
|
|
269
|
+
cursor = model_bottom
|
|
270
|
+
last_dom: object = None
|
|
271
|
+
for bottom, top, dom in zip(lo, hi, domains):
|
|
272
|
+
if top <= cursor + 1e-9:
|
|
273
|
+
continue
|
|
274
|
+
if bottom > cursor + 1e-6:
|
|
275
|
+
raise ValueError(f"domain model has a vertical coverage gap in column {col} at RL {cursor:g}")
|
|
276
|
+
if pd.isna(dom):
|
|
277
|
+
raise ValueError(f"stratified domain model contains a missing domain in column {col}")
|
|
278
|
+
effective_bottom = max(bottom, model_bottom)
|
|
279
|
+
events.append((effective_bottom, dom, 1))
|
|
280
|
+
events.append((top, dom, -1))
|
|
281
|
+
cursor = max(cursor, top)
|
|
282
|
+
last_dom = dom
|
|
283
|
+
if cursor >= topo_rl - 1e-6:
|
|
284
|
+
break
|
|
285
|
+
centre_topo = grid_centre_top[(int(col[0]), int(col[1]))]
|
|
286
|
+
required_rl = min(topo_rl, centre_topo)
|
|
287
|
+
if last_dom is None or cursor < required_rl - 1e-6:
|
|
288
|
+
raise ValueError(f"domain model does not reach topography in column {col}: RL {cursor:g} < {required_rl:g}")
|
|
289
|
+
if cursor < topo_rl - 1e-6:
|
|
290
|
+
# A column clipped at its centroid can sit slightly below an uphill subcell corner;
|
|
291
|
+
# carry the surface block's domain up to the column's highest subcell sample.
|
|
292
|
+
events.append((cursor, last_dom, 1))
|
|
293
|
+
events.append((topo_rl, last_dom, -1))
|
|
294
|
+
|
|
295
|
+
events.sort(key=lambda event: event[0])
|
|
296
|
+
active: Counter = Counter()
|
|
297
|
+
starts: list[float] = []
|
|
298
|
+
ends: list[float] = []
|
|
299
|
+
profile: list[BenchGeometry] = []
|
|
300
|
+
max_topo = max(grid_top.values())
|
|
301
|
+
positions = sorted({event[0] for event in events})
|
|
302
|
+
by_rl: dict[float, list[tuple[object, int]]] = {}
|
|
303
|
+
for rl, dom, delta in events:
|
|
304
|
+
by_rl.setdefault(rl, []).append((dom, delta))
|
|
305
|
+
for k, rl in enumerate(positions[:-1]):
|
|
306
|
+
for dom, delta in by_rl[rl]:
|
|
307
|
+
active[dom] += delta
|
|
308
|
+
if active[dom] <= 0:
|
|
309
|
+
del active[dom]
|
|
310
|
+
next_rl = positions[k + 1]
|
|
311
|
+
if next_rl <= rl or not active:
|
|
312
|
+
continue
|
|
313
|
+
geom = min((domain_geometries.get(d, default_geometry) for d in active), key=lambda g: g.overall_angle_deg)
|
|
314
|
+
if profile and profile[-1] == geom and abs(ends[-1] - rl) < 1e-9:
|
|
315
|
+
ends[-1] = next_rl
|
|
316
|
+
else:
|
|
317
|
+
starts.append(rl)
|
|
318
|
+
ends.append(next_rl)
|
|
319
|
+
profile.append(geom)
|
|
320
|
+
return np.asarray(starts), np.asarray(ends), profile, max_topo
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def pit_shell(
|
|
324
|
+
blocks: pd.DataFrame,
|
|
325
|
+
mined: np.ndarray,
|
|
326
|
+
grid: DesignGrid,
|
|
327
|
+
geometry: BenchGeometry,
|
|
328
|
+
domain_geometries: dict[object, BenchGeometry] | None = None,
|
|
329
|
+
*,
|
|
330
|
+
stratified_domains: bool = False,
|
|
331
|
+
domain_model: pd.DataFrame | None = None,
|
|
332
|
+
) -> np.ndarray:
|
|
333
|
+
"""The benched bowl. Walls rise from the edge of the optimised floor —
|
|
334
|
+
the toe sits on the shell's floor boundary, the usual design
|
|
335
|
+
convention — so the design always contains the floor of the shell,
|
|
336
|
+
and the wall material the block steps left behind is reported in the
|
|
337
|
+
reconciliation. `stratified_domains=True` uses one conservative,
|
|
338
|
+
model-wide flattest-domain envelope per elevation band; it is not a
|
|
339
|
+
local 3D geotechnical wall model. Pass the full pre-topography-clipped
|
|
340
|
+
block model as `domain_model` when `blocks` was clipped. Domains omitted
|
|
341
|
+
from `domain_geometries` use the explicit `geometry` overall-slope
|
|
342
|
+
geometry. Geological coverage gaps below topography raise `ValueError`.
|
|
343
|
+
Above topography the profile continues with `geometry`. Growing walls from column centres instead would leave
|
|
344
|
+
a cliff at every cell edge where two floors meet. Infinite where no
|
|
345
|
+
mined column is within reach."""
|
|
346
|
+
floor = _floor_raster(blocks, mined, grid)
|
|
347
|
+
if not np.isfinite(floor).any():
|
|
348
|
+
return floor
|
|
349
|
+
source = floor
|
|
350
|
+
cell = float(grid.xs[1] - grid.xs[0]) if len(grid.xs) > 1 else 1.0
|
|
351
|
+
|
|
352
|
+
# The bench profile only rises with distance, so among all floor
|
|
353
|
+
# columns at one elevation L the lowest wall at x comes from the
|
|
354
|
+
# nearest of them: L + g(distance to the nearest). One Euclidean
|
|
355
|
+
# distance transform per floor level gives that exactly, instead of
|
|
356
|
+
# dilating by every offset in the cone.
|
|
357
|
+
shell = floor.copy()
|
|
358
|
+
if stratified_domains:
|
|
359
|
+
if not domain_geometries:
|
|
360
|
+
raise ValueError("stratified domain design requires block domains and configured domain geometries")
|
|
361
|
+
source_blocks = blocks if domain_model is None else domain_model
|
|
362
|
+
if "domain" not in source_blocks.columns:
|
|
363
|
+
raise ValueError("stratified domain model must contain a domain column")
|
|
364
|
+
height = geometry.bench_height
|
|
365
|
+
profile_starts, profile_ends, profile, z_top = _stratified_domain_profile(
|
|
366
|
+
blocks, source_blocks, grid, domain_geometries, geometry
|
|
367
|
+
)
|
|
368
|
+
max_dist = math.hypot(float(grid.xs[-1] - grid.xs[0]), float(grid.ys[-1] - grid.ys[0]))
|
|
369
|
+
for level in np.unique(source[np.isfinite(source)]):
|
|
370
|
+
at_level = source == level
|
|
371
|
+
distance = ndimage.distance_transform_edt(~at_level, sampling=cell)
|
|
372
|
+
rises = np.zeros_like(distance, dtype=float)
|
|
373
|
+
start = 0.0
|
|
374
|
+
bench = 0
|
|
375
|
+
while start <= max_dist:
|
|
376
|
+
z0 = level + bench * height
|
|
377
|
+
z1 = z0 + height
|
|
378
|
+
if z0 >= z_top:
|
|
379
|
+
# Above ground there is no geological domain to consult. Continue the
|
|
380
|
+
# design object with its explicitly configured non-domain geometry.
|
|
381
|
+
geom = geometry
|
|
382
|
+
elif profile_starts.size:
|
|
383
|
+
first = int(np.searchsorted(profile_ends, z0, side="right"))
|
|
384
|
+
last = int(np.searchsorted(profile_starts, min(z1, z_top), side="left"))
|
|
385
|
+
if first >= last:
|
|
386
|
+
raise ValueError(f"no domain data covers wall interval RL {z0:g} to {min(z1, z_top):g}")
|
|
387
|
+
geom = min(profile[first:last], key=lambda g: g.overall_angle_deg)
|
|
388
|
+
else:
|
|
389
|
+
raise ValueError("stratified domain model has no covered elevation intervals")
|
|
390
|
+
face_end = start + geom.face_run
|
|
391
|
+
face_distance = np.clip(distance - start, 0.0, geom.face_run)
|
|
392
|
+
rises += np.minimum(height, face_distance * math.tan(math.radians(geom.face_angle_deg)))
|
|
393
|
+
rises = np.where(distance >= face_end, height * (bench + 1), rises)
|
|
394
|
+
start = face_end + geom.berm_width
|
|
395
|
+
bench += 1
|
|
396
|
+
np.minimum(shell, level + rises, out=shell)
|
|
397
|
+
return shell
|
|
398
|
+
|
|
399
|
+
if domain_geometries and "domain" in blocks.columns:
|
|
400
|
+
dom_keys = list(domain_geometries.keys())
|
|
401
|
+
dom_to_idx = {k: idx for idx, k in enumerate(dom_keys)}
|
|
402
|
+
floor_dom = _floor_domain_raster(blocks, mined, grid, dom_to_idx)
|
|
403
|
+
for level in np.unique(source[np.isfinite(source)]):
|
|
404
|
+
at_level = source == level
|
|
405
|
+
for d_idx in np.unique(floor_dom[at_level]):
|
|
406
|
+
geom = geometry if d_idx < 0 else domain_geometries[dom_keys[int(d_idx)]]
|
|
407
|
+
distance = ndimage.distance_transform_edt(~(at_level & (floor_dom == d_idx)), sampling=cell)
|
|
408
|
+
np.minimum(shell, level + geom.rise(distance), out=shell)
|
|
409
|
+
return shell
|
|
410
|
+
|
|
411
|
+
for level in np.unique(source[np.isfinite(source)]):
|
|
412
|
+
distance = ndimage.distance_transform_edt(source != level, sampling=cell)
|
|
413
|
+
np.minimum(shell, level + geometry.rise(distance), out=shell)
|
|
414
|
+
return shell
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
def face_position(shell: np.ndarray, grid: DesignGrid) -> np.ndarray:
|
|
418
|
+
"""The bowl clipped by topography: the ground after mining."""
|
|
419
|
+
return np.fmin(grid.topo, shell)
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
def shell_for_display(shell: np.ndarray, grid: DesignGrid, geometry: BenchGeometry) -> np.ndarray:
|
|
423
|
+
"""The bowl up to one bench above the highest ground, NaN beyond — the
|
|
424
|
+
walls stop where there is nothing left to cut."""
|
|
425
|
+
ceiling = float(np.nanmax(grid.topo)) + geometry.bench_height
|
|
426
|
+
return np.where(shell <= ceiling, shell, np.nan)
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
def design_fraction(blocks: pd.DataFrame, face: np.ndarray, grid: DesignGrid) -> np.ndarray:
|
|
430
|
+
"""Share of each block's volume that the design mines: the part of the block between the designed face
|
|
431
|
+
position and the topography, sampled over the block footprint on the design grid.
|
|
432
|
+
|
|
433
|
+
The share is of the block's full extent, capped by the topography, so it reproduces the integral of
|
|
434
|
+
(topography - face) over the design grid; the earlier tempting "share of the material below the topography"
|
|
435
|
+
overcounted a block that sits half above ground by a factor of two (+16% instead of +5% on the tin example).
|
|
436
|
+
|
|
437
|
+
Testing only the block centre against the surface (the earlier rule) is a one-point sample of a surface
|
|
438
|
+
that steps by whole benches; on a small pit it moved the design volume by 13% either way against the
|
|
439
|
+
integral of the very surface written to DXF. Sampling the footprint reproduces that integral."""
|
|
440
|
+
cell = float(grid.xs[1] - grid.xs[0]) if len(grid.xs) > 1 else 1.0
|
|
441
|
+
dx, dy, dz = (float(blocks[c].iloc[0]) for c in ("dx", "dy", "dz"))
|
|
442
|
+
nx, ny = max(1, int(round(dx / cell))), max(1, int(round(dy / cell)))
|
|
443
|
+
x, y, z = blocks["x"].to_numpy(), blocks["y"].to_numpy(), blocks["z"].to_numpy()
|
|
444
|
+
top, bottom = z + dz / 2, z - dz / 2
|
|
445
|
+
total = np.zeros(len(blocks))
|
|
446
|
+
for a in (np.arange(nx) + 0.5) / nx - 0.5:
|
|
447
|
+
for b in (np.arange(ny) + 0.5) / ny - 0.5:
|
|
448
|
+
ix = np.clip(np.round((x + a * dx - grid.xs[0]) / cell).astype(int), 0, len(grid.xs) - 1)
|
|
449
|
+
iy = np.clip(np.round((y + b * dy - grid.ys[0]) / cell).astype(int), 0, len(grid.ys) - 1)
|
|
450
|
+
upper = np.minimum(top, grid.topo[ix, iy]) # nothing is mined above the topography
|
|
451
|
+
lower = np.maximum(bottom, face[ix, iy])
|
|
452
|
+
total += np.clip((upper - lower) / dz, 0.0, 1.0)
|
|
453
|
+
return np.nan_to_num(total / (nx * ny))
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
def reconcile(blocks: pd.DataFrame, optimised: np.ndarray, face: np.ndarray, grid: DesignGrid) -> tuple[np.ndarray, dict]:
|
|
457
|
+
"""What the design mines against the optimiser shell. Returns (fraction of each block mined, summary);
|
|
458
|
+
design totals are the block totals weighted by that fraction, shell totals count whole blocks."""
|
|
459
|
+
fraction = design_fraction(blocks, face, grid)
|
|
460
|
+
|
|
461
|
+
def totals(weight: np.ndarray) -> dict:
|
|
462
|
+
ore = (blocks["destination"] == 1).to_numpy()
|
|
463
|
+
return {
|
|
464
|
+
"blocks": int(round(float(weight.sum()))),
|
|
465
|
+
"rock_tonnes": float((blocks["rock_tonnes"].to_numpy() * weight).sum()),
|
|
466
|
+
"ore_tonnes": float((blocks["ore_tonnes"].to_numpy() * weight * ore).sum()),
|
|
467
|
+
"value": float((blocks["value"].to_numpy() * weight).sum()),
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
shell_totals, design_totals = totals(optimised.astype(float)), totals(fraction)
|
|
471
|
+
summary = {"shell": shell_totals, "design": design_totals}
|
|
472
|
+
for key in ("rock_tonnes", "ore_tonnes", "value"):
|
|
473
|
+
base = shell_totals[key]
|
|
474
|
+
summary[f"{key}_change"] = (design_totals[key] - base) / base if base else float("nan")
|
|
475
|
+
return fraction, summary
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Overall slope angle, with and without the haul road.
|
|
3
|
+
|
|
4
|
+
The overall angle is the wall angle from the floor to the crest with every
|
|
5
|
+
berm counted in. It is flatter than the inter-ramp angle wherever the road
|
|
6
|
+
crosses, because the road takes a berm's place at a width wider than the
|
|
7
|
+
berm and the wall has to stand back by the difference:
|
|
8
|
+
|
|
9
|
+
OSA(bearing) = atan( depth / (wall width + crossings * (road - berm)) )
|
|
10
|
+
|
|
11
|
+
Two numbers are produced for each sector and kept apart. The measured one
|
|
12
|
+
reads the wall width and the road crossings off the geometry that was
|
|
13
|
+
actually built, along rays from the floor's centre. The analytic one is the
|
|
14
|
+
closed form from the sector's own bench parameters. On a regular pit they
|
|
15
|
+
agree; where they do not, the gap is reported instead of being averaged
|
|
16
|
+
away, because it says the wall is not doing what the parameters intended.
|
|
17
|
+
The worst angle in a sector decides its status: the steepest wall is the one
|
|
18
|
+
that has to meet the limit.
|
|
19
|
+
"""
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import math
|
|
23
|
+
from dataclasses import dataclass
|
|
24
|
+
|
|
25
|
+
import numpy as np
|
|
26
|
+
|
|
27
|
+
from .config import DesignLimitsConfig
|
|
28
|
+
from .parameters import SectorGeometry, angle_status
|
|
29
|
+
from .ramp import AZIMUTHS, Ramp, RingTable
|
|
30
|
+
from .stack import BenchStack
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass
|
|
34
|
+
class SectorOSA:
|
|
35
|
+
name: str
|
|
36
|
+
osa_no_ramp_deg: float # steepest angle in the sector, road ignored
|
|
37
|
+
osa_deg: float # steepest angle in the sector with the road
|
|
38
|
+
worst_azimuth_deg: float
|
|
39
|
+
crossings_max: int # most times the road crosses one bearing in the sector
|
|
40
|
+
analytic_no_ramp_deg: float # closed form from the sector's bench parameters
|
|
41
|
+
osa_max_deg: float | None
|
|
42
|
+
status: str
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def analytic_gap_deg(self) -> float:
|
|
46
|
+
"""Measured minus analytic, road ignored."""
|
|
47
|
+
return self.osa_no_ramp_deg - self.analytic_no_ramp_deg
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def margin_deg(self) -> float | None:
|
|
51
|
+
return None if self.osa_max_deg is None else self.osa_max_deg - self.osa_deg
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def sector_mask(sector: SectorGeometry, azimuths: np.ndarray) -> np.ndarray:
|
|
55
|
+
length = (sector.azimuth_to - sector.azimuth_from) % 360.0 or 360.0
|
|
56
|
+
return ((azimuths - sector.azimuth_from) % 360.0) < length
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def crossings(ramp: Ramp, azimuths: np.ndarray) -> np.ndarray:
|
|
60
|
+
"""How many times the road passes each bearing.
|
|
61
|
+
|
|
62
|
+
The road's bearing keeps counting past 360 as it goes round, so a
|
|
63
|
+
bearing is crossed once per turn: every segment of the polyline that
|
|
64
|
+
spans a bearing, plus a whole number of turns, is one crossing."""
|
|
65
|
+
if len(ramp.azimuth) < 2:
|
|
66
|
+
return np.zeros(len(azimuths), dtype=int)
|
|
67
|
+
a, b = ramp.azimuth[:-1], ramp.azimuth[1:]
|
|
68
|
+
lo, hi = np.minimum(a, b), np.maximum(a, b)
|
|
69
|
+
low_turn, high_turn = int(math.floor(lo.min() / 360.0)) - 1, int(math.ceil(hi.max() / 360.0)) + 1
|
|
70
|
+
count = np.zeros(len(azimuths), dtype=int)
|
|
71
|
+
for turn in range(low_turn, high_turn + 1):
|
|
72
|
+
shifted = (azimuths + 360.0 * turn)[:, None]
|
|
73
|
+
count += ((shifted > lo[None, :]) & (shifted <= hi[None, :])).sum(axis=1)
|
|
74
|
+
return count
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def sector_osa(stack: BenchStack, ramp: Ramp | None, top: RingTable, floor: RingTable,
|
|
78
|
+
limits: DesignLimitsConfig) -> list[SectorOSA]:
|
|
79
|
+
depth = stack.benches[0].crest_rl - stack.benches[-1].toe_rl
|
|
80
|
+
width = top.radius - floor.radius # wall width at each bearing, berms included
|
|
81
|
+
n = len(stack.benches)
|
|
82
|
+
cross = crossings(ramp, AZIMUTHS) if ramp is not None else np.zeros(len(AZIMUTHS), dtype=int)
|
|
83
|
+
road = ramp.sizing.width_m if ramp is not None else 0.0
|
|
84
|
+
|
|
85
|
+
out = []
|
|
86
|
+
for sector in stack.sectors:
|
|
87
|
+
mask = sector_mask(sector, AZIMUTHS) & np.isfinite(width)
|
|
88
|
+
if not mask.any():
|
|
89
|
+
continue
|
|
90
|
+
extra = cross * max(0.0, road - sector.berm_width)
|
|
91
|
+
without = np.degrees(np.arctan2(depth, width[mask]))
|
|
92
|
+
with_road = np.degrees(np.arctan2(depth, width[mask] + extra[mask]))
|
|
93
|
+
worst = int(np.argmax(with_road))
|
|
94
|
+
analytic = math.degrees(math.atan2(depth, sector.toe_offset(n - 1)))
|
|
95
|
+
out.append(SectorOSA(
|
|
96
|
+
sector.name, float(without.max()), float(with_road[worst]), float(AZIMUTHS[mask][worst]),
|
|
97
|
+
int(cross[mask].max()), analytic, sector.osa_max_deg,
|
|
98
|
+
angle_status(float(with_road[worst]), sector.osa_max_deg, limits.warn_margin_deg),
|
|
99
|
+
))
|
|
100
|
+
return out
|