280 lines
9.1 KiB
Python
280 lines
9.1 KiB
Python
import os
|
|
import time
|
|
import random
|
|
|
|
|
|
# 2025.11.15, beamline commissioning, A. Kleibert, C.A.F. Vaz
|
|
# Functions here require to compile first beamline_configurations.py and probably also beamline_functions.py
|
|
# path, name_only = bml_save_current_settings()
|
|
#
|
|
# We used monocam-4@129.129.121.54 with neutral density filters to image the beam after on the AV- blade of
|
|
# the aperture unit aftethe CMU at fully open front end slit.
|
|
#
|
|
# FE_slit_scan_on_AU() is a pressure supervising code to take images while opening the FE slits.
|
|
|
|
|
|
def take_image_and_save_data():
|
|
path, name_only = bml_save_current_settings()
|
|
# output_file = os.path.join(os.path.dirname(path), "Monocam_AU_"+name_only + ".jpg")
|
|
output_file = "/sls/X11MA/data/X11MA/pshell/home/data/2025_11/20251115/AU scans/" + name_only + ".jpg"
|
|
cmd = " curl http://root:monocam-4@129.129.121.54/axis-cgi/jpg/image.cgi -o " + output_file
|
|
os.system(cmd)
|
|
|
|
# cmd2 = "cp " + output_file + " " + copy_file
|
|
# cp -u *.jpg /sls/X11MA/data/X11MA/scratch/kleibert/20251113/
|
|
# copy_file = "/sls/X11MA/data/X11MA/scratch/kleibert/20251113/Monocam_AU_" + name_only + ".jpg"
|
|
# cmd = ["curl http://root:monocam-4@129.129.121.54/axis-cgi/jpg/image.cgi -o ", output_file]
|
|
# os.system(cmd)
|
|
|
|
|
|
|
|
def FE_slit_quick_photo_AU():
|
|
|
|
BML_FE_sizeX.setSpeed(0.4)
|
|
BML_FE_sizeY.setSpeed(0.4)
|
|
|
|
BML_FE_centerX.move(0.0)
|
|
BML_FE_centerY.move(0.0)
|
|
|
|
BML_FE_sizeX.move(2.5)
|
|
BML_FE_sizeY.move(2.5)
|
|
|
|
BML_FE_sizeX.moveAsync(-0.5)
|
|
BML_FE_sizeY.move(-0.5)
|
|
|
|
BML_FE_centerX.move(-0.2491)
|
|
BML_FE_centerY.move(0.5291)
|
|
|
|
BML_FE_sizeX.setSpeed(0.1)
|
|
BML_FE_sizeY.setSpeed(0.1)
|
|
|
|
|
|
def FE_slit_opening_scan_on_AU():
|
|
close_FE_slits()
|
|
|
|
# BML_FE_centerX.move(0.0)
|
|
# BML_FE_centerY.move(0.0)
|
|
# pressure = float(caget("X11MA-OP-AUMP:PRESSURE"))
|
|
|
|
max_versuche = 7
|
|
versuche = 0
|
|
cam_step = 40 # Jeder 3. Schritt
|
|
|
|
abbruch = False # Flag zum Verlassen aller Schleifen
|
|
schritt = 0 # Counter for images
|
|
|
|
wait_pressure = 10.0 # Wait time for pressure in seconds
|
|
pressure_threshold = 1.0e-7
|
|
y = 0.0
|
|
y_step = 0.002
|
|
y_max = 4.0
|
|
|
|
started = time.strftime("%H:%M:%S", time.localtime())
|
|
|
|
while y <= y_max and not abbruch:
|
|
# x = random.uniform(0, 20)
|
|
pressure = float(caget("X11MA-OP-AUMP:PRESSURE"))
|
|
x = pressure
|
|
print("current pressure: " + str(x) + ", y: " + str(y) + ", pressure: " + str(pressure))
|
|
|
|
while x > pressure_threshold:
|
|
versuche += 1
|
|
if versuche >= max_versuche:
|
|
print("Abort")
|
|
abbruch = True # Flag setzen
|
|
break # innere Schleife verlassen
|
|
print("wait for pressure...")
|
|
time.sleep(wait_pressure)
|
|
# x = random.uniform(0, 20)
|
|
pressure = float(caget("X11MA-OP-AUMP:PRESSURE"))
|
|
x = pressure
|
|
print("current pressure: " + str(x) + ", y: " + str(y) + ", pressure: " + str(pressure))
|
|
|
|
if abbruch:
|
|
break # aussere Schleife verlassen
|
|
|
|
if x <= pressure_threshold:
|
|
print("pressure is fine")
|
|
BML_FE_sizeX.move(y)
|
|
BML_FE_sizeY.move(y)
|
|
schritt += 1
|
|
if schritt % cam_step == 0: # Jeder 3. Schritt
|
|
schritt_str = "%04d" % schritt
|
|
print("take image: " + schritt_str)
|
|
output_file = "/sls/X11MA/data/X11MA/pshell/home/data/2025_11/20251115/" + schritt_str + ".jpg"
|
|
cmd = " curl http://root:monocam-4@129.129.121.54/axis-cgi/jpg/image.cgi -o " + output_file
|
|
print("write data to: " + cmd)
|
|
# time.sleep(0.5)
|
|
os.system(cmd)
|
|
# time.sleep(0.5)
|
|
versuche = 0
|
|
y += y_step # y nur erhohen, wenn x <= 10.0
|
|
|
|
time.sleep(0.1)
|
|
|
|
if not abbruch:
|
|
print("y = 4.0 erreicht. Fertig!")
|
|
|
|
stopped = time.strftime("%H:%M:%S", time.localtime())
|
|
print("started: " + started)
|
|
print("stopped: " + stopped)
|
|
|
|
close_FE_slits()
|
|
|
|
def AU_blades_dive(p_threshold, I_threshold):
|
|
|
|
# blades = ["BML_AU_TRYB", "BML_AU_TRYT", "BML_AU_TRXW", "BML_AU_TRXR"]
|
|
# BLADE = blades[number]
|
|
# BLADE.read()
|
|
|
|
# 1 Set blades to open position
|
|
BML_AU_TRYT.move(10.0)
|
|
# BML_AU_TRYB.move(-10.0)
|
|
# BML_AU_TRXR.move(10.0)
|
|
# BML_AU_TRXW.move(-10.0)
|
|
|
|
# 2 Setup dive parameters
|
|
|
|
max_versuche = 7
|
|
versuche = 0
|
|
|
|
abbruch = False # Flag zum Verlassen aller Schleifen
|
|
|
|
wait_pressure = 2.0 # Wait time for pressure in seconds
|
|
pressure_threshold = 1e-7
|
|
intensity_threshold_percent = 0.5
|
|
|
|
# 3 BML_AU_TRYT dive
|
|
|
|
y = 10.0
|
|
y_step = -0.002
|
|
# y_step = -1.0
|
|
y_max = BML_AU_TRYT.getMinValue()
|
|
|
|
intensity_ini = float(Keithley_2_raw.read())
|
|
intensity_threshold = intensity_threshold_percent * intensity_ini
|
|
|
|
# started = time.strftime("%H:%M:%S", time.localtime())
|
|
|
|
while y >= y_max and not abbruch:
|
|
# pressure = random.uniform(0, 20)
|
|
# intensity = random.uniform(0, 10)
|
|
pressure = float(caget("X11MA-OP-AUMP:PRESSURE"))
|
|
intensity = float(Keithley_2_raw.read())
|
|
# x = pressure
|
|
print("current pressure: " + str(pressure) + ", y: " + str(y) + ", intensity: " + str(intensity))
|
|
#
|
|
while pressure > pressure_threshold:
|
|
versuche += 1
|
|
if versuche >= max_versuche:
|
|
print("abort")
|
|
abbruch = True # Flag setzen
|
|
break # innere Schleife verlassen
|
|
print("wait for pressure...")
|
|
time.sleep(wait_pressure)
|
|
# pressure = random.uniform(0, 20)
|
|
pressure = float(caget("X11MA-OP-AUMP:PRESSURE"))
|
|
# x = pressure
|
|
# print("current pressure: " + str(x) + ", y: " + str(y) + ", pressure: " + str(pressure))
|
|
#
|
|
if abbruch:
|
|
break # aussere Schleife verlassen
|
|
#
|
|
if pressure <= pressure_threshold:
|
|
print("pressure is fine")
|
|
intensity = float(Keithley_2_raw.read())
|
|
print("current position: " + str(y) + ", intensity: " + str(intensity))
|
|
if intensity <= intensity_threshold:
|
|
print("intensity threshold reached at y = " + str(y))
|
|
abbruch = True
|
|
break
|
|
if abbruch:
|
|
break # aussere Schleife verlassen
|
|
# BML_FE_sizeX.move(y)
|
|
# BML_FE_sizeY.move(y)
|
|
versuche = 0
|
|
y += y_step # y nur erhohen, wenn x <= 10.0
|
|
|
|
time.sleep(0.1)
|
|
|
|
if not abbruch:
|
|
print("limit reached. no change in intensity")
|
|
#
|
|
# stopped = time.strftime("%H:%M:%S", time.localtime())
|
|
# print("started: " + started)
|
|
# print("stopped: " + stopped)
|
|
|
|
|
|
|
|
#def AU_2D_scan():
|
|
#
|
|
# close_FE_slits()
|
|
#
|
|
# # BML_FE_centerX.move(0.0)
|
|
# # BML_FE_centerY.move(0.0)
|
|
# # pressure = float(caget("X11MA-OP-AUMP:PRESSURE"))
|
|
#
|
|
# max_versuche = 7
|
|
# versuche = 0
|
|
# cam_step = 40 # Jeder 3. Schritt
|
|
#
|
|
# abbruch = False # Flag zum Verlassen aller Schleifen
|
|
# schritt = 0 # Counter for images
|
|
#
|
|
# wait_pressure = 10.0 # Wait time for pressure in seconds
|
|
# pressure_threshold = 1.0e-7
|
|
# y = 0.0
|
|
# y_step = 0.002
|
|
# y_max = 0.25
|
|
#
|
|
# started = time.strftime("%H:%M:%S", time.localtime())
|
|
#
|
|
# while y <= y_max and not abbruch:
|
|
# # x = random.uniform(0, 20)
|
|
# pressure = float(caget("X11MA-OP-AUMP:PRESSURE"))
|
|
# x = pressure
|
|
# print("current pressure: " + str(x) + ", y: " + str(y) + ", pressure: " + str(pressure))
|
|
#
|
|
# while x > pressure_threshold:
|
|
# versuche += 1
|
|
# if versuche >= max_versuche:
|
|
# print("Abort")
|
|
# abbruch = True # Flag setzen
|
|
# break # innere Schleife verlassen
|
|
# print("wait for pressure...")
|
|
# time.sleep(wait_pressure)
|
|
# # x = random.uniform(0, 20)
|
|
# pressure = float(caget("X11MA-OP-AUMP:PRESSURE"))
|
|
# x = pressure
|
|
# print("current pressure: " + str(x) + ", y: " + str(y) + ", pressure: " + str(pressure))
|
|
#
|
|
# if abbruch:
|
|
# break # aussere Schleife verlassen
|
|
#
|
|
# if x <= pressure_threshold:
|
|
# print("pressure is fine")
|
|
# BML_FE_sizeX.move(y)
|
|
# BML_FE_sizeY.move(y)
|
|
# schritt += 1
|
|
# if schritt % cam_step == 0: # Jeder 3. Schritt
|
|
# schritt_str = "%04d" % schritt
|
|
# print("take image: " + schritt_str)
|
|
# output_file = "/sls/X11MA/data/X11MA/pshell/home/data/2025_11/20251115/" + schritt_str + ".jpg"
|
|
# cmd = " curl http://root:monocam-4@129.129.121.54/axis-cgi/jpg/image.cgi -o " + output_file
|
|
# print("write data to: " + cmd)
|
|
# # time.sleep(0.5)
|
|
# os.system(cmd)
|
|
# # time.sleep(0.5)
|
|
# versuche = 0
|
|
# y += y_step # y nur erhohen, wenn x <= 10.0
|
|
#
|
|
# time.sleep(0.1)
|
|
#
|
|
# if not abbruch:
|
|
# print("y = 4.0 erreicht. Fertig!")
|
|
#
|
|
# stopped = time.strftime("%H:%M:%S", time.localtime())
|
|
# print("started: " + started)
|
|
# print("stopped: " + stopped)
|
|
#
|