""" 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() 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) create_dataset(self.channel_begin_dataset_name, 'd') create_dataset(self.channel_end_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']) append_dataset(self.channel_begin_dataset_name, elo) append_dataset(self.channel_end_dataset_name, ehi) 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 scan_index = -1 def do_scan(motors, positions, regions, latency): sensors = [SampleCurrent, RefCurrent] scan_index += 1 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) 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, {'Scienta spectrum':1}) do_scan(MOTORS, POSITIONS, REGIONS, LATENCY) finally: if CLOSE_SHUTTER_AT_END: after_scan()