def show_image(simtel_file_path, output_file_path, tel_num, event_id, channel=0, quiet=False):

    # GET EVENT #############################################################

    # hessio_event_source returns a Python generator that streams data from an
    # EventIO/HESSIO MC data file (e.g. a standard CTA data file).
    # This generator contains ctapipe.core.Container instances ("event").
    # 
    # Parameters:
    # - max_events: maximum number of events to read
    # - allowed_tels: select only a subset of telescope, if None, all are read.
    source = hessio_event_source(simtel_file_path, allowed_tels=[tel_num])

    event = None

    for ev in source:
        if int(ev.dl0.event_id) == event_id:
            event = ev
            break

    if event is None:
        raise Exception("Error: event '{}' not found for telescope '{}'.".format(event_id, tel_num))

    # INIT PLOT #############################################################

    x, y = event.meta.pixel_pos[tel_num]
    foclen = event.meta.optical_foclen[tel_num]
    geom = ctapipe.io.CameraGeometry.guess(x, y, foclen)

    disp = ctapipe.visualization.CameraDisplay(geom, title='CT%d' % tel_num)
    disp.enable_pixel_picker()
    disp.add_colorbar()

    disp.axes.set_title('Telescope {:03d}, Event {:05d}'.format(tel_num, event_id))

    # GET PHOTOELECTRON IMAGE (CLEAN IMAGE) #################################

    disp.image = event.mc.tel[tel_num].photo_electrons

    # COMPUTE hILLAS PARAMETERS #############################################

    image = disp.image.copy()
    #hillas = hillas_parameters(geom.pix_x.value, geom.pix_y.value, image)
    hillas = hillas_parameters(geom.pix_x, geom.pix_y, image)
    print("Hillas parameters:", hillas)

    # PLOT ##################################################################

    #disp.set_limits_minmax(0, 9000)
    disp.set_limits_percent(70)        # TODO

    # Plot Hillas parameters
    disp.overlay_moments(hillas, linewidth=3, color='yellow')

    plt.savefig(output_file_path, bbox_inches='tight')

    if not quiet:
        plt.show()
示例#2
0
            disp.image = im

            if args.hillas:
                clean_mask = reco.cleaning.tailcuts_clean(geom,im,1,picture_thresh=10,boundary_thresh=5)
                camera_coord = CameraFrame(x=x,y=y,z=np.zeros(x.shape)*u.m)

                nom_coord = camera_coord.transform_to(NominalFrame(array_direction=[70*u.deg,0*u.deg],
                                                           pointing_direction=[70*u.deg,0*u.deg],
                                                           focal_length=tel['TelescopeTable_VersionFeb2016'][tel['TelescopeTable_VersionFeb2016']['TelID']==args.tel]['FL'][0]*u.m))

                image = np.asanyarray(im * clean_mask, dtype=np.float64)

                nom_x = nom_coord.x
                nom_y = nom_coord.y

                hillas = reco.hillas_parameters(x,y,im * clean_mask)
                hillas_nom = reco.hillas_parameters(nom_x,nom_y,im * clean_mask)

                print (hillas)
                print (hillas_nom)

                disp.image = im * clean_mask
                disp.overlay_moments(hillas, color='seagreen', linewidth=3)
                disp.set_limits_percent(70)

            plt.pause(1.0)
            if args.write:
                plt.savefig('CT{:03d}_EV{:010d}.png'
                            .format(args.tel, event.dl0.event_id))

    print("FINISHED READING DATA FILE")
示例#3
0
    # Create a fake camera image to display:
    model = mock.generate_2d_shower_model(centroid=(0.2, 0.0),
                                          width=0.01,
                                          length=0.1,
                                          psi='35d')

    image, sig, bg = mock.make_mock_shower_image(geom, model.pdf,
                                                 intensity=50,
                                                 nsb_level_pe=1000)

    # Apply really stupid image cleaning (single threshold):
    clean = image.copy()
    clean[image <= 3.0 * image.mean()] = 0.0

    # Calculate image parameters
    hillas = hillas_parameters(geom.pix_x, geom.pix_y, clean)
    print(hillas)

    # Show the camera image and overlay Hillas ellipse
    disp.image = image
    disp.overlay_moments(hillas, color='seagreen', linewidth=3)

    # Draw the neighbors of pixel 100 in red, and the neighbor-neighbors in
    # green
    for ii in geom.neighbors[130]:
        draw_neighbors(geom, ii, color='green')

    draw_neighbors(geom, 130, color='cyan', lw=2)

    plt.show()
示例#4
0
    model = mock.generate_2d_shower_model(centroid=(0.2, 0.0),
                                          width=0.01,
                                          length=0.1,
                                          psi='35d')

    image, sig, bg = mock.make_mock_shower_image(geom,
                                                 model.pdf,
                                                 intensity=50,
                                                 nsb_level_pe=1000)

    # apply really stupid image cleaning (single threshold):
    clean = image.copy()
    clean[image <= 3.0 * image.mean()] = 0.0

    # calculate image parameters
    hillas = hillas_parameters(geom.pix_x.value, geom.pix_y.value, clean)
    print(hillas)

    # show the camera image and overlay Hillas ellipse
    disp.image = image
    disp.overlay_moments(hillas, color='seagreen', linewidth=3)

    # draw the neighbors of pixel 100 in red, and the
    # neighbor-neighbors in green
    for ii in geom.neighbors[130]:
        draw_neighbors(geom, ii, color='green')

    draw_neighbors(geom, 130, color='cyan', lw=2)

    plt.show()
示例#5
0
    # create a fake camera image to display:
    model = mock.generate_2d_shower_model(centroid=(0.2, 0.0),
                                          width=0.01,
                                          length=0.1,
                                          psi='35d')

    image, sig, bg = mock.make_mock_shower_image(geom, model.pdf,
                                                 intensity=50,
                                                 nsb_level_pe=1000)

    # apply really stupid image cleaning (single threshold):
    clean = image.copy()
    clean[image <= 3.0 * image.mean()] = 0.0

    # calculate image parameters
    hillas = hillas_parameters(geom.pix_x.value, geom.pix_y.value, clean)
    print(hillas)

    # show the camera image and overlay Hillas ellipse
    disp.image = image
    disp.overlay_moments(hillas, color='seagreen', linewidth=3)

    # draw the neighbors of pixel 100 in red, and the
    # neighbor-neighbors in green
    for ii in geom.neighbors[130]:
        draw_neighbors(geom, ii, color='green')

    draw_neighbors(geom, 130, color='cyan', lw=2)

    plt.show()
示例#6
0
    model = mock.generate_2d_shower_model(centroid=(0.2, 0.0),
                                          width=0.01,
                                          length=0.1,
                                          psi='35d')

    image, sig, bg = mock.make_mock_shower_image(geom,
                                                 model.pdf,
                                                 intensity=50,
                                                 nsb_level_pe=1000)

    # Apply really stupid image cleaning (single threshold):
    clean = image.copy()
    clean[image <= 3.0 * image.mean()] = 0.0

    # Calculate image parameters
    hillas = hillas_parameters(geom.pix_x, geom.pix_y, clean)
    print(hillas)

    # Show the camera image and overlay Hillas ellipse
    disp.image = image
    disp.overlay_moments(hillas, color='seagreen', linewidth=3)

    # Draw the neighbors of pixel 100 in red, and the neighbor-neighbors in
    # green
    for ii in geom.neighbors[130]:
        draw_neighbors(geom, ii, color='green')

    draw_neighbors(geom, 130, color='cyan', lw=2)

    plt.show()