herosdevices.hardware.allied_vision.vimba_camera
================================================

.. py:module:: herosdevices.hardware.allied_vision.vimba_camera

.. autoapi-nested-parse::

   Driver for cameras based on the Allied Vision VimbaX library.







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

.. py:data:: DEFAULT_FEATURE_VISIBLIY

.. py:data:: DEFAULT_CONFIG

.. py:class:: VimbaCompatibleCamera(cam_id: str, config_dict: dict, default_config: str | None = None, reset_to_continuous: bool = False, lib_path: str | None = None)

   Bases: :py:obj:`herosdevices.core.templates.camera.CameraTemplate`


   A class to interface with Allied Vision VimbaX cameras.

   The class provides functionality to control and capture images from Allied Vision VimbaX cameras.
   It manages camera configuration, acquisition, and data streaming.

   ``gain`` writes the ``Gain`` feature in dB, negative values are passed on. The setter writes ``GainAuto = "Off"``
   first only if the configuration has a ``GainAuto`` key. ``GainSelector`` is not written. ``frame_rate`` writes
   ``AcquisitionFrameRate``. ``None`` sets ``AcquisitionFrameRateEnable`` to ``False``, and the stored rate is not
   written while the limit is disabled. A stored enable value of ``False``, ``"Off"`` or ``"False"`` reads as
   disabled.

   .. important::

      The vendor underlying library must be obtained from the
      `official website <https://www.alliedvision.com/de/support/software-downloads/vimba-x-sdk/vimba-x>`_.
      Download the `Allied Vision VimbaX SDK`, unpack it and install it following the supplied ``README`` file.
      
      Note:
          For use with :ref:`BOSS in docker <boss-additional-deps>`, you can adapt the VimbaX install script
          ``cti/Install_GenTL_Path.sh``
      
      To find the ``cam_id`` of your camera, you can either use the VimbaXViewer
      (or start the driver with a wrong id, it will print the available ids).
      The ids look something like ``DEV_000A4717239E``.


   .. py:attribute:: cam_id


   .. py:attribute:: default_config_dict


   .. py:attribute:: reset_to_continuous
      :value: False



   .. py:method:: read_feature(feature_name: str) -> Any

      Read the current value of a VimbaX camera feature.

      :param feature_name: Name of the feature to read (e.g., "ExposureTime", "Gain")

      :returns: The current value of the feature, or False if the feature cannot be read.
                For enum features, returns the string representation of the enum value.

      .. rubric:: Example

      Read exposure time::

          exposure = camera.read_feature("ExposureTime")
          print(f"Current exposure: {exposure} µs")



   .. py:method:: set_feature(feature_name: str, value: Any) -> bool

      Set the value of a VimbaX camera feature.

      .. warning::

         This method is discouraged for production use. Instead, use the configuration
         system via :meth:`set_configuration` which provides better configuration management.

      :param feature_name: Name of the feature to set (e.g., "ExposureTime", "Gain")
      :param value: Value to set for the feature

      :returns: True if the feature was set successfully, False otherwise.

      .. rubric:: Example

      Set exposure time::

          success = camera.set_feature("ExposureTime", 1000)
          if not success:
              print("Failed to set exposure time")



   .. py:method:: run_feature(feature_name: str) -> Any

      Execute a command-type VimbaX camera feature.

      Command features are used for actions like triggering software triggers,
      saving settings, or other one-time operations.

      :param feature_name: Name of the command feature to execute (e.g., "TriggerSoftware")

      :returns: True if the feature was ran successfully, False otherwise.

      .. rubric:: Example

      Trigger a software trigger::

          result = camera.run_feature("TriggerSoftware")
          if result:
              print("Trigger executed successfully")



   .. py:attribute:: get_camera


   .. py:method:: supported_features() -> list[str]

      Return the names of the camera helper features this class supports.

      A feature is supported if the class overrides both its getter and its setter hook. If only one
      of the two is overridden, a warning is logged once per class and the feature is treated as unsupported.

      :returns: sorted feature names, equal to the names of the corresponding properties



   .. py:property:: exposure_time
      :type: float | None


      Exposure time in seconds. `None` if not set or not supported, see :meth:`supported_features`.


   .. py:property:: roi_coordinates
      :type: tuple[int, int, int, int] | None


      ROI as (x_offset, y_offset, width, height) in sensor pixels.

      `None` if not set or not supported, see :meth:`supported_features`.


   .. py:property:: binning
      :type: tuple[int, int] | None


      Binning as (horizontal, vertical). `None` if not set or not supported, see :meth:`supported_features`.


   .. py:property:: gain
      :type: float | None


      Gain in the native unit of the driver, see :ref:`camera-gain-frame-rate`.

      The setter raises :class:`ValueError` for NaN, infinity, booleans and non-numbers. The valid range is driver
      specific and checked by the driver. The getter returns `None` if not set or not supported, see
      :meth:`supported_features`.


   .. py:property:: frame_rate
      :type: float | None


      Frame rate limit in Hz, see :ref:`camera-gain-frame-rate`.

      Setting `None` removes the limit. Other values must be positive finite numbers, not booleans, otherwise the
      setter raises :class:`ValueError`. The getter returns `None` if the limit is removed, if no frame rate is
      configured and if the feature is not supported, see :meth:`supported_features`.


   .. py:attribute:: acquisition_running
      :type:  bool
      :value: False



   .. py:attribute:: payload_metadata
      :type:  dict


   .. py:attribute:: keep_device_open
      :value: True



   .. py:attribute:: default_config
      :type:  str


   .. py:method:: get_device() -> collections.abc.Iterator[None]

      Yield a device handle.

      .. code-block:: python

          # use the device in a with statement
          with self.get_device() as camera:
              camera.do_something()



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

      Open the device handler and assign it to `self._device`.



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

      Release the device handler and potentially de-initialize the API.



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

      Fire a software trigger.

      :returns: True if successful



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

      Abort the exposure and release queued buffers.

      :returns: True if successful



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

      Reset the device by aborting any ongoing exposure, closing and re-opening the handler.



   .. py:method:: get_status() -> dict

      Get a dict with the current device status.

      :returns: A dict with the device status



   .. py:method:: get_available_options() -> dict

      Get all configurable options/features of the device.

      :returns: Dict mapping option names to their properties (value, readable, writable, etc.).



   .. py:property:: config_dict
      :type: dict


      Get a copy of the configuration dict.

      :returns: Copy of the configuration dict


   .. py:method:: update_configuration(new_config_dict: dict, merge: bool = True) -> None

      Update the configuration dict with new configuration.

      Each dict key corresponds a (new) configuration name.
      Each value is a dict with config property -> config value.

      :param new_config_dict: A dict of configurations where the keys are the configuration names
      :param merge: If ``True``, the new dict is recursively merged with the current set config dict. If ``False`` the
                    old configurations with the provided names (keys) are overwritten. In this case each new configuration,
                    merged over ``default_config_dict``, must contain all ``_required_config_keys``.

      :raises ValueError: If ``merge`` is ``False`` and a required config key is missing. No configuration is changed.



   .. py:method:: get_configuration() -> dict

      Get the currently active configuration.

      :returns: The currently active configuration.



   .. py:method:: configure(config: str = '', metadata: dict | None = None) -> bool

      Configure the device with the known configuration `config`.

      To add a configuration to the device, use :meth:`update_configuration`.

      :param config: Key (name) of the configuration
      :param metadata: Metadata that is merged into the current payload metadata dict which is send with every emitted
                       :code:`acquisition_data` event.

      :returns: False if the acquisition is running or if :meth:`_set_config` returned False, True otherwise. Exceptions
                raised by :meth:`_set_config` are not caught.



   .. py:attribute:: set_configuration


   .. py:method:: update_payload_metadata(metadata: dict, merge: bool = True) -> None

      Update metadata dict send with every emitted frame by the :code:`acquisition_data` event method.

      :param metadata: Metadata that is merged into the current payload metadata dict which is send with every emitted
                       :code:`acquisition_data` event.
      :param merge: If ``True``, the new dict is merged with the current set metadata dict. If ``False`` the old
                    metadata is overwritten by the given dict.



   .. py:method:: arm(metadata: dict | None = None, kill_running: bool = False) -> bool

      Arm the device with the currently active configuration.

      :param metadata: Metadata that is merged into the current payload metadata dict which is send with every emitted
                       :code:`acquisition_data` event.
      :param kill_running: If ``True`` any running acquisition will be stopped. If ``False`` and an acquisition is
      :param already running:
      :param an error will be raised.:

      :returns: True if arming was successful else False



   .. py:method:: acquisition_data(frame: numpy.ndarray, metadata: dict | None = None) -> tuple

      Event to emit new frames.

      .. note::
          The dtype of the frame is not changed here.

      :param frame: The frame payload data (for example an image or an scope trace)
      :param metadata: The metadata which is passed along the payload. This argument takes precedence over the
                       :code:`payload_metadata` attribute (for example set by the :code:`update_payload_metadata` method)
                       while merging the two dicts.

      :returns: A tuple of image and metadata(-dict)



   .. py:method:: acquisition_started(metadata: dict | None = None) -> dict

      Event emitted when the acquisition thread starts.

      :returns: A dict with acquisition metadata



   .. py:method:: acquisition_stopped(metadata: dict | None = None) -> dict

      Event emitted when the acquisition thread stops.

      :returns: A dict with acquisition metadata



