def test_CutFlow(): with warns(FutureWarning): flow = CutFlow("TestFlow") # set_cut and add_cut a aliases flow.set_cut("smaller5", smaller5) flow.add_cut("smaller3", lambda x: x < 3) for i in range(2, 6): flow.count("noCuts") # .keep counts if the function returns True, # i.e. when we "keep" the event if flow.keep("smaller5", i): # .cut counts if the function returns False, # i.e. when we do NOT "cut" the event if flow.cut("smaller3", i): pass else: # do something else that could fail or be rejected try: assert i == 3 flow.count("something") except: pass t = flow(sort_column=1) assert np.all(t["selected Events"] == [4, 3, 2, 1]) with raises(UndefinedCut): flow.cut("undefined", 5) with raises(PureCountingCut): flow.cut("noCuts")
def test_CutFlow(): flow = CutFlow("TestFlow") # set_cut and add_cut a aliases flow.set_cut("smaller5", lambda x: x < 5) flow.add_cut("smaller3", lambda x: x < 3) for i in range(2, 6): flow.count("noCuts") # .keep counts if the function returns True, # i.e. when we "keep" the event if flow.keep("smaller5", i): # .cut counts if the function returns False, # i.e. when we do NOT "cut" the event if flow.cut("smaller3", i): pass else: # do something else that could fail or be rejected try: assert i == 3 flow.count("something") except: pass t = flow(sort_column=1) assert np.all(t["selected Events"] == [4, 3, 2, 1]) with raises(UndefinedCutException): flow.cut("undefined", 5) with raises(PureCountingCutException): flow.cut("noCuts")
island_cleaning=True) # the class that does the shower reconstruction shower_reco = HillasReconstructor() preper = EventPreparer( cleaner=cleaner, shower_reco=shower_reco, event_cutflow=Eventcutflow, image_cutflow=Imagecutflow, # event/image cuts: allowed_cam_ids=[], # [] or None means: all min_ntel=2, min_charge=args.min_charge, min_pixel=3) Imagecutflow.add_cut("features nan", lambda x: np.isnan(x).any()) energy_mc = [] energy_rec = [] filenamelist_gamma = sorted(glob("{}/gamma/*gz".format(args.indir))) filenamelist_gamma = sorted( glob(expandvars("$CTA_DATA/Prod3b/Paranal/*simtel.gz"))) allowed_tels = prod3b_tel_ids("L+N+D") for filename in filenamelist_gamma[:5][:args.last]: print("filename = {}".format(filename)) source = hessio_event_source(filename, allowed_tels=allowed_tels,
# takes care of image cleaning cleaner = ImageCleaner(mode=args.mode, cutflow=Imagecutflow, wavelet_options=args.raw, skip_edge_events=False, island_cleaning=True) # the class that does the shower reconstruction shower_reco = HillasReconstructor() preper = EventPreparer( cleaner=cleaner, shower_reco=shower_reco, event_cutflow=Eventcutflow, image_cutflow=Imagecutflow, # event/image cuts: allowed_cam_ids=[], # [] or None means: all min_ntel=2, min_charge=args.min_charge, min_pixel=3) Imagecutflow.add_cut("features nan", lambda x: np.isnan(x).any()) energy_mc = [] gammaness = [] true_class = [] filenamelist_gamma = sorted(glob("{}/gamma/*gz".format(args.indir)))[50:] filenamelist_gamma = sorted(glob(expandvars("$CTA_DATA/Prod3b/Paranal/*simtel.gz"))) filenamelist_proton = \ sorted(glob(expandvars("$CTA_DATA/Prod3b/Paranal/proton/*simtel.gz")))[50:] allowed_tels = prod3b_tel_ids("L+N+D") for filenamelist in [filenamelist_gamma, filenamelist_proton]: channel = "g" if "gamma" in "".join(filenamelist) else "p" for i, filename in enumerate(filenamelist[:5][:args.last]):