def DatatoImage(self): #, data, size, mode): """convert raw data to image""" x = debugtime() width, height = self.im_size d_size = (int(width*self.scale), int(height*self.scale)) data = self.data.flatten() # x.add('flatten %i' % len(data)) if self.imbuff is None or d_size != self.d_size or self.im_mode == 'L': try: self.imbuff = Image.frombuffer(self.im_mode, self.im_size, data, 'raw', self.im_mode, 0, 1) # x.add('made image') except: return self.d_size = d_size = (int(width*self.scale), int(height*self.scale)) if self.imbuff.size != d_size: self.imbuff = self.imbuff.resize(d_size) # x.add('resized imbuff') if self.wximage.GetSize() != self.imbuff.size: self.wximage = wx.EmptyImage(d_size[0], d_size[1]) # x.add('created wximage %s ' % (repr(self.wximage.GetSize()))) # print "IMAGE MODE ", self.im_mode, len(data), data.shape if self.im_mode == 'L': self.wximage.SetData(self.imbuff.convert('RGB').tostring()) elif self.im_mode == 'RGB': data.shape = (3, width, height) self.wximage = wx.ImageFromData(width, height, data) # x.add('set wx image wximage : %i, %i ' % d_size) self.image.SetValue(self.wximage)
def DatatoImage(self): #, data, size, mode): """convert raw data to image""" x = debugtime() width, height = self.im_size d_size = (int(width * self.scale), int(height * self.scale)) data = self.data.flatten() # x.add('flatten %i' % len(data)) if self.imbuff is None or d_size != self.d_size or self.im_mode == 'L': try: self.imbuff = Image.frombuffer(self.im_mode, self.im_size, data, 'raw', self.im_mode, 0, 1) # x.add('made image') except: return self.d_size = d_size = (int(width * self.scale), int(height * self.scale)) if self.imbuff.size != d_size: self.imbuff = self.imbuff.resize(d_size) # x.add('resized imbuff') if self.wximage.GetSize() != self.imbuff.size: self.wximage = wx.EmptyImage(d_size[0], d_size[1]) # x.add('created wximage %s ' % (repr(self.wximage.GetSize()))) # print "IMAGE MODE ", self.im_mode, len(data), data.shape if self.im_mode == 'L': self.wximage.SetData(self.imbuff.convert('RGB').tostring()) elif self.im_mode == 'RGB': data.shape = (3, width, height) self.wximage = wx.ImageFromData(width, height, data) # x.add('set wx image wximage : %i, %i ' % d_size) self.image.SetValue(self.wximage)
def connect_pvs(self, npvs=None): d = debugtime() self.get_pvnames() if npvs is None: npvs = len(self.pvnames) elif npvs < len(self.pvnames): self.pvnames = self.pvnames[:npvs] n_notify = npvs / 10 d.add("connecting to %i PVs" % npvs) for pvname in self.pvnames: try: self.pvs[pvname] = epics.PV(pvname, connection_timeout=1.0) except epics.ca.ChannelAccessException: sys.stderr.write(' Could not create PV %s \n' % pvname) d.add('Created %i PV Objects' % len(self.pvs), verbose=False) time.sleep(0.0001*npvs) epics.ca.poll() unconn = 0 for pv in self.pvs.values(): if not pv.connected: time.sleep(0.002) if not pv.connected: unconn = unconn + 1 epics.ca.poll() d.add("Connected to PVs (%i not connected)" % unconn, verbose=False) self.data = {} for pv in self.pvs.values(): if pv is not None and pv.connected: cval = pv.get(as_string=True) self.data[pv.pvname] = (pv.value, cval, time.time()) d.add("got initial values for PVs", verbose=False) #for pvname, vals in self.data.items(): # print pvname, vals self.last_update = 0 self.update_cache() d.add("Entered values for %i PVs to Db" % npvs) for i, pv in enumerate(self.pvs.values()): if pv is not None and pv.connected: pv.add_callback(self.onChanges) d.add("added callbacks for PVs") # unconn =self.look_for_unconnected_pvs() d.add("looked for unconnected pvs: %i not connected" % unconn) d.show()
def RefreshImage(self): d = debugtime() imgdim = self.ad_dev.NDimensions_RBV arraysize = self.arrsize[0] * self.arrsize[1] if imgdim == 3: arraysize = arraysize * self.arrsize[2] if not self.ad_dev.PV('ArrayData').connected: return im_mode = 'L' im_size = (self.arrsize[0], self.arrsize[1]) if self.colormode == 2: im_mode = 'RGB' im_size = [self.arrsize[1], self.arrsize[2]] d.add('know image size/type') rawdata = self.ad_dev.PV('ArrayData').get(count=arraysize) d.add('have rawdata') imbuff = Image.frombuffer(im_mode, im_size, rawdata, 'raw', im_mode, 0, 1) d.add('data to imbuff') self.GetImageSize() display_size = (int(self.img_h * self.scale), int(self.img_w * self.scale)) if self.img_h < 1 or self.img_w < 1: return imbuff = imbuff.resize(display_size) d.add('imbuff resized') if self.wximage.GetSize() != imbuff.size: self.wximage = wx.EmptyImage(display_size[0], display_size[1]) self.wximage.SetData(imbuff.convert('RGB').tostring()) self.image.SetValue(self.wximage) d.add('wx bitmap set')
def RefreshImage(self): d = debugtime() imgdim = self.ad_dev.NDimensions_RBV arraysize = self.arrsize[0] * self.arrsize[1] if imgdim == 3: arraysize = arraysize * self.arrsize[2] if not self.ad_dev.PV('ArrayData').connected: return im_mode = 'L' im_size = (self.arrsize[0], self.arrsize[1]) if self.colormode == 2: im_mode = 'RGB' im_size = [self.arrsize[1], self.arrsize[2]] d.add('know image size/type') rawdata = self.ad_dev.PV('ArrayData').get(count=arraysize) d.add('have rawdata') imbuff = Image.frombuffer(im_mode, im_size, rawdata, 'raw', im_mode, 0, 1) d.add('data to imbuff') self.GetImageSize() display_size = (int(self.img_h*self.scale), int(self.img_w*self.scale)) if self.img_h < 1 or self.img_w < 1: return imbuff = imbuff.resize(display_size) d.add('imbuff resized') if self.wximage.GetSize() != imbuff.size: self.wximage = wx.EmptyImage(display_size[0], display_size[1]) self.wximage.SetData(imbuff.convert('RGB').tostring()) self.image.SetValue(self.wximage) d.add('wx bitmap set')
from epics import ca, dbr import time import debugtime try: from collections import OrderedDict except: from ordereddict import OrderedDict dt = debugtime.debugtime() def add(x): print(x) dt.add(x) add('test of fast connection to many PVs') pvnames = [] results = OrderedDict() MAX_PVS = 12500 for line in open('fastconn_pvlist.txt','r').readlines(): if not line.startswith('#'): pvnames.append(line.strip()) if MAX_PVS is not None: pvnames = pvnames[:MAX_PVS] add('Read PV list: Will connect to %i PVs' % len(pvnames)) libca = ca.initialize_libca() for name in pvnames:
from epics import ca, dbr import time import debugtime try: from collections import OrderedDict except: from ordereddict import OrderedDict dt = debugtime.debugtime() dt.add('test of fast connection to many PVs') pvnames = [] results = OrderedDict() MAX_PVS = 20000 for line in open('fastconn_pvlist.txt','r').readlines(): if not line.startswith('#'): pvnames.append(line[:-1]) if MAX_PVS is not None: pvnames = pvnames[:MAX_PVS] dt.add('Read PV list: Will connect to %i PVs' % len(pvnames)) libca = ca.initialize_libca() for name in pvnames: chid = ca.create_channel(name, connect=False, auto_cb=False) results[name] = {'chid': chid}
def RefreshImage(self, pvname=None, **kws): try: wx.Yield() except: pass d = debugtime() if self.ad_img is None or self.ad_cam is None: return imgdim = self.ad_img.NDimensions_RBV imgcount = self.ad_cam.ArrayCounter_RBV now = time.time() if (imgcount == self.imgcount or abs(now - self.last_update) < 0.025): self.drawing = False return d.add('refresh img start') self.imgcount = imgcount self.drawing = True self.n_drawn += 1 self.n_img = imgcount - self.imgcount_start #print 'ImgCount, n_drawn: ', imgcount, self.n_img, self.n_drawn self.last_update = time.time() self.image.can_resize = False xmin = self.ad_cam.MinX ymin = self.ad_cam.MinY width = self.ad_cam.SizeX height = self.ad_cam.SizeY arraysize = self.arrsize[0] * self.arrsize[1] if imgdim == 3: arraysize = arraysize * self.arrsize[2] if not self.ad_img.PV('ArrayData').connected: self.drawing = False return d.add('refresh img before raw get %i' % arraysize) rawdata = self.ad_img.PV('ArrayData').get(count=arraysize) d.add('refresh img after raw get') im_mode = 'L' im_size = (self.arrsize[0], self.arrsize[1]) if self.colormode == 2: im_mode = 'RGB' im_size = [self.arrsize[1], self.arrsize[2]] if (self.colormode == 0 and isinstance(rawdata, np.ndarray) and rawdata.dtype != np.uint8): im_mode = 'I' rawdata = rawdata.astype(np.uint32) d.add('refresh img before msg') self.messag(' Image # %i ' % self.ad_cam.ArrayCounter_RBV, panel=2) d.add('refresh img before get image size') self.GetImageSize() self.im_size = im_size self.im_mode = im_mode self.data = rawdata d.add('refresh img before data to image') self.DatatoImage() d.add('refresh img after data to image') self.image.can_resize = True nmissed = max(0, self.n_img - self.n_drawn) delt = time.time() - self.starttime percent_drawn = self.n_drawn * 100 / (self.n_drawn + nmissed) smsg = self.stat_msg % (percent_drawn, self.n_drawn / delt) self.messag(smsg, panel=0) self.drawing = False d.add('refresh img done')
def RefreshImage(self, pvname=None, **kws): try: wx.Yield() except: pass d = debugtime() if self.ad_img is None or self.ad_cam is None: return imgdim = self.ad_img.NDimensions_RBV imgcount = self.ad_cam.ArrayCounter_RBV now = time.time() if (imgcount == self.imgcount or abs(now - self.last_update) < 0.025): self.drawing = False return d.add('refresh img start') self.imgcount = imgcount self.drawing = True self.n_drawn += 1 self.n_img = imgcount - self.imgcount_start #print 'ImgCount, n_drawn: ', imgcount, self.n_img, self.n_drawn self.last_update = time.time() self.image.can_resize = False xmin = self.ad_cam.MinX ymin = self.ad_cam.MinY width = self.ad_cam.SizeX height = self.ad_cam.SizeY arraysize = self.arrsize[0] * self.arrsize[1] if imgdim == 3: arraysize = arraysize * self.arrsize[2] if not self.ad_img.PV('ArrayData').connected: self.drawing = False return d.add('refresh img before raw get %i' % arraysize) rawdata = self.ad_img.PV('ArrayData').get(count=arraysize) d.add('refresh img after raw get') im_mode = 'L' im_size = (self.arrsize[0], self.arrsize[1]) if self.colormode == 2: im_mode = 'RGB' im_size = [self.arrsize[1], self.arrsize[2]] if (self.colormode == 0 and isinstance(rawdata, np.ndarray) and rawdata.dtype != np.uint8): im_mode = 'I' rawdata = rawdata.astype(np.uint32) d.add('refresh img before msg') self.messag(' Image # %i ' % self.ad_cam.ArrayCounter_RBV, panel=2) d.add('refresh img before get image size') self.GetImageSize() self.im_size = im_size self.im_mode = im_mode self.data = rawdata d.add('refresh img before data to image') self.DatatoImage() d.add('refresh img after data to image') self.image.can_resize = True nmissed = max(0, self.n_img-self.n_drawn) delt = time.time()-self.starttime percent_drawn = self.n_drawn * 100 / (self.n_drawn+nmissed) smsg = self.stat_msg % (percent_drawn, self.n_drawn/delt) self.messag(smsg, panel=0) self.drawing = False d.add('refresh img done')
import time import epics import debugtime from XYTrajectory import XY_Trajectory traj = XY_Trajectory() dtimes = debugtime.debugtime() xstart = -0.5 xstop = 0.5 xstep = 0.002 dwelltime = 5.0 accel = 10.0 traj.DefineTrajectory('Foreward', xstart=xstart, xstop=xstop, xstep=xstep, dwelltime=dwelltime, accel=accel) traj.DefineTrajectory('Backward', xstart=xstop, xstop=xstart, xstep=xstep, dwelltime=dwelltime, accel=accel) dtimes.add('trajectories defined') traj.file_index = 0 traj.file_prefix = 'Scan1' yPV = epics.PV('13XRM:m2.VAL') xPV = epics.PV('13XRM:m1.VAL') ystart = -0.5 ystop = 0.5 ystep = 0.002