{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# An interactive SMASH density map\n", "\n", "\n", "## Visualization\n", "In this notebook, we will use Datashader and Bokeh to make an interactive density map of SMASH all-sky photometry.\n", "\n", "## Known issues\n", "\n", "With this prototype notebook, there is not yet a way to clearly identify the field numbers or coordinates in the all sky plot." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Initialization\n", "\n", "We need modules from the Bokeh library, Datashader, NumPy, Pandas, and pyproj, as well as the Data Lab modules to connect to the database." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Start\n", "Got token anonymous.0.0.anon_access\n" ] } ], "source": [ "print \"Start\"\n", "import bokeh.plotting as bp\n", "from datashader.bokeh_ext import InteractiveImage\n", "from pyproj import Proj\n", "import numpy as np\n", "\n", "from cStringIO import StringIO\n", "from dl import authClient\n", "from dl import queryClient \n", "\n", "import pandas as pd\n", "import datashader as ds\n", "import datashader.glyphs\n", "import datashader.transfer_functions as tf\n", "\n", "\n", "# Get the security token for the datalab demo user\n", "token = authClient.login('anonymous')\n", "print \"Got token\",token" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Querying the SMASH DR1 catalog\n", "\n", "We will query the entire SMASH catalog, but with a somewhat restricted sharp, magnitude, and color range, as well as a limit on the depth flag, to limit the number of objects returned." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Your query is: select fieldid,ra,dec,gmag,rmag,depthflag from smash_dr1.object where (depthflag > 1 and (abs(sharp) < 0.5) and (gmag is not null) and (rmag is not null) and (gmag between 18 and 24) and ((gmag-rmag) between -1 and 3))\n", "Making query\n", "5445976 objects found.\n", "CPU times: user 4.27 s, sys: 875 ms, total: 5.15 s\n", "Wall time: 1min 1s\n" ] } ], "source": [ "%%time\n", "depth = 1 # minimum depth \n", "raname = 'ra'\n", "decname = 'dec'\n", "mags = 'gmag,rmag'\n", "dbase='smash_dr1.object'\n", "\n", "# Create the query string.\n", "query = ('select fieldid,'+raname+','+decname+','+mags+',depthflag from '+dbase+ \\\n", " ' where (depthflag > %d and ' + \\\n", " ' (abs(sharp) < 0.5) and ' + \\\n", " ' (gmag is not null) and (rmag is not null) and' + \\\n", " ' (gmag between 18 and 24) and ' + \\\n", " ' ((gmag-rmag) between -1 and 3))') % \\\n", " (depth)\n", " \n", "print \"Your query is:\", query\n", "print \"Making query\"\n", "\n", "# Call the Query Manager Service \n", "response = queryClient.query(token, adql = query, fmt = 'csv')\n", "df = pd.read_csv(StringIO(response))\n", "\n", "print len(df), \"objects found.\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Data munging\n", "\n", "We'll use our Pandas DataFrame to add a blue/red category for objects with colors bluer/redder than g-r=0.4, and use pyproj to project the coordinates to a Goode Homolosine projection." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", " | fieldid | \n", "ra | \n", "dec | \n", "gmag | \n", "rmag | \n", "depthflag | \n", "g_r | \n", "x | \n", "y | \n", "Class | \n", "
---|---|---|---|---|---|---|---|---|---|---|
5445971 | \n", "20 | \n", "35.705222 | \n", "-66.790792 | \n", "23.9966 | \n", "23.9193 | \n", "2 | \n", "0.0773 | \n", "-8.034689 | \n", "-7.163028 | \n", "Blue | \n", "
5445972 | \n", "20 | \n", "35.705774 | \n", "-66.789700 | \n", "23.8267 | \n", "23.5245 | \n", "2 | \n", "0.3022 | \n", "-8.034889 | \n", "-7.162933 | \n", "Blue | \n", "
5445973 | \n", "20 | \n", "35.696410 | \n", "-66.784513 | \n", "23.4505 | \n", "23.3245 | \n", "2 | \n", "0.1260 | \n", "-8.036501 | \n", "-7.162478 | \n", "Blue | \n", "
5445974 | \n", "20 | \n", "35.699459 | \n", "-66.783013 | \n", "23.4188 | \n", "23.2759 | \n", "2 | \n", "0.1429 | \n", "-8.036647 | \n", "-7.162346 | \n", "Blue | \n", "
5445975 | \n", "20 | \n", "35.669377 | \n", "-66.779954 | \n", "23.6111 | \n", "23.0070 | \n", "2 | \n", "0.6041 | \n", "-8.038966 | \n", "-7.162078 | \n", "Red | \n", "
\\n\"+\n", " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n", " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n", " \"
\\n\"+\n", " \"\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"
\\n\"+\n",
" \"