.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/algorithms/convert_images_to_2d.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_algorithms_convert_images_to_2d.py: Convert camera images to pixels on a s square grid ================================================== .. GENERATED FROM PYTHON SOURCE LINES 6-14 .. code-block:: Python :lineno-start: 7 import astropy.units as u import matplotlib.pyplot as plt from ctapipe.image.toymodel import Gaussian from ctapipe.instrument import SubarrayDescription from ctapipe.visualization import CameraDisplay .. GENERATED FROM PYTHON SOURCE LINES 15-16 get the subarray from an example file .. GENERATED FROM PYTHON SOURCE LINES 16-19 .. code-block:: Python :lineno-start: 16 subarray = SubarrayDescription.read("dataset://gamma_prod5.simtel.zst") .. GENERATED FROM PYTHON SOURCE LINES 20-25 Geometries with square pixels ----------------------------- Define a camera geometry and generate a dummy image: .. GENERATED FROM PYTHON SOURCE LINES 25-36 .. code-block:: Python :lineno-start: 26 geom = subarray.tel[40].camera.geometry 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) .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: Python :lineno-start: 37 CameraDisplay(geom, image) .. image-sg:: /auto_examples/algorithms/images/sphx_glr_convert_images_to_2d_001.png :alt: CHEC :srcset: /auto_examples/algorithms/images/sphx_glr_convert_images_to_2d_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 41-44 The ``CameraGeometry`` has functions to convert the 1d image arrays to 2d arrays and back to the 1d array: .. GENERATED FROM PYTHON SOURCE LINES 44-47 .. code-block:: Python :lineno-start: 45 image_square = geom.image_to_cartesian_representation(image) .. GENERATED FROM PYTHON SOURCE LINES 48-50 .. code-block:: Python :lineno-start: 48 plt.imshow(image_square) .. image-sg:: /auto_examples/algorithms/images/sphx_glr_convert_images_to_2d_002.png :alt: convert images to 2d :srcset: /auto_examples/algorithms/images/sphx_glr_convert_images_to_2d_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 51-53 .. code-block:: Python :lineno-start: 51 image_1d = geom.image_from_cartesian_representation(image_square) .. GENERATED FROM PYTHON SOURCE LINES 54-57 .. code-block:: Python :lineno-start: 54 CameraDisplay(geom, image_1d) .. image-sg:: /auto_examples/algorithms/images/sphx_glr_convert_images_to_2d_003.png :alt: CHEC :srcset: /auto_examples/algorithms/images/sphx_glr_convert_images_to_2d_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 58-63 Geometries with hexagonal pixels -------------------------------- Define a camera geometry and generate a dummy image: .. GENERATED FROM PYTHON SOURCE LINES 63-74 .. code-block:: Python :lineno-start: 64 geom = subarray.tel[1].camera.geometry 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) .. GENERATED FROM PYTHON SOURCE LINES 75-77 .. code-block:: Python :lineno-start: 75 CameraDisplay(geom, image) .. image-sg:: /auto_examples/algorithms/images/sphx_glr_convert_images_to_2d_004.png :alt: LSTCam :srcset: /auto_examples/algorithms/images/sphx_glr_convert_images_to_2d_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 78-81 .. code-block:: Python :lineno-start: 78 image_square = geom.image_to_cartesian_representation(image) .. GENERATED FROM PYTHON SOURCE LINES 82-89 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): .. GENERATED FROM PYTHON SOURCE LINES 89-92 .. code-block:: Python :lineno-start: 90 plt.imshow(image_square) .. image-sg:: /auto_examples/algorithms/images/sphx_glr_convert_images_to_2d_005.png :alt: convert images to 2d :srcset: /auto_examples/algorithms/images/sphx_glr_convert_images_to_2d_005.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 93-95 .. code-block:: Python :lineno-start: 93 image_1d = geom.image_from_cartesian_representation(image_square) .. GENERATED FROM PYTHON SOURCE LINES 96-97 .. code-block:: Python :lineno-start: 96 disp = CameraDisplay(geom, image_1d) .. image-sg:: /auto_examples/algorithms/images/sphx_glr_convert_images_to_2d_006.png :alt: LSTCam :srcset: /auto_examples/algorithms/images/sphx_glr_convert_images_to_2d_006.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.693 seconds) .. _sphx_glr_download_auto_examples_algorithms_convert_images_to_2d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: convert_images_to_2d.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: convert_images_to_2d.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: convert_images_to_2d.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_