Skip to content

Commit

Permalink
Wrong angle in ArrayDisplay. changed phi to psi. (#771)
Browse files Browse the repository at this point in the history
* Wrong angle in arrow plotting. changed phi to psi.

* Added set_line_hillas to plot lines from hillas parameter.

* Added function in tests.

* Fixed bug in range. Added a point for each telescope position.

* Fixed bug in **kwargs for axes.scatter and axes.plot.

* Removed useless code.

* Wrong phi is now psi. All tests passed.
  • Loading branch information
thomas gasparetto authored and kosack committed Aug 22, 2018
1 parent 6a2a6a8 commit 77aaf44
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
39 changes: 35 additions & 4 deletions ctapipe/visualization/mpl_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from astropy import units as u
from astropy.coordinates import Angle
from matplotlib import pyplot as plt
from matplotlib.collections import PatchCollection
from matplotlib.collections import PatchCollection, LineCollection
from matplotlib.lines import Line2D
from matplotlib.patches import Circle

Expand Down Expand Up @@ -182,15 +182,46 @@ def set_vector_hillas(self, hillas_dict, angle_offset=180 * u.deg):
mapping of tel_id to Hillas parameters
"""

# rot_angle_ellipse is psi parameter in HillasParametersContainer

rho = np.zeros(self.subarray.num_tels) * u.m
phi = np.zeros(self.subarray.num_tels) * u.deg
rot_angle_ellipse = np.zeros(self.subarray.num_tels) * u.deg

for tel_id, params in hillas_dict.items():
idx = self.subarray.tel_indices[tel_id]
rho[idx] = 1.0 * u.m # params.length
phi[idx] = Angle(params.phi) + Angle(angle_offset)
rot_angle_ellipse[idx] = Angle(params.psi)+ Angle(angle_offset)

self.set_vector_rho_phi(rho=rho, phi=rot_angle_ellipse)

def set_line_hillas(self, hillas_dict, range, **kwargs):
"""
Function to plot a segment of length 2*range for each telescope from a set of Hillas parameters.
The segment is centered on the telescope position.
A point is added at each telescope position for better visualization.
self.set_vector_rho_phi(rho=rho, phi=phi)
Parameters
----------
hillas_dict: Dict[int, HillasParametersContainer]
mapping of tel_id to Hillas parameters
range: float
half of the length of the segments to be plotted (in meters)
"""

coords = self.tel_coords
c = self.tel_colors

for tel_id, params in hillas_dict.items():
idx = self.subarray.tel_indices[tel_id]
x_0 = coords[idx].x.value
y_0 = coords[idx].y.value
m = np.tan(Angle(params.psi))
x = x_0 + np.linspace(-range, range, 50)
y = y_0 + m * (x-x_0)
distance = np.sqrt((x - x_0) ** 2 + (y - y_0) ** 2)
mask = np.ma.masked_where(distance < range, distance).mask
self.axes.plot(x[mask], y[mask], color=c[idx], **kwargs)
self.axes.scatter(x_0, y_0, color=c[idx])

def add_labels(self):
px = self.tel_coords.x.value
Expand Down
6 changes: 3 additions & 3 deletions ctapipe/visualization/tests/test_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ def test_array_display():

# 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"),
1: HillasParametersContainer(length=1.0 * u.m, psi=90 * u.deg),
2: HillasParametersContainer(length=200 * u.cm, psi="95deg"),
}
ad.set_vector_hillas(hillas_dict)

ad.set_line_hillas(hillas_dict, range=300)
ad.add_labels()
ad.remove_labels()

0 comments on commit 77aaf44

Please sign in to comment.