Exemple #1
0
    def scan(self):
        total_points = self.config.steps_1 * self.config.steps_2
        ref_value = 1.0

        for i, x2 in enumerate(self.config.positions_2):
            if i < self.config.position:
                continue
            if self.stopped:
                break
            self.config.m2.move_to(x2, wait=True)
            x1_positions = self.config.positions_1 if not self.config.snake else reversed(
                self.config.positions_1)
            for j, x1 in enumerate(x1_positions):
                if self.stopped:
                    break
                self.config.m1.move_to(x1, wait=True)

                counts = misc.multi_count(self.config.exposure,
                                          *self.config.counters)
                if self.config.i0:
                    if i == 0:
                        ref_value = counts[-1]
                    counts = (counts[0] * ref_value / counts[-1], ) + counts

                position = j + i * self.config.steps_2
                row = (
                    x1,
                    x2,
                ) + counts
                self.raw_data.append(row)
                self.emit("new-point", row)
                self.emit("progress", position / total_points, "")
                time.sleep(0)
            self.emit('new-row', i + 1)
Exemple #2
0
    def scan(self):
        ref_value = 1.0
        for i in range(self.config.steps):
            if self.stopped:
                logger.info("Scan stopped!")
                break
            if i < self.config.position:
                continue
            x1 = self.config.positions_1[i]
            x2 = self.config.positions_2[i]
            self.config.m1.move_to(x1)
            self.config.m2.move_to(x2)
            self.config.m1.wait()
            self.config.m2.wait()

            counts = misc.multi_count(self.config.exposure,
                                      *self.config.counters)
            if self.config.i0:
                if i == 0:
                    ref_value = counts[-1]
                counts = (counts[0] * ref_value / counts[-1], ) + counts

            row = (
                x1,
                x2,
            ) + counts
            self.raw_data.append(row)
            self.emit("new-point", row)
            self.emit("progress", (i + 1.0) / self.config.steps, "")
            time.sleep(0)
Exemple #3
0
    def scan(self):
        ref_value = 1.0
        for i, x in enumerate(self.config.positions):
            if self.stopped:
                logger.info("Scan stopped!")
                break

            # skip to current position
            if i < self.config.position: continue

            self.config.m1.move_to(x, wait=True)
            counts = misc.multi_count(self.config.exposure,
                                      *self.config.counters)
            if self.config.i0:
                if i == 0:
                    ref_value = counts[-1]
                counts = (counts[0] * ref_value / counts[-1], ) + counts

            row = (x, ) + counts
            self.raw_data.append(row)
            self.emit("new-point", row)
            self.emit("progress", (i + 1.0) / self.config.steps, "")
            time.sleep(0)
Exemple #4
0
    def scan(self):
        logger.info('Scan waiting for beamline to become available.')

        with self.beamline.lock:
            saved_attenuation = self.beamline.attenuator.get()
            self.raw_data = []
            self.results = {'data': [], 'scans': []}
            try:
                self.emit('started', None)
                self.prepare_for_scan()
                self.beamline.fast_shutter.open()
                self.beamline.fast_shutter.open()

                # calculate k and time for each target point
                self.total_time = 1.0
                targets_times = []
                for i, v in enumerate(self.config['targets']):
                    k = converter.energy_to_kspace(v -
                                                   self.config['edge_energy'])
                    t = scitools.exafs_time_func(self.config['exposure'], k)
                    targets_times.append((i, v, k, t))
                    self.total_time += t
                self.total_time *= self.config['scans']

                used_time = 0.0
                scan_length = len(self.config['targets'])
                reference = 1.0
                self.config['start_time'] = datetime.now(tz=pytz.utc)
                for scan in range(self.config['scans']):
                    self.scan_index = scan + 1
                    for i, x, k, t in targets_times:
                        if self.paused:
                            self.emit('paused', True, '')
                            logger.warning("Edge Scan paused at point %s." %
                                           str(x))
                            while self.paused and not self.stopped:
                                time.sleep(0.05)

                            self.beamline.manager.collect(wait=True)
                            self.beamline.multi_mca.configure(nozzle=True,
                                                              cooling=True)
                            self.emit('paused', False, '')
                            logger.info("Scan resumed.")
                        if self.stopped:
                            logger.info("Scan stopped!")
                            break

                        self.beamline.bragg_energy.move_to(x, wait=True)
                        y, i0 = multi_count(self.beamline.multi_mca,
                                            self.beamline.i0, t)
                        mca_values = self.beamline.multi_mca.get_roi_counts()
                        if i == 0:
                            scale = 1.0
                            reference = i0 * t
                        else:
                            scale = reference / (i0 * t)

                        data_point = [x, y * scale, i0, k, t]
                        corrected_sum = 0
                        rates = self.beamline.multi_mca.get_count_rates()
                        for j in range(self.beamline.multi_mca.elements):
                            data_point += [
                                mca_values[j], rates[j][0], rates[j][1]
                            ]
                            corrected_sum += mca_values[j] * float(
                                rates[j][0]) / rates[j][1]
                        data_point[1] = corrected_sum
                        self.raw_data.append(tuple(data_point))
                        used_time += t
                        self.emit("new-point", (x, y * scale, y, i0))
                        msg = "Scan {}/{}:  Point {}/{}...".format(
                            scan + 1, self.config['scans'], i, scan_length)
                        self.emit("progress", used_time / self.total_time, msg)
                        time.sleep(0)
                    data = self.set_data(self.raw_data)
                    self.results['data'].append(data)
                    self.config['end_time'] = datetime.now()
                    filename = os.path.join(
                        self.config['directory'],
                        self.config['frame_template'].format(scan + 1))
                    self.save(filename)
                    self.analyse()
                    self.emit('new-row', scan + 1)
                    self.raw_data = []

                if self.stopped:
                    logger.warning("Scan stopped.")
                    self.emit("stopped", None)

                else:
                    logger.info("Scan complete.")
                    self.emit("done", None)
                self.save_metadata()

            finally:
                self.beamline.energy.move_to(self.config['edge_energy'])
                self.beamline.fast_shutter.close()
                self.beamline.attenuator.set(saved_attenuation)
                self.beamline.multi_mca.configure(cooling=False, nozzle=False)
                logger.info('Edge scan done.')
                self.beamline.manager.collect()
        return self.results
Exemple #5
0
    def scan(self):
        logger.info('Edge Scan waiting for beamline to become available.')
        with self.beamline.lock:

            saved_attenuation = self.beamline.attenuator.get()
            self.raw_data = []
            self.results = {}

            ref_value = 1.0
            try:
                # prepare
                self.emit("progress", 0.01, "Preparing devices ...")
                self.beamline.energy.move_to(self.config.edge_energy)
                self.beamline.manager.collect(wait=True)
                self.beamline.mca.configure(cooling=True,
                                            energy=self.config.roi_energy,
                                            edge=self.config.edge_energy,
                                            nozzle=True,
                                            dark=True)
                self.beamline.attenuator.set(self.config.attenuation)
                self.beamline.energy.wait()
                self.beamline.bragg_energy.wait()
                self.beamline.goniometer.wait(start=False)
                self.emit("progress", 0.02,
                          "Waiting for beam to stabilize ...")
                time.sleep(3)
                self.beamline.fast_shutter.open()

                total = len(self.config.positions)
                self.config['start_time'] = datetime.now(tz=pytz.utc)
                for i, x in enumerate(self.config.positions):
                    if self.paused:
                        while self.paused and not self.stopped:
                            time.sleep(0.1)
                        self.beamline.manager.collect(wait=True)
                        self.beamline.mca.configure(cooling=True, nozzle=True)
                        time.sleep(1)  # wait for nozzle to move out.
                    if self.stopped:
                        break

                    self.beamline.bragg_energy.move_to(x, wait=True)
                    y, i0 = multi_count(self.config.exposure,
                                        self.beamline.mca, self.beamline.i0)
                    counts = self.beamline.mca.get_roi_counts() + (i0, )
                    self.beamline.mca.get_roi_counts()

                    if i == 0:
                        ref_value = i0
                    counts = (y * ref_value / i0, ) + counts
                    row = (x, ) + counts
                    self.raw_data.append(row)
                    self.emit("new-point", row)
                    self.emit("progress", (i + 1.0) / total, "")
                    time.sleep(0)
            except ValueError as e:
                self.emit("error", "Scan Error!")
                logger.error(e)
            finally:
                self.beamline.energy.move_to(self.config.edge_energy)
                self.beamline.fast_shutter.close()
                self.beamline.attenuator.set(saved_attenuation)
                self.beamline.mca.configure(cooling=False, nozzle=False)
                logger.info('Edge scan done.')
                self.beamline.manager.collect()