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 0x7f57072b9b80>
../_images/examples_convert_images_to_2d_4_1.png

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 0x7f570632c850>
../_images/examples_convert_images_to_2d_7_1.png
[6]:
image_1d = geom.image_from_cartesian_representation(image_square)
[7]:
CameraDisplay(geom, image_1d)
[7]:
<ctapipe.visualization.mpl_camera.CameraDisplay at 0x7f57062c2550>
../_images/examples_convert_images_to_2d_9_1.png

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 0x7f57062e33d0>
../_images/examples_convert_images_to_2d_12_1.png
[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 0x7f5706460670>
../_images/examples_convert_images_to_2d_15_1.png
[12]:
image_1d = geom.image_from_cartesian_representation(image_square)
[13]:
disp = CameraDisplay(geom, image_1d)
../_images/examples_convert_images_to_2d_17_0.png
[ ]: