Commit e04b3f39 authored by operator ID01's avatar operator ID01
Browse files

dump nano3 updates

parent eb5b85f9
......@@ -2,6 +2,7 @@
#----------------------------------------------------------------------
# Description:
# Author: Carsten Richter <carsten.richter@esrf.fr>
# Modified by: Steven Leake
# Created at: Sa 6. Mai 16:04:24 CEST 2017
# Computer: lid01gpu1.
# System: Linux 3.16.0-4-amd64 on x86_64
......@@ -51,7 +52,7 @@ _use_console = _use_console and PV.startswith("3.")
import silx
print("Using silx %s"%silx.version)
from silx.gui import plot
from silx.gui import plot, qt
from silx.gui.plot import PlotActions
import silx.gui.icons
from silx.image import sift
......@@ -87,6 +88,7 @@ _hints["AutoFocus"] = ('Use ROI sharpness and optimization of a motor position '
'to focus the image.')
_hints["selectPOI"] = 'Select Point of Interest (POI)'
_hints["Navg"] = 'Number of subsequent camera images to average'
_hints["Refresh"] = 'refresh time of live plot window'
_hints["enhance"] = 'Strech contrast of the camera image'
_hints["saveit"] = 'Save the new image to the current directory'
......@@ -149,7 +151,9 @@ class CamPlot(plot.PlotWindow):
self.toolBar().addAction(clearpoints)
self._clearpoints = clearpoints
#self.timer=qt.QTimer()
#self.timer.timeout.connect(self._queryupdateImage)
#self.timer.start(100)
#r = self.getDataRange()
#self.setGraphXLimits(r[0][0], r[0][1])
#self.setGraphYLimits(r[1][0], r[1][1])
......@@ -157,6 +161,7 @@ class CamPlot(plot.PlotWindow):
#self.profile = plot.Profile.ProfileToolBar(plot=self)
#self.addToolBar(self.profile)
def update_roi(self, event):
# if "button" in event and event["button"] == "right":
# self.remove("roi")
......@@ -184,10 +189,11 @@ class CamPlot(plot.PlotWindow):
self.addCurve(x, y, resetzoom=False, legend="roi", color="r")
def update_poi(self, event):
self.poi = poi = event["x"], event["y"]
m = self.addMarker(poi[0], poi[1], symbol="o",
legend="poi", color=(.3,1.,1.,1.), text="POI")
def update_poi(self, event,name):
print(name)
exec("self.%s = %s = event[\"x\"], event[\"y\"]"%(name,name))
m = "m = self.addMarker(%s[0], %s[1], symbol=\"o\", legend=\"%s\", color=(.3,1.,1.,1.), text=\"%s\")"%(name,name,name,name)
exec(m)
#m = self._getItem("marker", m)
#print(m.getSymbolSize())
#m.setSymbolSize(1)
......@@ -239,6 +245,7 @@ class ControlWidget(Q.QWidget):
hbox = Q.QHBoxLayout()
url = _reg(Q.QLineEdit(_default_url), "url")
enhance = Q.QCheckBox('enhance', self)
enhance.setStatusTip(_hints['enhance'])
enhance = _reg(enhance, "enhanced")
......@@ -248,7 +255,7 @@ class ControlWidget(Q.QWidget):
saveit = _reg(saveit, "saveit")
Navg = Q.QLineEdit("1")
Navg = Q.QLineEdit("10")
Navg.setValidator(_valid[int])
Navg.setStatusTip(_hints['Navg'])
Navg.setMaxLength(3)
......@@ -257,10 +264,25 @@ class ControlWidget(Q.QWidget):
hbox.addWidget(Q.QLabel("URL"))
hbox.addWidget(url)
hbox.addSpacing(5)
hbox.addWidget(Q.QLabel("Navg"))
#hbox.addSpacing(5)
form.layout.addRow(hbox)
hbox = Q.QHBoxLayout()
hbox.addWidget(Q.QLabel("No. exps to avg"))
hbox.addWidget(Navg)
hbox.addSpacing(5)
refresh = Q.QLineEdit("1")
refresh.setValidator(_valid[float])
refresh.setStatusTip(_hints['Refresh'])
refresh.setMaxLength(3)
refresh.setFixedWidth(25)
refresh = _reg(refresh, "Refresh")
hbox.addWidget(Q.QLabel("Refresh Rate (secs)"))
hbox.addWidget(refresh)
hbox.addSpacing(5)
hbox.addWidget(enhance)
hbox.addWidget(saveit)
form.layout.addRow(hbox)
......@@ -272,6 +294,81 @@ class ControlWidget(Q.QWidget):
btn.setStatusTip(_hints[name])
hbox.addWidget(btn)
form.layout.addRow(hbox)
"""
hbox = Q.QHBoxLayout()
CORx = Q.QLineEdit("0")
CORx.setValidator(_valid[int])
#CORx.setStatusTip(_hints['COR'])
CORx.setMaxLength(3)
CORx.setFixedWidth(25)
CORx.textChanged[str].connect(self.onChangedCORx)
CORx = _reg(CORx, "COR(x)")
hbox.addWidget(Q.QLabel("COR x:"))
hbox.addWidget(CORx)
hbox.addSpacing(5)
CORy = Q.QLineEdit("0")
CORy.setValidator(_valid[int])
#CORy.setStatusTip(_hints['COR'])
CORy.setMaxLength(3)
CORy.setFixedWidth(25)
CORy.textChanged[str].connect(self.onChangedCORy)
CORy = _reg(CORy, "COR(y)")
hbox.addWidget(Q.QLabel("y:"))
hbox.addWidget(CORy)
hbox.addSpacing(5)
POI0x = Q.QLineEdit("0")
POI0x.setValidator(_valid[int])
#POI0x.setStatusTip(_hints['POI'])
POI0x.setMaxLength(3)
POI0x.setFixedWidth(25)
POI0x.textChanged[str].connect(self.onChangedPOI0x)
POI0x = _reg(POI0x, "POI0(x)")
hbox.addWidget(Q.QLabel("POI0 x:"))
hbox.addWidget(POI0x)
hbox.addSpacing(5)
POI0y = Q.QLineEdit("0")
POI0y.setValidator(_valid[int])
#POI0y.setStatusTip(_hints['POI'])
POI0y.setMaxLength(3)
POI0y.setFixedWidth(25)
POI0y.textChanged[str].connect(self.onChangedPOI0y)
POI0y = _reg(POI0y, "POI0(y)")
hbox.addWidget(Q.QLabel("y:"))
hbox.addWidget(POI0y)
hbox.addSpacing(5)
POI1x = Q.QLineEdit("0")
POI1x.setValidator(_valid[int])
#POI1x.setStatusTip(_hints['POI1'])
POI1x.setMaxLength(3)
POI1x.setFixedWidth(25)
POI1x.textChanged[str].connect(self.onChangedPOI1x)
POI1x = _reg(POI1x, "POI1(x)")
hbox.addWidget(Q.QLabel("POI1 x:"))
hbox.addWidget(POI1x)
hbox.addSpacing(5)
POI1y = Q.QLineEdit("0")
POI1y.setValidator(_valid[int])
#POI1y.setStatusTip(_hints['POI1'])
POI1y.setMaxLength(3)
POI1y.setFixedWidth(25)
POI1y.textChanged[str].connect(self.onChangedPOI1y)
POI1y = _reg(POI1y, "POI1(y)")
hbox.addWidget(Q.QLabel("y:"))
hbox.addWidget(POI1y)
hbox.addSpacing(5)
form.layout.addRow(hbox)
"""
form.layout.addRow(_reg(Q.QTextEdit(""), "output"))
self.Input["output"].setReadOnly(True)
......@@ -281,7 +378,7 @@ class ControlWidget(Q.QWidget):
splitter.addWidget(form)
"""
if _use_console:
banner = "Inspect/Modify `MainWindow` App instance."
ipython = console.IPythonWidget(self)#, custom_banner=banner)
......@@ -296,7 +393,7 @@ class ControlWidget(Q.QWidget):
splitter.addWidget(ipython)
else:
splitter.addWidget(Q.QPushButton("Dummy"))
"""
splitter.setSizes([500,500])
self.setLayout(layout)
......@@ -310,9 +407,25 @@ class ControlWidget(Q.QWidget):
QtObject.resize(QtObject.minimumSizeHint())
return QtObject
def onChangedCORx(self, text):
self.CORx=text
#self.update_poi()
def onChangedCORy(self, text):
self.CORx=text
def onChangedPOI0x(self, text):
self.POI0x=text
def onChangedPOI0y(self, text):
self.POI0y=text
def onChangedPOI1x(self, text):
self.POI1x=text
def onChangedPOI1y(self, text):
self.POI1y=text
def update_poi(self, event,name):
print("TODO: not implemented")
#print(name)
#m = self.addMarker(%s[0], %s[1], symbol="o", legend="%s", color=(.3,1.,1.,1.), text="%s")
#exec(m)
class Window(Q.QMainWindow):
_ignoreEvent = False
......@@ -364,25 +477,32 @@ class Window(Q.QMainWindow):
self.plotLeft = pleft = CamPlot(data, "Latest", cw)
self.plotRight = pright = CamPlot(data, "Previous", cw)
g.addWidget(pleft, 0,0)
g.addWidget(pright, 0,1)
g.addWidget(pleft, 1,0)
g.addWidget(pright, 1,1)
self.plotLive = plive = CamPlot(data, "Live", cw)
g.addWidget(plive, 0,0)
crosshair = CrosshairAction(pleft, color="b")
crosshair.setToolTip(_hints["selectPOI"])
pleft.toolBar().addAction(crosshair)
pleft.crosshair = crosshair
crosshair1 = CrosshairAction(plive, color="b")
crosshair1.setToolTip(_hints["selectPOI"])
plive.toolBar().addAction(crosshair1)
plive.crosshair = crosshair1
pleft.setCallback( lambda event: self.handle_event(event, "l"))
pright.setCallback(lambda event: self.handle_event(event, "r"))
plive.setCallback(lambda event: self.handle_event(event, "live"))
pleft.setInteractiveMode("draw", shape="rectangle"
, color=(1.,1.,0.,0.8))
for p in (pleft, pright):
for p in (pleft, pright, plive):
p._defaultMode = p.getInteractiveMode()
self.control = control = ControlWidget(cw)
g.addWidget(control, 1, 0, 1, 2)
g.addWidget(control, 0, 1, 1, 1)
# control.adjustSize()
# Connect:
......@@ -394,12 +514,57 @@ class Window(Q.QMainWindow):
#self.plotLeft.resetZoom() #doesn't work
self.show()
self.refresh=1
self.POI0x,self.POI0y = 0,0
self.POI1x,self.POI1y = 0,0
self.CORx,self.CORy = 0,0
self.timer=qt.QTimer()
self.timer.timeout.connect(self._queryupdateImage)
self.timer.start(self.refresh*1000)
def _queryupdateImage(self,):
#if self.pollContinuous:
self._updateImage()
def _updateImage(self,):
self.timer.setInterval(self.refresh*1000)
self.refresh = float(self.control.Input["Refresh"].text())#.toAscii()
#self.echo("aaah: %i"%self.refresh)
#iso_time = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime())
url = self.control.Input["url"].text()#.toAscii()
url = str(url)
Navg = int(self.control.Input["Navg"].text())#.toAscii()
if Navg < 1:
#self.echo("Error: need Navg > 0")
return
Ntext = "once" if Navg is 1 else "%i times"%Navg
#self.echo("Exposure - %s"%iso_time)
#self.echo("Fetching %s %s..."%(url, Ntext))
try:
img = image.url2array(url, Navg)
#self.echo("Image shape: (%i, %i)"%img.shape)
except Exception as emsg:
#self.echo("...failed: %s"%emsg)
return
do_enhance = self.control.Input["enhanced"].checkState()
if do_enhance:
img = image.stretch_contrast(img)
imLive = self.plotLive.getImage()
imLive.setData(img)
#self.plotLeft.resetZoom()
def handle_event(self, event, side):
if event["event"] is "drawingFinished":
#print(event["xdata"], event["ydata"])
for p in [self.plotLeft, self.plotRight]:
for p in [self.plotLeft, self.plotRight, self.plotLive]:
p.update_roi(event)
elif event["event"]=="limitsChanged" \
......@@ -411,12 +576,19 @@ class Window(Q.QMainWindow):
self.plotRight.setLimits(*(event["xdata"]+event["ydata"]))
elif side is "r":
self.plotLeft.setLimits(*(event["xdata"]+event["ydata"]))
elif side is "live":
self.plotLive.setLimits(*(event["xdata"]+event["ydata"]))
self._ignoreEvent = False
elif event["event"] is "mouseClicked" and side is "l":
if event["button"] is "left" and \
not self.plotLeft.getGraphCursor() is None:
for p in [self.plotLeft, self.plotRight]:
p.update_poi(event)
for p in [self.plotLeft, self.plotRight,self.plotLive]:
p.update_poi(event,"poi0")
elif event["event"] is "mouseClicked" and side is "live":
if event["button"] is "left" and \
not self.plotLive.getGraphCursor() is None:
for p in [self.plotLeft, self.plotRight,self.plotLive]:
p.update_poi(event,"poi1")
# if event["button"] is "right":
# for p in [self.plotLeft, self.plotRight]:
# p.update_roi(event)
......@@ -527,6 +699,7 @@ class Window(Q.QMainWindow):
color=(1.,.3,.3,1.), text="COR")
self.plotLeft.addMarker(cor[0], cor[1], **plotcfg)
self.plotRight.addMarker(cor[0], cor[1], **plotcfg)
self.plotLive.addMarker(cor[0], cor[1], **plotcfg)
def calc_sharpness(self):
......@@ -846,4 +1019,4 @@ def run():
#app.exec_()
if __name__=="__main__":
run()
\ No newline at end of file
run()
#!/usr/bin/env blissrc
#!/usr/bin/env python
# print a PyTango device parameter every X seconds
# in this case the thermocouple on under the sample
......@@ -8,6 +8,9 @@ import sys
DeviceProxy("id01/eurotherm2400/012eh1")
tango_test = DeviceProxy("id01/eurotherm2400/012eh1")
DeviceProxy("id01/eurotherm2400/012eh1")
tango_test = DeviceProxy("id01/eurotherm2400/012eh1")
import time
t=float(sys.argv[1])
......@@ -15,4 +18,4 @@ print("time per point: %.2f seconds"%t)
while True:
print(tango_test.read_attribute("temperature").value)
time.sleep(1)
time.sleep(t)
......@@ -2,9 +2,8 @@
#!/users/blissadm/bin blissrc
# -*- coding: utf-8 -*-
"""
Created on Dec 1 21:02:27 2018
Created on Oct 5 13:10 2020
sending mail upon device server response
@author: opid01 - S.Leake
TODO:
......@@ -14,9 +13,12 @@ TODO:
#
# Warning system for tango device servers
#
# in a linux terminal export TANGO_HOST=orion:10000
# and use 'jive' to find available devices
# for machine related parameters
# use 'jive' to find available devices
# in jive use acs:10000
#
# for ID01 related parameters
# in jive use nano1:20000
########################################################################
from PyTango import DeviceProxy
......@@ -25,8 +27,25 @@ import numpy as np
import sys
import pdb
import pygame
import os
## ALARM for LN2 pressure
email = sys.argv[1]
print("Sending test email to %s"%sys.argv[1])
os.system('echo `date` | mail -s " The next email you receive will mean your macro failed :O) " %s'%email)
##########################
##########################
## reference params to test against
##########################
##########################
increment_time=1 # sleep time between datapoints
##########################
## LN2 pressure
##########################
dev1 = DeviceProxy('id01/wcid01cryo1/tg')
......@@ -34,23 +53,30 @@ moving_avg = dict()
ref_vals = dict()
ref_vals["cryo_p1"] = 6.98 #7.30 #6.95
ref_vals["cryo_p2"] = 7.5 #7.82 #7.51
ref_vals["cryo_p3"] = 7.63 #7.96 #7.68
ref_vals["cryo_p1"] = 6.67 #7.30 #6.95
ref_vals["cryo_p2"] = 7.53 #7.82 #7.51
ref_vals["cryo_p3"] = 7.61 #7.96 #7.68
pts_moving_avg=10
increment_time=0.8
for key in ref_vals:
moving_avg[key] = np.zeros(pts_moving_avg)
## ALARM for synchrotron current
##########################
## synchrotron current
##########################
dev2=DeviceProxy('//orion:10000/fe/id/1')
#dev2=DeviceProxy('//orion:10000/fe/id/1')
dev2=DeviceProxy('//acs:10000/fe/master/id01')
ref_vals["SR_Current"] = 170.0
##########################
## functions
##########################
## Check vacuum valves
def check_vac_valves():
valves = []
......@@ -78,6 +104,7 @@ try:
dev5=DeviceProxy('id01/limaccd/mpx_1x4')
toggle_det="mpx4"
except:
toggle_det="None"
print("Maxipix not switched on")
"""
try:
......@@ -115,7 +142,9 @@ attempt_reopen=0
while True:
time.sleep(increment_time)
sys.stdout.write('.')
##########################
# LN2 pressure
##########################
for key in ["cryo_p1","cryo_p2","cryo_p3"]:
moving_avg[key]=np.roll(moving_avg[key],-1,0)
moving_avg[key][-1]=dev1.read_attribute(key).value
......@@ -126,8 +155,12 @@ while True:
pygame.mixer.music.play()
#audible_alert(audible_alert_toggle,"/users/opid01/Documents/python/id01sware/cymbal.wav")
sys.stdout.write('\n\x1b[1;37;41m %s \x1b[0m'%"*** WARNING: LIQUID NITROGEN DCM PRESSURE FLUCTUATION (%s:%.3f(ref:%.3f)) ***"%(key,moving_avg[key][-1],ref_vals[key]))
os.system('echo `date` | mail -s " OH DEAR - LN2 pressure warning - check the beamline " %s'%email)
##########################
# SrCur
##########################
for key in ["SR_Current"]:
moving_avg[key]=np.roll(moving_avg[key],-1,0)
moving_avg[key][-1]=dev2.read_attribute(key).value
......@@ -151,8 +184,11 @@ while True:
pygame.mixer.music.play()
sys.stdout.write('\n\x1b[1;32;42m %s \x1b[0m'%"*** WARNING: THERE IS HOPE... SYNCHROTRON IS REFILLING (%s:%.3f(ref:%.3f)) ***"%(key,moving_avg[key][-1],ref_vals[key]))
toggle=False
##########################
# Vacuum Valves
##########################
#tested 20201005
#pdb.set_trace()
valves_closed=check_vac_valves()
......@@ -164,28 +200,37 @@ while True:
pygame.mixer.music.play()
#audible_alert(audible_alert_toggle,"/users/opid01/Documents/python/id01sware/cymbal.wav")
sys.stdout.write('\n\x1b[1;36;46m %s \x1b[0m'%"*** WARNING: Beryllium Valve closed ***")
os.system('echo `date` | mail -s " OH DEAR - Beryllium Valve closed " %s'%email)
attempt_reopen = 0
else:
pygame.mixer.init()
pygame.mixer.music.load("/users/opid01/Documents/python/id01sware/cymbal.wav")
pygame.mixer.music.play()
#audible_alert(audible_alert_toggle,"/users/opid01/Documents/python/id01sware/cymbal.wav")
sys.stdout.write('\n\x1b[1;36;46m %s \x1b[0m'%"*** WARNING: Vacuum valves %s closed ***"%str(valves_closed))
attempt_repoen=0
os.system('echo `date` | mail -s " OH DEAR - Vacuum valves have closed " %s'%email)
attempt_reopen=1
except:
pass
# try to autoreopen the penning gauge /vacuum valves in case of a spike
if len(valves_closed)>0 and attempt_reopen<6:
# try to autoreopen the penning gauge /vacuum valves in case of a spike
if len(valves_closed)>0 and attempt_reopen>0:
gauges2turnon = check_penning_gauge()
for _i in gauges2turnon:
dev3=DeviceProxy('//id01/v-balzpen/%s'%_i)
try:
dev3.On()
gauges2turnon.remove(_i)
sys.stdout.write('\n\x1b[1;36;46m %s \x1b[0m'%"*** WARNING: Opening Penning gauge %s ***"%str(_i))
except:
print("Failed to restart penning gauge %i\n"%_i)
attempt_reopen+=1
elif attempt_reopen>=6:
print("major vacuum problem")
os.system('echo `date` | mail -s " OH DEAR - major vacuum problem " %s'%email)
sys.exit()
valves_closed=check_vac_valves()
......@@ -195,24 +240,47 @@ while True:
dev3=DeviceProxy('//id01/v-rv/%s'%_i)
try:
dev3.open()
sys.stdout.write('\n\x1b[1;36;46m %s \x1b[0m'%"*** WARNING: Opening vacuum valve %s ***"%str(_i))
except:
print("Failed to open vac valve %i\n"%_i)
attempt_reopen+=1
elif attempt_reopen>=6:
print("major vacuum problem")
os.system('echo `date` | mail -s " OH DEAR - major vacuum problem " %s'%email)
sys.exit()
##########################
# Front End #tested 20201005
##########################
if dev2.read_attribute("FE_state").value!="FE open":
pygame.mixer.init()
pygame.mixer.music.load("/users/opid01/Documents/python/id01sware/cymbal.wav")
pygame.mixer.music.play()
sys.stdout.write('\n\x1b[1;33;43m %s \x1b[0m'%"*** WARNING: Front End closed ***")
os.system('echo `date` | mail -s " OH DEAR - Front End Closed " %s'%email)
try:
dev2.open()
time.sleep(10)
if dev2.read_attribute("FE_state").value=="FE open":
sys.stdout.write('\n\x1b[1;33;43m %s \x1b[0m'%"*** WARNING: reopen complete ***")
os.system('echo `date` | mail -s " OH DEAR - Front end is open" %s'%email)
except:
sys.stdout.write('\n\x1b[1;33;43m %s \x1b[0m'%"*** WARNING: failed to reopen ***")
os.system('echo `date` | mail -s " OH DEAR - failed to reopen front end " %s'%email)
# Safety shutter
# check PSS i.e all interlocked
if toggle_det == "mpx4":
if dev4.read_attribute("state").value!=3 and dev5.read_attribute("acq_status").value=="Running" :
if dev4.read_attribute("state").value!=3 and dev5.read_attribute("acq_status").value=="Running" : # note OPEN=3
pygame.mixer.init()
pygame.mixer.music.load("/users/opid01/Documents/python/id01sware/cymbal.wav")
pygame.mixer.music.play()
#audible_alert(audible_alert_toggle,"/users/opid01/Documents/python/id01sware/fail.wav")
sys.stdout.write('\n\x1b[1;33;43m %s \x1b[0m'%"*** WARNING: Safety Shutter closed ***")
os.system('echo `date` | mail -s " OH DEAR - Safety Shutter closed" %s'%email)
"""
elif toggle_det== "eiger2M":
if dev4.read_attribute("state").value!=3 and dev6.read_attribute("acq_status").value=="Running":
......@@ -224,13 +292,6 @@ while True:
"""
# Front End
if dev2.read_attribute("FE_state").value!="FE open":
pygame.mixer.init()
pygame.mixer.music.load("/users/opid01/Documents/python/id01sware/cymbal.wav")
pygame.mixer.music.play()
sys.stdout.write('\n\x1b[1;33;43m %s \x1b[0m'%"*** WARNING: Front End closed ***")
_ii+=1
sys.stdout.flush()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 1 21:02:27 2018
sending mail upon device server response
@author: opid01 - S.Leake
TODO:
"""
########################################################################
#
# Warning system for tango device servers
#
# in a linux terminal export TANGO_HOST=orion:10000
# and use 'jive' to find available devices
#
########################################################################