Files
x07db/script/local.py
gac-ISS a44512d8d4
2023-01-18 15:56:55 +01:00

110 lines
3.2 KiB
Python

###################################################################################################
# Deployment specific global definitions - executed after startup.py
###################################################################################################
import ch.psi.pshell.epics.ChannelString as ChannelString
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
scienta.getDataArray().setMonitored(True)
# Handlig diagnostics
diag_channels = []
diag_channels.append(scienta.channelBegin)
diag_channels.append(scienta.channelEnd)
diag_channels.append(scienta.sliceBegin)
diag_channels.append(scienta.sliceEnd)
diag_channels.append(scienta.numSlices)
diag_channels.append(scienta.numChannels)
diag_channels.append(scienta.lowEnergy)
diag_channels.append(scienta.centerEnergy)
diag_channels.append(scienta.highEnergy)
diag_channels.append(scienta.stepTime)
diag_channels.append(scienta.frames)
diag_channels.append(AcquisitionMode)
diag_channels.append(EnergyMode)
diag_channels.append(LensMode)
diag_channels.append(DetectorMode)
diag_channels.append(PassEnergy)
diag_channels.append(ElementSet)
diag_channels.append(StepSize)
diag_channels.append(NumIterations)
diag_channels.append(EntranceSlit)
diag_channels.append(ExitSlit)
diag_channels = sorted(diag_channels, key=lambda channel: channel.name)
def get_diag_name(diag):
return ch.psi.utils.Str.toTitleCase(diag.getName()).replace(" ", "").replace("Readback", "")
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 + "attrs/"
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 + "attrs/"
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]))
def after_readout(rec):
#if beam_ok:
if get_exec_pars().save:
#Saving only once the diag data
if rec.index == 0:
create_diag_datasets()
append_diag_datasets()
#else:
# rec.invalidate()
def trigger_scienta():
"""
Trigger new acquisition
"""
scienta.start()
scienta.waitNewImage(-1)
def dummy_trigger_scienta():
"""
Trigger detector to update the array sizes and calibration
"""
print "Dummy trigger... "
iterations = scienta.getIterations()
scienta.setIterations(1)
try:
trigger_scienta()
finally:
scienta.setIterations(iterations)
print "Done"
def clear_scan_output():
App.getInstance().mainFrame.clearScanDisplays(None)
def start_scan_output(scan):
App.getInstance().mainFrame.setScanDisplays(scan, None)