{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Visualizing Image Data\n", "\n", "This notebook will demonstrate how to load and visualize astronomical images in the pywwt viewer." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "## Step 1: Setting up WWT\n", "\n", "First, we need to connect to the WWT app. If WWT isn't running yet, activate the JupyterLab command palette from the View menu, and select \"AAS WorldWide Telescope\". Then all we need to do is run:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pywwt.jupyter import connect_to_app\n", "wwt = connect_to_app()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now the `wwt` variable will let us talk to the WWT app.\n", "\n", "We'll also set up a utility function to help us load data files stored alongside this notebook:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def datapath(*args):\n", " from os.path import join\n", " return join('data', *args)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "## Step 2: Visualizing a Local FITS file\n", "\n", "We'll start by visualizing a WISE 12µm image towards the [Westerhout 5 star forming region](https://en.wikipedia.org/wiki/Westerhout_5) and taking a look at some of the advanced visualization options.\n", "\n", "Images, like data tables, are represented in WWT as \"layers\" that can be added to the view. With a standard FITS file, all you need to do is provide a pathname:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "layer = wwt.layers.add_image_layer(datapath('w5.fits'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The viewer will automatically center and zoom to the image you've loaded. You may get a warning from the `reproject` module; this can safely be ignored.\n", "\n", "\"Printing\" the following variable will create a set of widgets that let you adjust how the data are visualized:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "layer.controls" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The image color scaling is controlled by the sliders in the \"Fine min/max\" row; the \"Coarse min/max\" boxes control the bounds that are placed on the range of those sliders.\n", "\n", "You should try sliding the image opacity back and forth to check the agreement between the morphology of the W5 image and the WWT all-sky map.\n", "\n", "All of the parameters that are controlled by the widgets above can be manipulated programmatically as well. Let's set a bunch of them at once:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "layer.cmap = 'plasma'\n", "layer.vmin = 400\n", "layer.vmax = 1000\n", "layer.stretch = 'sqrt'\n", "layer.opacity = 0.9" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that the settings in the widgets adjusted automatically to match what you entered. Fancy!\n", "\n", "After you're done playing around, let's reset the WWT widget:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wwt.reset()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "## Step 3: Loading data from remote sources\n", "\n", "Because pywwt is a Python module, not a standalone application, it gains a lot of power by being able to integrate with other components of the modern, Web-oriented astronomical software ecosystem.\n", "\n", "For instance, it is easy to use the Python module [astroquery](https://astroquery.readthedocs.io/en/latest/) to load in data directly from archive queries, without the requirement to save any files locally. Let's fetch 2MASS Ks-band images of the field of supernova 2011fe. This might take a little while since the Python kernel needs to download the data from MAST.\n", "\n", "**Temporarily using SDSS-u instead of 2MASS-Ks since SkyView's 2MASS service is currently down. (2020 Nov)**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from astroquery.skyview import SkyView\n", "\n", "img_list = SkyView.get_images(\n", " position='SN 2011FE', \n", " survey='SDSSu', \n", " pixels=700 # you can adjust the size if you want\n", ")\n", "assert len(img_list) == 1 # there's only one matching item in this example\n", "twomass_img = img_list[0]\n", "twomass_img.info()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Once the FITS data are available, we can display them in pywwt using the same command as before:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "twomass_layer = wwt.layers.add_image_layer(twomass_img)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Once again you should see the view automatically center on your image. Let's adjust the background imagery to be more relevant:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wwt.background = wwt.imagery.ir.twomass\n", "wwt.foreground_opacity = 0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "pywwt provides interactive controls to let you adjust the parameters of the contextual imagery that's being shown. Try choosing different sets of all-sky imagery and adjusting the blend between them:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wwt.layer_controls" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here are some settings that we like:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wwt.background = wwt.imagery.visible.sdss\n", "wwt.foreground = wwt.imagery.gamma.fermi\n", "wwt.foreground_opacity = .5" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we'll load up another image of the same field that came from *Swift*, this time stored as a local file as in the previous step:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "swift_layer = wwt.layers.add_image_layer(datapath('m101_swiftx.fits'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create controls to adjust all of the visualization parameters. If you want to go wild, you can overlay data from four different wavelengths in this one view!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wwt.layer_controls" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "twomass_layer.controls" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "swift_layer.controls" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "## Next Steps\n", "\n", "To learn how to display data tables along with your imagery, start with the [NASA Exoplanet Archive](./NASA%20Exoplanet%20Archive.ipynb) tutorial" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "## Credits\n", "\n", "This notebook was prepared by:\n", "\n", "- O. Justin Otor\n", "- Thomas Robitaille\n", "- Peter K. G. Williams" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.6" } }, "nbformat": 4, "nbformat_minor": 4 }