Skip to content

Commit dbfba85

Browse files
committed
fix(loop-link): send drillhole interval data as log set arrays
The viewer reads drillhole interval values only from arrays with the association interval that belong to a log set. The encoder sent cell, so the viewer accepted the data but did not offer it for colour. Send interval with the log set intervals. The fake viewer now refuses cell on a drillhole. Record the results of the manual checks M1 and M2 and add the 006 row to the spec index.
1 parent e3b264f commit dbfba85

6 files changed

Lines changed: 123 additions & 24 deletions

File tree

‎packages/loop_link/src/loop_link/encode.py‎

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
_I32_MIN = -(2**31)
3939
_I32_MAX = 2**31 - 1
4040

41+
# The name of the log set that holds the interval properties of a Drillhole.
42+
_INTERVAL_LOG_SET = "intervals"
43+
4144
Buffers = list[tuple[str, np.ndarray]]
4245

4346

@@ -207,7 +210,9 @@ def _declared_bytes(name: str, value: object) -> int:
207210
return 0
208211

209212

210-
def _data_array(name: str, value: object, association: str) -> tuple[dict[str, Any], Buffers]:
213+
def _data_array(
214+
name: str, value: object, association: str, log_set: str | None = None
215+
) -> tuple[dict[str, Any], Buffers]:
211216
"""Return the data description and the buffers of one property.
212217
213218
Parameters
@@ -217,8 +222,13 @@ def _data_array(name: str, value: object, association: str) -> tuple[dict[str, A
217222
value : numpy.ndarray or Categorical
218223
The values.
219224
association : str
220-
``"vertex"`` or ``"cell"``. For a Drillhole, ``"vertex"`` has one value for each
221-
survey station and ``"cell"`` has one value for each row of ``intervals``.
225+
``"vertex"``, ``"cell"`` or ``"interval"``. For a Drillhole, ``"vertex"`` has one
226+
value for each survey station and ``"interval"`` has one value for each row of
227+
``intervals``. An ``"interval"`` array belongs to a log set. ``"cell"`` is for
228+
the other object types.
229+
log_set : str or None
230+
The name of the log set of an ``"interval"`` array. The function writes it to
231+
the data description as ``log_set``. Use ``None`` for the other associations.
222232
223233
Returns
224234
-------
@@ -239,6 +249,8 @@ def _data_array(name: str, value: object, association: str) -> tuple[dict[str, A
239249
"buffer": buffer_name,
240250
"association": association,
241251
}
252+
if log_set is not None:
253+
desc["log_set"] = log_set
242254
if isinstance(value, Categorical):
243255
codes = np.asarray(value.codes).astype(np.uint32, copy=False)
244256
colours = value.colours
@@ -357,18 +369,22 @@ def add_index(self, role: str, array: object) -> None:
357369
self.reserve(int(view.size) * 4)
358370
self.add_geometry(role, view.astype(np.uint32, copy=False))
359371

360-
def add_property(self, name: str, value: object, association: str) -> None:
361-
"""Add a property with its buffers."""
372+
def add_property(
373+
self, name: str, value: object, association: str, log_set: str | None = None
374+
) -> None:
375+
"""Add a property with its buffers. A log set name is optional."""
362376
self.reserve(_declared_bytes(name, value))
363-
desc, buffers = _data_array(name, value, association)
377+
desc, buffers = _data_array(name, value, association, log_set)
364378
for buffer_name, array in buffers:
365379
self.add_buffer(buffer_name, array)
366380
self.data.append(desc)
367381

368-
def add_properties(self, props: Mapping[str, object], association: str) -> None:
369-
"""Add a mapping of properties."""
382+
def add_properties(
383+
self, props: Mapping[str, object], association: str, log_set: str | None = None
384+
) -> None:
385+
"""Add a mapping of properties. A log set name is optional."""
370386
for name, value in props.items():
371-
self.add_property(name, value, association)
387+
self.add_property(name, value, association, log_set)
372388

373389
def add_pair_group(self, role: str, names: tuple[str, str], pair: Sequence[object]) -> None:
374390
"""Add a property group of two float arrays, such as orientation."""
@@ -437,6 +453,7 @@ def encode_object(
437453
raise InvalidInputError("The origin must be three finite numbers. Check the input.")
438454
builder = _Builder(id, origin_arr)
439455
params: dict[str, Any] = {}
456+
log_sets: list[dict[str, str]] = []
440457
if isinstance(obj, Drillhole):
441458
object_type = "Drillhole"
442459
builder.reserve(
@@ -449,7 +466,9 @@ def encode_object(
449466
if obj.end_of_hole is not None:
450467
params["end_of_hole"] = [float(obj.end_of_hole)]
451468
builder.add_properties(obj.properties, "vertex")
452-
builder.add_properties(obj.interval_properties, "cell")
469+
if obj.interval_properties:
470+
log_sets.append({"name": _INTERVAL_LOG_SET, "kind": "interval"})
471+
builder.add_properties(obj.interval_properties, "interval", _INTERVAL_LOG_SET)
453472
elif isinstance(obj, BlockModel):
454473
object_type = "BlockModel"
455474
shifted = _finite_f64(obj.origin, "origin") - origin_arr
@@ -490,6 +509,8 @@ def encode_object(
490509
header["params"] = params
491510
header["data"] = builder.data
492511
header["property_groups"] = builder.groups
512+
if log_sets:
513+
header["log_sets"] = log_sets
493514
try:
494515
return protocol.encode_frame(header, builder.buffers)
495516
except protocol.ProtocolError as error:

‎packages/loop_link/src/loop_link/testing/fake_viewer.py‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,6 @@ def _expected_length(
194194
if object_type == "Drillhole":
195195
if association == "vertex" and "survey" in arrays:
196196
return arrays["survey"].shape[0]
197-
if association == "cell" and "intervals" in arrays:
198-
return arrays["intervals"].shape[0]
199197
has_set = isinstance(log_sets, list) and any(
200198
isinstance(item, dict) and item.get("kind") == "interval" for item in log_sets
201199
)
@@ -218,7 +216,10 @@ def _check_data(
218216
params: object,
219217
log_sets: object = None,
220218
) -> str | None:
221-
"""Return the text of a problem in one data array entry, or ``None``."""
219+
"""Return the text of a problem in one data array entry, or ``None``.
220+
221+
An ``interval`` array must name a log set of kind ``interval`` in ``log_set``.
222+
"""
222223
if not isinstance(entry, dict):
223224
return "A data entry is not an object."
224225
name = entry.get("buffer")
@@ -227,6 +228,18 @@ def _check_data(
227228
association = entry.get("association")
228229
if association not in ("vertex", "cell", "interval"):
229230
return f"The association {association!r} is not known."
231+
if association == "interval":
232+
log_set = entry.get("log_set")
233+
kinds = {
234+
item.get("name"): item.get("kind")
235+
for item in (log_sets if isinstance(log_sets, list) else [])
236+
if isinstance(item, dict)
237+
}
238+
if kinds.get(log_set) != "interval":
239+
return (
240+
f"The interval array {name!r} names the log set {log_set!r}. "
241+
"It needs a log set of kind 'interval' in 'log_sets'."
242+
)
230243
length = buffers[name].shape[0] if buffers[name].ndim else 0
231244
if entry.get("data_type") == "text":
232245
offsets_name = entry.get("offsets")

‎packages/loop_link/tests/manual_checks.md‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ from loop_link.objects import BlockModel, Drillhole, Lines, Points, Surface, Tet
6161
from loop_link.viewer import Viewer
6262

6363
grade3 = [1.0, 2.0, 3.0]
64-
tri = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
64+
tri = [[0, 0, 0], [100, 0, 0], [0, 100, 0]] # 100 units: the default glyph size is 1 percent of the object
6565
objects = {
6666
"points": Points(tri, {"grade": grade3}),
6767
"vectors": Vectors.from_directions(tri, [[0, 0, 1]] * 3, kind="normal",
6868
properties={"grade": grade3}),
6969
"lines": Lines(tri, [[0, 1], [1, 2]], {"grade": grade3}),
7070
"surface": Surface(tri, [[0, 1, 2]], {"grade": grade3}),
71-
"block": BlockModel((0, 0, 0), (1, 1, 1), (2, 2, 2), cell_properties={"grade": [1.0] * 8}),
72-
"tetra": TetraMesh(tri + [[0, 0, 1]], [[0, 1, 2, 3]], {"grade": [1.0, 2.0, 3.0, 4.0]}),
73-
"drillhole": Drillhole([0, 0, 0], [[0, 0, 90], [10, 0, 90]], [[0, 5], [5, 10]],
71+
"block": BlockModel((0, 0, 0), (50, 50, 50), (2, 2, 2), cell_properties={"grade": [1.0] * 8}),
72+
"tetra": TetraMesh(tri + [[0, 0, 100]], [[0, 1, 2, 3]], {"grade": [1.0, 2.0, 3.0, 4.0]}),
73+
"drillhole": Drillhole([0, 0, 0], [[0, 0, 90], [100, 0, 90]], [[0, 50], [50, 100]],
7474
interval_properties={"grade": [1.0, 2.0]}),
7575
}
7676

@@ -84,6 +84,19 @@ viewer.release_data()
8484
5. Run the script. Type `packages/loop_link/.venv/Scripts/python.exe <script path>` and press Enter.
8585
6. Check that seven objects show in the object list. Check that the types are: points, vectors, lines, surface, block model, tetra mesh and drillhole.
8686
7. Select each object, one at a time. Check that the property name `grade` shows in the property table.
87+
A tetra mesh has no Data button: use the isosurface or the filter controls to check `grade`.
88+
The vectors show as flat discs that face up (+z).
8789
8. Write the result in your test record.
8890

8991
Pass: seven objects show, each with the right type, and the property name `grade` shows in the property table for each object.
92+
93+
## Record
94+
95+
2026-11-07, window viewer of the geoviewer build with selection and fetch, token from the user:
96+
97+
- M1: pass. The grid was in the inventory 0.43 s after the send (limit 5 s). It ran against the window viewer, not the headless viewer.
98+
- M2: pass after one fix.
99+
- Drillhole `grade` was not selectable. The viewer reads drillhole interval values only from arrays with association `interval` in a log set. The encoder sent `cell`. It now sends `interval` with the log set `intervals`.
100+
- Tetra mesh `grade` works through the isosurface. The viewer has no Data button for a tetra mesh.
101+
- Vectors were too small to see on a 1 unit triangle (glyph size default is 1 percent of the object). They work on a 100 unit triangle.
102+
- Open viewer issue: the vector glyphs and the drillhole tubes look pixelated (geoviewer issue 181).

‎packages/loop_link/tests/test_encode.py‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,31 @@ def test_drillhole_interval_property_association():
166166
)
167167
frame = _encode(hole)
168168
assert _data_entry(frame, "az")["association"] == "vertex"
169-
assert _data_entry(frame, "lith")["association"] == "cell"
169+
assert _data_entry(frame, "lith")["association"] == "interval"
170170
assert frame.buffers["data/lith"].tolist() == [3.0, 4.0]
171171

172172

173+
def test_drillhole_with_interval_properties_has_log_sets():
174+
hole = Drillhole(
175+
[0, 0, 0],
176+
[[0, 0, 0], [10, 0, 0]],
177+
[[0, 1], [1, 2]],
178+
properties={"az": np.array([1.0, 2.0])},
179+
interval_properties={"lith": np.array([3.0, 4.0]), "g": np.array([1.0, 2.0])},
180+
)
181+
frame = _encode(hole)
182+
assert frame.header["log_sets"] == [{"name": "intervals", "kind": "interval"}]
183+
for name in ("lith", "g"):
184+
assert _data_entry(frame, name)["log_set"] == "intervals"
185+
assert "log_set" not in _data_entry(frame, "az")
186+
assert frame.header["geometry"]["intervals"] == "geometry/intervals"
187+
188+
189+
def test_drillhole_without_interval_properties_has_no_log_sets():
190+
frame = _encode(Drillhole([0, 0, 0], [[0, 0, 0]], [[0, 1]], properties={"a": np.zeros(1)}))
191+
assert "log_sets" not in frame.header
192+
193+
173194
def test_vertices_are_f32_after_shift_in_f64():
174195
# The shift must happen in f64. A shift in f32 would lose the small digits.
175196
origin = (500000.0, 7000000.0, 0.0)
@@ -504,6 +525,6 @@ def test_drillhole_property_lengths():
504525
)
505526
frame = _encode(hole)
506527
assert _data_entry(frame, "s")["association"] == "vertex"
507-
assert _data_entry(frame, "i")["association"] == "cell"
528+
assert _data_entry(frame, "i")["association"] == "interval"
508529
assert frame.buffers["data/s"].shape == (3,)
509530
assert frame.buffers["data/i"].shape == (2,)

‎packages/loop_link/tests/test_fake_viewer.py‎

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,33 @@ def points_frame(data: list[dict[str, Any]], groups: list[dict[str, Any]] | None
5555
return encode_frame(header, buffers)
5656

5757

58-
def drillhole_frame(association: str, log_sets: list[dict[str, Any]] | None = None) -> bytes:
58+
def drillhole_frame(
59+
association: str,
60+
log_sets: list[dict[str, Any]] | None = None,
61+
log_set: str | None = None,
62+
length: int = 2,
63+
) -> bytes:
5964
"""Return a hand-made Drillhole frame with a data array."""
6065
header = {
6166
"type": "scene.upsert",
6267
"id": "h",
6368
"object_type": "Drillhole",
6469
"revision": 1,
6570
"geometry": {"collar": "c", "survey": "s", "intervals": "i"},
66-
"data": [entry("x", association)],
71+
"data": [entry("x", association, **({"log_set": log_set} if log_set else {}))],
6772
"log_sets": log_sets or [],
6873
}
6974
buffers = [
7075
("c", np.zeros(3, dtype=np.float32)),
7176
("s", np.zeros((3, 3), dtype=np.float32)),
7277
("i", np.zeros((2, 2), dtype=np.float32)),
73-
("x", np.zeros(2, dtype=np.float32)),
78+
("x", np.zeros(length, dtype=np.float32)),
7479
]
7580
return encode_frame(header, buffers)
7681

7782

7883
def test_drillhole_with_interval_properties_is_accepted(fake: Any) -> None:
79-
"""The encoder sends interval properties as cell arrays. The viewer accepts them."""
84+
"""The encoder sends interval properties as interval arrays. The viewer accepts them."""
8085
hole = Drillhole(
8186
collar=[0.0, 0.0, 0.0],
8287
survey=[[0.0, 0.0, 0.0], [10.0, 0.0, -90.0]],
@@ -87,15 +92,40 @@ def test_drillhole_with_interval_properties_is_accepted(fake: Any) -> None:
8792
data = encode_object(hole, id="h", name=None, parent=None, revision=1, origin=(0.0, 0.0, 0.0))
8893
assert fake.accept_frame(data) == []
8994
assert "h" in fake.objects
95+
header = fake.objects["h"].header
96+
assert header["log_sets"] == [{"name": "intervals", "kind": "interval"}]
97+
assert {e["association"] for e in header["data"] if e["name"] == "grade"} == {"interval"}
9098

9199

92100
def test_interval_array_without_log_sets_is_refused(fake: Any) -> None:
93101
"""An interval association needs a log set of kind interval."""
94102
assert codes(fake.accept_frame(drillhole_frame("interval"))) == ["invalid_object"]
95-
with_set = drillhole_frame("interval", [{"name": "main", "kind": "interval"}])
103+
no_name = drillhole_frame("interval", [{"name": "main", "kind": "interval"}])
104+
assert codes(fake.accept_frame(no_name)) == ["invalid_object"]
105+
with_set = drillhole_frame("interval", [{"name": "main", "kind": "interval"}], "main")
96106
assert fake.accept_frame(with_set) == []
97107

98108

109+
def test_interval_array_with_unknown_or_wrong_kind_log_set_is_refused(fake: Any) -> None:
110+
"""The log set of an interval array must exist and must have the kind interval."""
111+
sets = [{"name": "main", "kind": "interval"}]
112+
assert codes(fake.accept_frame(drillhole_frame("interval", sets, "other"))) == [
113+
"invalid_object"
114+
]
115+
point = [{"name": "main", "kind": "point"}]
116+
assert codes(fake.accept_frame(drillhole_frame("interval", point, "main"))) == [
117+
"invalid_object"
118+
]
119+
120+
121+
def test_interval_array_with_wrong_length_is_refused(fake: Any) -> None:
122+
"""An interval array needs one value for each row of intervals."""
123+
sets = [{"name": "main", "kind": "interval"}]
124+
assert codes(fake.accept_frame(drillhole_frame("interval", sets, "main", 3))) == [
125+
"invalid_object"
126+
]
127+
128+
99129
def test_group_naming_missing_array_is_refused(fake: Any) -> None:
100130
"""A property group member must name an array of the message."""
101131
group = {

‎specs/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ not certify that an implementation or a numerical acceptance gate passed.
1010
| [003-fault-evaluation-performance](003-fault-evaluation-performance/spec.md) | Implementation in progress; 005 contract cascade applied | Its active plan and tasks remain in the existing LoopStructural-native worktree. OP3 and OP4 remain open; completed tasks, including concurrent T043, and measured failures are preserved. |
1111
| [004-matrix-free-directional-constraints](004-matrix-free-directional-constraints/spec.md) | Draft; 005 contract cascade applied; task graph checked | Review the updated plan and tasks. OP1 still requires the quadrature measurements before a default is chosen. |
1212
| [005-coordinate-frame-correctness](005-coordinate-frame-correctness/spec.md) | S1 implemented 2026-11-04 on `feat/005-coordinate-frame-correctness` (17 of 17 tasks; evidence in [verification.md](005-coordinate-frame-correctness/verification.md)); S5 planned 2026-11-05 and revised after review; S6 not planned | Review and merge the S1 branch. S2 planned and tasked 2026-11-04 (T018 to T031, waves 8 to 13); run spec-orchestrator for S2. S3 planned and tasked 2026-11-05 ("Stage S3 design" in plan.md; OP4 and OP5 closed; T033 to T050, waves 14 to 22; build after S2 merges). S3 is built on `feat/005-s3-frame-persistence` (pull request #397, stacked on #396; 18 of 18 tasks, evidence in verification.md). S3 merged (#397); a follow-up keeps the legacy load backward compatible (pull request #400). S4 planned and tasked 2026-11-05 ("Stage S4 design" in plan.md; OP8 to OP10 have defaults and block nothing; T051 to T068, waves 23 to 31); run spec-orchestrator for S4. S5 planned 2026-11-05 and revised the same day after review and five maintainer answers ("Stage S5 design" in plan.md; OP13 to OP15 closed; OP12, OP16 and OP17 have defaults; OP17 blocks the S5 merge only if a parity file changes); S5 tasked 2026-11-05 (T069 to T088, waves 32 to 42; no open point blocks a task; build after S4 merges). OP1: plan S6 in a later planner run. OP3: constant-norm accuracy check. OP2 closed 2026-11-04: the R2/R5 matrix stays in the default pytest run. 7 minor review findings are open (run-state.json). |
13+
| [006-loop-link](006-loop-link/spec.md) | S1 to S3 (stories 1 and 5) implemented 2026-11-07 on `feat/006-loop-link` (37 of 37 tasks, 13 waves; wave and end reviews passed; not merged) | Open a pull request. OP6: plan S4 (stories 6, 7). OP7: plan S5 (stories 2 to 4) after geoviewer spec 066-selection-and-fetch lands. Run manual checks M1 and M2 against the real viewer. |
1314

1415
## Cascade of 005
1516

0 commit comments

Comments
 (0)