This commit is contained in:
+12
-2
@@ -79,7 +79,7 @@ def put_id_pol(id, pol, alpha=None):
|
||||
|
||||
|
||||
if is_string(pol):
|
||||
pol=POL_IDS[v]
|
||||
pol=POL_IDS[pol]
|
||||
|
||||
if pol == 1:
|
||||
caput(pv1,1)
|
||||
@@ -94,4 +94,14 @@ def put_id_pol(id, pol, alpha=None):
|
||||
elif pol == 5:
|
||||
caput(pv1,0)
|
||||
time.sleep(1.0)
|
||||
caput(pv2,alpha)
|
||||
caput(pv2,alpha)
|
||||
|
||||
def tune_detune(active_id):
|
||||
if active_id ==1:
|
||||
print "Tune ID1"
|
||||
put_id_offset(2, float(get_setting("OFFSET_ID_2"))-40) #detuneID2
|
||||
put_id_offset(1, float(get_setting("OFFSET_ID_1"))) #tuneID1
|
||||
else:
|
||||
print "Tune ID2"
|
||||
put_id_offset(1, float(get_setting("OFFSET_ID_1"))-40) #detuneID1
|
||||
put_id_offset(2, float(get_setting("OFFSET_ID_2"))) #tuneID2
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import ch.psi.pshell.ui.App as App
|
||||
import ch.psi.pshell.imaging.DeviceSource as DeviceSource
|
||||
|
||||
class ImgageNorm (DeviceSource):
|
||||
def __init__(self, name, dev):
|
||||
DeviceSource.__init__(self, name, dev)
|
||||
self.filenane = get_setting("NORM_FILE")
|
||||
try:
|
||||
ip=open_image(self.filenane)
|
||||
|
||||
#TRANSPOSE - ImageJ stores the data transposed
|
||||
ip.getProcessor().rotate(-90)
|
||||
ip.getProcessor().flipVertical()
|
||||
|
||||
|
||||
array = get_ip_array(ip)
|
||||
self.ref = Data(array)
|
||||
except:
|
||||
self.ref = None
|
||||
self.pushData(None)
|
||||
print sys.exc_info()[1]
|
||||
|
||||
def onDataReceived(self,val):
|
||||
if self.ref:
|
||||
n = Data(eiger.getDataMatrix().take())
|
||||
n.threshold(1e9, False, None)
|
||||
n.div(self.ref)
|
||||
self.pushData(n)
|
||||
|
||||
|
||||
norm = ImgageNorm("norm", eiger.dataArray)
|
||||
norm.monitored=True
|
||||
add_device(norm, True)
|
||||
show_panel(norm)
|
||||
|
||||
dlg = App.getInstance().getDevicePanelManager().getPanelDialog("norm");
|
||||
dlg.setSize(800,800)
|
||||
|
||||
@@ -4,9 +4,7 @@ if get_exec_pars().source == CommandSource.ui:
|
||||
METHOD = "Two_Pol"
|
||||
SWITCHING = "Tune_Detune"
|
||||
MEASUREMENTS = 4
|
||||
CONTRAST = 0
|
||||
AUTO_SAVE = True
|
||||
AS_SEQUENCE = False
|
||||
EXPOSURE_1 = 1.0
|
||||
AVERAGE_1 = 2.0
|
||||
ENERGY_1 = 850.0
|
||||
@@ -17,7 +15,7 @@ if get_exec_pars().source == CommandSource.ui:
|
||||
POLARIZATION_2 = "Circ_Minus"
|
||||
␍
|
||||
|
||||
DRY_RUN=True
|
||||
DRY_RUN=False
|
||||
SHOW_IMAGES = True
|
||||
|
||||
ID = get_setting("ID")
|
||||
@@ -86,22 +84,20 @@ if not DRY_RUN:
|
||||
|
||||
active_id = 1
|
||||
current_pol=None
|
||||
polID1=get_id_pol(1)
|
||||
polID2=get_id_pol(2)
|
||||
id_off_1 = get_id_offset(1)
|
||||
id_off_2 = get_id_offset(2)
|
||||
pol_id1=POL_IDS[get_setting("POL_ID_1")]
|
||||
pol_id2=POL_IDS[get_setting("POL_ID_2")]
|
||||
|
||||
|
||||
#rbkEnergy=energy_rbk.read()
|
||||
if METHOD == "Two_Pol":
|
||||
if ID == "ID1":
|
||||
current_pol = polID1
|
||||
current_pol = pol_id1
|
||||
elif ID == "ID2":
|
||||
current_pol = polID2
|
||||
current_pol = pol_id2
|
||||
elif ID == "ID1_ID2":
|
||||
current_pol=polID1
|
||||
current_pol=pol_id1
|
||||
if SWITCHING == "Tune_Detune":
|
||||
put_id_offset(2, id_off_2-40) #detuneID2
|
||||
put_id_offset(1, id_off_1) #tuneID2
|
||||
tune_detune(1) #Tune ID1, Detune ID2
|
||||
wait_channel("X11PHS:alldone", 1)
|
||||
|
||||
def imageinfo(info):
|
||||
@@ -111,7 +107,7 @@ def imageinfo(info):
|
||||
|
||||
#Beamline setting
|
||||
def nextpol():
|
||||
global current_pol, polID1, polID2, active_id
|
||||
global current_pol, pol_id1, pol_id2, active_id
|
||||
if SWITCHING == "Normal":
|
||||
if current_pol==1: return 2 #circ+ -> circ-
|
||||
if current_pol==2: return 1 #circ+ -> circ-
|
||||
@@ -119,8 +115,8 @@ def nextpol():
|
||||
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 active_id==1: return polID2
|
||||
if active_id==2: return polID1
|
||||
if active_id==1: return pol_id2
|
||||
if active_id==2: return pol_id1
|
||||
|
||||
|
||||
def switch_pol():
|
||||
@@ -136,15 +132,12 @@ def switch_pol():
|
||||
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, id_off_1-40) #detuneID1
|
||||
put_id_offset(2, id_off_2) #tuneID2
|
||||
elif SWITCHING == "Tune_Detune":
|
||||
if active_id==1:
|
||||
active_id=2
|
||||
else:
|
||||
put_id_offset(2, id_off_2-40) #detuneID2
|
||||
put_id_offset(1, id_off_1) #tuneID2
|
||||
active_id=1
|
||||
tune_detune(active_id)
|
||||
time.sleep(1.0)
|
||||
wait_channel("X11PHS:alldone", 1)
|
||||
|
||||
@@ -187,23 +180,21 @@ try:
|
||||
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.append(average_frames(ret) if AVERAGE[i] > 1 else ret[0])
|
||||
imageinfo("I")
|
||||
save_image_file(frames[i], cycle, i)
|
||||
|
||||
print "--- Grabing frames step=", i
|
||||
ret = grab_frames(image, AVERAGE[i], roi=None, wait_next=True)
|
||||
frames.append(average_frames(ret) if AVERAGE[i] > 1 else ret[0])
|
||||
imageinfo("I")
|
||||
save_image_file(frames[i], cycle, i)
|
||||
|
||||
if METHOD == "Take_Image":
|
||||
break
|
||||
|
||||
|
||||
if METHOD == "Two_Pol":
|
||||
print "--- Switching polatization..."
|
||||
switch_pol()
|
||||
if METHOD == "Two_Energies":
|
||||
if METHOD == "Two_Energies":
|
||||
print "--- Switching energy..."
|
||||
change_energy(ENERGY_2)
|
||||
time.sleep(1)
|
||||
|
||||
@@ -223,6 +214,7 @@ try:
|
||||
# Auto average and save
|
||||
|
||||
if MEASUREMENTS > 1 and AUTO_SAVE == 1:
|
||||
print "--- Averaging..."
|
||||
for i in range(len(frames)):
|
||||
measures = []
|
||||
for cycle in range(1, MEASUREMENTS + 1):
|
||||
|
||||
@@ -55,8 +55,10 @@ def grab_image(position, scan):
|
||||
frames = grab_frames(image, AVERAGE, roi=None, wait_next=True)
|
||||
av = average_frames(frames)
|
||||
if SAVE_IMAGES:
|
||||
Scan_Nr = (scan.recordIndex-1)/NUMBER_SCANS
|
||||
filename = get_exec_pars().path + "/" + ("%02d" % Scan_Nr) + "/s" + "{seq}%03d" + "_" + ("%03d.tif" % scan.recordIndex)
|
||||
#Scan_Nr = (scan.recordIndex-1)/NUMBER_SCANS
|
||||
#filename = get_exec_pars().path + "/" + ("%02d" % Scan_Nr) + "/s" + "{seq}%03d" + "_" + ("%03d.tif" % scan.recordIndex)
|
||||
filename = get_exec_pars().path + "/" + str(scan.currentPass) + "/s" + "{seq}%03d" + "_" + ("%03d.tif" % scan.recordIndex)
|
||||
filename = get_context().setup.expandPath(filename)
|
||||
print filename
|
||||
save_as_tiff(av, filename)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#If running from editor
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
ID = "ID2"
|
||||
ID = "ID2" #"ID1_ID2"
|
||||
ENERGY = 805
|
||||
POL_ID_1 = "Circ_Plus"
|
||||
ALPHA_ID_1 = 0.0
|
||||
HARMONIC_ID_1 = 1
|
||||
@@ -10,8 +11,23 @@ if get_exec_pars().source == CommandSource.ui:
|
||||
HARMONIC_ID_2 = 1
|
||||
OFFSET_ID_2 = 0.0
|
||||
|
||||
DRY_RUN=False
|
||||
|
||||
|
||||
set_setting("ID", ID)
|
||||
set_setting("ENERGY", ENERGY)
|
||||
set_setting("POL_ID_1", POL_ID_1)
|
||||
set_setting("ALPHA_ID_1", ALPHA_ID_1)
|
||||
set_setting("HARMONIC_ID_1", HARMONIC_ID_1)
|
||||
set_setting("OFFSET_ID_1", OFFSET_ID_1)
|
||||
set_setting("POL_ID_2", POL_ID_2)
|
||||
set_setting("ALPHA_ID_2", ALPHA_ID_2)
|
||||
set_setting("HARMONIC_ID_2", HARMONIC_ID_2)
|
||||
set_setting("OFFSET_ID_2", OFFSET_ID_2)
|
||||
|
||||
if DRY_RUN:
|
||||
abort()
|
||||
|
||||
|
||||
if ID=='ID1':
|
||||
caput('X11PHS-E:OPT',1)
|
||||
@@ -20,31 +36,36 @@ elif ID=='ID2':
|
||||
elif ID =='ID1_ID2':
|
||||
caput('X11PHS-E:OPT',3)
|
||||
|
||||
|
||||
if ID == "ID1":
|
||||
#current_pol=POL_IDS[POL_ID_1] #get_id_pol(1)
|
||||
put_id_pol(1,POL_ID_1)
|
||||
caput('X11MA-ID2-GAP:SET',100) #open Gap ID2
|
||||
caput('X11MA-ID1:HARMONIC', HARMONIC_ID_1)
|
||||
caput('X11MA-ID1:HARMONIC', int(HARMONIC_ID_1))
|
||||
put_id_offset(1, float(OFFSET_ID_1)) #offset on ID1
|
||||
|
||||
elif ID == "ID2":
|
||||
#current_pol=POL_IDS[POL_ID_2]#get_id_pol(2)
|
||||
put_id_pol(2,POL_ID_2)
|
||||
caput('X11MA-ID1-GAP:SET',100) #open Gap ID1
|
||||
caput('X11MA-ID2:HARMONIC', HARMONIC_ID_2)
|
||||
caput('X11MA-ID2:HARMONIC', int(HARMONIC_ID_2))
|
||||
put_id_offset(2, float(OFFSET_ID_2)) #offset on ID2
|
||||
|
||||
elif ID == "ID1_ID2":
|
||||
#polID1=POL_IDS[POL_ID_1]
|
||||
#polID2=POL_IDS[POL_ID_2]
|
||||
put_id_pol(1,POL_ID_1)
|
||||
put_id_pol(2,POL_ID_2)
|
||||
#current_pol=polID1
|
||||
caput('X11MA-ID1:HARMONIC', HARMONIC_ID_1)
|
||||
caput('X11MA-ID2:HARMONIC', HARMONIC_ID_2)
|
||||
caput('X11MA-ID1:HARMONIC', int(HARMONIC_ID_1))
|
||||
caput('X11MA-ID2:HARMONIC', int(HARMONIC_ID_2))
|
||||
put_id_offset(1, float(OFFSET_ID_1)) #offset on ID1
|
||||
put_id_offset(2, float(OFFSET_ID_2)) #offset on ID2
|
||||
|
||||
|
||||
put_id_offset(1, OFFSET_ID_1) #offset on ID1
|
||||
put_id_offset(2, OFFSET_ID_2) #offset on ID2
|
||||
|
||||
#wait_channel("X11PHS:alldone", 1)
|
||||
|
||||
energy.write(ENERGY)
|
||||
wait_channel("X11PHS:alldone", 1)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#Create a listener to the positioner checking the setpoint before each command is sent.
|
||||
class ListenerAO (DeviceListener):
|
||||
def onStateChanged(self, device, state, former):
|
||||
pass
|
||||
def onValueChanged(self, device, value, former):
|
||||
print "Value to: " + str(value)
|
||||
def onCacheChanged(self, device, value, former, timestamp,value_changed):
|
||||
print "Cache to: " + str(value),
|
||||
|
||||
listenerAO = ListenerAO()
|
||||
|
||||
eiger.dataArray.addListener(listenerAO)
|
||||
|
||||
|
||||
eiger.dataArray.removeListener(listenerAO)
|
||||
|
||||
Reference in New Issue
Block a user