This notebook will demonstrate how you can use pywwt to create interactive figures suitable for submission to a journal such as The Astrophysical Journal.
The first thing to do is to open up pywwt in this notebook. Due to current technical limitations, the procedure is somewhat different than the one that we recommend for general usage. However, the beginning is the same as usual: a pywwt.jupyter
import:
from pywwt.jupyter import WWTJupyterWidget
We'll also set up a utility function to help us locate data files stored alongside this notebook:
def datapath(*args):
from os.path import join
return join('data', *args)
Next, we’ll create a viewer widget and display it inline. (That's why the final line is a bare wwt
.)
wwt = WWTJupyterWidget()
wwt
It might look like you got a black screen but it's probably OK. Click your mouse in the widget view and drag to either side. You should see the Milky Way scroll into view!
Unlike usual, we won't separate the viewer into its own pane, because that currently breaks the functionality demonstrated here. If you get annoyed with scrolling back and forth, you can drag the above cell down as you work your way through the notebook.
An interactive figure should presumably have some data in it to show off. Here, we'll just load up some of the data used in the other tutorials to show the general principles.
We'll start by displaying a WISE 12µm image towards the Westerhout 5 star forming region:
w5_img = wwt.layers.add_image_layer(datapath('w5.fits'))
Now is a good time to play around with the visualization parameters of the image, if you'd like. Executing the following line will create some UI elements that let you tune the colormap, stretch, and so on:
w5_img.controls
Likewise you can control the settings used for the all-sky contextual imagery:
wwt.layer_controls
pywwt, like all Jupyter widgets, is at its heart web-based. We've been working on building the technology to extract the visualizations that you create from Jupyter into standalone web assets that can be included anywhere that you can host HTML + JavaScript + CSS. This trio of technologies is exactly how interactive figures in the AAS journals work!
Once you've set up your viewer, exporting is easy:
wwt.save_as_html_bundle('figure.zip')
After a few seconds, you should see a file named figure.zip
appear in the folder view sidebar to the left of this notebook. What's cool is that even if you're running this notebook in the cloud, you can right-click that file and select "Download" to save the Zip bundle to your local machine.
If you were to open up this Zip file and inspect its contents, you'd see that it contains an index.html
file, some JavaScript, and a data
directory containing a FITS file correspond to the image that you just loaded into your view.
It’s a bit beyond the scope of this notebook to describe the full submission process here. But the key thing is that the figure.zip
file has virtually everything you need to include an interacting figure in an AAS journal. See this blog post by Peter Williams for a detailed guide involving similar files created with the AAS Timeseries Tool.
The same files that you submit to a journal can also be included on your own website, if your authoring platform allows you to upload arbitrary files and use HTML <iframe>
tags. Here’s a minimal sample HTML file, assuming that you have unpacked your Zip bundle into a directory named my_figure
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<style type="text/css">
.intfig { width: 600px; height: 400px; }
</style>
</head>
<body>
<h1>Welcome to My Personal Webpage</h1>
<p>Explore the data from my latest paper!</p>
<iframe class="intfig" src="my_figure/index.html">
<p>Unfortunately your browser doesn’t support iframes.</p>
</iframe>
</body>
</html>
Most of this is just boilerplate — the key is the <iframe>
line and the CSS styling that sets it to the correct size.
If you have Node.js installed on your computer, you can view your exported interactive figure in a relatively straightforward way:
cd
to the unpacked directory (the one containing index.html
).npx http-server
Note: alas, we have a race condition bug that sometimes pops up here. You might need to reload the page for all of your data to appear.
Other one-liner web servers might work, but not all of them serve files with the correct Content-Type
headers, which is needed for everything to work here.
To learn more about how to load image data into pywwt, check out the Visualizing Imagery tutorial.