<jupyter_start><jupyter_text>Convert camera images to pixels on a s square grid<jupyter_code>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<jupyter_output><empty_output><jupyter_text>Geometries with square pixelsDefine a camera geometry and generate a dummy image:<jupyter_code>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
)

CameraDisplay(geom, image)<jupyter_output><empty_output><jupyter_text>The `CameraGeometry` has functions to convert the 1d image arrays to 2d arrays and back to the 1d array:<jupyter_code>image_square = geom.image_to_cartesian_representation(image)
plt.imshow(image_square)
image_1d = geom.image_from_cartesian_representation(image_square)
CameraDisplay(geom, image_1d)<jupyter_output><empty_output><jupyter_text>Geometries with hexagonal pixelsDefine a camera geometry and generate a dummy image:<jupyter_code>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
)
CameraDisplay(geom, image)
image_square = geom.image_to_cartesian_representation(image)<jupyter_output><empty_output><jupyter_text>Conversion into square geometrySince 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):<jupyter_code>plt.imshow(image_square)
image_1d = geom.image_from_cartesian_representation(image_square)
disp = CameraDisplay(geom, image_1d)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08987090367428004, 'fraction_numerical': 0.019364448857994043, 'mean_word_length': 5.784511784511785, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '518483', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 719, 'n_tokens_neox': 675, 'n_words': 146, 'path': 'docs/examples/convert_images_to_2d.ipynb', 'repo_name': 'LukasBeiske/ctapipe', 'size': '2014'}