def initialize_camera(tel_id, filename, file_closed=1):
    if 'simtel.gz' in filename:
        if file_closed:
            ld.clear_lists_camera()
            load_hessio(filename)
            nextevent_hessio()
        else:
            pass

        px = h.get_pixel_position(tel_id)[0]
        py = h.get_pixel_position(tel_id)[1]
        ld.pixel_posX.append(px)
        ld.pixel_posY.append(py)
        ld.camera_class.append(
            io.guess_camera_geometry(px * u.m, py * u.m).cam_id)

        #to use this, one has to go through every event of the run...
        n_channel = h.get_num_channel(tel_id)
        ld.channel_num = n_channel
        for chan in range(n_channel):
            ld.adc_sampels.append(h.get_adc_sample(tel_id, chan).tolist())

        if file_closed:
            close_hessio()

    elif 'fits' in filename:
        hdulist = file_closed
        if file_closed == 1:
            ld.clear_lists_camera()
            ld.clear_lists_telescope()
            hdulist = load_fits(filename)
            teles = hdulist[1].data
            ld.telescope = teles["TelID"].tolist()
        else:
            pass

        index = ld.telescope_id.index(tel_id)
        ld.camera_fov.append(hdulist[1].data[index]["FOV"])

        pixel_id_cam = []
        index2 = np.where(hdulist[2].data['L0ID'] == index)[0]
        for i in index2:
            pixel_id_cam.append(hdulist[2].data[i]['PixelID'])
        ld.pixel_id.append(pixel_id_cam)

        if file_closed == 1:
            close_fits(hdulist)
def initialize_camera(tel_id, filename, file_closed = 1):
    if 'simtel.gz' in filename:
        if file_closed:
            ld.clear_lists_camera()
            load_hessio(filename)
            nextevent_hessio()
        else:
            pass
    
        px = h.get_pixel_position(tel_id)[0]
        py = h.get_pixel_position(tel_id)[1]
        ld.pixel_posX.append(px)
        ld.pixel_posY.append(py)
        ld.camera_class.append(io.guess_camera_geometry(px*u.m,py*u.m).cam_id)
        
        #to use this, one has to go through every event of the run...
        n_channel = h.get_num_channel(tel_id)
        ld.channel_num = n_channel
        for chan in range(n_channel):
            ld.adc_sampels.append(h.get_adc_sample(tel_id,chan).tolist())

        if file_closed:
            close_hessio()
        
    elif 'fits' in filename:
        hdulist = file_closed
        if file_closed == 1:
            ld.clear_lists_camera()
            ld.clear_lists_telescope()
            hdulist = load_fits(filename)
            teles = hdulist[1].data
            ld.telescope = teles["TelID"].tolist()
        else:
            pass
        
        index = ld.telescope_id.index(tel_id)
        ld.camera_fov.append(hdulist[1].data[index]["FOV"])
        
        pixel_id_cam = []
        index2 = np.where(hdulist[2].data['L0ID'] == index)[0]
        for i in index2:
            pixel_id_cam.append(hdulist[2].data[i]['PixelID'])
        ld.pixel_id.append(pixel_id_cam)
        
        if file_closed == 1:
            close_fits(hdulist)
示例#3
0
def initialize_hessio(filename, tel_id, file_closed):
    if file_closed:
        util_functions.load_hessio(filename)
        util_functions.nextevent_hessio()
    else:
        pass

    px = h.get_pixel_position(tel_id)[0]
    py = h.get_pixel_position(tel_id)[1]
    ld.pixel_posX.append(px)
    ld.pixel_posY.append(py)
    ld.camera_class.append(guess_camera_geometry(px * u.m, py * u.m).cam_id)

    #to use this, one has to go through every event of the run...
    n_channel = h.get_num_channel(tel_id)
    ld.channel_num = n_channel
    #for chan in range(n_channel):
    #    ld.adc_samples.append(h.get_adc_sample(tel_id,chan).tolist())

    if file_closed:
        util_functions.close_hessio()
def initialize_hessio(filename,tel_id, file_closed):
    if file_closed:
        util_functions.load_hessio(filename)
        util_functions.nextevent_hessio()
    else:
        pass
    
    px = h.get_pixel_position(tel_id)[0]
    py = h.get_pixel_position(tel_id)[1]
    ld.pixel_posX.append(px)
    ld.pixel_posY.append(py)
    ld.camera_class.append(guess_camera_geometry(px*u.m,py*u.m).cam_id)
    
    #to use this, one has to go through every event of the run...
    n_channel = h.get_num_channel(tel_id)
    ld.channel_num = n_channel
    #for chan in range(n_channel):
    #    ld.adc_samples.append(h.get_adc_sample(tel_id,chan).tolist())
        
    if file_closed:
        util_functions.close_hessio()
示例#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