Files
x03da/script/users/TUM/TUM_multi_XPS_201908.py
2019-08-27 02:11:50 +02:00

261 lines
10 KiB
Python

"""
Arguments:
"""
LATENCY = 0.0
MOTORS = [Eph]
POSITIONS_2 = [550]
REGION_2 = {'name': 'N1s', 'elo': 143, 'ehi': 149., 'estep': 0.05, 'epass': 50, 'tstep': 0.5, 'iter': 15, 'cis': True}
REGIONS_2 = [REGION_2]
POSITIONS_3 = [550]
REGION_3 = {'name': 'Ag3d', 'elo': 144., 'ehi': 151., 'estep': 0.05, 'epass': 50, 'tstep': 0.5, 'iter': 1, 'cis': True}
REGIONS_3 = [REGION_3]
#POSITIONS_4 = [435]
#REGION_4 = {'name': 'C1s', 'elo': 141, 'ehi': 151., 'estep': 0.05, 'epass': 10, 'tstep': 0.5, 'iter': 10, 'cis': True}
#REGIONS_4 = [REGION_4]
#POSITIONS_5 = [435]
#REGION_5 = {'name': 'Au4f', 'elo': 345., 'ehi': 349., 'estep': 0.05, 'epass': 10, 'tstep': 0.5, 'iter': 1, 'cis': True}
#REGIONS_5 = [REGION_5]
#POSITIONS_6 = [350]
#REGION_6 = {'name': 'B1s', 'elo': 150., 'ehi': 159., 'estep': 0.05, 'epass': 10, 'tstep': 0.5, 'iter': 15, 'cis': True}
#REGIONS_6 = [REGION_6]
#POSITIONS_7 = [350]
#REGION_7 = {'name': 'Au4f', 'elo': 260., 'ehi': 264., 'estep': 0.05, 'epass': 10, 'tstep': 0.5, 'iter': 1, 'cis': True}
#REGIONS_7 = [REGION_7]
#POSITIONS_8 = [350]
#REGION_8 = {'name': 'Cl2p', 'elo': 142., 'ehi': 150., 'estep': 0.05, 'epass': 10, 'tstep': 0.5, 'iter': 15, 'cis': True}
#REGIONS_8 = [REGION_8]
#POSITIONS_9 = [190]
#REGION_9 = {'name': 'Br3d', 'elo': 112., 'ehi': 121., 'estep': 0.05, 'epass': 10, 'tstep': 0.5, 'iter': 15, 'cis': True}
#REGIONS_9 = [REGION_9]
#POSITIONS_10 = [190]
#REGION_10 = {'name': 'FE', 'elo': 184., 'ehi': 187., 'estep': 0.05, 'epass': 10, 'tstep': 0.5, 'iter': 20, 'cis': True}
#REGIONS_10 = [REGION_10]
#POSITIONS_11 = [70]
#REGION_11 = {'name': 'Valence', 'elo': 55., 'ehi': 68., 'estep': 0.05, 'epass': 10, 'tstep': 0.5, 'iter': 10, 'cis': True}
#REGIONS_11 = [REGION_11]
#POSITIONS_9 = [550]
#REGION_9 = {'name': 'Ag3d', 'elo': 174, 'ehi': 180., 'estep': 0.05, 'epass': 10, 'tstep': 0.5, 'iter': 1, 'cis': True}
#REGIONS_9 = [REGION_9]
#POSITIONS_10 = [70]
#REGION_10 = {'name': 'Valence', 'elo': 55., 'ehi': 67., 'estep': 0.05, 'epass': 10, 'tstep': 0.5, 'iter': 10, 'cis': True}
#REGIONS_10 = [REGION_10]
#POSITIONS_4 = [435]
#REGION_4 = {'name': 'Ag3d', 'elo': 59, 'ehi': 66., 'estep': 0.05, 'epass': 10, 'tstep': 0.5, 'iter': 1, 'cis': True}
#REGIONS_4 = [REGION_4]
#POSITIONS_7 = [350]
#REGION_7 = {'name': 'Ag4s', 'elo': 243., 'ehi': 253., 'estep': 0.05, 'epass': 10, 'tstep': 0.5, 'iter': 10, 'cis': True}
#REGIONS_7 = [REGION_7]
#POSITIONS_9 = [190]
#REGION_9 = {'name': 'Ag4s', 'elo': 83., 'ehi': 93., 'estep': 0.05, 'epass': 10, 'tstep': 0.5, 'iter': 10, 'cis': True}
#REGIONS_9 = [REGION_9]
CLOSE_SHUTTER_AT_END = True
Scienta.setAcquisitionMode(ch.psi.pshell.epics.Scienta.AcquisitionMode.Swept)
class SpectrumReader(ReadonlyRegisterBase, ReadonlyRegisterArray):
def initialize(self):
#super(SpectrumReader, self).initialize()
self.scan_index = -1
def create_datasets(self):
path = get_exec_pars().scanPath + self.region_name + "/"
self.channel_begin_dataset_name = path + "ScientaChannelBegin"
self.channel_end_dataset_name = path + "ScientaChannelEnd"
self.pass_energy_dataset_name = path + "ScientaPassEnergy"
self.step_energy_dataset_name = path + "ScientaStepEnergy"
self.step_time_dataset_name = path + "ScientaStepTime"
self.iterations_dataset_name = path + "ScientaIterations"
create_dataset(self.channel_begin_dataset_name, 'd')
create_dataset(self.channel_end_dataset_name, 'd')
create_dataset(self.pass_energy_dataset_name, 'd')
create_dataset(self.step_energy_dataset_name, 'd')
create_dataset(self.step_time_dataset_name, 'd')
create_dataset(self.iterations_dataset_name, 'd')
def setup(self):
if self.scan_index != get_exec_pars().index:
self.scan_index = get_exec_pars().index
self.create_datasets()
if self.region_index == 0:
print "scan {0}: Polar = {pol}, Azimuth = {azm}, x = {X}, y = {Y}, z = {Z}".format(self.scan_index,pol=self.sample_pos[0],azm=self.sample_pos[1],X=self.sample_pos[2],Y=self.sample_pos[3],Z=self.sample_pos[4])
ephot = Eph.read()
try:
if self.region['cis']:
edelta = ephot - self.ephot_start
else:
edelta = 0.0
except AttributeError:
self.ephot_start = ephot
edelta = 0.0
elo = self.region['elo'] + edelta
ehi = self.region['ehi'] + edelta
Scienta.lowEnergy.write(elo)
Scienta.highEnergy.write(ehi)
Scienta.stepSize.write(self.region['estep'])
Scienta.setPassEnergy(self.region['epass'])
Scienta.stepTime.write(self.region['tstep'])
Scienta.setIterations(self.region['iter'])
Scienta.update()
append_dataset(self.channel_begin_dataset_name, elo)
append_dataset(self.channel_end_dataset_name, ehi)
append_dataset(self.pass_energy_dataset_name, self.region['epass'])
append_dataset(self.step_energy_dataset_name, self.region['estep'])
append_dataset(self.step_time_dataset_name, self.region['tstep'])
append_dataset(self.iterations_dataset_name, self.region['iter'])
def read(self):
global current_region_index
current_region_index = self.region_index
self.setup()
print "Photon energy {ephot} eV. Acquiring spectrum {elo}-{ehi} eV.".format(ephot=Eph.read(), elo=Scienta.lowEnergy.value, ehi=Scienta.highEnergy.value)
trig_scienta()
time.sleep(0.5)
sp = Scienta.getSpectrum().read()
return sp
def getSize(self):
nx = int((self.region['ehi'] - self.region['elo']) / self.region['estep']) + 1
return nx
class ImageReader(ReadonlyRegisterBase, ReadonlyRegisterMatrix):
def read(self):
return Scienta.getDataMatrix().read()
def getWidth(self):
nx = int((self.region['ehi'] - self.region['elo']) / self.region['estep']) + 1
return nx
def getHeight(self):
ny = Scienta.slices.read()
return ny
def setup_live_plots(regions):
global live_plots
global current_region_index
names = [region['name'] for region in regions]
live_plots = plot(None, names, title="Live Spectra")
current_region_index = 0
def update_live_plots():
global live_plots
global current_region_index
try:
while get_context().state.running:
y = Scienta.spectrum.take(100)
x = Scienta.spectrumX
try:
series = live_plots[current_region_index].getSeries(0)
series.setData(x, y)
except IndexError:
pass
time.sleep(1.0)
finally:
print "Stopping live spectra"
def do_scan(motors, positions, regions, latency, sample_position):
global SENSORS
SENSORS = []
for (index, region) in enumerate(regions):
reader = SpectrumReader()
reader.sample_pos = sample_position
reader.region_index = index
reader.region_name = "region{0}".format(index + 1)
reader.region = region
reader.initialize()
set_device_alias(reader, reader.region_name + "/ScientaSpectrum")
SENSORS.append(reader)
image = ImageReader()
image.region_index = index
image.region = region
image.initialize()
set_device_alias(image, reader.region_name + "/ScientaImage")
SENSORS.append(image)
SENSORS.append(SampleCurrent)
SENSORS.append(RefCurrent)
adjust_sensors()
set_adc_averaging()
vscan(motors, SENSORS, positions, True, latency,False, before_read=wait_beam, after_read = after_readout)
for (index, region) in enumerate(regions):
set_attribute(get_exec_pars().scanPath + "region{0}/ScientaSpectrum".format(index + 1), "RegionName", region['name'])
set_attribute(get_exec_pars().scanPath + "region{0}/ScientaImage".format(index + 1), "RegionName", region['name'])
set_attribute(get_exec_pars().scanPath, "Regions", [region['name'] for region in regions])
#set_attribute(get_exec_pars().scanPath + + "region{0}/Polar".format(index + 1), "Polar", polar)
#set_attribute(get_exec_pars().scanPath + + "region{0}/Azimuth".format(index + 1), "Azimuth", azimuth)
try:
setup_live_plots(REGIONS_1)
task = fork(update_live_plots)
# theta (polar), phi (azimuth), x, y, z
#sample_pos = [[-9.1,-90.0,-3.45, -0.5, 115.1]]
#sample_pos = [[-9.1,-90.0, -2.6, -0.5, 115.1]]
sample_pos = [[-9.1,-90.0, 0.45, -0.5, 115.1]]
for (index, nn) in enumerate(sample_pos):
polar = nn[0]
azimuth = nn[1]
ManipulatorX.move(nn[2])
ManipulatorY.move(nn[3])
ManipulatorZ.move(nn[4])
ManipulatorTheta.move(polar)
#ManipulatorPhi.move(nn[1])
if index == 0:
#do_scan(MOTORS, POSITIONS_QUICK, REGIONS_QUICK, LATENCY, nn)
#do_scan(MOTORS, POSITIONS_1, REGIONS_1, LATENCY, nn)
do_scan(MOTORS, POSITIONS_2, REGIONS_2, LATENCY, nn)
do_scan(MOTORS, POSITIONS_3, REGIONS_3, LATENCY, nn)
#do_scan(MOTORS, POSITIONS_4, REGIONS_4, LATENCY, nn)
#do_scan(MOTORS, POSITIONS_5, REGIONS_5, LATENCY, nn)
#do_scan(MOTORS, POSITIONS_6, REGIONS_6, LATENCY, nn)
#do_scan(MOTORS, POSITIONS_7, REGIONS_7, LATENCY, nn)
#do_scan(MOTORS, POSITIONS_8, REGIONS_8, LATENCY, nn)
#do_scan(MOTORS, POSITIONS_9, REGIONS_9, LATENCY, nn)
#do_scan(MOTORS, POSITIONS_10, REGIONS_10, LATENCY, nn)
#do_scan(MOTORS, POSITIONS_11, REGIONS_11, LATENCY, nn)
#do_scan(MOTORS, POSITIONS_4, REGIONS_4, LATENCY, nn)
#do_scan(MOTORS, POSITIONS_5, REGIONS_5, LATENCY, nn)
#elif index == 3:
#do_scan(MOTORS, POSITIONS_6, REGIONS_6, LATENCY, nn)
#do_scan(MOTORS, POSITIONS_7, REGIONS_7, LATENCY, nn)
#do_scan(MOTORS, POSITIONS_dummy2, REGIONS_dummy2, LATENCY, nn)
#do_scan(MOTORS, POSITIONS_8, REGIONS_8, LATENCY, nn)
finally:
if CLOSE_SHUTTER_AT_END:
after_scan()