Files
x07db/script/templates/XPS.py
gac-ISS e9ba08ce4f V2
2025-08-27 14:36:28 +02:00

141 lines
4.6 KiB
Python

import json
if get_exec_pars().debug:
print "Setting debug parameters"
NAME = None
FILE = None
PASSES = 2
R1 = """{
"scienta.acquisitionMode" : "Swept",
"scienta.elementSet" : "HiPPHAXPES",
"scienta.lensMode" : "T_HiPPHAXPES",
"scienta.detectorMode" : "ADC",
"scienta.energyMode" : "Kinetic",
"scienta.passEnergy" : 2,
"scienta.lowEnergy" : 387.0,
"scienta.centerEnergy" : 397.0,
"scienta.highEnergy" : 407.0,
"scienta.slices" : 1.0,
"scienta.stepSize" : 0.25,
"scienta.stepTime" : 0.08,
"scienta.iterations" : 1.0
} """
REGIONS = [["R1", R1]]
if FILE:
FILE = Setup.expandPath("{home}/parameters/" + FILE)
with open(FILE) as json_file:
cfg = json.load(json_file)
NAME , REGIONS, PASSES= cfg[0][0][0], cfg[1], cfg[2]
print "FILE: ", FILE
print "NAME: ", NAME
print "REGIONS: ", [name for (name, val) in REGIONS]
print "PASSES: ", PASSES
CURRENT_REGION = ""
CURRENT_INDEX = -1
CURRENT_PASS = 1
PLOT_TYPES={"spectrum":1, "energy":1}
SEQUENTIAL=False
DEBUG=False
parallel = not (SEQUENTIAL or (PASSES<=1) or (len(REGIONS)<=1))
set_exec_pars(enabled_plots=["spectrum",], plot_types=PLOT_TYPES)
for r in REGIONS:
name=r[0]
pars = json.loads(r[1])
for k,v in pars.items():
if (v is None) or (v== float("NaN")):
raise Exception ("Invalid value in region: ", r, " parameter: ", k)
set_device_alias(scienta.getSpectrum(), "spectrum")
set_device_alias(scienta.getSpectrumScale(), "energy")
set_device_alias(scienta.getDataMatrix(), "image")
set_device_alias(scienta.stats[0], "sum")
sensors=[i0, scienta.stats[0], scienta.getSpectrum(), scienta.getSpectrumScale()] #), scienta.getDataMatrix()]
def apply_pars(pars):
scienta.elementSet = scienta.elementSet.valueOf(pars["scienta.elementSet"])
scienta.lensMode = scienta.lensMode.valueOf(pars["scienta.lensMode"])
scienta.detectorMode = scienta.detectorMode.valueOf(pars["scienta.detectorMode"])
scienta.energyMode = scienta.energyMode.valueOf(pars["scienta.energyMode"])
scienta.acquisitionMode = scienta.acquisitionMode.valueOf(pars["scienta.acquisitionMode"])
scienta.passEnergy = pars["scienta.passEnergy"]
scienta.getLowEnergy().writeAsync(pars["scienta.lowEnergy"])
scienta.getCenterEnergy().writeAsync(pars["scienta.centerEnergy"])
scienta.getHighEnergy().writeAsync(pars["scienta.highEnergy"])
scienta.getSlices().writeAsync(pars["scienta.slices"])
scienta.getStepSize().writeAsync(pars["scienta.stepSize"])
scienta.getStepTime().writeAsync(pars["scienta.stepTime"])
scienta.setIterations(int(pars["scienta.iterations"]))
def set_region_index(index):
global REGIONS, CURRENT_REGION, CURRENT_INDEX
r=REGIONS[index]
name=r[0]
pars = json.loads(r[1])
CURRENT_REGION = name
CURRENT_INDEX = CURRENT_INDEX+1
if DEBUG: print "Setting Region: ", name, " ", index
apply_pars(pars)
def before_read(position, scan):
trigger_scienta()
if parallel:
start_scan_output(scan)
scanning=False
def scan(region):
if DEBUG: print "Starting scan region ", region
name=REGIONS[region][0]
def before_pass(pass_num):
global scanning, CURRENT_PASS
if DEBUG: print "Waiting for pass: " , pass_num, " on region: ", region
while (CURRENT_INDEX != (region-1)) or scanning:
time.sleep(0.1)
scanning = True
CURRENT_PASS = pass_num
if DEBUG: print "Starting pass: " , pass_num, " on region: ", region
set_region_index(region)
def after_pass(pass_num):
global scanning, CURRENT_INDEX
if DEBUG: print "Finished pass: " , pass_num, " on region: ", region
if CURRENT_INDEX>=(len(REGIONS)-1):
CURRENT_INDEX=-1
scanning = False
tscan(sensors, 1, 0.1, tag=name, passes=PASSES, #title=name, \
before_read=before_read, after_read=after_readout, \
before_pass = before_pass, after_pass=after_pass, \
name=NAME, lazy=True)
clear_scan_output()
try:
if not parallel:
for i in range(len(REGIONS)):
set_region_index(i)
tscan(sensors, PASSES, 0.1, tag=CURRENT_REGION, \
before_read=before_read, after_read=after_readout, \
name=NAME, lazy=True )
else:
scans = [[scan,[i,]] for i in range(len(REGIONS))]
parallelize(*scans)
finally:
scienta.zeroSupplies()
if DEBUG: print "Quit script"