{ "cells": [ { "cell_type": "markdown", "id": "e7797698-4ef1-459b-aba6-70f5a19700fe", "metadata": {}, "source": [ "# Fast theta2 plot" ] }, { "cell_type": "code", "execution_count": 11, "id": "5c70feea-56cc-47e0-ac6f-1a1badb72b6d", "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import os\n", "import pandas as pd\n", "import numpy as np\n", "import astropy.units as u\n", "import matplotlib.pyplot as plt\n", "import matplotlib.style as style\n", "from matplotlib.offsetbox import AnchoredText\n", "\n", "from lstchain.io.io import dl2_params_lstcam_key\n", "from lstchain.reco.utils import (\n", " compute_theta2,\n", " extract_source_position,\n", " clip_alt,\n", " get_effective_time,\n", " radec_to_camera,\n", ")\n", "from ctapipe.containers import EventType\n", "from ctapipe.coordinates import CameraFrame\n", "from astropy.coordinates import (\n", " ICRS,\n", " Galactic,\n", " FK4,\n", " FK5,\n", " AltAz,\n", " SkyCoord,\n", " EarthLocation,\n", ")\n", "from astropy.time import Time\n", "from gammapy.stats import WStatCountsStatistic\n", "\n", "style.use('tableau-colorblind10')\n", "plt.rcParams['font.size'] = 20" ] }, { "cell_type": "code", "execution_count": 12, "id": "13478fbb-ce71-40a7-ade3-ba24fd7bf3a8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "lstchain: 0.9.2\n" ] } ], "source": [ "import lstchain\n", "print(\"lstchain:\", lstchain.__version__)" ] }, { "cell_type": "markdown", "id": "ee6d5a07-31ac-4037-a344-d4d41bc1f301", "metadata": { "tags": [] }, "source": [ "## This function gets the source position in camera coordinates for any source" ] }, { "cell_type": "code", "execution_count": 13, "id": "c64aebd0-c499-45aa-b093-5457eab3110e", "metadata": {}, "outputs": [], "source": [ "def extract_source_position_from_coord(\n", " data, coord, equivalent_focal_length=28 * u.m\n", "):\n", " \"\"\"\n", " Extract source position from data\n", " Parameters:\n", " -----------\n", " pandas.DataFrame data: input data\n", " str observed_source_name: Name of the observed source\n", " astropy.units.m equivalent_focal_length: Equivalent focal length of a telescope\n", " Returns:\n", " --------\n", " 2D array of coordinates of the source in form [(x),(y)] in astropy.units.m\n", " \"\"\"\n", "\n", " obstime = pd.to_datetime(data[\"dragon_time\"], unit=\"s\")\n", " pointing_alt = u.Quantity(data[\"alt_tel\"], u.rad, copy=False)\n", " pointing_az = u.Quantity(data[\"az_tel\"], u.rad, copy=False)\n", " source_pos_camera = radec_to_camera(\n", " coord,\n", " obstime,\n", " pointing_alt,\n", " pointing_az,\n", " focal=equivalent_focal_length,\n", " )\n", " source_position = [source_pos_camera.x, source_pos_camera.y]\n", " return source_position" ] }, { "cell_type": "markdown", "id": "04be8310-f669-4d4b-9bc3-3d28ce3557b6", "metadata": {}, "source": [ "## Choose input files" ] }, { "cell_type": "code", "execution_count": 127, "id": "d86c8d23-6cdd-4203-8b74-080d5729581b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 0 ns, sys: 17 µs, total: 17 µs\n", "Wall time: 32.2 µs\n" ] } ], "source": [ "%time\n", "data=pd.DataFrame()\n", "base_dir = '/fefs/aswg/workspace/alice.donini/Analysis/data/DL2/OT081/03_04/'\n", "runs=['7247', '7248', '7249', '7250', '7268', '7269', '7270', '7271'] # You can concatenate several runs\n", "for run in runs:\n", " input_file = base_dir + 'dl2_LST-1.Run0' + run + '.h5'\n", " data = pd.concat([data, pd.read_hdf(input_file, key=dl2_params_lstcam_key)])" ] }, { "cell_type": "code", "execution_count": 128, "id": "6d3c7a4c-7962-4996-9fa1-63031759e082", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | obs_id | \n", "event_id | \n", "intensity | \n", "log_intensity | \n", "x | \n", "y | \n", "r | \n", "phi | \n", "length | \n", "length_uncertainty | \n", "... | \n", "reco_disp_dx | \n", "reco_disp_dy | \n", "reco_src_x | \n", "reco_src_y | \n", "signed_time_gradient | \n", "signed_skewness | \n", "reco_alt | \n", "reco_az | \n", "reco_type | \n", "gammaness | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "7247 | \n", "1 | \n", "5558.815268 | \n", "3.744982 | \n", "-0.004939 | \n", "0.015149 | \n", "0.015934 | \n", "1.885987 | \n", "1.129726 | \n", "0.007532 | \n", "... | \n", "0.832716 | \n", "-0.015970 | \n", "0.827777 | \n", "-0.000821 | \n", "0.812561 | \n", "-0.076595 | \n", "0.834200 | \n", "1.868510 | \n", "101 | \n", "0.003333 | \n", "
1 | \n", "7247 | \n", "2 | \n", "141.059285 | \n", "2.149402 | \n", "0.163317 | \n", "0.811628 | \n", "0.827897 | \n", "1.372226 | \n", "0.081826 | \n", "0.004962 | \n", "... | \n", "0.050537 | \n", "-0.248039 | \n", "0.213855 | \n", "0.563589 | \n", "-2.572229 | \n", "0.845133 | \n", "0.812062 | \n", "1.897811 | \n", "101 | \n", "0.085833 | \n", "
2 | \n", "7247 | \n", "4 | \n", "142.004474 | \n", "2.152302 | \n", "-0.071148 | \n", "-0.984977 | \n", "0.987544 | \n", "-1.642904 | \n", "0.104376 | \n", "0.006505 | \n", "... | \n", "-0.185304 | \n", "0.207286 | \n", "-0.256451 | \n", "-0.777691 | \n", "-2.829985 | \n", "1.035164 | \n", "0.795081 | \n", "1.828885 | \n", "101 | \n", "0.115690 | \n", "
3 | \n", "7247 | \n", "5 | \n", "82.812871 | \n", "1.918098 | \n", "0.706447 | \n", "-0.135670 | \n", "0.719357 | \n", "-0.189736 | \n", "0.089534 | \n", "0.007189 | \n", "... | \n", "0.027651 | \n", "-0.377567 | \n", "0.734098 | \n", "-0.513237 | \n", "-9.201743 | \n", "-0.596836 | \n", "0.830675 | \n", "1.841381 | \n", "101 | \n", "0.297679 | \n", "
4 | \n", "7247 | \n", "6 | \n", "387.911234 | \n", "2.588732 | \n", "-0.353784 | \n", "-0.610470 | \n", "0.705576 | \n", "-2.096026 | \n", "0.200827 | \n", "0.005634 | \n", "... | \n", "-0.343944 | \n", "0.008421 | \n", "-0.697729 | \n", "-0.602050 | \n", "1.243090 | \n", "0.158467 | \n", "0.779484 | \n", "1.838331 | \n", "101 | \n", "0.318167 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
4703232 | \n", "7271 | \n", "6875377 | \n", "26.366716 | \n", "1.421056 | \n", "0.363717 | \n", "0.163353 | \n", "0.398716 | \n", "0.422124 | \n", "0.072286 | \n", "0.004999 | \n", "... | \n", "0.323878 | \n", "0.058110 | \n", "0.687595 | \n", "0.221463 | \n", "0.133079 | \n", "-0.062316 | \n", "1.015517 | \n", "2.111565 | \n", "101 | \n", "0.234262 | \n", "
4703233 | \n", "7271 | \n", "6875380 | \n", "316.378483 | \n", "2.500207 | \n", "-0.627153 | \n", "0.324259 | \n", "0.706020 | \n", "2.664412 | \n", "0.549196 | \n", "0.007050 | \n", "... | \n", "-0.331546 | \n", "0.239815 | \n", "-0.958699 | \n", "0.564074 | \n", "0.918155 | \n", "-0.259290 | \n", "0.956476 | \n", "2.131501 | \n", "101 | \n", "0.000000 | \n", "
4703234 | \n", "7271 | \n", "6875382 | \n", "34.390079 | \n", "1.536433 | \n", "-0.543439 | \n", "0.177228 | \n", "0.571608 | \n", "2.826344 | \n", "0.044486 | \n", "0.001474 | \n", "... | \n", "-0.426950 | \n", "0.026139 | \n", "-0.970389 | \n", "0.203367 | \n", "20.490553 | \n", "0.075689 | \n", "0.956315 | \n", "2.109157 | \n", "101 | \n", "0.453071 | \n", "
4703235 | \n", "7271 | \n", "6875383 | \n", "609.365335 | \n", "2.784878 | \n", "-0.835687 | \n", "0.627784 | \n", "1.045221 | \n", "2.497312 | \n", "0.188546 | \n", "0.004151 | \n", "... | \n", "0.121237 | \n", "0.337459 | \n", "-0.714450 | \n", "0.965243 | \n", "1.780293 | \n", "0.264297 | \n", "0.964621 | \n", "2.157079 | \n", "101 | \n", "0.420667 | \n", "
4703236 | \n", "7271 | \n", "6875385 | \n", "35.637082 | \n", "1.551902 | \n", "0.255900 | \n", "0.675475 | \n", "0.722323 | \n", "1.208659 | \n", "0.066841 | \n", "0.004855 | \n", "... | \n", "-0.279754 | \n", "0.349490 | \n", "-0.023854 | \n", "1.024965 | \n", "-11.338355 | \n", "-0.089569 | \n", "0.989137 | \n", "2.163228 | \n", "101 | \n", "0.329143 | \n", "
32056543 rows × 58 columns
\n", "