reindent and some image tweeks
This commit is contained in:
85
camera.py
85
camera.py
@@ -24,6 +24,20 @@ Best regards
|
||||
Helge
|
||||
"""
|
||||
|
||||
# In [2]: np.array(range(20))
|
||||
# Out[2]:
|
||||
# array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||
# 17, 18, 19])
|
||||
|
||||
# In [3]: np.array(range(20)).reshape(4,5)
|
||||
# Out[3]:
|
||||
# array([[ 0, 1, 2, 3, 4],
|
||||
# [ 5, 6, 7, 8, 9],
|
||||
# [10, 11, 12, 13, 14],
|
||||
# [15, 16, 17, 18, 19]])
|
||||
|
||||
# shape is (imgidx,h,w) w is the fast counting index
|
||||
|
||||
import logging
|
||||
_log = logging.getLogger(__name__)
|
||||
|
||||
@@ -99,7 +113,7 @@ class epics_cam(object):
|
||||
imgSeq=self._sim['imgSeq']
|
||||
idx=self._sim['imgIdx']
|
||||
self._sim['imgIdx']=(idx + 1) % imgSeq.shape[0]
|
||||
_log.info('simulated idx:{}'.format(idx))
|
||||
#_log.debug('simulated idx:{}'.format(idx))
|
||||
self.pic=pic=imgSeq[idx]
|
||||
return pic
|
||||
try:
|
||||
@@ -200,9 +214,10 @@ class epics_cam(object):
|
||||
|
||||
def sim_gen(self,sz=(1500,1000),t=100,mode=0):
|
||||
'generate simulation data'
|
||||
_log.info('generate simulation images, mode:{}...'.format(mode))
|
||||
if mode==0:
|
||||
_log.info('generate {} pulsing wases simulation images, mode:{}...'.format(t,mode))
|
||||
w,h=sz
|
||||
self._imgSeq=imgSeq=np.ndarray(shape=(t,h,w),dtype=np.uint16)
|
||||
imgSeq=np.ndarray(shape=(t,h,w),dtype=np.uint16)
|
||||
x = np.linspace(-5, 5, w)
|
||||
y = np.linspace(-5, 5, h)
|
||||
# full coordinate arrays
|
||||
@@ -221,9 +236,32 @@ class epics_cam(object):
|
||||
wr=w//4
|
||||
hr=h//4
|
||||
imgSeq[:,0:hr,0:wr]+=np.random.randint(0,100,(t,hr,wr),dtype=np.uint16)
|
||||
elif mode==1:
|
||||
import glob,PIL.Image
|
||||
path='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/SwissMX/simCamImg/*.png'
|
||||
_log.info('generate simulation images:{}...'.format(path))
|
||||
glb=glob.glob(path)
|
||||
img = PIL.Image.open(glb[0])
|
||||
sz=img.size # (w,h)
|
||||
imgSeq=np.ndarray(shape=(len(glb),sz[1],sz[0]),dtype=np.uint8) # shape is (n,h,w)
|
||||
for i,fn in enumerate(glb):
|
||||
img=PIL.Image.open(fn)
|
||||
assert(img.mode=='L') # 8 bit grayscale
|
||||
assert(sz==img.size)
|
||||
imgSeq[i,:,:]=np.array(img.getdata()).reshape(sz[::-1])
|
||||
f=np.array(((0,0,0,0,0),
|
||||
(0,1,1,1,0),
|
||||
(0,1,0,0,0),
|
||||
(0,1,1,0,0),
|
||||
(0,1,0,0,0),
|
||||
(0,0,0,0,0),),imgSeq.dtype)
|
||||
imgSeq[i,0:6,0:5]=f*255
|
||||
|
||||
|
||||
|
||||
self._sim['imgSeq']=imgSeq
|
||||
self._sim['imgIdx']=0
|
||||
_log.info('dome')
|
||||
_log.info('done-> shape:{} dtype:{}'.format(imgSeq.shape,imgSeq.dtype))
|
||||
|
||||
def set_transformations(self,*args):
|
||||
_log.error('OLD FUNCTION NOT IMPLEMENTED {}'.format(args))
|
||||
@@ -232,7 +270,9 @@ class epics_cam(object):
|
||||
if __name__ == "__main__":
|
||||
import time, os, PIL.Image, platform, subprocess
|
||||
import argparse
|
||||
logging.basicConfig(level=logging.DEBUG,format='%(levelname)s:%(module)s:%(lineno)d:%(funcName)s:%(message)s ')
|
||||
logging.basicConfig(level=logging.DEBUG,format='%(name)s:%(levelname)s:%(module)s:%(lineno)d:%(funcName)s:%(message)s ')
|
||||
logging.getLogger('PIL').setLevel(logging.INFO)
|
||||
|
||||
|
||||
def default_app_open(file):
|
||||
if platform.system() == 'Darwin': # macOS
|
||||
@@ -248,6 +288,7 @@ if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--ui", "-u", help="qt test", type=int, default=0)
|
||||
parser.add_argument("--sim", "-s", help="simulation mode", type=int, default=None)
|
||||
parser.add_argument("--delay", "-d", help="delay in simulation mode", type=float, default=None)
|
||||
parser.add_argument("--prefix","-p",help="PV prefix for images: default=%(default)s",type=str,default="SARES30-CAMS156-SMX-OAV",)
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -328,8 +369,12 @@ if __name__ == "__main__":
|
||||
(0,1,0,0,0),
|
||||
(0,0,0,0,0),),pic.dtype)
|
||||
pic[0:6,0:5]=f*pic.max()
|
||||
if args.ui==1:
|
||||
img.setImage(pic)
|
||||
else:
|
||||
imv.setImage(pic, autoRange=False, autoLevels=False)
|
||||
|
||||
|
||||
def new_frame_sim_cb(self,arl=False):
|
||||
imgSeq =self._sim['imgSeq']
|
||||
idx =self._sim['imgIdx']
|
||||
@@ -338,9 +383,15 @@ if __name__ == "__main__":
|
||||
self._sim['imgIdx']=(idx+1) % imgSeq.shape[0]
|
||||
#_log.info('simulated idx:{}'.format(idx))
|
||||
pic = imgSeq[idx]
|
||||
if args.ui==1:
|
||||
img.setImage(pic)
|
||||
else:
|
||||
imv.setImage(pic, autoRange=arl, autoLevels=arl)
|
||||
|
||||
QtCore.QTimer.singleShot(1, self.new_frame_sim_cb)
|
||||
if args.delay:
|
||||
QtCore.QTimer.singleShot(int(1000*args.delay), self.new_frame_sim_cb)
|
||||
else:
|
||||
QtCore.QTimer.singleShot(0, self.new_frame_sim_cb)
|
||||
now = ptime.time()
|
||||
fps2 = 1.0 / (now - udt)
|
||||
self._sim['updateTime'] = now
|
||||
@@ -358,6 +409,26 @@ if __name__ == "__main__":
|
||||
|
||||
app = QtGui.QApplication([])
|
||||
|
||||
if args.ui==1:
|
||||
win = pg.GraphicsLayoutWidget()
|
||||
win.show() ## show widget alone in its own window
|
||||
win.setWindowTitle('pyqtgraph example: ImageItem')
|
||||
view = win.addViewBox(invertY=True)
|
||||
|
||||
## lock the aspect ratio so pixels are always square
|
||||
view.setAspectLocked(True)
|
||||
|
||||
## Create image item https://pyqtgraph.readthedocs.io/en/latest/graphicsItems/imageitem.html
|
||||
img = pg.ImageItem(border='g')
|
||||
#tr = QtGui.QTransform() # prepare ImageItem transformation:
|
||||
#tr.scale(6.0, 3.0) # scale horizontal and vertical axes
|
||||
#tr.translate(-1.5, -1.5) # move 3x3 image to locate center at axis origin
|
||||
#img.setTransform(tr) # assign transform
|
||||
view.addItem(img)
|
||||
|
||||
## Set initial view bounds
|
||||
view.setRange(QtCore.QRectF(0, 0, 600, 600))
|
||||
else:
|
||||
## Create window with ImageView widget
|
||||
win = QtGui.QMainWindow()
|
||||
win.resize(800,800)
|
||||
@@ -366,6 +437,7 @@ if __name__ == "__main__":
|
||||
win.show()
|
||||
win.setWindowTitle('pyqtgraph example: ImageView')
|
||||
|
||||
|
||||
## Display the data and assign each frame a time value from 1.0 to 3.0
|
||||
cam = UIcamera(prefix=args.prefix)
|
||||
|
||||
@@ -383,6 +455,7 @@ if __name__ == "__main__":
|
||||
cam._sim['updateTime'] = ptime.time()
|
||||
cam.new_frame_sim_cb(arl=True)
|
||||
|
||||
if args.ui==2:
|
||||
## Set a custom color map
|
||||
colors = [(0, 0, 0),(45, 5, 61),(84, 42, 55),(150, 87, 60),(208, 171, 141),(255, 255, 255)]
|
||||
cmap = pg.ColorMap(pos=np.linspace(0.0, 1.0, 6), color=colors)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import math
|
||||
import logging
|
||||
_log = logging.getLogger(__name__)
|
||||
|
||||
import math
|
||||
from time import sleep
|
||||
from PyQt5.QtCore import Qt, pyqtSignal
|
||||
from PyQt5.QtGui import QPainter, QBrush, QColor, QPainterPath, QPen, QDoubleValidator
|
||||
@@ -11,8 +13,6 @@ from epics.ca import pend_event
|
||||
from app_utils import DeltatauMotorStatus, assert_motor_positions
|
||||
|
||||
Ui_MotorTweak, QWidget = loadUiType('epics_widgets/MotorTweak.ui')
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.INFO)
|
||||
SPMG_STOP = 0
|
||||
SPMG_PAUSE = 1
|
||||
SPMG_MOVE = 2
|
||||
@@ -54,7 +54,7 @@ class MotorTweak(QWidget, Ui_MotorTweak):
|
||||
self._pvname = motor_base
|
||||
|
||||
for attr in ['RTYP', 'JVEL', 'HLS', 'LLS', 'TWV', 'RBV', 'VAL', 'LVIO', 'HLM', 'LLM']:
|
||||
# logger.debug('connecting to field {}'.format(attr))
|
||||
# _log.debug('connecting to field {}'.format(attr))
|
||||
m.PV(attr, connect=True)
|
||||
|
||||
self.set_motor_validator()
|
||||
@@ -97,7 +97,7 @@ class MotorTweak(QWidget, Ui_MotorTweak):
|
||||
|
||||
def set_val(self, **kw):
|
||||
v = kw['char_value']
|
||||
logger.debug('updating VAL = {}'.format(v))
|
||||
_log.debug('updating VAL = {}'.format(v))
|
||||
self._drive_val.setText(v)
|
||||
|
||||
|
||||
@@ -264,9 +264,9 @@ class MotorTweak(QWidget, Ui_MotorTweak):
|
||||
name = m.NAME
|
||||
prec = m.PREC
|
||||
msg = 'Precision for motor {}'.format(name)
|
||||
logger.debug('prec before %d', prec)
|
||||
_log.debug('prec before %d', prec)
|
||||
prec, ok = QInputDialog.getInt(self, msg, msg, prec, 0, 10)
|
||||
logger.debug('prec after (%d) %d', ok, prec)
|
||||
_log.debug('prec after (%d) %d', ok, prec)
|
||||
if ok:
|
||||
self.motor.put('PREC', prec, wait=True)
|
||||
|
||||
@@ -335,7 +335,11 @@ class MotorTweak(QWidget, Ui_MotorTweak):
|
||||
qp.end()
|
||||
|
||||
def _draw_limits(self, qp):
|
||||
try:
|
||||
m = self.motor
|
||||
except AttributeError:
|
||||
_log.warning('Motor not connected')
|
||||
return
|
||||
width, height = self.size().width(), self.size().height()
|
||||
pad = 5
|
||||
rounding = 2
|
||||
|
||||
@@ -318,7 +318,7 @@ class Main(QMainWindow, Ui_MainWindow):
|
||||
|
||||
self.init_actions()
|
||||
self.prepare_microscope_page()
|
||||
self.prepare_embl_gui()
|
||||
#self.prepare_embl_gui()
|
||||
self.prepare_left_tabs()
|
||||
#self.update_beam_marker(qoptic_zoom.get_position()) #ZAC: orig. code
|
||||
self._centerpiece_stack.setCurrentIndex(0)
|
||||
@@ -388,11 +388,13 @@ class Main(QMainWindow, Ui_MainWindow):
|
||||
self.vb.addItem(self._beammark)
|
||||
|
||||
def camera_pause_toggle(self):
|
||||
sample_camera.pause()
|
||||
app=QApplication.instance()
|
||||
app._camera.pause()
|
||||
|
||||
def updateImage(self, pause=False):
|
||||
#if not sample_camera.is_paused(): #ZAC: orig. code
|
||||
img = sample_camera.get_image()
|
||||
app=QApplication.instance()
|
||||
img = app._camera.get_image()
|
||||
if img is not None:
|
||||
self.img.setImage(img)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user