Files
x03da/script/users/X-Treme_XPSScan.py
gac-x03da 7c0d5f0a94 Closedown
2019-03-06 09:33:13 +01:00

374 lines
15 KiB
Python

"""
Discrete scan (vector scan) of multiple spectral regions
"""
PHI_RANGE = (-160.0, 160.0) # (tuple (min, max))
THETA_RANGE = (-9.0, 81.0) # (tuple (min, max))
STEPS = (40.0, 1.0) # (tuple (phi, theta))
ZIGZAG = True
# scan positioner: Eph = photon energy
#MOTORS = (ManipulatorPhi, ManipulatorTheta)
#MOTORS = [ManipulatorPhi]
MOTORS = [dummy]
# comma-separated discrete list of scan positions
#POSITIONS = [(PHI_RA
#POSITIONS = [(PNGE[0], THETA_RANGE[0]), (PHI_RANGE[1], THETA_RANGE[1]), STEPS]
#POSITIONS = [-175., 180., 5.]
POSITIONS = [0.]
# seconds to wait between positioning command and triggering the detector
LATENCY = 0.0
# region setup
#
# for each region, define a python dictionary with the following items.
# optional items can be left unspecified and will default to the indicated values.
# for swept mode, include 'elo', 'ehi', 'estep', 'iter' values, but do not include 'efix'.
# for fixed mode, include 'efix' value, but do not include 'elo', 'ehi', 'estep', 'iter'.
#
# 'name': user-specific name of the region (for graph title and RegionName attribute in data file)
# 'elo': lower kinetic energy boundary of the spectrum
# 'ehi': upper kinetic energy boundary of the spectrum
# 'estep': energy step size
# 'efix': center kinetic energy in fixed mode
# 'epass': pass energy
# 'tstep': dwell time in seconds
# 'iter': number of iterations/sweeps (default 1)
# 'cis': True = constant initial state (photoemission line), False = constant final state (Auger peak), (default False)
# 'slit': exit slit (default current value)
#REGION1 = {'name': 'VB62eV', 'ephot': 62, 'efix': 1222.1, 'epass': 200., 'tstep': 20., 'iter': 1, 'cis': False}
#REGION2 = {'name': 'off-resonance', 'ephot': 1235.0, 'efix': 1219.4, 'epass': 200., 'tstep': 20., 'iter': 1, 'cis': False}
#REGION1 = {'name': 'VB62eV', 'ephot': 62, 'elo': 49.0, 'ehi': 58.0, 'estep': 0.002, 'epass': 10, 'tstep': 0.5, 'iter': 1, 'cis': False}
#REGION1 = {'name': 'VB62eVzoom', 'elo': 54.0, 'ehi': 58.0, 'estep': 0.002, 'epass': 10.0, 'tstep': 0.5, 'iter': 1, 'cis': True}
######### X-TREME samples ##############
# front end 4x6 mm2
# Ephot = 62 eV; if 'ephot' is not specified in the region, it will not be set!!
REG1 = {'name': '62eV_VBcoarse', 'elo': 49.0, 'ehi': 58.0, 'estep': 0.002, 'epass': 10., 'tstep': 0.5, 'iter': 1, 'slit' : 100, 'cis': True}
REG2 = {'name': '62eV_VBzoom', 'elo': 54.0, 'ehi': 58.0, 'estep': 0.002, 'epass': 10., 'tstep': 0.5, 'iter': 1, 'slit' : 100, 'cis': True}
REGIONS = [REG2, REG1]
#REGIONS = [REG1, REG2]
"""
DO NOT DO 80 eV ANY MORE # front end 3x4 mm2
# Ephot = 80 eV; if 'ephot' is not specified in the region, it will not be set!!
REG1 = {'name': 'VB_80eV_coarse', 'elo': 67.0, 'ehi': 76.0, 'estep': 0.002, 'epass': 10., 'tstep': 0.5, 'iter': 1, 'slit' : 50, 'cis': True}
REG2 = {'name': 'VB_80eV_zoom', 'elo': 72.0, 'ehi': 76.0, 'estep': 0.002, 'epass': 10., 'tstep': 0.5, 'iter': 2, 'slit' : 50, 'cis': True}
REGIONS = [REG1, REG2]
"""
"""
# front end 3x4 mm2
# Ephot = 510 eV; if 'ephot' is not specified in the region, it will not be set!!
REG1 = {'name': '510eV_Dy4d', 'elo': 340.0, 'ehi': 360.0, 'estep': 0.05, 'epass': 20., 'tstep': 0.5, 'iter': 1, 'slit' : 30, 'cis': True}
REG2 = {'name': '510eV_Ag3d', 'elo': 127.0, 'ehi': 141.0, 'estep': 0.05, 'epass': 20., 'tstep': 0.5, 'iter': 1, 'slit' : 30, 'cis': True}
REGIONS = [REG1, REG2]
"""
"""
# front end 3x4 mm2
# Ephot = 490 eV; if 'ephot' is not specified in the region, it will not be set!!
REG1 = {'name': '490eV_Dy4d', 'elo': 320.0, 'ehi': 340.0, 'estep': 0.05, 'epass': 20., 'tstep': 0.5, 'iter': 3, 'slit' : 100, 'cis': True}
#REG2 = {'name': '490eV_Ag3d', 'elo': 107.0, 'ehi': 121.0, 'estep': 0.05, 'epass': 20., 'tstep': 0.5, 'iter': 1, 'slit' : 100, 'cis': True}
REGIONS = [REG1]
"""
"""
# front end 3x4 mm2
# Ephot = 810 eV; if 'ephot' is not specified in the region, it will not be set!!
REG1 = {'name': '810eV_Tb4d', 'elo': 644.0, 'ehi': 662.0, 'estep': 0.05, 'epass': 50., 'tstep': 0.5, 'iter': 5, 'slit' : 100, 'cis': True}
REG2 = {'name': '810eV_Ag3d', 'elo': 427.0, 'ehi': 441.0, 'estep': 0.05, 'epass': 50., 'tstep': 0.5, 'iter': 1, 'slit' : 30, 'cis': True}
REGIONS = [REG1]
"""
"""
# front end 3x4 mm2
# Ephot = 810 eV; if 'ephot' is not specified in the region, it will not be set!!
REG1 = {'name': '810eV_survey', 'elo': 60.0, 'ehi': 810.0, 'estep': 0.5, 'epass': 50., 'tstep': 0.25, 'iter': 1, 'slit' : 30, 'cis': True}
REG2 = {'name': '810eV_Ag3d', 'elo': 427.0, 'ehi': 441.0, 'estep': 0.05, 'epass': 50., 'tstep': 0.2, 'iter': 1, 'slit' : 30, 'cis': True}
REG3 = {'name': '810eV_O1s', 'elo': 270.0, 'ehi': 280.0, 'estep': 0.05, 'epass': 50., 'tstep': 0.5, 'iter': 1, 'slit' : 30, 'cis': True}
#REG4 = {'name': '810eV_N1s', 'elo': 400.0, 'ehi': 416.0, 'estep': 0.05, 'epass': 50., 'tstep': 0.5, 'iter': 1, 'slit' : 30, 'cis': True}
REG4 = {'name': '810eV_N1s', 'elo': 400.0, 'ehi': 416.0, 'estep': 0.05, 'epass': 50., 'tstep': 1, 'iter': 2, 'slit' : 30, 'cis': True}
REG5 = {'name': '810eV_C1s', 'elo': 512.0, 'ehi': 528.0, 'estep': 0.05, 'epass': 50., 'tstep': 0.5, 'iter': 2, 'slit' : 30, 'cis': True}
###REGVB_NaClcoarse = {'name': '810eV_VBcoarse', 'elo': 793.0, 'ehi': 807.0, 'estep': 0.02, 'epass': 50., 'tstep': 0.5, 'iter': 1, 'slit' : 100, 'cis': True}
###REGVB_NaClfine = {'name': '810eV_VBfine', 'elo': 802.0, 'ehi': 807.0, 'estep': 0.01, 'epass': 50., 'tstep': 0.5, 'iter': 2, 'slit' : 100, 'cis': True}
REG7 = {'name': '810eV_VBzoom', 'elo': 804.0, 'ehi': 806.0, 'estep': 0.005, 'epass': 50., 'tstep': 0.5, 'iter': 1, 'slit' : 50, 'cis': True}
#REGchlorine2s = {'name': '810eV_chlorine2s', 'elo': 528.0, 'ehi': 549.0, 'estep': 0.05, 'epass': 50., 'tstep': 0.5, 'iter': 1, 'slit' : 30, 'cis': True}
#REGchlorine2p = {'name': '810eV_chlorine2p', 'elo': 600.0, 'ehi': 609.0, 'estep': 0.05, 'epass': 50., 'tstep': 0.5, 'iter': 1, 'slit' : 30, 'cis': True}
#with NaCl
#REGIONS = [REG1, REG2, REG3, REG4b, REG5, REGchlorine2s, REGchlorine2p]
#REGIONS = [REG4b, REG5, REGVB_NaClcoarse, REGVB_NaClfine]
#with MgO
REGIONS = [REG1, REG2, REG3, REG4, REG5, REG7]
##REGIONS = [REGVB_NaClfine]
"""
"""
# Ephot = 1600 eV; if 'ephot' is not specified in the region, it will not be set!!
# front end 3x4 mm2
REGsurvey = {'name': '1600eV_survey', 'elo': 100.0, 'ehi': 1600.0, 'estep': 0.5, 'epass': 100., 'tstep': 0.25, 'iter': 1, 'slit' : 50, 'cis': True}
REGMg = {'name': '1600eV_Mg1s' , 'elo': 286.0, 'ehi': 300.0, 'estep': 0.02, 'epass': 100., 'tstep': 0.5, 'iter': 1, 'slit' : 30, 'cis': True}
REGAg = {'name': '1600eV_Ag3d1' , 'elo': 1219.0, 'ehi': 1231.0, 'estep': 0.02, 'epass': 100., 'tstep': 0.5, 'iter': 1, 'slit' : 30, 'cis': True}
REGNa = {'name': '1600eV_Na1s' , 'elo': 517.0, 'ehi': 531.0, 'estep': 0.02, 'epass': 100., 'tstep': 0.5, 'iter': 1, 'slit' : 30, 'cis': True}
#REGIONS = [REGsurvey, REGMg, REGAg]
#REGIONS = [REGsurvey, REGNa, REGAg] # for NaCl/Ag
REGIONS = [REGsurvey, REGAg]
"""
"""
# list of region dictionaries to execute at each scan position
#REGIONS = [REG1, REG2]
# close beam shutter and turn off analyser at the end of the scan
CLOSE_SHUTTER_AT_END = False
"""
# --- DO NOT EDIT BELOW THIS LINE! ---
set_exec_pars(keep=False)
def check_region(region):
"""
check region dictionary items and apply defaults where necessary
"""
region['fixed'] = 'efix' in region
if region['fixed']:
region['elo'] = region['efix']
region['ehi'] = region['efix']
if 'iter' not in region:
region['iter'] = 1
print("region {0}: setting default iter = {1}".format(region['name'], region['iter']))
if 'cis' not in region:
region['cis'] = False
print("region {0}: setting default cis = {1}".format(region['name'], region['cis']))
if 'slit' not in region:
region['slit'] = ExitSlit.read()
print("region {0}: setting default slit = {1}".format(region['name'], region['slit']))
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.channel_center_dataset_name = path + "ScientaChannelCenter"
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"
self.slit_dataset_name = path + "ExitSlit"
create_dataset(self.channel_begin_dataset_name, 'd')
create_dataset(self.channel_end_dataset_name, 'd')
create_dataset(self.channel_center_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')
create_dataset(self.slit_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}".format(self.scan_index)
#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
try:
Eph.write(self.region['ephot'])
except KeyError:
pass
if self.region['fixed']:
Scienta.setAcquisitionMode(ch.psi.pshell.epics.Scienta.AcquisitionMode.Fixed)
Scienta.centerEnergy.write(elo)
else:
Scienta.setAcquisitionMode(ch.psi.pshell.epics.Scienta.AcquisitionMode.Swept)
Scienta.lowEnergy.write(elo)
Scienta.highEnergy.write(ehi)
Scienta.stepSize.write(self.region['estep'])
Scienta.setPassEnergy(int(self.region['epass']))
Scienta.stepTime.write(self.region['tstep'])
Scienta.setIterations(self.region['iter'])
ExitSlit.write(self.region['slit'])
Scienta.update()
if self.region['fixed']:
append_dataset(self.channel_center_dataset_name, elo)
else:
append_dataset(self.channel_begin_dataset_name, elo)
append_dataset(self.channel_end_dataset_name, ehi)
append_dataset(self.step_energy_dataset_name, self.region['estep'])
append_dataset(self.pass_energy_dataset_name, self.region['epass'])
append_dataset(self.step_time_dataset_name, self.region['tstep'])
append_dataset(self.iterations_dataset_name, self.region['iter'])
append_dataset(self.slit_dataset_name, self.region['slit'])
def read(self):
global current_region_index
current_region_index = self.region_index
self.setup()
print("Acquiring region {0}.".format(self.region['name']))
trig_scienta()
time.sleep(0.5)
sp = Scienta.getSpectrum().read()
return sp
def getSize(self):
if self.region['fixed']:
nx = 992
else:
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):
if self.region['fixed']:
nx = 992
else:
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):
global SENSORS
SENSORS = []
for (index, region) in enumerate(regions):
check_region(region)
reader = SpectrumReader()
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()
#ascan(motors, SENSORS, positions[0], positions[1], positions[2], latency, False, zigzag = True, before_read=wait_beam, after_read = after_readout)
#lscan(motors, SENSORS, positions[0], positions[1], positions[2], latency, False, before_read=wait_beam, after_read = after_readout)
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])
try:
################## THIS IS TO OPEN THE VALVES /SHUTTER
if caget('X03DA-OP-VG7:OPEN') == 'Not_Open':
caput('X03DA-OP-VG7:WT_SET',0) #open ES vacuum valve
time.sleep(0.2)
caput('X03DA-OP-VG7:WT_SET',1) #open ES vacuum valve
"""
caput('X03DA-OP-ST1:WT_SET_CLOSE',0) #
caput('X03DA-OP-ST1:WT_SET_OPEN',1) # open ES Shutter
print "check that shutter is open..."
while True:
if caget('X03DA-OP-ST1:OPEN') == 'Open':
break
time.sleep(0.5)
print "OK."
time.sleep(3.0)
############################################# """
setup_live_plots(REGIONS)
task = fork(update_live_plots)
do_scan(MOTORS, POSITIONS, REGIONS, LATENCY)
finally:
caput('X03DA-OP-VG7:WT_SET',1) #close ES vacuum valve
time.sleep(0.2)
caput('X03DA-OP-VG7:WT_SET',0) #close ES vacuum valve
if CLOSE_SHUTTER_AT_END:
after_scan()