def targetio_source(filepath, max_events=None): """ Temporary function to return a "source" generator from a targetio file, only if targetpipe exists on this python interpreter. Parameters ---------- filepath : string Filepath for the input targetio file max_events : int Maximum number of events to read Returns ------- source : generator A generator that can be iterated over to obtain events, obtained from a targetio file. """ # Check targetpipe is installed try: import importlib targetpipe_spec = importlib.util.find_spec("targetpipe") found = targetpipe_spec is not None if found: from targetpipe.io.targetio import targetio_event_source return targetio_event_source(filepath, max_events=max_events) else: raise RuntimeError() except RuntimeError: log.exception("targetpipe is not installed on this interpreter") raise
def test_targetio_event_source(): dataset = get_oxpytools_extra_path("target_sky.fits") source = targetio_event_source(dataset) event = next(source) assert event.dl0.event_id == 0 assert event.dl0.tel[0].adc_samples[0][0][0] == 287 event = next(source) assert event.dl0.event_id == 1 assert event.dl0.tel[0].adc_samples[0][0][0] == 288
def targetio_source(filepath, max_events=None, allowed_tels=None, requested_event=None, use_event_id=False): """ Temporary function to return a "source" generator from a targetio file, only if targetpipe exists on this python interpreter. Parameters ---------- filepath : string Filepath for the input targetio file max_events : int Maximum number of events to read allowed_tels : list[int] select only a subset of telescope, if None, all are read. requested_event : int Seek to a paricular event index use_event_id : bool If True ,'requested_event' now seeks for a particular event id instead of index Returns ------- source : generator A generator that can be iterated over to obtain events, obtained from a targetio file. """ # Check targetpipe is installed try: import importlib targetpipe_spec = importlib.util.find_spec("targetpipe") found = targetpipe_spec is not None if found: from targetpipe.io.targetio import targetio_event_source return targetio_event_source(filepath, max_events=max_events, allowed_tels=allowed_tels, requested_event=requested_event, use_event_id=use_event_id) else: raise RuntimeError() except RuntimeError: log.exception("targetpipe is not installed on this interpreter") raise