{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Creating Interactive Figures\n", "\n", "This notebook will demonstrate how you can use pywwt to create [interactive figures](https://journals.aas.org/graphics-guide/#interactive_figures) suitable for submission to a journal such as [*The Astrophysical Journal*](https://apj.aas.org/).\n", "\n", "**This won't work correctly with the new viewer!! pywwt won't have the right internal state.**\n" ] }, { "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 = await connect_to_app().becomes_ready()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We'll also set up a utility function to help us locate 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: Inserting Some Data\n", "\n", "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.\n", "\n", "We'll start by displaying a WISE 12µm image towards the [Westerhout 5 star forming region](https://en.wikipedia.org/wiki/Westerhout_5):\n", "\n", "" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "w5_img = wwt.layers.add_image_layer(datapath('w5.fits'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "w5_img.controls" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Likewise you can control the settings used for the all-sky contextual imagery:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wwt.layer_controls" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "## Step 3: Exporting to standalone HTML\n", "\n", "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](https://journals.aas.org/graphics-guide/#interactive_figures) in the AAS journals work!\n", "\n", "Once you've set up your viewer, exporting is easy:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wwt.save_as_html_bundle('figure.zip')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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.\n", "\n", "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." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "## Example 1: Submitting the figure to a journal\n", "\n", "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](journals.aas.org/). See [this blog post by Peter Williams](https://newton.cx/~peter/2019/creating-aas-interactive-figures/) for a detailed guide involving similar files created with the [AAS Timeseries Tool](https://aas-timeseries.readthedocs.io/)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "## Example 2: Including the figure on a personal website\n", "\n", "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 [`\n", " \n", "\n", "```\n", "\n", "Most of this is just boilerplate — the key is the `