Cameras code

Architecture

The Cameras folder is defined as a module loaded in CAtImaPy main code.

The code controlling cameras rely on the use a base class CameraClass (described below) as an interface and parent for all manufacturer/model specific camera classes.

The configurations of cameras are set in the Cameras/Config.py file as a list camerasConfigs of dictionaries.

The creation of the Camera object, attribute of mainWin, is realized by the factory/builder function create_Camera(). create_Camera() selects the child class for the specified driver (manufacturer API) and model, as given by keys ‘driver’ and ‘model’ in camerasConfigs. Ideally, the creator should load a child class for the specified model with proper initialization of this model. The model classes <Model name>Class are inherited from the driver class <Driver name>Class, defined in <Driver name>.py file in Cameras directory. The model classes are defined in the same file. If no model class is defined, the creator loads the generic driver class.

Driver camera classes are derived from base class CameraClass. Either directly by connecting to a python driver, for example, FLIRPySpinClass connect to the PySpin driver package provided by FLIR. Or with the PyLabLib package, via an interface class PylablibInterfaceClass, inherited from CameraClass and used as parent of the driver class. An example is given by the camera class ThorlabsClass. Available driver classes are listed below in section Driver Camera classes.

Model camera classes are the way for the user to properly initialize the camera. Indeed, if the generic driver class may work, the different camera models often have different available options or properties. In order to set all the parameters optimally the user should define a model class. Even in the case where the driver class is working, the user should preferably define a model class simply inheriting everything from the driver class. This should avoid future conflicts if other camera models with the same driver need to be added. The <Driver name>.py file contains the definition of a ExampleModelClass, that you can copy to make your model <Model name>Class by changing its name (and docstring). Two examples of properly defined model classes are given below in section Model Camera classes.

Base Camera class

class Cameras.CameraClass(cameraNumber, triggerMode=0, exposurems=1.0, gaindB=0.0, camROI=None, loadDefault=False)[source]

Bases: object

Top Parent Class for controlling camera : used as an interface

__del__()[source]

Delete the Camera object by calling close function

Close the Camera and free memory

__init__(cameraNumber, triggerMode=0, exposurems=1.0, gaindB=0.0, camROI=None, loadDefault=False)[source]

Initialize the Camera object

Parameters:

cameraNumber (int) – index of camera in camerasConfigs list

Keyword Arguments:
  • triggerMode (int) – 0 for hardware/external, 1 for software/internal

  • exposurems (float) – Exposition duration (exposure) in ms.

  • gaindB (float) – hardware gain of the camera in dB.

  • camROI (None or [int]*4) – Camera region of interest to read from sensor [x offset , y offset , x size , y size ] (binning is not implemented)

  • loadDefault (bool) – Decide if default values from cameraConfigs should be set at creation

Returns:

CameraClass object

clearBuffer()[source]

Clear camera buffer from images. Use before imaging scans to make sure no previously acquired image is present in buffer

exposureLevelAutoAdjust(attemptsMax=20, Optimization='Max')[source]

Automatic adjustment of exposure for setting image ‘Max’ or ‘Average’ to a given level.

Can use gaindB increase to reach specified level if maximum exposure is not sufficient.

Keyword Arguments:
  • attemptsMax (int) – Maximum number of steps (images) in optimization

  • Optimization (str) – Select image value to optimize ‘Max’ or ‘Average’

Returns:

Optimized image value (int)

grabArray()[source]

Get an image from the camera. Wait for trigger if external or generate one if internal.

Returns:

Camera image (numpy 2D array)

sendSoftwareTrigger()[source]

Send a software trigger to the camera to start an exposure

setCamROI(ROI=None)[source]

Set the ROI of camera (without binning)

Keyword Arguments:

ROI (None or [int]*4) – [ x offset, y offset, x size, y size], if None, set to [0, 0, max Width, max height]

Returns:

[x offset, y offset, x size, y size]

Return type:

Camera ROI ([int]*4)

setExposurems(exposurems)[source]

Set the duration of the exposition

Parameters:

exposurems (float) – Exposition duration (exposure) in ms.

setGaindB(gaindB)[source]

Set the hardware gain of camera readout

Parameters:

gaindB (float) – hardware gain of the camera in dB.

setTriggerMode(triggerMode)[source]

Set the trigger mode

Parameters:

triggerMode (int) – 0 for hardware/external, 1 for software/internal

startAcquisition()[source]

Start acquisition or restart if already running

Camera creator

Cameras.create_Camera(cameraNumber, triggerMode=0, exposurems=1.0, gaindB=0.0, camROI=None, loadDefault=False)[source]

Builder / factory that create the Camera object

With the right specific class (interface with parent class CameraClass) depending on the camera model as defined by the info in Config.camerasConfigs

Parameters:

cameraNumber (int) – index of camera in camerasConfigs list

Keyword Arguments:
  • triggerMode=0 (int) – 0 for hardware/external, 1 for software/internal

  • exposurems=1. (float) – Exposition duration (exposure) in ms.

  • gaindB=0. (float) – hardware gain of the camera in dB.

  • camROI=None (None or [int]*4) – Camera region of interest to read from sensor [x offset , y offset , x size , y size ] (binning is not implemented)

  • False (loadDefault =) – Decide if default values from cameraConfigs should be set at creation

Returns:

Camera object (interface CameraClass)

Driver Camera classes

Direct driver classes

FLIRPySpinClass

Parent class for FLIR cameras using PySpin python driver.

PyLabLib interface class

PylablibInterfaceClass

Parent class for all camera driver classes using pylablib.

PyLabLib-based driver classes

AndorSDK2Class

Parent class for all camera ANdorSDK2 classes using pylablib python driver.

AndorSDK3Class

Parent class for all camera ANdorSDK3 classes using pylablib python driver.

HamamatsuDCAMClass

Parent class for all camera Hamamatsu DCAM classes using pylablib python driver.

IDSueyeClass

Parent class for all camera IDSueye classes using pylablib python driver.

NIIMAQdxClass

Parent class for all camera NIIMAQdx classes using pylablib python driver.

PCOSC2Class

Parent class for all camera PCOSC2 classes using pylablib python driver.

PhotometricsClass

Parent class for all camera Photometrics classes using pylablib python driver.

PrincetonInstrumentsClass

Parent class for all camera Thorlabs classes using pylablib python driver.

ThorlabsClass

Parent class for all camera Thorlabs classes using pylablib python driver.

ThorlabsUC480Class

Parent class for all camera ThorlabsUC480 (IDS cameras) classes using pylablib python driver.

Model Camera classes

Below you will find two examples of properly defined model classes.

FLIRPySpin.Chameleon3Class

Model-specific class for Chameleon3 FLIR cameras using PySpin python driver.

Thorlabs.ZeluxClass

Model-specific class for Zelux Thorlabs camera using pylablib python driver.