cleanup code
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*/__pycache__/
|
||||
scratch/
|
||||
@@ -39,13 +39,12 @@ import os.path
|
||||
|
||||
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QSlider, QLineEdit,\
|
||||
QCheckBox, QHBoxLayout, QVBoxLayout, QGroupBox, QGridLayout, QComboBox
|
||||
from PyQt5.QtGui import QPainter, QColor, QPen, QBrush, QPolygon, QPolygonF, QTransform, QPainterPath, QPixmap
|
||||
from PyQt5.QtGui import QPainter, QColor, QPen, QBrush, QPolygon, QPolygonF, QTransform, QPainterPath, \
|
||||
QPixmap, QMouseEvent
|
||||
from PyQt5.QtCore import QPoint, QPointF, Qt,pyqtSignal
|
||||
|
||||
import PyQt5.QtGui as QtGui
|
||||
import PyQt5.QtCore as QtCore
|
||||
import PyQt5.QtWidgets as QtW
|
||||
from PyQt5.uic import loadUiType
|
||||
#import PyQt5.QtGui as QtGui
|
||||
#import PyQt5.QtCore as QtCore
|
||||
import numpy as np
|
||||
|
||||
import sys, logging, copy
|
||||
@@ -103,14 +102,6 @@ class logHandler(logging.StreamHandler):
|
||||
|
||||
|
||||
class ARESdevice():
|
||||
_lutDifrBeamPaint=( # (number of difr beam,draw mode,alpha,width)
|
||||
(4, 2, 190, 0),
|
||||
(4, 1, 200, 0),
|
||||
(32, 1, 120, 0),
|
||||
(8, 1, 196, 0),
|
||||
(32, 0, 120, 3),
|
||||
(32, 2, 255, 0),
|
||||
)
|
||||
|
||||
def __init__(self,name,**kwargs):
|
||||
self._name=name
|
||||
@@ -128,22 +119,11 @@ class ARESdevice():
|
||||
'aDet':100, # angle detector
|
||||
'aTrg':10, # angle target
|
||||
|
||||
'mode':4, #difraction beam paint mode
|
||||
'szG':(200, 5), # size VLS grating
|
||||
'szD':(150, 5), # size detector
|
||||
'sclTrf':(2**(6/2), 2**(-2/2)), # scaling transfformation [angle, distance]
|
||||
}
|
||||
# 2thetha angle SATES30-ARES:MOT_2TRY
|
||||
# detector angle SATES30-ARES:MOT_DRY
|
||||
# sliding seal SATES30-RIXS:MOT_RY
|
||||
|
||||
p.update(kwargs)
|
||||
self._geo=g={
|
||||
'r1':2000, # distance probe grating
|
||||
'r2':3500, # distance grating detector
|
||||
'aa':88, # grating angle
|
||||
'bb':87, # reflection angle
|
||||
'cc':22, # detector angle
|
||||
}
|
||||
self.setGeometry(g)
|
||||
self._pic=pic=dict()
|
||||
@@ -166,49 +146,11 @@ class ARESdevice():
|
||||
def setGeometry(self,geo):
|
||||
self._geo=geo
|
||||
p=self._paint
|
||||
sclA,sclD=p['sclTrf']
|
||||
p.update({
|
||||
'r1':int(geo['r1']*sclD),
|
||||
'r2':int(geo['r2']*sclD),
|
||||
'aa':int((90-geo['aa'])*sclA),
|
||||
'bb':int((90-geo['bb'])*sclA),
|
||||
'cc':int(geo['cc']),
|
||||
})
|
||||
|
||||
def geometry2motor(self):
|
||||
# returns raw motor positions
|
||||
# offset detector plane to deflected beam: 34deg
|
||||
|
||||
geo=self._geo
|
||||
r1,r2,aa,bb,cc=geo['r1'],geo['r2'],geo['aa'],geo['bb'],geo['cc']
|
||||
mt=gtz=gty1=gty2=grx=gtx=dtz=dty1=dty2=drx=None
|
||||
degArm=90-aa+90-bb
|
||||
radArm=np.deg2rad(degArm)
|
||||
gtz=r1
|
||||
grx=90-aa
|
||||
dtz=np.cos(radArm)*r2
|
||||
dty1=dty2=np.sin(radArm)*r2
|
||||
drx=90-aa+90-bb+cc-34
|
||||
dd=cc-34 # angle of bellow to detector
|
||||
|
||||
geo.update({
|
||||
'mt':mt,
|
||||
'gtz':gtz,
|
||||
'gty1':gty1,
|
||||
'gty2': gty2,
|
||||
'grx':grx,
|
||||
'gtx':gtx,
|
||||
'dtz':dtz,
|
||||
'dty1':dty1,
|
||||
'dty2':dty2,
|
||||
'drx':drx})
|
||||
|
||||
if degArm>10:
|
||||
raise(ValueError('angle arm > 10deg'))
|
||||
elif degArm<1:
|
||||
raise(ValueError('angle arm < 1deg'))
|
||||
elif abs(dd)>15:
|
||||
raise(ValueError('angle bellow to detector > 15deg'))
|
||||
|
||||
def containsPoint(self,point):
|
||||
try:
|
||||
@@ -219,8 +161,8 @@ class ARESdevice():
|
||||
|
||||
@staticmethod
|
||||
def plotOrig(qp):
|
||||
penR=QPen(QtCore.Qt.red, 2, QtCore.Qt.SolidLine)
|
||||
penG=QPen(QtCore.Qt.green, 2, QtCore.Qt.SolidLine)
|
||||
penR=QPen(Qt.red, 2, Qt.SolidLine)
|
||||
penG=QPen(Qt.green, 2, Qt.SolidLine)
|
||||
pOrig=qp.pen()
|
||||
qp.setPen(penR)
|
||||
qp.drawLine(-20, 0, 20, 0)
|
||||
@@ -282,30 +224,28 @@ class ARESdevice():
|
||||
tfTrg.rotate(-aTrg)
|
||||
#tfd.translate(r2,0).rotate(-cc)
|
||||
|
||||
penBk=QPen(QtCore.Qt.black, 0, QtCore.Qt.SolidLine)
|
||||
penWt=QPen(QtCore.Qt.white, 1, QtCore.Qt.SolidLine)
|
||||
penYl=QPen(QtCore.Qt.yellow, 1, QtCore.Qt.SolidLine)
|
||||
penBl=QPen(QtCore.Qt.blue, 1, QtCore.Qt.SolidLine)
|
||||
penRd=QPen(QtCore.Qt.red, 1, QtCore.Qt.SolidLine)
|
||||
penBk=QPen(Qt.black, 0, Qt.SolidLine)
|
||||
penWt=QPen(Qt.white, 1, Qt.SolidLine)
|
||||
penYl=QPen(Qt.yellow, 1, Qt.SolidLine)
|
||||
penBl=QPen(Qt.blue, 1, Qt.SolidLine)
|
||||
penRd=QPen(Qt.red, 1, Qt.SolidLine)
|
||||
|
||||
# --- visualize ---
|
||||
#qp.setRenderHints(QPainter.HighQualityAntialiasing)
|
||||
|
||||
# setup and plot dragable region
|
||||
self._polygon=QPolygon([
|
||||
QPoint(*tf0.map(-rArm ,-rArm)),
|
||||
QPoint(*tf0.map(-rArm ,+rArm+100)),
|
||||
QPoint(*tf0.map(-rArm,-rArm )),
|
||||
QPoint(*tf0.map(-rArm,+rArm+100)),
|
||||
QPoint(*tf0.map(+rArm,+rArm+100)),
|
||||
QPoint(*tf0.map(+rArm,-rArm)),])
|
||||
QPoint(*tf0.map(+rArm,-rArm )),
|
||||
])
|
||||
qp.setBrush(QColor(0, 0, 0,64))
|
||||
qp.drawPolygon(self._polygon)
|
||||
|
||||
# plot beam path
|
||||
|
||||
qp.setTransform(tf0)
|
||||
qp.setPen(penBk)
|
||||
qp.setBrush(QColor(128, 128, 128, 128)) #r,g,b,a
|
||||
|
||||
#circles of rotation
|
||||
#qp.drawEllipse(-rArm, -rArm, 2*rArm, 2*rArm) # ARES chamber
|
||||
#qp.drawEllipse(-r2Th, -r2Th, 2*r2Th, 2*r2Th) # 2theta
|
||||
@@ -332,7 +272,7 @@ class ARESdevice():
|
||||
|
||||
|
||||
#beam arrow
|
||||
qp.setPen(QPen(QtCore.Qt.black, 3, QtCore.Qt.SolidLine))
|
||||
qp.setPen(QPen(Qt.black, 3, Qt.SolidLine))
|
||||
qp.drawLine(0,+rArm+100,0,rArm)
|
||||
qp.drawPolygon(QPolygon([QPoint(0,rArm),QPoint(-5,rArm+20),QPoint(+5,rArm+20),]))
|
||||
|
||||
@@ -383,7 +323,7 @@ class ARESdevice():
|
||||
|
||||
#--- RIXS-arm devices ---
|
||||
qp.setTransform(tfArm)
|
||||
qp.setPen(QPen(QtCore.Qt.red, tickW, QtCore.Qt.SolidLine))
|
||||
qp.setPen(QPen(Qt.red, tickW, Qt.SolidLine))
|
||||
qp.drawLine(0,-rArm,0,-rArm+tickL) #tick
|
||||
qp.setPen(penBk)
|
||||
qp.setBrush(QColor(255,0,0,128))
|
||||
@@ -392,7 +332,7 @@ class ARESdevice():
|
||||
|
||||
#--- 2-theta devices ---
|
||||
qp.setTransform(tf2Th)
|
||||
qp.setPen(QPen(QtCore.Qt.green, tickW, QtCore.Qt.SolidLine))
|
||||
qp.setPen(QPen(Qt.green, tickW, Qt.SolidLine))
|
||||
qp.drawLine(0,-r2Th,0,-r2Th+tickL) #tick
|
||||
qp.setPen(penBk)
|
||||
qp.setBrush(QColor(0,255,0,192))
|
||||
@@ -410,7 +350,7 @@ class ARESdevice():
|
||||
|
||||
#--- Jungfrau devices ---
|
||||
qp.setTransform(tfJFr)
|
||||
qp.setPen(QPen(QtCore.Qt.magenta, tickW, QtCore.Qt.SolidLine))
|
||||
qp.setPen(QPen(Qt.magenta, tickW, Qt.SolidLine))
|
||||
qp.drawLine(0,-rJFr,0,-rJFr+tickL) #tick
|
||||
qp.setPen(penBk)
|
||||
qp.setBrush(QColor(255,0,255,192))
|
||||
@@ -420,7 +360,7 @@ class ARESdevice():
|
||||
|
||||
#--- detector devices ---
|
||||
qp.setTransform(tfDet)
|
||||
qp.setPen(QPen(QtCore.Qt.blue, tickW, QtCore.Qt.SolidLine))
|
||||
qp.setPen(QPen(Qt.blue, tickW, Qt.SolidLine))
|
||||
qp.drawLine(0,-rDet,0,-rDet+tickL) #tick
|
||||
qp.setPen(penBk)
|
||||
qp.setBrush(QColor(0,0,255,192))
|
||||
@@ -432,7 +372,7 @@ class ARESdevice():
|
||||
|
||||
#--- target devices ---
|
||||
qp.setTransform(tfTrg)
|
||||
qp.setPen(QPen(QtCore.Qt.cyan, tickW, QtCore.Qt.SolidLine))
|
||||
qp.setPen(QPen(Qt.cyan, tickW, Qt.SolidLine))
|
||||
qp.drawLine(0,-rTrg,0,-rTrg+tickL) #tick
|
||||
qp.setPen(penBk)
|
||||
qp.setBrush(QColor(0,255,255,192))
|
||||
@@ -463,31 +403,6 @@ class ARESdevice():
|
||||
qp.drawLine(int(rArm),int(a) ,int(-a/2),int(a ))
|
||||
|
||||
|
||||
|
||||
#qp.setPen(penBk)
|
||||
#qp.drawRect(-10, -10+rArm, 20, 20)
|
||||
#self.plotOrig(qp)
|
||||
#qp.setTransform(tf2Th)
|
||||
#qp.setPen(penYl)
|
||||
#qp.drawRect(-10, -10+r2Th, 20, 20)
|
||||
#self.plotOrig(qp)
|
||||
#qp.setTransform(tfDet)
|
||||
#qp.setPen(penBl)
|
||||
#qp.drawRect(-10, -10+r2Th+20, 20, 20)
|
||||
#qp.setTransform(tfTrg)
|
||||
#qp.setPen(penBl)
|
||||
#qp.drawRect(-10, -10+r2Th+20, 20, 20)
|
||||
#self.plotOrig(qp)
|
||||
#qp.setCompositionMode(QtGui.QPainter.CompositionMode_Lighten)
|
||||
#qp.setCompositionMode(QtGui.QPainter.CompositionMode_SourceOver)
|
||||
#mouse move polygon
|
||||
#qp.setTransform(QTransform())
|
||||
#qp.setPen(penRd)
|
||||
#qp.drawPolygon(self._polygon)
|
||||
#origin crosses
|
||||
#for tf in (tf0,tfa,tfab,tfc):#,tfg,tfs):#,tfc,tfs):
|
||||
# qp.setTransform(tf);self.plotOrig(qp)
|
||||
|
||||
class WndVisualize(QWidget):
|
||||
_pv2key={
|
||||
'SATES30-RIXS:MOT_RY.RBV' :'aArm',
|
||||
@@ -526,7 +441,7 @@ class WndVisualize(QWidget):
|
||||
|
||||
wLb=QLabel(f"<font>{key}</font>",objectName=key) #MOST BE with <font> as it is changed later and else creates a seg fault
|
||||
|
||||
wSl=QSlider(QtCore.Qt.Horizontal,objectName=key)
|
||||
wSl=QSlider(Qt.Horizontal,objectName=key)
|
||||
wSl.setFixedWidth(200);wSl.setMinimum(rng[0]);wSl.setMaximum(rng[1])
|
||||
if key.startswith('scl'):
|
||||
if key[-1]=='A':
|
||||
@@ -545,9 +460,17 @@ class WndVisualize(QWidget):
|
||||
lg.addWidget(wLb, row, 0)
|
||||
lg.addWidget(wSl, row, 1);row+=1
|
||||
|
||||
w=QPushButton('sync motors')
|
||||
w.clicked.connect(self.btnSyncMotors)
|
||||
lg.addWidget(w, row, 1)
|
||||
#self.event_update.connect(self.cb_update)
|
||||
self.show()
|
||||
|
||||
def btnSyncMotors(self):
|
||||
# reads the epics motor and updates the vizualization
|
||||
_log.info('')
|
||||
self.liveView()
|
||||
|
||||
def cb_update(self,*args,**kwargs):
|
||||
_log.debug(f'{args} {kwargs}')
|
||||
|
||||
@@ -643,7 +566,6 @@ class WndVisualize(QWidget):
|
||||
print (pvn,key)
|
||||
pass
|
||||
|
||||
|
||||
def destroy(self, destroyWindow, destroySubWindows): #overloaded function
|
||||
_log.info('destroy')
|
||||
|
||||
@@ -689,34 +611,18 @@ class WndVisualize(QWidget):
|
||||
def mousePressEvent(self, a0):
|
||||
app=QApplication.instance()
|
||||
mousePos=a0.pos()
|
||||
print(a0.type)
|
||||
if a0.type()!=QtGui.QMouseEvent.MouseButtonPress:
|
||||
#print(a0.type)
|
||||
if a0.type()!=QMouseEvent.MouseButtonPress:
|
||||
return
|
||||
wGrp=self._wdGrpDraw
|
||||
#if wGrp.underMouse(): #draging sliders?
|
||||
if wGrp.geometry().contains(mousePos):
|
||||
self.liveView()
|
||||
self._mouseDrag={'obj':wGrp, 'start':mousePos}
|
||||
return
|
||||
#if wGrp.geometry().contains(mousePos):
|
||||
# self.liveView()
|
||||
# self._mouseDrag={'obj':wGrp, 'start':mousePos}
|
||||
# return
|
||||
dev=app._dev
|
||||
if dev.containsPoint(mousePos):
|
||||
self._devSel=dev
|
||||
#wGrp=self._wdGrpDraw
|
||||
#wGrp.setTitle(dev._name)
|
||||
#devP=dev._paint
|
||||
#for wSl in wGrp.findChildren(QSlider):
|
||||
# #_log.info(wSl)
|
||||
# key=wSl.objectName()
|
||||
# if key.startswith('scl'):
|
||||
# if key[-1]=='A':
|
||||
# v=devP['sclTrf'][0]
|
||||
# else:
|
||||
# v=devP['sclTrf'][1]
|
||||
# v=int(round(np.log2(v)*2))
|
||||
# else:
|
||||
# v=devP[key]
|
||||
# wSl.setValue(int(v))
|
||||
|
||||
self._mouseDrag={'obj':dev,'start':(mousePos,dev._paint['ofs'])}
|
||||
try:
|
||||
_log.info(f'{self._mouseDrag}')
|
||||
@@ -800,4 +706,4 @@ if __name__ == '__main__':
|
||||
wnd.show()
|
||||
sys.exit(app.exec_())
|
||||
|
||||
main()
|
||||
main()
|
||||
|
||||
3
Makefile
3
Makefile
@@ -18,7 +18,8 @@ install:
|
||||
@echo "- /EsfRixsApps/.git/\n- /EsfRixsApps/scratch/\n- /**/__pycache__/\n- /**.ipynb*" >/tmp/rsync.filt
|
||||
@cat /tmp/rsync.filt
|
||||
rsync -vai --filter='. /tmp/rsync.filt' $(SRC) $(REMOTE):$(APP)
|
||||
-ssh $(REMOTE) 'for A in ARESvis RIXSconfig spectrumProc; do ln -sF $(APP)/EsfRixsApps/$$A/$$A.py $(BIN)/$$A;done'
|
||||
-ssh $(REMOTE) 'for A in ARESvis RIXSconfig spectrumProc; do $(APP)/EsfRixsApps/AppTemplate.py -b /sf/furka -a $$A -p EsfRixsApps ;done'
|
||||
# -ssh $(REMOTE) 'for A in ARESvis RIXSconfig spectrumProc; do ln -sF $(APP)/EsfRixsApps/$$A/$$A.py $(BIN)/$$A;done'
|
||||
|
||||
|
||||
# @echo MODULE $(MODULE)
|
||||
|
||||
Reference in New Issue
Block a user