pylablib.devices.interface package

Submodules

pylablib.devices.interface.camera module

exception pylablib.devices.interface.camera.DefaultFrameTransferError[source]

Bases: pylablib.core.devio.base.DeviceError

Generic frame transfer error

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class pylablib.devices.interface.camera.TFramesStatus(acquired, unread, skipped, buffer_size)

Bases: tuple

acquired
buffer_size
count()

Return number of occurrences of value.

index()

Return first index of value.

Raises ValueError if the value is not present.

skipped
unread
class pylablib.devices.interface.camera.TFrameSize(width, height)

Bases: tuple

count()

Return number of occurrences of value.

height
index()

Return first index of value.

Raises ValueError if the value is not present.

width
class pylablib.devices.interface.camera.TFramePosition(left, top)

Bases: tuple

count()

Return number of occurrences of value.

index()

Return first index of value.

Raises ValueError if the value is not present.

left
top
class pylablib.devices.interface.camera.TFrameInfo(frame_index)

Bases: tuple

count()

Return number of occurrences of value.

frame_index
index()

Return first index of value.

Raises ValueError if the value is not present.

class pylablib.devices.interface.camera.ICamera(*args, **kwargs)[source]

Bases: pylablib.core.devio.interface.IDevice

Generic camera class.

Provides a consistent common interface for the most frequently encountered camera functions.

Error

alias of pylablib.core.devio.base.DeviceError

TimeoutError

alias of pylablib.core.devio.base.DeviceError

FrameTransferError

alias of DefaultFrameTransferError

is_acquisition_setup()[source]

Check if acquisition is set up.

If the camera does not support separate acquisition setup, always return True.

get_acquisition_parameters()[source]

Get acquisition parameters.

Return dictionary {name: value}

setup_acquisition(**kwargs)[source]

Setup acquisition.

Any non-specified acquisition parameters are assumed to be the same as previously set (or default, if not explicitly set before). Return the new acquisition parameters.

clear_acquisition()[source]

Clear acquisition settings

start_acquisition(*args, **kwargs)[source]

Start acquisition.

Can take the same keyword parameters as :meth:``setup_acquisition. If the acquisition is not set up yet, set it up using the supplied parameters (use default of setup_acquisition(),if the parameter is None). Otherwise, if any supplied parameters are different from the current ones, change them and reset the acquisition.

stop_acquisition()[source]

Stop acquisition

acquisition_in_progress()[source]

Check if acquisition is in progress

pausing_acquisition(clear=None)[source]

Context manager which temporarily pauses acquisition during execution of with block.

Useful for applying certain settings which can’t be changed during the acquisition. If clear==True, clear acquisition in addition to pausing (by default, use the class default specified as _clear_pausing_acquisition attribute). Yields tuple (acq_in_progress, acq_params), which indicates whether acquisition is currently in progress, and what are the current acquisition parameters.

get_detector_size()[source]

Get camera detector size (in pixels) as a tuple (width, height)

get_frames_status()[source]

Get acquisition and buffer status.

Return tuple (acquired, unread, skipped, size), where acquired is the total number of acquired frames, unread is the number of acquired but not read frames, skipped is the number of skipped (not read and then written over) frames, and buffer_size is the total buffer size (in frames).

wait_for_frame(since='lastread', nframes=1, timeout=20.0, error_on_stopped=False)[source]

Wait for one or several new camera frames.

since specifies the reference point for waiting to acquire nframes frames; can be “lastread”`` (from the last read frame), "lastwait" (wait for the last successful wait_for_frame() call), "now" (from the start of the current call), or "start" (from the acquisition start, i.e., wait until nframes frames have been acquired). timeout can be either a number, None (infinite timeout), or a tuple (timeout, frame_timeout), in which case the call times out if the total time exceeds timeout, or a single frame wait exceeds frame_timeout. If the call times out, raise TimeoutError. If error_on_stopped==True and the acquisition is not running, raise Error; otherwise, simply return False without waiting.

get_image_indexing()[source]

Get indexing for the returned images.

Can be "rct" (first index row, second index column, rows counted from the top), "rcb" (same as "rc", rows counted from the bottom), "xyt" (first index column, second index row, rows counted from the top), or "xyb" (same as "xyt", rows counted from the bottom)

set_image_indexing(indexing)[source]

Set up indexing for the returned images.

Can be "rct" (first index row, second index column, rows counted from the top), "rcb" (same as "rc", rows counted from the bottom), "xyt" (first index column, second index row, rows counted from the top), or "xyb" (same as "xyt", rows counted from the bottom)

get_data_dimensions()[source]

Get readout data dimensions (in pixels) as a tuple (width, height); take indexing mode into account

get_frame_format()[source]

Get format for the returned images.

Can be "list" (list of 2D arrays, or 3D array for some fastbuff cameras), "array" (a single 3D array).

set_frame_format(fmt)[source]

Set format for the returned images.

Can be "list" (list of 2D arrays, or 3D array for some fastbuff cameras), "array" (a single 3D array). Note that if the format is set to "array", the frame info format is also automatically set to "array".

get_frame_info_format()[source]

Get format of the frame info.

Can be "namedtuple" (potentially nested named tuples; convenient to get particular values), "list" (flat list of values, with field names are given by get_frame_info_fields(); convenient for building a table), "array" (same as "list", but with a numpy array, which is easier to use for fastbuff readout supported by some cameras), or "dict" (flat dictionary with the same fields as the "list" format; more resilient to future format changes)

set_frame_info_format(fmt, include_fields=None)[source]

Set format of the frame info.

Can be "namedtuple" (potentially nested named tuples; convenient to get particular values), "list" (flat list of values, with field names are given by get_frame_info_fields(); convenient for building a table), "array" (same as "list", but with a numpy array, which is easier to use for fastbuff readout supported by some cameras), or "dict" (flat dictionary with the same fields as the "list" format; more resilient to future format changes) If include_fields is not None, it specifies the fields included for non-"tuple" formats.

get_frame_info_period()[source]

Get period of frame info acquisition.

Frame info might be skipped (set to None) except for frames which indices are divisible by period. Useful for certain cameras where acquiring frame info takes a lot of time and can reduce performance at higher frame rates. Note that this parameter can still be ignored (i.e., always set to 1) if the performance is not an issue for a given camera class.

set_frame_info_period(period=1)[source]

Set period of frame info acquisition.

Frame info might be skipped (set to None) except for frames which indices are divisible by period. Useful for certain cameras where acquiring frame info takes a lot of time and can reduce performance at higher frame rates. Note that this parameter can still be ignored (i.e., always set to 1) if the performance is not an issue for a given camera class.

get_frame_info_fields()[source]

Get the names of frame info fields.

Applicable when frame info format (set by set_frame_info_format()) is "list" or "array".

get_new_images_range()[source]

Get the range of the new images.

Return tuple (first, last) with images range (first inclusive). If no images are available, return None. If some images were in the buffer were overwritten, exclude them from the range.

read_multiple_images(rng=None, peek=False, missing_frame='skip', return_info=False)[source]

Read multiple images specified by rng (by default, all un-read images).

If rng is specified, it is a tuple (first, last) with images range (first inclusive). If no new frames are available, return an empty list; if no acquisition is running, return None. If peek==True, return images but not mark them as read. missing_frame determines what to do with frames which are out of range (missing or lost): can be "none" (replacing them with None), "zero" (replacing them with zero-filled frame), or "skip" (skipping them). If return_info==True, return tuple (frames, infos), where infos is a list of frame info tuples (camera-dependent, by default, only the frame index); if some frames are missing and missing_frame!="skip", the corresponding frame info is None.

read_oldest_image(peek=False, return_info=False)[source]

Read the oldest un-read image.

If no un-read frames are available, return None. If peek==True, return the image but not mark it as read. If return_info==True, return tuple (frame, info), where info is an info tuples (camera-dependent, see read_multiple_images()).

read_newest_image(peek=False, return_info=False)[source]

Read the newest un-read image.

If no un-read frames are available, return None. If peek==True, return the image but not mark it as read. If return_info==True, return tuple (frame, info), where info is an info tuples (camera-dependent, see read_multiple_images()).

grab(nframes=1, frame_timeout=5.0, missing_frame='none', return_info=False, buff_size=None)[source]

Snap nframes images (with preset image read mode parameters)

buff_size determines buffer size (if None, use the default size). Timeout is specified for a single-frame acquisition, not for the whole acquisition time. missing_frame determines what to do with frames which have been lost: can be "none" (replacing them with None), "zero" (replacing them with zero-filled frame), or "skip" (skipping them, while still keeping total returned frames number to n). If return_info==True, return tuple (frames, infos), where infos is a list of frame info tuples (camera-dependent); if some frames are missing and missing_frame!="skip", the corresponding frame info is None.

snap(timeout=5.0, return_info=False)[source]

Snap a single frame

class NoParameterCaller(device, kind)

Bases: object

Class to simplify calling functions without a parameter

apply_settings(settings)

Apply the settings.

settings is the dict {name: value} of the device available settings. Non-applicable settings are ignored.

close()

Close the connection

get_device_variable(key)

Get the value of a settings, status, or full info parameter

get_full_info(include=0)

Get dict {name: value} containing full device information (including status and settings).

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

get_full_status(include=0)

Get dict {name: value} containing the device status (including settings).

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

get_settings(include=0)

Get dict {name: value} containing all the device settings.

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

is_opened()

Check if the device is connected

open()

Open the connection

set_device_variable(key, value)

Set the value of a settings parameter

pylablib.devices.interface.camera.acqstopped(*args, **kwargs)[source]

Decorator which temporarily stops acquisition for the function call

pylablib.devices.interface.camera.acqcleared(*args, **kwargs)[source]

Decorator which temporarily clears acquisition for the function call

class pylablib.devices.interface.camera.FrameCounter[source]

Bases: object

Frame counter.

Keeps track of the buffer occupation, acquired/missed frames, last read and wait buffers, etc.

reset(buffer_size=None)[source]

Reset the counters.

If buffer_size is None, assume the the buffer is deallocated. Otherwise, it specifies the frame buffer size (in frames).

update_acquired_frames(acquired_frames)[source]

Update the counter of acquired frames (needs to be called by the camera whenever necessary)

wait_start(acquired_frames)[source]

Set up waiting routine (called in the beginning of ICamera.wait_for_frame())

is_wait_done(acquired_frames=None, since='lastread', nframes=1)[source]

Check if the waiting condition is satisfied based on the counter values:

If not None, acquired_frames specifies the most recent number of acquired frames (the internal counters is automatically updated). since and nframes have the same meaning as in ICamera.wait_for_frame().

wait_done()[source]

Clean up waiting routine (called in the end of ICamera.wait_for_frame())

get_frames_status(acquired_frames=None)[source]

Get status of the internal counters.

Return tuple (acquired, unread, skipped, buffer_size). If the buffer is not allocated, all counters are 0.

get_new_frames_range(acquired_frames=None)[source]

Get the range of the new frames (acquired but not read)

trim_frames_range(rng)[source]

Trim the given frames range to only contains frames which are still in the buffer (i.e., remove the frames which are too old and have been overwritten)

advance_read_frames(rng)[source]

Mark the specified frames range as read and advance the last read counter

set_first_valid_frame(first_valid_frame)[source]

Set the first valid frame; all frames older than it are considered invalid when calculating skipped frames and trimming ranges

class pylablib.devices.interface.camera.FrameNotifier(strict=False)[source]

Bases: object

Notifier for a new available frame.

Used when the camera runs a separate polling thread or a callback, which needs to notify the main thread that a new frame has been acquired.

Parameters:strict – determines whether wait() waits for a specified frame index, or just for any new frame (which is checked later)
reset()[source]

Reset the internal frame counter

inc()[source]

Increment the internal frame counter, notify the waiting threads, and return the counter value

wait(idx=None, timeout=None)[source]

Wait for a new frame with a given index (if None, for the next acquired frame)

class pylablib.devices.interface.camera.ChunkBufferManager(chunk_size=1048576)[source]

Bases: object

Buffer manager, which takes care of creating and removing the buffer chunks, and reading out some parts of them.

Parameters:chunk_size – the minimal size of a single buffer chunk (continuous memory segment potentially containing several frames).
get_ctypes_frames_list(ctype=<class 'ctypes.c_char_p'>)[source]

Get stored buffers as a ctypes array with pointer of the given type

get_frames_data(idx, nframes=1)[source]

Get frames data starting from idx and spanning nframes frames.

Return a list of tuples (nread, chunk_data), where nread is the number of frames in the chunk, and chunk_data is the raw buffer pointer as a ctypes.c_char_p object.

allocate(nframes, frame_size)[source]

Allocate buffers for the given number of frames and frame size (in bytes)

deallocate()[source]

Deallocate the buffers

class pylablib.devices.interface.camera.IAttributeCamera(*args, **kwargs)[source]

Bases: pylablib.devices.interface.camera.ICamera

Camera class which supports camera attributes.

The method _list_attributes must be defined in a subclass; it should produce a list of camera attributes, which have name attribute for placing them into a dictionary. Attributes can also have readable and writable attributes, which are used in get_all_attribute_values() and set_all_attribute_values() to determine if the attribute values should be collected or set. Method _update_attributes should be called on opening to populate the dictionary of available attributes.

One can also define _normalize_attribute_name, which normalizes the attribute name into a dictionary name (e.g., replaces separators, removes spaces, or normalizes case).

get_attribute(name, error_on_missing=True)[source]

Get the camera attribute with the given name

get_all_attributes(copy=False)[source]

Return a dictionary of all available attributes.

If copy==True, copy the dictionary; otherwise, return the internal dictionary structure (should not be modified).

get_attribute_value(name, error_on_missing=True, default=None, **kwargs)[source]

Get value of an attribute with the given name.

If the value doesn’t exist and error_on_missing==True, raise error; otherwise, return default. If default is not None, automatically assume that error_on_missing==False. If name points at a dictionary branch, return a dictionary with all values in this branch. Additional arguments are passed to get_value methods of the individual attribute.

set_attribute_value(name, value, error_on_missing=True, **kwargs)[source]

Set value of an attribute with the given name.

If the value doesn’t exist and error_on_missing==True, raise error; otherwise, do nothing. If name points at a dictionary branch, set all values in this branch (in this case value must be a dictionary). Additional arguments are passed to set_value methods of the individual attribute.

get_all_attribute_values(root='', **kwargs)[source]

Get values of all attributes with the given root.

Additional arguments are passed to get_value methods of individual attributes.

set_all_attribute_values(settings, root='', **kwargs)[source]

Set values of all attributes with the given root.

Additional arguments are passed to set_value methods of individual attributes.

Error

alias of pylablib.core.devio.base.DeviceError

FrameTransferError

alias of DefaultFrameTransferError

class NoParameterCaller(device, kind)

Bases: object

Class to simplify calling functions without a parameter

TimeoutError

alias of pylablib.core.devio.base.DeviceError

acquisition_in_progress()

Check if acquisition is in progress

apply_settings(settings)

Apply the settings.

settings is the dict {name: value} of the device available settings. Non-applicable settings are ignored.

clear_acquisition()

Clear acquisition settings

close()

Close the connection

get_acquisition_parameters()

Get acquisition parameters.

Return dictionary {name: value}

get_data_dimensions()

Get readout data dimensions (in pixels) as a tuple (width, height); take indexing mode into account

get_detector_size()

Get camera detector size (in pixels) as a tuple (width, height)

get_device_variable(key)

Get the value of a settings, status, or full info parameter

get_frame_format()

Get format for the returned images.

Can be "list" (list of 2D arrays, or 3D array for some fastbuff cameras), "array" (a single 3D array).

get_frame_info_fields()

Get the names of frame info fields.

Applicable when frame info format (set by set_frame_info_format()) is "list" or "array".

get_frame_info_format()

Get format of the frame info.

Can be "namedtuple" (potentially nested named tuples; convenient to get particular values), "list" (flat list of values, with field names are given by get_frame_info_fields(); convenient for building a table), "array" (same as "list", but with a numpy array, which is easier to use for fastbuff readout supported by some cameras), or "dict" (flat dictionary with the same fields as the "list" format; more resilient to future format changes)

get_frame_info_period()

Get period of frame info acquisition.

Frame info might be skipped (set to None) except for frames which indices are divisible by period. Useful for certain cameras where acquiring frame info takes a lot of time and can reduce performance at higher frame rates. Note that this parameter can still be ignored (i.e., always set to 1) if the performance is not an issue for a given camera class.

get_frames_status()

Get acquisition and buffer status.

Return tuple (acquired, unread, skipped, size), where acquired is the total number of acquired frames, unread is the number of acquired but not read frames, skipped is the number of skipped (not read and then written over) frames, and buffer_size is the total buffer size (in frames).

get_full_info(include=0)

Get dict {name: value} containing full device information (including status and settings).

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

get_full_status(include=0)

Get dict {name: value} containing the device status (including settings).

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

get_image_indexing()

Get indexing for the returned images.

Can be "rct" (first index row, second index column, rows counted from the top), "rcb" (same as "rc", rows counted from the bottom), "xyt" (first index column, second index row, rows counted from the top), or "xyb" (same as "xyt", rows counted from the bottom)

get_new_images_range()

Get the range of the new images.

Return tuple (first, last) with images range (first inclusive). If no images are available, return None. If some images were in the buffer were overwritten, exclude them from the range.

get_settings(include=0)

Get dict {name: value} containing all the device settings.

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

grab(nframes=1, frame_timeout=5.0, missing_frame='none', return_info=False, buff_size=None)

Snap nframes images (with preset image read mode parameters)

buff_size determines buffer size (if None, use the default size). Timeout is specified for a single-frame acquisition, not for the whole acquisition time. missing_frame determines what to do with frames which have been lost: can be "none" (replacing them with None), "zero" (replacing them with zero-filled frame), or "skip" (skipping them, while still keeping total returned frames number to n). If return_info==True, return tuple (frames, infos), where infos is a list of frame info tuples (camera-dependent); if some frames are missing and missing_frame!="skip", the corresponding frame info is None.

is_acquisition_setup()

Check if acquisition is set up.

If the camera does not support separate acquisition setup, always return True.

is_opened()

Check if the device is connected

open()

Open the connection

pausing_acquisition(clear=None)

Context manager which temporarily pauses acquisition during execution of with block.

Useful for applying certain settings which can’t be changed during the acquisition. If clear==True, clear acquisition in addition to pausing (by default, use the class default specified as _clear_pausing_acquisition attribute). Yields tuple (acq_in_progress, acq_params), which indicates whether acquisition is currently in progress, and what are the current acquisition parameters.

read_multiple_images(rng=None, peek=False, missing_frame='skip', return_info=False)

Read multiple images specified by rng (by default, all un-read images).

If rng is specified, it is a tuple (first, last) with images range (first inclusive). If no new frames are available, return an empty list; if no acquisition is running, return None. If peek==True, return images but not mark them as read. missing_frame determines what to do with frames which are out of range (missing or lost): can be "none" (replacing them with None), "zero" (replacing them with zero-filled frame), or "skip" (skipping them). If return_info==True, return tuple (frames, infos), where infos is a list of frame info tuples (camera-dependent, by default, only the frame index); if some frames are missing and missing_frame!="skip", the corresponding frame info is None.

read_newest_image(peek=False, return_info=False)

Read the newest un-read image.

If no un-read frames are available, return None. If peek==True, return the image but not mark it as read. If return_info==True, return tuple (frame, info), where info is an info tuples (camera-dependent, see read_multiple_images()).

read_oldest_image(peek=False, return_info=False)

Read the oldest un-read image.

If no un-read frames are available, return None. If peek==True, return the image but not mark it as read. If return_info==True, return tuple (frame, info), where info is an info tuples (camera-dependent, see read_multiple_images()).

set_device_variable(key, value)

Set the value of a settings parameter

set_frame_format(fmt)

Set format for the returned images.

Can be "list" (list of 2D arrays, or 3D array for some fastbuff cameras), "array" (a single 3D array). Note that if the format is set to "array", the frame info format is also automatically set to "array".

set_frame_info_format(fmt, include_fields=None)

Set format of the frame info.

Can be "namedtuple" (potentially nested named tuples; convenient to get particular values), "list" (flat list of values, with field names are given by get_frame_info_fields(); convenient for building a table), "array" (same as "list", but with a numpy array, which is easier to use for fastbuff readout supported by some cameras), or "dict" (flat dictionary with the same fields as the "list" format; more resilient to future format changes) If include_fields is not None, it specifies the fields included for non-"tuple" formats.

set_frame_info_period(period=1)

Set period of frame info acquisition.

Frame info might be skipped (set to None) except for frames which indices are divisible by period. Useful for certain cameras where acquiring frame info takes a lot of time and can reduce performance at higher frame rates. Note that this parameter can still be ignored (i.e., always set to 1) if the performance is not an issue for a given camera class.

set_image_indexing(indexing)

Set up indexing for the returned images.

Can be "rct" (first index row, second index column, rows counted from the top), "rcb" (same as "rc", rows counted from the bottom), "xyt" (first index column, second index row, rows counted from the top), or "xyb" (same as "xyt", rows counted from the bottom)

setup_acquisition(**kwargs)

Setup acquisition.

Any non-specified acquisition parameters are assumed to be the same as previously set (or default, if not explicitly set before). Return the new acquisition parameters.

snap(timeout=5.0, return_info=False)

Snap a single frame

start_acquisition(*args, **kwargs)

Start acquisition.

Can take the same keyword parameters as :meth:``setup_acquisition. If the acquisition is not set up yet, set it up using the supplied parameters (use default of setup_acquisition(),if the parameter is None). Otherwise, if any supplied parameters are different from the current ones, change them and reset the acquisition.

stop_acquisition()

Stop acquisition

wait_for_frame(since='lastread', nframes=1, timeout=20.0, error_on_stopped=False)

Wait for one or several new camera frames.

since specifies the reference point for waiting to acquire nframes frames; can be “lastread”`` (from the last read frame), "lastwait" (wait for the last successful wait_for_frame() call), "now" (from the start of the current call), or "start" (from the acquisition start, i.e., wait until nframes frames have been acquired). timeout can be either a number, None (infinite timeout), or a tuple (timeout, frame_timeout), in which case the call times out if the total time exceeds timeout, or a single frame wait exceeds frame_timeout. If the call times out, raise TimeoutError. If error_on_stopped==True and the acquisition is not running, raise Error; otherwise, simply return False without waiting.

class pylablib.devices.interface.camera.IGrabberAttributeCamera(*args, **kwargs)[source]

Bases: pylablib.devices.interface.camera.ICamera

Camera class which supports frame grabber attributes.

Essentially the same as IAttributeCamera, but with relevant methods and attributes renamed to support both frame grabber and camera attributes handling simultaneously.

The method _list_grabber_attributes must be defined in a subclass; it should produce a list of camera attributes, which have name attribute for placing them into a dictionary. Attributes can also have readable and writable attributes, which are used in get_all_grabber_attribute_values() and set_all_grabber_attribute_values() to determine if the attribute values should be collected or set. Method _update_grabber_attributes should be called on opening to populate the dictionary of available attributes.

One can also define _normalize_grabber_attribute_name, which normalizes the attribute name into a dictionary name (e.g., replaces separators, removes spaces, or normalizes case).

get_grabber_attribute(name, error_on_missing=True)[source]

Get the camera attribute with the given name

get_all_grabber_attributes(copy=False)[source]

Return a dictionary of all available frame grabber grabber_attributes.

If copy==True, copy the dictionary; otherwise, return the internal dictionary structure (should not be modified).

get_grabber_attribute_value(name, error_on_missing=True, default=None, **kwargs)[source]

Get value of a frame grabber attribute with the given name.

If the value doesn’t exist and error_on_missing==True, raise error; otherwise, return default. If default is not None, automatically assume that error_on_missing==False. If name points at a dictionary branch, return a dictionary with all values in this branch. Additional arguments are passed to get_value methods of the individual attribute.

set_grabber_attribute_value(name, value, error_on_missing=True, **kwargs)[source]

Set value of a frame grabber attribute with the given name.

If the value doesn’t exist and error_on_missing==True, raise error; otherwise, do nothing. If name points at a dictionary branch, set all values in this branch (in this case value must be a dictionary). Additional arguments are passed to set_value methods of the individual attribute.

get_all_grabber_attribute_values(root='', **kwargs)[source]

Get values of all frame grabber attributes with the given root.

Additional arguments are passed to get_value methods of individual attributes.

set_all_grabber_attribute_values(settings, root='', **kwargs)[source]

Set values of all frame grabber attributes with the given root.

Additional arguments are passed to set_value methods of individual attributes.

Error

alias of pylablib.core.devio.base.DeviceError

FrameTransferError

alias of DefaultFrameTransferError

class NoParameterCaller(device, kind)

Bases: object

Class to simplify calling functions without a parameter

TimeoutError

alias of pylablib.core.devio.base.DeviceError

acquisition_in_progress()

Check if acquisition is in progress

apply_settings(settings)

Apply the settings.

settings is the dict {name: value} of the device available settings. Non-applicable settings are ignored.

clear_acquisition()

Clear acquisition settings

close()

Close the connection

get_acquisition_parameters()

Get acquisition parameters.

Return dictionary {name: value}

get_data_dimensions()

Get readout data dimensions (in pixels) as a tuple (width, height); take indexing mode into account

get_detector_size()

Get camera detector size (in pixels) as a tuple (width, height)

get_device_variable(key)

Get the value of a settings, status, or full info parameter

get_frame_format()

Get format for the returned images.

Can be "list" (list of 2D arrays, or 3D array for some fastbuff cameras), "array" (a single 3D array).

get_frame_info_fields()

Get the names of frame info fields.

Applicable when frame info format (set by set_frame_info_format()) is "list" or "array".

get_frame_info_format()

Get format of the frame info.

Can be "namedtuple" (potentially nested named tuples; convenient to get particular values), "list" (flat list of values, with field names are given by get_frame_info_fields(); convenient for building a table), "array" (same as "list", but with a numpy array, which is easier to use for fastbuff readout supported by some cameras), or "dict" (flat dictionary with the same fields as the "list" format; more resilient to future format changes)

get_frame_info_period()

Get period of frame info acquisition.

Frame info might be skipped (set to None) except for frames which indices are divisible by period. Useful for certain cameras where acquiring frame info takes a lot of time and can reduce performance at higher frame rates. Note that this parameter can still be ignored (i.e., always set to 1) if the performance is not an issue for a given camera class.

get_frames_status()

Get acquisition and buffer status.

Return tuple (acquired, unread, skipped, size), where acquired is the total number of acquired frames, unread is the number of acquired but not read frames, skipped is the number of skipped (not read and then written over) frames, and buffer_size is the total buffer size (in frames).

get_full_info(include=0)

Get dict {name: value} containing full device information (including status and settings).

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

get_full_status(include=0)

Get dict {name: value} containing the device status (including settings).

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

get_image_indexing()

Get indexing for the returned images.

Can be "rct" (first index row, second index column, rows counted from the top), "rcb" (same as "rc", rows counted from the bottom), "xyt" (first index column, second index row, rows counted from the top), or "xyb" (same as "xyt", rows counted from the bottom)

get_new_images_range()

Get the range of the new images.

Return tuple (first, last) with images range (first inclusive). If no images are available, return None. If some images were in the buffer were overwritten, exclude them from the range.

get_settings(include=0)

Get dict {name: value} containing all the device settings.

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

grab(nframes=1, frame_timeout=5.0, missing_frame='none', return_info=False, buff_size=None)

Snap nframes images (with preset image read mode parameters)

buff_size determines buffer size (if None, use the default size). Timeout is specified for a single-frame acquisition, not for the whole acquisition time. missing_frame determines what to do with frames which have been lost: can be "none" (replacing them with None), "zero" (replacing them with zero-filled frame), or "skip" (skipping them, while still keeping total returned frames number to n). If return_info==True, return tuple (frames, infos), where infos is a list of frame info tuples (camera-dependent); if some frames are missing and missing_frame!="skip", the corresponding frame info is None.

is_acquisition_setup()

Check if acquisition is set up.

If the camera does not support separate acquisition setup, always return True.

is_opened()

Check if the device is connected

open()

Open the connection

pausing_acquisition(clear=None)

Context manager which temporarily pauses acquisition during execution of with block.

Useful for applying certain settings which can’t be changed during the acquisition. If clear==True, clear acquisition in addition to pausing (by default, use the class default specified as _clear_pausing_acquisition attribute). Yields tuple (acq_in_progress, acq_params), which indicates whether acquisition is currently in progress, and what are the current acquisition parameters.

read_multiple_images(rng=None, peek=False, missing_frame='skip', return_info=False)

Read multiple images specified by rng (by default, all un-read images).

If rng is specified, it is a tuple (first, last) with images range (first inclusive). If no new frames are available, return an empty list; if no acquisition is running, return None. If peek==True, return images but not mark them as read. missing_frame determines what to do with frames which are out of range (missing or lost): can be "none" (replacing them with None), "zero" (replacing them with zero-filled frame), or "skip" (skipping them). If return_info==True, return tuple (frames, infos), where infos is a list of frame info tuples (camera-dependent, by default, only the frame index); if some frames are missing and missing_frame!="skip", the corresponding frame info is None.

read_newest_image(peek=False, return_info=False)

Read the newest un-read image.

If no un-read frames are available, return None. If peek==True, return the image but not mark it as read. If return_info==True, return tuple (frame, info), where info is an info tuples (camera-dependent, see read_multiple_images()).

read_oldest_image(peek=False, return_info=False)

Read the oldest un-read image.

If no un-read frames are available, return None. If peek==True, return the image but not mark it as read. If return_info==True, return tuple (frame, info), where info is an info tuples (camera-dependent, see read_multiple_images()).

set_device_variable(key, value)

Set the value of a settings parameter

set_frame_format(fmt)

Set format for the returned images.

Can be "list" (list of 2D arrays, or 3D array for some fastbuff cameras), "array" (a single 3D array). Note that if the format is set to "array", the frame info format is also automatically set to "array".

set_frame_info_format(fmt, include_fields=None)

Set format of the frame info.

Can be "namedtuple" (potentially nested named tuples; convenient to get particular values), "list" (flat list of values, with field names are given by get_frame_info_fields(); convenient for building a table), "array" (same as "list", but with a numpy array, which is easier to use for fastbuff readout supported by some cameras), or "dict" (flat dictionary with the same fields as the "list" format; more resilient to future format changes) If include_fields is not None, it specifies the fields included for non-"tuple" formats.

set_frame_info_period(period=1)

Set period of frame info acquisition.

Frame info might be skipped (set to None) except for frames which indices are divisible by period. Useful for certain cameras where acquiring frame info takes a lot of time and can reduce performance at higher frame rates. Note that this parameter can still be ignored (i.e., always set to 1) if the performance is not an issue for a given camera class.

set_image_indexing(indexing)

Set up indexing for the returned images.

Can be "rct" (first index row, second index column, rows counted from the top), "rcb" (same as "rc", rows counted from the bottom), "xyt" (first index column, second index row, rows counted from the top), or "xyb" (same as "xyt", rows counted from the bottom)

setup_acquisition(**kwargs)

Setup acquisition.

Any non-specified acquisition parameters are assumed to be the same as previously set (or default, if not explicitly set before). Return the new acquisition parameters.

snap(timeout=5.0, return_info=False)

Snap a single frame

start_acquisition(*args, **kwargs)

Start acquisition.

Can take the same keyword parameters as :meth:``setup_acquisition. If the acquisition is not set up yet, set it up using the supplied parameters (use default of setup_acquisition(),if the parameter is None). Otherwise, if any supplied parameters are different from the current ones, change them and reset the acquisition.

stop_acquisition()

Stop acquisition

wait_for_frame(since='lastread', nframes=1, timeout=20.0, error_on_stopped=False)

Wait for one or several new camera frames.

since specifies the reference point for waiting to acquire nframes frames; can be “lastread”`` (from the last read frame), "lastwait" (wait for the last successful wait_for_frame() call), "now" (from the start of the current call), or "start" (from the acquisition start, i.e., wait until nframes frames have been acquired). timeout can be either a number, None (infinite timeout), or a tuple (timeout, frame_timeout), in which case the call times out if the total time exceeds timeout, or a single frame wait exceeds frame_timeout. If the call times out, raise TimeoutError. If error_on_stopped==True and the acquisition is not running, raise Error; otherwise, simply return False without waiting.

class pylablib.devices.interface.camera.TAcqTimings(exposure, frame_period)

Bases: tuple

count()

Return number of occurrences of value.

exposure
frame_period
index()

Return first index of value.

Raises ValueError if the value is not present.

class pylablib.devices.interface.camera.IExposureCamera(*args, **kwargs)[source]

Bases: pylablib.devices.interface.camera.ICamera

get_exposure()[source]

Get current exposure

set_exposure(exposure)[source]

Set camera exposure

get_frame_period()[source]

Get frame period (time between two consecutive frames in the internal trigger mode)

get_frame_timings()[source]

Get acquisition timing.

Return tuple (exposure, frame_period).

Error

alias of pylablib.core.devio.base.DeviceError

FrameTransferError

alias of DefaultFrameTransferError

class NoParameterCaller(device, kind)

Bases: object

Class to simplify calling functions without a parameter

TimeoutError

alias of pylablib.core.devio.base.DeviceError

acquisition_in_progress()

Check if acquisition is in progress

apply_settings(settings)

Apply the settings.

settings is the dict {name: value} of the device available settings. Non-applicable settings are ignored.

clear_acquisition()

Clear acquisition settings

close()

Close the connection

get_acquisition_parameters()

Get acquisition parameters.

Return dictionary {name: value}

get_data_dimensions()

Get readout data dimensions (in pixels) as a tuple (width, height); take indexing mode into account

get_detector_size()

Get camera detector size (in pixels) as a tuple (width, height)

get_device_variable(key)

Get the value of a settings, status, or full info parameter

get_frame_format()

Get format for the returned images.

Can be "list" (list of 2D arrays, or 3D array for some fastbuff cameras), "array" (a single 3D array).

get_frame_info_fields()

Get the names of frame info fields.

Applicable when frame info format (set by set_frame_info_format()) is "list" or "array".

get_frame_info_format()

Get format of the frame info.

Can be "namedtuple" (potentially nested named tuples; convenient to get particular values), "list" (flat list of values, with field names are given by get_frame_info_fields(); convenient for building a table), "array" (same as "list", but with a numpy array, which is easier to use for fastbuff readout supported by some cameras), or "dict" (flat dictionary with the same fields as the "list" format; more resilient to future format changes)

get_frame_info_period()

Get period of frame info acquisition.

Frame info might be skipped (set to None) except for frames which indices are divisible by period. Useful for certain cameras where acquiring frame info takes a lot of time and can reduce performance at higher frame rates. Note that this parameter can still be ignored (i.e., always set to 1) if the performance is not an issue for a given camera class.

get_frames_status()

Get acquisition and buffer status.

Return tuple (acquired, unread, skipped, size), where acquired is the total number of acquired frames, unread is the number of acquired but not read frames, skipped is the number of skipped (not read and then written over) frames, and buffer_size is the total buffer size (in frames).

get_full_info(include=0)

Get dict {name: value} containing full device information (including status and settings).

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

get_full_status(include=0)

Get dict {name: value} containing the device status (including settings).

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

get_image_indexing()

Get indexing for the returned images.

Can be "rct" (first index row, second index column, rows counted from the top), "rcb" (same as "rc", rows counted from the bottom), "xyt" (first index column, second index row, rows counted from the top), or "xyb" (same as "xyt", rows counted from the bottom)

get_new_images_range()

Get the range of the new images.

Return tuple (first, last) with images range (first inclusive). If no images are available, return None. If some images were in the buffer were overwritten, exclude them from the range.

get_settings(include=0)

Get dict {name: value} containing all the device settings.

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

grab(nframes=1, frame_timeout=5.0, missing_frame='none', return_info=False, buff_size=None)

Snap nframes images (with preset image read mode parameters)

buff_size determines buffer size (if None, use the default size). Timeout is specified for a single-frame acquisition, not for the whole acquisition time. missing_frame determines what to do with frames which have been lost: can be "none" (replacing them with None), "zero" (replacing them with zero-filled frame), or "skip" (skipping them, while still keeping total returned frames number to n). If return_info==True, return tuple (frames, infos), where infos is a list of frame info tuples (camera-dependent); if some frames are missing and missing_frame!="skip", the corresponding frame info is None.

is_acquisition_setup()

Check if acquisition is set up.

If the camera does not support separate acquisition setup, always return True.

is_opened()

Check if the device is connected

open()

Open the connection

pausing_acquisition(clear=None)

Context manager which temporarily pauses acquisition during execution of with block.

Useful for applying certain settings which can’t be changed during the acquisition. If clear==True, clear acquisition in addition to pausing (by default, use the class default specified as _clear_pausing_acquisition attribute). Yields tuple (acq_in_progress, acq_params), which indicates whether acquisition is currently in progress, and what are the current acquisition parameters.

read_multiple_images(rng=None, peek=False, missing_frame='skip', return_info=False)

Read multiple images specified by rng (by default, all un-read images).

If rng is specified, it is a tuple (first, last) with images range (first inclusive). If no new frames are available, return an empty list; if no acquisition is running, return None. If peek==True, return images but not mark them as read. missing_frame determines what to do with frames which are out of range (missing or lost): can be "none" (replacing them with None), "zero" (replacing them with zero-filled frame), or "skip" (skipping them). If return_info==True, return tuple (frames, infos), where infos is a list of frame info tuples (camera-dependent, by default, only the frame index); if some frames are missing and missing_frame!="skip", the corresponding frame info is None.

read_newest_image(peek=False, return_info=False)

Read the newest un-read image.

If no un-read frames are available, return None. If peek==True, return the image but not mark it as read. If return_info==True, return tuple (frame, info), where info is an info tuples (camera-dependent, see read_multiple_images()).

read_oldest_image(peek=False, return_info=False)

Read the oldest un-read image.

If no un-read frames are available, return None. If peek==True, return the image but not mark it as read. If return_info==True, return tuple (frame, info), where info is an info tuples (camera-dependent, see read_multiple_images()).

set_device_variable(key, value)

Set the value of a settings parameter

set_frame_format(fmt)

Set format for the returned images.

Can be "list" (list of 2D arrays, or 3D array for some fastbuff cameras), "array" (a single 3D array). Note that if the format is set to "array", the frame info format is also automatically set to "array".

set_frame_info_format(fmt, include_fields=None)

Set format of the frame info.

Can be "namedtuple" (potentially nested named tuples; convenient to get particular values), "list" (flat list of values, with field names are given by get_frame_info_fields(); convenient for building a table), "array" (same as "list", but with a numpy array, which is easier to use for fastbuff readout supported by some cameras), or "dict" (flat dictionary with the same fields as the "list" format; more resilient to future format changes) If include_fields is not None, it specifies the fields included for non-"tuple" formats.

set_frame_info_period(period=1)

Set period of frame info acquisition.

Frame info might be skipped (set to None) except for frames which indices are divisible by period. Useful for certain cameras where acquiring frame info takes a lot of time and can reduce performance at higher frame rates. Note that this parameter can still be ignored (i.e., always set to 1) if the performance is not an issue for a given camera class.

set_image_indexing(indexing)

Set up indexing for the returned images.

Can be "rct" (first index row, second index column, rows counted from the top), "rcb" (same as "rc", rows counted from the bottom), "xyt" (first index column, second index row, rows counted from the top), or "xyb" (same as "xyt", rows counted from the bottom)

setup_acquisition(**kwargs)

Setup acquisition.

Any non-specified acquisition parameters are assumed to be the same as previously set (or default, if not explicitly set before). Return the new acquisition parameters.

snap(timeout=5.0, return_info=False)

Snap a single frame

start_acquisition(*args, **kwargs)

Start acquisition.

Can take the same keyword parameters as :meth:``setup_acquisition. If the acquisition is not set up yet, set it up using the supplied parameters (use default of setup_acquisition(),if the parameter is None). Otherwise, if any supplied parameters are different from the current ones, change them and reset the acquisition.

stop_acquisition()

Stop acquisition

wait_for_frame(since='lastread', nframes=1, timeout=20.0, error_on_stopped=False)

Wait for one or several new camera frames.

since specifies the reference point for waiting to acquire nframes frames; can be “lastread”`` (from the last read frame), "lastwait" (wait for the last successful wait_for_frame() call), "now" (from the start of the current call), or "start" (from the acquisition start, i.e., wait until nframes frames have been acquired). timeout can be either a number, None (infinite timeout), or a tuple (timeout, frame_timeout), in which case the call times out if the total time exceeds timeout, or a single frame wait exceeds frame_timeout. If the call times out, raise TimeoutError. If error_on_stopped==True and the acquisition is not running, raise Error; otherwise, simply return False without waiting.

class pylablib.devices.interface.camera.TAxisROILimit(min, max, pstep, sstep, maxbin)

Bases: tuple

count()

Return number of occurrences of value.

index()

Return first index of value.

Raises ValueError if the value is not present.

max
maxbin
min
pstep
sstep
pylablib.devices.interface.camera.truncate_roi_axis(roi, lim, symmetric=False)[source]

Truncate ROI to conform to the given ROI limits.

roi is a tuple (start, stop, bin), and lim is a tuple (min, max, pstep, sstep, maxbin). Assume that pstep and sstep divide min and max, and that either pstep divides sstep or the other way around. If symmetric==True, then max should be even.

class pylablib.devices.interface.camera.IROICamera(*args, **kwargs)[source]

Bases: pylablib.devices.interface.camera.ICamera

get_roi()[source]

Get current ROI.

Return tuple (hstart, hend, vstart, vend). hstart and hend specify horizontal image extent, vstart and vend specify vertical image extent (start is inclusive, stop is exclusive, starting from 0).

set_roi(hstart=0, hend=None, vstart=0, vend=None)[source]

Setup camera ROI.

hstart and hend specify horizontal image extent, vstart and vend specify vertical image extent (start is inclusive, stop is exclusive, starting from 0). By default, all non-supplied parameters take extreme values (0 for start, maximal for end).

get_roi_limits(hbin=1, vbin=1)[source]

Get the minimal and maximal ROI parameters.

Return tuple (hlim, vlim), where each element is in turn a limit 5-tuple (min, max, pstep, sstep, maxbin) with, correspondingly, minimal and maximal size, position and size step, and the maximal binning (fixed to 1 if not binning is allowed). In some cameras, the step and the minimal size depend on the binning, which can be supplied.

Error

alias of pylablib.core.devio.base.DeviceError

FrameTransferError

alias of DefaultFrameTransferError

class NoParameterCaller(device, kind)

Bases: object

Class to simplify calling functions without a parameter

TimeoutError

alias of pylablib.core.devio.base.DeviceError

acquisition_in_progress()

Check if acquisition is in progress

apply_settings(settings)

Apply the settings.

settings is the dict {name: value} of the device available settings. Non-applicable settings are ignored.

clear_acquisition()

Clear acquisition settings

close()

Close the connection

get_acquisition_parameters()

Get acquisition parameters.

Return dictionary {name: value}

get_data_dimensions()

Get readout data dimensions (in pixels) as a tuple (width, height); take indexing mode into account

get_detector_size()

Get camera detector size (in pixels) as a tuple (width, height)

get_device_variable(key)

Get the value of a settings, status, or full info parameter

get_frame_format()

Get format for the returned images.

Can be "list" (list of 2D arrays, or 3D array for some fastbuff cameras), "array" (a single 3D array).

get_frame_info_fields()

Get the names of frame info fields.

Applicable when frame info format (set by set_frame_info_format()) is "list" or "array".

get_frame_info_format()

Get format of the frame info.

Can be "namedtuple" (potentially nested named tuples; convenient to get particular values), "list" (flat list of values, with field names are given by get_frame_info_fields(); convenient for building a table), "array" (same as "list", but with a numpy array, which is easier to use for fastbuff readout supported by some cameras), or "dict" (flat dictionary with the same fields as the "list" format; more resilient to future format changes)

get_frame_info_period()

Get period of frame info acquisition.

Frame info might be skipped (set to None) except for frames which indices are divisible by period. Useful for certain cameras where acquiring frame info takes a lot of time and can reduce performance at higher frame rates. Note that this parameter can still be ignored (i.e., always set to 1) if the performance is not an issue for a given camera class.

get_frames_status()

Get acquisition and buffer status.

Return tuple (acquired, unread, skipped, size), where acquired is the total number of acquired frames, unread is the number of acquired but not read frames, skipped is the number of skipped (not read and then written over) frames, and buffer_size is the total buffer size (in frames).

get_full_info(include=0)

Get dict {name: value} containing full device information (including status and settings).

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

get_full_status(include=0)

Get dict {name: value} containing the device status (including settings).

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

get_image_indexing()

Get indexing for the returned images.

Can be "rct" (first index row, second index column, rows counted from the top), "rcb" (same as "rc", rows counted from the bottom), "xyt" (first index column, second index row, rows counted from the top), or "xyb" (same as "xyt", rows counted from the bottom)

get_new_images_range()

Get the range of the new images.

Return tuple (first, last) with images range (first inclusive). If no images are available, return None. If some images were in the buffer were overwritten, exclude them from the range.

get_settings(include=0)

Get dict {name: value} containing all the device settings.

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

grab(nframes=1, frame_timeout=5.0, missing_frame='none', return_info=False, buff_size=None)

Snap nframes images (with preset image read mode parameters)

buff_size determines buffer size (if None, use the default size). Timeout is specified for a single-frame acquisition, not for the whole acquisition time. missing_frame determines what to do with frames which have been lost: can be "none" (replacing them with None), "zero" (replacing them with zero-filled frame), or "skip" (skipping them, while still keeping total returned frames number to n). If return_info==True, return tuple (frames, infos), where infos is a list of frame info tuples (camera-dependent); if some frames are missing and missing_frame!="skip", the corresponding frame info is None.

is_acquisition_setup()

Check if acquisition is set up.

If the camera does not support separate acquisition setup, always return True.

is_opened()

Check if the device is connected

open()

Open the connection

pausing_acquisition(clear=None)

Context manager which temporarily pauses acquisition during execution of with block.

Useful for applying certain settings which can’t be changed during the acquisition. If clear==True, clear acquisition in addition to pausing (by default, use the class default specified as _clear_pausing_acquisition attribute). Yields tuple (acq_in_progress, acq_params), which indicates whether acquisition is currently in progress, and what are the current acquisition parameters.

read_multiple_images(rng=None, peek=False, missing_frame='skip', return_info=False)

Read multiple images specified by rng (by default, all un-read images).

If rng is specified, it is a tuple (first, last) with images range (first inclusive). If no new frames are available, return an empty list; if no acquisition is running, return None. If peek==True, return images but not mark them as read. missing_frame determines what to do with frames which are out of range (missing or lost): can be "none" (replacing them with None), "zero" (replacing them with zero-filled frame), or "skip" (skipping them). If return_info==True, return tuple (frames, infos), where infos is a list of frame info tuples (camera-dependent, by default, only the frame index); if some frames are missing and missing_frame!="skip", the corresponding frame info is None.

read_newest_image(peek=False, return_info=False)

Read the newest un-read image.

If no un-read frames are available, return None. If peek==True, return the image but not mark it as read. If return_info==True, return tuple (frame, info), where info is an info tuples (camera-dependent, see read_multiple_images()).

read_oldest_image(peek=False, return_info=False)

Read the oldest un-read image.

If no un-read frames are available, return None. If peek==True, return the image but not mark it as read. If return_info==True, return tuple (frame, info), where info is an info tuples (camera-dependent, see read_multiple_images()).

set_device_variable(key, value)

Set the value of a settings parameter

set_frame_format(fmt)

Set format for the returned images.

Can be "list" (list of 2D arrays, or 3D array for some fastbuff cameras), "array" (a single 3D array). Note that if the format is set to "array", the frame info format is also automatically set to "array".

set_frame_info_format(fmt, include_fields=None)

Set format of the frame info.

Can be "namedtuple" (potentially nested named tuples; convenient to get particular values), "list" (flat list of values, with field names are given by get_frame_info_fields(); convenient for building a table), "array" (same as "list", but with a numpy array, which is easier to use for fastbuff readout supported by some cameras), or "dict" (flat dictionary with the same fields as the "list" format; more resilient to future format changes) If include_fields is not None, it specifies the fields included for non-"tuple" formats.

set_frame_info_period(period=1)

Set period of frame info acquisition.

Frame info might be skipped (set to None) except for frames which indices are divisible by period. Useful for certain cameras where acquiring frame info takes a lot of time and can reduce performance at higher frame rates. Note that this parameter can still be ignored (i.e., always set to 1) if the performance is not an issue for a given camera class.

set_image_indexing(indexing)

Set up indexing for the returned images.

Can be "rct" (first index row, second index column, rows counted from the top), "rcb" (same as "rc", rows counted from the bottom), "xyt" (first index column, second index row, rows counted from the top), or "xyb" (same as "xyt", rows counted from the bottom)

setup_acquisition(**kwargs)

Setup acquisition.

Any non-specified acquisition parameters are assumed to be the same as previously set (or default, if not explicitly set before). Return the new acquisition parameters.

snap(timeout=5.0, return_info=False)

Snap a single frame

start_acquisition(*args, **kwargs)

Start acquisition.

Can take the same keyword parameters as :meth:``setup_acquisition. If the acquisition is not set up yet, set it up using the supplied parameters (use default of setup_acquisition(),if the parameter is None). Otherwise, if any supplied parameters are different from the current ones, change them and reset the acquisition.

stop_acquisition()

Stop acquisition

wait_for_frame(since='lastread', nframes=1, timeout=20.0, error_on_stopped=False)

Wait for one or several new camera frames.

since specifies the reference point for waiting to acquire nframes frames; can be “lastread”`` (from the last read frame), "lastwait" (wait for the last successful wait_for_frame() call), "now" (from the start of the current call), or "start" (from the acquisition start, i.e., wait until nframes frames have been acquired). timeout can be either a number, None (infinite timeout), or a tuple (timeout, frame_timeout), in which case the call times out if the total time exceeds timeout, or a single frame wait exceeds frame_timeout. If the call times out, raise TimeoutError. If error_on_stopped==True and the acquisition is not running, raise Error; otherwise, simply return False without waiting.

class pylablib.devices.interface.camera.IBinROICamera(*args, **kwargs)[source]

Bases: pylablib.devices.interface.camera.ICamera

get_roi()[source]

Get current ROI.

Return tuple (hstart, hend, vstart, vend, hbin, vbin). hstart and hend specify horizontal image extent, vstart and vend specify vertical image extent (start is inclusive, stop is exclusive, starting from 0), hbin and vbin specify binning.

set_roi(hstart=0, hend=None, vstart=0, vend=None, hbin=1, vbin=1)[source]

Setup camera ROI.

hstart and hend specify horizontal image extent, vstart and vend specify vertical image extent (start is inclusive, stop is exclusive, starting from 0), hbin and vbin specify binning. By default, all non-supplied parameters take extreme values (0 for start, maximal for end, 1 for binning).

get_roi_limits(hbin=1, vbin=1)[source]

Get the minimal and maximal ROI parameters.

Return tuple (hlim, vlim), where each element is in turn a limit 5-tuple (min, max, pstep, sstep, maxbin) with, correspondingly, minimal and maximal size, position and size step, and the maximal binning. In some cameras, the step and the minimal size depend on the binning, which can be supplied.

Error

alias of pylablib.core.devio.base.DeviceError

FrameTransferError

alias of DefaultFrameTransferError

class NoParameterCaller(device, kind)

Bases: object

Class to simplify calling functions without a parameter

TimeoutError

alias of pylablib.core.devio.base.DeviceError

acquisition_in_progress()

Check if acquisition is in progress

apply_settings(settings)

Apply the settings.

settings is the dict {name: value} of the device available settings. Non-applicable settings are ignored.

clear_acquisition()

Clear acquisition settings

close()

Close the connection

get_acquisition_parameters()

Get acquisition parameters.

Return dictionary {name: value}

get_data_dimensions()

Get readout data dimensions (in pixels) as a tuple (width, height); take indexing mode into account

get_detector_size()

Get camera detector size (in pixels) as a tuple (width, height)

get_device_variable(key)

Get the value of a settings, status, or full info parameter

get_frame_format()

Get format for the returned images.

Can be "list" (list of 2D arrays, or 3D array for some fastbuff cameras), "array" (a single 3D array).

get_frame_info_fields()

Get the names of frame info fields.

Applicable when frame info format (set by set_frame_info_format()) is "list" or "array".

get_frame_info_format()

Get format of the frame info.

Can be "namedtuple" (potentially nested named tuples; convenient to get particular values), "list" (flat list of values, with field names are given by get_frame_info_fields(); convenient for building a table), "array" (same as "list", but with a numpy array, which is easier to use for fastbuff readout supported by some cameras), or "dict" (flat dictionary with the same fields as the "list" format; more resilient to future format changes)

get_frame_info_period()

Get period of frame info acquisition.

Frame info might be skipped (set to None) except for frames which indices are divisible by period. Useful for certain cameras where acquiring frame info takes a lot of time and can reduce performance at higher frame rates. Note that this parameter can still be ignored (i.e., always set to 1) if the performance is not an issue for a given camera class.

get_frames_status()

Get acquisition and buffer status.

Return tuple (acquired, unread, skipped, size), where acquired is the total number of acquired frames, unread is the number of acquired but not read frames, skipped is the number of skipped (not read and then written over) frames, and buffer_size is the total buffer size (in frames).

get_full_info(include=0)

Get dict {name: value} containing full device information (including status and settings).

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

get_full_status(include=0)

Get dict {name: value} containing the device status (including settings).

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

get_image_indexing()

Get indexing for the returned images.

Can be "rct" (first index row, second index column, rows counted from the top), "rcb" (same as "rc", rows counted from the bottom), "xyt" (first index column, second index row, rows counted from the top), or "xyb" (same as "xyt", rows counted from the bottom)

get_new_images_range()

Get the range of the new images.

Return tuple (first, last) with images range (first inclusive). If no images are available, return None. If some images were in the buffer were overwritten, exclude them from the range.

get_settings(include=0)

Get dict {name: value} containing all the device settings.

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

grab(nframes=1, frame_timeout=5.0, missing_frame='none', return_info=False, buff_size=None)

Snap nframes images (with preset image read mode parameters)

buff_size determines buffer size (if None, use the default size). Timeout is specified for a single-frame acquisition, not for the whole acquisition time. missing_frame determines what to do with frames which have been lost: can be "none" (replacing them with None), "zero" (replacing them with zero-filled frame), or "skip" (skipping them, while still keeping total returned frames number to n). If return_info==True, return tuple (frames, infos), where infos is a list of frame info tuples (camera-dependent); if some frames are missing and missing_frame!="skip", the corresponding frame info is None.

is_acquisition_setup()

Check if acquisition is set up.

If the camera does not support separate acquisition setup, always return True.

is_opened()

Check if the device is connected

open()

Open the connection

pausing_acquisition(clear=None)

Context manager which temporarily pauses acquisition during execution of with block.

Useful for applying certain settings which can’t be changed during the acquisition. If clear==True, clear acquisition in addition to pausing (by default, use the class default specified as _clear_pausing_acquisition attribute). Yields tuple (acq_in_progress, acq_params), which indicates whether acquisition is currently in progress, and what are the current acquisition parameters.

read_multiple_images(rng=None, peek=False, missing_frame='skip', return_info=False)

Read multiple images specified by rng (by default, all un-read images).

If rng is specified, it is a tuple (first, last) with images range (first inclusive). If no new frames are available, return an empty list; if no acquisition is running, return None. If peek==True, return images but not mark them as read. missing_frame determines what to do with frames which are out of range (missing or lost): can be "none" (replacing them with None), "zero" (replacing them with zero-filled frame), or "skip" (skipping them). If return_info==True, return tuple (frames, infos), where infos is a list of frame info tuples (camera-dependent, by default, only the frame index); if some frames are missing and missing_frame!="skip", the corresponding frame info is None.

read_newest_image(peek=False, return_info=False)

Read the newest un-read image.

If no un-read frames are available, return None. If peek==True, return the image but not mark it as read. If return_info==True, return tuple (frame, info), where info is an info tuples (camera-dependent, see read_multiple_images()).

read_oldest_image(peek=False, return_info=False)

Read the oldest un-read image.

If no un-read frames are available, return None. If peek==True, return the image but not mark it as read. If return_info==True, return tuple (frame, info), where info is an info tuples (camera-dependent, see read_multiple_images()).

set_device_variable(key, value)

Set the value of a settings parameter

set_frame_format(fmt)

Set format for the returned images.

Can be "list" (list of 2D arrays, or 3D array for some fastbuff cameras), "array" (a single 3D array). Note that if the format is set to "array", the frame info format is also automatically set to "array".

set_frame_info_format(fmt, include_fields=None)

Set format of the frame info.

Can be "namedtuple" (potentially nested named tuples; convenient to get particular values), "list" (flat list of values, with field names are given by get_frame_info_fields(); convenient for building a table), "array" (same as "list", but with a numpy array, which is easier to use for fastbuff readout supported by some cameras), or "dict" (flat dictionary with the same fields as the "list" format; more resilient to future format changes) If include_fields is not None, it specifies the fields included for non-"tuple" formats.

set_frame_info_period(period=1)

Set period of frame info acquisition.

Frame info might be skipped (set to None) except for frames which indices are divisible by period. Useful for certain cameras where acquiring frame info takes a lot of time and can reduce performance at higher frame rates. Note that this parameter can still be ignored (i.e., always set to 1) if the performance is not an issue for a given camera class.

set_image_indexing(indexing)

Set up indexing for the returned images.

Can be "rct" (first index row, second index column, rows counted from the top), "rcb" (same as "rc", rows counted from the bottom), "xyt" (first index column, second index row, rows counted from the top), or "xyb" (same as "xyt", rows counted from the bottom)

setup_acquisition(**kwargs)

Setup acquisition.

Any non-specified acquisition parameters are assumed to be the same as previously set (or default, if not explicitly set before). Return the new acquisition parameters.

snap(timeout=5.0, return_info=False)

Snap a single frame

start_acquisition(*args, **kwargs)

Start acquisition.

Can take the same keyword parameters as :meth:``setup_acquisition. If the acquisition is not set up yet, set it up using the supplied parameters (use default of setup_acquisition(),if the parameter is None). Otherwise, if any supplied parameters are different from the current ones, change them and reset the acquisition.

stop_acquisition()

Stop acquisition

wait_for_frame(since='lastread', nframes=1, timeout=20.0, error_on_stopped=False)

Wait for one or several new camera frames.

since specifies the reference point for waiting to acquire nframes frames; can be “lastread”`` (from the last read frame), "lastwait" (wait for the last successful wait_for_frame() call), "now" (from the start of the current call), or "start" (from the acquisition start, i.e., wait until nframes frames have been acquired). timeout can be either a number, None (infinite timeout), or a tuple (timeout, frame_timeout), in which case the call times out if the total time exceeds timeout, or a single frame wait exceeds frame_timeout. If the call times out, raise TimeoutError. If error_on_stopped==True and the acquisition is not running, raise Error; otherwise, simply return False without waiting.

pylablib.devices.interface.camera.remove_status_line(frame, status_line, policy='duplicate', copy=True, value=0)[source]

Remove status line, if present.

Parameters:
  • frame – a frame to process (2D or 3D numpy array; if 3D, the first axis is the frame number)
  • status_line – status line descriptor (from the frames message)
  • policy – determines way to deal with the status line; can be "keep" (keep as is), "cut" (cut off the status-line-containing row/column), "zero" (set it to zero), "value" (set it to a given value), "median" (set it to the image median), or "duplicate" (set it equal to the previous row; default) "cut" is only possible of the status line is on the edge of the image.
  • copy – if True, make copy of the original frames; otherwise, attempt to remove the line in-place
pylablib.devices.interface.camera.extract_status_line(frame, status_line, copy=True)[source]

Extract status line, if present.

Parameters:
  • frame – a frame to process (2D or 3D numpy array; if 3D, the first axis is the frame number)
  • status_line – status line descriptor (from the frames message)
  • copy – if True, make copy of the original status line data.
pylablib.devices.interface.camera.insert_status_line(frame, status_line, value, copy=True)[source]

Insert status line, if present.

Parameters:
  • frame – a frame to process (2D or 3D numpy array; if 3D, the first axis is the frame number)
  • status_line – status line descriptor (from the frames message)
  • value – status line value
  • copy – if True, make copy of the original status line data.
pylablib.devices.interface.camera.get_status_line_roi(frame, status_line)[source]

Return ROI taken by the status line in the given frame

pylablib.devices.interface.stage module

class pylablib.devices.interface.stage.IStage[source]

Bases: pylablib.core.devio.interface.IDevice

Generic stage class

class NoParameterCaller(device, kind)

Bases: object

Class to simplify calling functions without a parameter

apply_settings(settings)

Apply the settings.

settings is the dict {name: value} of the device available settings. Non-applicable settings are ignored.

close()

Close the connection

get_device_variable(key)

Get the value of a settings, status, or full info parameter

get_full_info(include=0)

Get dict {name: value} containing full device information (including status and settings).

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

get_full_status(include=0)

Get dict {name: value} containing the device status (including settings).

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

get_settings(include=0)

Get dict {name: value} containing all the device settings.

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

is_opened()

Check if the device is connected

open()

Open the connection

set_device_variable(key, value)

Set the value of a settings parameter

pylablib.devices.interface.stage.muxaxis(*args, argname='axis', **kwargs)[source]

Multiplex the function over its axis argument

class pylablib.devices.interface.stage.IMultiaxisStage(*args, default_axis='all', **kwargs)[source]

Bases: pylablib.devices.interface.stage.IStage

Generic multiaxis stage class.

Has methods to assign and map axes and the axis device parameter.

Parameters:default_axis – default axis parameter value used when axis=None is provided
get_all_axes()[source]

Get the list of all available axes (taking mapping into account)

remap_axes(mapping, accept_original=True)[source]

Rename axes to the new labels.

mapping is the new axes mapping, which can be a list of new axes name (corresponding to the old axes in order returned by get_all_axes()), or a dictionary {alias: original} of the new axes aliases.

class NoParameterCaller(device, kind)

Bases: object

Class to simplify calling functions without a parameter

apply_settings(settings)

Apply the settings.

settings is the dict {name: value} of the device available settings. Non-applicable settings are ignored.

close()

Close the connection

get_device_variable(key)

Get the value of a settings, status, or full info parameter

get_full_info(include=0)

Get dict {name: value} containing full device information (including status and settings).

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

get_full_status(include=0)

Get dict {name: value} containing the device status (including settings).

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

get_settings(include=0)

Get dict {name: value} containing all the device settings.

include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or "all" (all available variables). Since the lowest priority is -10, setting include=-10 queries all available variables, which is equivalent to include="all".

is_opened()

Check if the device is connected

open()

Open the connection

set_device_variable(key, value)

Set the value of a settings parameter

Module contents