예제 #1
0
def test_r0_to_dl1_filename():
    from lstchain.paths import r0_to_dl1_filename

    assert str(r0_to_dl1_filename('/foo/test.simtel.gz')) == '/foo/dl1_test.h5'
    assert str(r0_to_dl1_filename('test.simtel')) == 'dl1_test.h5'
    assert str(
        r0_to_dl1_filename('LST1_custom.fits.fz')) == 'dl1_LST1_custom.h5'
예제 #2
0
def main():

    args = parser.parse_args()

    # using a default of None and only using get_dataset_path here
    # prevents downloading gamma_test_large when an input file is actually given
    # or just --help is called.
    if args.input_file is None:
        args.input_file = get_dataset_path('gamma_test_large.simtel.gz')

    output_dir = args.output_dir.absolute()
    output_dir.mkdir(exist_ok=True, parents=True)
    output_file = output_dir / r0_to_dl1_filename(args.input_file.name)

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

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

    r0_to_dl1.r0_to_dl1(
        args.input_file,
        output_filename=output_file,
        custom_config=config,
    )
예제 #3
0
def main():
    ctaplot.set_style()

    output_dir = args.output_dir.absolute()
    output_dir.mkdir(exist_ok=True, parents=True)
    output_file = output_dir / r0_to_dl1_filename(args.input_file.name)

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

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

    # This benchmark needs true pe image
    config['write_pe_image'] = True

    # directly jump to the benchmarks if the dl1 file already exists
    if not os.path.exists(output_file):
        r0_to_dl1.r0_to_dl1(
            args.input_file,
            output_filename=output_file,
            custom_config=config,
        )

    with tables.open_file(output_file) as f:
        sim_table = Table(f.root.dl1.event.simulation.LST_LSTCam.read())
        im_table = Table(f.root.dl1.event.telescope.image.LST_LSTCam.read())

    if len(sim_table) != len(im_table):
        raise ValueError(
            'the number of events with simulation info is not equal to the number of dl1 events'
        )

    pdf_filename = os.path.join(
        args.output_dir,
        f"charge_bench_{os.path.basename(output_file).replace('.h5', '')}.pdf")
    with PdfPages(pdf_filename) as pdf:

        plot_pixels_pe_spectrum(sim_table['true_image'], im_table['image'])
        plt.tight_layout()
        pdf.savefig()
        plt.close()

        plot_photoelectron_true_reco(sim_table['true_image'],
                                     im_table['image'])
        plt.tight_layout()
        pdf.savefig()
        plt.close()

        ax = plot_charge_resolution(sim_table['true_image'], im_table['image'])
        ax.set_ylim(-1, 10)
        plt.tight_layout()
        pdf.savefig()
        plt.close()
def main():
    outdir = args.outdir.absolute()
    dl1_file = outdir / r0_to_dl1_filename(args.datafile.name)

    cmd_r0_to_dl1 = f'lstchain_mc_r0_to_dl1 -f {args.datafile} -o {outdir}'
    if args.config_file is not None:
        cmd_r0_to_dl1 = cmd_r0_to_dl1 + f' -conf {args.config_file}'

    cmd_dl1_to_dl2 = f'lstchain_dl1_to_dl2 -f {dl1_file} -p {args.path_models} -o {outdir}'
    if args.config_file is not None:
        cmd_dl1_to_dl2 = cmd_dl1_to_dl2 + f' -conf {args.config_file}'

    os.system(cmd_r0_to_dl1)
    os.system(cmd_dl1_to_dl2)

    if not args.store_dl1:
        os.remove(dl1_file)
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)
예제 #6
0
def main():

    output_dir = args.output_dir.absolute()
    output_dir.mkdir(exist_ok=True)
    output_file = output_dir / r0_to_dl1_filename(args.input_file.name)

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

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

    r0_to_dl1.r0_to_dl1(
        args.input_file,
        output_filename=output_file,
        custom_config=config,
    )
예제 #7
0
def main():
    args = parser.parse_args()

    # using a default of None and only using get_dataset_path here
    # prevents downloading gamma_test_large when an input file is actually given
    # or just --help is called.
    if args.datafile is None:
        args.datafile = get_dataset_path('gamma_test_large.simtel.gz')

    output_dir = args.output_dir.absolute()
    dl1_file = output_dir / r0_to_dl1_filename(args.datafile.name)

    cmd_r0_to_dl1 = [
        'lstchain_mc_r0_to_dl1',
        '-f',
        str(args.datafile),
        '-o',
        str(output_dir),
    ]
    if args.config_file is not None:
        cmd_r0_to_dl1.extend(['--config', str(args.config_file)])

    cmd_dl1_to_dl2 = [
        'lstchain_dl1_to_dl2',
        '-f',
        str(dl1_file),
        '-p',
        str(args.path_models),
        '-o',
        str(output_dir),
    ]
    if args.config_file is not None:
        cmd_dl1_to_dl2.extend(['--config', str(args.config_file)])

    sp.run(cmd_r0_to_dl1, check=True)
    sp.run(cmd_dl1_to_dl2, check=True)

    if args.no_dl1:
        os.remove(dl1_file)
예제 #8
0
def main():
    logging.basicConfig()
    logging.getLogger("lstchain.reco.r0_to_dl1").setLevel(args.log_level)
    logging.getLogger("lstchain.reco.reconstructor").setLevel(args.log_level)

    output_dir = args.output_dir.absolute()
    output_dir.mkdir(exist_ok=True)
    output_file = output_dir / r0_to_dl1_filename(args.input_file.name)

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

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

    r0_to_dl1.r0_to_dl1(
        args.input_file,
        output_filename=output_file,
        custom_config=config,
    )
예제 #9
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,
    )