Included Memory Shift
This commit is contained in:
Executable → Regular
+2
-2
@@ -33,9 +33,9 @@ def update_roi():
|
||||
cur_data = image.data
|
||||
calc_roi = Roi(ROI.x,ROI.y,ROI.width, ROI.height)
|
||||
try:
|
||||
xoff, yoff, error, diffphase = calculate_shift(former_data,cur_data, calc_roi)
|
||||
xoff, yoff, error, diffphase, _ = calculate_shift(former_data,cur_data, calc_roi)
|
||||
print "Calculated shift: ", xoff, yoff, error, diffphase
|
||||
if (0<abs(xoff) < MAX_SHIFT) and (0<abs(yoff) < MAX_SHIFT):
|
||||
if (abs(xoff) <= MAX_SHIFT) and (abs(yoff) <= MAX_SHIFT):
|
||||
x,y=int(ROI.x - xoff), int(ROI.y - yoff)
|
||||
print "Updating ROI location to ", x, y
|
||||
ROI.setLocation(x,y)
|
||||
|
||||
@@ -272,7 +272,6 @@ def stop_eiger():
|
||||
if started:
|
||||
eiger.stop()
|
||||
eiger.grabMode=eiger.GrabMode.Single
|
||||
eiger.stop()
|
||||
eiger.waitReady(5000)
|
||||
else:
|
||||
eiger.grabMode=eiger.GrabMode.Single
|
||||
|
||||
@@ -258,7 +258,7 @@ def switch_pol():
|
||||
put_id_pol(1,newpol)
|
||||
elif _switching_id == "ID2":
|
||||
put_id_pol(2,newpol)
|
||||
elif ID == "ID1_ID2":
|
||||
elif ID == "PGM_ID1_ID2":
|
||||
if _switching_type == "Normal":
|
||||
put_id_pol(1, newpol)
|
||||
put_id_pol(2, newpol)
|
||||
|
||||
@@ -638,5 +638,10 @@ def calculate_shift(ref,img, roi, g_sigma=3.0, upscale_factor=100, max_error=2.0
|
||||
raise Exception("Bad image registration error: " + str(error))
|
||||
if math.isnan(diffphase) or abs(diffphase)> max_diffphase:
|
||||
raise Exception("Bad image registration phase difference: " + str(diffphase))
|
||||
return xoff, yoff, error, diffphase
|
||||
return xoff, yoff, error, diffphase, shifts
|
||||
|
||||
def apply_shift(img, shifts):
|
||||
img = to_ip(img)
|
||||
stack = create_stack([img,])
|
||||
r=translate(stack, shifts)
|
||||
return r
|
||||
+9
-6
@@ -466,13 +466,13 @@ def assert_beamline_ok():
|
||||
checkbeamline=0
|
||||
message=[ "PLC error","Encoder error", "Feedforward error","Operator control", "Moving timeout", "Interlock"]
|
||||
ID = get_setting("ID")
|
||||
if ID == "ID1":
|
||||
if ID == "PGM_ID1":
|
||||
id1_status=get_id_status(1)
|
||||
id2_status=0
|
||||
elif ID == "ID2":
|
||||
elif ID == "PGM_ID2":
|
||||
id1_status=0
|
||||
id2_status=get_id_status(2)
|
||||
if ID == "ID1_ID2":
|
||||
if ID == "PGM_ID1_ID2":
|
||||
id1_status=get_id_status(1)
|
||||
id2_status=get_id_status(2)
|
||||
if id1_status >= 1:
|
||||
@@ -752,11 +752,14 @@ def apply_beamline_setup(id,en=None,pol1=None,alp1=None,har1=None,off1=None,pol2
|
||||
# Monochromator part
|
||||
if grat is not None:
|
||||
if grat=='G1_300':
|
||||
Grating.write(0)
|
||||
Grating.write("0")
|
||||
Grating_ch.write("0")
|
||||
elif grat=='G2_1200':
|
||||
Grating.write(1)
|
||||
Grating.write("1")
|
||||
Grating_ch.write("1")
|
||||
elif grat =='G3_600':
|
||||
Grating.write(2)
|
||||
Grating.write("2")
|
||||
Grating_ch.write("2")
|
||||
if order is not None:
|
||||
DiffOrd.write(order)
|
||||
if Cff is not None:
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
#Sample 01 - RW-2-4
|
||||
open_vg13()
|
||||
|
||||
TRX.write(1.41)
|
||||
TRZ.write(11.9)
|
||||
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
##Survey
|
||||
#nr_loops=1
|
||||
#for i in range(nr_loops):
|
||||
# caput('X11MA-KEI10:RANGE', 6)
|
||||
# caput('X11MA-KEI11:RANGE', 7)
|
||||
# caput('X11MA-KEI12:RANGE', 8)
|
||||
# otf2(start=500, end=900, time=4, delay=10, mode='LINEAR', alpha = 0.0, offset=-3.8, name='RW-2-4_Survey')
|
||||
|
||||
#Nickel L edge
|
||||
nr_loops=1
|
||||
for i in range(nr_loops):
|
||||
caput('X11MA-KEI10:RANGE', 6)
|
||||
caput('X11MA-KEI11:RANGE', 7)
|
||||
caput('X11MA-KEI12:RANGE', 9)
|
||||
otf2(start=845, end=885, time=2, delay=10, mode='LINEAR', alpha = 0.0, offset=-3.8, name='RW-2-4_Ni')
|
||||
|
||||
#Cobalt L edge
|
||||
nr_loops=1
|
||||
for i in range(nr_loops):
|
||||
caput('X11MA-KEI10:RANGE', 6)
|
||||
caput('X11MA-KEI11:RANGE', 7)
|
||||
caput('X11MA-KEI12:RANGE', 9)
|
||||
otf2(start=772, end=805, time=2, delay=10, mode='LINEAR', alpha = 0.0, offset=-3.8, name='RW-2-4_Co')
|
||||
|
||||
#Manganese L edge
|
||||
nr_loops=1
|
||||
for i in range(nr_loops):
|
||||
caput('X11MA-KEI10:RANGE', 6)
|
||||
caput('X11MA-KEI11:RANGE', 7)
|
||||
caput('X11MA-KEI12:RANGE', 9)
|
||||
otf2(start=630, end=670, time=2, delay=10, mode='LINEAR', alpha = 0.0, offset=-3.8, name='RW-2-4_Mn')
|
||||
|
||||
|
||||
#Oxygen K edge
|
||||
nr_loops=1
|
||||
for i in range(nr_loops):
|
||||
caput('X11MA-KEI10:RANGE', 6)
|
||||
caput('X11MA-KEI11:RANGE', 7)
|
||||
caput('X11MA-KEI12:RANGE', 8)
|
||||
otf2(start=520, end=570, time=2, delay=10, mode='LINEAR', alpha = 0.0, offset=-3.8, name='RW-2-4_O')
|
||||
|
||||
#Carbon K edge
|
||||
nr_loops=1
|
||||
for i in range(nr_loops):
|
||||
caput('X11MA-KEI10:RANGE', 6)
|
||||
caput('X11MA-KEI11:RANGE', 7)
|
||||
caput('X11MA-KEI12:RANGE', 9)
|
||||
otf2(start=270, end=320, time=2, delay=10, mode='LINEAR', alpha = 0.0, offset=-3.8, name='RW-2-4_C')#
|
||||
|
||||
#Sample 03 - HR016
|
||||
#open_vg13()
|
||||
#
|
||||
#TRX.write(11.95)
|
||||
#TRZ.write(13.71)
|
||||
#
|
||||
#
|
||||
#time.sleep(1)
|
||||
##
|
||||
###Survey
|
||||
##nr_loops=1
|
||||
##for i in range(nr_loops):
|
||||
## caput('X11MA-KEI10:RANGE', 6)
|
||||
## caput('X11MA-KEI11:RANGE', 7)
|
||||
## caput('X11MA-KEI12:RANGE', 8)
|
||||
## otf2(start=500, end=900, time=4, delay=10, mode='LINEAR', alpha = 0.0, offset=0.0, name='HR016_Survey')
|
||||
#
|
||||
###Nickel L edge
|
||||
##nr_loops=1
|
||||
##for i in range(nr_loops):
|
||||
## caput('X11MA-KEI10:RANGE', 6)
|
||||
## caput('X11MA-KEI11:RANGE', 7)
|
||||
## caput('X11MA-KEI12:RANGE', 9)
|
||||
## otf2(start=845, end=885, time=2, delay=10, mode='LINEAR', alpha = 0.0, offset=0.0, name='HR016_Ni')
|
||||
#
|
||||
##Manganese L edge
|
||||
#nr_loops=1
|
||||
#for i in range(nr_loops):
|
||||
# caput('X11MA-KEI10:RANGE', 6)
|
||||
# caput('X11MA-KEI11:RANGE', 7)
|
||||
# caput('X11MA-KEI12:RANGE', 8)
|
||||
# otf2(start=630, end=670, time=2, delay=10, mode='LINEAR', alpha = 0.0, offset=-3.8, name='HR016_Mn')
|
||||
#
|
||||
#
|
||||
##Oxygen K edge
|
||||
#nr_loops=1
|
||||
#for i in range(nr_loops):
|
||||
# caput('X11MA-KEI10:RANGE', 6)
|
||||
# caput('X11MA-KEI11:RANGE', 7)
|
||||
# caput('X11MA-KEI12:RANGE', 8)
|
||||
# otf2(start=520, end=570, time=2, delay=10, mode='LINEAR', alpha = 0.0, offset=-3.8, name='HR016_O')
|
||||
#
|
||||
##Sn M edge
|
||||
#nr_loops=1
|
||||
#for i in range(nr_loops):
|
||||
# caput('X11MA-KEI10:RANGE', 6)
|
||||
# caput('X11MA-KEI11:RANGE', 7)
|
||||
# caput('X11MA-KEI12:RANGE', 9)
|
||||
# otf2(start=485, end=506, time=2, delay=10, mode='LINEAR', alpha = 0.0, offset=-3.8, name='HR016_Sn')
|
||||
#
|
||||
#
|
||||
##Carbon K edge
|
||||
#nr_loops=1
|
||||
#for i in range(nr_loops):
|
||||
# caput('X11MA-KEI10:RANGE', 6)
|
||||
# caput('X11MA-KEI11:RANGE', 7)
|
||||
# caput('X11MA-KEI12:RANGE', 9)
|
||||
# otf2(start=270, end=320, time=2, delay=10, mode='LINEAR', alpha = 0.0, offset=-3.8, name='HR016_C')
|
||||
#
|
||||
#time.sleep(1)
|
||||
@@ -5,6 +5,7 @@ if (get_exec_pars().source == CommandSource.ui) and (get_exec_pars().script == "
|
||||
SEQUENCE = "A"
|
||||
MEASUREMENTS = 4
|
||||
AUTO_SAVE = True
|
||||
DRIFT_CORRECTION = True
|
||||
EXPOSURE = 1.0
|
||||
AVERAGE = 2.0
|
||||
ENERGY_1 = 850.0
|
||||
@@ -18,7 +19,10 @@ print "Starting 2Img: ", METHOD, SWITCHING, SEQUENCE , MEASUREMENTS, AUTO_SAVE,
|
||||
#SEQUENCE = "B": C+,C-,C+,C-,C+,-;C+,C-.
|
||||
|
||||
SHOW_IMAGES = True
|
||||
SAVE_DIAGS = True
|
||||
SAVE_DIAGS = True
|
||||
DEFAULT_ROI = Rectangle(128,128,256,256)
|
||||
|
||||
#DEFAULT_ROI = Rectangle(0,0,512,512)
|
||||
|
||||
|
||||
ID = get_setting("ID")
|
||||
@@ -32,7 +36,7 @@ if METHOD == "Two_Energies":
|
||||
raise Exception("Bad energy argument")
|
||||
|
||||
start = time.time()
|
||||
threads = []
|
||||
threads = []
|
||||
image_drift=None
|
||||
|
||||
#path = "{data}/{year}_{month}/{date}" + "/" + "{seq}%03d_" + METHOD
|
||||
@@ -44,7 +48,7 @@ set_exec_pars(name=METHOD, path = data_path, format="txt", layout="table", open=
|
||||
|
||||
#get_context().incrementFileSequentialNumber()
|
||||
|
||||
|
||||
|
||||
def get_image_file_name(cycle=-1, frame_index=0, short_name=False, shifted=False):
|
||||
global max_index
|
||||
if (METHOD == "Two_Pol") and (SEQUENCE == "A") and (frame_index<2) and ((cycle%2)==0): #Swapped
|
||||
@@ -54,7 +58,10 @@ def get_image_file_name(cycle=-1, frame_index=0, short_name=False):
|
||||
abs_index=run_index + frame_index
|
||||
max_index= max(max_index, frame_index)
|
||||
#prefix = get_context().setup.expandPath("i{date}%02d_{seq}%03d")
|
||||
prefix = get_context().setup.expandPath("i{date}%02d_" + ("%03d" % (abs_index,)))
|
||||
prefix = get_context().setup.expandPath("i{date}%02d_" + ("%03d" % (abs_index,)))
|
||||
|
||||
if (shifted):
|
||||
prefix = prefix + "_shifted"
|
||||
|
||||
if cycle < 0:
|
||||
ret = root + prefix + ".tif"
|
||||
@@ -105,10 +112,22 @@ def save_image_file(frame, cycle=-1, frame_index=0):
|
||||
p=plots[0]
|
||||
p.getAxis(p.AxisId.Y).setInverted(True)
|
||||
if AUTO_SAVE and (frame is not None):
|
||||
filename = get_image_file_name(cycle, frame_index)
|
||||
filename = get_image_file_name(cycle, frame_index)
|
||||
metadata = get_diags() if SAVE_DIAGS else {}
|
||||
threads.append(save_as_tiff(frame, filename, check=False, parallel=True, metadata=metadata))
|
||||
|
||||
log(filename)
|
||||
print filename
|
||||
|
||||
if DRIFT_CORRECTION:
|
||||
filename = get_image_file_name(cycle, frame_index, shifted=True)
|
||||
if image_drift is not None:
|
||||
print "->", filename
|
||||
shifted_frame = apply_shift(frame, image_drift)
|
||||
threads.append(save_as_tiff(shifted_frame, filename, check=False, parallel=True, metadata=metadata))
|
||||
elif frame_index==0:
|
||||
print "->", filename
|
||||
threads.append(save_as_tiff(frame, filename, check=False, parallel=True, metadata=metadata))
|
||||
|
||||
# log("SV:"+Format(startvoltage,"0.000")+" OB:"+Format(objective,"0.00")+" ST:"+Format(LEEMtemp,"0.0"))
|
||||
|
||||
@@ -117,10 +136,11 @@ run_index = get_context().getDaySequentialNumber()
|
||||
run_index = get_context().getDaySequentialNumber()
|
||||
print " ---- Run index : %d" %(run_index,)
|
||||
max_index=0
|
||||
|
||||
|
||||
if DRIFT_CORRECTION:
|
||||
roi = get_focus_scan_roi()
|
||||
calc_roi = None if (roi is None) else Roi(roi.x,roi.y,roi.width, roi.height)
|
||||
roi = get_focus_scan_roi()
|
||||
if roi is None:
|
||||
roi = DEFAULT_ROI
|
||||
calc_roi = Roi(roi.x,roi.y,roi.width, roi.height)
|
||||
ref_image = None # grab_frame(image, None, True)
|
||||
|
||||
@@ -144,7 +164,25 @@ try:
|
||||
av = average_eiger_frames(AVERAGE, roi=None, wait_next=True)
|
||||
#print "--- Time: " + str(time.time() - s)
|
||||
#time.sleep(1) #added by Armin
|
||||
frames.append(av)
|
||||
frames.append(av)
|
||||
|
||||
if (i==0) and DRIFT_CORRECTION and (calc_roi is not None):
|
||||
if ref_image is None:
|
||||
ref_image = frames[0]
|
||||
print "-> Saved shift ref image"
|
||||
else:
|
||||
try:
|
||||
cur_image = frames[0]
|
||||
xoff, yoff, error, diffphase, image_drift = calculate_shift(ref_image,cur_image, calc_roi)
|
||||
if (abs(xoff) <= MAX_SHIFT) and (abs(yoff) <= MAX_SHIFT):
|
||||
print "-> Calculated shift: ", xoff, yoff, error, diffphase
|
||||
else:
|
||||
print "-> Error: shift too big:", xoff, yoff
|
||||
image_drift = None
|
||||
except:
|
||||
print "-> Error calculating shift: " + str(sys.exc_info()[1])
|
||||
image_drift = None
|
||||
|
||||
imageinfo("I")
|
||||
save_image_file(frames[i], cycle, i)
|
||||
if METHOD == "Take_Image":
|
||||
@@ -164,18 +202,7 @@ try:
|
||||
print "Divide second frame by first"
|
||||
frames.append(frames[1].copy())
|
||||
frames[2].div(frames[0])
|
||||
save_image_file(frames[2],cycle, 2)
|
||||
if CORRECT_DRIFTS and (calc_roi is not None):
|
||||
if ref_image is None:
|
||||
ref_image = frames[0]
|
||||
print "-> Saved shift ref image"
|
||||
else:
|
||||
cur_image = frames[0]
|
||||
xoff, yoff, error, diffphase = calculate_shift(ref_image,cur_image, calc_roi)
|
||||
if (0<abs(xoff) < MAX_SHIFT) and (0<abs(yoff) < MAX_SHIFT):
|
||||
print "-> Calculated shift: ", xoff, yoff, error, diffphase
|
||||
else:
|
||||
print "-> Error - shift too big:", xoff, yoff
|
||||
save_image_file(frames[2],cycle, 2)
|
||||
|
||||
# objective = getObjective()
|
||||
# temp = getLEEMtemp()
|
||||
|
||||
@@ -166,8 +166,8 @@ try:
|
||||
ref_image = frames[0]
|
||||
print "-> Saved shift ref image"
|
||||
else:
|
||||
cur_image = frames[0]
|
||||
xoff, yoff, error, diffphase = calculate_shift(ref_image,cur_image, calc_roi)
|
||||
cur_image = frames[0]
|
||||
xoff, yoff, error, diffphase, _ = calculate_shift(ref_image,cur_image, calc_roi)
|
||||
if (abs(xoff) <= MAX_SHIFT) and (abs(yoff) <= MAX_SHIFT):
|
||||
print "-> Calculated shift: ", xoff, yoff, error, diffphase
|
||||
else:
|
||||
|
||||
@@ -160,8 +160,8 @@ try:
|
||||
ref_image = frames[0]
|
||||
print "-> Saved shift ref image"
|
||||
else:
|
||||
cur_image = frames[0]
|
||||
xoff, yoff, error, diffphase = calculate_shift(ref_image,cur_image, calc_roi)
|
||||
cur_image = frames[0]
|
||||
xoff, yoff, error, diffphase, _ = calculate_shift(ref_image,cur_image, calc_roi)
|
||||
if (abs(xoff) <= MAX_SHIFT) and (abs(yoff) <= MAX_SHIFT):
|
||||
print "-> Calculated shift: ", xoff, yoff, error, diffphase
|
||||
else:
|
||||
|
||||
@@ -110,9 +110,9 @@ def update_roi_pos(cur_data, former_data):
|
||||
roi=get_focus_scan_roi()
|
||||
calc_roi = Roi(roi.x,roi.y,roi.width, roi.height)
|
||||
try:
|
||||
xoff, yoff, error, diffphase = calculate_shift(former_data,cur_data, calc_roi)
|
||||
xoff, yoff, error, diffphase, _ = calculate_shift(former_data,cur_data, calc_roi)
|
||||
print "Calculated shift: ", xoff, yoff, error, diffphase
|
||||
if (0<abs(xoff) < MAX_SHIFT) and (0<abs(yoff) < MAX_SHIFT):
|
||||
if (abs(xoff) <= MAX_SHIFT) and (abs(yoff) <= MAX_SHIFT):
|
||||
x,y=int(roi.x - xoff), int(roi.y - yoff)
|
||||
print "Updating ROI location to ", x, y
|
||||
x,y=max(x,0), max(y,0)
|
||||
|
||||
@@ -11,7 +11,7 @@ if get_exec_pars().source == CommandSource.ui:
|
||||
HARMONIC_ID_2 = 1
|
||||
OFFSET_ID_2 = 0.0
|
||||
GRATING = "G2 1200"
|
||||
DIFF_ORDER = 1
|
||||
DIFF_ORD = 1
|
||||
CFF = 2.250
|
||||
|
||||
set_beamline_setup(ID,ENERGY,POL_ID_1,ALPHA_ID_1,HARMONIC_ID_1,OFFSET_ID_1,POL_ID_2,ALPHA_ID_2,HARMONIC_ID_2,OFFSET_ID_2, GRATING, DIFF_ORDER, CFF)
|
||||
set_beamline_setup(ID,ENERGY,POL_ID_1,ALPHA_ID_1,HARMONIC_ID_1,OFFSET_ID_1,POL_ID_2,ALPHA_ID_2,HARMONIC_ID_2,OFFSET_ID_2, GRATING, DIFF_ORD, CFF)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
##Nickel L edge
|
||||
#nr_loops=2
|
||||
#for i in range(nr_loops)
|
||||
caput('X11MA-KEI10:RANGE', 6)
|
||||
caput('X11MA-KEI11:RANGE', 8)
|
||||
caput('X11MA-KEI12:RANGE', 9)
|
||||
otf2(start=845, end=885, time=2, delay=10, mode='LINEAR', alpha = 0.0, offset=0.0, name='test_Ni')
|
||||
@@ -0,0 +1,135 @@
|
||||
MAX_SHIFT = 300
|
||||
SLEEP_MOVE = 3.0
|
||||
CALIBRATE_RANGE = 20.0
|
||||
|
||||
shift_ref = shift_ref_x = shift_ref_y = None
|
||||
|
||||
def get_image_shift(cur_data=None, former_data=None, roi=None):
|
||||
global shift_ref
|
||||
if roi is None:
|
||||
roi=get_focus_scan_roi()
|
||||
if roi is None:
|
||||
roi = Rectangle(128,128,256,256)
|
||||
if former_data is None:
|
||||
former_data = shift_ref
|
||||
if former_data is None:
|
||||
raise Exception("Image reference not available")
|
||||
if cur_data is None:
|
||||
cur_data = get_cur_data()
|
||||
print roi
|
||||
calc_roi = Roi(roi.x,roi.y,roi.width, roi.height)
|
||||
try:
|
||||
xoff, yoff, error, diffphase, _ = calculate_shift(former_data,cur_data, calc_roi)
|
||||
print "Calculated shift: ", xoff, yoff, error, diffphase
|
||||
if ( abs(xoff) <= MAX_SHIFT) and (abs(yoff) <= MAX_SHIFT):
|
||||
return -xoff, -yoff
|
||||
else:
|
||||
raise Exception("Error - shift too big: " + str(xoff) + "," + str(yoff))
|
||||
except:
|
||||
raise Exception("Error calculating shift: " + str(sys.exc_info()[1]))
|
||||
|
||||
def get_cur_data():
|
||||
return image.data
|
||||
|
||||
|
||||
def grab_shift_ref():
|
||||
global shift_ref, shift_ref_x, shift_ref_y
|
||||
#TODO: read from device
|
||||
obj_align_x.write(0.0);obj_align_y.write(0.0)
|
||||
time.sleep(SLEEP_MOVE)
|
||||
shift_ref_x = shift_ref_y = 0.0
|
||||
|
||||
shift_ref = get_cur_data()
|
||||
|
||||
def calibrate_image_shift():
|
||||
|
||||
|
||||
#TODO: Must find way to read current OBJDX and OBJDY values
|
||||
obj_align_y.write(0.0)
|
||||
obj_align_x.write(-CALIBRATE_RANGE)
|
||||
time.sleep(SLEEP_MOVE)
|
||||
grab_shift_ref()
|
||||
obj_align_x.write(CALIBRATE_RANGE)
|
||||
time.sleep(SLEEP_MOVE)
|
||||
xdx, xdy = get_image_shift()
|
||||
|
||||
obj_align_x.write(0.0)
|
||||
obj_align_y.write(-CALIBRATE_RANGE)
|
||||
time.sleep(SLEEP_MOVE)
|
||||
grab_shift_ref()
|
||||
obj_align_y.write(CALIBRATE_RANGE)
|
||||
time.sleep(SLEEP_MOVE)
|
||||
ydx, ydy = get_image_shift()
|
||||
obj_align_x.write(0.0)
|
||||
obj_align_y.write(0.0)
|
||||
time.sleep(SLEEP_MOVE)
|
||||
|
||||
#TODO calcs are wrong
|
||||
#s = hipot(mdy,mdx) / hipot(idt,idx)
|
||||
# cos beta = mdx/mdy
|
||||
# th alpha = idy/idx
|
||||
#teta = alpha - beta
|
||||
|
||||
|
||||
ixt, iyt = math.hypot(xdx, xdy), math.hypot(ydx, ydy) #image move
|
||||
mdx= mdy = 2 * 10.0 #Total motor move
|
||||
sx,sy = ixt/mdx, iyt/mdy #Scale
|
||||
s = mean ((sx,sy)) #supposing x and y scale equal
|
||||
#angle
|
||||
t1 = math.acos((-xdx/sx)/mdx)
|
||||
t2 = math.asin((xdy/sx)/mdx)
|
||||
t3 = math.acos((ydy/sy)/mdy)
|
||||
t4 = math.asin((ydx/sy)/mdy)
|
||||
theta = mean((t1,t2,t3,t4))
|
||||
|
||||
set_setting("image_shift_angle", theta)
|
||||
set_setting("image_shift_scale", s)
|
||||
print s, math.degrees(theta)
|
||||
|
||||
|
||||
def correct_image_shift():
|
||||
angle = get_setting("image_shift_angle")
|
||||
scale = get_setting("image_shift_scale")
|
||||
if (angle is None) or (scale is None) :
|
||||
raise Exception("Image shift not calibrated")
|
||||
|
||||
angle, scale = float(angle), float(scale)
|
||||
idx, idy = get_image_shift()
|
||||
#idx, idy = idx/scale, idy/scale
|
||||
|
||||
|
||||
it = math.hypot(idx, idy)
|
||||
#mdx = idx / math.cos(angle)
|
||||
#mdy = idy / math.sin(angle)
|
||||
mt = it/scale
|
||||
#mdx = mt * math.sin(angle)
|
||||
#mdy = mt * math.cos(angle)
|
||||
|
||||
try:
|
||||
t=math.atan(idy/idx)
|
||||
t2 = t+angle
|
||||
#mdx = it * math.cos(-t2)
|
||||
#mdy = it * math.sin(-t2)
|
||||
|
||||
mdx = idx * math.cos(t2)
|
||||
mdy = idy * math.sin(t2)
|
||||
#mdx = mt * math.cos(t2)
|
||||
#mdy = mt * math.sin(t2)
|
||||
except:
|
||||
#ZeroDivisionError
|
||||
mdx = mdy = 0.0
|
||||
|
||||
|
||||
mdx=mdx+shift_ref_x
|
||||
mdy=mdy+shift_ref_y
|
||||
print "Moving " , mdx, ", ", mdy
|
||||
|
||||
def translate(shift, image):
|
||||
#shifts= load_shifts("{images}/TestObjAligner/shifts.mat")
|
||||
stack = load_test_stack(show=True)
|
||||
r=translate(stack, shifts, show=True)
|
||||
|
||||
#
|
||||
#grab_shift_ref()
|
||||
#print get_image_shift()
|
||||
#calibrate_image_shift()
|
||||
@@ -6,7 +6,7 @@ run ("imaging/shifts")
|
||||
roi=Roi(256,0,128,128)
|
||||
stack = load_test_stack(show=False, size=9)
|
||||
ipr, ipi = complex_edge_filtering(stack, show=False)
|
||||
shifts = calculate_shifts(ipr, ipi, roi, java_code=True)
|
||||
shifts = (ipr, ipi, roi, java_code=True)
|
||||
#shifts= load_shifts("{images}/TestObjAligner/shifts.mat")
|
||||
#stack = load_test_stack(show=True)
|
||||
r=translate(stack, shifts, show=True)
|
||||
@@ -33,7 +33,7 @@ def eval_shift(roi, obj=None, stiga=None, stigb=None, wait=3.0):
|
||||
time.sleep(wait)
|
||||
image.waitNext(10000)
|
||||
img = image.data
|
||||
xoff, yoff, error, diffphase = calculate_shift(ref,img, roi)
|
||||
xoff, yoff, error, diffphase, _ = calculate_shift(ref,img, roi)
|
||||
print "xoff: ", xoff
|
||||
print "yoff: ", yoff
|
||||
print "error: ", error
|
||||
@@ -56,7 +56,7 @@ def eval_shift_obj(roi, obj1, obj2, wait=3.0):
|
||||
time.sleep(wait)
|
||||
image.waitNext(10000)
|
||||
img = image.data
|
||||
xoff, yoff, error, diffphase = calculate_shift(ref,img, roi)
|
||||
xoff, yoff, error, diffphase, _ = calculate_shift(ref,img, roi)
|
||||
print "Ref obj: ", obj1, " img obj: ", obj2
|
||||
print "xoff: ", xoff
|
||||
print "yoff: ", yoff
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
|
||||
|
||||
|
||||
|
||||
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?]
|
||||
caputq("X11MA-ES1-SD1:cam1:NumImages",1);
|
||||
set_eiger_number_of_frames(1)
|
||||
caget("X11MA-ES1-SD1:cam1:NumFrames_RBV") and compares before writing (therefore does nothing)
|
||||
if exposure:
|
||||
set_exposure_time(exposure, check)
|
||||
apply_averaging_detector(is_averaging_detector())
|
||||
caput("X11MA-ES1-SD1:Proc1:EnableFilter", False)
|
||||
caput("X11MA-ES1-SD1:Proc1:NumFilter", 1)
|
||||
caput("X11MA-ES1-SD1:cam1:NumCycles", 1)
|
||||
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, exposure_time = 0.2):
|
||||
"""
|
||||
Set Eiger default mode
|
||||
"""
|
||||
global chrono_eiger
|
||||
for i in range(retries):
|
||||
try:
|
||||
stop_eiger()
|
||||
eiger.setNumImages(1)# Is it relevant?
|
||||
caputq("X11MA-ES1-SD1:cam1:NumImages",1);
|
||||
set_eiger_number_of_frames(1, check)
|
||||
set_exposure_time(exposure_time, check)
|
||||
apply_averaging_detector(False)
|
||||
caput("X11MA-ES1-SD1:Proc1:EnableFilter", False)
|
||||
caput("X11MA-ES1-SD1:Proc1:NumFilter", 1)
|
||||
caput("X11MA-ES1-SD1:cam1:NumCycles", 1)
|
||||
eiger.grabMode=eiger.GrabMode.Continuous
|
||||
caputq("X11MA-ES1-SD1:cam1:ImageMode", Single)
|
||||
eiger.start()
|
||||
caputq("X11MA-ES1-SD1:cam1:Acquire", 1)
|
||||
chrono_eiger = Chrono()
|
||||
break
|
||||
except:
|
||||
if i==(retries-1):
|
||||
raise
|
||||
else:
|
||||
print "Error restoring Eiger, retrying " + str(sys.exc_info()[1])
|
||||
|
||||
|
||||
def set_exposure_time(value, check = True, retries=5):
|
||||
if value == eiger.getExposure():
|
||||
caget("X11MA-ES1-SD1:cam1:AcquireTime"), if equals retuem
|
||||
return
|
||||
started = eiger.isStarted()
|
||||
caget("X11MA-ES1-SD1:cam1:Acquire"),
|
||||
if started:
|
||||
stop_eiger()
|
||||
for i in range(retries):
|
||||
try:
|
||||
eiger.setExposure(value)
|
||||
caputq("X11MA-ES1-SD1:cam1:AcquireTime", value)
|
||||
if check:
|
||||
readback=get_eiger_exposure_readback()
|
||||
caget("X11MA-ES1-SD1:cam1:AcquireTime_RBV")
|
||||
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:
|
||||
caget("X11MA-ES1-SD1:cam1:ImageMode")
|
||||
eiger.start()
|
||||
caputq("X11MA-ES1-SD1:cam1:Acquire", 1)
|
||||
|
||||
|
||||
def set_eiger_number_of_frames(value, check = True):
|
||||
if value == get_eiger_number_of_frames():
|
||||
caget("X11MA-ES1-SD1:cam1:NumFrames_RBV",'i')
|
||||
return
|
||||
started = eiger.isStarted()
|
||||
caget("X11MA-ES1-SD1:cam1:Acquire")
|
||||
if started:
|
||||
stop_eiger()
|
||||
|
||||
caput("X11MA-ES1-SD1:cam1:NumFrames",value)
|
||||
if check:
|
||||
readback = get_eiger_number_of_frames()
|
||||
caget("X11MA-ES1-SD1:cam1:NumFrames_RBV",'i')
|
||||
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:
|
||||
caget("X11MA-ES1-SD1:cam1:ImageMode")
|
||||
eiger.start()
|
||||
caputq("X11MA-ES1-SD1:cam1:Acquire", 1)
|
||||
|
||||
|
||||
def stop_eiger():
|
||||
global chrono_eiger
|
||||
chrono_eiger.waitTimeout(CONTINOUS_MODE_MIN_TIME)
|
||||
started = eiger.isStarted()
|
||||
caget("X11MA-ES1-SD1:cam1:Acquire")
|
||||
if started:
|
||||
eiger.stop()
|
||||
caputq("X11MA-ES1-SD1:cam1:Acquire", 0)
|
||||
eiger.grabMode=eiger.GrabMode.Single
|
||||
caputq("X11MA-ES1-SD1:cam1:ImageMode", Single)
|
||||
eiger.stop()
|
||||
caputq("X11MA-ES1-SD1:cam1:Acquire", 0)
|
||||
eiger.waitReady(5000)
|
||||
wait until monitor of X11MA-ES1-SD1:cam1:Acquire == 0 is received
|
||||
else:
|
||||
eiger.grabMode=eiger.GrabMode.Single
|
||||
caputq("X11MA-ES1-SD1:cam1:ImageMode", Single)
|
||||
time.sleep(0.1)
|
||||
|
||||
|
||||
def average_eiger_frames(samples, roi=None, wait_next=False, sleep=0, outliers_threshold=None, outliers_mask=None, retries=None, timeout=None):
|
||||
global eiger_averaging_number_of_samples #, chrono_eiger
|
||||
sample = int(samples)
|
||||
if is_averaging_detector():
|
||||
#Not now
|
||||
else:
|
||||
ret = grab_frames(image, samples, roi, wait_next, sleep, outliers_threshold, outliers_mask, retries, timeout)
|
||||
if wait_next:
|
||||
|
||||
eiger.waitReady(5000)
|
||||
eiger.start()
|
||||
elif str(eiger.grabMode)=="Continuous":
|
||||
if not eiger.isStarted():
|
||||
eiger.start()
|
||||
try:
|
||||
#eiger.getDataArray().waitCacheChange(timeout)
|
||||
source.waitNext(timeout)
|
||||
breakzxZZy
|
||||
except java.util.concurrent.TimeoutException:
|
||||
if try_count == (retries-1):
|
||||
raise
|
||||
msg = "Eiger timeout - retrying #" + str(try_count)
|
||||
print msg
|
||||
log(msg)
|
||||
|
||||
return average_frames(ret) if samples > 1 else ret[0]
|
||||
|
||||
+5
-1
@@ -1 +1,5 @@
|
||||
otf2(start=500, end=510, time=1, delay=10, mode='LINEAR', alpha = 0.0, offset=0.0, name='test')
|
||||
#otf2(start=778, end=785, time=1, delay=10, mode='LINEAR', alpha = 0.0, offset=-3.8, name='test_Co')
|
||||
#otf2(start=772, end=805, time=2, delay=10, mode='LINEAR', alpha = 0.0, offset=-3.8, name='test')
|
||||
#otf2(start=845, end=885, time=2, delay=10, mode='LINEAR', alpha = 0.0, offset=-3.8, name='test_Ni')
|
||||
#otf2(start=520, end=570, time=2, delay=10, mode='LINEAR', alpha = 0.0, offset= 0, name='oXAS-VS01-OCP_O_test')
|
||||
otf2(start=520, end=595, time=2, delay=10, mode='LINEAR', alpha = 0.0, offset= 0, name='oXAS-VS01-OCP_O_test')
|
||||
Reference in New Issue
Block a user