How to use the ctapipe.io.CameraGeometry.guess 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 / calibration_pipeline.py View on Github external
container.dl1.tels_with_data,
                        "%.3e TeV @ (%.0f,%.0f)deg @ %.3f m"%
                        (get_mc_shower_energy(), get_mc_shower_altitude(),
                         get_mc_shower_azimuth(),
                         np.sqrt(pow(get_mc_event_xcore(), 2) +
                                 pow(get_mc_event_ycore(), 2)))
                        )

        for telid in event.dl0.tels_with_data:
            logger.info("%s> Calibrating.. CT%d\n"
                        %(sys._getframe().f_code.co_name,  telid))

            # Get per telescope the camera geometry
            x, y = event.meta.pixel_pos[telid]
            #geom = io.CameraGeometry.guess(x * u.m, y * u.m)
            geom = io.CameraGeometry.guess(x,y)

            # Get the calibration data sets (pedestals and single-pe)
            ped = get_pedestal(telid)
            calib = get_calibration(telid)

            # Integrate pixels traces and substract pedestal
            # See pixel_integration_mc function documentation in mc.py
            # for the different algorithms options
            int_adc_pix, peak_adc_pix = pixel_integration_mc(event, 
                                                             ped, telid, 
                                                             parameters)

            # Convert integrated ADC counts into p.e.
            # selecting also the HG/LG channel (currently hard-coded)
            pe_pix = calibrate_amplitude_mc(int_adc_pix, calib,
                                            telid, parameters)
github cta-observatory / ctapipe / examples / calibration_tool.py View on Github external
for event in hessio_event_source(filename):
        if event.dl0.event_id == 409:
            return event

# TEMP GLOBALS FOR PLAYING WITH
telid = 11
event = get_test_event()
nsamples = event.inst.num_samples[telid]
data = np.array(list(event.dl0.tel[telid].adc_samples.values()))
ped = event.mc.tel[telid].pedestal
data_ped = data - np.atleast_3d(ped / nsamples)
data_ped = np.array([data_ped[0], data_ped[0]])
pixel_pos = event.inst.pixel_pos[telid]
optical_foclen = event.inst.optical_foclen[telid]

geom = CameraGeometry.guess(*pixel_pos, optical_foclen)
nei = geom.neighbors

params = get_test_parameters()


class CalTool(Tool):
    name = "mytool"
    description = "do some things and stuff"

    aliases = Dict(dict(extractor='ChargeExtractorFactory.extractor',
                        window_width='ChargeExtractorFactory.window_width',
                        ))
    classes = List([ChargeExtractorFactory])

    def setup(self):
        print("setting up")
github cta-observatory / ctapipe / examples / list_telescopes_geometry.py View on Github external
simtel_file_path : str
        The path of the simtel file to process.
    """

    source = hessio_event_source(simtel_file_path)

    tel_id_set = set()

    for event in source:
        for tel_id in event.r0.tels_with_data:
            tel_id_set.add(tel_id)

    for tel_id in tel_id_set:
        x, y = event.inst.pixel_pos[tel_id]
        foclen = event.inst.optical_foclen[tel_id]
        geom = ctapipe.io.CameraGeometry.guess(x, y, foclen)
        print("Telescope {:03d}: {} ({} pixels)".format(tel_id, geom.cam_id, geom.pix_type))
github cta-observatory / ctapipe / examples / obsolete / muon_reco_rdp.py View on Github external
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"

        for tel_id in container.dl0.tels_with_data:

            x, y = event.meta.pixel_pos[tel_id]
            if geom == 0:
                geom = io.CameraGeometry.guess(x, y,event.meta.optical_foclen[tel_id])
            image = apply_mc_calibration(event.dl0.tel[tel_id].image[0], tel_id)
            if image.shape[0] >1000:
                continue
            clean_mask = tailcuts_clean(geom,image,1,picture_thresh=5,boundary_thresh=7)

            camera_coord = CameraFrame(x=x,y=y,z=np.zeros(x.shape)*u.m)

            nom_coord = camera_coord.transform_to(NominalFrame(array_direction=[container.mc.alt,container.mc.az],
                                                       pointing_direction=[container.mc.alt,container.mc.az],
                                                       focal_length=tel['TelescopeTable_VersionFeb2016'][tel['TelescopeTable_VersionFeb2016']['TelID']==tel_id]['FL'][0]*u.m))

            x = nom_coord.x.to(u.deg)
            y = nom_coord.y.to(u.deg)

            img = image*clean_mask
            noise = 5
github cta-observatory / ctapipe / examples / calibration_pipeline.py View on Github external
def display_telescope(event, tel_id):
    global fig
    ntels = len(event.dl1.tels_with_data)
    fig.clear()

    plt.suptitle("EVENT {} {:.1e} TeV @({:.1f},{:.1f})deg @{:.1f} m".format(
            event.dl1.event_id, get_mc_shower_energy(),
            get_mc_shower_altitude(), get_mc_shower_azimuth(),
            np.sqrt(pow(get_mc_event_xcore(), 2) +
                    pow(get_mc_event_ycore(), 2))))
    print("\t draw cam {}...".format(tel_id))
    x, y = event.meta.pixel_pos[tel_id]
    #geom = io.CameraGeometry.guess(x * u.m, y * u.m)
    geom = io.CameraGeometry.guess(x, y)
    npads = 1
    # Only create two pads if there is timing information extracted
    # from the calibration
    if not event.dl1.tel[tel_id].tom is None:
        npads = 2

    ax = plt.subplot(1, npads, npads-1)
    disp = visualization.CameraDisplay(geom, ax=ax,
                                       title="CT{0}".format(tel_id))

    disp.pixels.set_antialiaseds(False)
    disp.autoupdate = False
    disp.pixels.set_cmap('seismic')
    chan = 0
    signals = event.dl1.tel[tel_id].pe_charge
    disp.image = signals
github cta-observatory / ctapipe / examples / obsolete / muon_reco.py View on Github external
flen = event.meta.optical_foclen[tel_id]

            dictindex = 0

            if npix != 1855:
                dictindex = teloptconfigdict['Npix'].index(npix)
                # print('Found dictionary index npix',dictindex,npix)
            else:
                dictindex = teloptconfigdict['focallengths'].index(flen / u.m)
                # print('Found dictionary index flen',dictindex,flen)

            print('Found telescope', teloptconfigdict['teltypes'][dictindex])

            x, y = event.meta.pixel_pos[tel_id]
            if geom == 0:
                geom = io.CameraGeometry.guess(x, y, event.meta.optical_foclen[
                    tel_id])
            image = apply_mc_calibration(event.dl0.tel[tel_id].image[0],
                                         tel_id)

            if image.shape[0] > 2500:
                continue

            # CUTS also need to change for each telescope type....
            # clean_mask = tailcuts_clean(geom,image,1,picture_thresh=5,
            # boundary_thresh=7)
            clean_mask = tailcuts_clean(geom, image, 1, picture_thresh=1,
                                        boundary_thresh=2)

            pixwidth = np.sqrt(geom.pix_area)
            angpixwidth = pixwidth / (teloptconfigdict['focallengths'][
                                          dictindex]) * (180. / np.pi) * (