コード例 #1
0
ファイル: dump_triggers.py プロジェクト: betsman/ctapipe
    def add_event_to_table(self, event_id):
        """
        add the current pyhessio event to a row in the `self.events` table
        """
        ts, tns = pyhessio.get_central_event_gps_time()
        gpstime = Time(ts * u.s, tns * u.ns, format='gps', scale='utc')

        if self._prev_gpstime is None:
            self._prev_gpstime = gpstime

        if self._current_starttime is None:
            self._current_starttime = gpstime

        relative_time = gpstime - self._current_starttime
        delta_t = gpstime - self._prev_gpstime
        self._prev_gpstime = gpstime

        # build the trigger pattern as a fixed-length array
        # (better for storage in FITS format)
        trigtels = pyhessio.get_telescope_with_data_list()
        self._current_trigpattern[:] = 0  # zero the trigger pattern
        self._current_trigpattern[trigtels] = 1  # set the triggered tels to 1

        # insert the row into the table
        self.events.add_row((event_id, relative_time.sec, delta_t.sec,
                             len(trigtels),
                             self._current_trigpattern))
コード例 #2
0
ファイル: dump_triggers.py プロジェクト: vic0ward/ctapipe
    def add_event_to_table(self, event_id):
        """
        add the current pyhessio event to a row in the `self.events` table
        """
        ts, tns = pyhessio.get_central_event_gps_time()
        gpstime = Time(ts * u.s, tns * u.ns, format='gps', scale='utc')

        if self._prev_gpstime is None:
            self._prev_gpstime = gpstime

        if self._current_starttime is None:
            self._current_starttime = gpstime

        relative_time = gpstime - self._current_starttime
        delta_t = gpstime - self._prev_gpstime
        self._prev_gpstime = gpstime

        # build the trigger pattern as a fixed-length array
        # (better for storage in FITS format)
        trigtels = pyhessio.get_telescope_with_data_list()
        self._current_trigpattern[:] = 0  # zero the trigger pattern
        self._current_trigpattern[trigtels] = 1  # set the triggered tels to 1

        # insert the row into the table
        self.events.add_row((event_id, relative_time.sec, delta_t.sec,
                             len(trigtels), self._current_trigpattern))
コード例 #3
0
ファイル: dump_triggers.py プロジェクト: ohma81/ctapipe
def main():

    # get command-line arguments:
    parser = argparse.ArgumentParser()
    parser.add_argument('filename',
                        metavar='SIMTEL_FILE',
                        help='Input simtelarray file')
    parser.add_argument('-o',
                        '--output',
                        metavar='FILENAME',
                        help=('output filename (e.g. times.fits), which '
                              'can be any format supported by astropy.table'),
                        default='times.fits.gz')
    args = parser.parse_args()

    # setup output table
    events = Table(names=['EVENT_ID', 'T_REL', 'TRIGGERED_TELS'],
                   dtype=[np.int64, np.float64, np.uint8])

    events['TRIGGERED_TELS'].shape = (0, MAX_TELS)
    events['T_REL'].unit = u.s
    events['T_REL'].description = 'Time relative to first event'
    events.meta['INPUT'] = args.filename

    trigpattern = np.zeros(MAX_TELS)
    starttime = None

    try:
        pyhessio.file_open(args.filename)

        for run_id, event_id in pyhessio.move_to_next_event():

            ts, tns = pyhessio.get_central_event_gps_time()
            gpstime = Time(ts * u.s, tns * u.ns, format='gps', scale='utc')
            if starttime is None:
                starttime = gpstime

            reltime = (gpstime - starttime).sec

            # build the trigger pattern as a fixed-length array
            # (better for storage in FITS format)
            trigtels = pyhessio.get_telescope_with_data_list()
            trigpattern[:] = 0  # zero the trigger pattern
            trigpattern[trigtels] = 1  # set the triggered telescopes to 1

            events.add_row((event_id, reltime, trigpattern))

        events.write(args.output)
        print("Table written to '{}'".format(args.output))
        print(events)

    except Exception as err:
        print("ERROR: {}, stopping".format(err))

    finally:
        pyhessio.close_file()
コード例 #4
0
ファイル: dump_triggers.py プロジェクト: bregeon/ctapipe
def main():

    # get command-line arguments:
    parser=argparse.ArgumentParser()
    parser.add_argument('filename', metavar='SIMTEL_FILE',
                        help='Input simtelarray file')
    parser.add_argument('-o','--output', metavar='FILENAME',
                        help=('output filename (e.g. times.fits), which '
                              'can be any format supported by astropy.table'),
                        default='times.fits.gz')
    args = parser.parse_args()

    # setup output table
    events = Table(names=['EVENT_ID', 'T_REL', 'TRIGGERED_TELS'],
                dtype=[np.int64, np.float64, np.uint8])

    events['TRIGGERED_TELS'].shape = (0, MAX_TELS)
    events['T_REL'].unit = u.s
    events['T_REL'].description = 'Time relative to first event'
    events.meta['INPUT'] = args.filename
    
    trigpattern = np.zeros(MAX_TELS)
    starttime = None
        
    try:
        pyhessio.file_open(args.filename)

        for run_id, event_id in pyhessio.move_to_next_event():

            ts, tns = pyhessio.get_central_event_gps_time()
            gpstime = Time(ts*u.s, tns*u.ns, format='gps', scale='utc')
            if starttime is None:
                starttime = gpstime

            reltime = (gpstime - starttime).sec
                                
            # build the trigger pattern as a fixed-length array
            # (better for storage in FITS format)
            trigtels = pyhessio.get_telescope_with_data_list()
            trigpattern[:] = 0        # zero the trigger pattern
            trigpattern[trigtels] = 1  # set the triggered telescopes to 1

            events.add_row((event_id, reltime, trigpattern))

        events.write(args.output)
        print("Table written to '{}'".format(args.output))
        print(events)

    except Exception as err:
        print("ERROR: {}, stopping".format(err))
        
    finally:
        pyhessio.close_file()
コード例 #5
0
ファイル: hessio.py プロジェクト: hlaffon/ctapipe
def hessio_event_source(url, max_events=None, allowed_tels=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
    allowed_tels : list[int]
        select only a subset of telescope, if None, all are read. This can
        be used for example 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 = pyhessio.file_open(url)

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

    counter = 0
    eventstream = pyhessio.move_to_next_event()
    if allowed_tels is not None:
        allowed_tels = set(allowed_tels)
    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.meta.add_item('optical_foclen', dict())
    container.add_item("dl0", RawData())
    container.add_item("mc", MCEvent())
    container.add_item("trig", CentralTriggerData())
    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 = set(pyhessio.get_teldata_list())

        # handle telescope filtering by taking the intersection of
        # tels_with_data and allowed_tels
        if allowed_tels is not None:
            selected = container.dl0.tels_with_data & allowed_tels
            if len(selected) == 0:
                continue  # skip event
            container.dl0.tels_with_data = selected

        container.trig.tels_with_trigger \
            = pyhessio.get_central_event_teltrg_list()
        time_s, time_ns = pyhessio.get_central_event_gps_time()
        container.trig.gps_time = Time(time_s * u.s, time_ns * u.ns,
                                       format='gps', scale='utc')
        container.mc.energy = pyhessio.get_mc_shower_energy() * u.TeV
        container.mc.alt = Angle(pyhessio.get_mc_shower_altitude(), u.rad)
        container.mc.az = Angle(pyhessio.get_mc_shower_azimuth(), u.rad)
        container.mc.core_x = pyhessio.get_mc_event_xcore() * u.m
        container.mc.core_y = pyhessio.get_mc_event_ycore() * u.m

        container.count = counter

        # 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] \
                    = pyhessio.get_pixel_position(tel_id) * u.m
                container.meta.optical_foclen[tel_id] = pyhessio.get_optical_foclen(tel_id) * u.m;

            # fill the photo electrons list
            if tel_id not in container.mc.photo_electrons:
                container.mc.photo_electrons[tel_id] = dict()
            for pix_id in range(pyhessio.get_num_pixels(tel_id)):
                container.mc.photo_electrons[tel_id][pix_id] = pyhessio.get_mc_number_photon_electron(tel_id, pix_id)[0]


            nchans = pyhessio.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] \
                    = pyhessio.get_adc_sample(channel=chan,
                                              telescope_id=tel_id)
                container.dl0.tel[tel_id].adc_sums[chan] \
                    = pyhessio.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
ファイル: muon_reco.py プロジェクト: epuesche/ctapipe
                        'telheight': height, 'Npix': numpix, 'mirarea': mirarea,
                        'mirradii': mirradii, 'holeradii': holeradii,
                        'secondmirradii': mir2radii,
                        'secondholeradii': hole2radii}

    print(teloptconfigdict)

    impact = list()
    geom = 0
    for event in source:

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

        container.trig.tels_with_trigger \
            = pyhessio.get_central_event_teltrg_list()
        time_s, time_ns = pyhessio.get_central_event_gps_time()
        container.trig.gps_time = Time(time_s * u.s, time_ns * u.ns,
                                       format='gps', scale='utc')
        container.mc.energy = pyhessio.get_mc_shower_energy() * u.TeV
        container.mc.alt = Angle(pyhessio.get_mc_shower_altitude(), u.rad)
        container.mc.az = Angle(pyhessio.get_mc_shower_azimuth(), u.rad)
        container.mc.core_x = pyhessio.get_mc_event_xcore() * u.m
        container.mc.core_y = pyhessio.get_mc_event_ycore() * u.m

        # 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

        table = "CameraTable_VersionFeb2016_TelID"
コード例 #7
0
def hessio_event_source(url, max_events=None, allowed_tels=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
    allowed_tels : list[int]
        select only a subset of telescope, if None, all are read. This can
        be used for example 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 = pyhessio.file_open(url)

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

    # the container is initialized once, and data is replaced within
    # it after each yield

    counter = 0
    eventstream = pyhessio.move_to_next_event()
    if allowed_tels is not None:
        allowed_tels = set(allowed_tels)
    event = EventContainer()
    event.meta.source = "hessio"

    # some hessio_event_source specific parameters
    event.meta.add_item('hessio__input', url)
    event.meta.add_item('hessio__max_events', max_events)

    for run_id, event_id in eventstream:

        event.dl0.run_id = run_id
        event.dl0.event_id = event_id
        event.dl0.tels_with_data = set(pyhessio.get_teldata_list())
        
        # handle telescope filtering by taking the intersection of
        # tels_with_data and allowed_tels
        if allowed_tels is not None:
            selected = event.dl0.tels_with_data & allowed_tels
            if len(selected) == 0:
                continue  # skip event
            event.dl0.tels_with_data = selected

        event.trig.tels_with_trigger \
            = pyhessio.get_central_event_teltrg_list()
        time_s, time_ns = pyhessio.get_central_event_gps_time()
        event.trig.gps_time = Time(time_s * u.s, time_ns * u.ns,
                                   format='gps', scale='utc')
        event.mc.energy = pyhessio.get_mc_shower_energy() * u.TeV
        event.mc.alt = Angle(pyhessio.get_mc_shower_altitude(), u.rad)
        event.mc.az = Angle(pyhessio.get_mc_shower_azimuth(), u.rad)
        event.mc.core_x = pyhessio.get_mc_event_xcore() * u.m
        event.mc.core_y = pyhessio.get_mc_event_ycore() * u.m
        event.mc.h_first_int = pyhessio.get_mc_shower_h_first_int() * u.m

        event.count = counter

        # 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)

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

        for tel_id in event.dl0.tels_with_data:

            # fill pixel position dictionary, if not already done:
            if tel_id not in event.meta.pixel_pos:
                event.meta.pixel_pos[tel_id] \
                    = pyhessio.get_pixel_position(tel_id) * u.m
                event.meta.optical_foclen[
                    tel_id] = pyhessio.get_optical_foclen(tel_id) * u.m

            # fill telescope position dictionary, if not already done:
            if tel_id not in event.meta.tel_pos:
                event.meta.tel_pos[
                    tel_id] = pyhessio.get_telescope_position(tel_id) * u.m

            nchans = pyhessio.get_num_channel(tel_id)
            npix = pyhessio.get_num_pixels(tel_id)
            nsamples = pyhessio.get_num_samples(tel_id)
            event.dl0.tel[tel_id] = RawCameraData(tel_id)
            event.dl0.tel[tel_id].num_channels = nchans
            event.dl0.tel[tel_id].num_pixels = npix
            event.dl0.tel[tel_id].num_samples = nsamples
            event.mc.tel[tel_id] = MCCamera(tel_id)

            event.dl0.tel[tel_id].calibration \
                = pyhessio.get_calibration(tel_id)
            event.dl0.tel[tel_id].pedestal \
                = pyhessio.get_pedestal(tel_id)

            # load the data per telescope/chan
            for chan in range(nchans):
                event.dl0.tel[tel_id].adc_samples[chan] \
                    = pyhessio.get_adc_sample(channel=chan,
                                              telescope_id=tel_id)
                event.dl0.tel[tel_id].adc_sums[chan] \
                    = pyhessio.get_adc_sum(channel=chan,
                                           telescope_id=tel_id)
                event.mc.tel[tel_id].refshapes[chan] = \
                    pyhessio.get_ref_shapes(tel_id, chan)

            # load the data per telescope/pixel
            event.mc.tel[tel_id].photo_electrons \
                = pyhessio.get_mc_number_photon_electron(telescope_id=tel_id)
            event.mc.tel[tel_id].refstep = pyhessio.get_ref_step(tel_id)
            event.mc.tel[tel_id].lrefshape = pyhessio.get_lrefshape(tel_id)
            event.mc.tel[tel_id].time_slice = \
                pyhessio.get_time_slice(tel_id)
        yield event
        counter += 1

        if max_events is not None and counter >= max_events:
            return
コード例 #8
0
    efficiency = list()
    efficiency.append(list())
    efficiency.append(list())
    efficiency.append(list())
    efficiency.append(list())


    impact = list()
    geom = 0
    for event in source:

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

        container.trig.tels_with_trigger \
            = pyhessio.get_central_event_teltrg_list()
        time_s, time_ns = pyhessio.get_central_event_gps_time()
        container.trig.gps_time = Time(time_s * u.s, time_ns * u.ns,
                                       format='gps', scale='utc')
        container.mc.energy = pyhessio.get_mc_shower_energy() * u.TeV
        container.mc.alt = Angle(pyhessio.get_mc_shower_altitude(), u.rad)
        container.mc.az = Angle(pyhessio.get_mc_shower_azimuth(), u.rad)
        container.mc.core_x = pyhessio.get_mc_event_xcore() * u.m
        container.mc.core_y = pyhessio.get_mc_event_ycore() * u.m

        # 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

        table = "CameraTable_VersionFeb2016_TelID"
コード例 #9
0
def hessio_event_source(url, max_events=None, allowed_tels=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
    allowed_tels : list[int]
        select only a subset of telescope, if None, all are read. This can
        be used for example 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 = pyhessio.file_open(url)

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

    counter = 0
    eventstream = pyhessio.move_to_next_event()
    if allowed_tels is not None:
        allowed_tels = set(allowed_tels)
    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.meta.add_item('optical_foclen', dict())
    container.add_item("dl0", RawData())
    container.add_item("mc", MCShowerData())
    container.add_item("trig", CentralTriggerData())
    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 = set(pyhessio.get_teldata_list())

        # handle telescope filtering by taking the intersection of
        # tels_with_data and allowed_tels
        if allowed_tels is not None:
            selected = container.dl0.tels_with_data & allowed_tels
            if len(selected) == 0:
                continue  # skip event
            container.dl0.tels_with_data = selected

        container.trig.tels_with_trigger \
            = pyhessio.get_central_event_teltrg_list()
        time_s, time_ns = pyhessio.get_central_event_gps_time()
        container.trig.gps_time = Time(time_s * u.s,
                                       time_ns * u.ns,
                                       format='gps',
                                       scale='utc')
        container.mc.energy = pyhessio.get_mc_shower_energy() * u.TeV
        container.mc.alt = Angle(pyhessio.get_mc_shower_altitude(), u.rad)
        container.mc.az = Angle(pyhessio.get_mc_shower_azimuth(), u.rad)
        container.mc.core_x = pyhessio.get_mc_event_xcore() * u.m
        container.mc.core_y = pyhessio.get_mc_event_ycore() * u.m

        container.count = counter

        # 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] \
                    = pyhessio.get_pixel_position(tel_id) * u.m
                container.meta.optical_foclen[
                    tel_id] = pyhessio.get_optical_foclen(tel_id) * u.m

            nchans = pyhessio.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] \
                    = pyhessio.get_adc_sample(channel=chan,
                                              telescope_id=tel_id)
                container.dl0.tel[tel_id].adc_sums[chan] \
                    = pyhessio.get_adc_sum(channel=chan,
                                           telescope_id=tel_id)
        yield container
        counter += 1

        if max_events is not None and counter > max_events:
            return