This commit is contained in:
39
script/Users/PEEM/Armin/02_Eslit_offset_AK.py
Normal file
39
script/Users/PEEM/Armin/02_Eslit_offset_AK.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import sys
|
||||
|
||||
from mathutils import fit_polynomial
|
||||
from mathutils import PolynomialFunction
|
||||
|
||||
|
||||
#seting parameters
|
||||
sensor = 'KEI11'
|
||||
if sensor == 'KEI10':
|
||||
detector= keithley_1a
|
||||
detector_range='X11MA-KEI10:RANGE'
|
||||
elif sensor == 'KEI11':
|
||||
detector= keithley_2a
|
||||
detector_range='X11MA-KEI11:RANGE'
|
||||
else:
|
||||
print "Select a proper detector: KEI10 or KEI11."
|
||||
sys.exit()
|
||||
|
||||
caput(detector_range, 4) # 6 --> 200 nA
|
||||
exit_slit.move(30.0)
|
||||
speed = exit_slit.getSpeed()
|
||||
min_speed=exit_slit.getMinSpeed()
|
||||
exit_slit.setSpeed(min_speed)
|
||||
|
||||
#scan Energy Slit
|
||||
time.sleep(1)
|
||||
#run('Users/PEEM/Armin/Functions/SlitCalib.py',{"Slit":exit_slit, "Slit_offset":exit_slit_offset, "detector":detector, "start":30, "end":-20.0, "step_size":1.0, "final_pos":20.0})
|
||||
#cscan([girder_x], ['ca://machine_cur'], [0.16], [0.18], [0.01], latency=1.0, time=10.0, relative=False, passes=1, zigzag=False, keep=False, name='Unknown')
|
||||
result=lscan([exit_slit], [detector], [30.0], [-20.0], [1.0], latency=1.0)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
#resetting parameters
|
||||
caput(detector_range, 0) # 0--> AUTO
|
||||
exit_slit.setSpeed(speed)
|
||||
67
script/Users/PEEM/Armin/Functions/SlitCalib.py
Normal file
67
script/Users/PEEM/Armin/Functions/SlitCalib.py
Normal file
@@ -0,0 +1,67 @@
|
||||
###################################################################################################
|
||||
# Function fitting and peak search with mathutils.py
|
||||
###################################################################################################
|
||||
|
||||
from mathutils import fit_polynomial
|
||||
from mathutils import PolynomialFunction
|
||||
|
||||
# Input parameters (example)
|
||||
#Slit = exit_slit
|
||||
#Slit_offset = exit_slit_offset
|
||||
#detector = keithley_1a
|
||||
#start = 30.0
|
||||
#end = -20.0
|
||||
#step_size = 1.0
|
||||
#final_pos = 20.0
|
||||
#run('beamline_init/with_x-rays/functions/SlitCalib.py',{"Slit":exit_slit, "Slit_offset":exit_slit_offset, "detector":detector, "start":30, "end":-20.0, "step_size":1.0, "final_pos":20.0})
|
||||
|
||||
# Execute the scan
|
||||
result=lscan(Slit, detector, start, end, float(step_size))
|
||||
|
||||
readable_ = result[detector]
|
||||
positions_ = result[Slit]
|
||||
print positions_
|
||||
readable=[]
|
||||
positions=[]
|
||||
|
||||
# execute the fit
|
||||
fit_threshold=readable_[0]*0.05
|
||||
|
||||
#filter the positions with analog values above the threshold
|
||||
for i in range(8,len(positions_),1):
|
||||
if(readable_[i]<fit_threshold):
|
||||
readable.append(readable_[i])
|
||||
positions.append(positions_[i])
|
||||
|
||||
|
||||
|
||||
pars_polynomial = (a0, a1) = fit_polynomial(readable, positions,1)
|
||||
fitted_polynomial_function = PolynomialFunction(pars_polynomial)
|
||||
print pars_polynomial
|
||||
|
||||
|
||||
resolution = step_size/100
|
||||
fit_polinomial = []
|
||||
|
||||
# from the fit function calculate the values at the positions
|
||||
for x in frange(end,start,resolution, True):
|
||||
fit_polinomial.append(fitted_polynomial_function.value(x))
|
||||
x = frange(end, start+resolution, resolution)
|
||||
|
||||
# crate plots
|
||||
plots = plot([readable_, fit_polinomial] , ["data", "polinomial"], xdata = [positions_,x], title="Data")
|
||||
p = plot(None,name="Data 1")[0]
|
||||
p.addSeries(LinePlotSeries("Data2"))
|
||||
p.getSeries(0).setData(positions_, readable_)
|
||||
p.getSeries(1).setData(x, fit_polinomial)
|
||||
|
||||
#calculate the position where the line crosses zero
|
||||
k=-pars_polynomial[0]/pars_polynomial[1]
|
||||
print k
|
||||
|
||||
#change the offset
|
||||
#offset=Slit_offset.read()
|
||||
#Slit_offset.write(offset+k)
|
||||
|
||||
Slit.write(final_pos)
|
||||
|
||||
23
script/Users/PEEM/Armin/PEEM_slit.py
Normal file
23
script/Users/PEEM/Armin/PEEM_slit.py
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
# Commands to move slit and CA>
|
||||
# microscope.send_receive("mmp 7 -9044.7", 60000)
|
||||
# microscope.send_receive("mmp 2 -5998.6", 60000)
|
||||
# microscope.send_receive("mmp 1 0.0", 60000)
|
||||
# slitttt.read()
|
||||
# slitttt.write(pos[0])
|
||||
|
||||
# read ROI intensity, see FocusScan.py
|
||||
# scan_contrast
|
||||
# if roi is None:
|
||||
# sensor = image_contrast
|
||||
# else:
|
||||
# sensor = roi_contrast
|
||||
# roi_contrast.set_roi(roi)
|
||||
#
|
||||
# see test_autofocus
|
||||
#r=lscan (objective, image.contrast, RANGE[0], RANGE[1], STEP_SIZE, latency=(SETTLING_TIME + eiger.getExposure()))
|
||||
#(norm, mn, std )= fit (r["image_contrast"], r["objective"])
|
||||
#if (mn<RANGE[0] or mn>RANGE[1]):
|
||||
# raise Exception("Invalid fit")
|
||||
#objective.write(mn)
|
||||
|
||||
20
script/Users/PEEM/Armin/RMU_scan.py
Normal file
20
script/Users/PEEM/Armin/RMU_scan.py
Normal file
@@ -0,0 +1,20 @@
|
||||
#for i in [-1.9, -2.0, -2.1]:
|
||||
## girder_x.move(i, -1)
|
||||
## rmu_ry.move(-4.477, -1)
|
||||
# print "Do something"
|
||||
# time.sleep(1.0)
|
||||
#
|
||||
#for x in range(0, 15):
|
||||
# y = -3.5 + float(x)*0.5
|
||||
# z = -5.2211 + y*0.4865
|
||||
# #print("Girder x %f" % (y))
|
||||
# print("RMU Ry %f" % (z))
|
||||
# #str(1.23)
|
||||
for x in range(30, 70):
|
||||
y = -3.5 + float(x)*0.05
|
||||
z = -5.222 + y*0.4638
|
||||
print("Girder x %f" % (y))
|
||||
#girder_x.move(y, -1)
|
||||
print("RMU Ry %f" % (z))
|
||||
#rmu_ry.move(z, -1)
|
||||
time.sleep(3.0)
|
||||
17
script/Users/PEEM/Armin/TestUserScript_Armin.py
Executable file → Normal file
17
script/Users/PEEM/Armin/TestUserScript_Armin.py
Executable file → Normal file
@@ -14,17 +14,18 @@ two_pol(switching="Tune_Detune", sequence="A", measurements=MEASUREMENTS, exposu
|
||||
time.sleep(2.0)
|
||||
|
||||
#TwoEnergies with lin hor polarization ID2 only (normal)
|
||||
set_beamline_setup(id ="ID2", en=710, pol2="Lin_Hor")
|
||||
#set_beamline_setup(id ="ID2", en=710, pol2="Lin_Hor") -> causes problems?
|
||||
two_energies(705, 710, measurements=MEASUREMENTS, exposure=EXPOSURE, average=AVERAGE)
|
||||
time.sleep(2.0)
|
||||
|
||||
#abs_spec(ranges=[[500.0, 1000.0, 100.0],], switch_pol=False, scans=1, exposure=EXPOSURE, average=AVERAGE) #Use manulally defined ranges and rois defined in GUI
|
||||
abs_spec(ranges="Fe_L3_fine", roi="test", switch_pol=False, scans=1, exposure=EXPOSURE, average=AVERAGE)
|
||||
|
||||
#eiger.stop()
|
||||
#eiger_threshold.write(7500)
|
||||
#eiger.start()
|
||||
|
||||
|
||||
|
||||
|
||||
#tscan(['ca://X11MA-PC-ET7000:SW-K'], points=10, interval=1.0, title='temperature', keep=False, name='tewsst', layout='table', provider='txt', auto_range=True, domain_axis='Time')
|
||||
|
||||
#Direct functions to change energy, pol, offset:
|
||||
#change_energy(700)
|
||||
@@ -36,4 +37,10 @@ abs_spec(ranges="Fe_L3_fine", roi="test", switch_pol=False, scans=1, exposure=EX
|
||||
#switch_pol()
|
||||
|
||||
#Restoring beamline state defined in last set_beamline_setut:
|
||||
#restore_beamline_setup()
|
||||
#restore_beamline_setup()
|
||||
#
|
||||
#for i in [-1.9, -2.0, -2.1]:
|
||||
# girder_x.move(i, -1)
|
||||
# rmu_ry.move(-4.477, -1)
|
||||
# print "Do something"
|
||||
# caput("X11MA-HG:X_SET", 1.9)
|
||||
26
script/Users/PEEM/Armin/Threshold_Scan.py
Normal file
26
script/Users/PEEM/Armin/Threshold_Scan.py
Normal file
@@ -0,0 +1,26 @@
|
||||
##Constants
|
||||
AVERAGE = 1
|
||||
EXPOSURE = 1.0
|
||||
MEASUREMENTS = 5
|
||||
DRIFT_CORRECTION = True
|
||||
|
||||
eiger.stop()
|
||||
eiger_threshold.write(4000.0)
|
||||
time.sleep(2.0)
|
||||
#eiger.start()
|
||||
|
||||
##TakeImage at 710 eV at the given polarization
|
||||
#change_energy(712)
|
||||
take_image(scans=1, switch_pol=False, measurements=MEASUREMENTS, exposure=EXPOSURE, average=AVERAGE)
|
||||
time.sleep(2.0)
|
||||
#
|
||||
|
||||
eiger.stop()
|
||||
eiger_threshold.write(4100.0)
|
||||
time.sleep(2.0)
|
||||
#eiger.start()
|
||||
|
||||
##TakeImage at 710 eV at the given polarization
|
||||
#change_energy(712)
|
||||
take_image(scans=1, switch_pol=False, measurements=MEASUREMENTS, exposure=EXPOSURE, average=AVERAGE)
|
||||
time.sleep(2.0)
|
||||
2
script/Users/PEEM/Armin/test.py
Normal file
2
script/Users/PEEM/Armin/test.py
Normal file
@@ -0,0 +1,2 @@
|
||||
#cscan([girder_x], ['ca://machine_cur'], [0.16], [0.18], [0.01], latency=1.0, time=10.0, relative=False, passes=1, zigzag=False, keep=False, name='Unknown')
|
||||
cscan(girder_x, machine_cur, 0.16, 0.18, 0.01)
|
||||
102
script/beamline_init/init/InitAU.py
Normal file
102
script/beamline_init/init/InitAU.py
Normal file
@@ -0,0 +1,102 @@
|
||||
import subprocess
|
||||
import time
|
||||
import traceback
|
||||
|
||||
running = False
|
||||
counts = {}
|
||||
|
||||
def countHLS(motor):
|
||||
global counts
|
||||
try:
|
||||
time.sleep(1.0)
|
||||
counts[motor]=0
|
||||
def on_change(value):
|
||||
global counts
|
||||
print "LimitSW changed on" , motor, "to", value
|
||||
if int(value) == 1:
|
||||
counts[motor]=counts[motor]+1
|
||||
|
||||
with Channel(motor+".HLS", callback=on_change, monitored=True, name="test") as ch:
|
||||
if int(ch.read()) == 1:
|
||||
counts[motor]=1
|
||||
while(running==True):
|
||||
time.sleep(0.1)
|
||||
print "High Limit Switch motor "+motor +" reached "+ str(counts[motor]) + " times\n"
|
||||
return counts[motor]
|
||||
except:
|
||||
print "Exception counting "+str(motor)
|
||||
traceback.print_exc()
|
||||
raise
|
||||
|
||||
|
||||
def countLLS(motor):
|
||||
global counts
|
||||
try:
|
||||
time.sleep(1.0)
|
||||
counts[motor]=0
|
||||
def on_change(value):
|
||||
global counts
|
||||
print "LimitSW changed on" , motor, "to", value
|
||||
if int(value) == 1:
|
||||
counts[motor]=counts[motor]+1
|
||||
|
||||
with Channel(motor+".LLS", callback=on_change, monitored=True, name="test") as ch:
|
||||
if int(ch.read()) == 1:
|
||||
counts[motor]=1
|
||||
while(running==True):
|
||||
time.sleep(0.1)
|
||||
print "Low Limit Switch motor "+motor +" reached "+ str(counts[motor]) + " times\n"
|
||||
return counts[motor]
|
||||
except:
|
||||
print "Exception counting "+str(motor)
|
||||
traceback.print_exc()
|
||||
raise
|
||||
|
||||
def init():
|
||||
try:
|
||||
global running
|
||||
running = True
|
||||
|
||||
subprocess.call("X_X11MA_init-AU.sh", shell=True)
|
||||
# Positions at limit switches are not checked
|
||||
time.sleep(1.0)
|
||||
caput('X11MA-OP2-AVsize',20)
|
||||
caput('X11MA-OP2-AHsize',20)
|
||||
|
||||
running = False
|
||||
return 0
|
||||
except:
|
||||
print "Exception in init"
|
||||
traceback.print_exc()
|
||||
raise
|
||||
|
||||
|
||||
#Fork and join
|
||||
try:
|
||||
futures = fork(init,(countHLS,("X11MA-OP2-AU:TRY1",)), \
|
||||
(countLLS,("X11MA-OP2-AU:TRY4",)), \
|
||||
(countHLS,("X11MA-OP2-AU:TRZ1",)), \
|
||||
(countLLS,("X11MA-OP2-AU:TRZ4",)), \
|
||||
(countHLS,("X11MA-OP2-BP1:TRY",)), \
|
||||
(countHLS,("X11MA-OP2-BP1:TRZ",)) )
|
||||
ret = join(futures)
|
||||
|
||||
#check limit switch status after init
|
||||
limitsw=True
|
||||
for i in range(1,6):
|
||||
if(ret[i]!=1):
|
||||
limitsw=False
|
||||
print "Limit switch status for all motors: %s" %("OK" if limitsw == True else "Not OK")
|
||||
|
||||
#final status report
|
||||
if(limitsw==True):
|
||||
print "init-AU: ==> done. OK!"
|
||||
set_return("OK")
|
||||
else:
|
||||
print "init-AU: ==> not done. NOT OK!"
|
||||
set_return("Not OK")
|
||||
|
||||
except:
|
||||
set_return("Error")
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ def countHS(motor):
|
||||
counts[motor]=1
|
||||
while(running==True):
|
||||
time.sleep(0.1)
|
||||
print "Home Switch motor "+motor +" reached "+ str(counts[motor]) + " times"
|
||||
print "Home Switch motor "+motor +" reached "+ str(counts[motor]) + " times\n"
|
||||
return counts[motor]
|
||||
except:
|
||||
print "Exception counting "+str(motor)
|
||||
|
||||
9
script/beamline_init/init/InitExitSlit.py
Normal file
9
script/beamline_init/init/InitExitSlit.py
Normal file
@@ -0,0 +1,9 @@
|
||||
run("xrays_default")
|
||||
|
||||
time.sleep(3)
|
||||
|
||||
caput("X11MA-OP-SL:GO.PROC",1)
|
||||
time.sleep(30)
|
||||
exit_slit.write(20.0)
|
||||
|
||||
print "Init Exit Slit OK."
|
||||
@@ -1,27 +1,28 @@
|
||||
import sys
|
||||
|
||||
#seting parameters
|
||||
sensor = KEI11
|
||||
if sensor == KEI10:
|
||||
sensor = 'KEI11'
|
||||
if sensor == 'KEI10':
|
||||
detector= keithley_1a
|
||||
detector_range='X11MA-KEI10:RANGE'
|
||||
elif sensor == KEI11:
|
||||
elif sensor == 'KEI11':
|
||||
detector= keithley_2a
|
||||
detector_range='X11MA-KEI11:RANGE'
|
||||
else:
|
||||
print "Select a proper detector: KEI10 or KEI11."
|
||||
sys.exit()
|
||||
|
||||
caput(detector_range, 5) # 6 --> 200 nA
|
||||
caput(detector_range, 4) # 6 --> 200 nA
|
||||
exit_slit.move(30.0)
|
||||
speed = exit_slit.getSpeed()
|
||||
min_speed=exit_slit.getMinSpeed()
|
||||
exit_slit.setSpeed(min_speed)
|
||||
|
||||
#scan Energy Slit
|
||||
time.sleep(1)
|
||||
run('beamline_init/with_x-rays/functions/SlitCalib.py',{"Slit":exit_slit, "Slit_offset":exit_slit_offset, "detector":detector, "start":30, "end":-20.0, "step_size":1.0, "final_pos":20.0})
|
||||
time.sleep(1)
|
||||
|
||||
#resetting parameters
|
||||
caput(detector_range, 0) # 0--> AUTO
|
||||
exit_slit.setSpeed(speed)
|
||||
exit_slit.setSpeed(speed)
|
||||
|
||||
@@ -28,7 +28,7 @@ fit_threshold=readable_[0]*0.05
|
||||
|
||||
#filter the positions with analog values above the threshold
|
||||
for i in range(8,len(positions_),1):
|
||||
if(readable_[i]>fit_threshold):
|
||||
if(readable_[i]<fit_threshold):
|
||||
readable.append(readable_[i])
|
||||
positions.append(positions_[i])
|
||||
|
||||
|
||||
@@ -367,7 +367,7 @@ class ListenerAzimuth (DeviceListener):
|
||||
set_azimuth_rot(value)
|
||||
except:
|
||||
if self.debug:
|
||||
self.getLogger().warning(str(sys.exc_info()[1]))
|
||||
log(str(sys.exc_info()[1]))
|
||||
listenerAzimuth = ListenerAzimuth()
|
||||
listenerAzimuth.debug=True
|
||||
azimuth_rot.addListener(listenerAzimuth)
|
||||
|
||||
@@ -103,6 +103,7 @@ diag_devices = {
|
||||
"PEEM high voltage": microscope.high_voltage, \
|
||||
"Tilt vertical": tilt_vertical, \
|
||||
"Tilt horizontal": tilt_horizontal, \
|
||||
"ai1 current": ai1, \
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -224,6 +224,7 @@ def _shift_and_save_as_tiff(data, filename, reference=None, roi=None, image_drif
|
||||
except:
|
||||
print "-> Error shifting image: " + str(sys.exc_info()[1])
|
||||
return
|
||||
metadata["roi"] = str(roi)
|
||||
save_as_tiff(shifted_frame, filename, check, show, parallel=False, metadata=metadata)
|
||||
|
||||
def shift_and_save_as_tiff(data, filename, reference=None, roi=None, shift=None, check=False, show = False, parallel=True, metadata={}):
|
||||
@@ -426,10 +427,12 @@ class ProcImage(Filter):
|
||||
self.outliers_mask =None
|
||||
|
||||
def processData(self, data):
|
||||
if data is None:
|
||||
return None
|
||||
outliers_threshold = get_outliers_threshold() if (self.outliers_threshold is None) else self.outliers_threshold
|
||||
outliers_mask = get_outliers_mask() if (self.outliers_mask is None) else self.outliers_mask
|
||||
roi = self.roi
|
||||
data=data.copy()
|
||||
data=data.copy()
|
||||
if roi is not None:
|
||||
data = data.getRoi(Rectangle(roi[0], roi[1], roi[2], roi[3]))
|
||||
#ret = load_image(img)
|
||||
|
||||
@@ -53,7 +53,7 @@ def update_arrows():
|
||||
arrow_a.update(FOV_ARROWS_ORIGIN, Point(xa,ya))
|
||||
xa,ya=int(x+FOV_XRAY_LABEL_POS*math.cos(a)), int(y-FOV_XRAY_LABEL_POS*math.sin(a))
|
||||
label_a.update(Point(xa,ya))
|
||||
angle=angle+azimuth
|
||||
angle=angle-azimuth
|
||||
a=math.radians(angle)
|
||||
xa,ya=int(x+FOV_ARROWS_SIZE*math.cos(a)), int(y-FOV_ARROWS_SIZE*math.sin(a))
|
||||
arrow_x.update(FOV_ARROWS_ORIGIN, Point(xa,ya))
|
||||
|
||||
@@ -3,7 +3,9 @@ import java.lang.reflect
|
||||
import flanagan.complex.ComplexMatrix as ComplexMatrix
|
||||
import flanagan.math.Matrix as Matrix
|
||||
import flanagan.complex.Complex as Complex
|
||||
import org.jtransforms.fft.DoubleFFT_2D as DoubleFFT_2D
|
||||
#import org.jtransforms.fft.DoubleFFT_2D as DoubleFFT_2D
|
||||
import edu.emory.mathcs.jtransforms.fft.DoubleFFT_2D
|
||||
|
||||
import math
|
||||
from startup import ScriptUtils
|
||||
import ij.plugin.filter.PlugInFilterRunner as PlugInFilterRunner
|
||||
@@ -613,6 +615,7 @@ def calculate_shifts(imp_r, imp_i, roi, upscale_factor=100, reference_slide=1, j
|
||||
IJ.showProgress(i + 1, len(ffts))\
|
||||
return shifts # [ref, drifted, dr, dc, error, diffphase]
|
||||
|
||||
#Transforms an array in memory, a BufferedImage, or a file name into a ImagePlus object.
|
||||
def to_ip(obj):
|
||||
if is_string(obj):
|
||||
try:
|
||||
|
||||
@@ -147,6 +147,15 @@ def is_id_error():
|
||||
def check_id_error():
|
||||
if is_id_error():
|
||||
raise Exception ("ID error: check ID status")
|
||||
|
||||
def gude1(pwr):
|
||||
caput("PEEM-GUDE:CH1SET",pwr)
|
||||
def gude2(pwr):
|
||||
caput("PEEM-GUDE:CH2SET",pwr)
|
||||
def gude3(pwr):
|
||||
caput("PEEM-GUDE:CH3SET",pwr)
|
||||
def gude4(pwr):
|
||||
caput("PEEM-GUDE:CH4SET",pwr)
|
||||
|
||||
###################################################################################################
|
||||
#Default scan callbacks
|
||||
@@ -468,13 +477,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 == "PGM_ID1":
|
||||
if ID in ("PGM_ID1", "ID1"):
|
||||
id1_status=get_id_status(1)
|
||||
id2_status=0
|
||||
elif ID == "PGM_ID2":
|
||||
elif ID in ("PGM_ID2", "ID2"):
|
||||
id1_status=0
|
||||
id2_status=get_id_status(2)
|
||||
if ID == "PGM_ID1_ID2":
|
||||
else: # if ID in ("PGM_ID1_ID2", "ID1_ID2") :
|
||||
id1_status=get_id_status(1)
|
||||
id2_status=get_id_status(2)
|
||||
if id1_status >= 1:
|
||||
@@ -759,12 +768,15 @@ 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':
|
||||
print "Grat G1"
|
||||
Grating.write("0")
|
||||
Grating_ch.write("0")
|
||||
elif grat=='G2_1200':
|
||||
print "Grat G2"
|
||||
Grating.write("1")
|
||||
Grating_ch.write("1")
|
||||
elif grat =='G3_600':
|
||||
print "Grat G3"
|
||||
Grating.write("2")
|
||||
Grating_ch.write("2")
|
||||
if order is not None:
|
||||
@@ -840,9 +852,6 @@ def peem_optics_default_15kV():
|
||||
start_voltage.write(0)
|
||||
# fov.write(100)
|
||||
microscope.send_receive("sep 100um")
|
||||
microscope.send_receive("mmp 7 -9044.7", 60000)
|
||||
microscope.send_receive("mmp 2 -5998.6", 60000)
|
||||
microscope.send_receive("mmp 1 0.0", 60000)
|
||||
|
||||
def peem_optics_default_10kV():
|
||||
objective.write(1220)
|
||||
@@ -852,9 +861,6 @@ def peem_optics_default_10kV():
|
||||
obj_align_y.write(0)
|
||||
start_voltage.write(0)
|
||||
microscope.send_receive("sep 100um")
|
||||
microscope.send_receive("mmp 7 -9044.7", 60000)
|
||||
microscope.send_receive("mmp 2 -5998.6", 60000)
|
||||
microscope.send_receive("mmp 1 0.0", 60000)
|
||||
|
||||
|
||||
|
||||
@@ -878,7 +884,11 @@ def neutralize_position(retries = 3):
|
||||
log("neutralize_position error - retrying: " + sys.exc_info()[1])
|
||||
time.sleep(1)
|
||||
microscope.home_tilt('H')
|
||||
microscope.home_tilt('V')
|
||||
microscope.home_tilt('V')
|
||||
microscope.send_receive("mmp 7 -9044.7", 60000)
|
||||
microscope.send_receive("mmp 2 -5998.6", 60000)
|
||||
microscope.send_receive("mmp 1 0.0", 60000)
|
||||
close_vg10()
|
||||
###################################################################################################
|
||||
#Maths
|
||||
###################################################################################################
|
||||
@@ -983,3 +993,13 @@ def auto_intensity(roi=None, exposure=None):
|
||||
return scan_intensity(roi)
|
||||
finally:
|
||||
restore_eiger()
|
||||
|
||||
###################################################################################################
|
||||
# System utilities
|
||||
###################################################################################################
|
||||
|
||||
def memory():
|
||||
import java.lang.Runtime as Runtime
|
||||
r=Runtime.getRuntime()
|
||||
print "Used: ", r.totalMemory()
|
||||
print "Max : ", r.maxMemory()
|
||||
@@ -34,14 +34,8 @@ start = time.time()
|
||||
start = time.time()
|
||||
threads = []
|
||||
image_drift=None
|
||||
calculated_shifts={}
|
||||
#path = "{data}/{year}_{month}/{date}" + "/" + "{seq}%03d_" + METHOD
|
||||
#set_exec_pars(path= path, format="txt", layout="table", open=True)
|
||||
calculated_shifts={}
|
||||
data_path = "{data}/{year}_{month}/{date}/{date}_{name}"
|
||||
set_exec_pars(name=METHOD, path = data_path, format="txt", layout="table", open=True)
|
||||
#data_path = get_exec_pars().path
|
||||
|
||||
set_exec_pars(name=METHOD, path = data_path, format="txt", layout="table", open=True)
|
||||
|
||||
|
||||
@@ -49,10 +43,8 @@ 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
|
||||
frame_index = 0 if frame_index else 1
|
||||
root = "" if short_name else (data_path + "/")
|
||||
root = "" if short_name else (data_path + "/")
|
||||
abs_index=run_index + frame_index
|
||||
max_index= max(max_index, frame_index)
|
||||
max_index= max(max_index, frame_index)
|
||||
prefix = get_context().setup.expandPath("i{date}%02d_" + ("%03d" % (abs_index,)))
|
||||
|
||||
@@ -87,8 +79,9 @@ if METHOD == "Two_Pol" or (SWITCH_POL and (METHOD == "Take_Image")):
|
||||
|
||||
def imageinfo(info):
|
||||
pass
|
||||
|
||||
|
||||
ref_image = None
|
||||
def save_image_file(frame, cycle=-1, frame_index=0, processed_shift=False):
|
||||
global ref_image
|
||||
if frame is None:
|
||||
raise Exception("Cannot save frame - None: cycle: " + str(cycle) + " index: " + str(frame_index))
|
||||
@@ -119,27 +112,18 @@ def save_image_file(frame, cycle=-1, frame_index=0, processed_shift=False):
|
||||
if DRIFT_CORRECTION and (not processed_shift):
|
||||
filename = get_image_file_name(cycle, frame_index, shifted=True)
|
||||
#print " *** ", cycle, frame_index
|
||||
if cycle>0:
|
||||
if cycle==1:
|
||||
if cycle>0:
|
||||
if ref_image is None:
|
||||
if (cycle!=1) or (frame_index!=0):
|
||||
raise Exception ("Invalid reference image: cycle=" + str(cycle) + " index="+ str (frame_index))
|
||||
ref_image = frame
|
||||
threads.append(save_as_tiff(frame, filename, metadata=metadata))
|
||||
else:
|
||||
"""
|
||||
if image_drift is not None:
|
||||
print "-> Shifting ", filename
|
||||
#shifted_frame = apply_shift(frame, image_drift)
|
||||
#threads.append(save_as_tiff(shifted_frame, filename, metadata=metadata))
|
||||
threads.append(shift_and_save_as_tiff(frame, shift=image_drift, metadata=metadata))
|
||||
else:
|
||||
if frame_index==2:
|
||||
#shift = calculated_shifts[get_image_file_name(cycle, 0, shifted=True)]
|
||||
if frame_index==2:
|
||||
#Done later
|
||||
pass
|
||||
else:
|
||||
threads.append(shift_and_save_as_tiff(frame, filename, ref_images[0], calc_roi, metadata=metadata))
|
||||
|
||||
|
||||
# log("SV:"+Format(startvoltage,"0.000")+" OB:"+Format(objective,"0.00")+" ST:"+Format(LEEMtemp,"0.0"))
|
||||
else:
|
||||
threads.append(shift_and_save_as_tiff(frame, filename, ref_image, calc_roi, metadata=metadata))
|
||||
|
||||
init_eiger(exposure=EXPOSURE)
|
||||
|
||||
@@ -169,29 +153,8 @@ try:
|
||||
assert_status_ok()
|
||||
if METHOD == "Two_Energies":
|
||||
change_energy(ENERGY[i])
|
||||
print "--- Grabing " + str(AVERAGE)+ " frames - cycle: " + str(cycle) + " step: " + str(i)
|
||||
print "--- Grabing " + str(AVERAGE)+ " frames - cycle: " + str(cycle) + " step: " + str(i)
|
||||
av = average_eiger_frames(AVERAGE, roi=None, wait_next=True)
|
||||
#print "--- Time: " + str(time.time() - s)
|
||||
av = average_eiger_frames(AVERAGE, roi=None, wait_next=True)
|
||||
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
|
||||
frames.append(av)
|
||||
imageinfo("I")
|
||||
save_image_file(frames[i], cycle, i)
|
||||
@@ -200,7 +163,6 @@ try:
|
||||
|
||||
if METHOD == "Two_Pol":
|
||||
if (i==0) or (SEQUENCE == "B"):
|
||||
switch_pol()
|
||||
switch_pol()
|
||||
|
||||
if (METHOD == "Two_Pol") or (METHOD == "Two_Energies"):
|
||||
@@ -241,16 +203,6 @@ try:
|
||||
save_image_file(ip1,cycle, 2, processed_shift=True)
|
||||
|
||||
print "--- Averaging..."
|
||||
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)
|
||||
for i in range(len(frames)):
|
||||
integration = None
|
||||
for cycle in range(1, MEASUREMENTS + 1):
|
||||
@@ -284,25 +236,7 @@ try:
|
||||
save_image_file(av, -1, i, processed_shift=True)
|
||||
|
||||
if SWITCH_POL and (METHOD == "Take_Image"):
|
||||
switch_pol()
|
||||
|
||||
#SWITCH_POL = False
|
||||
#set_exec_pars(then_success="run('templates/Eiger2Img')")
|
||||
|
||||
"""
|
||||
get_context().incrementDaySequentialNumber()
|
||||
set_exec_pars(open=False)
|
||||
set_exec_pars(open=True)
|
||||
|
||||
for cycle in range(1, MEASUREMENTS + 1):
|
||||
frames = []
|
||||
if MEASUREMENTS > 1:
|
||||
log("nround = " + str(cycle) + " / " + str(MEASUREMENTS))
|
||||
print "--- Grabing " + str(AVERAGE)+ " frames - cycle: " + str(cycle) + " step: " + str(i)
|
||||
av = average_eiger_frames(AVERAGE, roi=None, wait_next=True)
|
||||
imageinfo("I")
|
||||
save_image_file(av, cycle, i)
|
||||
|
||||
switch_pol()
|
||||
|
||||
#TODO: This is a workaround to handle 2-Images, should be removed
|
||||
run_index = run_index + 1
|
||||
|
||||
1
script/test/Diagnostics.py
Executable file → Normal file
1
script/test/Diagnostics.py
Executable file → Normal file
@@ -60,6 +60,7 @@ diag_devices = {
|
||||
"id2 alpha": id2_alpha, \
|
||||
"id2 harmonic": id2_harmonic, \
|
||||
"ring current": machine_cur, \
|
||||
"ai1 current": ai1, \
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user