Skip to content

Commit

Permalink
Start adapting docs
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Jul 10, 2023
1 parent 66fe529 commit c16ba3b
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 186 deletions.
38 changes: 23 additions & 15 deletions docs/examples/array_display.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,10 @@
"ad = ArrayDisplay(subarray)\n",
"ad.telescopes.set_linewidth(0) # to turn off the telescope borders\n",
"\n",
"tels_with_trigger = [1, 4, 5, 6]\n",
"trigger_pattern = np.zeros(subarray.n_tels)\n",
"trigger_pattern[\n",
" [\n",
" 1,\n",
" 4,\n",
" 5,\n",
" 6,\n",
" ]\n",
"] = 1\n",
"trigger_pattern[tels_with_trigger] = 1\n",
"\n",
"ad.values = trigger_pattern # display certain telescopes in a color\n",
"ad.add_labels()"
]
Expand Down Expand Up @@ -184,16 +179,20 @@
},
"outputs": [],
"source": [
"plt.set_cmap(\"rainbow\") # the array display will use the current colormap for values\n",
"plt.set_cmap(\"inferno\") # the array display will use the current colormap for values\n",
"\n",
"ad = ArrayDisplay(subarray)\n",
"ad.telescopes.set_linewidth(0) # to turn off the telescope borders\n",
"\n",
"plt.scatter(shower_impact.easting, shower_impact.northing, marker=\"+\", s=200)\n",
"\n",
"distances = np.hypot(\n",
" subarray.tel_coords.cartesian.x - shower_impact.cartesian.x,\n",
" subarray.tel_coords.cartesian.y - shower_impact.cartesian.y,\n",
")\n",
"\n",
"ad.values = distances\n",
"\n",
"plt.colorbar(ad.telescopes, label=\"Distance (m)\")"
]
},
Expand All @@ -219,8 +218,8 @@
},
"outputs": [],
"source": [
"np.random.seed(0)\n",
"phis = np.random.uniform(0, 180.0, size=subarray.n_tels) * u.deg\n",
"rng = np.random.default_rng(0)\n",
"phis = rng.uniform(0, 180.0, size=subarray.n_tels) * u.deg\n",
"rhos = np.ones(subarray.n_tels) * 200 * u.m\n",
"\n",
"\n",
Expand Down Expand Up @@ -297,8 +296,8 @@
" angle_offset = event.pointing.azimuth\n",
" disp = ArrayDisplay(subarray, axes=ax)\n",
"\n",
" hillas_dict = {tid: tel.parameters.hillas for tid, tel in event.dl1.tel.items()}\n",
" core_dict = {tid: tel.parameters.core.psi for tid, tel in event.dl1.tel.items()}\n",
" hillas_dict = {tid: tel.dl1.parameters.hillas for tid, tel in event.tel.items()}\n",
" core_dict = {tid: tel.dl1.parameters.core.psi for tid, tel in event.tel.items()}\n",
"\n",
" disp.set_line_hillas(\n",
" hillas_dict,\n",
Expand Down Expand Up @@ -341,6 +340,7 @@
"execution_count": null,
"id": "502fe577-3e8a-4e6d-90f3-8db8fbb57b90",
"metadata": {
"scrolled": false,
"tags": []
},
"outputs": [],
Expand All @@ -362,14 +362,22 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython"
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python"
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
}
},
"nbformat": 4,
Expand Down
123 changes: 61 additions & 62 deletions docs/tutorials/calibrated_data_exploration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
},
"outputs": [],
"source": [
"print(event.r1)"
"event.tel[26]"
]
},
{
Expand All @@ -100,12 +100,11 @@
"source": [
"## Perform basic calibration:\n",
"\n",
"Here we will use a `CameraCalibrator` which is just a simple wrapper that runs the three calibraraton and trace-integration phases of the pipeline, taking the data from levels:\n",
"Here we will use a `CameraCalibrator` which is just a simple wrapper that runs the two calibration and trace-integration phases of the pipeline, taking the data from levels:\n",
"\n",
" **R0** → **R1** → **DL0** → **DL1**\n",
" **R1** → **DL0** → **DL1**\n",
"\n",
"You could of course do these each separately, by using the classes `R1Calibrator`, `DL0Reducer`, and `DL1Calibrator`.\n",
"Note that we have not specified any configuration to the `CameraCalibrator`, so it will be using the default algorithms and thresholds, other than specifying that the product is a \"HESSIOR1Calibrator\" (hopefully in the near future that will be automatic)."
"Note that we have not specified any configuration to the `CameraCalibrator`, so it will be using the default algorithms and thresholds."
]
},
{
Expand All @@ -126,9 +125,10 @@
"source": [
"Now the *r1*, *dl0* and *dl1* containers are filled in the event\n",
"\n",
"* **r1.tel[x]**: contains the \"r1-calibrated\" waveforms, after gain-selection, pedestal subtraciton, and gain-correction\n",
"* **dl0.tel[x]**: is the same but with optional data volume reduction (some pixels not filled), in this case this is not performed by default, so it is the same as r1\n",
"* **dl1.tel[x]**: contains the (possibly re-calibrated) waveforms as dl0, but also the time-integrated *image* that has been calculated using a `ImageExtractor` (a `NeighborPeakWindowSum` by default)"
"* **r0**: Contains device specific raw data. This is usually only available in simulations or in expert data. \n",
"* **r1**: contains the \"r1-calibrated\" waveforms, after gain-selection, pedestal subtraction, and gain-correction\n",
"* **dl0**: is the same but with optional data volume reduction (some pixels not filled), by default, this is not performed, so it is the same as r1\n",
"* **dl1**: contains the time-integrated *image* that has been calculated using an `ImageExtractor` (`NeighborPeakWindowSum` by default)"
]
},
{
Expand All @@ -137,11 +137,11 @@
"metadata": {},
"outputs": [],
"source": [
"for tel_id in event.dl1.tel:\n",
"for tel_id, tel_event in event.tel.items():\n",
" print(\"TEL{:03}: {}\".format(tel_id, source.subarray.tel[tel_id]))\n",
" print(\" - r0 wave shape : {}\".format(event.r0.tel[tel_id].waveform.shape))\n",
" print(\" - r1 wave shape : {}\".format(event.r1.tel[tel_id].waveform.shape))\n",
" print(\" - dl1 image shape : {}\".format(event.dl1.tel[tel_id].image.shape))"
" print(\" - r0 wave shape : {}\".format(tel_event.r0.waveform.shape))\n",
" print(\" - r1 wave shape : {}\".format(tel_event.r1.waveform.shape))\n",
" print(\" - dl1 image shape : {}\".format(tel_event.dl1.image.shape))"
]
},
{
Expand All @@ -161,10 +161,10 @@
"source": [
"from ctapipe.visualization import CameraDisplay\n",
"\n",
"tel_id = sorted(event.r1.tel.keys())[1]\n",
"tel_id, tel_event = next(iter(event.tel.items()))\n",
"sub = source.subarray\n",
"geometry = sub.tel[tel_id].camera.geometry\n",
"image = event.dl1.tel[tel_id].image"
"image = tel_event.dl1.image"
]
},
{
Expand Down Expand Up @@ -222,23 +222,36 @@
"source": [
"params = hillas_parameters(geometry, cleaned)\n",
"\n",
"plt.figure(figsize=(10, 10))\n",
"plt.figure(figsize=(5, 5))\n",
"disp = CameraDisplay(geometry, image=image)\n",
"disp.add_colorbar()\n",
"disp.overlay_moments(params, color=\"red\", lw=3)\n",
"disp.overlay_moments(params, color=\"xkcd:light blue\", lw=3)\n",
"disp.highlight_pixels(mask, color=\"white\", alpha=0.3, linewidth=2)\n",
"\n",
"plt.xlim(params.x.to_value(u.m) - 0.5, params.x.to_value(u.m) + 0.5)\n",
"plt.ylim(params.y.to_value(u.m) - 0.5, params.y.to_value(u.m) + 0.5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## ImageProcessor\n",
"\n",
"The above steps can be configured and run easily using the `ImageProcessor` class:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"source.metadata"
"from ctapipe.image import ImageProcessor\n",
"\n",
"image_processor = ImageProcessor(subarray=source.subarray, use_telescope_frame=False)\n",
"\n",
"image_processor(event)"
]
},
{
Expand All @@ -262,9 +275,8 @@
"metadata": {},
"outputs": [],
"source": [
"tels_in_event = set(\n",
" event.dl1.tel.keys()\n",
") # use a set here, so we can intersect it later\n",
"# use a set here, so we can intersect it later\n",
"tels_in_event = set(event.tel.keys())\n",
"tels_in_event"
]
},
Expand All @@ -274,27 +286,8 @@
"metadata": {},
"outputs": [],
"source": [
"cam_ids = set(sub.get_tel_ids_for_type(\"MST_MST_NectarCam\"))\n",
"cam_ids"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"cams_in_event = tels_in_event.intersection(cam_ids)\n",
"first_tel_id = list(cams_in_event)[0]\n",
"tel = sub.tel[first_tel_id]\n",
"print(\"{}s in event: {}\".format(tel, cams_in_event))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, let's sum those images:"
"mst_tel_ids = set(sub.get_tel_ids_for_type(\"MST_MST_NectarCam\"))\n",
"mst_tel_ids"
]
},
{
Expand All @@ -303,32 +296,45 @@
"metadata": {},
"outputs": [],
"source": [
"image_sum = np.zeros_like(\n",
" tel.camera.geometry.pix_x.value\n",
") # just make an array of 0's in the same shape as the camera\n",
"msts_in_event = list(tels_in_event.intersection(mst_tel_ids))\n",
"\n",
"for tel_id in cams_in_event:\n",
" image_sum += event.dl1.tel[tel_id].image"
"tel = sub.tel[msts_in_event[0]]\n",
"print(f\"{tel} in event: {msts_in_event}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And finally display the sum of those images"
"Now let's sum and display those images"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"plt.figure(figsize=(8, 8))\n",
"image_sum = np.zeros(tel.camera.geometry.n_pixels)\n",
"\n",
"\n",
"fig, ax = plt.subplots(figsize=(8, 8))\n",
"\n",
"disp = CameraDisplay(tel.camera.geometry, image=image_sum)\n",
"disp.overlay_moments(params, with_label=False)\n",
"plt.title(\"Sum of {}x {}\".format(len(cams_in_event), tel))"
"disp = CameraDisplay(tel.camera.geometry, ax=ax)\n",
"\n",
"\n",
"for tel_id in msts_in_event:\n",
" dl1 = event.tel[tel_id].dl1\n",
" image_sum += dl1.image\n",
"\n",
" disp.overlay_moments(\n",
" dl1.parameters.hillas, with_label=False, keep_old=True, lw=3, n_sigma=2\n",
" )\n",
"\n",
"disp.image = image_sum\n",
"plt.title(\"Sum of {}x {}\".format(len(msts_in_event), tel))"
]
},
{
Expand All @@ -353,10 +359,10 @@
"metadata": {},
"outputs": [],
"source": [
"nectarcam_subarray = sub.select_subarray(cam_ids, name=\"NectarCam\")\n",
"nectarcam_subarray = sub.select_subarray(mst_tel_ids, name=\"NectarCam\")\n",
"\n",
"hit_pattern = np.zeros(shape=nectarcam_subarray.n_tels)\n",
"hit_pattern[[nectarcam_subarray.tel_indices[x] for x in cams_in_event]] = 100\n",
"hit_pattern[nectarcam_subarray.tel_ids_to_indices(msts_in_event)] = 1\n",
"\n",
"plt.set_cmap(plt.cm.Accent)\n",
"plt.figure(figsize=(8, 8))\n",
Expand All @@ -365,13 +371,6 @@
"ad.values = hit_pattern\n",
"ad.add_labels()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -390,7 +389,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.9.16"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit c16ba3b

Please sign in to comment.