""" Arguments: """ MOTORS = [Eph] POSITIONS_N = [540] for nn in range(52): POSITIONS_N.append(POSITIONS_N[-1]+4) POSITIONS_C = [355] for nn in range(64): POSITIONS_C.append(POSITIONS_C[-1]+4) POSITIONS_O = [600] for nn in range(64): POSITIONS_O.append(POSITIONS_O[-1]+4) LATENCY = 0.0 REGION_N1 = {'name': 'N 1s peak', 'elo': 129., 'ehi': 138.5, 'estep': 0.15, 'epass': 100, 'tstep': 1.5, 'iter': 1, 'cis': True} REGION_N2 = {'name': 'N 1s tail', 'elo': 138.5, 'ehi': 148.0, 'estep': 0.5, 'epass': 100, 'tstep': 1.5, 'iter': 1, 'cis': True} REGIONS_N = [REGION_N1, REGION_N2] REGION_C1 = {'name': 'C 1s lower tail', 'elo': 50, 'ehi': 58, 'estep': 0.5, 'epass': 50, 'tstep': 1.5, 'iter': 1, 'cis': True} REGION_C2 = {'name': 'C 1s peak', 'elo': 58, 'ehi': 68.5, 'estep': 0.15, 'epass': 50, 'tstep': 1.5, 'iter': 1, 'cis': True} REGION_C3 = {'name': 'C 1s upper tail', 'elo': 68.5, 'ehi': 78.5, 'estep': 0.5, 'epass': 50, 'tstep': 1.5, 'iter': 1, 'cis': True} REGIONS_C = [REGION_C1, REGION_C2, REGION_C3] REGION_O1 = {'name': 'O 1s lower tail', 'elo': 50, 'ehi': 60, 'estep': 0.5, 'epass': 50, 'tstep': 1.5, 'iter': 1, 'cis': True} REGION_O2 = {'name': 'O 1s peak', 'elo': 60, 'ehi': 67, 'estep': 0.15, 'epass': 50, 'tstep': 1.5, 'iter': 1, 'cis': True} REGION_O3 = {'name': 'O 1s upper tail', 'elo': 67, 'ehi': 77, 'estep': 0.5, 'epass': 50, 'tstep': 1.5, 'iter': 1, 'cis': True} REGIONS_O = [REGION_O1, REGION_O2, REGION_O3] POSITIONB = [550] REGION3 = {'name': 'N 1s peak', 'elo': 134., 'ehi': 154, 'estep': 0.05, 'epass': 50, 'tstep': 0.5, 'iter': 1, 'cis': True} REGIONSB = [REGION3] 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}".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 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): global SENSORS SENSORS = [] for (index, region) in enumerate(regions): 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() 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: setup_live_plots(REGIONSB) task = fork(update_live_plots) sample_pos = [ [-8.8,-3.60, 0.20,114.0], [-8.8,-3.60,-2.20,115.1], [-8.8,-3.60,-2.20,117.1], [11.2,-3.75, 0.20,113.0], [11.2,-3.75, 0.20,112.0], [11.2,-3.10,-2.20,116.1], [31.2,-3.60,-0.10,116.5], [31.2,-3.60, 0.25,115.5], [31.2,-2.70,-2.20,114.1], [51.2,-3.80,-0.10,118.5], [51.2,-3.80,-0.10,117.5], [51.2,-0.90,-2.20,112.1]] jj = 0 for nn in sample_pos: ManipulatorX.move(nn[1]) ManipulatorY.move(nn[2]) ManipulatorZ.move(nn[3]) ManipulatorTheta.move(nn[0]) if jj == 0: do_scan(MOTORS, POSITIONB, REGIONSB, LATENCY) #XPS before PhD do_scan(MOTORS, POSITIONS_N, REGIONS_N, LATENCY) #PhD do_scan(MOTORS, POSITIONB, REGIONSB, LATENCY) #XPS after PhD jj = 1 elif jj == 1: do_scan(MOTORS, POSITIONB, REGIONSB, LATENCY) #XPS before PhD do_scan(MOTORS, POSITIONS_C, REGIONS_C, LATENCY) #PhD do_scan(MOTORS, POSITIONB, REGIONSB, LATENCY) #XPS after PhD jj = 2 else: do_scan(MOTORS, POSITIONB, REGIONSB, LATENCY) #XPS before PhD do_scan(MOTORS, POSITIONS_O, REGIONS_O, LATENCY) #PhD do_scan(MOTORS, POSITIONB, REGIONSB, LATENCY) #XPS after PhD jj = 0 finally: if CLOSE_SHUTTER_AT_END: after_scan()