Source code for hipecta.image.hillas

from .._image import hillas
from . import get_hillas_parameters_container
from ..memory import copyto
from ..memory import empty
import numpy as np
from astropy import units as u
from ctapipe.instrument import CameraGeometry


[docs]class HillasParamater: def __init__(self): self.telescope_position = dict() def _add_telescope(self, tel_id, geom: CameraGeometry): pixels_position = np.ascontiguousarray( np.transpose([geom.pix_x.to(u.m).value, geom.pix_y.to(u.m).value]).astype(np.float32)) # Allocated posx, posy numpy array aligned on SIMD register size. pos_x = empty(pixels_position[:, 0].shape, dtype=np.float32) pos_y = empty(pixels_position[:, 1].shape, dtype=np.float32) # copy positions to new array copyto(pos_x, pixels_position[:, 0]) copyto(pos_y, pixels_position[:, 1]) self.telescope_position[tel_id] = (pos_x, pos_y)
[docs] def process(self, telescope_id, geom: CameraGeometry, image): """Compute Hillas parameters for a given shower image. Parameters ---------- geom: ctapipe.instrument.CameraGeometry Camera corresponding to the image image : array_like Pixel values Returns ------- hillas_parameters : `HillasParametersContainer` """ if not telescope_id in self.telescope_position: self._add_telescope(telescope_id, geom) # Allocated image numpy array aligned on SIMD register size. image_align = empty(image.shape, dtype=np.float32) copyto(image_align, image) # Compute hillas paramters hillas_params = hillas(image_align, self.telescope_position[telescope_id][0], self.telescope_position[telescope_id][1]) return get_hillas_parameters_container(hillas_params)