This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#Thu Jan 09 10:48:13 CET 2020
|
||||
#Mon Jan 13 15:27:01 CET 2020
|
||||
imageSourcesFile={config}/imaging.properties
|
||||
autoSaveScanData=true
|
||||
simulation=false
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#Thu Jan 09 10:48:32 CET 2020
|
||||
FileSequentialNumber=33
|
||||
#Tue Jan 14 17:13:08 CET 2020
|
||||
FileSequentialNumber=86
|
||||
|
||||
20
devices/0000.tif.properties
Normal file
20
devices/0000.tif.properties
Normal file
@@ -0,0 +1,20 @@
|
||||
#Mon Jan 13 16:29:44 CET 2020
|
||||
spatialCalOffsetY=NaN
|
||||
invert=false
|
||||
spatialCalOffsetX=NaN
|
||||
rotation=0.0
|
||||
rotationCrop=false
|
||||
scale=1.0
|
||||
rescaleFactor=1.0
|
||||
grayscale=false
|
||||
spatialCalUnits=mm
|
||||
flipVertically=false
|
||||
roiHeight=-1
|
||||
spatialCalScaleX=NaN
|
||||
spatialCalScaleY=NaN
|
||||
flipHorizontally=false
|
||||
roiY=0
|
||||
roiX=0
|
||||
rescaleOffset=0.0
|
||||
transpose=false
|
||||
roiWidth=-1
|
||||
20
devices/1_2_0002.tif.properties
Normal file
20
devices/1_2_0002.tif.properties
Normal file
@@ -0,0 +1,20 @@
|
||||
#Mon Jan 13 16:29:53 CET 2020
|
||||
spatialCalOffsetY=NaN
|
||||
invert=false
|
||||
spatialCalOffsetX=NaN
|
||||
rotation=0.0
|
||||
rotationCrop=false
|
||||
scale=1.0
|
||||
rescaleFactor=1.0
|
||||
grayscale=false
|
||||
spatialCalUnits=mm
|
||||
flipVertically=false
|
||||
roiHeight=-1
|
||||
spatialCalScaleX=NaN
|
||||
spatialCalScaleY=NaN
|
||||
flipHorizontally=false
|
||||
roiY=0
|
||||
roiX=0
|
||||
rescaleOffset=0.0
|
||||
transpose=false
|
||||
roiWidth=-1
|
||||
@@ -1,22 +1,22 @@
|
||||
#Thu Oct 31 10:40:48 CET 2019
|
||||
#Mon Jan 13 16:25:54 CET 2020
|
||||
colormapLogarithmic=false
|
||||
spatialCalScaleX=NaN
|
||||
spatialCalScaleY=NaN
|
||||
rescaleOffset=0.0
|
||||
roiWidth=-1
|
||||
colormap=Grayscale
|
||||
colormap=Flame
|
||||
invert=false
|
||||
colormapMin=NaN
|
||||
colormapMin=2.906652671323E9
|
||||
rotationCrop=false
|
||||
roiHeight=-1
|
||||
colormapAutomatic=true
|
||||
colormapAutomatic=false
|
||||
roiY=0
|
||||
roiX=0
|
||||
spatialCalOffsetY=NaN
|
||||
spatialCalOffsetX=NaN
|
||||
scale=1.0
|
||||
grayscale=false
|
||||
colormapMax=NaN
|
||||
colormapMax=3.808717293458E9
|
||||
rotation=0.0
|
||||
rescaleFactor=1.0
|
||||
spatialCalUnits=null
|
||||
|
||||
10
script/devices/chopper.py
Normal file
10
script/devices/chopper.py
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
def put_chopper(v):
|
||||
#0 : "closed"
|
||||
#1 : "opened"
|
||||
caput("X11MA-ES1-CHOPP:TRG",1 if v else 0)
|
||||
|
||||
def get_chopper():
|
||||
#0 : "closed"
|
||||
#1 : "opened"
|
||||
return True if caget("X11MA-ES1-CHOPP:TRG") else False
|
||||
@@ -1,95 +1,167 @@
|
||||
from ijutils import *
|
||||
from ch.psi.pshell.imaging.Overlays import *
|
||||
from ch.psi.pshell.imaging.Utils import *
|
||||
import ch.psi.pshell.imaging.Pen as Pen
|
||||
import java.awt.Rectangle as Rectangle
|
||||
import ch.psi.pshell.imaging.Data as Data
|
||||
|
||||
|
||||
###############################################################################
|
||||
# ROI Integration
|
||||
###############################################################################
|
||||
|
||||
def integrate_roi(source, x,y, w, h):
|
||||
if source.data is None:
|
||||
source.update()
|
||||
roi = source.data.getRoi(Rectangle(x,y, w, h))
|
||||
return roi.integrate(False)
|
||||
|
||||
|
||||
|
||||
class RoiIntensity(ReadonlyRegisterBase):
|
||||
def __init__(self, name, source, x,y, w, h):
|
||||
ReadonlyRegisterBase.__init__(self, name)
|
||||
self.source=source
|
||||
self.roi = x,y, w, h
|
||||
|
||||
def doRead(self):
|
||||
x,y, w, h = self.roi
|
||||
return integrate_roi(self.source, x,y, w, h)
|
||||
|
||||
def create_roi_devices(roi_list, add = True):
|
||||
rois = []
|
||||
for r in roi_list:
|
||||
roi = RoiIntensity(r, image, roi_list[r][0], roi_list[r][1], roi_list[r][2], roi_list[r][3])
|
||||
if add:
|
||||
add_device(roi, True)
|
||||
rois.append(roi)
|
||||
return rois
|
||||
|
||||
###############################################################################
|
||||
# Frame integration
|
||||
###############################################################################
|
||||
|
||||
def get_image(source, roi=None, wait_next=False):
|
||||
if wait_next:
|
||||
source.waitNext(-1)
|
||||
ret = load_image(Utils.grayscale(source.output, Rectangle(roi[0], roi[1], roi[2], roi[3]) if (roi is not None) else None))
|
||||
return ret
|
||||
|
||||
def grab_frames(source, samples, roi=None, wait_next=False, sleep=0):
|
||||
frames = []
|
||||
for i in range(samples):
|
||||
if sleep>0:
|
||||
time.sleep(sleep)
|
||||
aux = get_image(source, roi, wait_next)
|
||||
frames.append(aux)
|
||||
return frames
|
||||
|
||||
def average_frames(source, samples=1, roi=None, wait_next=False, sleep=0, as_float=True):
|
||||
return average_ips(grab_frames(source, samples, roi, wait_next, sleep), as_float)
|
||||
|
||||
def integrate_frames(source, samples=1, roi=None, wait_next=False, sleep=0, as_float=True):
|
||||
return integrate_ips(grab_frames(sotscanurce, samples, roi, wait_next, sleep), as_float)
|
||||
|
||||
|
||||
if False:
|
||||
integrate_roi(image, 10, 5, 20, 10)
|
||||
|
||||
add_device(RoiIntensity("Region1", image, 10, 5, 20, 10), True)
|
||||
add_device(RoiIntensity("Region2", image, 10, 5, 40, 20), True)
|
||||
|
||||
|
||||
import ch.psi.pshell.data.ProviderCSV as ProviderCSV
|
||||
ProviderCSV.setDefaultItemSeparator(" ")
|
||||
tscan((Region1, Region2), 10, 0.1, layout="table", provider = "csv")
|
||||
|
||||
ret = grab_frames(image, 10, sleep=0.1)
|
||||
av = average_ips(ret, None, True)
|
||||
data = get_ip_array(av)
|
||||
plot(data)
|
||||
save_image(av, "{images}/float.tif","tiff")
|
||||
|
||||
av = average_ips(ret, None, False)
|
||||
save_image(av, "{images}/int.tif","tiff")
|
||||
from ijutils import *
|
||||
from ch.psi.pshell.imaging.Overlays import *
|
||||
from ch.psi.pshell.imaging.Utils import *
|
||||
import ch.psi.pshell.imaging.Pen as Pen
|
||||
import java.awt.Rectangle as Rectangle
|
||||
import ch.psi.pshell.imaging.Data as Data
|
||||
import ch.psi.pshell.device.Camera.DataType as DataType
|
||||
|
||||
eiger.setDataType(DataType.Float32)
|
||||
eiger.getDataArray().monitored=True
|
||||
###############################################################################
|
||||
# Triggering
|
||||
# ROI Integration
|
||||
###############################################################################
|
||||
|
||||
def trigger_eiger(wait=False):
|
||||
|
||||
def integrate_roi(source, x,y, w, h):
|
||||
if source.data is None:
|
||||
source.update()
|
||||
roi = source.data.getRoi(Rectangle(x,y, w, h))
|
||||
return roi.integrate(False)
|
||||
|
||||
|
||||
|
||||
class RoiIntensity(ReadonlyRegisterBase):
|
||||
def __init__(self, name, source, x,y, w, h):
|
||||
ReadonlyRegisterBase.__init__(self, name)
|
||||
self.source=source
|
||||
self.roi = x,y, w, h
|
||||
|
||||
def doRead(self):
|
||||
x,y, w, h = self.roi
|
||||
return integrate_roi(self.source, x,y, w, h)
|
||||
|
||||
def create_roi_devices(roi_list, add = True):
|
||||
rois = []
|
||||
for r in roi_list:
|
||||
roi = RoiIntensity(r, image, roi_list[r][0], roi_list[r][1], roi_list[r][2], roi_list[r][3])
|
||||
if add:
|
||||
add_device(roi, True)
|
||||
rois.append(roi)
|
||||
return rois
|
||||
|
||||
###############################################################################
|
||||
# Frame integration
|
||||
###############################################################################
|
||||
"""
|
||||
def get_image(source, roi=None, wait_next=False):
|
||||
if wait_next:
|
||||
source.waitNext(-1)
|
||||
elif wait_next:
|
||||
if str(source.camera)=="Single":
|
||||
eiger.start()
|
||||
eiger.waitCacheChange(20000)
|
||||
ret = load_image(Utils.grayscale(source.output, Rectangle(roi[0], roi[1], roi[2], roi[3]) if (roi is not None) else None))
|
||||
return ret
|
||||
|
||||
def grab_frames(source, samples, roi=None, wait_next=False, sleep=0):
|
||||
frames = []
|
||||
for i in range(samples):
|
||||
if sleep>0:
|
||||
time.sleep(sleep)
|
||||
aux = get_image(source, roi, wait_next)
|
||||
frames.append(aux)
|
||||
return frames
|
||||
|
||||
def average_frames(source, samples=1, roi=None, wait_next=False, sleep=0, as_float=True):
|
||||
return average_ips(grab_frames(source, samples, roi, wait_next, sleep), as_float)
|
||||
|
||||
def integrate_frames(source, samples=1, roi=None, wait_next=False, sleep=0, as_float=True):
|
||||
return integrate_ips(grab_frames(source, samples, roi, wait_next, sleep), as_float)
|
||||
"""
|
||||
def grab_frame(source, roi=None, wait_next=False):
|
||||
if wait_next:
|
||||
if str(eiger.grabMode)=="Single":
|
||||
eiger.start()
|
||||
#eigar.waitCacheChange(20000)
|
||||
source.waitNext(20000)
|
||||
#ret = load_image(Utils.grayscale(source.output, Rectangle(roi[0], roi[1], roi[2], roi[3]) if (roi is not None) else None))
|
||||
time.sleep(1.0)
|
||||
data=source.data
|
||||
if roi is not None:
|
||||
data = data.getRoi(Rectangle(roi[0], roi[1], roi[2], roi[3]))
|
||||
#ret = load_image(img)
|
||||
return data
|
||||
|
||||
def grab_frames(source, samples, roi=None, wait_next=False, sleep=0):
|
||||
frames = []
|
||||
for i in range(samples):
|
||||
if (i>0) and (sleep>0):
|
||||
time.sleep(sleep)
|
||||
aux = grab_frame(source, roi, wait_next)
|
||||
frames.append(aux)
|
||||
return frames
|
||||
|
||||
def integrate_frames(frames):
|
||||
if frames is None or (len(frames)==0):
|
||||
return None
|
||||
ret = frames[0].copy()
|
||||
for data in frames[1:]:
|
||||
ret.sum(data)
|
||||
return ret
|
||||
|
||||
def get_ip_array(ip):
|
||||
"""
|
||||
Returns data array of ImagePlus
|
||||
"""
|
||||
if type(ip.getProcessor()) == FloatProcessor:
|
||||
ret = ip.getProcessor().getFloatArray()
|
||||
else:
|
||||
ret = ip.getProcessor().getIntArray()
|
||||
ret = Convert.reshape(ret, [ip.getHeight(), ip.getWidth()])
|
||||
return ret
|
||||
|
||||
def average_frames(frames):
|
||||
ret = integrate_frames(frames)
|
||||
if ret is not None:
|
||||
ret.div(len(frames))
|
||||
return ret
|
||||
|
||||
def save_as_tiff(data, filename, check=False):
|
||||
if type(data) == Data:
|
||||
ip = load_array(data.matrix)
|
||||
else:
|
||||
ip = data
|
||||
data = get_ip_array(ip)
|
||||
#ip.show()
|
||||
#plot(data)
|
||||
if not os.path.exists(os.path.dirname(filename)):
|
||||
os.makedirs(os.path.dirname(filename))
|
||||
save_image(ip, filename,"tiff")
|
||||
|
||||
if check:
|
||||
import java.util.Arrays as Arrays
|
||||
ip=open_image(filename)
|
||||
read = get_ip_array(ip)
|
||||
if not Arrays.deepEquals(read, data):
|
||||
raise Exception("Error reading array")
|
||||
#plot(read)
|
||||
|
||||
def trigger_eiger(wait=False):
|
||||
eiger.start()
|
||||
if wait:
|
||||
eiger.waitNewImage(20000)
|
||||
|
||||
|
||||
|
||||
if False:
|
||||
integrate_roi(image, 10, 5, 20, 10)
|
||||
|
||||
add_device(RoiIntensity("Region1", image, 10, 5, 20, 10), True)
|
||||
add_device(RoiIntensity("Region2", image, 10, 5, 40, 20), True)
|
||||
|
||||
|
||||
|
||||
import ch.psi.pshell.data.ProviderCSV as ProviderCSV
|
||||
ProviderCSV.setDefaultItemSeparator(" ")
|
||||
tscan((Region1, Region2), 10, 0.1, layout="table", provider = "csv")
|
||||
|
||||
ret = grab_frames(image, 10, sleep=0.1)
|
||||
av = integrate_frames(ret)
|
||||
save_as_tiff(av,"{images}/data.tif", True)
|
||||
|
||||
|
||||
print "Success"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
83
script/devices/id.py
Normal file
83
script/devices/id.py
Normal file
@@ -0,0 +1,83 @@
|
||||
|
||||
POL_IDS={ "Circ_Plus": 1, "Circ_Minus": 2, "Lin_Hor":3, "Lin_Ver": 4}
|
||||
|
||||
|
||||
|
||||
def get_id_status(id):
|
||||
# 0 = ok
|
||||
# 1 = Warning
|
||||
# 2 = Error
|
||||
# 3 = Not available
|
||||
if id<1 or id>2: raise Exception("Invalid id")
|
||||
return caget("X11MA-ID1-USER:STATUS" if (id==1) else "X11MA-ID2-USER:STATUS")
|
||||
|
||||
def get_id_error(id):
|
||||
# B0 (1) = PLC (Taper, Motor controller, Limitswitch....)
|
||||
# B1 (2) = Encoders (cabel, not referenced)
|
||||
# B2 (4) = FeedForward (PS off, PS defect, FF ausgeschaltet)
|
||||
# B3 (8) = Operator COntrol
|
||||
# B4 (16)= Moving Timeout (moving longer then 120 sec)
|
||||
# B5 (32)= Interlock (Orbit, Temperature...)\
|
||||
if id<1 or id>2:
|
||||
raise Exception("Invalid id")
|
||||
return caget("X11MA-ID1-USER:ERROR-SOURCE" if (id==1) else "X11MA-ID2-USER:ERROR-SOURCE")
|
||||
|
||||
|
||||
|
||||
def get_id_pol(id, as_string=False):
|
||||
# 1: Circ+
|
||||
# 2: Circ-
|
||||
# 3: Lin H
|
||||
# 4: Lin V
|
||||
# 5: LIn
|
||||
if id<1 or id>2: raise Exception("Invalid id")
|
||||
ret = caget ("X11MA-ID1:MODE" if id==1 else "X11MA-ID2:MODE", 's' if as_string else 'i')
|
||||
if ret!=0: return ret
|
||||
#linear mode
|
||||
alpha = get_alpha_id(id)
|
||||
if alpha==0 : return 3
|
||||
if alpha==90 : return 4
|
||||
return 5
|
||||
|
||||
def get_alpha_id(id):
|
||||
if id<1 or id>2: raise Exception("Invalid id")
|
||||
return caget ("X11MA-ID1:ALPHA" if id==1 else "X11MA-ID2:ALPHA")
|
||||
|
||||
|
||||
def put_id_offset(id, v):
|
||||
if id<1 or id>2:
|
||||
raise Exception("Invalid id")
|
||||
caput(pv,"X11MA-ID1:ENERGY-OFFS" if (id==1) else "X11MA-ID2:ENERGY-OFFS",v)
|
||||
|
||||
def get_id_offset(id):
|
||||
if id<1 or id>2:
|
||||
raise Exception("Invalid id")
|
||||
return caget("X11MA-ID1:ENERGY-OFFS" if (id==1) else "X11MA-ID2:ENERGY-OFFS")
|
||||
|
||||
|
||||
def put_id_pol(id, pol, alpha=None):
|
||||
#pol = 1 : Mode =1, alpha = 0 circ +
|
||||
#pol = 2 : Mode =2, alpha = 0 circ -
|
||||
#pol = 3 : Mode =0, alpha = 0 lin hor
|
||||
#pol = 4 : Mode =0, alpha = 90 lin vert
|
||||
#pol = 5 : Mode =0, alpha = ? lin rot
|
||||
if id<1 or id>2:
|
||||
raise Exception("Invalid id")
|
||||
|
||||
pv1="X11MA-ID1:MODE" if (id==1) else "X11MA-ID2:MODE"
|
||||
pv2="X11MA-ID1:ALPHA" if (id==1) else "X11MA-ID2:ALPHA"
|
||||
|
||||
if pol == 1:
|
||||
caput(pv1,1)
|
||||
elif pol == 2:
|
||||
caput(pv1,2)
|
||||
elif pol == 3:
|
||||
caput(pv1,0)
|
||||
caput(pv2,0)
|
||||
elif pol == 4:
|
||||
caput(pv1,0)
|
||||
caput(pv2,0)
|
||||
elif pol == 5:
|
||||
caput(pv1,0)
|
||||
time.sleep(1.0)
|
||||
caput(pv2,alpha)
|
||||
187
script/local.py
187
script/local.py
@@ -236,5 +236,192 @@ def otf(start, end, time, delay = 0.0, mode = None, offset = None, alpha = None,
|
||||
###################################################################################################
|
||||
|
||||
run("devices/eiger")
|
||||
run("devices/id")
|
||||
run("devices/chopper")
|
||||
|
||||
|
||||
###################################################################################################
|
||||
#ID and Machine status
|
||||
###################################################################################################
|
||||
|
||||
def get_id_status(id):
|
||||
# 0 = ok
|
||||
# 1 = Warning
|
||||
# 2 = Error
|
||||
# 3 = Not available
|
||||
if id<1 or id>2:
|
||||
raise Exception("Invalid id")
|
||||
return caget("X11MA-ID1-USER:STATUS" if (id==1) else "X11MA-ID2-USER:STATUS")
|
||||
|
||||
def get_id_error(id):
|
||||
# B0 (1) = PLC (Taper, Motor controller, Limitswitch....)
|
||||
# B1 (2) = Encoders (cabel, not referenced)
|
||||
# B2 (4) = FeedForward (PS off, PS defect, FF ausgeschaltet)
|
||||
# B3 (8) = Operator COntrol
|
||||
# B4 (16)= Moving Timeout (moving longer then 120 sec)
|
||||
# B5 (32)= Interlock (Orbit, Temperature...)\
|
||||
if id<1 or id>2:
|
||||
raise Exception("Invalid id")
|
||||
return caget("X11MA-ID1-USER:ERROR-SOURCE" if (id==1) else "X11MA-ID2-USER:ERROR-SOURCE")
|
||||
|
||||
|
||||
def get_id_control(id):
|
||||
#0 = SLS control, 1 = experiment
|
||||
if id<1 or id>2: raise Exception("Invalid id")
|
||||
return caget("X11MA-ID1-GAP:SCTRL" if id==1 else "X11MA-ID2-GAP:SCTRL")
|
||||
|
||||
def get_ring_status():
|
||||
#ACOAU-ACCU:OP-MODE kann Werte zwischen 0 und 5 annehmen:
|
||||
# rule from 24.8.04
|
||||
#If (PCT beam current <0.09) -> State 0: "Machine Down"
|
||||
#Else If (GUN Trigger OFF) -> State 1: "Inj. Stopped"
|
||||
#Else If (INJ_MODE == Normal) -> State 2: "Accumulating."
|
||||
#Else If !(reached Top-Up Current) -> State 3: "Accumulating"
|
||||
#Else If (OP-READY == Wait) -> State 4: "Top-up ready"
|
||||
#Else If (OFB off) -> State 5: "Light-Available" (former State 4)
|
||||
#Else -> State 6: "Light Available" (former State 5)
|
||||
return caget("ACOAU-ACCU:OP-MODE", 'i')
|
||||
|
||||
|
||||
|
||||
def assert_machine_ok(wait = True):
|
||||
ID1status=get_id_control(1)
|
||||
ID2status=get_id_control(2)
|
||||
Ringstatus=get_ring_status()
|
||||
oldRingstatus=Ringstatus
|
||||
checkRing=0
|
||||
|
||||
if Ringstatus==5:
|
||||
log ("FB off")
|
||||
checkRing=1
|
||||
if Ringstatus==0:
|
||||
log ("Machine down")
|
||||
checkRing=2
|
||||
|
||||
if checkRing>0:
|
||||
status=False
|
||||
|
||||
while not status:
|
||||
ID1status=get_id_control(1)
|
||||
ID2status=get_id_control(2)
|
||||
Ringstatus=get_ring_status()
|
||||
if oldRingstatus != Ringstatus:
|
||||
if Ringstatus == 0:
|
||||
log("Machine down")
|
||||
checkRing=2
|
||||
oldRingstatus=Ringstatus
|
||||
elif Ringstatus == 1:
|
||||
log("Inj. Stopped")
|
||||
checkRing=2
|
||||
oldRingstatus=Ringstatus
|
||||
elif Ringstatus == 2:
|
||||
log("Accumulating.")
|
||||
checkRing=2
|
||||
oldRingstatus=Ringstatus
|
||||
elif Ringstatus == 3:
|
||||
log("Accumulating")
|
||||
checkRing=2
|
||||
oldRingstatus=Ringstatus
|
||||
elif Ringstatus == 4:
|
||||
log("Top-up ready, Gap still open")
|
||||
checkRing=2
|
||||
oldRingstatus=Ringstatus
|
||||
elif Ringstatus == 5:
|
||||
log("Light-Available, no OFB")
|
||||
checkRing=2
|
||||
oldRingstatus=Ringstatus
|
||||
elif Ringstatus == 6:
|
||||
log("Light Available")
|
||||
checkRing=2
|
||||
oldRingstatus=Ringstatus
|
||||
status= (Ringstatus ==6) and (ID1status==1) and (ID2status==1)
|
||||
if not wait:
|
||||
raise Exception ("Ring error: " + str(Ringstatus))
|
||||
time.sleep(1)
|
||||
if checkRing==2:
|
||||
log("wait 120 s")
|
||||
time.sleep(120)
|
||||
log("continue")
|
||||
elif checkRing==2:
|
||||
log("wait 10 s")
|
||||
time.sleep(10)
|
||||
log("continue")
|
||||
|
||||
|
||||
def assert_bemline_ok():
|
||||
checkbeamline=0
|
||||
message=[ "PLC error","Encoder error", "Feedforward error","Operator control", "Moving timeout", "Interlock"]
|
||||
|
||||
if ID == "ID1":
|
||||
ID1status=get_id_status(1)
|
||||
ID2status=0
|
||||
elif ID == "ID2":
|
||||
ID1status=0
|
||||
ID2status=get_id_status(2)
|
||||
if ID == "ID1_ID2":
|
||||
ID1status=get_id_status(1)
|
||||
ID2status=get_id_status(2)
|
||||
if ID1status >= 1:
|
||||
ID1error=get_id_error(1)
|
||||
for bit in range (5,-1, -1):
|
||||
if ID1error & (2**bit):
|
||||
log ("ID1 "+ str(message[bit]))
|
||||
ID1error=ID1error-(2**bit)
|
||||
if ID2status >= 1:
|
||||
ID2error=get_id_error(2)
|
||||
for bit in range (5,-1, -1):
|
||||
if ID2error & (2**bit):
|
||||
log ("ID2 "+ str(message[bit]))
|
||||
ID2error=ID2error-(2**bit)
|
||||
if ID1status >= 1:
|
||||
raise Exception("ID1 error")
|
||||
if ID2status >= 1:
|
||||
raise Exception("ID2 error")
|
||||
|
||||
###################################################################################################
|
||||
#Manual log file
|
||||
###################################################################################################
|
||||
|
||||
"""
|
||||
def get_log_file():
|
||||
return data_path + "/logs.txt"
|
||||
|
||||
def write_logfile(msg):
|
||||
log(msg, True)
|
||||
if not os.path.exists(os.path.dirname(get_log_file())):
|
||||
os.makedirs(os.path.dirname(get_log_file()))
|
||||
with open( get_log_file(), "a") as myfile:
|
||||
myfile.write(msgv + "\n")
|
||||
"""
|
||||
|
||||
###################################################################################################
|
||||
#Energy
|
||||
###################################################################################################
|
||||
|
||||
"""
|
||||
def put_energy(v):
|
||||
if DRY_RUN: return
|
||||
if v>91 and v<2500:
|
||||
caput("X11PHS:alldone",0)
|
||||
caput("X11PHS-E:GO.A",v)
|
||||
else:
|
||||
log("Energy out of range (91-2500) :" + str(v))
|
||||
|
||||
|
||||
def is_done():
|
||||
#1: done move
|
||||
#0: moving
|
||||
return True if caget("X11PHS:alldone") else False
|
||||
|
||||
def wait_done():
|
||||
if DRY_RUN: return
|
||||
time.sleep(1.0) #in order to reduce trafic on the IOC
|
||||
wait_channel("X11PHS:alldone", 1)
|
||||
"""
|
||||
|
||||
def put_energy(v):
|
||||
energy.write(float(v))
|
||||
time.sleep(0.5)
|
||||
wait_channel(ALL_DONE, 1, type = 'i')
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
#If running from editor
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
ID = "ID1"
|
||||
@@ -13,17 +14,235 @@ if get_exec_pars().source == CommandSource.ui:
|
||||
ROI = {"ROI1": [50,50,200, 100]}
|
||||
|
||||
METHOD = "Two_Pol"
|
||||
MEASUREMENTS = 1
|
||||
MEASUREMENTS = 2
|
||||
CONTRAST = 0
|
||||
AUTO_SAVE = True
|
||||
AS_SEQUENCE = False
|
||||
EXPOSURE_1 = 1.0
|
||||
AVERAGE_1 = 1.0
|
||||
AVERAGE_1 = 2.0
|
||||
ENERGY_1 = 1000.0
|
||||
POLARIZATION_1 = "Circ_Plus"
|
||||
EXPOSURE_2 = 1.0
|
||||
AVERAGE_2 = 1.0
|
||||
AVERAGE_2 = 2.0
|
||||
ENERGY_2= 1000.0
|
||||
POLARIZATION_2 = "Circ_Minus"
|
||||
|
||||
tscan((keithley_1a,keithley_2a,keithley_3a), 10, 0.1)
|
||||
|
||||
|
||||
|
||||
DRY_RUN=True
|
||||
|
||||
EXPOSURE = [EXPOSURE_1, EXPOSURE_2]
|
||||
AVERAGE = [int(AVERAGE_1), int(AVERAGE_2)]
|
||||
ENERGY = [ENERGY_1, ENERGY_2]
|
||||
POLARIZATION = [POLARIZATION_1, POLARIZATION_2]
|
||||
|
||||
|
||||
if METHOD == "Two_Energies":
|
||||
for en in [ENERGY_1, ENERGY_2]:
|
||||
if en < 89.9 or en > 2000:
|
||||
raise Exception("Bad energy argument")
|
||||
|
||||
path = "{data}/{year}_{month}/{date}" + "/" + METHOD + "_{seq}%03d"
|
||||
set_exec_pars(path= path, format="txt", layout="table", open="True")
|
||||
data_path = get_context().setup.expandPath(path)
|
||||
#get_context().incrementFileSequentialNumber()
|
||||
|
||||
frames = [None, None, None]
|
||||
|
||||
def get_image_file_name(cicle=-1, frame_index=0):
|
||||
if cicle < 0:
|
||||
return data_path + "/" + ("%04d" % i) + ".tif"
|
||||
return data_path + "/" + str(cycle) + "_" + str(MEASUREMENTS) + "_" + ("%04d" % frame_index) + ".tif"
|
||||
|
||||
|
||||
def nextpol():
|
||||
global current_pol, polID1, polID2
|
||||
if SWITCHING == "Normal":
|
||||
if current_pol==1: return 2 #circ+ -> circ-
|
||||
if current_pol==2: return 1 #circ+ -> circ-
|
||||
if current_pol==3: return 4 #lin hor -> lin vert
|
||||
if current_pol==4: return 3 #lin vert -> lin hor
|
||||
if current_pol==5: return 5 #lin rot -> lin rot
|
||||
elif SWITCHING == "Tune_Detune":
|
||||
if activeID==1: return polID2
|
||||
if activeID==2: return polID1
|
||||
|
||||
|
||||
def switch_pol():
|
||||
global active_id
|
||||
if DRY_RUN:
|
||||
return
|
||||
newpol=nextpol()
|
||||
if ID == "ID1":
|
||||
put_id_pol(1,newpol)
|
||||
elif ID == "ID2":
|
||||
put_id_pol(2,newpol)
|
||||
elif ID == "ID1_ID2":
|
||||
if SWITCHING == "Normal":
|
||||
put_id_pol(1, newpol)
|
||||
put_id_pol(2, newpol)
|
||||
elif SWITCHING == "Tune_Detune":
|
||||
if active_id ==1:
|
||||
put_id_offset(1, OFFSET_ID_1-40) #detuneID1
|
||||
put_id_offset(2, OFFSET_ID_2) #tuneID2
|
||||
active_id=2
|
||||
else:
|
||||
put_id_offset(2, OFFSET_ID_2-40) #detuneID2
|
||||
put_id_offset(1, OFFSET_ID_1) #tuneID2
|
||||
active_id=1
|
||||
elif SWITCHING == "Chopper":
|
||||
if active_id == 1:
|
||||
active_id = 2
|
||||
set_chopper(1)
|
||||
else:
|
||||
active_id = 1
|
||||
set_chopper(0)
|
||||
time.sleep(1.0)
|
||||
|
||||
|
||||
def change_energy(v):
|
||||
if v<91 or v>2500:
|
||||
raise Exception ("Invalid energy: " + str(v))
|
||||
if DRY_RUN:
|
||||
return
|
||||
put_energy(v)
|
||||
|
||||
"""
|
||||
def getLEEM():
|
||||
global startvoltage,objective, LEEMtemp
|
||||
startvoltage=getStartvoltage()
|
||||
objective=getObjective()
|
||||
LEEMtemp=getLEEMtemp()
|
||||
"""
|
||||
|
||||
|
||||
|
||||
def assert_status_ok():
|
||||
if DRY_RUN: return
|
||||
assert_machine_ok()
|
||||
assert_beamline_ok()
|
||||
"""
|
||||
getbeamline
|
||||
getLEEM
|
||||
Rem check status of machine
|
||||
If checkRing = 3 Then
|
||||
Close
|
||||
Exit Sub
|
||||
End If
|
||||
Rem check status of the beamline
|
||||
If checkbeamline = 3 Then
|
||||
Close
|
||||
Exit Sub
|
||||
"""
|
||||
|
||||
#Initialize vartiables
|
||||
|
||||
active_id = 1
|
||||
current_pol=None
|
||||
polID1=None
|
||||
polID2=None
|
||||
#rbkEnergy=energy_rbk.read()
|
||||
if METHOD == "Two_Pol":
|
||||
global current_pol
|
||||
if ID == "ID1":
|
||||
current_pol=POL_IDS[POL_ID_1] #get_id_pol(1)
|
||||
put_id_pol(1,current_pol)
|
||||
elif ID == "ID2":
|
||||
current_pol=POL_IDS[POL_ID_2]#get_id_pol(2)
|
||||
put_id_pol(2,current_pol)
|
||||
elif ID == "ID1_ID2":
|
||||
polID1=POL_IDS[POL_ID_1]
|
||||
polID2=POL_IDS[POL_ID_2]
|
||||
put_id_pol(1,polID1)
|
||||
put_id_pol(2,polID2)
|
||||
current_pol=polID1
|
||||
if SWITCHING == "Tune_Detune":
|
||||
put_id_offset(2, OFFSET_ID_2-40) #detuneID2
|
||||
put_id_offset(1, OFFSET_ID_1) #tuneID2
|
||||
|
||||
elif SWITCHING == "Chopper":
|
||||
set_chopper(0)
|
||||
|
||||
def imageinfo(info):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
#Do the measurement loop
|
||||
for cycle in range(1, MEASUREMENTS + 1):
|
||||
if MEASUREMENTS > 1:
|
||||
log("")
|
||||
log("nround = " + str(cycle) + " / " + str(MEASUREMENTS))
|
||||
|
||||
if METHOD == "Two_Energies":
|
||||
change_energy(ENERGY_1)
|
||||
|
||||
###??? SETAR POLARIZATION?
|
||||
time.sleep(1)
|
||||
|
||||
for i in range(2):
|
||||
assert_status_ok()
|
||||
eiger.setExposure(EXPOSURE[i])
|
||||
|
||||
if AS_SEQUENCE:
|
||||
raise Exception("As sequence not implemented")
|
||||
# TODO
|
||||
else:
|
||||
ret = grab_frames(image, AVERAGE[i], roi=None, wait_next=True)
|
||||
frames[i] = average_frames(ret) if AVERAGE[i] > 1 else ret[0]
|
||||
imageinfo("I")
|
||||
|
||||
if METHOD == "Take_Image":
|
||||
break
|
||||
|
||||
if i == 0:
|
||||
if METHOD == "Two_Pol":
|
||||
switch_pol()
|
||||
if METHOD == "Two_Energies":
|
||||
change_energy(ENERGY_2)
|
||||
wait_done()
|
||||
time.sleep(1)
|
||||
|
||||
if METHOD == "Two_Pol":
|
||||
if (current_pol == 2) or (current_pol==3):
|
||||
###??? autocontrast???
|
||||
frames[2] = frames[0].copy()
|
||||
frames[2].div(frames[1])
|
||||
else:
|
||||
frames[2] = frames[1].copy()
|
||||
frames[2].div(frames[0])
|
||||
|
||||
if METHOD == "Two_Energies":
|
||||
frames[2] = frames[0].copy()
|
||||
frames[2].div(frames[1])
|
||||
|
||||
if AUTO_SAVE:
|
||||
for i in range(len(frames)):
|
||||
filename = get_image_file_name(cycle, i)
|
||||
save_as_tiff(frames[i], filename, check=True)
|
||||
log(filename)
|
||||
print filename
|
||||
# +" "+imagetext)
|
||||
# log("SV:"+Format(startvoltage,"0.000")+" OB:"+Format(objective,"0.00")+" ST:"+Format(LEEMtemp,"0.0"))
|
||||
if METHOD == "Take_Image":
|
||||
break
|
||||
else:
|
||||
pass
|
||||
# objective = getObjective()
|
||||
# temp = getLEEMtemp()
|
||||
# log(0 , "Temp : " + Format(temp,"0.00") + " OB : " + Format(objective,"0.00") + " StigmaA : " + " StigmaB : " )
|
||||
# Auto average and save
|
||||
if MEASUREMENTS > 1 and AUTO_SAVE == 1:
|
||||
for i in range(len(frames)):
|
||||
measures = []
|
||||
for cycle in range(1, MEASUREMENTS + 1):
|
||||
filename = get_image_file_name(cycle, i)
|
||||
ip = open_image(filename)
|
||||
#measures.append(Data(get_ip_array(ip)))
|
||||
measures.append(ip)
|
||||
#av = average_frames(measures) #Result is transposed???
|
||||
av=average_ips (measures, roi=None, as_float=True)
|
||||
filename = get_image_file_name(-1, i)
|
||||
save_as_tiff(av, filename, check=True)
|
||||
print filename
|
||||
if METHOD == "Take_Image":
|
||||
|
||||
@@ -19,7 +19,26 @@ if get_exec_pars().source == CommandSource.ui:
|
||||
EXPOSURE = 1.0
|
||||
AVERAGE = 1
|
||||
NUMBER_SCANS =1
|
||||
|
||||
|
||||
RANGES = [[500, 1000, 1]]
|
||||
|
||||
|
||||
rois = create_roi_devices(ROI)
|
||||
|
||||
rois = create_roi_devices(ROI)
|
||||
|
||||
class SyncEnergy(Writable):
|
||||
def write(self,pos):
|
||||
put_energy(pos)
|
||||
sync_energy=SyncEnergy()
|
||||
|
||||
|
||||
|
||||
def grab_image(position, scan):
|
||||
grab_frame(image, roi=None, wait_next=True)
|
||||
|
||||
|
||||
set_exec_pars(path="{data}/{year}_{month}/{date}", layout="table")
|
||||
|
||||
|
||||
tscan(rois, 10, 0.1, format="csv", before_read=grab_image)
|
||||
#rscan(sync_energy, rois +[machine_cur], RANGES, latency = 0.0, tag="AbsortionSpectrum_{seq}%03d", latency=0.0, before_read=grab_image)
|
||||
|
||||
53
script/test/TestAverage.py
Normal file
53
script/test/TestAverage.py
Normal file
@@ -0,0 +1,53 @@
|
||||
from ijutils import *
|
||||
import java.util.Arrays as Arrays
|
||||
|
||||
ret = grab_frames(image, 3, roi=None, wait_next=True)
|
||||
av = average_frames(ret)
|
||||
|
||||
div = ret[0].copy()
|
||||
div.div(ret[1])
|
||||
|
||||
save_as_tiff(ret[0], "{images}/0.tif", check=True)
|
||||
save_as_tiff(ret[1], "{images}/1.tif", check=True)
|
||||
save_as_tiff(ret[2], "{images}/2.tif", check=True)
|
||||
save_as_tiff(av, "{images}/av.tif", check=True)
|
||||
save_as_tiff(div, "{images}/div.tif", check=True)
|
||||
|
||||
|
||||
plot([ret[0].matrix, ret[1].matrix, ret[2].matrix, av.matrix, div.matrix], name=["1","2","3","av", "div"])
|
||||
|
||||
|
||||
|
||||
i0=open_image("{images}/0.tif")
|
||||
a0 = get_ip_array(i0)
|
||||
i1=open_image("{images}/0.tif")
|
||||
a1 = get_ip_array(i1)
|
||||
i2=open_image("{images}/0.tif")
|
||||
a2 = get_ip_array(i2)
|
||||
ia=open_image("{images}/av.tif")
|
||||
aa = get_ip_array(ia)
|
||||
|
||||
plot([a0,a1,a2,aa], name=["1","2","3","av"], title="Read")
|
||||
|
||||
|
||||
a = get_ip_array(load_array(ret[0].matrix))
|
||||
print Arrays.deepEquals(a, a0)
|
||||
|
||||
|
||||
a0 = get_ip_array(open_image("{images}/0.tif"))
|
||||
a1 = get_ip_array(open_image("{images}/1.tif"))
|
||||
a2 = get_ip_array(open_image("{images}/2.tif"))
|
||||
|
||||
|
||||
|
||||
measures = [i0,i1,i2]
|
||||
av2=average_ips (measures, roi=None, as_float=True)
|
||||
save_as_tiff(av2, "{images}/av2.tif", check=True)
|
||||
|
||||
|
||||
|
||||
arr1=av.matrix
|
||||
arr2=get_ip_array(av2)
|
||||
print Arrays.deepEquals(arr1,arr2)
|
||||
plot([arr1[0], arr2[0]], name =["arr1", "arr2"], title = "Cmp")
|
||||
|
||||
3607
script/test/X11MA_main_macros.ipm.tex.py
Normal file
3607
script/test/X11MA_main_macros.ipm.tex.py
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<configuration xmlns="http://www.psi.ch/~ebner/models/scan/1.0">
|
||||
<data/>
|
||||
<scan/>
|
||||
<configuration xmlns="http://www.psi.ch/~ebner/models/scan/1.0" failOnSensorError="true">
|
||||
<data fileName="fda"/>
|
||||
<scan>
|
||||
<dimension zigzag="false" dataGroup="false">
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="PseudoPositioner" id="id683170">
|
||||
<counts>10</counts>
|
||||
</positioner>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Timestamp" id="id691479"/>
|
||||
</dimension>
|
||||
</scan>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="id683170" y="id691479"/>
|
||||
</configuration>
|
||||
|
||||
Reference in New Issue
Block a user