Example #1
0
        def update(frame):

            centroid = np.random.uniform(-0.5, 0.5, size=2)
            width = np.random.uniform(0, 0.01)
            length = np.random.uniform(0, 0.03) + width
            angle = np.random.uniform(0, 360)
            intens = np.random.exponential(2) * 50
            model = mock.generate_2d_shower_model(centroid=centroid,
                                                  width=width,
                                                  length=length,
                                                  psi=angle * u.deg)
            image, sig, bg = mock.make_mock_shower_image(geom,
                                                         model.pdf,
                                                         intensity=intens,
                                                         nsb_level_pe=5000)

            # alternate between cleaned and raw images
            if self._counter > 20:
                plt.suptitle("Image Cleaning ON")
                cleanmask = reco.cleaning.tailcuts_clean(geom,
                                                         image,
                                                         pedvars=80)
                for ii in range(3):
                    reco.cleaning.dilate(geom, cleanmask)
                image[cleanmask == 0] = 0  # zero noise pixels
            if self._counter >= 40:
                plt.suptitle("Image Cleaning OFF")
                self._counter = 0

            disp.image = image
            disp.set_limits_percent(100)
            self._counter += 1
def draw_several_cams(geom):

    ncams = 4
    cmaps = [plt.cm.jet, plt.cm.afmhot, plt.cm.terrain, plt.cm.autumn]
    fig, ax = plt.subplots(1, ncams, figsize=(15, 4), sharey=True, sharex=True)

    for ii in range(ncams):
        disp = visualization.CameraDisplay(geom, axes=ax[ii],
                                           title="CT{}".format(ii + 1))

        model = mock.generate_2d_shower_model(centroid=(0.2 - ii * 0.1,
                                                        -ii * 0.05),
                                              width=0.005 + 0.001 * ii,
                                              length=0.1 + 0.05 * ii,
                                              psi=np.radians(ii * 20))

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

        clean = image.copy()
        clean[image <= 3.0 * image.mean()] = 0.0
        hillas = hillas_parameters(geom.pix_x.value, geom.pix_y.value, clean)

        disp.set_cmap(cmaps[ii])
        disp.set_image(image)
        disp.overlay_moments(hillas, linewidth=3, color='blue')
def draw_several_cams(geom, ncams=4):

    cmaps = ['jet', 'afmhot', 'terrain', 'autumn']
    fig, axs = plt.subplots(1, ncams, figsize=(15, 4), sharey=True, sharex=True)

    for ii in range(ncams):
        disp = visualization.CameraDisplay(
            geom,
            ax=axs[ii],
            title="CT{}".format(ii + 1),
        )
        disp.cmap = cmaps[ii]

        model = mock.generate_2d_shower_model(
            centroid=(0.2 - ii * 0.1, -ii * 0.05),
            width=0.005 + 0.001 * ii,
            length=0.1 + 0.05 * ii,
            psi=ii * 20 * u.deg,
        )

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

        clean = image.copy()
        clean[image <= 3.0 * image.mean()] = 0.0
        hillas = hillas_parameters(geom.pix_x, geom.pix_y, clean)

        disp.image = image
        disp.add_colorbar(ax=axs[ii])
        disp.set_limits_percent(95)
        disp.overlay_moments(hillas, linewidth=3, color='blue')
Example #4
0
    def update(frame):
        global _counter
        centroid = np.random.uniform(-0.5, 0.5, size=2)
        width = np.random.uniform(0, 0.01)
        length = np.random.uniform(0, 0.03) + width
        angle = np.random.uniform(0, 360)
        intens = np.random.exponential(2) * 50
        model = mock.generate_2d_shower_model(centroid=centroid,
                                              width=width,
                                              length=length,
                                              psi=angle * u.deg)
        image, sig, bg = mock.make_mock_shower_image(geom, model.pdf,
                                                     intensity=intens,
                                                     nsb_level_pe=5000)

        # alternate between cleaned and raw images
        if _counter > 20:
            plt.suptitle("Image Cleaning ON")
            cleanmask = reco.cleaning.tailcuts_clean(geom, image, pedvars=80)
            for ii in range(3):
                reco.cleaning.dilate(geom, cleanmask)
            image[cleanmask == 0] = 0  # zero noise pixels
        if _counter >= 40:
            plt.suptitle("Image Cleaning OFF")
            _counter = 0

        disp.image = image
        disp.set_limits_percent(100)
        _counter += 1
Example #5
0
def draw_several_cams(geom):

    ncams = 4
    cmaps = [plt.cm.jet, plt.cm.afmhot, plt.cm.terrain, plt.cm.autumn]
    fig, ax = plt.subplots(1, ncams, figsize=(15, 4), sharey=True, sharex=True)

    for ii in range(ncams):
        disp = visualization.CameraDisplay(geom,
                                           ax=ax[ii],
                                           title="CT{}".format(ii + 1))
        disp.cmap = cmaps[ii]

        model = mock.generate_2d_shower_model(centroid=(0.2 - ii * 0.1,
                                                        -ii * 0.05),
                                              width=0.005 + 0.001 * ii,
                                              length=0.1 + 0.05 * ii,
                                              psi=ii * 20 * u.deg)

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

        clean = image.copy()
        clean[image <= 3.0 * image.mean()] = 0.0
        hillas = hillas_parameters(geom.pix_x.value, geom.pix_y.value, clean)

        disp.image = image
        disp.set_limits_percent(95)
        disp.overlay_moments(hillas, linewidth=3, color='blue')
Example #6
0
 def update(frame):
     centroid = np.random.uniform(-0.5, 0.5, size=2)
     width = np.random.uniform(0, 0.01)
     length = np.random.uniform(0, 0.03) + width
     angle = np.random.uniform(0, 360)
     intens = np.random.exponential(2) * 50
     model = mock.generate_2d_shower_model(centroid=centroid, width=width, length=length, psi=np.radians(angle))
     image, sig, bg = mock.make_mock_shower_image(geom, model.pdf, intensity=intens, nsb_level_pe=5000)
     image /= image.max()
     disp.set_image(image)
Example #7
0
 def update(frame):
     centroid = np.random.uniform(-0.5, 0.5, size=2)
     width = np.random.uniform(0, 0.01)
     length = np.random.uniform(0, 0.03) + width
     angle = np.random.uniform(0, 360)
     intens = np.random.exponential(2) * 50
     model = mock.generate_2d_shower_model(centroid=centroid,
                                           width=width,
                                           length=length,
                                           psi=angle * u.deg)
     image, sig, bg = mock.make_mock_shower_image(geom,
                                                  model.pdf,
                                                  intensity=intens,
                                                  nsb_level_pe=5000)
     image /= image.max()
     disp.image = image
Example #8
0
from ctapipe.reco import mock

if __name__ == '__main__':

    plt.style.use('ggplot')

    fig = plt.figure(figsize=(12, 8))
    ax = fig.add_subplot(1, 1, 1)

    geom = CameraGeometry.from_name('hess', 1)
    disp = CameraDisplay(geom, ax=ax)
    disp.add_colorbar()

    model = mock.generate_2d_shower_model(centroid=(0.05, 0.0),
                                          width=0.005,
                                          length=0.025,
                                          psi='35d')

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

    disp.image = image

    mask = disp.image > 15
    disp.highlight_pixels(mask, linewidth=3)

    plt.show()
Example #9
0
def mock_event_source(
        geoms,
        events=100,
        single_tel=False,
        n_channels=1,
        n_samples=25,
        p_trigger=0.3,
        ):
    """
    An event source that produces array
    Parameters
    ----------
    geoms : list of CameraGeometry instances
        Geometries for the telescopes to simulate
    events : int, default: 100
        maximum number of events to create
    n_channels : int
        how many channels per telescope
    n_samples : int
        how many adc samples per pixel
    p_trigger : float
        mean trigger probability for the telescopes
    """
    n_telescopes = len(geoms)
    container = Container("mock_container")
    container.meta.add_item('mock__max_events', events)
    container.meta.add_item('pixel_pos', dict())
    container.add_item("dl0", RawData())
    container.add_item("count")
    tel_ids = np.arange(n_telescopes)

    for event_id in range(events):

        n_triggered = np.random.poisson(n_telescopes * 0.3)
        if n_triggered > n_telescopes:
            n_triggered = n_telescopes

        triggered_tels = np.random.choice(tel_ids, n_triggered, replace=False)

        container.dl0.event_id = event_id
        container.dl0.tels_with_data = triggered_tels
        container.count = event_id

        # handle single-telescope case (ignore others:
        if single_tel:
            if single_tel not in container.dl0.tels_with_data:
                continue
            container.dl0.tels_with_data = [single_tel, ]

        container.dl0.tel = dict()  # clear the previous telescopes
        t = np.arange(n_samples)

        for tel_id in container.dl0.tels_with_data:
            geom = geoms[tel_id]

            # fill pixel position dictionary, if not already done:
            if tel_id not in container.meta.pixel_pos:
                container.meta.pixel_pos[tel_id] = (
                    geom.pix_x.value,
                    geom.pix_y.value,
                )

            centroid = np.random.uniform(geom.pix_x.min(), geom.pix_y.max(), 2)
            length = np.random.uniform(0.02, 0.2)
            width = np.random.uniform(0.01, length)
            psi = np.random.randint(0, 360)
            intensity = np.random.poisson(int(10000 * width * length))
            model = mock.generate_2d_shower_model(
                centroid,
                width,
                length,
                '{}d'.format(psi)
            )
            image, _, _ = mock.make_mock_shower_image(
                geom,
                model.pdf,
                intensity,
            )

            container.dl0.tel[tel_id] = RawCameraData(tel_id)
            container.dl0.tel[tel_id].num_channels = n_channels
            n_pix = len(geom.pix_id)
            samples = np.empty((n_pix, n_samples))
            means = np.random.normal(15, 1, (n_pix, 1))
            stds = np.random.uniform(3, 6, (n_pix, 1))
            samples = image[:, np.newaxis] * norm.pdf(t, means, stds)

            for chan in range(n_channels):
                container.dl0.tel[tel_id].adc_samples[chan] = samples
                container.dl0.tel[tel_id].adc_sums[chan] = image

        yield container
Example #10
0
if __name__ == '__main__':

    # Load the camera
    geom = io.CameraGeometry.from_name("hess", 1)
    disp = visualization.CameraDisplay(geom)
    disp.set_limits_minmax(0, 300)
    disp.add_colorbar()

    # 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
    # Prepare the camera geometry
    geom = io.CameraGeometry.from_name('hess', 1)
    disp = visualization.CameraDisplay(geom)
    disp.set_limits_minmax(0, 350)
    disp.add_colorbar()

    # make a mock shower model
    model = mock.generate_2d_shower_model(centroid=(0.2, 0.2),
                                          width=0.01,
                                          length=0.1,
                                          psi='45d')

    # generate mock image in camera for this shower model.
    image, signal, noise = mock.make_mock_shower_image(geom,
                                                       model.pdf,
                                                       intensity=50,
                                                       nsb_level_pe=100)

    #Image cleaning
    clean_mask = tailcuts_clean(
        geom, image, 1, 10,
        5)  #pedvars = 1 and core and boundary threshold in pe
    image[~clean_mask] = 0

    #Pixel values in the camera
    pix_x = geom.pix_x.value
    pix_y = geom.pix_y.value

    # Hillas parameters
    hillas1, hillas2 = hillas_parameters(pix_x, pix_y, image)
    print(hillas1, hillas2)