pyhiperta.waveform_indexing
Implements the indexing/mapping of waveforms from 1D array (hexagonal structure) to 2D square array.
The 1D array representation is suited for vectorization of "per-element" operations such as calibration, Hillas computation, etc. while the 2D square representation is faster for operations requiring neighbors look-up, such as the tail-cut cleaning. It is faster to copy the data from one representation to the other than to perform the cleaning with the 1D representation.
Functions:
| Name | Description |
|---|---|
leakage_pixel_masks |
Returns a mask (boolean array) that multiplied with waveforms (1D) puts all pixels except the outer rings to 0. |
neighbors_only_stencil |
Return the stencil selecting only the neighbors of a pixel in 2D array. |
waveform1Dto2D |
Get the 2D array representation of waveform |
waveform2Dto1D |
Get the 1D array representing the waveform from the 2D representation |
waveform_1D_to_2D_maps |
Create the 2D waveform array with "squared geometry" and 1D to 2D indices maps. |
leakage_pixel_masks
Returns a mask (boolean array) that multiplied with waveforms (1D) puts all pixels except the outer rings to 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pixel_positions
|
ndarray
|
2D array (shape: (2, N_pixels)) containing the pixels x and y coordinates. This should be the actual pixels positions in the camera. It is important that the referential in which the position are measured has equal metrics on both axis (1m in the real world is 1 on x and y axis) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
leakage_mask |
ndarray
|
Mask array with values True at the indices of pixels on the outermost rings, False otherwise. The shape is (2, nb_pixels). leakage_mask[0, :] selects the pixels of the outermost ring (leakage 1) while leakage[1:] selects the pixels of the 1st and 2nd outermost ring (leakage 2). |
Source code in src/pyhiperta/waveform_indexing.py
neighbors_only_stencil
Return the stencil selecting only the neighbors of a pixel in 2D array.
The pixel itself is not included: center element of the stencil is 0.
Notes
The stencil values depend on the way the 1D to 2D conversion is performed. Depending on how the axis are deformed, it could be transposed or reversed. The current implementation does 0 1 1 4 2 3 4 -> 0 3 6 5 6 2 5 so the stencil is 1 where the neighbors are and 0 otherwise (and 0 at the center to exclude current pixel).
Source code in src/pyhiperta/waveform_indexing.py
waveform1Dto2D
Get the 2D array representation of waveform
If waveform2D is passed, the values of waveform2D will be updated with waveform's.
Otherwise a new 2D array will be created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
maps1D_to_2D
|
tuple of np.ndarray
|
The tuple holding the indices to go from 1D to 2D representation |
required |
waveform
|
ndarray
|
Waveform values in 1D shape. |
required |
waveform2D
|
(ndarray, optionnal)
|
An already existing 2D representation of the waveform, to update with |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
A 2D array representing the waveform. (The array is independent of waveform, not a view) |
Source code in src/pyhiperta/waveform_indexing.py
waveform2Dto1D
Get the 1D array representing the waveform from the 2D representation waveform2D.
Notes
The result is a view in waveform2D! Modifying the view will modify waveform2D!
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
maps1D_to_2D
|
tuple of np.ndarray
|
The tuple holding the indices to go from 2D to 1D representation |
required |
waveform2D
|
ndarray
|
The 2D array holding the waveform values. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
1D array holding the waveform values. |
Source code in src/pyhiperta/waveform_indexing.py
waveform_1D_to_2D_maps
Create the 2D waveform array with "squared geometry" and 1D to 2D indices maps.
To perform fast "neighbour looking" operations such as convolution we need to store the waveform as a 2D array. To fit the hexagonal geometry of the camera into a 2D square grid (the 2D array) we perform a rotation (to align an axis with the 2D array axis) and then deform the other axis to align the hexagonal neighbour on the square grid. If we represent the pixels by their index in the 1D array: 0 1 1 4 2 3 4 -> 0 3 6 5 6 2 5 The algorithm is: - find 3 neighbours forming a triangle in the hexagonal representation. The pixels should be such that: the left-most pixel is in between the other two pixels on the y coordinate, eg: x x x Such a combination is always possible as the angle in the triangles is 60° and we search a space of 90°. The goal of this is to use the left-most pixel as our 2D grid origin, and the other pixels coordinates will give us the rotation and deformation. In the example, the chosen are pixels are 0, 1 and 3. (1's y is equal or higher than 0's y) - Rotate all pixels coordinates such that the "down" neighbour is aligned with the 2D grid rows x x x -> x x x - Normalize the distances between pixels, so that a pixel is at distance 1 from another on row and column axis (makes next step easier). - "Deform" along the row axis to align the pixels on the 2D columns. This is a linear transformation of the x coordinate with respect to the y coordinate: ___x x ___ is the deformation to apply for a distance of +1 y -> x x x x - Bin the pixel positions to get their index in the 2D array. This gives the 1D to 2D indices maps.
Notes
This function is slow and runs only on cpu (scipy.cKDTree). It should be used only once to get the mappings for a given camera geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pixel_positions
|
array
|
2D array (shape: (2, N_pixels)) containing the pixels x and y coordinates. This should be the actual pixels positions in the camera. It is important that the referential in which the position are measured has equal metrics on both axis (1m in the real world is 1 on x and y axis) |
required |
Returns:
| Type | Description |
|---|---|
Tuple[ndarray, ndarray]
|
Row and column indices (shape (N_pixels,) each) to use as 1D to 2D indexing maps. |
Source code in src/pyhiperta/waveform_indexing.py
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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |