Exemplo n.º 1
0
def test_camera_display_single():
    """ test CameraDisplay functionality """
    from ..mpl_camera import CameraDisplay

    geom = CameraGeometry.from_name("LSTCam")
    disp = CameraDisplay(geom)
    image = np.random.normal(size=len(geom.pix_x))
    disp.image = image
    disp.add_colorbar()
    disp.cmap = "nipy_spectral"
    disp.set_limits_minmax(0, 10)
    disp.set_limits_percent(95)
    disp.enable_pixel_picker()
    disp.highlight_pixels([1, 2, 3, 4, 5])
    disp.norm = "log"
    disp.norm = "symlog"
    disp.cmap = "rainbow"

    with pytest.raises(ValueError):
        disp.image = np.ones(10)

    with pytest.raises(ValueError):
        disp.add_colorbar()

    disp.add_ellipse(centroid=(0, 0), width=0.1, length=0.1, angle=0.1)
    disp.clear_overlays()
Exemplo n.º 2
0
def test_pixel_shapes(pix_type):
    """ test CameraDisplay functionality """
    from ..mpl_camera import CameraDisplay

    geom = CameraGeometry.from_name("LSTCam")
    geom.pix_type = pix_type

    disp = CameraDisplay(geom)
    image = np.random.normal(size=len(geom.pix_x))
    disp.image = image
    disp.add_colorbar()
    disp.highlight_pixels([1, 2, 3, 4, 5])
    disp.add_ellipse(centroid=(0, 0), width=0.1, length=0.1, angle=0.1)
Exemplo n.º 3
0
    def start(self):
        # n_events = self.reader.num_events
        source = self.reader.read()
        desc = "Looping through file"
        for event in tqdm(source, desc=desc): #, total=n_events):
            ev = event.count
            self.calibrator.calibrate(event)

            for tel_id in event.r0.tels_with_data:
                geom = self.geometry.get_camera(tel_id)
                nom_geom = self.geometry.get_nominal(tel_id)

                image = event.dl1.tel[tel_id].image[0]

                # Cleaning
                cuts = self.tail_cut[geom.cam_id]
                tc = tailcuts_clean(geom, image, *cuts)
                if not tc.any():
                    # self.log.warning('No image')
                    continue
                # cleaned = np.ma.masked_array(image, mask=~tc)
                cleaned = image * tc

                # Hillas
                try:
                    hillas = hillas_parameters(nom_geom, cleaned)
                except HillasParameterizationError:
                    # self.log.warning('HillasParameterizationError')
                    continue

                # embed()

                fig = plt.figure(figsize=(10, 10))
                ax = fig.add_subplot(111)
                camera = CameraDisplay(nom_geom, ax=ax, image=image, cmap='viridis')
                camera.add_colorbar()
                cen_x = u.Quantity(hillas.cen_x).value
                cen_y = u.Quantity(hillas.cen_y).value
                length = u.Quantity(hillas.length).value
                width = u.Quantity(hillas.width).value

                print(cen_x, cen_y, length, width)

                camera.add_ellipse(centroid=(cen_x, cen_y),
                                   length=length * 2,
                                   width=width * 2,
                                   angle=hillas.psi.rad)

                plt.show()
Exemplo n.º 4
0
def plot_muon_event(ax, geom, image, centroid, ringrad_camcoord, 
                    ringrad_inner, ringrad_outer, event_id):
    """
    

    Paramenters
    ---------
    ax:               `matplotlib.pyplot.axis`
    geom:             CameraGeometry  
    centroid:         `float` centroid of the muon ring
    ringrad_camcoord: `float` ring radius in camera coordinates
    ringrad_inner:    `float` inner ring radius in camera coordinates
    ringrad_outer:    `float` outer ring radius in camera coordinates
    event_id:         `int` id of the analyzed event

    Returns
    ---------
    ax:               `matplotlib.pyplot.axis`
    """

    disp0 = CameraDisplay(geom, ax=ax)
    disp0.image = image
    disp0.cmap = 'viridis'
    disp0.add_colorbar(ax=ax)
    disp0.add_ellipse(centroid, ringrad_camcoord.value,
                  ringrad_camcoord.value, 0., 0., color="red")
    disp0.add_ellipse(centroid, ringrad_inner.value,
                                    ringrad_inner.value, 0., 0.,
                                    color="magenta")
    disp0.add_ellipse(centroid, ringrad_outer.value,
                                    ringrad_outer.value, 0., 0.,
                                    color="magenta")
    ax.set_title(f"Event {event_id}")

    return ax
Exemplo n.º 5
0
def plot_event(fitter,
               image,
               geometry,
               n_sigma=3,
               init=False,
               clean_mask=None,
               show_ellipsis=True,
               save=False,
               ids=''):
    """
        Plot the image of the event in the camera along with the extracted
        ellipsis before or after the fitting procedure.

    Parameters
    ----------
    image:
        Distribution of signal for the event in number of p.e.
    n_sigma: float
        Multiplicative factor on the extracted width and length
        used for the displayed ellipsis
    init: boolean
        If True, use the starting parameters for the ellipsis
        If False, use the ending parameters for the ellipsis
    clean_mask: boolean array
        cleaning selected pixels for the Hillas parameters extraction
    show_ellipsis: boolean
        If True, display the ellipsis
    save: bool
        Save and close the figure if True, return it otherwise
    ids: string
        Can be used to modify the save location
    Returns
    -------
    cam_display: `ctapipe.visualization.CameraDisplay`
        Camera image using matplotlib

    """

    fig, axes = plt.subplots(figsize=(10, 8))
    cam_display = CameraDisplay(geometry, image, ax=axes)
    cam_display.add_colorbar(ax=axes)
    if init:
        params = fitter.start_parameters
    else:
        params = fitter.end_parameters

    length = n_sigma * params['length']
    psi = params['psi']
    if show_ellipsis:
        cam_display.add_ellipse(centroid=(params['x_cm'], params['y_cm']),
                                width=n_sigma * params['wl'] *
                                params['length'],
                                length=length,
                                angle=psi,
                                linewidth=6,
                                color='r',
                                linestyle='--',
                                label=r'{} $\sigma$ contour'.format(n_sigma))
        cam_display.axes.legend(loc='best')

    if init and clean_mask is not None:
        cam_display.highlight_pixels(clean_mask, color='r')

    if save:
        cam_display.axes.get_figure().savefig('event/' + ids + '_init' +
                                              str(init) + '.png')
        plt.close()
    return None if save else cam_display