async def _grab_real(self, index=None): array = np.empty(self._record_shape, dtype=self._record_dtype) data = array.__array_interface__['data'][0] if index is not None: if await run_in_executor(self.uca.readout, data, index): return array else: raise base.CameraError('No frame available') if await run_in_executor(self.uca.grab, data): return array else: raise base.CameraError('No frame available')
def _grab_real(self): array = np.empty(self._record_shape, dtype=self._record_dtype) data = array.__array_interface__['data'][0] if self.uca.grab(data): return array else: raise base.CameraError('No frame available')
def _wrapper(instance, value): if instance.state == 'recording': raise base.CameraError('Changing parameters is not allowed while recording') if unit: value = value.to(unit) try: dic = {name: value.magnitude} except AttributeError: dic = {name: value} instance.uca.set_properties(**dic)
def __init__(self, directory, reset_on_start=True): # Let users change the directory self.directory = directory super(FileCamera, self).__init__() self.index = 0 self.reset_on_start = reset_on_start self.filenames = [ os.path.join(directory, file_name) for file_name in sorted(os.listdir(directory)) ] if not self.filenames: raise base.CameraError("No files found") image = read_image(self.filenames[0]) self._roi_width = image.shape[1] * q.pixel self._roi_height = image.shape[0] * q.pixel
async def _readout_real(self, num_frames=None): """Readout *num_frames* frames.""" recorded_frames = await self.get_recorded_frames() if num_frames is None: num_frames = recorded_frames.magnitude if not 0 < num_frames <= recorded_frames: raise base.CameraError( "Number of frames {} ".format(num_frames) + "must be more than zero and less than the recorded " + "number of frames {}".format(recorded_frames)) try: self.uca.start_readout() for i in range(num_frames): yield await self.grab() finally: self.uca.stop_readout()
def _readout_real(self, num_frames=None): """Readout *num_frames* frames.""" if num_frames is None: num_frames = self.recorded_frames.magnitude if not 0 < num_frames <= self.recorded_frames: raise base.CameraError( "Number of frames {} ".format(num_frames) + "must be more than zero and less than the recorded " + "number of frames {}".format(self.recorded_frames)) try: self.uca.start_readout() for i in xrange(num_frames): yield self.grab() except base.CameraError: raise StopIteration finally: self.uca.stop_readout()
def __init__(self, name, params=None): """ Create a new libuca camera. The *name* is passed to the uca plugin manager. :raises CameraError: In case camera *name* does not exist. """ super(Camera, self).__init__() import gi gi.require_version('Uca', '2.0') from gi.repository import GObject, GLib, Uca self._manager = Uca.PluginManager() params = params if params else {} try: self.uca = self._manager.get_camerah(name, params) except GLib.GError as ge: raise base.CameraError(str(ge)) except Exception: raise base.CameraError("`{0}' is not a valid camera".format(name)) units = { Uca.Unit.METER: q.m, Uca.Unit.SECOND: q.s, Uca.Unit.DEGREE_CELSIUS: q.celsius, Uca.Unit.COUNT: q.dimensionless, Uca.Unit.PIXEL: q.pixel, } parameters = {} for prop in self.uca.props: if prop.name in ('trigger-source', 'trigger-type', 'frames-per-second'): continue getter, setter, unit = None, None, None uca_unit = self.uca.get_unit(prop.name) if uca_unit in units: unit = units[uca_unit] if prop.flags & GObject.ParamFlags.READABLE: getter = _new_getter_wrapper(prop.name, unit) if prop.flags & GObject.ParamFlags.WRITABLE: setter = _new_setter_wrapper(prop.name, unit) name = prop.name.replace('-', '_') if uca_unit in units: parameters[name] = Quantity(unit, fget=getter, fset=setter, help=prop.blurb) else: parameters[name] = Parameter(fget=getter, fset=setter, help=prop.blurb) if parameters: self.install_parameters(parameters) class _Dummy(object): pass setattr(self.uca, 'enum_values', _Dummy()) def get_enum_bunch(enum): enum_map = {} for key, value in list(enum.__enum_values__.items()): name = value.value_nick.upper().replace('-', '_') enum_map[name] = key return Bunch(enum_map) for prop in self.uca.props: if hasattr(prop, 'enum_class'): setattr(self.uca.enum_values, prop.name.replace('-', '_'), get_enum_bunch(prop.default_value)) self._uca_get_frame_rate = _new_getter_wrapper('frames-per-second') self._uca_set_frame_rate = _new_setter_wrapper('frames-per-second') # Invert the uca trigger source dict in order to return concert values trigger_dict = self.uca.enum_values.trigger_source.__dict__ self._uca_to_concert_trigger = { v: k for k, v in list(trigger_dict.items()) } self._uca_get_trigger = _new_getter_wrapper('trigger-source') self._uca_set_trigger = _new_setter_wrapper('trigger-source') self._record_shape = None self._record_dtype = None
def _wrapper(*args, **kwargs): from gi.repository import GLib try: return func(*args, **kwargs) except GLib.GError as ge: raise base.CameraError(str(ge))