Files
x04sa-es3/script/local.py
2018-10-30 17:35:47 +01:00

168 lines
4.4 KiB
Python

###################################################################################################
# Deployment specific global definitions - executed after startup.py
###################################################################################################
class MyInterlock1 (Interlock):
def __init__(self):
Interlock.__init__(self, (alpha, gamma))
def check(self, (a, g)):
if a>=g:
return False
return True
#interlock1 = MyInterlock1()
def open_shutter():
"""
"""
shutter.write("On")
time.sleep(0.1)
def close_shutter():
"""
"""
shutter.write("Off")
run("cpython/wrapper")
run("device/Mythen")
run("device/Pixel")
run("device/Image")
def after_sample(record, scan):
close_shutter()
count_time = 1.0
count_id = None
image_filename = None
def trigger_detectors(position, scan):
global count_time, count_id, image_filename
pix_is_on = pixel in scan.readables
mythen.abort()
open_shutter()
try:
if (count_time != 0):
if pix_is_on:
pixel.set_expose(count_time)
pixel.start()
if (count_time > 0):
mythen.set_acquire_time(count_time)
mythen.set_acquire_mode("Single")
mythen.start()
else:
print "Preset monitor counting is not supported\!"
#waitcount
if pix_is_on:
pixel.wait_finished()
i = 0
while (mythen.is_acquiring()):
time.sleep (0.05)
i += 1
if (i * 0.05 >= count_time * 2):
print "MYTHEN Izero times out, status: " + str(mythen.get_status())
break
#count_end()
# update the IMAGE_FILENAME and COUNT_ID variables
if pix_is_on:
image_filename = pixel.get_image_filename()
count_id = pixel.doUpdate()
#pixel.logwrite()
else :
image_filename = None
count_id = + 1
finally:
close_shutter()
def save_metadata(rec):
print "Acquired record ", rec.index
if get_exec_pars().save:
if rec.index == 0:
create_diag_datasets()
append_diag_datasets()
"""
#get_counts
global COUNT_ID
S[0] = mythen.acquire_time.read()
S[1] = mythen.read() #get_total_counts
# S[2] is detector counts from image.mac ###TODO
S[3] = S[2] / count_time / transm.getValue()
S[5] = transm.readback.read()
#TODO:Auto
# set threshold counts in case auto-level support is available
#if "AUTO_THRESH1" in globals():
# AUTO_THRESH1_COUNT = (S[2]>=AUTO_THRESH1)?S[2]:0
# AUTO_THRESH2_COUNT = (S[2]>=AUTO_THRESH2)?S[2]:0
# AUTO_THRESH3_COUNT = (S[2]>=AUTO_THRESH3)?S[2]:0
# AUTO_THRESH4_COUNT = (S[2]>=AUTO_THRESH4)?S[2]:0
#user_getcounts
#TODO: image
#imageUserGetcounts()
"""
diag_channels = [ phi, \
omegaH,
nu,\
omegaV, \
alpha, \
delta, \
gamma, \
xv, \
y1, \
y2, \
y3, \
trx, \
thy, \
]
def get_diag_name(diag):
return ch.psi.utils.Str.toTitleCase(diag.getName()).replace(" ", "")
def print_diag():
for f in diag_channels:
print "%-25s %s" % (get_diag_name(f) , str(f.read()))
def create_diag_datasets(parent = None):
if parent is None:
parent = get_exec_pars().group
group = parent + "meta/"
for f in diag_channels:
create_dataset(group+get_diag_name(f) , 's' if (type(f) is ch.psi.pshell.epics.ChannelString) else 'd')
def append_diag_datasets(parent = None):
if parent is None:
parent = get_exec_pars().group
group = parent + "meta/"
for f in diag_channels:
try:
x = f.read()
if x is None:
x = '' if (type(f) is ch.psi.pshell.epics.ChannelString) else float('nan')
append_dataset(group+get_diag_name(f), x)
except:
log("Error sampling " + str(get_diag_name(f)) + ": " + str(sys.exc_info()[1]))
#PSEUDO_DEVICES = h, k, l, lambda