def getData(self): """ provides image name, image data and metadata :returns: image name, image data, json dictionary with metadata :rtype: (:obj:`str` , :class:`numpy.ndarray` , :obj:`str`) """ try: attr = self.__aproxy.read() if str(attr.type) == "DevEncoded": avalue = attr.value if avalue[0] in self.__tangodecoders: da = self.__aproxy.read( extract_as=PyTango.ExtractAs.Nothing) enc = PyTango.EncodedAttribute() data = getattr(enc, self.__tangodecoders[avalue[0]])(da) return (np.transpose(data), '%s (%s)' % (self._configuration, str(attr.time)), "") else: dec = self.__decoders[avalue[0]] dec.load(avalue) return (np.transpose(dec.decode()), '%s (%s)' % (self._configuration, str(attr.time)), "") else: return (np.transpose(attr.value), '%s (%s)' % (self._configuration, str(attr.time)), "") except Exception as e: print(str(e)) return str(e), "__ERROR__", "" pass # this needs a bit more care return None, None, None
def init_device(self): self.debug_stream("In init_device()") self.get_device_properties(self.get_device_class()) self.attr_exposure_read = 0 self.attr_image_read = '' self.attr_hous_temp_read = 0.0 self.attr_chip_temp_read = 0.0 #----- PROTECTED REGION ID(Detector.init_device) ENABLED START -----# self.set_state(PyTango.DevState.OFF) try: self.debug_stream("Creating link to detector driver...") self.detector = xiApi.Detector() self.debug_stream("Link created") except PyTango.DevFailed as df: self.error_stream(str(df)) raise except Exception as e: self.error_stream(str(e)) raise print(self.detector.get_name()) self.set_state(PyTango.DevState.ON) self.attr_exposure_read = self._read_exposure() self.detector.enable_cooling() for tries in range(2): #self.detector.set_roi(0, 4007, 0, 2671) self.detector.set_roi(500, 3000, 10, 2650) # self.detector.set_roi(100, 2000, 700, 1970) self.attr_image_read = PyTango.EncodedAttribute()
def read_JpegImage(self, attr): depth, signed, tgType = self.get_ImageType() data = self.control.ReadImage(-1) db = data.buffer release = getattr(data, 'releaseBuffer', None) if release: release() enc = PyTango.EncodedAttribute() if depth == 1: enc.encode_jpeg_gray8(db, quality=self.attr_JPeg_Quality) else: self.warn_stream("Cannot Jpeg encode none gray8 image") attr.set_value(enc)
def prepare_send_frame(raw_image_with_metadata, experiment, send_to_webpage=False): raw_image = raw_image_with_metadata['image_data']['raw_image'] del raw_image_with_metadata['image_data']['raw_image'] frame_metadata = raw_image_with_metadata try: get_logger().info("Image was red, preparing the image to send...") try: enc = PyTango.EncodedAttribute() image_numpy = enc.decode_gray16(raw_image) # image_numpy = numpy.zeros((10, 10)) except Exception as e: raise ModExpError( error='Could not convert raw image to numpy.array', exception_message=e.message) if experiment: pass frame_metadata_event = create_event(event_type='frame', exp_id=experiment.exp_id, MoF=frame_metadata) send_frame_to_storage_webpage( frame_metadata_event=frame_metadata_event, image_numpy=image_numpy, send_to_webpage=send_to_webpage) else: make_png(image_numpy) except ModExpError as e: if experiment is not None: experiment.stop_exception = e experiment.to_be_stopped = True return False, e return True, None