Files
x03da/script/MultiRegionScan.py
2017-04-12 11:23:41 +02:00

151 lines
5.2 KiB
Python

"""
Arguments:
"""
MOTORS = [Eph]
POSITIONS = [400.0, 401.0]
LATENCY = 0.0
REGION1 = {'elo': 243.0, 'ehi': 245.0, 'estep': 0.1, 'epass': 50, 'tstep': 0.1, 'iter': 1, 'cis': True}
REGION2 = {'elo': 214.0, 'ehi': 217.0, 'estep': 0.1, 'epass': 50, 'tstep': 0.1, 'iter': 1, 'cis': False}
REGIONS = [REGION1, REGION2]
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()
print get_exec_pars().index
print get_exec_pars().group
print get_exec_pars().scanPath
self.channel_begin_dataset_name = "scan{0}/ScientaChannelBegin{1}".format(self.scan_index + 1, self.region_index + 1)
self.channel_end_dataset_name = "scan{0}/ScientaChannelEnd{1}".format(self.scan_index + 1, self.region_index + 1)
self.pass_energy_dataset_name = "scan{0}/ScientaPassEnergy{1}".format(self.scan_index + 1, self.region_index + 1)
self.step_energy_dataset_name = "scan{0}/ScientaStepEnergy{1}".format(self.scan_index + 1, self.region_index + 1)
self.step_time_dataset_name = "scan{0}/ScientaStepTime{1}".format(self.scan_index + 1, self.region_index + 1)
self.iterations_dataset_name = "scan{0}/ScientaIterations{1}".format(self.scan_index + 1, self.region_index + 1)
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):
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):
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
# plotting current spectrum
names = "Scienta spectrum"
plots = plot(None, names)
global online_spectrum_plot
spectrum_series = plots[0].getSeries(0)
task = None
def plot_cur_spectrum():
global spectrum_series
try:
while get_context().state.running:
y = Scienta.spectrum.take(100)
x = Scienta.spectrumX
spectrum_series.setData(x, y)
time.sleep(1.0)
finally:
print "Stopping spectrum plotting"
global scan_index
scan_index = -1
def do_scan(motors, positions, regions, latency):
global scan_index
global SENSORS
scan_index += 1
SENSORS = []
for (index, region) in enumerate(regions):
reader = SpectrumReader()
reader.scan_index = scan_index
reader.region_index = index
reader.region = region
reader.initialize()
set_device_alias(reader, "ScientaSpectrum{0}".format(index + 1))
SENSORS.append(reader)
image = ImageReader()
image.region_index = index
image.region = region
image.initialize()
set_device_alias(image, "ScientaImage{0}".format(index + 1))
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)
try:
set_preference(Preference.PLOT_TYPES, {'ScientaSpectrum1':1})
#task = fork(plot_cur_spectrum)
do_scan(MOTORS, POSITIONS, REGIONS, LATENCY)
finally:
if CLOSE_SHUTTER_AT_END:
after_scan()