Skip to content

Commit

Permalink
PVCAM bugfixes, image plotter updates
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexShkarin committed Apr 14, 2022
1 parent 4973e1e commit 39b8248
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .pylintdict
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,6 @@ ilabels
multiline
subpaths
titlebar
cai
framestamps
Neo
25 changes: 20 additions & 5 deletions pylablib/devices/Photometrics/pvcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,21 @@ def __init__(self, handle, pid, cam=None):
self.pid=pid
self.cam=cam
self.name=_lstrip(pvcam_defs.drPARAM.get(pid,"UNKNOWN"),"PARAM_")
self._attr_type_n=lib.get_param(self.handle,self.pid,pvcam_defs.PL_PARAM_ATTRIBUTES.ATTR_TYPE,pvcam_defs.PARAM_TYPE.TYPE_UNS16)
self.kind=_lstrip(pvcam_defs.drPARAM_TYPE.get(self._attr_type_n,"UNKNOWN"),"TYPE_")
self.available=lib.get_param(self.handle,self.pid,pvcam_defs.PL_PARAM_ATTRIBUTES.ATTR_AVAIL,pvcam_defs.PARAM_TYPE.TYPE_BOOLEAN)
self._value_access_n=lib.get_param(self.handle,self.pid,pvcam_defs.PL_PARAM_ATTRIBUTES.ATTR_ACCESS,pvcam_defs.PARAM_TYPE.TYPE_UNS16)
self.value_access=_lstrip(pvcam_defs.drPL_PARAM_ACCESS.get(self._value_access_n,"UNKNOWN"),"ACC_")
try:
self.available=lib.get_param(self.handle,self.pid,pvcam_defs.PL_PARAM_ATTRIBUTES.ATTR_AVAIL,pvcam_defs.PARAM_TYPE.TYPE_BOOLEAN)
self._attr_type_n=lib.get_param(self.handle,self.pid,pvcam_defs.PL_PARAM_ATTRIBUTES.ATTR_TYPE,pvcam_defs.PARAM_TYPE.TYPE_UNS16)
self.kind=_lstrip(pvcam_defs.drPARAM_TYPE.get(self._attr_type_n,"UNKNOWN"),"TYPE_")
self._value_access_n=lib.get_param(self.handle,self.pid,pvcam_defs.PL_PARAM_ATTRIBUTES.ATTR_ACCESS,pvcam_defs.PARAM_TYPE.TYPE_UNS16)
self.value_access=_lstrip(pvcam_defs.drPL_PARAM_ACCESS.get(self._value_access_n,"UNKNOWN"),"ACC_")
except PvcamLibError as err:
if err.code==25: # PL_NOT_AVAILABLE
self.available=False
self._attr_type_n=0
self.kind="UNKNOWN"
self._value_access_n=0
self.value_access="UNKNOWN"
else:
raise
self.readable=self.value_access in {"READ_ONLY","READ_WRITE"}
self.writable=self.value_access in {"WRITE_ONLY","READ_WRITE"}

Expand Down Expand Up @@ -806,6 +816,11 @@ def read_multiple_images(self, rng=None, peek=False, missing_frame="skip", retur
than the supplied `rng` if some frames are skipped.
"""
return super().read_multiple_images(rng=rng,peek=peek,missing_frame=missing_frame,return_info=return_info,return_rng=return_rng)
def _get_grab_acquisition_parameters(self, nframes, buff_size):
params=super()._get_grab_acquisition_parameters(nframes,buff_size)
if params["mode"]=="snap":
params["nframes"]+=2+int(.05/self.get_frame_period()) # looks like the first/last several frame get missing sometimes
return params



Expand Down
29 changes: 21 additions & 8 deletions pylablib/gui/widgets/plotters/image_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import numpy as np
import contextlib
import time
import collections

_pre_0p11=module.cmp_package_version("pyqtgraph","0.11.0")=="<"

Expand Down Expand Up @@ -240,6 +241,7 @@ def paint(self, *args):
pyqtgraph.graphicsItems.GradientEditorItem.Gradients[cm]={"ticks":ticks,"mode":"rgb"}
except (TypeError,AttributeError): # sphinx autodoc Mock can't handle assignment
pass
TRectangle=collections.namedtuple("TRectangle",["center","size","visible"])
class ImagePlotter(QLayoutManagedWidget):
"""
Image plotter object.
Expand Down Expand Up @@ -632,20 +634,31 @@ def del_rectangle(self, name):
"""Delete a rectangle with a given name"""
if name in self.rectangles:
rect=self.rectangles.pop(name)
self.image_window.getView().removeItem(rect)
self.image_window.getView().removeItem(rect.rect)
def _get_rect_names(self, names, include_special=False):
if names is None:
return [n for n in self.rectangles if include_special or not (isinstance(n,tuple) and n[0]=="special")]
return [n for n in funcargparse.as_sequence(names) if n in self.rectangles]
def show_rectangles(self, show=True, names=None):
"""
Toggle showing rectangles on or off
If `names` is given, it specifies names of rectangles to show or hide (by default, all rectangles).
"""
if names is None:
names=self.rectangles
else:
names=funcargparse.as_sequence(names)
names=[n for n in names if n in self.rectangles]
updated=any([self.set_rectangle(n,visible=show) for n in names])
return updated
names=self._get_rect_names(names)
return any([self.set_rectangle(n,visible=show) for n in names])
def get_rectangles(self, names=None, coord_system="image", include_special=False):
"""
Get a dictionary of rectangle properties.
Return dictionary of tuple ``(center, size, visible)``.
`coord_system` specifies the coordinate system for the positions and sizes.
If ``include_special==True``, include special rectangles such as selection frame.
"""
names=self._get_rect_names(names,include_special=include_special)
rects=[self.rectangles[n] for n in names]
geom=[self._convert_rectangle(r.center,r.size,src=r.coord_system,dst=coord_system) for r in rects]
return {n:TRectangle(g[0],g[1],r.visible) for n,r,g in zip(names,rects,geom)}
@controller.exsafe
def _update_dummy_frame(self, rng):
(l,r),(b,t)=rng
Expand Down

0 comments on commit 39b8248

Please sign in to comment.