Files
x09lb/script/local.py
gac-x09lb 64c6f80912 Startup
2022-11-23 09:06:55 +01:00

153 lines
6.7 KiB
Python

###################################################################################################
# Deployment specific global definitions - executed after startup.py
###################################################################################################
def trig_ccd():
if ccd.dataMatrix in SENSORS:
if ccd.isSimulated():
time.sleep(0.1)
else:
image_id = ccd.currentImageCount
ccd.start()
ccd.waitReady(-1)
ccd.waitNewImage(5000, image_id)
def is_beam_ok():
return True
def wait_beam():
if not is_beam_ok():
print "Waiting for beam..."
while not beam_ok:
time.sleep(0.1)
print "Beam ok"
def before_readout():
wait_beam()
trig_ccd()
def after_readout(rec, scan):
if not is_beam_ok():
rec.invalidate()
def after_scan():
pass
#Scanning exposure
class exposure_index (Writable, Readable):
def __init__(self):
self.pos=0.0
def read(self):
return self.pos
def write(self, value):
ccd.setExposure(EXPOSURES[int(value)])
self.pos = value
class exposure (Readable):
def read(self):
return ccd.exposure
#High level commands
def scan_2d(range_x, range_y, steps_x, steps_y, exposures=None, settling_time=0.1, zigzag=True, compression=False, dry_run=False):
"""Relative area scan on sample sample_x and sample_y. A 2D scan is performed if 'exposures' is not defined.
Otherwise a 3D scan is performed, where the third dimension correspond to the exposure indexes.
Args:
range_x(float or list): the relative range for sample x [start, stop]. If a float value is used, the range is set to [-value, value].
range_y(float or list): the relative range for sample y [start, stop]. If a float value is used, the range is set to [-value, value].
steps_x(int): number of steps for sample_x
steps_y(int): number of steps for sample_y
exposures(list of float, optional): f specified, samples for each exposure time value in each xy position.
settling_time(float, optional): time in seconds to wait after positioners are set, before sampling sensors.
zigzag(boolean, optional): if True each fast changing dimension revert direction after finishing a line.
compression(boolean, optional): if True images are saved compressed.
dry_run(boolean, optional): if True uses dummy_x and dummy_y instead of sample_x and sample_y.
Returns:
ScanResult object
"""
if type(range_x)==float: range_x =[-range_x, range_x]
if type(range_y)==float: range_y =[-range_y, range_y]
return run("templates/Scan2D", { \
"DRY_RUN": dry_run, \
"RANGE_X": [float(range_x[0]), float(range_x[1])], \
"RANGE_Y": [float(range_y[0]), float(range_y[1])], \
"STEPS": [int(steps_x), int(steps_y)], \
"EXPOSURES": exposures, \
"SETTLING_TIME": settling_time, \
"ZIGZAG": zigzag, \
"COMPRESSION": compression
})
def scan_2d(center_x, center_y, steps_x, steps_y, exposures=None, settling_time=0.1, zigzag=True, compression=False, dry_run=False):
"""Relative area scan on sample sample_x and sample_y. A 2D scan is performed if 'exposures' is not defined.
Otherwise a 3D scan is performed, where the third dimension correspond to the exposure indexes.
Args:
range_x(float or list): the relative range for sample x [start, stop]. If a float value is used, the range is set to [-value, value].
range_y(float or list): the relative range for sample y [start, stop]. If a float value is used, the range is set to [-value, value].
steps_x(int): number of steps for sample_x
steps_y(int): number of steps for sample_y
exposures(list of float, optional): f specified, samples for each exposure time value in each xy position.
settling_time(float, optional): time in seconds to wait after positioners are set, before sampling sensors.
zigzag(boolean, optional): if True each fast changing dimension revert direction after finishing a line.
compression(boolean, optional): if True images are saved compressed.
dry_run(boolean, optional): if True uses dummy_x and dummy_y instead of sample_x and sample_y.
Returns:
ScanResult object
"""
if type(range_x)==float: range_x =[-range_x, range_x]
if type(range_y)==float: range_y =[-range_y, range_y]
return run("templates/Scan2D", { \
"DRY_RUN": dry_run, \
"RANGE_X": [float(range_x[0]), float(range_x[1])], \
"RANGE_Y": [float(range_y[0]), float(range_y[1])], \
"STEPS": [int(steps_x), int(steps_y)], \
"EXPOSURES": exposures, \
"SETTLING_TIME": settling_time, \
"ZIGZAG": zigzag, \
"COMPRESSION": compression
})
def regine(center_x, center_y, steps_x, steps_y, step_size_x, step_size_y, noise=0.0, exposures=None, settling_time=0.1, zigzag=True, compression=False, dry_run=False):
"""Relative area scan on sample sample_x and sample_y. A 2D scan is performed if 'exposures' is not defined.
Otherwise a 3D scan is performed, where the third dimension correspond to the exposure indexes.
Args:
center_x(float): Center position of sample_x
center_y(float): Center position of sample_y
steps_x(int): number of steps for sample_x
steps_y(int): number of steps for sample_y
step_size_x(float): step size for sample_x
step_size_y(float): step size for sample_y
noise(float): noise added to sample_x and sample_y positions, as fraction of the step.
exposures(list of float, optional): f specified, samples for each exposure time value in each xy position.
settling_time(float, optional): time in seconds to wait after positioners are set, before sampling sensors.
zigzag(boolean, optional): if True each fast changing dimension revert direction after finishing a line.
compression(boolean, optional): if True images are saved compressed.
dry_run(boolean, optional): if True uses dummy_x and dummy_y instead of sample_x and sample_y.
Returns:
ScanResult object
"""
return run("templates/Regine", { \
"DRY_RUN": dry_run, \
"CENTER_X": float(center_x), \
"CENTER_Y": float(center_y), \
"STEPS_X": int(steps_x), \
"STEPS_Y": int(steps_y), \
"STEP_SIZE_X": float(step_size_x), \
"STEP_SIZE_Y": float(step_size_y), \
"NOISE": float(noise), \
"EXPOSURES": exposures, \
"SETTLING_TIME": settling_time, \
"ZIGZAG": zigzag, \
"COMPRESSION": compression
})