Convert hexagonal cameras into square grid and back

[1]:
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 ctapipe.io import EventSource
import copy
import matplotlib.pyplot as plt

Setup

[2]:
filename = get_dataset_path('gamma_test_large.simtel.gz')
[3]:
source = EventSource(filename, max_events=10, allowed_tels={1})
[4]:
events = [copy.deepcopy(event) for event in source]
[5]:
event = events[0]
[6]:
geometry = source.subarray.tel[1].camera.geometry
image = event.r0.tel[1].waveform[0].sum(axis=1)
CameraDisplay(geometry, image)
[6]:
<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
[7]:
key = 0
square_geom, square_image = convert_geometry_hex1d_to_rect2d(geometry, image, key=key)
[8]:
plt.imshow(square_image)
[8]:
<matplotlib.image.AxesImage at 0x7fab260cd760>

Conversion back to hexagonal geometry

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

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

[11]:
assert (hex_image == image).all()
[12]:
assert hex_geom == geometry