This commit is contained in:
gac-x11ma
2020-02-04 12:08:13 +01:00
parent a0b61220e9
commit 27152efce8
9 changed files with 243 additions and 233 deletions

View File

@@ -99,7 +99,8 @@ def grab_frame(source, roi=None, wait_next=False, rmv_outliers=True):
data = data.getRoi(Rectangle(roi[0], roi[1], roi[2], roi[3]))
#ret = load_image(img)
if rmv_outliers:
data = remove_outliers(data)
#data = remove_outliers(data)
data.threshold(1e9, False, None)
return data
def grab_frames(source, samples, roi=None, wait_next=False, sleep=0, rmv_outliers=True):
@@ -125,6 +126,7 @@ def average_frames(frames):
ret.div(len(frames))
return ret
"""
def remove_outliers(imgdata, threshold = 1e9, replace_value=None):
if replace_value is None:
if str(imgdata.getType()) in ('float', 'double'):
@@ -136,7 +138,8 @@ def remove_outliers(imgdata, threshold = 1e9, replace_value=None):
for j in range(data.height):
if data.getElementDbl(j,i, False) >=threshold:
data.setElement(j*data.width + i, replace_value)
return data
return data
"""
def save_as_tiff(data, filename, check=False, show = False):
if type(data) == Data:

View File

@@ -1,5 +1,5 @@
POL_IDS={ "Circ_Plus": 1, "Circ_Minus": 2, "Lin_Hor":3, "Lin_Ver": 4}
POL_IDS={ "Circ_Plus": 1, "Circ_Minus": 2, "Lin_Hor":3, "Lin_Ver": 4, "Lin": 5}
@@ -31,13 +31,23 @@ def get_id_pol(id, as_string=False):
# 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
#ret = caget ("X11MA-ID1:MODE" if id==1 else "X11MA-ID2:MODE", 's' if as_string else 'i')
ret = caget ("X11MA-ID1:MODE" if id==1 else "X11MA-ID2:MODE", 'i')
if ret==0:
#linear mode
alpha = get_alpha_id(id)
if alpha==0 :
ret = 3
elif alpha==90:
ret = 4
else:
ret = 5
if as_string:
for (k,v) in POL_IDS.items():
if v==ret:
return k
return "Unknown"
return ret
def get_alpha_id(id):
if id<1 or id>2: raise Exception("Invalid id")
@@ -66,7 +76,11 @@ def put_id_pol(id, pol, alpha=None):
pv1="X11MA-ID1:MODE" if (id==1) else "X11MA-ID2:MODE"
pv2="X11MA-ID1:ALPHA" if (id==1) else "X11MA-ID2:ALPHA"
if is_string(pol):
pol=POL_IDS[v]
if pol == 1:
caput(pv1,1)
elif pol == 2:

View File

@@ -1,19 +1,8 @@
#If running from editor
if get_exec_pars().source == CommandSource.ui:
ID = "ID1_ID2"
SWITCHING = "Tune_Detune"
POL_ID_1 = "Circ_Plus"
ALPHA_ID_1 = 0.0
HARMONIC_ID_1 = 1
OFFSET_ID_1 = 0.0
POL_ID_2 = "Circ_Minus"
ALPHA_ID_2 = 0.0
HARMONIC_ID_2 = 1
OFFSET_ID_2 = 0.0
ROI = {"ROI1": [50,50,200, 100]}
METHOD = "Two_Pol"
SWITCHING = "Tune_Detune"
MEASUREMENTS = 4
CONTRAST = 0
AUTO_SAVE = True
@@ -27,10 +16,12 @@ if get_exec_pars().source == CommandSource.ui:
ENERGY_2= 900.0
POLARIZATION_2 = "Circ_Minus"
DRY_RUN=True
SHOW_IMAGES = True
ID = get_setting("ID")
EXPOSURE = [EXPOSURE_1, EXPOSURE_2]
AVERAGE = [int(AVERAGE_1), int(AVERAGE_2)]
@@ -92,40 +83,26 @@ def assert_status_ok():
#Initialize vartiables
if not DRY_RUN:
open_vg10()
if ID=='ID1':
caput('X11PHS-E:OPT',1)
elif ID=='ID2':
caput('X11PHS-E:OPT',2)
elif ID =='ID1_ID2':
caput('X11PHS-E:OPT',3)
active_id = 1
current_pol=None
polID1=None
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)
#rbkEnergy=energy_rbk.read()
if METHOD == "Two_Pol":
if not DRY_RUN:
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)
if METHOD == "Two_Pol":
if ID == "ID1":
current_pol = polID1
elif ID == "ID2":
current_pol = polID2
elif ID == "ID1_ID2":
current_pol=polID1
if SWITCHING == "Tune_Detune":
put_id_offset(2, id_off_2-40) #detuneID2
put_id_offset(1, id_off_1) #tuneID2
wait_channel("X11PHS:alldone", 1)
def imageinfo(info):
@@ -161,20 +138,13 @@ def switch_pol():
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
if active_id ==1:
put_id_offset(1, id_off_1-40) #detuneID1
put_id_offset(2, id_off_2) #tuneID2
active_id=2
else:
put_id_offset(2, OFFSET_ID_2-40) #detuneID2
else:
put_id_offset(2, id_off_2-40) #detuneID2
put_id_offset(1, id_off_1) #tuneID2
active_id=1
elif SWITCHING == "Chopper":
if active_id == 1:
active_id = 2
set_chopper(1)
else:
active_id = 1
active_id=1
time.sleep(1.0)
wait_channel("X11PHS:alldone", 1)
@@ -187,8 +157,6 @@ def change_energy(v):
put_energy(v)
def save_image_file(frame, cycle=-1, frame_index=0):
if SHOW_IMAGES:

View File

@@ -1,17 +1,6 @@
#If running from editor
if get_exec_pars().source == CommandSource.ui:
ID = "ID2"
SWITCHING = "Normal"
POL_ID_1 = "Circ_Plus"
ALPHA_ID_1 = 0.0
HARMONIC_ID_1 = 1
OFFSET_ID_1 = 0.0
POL_ID_2 = "Circ_Minus"
ALPHA_ID_2 = 0.0
HARMONIC_ID_2 = 1
OFFSET_ID_2 = 0.0
ROI = {"Region1": [10,5,20, 10], "Region2": [20,15,20, 10]}
SAVE_SPECTRUM = True
SAVE_IMAGES = False
WITH_I0 = True
@@ -83,24 +72,15 @@ set_device_alias(averager, "Image") #Set display name
sensors.append(averager) #sensors.append(eiger.getDataMatrix())
#Initialize vartiables
open_vg10()
if not DRY_RUN:
open_vg10()
if ID=='ID1':
caput('X11PHS-E:OPT',1)
elif ID=='ID2':
caput('X11PHS-E:OPT',2)
elif ID =='ID1_ID2':
caput('X11PHS-E:OPT',3)
put_id_offset(1, OFFSET_ID_1) #offset on ID1
put_id_offset(2, 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
active_id = 1
current_pol=None
polID1=None
polID2=None
"""
if ID == "ID1":
current_pol=POL_IDS[POL_ID_1] #get_id_pol(1)
put_id_pol(1,current_pol)
@@ -116,6 +96,7 @@ elif ID == "ID1_ID2":
put_id_pol(1,polID1)
put_id_pol(2,polID2)
wait_channel("X11PHS:alldone", 1)
"""
try:
#tscan(rois, 10, 0.1, format="csv", before_read=grab_image, passes = NUMBER_SCANS, tag=tag)
@@ -124,6 +105,7 @@ finally:
if AVERAGE>1:
for i in range(len(rois)):
rois[i].parent.monitored = False # Remove listeners on the image
close_vg10()
if not DRY_RUN:
close_vg10()
eiger.grabMode=eiger.GrabMode.Continuous
eiger.start()

View File

@@ -0,0 +1,52 @@
#If running from editor
if get_exec_pars().source == CommandSource.ui:
ID = "ID2"
POL_ID_1 = "Circ_Plus"
ALPHA_ID_1 = 0.0
HARMONIC_ID_1 = 1
OFFSET_ID_1 = 0.0
POL_ID_2 = "Circ_Minus"
ALPHA_ID_2 = 0.0
HARMONIC_ID_2 = 1
OFFSET_ID_2 = 0.0
set_setting("ID", ID)
if ID=='ID1':
caput('X11PHS-E:OPT',1)
elif ID=='ID2':
caput('X11PHS-E:OPT',2)
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)
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)
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)
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)