How to use the ctapipe.visualization.CameraDisplay 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 / display_DL0testbed3_withID.py View on Github external
plt.suptitle("EVENT {} {:.1e} TeV @({:.1f},{:.1f})deg @{:.1f} m".format(
            event.r0.event_id, event.mc.energy,
            event.mc.alt, event.mc.az,
            np.sqrt(pow(event.mc.core_x, 2) +
                    pow(event.mc.core_y, 2))))
        print("\t draw cam {} (gains={})...".format(tel_id,nchan))
        ax=[]
        disp=[]
        signals=[]
        npads=0
        for i in range(nchan):
            npads += 1
            # Display the camera charge (HG/LG)
            ax.append(plt.subplot(nchan, 2, npads))
            disp.append(visualization.CameraDisplay(geom, ax=ax[-1],
                                                    title="CT{} [{} ADC cts]".format(tel_id,gain_label[i])))
            disp[-1].pixels.set_antialiaseds(False)
            signals.append(event.r0.tel[tel_id].adc_sums[i])
            disp[-1].image = signals[-1]
            disp[-1].pixels.set_cmap(get_cmap(disp[-1].image))
            disp[-1].add_colorbar(label=" [{} ADC cts]".format(gain_label[i]))

            # Display the camera charge for significant pixels (HG/LG)
            npads += 1
            ax.append(plt.subplot(nchan, 2, npads))
            disp.append(visualization.CameraDisplay(geom, ax=ax[-1],
                                                    title="CT{} [{} ADC cts]".format(tel_id,gain_label[i])))
            disp[-1].pixels.set_antialiaseds(False)
            signals.append(event.r0.tel[tel_id].adc_sums[i])
            m = (get_zero_sup_mode(tel_id) & 0x001) or (get_significant(tel_id) & 0x020)
            disp[-1].image = signals[-1]*(m/m.max())
github cta-observatory / ctapipe / examples / calibration_pipeline.py View on Github external
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
    disp.add_colorbar()
    if npads == 2:
        ax = plt.subplot(1, npads, npads)
        disp = visualization.CameraDisplay(geom,
                                           ax=ax,
                                           title="CT{0}".format(tel_id))
        disp.pixels.set_antialiaseds(False)
        disp.autoupdate = False
        disp.pixels.set_cmap('gnuplot')
        chan = 0
        disp.image = event.dl1.tel[tel_id].tom
        disp.add_colorbar()

    if __debug__:
        print("All sum = %.3f\n" % sum(event.dl1.tel[tel_id].pe_charge))
github cta-observatory / ctapipe / examples / plot_camera_frames.py View on Github external
def main():
    fig, axs = plt.subplots(1, 2, constrained_layout=True, figsize=(6, 3))

    model = Gaussian(0 * u.m, 0.1 * u.m, 0.3 * u.m, 0.05 * u.m, 25 * u.deg)
    cam = CameraGeometry.from_name("FlashCam")
    image, *_ = model.generate_image(cam, 2500)

    CameraDisplay(cam, ax=axs[0], image=image)
    CameraDisplay(
        cam.transform_to(EngineeringCameraFrame()), ax=axs[1], image=image,
    )

    axs[0].set_title("CameraFrame")
    axs[1].set_title("EngineeringCameraFrame")

    plt.show()
github cta-observatory / ctapipe / examples / mock_generator.py View on Github external
global fig
    ntels = len(event.dl0.tels_with_data)
    fig.clear()

    plt.suptitle("EVENT {}".format(event.dl0.event_id))

    disps = []

    for ii, tel_id in enumerate(event.dl0.tels_with_data):
        print("\t draw cam {}...".format(tel_id))
        nn = int(ceil(sqrt(ntels)))
        ax = plt.subplot(nn, nn, ii + 1)

        x, y = event.inst.pixel_pos[tel_id]
        geom = geoms[tel_id]
        disp = visualization.CameraDisplay(geom, ax=ax,
                                           title="CT{0}".format(tel_id))
        disp.pixels.set_antialiaseds(False)
        disp.autoupdate = False
        disp.cmap = 'afmhot'
        chan = 0
        signals = event.dl0.tel[tel_id].adc_sums[chan].astype(float)
        signals -= signals.mean()
        disp.image = signals
        disp.set_limits_percent(95)
        disp.add_colorbar()
        disps.append(disp)

    return disps
github cta-observatory / ctapipe / ctapipe / tools / ImPACT_reconstruction.py View on Github external
for tel_num in hillas_nom:
                    fig, axs = plt.subplots(1, 3, figsize=(24, 8), sharey=True, sharex=True)

                    prediction = self.ImPACT.get_prediction(tel_num, ImPACT_shower,
                                                         ImPACT_energy)

                    image_pred[tel_num][mask_dict[tel_num]] = prediction
                    img = np.zeros(image_pred[tel_num].shape)
                    img[mask_dict[tel_num]] = image[tel_num]

                    disp = visualization.CameraDisplay(self.geoms[tel_num], ax=axs[0],
                                                       title="Image")
                    disp.image = img
                    disp.add_colorbar(ax=axs[0])

                    disp_pred = visualization.CameraDisplay(self.geoms[tel_num], ax=axs[1],
                                                            title="Prediction")
                    disp_pred.image = image_pred[tel_num]
                    disp_pred.add_colorbar(ax=axs[1])

                    disp_resid = visualization.CameraDisplay(self.geoms[tel_num], ax=axs[2],
                                                             title="Prediction")
                    disp_resid.image = img - image_pred[tel_num]
                    disp_resid.add_colorbar(ax=axs[2])
                    plt.show()
def main():
github cta-observatory / ctapipe / ctapipe / tools / display_events_single_tel.py View on Github external
for event in tqdm(
            self.event_source,
            desc=f"Tel{self.tel}",
            total=self.event_source.max_events,
            disable=~self.progress,
        ):

            self.log.debug(event.trigger)
            self.log.debug(f"Energy: {event.mc.energy}")

            self.calibrator(event)

            if disp is None:
                geom = self.event_source.subarray.tel[self.tel].camera.geometry
                self.log.info(geom)
                disp = CameraDisplay(geom)
                # disp.enable_pixel_picker()
                disp.add_colorbar()
                if self.display:
                    plt.show(block=False)

            # display the event
            disp.axes.set_title(
                "CT{:03d} ({}), event {:06d}".format(
                    self.tel, geom.camera_name, event.index.event_id
                )
            )

            if self.samples:
                # display time-varying event
                data = event.dl0.tel[self.tel].waveform
                for ii in range(data.shape[1]):
github cta-observatory / ctapipe / examples / plot_camera_frames.py View on Github external
def main():
    fig, axs = plt.subplots(1, 2, constrained_layout=True, figsize=(6, 3))

    model = Gaussian(0 * u.m, 0.1 * u.m, 0.3 * u.m, 0.05 * u.m, 25 * u.deg)
    cam = CameraGeometry.from_name("FlashCam")
    image, *_ = model.generate_image(cam, 2500)

    CameraDisplay(cam, ax=axs[0], image=image)
    CameraDisplay(
        cam.transform_to(EngineeringCameraFrame()), ax=axs[1], image=image,
    )

    axs[0].set_title("CameraFrame")
    axs[1].set_title("EngineeringCameraFrame")

    plt.show()
github cta-observatory / ctapipe / ctapipe / tools / display_integrator.py View on Github external
ax.plot(dl0[pix])
            ax.set_xlabel("Time (ns)")
            ax.set_ylabel("DL0 Samples (ADC)")
            ax.set_title(
                f"(Min Nei) Pixel: {pix}, True: {t_pe[pix]}, "
                f"Measured = {dl1[pix]:.3f}"
            )
            ax.set_ylim(max_ylim)

    # Draw cameras
    nei_camera = np.zeros_like(max_charges, dtype=np.int)
    nei_camera[min_pixel_nei] = 2
    nei_camera[min_pix] = 1
    nei_camera[max_pixel_nei] = 3
    nei_camera[max_pix] = 4
    camera = CameraDisplay(geom, ax=ax_img_nei)
    camera.image = nei_camera
    ax_img_nei.set_title("Neighbour Map")
    ax_img_nei.annotate(
        f"Pixel: {max_pix}",
        xy=(geom.pix_x.value[max_pix], geom.pix_y.value[max_pix]),
        xycoords="data",
        xytext=(0.05, 0.98),
        textcoords="axes fraction",
        arrowprops=dict(facecolor="red", width=2, alpha=0.4),
        horizontalalignment="left",
        verticalalignment="top",
    )
    ax_img_nei.annotate(
        f"Pixel: {min_pix}",
        xy=(geom.pix_x.value[min_pix], geom.pix_y.value[min_pix]),
        xycoords="data",
github cta-observatory / ctapipe / ctapipe / tools / display_summed_images.py View on Github external
def start(self):
        geom = None
        imsum = None
        disp = None

        for event in self.reader:

            self.calibrator(event)

            if geom is None:
                geom = self.reader.subarray.tel[self._base_tel].camera.geometry
                imsum = np.zeros(shape=geom.pix_x.shape, dtype=np.float)
                disp = CameraDisplay(geom, title=geom.camera_name)
                disp.add_colorbar()
                disp.cmap = "viridis"

            if len(event.dl0.tels_with_data) <= 2:
                continue

            imsum[:] = 0
            for telid in event.dl0.tels_with_data:
                imsum += event.dl1.tel[telid].image

            self.log.info(
                "event={} ntels={} energy={}".format(
                    event.index.event_id, len(event.dl0.tels_with_data), event.mc.energy
                )
            )
            disp.image = imsum