Esempio n. 1
0
def main(args):
    """
    Handles the command line arguments
    args is the list of arguments passed
    return (int): value to return to the OS as program exit code
    """
    # arguments handling
    parser = argparse.ArgumentParser()
    parser.add_argument("--role",
                        dest="role",
                        metavar="<component>",
                        help="display and update an image on the screen")
    parser.add_argument("--gridsize",
                        dest="gridsize",
                        nargs=2,
                        metavar="<gridsize>",
                        type=int,
                        default=None,
                        help="size of the grid of spots in x y, default 14 14")
    parser.add_argument("--log-level",
                        dest="loglev",
                        metavar="<level>",
                        type=int,
                        choices=[0, 1, 2],
                        default=0,
                        help="set verbosity level (0-2, default = 0)")
    options = parser.parse_args(args[1:])
    # Set up logging before everything else
    loglev_names = [logging.WARNING, logging.INFO, logging.DEBUG]
    loglev = loglev_names[min(len(loglev_names) - 1, options.loglev)]

    # change the log format to be more descriptive
    handler = logging.StreamHandler()
    logging.getLogger().setLevel(loglev)
    handler.setFormatter(
        logging.Formatter(
            '%(asctime)s (%(module)s) %(levelname)s: %(message)s'))
    logging.getLogger().addHandler(handler)

    if options.role:
        if get_backend_status() != BACKEND_RUNNING:
            raise ValueError(
                "Backend is not running while role command is specified.")
        ccd = model.getComponent(role=options.role)
        live_display(ccd, ccd.data, kill_ccd=False, gridsize=options.gridsize)
    else:
        ccd = ueye.Camera("camera", "ccd", device=None)
        ccd.SetFrameRate(2)
        live_display(ccd, ccd.data, gridsize=options.gridsize)
    return 0
Esempio n. 2
0
def main(args):
    """
    Handles the command line arguments
    args is the list of arguments passed
    return (int): value to return to the OS as program exit code
    """
    # arguments handling
    parser = argparse.ArgumentParser()
    group = parser.add_mutually_exclusive_group()
    group.add_argument("--role",
                       dest="role",
                       metavar="<component>",
                       help="display and update an image on the screen")
    group.add_argument("--file",
                       metavar="<filename>",
                       dest="filename",
                       help="display and update an image on the screen")
    parser.add_argument("--gridsize",
                        dest="gridsize",
                        nargs=2,
                        metavar="<gridsize>",
                        type=int,
                        default=None,
                        help="size of the grid of spots in x y, default 8 8")
    parser.add_argument("--magnification",
                        dest="magnification",
                        type=float,
                        help="magnification (typically 40 or 50)")
    parser.add_argument("--log-level",
                        dest="loglev",
                        metavar="<level>",
                        type=int,
                        choices=[0, 1, 2],
                        default=0,
                        help="set verbosity level (0-2, default = 0)")
    options = parser.parse_args(args[1:])
    # Set up logging before everything else
    loglev_names = [logging.WARNING, logging.INFO, logging.DEBUG]
    loglev = loglev_names[min(len(loglev_names) - 1, options.loglev)]

    # change the log format to be more descriptive
    handler = logging.StreamHandler()
    logging.getLogger().setLevel(loglev)
    handler.setFormatter(
        logging.Formatter(
            '%(asctime)s (%(module)s) %(levelname)s: %(message)s'))
    logging.getLogger().addHandler(handler)

    # Magnification: use cli input value. If none is specified, try to read out lens magnification.
    try:
        lens = model.getComponent(role="lens")
        lens_mag = lens.magnification.value
    except Exception as ex:
        logging.debug("Failed to read magnification from lens, ex: %s", ex)
        lens_mag = None

    if options.magnification:
        magnification = options.magnification
        if lens_mag and lens_mag != magnification:
            logging.warning(
                "Requested magnification %s differs from lens magnification %s.",
                magnification, lens_mag)
    elif lens_mag:
        magnification = lens_mag
        logging.debug(
            "No magnification specified, using lens magnification %s.",
            lens_mag)
    else:
        magnification = DEFAULT_MAGNIFICATION
        logging.warning("No magnification specified, falling back to %s.",
                        magnification)
    pxsize = PIXEL_SIZE_SAMPLE_PLANE / magnification

    if options.filename:
        logging.info("Will process image file %s" % options.filename)
        converter = dataio.find_fittest_converter(options.filename,
                                                  default=None,
                                                  mode=os.O_RDONLY)
        data = converter.read_data(options.filename)[0]
        fakeccd = StaticCCD(options.filename, "fakeccd", data)
        live_display(fakeccd, fakeccd.data, pxsize, gridsize=options.gridsize)
    elif options.role:
        if get_backend_status() != BACKEND_RUNNING:
            raise ValueError(
                "Backend is not running while role command is specified.")
        ccd = model.getComponent(role=options.role)
        live_display(ccd,
                     ccd.data,
                     pxsize,
                     kill_ccd=False,
                     gridsize=options.gridsize)
    else:
        ccd = ueye.Camera("camera", "ccd", device=None)
        ccd.SetFrameRate(2)
        live_display(ccd, ccd.data, pxsize, gridsize=options.gridsize)
    return 0