Пример #1
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,
    )
Пример #2
0
def test_r0_to_dl1_observed(tmp_path):
    from lstchain.reco.r0_to_dl1 import r0_to_dl1

    output_path = tmp_path / ('dl1_' + test_r0_path.stem + '.h5')

    config = standard_config
    lst_event_source = config['source_config']['LSTEventSource']
    lst_event_source['PointingSource']['drive_report_path'] = test_drive_report
    lst_event_source['LSTR0Corrections']['drs4_pedestal_path'] = \
        test_drs4_pedestal_path
    lst_event_source['LSTR0Corrections']['calibration_path'] = \
        test_calib_path
    lst_event_source['LSTR0Corrections']['drs4_time_calibration_path']\
        = test_time_calib_path

    r0_to_dl1(test_r0_path, output_filename=output_path, custom_config=config)

    with tables.open_file(output_path, 'r') as f:
        images_table = f.root[dl1_images_lstcam_key]
        params_table = f.root[dl1_params_lstcam_key]
        assert 'image' in images_table.colnames
        assert 'peak_time' in images_table.colnames
        assert 'tel_id' in images_table.colnames
        assert 'obs_id' in images_table.colnames
        assert 'event_id' in images_table.colnames
        assert 'tel_id' in params_table.colnames
        assert 'event_id' in params_table.colnames
        assert 'obs_id' in params_table.colnames
Пример #3
0
def test_r0_to_dl1(tmp_path, mc_gamma_testfile):
    from lstchain.reco.r0_to_dl1 import r0_to_dl1

    infile = mc_gamma_testfile
    r0_to_dl1(infile,
              custom_config=standard_config,
              output_filename=tmp_path / "dl1_gamma.h5")
Пример #4
0
def test_r0_to_dl1_lhfit_observed(tmp_path):
    from lstchain.reco.r0_to_dl1 import r0_to_dl1
    config = deepcopy(standard_config)
    config['source_config']['EventSource']['max_events'] = None
    config['source_config']['EventSource']['allowed_tels'] = [1]
    config['lh_fit_config'] = {
        "sigma_s": [["type", "*", 1.0], ["type", "LST_LST_LSTCam", 0.3282]],
        "crosstalk": [["type", "*", 0.0], ["type", "LST_LST_LSTCam", 0.0]],
        "sigma_space":
        3,
        "sigma_time":
        4,
        "time_before_shower": [["type", "*", 0.0],
                               ["type", "LST_LST_LSTCam", 0.0]],
        "time_after_shower": [["type", "*", 20.0],
                              ["type", "LST_LST_LSTCam", 20.0]],
        "n_peaks":
        0,
        "no_asymmetry":
        False,
        "use_weight":
        False,
        "verbose":
        0
    }
    r0_to_dl1(test_r0_path,
              custom_config=config,
              output_filename=tmp_path / "tmp2.h5")
Пример #5
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()
Пример #6
0
def test_r0_to_dl1_nsb_tuning(tmp_path, mc_gamma_testfile):
    config = deepcopy(standard_config)
    config['source_config']['EventSource']['allowed_tels'] = [1]
    config['waveform_nsb_tuning']['nsb_tuning'] = True
    config['waveform_nsb_tuning']['spe_location'] = os.path.join(
        os.path.dirname(__file__),
        '../../data/SinglePhE_ResponseInPhE_expo2Gaus.dat')
    r0_to_dl1(mc_gamma_testfile,
              custom_config=config,
              output_filename=tmp_path / "tmp.h5")
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)
def main():

    outdir = os.path.abspath(args.outdir)
    os.makedirs(outdir, exist_ok=True)

    r0_to_dl1.allowed_tels = {1, 2, 3, 4}
    output_filename = os.path.join(
        outdir,
        'dl1_' + os.path.basename(args.infile).rsplit('.', 1)[0] + '.h5')

    config = {}
    if args.config_file is not None:
        try:
            config = read_configuration_file(os.path.abspath(args.config_file))
        except ("Custom configuration could not be loaded !!!"):
            pass

    r0_to_dl1.r0_to_dl1(args.infile,
                        output_filename=output_filename,
                        custom_config=config)
Пример #9
0
def test_r0_to_dl1_lhfit_mc(tmp_path, mc_gamma_testfile):
    from lstchain.reco.r0_to_dl1 import r0_to_dl1
    config = deepcopy(standard_config)
    config['source_config']['EventSource']['max_events'] = 5
    config['source_config']['EventSource']['allowed_tels'] = [1]
    config['lh_fit_config'] = {
        "sigma_s": [["type", "*", 1.0], ["type", "LST_LST_LSTCam", 0.3282]],
        "crosstalk": [["type", "*", 0.0], ["type", "LST_LST_LSTCam", 0.0]],
        "sigma_space":
        3,
        "sigma_time":
        4,
        "time_before_shower": [["type", "*", 0.0],
                               ["type", "LST_LST_LSTCam", 0.0]],
        "time_after_shower": [["type", "*", 20.0],
                              ["type", "LST_LST_LSTCam", 20.0]],
        "n_peaks":
        20,
        "no_asymmetry":
        False,
        "use_weight":
        False,
        "verbose":
        4
    }
    os.makedirs('./event', exist_ok=True)
    r0_to_dl1(mc_gamma_testfile,
              custom_config=config,
              output_filename=tmp_path / "tmp.h5")
    assert len(os.listdir('./event')) > 1
    for path in os.listdir('./event'):
        os.remove('./event/' + path)
    os.rmdir('./event')
    os.remove(tmp_path / "tmp.h5")
    config['source_config']['EventSource']['allowed_tels'] = [1, 2]
    config['lh_fit_config']["no_asymmetry"] = True
    config['lh_fit_config']["use_weight"] = True
    config['lh_fit_config']["verbose"] = 0
    r0_to_dl1(mc_gamma_testfile,
              custom_config=config,
              output_filename=tmp_path / "tmp.h5")
Пример #10
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,
    )
Пример #11
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,
    )
Пример #12
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,
    )
Пример #13
0
def test_r0_to_dl1():
    from lstchain.reco.r0_to_dl1 import r0_to_dl1
    infile = mc_gamma_testfile
    r0_to_dl1(infile, custom_config=standard_config, output_filename=dl1_file)