{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# A demonstration of Star/Galaxy separation in the SMASH catalog\n", "In this notebook, we will query the SMASH DR1 catalog and apply constraints on the \"sharp\" and \"prob\" parameters to demonstrate ways to create samples of likely stars and galaxies.\n", "\n", "## Visualization\n", "We will use Datashader and Bokeh to make fast interactive plots.\n", "\n", "## Known issues\n", "The color-magnitude diagram is plotted upside-down from the usual sense due to a current limitation in the notebook's use of Datashader." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Initialization\n", "\n", "We need modules from the Bokeh library, Datashader, NumPy, and Pandas, as well as the Data Lab modules to connect to and query 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", "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", "import bokeh.plotting as bp\n", "from datashader.bokeh_ext import InteractiveImage\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 SMASH catalog over a range of fields to sample a variety of field properties. We set a constraint on the depthflag parameter to insist on detection in the deep exposures. To make the query go faster, one can restrict the range of fieldid in the query. The default field range will return roughly 6 million objects." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Your query is: select ra,dec,gmag,rmag,sharp,chi,prob from smash_dr1.object where (depthflag > 1 and (gmag is not null) and (fieldid>55 and fieldid<70))\n", "Making query\n", "6392274 objects found.\n", "CPU times: user 6.57 s, sys: 1.33 s, total: 7.9 s\n", "Wall time: 46.5 s\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 '+raname+','+decname+','+mags+',sharp,chi,prob from '+dbase+ \\\n", " ' where (depthflag > %d and ' + \\\n", " ' (gmag is not null) and ' + \\\n", " ' (fieldid>55 and fieldid<70))') % \\\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": [ "### Making cuts on parameters to separate stars from galaxies\n", "\n", "We will first make a single cut on the sharp parameter, and classify objects with sharp>0.7 as galaxies. Pandas allows us to add a Class column to the dataframe and specify that it should be considered a category. We will also add a g_r column to the Pandas dataframe." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
radecgmagrmagsharpchiprobClassg_r
6392269107.060693-54.16388099.9999.99-0.8460.780.73Galaxy0.0
6392270107.059618-54.16621999.9999.990.9650.710.92Galaxy0.0
6392271107.058524-54.16643399.9999.990.7780.830.56Galaxy0.0
6392272107.058557-54.16668499.9999.993.2600.970.96Galaxy0.0
6392273107.059356-54.16024699.9999.990.3350.590.72Star0.0
\n", "
" ], "text/plain": [ " ra dec gmag rmag sharp chi prob Class g_r\n", "6392269 107.060693 -54.163880 99.99 99.99 -0.846 0.78 0.73 Galaxy 0.0\n", "6392270 107.059618 -54.166219 99.99 99.99 0.965 0.71 0.92 Galaxy 0.0\n", "6392271 107.058524 -54.166433 99.99 99.99 0.778 0.83 0.56 Galaxy 0.0\n", "6392272 107.058557 -54.166684 99.99 99.99 3.260 0.97 0.96 Galaxy 0.0\n", "6392273 107.059356 -54.160246 99.99 99.99 0.335 0.59 0.72 Star 0.0" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sharpthresh=0.7\n", "df[\"Class\"]='Star'\n", "df.loc[(abs(df[\"sharp\"])>sharpthresh),\"Class\"]='Galaxy'\n", "df[\"Class\"]=df[\"Class\"].astype('category')\n", "df[\"g_r\"]=df[\"gmag\"]-df[\"rmag\"]\n", "df.tail()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Displaying the results of our cut\n", "\n", "We now use Datashader and Bokeh to make an interactive plot of g magnitude vs. chi. Datashader assigns different colors to each category, in this case blue for objects labeled stars, and red for objects labeled galaxies. The plot shows that the sharp cut separates two sequences in the magnitude-chi plane, with galaxies having larger chi values. One might be tempted to use chi as an additional constraint. However, at bright magnitudes the chi for stars clearly increases, while at bright magnitudes the sequences overlap in chi. The sharp cut likely confuses some stars and galaxies, especially at faint magnitudes. One could increase the sharp threshold for a more complete star sample, or decrease it for a more pure one." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " Loading BokehJS ...\n", "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function(global) {\n", " function now() {\n", " return new Date();\n", " }\n", "\n", " var force = \"1\";\n", "\n", " if (typeof (window._bokeh_onload_callbacks) === \"undefined\" || force !== \"\") {\n", " window._bokeh_onload_callbacks = [];\n", " window._bokeh_is_loading = undefined;\n", " }\n", "\n", "\n", " \n", " if (typeof (window._bokeh_timeout) === \"undefined\" || force !== \"\") {\n", " window._bokeh_timeout = Date.now() + 5000;\n", " window._bokeh_failed_load = false;\n", " }\n", "\n", " var NB_LOAD_WARNING = {'data': {'text/html':\n", " \"
\\n\"+\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", " \"\\n\"+\n", " \"from bokeh.resources import INLINE\\n\"+\n", " \"output_notebook(resources=INLINE)\\n\"+\n", " \"\\n\"+\n", " \"
\"}};\n", "\n", " function display_loaded() {\n", " if (window.Bokeh !== undefined) {\n", " Bokeh.$(\"#9588ea37-3cbf-4b4c-84eb-0002a8e089ce\").text(\"BokehJS successfully loaded.\");\n", " } else if (Date.now() < window._bokeh_timeout) {\n", " setTimeout(display_loaded, 100)\n", " }\n", " }\n", "\n", " function run_callbacks() {\n", " window._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n", " delete window._bokeh_onload_callbacks\n", " console.info(\"Bokeh: all callbacks have finished\");\n", " }\n", "\n", " function load_libs(js_urls, callback) {\n", " window._bokeh_onload_callbacks.push(callback);\n", " if (window._bokeh_is_loading > 0) {\n", " console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", " return null;\n", " }\n", " if (js_urls == null || js_urls.length === 0) {\n", " run_callbacks();\n", " return null;\n", " }\n", " console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", " window._bokeh_is_loading = js_urls.length;\n", " for (var i = 0; i < js_urls.length; i++) {\n", " var url = js_urls[i];\n", " var s = document.createElement('script');\n", " s.src = url;\n", " s.async = false;\n", " s.onreadystatechange = s.onload = function() {\n", " window._bokeh_is_loading--;\n", " if (window._bokeh_is_loading === 0) {\n", " console.log(\"Bokeh: all BokehJS libraries loaded\");\n", " run_callbacks()\n", " }\n", " };\n", " s.onerror = function() {\n", " console.warn(\"failed to load library \" + url);\n", " };\n", " console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", " }\n", " };var element = document.getElementById(\"9588ea37-3cbf-4b4c-84eb-0002a8e089ce\");\n", " if (element == null) {\n", " console.log(\"Bokeh: ERROR: autoload.js configured with elementid '9588ea37-3cbf-4b4c-84eb-0002a8e089ce' but no matching script tag was found. \")\n", " return false;\n", " }\n", "\n", " var js_urls = ['https://cdn.pydata.org/bokeh/release/bokeh-0.12.3.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.3.min.js'];\n", "\n", " var inline_js = [\n", " function(Bokeh) {\n", " Bokeh.set_log_level(\"info\");\n", " },\n", " \n", " function(Bokeh) {\n", " \n", " Bokeh.$(\"#9588ea37-3cbf-4b4c-84eb-0002a8e089ce\").text(\"BokehJS is loading...\");\n", " },\n", " function(Bokeh) {\n", " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.3.min.css\");\n", " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.3.min.css\");\n", " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.3.min.css\");\n", " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.3.min.css\");\n", " }\n", " ];\n", "\n", " function run_inline_js() {\n", " \n", " if ((window.Bokeh !== undefined) || (force === \"1\")) {\n", " for (var i = 0; i < inline_js.length; i++) {\n", " inline_js[i](window.Bokeh);\n", " }if (force === \"1\") {\n", " display_loaded();\n", " }} else if (Date.now() < window._bokeh_timeout) {\n", " setTimeout(run_inline_js, 100);\n", " } else if (!window._bokeh_failed_load) {\n", " console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n", " window._bokeh_failed_load = true;\n", " } else if (!force) {\n", " var cell = $(\"#9588ea37-3cbf-4b4c-84eb-0002a8e089ce\").parents('.cell').data().cell;\n", " cell.output_area.append_execute_result(NB_LOAD_WARNING)\n", " }\n", "\n", " }\n", "\n", " if (window._bokeh_is_loading === 0) {\n", " console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", " run_inline_js();\n", " } else {\n", " load_libs(js_urls, function() {\n", " console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n", " run_inline_js();\n", " });\n", " }\n", "}(this));" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "/dl1/sw/anaconda2/lib/python2.7/site-packages/datashader/transfer_functions.py:258: RuntimeWarning: invalid value encountered in true_divide\n", " r = (data.dot(rs)/total).astype(np.uint8)\n", "/dl1/sw/anaconda2/lib/python2.7/site-packages/datashader/transfer_functions.py:259: RuntimeWarning: invalid value encountered in true_divide\n", " g = (data.dot(gs)/total).astype(np.uint8)\n", "/dl1/sw/anaconda2/lib/python2.7/site-packages/datashader/transfer_functions.py:260: RuntimeWarning: invalid value encountered in true_divide\n", " b = (data.dot(bs)/total).astype(np.uint8)\n" ] }, { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "
\n", "" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bp.output_notebook()\n", "p = bp.figure(tools='pan,wheel_zoom,box_zoom,reset',x_range=(14,26), y_range=(0,5))\n", "p.xaxis.axis_label='gmag'\n", "p.yaxis.axis_label='chi'\n", "\n", "def image_callback(x_range, y_range, w, h):\n", " cvs = ds.Canvas(plot_width=w, plot_height=h, x_range=x_range, y_range=y_range)\n", " agg = cvs.points(df, 'gmag', 'chi', ds.count_cat('Class'))\n", " img = tf.shade(agg, how='log')\n", " return tf.dynspread(img, how='add',threshold=0.5)\n", "\n", "InteractiveImage(p, image_callback)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Effect of our cut on the CMD\n", "\n", "Here we make an additional interactive plot featureing the g-r,g color-magnitude diagram. Note that the CMD is upside down from the usual sense." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "
\n", "" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = bp.figure(tools='pan,wheel_zoom,box_zoom,reset',x_range=(-2,3), y_range=(14,26))\n", "p.xaxis.axis_label='gmag-rmag'\n", "p.yaxis.axis_label='gmag'\n", "\n", "def image_callback(x_range, y_range, w, h):\n", " cvs = ds.Canvas(plot_width=w, plot_height=h, x_range=x_range, y_range=y_range)\n", " agg = cvs.points(df, 'g_r', 'gmag', ds.count_cat('Class'))\n", " img = tf.shade(agg, how='log')\n", " return tf.dynspread(img, how='add',threshold=0.5)\n", "\n", "InteractiveImage(p, image_callback)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Making a cut on both sharp and prob to get a cleaner sample of galaxies\n", "\n", "The simple sharp>0.7 cut potentially labels faint junk objects as galaxies. We will add a second cut on the prob parameter, which derives from SExtractor's Stellaricity Index, to get a cleaner sample of galaxies." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
radecgmagrmagsharpchiprobClassg_r
6392269107.060693-54.16388099.9999.99-0.8460.780.73Star0.0
6392270107.059618-54.16621999.9999.990.9650.710.92Star0.0
6392271107.058524-54.16643399.9999.990.7780.830.56Star0.0
6392272107.058557-54.16668499.9999.993.2600.970.96Star0.0
6392273107.059356-54.16024699.9999.990.3350.590.72Star0.0
\n", "
" ], "text/plain": [ " ra dec gmag rmag sharp chi prob Class g_r\n", "6392269 107.060693 -54.163880 99.99 99.99 -0.846 0.78 0.73 Star 0.0\n", "6392270 107.059618 -54.166219 99.99 99.99 0.965 0.71 0.92 Star 0.0\n", "6392271 107.058524 -54.166433 99.99 99.99 0.778 0.83 0.56 Star 0.0\n", "6392272 107.058557 -54.166684 99.99 99.99 3.260 0.97 0.96 Star 0.0\n", "6392273 107.059356 -54.160246 99.99 99.99 0.335 0.59 0.72 Star 0.0" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sharpthresh=0.7\n", "probthresh=0.2\n", "df[\"Class\"]='Star'\n", "df.loc[(abs(df[\"sharp\"])>sharpthresh) & (df[\"prob\"]\n", " \n", " Loading BokehJS ...\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function(global) {\n", " function now() {\n", " return new Date();\n", " }\n", "\n", " var force = \"1\";\n", "\n", " if (typeof (window._bokeh_onload_callbacks) === \"undefined\" || force !== \"\") {\n", " window._bokeh_onload_callbacks = [];\n", " window._bokeh_is_loading = undefined;\n", " }\n", "\n", "\n", " \n", " if (typeof (window._bokeh_timeout) === \"undefined\" || force !== \"\") {\n", " window._bokeh_timeout = Date.now() + 5000;\n", " window._bokeh_failed_load = false;\n", " }\n", "\n", " var NB_LOAD_WARNING = {'data': {'text/html':\n", " \"
\\n\"+\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", " \"
  • re-rerun `output_notebook()` to attempt to load from CDN again, or
  • \\n\"+\n", " \"
  • use INLINE resources instead, as so:
  • \\n\"+\n", " \"
\\n\"+\n", " \"\\n\"+\n", " \"from bokeh.resources import INLINE\\n\"+\n", " \"output_notebook(resources=INLINE)\\n\"+\n", " \"\\n\"+\n", " \"
\"}};\n", "\n", " function display_loaded() {\n", " if (window.Bokeh !== undefined) {\n", " Bokeh.$(\"#fcc3ff87-7860-4ef0-b91c-a0b1d7a62aed\").text(\"BokehJS successfully loaded.\");\n", " } else if (Date.now() < window._bokeh_timeout) {\n", " setTimeout(display_loaded, 100)\n", " }\n", " }\n", "\n", " function run_callbacks() {\n", " window._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n", " delete window._bokeh_onload_callbacks\n", " console.info(\"Bokeh: all callbacks have finished\");\n", " }\n", "\n", " function load_libs(js_urls, callback) {\n", " window._bokeh_onload_callbacks.push(callback);\n", " if (window._bokeh_is_loading > 0) {\n", " console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n", " return null;\n", " }\n", " if (js_urls == null || js_urls.length === 0) {\n", " run_callbacks();\n", " return null;\n", " }\n", " console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n", " window._bokeh_is_loading = js_urls.length;\n", " for (var i = 0; i < js_urls.length; i++) {\n", " var url = js_urls[i];\n", " var s = document.createElement('script');\n", " s.src = url;\n", " s.async = false;\n", " s.onreadystatechange = s.onload = function() {\n", " window._bokeh_is_loading--;\n", " if (window._bokeh_is_loading === 0) {\n", " console.log(\"Bokeh: all BokehJS libraries loaded\");\n", " run_callbacks()\n", " }\n", " };\n", " s.onerror = function() {\n", " console.warn(\"failed to load library \" + url);\n", " };\n", " console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n", " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", " }\n", " };var element = document.getElementById(\"fcc3ff87-7860-4ef0-b91c-a0b1d7a62aed\");\n", " if (element == null) {\n", " console.log(\"Bokeh: ERROR: autoload.js configured with elementid 'fcc3ff87-7860-4ef0-b91c-a0b1d7a62aed' but no matching script tag was found. \")\n", " return false;\n", " }\n", "\n", " var js_urls = ['https://cdn.pydata.org/bokeh/release/bokeh-0.12.3.min.js', 'https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.3.min.js'];\n", "\n", " var inline_js = [\n", " function(Bokeh) {\n", " Bokeh.set_log_level(\"info\");\n", " },\n", " \n", " function(Bokeh) {\n", " \n", " Bokeh.$(\"#fcc3ff87-7860-4ef0-b91c-a0b1d7a62aed\").text(\"BokehJS is loading...\");\n", " },\n", " function(Bokeh) {\n", " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.3.min.css\");\n", " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.3.min.css\");\n", " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.3.min.css\");\n", " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.3.min.css\");\n", " }\n", " ];\n", "\n", " function run_inline_js() {\n", " \n", " if ((window.Bokeh !== undefined) || (force === \"1\")) {\n", " for (var i = 0; i < inline_js.length; i++) {\n", " inline_js[i](window.Bokeh);\n", " }if (force === \"1\") {\n", " display_loaded();\n", " }} else if (Date.now() < window._bokeh_timeout) {\n", " setTimeout(run_inline_js, 100);\n", " } else if (!window._bokeh_failed_load) {\n", " console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n", " window._bokeh_failed_load = true;\n", " } else if (!force) {\n", " var cell = $(\"#fcc3ff87-7860-4ef0-b91c-a0b1d7a62aed\").parents('.cell').data().cell;\n", " cell.output_area.append_execute_result(NB_LOAD_WARNING)\n", " }\n", "\n", " }\n", "\n", " if (window._bokeh_is_loading === 0) {\n", " console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n", " run_inline_js();\n", " } else {\n", " load_libs(js_urls, function() {\n", " console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n", " run_inline_js();\n", " });\n", " }\n", "}(this));" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "
\n", "" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bp.output_notebook()\n", "p = bp.figure(tools='pan,wheel_zoom,box_zoom,reset',x_range=(14,26), y_range=(0,5))\n", "p.xaxis.axis_label='gmag'\n", "p.yaxis.axis_label='chi'\n", "\n", "def image_callback(x_range, y_range, w, h):\n", " cvs = ds.Canvas(plot_width=w, plot_height=h, x_range=x_range, y_range=y_range)\n", " agg = cvs.points(df, 'gmag', 'chi', ds.count_cat('Class'))\n", " img = tf.shade(agg, how='log')\n", " return tf.dynspread(img, how='add',threshold=0.5)\n", "\n", "InteractiveImage(p, image_callback)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "
\n", "" ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p = bp.figure(tools='pan,wheel_zoom,box_zoom,reset',x_range=(-2,3), y_range=(14,26))\n", "p.xaxis.axis_label='gmag-rmag'\n", "p.yaxis.axis_label='gmag'\n", "\n", "def image_callback(x_range, y_range, w, h):\n", " cvs = ds.Canvas(plot_width=w, plot_height=h, x_range=x_range, y_range=y_range)\n", " agg = cvs.points(df, 'g_r', 'gmag', ds.count_cat('Class'))\n", " img = tf.shade(agg, how='log')\n", " return tf.dynspread(img, how='add',threshold=0.5)\n", "\n", "InteractiveImage(p, image_callback)" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.13" } }, "nbformat": 4, "nbformat_minor": 2 }