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
/usr/local/lib/python3.8/site-packages/setuptools_scm/ UserWarning: "/github/workspace" is shallow and may cause errors
  warnings.warn('"{}" is shallow and may cause errors'.format(wd.path))


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 0x7f192fa2e220>

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 0x7f192f7c9850>

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 0x7f192f7d0cd0>

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

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