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 __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.x.to(u.deg).value for i in hillas_parameters.values()] self.cen_y = [i.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 test_array_display(): """ check that we can do basic array display functionality """ from ctapipe.visualization.mpl_array import ArrayDisplay from ctapipe.image import timing_parameters # build a test subarray: tels = dict() tel_pos = dict() for ii, pos in enumerate([[0, 0, 0], [100, 0, 0], [-100, 0, 0]] * u.m): tels[ii + 1] = TelescopeDescription.from_name("MST", "NectarCam") tel_pos[ii + 1] = pos sub = SubarrayDescription(name="TestSubarray", tel_positions=tel_pos, tel_descriptions=tels) ad = ArrayDisplay(sub) ad.set_vector_rho_phi(1 * u.m, 90 * u.deg) # try setting a value vals = ones(sub.num_tels) ad.values = vals assert (vals == ad.values).all() # test using hillas params: hillas_dict = { 1: HillasParametersContainer(length=100.0 * u.m, psi=90 * u.deg), 2: HillasParametersContainer(length=20000 * u.cm, psi="95deg"), } grad = 2 intercept = 1 geom = CameraGeometry.from_name("LSTCam") rot_angle = 20 * u.deg hillas = HillasParametersContainer(x=0 * u.m, y=0 * u.m, psi=rot_angle) timing_rot20 = timing_parameters( geom, image=ones(geom.n_pixels), peak_time=intercept + grad * geom.pix_x.value, hillas_parameters=hillas, cleaning_mask=ones(geom.n_pixels, dtype=bool), ) gradient_dict = { 1: timing_rot20.slope.value, 2: timing_rot20.slope.value, } ad.set_vector_hillas( hillas_dict=hillas_dict, length=500, time_gradient=gradient_dict, angle_offset=0 * u.deg, ) ad.set_line_hillas(hillas_dict, range=300) ad.add_labels() ad.remove_labels()
def test_array_display(): from ctapipe.visualization.mpl_array import ArrayDisplay # build a test subarray: tels = dict() tel_pos = dict() for ii, pos in enumerate([[0, 0, 0], [100, 0, 0], [-100, 0, 0]] * u.m): tels[ii + 1] = TelescopeDescription.from_name("MST", "NectarCam") tel_pos[ii + 1] = pos sub = SubarrayDescription(name="TestSubarray", tel_positions=tel_pos, tel_descriptions=tels) ad = ArrayDisplay(sub) ad.set_vector_rho_phi(1 * u.m, 90 * u.deg) # try setting a value vals = ones(sub.num_tels) ad.values = vals assert (vals == ad.values).all() # test using hillas params: hillas_dict = { 1: HillasParametersContainer(length=1.0 * u.m, phi=90 * u.deg), 2: HillasParametersContainer(length=200 * u.cm, phi="95deg"), } ad.set_vector_hillas(hillas_dict) ad.add_labels() ad.remove_labels()
def test_array_display(): """ check that we can do basic array display functionality """ from ctapipe.visualization.mpl_array import ArrayDisplay from ctapipe.image import timing_parameters from ctapipe.containers import ( ArrayEventContainer, DL1Container, DL1CameraContainer, ImageParametersContainer, CoreParametersContainer, ) # build a test subarray: tels = dict() tel_pos = dict() for ii, pos in enumerate([[0, 0, 0], [100, 0, 0], [-100, 0, 0]] * u.m): tels[ii + 1] = TelescopeDescription.from_name("MST", "NectarCam") tel_pos[ii + 1] = pos sub = SubarrayDescription(name="TestSubarray", tel_positions=tel_pos, tel_descriptions=tels) # Create a fake event containing telescope-wise information about # the image directions projected on the ground event = ArrayEventContainer() event.dl1 = DL1Container() event.dl1.tel = {1: DL1CameraContainer(), 2: DL1CameraContainer()} event.dl1.tel[1].parameters = ImageParametersContainer() event.dl1.tel[2].parameters = ImageParametersContainer() event.dl1.tel[2].parameters.core = CoreParametersContainer() event.dl1.tel[1].parameters.core = CoreParametersContainer() event.dl1.tel[1].parameters.core.psi = u.Quantity(2.0, unit=u.deg) event.dl1.tel[2].parameters.core.psi = u.Quantity(1.0, unit=u.deg) ad = ArrayDisplay(subarray=sub) ad.set_vector_rho_phi(1 * u.m, 90 * u.deg) # try setting a value vals = np.ones(sub.num_tels) ad.values = vals assert (vals == ad.values).all() # test UV field ... # ...with colors by telescope type ad.set_vector_uv(np.array([1, 2, 3]) * u.m, np.array([1, 2, 3]) * u.m) # ...with scalar color ad.set_vector_uv(np.array([1, 2, 3]) * u.m, np.array([1, 2, 3]) * u.m, c=3) geom = CameraGeometry.from_name("LSTCam") rot_angle = 20 * u.deg hillas = CameraHillasParametersContainer(x=0 * u.m, y=0 * u.m, psi=rot_angle) # test using hillas params CameraFrame: hillas_dict = { 1: CameraHillasParametersContainer(length=100.0 * u.m, psi=90 * u.deg), 2: CameraHillasParametersContainer(length=20000 * u.cm, psi="95deg"), } grad = 2 intercept = 1 timing_rot20 = timing_parameters( geom, image=np.ones(geom.n_pixels), peak_time=intercept + grad * geom.pix_x.value, hillas_parameters=hillas, cleaning_mask=np.ones(geom.n_pixels, dtype=bool), ) gradient_dict = {1: timing_rot20.slope.value, 2: timing_rot20.slope.value} core_dict = { tel_id: dl1.parameters.core.psi for tel_id, dl1 in event.dl1.tel.items() } ad.set_vector_hillas( hillas_dict=hillas_dict, core_dict=core_dict, length=500, time_gradient=gradient_dict, angle_offset=0 * u.deg, ) ad.set_line_hillas(hillas_dict=hillas_dict, core_dict=core_dict, range=300) # test using hillas params for divergent pointing in telescopeframe: hillas_dict = { 1: HillasParametersContainer(fov_lon=1.0 * u.deg, fov_lat=1.0 * u.deg, length=1.0 * u.deg, psi=90 * u.deg), 2: HillasParametersContainer(fov_lon=1.0 * u.deg, fov_lat=1.0 * u.deg, length=1.0 * u.deg, psi=95 * u.deg), } ad.set_vector_hillas( hillas_dict=hillas_dict, core_dict=core_dict, length=500, time_gradient=gradient_dict, angle_offset=0 * u.deg, ) ad.set_line_hillas(hillas_dict=hillas_dict, core_dict=core_dict, range=300) # test using hillas params for parallel pointing in telescopeframe: hillas_dict = { 1: HillasParametersContainer(fov_lon=1.0 * u.deg, fov_lat=1.0 * u.deg, length=1.0 * u.deg, psi=90 * u.deg), 2: HillasParametersContainer(fov_lon=1.0 * u.deg, fov_lat=1.0 * u.deg, length=1.0 * u.deg, psi=95 * u.deg), } ad.set_vector_hillas( hillas_dict=hillas_dict, core_dict=core_dict, length=500, time_gradient=gradient_dict, angle_offset=0 * u.deg, ) # test negative time_gradients gradient_dict = {1: -0.03, 2: -0.02} ad.set_vector_hillas( hillas_dict=hillas_dict, core_dict=core_dict, length=500, time_gradient=gradient_dict, angle_offset=0 * u.deg, ) # and very small gradient_dict = {1: 0.003, 2: 0.002} ad.set_vector_hillas( hillas_dict=hillas_dict, core_dict=core_dict, length=500, time_gradient=gradient_dict, angle_offset=0 * u.deg, ) # Test background contour ad.background_contour( x=np.array([0, 1, 2]), y=np.array([0, 1, 2]), background=np.array([[0, 1, 2], [0, 1, 2], [0, 1, 2]]), ) ad.set_line_hillas(hillas_dict=hillas_dict, core_dict=core_dict, range=300) ad.add_labels() ad.remove_labels()
def test_array_display(): from ctapipe.visualization.mpl_array import ArrayDisplay from ctapipe.image.timing_parameters import timing_parameters # build a test subarray: tels = dict() tel_pos = dict() for ii, pos in enumerate([[0, 0, 0], [100, 0, 0], [-100, 0, 0]] * u.m): tels[ii + 1] = TelescopeDescription.from_name("MST", "NectarCam") tel_pos[ii + 1] = pos sub = SubarrayDescription(name="TestSubarray", tel_positions=tel_pos, tel_descriptions=tels) ad = ArrayDisplay(sub) ad.set_vector_rho_phi(1 * u.m, 90 * u.deg) # try setting a value vals = ones(sub.num_tels) ad.values = vals assert (vals == ad.values).all() # test using hillas params: hillas_dict = { 1: HillasParametersContainer(length=100.0 * u.m, psi=90 * u.deg), 2: HillasParametersContainer(length=20000 * u.cm, psi="95deg"), } grad = 2 intercept = 1 rot_angle = 20 * u.deg timing_rot20 = timing_parameters(pix_x=arange(4) * u.deg, pix_y=zeros(4) * u.deg, image=ones(4), peak_time=intercept * u.ns + grad * arange(4) * u.ns, rotation_angle=rot_angle) gradient_dict = { 1: timing_rot20.gradient.value, 2: timing_rot20.gradient.value, } ad.set_vector_hillas(hillas_dict=hillas_dict, length=500, time_gradient=gradient_dict, angle_offset=0 * u.deg) ad.set_line_hillas(hillas_dict, range=300) ad.add_labels() ad.remove_labels()
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.x.to(u.deg).value for i in hillas_parameters.values()] self.cen_y = [i.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, coord_range=((-4, 4), (-4, 4))): """ Draw the array plotter (including any overlayed elements) Parameters ---------- coord_range: tuple XY range in which to draw plotter Returns ------- None """ self.array.axes.set_xlim((self.centre[0] + coord_range[0][0], coord_range[0][1] + self.centre[0])) self.array.axes.set_ylim((self.centre[1] + coord_range[1][0], coord_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)