def initialize_hessio(filename,file_closed):
    if file_closed:
        file_closed = util_functions.load_hessio(filename)
        print(file_closed)
        util_functions.nextevent_hessio()
    else:
        pass
    
    #ld.telescope_id = h.get_telescope_ids().tolist() #--> this function only can be used if the according python wrapper hase been added to pyhessio.c and hessio.py
    
    ld.telescope_id = h.get_teldata_list().tolist()
    ld.telescope_num = h.get_num_telescope()

    return file_closed
示例#2
0
def initialize_hessio(filename, file_closed):
    if file_closed:
        file_closed = util_functions.load_hessio(filename)
        print(file_closed)
        util_functions.nextevent_hessio()
    else:
        pass

    #ld.telescope_id = h.get_telescope_ids().tolist() #--> this function only can be used if the according python wrapper hase been added to pyhessio.c and hessio.py

    ld.telescope_id = h.get_teldata_list().tolist()
    ld.telescope_num = h.get_num_telescope()

    return file_closed
def initialize_telescope(filename, file_closed = True):
    ld.clear_lists_telescope()
    ld.clear_lists_camera()

    if 'simtel.gz' in filename:
        if file_closed:
            file_closed = load_hessio(filename)
            nextevent_hessio()
        else:
            pass

        #ld.telescope_id = h.get_telescope_ids().tolist() #--> this function only can be used if the according python wrapper hase been added to pyhessio.c and hessio.py
        ld.telescope_id = h.get_teldata_list().tolist()
        ld.telescope_num = h.get_num_telescope()

    elif 'fits' in filename:
        if file_closed:
            hdulist = load_fits(filename)
            file_closed = hdulist
        else:
            pass
        teles = hdulist[1].data
        ld.telescope_id = teles["TelID"].tolist()
        ld.telescope_posX = teles["TelX"].tolist()
        ld.telescope_posY = teles["TelY"].tolist()
        ld.telescope_posZ = teles["TelZ"].tolist()
        ld.telescope_num = len(ld.telescope_id)

    for tel in ld.telescope_id:
        initialize_camera(tel,filename,file_closed)
        initialize_optics(tel,filename,file_closed)

    if 'simtel.gz' in filename:   
        close_hessio()
    elif 'fits' in filename:
        close_fits(hdulist)
def initialize_telescope(filename, file_closed=True):
    ld.clear_lists_telescope()
    ld.clear_lists_camera()

    if 'simtel.gz' in filename:
        if file_closed:
            file_closed = load_hessio(filename)
            nextevent_hessio()
        else:
            pass

        #ld.telescope_id = h.get_telescope_ids().tolist() #--> this function only can be used if the according python wrapper hase been added to pyhessio.c and hessio.py
        ld.telescope_id = h.get_teldata_list().tolist()
        ld.telescope_num = h.get_num_telescope()

    elif 'fits' in filename:
        if file_closed:
            hdulist = load_fits(filename)
            file_closed = hdulist
        else:
            pass
        teles = hdulist[1].data
        ld.telescope_id = teles["TelID"].tolist()
        ld.telescope_posX = teles["TelX"].tolist()
        ld.telescope_posY = teles["TelY"].tolist()
        ld.telescope_posZ = teles["TelZ"].tolist()
        ld.telescope_num = len(ld.telescope_id)

    for tel in ld.telescope_id:
        initialize_camera(tel, filename, file_closed)
        initialize_optics(tel, filename, file_closed)

    if 'simtel.gz' in filename:
        close_hessio()
    elif 'fits' in filename:
        close_fits(hdulist)
示例#5
0
文件: hessio.py 项目: cdeil/ctapipe
def hessio_event_source(url, max_events=None, single_tel=None):
    """A generator that streams data from an EventIO/HESSIO MC data file
    (e.g. a standard CTA data file.)

    Parameters
    ----------
    url : str
        path to file to open
    max_events : int, optional
        maximum number of events to read
    single_tel : int
        select only a single telescope, if None, all are read. This is
        to emulate the final CTA data format, where there would be 1
        telescope per file (whereas in current monte-carlo, they are
        all interleaved into one file)

    """

    ret = hessio.file_open(url)

    if ret is not 0:
        raise RuntimeError(
            "hessio_event_source failed to open '{}'".format(url))

    counter = 0
    eventstream = hessio.move_to_next_event()
    container = Container("hessio_container")
    container.meta.add_item('hessio__input', url)
    container.meta.add_item('hessio__max_events', max_events)
    container.meta.add_item('pixel_pos', dict())
    container.add_item("dl0", RawData())
    container.add_item("count")

    for run_id, event_id in eventstream:

        container.dl0.run_id = run_id
        container.dl0.event_id = event_id
        container.dl0.tels_with_data = hessio.get_teldata_list()
        container.count = counter

        # handle single-telescope case (ignore others:
        if single_tel is not None:
            if single_tel not in container.dl0.tels_with_data:
                continue
            container.dl0.tels_with_data = [
                single_tel,
            ]

        # this should be done in a nicer way to not re-allocate the
        # data each time (right now it's just deleted and garbage
        # collected)

        container.dl0.tel = dict()  # clear the previous telescopes

        for tel_id in container.dl0.tels_with_data:

            # fill pixel position dictionary, if not already done:
            if tel_id not in container.meta.pixel_pos:
                container.meta.pixel_pos[tel_id] = hessio.get_pixel_position(
                    tel_id)

            nchans = hessio.get_num_channel(tel_id)
            container.dl0.tel[tel_id] = RawCameraData(tel_id)
            container.dl0.tel[tel_id].num_channels = nchans

            # load the data per telescope/chan
            for chan in range(nchans):
                container.dl0.tel[tel_id].adc_samples[chan] \
                    = hessio.get_adc_sample(channel=chan,
                                            telescope_id=tel_id)
                container.dl0.tel[tel_id].adc_sums[chan] \
                    = hessio.get_adc_sum(channel=chan,
                                         telescope_id=tel_id)
        yield container
        counter += 1

        if max_events is not None and counter > max_events:
            return
示例#6
0
文件: hessio.py 项目: cdeil/ctapipe
def hessio_event_source(url, max_events=None, single_tel=None):
    """A generator that streams data from an EventIO/HESSIO MC data file
    (e.g. a standard CTA data file.)

    Parameters
    ----------
    url : str
        path to file to open
    max_events : int, optional
        maximum number of events to read
    single_tel : int
        select only a single telescope, if None, all are read. This is
        to emulate the final CTA data format, where there would be 1
        telescope per file (whereas in current monte-carlo, they are
        all interleaved into one file)

    """

    ret = hessio.file_open(url)

    if ret is not 0:
        raise RuntimeError("hessio_event_source failed to open '{}'"
                           .format(url))

    counter = 0
    eventstream = hessio.move_to_next_event()
    container = Container("hessio_container")
    container.meta.add_item('hessio__input', url)
    container.meta.add_item('hessio__max_events', max_events)
    container.meta.add_item('pixel_pos', dict())
    container.add_item("dl0", RawData())
    container.add_item("count")

    for run_id, event_id in eventstream:

        container.dl0.run_id = run_id
        container.dl0.event_id = event_id
        container.dl0.tels_with_data = hessio.get_teldata_list()
        container.count = counter
        
        # handle single-telescope case (ignore others:
        if single_tel is not None:
            if single_tel not in container.dl0.tels_with_data:
                continue
            container.dl0.tels_with_data = [single_tel, ]

        # this should be done in a nicer way to not re-allocate the
        # data each time (right now it's just deleted and garbage
        # collected)

        container.dl0.tel = dict()  # clear the previous telescopes

        for tel_id in container.dl0.tels_with_data:

            # fill pixel position dictionary, if not already done:
            if tel_id not in container.meta.pixel_pos:
                container.meta.pixel_pos[
                    tel_id] = hessio.get_pixel_position(tel_id)

            nchans = hessio.get_num_channel(tel_id)
            container.dl0.tel[tel_id] = RawCameraData(tel_id)
            container.dl0.tel[tel_id].num_channels = nchans

            # load the data per telescope/chan
            for chan in range(nchans):
                container.dl0.tel[tel_id].adc_samples[chan] \
                    = hessio.get_adc_sample(channel=chan,
                                            telescope_id=tel_id)
                container.dl0.tel[tel_id].adc_sums[chan] \
                    = hessio.get_adc_sum(channel=chan,
                                         telescope_id=tel_id)
        yield container
        counter += 1

        if max_events is not None and counter > max_events:
            return