{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "# Developer Tutorial" ] }, { "cell_type": "markdown", "id": "1", "metadata": {}, "source": [ "> **TIP**: add the following to the top of your notebook or ipython script to have it automatically reload the imports as you make changes. That makes it much nicer to develop at the same time as working in the notebook:\n" ] }, { "cell_type": "markdown", "id": "2", "metadata": {}, "source": [ "```\n", "%load_ext autoreload\n", "%autoreload 2\n", "```" ] }, { "cell_type": "markdown", "id": "3", "metadata": {}, "source": [ "## Using the EventSource interactively. \n", "\n", "Note that you can find detailed tutorials about working with events and `EventSources` in general in the [ctapipe documentation](https://ctapipe.readthedocs.io/en/latest/).\n", "\n", "The purpose of the HESSEventSource is too make HESS data work with the `ctapipe-process` command-line tool. Howwever, during development instead of running the tool, it's often nice to make a small test script to help explore the functionality of the `HESSEventSource` interactively, either in a python REPL like *ipython*, or in a *Jupyter Notebook*. \n", "\n", "A basic test is as follows:\n" ] }, { "cell_type": "code", "execution_count": null, "id": "4", "metadata": {}, "outputs": [], "source": [ "%matplotlib inline \n", "\n", "from ctapipe.coordinates import EngineeringCameraFrame\n", "from ctapipe.io import EventSource\n", "from ctapipe.utils import get_dataset_path\n", "from ctapipe.visualization import CameraDisplay\n", "\n", "# load the test file. Note you can substitute your own local filename here instead\n", "# , e.g. filename=\"my_local_dst_file.root\"\n", "FILENAME = get_dataset_path(\"example_hess_dst.root\")\n", "\n", "# now just load the first event in the file:\n", "with EventSource(FILENAME, max_events=1) as source:\n", " for event in source:\n", " print(event.index)" ] }, { "cell_type": "markdown", "id": "5", "metadata": {}, "source": [ "Now ``event`` is the first loaded event, and ``source`` will be an instance of HESSIOEventSource, if everything worked correctly" ] }, { "cell_type": "code", "execution_count": null, "id": "6", "metadata": {}, "outputs": [], "source": [ "source" ] }, { "cell_type": "markdown", "id": "7", "metadata": {}, "source": [ "## Look at attributes of the event source and see if they make sense:" ] }, { "cell_type": "code", "execution_count": null, "id": "8", "metadata": {}, "outputs": [], "source": [ "source.obs_ids" ] }, { "cell_type": "code", "execution_count": null, "id": "9", "metadata": {}, "outputs": [], "source": [ "for obs_id, ob in source.observation_blocks.items():\n", " print(ob)\n", "ob" ] }, { "cell_type": "code", "execution_count": null, "id": "10", "metadata": {}, "outputs": [], "source": [ "source.atmosphere_density_profile" ] }, { "cell_type": "code", "execution_count": null, "id": "11", "metadata": {}, "outputs": [], "source": [ "source.metadata" ] }, { "cell_type": "code", "execution_count": null, "id": "12", "metadata": {}, "outputs": [], "source": [ "source.subarray" ] }, { "cell_type": "code", "execution_count": null, "id": "13", "metadata": {}, "outputs": [], "source": [ "source.subarray.info()" ] }, { "cell_type": "code", "execution_count": null, "id": "14", "metadata": {}, "outputs": [], "source": [ "source.subarray.peek()" ] }, { "cell_type": "markdown", "id": "15", "metadata": {}, "source": [ "## Look at the images\n", "\n", "first let's see what telescopes have data in this event:" ] }, { "cell_type": "code", "execution_count": null, "id": "16", "metadata": {}, "outputs": [], "source": [ "event.dl1.tel.keys()" ] }, { "cell_type": "markdown", "id": "17", "metadata": {}, "source": [ "Ok, then we can look at `tel_id`=1 (which is \"CT1\")\n", "\n", "The *repr* of a Container class gives you its contents:" ] }, { "cell_type": "code", "execution_count": null, "id": "18", "metadata": {}, "outputs": [], "source": [ "event.dl1.tel[1]" ] }, { "cell_type": "markdown", "id": "19", "metadata": {}, "source": [ "So, then you can look at elements:" ] }, { "cell_type": "code", "execution_count": null, "id": "20", "metadata": {}, "outputs": [], "source": [ "event.dl1.tel[1].image.sum()" ] }, { "cell_type": "markdown", "id": "21", "metadata": {}, "source": [ "## Display an image to see if things look ok:" ] }, { "cell_type": "code", "execution_count": null, "id": "22", "metadata": {}, "outputs": [], "source": [ "tel_id = 1\n", "image = event.dl1.tel[tel_id].image\n", "\n", "# best to get the geometry and transform\n", "# it to the EngineeringCameraFrame, which is what you would see if\n", "# looking at the front of the camera\n", "geometry = source.subarray.tel[1].camera.geometry.transform_to(EngineeringCameraFrame())\n", "\n", "disp = CameraDisplay(geometry, image=image)" ] }, { "cell_type": "code", "execution_count": null, "id": "23", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "24", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "language_info": { "codemirror_mode": { "name": "ipython" }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python" } }, "nbformat": 4, "nbformat_minor": 5 }