Exemplo n.º 1
0
def main():
    script = os.path.splitext(os.path.basename(__file__))[0]
    log.info("[SCRIPT] {}".format(script))

    parser = argparse.ArgumentParser(
        description='Display each event in the file')
    parser.add_argument('-f', '--file', dest='input_path', action='store',
                        default=get_path('gamma_test.simtel.gz'),
                        help='path to the input file. '
                             'Default = gamma_test.simtel.gz')
    parser.add_argument('-O', '--origin', dest='origin', action='store',
                        default='hessio',
                        help='origin of the file: {}. Default = hessio'
                        .format(origin_list()))
    parser.add_argument('-D', dest='display', action='store_true',
                        default=False, help='display the camera events')
    parser.add_argument('--pdf', dest='output_path', action='store',
                        default=None,
                        help='path to store a pdf output of the plots')
    parser.add_argument('-t', '--telescope', dest='tel', action='store',
                        type=int, default=None, help='telecope to view. '
                                                     'Default = All')

    calibration_arguments(parser)

    logger_detail = parser.add_mutually_exclusive_group()
    logger_detail.add_argument('-q', '--quiet', dest='quiet',
                               action='store_true', default=False,
                               help='Quiet mode')
    logger_detail.add_argument('-v', '--verbose', dest='verbose',
                               action='store_true', default=False,
                               help='Verbose mode')
    logger_detail.add_argument('-d', '--debug', dest='debug',
                               action='store_true', default=False,
                               help='Debug mode')

    args = parser.parse_args()
    params = calibration_parameters(args)

    if args.quiet:
        log.setLevel(40)
    if args.verbose:
        log.setLevel(20)
    if args.debug:
        log.setLevel(10)

    log.debug("[file] Reading file")
    input_file = InputFile(args.input_path, args.origin)
    source = input_file.read()

    # geom_dict is a dictionary of CameraGeometry, with keys of
    # (num_pixels, focal_length), the parameters that are used to guess the
    # geometry of the telescope. By using these keys, the geometry is
    # calculated only once per telescope type as needed, reducing computation
    # time.
    # Creating a geom_dict at this point is optional, but is recommended, as
    # the same geom_dict can then be shared between the calibration and
    # CameraPlotter, again reducing computation time.
    # The dictionary becomes filled as a result of a dictionary's mutable
    # nature.
    geom_dict = {}

    # Calibrate events and fill geom_dict
    calibrated_source = calibrate_source(source, params, geom_dict)

    fig = plt.figure(figsize=(16, 7))
    if args.display:
        plt.show(block=False)
    pp = PdfPages(args.output_path) if args.output_path is not None else None
    for event in calibrated_source:
        tels = list(event.dl0.tels_with_data)
        if args.tel is None:
            tel_loop = tels
        else:
            if args.tel not in tels:
                continue
            tel_loop = [args.tel]
        log.debug(tels)
        for tel_id in tel_loop:
            display_telescope(event, tel_id, args.display, geom_dict, pp, fig)
    if pp is not None:
        pp.close()

    log.info("[COMPLETE]")
Exemplo n.º 2
0
def main():
    script = os.path.splitext(os.path.basename(__file__))[0]
    log.info("[SCRIPT] {}".format(script))

    parser = argparse.ArgumentParser(
        description='Display each event in the file')
    parser.add_argument('-f',
                        '--file',
                        dest='input_path',
                        action='store',
                        default=get_path('gamma_test.simtel.gz'),
                        help='path to the input file. '
                        'Default = gamma_test.simtel.gz')
    parser.add_argument('-O',
                        '--origin',
                        dest='origin',
                        action='store',
                        default='hessio',
                        help='origin of the file: {}. Default = hessio'.format(
                            InputFile.origin_list()))
    parser.add_argument('-D',
                        dest='display',
                        action='store_true',
                        default=False,
                        help='display the camera events')
    parser.add_argument('--pdf',
                        dest='output_path',
                        action='store',
                        default=None,
                        help='path to store a pdf output of the plots')
    parser.add_argument('-t',
                        '--telescope',
                        dest='tel',
                        action='store',
                        type=int,
                        default=None,
                        help='telecope to view. '
                        'Default = All')

    calibration_arguments(parser)

    logger_detail = parser.add_mutually_exclusive_group()
    logger_detail.add_argument('-q',
                               '--quiet',
                               dest='quiet',
                               action='store_true',
                               default=False,
                               help='Quiet mode')
    logger_detail.add_argument('-v',
                               '--verbose',
                               dest='verbose',
                               action='store_true',
                               default=False,
                               help='Verbose mode')
    logger_detail.add_argument('-d',
                               '--debug',
                               dest='debug',
                               action='store_true',
                               default=False,
                               help='Debug mode')

    args = parser.parse_args()
    print('DEBUG type(args) {}'.format(type(args)))
    print('DEBUG args {}'.format(args))
    params = calibration_parameters(args)

    if args.quiet:
        log.setLevel(40)
    if args.verbose:
        log.setLevel(20)
    if args.debug:
        log.setLevel(10)

    log.debug("[file] Reading file")
    input_file = InputFile(args.input_path, args.origin)
    source = input_file.read()

    # geom_dict is a dictionary of CameraGeometry, with keys of
    # (num_pixels, focal_length), the parameters that are used to guess the
    # geometry of the telescope. By using these keys, the geometry is
    # calculated only once per telescope type as needed, reducing computation
    # time.
    # Creating a geom_dict at this point is optional, but is recommended, as
    # the same geom_dict can then be shared between the calibration and
    # CameraPlotter, again reducing computation time.
    # The dictionary becomes filled as a result of a dictionary's mutable
    # nature.
    geom_dict = {}

    # Calibrate events and fill geom_dict

    calibrated_source = calibrate_source(source, params, geom_dict)

    fig = plt.figure(figsize=(16, 7))
    if args.display:
        plt.show(block=False)
    pp = PdfPages(args.output_path) if args.output_path is not None else None
    for event in calibrated_source:
        tels = list(event.dl0.tels_with_data)
        if args.tel is None:
            tel_loop = tels
        else:
            if args.tel not in tels:
                continue
            tel_loop = [args.tel]
        log.debug(tels)
        for tel_id in tel_loop:
            display_telescope(event, tel_id, args.display, geom_dict, pp, fig)
    if pp is not None:
        pp.close()

    log.info("[COMPLETE]")
    def initialize(self, argv=None):
        self.log.info("Initializing the calibration pipeline...")

        # Declare and parse command line option
        parser = argparse.ArgumentParser(
            description='Display each event in the file')
        parser.add_argument('-f', '--file', dest='input_path',
                            action='store',
                            default=get_path('gamma_test.simtel.gz'),
                            help='path to the input file. '
                            ' Default = gamma_test.simtel.gz')
        parser.add_argument('-O', '--origin', dest='origin',
                            action='store',
                            default='hessio',
                            help='origin of the file: {}. '
                            'Default = hessio'
                            .format(origin_list()))
        parser.add_argument('-D', dest='display', action='store_true',
                            default=False,
                            help='display the camera events')
        parser.add_argument('--pdf', dest='output_path', action='store',
                            default=None,
                            help='path to store a pdf output of the plots')
        parser.add_argument('-t', '--telescope', dest='tel',
                            action='store',
                            type=int, default=None,
                            help='telecope to view. Default = All')

        calibration_arguments(parser)

        logger_detail = parser.add_mutually_exclusive_group()
        logger_detail.add_argument('-q', '--quiet', dest='quiet',
                                   action='store_true', default=False,
                                   help='Quiet mode')
        logger_detail.add_argument('-v', '--verbose', dest='verbose',
                                   action='store_true', default=False,
                                   help='Verbose mode')
        logger_detail.add_argument('-d', '--debug', dest='debug',
                                   action='store_true', default=False,
                                   help='Debug mode')

        self.args = parser.parse_args()
        self.params = calibration_parameters(self.args)

        if self.args.quiet:
            self.log.setLevel(40)
        if self.args.verbose:
            self.log.setLevel(20)
        if self.args.debug:
            self.log.setLevel(10)

        self.log.debug("[file] Reading file")
        input_file = InputFile(self.args.input_path, self.args.origin)
        self.source = input_file.read()

        # geom_dict is a dictionary of CameraGeometry, with keys of
        # (num_pixels, focal_length), the parameters that are used to guess the
        # geometry of the telescope. By using these keys, the geometry is
        # calculated only once per telescope type as needed, reducing
        # computation time.
        # Creating a geom_dict at this point is optional, but is recommended,
        # as the same geom_dict can then be shared between the calibration and
        # CameraPlotter, again reducing computation time.
        # The dictionary becomes filled as a result of a dictionary's mutable
        # nature.def display_telescope(event, tel_id, display,
        # geom_dict, pp, fig):
        self.geom_dict = {}