Esempio n. 1
0
    async def receive(self, replies):
        """Receive replies from CAM server and fire an event per reply.

        Parameters
        ----------
        replies : list
            A list of replies from the CAM server.
        """
        # if reply check reply and call correct listener
        # parse reply and create Event
        # await event notify in sequential order
        # reply must be an iterable
        if not isinstance(replies, list):
            replies = [replies]
        for reply in replies:
            if not reply or not isinstance(reply, dict):
                continue
            if REL_IMAGE_PATH in reply:
                imaging_dir = self.config[CONF_IMAGING_DIR]
                rel_path = reply[REL_IMAGE_PATH]
                if rel_path == self._last_image_path:
                    # guard against duplicate image events from the microscope
                    _LOGGER.debug("Duplicate image reply received: %s", rel_path)
                    continue
                self._last_image_path = rel_path
                image_path = find_image_path(rel_path, imaging_dir)
                field_path = await self.center.add_executor_job(get_field, image_path)
                image_paths = await self.center.add_executor_job(
                    partial(
                        get_imgs,
                        field_path,
                        search=JOB_ID.format(attribute(image_path, "E")),
                    )
                )
                for path in image_paths:
                    # await in sequential order
                    await self.center.bus.notify(LeicaImageEvent({"path": path}))
            elif SCAN_STARTED in list(reply.values()):
                await self.center.bus.notify(LeicaStartCommandEvent(reply))
            elif SCAN_FINISHED in list(reply.values()):
                await self.center.bus.notify(LeicaStopCommandEvent(reply))
            else:
                await self.center.bus.notify(LeicaCommandEvent(reply))
Esempio n. 2
0
 def job_id(self):
     """:int: Return job id of the image."""
     return attribute(self.path, "E")
Esempio n. 3
0
 def channel_id(self):
     """:int: Return channel id of the image."""
     return attribute(self.path, "C")
Esempio n. 4
0
 def z_slice_id(self):
     """:int: Return z index of the image."""
     return attribute(self.path, "Z")
Esempio n. 5
0
 def field_y(self):
     """:int: Return y coordinate of the well of the image."""
     return attribute(self.path, "Y")
Esempio n. 6
0
 def well_x(self):
     """:int: Return x coordinate of the well of the image."""
     return attribute(self.path, "U")