Convert hexagonal cameras into square grid and back

from ctapipe.utils import get_dataset_path
from ctapipe.image.geometry_converter import convert_geometry_hex1d_to_rect2d, convert_geometry_rect2d_back_to_hexe1d
from ctapipe.visualization import CameraDisplay
from import EventSource
import copy
import matplotlib.pyplot as plt


filename = get_dataset_path('gamma_test_large.simtel.gz')
source = EventSource(filename, max_events=10, allowed_tels={1})
events = [copy.deepcopy(event) for event in source]
event = events[0]
geometry =[1].camera.geometry
image =[1].waveform[0].sum(axis=1)
CameraDisplay(geometry, image)
<ctapipe.visualization.mpl_camera.CameraDisplay at 0x7fab26473af0>

Conversion into square geometry

A key must be speficied to be able to convert back to hexagonal afterwards
The conversion geometry is stored in ctapipe.image.geometry_convert.rot_buffer
key = 0
square_geom, square_image = convert_geometry_hex1d_to_rect2d(geometry, image, key=key)
<matplotlib.image.AxesImage at 0x7fab260cd760>

Conversion back to hexagonal geometry

hex_geom, hex_image = convert_geometry_rect2d_back_to_hexe1d(square_geom, square_image, key=key)
CameraDisplay(hex_geom, hex_image)
<ctapipe.visualization.mpl_camera.CameraDisplay at 0x7fab260cd7f0>

Let’s check that the images are exactly the same:

assert (hex_image == image).all()
assert hex_geom == geometry