Sprint 12/21

This commit is contained in:
gac-x11ma
2020-12-09 15:06:55 +01:00
parent 13352381ed
commit b0718601c2
19 changed files with 1717 additions and 682 deletions
+97 -16
View File
@@ -5,8 +5,9 @@ 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
import ch.psi.utils.Chrono as Chrono
CONTINOUS_MODE_MIN_TIME = 4000
###############################################################################
# ROI Integration
###############################################################################
@@ -179,31 +180,111 @@ def trigger_eiger(wait=False):
if wait:
eiger.waitNewImage(20000)
def set_exposure_time(exposure):
if exposure == eiger.getExposure():
return
def get_eiger_exposure_readback():
return caget("X11MA-ES1-SD1:cam1:AcquireTime_RBV",'f')
def set_exposure_time(value, check = True, retries=3):
if value == eiger.getExposure():
return
started = eiger.isStarted()
if started:
eiger.stop()
time.sleep(0.2)
eiger.setExposure(exposure)
stop_eiger()
for i in range(retries):
try:
eiger.setExposure(value)
if check:
readback=get_eiger_exposure_readback()
if abs(value - readback) > 0.01:
raise Exception("Error changing Eiger exposure time to %f: readback=%f" % (value, readback))
except:
if i==(retries-1):
raise
else:
print "Error changing Eiger exposure time: retrying"
time.sleep(0.3)
if started:
if eiger.grabMode==eiger.GrabMode.Continuous:
eiger.start()
def get_eiger_number_of_frames():
return caget("X11MA-ES1-SD1:cam1:NumFrames_RBV",'i')
def restore_eiger():
def set_eiger_number_of_frames(value, check = True):
if value == get_eiger_number_of_frames():
return
started = eiger.isStarted()
if started:
stop_eiger()
caput("X11MA-ES1-SD1:cam1:NumFrames",value)
if check:
readback = get_eiger_number_of_frames()
if value != readback:
raise Exception("Error changing Eiger number of frames to %d: readback=%d" % (value, readback))
if started:
if eiger.grabMode==eiger.GrabMode.Continuous:
eiger.start()
#Wait for channel to chenge
def stop_eiger():
global chrono_eiger
chrono_eiger.waitTimeout(CONTINOUS_MODE_MIN_TIME)
started = eiger.isStarted()
if started:
eiger.stop()
eiger.grabMode=eiger.GrabMode.Single
eiger.stop()
time.sleep(0.3)
if eiger.acquire.read() >0:
raise Exception("Error stopping Eiger")
chrono_eiger = Chrono()
def init_eiger(exposure=None, check=True, retries=2):
"""
Set Eiger scan mode
"""
global chrono_eiger
chrono_eiger.waitTimeout(CONTINOUS_MODE_MIN_TIME)
for i in range(retries):
try:
stop_eiger() #Set mode single
eiger.setNumImages(1)# Is it relevant?
set_eiger_number_of_frames(1)
if exposure:
set_exposure_time(exposure, check)
break
except:
if i==(retries-1):
raise
else:
print "Error initializing Eiger, retrying: " + str(sys.exc_info()[1])
def restore_eiger(check=True, retries=2):
"""
Set Eiger default mode
"""
if eiger.isStarted():
eiger.stop()
time.sleep(0.2)
eiger.grabMode=eiger.GrabMode.Continuous
eiger.setExposure(0.2)
eiger.setNumImages(1)
eiger.start()
global chrono_eiger
for i in range(retries):
try:
stop_eiger()
eiger.setNumImages(1)# Is it relevant?
set_eiger_number_of_frames(1, check)
set_exposure_time(0.2, check)
eiger.grabMode=eiger.GrabMode.Continuous
eiger.start()
chrono_eiger = Chrono()
break
except:
if i==(retries-1):
raise
else:
print "Error restoring Eiger, retrying " + str(sys.exc_info()[1])
_outliers_mask_timestamp = 0
_outliers_mask = None
+96 -6
View File
@@ -96,17 +96,20 @@ def put_id_pol(id, pol, alpha=None):
elif pol == 2:
mode_dev.write("CIRC -")
elif pol == 3:
mode_dev.write("LINEAR")
time.sleep(0.5)
if mode_dev.read() != "LINEAR":
mode_dev.write("LINEAR")
time.sleep(0.5)
alpha_dev.write(0)
elif pol == 4:
mode_dev.write("LINEAR")
time.sleep(0.5)
if mode_dev.read() != "LINEAR":
mode_dev.write("LINEAR")
time.sleep(0.5)
alpha_dev.write(90)
elif pol == 5:
mode_dev.write("LINEAR")
if alpha is not None:
if mode_dev.read() != "LINEAR":
mode_dev.write("LINEAR")
time.sleep(0.5)
if alpha is not None:
alpha_dev.write(alpha)
@@ -153,3 +156,90 @@ class EnOptDesc(ReadonlyRegisterBase):
add_device(EnOptDesc(), True)
energy_opt_desc.setPolling(2000)
#Polarizarion Switch Tools
_switching_type = None
_switching_active_id = None
_switching_current_pol = None
_switching_pol_id1 = None
_switching_pol_id2 = None
_switching_id = None
def init_pol_switch(switching_type, sid = None, pol_id1=None, pol_id2=None):
global _switching_type, _switching_active_id, _switching_current_pol, _switching_pol_id1, _switching_pol_id2, _switching_id
if sid is None:
sid = get_setting("ID")
if pol_id1 is None:
#pol_id1 = POL_IDS[get_setting("POL_ID_1")] #From config
pol_id1=get_id_pol(1) #Current
if pol_id2 is None:
#pol_id2 =POL_IDS[get_setting("POL_ID_2")] #From config
pol_id2 =get_id_pol(2) #Current
_switching_type = switching_type
_switching_id =sid
_switching_pol_id1=pol_id1
_switching_pol_id2=pol_id2
print "Init pol switch: %s id:%s pol_id1:%s pol_id2:%s" %(_switching_type, _switching_id, _switching_pol_id1, _switching_pol_id2)
_switching_active_id = 1
if _switching_id == "ID1":
_switching_current_pol = _switching_pol_id1
elif _switching_id == "ID2":
_switching_current_pol = _switching_pol_id2
elif _switching_id == "ID1_ID2":
_switching_current_pol=_switching_pol_id1
if switching_type == "Tune_Detune":
tune_detune(1) #Tune ID1, Detune ID2
else:
if _switching_id == "ID1_ID2":
put_id_pol(2, _switching_current_pol) #Force both IDs to same polarization
wait_channel("X11PHS:alldone", 1)
def nextpol():
global _switching_type, _switching_active_id, _switching_current_pol, _switching_pol_id1, _switching_pol_id2
if _switching_type == "Normal":
if _switching_current_pol==1: return 2 #circ+ -> circ-
elif _switching_current_pol==2: return 1 #circ+ -> circ-
elif _switching_current_pol==3: return 4 #lin hor -> lin vert
elif _switching_current_pol==4: return 3 #lin vert -> lin hor
elif _switching_current_pol==5: return5 #lin rot -> lin rot
else: raise "Invalid pol: " + str(_switching_current_pol)
elif _switching_type == "Tune_Detune":
if _switching_active_id==1: return _switching_pol_id2
elif _switching_active_id==2: return _switching_pol_id1
else: raise "Invalid ID: " + str(_switching_active_id)
else: raise "Invalid switching: " + str(_switching_type)
def switch_pol():
global _switching_type, _switching_active_id, _switching_current_pol, _switching_pol_id1, _switching_pol_id2, _switching_id
if DRY_RUN:
return
newpol=nextpol()
print "Switch pol: ", newpol
if _switching_id == "ID1":
put_id_pol(1,newpol)
elif _switching_id == "ID2":
put_id_pol(2,newpol)
elif ID == "ID1_ID2":
if _switching_type == "Normal":
put_id_pol(1, newpol)
put_id_pol(2, newpol)
elif _switching_type == "Tune_Detune":
if _switching_active_id==1:
_switching_active_id=2
else:
_switching_active_id=1
tune_detune(_switching_active_id)
if _switching_type == "Normal":
_switching_current_pol = newpol
time.sleep(1.0)
wait_channel("X11PHS:alldone", 1)
def get_cur_pol():
return _switching_current_pol