コード例 #1
0
ファイル: test_paths.py プロジェクト: mexanick/cta-lstchain
def test_parse_r0():
    from lstchain.paths import parse_r0_filename

    run = parse_r0_filename('LST-1.1.Run01920.0000.fits.fz')
    assert run.tel_id == 1
    assert run.stream == 1
    assert run.run == 1920
    assert run.subrun == 0

    run = parse_r0_filename(Path('LST-1.1.Run01920.0000.fits.fz'))
    assert run.tel_id == 1
    assert run.stream == 1
    assert run.run == 1920
    assert run.subrun == 0

    with pytest.raises(ValueError):
        run = parse_r0_filename('foo.fits.fz')
コード例 #2
0
def get_list_of_runs(list_of_files):
    """
    Get the sorted list of run objects from R0 filenames.

    Parameters
    ----------
    list_of_files : pathlib.Path.glob
        List of files
    Returns
    -------
    list_of_run_objects
    """
    return sorted(parse_r0_filename(file) for file in list_of_files)
コード例 #3
0
def main():
    output_dir = args.output_dir.absolute()
    output_dir.mkdir(exist_ok=True)

    if not args.input_file.is_file():
        log.error('Input file does not exist or is not a file')
        sys.exit(1)

    log.setLevel(logging.INFO)
    handler = logging.StreamHandler()
    logging.getLogger().addHandler(handler)

    r0_to_dl1.allowed_tels = {1, 2, 3, 4}

    # test if this matches data file name pattern
    try:
        run = parse_r0_filename(args.input_file)
        output_filename = output_dir / run_to_dl1_filename(
            run.tel_id, run.run, run.subrun)
    except ValueError:
        # for arbitrary filenames, including mc
        output_filename = output_dir / r0_to_dl1_filename(args.input_file.name)

    config = {}
    if args.config_file is not None:
        try:
            config = read_configuration_file(args.config_file)
        except Exception as e:
            log.error(f'Configuration file could not be read: {e}')
            sys.exit(1)

    config["max_events"] = args.max_events

    r0_to_dl1.r0_to_dl1(args.input_file,
                        output_filename=output_filename,
                        custom_config=config,
                        pedestal_path=args.pedestal_file,
                        calibration_path=args.calibration_file,
                        time_calibration_path=args.time_calibration_file,
                        pointing_file_path=args.pointing_file,
                        ucts_t0_dragon=args.ucts_t0_dragon,
                        dragon_counter0=args.dragon_counter0,
                        ucts_t0_tib=args.ucts_t0_tib,
                        tib_counter0=args.tib_counter0)
コード例 #4
0
def main():
    args = parser.parse_args()

    output_dir = args.output_dir.absolute()
    output_dir.mkdir(exist_ok=True, parents=True)

    if not args.input_file.is_file():
        log.error('Input file does not exist or is not a file')
        sys.exit(1)

    log.setLevel(logging.INFO)
    handler = logging.StreamHandler()
    logging.getLogger().addHandler(handler)

    r0_to_dl1.allowed_tels = {1, 2, 3, 4}

    # test if this matches data file name pattern
    try:
        run = parse_r0_filename(args.input_file)
        output_filename = output_dir / run_to_dl1_filename(
            run.tel_id, run.run, run.subrun)
    except ValueError:
        # for arbitrary filenames, including mc
        output_filename = output_dir / r0_to_dl1_filename(args.input_file.name)

    config = {}
    if args.config_file is not None:
        try:
            config = read_configuration_file(args.config_file)
        except Exception as e:
            log.error(f'Configuration file could not be read: {e}')
            sys.exit(1)
    else:
        config = standard_config

    # Add to configuration config the parameters provided through command-line,
    # which supersede those in the file:
    if args.max_events is not None:
        config['source_config']['EventSource']['max_events'] = args.max_events

    lst_event_source = config['source_config']['LSTEventSource']
    time_calculator = lst_event_source['EventTimeCalculator']

    if args.dragon_reference_time is not None:
        time_calculator['dragon_reference_time'] = args.dragon_reference_time
    if args.dragon_reference_counter is not None:
        time_calculator[
            'dragon_reference_counter'] = args.dragon_reference_counter
    if args.dragon_module_id is not None:
        time_calculator['dragon_module_id'] = args.dragon_module_id
    if args.run_summary_path is not None:
        time_calculator['run_summary_path'] = args.run_summary_path

    if args.pointing_file is not None:
        lst_event_source['PointingSource'][
            'drive_report_path'] = args.pointing_file
    if args.pedestal_ids_path is not None:
        lst_event_source['pedestal_ids_path'] = args.pedestal_ids_path

    if args.default_trigger_type is not None:
        lst_event_source["default_trigger_type"] = args.default_trigger_type

    lst_r0_corrections = lst_event_source['LSTR0Corrections']
    if args.pedestal_file is not None:
        lst_r0_corrections['drs4_pedestal_path'] = args.pedestal_file
    if args.calibration_file is not None:
        lst_r0_corrections['calibration_path'] = args.calibration_file
    if args.time_calibration_file is not None:
        lst_r0_corrections[
            'drs4_time_calibration_path'] = args.time_calibration_file

    calib_config = config[config['calibration_product']]
    if args.systematic_correction_file is not None:
        calib_config[
            'systematic_correction_path'] = args.systematic_correction_file

    lst_event_source["use_flatfield_heuristic"] = args.use_flatfield_heuristic

    r0_to_dl1.r0_to_dl1(
        args.input_file,
        output_filename=output_filename,
        custom_config=config,
    )