예제 #1
0
def runner(parser, options, args):

    if options.task == 'scan':
        from scanner import Scanner
        scan = Scanner(options)

        if options.flyback is None:
            flyback_range = get_range(options.flyback_range)
        else:
            flyback_range = [options.flyback]

        scan_speed_range = [options.scan_speed]

        title = scan.title()
        filename = 'pos_dict_%s.pickle' % (title)
        pos_dict_cache = Cache(filename).load()

        pos_dict = pos_dict_cache.data
        if 0:
            # scan
            for scan_speed in scan_speed_range:
                if scan_speed not in pos_dict:
                    pos_dict[scan_speed] = set([])
                elif isinstance(pos_dict[scan_speed], list):
                    pos_dict[scan_speed] = set(pos_dict[scan_speed])
                stop = False
                for flyback in flyback_range:
                    scan.create_tasks()
                    scan.setup(scan_speed, flyback)
                    try:
                        scan.iterate()
                    except RuntimeError, msg:
                        print 'Scanning failed with runtime error: %s' % (msg)
                        stop = True
                    scan.free_tasks()
                    if stop:
                        break
                    data = (flyback,
                            scan.mirror.line_average(scan.xa_error).std() *
                            1e6)
                    if data not in pos_dict[scan_speed]:
                        pos_dict[scan_speed].add(data)
                        pos_dict_cache.dump()
            #plt = scan.show()
            #plt.draw()
            #plt.show()
            pos_dict_cache.dump()

        import matplotlib.pyplot as plt
        fig = plt.figure(figsize=(12, 12))

        def on_keypressed(event, plt=plt, fig=fig):
            key = event.key
            if key == 'q':
                plt.close(fig)
            if key == 'x':
                plt.close(fig)
                sys.exit(0)

        fig.canvas.mpl_connect('key_press_event', on_keypressed)

        legends = []
        scan_speed_list = sorted(pos_dict.keys())
        for scan_speed in scan_speed_list:
            flyback_data = pos_dict[scan_speed]
            legends.append('%.3f m/s' % (scan_speed))
            flyback, data = zip(*flyback_data)
            plt.semilogy(flyback, data, 'x')
        plt.title('Scan speed - flyback ratio curves: %s' % (title))
        plt.xlabel('flyback ratio')
        plt.ylabel('position resolution, um')
        plt.legend(legends)
        plt.show()

        return
예제 #2
0
파일: run_mirrors.py 프로젝트: pearu/iocbio
def runner (parser, options, args):

    if options.task=='scan':
        from scanner import Scanner
        scan = Scanner(options)

        if options.flyback is None:
            flyback_range = get_range(options.flyback_range)
        else:
            flyback_range = [options.flyback]

        scan_speed_range = [options.scan_speed]

        title = scan.title ()
        filename = 'pos_dict_%s.pickle' % (title)
        pos_dict_cache = Cache(filename).load()

        pos_dict = pos_dict_cache.data
        if 0:
            # scan
            for scan_speed in scan_speed_range:
                if scan_speed not in pos_dict:
                    pos_dict[scan_speed] = set([])
                elif isinstance (pos_dict[scan_speed], list):
                    pos_dict[scan_speed] = set(pos_dict[scan_speed])
                stop = False
                for flyback in flyback_range:
                    scan.create_tasks()
                    scan.setup (scan_speed, flyback)
                    try:
                        scan.iterate()
                    except RuntimeError, msg:
                        print 'Scanning failed with runtime error: %s' % (msg)
                        stop = True
                    scan.free_tasks()
                    if stop:
                        break
                    data = (flyback, scan.mirror.line_average(scan.xa_error).std()*1e6)
                    if data not in pos_dict[scan_speed]:
                        pos_dict[scan_speed].add(data)
                        pos_dict_cache.dump()
            #plt = scan.show()
            #plt.draw()
            #plt.show()
            pos_dict_cache.dump()


        import matplotlib.pyplot as plt
        fig = plt.figure(figsize=(12,12))
        def on_keypressed(event, plt=plt, fig=fig):
            key = event.key
            if key=='q':
                plt.close(fig)
            if key=='x':
                plt.close(fig)
                sys.exit(0)
        fig.canvas.mpl_connect('key_press_event', on_keypressed)

        legends = []
        scan_speed_list = sorted(pos_dict.keys ())
        for scan_speed in scan_speed_list:
            flyback_data = pos_dict[scan_speed]
            legends.append ('%.3f m/s' % (scan_speed))
            flyback, data = zip (*flyback_data)
            plt.semilogy(flyback,data, 'x')
        plt.title('Scan speed - flyback ratio curves: %s' % (title))
        plt.xlabel('flyback ratio')
        plt.ylabel('position resolution, um')
        plt.legend(legends)
        plt.show()

        return
예제 #3
0
            (numpy.log(max_scan_speed / min_scan_speed)))
        pixel_time_range = min_pixel_time + numpy.arange(
            nof_pixel_times, dtype=float) / (nof_pixel_times - 1) * (
                max_pixel_time - min_pixel_time)
        alpha = options.orientation_angle
        roi = (options.roi_x0, options.roi_y0, options.roi_x1, options.roi_y1)
        ll = xya_pq(roi[0], roi[1])
        ur = xya_pq(roi[2], roi[3])
        scan_area_width = (ur[0] - ll[0]) * 1e6  # um
        scan_area_height = (ur[1] - ll[1]) * 1e6  # um
        M = options.image_height

        data_scan_speed = []
        data_flyback_ratio = []

        cache = Cache()
        cache.load()

        flystart_ratio = 0.5

        target_ioffset_std = 1.0
        error_margin = 0.1
        for pixel_time in pixel_time_range:
            for scan_speed in scan_speed_log_range:
                pixel_size_x = scan_speed * pixel_time  # um
                N = max(1, int(scan_area_width / pixel_size_x))

                K = N

                error_must_increase = None
                last_error = None
예제 #4
0
파일: run_mirrors.py 프로젝트: pearu/iocbio
        nof_pixel_times = 2
        scan_speed_range = min_scan_speed + numpy.arange(nof_scan_speeds, dtype=float)/(nof_scan_speeds-1) * (max_scan_speed - min_scan_speed)
        scan_speed_log_range = numpy.exp(numpy.log(min_scan_speed) + numpy.arange(nof_scan_speeds, dtype=float)/(nof_scan_speeds-1) * (numpy.log(max_scan_speed/min_scan_speed)))
        pixel_time_range = min_pixel_time + numpy.arange(nof_pixel_times, dtype=float)/(nof_pixel_times-1) * (max_pixel_time - min_pixel_time)
        alpha = options.orientation_angle
        roi = (options.roi_x0, options.roi_y0, options.roi_x1, options.roi_y1)
        ll = xya_pq(roi[0], roi[1])
        ur = xya_pq(roi[2], roi[3])
        scan_area_width = (ur[0] - ll[0]) * 1e6 # um
        scan_area_height = (ur[1] - ll[1]) * 1e6 # um
        M = options.image_height

        data_scan_speed = []
        data_flyback_ratio = []

        cache = Cache()
        cache.load()

        flystart_ratio = 0.5

        target_ioffset_std = 1.0
        error_margin = 0.1
        for pixel_time in pixel_time_range:
            for scan_speed in scan_speed_log_range:
                pixel_size_x = scan_speed * pixel_time # um
                N = max(1, int(scan_area_width / pixel_size_x))

                K = N
                
                error_must_increase = None
                last_error = None