#Apply the models to the data features = ['intensity', 'time_gradient', 'width', 'length', 'wl', 'phi', 'psi'] dl2 = reco_dl1_to_dl2.ApplyModels(data, features, RFcls_GH, RFreg_Energy, RFreg_Disp) if args.storeresults==True: #Store results if not os.path.exists(args.outdir): os.mkdir(args.outdir) outfile = args.outdir+"/dl2_events.hdf5" dl2.to_hdf(outfile, key="dl2_events", mode="w") #Plot some results plot_dl2.plot_features(dl2) plt.show() plot_dl2.plot_e(dl2) plt.show() plot_dl2.plot_disp(dl2) plt.show() plot_dl2.plot_pos(dl2) plt.show()
features_sep) test['hadro_rec'] = RFcls_GH.predict(test[features_sep]) if args.storerf==True: fileE = args.path_models+"/RFreg_Energy.sav" fileD = args.path_models+"/RFreg_Disp.sav" fileH = args.path_models+"/RFcls_GH.sav" joblib.dump(RFreg_Energy, fileE) joblib.dump(RFreg_Disp, fileD) joblib.dump(RFcls_GH, fileH) #Plot some results e_cuts = [-1,np.log10(500),np.log10(1000)] for e_cut in e_cuts: test = test[test['e_rec']>e_cut] plot_dl2.plot_features(test) plt.show() plot_dl2.plot_e(test) plt.show() plot_dl2.plot_disp(test) plt.show() plot_dl2.plot_pos(test) plt.show() plot_dl2.plot_importances(RFcls_GH,features_sep) plt.show() plot_dl2.plot_ROC(RFcls_GH,test,features_sep,e_cut) plt.show()
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##### gammas = dl2[dl2.gammaness >= 0.5] protons = dl2[dl2.gammaness < 0.5] gammas.reco_type = 0 protons.reco_type = 1 focal_length = 28 * u.m src_pos_reco = utils.reco_source_position_sky( gammas.x.values * u.m, gammas.y.values * u.m, gammas.reco_disp_dx.values * u.m, gammas.reco_disp_dy.values * u.m, focal_length, gammas.mc_alt_tel.values * u.rad, gammas.mc_az_tel.values * u.rad) plot_dl2.plot_features(dl2) plt.show() plot_dl2.plot_e(gammas, 10, 1.5, 3.5) plt.show() plot_dl2.calc_resolution(gammas) plt.show() plot_dl2.plot_e_resolution(gammas, 10, 1.5, 3.5) plt.show() plot_dl2.plot_disp_vector(gammas) plt.show() try: ctaplot.plot_theta2( gammas.mc_alt, np.arctan(np.tan(gammas.mc_az)), src_pos_reco.alt.rad, np.arctan(np.tan(src_pos_reco.az.rad)), bins=50, range=(0, 1), ) plt.show() ctaplot.plot_angular_res_per_energy( src_pos_reco.alt.rad, np.arctan(np.tan(src_pos_reco.az.rad)), gammas.mc_alt, np.arctan(np.tan(gammas.mc_az)), gammas.mc_energy) plt.show() except: pass regression_features = config["regression_features"] classification_features = config["classification_features"] plt.show() plot_dl2.plot_pos(dl2) plt.show() plot_dl2.plot_ROC(cls_gh, dl2, classification_features, -1) plt.show() plot_dl2.plot_importances(cls_gh, classification_features) plt.show() plot_dl2.plot_importances(reg_energy, regression_features) plt.show() plot_dl2.plot_importances(reg_disp_vector, regression_features) plt.show() plt.hist(dl2[dl2['mc_type'] == 101]['gammaness'], bins=100) plt.hist(dl2[dl2['mc_type'] == 0]['gammaness'], bins=100) plt.show()
gammas = dl2[dl2.gammaness >= 0.5] protons = dl2[dl2.gammaness < 0.5] gammas.reco_type = 0 protons.reco_type = 1 focal_length = 28 * u.m src_pos_reco = utils.reco_source_position_sky( gammas.x.values * u.m, gammas.y.values * u.m, gammas.disp_dx_rec.values * u.m, gammas.disp_dy_rec.values * u.m, focal_length, gammas.mc_alt_tel.values * u.rad, gammas.mc_az_tel.values * u.rad) plot_dl2.plot_features(dl2) plt.show() plot_dl2.plot_e(gammas, 10, 1.5, 3.5) plt.show() plot_dl2.calc_resolution(gammas) plt.show() plot_dl2.plot_e_resolution(gammas, 10, 1.5, 3.5) plt.show() plot_dl2.plot_disp_vector(gammas) plt.show() ctaplot.plot_theta2( gammas.mc_alt, np.arctan(np.tan(gammas.mc_az)), src_pos_reco.alt.rad,