Loading and manipulating FITS files with pywwt

Import dependencies.

In [ ]:
from astroquery.skyview import SkyView
from pywwt.jupyter import WWTJupyterWidget

Layer FITS images over existing all-sky surveys.

We download a FITS image of a galaxy in the infrared using astroquery.

In [ ]:
size = 500
img_list = SkyView.get_images(position='SN 2011FE',
                              survey='2MASS-K', pixels=size)
In [ ]:
sn11 = img_list[0]

Load the image in pywwt.

In [ ]:
wwt = WWTJupyterWidget()

If you're using JupyterLab, right-click to the side of the viewer after it loads and select "Create New View for Output.":

Examine the area around the image by clicking and dragging the viewer or by pressing 'I', 'J', 'K', and 'L' as directional keys. Pinch in/out or press 'Z'/'X' to zoom.

In [ ]:
wwt.background = wwt.imagery.ir.twomass
wwt.foreground_opacity = 0
In [ ]:
img = wwt.layers.add_image_layer(sn11)

It's also possible to upload a local FITS image by providing the relative path to the file as the argument for add_image_layer() — see the additional content at the end of the notebook for an example.

Manipulate the image in pywwt.

We test different values for each of the image layer's attributes. We end by choosing background layers that help visualize the galaxy in three wavelengths at once.

In [ ]:
img.opacity = .4
In [ ]:
img.opacity = .6
In [ ]:
img.vmin = 360
In [ ]:
img.vmax = 370
In [ ]:
img.stretch = 'power'
In [ ]:
img.stretch = 'log'

Once we've adjusted the image to our liking, we can load visible and gamma-wavelength layers in the viewer via code...

In [ ]:
wwt.background = wwt.imagery.visible.sdss
wwt.foreground = wwt.imagery.gamma.fermi
wwt.foreground_opacity = .7

...or interactively through a Jupyter widget. It includes a slider for foreground opacity and respective drop-downs for the background and foreground layers.

In [ ]:

We can also continue to tinker with the FITS image layer through another interactive widget.

In [ ]:

Additional content: Load a local FITS image

As stated earlier, local FITS files are also fair game for add_image_layer(). You need only provide the path; pywwt does the rest of the work to open it up. To provide a view of M101 from yet another wavelength, we'll use an image from the Swift Soft X-ray Survey.

In [ ]:
img2 = wwt.layers.add_image_layer('../data/m101_swiftx.fits')

This file was also created with astroquery with the following code:

img_list2 = SkyView.get_images(position='SN 2011FE', survey='SwiftXRTCnt', pixels=140)`

This time, we'll leave the image manipulation process to you.

In [ ]:

You can find out more about adding layers in our documentation and contact us with any comments or questions at the WorldWide Telescope Forum or by opening an issue or pull request at pywwt's main GitHub repository. Thank you for trying out this example notebook on working with FITS images in pywwt.


This notebook was prepared by O. Justin Otor.