Script execution

This commit is contained in:
gac-x03da
2019-07-09 18:27:57 +02:00
parent 6d304bee6d
commit bb52067b67

View File

@@ -1,23 +1,55 @@
"""
Discrete scan (vector scan) of multiple spectral regions
Line/vector/area/holo scan of multiple spectral regions
save this script into your script/user folder before editing!
usage:
1. uncomment one of the MOTORS lines.
add another line if necessary.
2. uncomment one of the scan blocks and adjust the parameters.
add another block if necessary.
3. declare the regions.
4. add the regions to the REGIONS list.
5. run the script.
"""
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]
# dummy scan (time series)
MOTORS = [dummy]
# comma-separated discrete list of scan positions
# photon energy scan (do not include 'ephot' in regions in this case!)
#MOTORS = [Eph]
# phi scan
#MOTORS = [ManipulatorPhi]
# holo scan
#MOTORS = (ManipulatorPhi, ManipulatorTheta)
# 2D YZ scan
#MOTORS = [ManipulatorY, ManipulatorZ]
# line scan [start, stop, step]
POSITIONS = [0., 10., 0.5]
SCAN = 'lscan'
# vector scan [pos1, pos2, pos3, ...]
#POSITIONS = [200., 300., 400., 500.]
#SCAN = 'vscan'
# area scan [(start1, start2), (stop1, stop2), (step1, step2)]
# corresponding to (positioner1, positioner2)
#POSITIONS = [(-1., 114.), (+1., 116.), (20, 20)]
#ZIGZAG = True
#SCAN = 'ascan'
# holo scan
#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
#POSITIONS = [(PHI_RANGE[0], THETA_RANGE[0]), (PHI_RANGE[1], THETA_RANGE[1]), STEPS]
POSITIONS = [0., 100., 1.]
#POSITIONS = [0.]
#SCAN = 'ascan'
# 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.
@@ -31,15 +63,14 @@ LATENCY = 0.0
# 'estep': energy step size
# 'efix': center kinetic energy in fixed mode
# 'epass': pass energy
# 'ephot': photon energy (default: unchanged)
# '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)
# 'slit': exit slit (default: unchanged)
REGION1 = {'name': 'on-resonance', 'ephot': 1237.7, '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': 'secondary', 'elo': 9.0, 'ehi': 11.0, 'estep': 0.02, 'epass': 2, 'tstep': 0.20, 'iter': 1, 'cis': False}
#REGION2 = {'name': 'fermi', 'elo': 23.5, 'ehi': 27.5, 'estep': 0.02, 'epass': 2, 'tstep': 0.35, 'iter': 1, 'cis': False}
REGION1 = {'name': 'peak 1', 'ephot': 1237.7, 'efix': 1222.1, 'epass': 50., 'tstep': 5., 'iter': 1, 'cis': False}
REGION2 = {'name': 'peak 2', 'ephot': 1235.0, 'efix': 1219.4, 'epass': 50., 'tstep': 5., 'iter': 1, 'cis': False}
# list of region dictionaries to execute at each scan position
REGIONS = [REGION1, REGION2]
@@ -97,42 +128,56 @@ class SpectrumReader(ReadonlyRegisterBase, ReadonlyRegisterArray):
create_dataset(self.slit_dataset_name, 'd')
def setup(self):
print("spectrum.setup")
# print("spectrum.setup")
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)
try:
Eph.move(self.region['ephot'])
except KeyError:
pass
#ephot = Eph.read()
#try:
# if self.region['cis']:
# edelta = ephot - self.ephot_start
# else:
# edelta = 0.0
#except AttributeError:
# self.ephot_start = ephot
ephot = Eph.take(100)
edelta = 0.0
if isinstance(ephot, float) and ephot > 0.:
try:
if self.region['cis']:
edelta = ephot - self.ephot_start
except AttributeError:
self.ephot_start = ephot
elo = self.region['elo'] + edelta
ehi = self.region['ehi'] + edelta
if self.region['fixed']:
Eph.write(self.region['ephot'])
Scienta.setAcquisitionMode(ch.psi.pshell.epics.Scienta.AcquisitionMode.Fixed)
Scienta.centerEnergy.write(elo)
else:
Eph.write(self.region['ephot'])
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(self.region['epass'])
#Scienta.stepTime.write(self.region['tstep'])
#Scienta.setIterations(self.region['iter'])
#ExitSlit.write(self.region['slit'])
#Scienta.update()
try:
Scienta.setPassEnergy(self.region['epass'])
except KeyError:
pass
try:
Scienta.stepTime.write(self.region['tstep'])
except KeyError:
pass
try:
Scienta.setIterations(self.region['iter'])
except KeyError:
pass
try:
ExitSlit.move(self.region['slit'])
except KeyError:
pass
Scienta.update()
if self.region['fixed']:
append_dataset(self.channel_center_dataset_name, elo)
@@ -147,7 +192,7 @@ class SpectrumReader(ReadonlyRegisterBase, ReadonlyRegisterArray):
append_dataset(self.slit_dataset_name, self.region['slit'])
def read(self):
print("spectrum.read")
# print("spectrum.read")
global current_region_index
current_region_index = self.region_index
self.setup()
@@ -167,7 +212,7 @@ class SpectrumReader(ReadonlyRegisterBase, ReadonlyRegisterArray):
class ImageReader(ReadonlyRegisterBase, ReadonlyRegisterMatrix):
def read(self):
print("image.read")
# print("image.read")
return Scienta.getDataMatrix().read()
def getWidth(self):
@@ -204,7 +249,7 @@ def update_live_plots():
finally:
print "Stopping live spectra"
def do_scan(motors, positions, regions, latency):
def do_scan(scan, motors, positions, regions, latency):
global SENSORS
SENSORS = []
@@ -232,9 +277,14 @@ def do_scan(motors, positions, regions, latency):
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)
if scan == 'ascan':
ascan(motors, SENSORS, positions[0], positions[1], positions[2], latency, False, zigzag = True, before_read=wait_beam, after_read = after_readout)
elif scan == 'lscan':
lscan(motors, SENSORS, positions[0], positions[1], positions[2], latency, False, before_read=wait_beam, after_read = after_readout)
elif scan == 'vscan':
vscan(motors, SENSORS, positions, True, latency,False, before_read=wait_beam, after_read = after_readout)
else:
print('unknown scan mode {}'.format(scan))
for (index, region) in enumerate(regions):
set_attribute(get_exec_pars().scanPath + "region{0}/ScientaSpectrum".format(index + 1), "RegionName", region['name'])
@@ -244,7 +294,8 @@ def do_scan(motors, positions, regions, latency):
try:
setup_live_plots(REGIONS)
task = fork(update_live_plots)
do_scan(MOTORS, POSITIONS, REGIONS, LATENCY)
do_scan(SCAN, MOTORS, POSITIONS, REGIONS, LATENCY)
finally:
if CLOSE_SHUTTER_AT_END:
after_scan()