slmsuite.hardware.cameras.thorlabs.ThorCam

class ThorCam(serial='', verbose=True, **kwargs)[source]

Bases: Camera

Thorlabs camera.

sdk

Object to talk with the Thorlabs SDK. Shared among instances of ThorCam.

Type

TLCameraSDK

cam

Object to talk with the desired camera.

Type

ThorCam

profile

Current operation mode.

‘free’ means always capturing.

‘single’ means only gets frame on command.

‘single_hardware’ means only gets frame on hardware trigger or command.

None means camera is disarmed.

Type

{‘free’, ‘single’, ‘single_hardware’} or None

Methods

autoexposure

Sets the exposure of the camera such that the maximum value is at set_fraction of the dynamic range.

autofocus

Uses an FFT contrast metric to find optimal focus when scanning over some variable z.

close

See Camera.close().

close_sdk

Close the TLCameraSDK instance.

flush

See Camera.flush().

get_exposure

See Camera.get_exposure().

get_image

See Camera.get_image().

get_images

Grab image_count images in succession.

info

Discovers all Thorlabs scientific cameras.

is_capturing

Determine whether or not the camera is currently capturing images.

reset

See Camera.reset().

set_binning

Set the binning of the camera.

set_exposure

See Camera.set_exposure().

set_woi

See Camera.set_woi().

setup

Set operation mode.

Attributes

sdk

__init__(serial='', verbose=True, **kwargs)[source]

Initialize camera and attributes. Initial profile is "single".

Parameters
  • serial (str) – Serial number of the camera to open. If empty, defaults to the first camera in the list returned by TLCameraSDK.discover_available_cameras().

  • verbose (bool) – Whether or not to print extra information.

  • kwargs – See Camera.__init__() for permissible options.

Raises

RuntimeError – If the camera can not be reached.

close(close_sdk=False)[source]

See Camera.close().

Parameters

close_sdk (bool) – Whether or not to close the TLCameraSDK instance.

static info(verbose=True)[source]

Discovers all Thorlabs scientific cameras.

Parameters

verbose (bool) – Whether to print the discovered information.

Returns

List of ThorCam serial numbers.

Return type

list of str

static close_sdk()[source]

Close the TLCameraSDK instance.

reset()[source]

See Camera.reset().

get_exposure()[source]

See Camera.get_exposure().

set_exposure(exposure_s)[source]

See Camera.set_exposure().

set_binning(bx=None, by=None)[source]

Set the binning of the camera. Will error if a certain binning is not supported.

Parameters
  • bx (int) – The binning value in the horizontal direction.

  • by (int) – The binning value in the vertical direction.

set_woi(woi=None)[source]

See Camera.set_woi().

setup(profile)[source]

Set operation mode.

Parameters

profile – See profile.

get_image(timeout_s=0.1, trigger=True, grab=True, attempts=1)[source]

See Camera.get_image(). By default trigger=True and grab=True which will result in blocking image acquisition. For non-blocking acquisition, set trigger=True and grab=False to issue a software trigger; then, call the method again with trigger=False and grab=True to grab the resulting frame.

Parameters
  • trigger (bool) – Whether or not to issue a software trigger.

  • grab (bool) – Whether or not to grab the frame (blocking).

Returns

Array of shape shape if grab=True, else None.

Return type

numpy.ndarray or None

flush(timeout_s=1, verbose=False)[source]

See Camera.flush().

Parameters

verbose (bool) – Whether or not to print extra information.

is_capturing()[source]

Determine whether or not the camera is currently capturing images.

Returns

Whether or not the camera is actively capturing images.

Return type

bool

autoexposure(set_fraction=0.5, tol=0.05, exposure_bounds_s=None, window=None, average_count=5, timeout_s=5, verbose=True)[source]

Sets the exposure of the camera such that the maximum value is at set_fraction of the dynamic range. Useful for mitigating deleterious over- or under- exposure.

Parameters
  • set_fraction (float) – Fraction of camera dynamic range to target image maximum.

  • tol (float) – Fractional tolerance for exposure adjustment.

  • exposure_bounds_s ((float, float) OR None) – Shortest and longest allowable integration in seconds. If None, defaults to exposure_bounds_s. If this attribute was not set (or not availible on a particular camera), then None instead defaults to unbounded.

  • window (array_like or None) – See window. If None, the full camera frame will be used.

  • average_count (int) – Number of frames to average intensity over for noise reduction.

  • timeout_s (float) – Stop attempting to autoexpose after timeout_s seconds.

  • verbose (bool) – Whether to print exposure updates.

Returns

Resulting exposure in seconds.

Return type

float

autofocus(z_get, z_set, z_list=None, plot=False)[source]

Uses an FFT contrast metric to find optimal focus when scanning over some variable z. This z often takes the form of a vertical stage to position a sample precisely at the plane of imaging of a lens or objective. The contrast metric works particularly well when combined with a projected spot array hologram.

Parameters
  • z_get (lambda) – Gets the current position of the focusing stage. Should return a float.

  • z_set (lambda) – Sets the position of the focusing stage to a given float.

  • z_list (array_like or None) – z values to sweep over during search. Defaults (when None) to numpy.linspace(-4,4,16).

  • plot (bool) – Whether to provide illustrative plots.

get_images(image_count, flush=False)[source]

Grab image_count images in succession. Overwrite this implementation if a camera supports faster batch acquisition.

Parameters
  • image_count (int) – Number of images to grab.

  • flush (bool) – Whether to flush before grabbing.

Returns

Array of shape (image_count, height, width).

Return type

numpy.ndarray