Commit efa076e9 authored by vertighel's avatar vertighel
Browse files

fix: harmonize camera device interfaces



- atik.Camera: add acquisition='trigger' and dtype=np.float32 class
  attributes; add state guard in start(); download() returns filepath
- stx.Camera: download() returns filepath
- mako.Guider: rename save_image→save_png with viewer.ini default path;
  image property now uses make_png (viridis+auto-range) matching STX/Atik;
  replace array_to_png import with make_png

Co-Authored-By: default avatarClaude Sonnet 4.6 <noreply@anthropic.com>
parent 7beeb733
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -45,6 +45,9 @@ class ArtemisProperties(ctypes.Structure):


class Camera(BaseDevice):
    dtype = np.float32
    acquisition = 'trigger'

    def __init__(self, url):
        super().__init__(url)
        self._lib = None
@@ -133,6 +136,10 @@ class Camera(BaseDevice):
    def start(self, duration, imagetype, datetime=None):
        h = self._check_connection()
        if not h: return
        if self.state != 0:
            log.error(f"Cannot start exposure, camera is not idle. State: {self.state}")
            self.error.append("Camera not idle")
            return
        self._last_exptime = duration
        self._last_imagetype = imagetype
        self._last_datetime = datetime
@@ -207,6 +214,7 @@ class Camera(BaseDevice):
                           "Image type")

        hdu.writeto(filepath, overwrite=True)
        return filepath

    @property
    def matrix(self):
+14 −12
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ from vmbpy import VmbSystem, FrameStatus

# Custom modules
from .basedevice import BaseDevice
from ..utils.image import array_to_png, Streamer
from ..utils.image import make_png, Streamer
from ..utils.logger import log


@@ -164,22 +164,24 @@ class Guider(Mako):

    @property
    def image(self):
        """Get the current frame as a raw binary PNG."""
        
        """Current frame as viridis PNG bytes."""
        data = self.matrix
        if data is not None:
            return array_to_png(data, vmin=self._range[0], vmax=self._range[1])
        if data is None:
            return None
        return make_png(data)

    
    def save_image(self, filename="temp.png", vmin=None, vmax=None, color=True):
        """Save the current frame as a PNG file."""
    def save_png(self, filepath=None, vmin=None, vmax=None, color=True):
        """Save current frame as PNG. Returns filepath."""
        if filepath is None:
            from ..config.constants import viewer_fits_path
            filepath = viewer_fits_path(getattr(self, "_viewer_key", None)).replace(".fits", ".png")
        data = self.matrix
        if data is not None:
            from ..utils.image import make_png
            with open(filename, "wb") as f:
            from pathlib import Path
            Path(filepath).parent.mkdir(parents=True, exist_ok=True)
            with open(filepath, "wb") as f:
                f.write(make_png(data, vmin=vmin, vmax=vmax, color=color))
        return filename
        return filepath

    
    def download(self, filename=None):
+1 −0
Original line number Diff line number Diff line
@@ -249,6 +249,7 @@ class Camera(STX):
            log.debug(f"Writing on disk")
            f.write(res.content)
            log.debug(f"Written")
        return filepath


    @property