|
70 | 70 | "# Bokeh and Holoviews for visualization\n", |
71 | 71 | "import bokeh\n", |
72 | 72 | "from bokeh.io import output_notebook\n", |
| 73 | + "from bokeh.models import HoverTool\n", |
73 | 74 | "\n", |
74 | 75 | "import holoviews as hv\n", |
75 | 76 | "from holoviews import streams, opts\n", |
|
270 | 271 | "metadata": {}, |
271 | 272 | "outputs": [], |
272 | 273 | "source": [ |
273 | | - "# Make a function to generate a plot title from the dataId.\n", |
| 274 | + "# Make a function to autogenerate a plot title from the dataId.\n", |
274 | 275 | "def dataIdToString(dataId: dict) -> str:\n", |
275 | 276 | " title = \"DC2 image: \"\n", |
276 | 277 | " for key, value in dataId.items():\n", |
|
316 | 317 | "metadata": {}, |
317 | 318 | "outputs": [], |
318 | 319 | "source": [ |
319 | | - "s = calexpSrc.getColumnView()\n", |
320 | | - "coords = s.getX(), s.getY()" |
| 320 | + "coords = calexpSrc.getX(), calexpSrc.getY()" |
321 | 321 | ] |
322 | 322 | }, |
323 | 323 | { |
|
329 | 329 | "f\"Number of src detections is, {len(coords[1])}\"" |
330 | 330 | ] |
331 | 331 | }, |
332 | | - { |
333 | | - "cell_type": "markdown", |
334 | | - "metadata": {}, |
335 | | - "source": [ |
336 | | - "You can view an HTML rendering of the `src` table by getting an `astropy.table.Table` version of it. The coord columns are `coord_ra` and `coord_dec`" |
337 | | - ] |
338 | | - }, |
339 | 332 | { |
340 | 333 | "cell_type": "code", |
341 | 334 | "execution_count": null, |
342 | 335 | "metadata": {}, |
343 | 336 | "outputs": [], |
344 | 337 | "source": [ |
345 | 338 | "detections = hv.Points(coords).opts(\n", |
346 | | - " fill_color=None, size = 9, color=\"darkorange\")" |
| 339 | + " fill_color=None, size = 9, color=\"darkorange\")\n", |
| 340 | + "\n", |
| 341 | + "# Custom hover tool for the source detections\n", |
| 342 | + "detHoverTool = HoverTool(\n", |
| 343 | + " tooltips=[\n", |
| 344 | + " ( 'X', '@x'),\n", |
| 345 | + " ( 'Y', '@y'),\n", |
| 346 | + " ]\n", |
| 347 | + ")" |
347 | 348 | ] |
348 | 349 | }, |
349 | 350 | { |
350 | 351 | "cell_type": "markdown", |
351 | 352 | "metadata": {}, |
352 | 353 | "source": [ |
353 | | - "Now we overlay the detected sources on the image. The `*` operator is used to overlay one Element on to another. You can now mouse-over the sources and get information about the detections. " |
| 354 | + "Now we overlay the detected sources on the image. The `*` operator is used to overlay one Element on to another. " |
354 | 355 | ] |
355 | 356 | }, |
356 | 357 | { |
|
359 | 360 | "metadata": {}, |
360 | 361 | "outputs": [], |
361 | 362 | "source": [ |
362 | | - "rasterize(img) * detections" |
| 363 | + "# Reset the tools on the image and add a hover on the detections. \n", |
| 364 | + "rasterize(img.opts(tools=[])) * detections.opts(tools=[detHoverTool])" |
| 365 | + ] |
| 366 | + }, |
| 367 | + { |
| 368 | + "cell_type": "markdown", |
| 369 | + "metadata": {}, |
| 370 | + "source": [ |
| 371 | + "You can now mouse-over the sources and get the coordinates of the detections. " |
363 | 372 | ] |
364 | 373 | }, |
365 | 374 | { |
|
403 | 412 | "cell_type": "markdown", |
404 | 413 | "metadata": {}, |
405 | 414 | "source": [ |
406 | | - "Using the interactive callback features on the image plots, such as the selection box, we can explore regions of the image. Use the box select tool on the image above to select a region and then execute the cell below to get the box boundary coordinates. " |
| 415 | + "Using the interactive callback features on the image plots, such as the selection box (the icon of the box with a '+' in the lower right corner), we can explore regions of the image. Use the box select tool on the image above to select a region and then execute the cell below to get the box boundary coordinates. " |
407 | 416 | ] |
408 | 417 | }, |
409 | 418 | { |
|
419 | 428 | "cell_type": "markdown", |
420 | 429 | "metadata": {}, |
421 | 430 | "source": [ |
422 | | - "Here's another version of the image with a tap stream instead of box select. Try zooming in on an interesting part of the image and then click somewhere to place an 'X' marker. " |
| 431 | + "Here's another version of the image with a [tap stream](http://holoviews.org/reference/streams/bokeh/Tap.html) instead of box select. A Tap stream allows you to click or 'tap' a position to interact with a plot. Try zooming in on an interesting part of the image and then 'tap' somewhere to place an 'X' marker. " |
423 | 432 | ] |
424 | 433 | }, |
425 | 434 | { |
|
461 | 470 | " 1. Holoviews works with a wide range of plotting libraries, Bokeh, matplotlib, plotly, mpld3, pygal to name a few. As an exercise, try changing the Holoviews plotting library to be `matplotlib` instead of `bokeh` in the `Setup` cell at the beginning of the notebook with `hv.extension('matplotlib')`. You will see the holoviews + matplotlib icons displayed when the library is loaded successfully. Run the cells in section 2.1 again and compare the outputs. Try again with some other plotting library. Don't forget to set the plotting library back to whichever you prefer to use for the rest of this tutorial.\n", |
462 | 471 | " 2. In the image display sections, try using the coadd image instead of the calexp image. \n", |
463 | 472 | " \n", |
| 473 | + " 3. In section 2.3, try extracting additional information about the detected sources from the calexpSrc table and adding it to the custom hover tool. For example, the corresponding RA/DEC or the PSF flux. \n", |
| 474 | + " \n", |
464 | 475 | " 3. Try using a different stream function to interact with the images in section 3 " |
465 | 476 | ] |
466 | 477 | }, |
|
0 commit comments