This notebook will demonstrate some of what you can do with WWT’s clock using a dataset of gamma-ray burst events.
The first thing to do is to open up a pywwt window in this notebook session. As is generally the case, we have to start with some Python imports:
from pywwt.jupyter import WWTJupyterWidget
We'll also set up a utility function to help locate the data files stored alongside this notebook:
def datapath(*args):
from os.path import join
return join('data', *args)
Next, create a widget and display it inline. (That's why the final line is a bare wwt
.)
wwt = WWTJupyterWidget()
wwt
If everything is working correctly, the above command should create a pywwt viewer that looks mostly like a black box. If you’re using the JupyterLab environment rather than a plain Jupyter notebook, it is strongly recommended that you move the viewer to its own window pane so that you can have your code and viz side-by-side:
If you don't get a menu or the menu doesn’t look like the one pictured, you are probably not using JupyterLab and will have to move the viewer cell down as you work your way through the notebook. See the First Steps notebook for more information and troubleshooting tips if you don’t get a viewer at all.
Now that the viewer is set up, we need some data. First, some imports:
from astropy.coordinates import SkyCoord
from astropy.table import Table
from astropy.time import Time, TimeDelta
from astropy import units as u
from datetime import datetime
Now, we'll load up a table of GRB data. We'll print out the first few rows to get a sense of the data structure. In this case it's pretty simple.
bursts = Table.read(datapath('grb_table_lite.ecsv'), format='ascii.ecsv')
bursts[:5]
The WWT engine doesn't know enough to know that the Julian Date values above are actually dates (and not just some random floating-point measurements), so we convert them to the ISO8601 format:
bursts['dates_ISOT'] = Time(bursts['dates_JD'], format='jd').isot
bursts[:5]
layer = wwt.layers.add_table_layer(
table = bursts,
frame = 'Sky',
lon_att = 'ra', # treat the column named "ra" as a longitude coordinate
lat_att = 'dec', # likewise for the column named "dec"
size_scale=200
)
Now let's tell the engine that we want to pay attention to the time axis of the table. This will make all of the points disappear, since the engine's clock is synchronized to your computer — it's plotting data for the current year, and our GRBs only go up to 2014.
layer.time_series = True
layer.time_att = 'dates_ISOT'
We can check the engine's clock using the get_current_time()
method:
wwt.get_current_time()
Let's demonstrate that things are actually working by centering on the first GRB in both space and time — setting the WWT clock to just before it goes off.
first_grb = bursts[0]
start_pos = SkyCoord(first_grb['ra'], first_grb['dec'], unit=u.deg)
start_time = Time(first_grb['dates_ISOT'], format='isot') - TimeDelta(5 * u.second)
wwt.center_on_coordinates(start_pos)
wwt.set_current_time(start_time)
You should see a white dot appear in the screen center after five seconds!
The WWT timeseries support has the concept of a "decay time". Points that appear on the screen slowly fade over the decay timescale — according to the WWT simulation clock, that is, not wallclock time. The default is 16 days. That's a bit short for visualizing GRBs, so let's make it longer:
layer.time_decay = 1 * u.yr
Now, let's speed time up to see the GRBs pop off over time. If you find the right patch of the sky (namely, the ecliptic), you might also see the Sun and planets moving around at enhanced speed.
wwt.play_time(rate=3e6)
Once you've had your fill, the following function call will reset the clock to run at real time:
wwt.play_time()
How much time passed inside WWT?
wwt.get_current_time() - start_time
This notebook was prepared by:
With thanks to Mark SubbaRao for creating the first version of this demonstration.