Script execution
This commit is contained in:
154
script/users/Granas/XPSSpectrum.py
Normal file
154
script/users/Granas/XPSSpectrum.py
Normal file
@@ -0,0 +1,154 @@
|
||||
#Parameters (global variables):
|
||||
# ranges: list of RangeSelection havinf args = (step_size, step_time, iterations)
|
||||
# pass_energy
|
||||
# save_scienta_image
|
||||
#
|
||||
# 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
|
||||
import org.jfree.chart.axis.NumberAxis as NumberAxis
|
||||
|
||||
cur_range = 0
|
||||
cur_iteration = 0
|
||||
|
||||
if Scienta.acquisitionMode != Scienta.AcquisitionMode.Swept:
|
||||
Scienta.acquisitionMode = Scienta.AcquisitionMode.Swept
|
||||
ret=[]
|
||||
|
||||
adjusted_ranges = []
|
||||
for cur_range in range(len(ranges)):
|
||||
r = ranges[cur_range]
|
||||
ar = [round(r.min / r.vars[1]) * r.vars[1], round(r.max / r.vars[1]) * r.vars[1]]
|
||||
adjusted_ranges.append(ar)
|
||||
|
||||
set_exec_pars(open = True)
|
||||
|
||||
#Global arguments
|
||||
Scienta.passEnergy = pass_energy
|
||||
|
||||
names=[]
|
||||
names.append("Online Spectrum")
|
||||
for i in range(len(ranges)):
|
||||
names.append(str(ranges[i]))
|
||||
plots = plot(None, names)
|
||||
|
||||
for p in plots:
|
||||
p.getAxis(p.AxisId.X).label = "kinetic energy"
|
||||
eb_axis = NumberAxis("binding energy")
|
||||
eb_axis.inverted = True
|
||||
jf = p.chart.plot
|
||||
jf.setDomainAxis(1, eb_axis)
|
||||
jf.getDomainAxis(1).labelPaint = jf.getDomainAxis(0).labelPaint
|
||||
jf.getDomainAxis(1).labelFont = jf.getDomainAxis(0).labelFont
|
||||
jf.getDomainAxis(1).tickLabelPaint = jf.getDomainAxis(0).tickLabelPaint
|
||||
jf.getDomainAxis(1).tickLabelFont = jf.getDomainAxis(0).tickLabelFont
|
||||
|
||||
|
||||
# online spectrum
|
||||
|
||||
p = plots[0]
|
||||
spectrum_series = p.getSeries(0)
|
||||
spectrum_eb_axis = p.chart.plot.getDomainAxis(1)
|
||||
def plot_cur_spectrum():
|
||||
global spectrum_series
|
||||
global spectrum_eb_axis
|
||||
try:
|
||||
while get_context().state.running:
|
||||
y = Scienta.spectrum.take(100)
|
||||
x = Scienta.spectrumX
|
||||
spectrum_series.setData(x, y)
|
||||
eb1 = Eph.take(100) - Scienta.lowEnergy.take(100) - 4.5
|
||||
eb2 = Eph.take(100) - Scienta.highEnergy.take(100) - 4.5
|
||||
spectrum_eb_axis.setRange(eb2, eb1)
|
||||
time.sleep(1.0)
|
||||
finally:
|
||||
print "Stopping spectrum plotting"
|
||||
task = None
|
||||
|
||||
|
||||
# measurements
|
||||
|
||||
try:
|
||||
for cur_range in range(len(ranges)):
|
||||
cur_iteration = 0
|
||||
skip_iteration = False
|
||||
Scienta.lowEnergy.write(adjusted_ranges[cur_range][0])
|
||||
Scienta.highEnergy.write(adjusted_ranges[cur_range][1])
|
||||
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
|
||||
image_data = None
|
||||
task = fork(plot_cur_spectrum)
|
||||
|
||||
path="scan" + str(cur_range+1) + "/"
|
||||
for cur_iteration in range(vars[2]):
|
||||
p = plots[cur_range+1]
|
||||
p.setTitle(str(ranges[cur_range]) + " - iteration " + str(cur_iteration+1))
|
||||
while True:
|
||||
wait_beam()
|
||||
trig_scienta()
|
||||
spectrum_array = Scienta.spectrum.read()
|
||||
if beam_ok:
|
||||
break
|
||||
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
|
||||
p.getSeries(0).setData(xdata, ydata)
|
||||
eb_axis = p.chart.plot.getDomainAxis(1)
|
||||
eb1 = Eph.take(100) - Scienta.lowEnergy.take(100) - 4.5
|
||||
eb2 = Eph.take(100) - Scienta.highEnergy.take(100) - 4.5
|
||||
eb_axis.setRange(eb2, eb1)
|
||||
|
||||
if save_scienta_image:
|
||||
image_array = Scienta.dataMatrix.read()
|
||||
if image_data is None:
|
||||
image_data = image_array
|
||||
else:
|
||||
for k in range (len(image_data)):
|
||||
for j in range (len(image_data[0])):
|
||||
image_data[k][j] = image_data[k][j] + image_array[k][j]
|
||||
if skip_iteration:
|
||||
break
|
||||
save_dataset(path + "ScientaSpectrum", ydata)
|
||||
set_attribute(path, "Iterations",cur_iteration+1)
|
||||
if save_scienta_image:
|
||||
save_dataset(path + "ScientaImage", image_data)
|
||||
if cur_iteration==0:
|
||||
save_dataset(path + "ScientaChannels", xdata)
|
||||
set_attribute(path + "ScientaChannels", ATTR_WRITABLE_DIMENSION, 1)
|
||||
set_attribute(path, "Range Low", adjusted_ranges[cur_range][0])
|
||||
set_attribute(path, "Range High", adjusted_ranges[cur_range][1])
|
||||
set_attribute(path, "Step Time", vars[0])
|
||||
set_attribute(path, "Step Size", vars[1])
|
||||
set_attribute(path, "Pass Energy",pass_energy)
|
||||
set_attribute(path, "Readables", ["ScientaSpectrum","ScientaImage"] if save_scienta_image else ["ScientaSpectrum",])
|
||||
set_attribute(path, "Writables", ["ScientaChannels",])
|
||||
create_diag_datasets(path)
|
||||
append_diag_datasets(path)
|
||||
|
||||
plots[cur_range+1].setTitle(str(ranges[cur_range]))
|
||||
ret.append((xdata, ydata))
|
||||
|
||||
|
||||
finally:
|
||||
cur_range = -1
|
||||
if not Scienta.isReady():
|
||||
Scienta.stop()
|
||||
Scienta.update()
|
||||
task[0].cancel(True)
|
||||
if ENDSCAN:
|
||||
after_scan()
|
||||
|
||||
set_return(to_array(ret,'o'))
|
||||
Reference in New Issue
Block a user