magscope.python_microscope
==========================

.. py:module:: magscope.python_microscope


Classes
-------

.. autoapisummary::

   magscope.python_microscope.PythonMicroscopeHardwareManagerBase
   magscope.python_microscope.PythonMicroscopeFocusMotor
   magscope.python_microscope.PythonMicroscopeCamera
   magscope.python_microscope.PythonMicroscopeHardwareManager


Module Contents
---------------

.. py:class:: PythonMicroscopeHardwareManagerBase(*, device: Any | None = None, device_factory: collections.abc.Callable[[], Any] | None = None, device_uri: str | None = None, device_getter: collections.abc.Callable[[Any], Any] | None = None)

   Bases: :py:obj:`_PythonMicroscopeDeviceMixin`, :py:obj:`magscope.hardware.HardwareManagerBase`, :py:obj:`abc.ABC`


   Base class for hardware managers backed by python-microscope devices.


   .. py:method:: connect() -> None


   .. py:method:: disconnect() -> None


.. py:class:: PythonMicroscopeFocusMotor(*, axis_name: str = 'z', device: Any | None = None, device_factory: collections.abc.Callable[[], Any] | None = None, device_uri: str | None = None, device_getter: collections.abc.Callable[[Any], Any] | None = None, position_scale: float = 1.0)

   Bases: :py:obj:`_PythonMicroscopeDeviceMixin`, :py:obj:`magscope.hardware.FocusMotorBase`


   Focus motor adapter for a python-microscope stage or stage axis.


   .. py:attribute:: axis_name
      :value: 'z'



   .. py:attribute:: position_scale


   .. py:attribute:: _axis
      :type:  Any | None
      :value: None



   .. py:attribute:: _moving_target
      :type:  float | None
      :value: None



   .. py:method:: connect() -> None


   .. py:method:: disconnect() -> None


   .. py:method:: move_absolute(z: float) -> None

      Command the motor to move to an absolute Z position.



   .. py:method:: get_current_z() -> float

      Return the motor's reported current Z position.



   .. py:method:: get_is_moving() -> bool

      Return the motor's reported moving state.



   .. py:method:: get_position_limits() -> tuple[float, float]

      Return the allowed absolute Z limits for this motor.



   .. py:method:: _resolve_axis(device: Any) -> Any


   .. py:method:: _require_axis() -> Any


   .. py:method:: _to_device_units(z: float) -> float


   .. py:method:: _from_device_units(z: float) -> float


.. py:class:: PythonMicroscopeCamera(*, width: int, height: int, dtype: numpy.dtype, bits: int, nm_per_px: float, settings_map: collections.abc.Mapping[str, str] | None = None, readout_transform: tuple[bool, bool, bool] | None = None, device: Any | None = None, device_factory: collections.abc.Callable[[], Any] | None = None, device_uri: str | None = None, device_getter: collections.abc.Callable[[Any], Any] | None = None)

   Bases: :py:obj:`_PythonMicroscopeDeviceMixin`, :py:obj:`magscope.camera.CameraBase`


   Camera adapter for python-microscope devices and device-server URIs.


   .. py:attribute:: settings
      :value: ['framerate']



   .. py:attribute:: width


   .. py:attribute:: height


   .. py:attribute:: dtype


   .. py:attribute:: bits


   .. py:attribute:: nm_per_px


   .. py:attribute:: settings_map


   .. py:attribute:: _last_fetch_time
      :value: 0.0



   .. py:attribute:: _fps_estimate
      :value: 0.0



   .. py:attribute:: _fetch_count
      :value: 0



   .. py:attribute:: _fps_window_start


   .. py:attribute:: _readout_transform
      :value: (False, False, False)



   .. py:method:: connect(video_buffer) -> None

      Attempts to connect to the camera.

      But does not start an acquisition. This method should set the value of self.is_connected to True if successful
      or False if not.



   .. py:method:: fetch() -> None

      Checks if the camera has new images.

      If the camera has a new image, then it holds the camera's
      buffered image in a queue (self.camera_buffers). And stores the
      image and timestamp in the video buffer (self._video_buffer).

      The timestamp should be the seconds since the unix epoch:
      (January 1, 1970, 00:00:00 UTC)



   .. py:method:: release() -> None

      Gives the buffer back to the camera.



   .. py:method:: release_all() -> None


   .. py:method:: get_setting(name: str) -> str

      Should return the current value of the setting from the camera



   .. py:method:: set_setting(name: str, value: str) -> None

      Should set the value of the setting on the camera



   .. py:method:: shutdown() -> None


   .. py:method:: _build_settings(settings_map: collections.abc.Mapping[str, str]) -> list[str]
      :staticmethod:



   .. py:method:: _grab_frame(device: Any) -> tuple[Any, float]
      :staticmethod:



   .. py:method:: _update_framerate_estimate(timestamp: float) -> None


.. py:class:: PythonMicroscopeHardwareManager(*, device: Any | None = None, device_factory: collections.abc.Callable[[], Any] | None = None, device_uri: str | None = None, device_getter: collections.abc.Callable[[Any], Any] | None = None)

   Bases: :py:obj:`PythonMicroscopeHardwareManagerBase`


   Concrete alias for users who only need the connection helper mixin.


   .. py:method:: fetch() -> None
      :abstractmethod:


      Checks if the hardware has new data.

      If the hardware has new data, then it stores the
      data and timestamp in the matrix buffer (self._buffer).

      The timestamp should be the seconds since the unix epoch:
      (January 1, 1970, 00:00:00 UTC)



