From 94d6109bda289e6cf8c6c858082491c75663faae Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 19 May 2026 09:26:30 +0100 Subject: [PATCH] Move LOD JSON behind diagnostics --- docs/implementation-plan.md | 4 ++-- docs/sensor-fusion-architecture.md | 10 +++++++++- localcast/diagnostics/lod_json.py | 11 +++++++++++ localcast/sensor_fusion/stochastic_mapping.py | 6 ------ scripts/diagnostic_live_sensor_fusion.py | 6 ++++-- state/evidence.jsonl | 1 + state/map.yaml | 8 +++++--- tests/test_stochastic_mapping.py | 3 ++- 8 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 localcast/diagnostics/lod_json.py diff --git a/docs/implementation-plan.md b/docs/implementation-plan.md index 2c4bbae..6dba551 100644 --- a/docs/implementation-plan.md +++ b/docs/implementation-plan.md @@ -103,8 +103,8 @@ shape removes independent per-kind storage from the live foundation. ## Next 1. Delete remaining production dependence on `scripts/diagnostic_live_sensor_fusion.py`, - `localcast.diagnostics.spout_output`, JSON render-frame stores, JSON LOD - stores, and Python reservoir-window clipping. + `localcast.diagnostics.spout_output`, diagnostic JSON render-frame adapters, + diagnostic JSON LOD adapters, and Python reservoir-window clipping. 2. Bind Aquarium/Faust to the rolling-buffer `LocalcastRuntime`. 3. Move camera/mic/loopback ingest into native capture workers that append typed sample handles. diff --git a/docs/sensor-fusion-architecture.md b/docs/sensor-fusion-architecture.md index cde959f..8cdf8b6 100644 --- a/docs/sensor-fusion-architecture.md +++ b/docs/sensor-fusion-architecture.md @@ -101,7 +101,15 @@ sensor observation The cache is not a bucket. `TrackCache` has a TTL and confidence update rule so the system can buffer and converge without pretending stale points are fresh. The live frame reservoir is explicitly five seconds wide: frame history expires from the newest shared sample, LOD evidence is clipped to that same interval, and each `RenderFramePacket` reports the exact source window. Later GPU buffers should mirror this shape: observation SoA, track SoA, material/BRDF estimate SoA, brush packet SoA. -`visual-lod-cache.json` is the current CPU-authored shape for the next compute pass. It is not the final renderer. It groups stochastic/fused scene claims into multiple world-space voxel sizes, carrying center, radius, confidence, count, source-time bounds, and first-pass material estimates. The material channel is deliberately modest: weighted albedo plus roughness/metallic hints so Aquarium can start relighting brush/splat packets without treating screen-space color as the whole truth. A later shader pass should replace those hints with multi-view BRDF fitting inside the same reservoir. +`visual-lod-cache.json` is the diagnostic CPU-authored shape for the next +compute pass. JSON serialization lives under `localcast.diagnostics.lod_json`, +not in the mapping model. It groups stochastic/fused scene claims into multiple +world-space voxel sizes, carrying center, radius, confidence, count, source-time +bounds, and first-pass material estimates. The material channel is deliberately +modest: weighted albedo plus roughness/metallic hints so Aquarium can start +relighting brush/splat packets without treating screen-space color as the whole +truth. A later shader pass should replace those hints with multi-view BRDF +fitting inside the same reservoir. ## Test Boundaries diff --git a/localcast/diagnostics/lod_json.py b/localcast/diagnostics/lod_json.py new file mode 100644 index 0000000..3949086 --- /dev/null +++ b/localcast/diagnostics/lod_json.py @@ -0,0 +1,11 @@ +from __future__ import annotations + +import json +from pathlib import Path + +from localcast.sensor_fusion.stochastic_mapping import MultiLODSceneCache + + +def write_lod_cache_json(path: Path, cache: MultiLODSceneCache) -> None: + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(json.dumps(cache.to_dict(), indent=2), encoding="utf-8") diff --git a/localcast/sensor_fusion/stochastic_mapping.py b/localcast/sensor_fusion/stochastic_mapping.py index 7480a82..b1c720c 100644 --- a/localcast/sensor_fusion/stochastic_mapping.py +++ b/localcast/sensor_fusion/stochastic_mapping.py @@ -1,8 +1,6 @@ from __future__ import annotations from dataclasses import dataclass, field -import json -from pathlib import Path from typing import Iterable, Sequence import numpy as np @@ -136,10 +134,6 @@ class MultiLODSceneCache: ], } - def write_json(self, path: Path) -> None: - path.parent.mkdir(parents=True, exist_ok=True) - path.write_text(json.dumps(self.to_dict(), indent=2), encoding="utf-8") - def pixel_scene_ray(camera: CameraModel, uv: np.ndarray, timestamp_ns: int, confidence: float = 1.0) -> SceneRay: point = np.asarray([float(uv[0]), float(uv[1]), 1.0], dtype=np.float64) diff --git a/scripts/diagnostic_live_sensor_fusion.py b/scripts/diagnostic_live_sensor_fusion.py index 5e4f76c..560c3a8 100644 --- a/scripts/diagnostic_live_sensor_fusion.py +++ b/scripts/diagnostic_live_sensor_fusion.py @@ -46,6 +46,7 @@ from localcast.diagnostics.visual_cache import ( put_live_clap_events, put_live_render_frame, ) +from localcast.diagnostics.lod_json import write_lod_cache_json from localcast.sensor_fusion.camera_control import AdaptiveCameraController, OpenCvCameraSettingPort from localcast.sensor_fusion.adapters import LatestFramePump, OpenCvCaptureConfig, OpenCvFrameSource from audio_field.cultcache_audio import frame_to_numpy, get_live_audio_phase_field, get_live_spatial_audio_frame @@ -1290,11 +1291,12 @@ def main() -> None: reservoir_ns=reservoir_ns, ) source_time_min_ns, source_time_max_ns = reservoir_window_ns(reservoir_edge_ns, reservoir_ns) - multilod_cache_from_evidence( + lod_cache = multilod_cache_from_evidence( evidence, levels=(0.01, 0.04, 0.16, 0.64), created_monotonic_ns=time.monotonic_ns(), - ).write_json(lod_cache_path) + ) + write_lod_cache_json(lod_cache_path, lod_cache) frame = RenderFramePacket( schema=frame.schema, frame_id=frame.frame_id, diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 2828ebd..56deb26 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -60,3 +60,4 @@ {"ts": "2026-05-19T09:11:35+01:00", "type": "implementation", "status": "ok", "note": "Native reservoir provenance guard added: LocalcastSampleHandle now carries flags/reserved fields, diagnostic samples are rejected by localcast_reservoir_push and LocalcastRuntime producer calls, and tests prove fallback/diagnostic handles cannot enter the live rolling buffer."} {"ts": "2026-05-19T09:25:00+01:00", "type": "implementation", "status": "partial", "note": "Python visual CultCache file adapter quarantined under localcast.diagnostics.visual_cache and removed from localcast.sensor_fusion exports; diagnostic producer/Spout/tests now import it explicitly. Import guard passed, but bundled Python cannot run visual-cache round-trip tests because msgpack is not installed."} {"ts": "2026-05-19T09:36:00+01:00", "type": "implementation", "status": "ok", "note": "RenderFramePacket no longer owns JSON file serialization. Compatibility JSON load/write moved to localcast.diagnostics.render_frame_json, diagnostic Spout and sparse-fusion scripts import it explicitly, and tests/import guards prove the production packet module is typed data only."} +{"ts": "2026-05-19T09:45:00+01:00", "type": "implementation", "status": "ok", "note": "MultiLODSceneCache no longer owns JSON file serialization. Diagnostic LOD writes moved to localcast.diagnostics.lod_json, diagnostic_live_sensor_fusion imports that adapter explicitly, and tests/import guards prove stochastic_mapping is model/algorithm code only."} diff --git a/state/map.yaml b/state/map.yaml index 0f4bc02..6326835 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -242,9 +242,11 @@ research: `localcast.visual.stream_status` in `calibration/runs/visual-stream-status.msgpack`. Production visual state crosses native/CultNet typed document boundaries; the Python file adapter - is not live authority. Edge JSON may define schemas or export - diagnostics, but runtime data should remain typed documents because every - networked subsystem is under our control. + is not live authority. Diagnostic JSON render-frame and LOD writers live + under `localcast.diagnostics`; model modules do not own file + serialization. Edge JSON may define schemas or export diagnostics, but + runtime data should remain typed documents because every networked + subsystem is under our control. current_status: summary: > diff --git a/tests/test_stochastic_mapping.py b/tests/test_stochastic_mapping.py index 10e8f15..f54b41f 100644 --- a/tests/test_stochastic_mapping.py +++ b/tests/test_stochastic_mapping.py @@ -15,6 +15,7 @@ from localcast.sensor_fusion.stochastic_mapping import ( stochastic_transient_matches, ) from localcast.sensor_fusion.surface_features import SurfaceFeatureObservation +from localcast.diagnostics.lod_json import write_lod_cache_json def camera(sensor_id, x): @@ -94,7 +95,7 @@ class StochasticMappingTests(unittest.TestCase): self.assertTrue(any(cell.level == 1 and cell.count == 2 for cell in cache.cells)) with tempfile.TemporaryDirectory() as tmp: path = Path(tmp) / "lod.json" - cache.write_json(path) + write_lod_cache_json(path, cache) self.assertIn("multilod_scene_cache", path.read_text(encoding="utf-8")) def test_multilod_evidence_prefers_leap_priority(self):