Files
x03da/script/XPSSpectrum.py
2016-04-05 11:18:16 +02:00

99 lines
3.1 KiB
Python

#Parameters (global variables):
# ranges: list of RangeSelection havinf args = (step_size, step_time, iterations)
# pass_energy
#
# skip_iteration: if set to 1 then skips after end of current iteration
from ch.psi.pshell.data.LayoutDefault import ATTR_WRITABLE_DIMENSION as ATTR_WRITABLE_DIMENSION
cur_range = 0
cur_iteration = 0
if Scienta.acquisitionMode == Scienta.AcquisitionMode.Fixed:
Scienta.acquisitionMode = Scienta.AcquisitionMode.Swept
ret=[]
#Global arguments
Scienta.passEnergy = pass_energy
names=[]
for i in range(len(ranges)):
names.append(str(ranges[i]))
names.append("Spectrum")
plots = plot(None, names)
spectrum_series = plots[len(names)-1].getSeries(0)
def plot_cur_spectrum():
global spectrum_series
try:
while True:
y = Scienta.spectrum.take(100)
x = Scienta.spectrumX
spectrum_series.setData(x, y)
time.sleep(1.0)
finally:
print "Stopping spectrum plotting"
task = None
try:
for cur_range in range(len(ranges)):
cur_iteration = 0
skip_iteration = False
Scienta.lowEnergy.write(ranges[cur_range].min)
Scienta.highEnergy.write(ranges[cur_range].max)
Scienta.update()
vars = ranges[cur_range].vars
Scienta.stepTime.write(vars[0])
Scienta.stepSize.write(vars[1])
Scienta.setIterations(1)
set_adc_averaging()
#iterations done in script
xdata = None
ydata = None
task = fork(plot_cur_spectrum)
for cur_iteration in range(vars[2]):
plots[cur_range].setTitle(str(ranges[cur_range]) + " - iteration " + str(cur_iteration+1))
trig_scienta()
spectrum_array = Scienta.spectrum.read()
if ydata is None:
ydata = spectrum_array
else:
for k in range (len(spectrum_array)):
ydata[k] = ydata[k] + spectrum_array[k]
if xdata is None:
xdata = Scienta.spectrumX
plots[cur_range].getSeries(0).setData(xdata, ydata)
if skip_iteration:
break
plots[cur_range].setTitle(str(ranges[cur_range]))
ret.append((xdata, ydata))
data1d = [1,2,3,4,5]
path="scan" + str(cur_range+1) + "/"
save_dataset(path + "ScientaSpectrum", ydata)
save_dataset(path + "channels", xdata)
set_attribute(path + "channels", ATTR_WRITABLE_DIMENSION, 1)
set_attribute(path, "Range Low", ranges[cur_range].min)
set_attribute(path, "Range High", ranges[cur_range].max)
set_attribute(path, "Step Time",vars[0])
set_attribute(path, "Step Size",vars[1])
set_attribute(path, "Pass Energy",pass_energy)
set_attribute(path, "Iterations",cur_iteration+1)
set_attribute(path, "Readables", ["ScientaSpectrum",])
set_attribute(path, "Writables", ["channels",])
create_diag_datasets(path)
append_diag_datasets(path)
finally:
cur_range = 0
if not Scienta.isReady():
Scienta.stop()
Scienta.update()
task[0].cancel(True)
set_return(to_array(ret,'o'))