Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
{
"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": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>obs_id</th>\n",
" <th>event_id</th>\n",
" <th>intensity</th>\n",
" <th>log_intensity</th>\n",
" <th>x</th>\n",
" <th>y</th>\n",
" <th>r</th>\n",
" <th>phi</th>\n",
" <th>length</th>\n",
" <th>length_uncertainty</th>\n",
" <th>...</th>\n",
" <th>reco_disp_dx</th>\n",
" <th>reco_disp_dy</th>\n",
" <th>reco_src_x</th>\n",
" <th>reco_src_y</th>\n",
" <th>signed_time_gradient</th>\n",
" <th>signed_skewness</th>\n",
" <th>reco_alt</th>\n",
" <th>reco_az</th>\n",
" <th>reco_type</th>\n",
" <th>gammaness</th>\n",
" </tr>\n",
" </thead>\n",
Loading full blame...