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
.
-
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.
-
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 isNone
). Otherwise, if any supplied parameters are different from the current ones, change them and reset the acquisition.
-
pausing_acquisition
(clear=None, stop=True, setup_after=None, start_after=True, combine_nested=True)[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 stopping (by default, use the class default specified as_clear_pausing_acquisition
attribute). Ifstop==True
, stop the acquisition (ifclear==True
, stop regardless). Ifsetup_after==True
, setup the acquisition after pause if necessary (None
means setup only if clearing was required). Ifstart_after==True
, start the acquisition after pause if necessary (None
means start only if stopping was required). Ifcombine_nested==True
, then any nestedpausing_acquisition
calls will stop/clear acquisition as necessary, but won’t setup/start it again until thispausing_acquisition
call is complete.Yields tuple
(acq_in_progress, acq_params)
, which indicates whether acquisition is currently in progress, and what are the current acquisition parameters.
-
get_frames_status
()[source]¶ Get acquisition and buffer status.
Return tuple
(acquired, unread, skipped, size)
, whereacquired
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, andbuffer_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 successfulwait_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 exceedstimeout
, or a single frame wait exceedsframe_timeout
. If the call times out, raiseTimeoutError
. Iferror_on_stopped==True
and the acquisition is not running, raiseError
; otherwise, simply returnFalse
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),"array"
(a single 3D array), or"chunks"
(list of 3D “chunk” arrays; supported for some cameras and provides the best performance).
-
set_frame_format
(fmt)[source]¶ Set format for the returned images.
Can be
"list"
(list of 2D arrays),"array"
(a single 3D array),"chunks"
(list of 3D “chunk” arrays; supported for some cameras and provides the best performance), or"try_chunks"
(same as"chunks"
, but if chunks are not supported, set to"list"
instead). If format is"chunks"
and chunks are not supported by the camera, it results in one frame per chunk. Note that if the format is set to"array"
or"chunks"
, the frame info format is also automatically set to"array"
. If the format is set to"chunks"
, then the image info is also returned in chunks form (list of 2D info arrays with the same length as the corresponding frame chunks).
-
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 byget_frame_info_fields()
; convenient for building a table),"array"
(same as"list"
, but with a numpy array, which is easier to use for"chunks"
frame format), 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 byget_frame_info_fields()
; convenient for building a table),"array"
(same as"list"
, but with a numpy array, which is easier to use for"chunks"
frame format), or"dict"
(flat dictionary with the same fields as the"list"
format; more resilient to future format changes) If include_fields is notNone
, it specifies the fields included for non-"tuple"
formats; note that order or include_fields is ignored, and the resulting fields are always ordered same as in the original.
-
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, returnNone
. 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, return_rng=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, returnNone
. Ifpeek==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 withNone
),"zero"
(replacing them with zero-filled frame), or"skip"
(skipping them). Ifreturn_info==True
, return tuple(frames, infos)
, whereinfos
is a list of frame info tuples (camera-dependent, by default, only the frame index); if some frames are missing andmissing_frame!="skip"
, the corresponding frame info isNone
. ifreturn_rng==True
, return the range covered resulting frames; ifmissing_frame=="skip"
, the range can be smaller than the supplied rng if some frames are skipped.
-
read_oldest_image
(peek=False, return_info=False)[source]¶ Read the oldest un-read image.
If no un-read frames are available, return
None
. Ifpeek==True
, return the image but not mark it as read. Ifreturn_info==True
, return tuple(frame, info)
, whereinfo
is an info tuples (camera-dependent, seeread_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
. Ifpeek==True
, return the image but not mark it as read. Ifreturn_info==True
, return tuple(frame, info)
, whereinfo
is an info tuples (camera-dependent, seeread_multiple_images()
).
-
grab
(nframes=1, frame_timeout=5.0, missing_frame='skip', 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 withNone
),"zero"
(replacing them with zero-filled frame), or"skip"
(skipping them, while still keeping total returned frames number to n). Ifreturn_info==True
, return tuple(frames, infos)
, whereinfos
is a list of frame info tuples (camera-dependent); if some frames are missing andmissing_frame!="skip"
, the corresponding frame info isNone
.
-
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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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
-
pylablib.devices.interface.camera.
trim_frames
(frames, l, info=None, chunks='auto')[source]¶ Trim frames in different formats to the desired length
-
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 inICamera.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)
-
-
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)
-
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)
, wherenread
is the number of frames in the chunk, andchunk_data
is the raw buffer pointer as actypes.c_char_p
object.
-
-
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 havename
attribute for placing them into a dictionary. Attributes can also havereadable
andwritable
attributes, which are used inget_all_attribute_values()
andset_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_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 notNone
, automatically assume thaterror_on_missing==False
. If name points at a dictionary branch, return a dictionary with all values in this branch. Additional arguments are passed toget_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 toset_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),"array"
(a single 3D array), or"chunks"
(list of 3D “chunk” arrays; supported for some cameras and provides the best performance).
-
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 byget_frame_info_fields()
; convenient for building a table),"array"
(same as"list"
, but with a numpy array, which is easier to use for"chunks"
frame format), 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)
, whereacquired
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, andbuffer_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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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, returnNone
. 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, settinginclude=-10
queries all available variables, which is equivalent toinclude="all"
.
-
grab
(nframes=1, frame_timeout=5.0, missing_frame='skip', 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 withNone
),"zero"
(replacing them with zero-filled frame), or"skip"
(skipping them, while still keeping total returned frames number to n). Ifreturn_info==True
, return tuple(frames, infos)
, whereinfos
is a list of frame info tuples (camera-dependent); if some frames are missing andmissing_frame!="skip"
, the corresponding frame info isNone
.
-
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, stop=True, setup_after=None, start_after=True, combine_nested=True)¶ 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 stopping (by default, use the class default specified as_clear_pausing_acquisition
attribute). Ifstop==True
, stop the acquisition (ifclear==True
, stop regardless). Ifsetup_after==True
, setup the acquisition after pause if necessary (None
means setup only if clearing was required). Ifstart_after==True
, start the acquisition after pause if necessary (None
means start only if stopping was required). Ifcombine_nested==True
, then any nestedpausing_acquisition
calls will stop/clear acquisition as necessary, but won’t setup/start it again until thispausing_acquisition
call is complete.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, return_rng=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, returnNone
. Ifpeek==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 withNone
),"zero"
(replacing them with zero-filled frame), or"skip"
(skipping them). Ifreturn_info==True
, return tuple(frames, infos)
, whereinfos
is a list of frame info tuples (camera-dependent, by default, only the frame index); if some frames are missing andmissing_frame!="skip"
, the corresponding frame info isNone
. ifreturn_rng==True
, return the range covered resulting frames; ifmissing_frame=="skip"
, the range can be smaller than the supplied rng if some frames are skipped.
-
read_newest_image
(peek=False, return_info=False)¶ Read the newest un-read image.
If no un-read frames are available, return
None
. Ifpeek==True
, return the image but not mark it as read. Ifreturn_info==True
, return tuple(frame, info)
, whereinfo
is an info tuples (camera-dependent, seeread_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
. Ifpeek==True
, return the image but not mark it as read. Ifreturn_info==True
, return tuple(frame, info)
, whereinfo
is an info tuples (camera-dependent, seeread_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),"array"
(a single 3D array),"chunks"
(list of 3D “chunk” arrays; supported for some cameras and provides the best performance), or"try_chunks"
(same as"chunks"
, but if chunks are not supported, set to"list"
instead). If format is"chunks"
and chunks are not supported by the camera, it results in one frame per chunk. Note that if the format is set to"array"
or"chunks"
, the frame info format is also automatically set to"array"
. If the format is set to"chunks"
, then the image info is also returned in chunks form (list of 2D info arrays with the same length as the corresponding frame chunks).
-
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 byget_frame_info_fields()
; convenient for building a table),"array"
(same as"list"
, but with a numpy array, which is easier to use for"chunks"
frame format), or"dict"
(flat dictionary with the same fields as the"list"
format; more resilient to future format changes) If include_fields is notNone
, it specifies the fields included for non-"tuple"
formats; note that order or include_fields is ignored, and the resulting fields are always ordered same as in the original.
-
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 isNone
). 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 successfulwait_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 exceedstimeout
, or a single frame wait exceedsframe_timeout
. If the call times out, raiseTimeoutError
. Iferror_on_stopped==True
and the acquisition is not running, raiseError
; otherwise, simply returnFalse
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 havename
attribute for placing them into a dictionary. Attributes can also havereadable
andwritable
attributes, which are used inget_all_grabber_attribute_values()
andset_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 notNone
, automatically assume thaterror_on_missing==False
. If name points at a dictionary branch, return a dictionary with all values in this branch. Additional arguments are passed toget_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 toset_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),"array"
(a single 3D array), or"chunks"
(list of 3D “chunk” arrays; supported for some cameras and provides the best performance).
-
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 byget_frame_info_fields()
; convenient for building a table),"array"
(same as"list"
, but with a numpy array, which is easier to use for"chunks"
frame format), 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)
, whereacquired
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, andbuffer_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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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, returnNone
. 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, settinginclude=-10
queries all available variables, which is equivalent toinclude="all"
.
-
grab
(nframes=1, frame_timeout=5.0, missing_frame='skip', 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 withNone
),"zero"
(replacing them with zero-filled frame), or"skip"
(skipping them, while still keeping total returned frames number to n). Ifreturn_info==True
, return tuple(frames, infos)
, whereinfos
is a list of frame info tuples (camera-dependent); if some frames are missing andmissing_frame!="skip"
, the corresponding frame info isNone
.
-
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, stop=True, setup_after=None, start_after=True, combine_nested=True)¶ 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 stopping (by default, use the class default specified as_clear_pausing_acquisition
attribute). Ifstop==True
, stop the acquisition (ifclear==True
, stop regardless). Ifsetup_after==True
, setup the acquisition after pause if necessary (None
means setup only if clearing was required). Ifstart_after==True
, start the acquisition after pause if necessary (None
means start only if stopping was required). Ifcombine_nested==True
, then any nestedpausing_acquisition
calls will stop/clear acquisition as necessary, but won’t setup/start it again until thispausing_acquisition
call is complete.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, return_rng=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, returnNone
. Ifpeek==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 withNone
),"zero"
(replacing them with zero-filled frame), or"skip"
(skipping them). Ifreturn_info==True
, return tuple(frames, infos)
, whereinfos
is a list of frame info tuples (camera-dependent, by default, only the frame index); if some frames are missing andmissing_frame!="skip"
, the corresponding frame info isNone
. ifreturn_rng==True
, return the range covered resulting frames; ifmissing_frame=="skip"
, the range can be smaller than the supplied rng if some frames are skipped.
-
read_newest_image
(peek=False, return_info=False)¶ Read the newest un-read image.
If no un-read frames are available, return
None
. Ifpeek==True
, return the image but not mark it as read. Ifreturn_info==True
, return tuple(frame, info)
, whereinfo
is an info tuples (camera-dependent, seeread_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
. Ifpeek==True
, return the image but not mark it as read. Ifreturn_info==True
, return tuple(frame, info)
, whereinfo
is an info tuples (camera-dependent, seeread_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),"array"
(a single 3D array),"chunks"
(list of 3D “chunk” arrays; supported for some cameras and provides the best performance), or"try_chunks"
(same as"chunks"
, but if chunks are not supported, set to"list"
instead). If format is"chunks"
and chunks are not supported by the camera, it results in one frame per chunk. Note that if the format is set to"array"
or"chunks"
, the frame info format is also automatically set to"array"
. If the format is set to"chunks"
, then the image info is also returned in chunks form (list of 2D info arrays with the same length as the corresponding frame chunks).
-
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 byget_frame_info_fields()
; convenient for building a table),"array"
(same as"list"
, but with a numpy array, which is easier to use for"chunks"
frame format), or"dict"
(flat dictionary with the same fields as the"list"
format; more resilient to future format changes) If include_fields is notNone
, it specifies the fields included for non-"tuple"
formats; note that order or include_fields is ignored, and the resulting fields are always ordered same as in the original.
-
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 isNone
). 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 successfulwait_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 exceedstimeout
, or a single frame wait exceedsframe_timeout
. If the call times out, raiseTimeoutError
. Iferror_on_stopped==True
and the acquisition is not running, raiseError
; otherwise, simply returnFalse
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_frame_period
()[source]¶ Get frame period (time between two consecutive frames in the internal trigger mode)
-
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),"array"
(a single 3D array), or"chunks"
(list of 3D “chunk” arrays; supported for some cameras and provides the best performance).
-
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 byget_frame_info_fields()
; convenient for building a table),"array"
(same as"list"
, but with a numpy array, which is easier to use for"chunks"
frame format), 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)
, whereacquired
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, andbuffer_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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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, returnNone
. 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, settinginclude=-10
queries all available variables, which is equivalent toinclude="all"
.
-
grab
(nframes=1, frame_timeout=5.0, missing_frame='skip', 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 withNone
),"zero"
(replacing them with zero-filled frame), or"skip"
(skipping them, while still keeping total returned frames number to n). Ifreturn_info==True
, return tuple(frames, infos)
, whereinfos
is a list of frame info tuples (camera-dependent); if some frames are missing andmissing_frame!="skip"
, the corresponding frame info isNone
.
-
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, stop=True, setup_after=None, start_after=True, combine_nested=True)¶ 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 stopping (by default, use the class default specified as_clear_pausing_acquisition
attribute). Ifstop==True
, stop the acquisition (ifclear==True
, stop regardless). Ifsetup_after==True
, setup the acquisition after pause if necessary (None
means setup only if clearing was required). Ifstart_after==True
, start the acquisition after pause if necessary (None
means start only if stopping was required). Ifcombine_nested==True
, then any nestedpausing_acquisition
calls will stop/clear acquisition as necessary, but won’t setup/start it again until thispausing_acquisition
call is complete.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, return_rng=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, returnNone
. Ifpeek==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 withNone
),"zero"
(replacing them with zero-filled frame), or"skip"
(skipping them). Ifreturn_info==True
, return tuple(frames, infos)
, whereinfos
is a list of frame info tuples (camera-dependent, by default, only the frame index); if some frames are missing andmissing_frame!="skip"
, the corresponding frame info isNone
. ifreturn_rng==True
, return the range covered resulting frames; ifmissing_frame=="skip"
, the range can be smaller than the supplied rng if some frames are skipped.
-
read_newest_image
(peek=False, return_info=False)¶ Read the newest un-read image.
If no un-read frames are available, return
None
. Ifpeek==True
, return the image but not mark it as read. Ifreturn_info==True
, return tuple(frame, info)
, whereinfo
is an info tuples (camera-dependent, seeread_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
. Ifpeek==True
, return the image but not mark it as read. Ifreturn_info==True
, return tuple(frame, info)
, whereinfo
is an info tuples (camera-dependent, seeread_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),"array"
(a single 3D array),"chunks"
(list of 3D “chunk” arrays; supported for some cameras and provides the best performance), or"try_chunks"
(same as"chunks"
, but if chunks are not supported, set to"list"
instead). If format is"chunks"
and chunks are not supported by the camera, it results in one frame per chunk. Note that if the format is set to"array"
or"chunks"
, the frame info format is also automatically set to"array"
. If the format is set to"chunks"
, then the image info is also returned in chunks form (list of 2D info arrays with the same length as the corresponding frame chunks).
-
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 byget_frame_info_fields()
; convenient for building a table),"array"
(same as"list"
, but with a numpy array, which is easier to use for"chunks"
frame format), or"dict"
(flat dictionary with the same fields as the"list"
format; more resilient to future format changes) If include_fields is notNone
, it specifies the fields included for non-"tuple"
formats; note that order or include_fields is ignored, and the resulting fields are always ordered same as in the original.
-
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 isNone
). 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 successfulwait_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 exceedstimeout
, or a single frame wait exceedsframe_timeout
. If the call times out, raiseTimeoutError
. Iferror_on_stopped==True
and the acquisition is not running, raiseError
; otherwise, simply returnFalse
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 thatpstep
andsstep
dividemin
andmax
, and that eitherpstep
dividessstep
or the other way around. Ifsymmetric==True
, thenmax
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),"array"
(a single 3D array), or"chunks"
(list of 3D “chunk” arrays; supported for some cameras and provides the best performance).
-
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 byget_frame_info_fields()
; convenient for building a table),"array"
(same as"list"
, but with a numpy array, which is easier to use for"chunks"
frame format), 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)
, whereacquired
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, andbuffer_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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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, returnNone
. 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, settinginclude=-10
queries all available variables, which is equivalent toinclude="all"
.
-
grab
(nframes=1, frame_timeout=5.0, missing_frame='skip', 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 withNone
),"zero"
(replacing them with zero-filled frame), or"skip"
(skipping them, while still keeping total returned frames number to n). Ifreturn_info==True
, return tuple(frames, infos)
, whereinfos
is a list of frame info tuples (camera-dependent); if some frames are missing andmissing_frame!="skip"
, the corresponding frame info isNone
.
-
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, stop=True, setup_after=None, start_after=True, combine_nested=True)¶ 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 stopping (by default, use the class default specified as_clear_pausing_acquisition
attribute). Ifstop==True
, stop the acquisition (ifclear==True
, stop regardless). Ifsetup_after==True
, setup the acquisition after pause if necessary (None
means setup only if clearing was required). Ifstart_after==True
, start the acquisition after pause if necessary (None
means start only if stopping was required). Ifcombine_nested==True
, then any nestedpausing_acquisition
calls will stop/clear acquisition as necessary, but won’t setup/start it again until thispausing_acquisition
call is complete.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, return_rng=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, returnNone
. Ifpeek==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 withNone
),"zero"
(replacing them with zero-filled frame), or"skip"
(skipping them). Ifreturn_info==True
, return tuple(frames, infos)
, whereinfos
is a list of frame info tuples (camera-dependent, by default, only the frame index); if some frames are missing andmissing_frame!="skip"
, the corresponding frame info isNone
. ifreturn_rng==True
, return the range covered resulting frames; ifmissing_frame=="skip"
, the range can be smaller than the supplied rng if some frames are skipped.
-
read_newest_image
(peek=False, return_info=False)¶ Read the newest un-read image.
If no un-read frames are available, return
None
. Ifpeek==True
, return the image but not mark it as read. Ifreturn_info==True
, return tuple(frame, info)
, whereinfo
is an info tuples (camera-dependent, seeread_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
. Ifpeek==True
, return the image but not mark it as read. Ifreturn_info==True
, return tuple(frame, info)
, whereinfo
is an info tuples (camera-dependent, seeread_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),"array"
(a single 3D array),"chunks"
(list of 3D “chunk” arrays; supported for some cameras and provides the best performance), or"try_chunks"
(same as"chunks"
, but if chunks are not supported, set to"list"
instead). If format is"chunks"
and chunks are not supported by the camera, it results in one frame per chunk. Note that if the format is set to"array"
or"chunks"
, the frame info format is also automatically set to"array"
. If the format is set to"chunks"
, then the image info is also returned in chunks form (list of 2D info arrays with the same length as the corresponding frame chunks).
-
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 byget_frame_info_fields()
; convenient for building a table),"array"
(same as"list"
, but with a numpy array, which is easier to use for"chunks"
frame format), or"dict"
(flat dictionary with the same fields as the"list"
format; more resilient to future format changes) If include_fields is notNone
, it specifies the fields included for non-"tuple"
formats; note that order or include_fields is ignored, and the resulting fields are always ordered same as in the original.
-
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 isNone
). 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 successfulwait_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 exceedstimeout
, or a single frame wait exceedsframe_timeout
. If the call times out, raiseTimeoutError
. Iferror_on_stopped==True
and the acquisition is not running, raiseError
; otherwise, simply returnFalse
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),"array"
(a single 3D array), or"chunks"
(list of 3D “chunk” arrays; supported for some cameras and provides the best performance).
-
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 byget_frame_info_fields()
; convenient for building a table),"array"
(same as"list"
, but with a numpy array, which is easier to use for"chunks"
frame format), 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)
, whereacquired
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, andbuffer_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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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, returnNone
. 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, settinginclude=-10
queries all available variables, which is equivalent toinclude="all"
.
-
grab
(nframes=1, frame_timeout=5.0, missing_frame='skip', 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 withNone
),"zero"
(replacing them with zero-filled frame), or"skip"
(skipping them, while still keeping total returned frames number to n). Ifreturn_info==True
, return tuple(frames, infos)
, whereinfos
is a list of frame info tuples (camera-dependent); if some frames are missing andmissing_frame!="skip"
, the corresponding frame info isNone
.
-
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, stop=True, setup_after=None, start_after=True, combine_nested=True)¶ 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 stopping (by default, use the class default specified as_clear_pausing_acquisition
attribute). Ifstop==True
, stop the acquisition (ifclear==True
, stop regardless). Ifsetup_after==True
, setup the acquisition after pause if necessary (None
means setup only if clearing was required). Ifstart_after==True
, start the acquisition after pause if necessary (None
means start only if stopping was required). Ifcombine_nested==True
, then any nestedpausing_acquisition
calls will stop/clear acquisition as necessary, but won’t setup/start it again until thispausing_acquisition
call is complete.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, return_rng=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, returnNone
. Ifpeek==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 withNone
),"zero"
(replacing them with zero-filled frame), or"skip"
(skipping them). Ifreturn_info==True
, return tuple(frames, infos)
, whereinfos
is a list of frame info tuples (camera-dependent, by default, only the frame index); if some frames are missing andmissing_frame!="skip"
, the corresponding frame info isNone
. ifreturn_rng==True
, return the range covered resulting frames; ifmissing_frame=="skip"
, the range can be smaller than the supplied rng if some frames are skipped.
-
read_newest_image
(peek=False, return_info=False)¶ Read the newest un-read image.
If no un-read frames are available, return
None
. Ifpeek==True
, return the image but not mark it as read. Ifreturn_info==True
, return tuple(frame, info)
, whereinfo
is an info tuples (camera-dependent, seeread_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
. Ifpeek==True
, return the image but not mark it as read. Ifreturn_info==True
, return tuple(frame, info)
, whereinfo
is an info tuples (camera-dependent, seeread_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),"array"
(a single 3D array),"chunks"
(list of 3D “chunk” arrays; supported for some cameras and provides the best performance), or"try_chunks"
(same as"chunks"
, but if chunks are not supported, set to"list"
instead). If format is"chunks"
and chunks are not supported by the camera, it results in one frame per chunk. Note that if the format is set to"array"
or"chunks"
, the frame info format is also automatically set to"array"
. If the format is set to"chunks"
, then the image info is also returned in chunks form (list of 2D info arrays with the same length as the corresponding frame chunks).
-
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 byget_frame_info_fields()
; convenient for building a table),"array"
(same as"list"
, but with a numpy array, which is easier to use for"chunks"
frame format), or"dict"
(flat dictionary with the same fields as the"list"
format; more resilient to future format changes) If include_fields is notNone
, it specifies the fields included for non-"tuple"
formats; note that order or include_fields is ignored, and the resulting fields are always ordered same as in the original.
-
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 isNone
). 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 successfulwait_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 exceedstimeout
, or a single frame wait exceedsframe_timeout
. If the call times out, raiseTimeoutError
. Iferror_on_stopped==True
and the acquisition is not running, raiseError
; otherwise, simply returnFalse
without waiting.
-
-
class
pylablib.devices.interface.camera.
TStatusLineDescription
(kind, roi, framestamp_checker)¶ Bases:
tuple
-
count
()¶ Return number of occurrences of value.
-
framestamp_checker
¶
-
index
()¶ Return first index of value.
Raises ValueError if the value is not present.
-
kind
¶
-
roi
¶
-
-
class
pylablib.devices.interface.camera.
StatusLineChecker
[source]¶ Bases:
object
Class responsible for checking status line consistency
-
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.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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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
-
class
-
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-
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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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, settinginclude=-10
queries all available variables, which is equivalent toinclude="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
-