Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Began stellar streams tutorial #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
357 changes: 357 additions & 0 deletions tutorials/stellar_streams.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,357 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\\*\\* *(under construction. If you're using Binder, please note that this tutorial is only fully functional in Firefox at the moment.)* \\*\\*\n",
"\n",
"Adapted from [two](https://nbviewer.jupyter.org/github/marksubbarao/pyWWT_AAS225/blob/master/SgrStream.ipynb) [notebooks](https://nbviewer.jupyter.org/github/marksubbarao/pyWWT_AAS225/blob/master/CosmicFlows.ipynb) by Mark SubbaRao that use files from [here](http://faculty.virginia.edu/srm4n/Sgr/data.html) and visualize the tidal disruption of the Sagittarius Dwarf Galaxy by the Milky Way as described in [Law & Majewski 2010](https://iopscience.iop.org/article/10.1088/0004-637X/714/1/229)."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import time\n",
"\n",
"from astropy.coordinates import SkyCoord\n",
"from astropy import units as u\n",
"from astropy.table import Table, Column\n",
"from astropy.time import Time, TimeDelta\n",
"\n",
"import numpy as np\n",
"\n",
"from pywwt.jupyter import WWTJupyterWidget"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"wwt = WWTJupyterWidget()\n",
"wwt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*WWT works under HTTP, while Binder uses HTTPS. As such, in order to access all features of pywwt, Binder users will need to disable HTTPS for this session. Firefox users can do this with the following steps:*\n",
"- *Click the lock icon to the left of the address bar,*\n",
"- *Select the arrow next to “Connection,”*\n",
"- *Then, press the “Disable protection for now” button. (Protection is disabled for this page and only during this session, not for your whole browser. We are working on upgrading WWT so this step is no longer necessary.)*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Simulating a galaxy merger and plotting stellar streams"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(In this example, we a) simulate the position of the center of a dwarf galaxy during its near-merger with the Milky Way, and b) plot the positions of a snapshot of the resulting debris near the present day.)\n",
"\n",
"**First, we retrieve a table with time and position data for the Sagittarius Dwarf Galaxy from a `pywwt`-affiliated GitHub repository. Then, we cut it down to only the columns needed for this example and assign them their proper units.**"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"orbit = Table.read('https://raw.githubusercontent.com/WorldWideTelescope/pywwt-notebooks/master/tutorials/data/SgrTriax_orbit.dat',\n",
" format='ascii.basic')\n",
"#orbit = Table.read('SgrTriax_orbit.dat', format='ascii.basic')"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"orbit.keep_columns(['time', 'ra', 'dec', 'dist'])\n",
"orbit['ra'].unit = u.deg\n",
"orbit['dec'].unit = u.deg\n",
"orbit['time'].unit = u.Gyr\n",
"orbit['dist'] *= 1000\n",
"orbit['dist'].unit = u.pc"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**We'll also need to create a new column -- based on the original time column -- that converts and compresses our current gigayear times, which are too large for `pywwt` to simulate.** \n",
"\n",
"Instead, we'll convert them to Julian dates (which *are* readable by `pywwt`) and compress them so the action happens in a matter of seconds."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"# translate times from gigayears, which are too large for pywwt, ...\n",
"# to days -- so 1 day in the viewer translates to 1 gigayear real-time\n",
"\n",
"# T0-D0: find proper factor so that 1 gyr to translates to 10 seconds\n",
"base = Time('2019-01-01', format='iso').jd\n",
"orbit['wwt_times'] = base\n",
"orbit['wwt_times'] += orbit['time']"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<i>Table length=4266</i>\n",
"<table id=\"table140129295370280\" class=\"table-striped table-bordered table-condensed\">\n",
"<thead><tr><th>time</th><th>ra</th><th>dec</th><th>dist</th><th>wwt_times</th></tr></thead>\n",
"<thead><tr><th>Gyr</th><th>deg</th><th>deg</th><th>pc</th><th></th></tr></thead>\n",
"<thead><tr><th>float64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th></tr></thead>\n",
"<tr><td>-7.9961</td><td>29.7451</td><td>-8.51732</td><td>52743.6</td><td>2458476.5039</td></tr>\n",
"<tr><td>-7.9889</td><td>28.869</td><td>-8.92598</td><td>53198.1</td><td>2458476.5111</td></tr>\n",
"<tr><td>-7.9817</td><td>27.9937</td><td>-9.33262</td><td>53632.8</td><td>2458476.5183</td></tr>\n",
"<tr><td>-7.9744</td><td>27.1194</td><td>-9.73709</td><td>54049.6</td><td>2458476.5256</td></tr>\n",
"<tr><td>-7.9672</td><td>26.2453</td><td>-10.1392</td><td>54446.9</td><td>2458476.5328</td></tr>\n",
"<tr><td>-7.96</td><td>25.37</td><td>-10.5403</td><td>54826.799999999996</td><td>2458476.54</td></tr>\n",
"<tr><td>-7.9527</td><td>24.4935</td><td>-10.9395</td><td>55188.0</td><td>2458476.5473</td></tr>\n",
"<tr><td>-7.9455</td><td>23.6163</td><td>-11.3363</td><td>55531.5</td><td>2458476.5545</td></tr>\n",
"<tr><td>-7.9383</td><td>22.7355</td><td>-11.7326</td><td>55857.700000000004</td><td>2458476.5617</td></tr>\n",
"<tr><td>...</td><td>...</td><td>...</td><td>...</td><td>...</td></tr>\n",
"<tr><td>7.8936</td><td>266.154</td><td>-27.5093</td><td>65477.8</td><td>2458492.3936</td></tr>\n",
"<tr><td>7.9054</td><td>265.448</td><td>-26.9654</td><td>65230.7</td><td>2458492.4054</td></tr>\n",
"<tr><td>7.9166</td><td>264.78</td><td>-26.4471</td><td>64920.7</td><td>2458492.4166</td></tr>\n",
"<tr><td>7.9278</td><td>264.111</td><td>-25.923</td><td>64534.899999999994</td><td>2458492.4278</td></tr>\n",
"<tr><td>7.9389</td><td>263.438</td><td>-25.3915</td><td>64073.49999999999</td><td>2458492.4389</td></tr>\n",
"<tr><td>7.9501</td><td>262.759</td><td>-24.8513</td><td>63536.5</td><td>2458492.4501</td></tr>\n",
"<tr><td>7.9606</td><td>262.113</td><td>-24.3332</td><td>62960.9</td><td>2458492.4606</td></tr>\n",
"<tr><td>7.9711</td><td>261.457</td><td>-23.8042</td><td>62316.7</td><td>2458492.4711</td></tr>\n",
"<tr><td>7.9817</td><td>260.791</td><td>-23.2628</td><td>61603.299999999996</td><td>2458492.4817</td></tr>\n",
"<tr><td>7.9915</td><td>260.155</td><td>-22.7422</td><td>60871.299999999996</td><td>2458492.4915</td></tr>\n",
"</table>"
],
"text/plain": [
"<Table length=4266>\n",
" time ra dec dist wwt_times \n",
" Gyr deg deg pc \n",
"float64 float64 float64 float64 float64 \n",
"------- ------- -------- ------------------ ------------\n",
"-7.9961 29.7451 -8.51732 52743.6 2458476.5039\n",
"-7.9889 28.869 -8.92598 53198.1 2458476.5111\n",
"-7.9817 27.9937 -9.33262 53632.8 2458476.5183\n",
"-7.9744 27.1194 -9.73709 54049.6 2458476.5256\n",
"-7.9672 26.2453 -10.1392 54446.9 2458476.5328\n",
" -7.96 25.37 -10.5403 54826.799999999996 2458476.54\n",
"-7.9527 24.4935 -10.9395 55188.0 2458476.5473\n",
"-7.9455 23.6163 -11.3363 55531.5 2458476.5545\n",
"-7.9383 22.7355 -11.7326 55857.700000000004 2458476.5617\n",
" ... ... ... ... ...\n",
" 7.8936 266.154 -27.5093 65477.8 2458492.3936\n",
" 7.9054 265.448 -26.9654 65230.7 2458492.4054\n",
" 7.9166 264.78 -26.4471 64920.7 2458492.4166\n",
" 7.9278 264.111 -25.923 64534.899999999994 2458492.4278\n",
" 7.9389 263.438 -25.3915 64073.49999999999 2458492.4389\n",
" 7.9501 262.759 -24.8513 63536.5 2458492.4501\n",
" 7.9606 262.113 -24.3332 62960.9 2458492.4606\n",
" 7.9711 261.457 -23.8042 62316.7 2458492.4711\n",
" 7.9817 260.791 -23.2628 61603.299999999996 2458492.4817\n",
" 7.9915 260.155 -22.7422 60871.299999999996 2458492.4915"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"orbit"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*(You can see how our table looks now by typing `orbit` in a new cell above this one and running it.)*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Now, we can begin building the stellar streams table. The process is similar to the one for `orbit` -- importing the table, slim it down to the necessary columns, and give units to columns that need them.**"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# import and manipulate a table with stellar stream data\n",
"stars = Table.read('https://raw.githubusercontent.com/WorldWideTelescope/pywwt-notebooks/master/tutorials/data/SgrTriax_DYN.dat',\n",
" format='ascii.basic')\n",
"#stars = Table.read('data/SgrTriax_DYN.dat', format='ascii.basic')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"stars.keep_columns([\"ra\", \"dec\", \"dist\", \"Pcol\"])\n",
"stars['ra'].unit = u.deg\n",
"stars['dec'].unit = u.deg\n",
"stars['dist'] *= 1000\n",
"stars['dist'].unit = u.pc"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Next, we add a colormap column for pywwt to read in creating the data layer.** \n",
"\n",
"In Law & Majewski 2010, the authors color the tidal debris based on how many rotations it took before that patch of debris was stripped from its parent galaxy. We follow the same system, with the specific colors listed as comments below."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"stars['colormap'] = '#000000'\n",
"for i, val in enumerate(stars['Pcol']):\n",
" if val == -1:\n",
" stars['colormap'][i] = '#c0c0c0' # silver\n",
" elif val == 0 or val == 1:\n",
" stars['colormap'][i] = '#ffa500' # orange\n",
" elif val == 2 or val == 3:\n",
" stars['colormap'][i] = '#ff00ff' # magenta\n",
" elif val == 4 or val == 5:\n",
" stars['colormap'][i] = '#00ffff' # cyan\n",
" elif val == 6 or val == 7:\n",
" stars['colormap'][i] = '#228b22' # forest green"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Let's transition back to `pywwt` now that we have the tables we need for our data layers. Move the viewer down here and switch to the 3-D solar system view.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"wwt.set_view('solar system')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**As indicated in this tutorial's title, we have two visualizations to make. First, we'll plot the center of mass of the Sagittarius Dwarf Galaxy in order to simulate its tidal disruption by the Milky Way.**\n",
"\n",
"\\*\\* *(still under development, as we need working time series first)* \\*\\*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"orb_ly = wwt.layers.add_data_layer(table=orbit, frame='Sky',\n",
" lon_att='ra', lat_att='dec',\n",
" alt_att='dist', alt_type='distance',\n",
" size_scale=20)\n",
"\n",
"#wwt.play_time(...) # T0-D0: find proper rate at which to play time"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Once the simulation has concluded, delete this layer and pause the passage of time to make way for the next visualization."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"wwt.pause_time()\n",
"orb_ly.remove()\n",
"# wwt.play_time(1) # ??"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**In the second visualization, we plot a color-coded, present-day snapshot of the Sagittarius Dwarf's stellar streams.**\n",
"\n",
"Again, we link attributes to the proper columns, equip the proper distance setting, and choose our desired point size. (Each attribute is also editable after the layer is created.)\n",
"\n",
"For this one, we also set `far_side_visible` to `True` so we can see the debris even when it lies behind the Milky Way."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dbr_ly = wwt.layers.add_data_layer(table=stars, frame='Sky',\n",
" lon_att='ra', lat_att='dec',\n",
" alt_att='dist', alt_type='distance',\n",
" size_scale=40, far_side_visible=True)"
]
}
],
"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.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}