How to use the ctapipe.io.hessio.hessio_event_source function in ctapipe

To help you get started, we’ve selected a few ctapipe examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cta-observatory / ctapipe / examples / read_hessio_single_tel.py View on Github external
parser.add_argument('tel', metavar='TEL_ID', type=int)
    parser.add_argument('filename', metavar='EVENTIO_FILE', nargs='?',
                        default=get_example_simtelarray_file())
    parser.add_argument('-m', '--max-events', type=int, default=10)
    parser.add_argument('-c', '--channel', type=int, default=0)
    parser.add_argument('-w', '--write', action='store_true',
                        help='write images to files')
    parser.add_argument('-s', '--show-samples', action='store_true',
                        help='show time-variablity, one frame at a time')
    parser.add_argument('--calibrate', action='store_true',
                        help='apply calibration coeffs from MC')
    parser.add_argument('--hillas', action='store_true',
                        help='apply hillas parameterization and cleaning')
    args = parser.parse_args()

    source = hessio_event_source(args.filename,
                                 allowed_tels=[args.tel, ],
                                 max_events=args.max_events)
    disp = None
    tel,cam,opt = ID.load(args.filename)
    print(tel['TelescopeTable_VersionFeb2016'][tel['TelescopeTable_VersionFeb2016']['TelID']==args.tel])

    print('SELECTING EVENTS FROM TELESCOPE {}'.format(args.tel))
    print('=' * 70)

    for event in source:

        print('Scanning input file... count = {}'.format(event.count))
        print(event.trig)
        print(event.mc)
        print(event.dl0)
github cta-observatory / ctapipe / ctapipe / tools / ImPACT_reconstruction.py View on Github external
self.pix_cut = {"LSTCam": 5,
                             "NectarCam": 4,
                             "FlashCam": 4,
                             "GATE": 4}

        # Calibrators set to default for now
        self.r1 = HessioR1Calibrator(None, None)
        self.dl0 = CameraDL0Reducer(None, None)
        self.calibrator = CameraDL1Calibrator(None, None,
                                              extractor=FullIntegrator(None, None))

        # If we don't set this just use everything
        if len(self.telescopes) < 2:
            self.telescopes = None

        self.source = hessio_event_source(self.infile, allowed_tels=self.telescopes,
                                          max_events=self.max_events)

        self.fit = HillasIntersection()
        self.energy_reco = EnergyReconstructorMVA()
        self.ImPACT = ImPACTReconstructor(fit_xmax=True, minimiser=self.minimiser,
                                          prior="energy, xmax")
        self.viewer = EventViewer(draw_hillas_planes=True)

        self.output = Table(names=['EVENT_ID', 'RECO_ALT', 'RECO_AZ',
                                   'RECO_EN', 'SIM_ALT', 'SIM_AZ', 'SIM_EN', 'NTELS'],
                            dtype=[np.int64, np.float64, np.float64,
                                   np.float64, np.float64, np.float64, np.float64,
                                   np.int16])
github cta-observatory / ctapipe / examples / obsolete / muon_reco.py View on Github external
def apply_mc_calibration(adcs, tel_id):
    """
    apply basic calibration
    """
    peds, gains = get_mc_calibration_coeffs(tel_id)
    return (adcs - peds) * gains


if __name__ == '__main__':

    parser = argparse.ArgumentParser(description='Perform simple Hillas Reco')
    parser.add_argument('filename', metavar='EVENTIO_FILE', nargs='?',
                        default=get_example_simtelarray_file())
    args = parser.parse_args()

    source = hessio_event_source(args.filename)

    container = Container("hessio_container")
    container.meta.add_item('pixel_pos', dict())
    container.add_item("dl0", RawData())
    container.add_item("mc", MCShowerData())
    container.add_item("trig", CentralTriggerData())
    container.add_item("count")
    tel_FIXME, cam_FIXME, opt_FIXME = ID.load(filename=args.filename)
    # embed()

    ev = 0
    efficiency = list()
    efficiency.append(list())
    efficiency.append(list())
    efficiency.append(list())
    efficiency.append(list())
github cta-observatory / ctapipe / examples / calibration_tool.py View on Github external
def get_test_event():
    filename = get_path('gamma_test.simtel.gz')
    for event in hessio_event_source(filename):
        if event.dl0.event_id == 409:
            return event
github cta-observatory / ctapipe / examples / hillas_reconstruction.py View on Github external
"""
    apply basic calibration
    """
    peds, gains = get_mc_calibration_coeffs(tel_id)
    return (adcs - peds) * gains


if __name__ == '__main__':


    parser = argparse.ArgumentParser(description='Perform simple Hillas Reco')
    parser.add_argument('filename', metavar='EVENTIO_FILE', nargs='?',
                        default=get_example_simtelarray_file())
    args = parser.parse_args()

    source = hessio_event_source(args.filename)

    container = Container("hessio_container")
    container.meta.add_item('pixel_pos', dict())
    container.add_item("dl0", RawData())
    container.add_item("mc", MCShowerData())
    container.add_item("trig", CentralTriggerData())
    container.add_item("count")
    tel,cam,opt = ID.load(filename=args.filename)

    for event in source:
        start_t = time.time()

        container.dl0.tels_with_data = set(pyhessio.get_teldata_list())

        container.trig.tels_with_trigger \
            = pyhessio.get_central_event_teltrg_list()
github cta-observatory / ctapipe / examples / list_simtel_triggered_telescopes_per_event.py View on Github external
def list_simtel_triggered_telescopes_per_event(simtel_file_path):
    """Make a dictionary of triggered telescopes per event of the
    'simtel_file_path' file.

    Parameters
    ----------
    simtel_file_path : str
        The path of the simtel file to process.

    Returns
    -------
    Dictionary of triggered telescopes per event of the 'simtel_file_path'
    file (for each item: key=event id, value=the list of triggered telescopes).
    """

    source = hessio_event_source(simtel_file_path, allowed_tels=None, max_events=None)

    tels_per_event_dict = {}   # List of events per telescope

    for event in source:
        tels_per_event_dict[int(event.r0.event_id)] = [int(tel) for tel in event.trig.tels_with_trigger]

    return tels_per_event_dict
github cta-observatory / ctapipe / examples / list_simtel_events_per_telescope.py View on Github external
def list_simtel_events_per_telescope(simtel_file_path):
    """Make a dictionary of triggered events per telescope of the
    'simtel_file_path' file.

    Parameters
    ----------
    simtel_file_path : str
        The path of the simtel file to process.

    Returns
    -------
    Dictionary of triggered events per telescope of the 'simtel_file_path'
    file (for each item: key=telescope id, value=the list of triggered events).
    """

    source = hessio_event_source(simtel_file_path, allowed_tels=None, max_events=None)

    events_per_tel_dict = {}   # List of events per telescope

    for event in source:
        triggered_telescopes_list = [int(tel_id) for tel_id in event.trig.tels_with_trigger]
        for telescope_id in triggered_telescopes_list:
            if telescope_id not in events_per_tel_dict:
                events_per_tel_dict[telescope_id] = []
            events_per_tel_dict[telescope_id].append(int(event.r0.event_id))

    return events_per_tel_dict
github cta-observatory / ctapipe / ctapipe / io / files.py View on Github external
                lambda: hessio_event_source(get_path(self.input_path),
                                            max_events=max_events),
            'targetio':