Convert camera images to pixels on a s square grid

[1]:
from ctapipe.utils import get_dataset_path
from ctapipe.visualization import CameraDisplay
from ctapipe.instrument import CameraGeometry
from ctapipe.io import EventSource
from ctapipe.image.toymodel import Gaussian
import matplotlib.pyplot as plt
import astropy.units as u

Geometries with square pixels

Define a camera geometry and generate a dummy image:

[2]:
geom = CameraGeometry.from_name('CHEC')
model = Gaussian(
        x=0.05*u.m,
        y=0.05*u.m,
        width=0.01*u.m,
        length=0.05*u.m,
        psi='30d',
    )
_, image, _ = model.generate_image(
    geom, intensity=500, nsb_level_pe=3
)
[3]:

CameraDisplay(geom, image)
[3]:
<ctapipe.visualization.mpl_camera.CameraDisplay at 0x7f8d1bc88490>

The CameraGeometry has functions to convert the 1d image arrays to 2d arrays and back to the 1d array:

[4]:
image_square = geom.image_to_cartesian_representation(image)
[5]:
plt.imshow(image_square)
[5]:
<matplotlib.image.AxesImage at 0x7f8d1b9b0910>
[6]:
image_1d = geom.image_from_cartesian_representation(image_square)
[7]:
CameraDisplay(geom, image_1d)
[7]:
<ctapipe.visualization.mpl_camera.CameraDisplay at 0x7f8d1b9b0a90>

Geometries with hexagonal pixels

Define a camera geometry and generate a dummy image:

[8]:
geom = CameraGeometry.from_name('LSTCam')
model = Gaussian(
        x=0.5*u.m,
        y=0.5*u.m,
        width=0.1*u.m,
        length=0.2*u.m,
        psi='30d',
    )
_, image, _ = model.generate_image(
    geom, intensity=5000
)
[9]:
CameraDisplay(geom, image)
[9]:
<ctapipe.visualization.mpl_camera.CameraDisplay at 0x7f8d1b70f6a0>
[10]:
image_square = geom.image_to_cartesian_representation(image)

Conversion into square geometry

Since the resulting array has square pixels, the pixel grid has to be rotated and distorted. This is reversible (The image_from_cartesian_representation method takes care of this):

[11]:
plt.imshow(image_square)
[11]:
<matplotlib.image.AxesImage at 0x7f8d1b72b5e0>
[12]:
image_1d = geom.image_from_cartesian_representation(image_square)
[13]:
disp = CameraDisplay(geom, image_1d)
[ ]: