Commit 69d99067 authored by vertighel's avatar vertighel
Browse files

Fix teccam loop stripe artifacts: use device.image for Mako



Mako's _broadcast_preview path applied viridis with percentile
auto-range, amplifying sensor hot-rows into visible stripes.
Switch to device.image (array_to_png vmin=0 vmax=255), identical
to the Mako HTTP stream pipeline. STX path unchanged.

Co-Authored-By: default avatarClaude Sonnet 4.6 <noreply@anthropic.com>
parent afa3727d
Loading
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ The key must match the URL segment ``<station>/<camera>``.

# System modules
import asyncio
import base64
import configparser
from pathlib import Path

@@ -189,7 +190,7 @@ async def _run_loop(device, exposure: float, station: str, camera: str):
    try:
        while True:
            if is_stx:
                # STX Guider: trigger exposure, poll ready, then grab matrix
                # STX Guider: trigger exposure, poll ready, then grab matrix → viridis
                await ev.run_in_executor(None, device.start, exposure, 1)
                deadline = ev.time() + exposure + 30.0
                while ev.time() < deadline:
@@ -197,13 +198,19 @@ async def _run_loop(device, exposure: float, station: str, camera: str):
                    if ready == 1:
                        break
                    await asyncio.sleep(0.3)

                data = await ev.run_in_executor(None, lambda: device.matrix)
                if data is not None:
                    await streamer._broadcast_preview(station, camera, np.squeeze(data))

            if not is_stx:
                # Mako: broadcast first frame immediately, then wait before next
            else:
                # Mako: device.image uses array_to_png(matrix, vmin=0, vmax=255),
                # identical to the HTTP stream — no viridis auto-range amplification
                png = await ev.run_in_executor(None, lambda: device.image)
                if png is not None:
                    encoded = base64.b64encode(png).decode('utf-8')
                    await streamer.broadcaster.broadcast(
                        "fits-preview",
                        {"station": station, "camera": camera, "png": encoded},
                    )
                await asyncio.sleep(exposure)
    except asyncio.CancelledError:
        pass