コード例 #1
0
    def background_contour(self, x, y, background, **kwargs):
        """
        Draw image contours in background of the display, useful when likelihood fitting

        Parameters
        ----------
        x: ndarray
            array of image X coordinates
        y: ndarray
            array of image Y coordinates
        background: ndarray
            Array of image to use in background
        kwargs: key=value
            any style keywords to pass to matplotlib

        Returns
        -------
        None
        """

        self.axes.contour(x, y, background, **kwargs)

        # Annoyingly we need to redraw everything
        self.array = ArrayDisplay(telx=np.asarray(self.cen_x),
                                  tely=np.asarray(self.cen_y),
                                  tel_type=np.ones(len(self.cen_y)),
                                  axes=self.axes)
コード例 #2
0
ファイル: array.py プロジェクト: smicanov/ctapipe
    def __init__(self, hillas_parameters, draw_axes=False, ax=None, **kwargs):
        """

        Parameters
        ----------
        instrument: dictionary
            intrument containers for this event
        telescopes: list
            List of telescopes included
        system: Coordinate system
            Coordinate system to transform coordinates into
        """
        self.axes = ax if ax is not None else plt.gca()

        self.cen_x = [i.cen_x.to(u.deg).value for i in hillas_parameters.values()]
        self.cen_y = [i.cen_y.to(u.deg).value for i in hillas_parameters.values()]

        self.centre = (0, 0)
        self.array = ArrayDisplay(telx=np.asarray(self.cen_x),
                                  tely=np.asarray(self.cen_y),
                                  tel_type=np.ones(len(self.cen_y)),
                                  axes=self.axes)

        self.hillas = hillas_parameters
        scale_fac = 57.3 * 2

        self.array.overlay_moments(hillas_parameters, (self.cen_x, self.cen_y), scale_fac,
                                   cmap="Greys", alpha=0.5, **kwargs)

        if draw_axes:
            self.array.overlay_axis(hillas_parameters, (self.cen_x, self.cen_y))
コード例 #3
0
ファイル: subarray.py プロジェクト: LukasBeiske/ctapipe
    def peek(self):
        """
        Draw a quick matplotlib plot of the array
        """
        from ctapipe.coordinates.ground_frames import EastingNorthingFrame
        from ctapipe.visualization import ArrayDisplay
        from matplotlib import pyplot as plt

        plt.figure(figsize=(8, 8))
        ad = ArrayDisplay(subarray=self, frame=EastingNorthingFrame(), tel_scale=0.75)
        ad.add_labels()
        plt.title(self.name)
        plt.tight_layout()
コード例 #4
0
ファイル: array.py プロジェクト: smicanov/ctapipe
    def __init__(self, instrument, telescopes=None, system=None, ax=None):
        """

        Parameters
        ----------
        instrument: dictionary
            intrument containers for this event
        telescopes: list
            List of telescopes included
        system: Coordinate system
            Coordinate system to transform coordinates into
        """

        self.instrument = instrument
        self.system = system
        if telescopes is None:
            self.telescopes = instrument.telescope_ids
        else:
            self.telescopes = telescopes
        type_dict = {28.0: 1, 16.0: 2,
                     2.1500000953674316: 3,
                     2.2829999923706055: 4,
                     5.599999904632568: 5}

        tel_x = [self.instrument.tel_pos[i][0].to(u.m).value for i in self.telescopes]
        tel_y = [self.instrument.tel_pos[i][1].to(u.m).value for i in self.telescopes]
        tel_z = [self.instrument.tel_pos[i][2].to(u.m).value for i in self.telescopes]

        self.axes = ax if ax is not None else plt.gca()

        tel_type = np.asarray([type_dict[self.instrument.optical_foclen[i].
                                         to(u.m).value] for i in self.telescopes])
        self.tel_type = tel_type

        if system is not None:
            ground = GroundFrame(x=np.asarray(tel_x) * u.m, y=np.asarray(tel_y)
                                 * u.m, z=np.asarray(tel_z) * u.m)
            new_sys = ground.transform_to(system)
            self.tel_x = new_sys.x
            self.tel_y = new_sys.y
        else:
            self.tel_x = tel_x * u.m
            self.tel_y = tel_y * u.m

        self.centre = (0, 0)
        self.array = ArrayDisplay(telx=np.asarray(self.tel_x),
                                  tely=np.asarray(self.tel_y), tel_type=tel_type,
                                  axes=self.axes)

        self.hillas = None
コード例 #5
0
def plot_telescope_layout(tel_layout_file_name):
    layout_file = "/Users/alicedonini/PycharmProjects/Pointing_tool/layout-3AL4-BN15-MST.txt"
    grd_coords = pd.read_csv(layout_file,
                             header=None,
                             delimiter="  ",
                             names=["x", "y", "z"],
                             engine='python')

    # convert to m
    grd_coords = grd_coords / 100

    # create a dictionary with the tel position on the ground by tel_id and the tel description
    tel_descr = {}
    G_coords = {}
    for tel_id, coord in enumerate(grd_coords.values, 1):
        G_coords[tel_id] = coord * u.m
        tel_descr[tel_id] = TelescopeDescription.from_name(
            optics_name='MST', camera_name='NectarCam')

    # create the subarray
    sub = SubarrayDescription(name="Baseline only MST",
                              tel_positions=G_coords,
                              tel_descriptions=tel_descr)
    #sub.info()
    #sub.to_table(kind='optics')

    # display the array
    plt.figure(num=None, figsize=(7, 7), facecolor='w', edgecolor='k')
    disp = ArrayDisplay(sub, tel_scale=3.0)

    return sub
コード例 #6
0
ファイル: array.py プロジェクト: epuesche/ctapipe
    def background_contour(self, x, y, background, **kwargs):
        """
        Draw image contours in background of the display, useful when likelihood fitting

        Parameters
        ----------
        x: ndarray
            array of image X coordinates
        y: ndarray
            array of image Y coordinates
        background: ndarray
            Array of image to use in background
        kwargs: key=value
            any style keywords to pass to matplotlib

        Returns
        -------
        None
        """

        self.axes.contour(x, y, background, **kwargs)

        # Annoyingly we need to redraw everything
        self.array = ArrayDisplay(telx=np.asarray(self.tel_x),
                                  tely=np.asarray(self.tel_y),
                                  tel_type=self.tel_type)

        if self.hillas is not None:
            self.overlay_hillas(self.hillas)
コード例 #7
0
ファイル: array.py プロジェクト: epuesche/ctapipe
    def __init__(self, hillas_parameters, draw_axes=False, ax=None, **kwargs):
        """

        Parameters
        ----------
        instrument: dictionary
            intrument containers for this event
        telescopes: list
            List of telescopes included
        system: Coordinate system
            Coordinate system to transform coordinates into
        """
        self.axes = ax if ax is not None else plt.gca()

        self.cen_x = [i.cen_x.to(u.deg).value for i in hillas_parameters.values()]
        self.cen_y = [i.cen_y.to(u.deg).value for i in hillas_parameters.values()]

        self.centre = (0,0)
        self.array = ArrayDisplay(telx=np.asarray(self.cen_x), tely=np.asarray(self.cen_y),
                                  tel_type=np.ones(len(self.cen_y)), axes=self.axes)

        self.hillas = hillas_parameters
        scale_fac = 57.3 * 2

        self.array.overlay_moments(hillas_parameters, (self.cen_x, self.cen_y), scale_fac,
                                   cmap="Greys", alpha=0.5, **kwargs)

        if draw_axes:
            self.array.overlay_axis(hillas_parameters, (self.cen_x, self.cen_y))
 def plotSubArray(self):
     ad = ArrayDisplay(ld.telescope_posX, ld.telescope_posY, ld.mirror_area)
     for i in range(len(ld.telescope_id)):
         name = "CT%i" % ld.telescope_id[i]
         plt.text(ld.telescope_posX[i],
                  ld.telescope_posY[i],
                  name,
                  fontsize=8)
     ad.axes.set_xlim(-1000, 1000)
     ad.axes.set_ylim(-1000, 1000)
     plt.show()
コード例 #9
0
ファイル: array.py プロジェクト: epuesche/ctapipe
    def __init__(self, instrument, telescopes=None, system=None, ax=None):
        """

        Parameters
        ----------
        instrument: dictionary
            intrument containers for this event
        telescopes: list
            List of telescopes included
        system: Coordinate system
            Coordinate system to transform coordinates into
        """

        self.instrument = instrument
        self.system = system
        if telescopes is None:
            self.telescopes = instrument.telescope_ids
        else:
            self.telescopes = telescopes
        type_dict = {28.0: 1, 16.0: 2,
                     2.1500000953674316: 3,
                     2.2829999923706055: 4,
                     5.599999904632568: 5}

        tel_x = [self.instrument.tel_pos[i][0].to(u.m).value for i in self.telescopes]
        tel_y = [self.instrument.tel_pos[i][1].to(u.m).value for i in self.telescopes]
        tel_z = [self.instrument.tel_pos[i][2].to(u.m).value for i in self.telescopes]

        self.axes = ax if ax is not None else plt.gca()

        tel_type = np.asarray([type_dict[self.instrument.optical_foclen[i].to(u.m).value] for i in self.telescopes])
        self.tel_type = tel_type

        if system is not None:
            ground = GroundFrame(x=np.asarray(tel_x)*u.m, y=np.asarray(tel_y)*u.m, z=np.asarray(tel_z)*u.m)
            new_sys = ground.transform_to(system)
            self.tel_x = new_sys.x
            self.tel_y = new_sys.y
        else:
            self.tel_x = tel_x*u.m
            self.tel_y = tel_y*u.m

        self.centre = (0,0)
        self.array = ArrayDisplay(telx=np.asarray(self.tel_x), tely=np.asarray(self.tel_y), tel_type=tel_type,
                                  axes=self.axes)

        self.hillas = None
コード例 #10
0
    source = EventSource(filename)

    # pointing direction of the telescopes
    point_azimuth = {}
    point_altitude = {}

    subarray = source.subarray
    calib = CameraCalibrator(subarray=subarray)
    off_angles = []
    first_event = True
    markers = None

    for event in source:
        if first_event:
            fig, ax = plt.subplots(1, 1, figsize=(10, 8))
            array_disp = ArrayDisplay(subarray, axes=ax, tel_scale=1.0)
            array_disp.telescopes.set_linewidth(3)
            array_disp.add_labels()
            first_event = False
            hit_pattern = np.zeros(subarray.num_tels)

        if len(event.r0.tel.keys()) < 3:
            continue

        # calibrating the event
        calib(event)
        hillas_dict = {}
        timing_dict = {}

        # plot the core position, which must be transformed from the tilted
        # system to the system that the ArrayDisplay is in (default
コード例 #11
0
class ArrayPlotter:
    """
    Simple plotter for drawing array level items
    """
    def __init__(self, instrument, telescopes=None, system=None, ax=None):
        """

        Parameters
        ----------
        instrument: dictionary
            intrument containers for this event
        telescopes: list
            List of telescopes included
        system: Coordinate system
            Coordinate system to transform coordinates into
        """

        self.instrument = instrument
        self.system = system
        if telescopes is None:
            self.telescopes = instrument.telescope_ids
        else:
            self.telescopes = telescopes
        type_dict = {
            28.0: 1,
            16.0: 2,
            2.1500000953674316: 3,
            2.2829999923706055: 4,
            5.599999904632568: 5
        }

        tel_x = [
            self.instrument.tel_pos[i][0].to(u.m).value
            for i in self.telescopes
        ]
        tel_y = [
            self.instrument.tel_pos[i][1].to(u.m).value
            for i in self.telescopes
        ]
        tel_z = [
            self.instrument.tel_pos[i][2].to(u.m).value
            for i in self.telescopes
        ]

        self.axes = ax if ax is not None else plt.gca()

        tel_type = np.asarray([
            type_dict[self.instrument.optical_foclen[i].to(u.m).value]
            for i in self.telescopes
        ])
        self.tel_type = tel_type

        if system is not None:
            ground = GroundFrame(x=np.asarray(tel_x) * u.m,
                                 y=np.asarray(tel_y) * u.m,
                                 z=np.asarray(tel_z) * u.m)
            new_sys = ground.transform_to(system)
            self.tel_x = new_sys.x
            self.tel_y = new_sys.y
        else:
            self.tel_x = tel_x * u.m
            self.tel_y = tel_y * u.m

        self.centre = (0, 0)
        self.array = ArrayDisplay(telx=np.asarray(self.tel_x),
                                  tely=np.asarray(self.tel_y),
                                  tel_type=tel_type,
                                  axes=self.axes)

        self.hillas = None

    def overlay_hillas(self,
                       hillas,
                       scale_fac=10000,
                       draw_axes=False,
                       **kwargs):
        """
        Overlay hillas parameters on top of the array map

        Parameters
        ----------
        hillas: dictionary
            Hillas moments objects to overlay
        scale_fac: float
            Scaling factor to array to hillas width and length when drawing
        kwargs: key=value
            any style keywords to pass to matplotlib

        Returns
        -------
        None
        """
        tel_x = [self.instrument.tel_pos[i][0].to(u.m).value for i in hillas]
        tel_y = [self.instrument.tel_pos[i][1].to(u.m).value for i in hillas]
        tel_z = [self.instrument.tel_pos[i][2].to(u.m).value for i in hillas]
        if self.system is not None:
            ground = GroundFrame(x=np.asarray(tel_x) * u.m,
                                 y=np.asarray(tel_y) * u.m,
                                 z=np.asarray(tel_z) * u.m)
            new_sys = ground.transform_to(self.system)
            self.array.overlay_moments(hillas, (new_sys.x, new_sys.y),
                                       scale_fac,
                                       cmap="Greys",
                                       alpha=0.5,
                                       **kwargs)
            if draw_axes:
                self.array.overlay_axis(hillas, (new_sys.x, new_sys.y))
        else:
            self.array.overlay_moments(hillas, (tel_x, tel_y),
                                       scale_fac,
                                       alpha=0.5,
                                       cmap="Greys",
                                       **kwargs)

        self.hillas = hillas

    def background_contour(self, x, y, background, **kwargs):
        """
        Draw image contours in background of the display, useful when likelihood fitting

        Parameters
        ----------
        x: ndarray
            array of image X coordinates
        y: ndarray
            array of image Y coordinates
        background: ndarray
            Array of image to use in background
        kwargs: key=value
            any style keywords to pass to matplotlib

        Returns
        -------
        None
        """

        self.axes.contour(x, y, background, **kwargs)

        # Annoyingly we need to redraw everything
        self.array = ArrayDisplay(telx=np.asarray(self.tel_x),
                                  tely=np.asarray(self.tel_y),
                                  tel_type=self.tel_type)

        if self.hillas is not None:
            self.overlay_hillas(self.hillas)

    def draw_array(self, range=((-2000, 2000), (-2000, 2000)), annotate=False):
        """
        Draw the array plotter (including any overlayed elements)

        Parameters
        ----------
        range: tuple
            XY range in which to draw plotter

        Returns
        -------
        None
        """

        self.array.axes.set_xlim(
            (self.centre[0] + range[0][0], range[0][1] + self.centre[0]))
        self.array.axes.set_ylim(
            (self.centre[1] + range[1][0], range[1][1] + self.centre[1]))

        if annotate:
            for txt, x, y in zip(self.telescopes, self.tel_x.value,
                                 self.tel_y.value):
                self.axes.annotate(txt, (x, y))

        #self.axes.tight_layout()
        #self.axes.show()

    def draw_position(self, core_x, core_y, use_centre=False, **kwargs):
        """
        Draw a marker at a position in the array plotter (for marking reconstructed
        positions etc)

        Parameters
        ----------
        core_x: float
            X position of point
        core_y: float
            Y position of point
        use_centre: bool
            Centre the plotter on this position
        kwargs: key=value
            any style keywords to pass to matplotlib

        Returns
        -------
        None
        """
        ground = GroundFrame(x=np.asarray(core_x) * u.m,
                             y=np.asarray(core_y) * u.m,
                             z=np.asarray(0) * u.m)

        if self.system is not None:
            new_sys = ground.transform_to(self.system)
        else:
            new_sys = ground

        self.array.add_polygon(centroid=(new_sys.x.value, new_sys.y.value),
                               radius=10,
                               nsides=3,
                               **kwargs)
        if use_centre:
            self.centre = (new_sys.x.value, new_sys.y.value)
コード例 #12
0
ファイル: array_animation.py プロジェクト: betsman/ctapipe
import numpy as np
from astropy.table import Table
from ctapipe.utils import datasets
from ctapipe.visualization import ArrayDisplay
from matplotlib import pyplot as plt


if __name__ == '__main__':

    plt.style.use("ggplot")
    plt.figure(figsize=(10, 8))

    arrayfile = datasets.get_path("PROD2_telconfig.fits.gz")
    tels = Table.read(arrayfile, hdu="TELESCOPE_LEVEL0")

    adisp = ArrayDisplay(tels['TelX'], tels['TelY'], tels['MirrorArea'] * 2,
                         title='PROD2 telescopes', autoupdate=True)
    plt.tight_layout()

    values = np.zeros(len(tels))

    # do a small animation to show various trigger patterns:

    for ii in range(20):

        # generate a random trigger pattern and integrated intensity:
        ntrig = np.random.poisson(10)
        trigmask = np.random.random_integers(len(tels) - 1, size=ntrig)
        values[:] = 0
        values[trigmask] = np.random.uniform(0, 100, size=ntrig)

        # update the display:
コード例 #13
0
class NominalPlotter:
    """
    Simple plotter for drawing camera level items in the nominal system
    """
    def __init__(self, hillas_parameters, draw_axes=False, ax=None, **kwargs):
        """

        Parameters
        ----------
        instrument: dictionary
            intrument containers for this event
        telescopes: list
            List of telescopes included
        system: Coordinate system
            Coordinate system to transform coordinates into
        """
        self.axes = ax if ax is not None else plt.gca()

        self.cen_x = [
            i.cen_x.to(u.deg).value for i in hillas_parameters.values()
        ]
        self.cen_y = [
            i.cen_y.to(u.deg).value for i in hillas_parameters.values()
        ]

        self.centre = (0, 0)
        self.array = ArrayDisplay(telx=np.asarray(self.cen_x),
                                  tely=np.asarray(self.cen_y),
                                  tel_type=np.ones(len(self.cen_y)),
                                  axes=self.axes)

        self.hillas = hillas_parameters
        scale_fac = 57.3 * 2

        self.array.overlay_moments(hillas_parameters, (self.cen_x, self.cen_y),
                                   scale_fac,
                                   cmap="Greys",
                                   alpha=0.5,
                                   **kwargs)

        if draw_axes:
            self.array.overlay_axis(hillas_parameters,
                                    (self.cen_x, self.cen_y))

    def background_contour(self, x, y, background, **kwargs):
        """
        Draw image contours in background of the display, useful when likelihood fitting

        Parameters
        ----------
        x: ndarray
            array of image X coordinates
        y: ndarray
            array of image Y coordinates
        background: ndarray
            Array of image to use in background
        kwargs: key=value
            any style keywords to pass to matplotlib

        Returns
        -------
        None
        """

        self.axes.contour(x, y, background, **kwargs)

        # Annoyingly we need to redraw everything
        self.array = ArrayDisplay(telx=np.asarray(self.cen_x),
                                  tely=np.asarray(self.cen_y),
                                  tel_type=np.ones(len(self.cen_y)),
                                  axes=self.axes)

    def draw_array(self, range=((-4, 4), (-4, 4))):
        """
        Draw the array plotter (including any overlayed elements)

        Parameters
        ----------
        range: tuple
            XY range in which to draw plotter

        Returns
        -------
        None
        """

        self.array.axes.set_xlim(
            (self.centre[0] + range[0][0], range[0][1] + self.centre[0]))
        self.array.axes.set_ylim(
            (self.centre[1] + range[1][0], range[1][1] + self.centre[1]))

        #self.axes.tight_layout()
        #self.axes.show()

    def draw_position(self, source_x, source_y, use_centre=False, **kwargs):
        """
        Draw a marker at a position in the array plotter (for marking reconstructed
        positions etc)

        Parameters
        ----------
        source_x: float
            X position of point
        source_y: float
            Y position of point
        use_centre: bool
            Centre the plotter on this position
        kwargs: key=value
            any style keywords to pass to matplotlib

        Returns
        -------
        None
        """
        self.array.add_polygon(centroid=(source_x.to(u.deg).value,
                                         source_y.to(u.deg).value),
                               radius=0.1,
                               nsides=3,
                               **kwargs)
        if use_centre:
            self.centre = (source_x.value, source_y.value)
コード例 #14
0
ファイル: array.py プロジェクト: epuesche/ctapipe
class ArrayPlotter:
    """
    Simple plotter for drawing array level items
    """

    def __init__(self, instrument, telescopes=None, system=None, ax=None):
        """

        Parameters
        ----------
        instrument: dictionary
            intrument containers for this event
        telescopes: list
            List of telescopes included
        system: Coordinate system
            Coordinate system to transform coordinates into
        """

        self.instrument = instrument
        self.system = system
        if telescopes is None:
            self.telescopes = instrument.telescope_ids
        else:
            self.telescopes = telescopes
        type_dict = {28.0: 1, 16.0: 2,
                     2.1500000953674316: 3,
                     2.2829999923706055: 4,
                     5.599999904632568: 5}

        tel_x = [self.instrument.tel_pos[i][0].to(u.m).value for i in self.telescopes]
        tel_y = [self.instrument.tel_pos[i][1].to(u.m).value for i in self.telescopes]
        tel_z = [self.instrument.tel_pos[i][2].to(u.m).value for i in self.telescopes]

        self.axes = ax if ax is not None else plt.gca()

        tel_type = np.asarray([type_dict[self.instrument.optical_foclen[i].to(u.m).value] for i in self.telescopes])
        self.tel_type = tel_type

        if system is not None:
            ground = GroundFrame(x=np.asarray(tel_x)*u.m, y=np.asarray(tel_y)*u.m, z=np.asarray(tel_z)*u.m)
            new_sys = ground.transform_to(system)
            self.tel_x = new_sys.x
            self.tel_y = new_sys.y
        else:
            self.tel_x = tel_x*u.m
            self.tel_y = tel_y*u.m

        self.centre = (0,0)
        self.array = ArrayDisplay(telx=np.asarray(self.tel_x), tely=np.asarray(self.tel_y), tel_type=tel_type,
                                  axes=self.axes)

        self.hillas = None

    def overlay_hillas(self, hillas, scale_fac=10000, draw_axes=False, **kwargs):
        """
        Overlay hillas parameters on top of the array map

        Parameters
        ----------
        hillas: dictionary
            Hillas moments objects to overlay
        scale_fac: float
            Scaling factor to array to hillas width and length when drawing
        kwargs: key=value
            any style keywords to pass to matplotlib

        Returns
        -------
        None
        """
        tel_x = [self.instrument.tel_pos[i][0].to(u.m).value for i in hillas]
        tel_y = [self.instrument.tel_pos[i][1].to(u.m).value for i in hillas]
        tel_z = [self.instrument.tel_pos[i][2].to(u.m).value for i in hillas]
        if self.system is not None:
            ground = GroundFrame(x=np.asarray(tel_x)*u.m, y=np.asarray(tel_y)*u.m, z=np.asarray(tel_z)*u.m)
            new_sys = ground.transform_to(self.system)
            self.array.overlay_moments(hillas, (new_sys.x, new_sys.y), scale_fac,
                                       cmap="Greys", alpha=0.5, **kwargs)
            if draw_axes:
                self.array.overlay_axis(hillas, (new_sys.x, new_sys.y))
        else:
            self.array.overlay_moments(hillas, (tel_x, tel_y), scale_fac, alpha=0.5,
                                       cmap="Greys", **kwargs)

        self.hillas = hillas

    def background_contour(self, x, y, background, **kwargs):
        """
        Draw image contours in background of the display, useful when likelihood fitting

        Parameters
        ----------
        x: ndarray
            array of image X coordinates
        y: ndarray
            array of image Y coordinates
        background: ndarray
            Array of image to use in background
        kwargs: key=value
            any style keywords to pass to matplotlib

        Returns
        -------
        None
        """

        self.axes.contour(x, y, background, **kwargs)

        # Annoyingly we need to redraw everything
        self.array = ArrayDisplay(telx=np.asarray(self.tel_x),
                                  tely=np.asarray(self.tel_y),
                                  tel_type=self.tel_type)

        if self.hillas is not None:
            self.overlay_hillas(self.hillas)

    def draw_array(self, range=((-2000, 2000), (-2000, 2000)),
                   annotate=False):
        """
        Draw the array plotter (including any overlayed elements)

        Parameters
        ----------
        range: tuple
            XY range in which to draw plotter

        Returns
        -------
        None
        """

        self.array.axes.set_xlim((self.centre[0]+range[0][0], range[0][1]+self.centre[0]))
        self.array.axes.set_ylim((self.centre[1]+range[1][0], range[1][1]+self.centre[1]))

        if annotate:
            for txt, x, y in zip(self.telescopes,
                                 self.tel_x.value, self.tel_y.value):
                self.axes.annotate(txt, (x, y))

        #self.axes.tight_layout()
        #self.axes.show()

    def draw_position(self, core_x, core_y, use_centre=False, **kwargs):
        """
        Draw a marker at a position in the array plotter (for marking reconstructed
        positions etc)

        Parameters
        ----------
        core_x: float
            X position of point
        core_y: float
            Y position of point
        use_centre: bool
            Centre the plotter on this position
        kwargs: key=value
            any style keywords to pass to matplotlib

        Returns
        -------
        None
        """
        ground = GroundFrame(x=np.asarray(core_x) * u.m, y=np.asarray(core_y) * u.m, z=np.asarray(0) * u.m)

        if self.system is not None:
            new_sys = ground.transform_to(self.system)
        else:
            new_sys = ground

        self.array.add_polygon(centroid=(new_sys.x.value,new_sys.y.value), radius=10, nsides=3, **kwargs)
        if use_centre:
            self.centre = (new_sys.x.value,new_sys.y.value)
コード例 #15
0
if __name__ == '__main__':

    plt.figure(figsize=(9.5, 8.5))

    # load up a single event, so we can get the subarray info:
    source = event_source(
        datasets.get_dataset_path("gamma_test_large.simtel.gz"),
        max_events=1,
    )

    event = next(iter(source))

    # display the array
    subarray = event.inst.subarray
    ad = ArrayDisplay(subarray, tel_scale=3.0)

    print("Now setting vectors")
    plt.pause(1.0)
    plt.tight_layout()

    for phi in np.linspace(0, 360, 30) * u.deg:
        r = np.cos(phi / 2)
        ad.set_vector_rho_phi(r, phi)
        plt.pause(0.01)

    ad.set_vector_rho_phi(0, 0 * u.deg)
    plt.pause(1.0)

    print("Now setting values")
    ad.telescopes.set_linewidth(0)
コード例 #16
0
    # ignore events with less than two telescopes
    if len(hillas_containers) < 2:
        continue
    array_pointing = SkyCoord(az=event.mcheader.run_array_direction[0],
                              alt=event.mcheader.run_array_direction[1],
                              frame=horizon_frame)
    stereo = reco.predict(
        hillas_containers,
        event_source.subarray,
        array_pointing,
    )

    plt.figure()
    angle_offset = event.mcheader.run_array_direction[0]
    disp = ArrayDisplay(event_source.subarray)

    disp.set_vector_hillas(hillas_containers,
                           time_gradient=time_gradients,
                           angle_offset=angle_offset,
                           length=500)
    plt.scatter(
        event.mc.core_x,
        event.mc.core_y,
        s=200,
        c='k',
        marker='x',
        label='True Impact',
    )
    plt.scatter(
        stereo.core_x,
コード例 #17
0
ファイル: array_display.py プロジェクト: cdeil/ctapipe
import numpy as np
from astropy.table import Table
from ctapipe.utils import datasets
from ctapipe.visualization import ArrayDisplay
from matplotlib import pyplot as plt


if __name__ == '__main__':

    plt.style.use("ggplot")
    arrayfile = datasets.get_path("PROD2_telconfig.fits.gz")
    tels = Table.read(arrayfile, hdu="TELESCOPE_LEVEL0")

    plt.figure(figsize=(10, 8))
    adisp = ArrayDisplay(tels['TelX'], tels['TelY'], tels['MirrorArea'] * 2,
                         title='PROD2 all telescopes', autoupdate=False)
    plt.tight_layout()

    intensities = np.zeros(len(tels))

    # do a small animation to show various trigger patterns:
    
    for ii in range(20):
        # generate a random trigger pattern and integrated intensity:
        ntrig = np.random.poisson(10)
        trigmask = np.random.random_integers(len(tels) - 1, size=ntrig)
        intensities[:] = 0
        intensities[trigmask] = np.random.uniform(0, 100, size=ntrig)
        # update the display:
        adisp.intensities = intensities
        plt.pause(0.5)
コード例 #18
0
            time_gradients[telescope_id] = 1

    # ignore events with less than two telescopes
    if len(hillas_containers) < 2:
        continue

    stereo = reco.predict(
        hillas_containers,
        event.inst,
        pointing_alt=pointing_altitude,
        pointing_az=pointing_azimuth
    )

    plt.figure()
    angle_offset = event.mcheader.run_array_direction[0]
    disp = ArrayDisplay(event.inst.subarray)

    disp.set_vector_hillas(
        hillas_containers,
        time_gradient=time_gradients,
        angle_offset=angle_offset,
        length=500
    )
    plt.scatter(
        event.mc.core_x, event.mc.core_y,
        s=200, c='k', marker='x', label='True Impact',
    )
    plt.scatter(
        stereo.core_x, stereo.core_y,
        s=200, c='r', marker='x', label='Estimated Impact',
    )
コード例 #19
0
from astropy.table import Table
from ctapipe.utils import datasets
from ctapipe.visualization import ArrayDisplay
from matplotlib import pyplot as plt

if __name__ == '__main__':

    plt.style.use("ggplot")
    plt.figure(figsize=(10, 8))

    arrayfile = datasets.get_path("PROD2_telconfig.fits.gz")
    tels = Table.read(arrayfile, hdu="TELESCOPE_LEVEL0")

    adisp = ArrayDisplay(tels['TelX'],
                         tels['TelY'],
                         tels['MirrorArea'] * 2,
                         title='PROD2 telescopes',
                         autoupdate=True)
    plt.tight_layout()

    values = np.zeros(len(tels))

    # do a small animation to show various trigger patterns:

    for ii in range(20):

        # generate a random trigger pattern and integrated intensity:
        ntrig = np.random.poisson(10)
        trigmask = np.random.random_integers(len(tels) - 1, size=ntrig)
        values[:] = 0
        values[trigmask] = np.random.uniform(0, 100, size=ntrig)
コード例 #20
0
from numpy import ones_like
import matplotlib.pylab as plt

if __name__ == '__main__':

    plt.style.use("ggplot")
    plt.figure(figsize=(9.5, 8.5))

    # load up an example table that has the telescope positions and
    # mirror areas in it:
    arrayfile = datasets.get_path("PROD2_telconfig.fits.gz")
    tels = Table.read(arrayfile, hdu="TELESCOPE_LEVEL0")

    X = tels['TelX']
    Y = tels['TelY']
    A = tels['MirrorArea'] * 2  # exaggerate scale a bit

    # display the array, and set the color value to 50
    ad = ArrayDisplay(X, Y, A, title="Prod 2 Full Array")
    ad.values = ones_like(X) * 50

    # label them
    for tel in tels:
        name = "CT{tid}".format(tid=tel['TelID'])
        plt.text(tel['TelX'], tel['TelY'], name, fontsize=8)

    ad.axes.set_xlim(-1000, 1000)
    ad.axes.set_ylim(-1000, 1000)
    plt.tight_layout()
    plt.show()
コード例 #21
0
ファイル: array.py プロジェクト: epuesche/ctapipe
class NominalPlotter:
    """
    Simple plotter for drawing camera level items in the nominal system
    """

    def __init__(self, hillas_parameters, draw_axes=False, ax=None, **kwargs):
        """

        Parameters
        ----------
        instrument: dictionary
            intrument containers for this event
        telescopes: list
            List of telescopes included
        system: Coordinate system
            Coordinate system to transform coordinates into
        """
        self.axes = ax if ax is not None else plt.gca()

        self.cen_x = [i.cen_x.to(u.deg).value for i in hillas_parameters.values()]
        self.cen_y = [i.cen_y.to(u.deg).value for i in hillas_parameters.values()]

        self.centre = (0,0)
        self.array = ArrayDisplay(telx=np.asarray(self.cen_x), tely=np.asarray(self.cen_y),
                                  tel_type=np.ones(len(self.cen_y)), axes=self.axes)

        self.hillas = hillas_parameters
        scale_fac = 57.3 * 2

        self.array.overlay_moments(hillas_parameters, (self.cen_x, self.cen_y), scale_fac,
                                   cmap="Greys", alpha=0.5, **kwargs)

        if draw_axes:
            self.array.overlay_axis(hillas_parameters, (self.cen_x, self.cen_y))

    def background_contour(self, x, y, background, **kwargs):
        """
        Draw image contours in background of the display, useful when likelihood fitting

        Parameters
        ----------
        x: ndarray
            array of image X coordinates
        y: ndarray
            array of image Y coordinates
        background: ndarray
            Array of image to use in background
        kwargs: key=value
            any style keywords to pass to matplotlib

        Returns
        -------
        None
        """

        self.axes.contour(x, y, background, **kwargs)

        # Annoyingly we need to redraw everything
        self.array = ArrayDisplay(telx=np.asarray(self.cen_x), tely=np.asarray(self.cen_y),
                                  tel_type=np.ones(len(self.cen_y)), axes=self.axes)

    def draw_array(self, range=((-4,4),(-4,4))):
        """
        Draw the array plotter (including any overlayed elements)

        Parameters
        ----------
        range: tuple
            XY range in which to draw plotter

        Returns
        -------
        None
        """

        self.array.axes.set_xlim((self.centre[0]+range[0][0], range[0][1]+self.centre[0]))
        self.array.axes.set_ylim((self.centre[1]+range[1][0], range[1][1]+self.centre[1]))

        #self.axes.tight_layout()
        #self.axes.show()

    def draw_position(self, source_x, source_y, use_centre=False, **kwargs):
        """
        Draw a marker at a position in the array plotter (for marking reconstructed
        positions etc)

        Parameters
        ----------
        source_x: float
            X position of point
        source_y: float
            Y position of point
        use_centre: bool
            Centre the plotter on this position
        kwargs: key=value
            any style keywords to pass to matplotlib

        Returns
        -------
        None
        """
        self.array.add_polygon(centroid=(source_x.to(u.deg).value,source_y.to(u.deg).value), radius=0.1, nsides=3, **kwargs)
        if use_centre:
            self.centre = (source_x.value,source_y.value)
コード例 #22
0
ファイル: array_layout.py プロジェクト: cdeil/ctapipe
from ctapipe import io
from ctapipe.visualization import ArrayDisplay
import matplotlib.pylab as plt

if __name__ == '__main__':

    plt.style.use("ggplot")
    layout = io.get_array_layout("hess")
    X = layout['POSX']
    Y = layout['POSY']
    A = layout['MIRAREA']
    A[:] = 132

    ad = ArrayDisplay(X, Y, A, title="HESS")

    # label them
    for tel in layout:
        name = "CT{tid}:{tclass}".format(tid=tel['TELID'],
                                         tclass=io.tel_class_name(
                                             tel['CLASS']))
        plt.text(tel['POSX'], tel['POSY'], name)

    ad.axes.set_xlim(-300, 300)
    ad.axes.set_ylim(-300, 300)
    plt.show()
コード例 #23
0
    # pointing direction of the telescopes
    point_azimuth = {}
    point_altitude = {}

    calib = CameraCalibrator(eventsource=source)
    off_angles = []
    first_event = True
    markers = None

    for event in source:

        subarray = event.inst.subarray

        if first_event:
            fig, ax = plt.subplots(1, 1, figsize=(10, 8))
            array_disp = ArrayDisplay(subarray, axes=ax, tel_scale=1.0)
            array_disp.telescopes.set_linewidth(3)
            array_disp.add_labels()
            first_event = False
            hit_pattern = np.zeros(subarray.num_tels)

        if len(event.r0.tels_with_data) < 3:
            continue

        # calibrating the event
        calib.calibrate(event)
        hillas_dict = {}

        # plot the core position, which must be transformed from the tilted
        # system to the system that the ArrayDisplay is in (default
        # GroundFrame)