Skip to content

Commit e2c6cae

Browse files
committed
Combine ex_identifiers functions, add LST neighbor matrix
1 parent fea9474 commit e2c6cae

2 files changed

Lines changed: 137 additions & 220 deletions

File tree

dl1_data_handler/image_mapper.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class ImageMapper(TelescopeComponent):
5757
Multiplication factor used for rebinning.
5858
index_matrix : numpy.ndarray or None
5959
Matrix used for indexing, initialized to None.
60+
cam_neighbor_array : numpy.ndarray or None
61+
Matrix used for indexing, initialized to None.
6062
6163
Methods
6264
-------
@@ -125,6 +127,7 @@ def __init__(
125127

126128
# Set the indexed matrix to None
127129
self.index_matrix = None
130+
self.cam_neighbor_array = None
128131

129132
def map_image(self, raw_vector: np.array) -> np.array:
130133
"""
@@ -651,7 +654,8 @@ def _get_grids(
651654

652655
class HexagonalPatchMapper(ImageMapper):
653656
"""
654-
HexagonalPatchMapper crops the images following the "sipm_patches.h5"
657+
HexagonalPatchMapper retrieves the necessary information to perform indexed
658+
convolutions, also allows croping the images following the "sipm_patches.h5"
655659
patches geometry and reorders the pixels.
656660
657661
This class extends the functionality of ImageMapper by implementing
@@ -685,24 +689,33 @@ def __init__(
685689
if geometry.pix_type != PixelShape.HEXAGON:
686690
raise ValueError(
687691
f"HexagonalPatchMapper is only available for hexagonal pixel cameras. Pixel type of the selected camera is '{geometry.pix_type}'."
688-
)
689-
if geometry.name != "UNKNOWN-7987PX":
690-
raise ValueError(
691-
f"HexagonalPatchMapper is only available for the SiPMCa. Selected camera is '{geometry.name}'."
692-
)
693-
694-
with h5py.File(self.h5_patches_path, "r") as f:
695-
# patches
696-
self.patch_coords = f["patches/centers"][:] # shape (103, 2)
697-
self.trigger_patches = f["patches/masks"][:] # shape (103, 7987)
698-
# mappings
699-
self.index_map = f["mappings/index_map"][:] # shape (103, 343)
700-
# neighbor array
701-
self.neighbor_array = f["mappings/mod_neighbors"][:] # shape (343, 7)
702-
self.cam_neighbor_array = f["mappings/cam_neighbors"][:] # shape (7987, 7)
703-
704-
self.num_patches = len(self.trigger_patches)
705-
self.patch_size = len(self.index_map[0])
692+
)
693+
if geometry.name == "UNKNOWN-7987PX":
694+
with h5py.File(self.h5_patches_path, "r") as f:
695+
# patches
696+
self.patch_coords = f["patches/centers"][:] # shape (103, 2)
697+
self.trigger_patches = f["patches/masks"][:] # shape (103, 7987)
698+
# mappings
699+
self.index_map = f["mappings/index_map"][:] # shape (103, 343)
700+
# neighbor array
701+
self.neighbor_array = f["mappings/mod_neighbors"][:] # shape (343, 7)
702+
self.cam_neighbor_array = f["mappings/cam_neighbors"][:] # shape (7987, 7)
703+
704+
self.num_patches = len(self.trigger_patches)
705+
self.patch_size = len(self.index_map[0])
706+
707+
elif geometry.name == "LSTCam":
708+
neighbor_matrix = geometry.neighbor_matrix
709+
num_pixels = neighbor_matrix.shape[0]
710+
neighbor_lists = []
711+
for i in range(num_pixels):
712+
# Find indices where the row is True
713+
neighbors = np.where(neighbor_matrix[i])[0]
714+
neighbor_lists.append([i] + neighbors.tolist())
715+
716+
self.cam_neighbor_array = np.full((num_pixels, 7), -1, dtype=int)
717+
for i, neighbors in enumerate(neighbor_lists):
718+
self.cam_neighbor_array[i, :len(neighbors)] = neighbors
706719

707720
def get_reordered_patch(self, raw_vector, patch_index):
708721
# Retrieve the patch needed

0 commit comments

Comments
 (0)