Adds rerun timelapse preview with brightness thresholding.
Browse files- previews/001/timelapse_chamber.gif +2 -2
- previews/001/timelapse_composite.gif +2 -2
- previews/012/timelapse_chamber.gif +2 -2
- previews/012/timelapse_composite.gif +2 -2
- previews/026/timelapse_chamber.gif +2 -2
- previews/026/timelapse_composite.gif +2 -2
- previews/028/timelapse_chamber.gif +2 -2
- previews/030/timelapse_composite.gif +3 -0
- previews/031/timelapse_chamber.gif +3 -0
- previews/031/timelapse_composite.gif +3 -0
- previews/031/timelapse_galvo.gif +3 -0
- previews/031/timelapse_thermal.gif +3 -0
- previews/032/timelapse_chamber.gif +3 -0
- previews/032/timelapse_composite.gif +3 -0
- previews/032/timelapse_galvo.gif +3 -0
- previews/032/timelapse_thermal.gif +3 -0
- previews/033/timelapse_chamber.gif +3 -0
- previews/033/timelapse_composite.gif +3 -0
- previews/033/timelapse_galvo.gif +3 -0
- previews/033/timelapse_thermal.gif +3 -0
- previews/034/timelapse_chamber.gif +3 -0
- previews/034/timelapse_composite.gif +3 -0
- previews/034/timelapse_galvo.gif +3 -0
- previews/034/timelapse_thermal.gif +3 -0
- previews/035/timelapse_chamber.gif +3 -0
- previews/035/timelapse_composite.gif +3 -0
- previews/035/timelapse_galvo.gif +3 -0
- previews/035/timelapse_thermal.gif +3 -0
- previews/036/timelapse_chamber.gif +3 -0
- previews/041/composite.mp4 +3 -0
- previews/041/galvo.mp4 +3 -0
- previews/041/thermal.mp4 +2 -2
- scripts/previews/02_timelapse.py +90 -17
previews/001/timelapse_chamber.gif
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
previews/001/timelapse_composite.gif
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
previews/012/timelapse_chamber.gif
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
previews/012/timelapse_composite.gif
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
previews/026/timelapse_chamber.gif
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
previews/026/timelapse_composite.gif
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
previews/028/timelapse_chamber.gif
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
previews/030/timelapse_composite.gif
ADDED
|
Git LFS Details
|
previews/031/timelapse_chamber.gif
ADDED
|
Git LFS Details
|
previews/031/timelapse_composite.gif
ADDED
|
Git LFS Details
|
previews/031/timelapse_galvo.gif
ADDED
|
Git LFS Details
|
previews/031/timelapse_thermal.gif
ADDED
|
Git LFS Details
|
previews/032/timelapse_chamber.gif
ADDED
|
Git LFS Details
|
previews/032/timelapse_composite.gif
ADDED
|
Git LFS Details
|
previews/032/timelapse_galvo.gif
ADDED
|
Git LFS Details
|
previews/032/timelapse_thermal.gif
ADDED
|
Git LFS Details
|
previews/033/timelapse_chamber.gif
ADDED
|
Git LFS Details
|
previews/033/timelapse_composite.gif
ADDED
|
Git LFS Details
|
previews/033/timelapse_galvo.gif
ADDED
|
Git LFS Details
|
previews/033/timelapse_thermal.gif
ADDED
|
Git LFS Details
|
previews/034/timelapse_chamber.gif
ADDED
|
Git LFS Details
|
previews/034/timelapse_composite.gif
ADDED
|
Git LFS Details
|
previews/034/timelapse_galvo.gif
ADDED
|
Git LFS Details
|
previews/034/timelapse_thermal.gif
ADDED
|
Git LFS Details
|
previews/035/timelapse_chamber.gif
ADDED
|
Git LFS Details
|
previews/035/timelapse_composite.gif
ADDED
|
Git LFS Details
|
previews/035/timelapse_galvo.gif
ADDED
|
Git LFS Details
|
previews/035/timelapse_thermal.gif
ADDED
|
Git LFS Details
|
previews/036/timelapse_chamber.gif
ADDED
|
Git LFS Details
|
previews/041/composite.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b08f25875abcea892b11133651a2fbb0f549af7e22c51acaa209d48aa2c0c088
|
| 3 |
+
size 225181744
|
previews/041/galvo.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cfe94971f66a9bdd46a4bf7e15f8b0c71f65788d16043dd21f93790a146df824
|
| 3 |
+
size 6418940
|
previews/041/thermal.mp4
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8377f08d39ca245d797065c62bd1c9f3dc63b5735d52f028f36bf6bae2aace9c
|
| 3 |
+
size 532242896
|
scripts/previews/02_timelapse.py
CHANGED
|
@@ -32,7 +32,7 @@ import sys
|
|
| 32 |
from pathlib import Path
|
| 33 |
|
| 34 |
import pyarrow.parquet as pq
|
| 35 |
-
from PIL import Image
|
| 36 |
|
| 37 |
sys.path.insert(0, str(Path(__file__).parent.parent))
|
| 38 |
from _lib import DATA_DIR
|
|
@@ -50,6 +50,15 @@ LAYER_QUANTIZE_UM = 100 # z2 bucket size in microns
|
|
| 50 |
GIF_PANEL_HEIGHT = 240 # panel height in pixels for GIF canvas
|
| 51 |
BATCH_ROWS = 1000 # pyarrow streaming batch size
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
# ---------------------------------------------------------------------------
|
| 55 |
# Image helpers (mirrors 01_render.py exactly)
|
|
@@ -89,6 +98,18 @@ def _placeholder(canvas_w: int) -> Image.Image:
|
|
| 89 |
return Image.new("RGB", (canvas_w, GIF_PANEL_HEIGHT), (20, 20, 20))
|
| 90 |
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
def _canvas_width_from_bytes(b: bytes, kind: str) -> int:
|
| 93 |
"""Decode one frame to determine the locked canvas width for this kind."""
|
| 94 |
img = _decode_raw(b, kind)
|
|
@@ -218,30 +239,64 @@ def _write_gif(frames: list[Image.Image], out_path: Path) -> None:
|
|
| 218 |
# ---------------------------------------------------------------------------
|
| 219 |
|
| 220 |
def render_timelapse_kind(parquet_path: Path, kind: str, out_path: Path) -> int:
|
| 221 |
-
"""Write timelapse_{kind}.gif. Returns number of GIF frames written.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
layer_bytes = collect_layer_bytes(parquet_path, kind)
|
| 223 |
if not layer_bytes:
|
| 224 |
print(f" {kind:8s}: no printing-phase frames (z2 > 0), skipping")
|
| 225 |
return 0
|
| 226 |
|
| 227 |
-
sorted_levels
|
| 228 |
-
target_levels
|
| 229 |
-
fill_bytes
|
| 230 |
-
canvas_w
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
for b in fill_bytes
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
|
| 239 |
_write_gif(pil_frames, out_path)
|
| 240 |
return len(pil_frames)
|
| 241 |
|
| 242 |
|
| 243 |
def render_timelapse_composite(parquet_path: Path, out_path: Path) -> int:
|
| 244 |
-
"""Write timelapse_composite.gif (1×3 panel). Single parquet pass.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
all_bytes = collect_all_kinds(parquet_path)
|
| 246 |
|
| 247 |
all_levels = sorted(set().union(*(set(d) for d in all_bytes.values())))
|
|
@@ -260,16 +315,34 @@ def render_timelapse_composite(parquet_path: Path, out_path: Path) -> int:
|
|
| 260 |
)
|
| 261 |
total_w = sum(canvas_widths.values())
|
| 262 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
pil_frames: list[Image.Image] = []
|
| 264 |
for i in range(len(target_levels)):
|
| 265 |
composite = Image.new("RGB", (total_w, GIF_PANEL_HEIGHT), (20, 20, 20))
|
| 266 |
x = 0
|
| 267 |
for kind in FRAME_KINDS:
|
| 268 |
-
|
| 269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
panel = (
|
| 271 |
-
_fit_to_canvas(
|
| 272 |
-
if
|
| 273 |
)
|
| 274 |
composite.paste(panel, (x, 0))
|
| 275 |
x += canvas_widths[kind]
|
|
|
|
| 32 |
from pathlib import Path
|
| 33 |
|
| 34 |
import pyarrow.parquet as pq
|
| 35 |
+
from PIL import Image, ImageStat
|
| 36 |
|
| 37 |
sys.path.insert(0, str(Path(__file__).parent.parent))
|
| 38 |
from _lib import DATA_DIR
|
|
|
|
| 50 |
GIF_PANEL_HEIGHT = 240 # panel height in pixels for GIF canvas
|
| 51 |
BATCH_ROWS = 1000 # pyarrow streaming batch size
|
| 52 |
|
| 53 |
+
# Halogen brightness filter — applies to chamber frames only.
|
| 54 |
+
# The halogens pulse on/off throughout a build; dark frames (halogens off) are
|
| 55 |
+
# uninformative for viewing. A frame is kept if its mean grayscale brightness is
|
| 56 |
+
# at least this fraction of the brightest frame seen in the same build.
|
| 57 |
+
# For the individual chamber GIF dark frames are dropped entirely; for the
|
| 58 |
+
# composite they are forward-filled from the last bright frame so thermal/galvo
|
| 59 |
+
# stay in layer-sync.
|
| 60 |
+
CHAMBER_BRIGHTNESS_RATIO = 0.25
|
| 61 |
+
|
| 62 |
|
| 63 |
# ---------------------------------------------------------------------------
|
| 64 |
# Image helpers (mirrors 01_render.py exactly)
|
|
|
|
| 98 |
return Image.new("RGB", (canvas_w, GIF_PANEL_HEIGHT), (20, 20, 20))
|
| 99 |
|
| 100 |
|
| 101 |
+
def _mean_brightness(img: Image.Image) -> float:
|
| 102 |
+
"""Mean grayscale pixel value 0–255 (uses PIL ImageStat, no numpy)."""
|
| 103 |
+
return ImageStat.Stat(img.convert("L")).mean[0]
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def _chamber_threshold(decoded_frames: list[Image.Image | None]) -> float:
|
| 107 |
+
"""Return the brightness threshold for a build's chamber frames.
|
| 108 |
+
25 % of the brightest frame seen; 0 if no frames (no filtering applied)."""
|
| 109 |
+
brightnesses = [_mean_brightness(f) for f in decoded_frames if f is not None]
|
| 110 |
+
return max(brightnesses) * CHAMBER_BRIGHTNESS_RATIO if brightnesses else 0.0
|
| 111 |
+
|
| 112 |
+
|
| 113 |
def _canvas_width_from_bytes(b: bytes, kind: str) -> int:
|
| 114 |
"""Decode one frame to determine the locked canvas width for this kind."""
|
| 115 |
img = _decode_raw(b, kind)
|
|
|
|
| 239 |
# ---------------------------------------------------------------------------
|
| 240 |
|
| 241 |
def render_timelapse_kind(parquet_path: Path, kind: str, out_path: Path) -> int:
|
| 242 |
+
"""Write timelapse_{kind}.gif. Returns number of GIF frames written.
|
| 243 |
+
|
| 244 |
+
Chamber only: dark frames (halogens off) are dropped entirely so the GIF
|
| 245 |
+
shows only moments where the part is visible. Thermal and galvo are
|
| 246 |
+
unaffected — they don't depend on halogen lighting.
|
| 247 |
+
"""
|
| 248 |
layer_bytes = collect_layer_bytes(parquet_path, kind)
|
| 249 |
if not layer_bytes:
|
| 250 |
print(f" {kind:8s}: no printing-phase frames (z2 > 0), skipping")
|
| 251 |
return 0
|
| 252 |
|
| 253 |
+
sorted_levels = sorted(layer_bytes)
|
| 254 |
+
target_levels = _subsample(sorted_levels)
|
| 255 |
+
fill_bytes = _forward_fill(layer_bytes, target_levels)
|
| 256 |
+
canvas_w = _canvas_width_from_bytes(next(b for b in fill_bytes if b), kind)
|
| 257 |
+
|
| 258 |
+
# Decode all selected frames up front (needed for brightness scan on chamber).
|
| 259 |
+
decoded = [_decode_raw(b, kind) if b else None for b in fill_bytes]
|
| 260 |
+
|
| 261 |
+
if kind == "chamber":
|
| 262 |
+
# Compute brightness once per decoded frame, then threshold and filter.
|
| 263 |
+
brightnesses = [_mean_brightness(img) if img is not None else None
|
| 264 |
+
for img in decoded]
|
| 265 |
+
threshold = _chamber_threshold(decoded)
|
| 266 |
+
pil_frames = [
|
| 267 |
+
_fit_to_canvas(img, canvas_w)
|
| 268 |
+
for img, b in zip(decoded, brightnesses)
|
| 269 |
+
if img is not None and b is not None and b >= threshold
|
| 270 |
+
]
|
| 271 |
+
dark_dropped = sum(
|
| 272 |
+
1 for img, b in zip(decoded, brightnesses)
|
| 273 |
+
if img is not None and b is not None and b < threshold
|
| 274 |
)
|
| 275 |
+
if dark_dropped:
|
| 276 |
+
print(f" {kind:8s}: dropped {dark_dropped} dark frames "
|
| 277 |
+
f"(threshold {threshold:.1f}/255)")
|
| 278 |
+
else:
|
| 279 |
+
pil_frames = [
|
| 280 |
+
_fit_to_canvas(img, canvas_w) if img else _placeholder(canvas_w)
|
| 281 |
+
for img in decoded
|
| 282 |
+
]
|
| 283 |
+
|
| 284 |
+
if not pil_frames:
|
| 285 |
+
print(f" {kind:8s}: no frames survived brightness filter, skipping")
|
| 286 |
+
return 0
|
| 287 |
|
| 288 |
_write_gif(pil_frames, out_path)
|
| 289 |
return len(pil_frames)
|
| 290 |
|
| 291 |
|
| 292 |
def render_timelapse_composite(parquet_path: Path, out_path: Path) -> int:
|
| 293 |
+
"""Write timelapse_composite.gif (1×3 panel). Single parquet pass.
|
| 294 |
+
|
| 295 |
+
Thermal and galvo show the actual frame for every layer (unaffected by
|
| 296 |
+
halogens). The chamber panel forward-fills from the last *bright* frame
|
| 297 |
+
when the current layer's chamber frame is dark — this keeps all three
|
| 298 |
+
panels in layer-sync while never displaying a dark chamber view.
|
| 299 |
+
"""
|
| 300 |
all_bytes = collect_all_kinds(parquet_path)
|
| 301 |
|
| 302 |
all_levels = sorted(set().union(*(set(d) for d in all_bytes.values())))
|
|
|
|
| 315 |
)
|
| 316 |
total_w = sum(canvas_widths.values())
|
| 317 |
|
| 318 |
+
# Pre-decode chamber frames once; compute adaptive brightness threshold.
|
| 319 |
+
chamber_decoded = [
|
| 320 |
+
_decode_raw(b, "chamber") if b else None
|
| 321 |
+
for b in fill_per_kind["chamber"]
|
| 322 |
+
]
|
| 323 |
+
chamber_threshold = _chamber_threshold(chamber_decoded)
|
| 324 |
+
|
| 325 |
+
last_bright_chamber: Image.Image | None = None
|
| 326 |
pil_frames: list[Image.Image] = []
|
| 327 |
for i in range(len(target_levels)):
|
| 328 |
composite = Image.new("RGB", (total_w, GIF_PANEL_HEIGHT), (20, 20, 20))
|
| 329 |
x = 0
|
| 330 |
for kind in FRAME_KINDS:
|
| 331 |
+
if kind == "chamber":
|
| 332 |
+
img = chamber_decoded[i]
|
| 333 |
+
# Update the running bright-chamber reference when this frame is bright.
|
| 334 |
+
if img is not None and _mean_brightness(img) >= chamber_threshold:
|
| 335 |
+
last_bright_chamber = img
|
| 336 |
+
# Always use the last bright frame (forward-fill); placeholder until
|
| 337 |
+
# the first bright frame arrives.
|
| 338 |
+
panel_img = last_bright_chamber
|
| 339 |
+
else:
|
| 340 |
+
b = fill_per_kind[kind][i]
|
| 341 |
+
panel_img = _decode_raw(b, kind) if b else None
|
| 342 |
+
|
| 343 |
panel = (
|
| 344 |
+
_fit_to_canvas(panel_img, canvas_widths[kind])
|
| 345 |
+
if panel_img else _placeholder(canvas_widths[kind])
|
| 346 |
)
|
| 347 |
composite.paste(panel, (x, 0))
|
| 348 |
x += canvas_widths[kind]
|