def test_direction_results(tmp_path, simulated_dl2_file): dl2_df = pd.read_hdf(simulated_dl2_file, key=dl2_params_lstcam_key) # Strings are required as input for the output files not PosixPath plt.figure() plot_dl2.direction_results(dl2_df, points_outfile=os.path.join(tmp_path, 'dir.h5'), plot_outfile=os.path.join(tmp_path, 'dir.png'))
def main(): custom_config = {} if args.config_file is not None: try: custom_config = read_configuration_file(args.config_file) except ("Custom configuration could not be loaded !!!"): pass config = replace_config(standard_config, custom_config) reg_energy, reg_disp_vector, cls_gh = dl1_to_dl2.build_models( args.gammafile, args.protonfile, save_models=args.storerf, path_models=args.path_models, custom_config=config, ) gammas = filter_events( pd.read_hdf(args.gammatest, key=dl1_params_lstcam_key), config["events_filters"], ) proton = filter_events( pd.read_hdf(args.protontest, key=dl1_params_lstcam_key), config["events_filters"], ) data = pd.concat([gammas, proton], ignore_index=True) dl2 = dl1_to_dl2.apply_models(data, cls_gh, reg_energy, reg_disp_vector, custom_config=config) ####PLOT SOME RESULTS##### selected_gammas = dl2.query('reco_type==0 & mc_type==0') if (len(selected_gammas) == 0): log.warning('No gammas selected, I will not plot any output') sys.exit() plot_dl2.plot_features(dl2) if not args.batch: plt.show() plot_dl2.energy_results(selected_gammas) if not args.batch: plt.show() plot_dl2.direction_results(selected_gammas) if not args.batch: plt.show() plot_dl2.plot_disp_vector(selected_gammas) if not args.batch: plt.show() plot_dl2.plot_pos(dl2) if not args.batch: plt.show() plot_dl2.plot_roc_gamma(dl2) if not args.batch: plt.show() plot_dl2.plot_models_features_importances(args.path_models, args.config_file) if not args.batch: plt.show() plt.hist(dl2[dl2['mc_type'] == 101]['gammaness'], bins=100) plt.hist(dl2[dl2['mc_type'] == 0]['gammaness'], bins=100) if not args.batch: plt.show()
def test_direction_results(): dl2_df = pd.read_hdf(dl2_file, key=dl2_params_lstcam_key) plot_dl2.direction_results(dl2_df, points_outfile=os.path.join(test_dir, 'dir.h5'), plot_outfile=os.path.join(test_dir, 'dir.png'))
def main(): args = parser.parse_args() custom_config = {} if args.config_file is not None: custom_config = read_configuration_file(args.config_file) config = replace_config(standard_config, custom_config) subarray_info = SubarrayDescription.from_hdf(args.gammatest) tel_id = config["allowed_tels"][0] if "allowed_tels" in config else 1 focal_length = subarray_info.tel[tel_id].optics.equivalent_focal_length reg_energy, reg_disp_norm, cls_disp_sign, cls_gh = dl1_to_dl2.build_models( args.gammafile, args.protonfile, save_models=args.save_models, path_models=args.path_models, custom_config=config, ) gammas = filter_events( pd.read_hdf(args.gammatest, key=dl1_params_lstcam_key), config["events_filters"], ) proton = filter_events( pd.read_hdf(args.protontest, key=dl1_params_lstcam_key), config["events_filters"], ) data = pd.concat([gammas, proton], ignore_index=True) dl2 = dl1_to_dl2.apply_models(data, cls_gh, reg_energy, reg_disp_norm=reg_disp_norm, cls_disp_sign=cls_disp_sign, focal_length=focal_length, custom_config=config) ####PLOT SOME RESULTS##### selected_gammas = dl2.query('reco_type==0 & mc_type==0') if (len(selected_gammas) == 0): log.warning('No gammas selected, I will not plot any output') sys.exit() plot_dl2.plot_features(dl2) if not args.batch: plt.show() plot_dl2.energy_results(selected_gammas) if not args.batch: plt.show() plot_dl2.direction_results(selected_gammas) if not args.batch: plt.show() plot_dl2.plot_disp_vector(selected_gammas) if not args.batch: plt.show() plot_dl2.plot_pos(dl2) if not args.batch: plt.show() plot_dl2.plot_roc_gamma(dl2) if not args.batch: plt.show() plot_dl2.plot_models_features_importances(args.path_models, args.config_file) if not args.batch: plt.show() plt.hist(dl2[dl2['mc_type'] == 101]['gammaness'], bins=100) plt.hist(dl2[dl2['mc_type'] == 0]['gammaness'], bins=100) if not args.batch: plt.show()