{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tailcut cleaning with PyWI-CTA" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/jeremiedecock/pywi-cta-notebooks/master?filepath=tuto_2a_tailcut_cleaning.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Import required modules" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook requires PyWI-CTA for the I/O." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "\n", "import matplotlib.pyplot as plt\n", "\n", "import pywicta\n", "import pywicta.data\n", "from pywicta.io import geometry_converter\n", "from pywicta.io.images import image_generator\n", "from pywicta.io.images import plot_ctapipe_image\n", "from pywicta.io.images import plot_hillas_parameters_on_axes\n", "\n", "from pywicta.denoising.tailcut import Tailcut\n", "\n", "print(pywicta.get_version())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get image" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The next cells define the list of images to use in this notebook.\n", "\n", "Images can be fetched from Fits files or from Simtel files.\n", "Fits files are much lighter and much faster to process than Simtel files but they are specific to PyWI-CTA and thus you first have to generate them from Simtel files using [the following script](). Also, contrary to Simtel files, a Fits files contains only one \"image\" (i.e. an unique event viewed from one unique telescope)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#pywicta.data.lst([\"lst_gamma_r104_prod3b-north_t1_e1016403_660GeV\", \"lst_gamma_r104_prod3b-north_t1_e6905_87GeV\"])\n", "pywicta.data.lst()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#CAM_ID = \"ASTRICam\"\n", "#CAM_ID = \"CHEC\"\n", "#CAM_ID = \"DigiCam\"\n", "#CAM_ID = \"FlashCam\"\n", "#CAM_ID = \"NectarCam\"\n", "CAM_ID = \"LSTCam\"\n", "\n", "IMG_PATH_LIST = pywicta.data.lst([\"lst_gamma_r104_prod3b-north_t1_e1016403_660GeV\"])\n", "\n", "image_gen = image_generator(IMG_PATH_LIST,\n", " cam_filter_list=[CAM_ID],\n", " ctapipe_format=False)\n", "\n", "img = next(image_gen)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "img.meta" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plot" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Images comming from FITS files are stored in 2D arrays (mainly because the Sparce2D wavelet transform expects images stored in 2D arrays).\n", "But ctapipe uses a special 1D array representation for IACT images (defined in \"geom\" objects).\n", "Thus conversion has to be done prior to use ctapipe functions on images comming from Fits files (using the \"geometry_converter\" function)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geom1d = geometry_converter.get_geom1d(CAM_ID)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "img_input_1d = geometry_converter.image_2d_to_1d(img.input_image, CAM_ID)\n", "\n", "disp = plot_ctapipe_image(img_input_1d,\n", " geom1d,\n", " title='Noised image',\n", " norm='lin',\n", " plot_axis=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setup the Tailcut cleaning" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Fell free to change the following default setup to get a better understanding of the Tailcut cleaning..." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "picture_thresh = 8\n", "boundary_thresh = 4\n", "pixels_clusters = \"off\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Clean the image with Tailcut" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tailcut = Tailcut()\n", "\n", "tailcut_cleaned_img = tailcut.clean_image(img.input_image,\n", " high_threshold=picture_thresh,\n", " low_threshold=boundary_thresh,\n", " pixels_clusters_filtering=pixels_clusters,\n", " cam_id=CAM_ID)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tailcut_cleaned_img_1d = geometry_converter.image_2d_to_1d(tailcut_cleaned_img, CAM_ID)\n", "\n", "disp = plot_ctapipe_image(tailcut_cleaned_img_1d,\n", " geom1d,\n", " title='Clean image',\n", " norm='lin',\n", " plot_axis=False)\n", "\n", "plot_hillas_parameters_on_axes(disp.axes,\n", " tailcut_cleaned_img_1d,\n", " geom1d,\n", " hillas_implementation=2)" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.6" } }, "nbformat": 4, "nbformat_minor": 2 }