def DevCcdSetRoI(self, argin): roi = Core.Roi(Core.Point(argin[0], argin[1]), Core.Point(argin[2], argin[3])) control = _control_ref() image = control.image() if roi == self.getMaxRoi() : roi = Core.Roi() image.setRoi(roi)
def getMaxRoi(self): control = _control_ref() ct_image = control.image() max_roi_size = ct_image.getMaxImageSize() max_roi_size /= Core.Point(ct_image.getBin()) max_roi = Core.Roi(Core.Point(0, 0), max_roi_size) return max_roi
def apply_config(self, c): try: active = c.get("active", False) self.Stop() if active: self._runLevel = c.get("runLevel", 0) self.Start() namedRois = [] names = [] for name, d in c.iteritems(): try: if isinstance(d, dict): rType = d.get("type", None) if rType == RoiCounterTask.SQUARE: x = d["x"] y = d["y"] width = d["width"] height = d["height"] namedRois.append( (name, Core.Roi(x, y, width, height))) elif rType == RoiCounterTask.ARC: x = d["x"] y = d["y"] r1 = d["r1"] r2 = d["r2"] a1 = d["a1"] a2 = d["a2"] namedRois.append( (name, Core.ArcRoi(x, y, r1, r2, a1, a2))) elif rType == RoiCounterTask.MASK: x = d["x"] y = d["y"] data = d["data"] self.__roiCounterMgr.setLutMask( name, Core.Point(x, y), data) elif rType == RoiCounterTask.LUT: x = d["x"] y = d["y"] data = d["data"] self.__roiCounterMgr.setLut( name, Core.Point(x, y), data) names.append(name) except KeyError as err: PyTango.Except.throw_exception( 'Config error', 'Missing key %s in roi named %s' % (err, name), 'RoiCounterDeviceServer Class') self.__roiCounterMgr.updateRois(namedRois) self.add(names) except: import traceback traceback.print_exc()
def write_Roi(self, attr): data = attr.get_write_value() state = self.dev_state() self.Stop() roi = Core.Roi() roi.setTopLeft(Core.Point(data[0], data[1])) roi.setSize(Core.Size(data[2], data[3])) self.image.setRoi(roi) if state == PyTango.DevState.ON: self.Start()
def test_slsdetector_control(config_fname, enable_debug, use_events, print_time, sleep_time, all_frames): if enable_debug: Core.DebParams.enableModuleFlags(Core.DebParams.AllFlags) Core.DebParams.enableTypeFlags(Core.DebParams.AllFlags) else: Core.DebParams.disableModuleFlags(Core.DebParams.AllFlags) deb.Always("Creating SlsDetectorAcq") acq = SlsDetectorAcq(config_fname, use_events, print_time, sleep_time, all_frames) deb.Always("Done!") acq.initSaving("data", "img", ".edf", 0, Core.CtSaving.EDF, Core.CtSaving.AutoFrame, 1) deb.Always("First run with default pars") acq.run() deb.Always("Done!") exp_time = 100e-3 acq.setExpTime(exp_time) nb_acq_frames = 50 acq.setNbAcqFrames(nb_acq_frames) deb.Always("Run exp_time=%s, nb_acq_frames=%s" % (exp_time, nb_acq_frames)) acq.run() deb.Always("Done!") bin = Core.Bin(2, 2) acq.setBin(bin) nb_acq_frames = 5 acq.setNbAcqFrames(nb_acq_frames) deb.Always("Run bin=<%sx%s>, nb_acq_frames=%s" % (bin.getX(), bin.getY(), nb_acq_frames)) acq.run() deb.Always("Done!") roi = Core.Roi(Core.Point(256, 512), Core.Size(256, 512)) if acq.checkValidRoi(roi): acq.setRoi(roi) roi_tl, roi_size = roi.getTopLeft(), roi.getSize() deb.Always( "Run roi=<%s,%s>-<%sx%s>" % (roi_tl.x, roi_tl.y, roi_size.getWidth(), roi_size.getHeight())) acq.run() deb.Always("Done!")
def data2FrameInfo(self, data): arr = data.buffer arr_type = arr.dtype.type arr_height, arr_width = arr.shape image_type = self.DataType2ImageType[arr_type] buffer_ctrl = self.m_hw_inter.getHwCtrlObj(Core.HwCap.Buffer) start_ts = buffer_ctrl.getStartTimestamp() fdim = Core.FrameDim(arr_width, arr_height, image_type) timestamp = Core.Timestamp(data.timestamp) valid_pixels = Core.Point(fdim.getSize()).getArea() ownership = Core.HwFrameInfoType.Managed finfo = Core.HwFrameInfoType(data.frameNumber, arr, timestamp, valid_pixels, ownership) return finfo, fdim
def setKinPars(self, kin_win_size, kin_line_beg, kin_stripes): deb.Param('Setting kin pars: ' + 'kin_win_size=%s, kin_line_beg=%s, kin_stripes=%s' % \ (kin_win_size, kin_line_beg, kin_stripes)) if kin_stripes > 1: deb.Warning('Ignoring kin_stripes=%d' % kin_stripes) bin = _FrelonAcq.getBin() if kin_win_size % bin.getY() != 0: msg = 'Invalid kinetics window size (%d): ' % kin_win_size + \ 'must be multiple of vert. bin (%d)' % bin.getY() raise Core.Exception, msg roi = _FrelonAcq.getRoi() roi = roi.getUnbinned(bin) tl = Core.Point(roi.getTopLeft().x, kin_line_beg) size = Core.Size(roi.getSize().getWidth(), kin_win_size) roi = Core.Roi(tl, size) roi = roi.getBinned(bin) _FrelonAcq.setRoi(roi) _FrelonAcq.setRoiLineBegin(kin_line_beg)
def test_frelon_acc(enable_debug, espia_dev_nb, vert_bin, exp_time, acc_max_exp_time, nb_frames, acc_time_mode): if enable_debug: Core.DebParams.enableModuleFlags(Core.DebParams.AllFlags) Core.DebParams.enableTypeFlags(Core.DebParams.AllFlags) else: Core.DebParams.disableModuleFlags(Core.DebParams.AllFlags) deb.Always("Creating FrelonAcq") acq = Frelon.FrelonAcq(espia_dev_nb) deb.Trace("Done!") cam = acq.getFrelonCamera() ct = acq.getGlobalControl() ct_image = ct.image() ct_acq = ct.acquisition() acq_state = Core.AcqState() status_cb = ImageStatusCallback(ct, acq_state) ct.registerImageStatusCallback(status_cb) deb.Always("Setting Full Frame Mode - Speed - Chan 3&4") cam.setSPB2Config(Frelon.SPB2Speed) cam.setFrameTransferMode(Frelon.FFM) cam.setInputChan(Frelon.Chan34) deb.Trace("Done!") frame_dim = acq.getFrameDim(max_dim=True) bin = Core.Bin(1, vert_bin) deb.Always("Setting binning %s" % bin) ct_image.setBin(bin) deb.Trace("Done!") image_size = frame_dim.getSize() nb_cols = image_size.getWidth() nb_lines = image_size.getHeight() / vert_bin roi = Core.Roi(Core.Point(0, nb_lines - 2), Core.Size(nb_cols, 1)) deb.Always("Setting RoI %s" % roi) ct_image.setRoi(roi) deb.Trace("Done!") deb.Always("Setting Kinetic RoI mode") cam.setRoiMode(Frelon.Kinetic) deb.Trace("Done!") deb.Always("Setting Acc. mode") ct_acq.setAcqMode(Core.Accumulation) deb.Trace("Done!") deb.Always("Setting %s Acc. Time mode" % acc_time_mode) acc_mode = Core.CtAcquisition.Live \ if acc_time_mode == 'Live' \ else Core.CtAcquisition.Real ct_acq.setAccTimeMode(acc_mode) deb.Trace("Done!") deb.Always("Setting Acc. max. exp. time %s" % acc_max_exp_time) ct_acq.setAccMaxExpoTime(acc_max_exp_time) deb.Trace("Done!") deb.Always("Setting exp. time %s" % exp_time) ct_acq.setAcqExpoTime(exp_time) deb.Trace("Done!") deb.Always("Setting nb. frames %s" % nb_frames) ct_acq.setAcqNbFrames(nb_frames) deb.Trace("Done!") acc_nb_frames = ct_acq.getAccNbFrames() acc_dead_time = ct_acq.getAccDeadTime() acc_live_time = ct_acq.getAccLiveTime() deb.Always("AccNbFrames: %d, AccDeadTime: %.6f, AccLiveTime: %.6f" % (acc_nb_frames, acc_dead_time, acc_live_time)) deb.Always("Preparing acq.") ct.prepareAcq() deb.Trace("Done!") deb.Always("Starting acq.") status_cb.start() ct.startAcq() deb.Trace("Done!") state_mask = Core.AcqState.Acquiring acq_state.waitNot(state_mask) deb.Always("Finished!") dead_time = cam.getDeadTime() read_time = cam.getReadoutTime() xfer_time = cam.getTransferTime() deb.Always("Dead Time: %.6f, Readout Time: %.6f, Transfer Time: %.6f" % (dead_time, read_time, xfer_time))
def write_roi_bin_offset(self, attr): roi_bin_offset = Core.Point(0, attr.get_write_value()) _FrelonAcq.setRoiBinOffset(roi_bin_offset)
def write_roi_bin_offset(self, attr): roi_bin_offset = Core.Point(0, attr.get_write_value()) cam = _FrelonAcq.getFrelonCamera() cam.setRoiBinOffset(roi_bin_offset)
def main(argv): deb.Always("Creating Espia.Dev") edev = Espia.Dev(0) deb.Always("Creating Espia.Acq") acq = Espia.Acq(edev) acqstat = acq.getStatus() deb.Always("Whether the Acquisition is running : %s" % acqstat.running) deb.Always("Creating Espia.BufferMgr") buffer_cb_mgr = Espia.BufferMgr(acq) deb.Always("Creating BufferCtrlMgr") buffer_mgr = Core.BufferCtrlMgr(buffer_cb_mgr) deb.Always("Creating Espia.SerialLine") eser_line = Espia.SerialLine(edev) deb.Always("Creating Frelon.Camera") cam = Frelon.Camera(eser_line) deb.Always("Creating the Hw Interface ... ") hw_inter = Frelon.Interface(acq, buffer_mgr, cam) deb.Always("Creating HW BufferSave") buffer_save = Core.HwBufferSave(Core.HwBufferSave.EDF, "img", 0, ".edf", True, 1) deb.Always("Getting HW detector info") hw_det_info = hw_inter.getHwCtrlObj(Core.HwCap.DetInfo) deb.Always("Getting HW buffer") hw_buffer = hw_inter.getHwCtrlObj(Core.HwCap.Buffer) deb.Always("Getting HW Sync") hw_sync = hw_inter.getHwCtrlObj(Core.HwCap.Sync) deb.Always("Getting HW Bin") hw_bin = hw_inter.getHwCtrlObj(Core.HwCap.Bin) deb.Always("Getting HW RoI") hw_roi = hw_inter.getHwCtrlObj(Core.HwCap.Roi) mis_cb = MaxImageSizeCallback() hw_det_info.registerMaxImageSizeCallback(mis_cb) deb.Always("Setting FTM") cam.setFrameTransferMode(Frelon.FTM) deb.Always("Setting FFM") cam.setFrameTransferMode(Frelon.FFM) soft_roi = Core.Roi() acq_state = Core.AcqState() deb.Always("Creating a TestFrameCallback") cb = TestFrameCallback(hw_inter, soft_roi, buffer_save, acq_state) do_reset = False if do_reset: deb.Always("Reseting hardware ...") hw_inter.reset(HwInterface.HardReset) deb.Always(" Done!") size = hw_det_info.getMaxImageSize() image_type = hw_det_info.getCurrImageType() frame_dim = Core.FrameDim(size, image_type) bin = Core.Bin(Core.Point(1)) hw_bin.setBin(bin) #Roi set_roi, real_roi; #set_hw_roi(hw_roi, set_roi, real_roi, soft_roi); effect_frame_dim = Core.FrameDim(frame_dim) # was (frame_dim / bin) hw_buffer.setFrameDim(effect_frame_dim) hw_buffer.setNbBuffers(10) hw_buffer.registerFrameCallback(cb) hw_sync.setExpTime(2) hw_sync.setNbFrames(3) deb.Always("Starting Acquisition") acq_state.set(Core.AcqState.Acquiring) hw_inter.startAcq() deb.Always("Waiting acq finished...") acq_state.waitNot(Core.AcqState.Acquiring) deb.Always("Acq finished!!") deb.Always("Stopping Acquisition") hw_inter.stopAcq() deb.Always("This is the End...")
def test_frelon_control(enable_debug, use_events, print_time, sleep_time, all_frames): if enable_debug: Core.DebParams.enableModuleFlags(Core.DebParams.AllFlags) Core.DebParams.enableTypeFlags(Core.DebParams.AllFlags) else: Core.DebParams.disableModuleFlags(Core.DebParams.AllFlags) deb.Always("Creating FrelonAcq") espia_dev_nb = 0 acq = FrelonAcq(espia_dev_nb, use_events, print_time, sleep_time, all_frames) deb.Always("Done!") acq.initSaving("data", "img", ".edf", 0, Core.CtSaving.EDF, Core.CtSaving.AutoFrame, 1); deb.Always("First run with default pars") acq.run() deb.Always("Done!") exp_time = 1e-6 acq.setExpTime(exp_time) nb_acq_frames = 500 acq.setNbAcqFrames(nb_acq_frames) deb.Always("Run exp_time=%s, nb_acq_frames=%s" % (exp_time, nb_acq_frames)) acq.run() deb.Always("Done!") bin = Core.Bin(2, 2) acq.setBin(bin) nb_acq_frames = 5 acq.setNbAcqFrames(nb_acq_frames) deb.Always("Run bin=<%sx%s>, nb_acq_frames=%s" % (bin.getX(), bin.getY(), nb_acq_frames)) acq.run() deb.Always("Done!") roi = Core.Roi(Core.Point(256, 256), Core.Size(512, 512)); acq.setRoi(roi); roi_tl, roi_size = roi.getTopLeft(), roi.getSize() deb.Always("Run roi=<%s,%s>-<%sx%s>" % (roi_tl.x, roi_tl.y, roi_size.getWidth(), roi_size.getHeight())) acq.run() deb.Always("Done!") roi = Core.Roi(Core.Point(267, 267), Core.Size(501, 501)); acq.setRoi(roi); roi_tl, roi_size = roi.getTopLeft(), roi.getSize() deb.Always("Run roi=<%s,%s>-<%sx%s>" % (roi_tl.x, roi_tl.y, roi_size.getWidth(), roi_size.getHeight())) acq.run() deb.Always("Done!")