forked from cta-observatory/ctapipe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_array_hillas.py
More file actions
121 lines (93 loc) · 3.79 KB
/
Copy pathplot_array_hillas.py
File metadata and controls
121 lines (93 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
"""
Plots the (rough) hillas parameters for each event on an ArrayDisplay
"""
import sys
import matplotlib.pyplot as plt
import numpy as np
from astropy.coordinates import SkyCoord
from astropy import units as u
from ctapipe.calib import CameraCalibrator
from ctapipe.coordinates import TiltedGroundFrame
from ctapipe.image import hillas_parameters, tailcuts_clean, \
HillasParameterizationError
from ctapipe.io import event_source
from ctapipe.utils import datasets
from ctapipe.visualization import ArrayDisplay
if __name__ == '__main__':
# importing data from avaiable datasets in ctapipe
filename = datasets.get_dataset_path("gamma_test_large.simtel.gz")
if len(sys.argv) > 1:
filename = sys.argv[1]
# reading the Monte Carlo file for LST
source = event_source(filename)
# 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)
point_dir = SkyCoord(
*event.mcheader.run_array_direction,
frame='altaz'
)
tiltedframe = TiltedGroundFrame(pointing_direction=point_dir)
if markers:
for marker in markers:
marker.remove()
core_coord = SkyCoord(
x=event.mc.core_x,
y=event.mc.core_y,
frame=tiltedframe
).transform_to(array_disp.frame)
markers = ax.plot([core_coord.x.value, ], [core_coord.y.value, ],
"r+", markersize=10)
# plot the hit pattern (triggered tels).
# first expand the tels_with_data list into a fixed-length vector,
# then set the value so that the ArrayDisplay shows it as color per
# telescope.
tel_idx = event.inst.subarray.tel_indices
hit_pattern[:] = 0
mask = [tel_idx[t] for t in event.r0.tels_with_data]
hit_pattern[mask] = 10.0
array_disp.values = hit_pattern
# calculate and plot the hillas params
for tel_id in event.dl0.tels_with_data:
# Camera Geometry required for hillas parametrization
camgeom = subarray.tel[tel_id].camera
# note the [0] is for channel 0 which is high-gain channel
image = event.dl1.tel[tel_id].image[0]
# Cleaning of the image
cleaned_image = image.copy()
# create a clean mask of pixels above the threshold
cleanmask = tailcuts_clean(
camgeom, image, picture_thresh=10, boundary_thresh=5
)
# set all rejected pixels to zero
cleaned_image[~cleanmask] = 0
# Calculate hillas parameters
try:
hillas_dict[tel_id] = hillas_parameters(camgeom, cleaned_image)
except HillasParameterizationError:
pass # skip failed parameterization (normally no signal)
array_disp.set_vector_hillas(hillas_dict, angle_offset=0 * u.deg)
plt.pause(0.1) # allow matplotlib to redraw the display
if len(hillas_dict) < 2:
continue