{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Get import" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['', '/Users/tlinnet/anaconda/envs/py36/lib/python36.zip', '/Users/tlinnet/anaconda/envs/py36/lib/python3.6', '/Users/tlinnet/anaconda/envs/py36/lib/python3.6/lib-dynload', '/Users/tlinnet/anaconda/envs/py36/lib/python3.6/site-packages', '/Users/tlinnet/anaconda/envs/py36/lib/python3.6/site-packages/IPython/extensions', '/Users/tlinnet/.ipython', '/Users/tlinnet/software/drawnmr/examples/..']\n" ] } ], "source": [ "try:\n", " from drawnmr import draw\n", "except ModuleNotFoundError:\n", " import sys, os\n", " sys.path.append( os.getcwd()+os.sep+\"..\")\n", " print(sys.path)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Get import" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from drawnmr import draw\n", "import nmrglue as ng\n", "import bokeh.plotting as bplt\n", "from bokeh.models import Range1d" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Get data" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Get data\n", "import os, os.path\n", "ng_dir = 'nmrglue_data/s4_2d_plotting'\n", "if not os.path.exists(ng_dir):\n", " print(\"No %s. Downloading.\"%ng_dir)\n", " import urllib.request, zipfile\n", " zipf = 'jbnmr_s4_2d_plotting.zip'\n", " urllib.request.urlretrieve('https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/nmrglue/%s'%zipf, zipf)\n", " with zipfile.ZipFile(zipf,\"r\") as zip_ref:\n", " zip_ref.extractall(\"nmrglue_data\")\n", " os.remove(zipf)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Read data" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Specify data\n", "ng_ft2 = 'nmrglue_data/s4_2d_plotting/test.ft2'\n", "\n", "# read in data\n", "ng_dic, ng_data = ng.pipe.read(ng_ft2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Create figure" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Pass to figure class\n", "fig2d = draw.fig2d(ng_dic, ng_data)\n", "# Change contour_start\n", "fig2d.contour_start = 85e3\n", "\n", "# Get the bokeh figure\n", "fig= fig2d.get_fig()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Alter figure" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Alter the figure after creation\n", "#fig.xaxis.axis_label = \"Nonsense\"\n", "\n", "# Set limits for view\n", "fig.x_range = Range1d(183.5, 167.5)\n", "fig.y_range = Range1d(139.5, 95.5)\n", "\n", "# Set larger image size\n", "fig.plot_width = 800\n", "fig.plot_height = 800" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Get peaks" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " x_ppm y_ppm x_p y_p cID VOL zs\n", "0 175.266401 131.102998 4081 788 1 14297425.0 339577.93750\n", "1 173.809599 130.187133 4111 807 2 14197980.0 339726.21875\n", "2 174.295200 129.946116 4101 812 3 10963096.0 288179.81250\n", "3 173.081198 127.535946 4126 862 4 36947544.0 316585.34375\n", "4 175.217841 126.764691 4082 878 5 18468114.0 360951.87500\n" ] } ], "source": [ "peaks = fig2d.get_peakpick(pthres=200e3)\n", "print(peaks.head())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Show output" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " Loading BokehJS ...\n", "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", "(function(root) {\n", " function now() {\n", " return new Date();\n", " }\n", "\n", " var force = true;\n", "\n", " if (typeof (root._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n", " root._bokeh_onload_callbacks = [];\n", " root._bokeh_is_loading = undefined;\n", " }\n", "\n", "\n", " \n", " if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n", " root._bokeh_timeout = Date.now() + 5000;\n", " root._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 (root.Bokeh !== undefined) {\n", " var el = document.getElementById(\"a7c8396b-cb08-4b2d-a4e5-9efd96026b72\");\n", " if (el != null) {\n", " el.textContent = \"BokehJS \" + Bokeh.version + \" successfully loaded.\";\n", " }\n", " } else if (Date.now() < root._bokeh_timeout) {\n", " setTimeout(display_loaded, 100)\n", " }\n", " }\n", "\n", "\n", " function run_callbacks() {\n", " try {\n", " root._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n", " }\n", " finally {\n", " delete root._bokeh_onload_callbacks\n", " }\n", " console.info(\"Bokeh: all callbacks have finished\");\n", " }\n", "\n", " function load_libs(js_urls, callback) {\n", " root._bokeh_onload_callbacks.push(callback);\n", " if (root._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", " root._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", " root._bokeh_is_loading--;\n", " if (root._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(\"a7c8396b-cb08-4b2d-a4e5-9efd96026b72\");\n", " if (element == null) {\n", " console.log(\"Bokeh: ERROR: autoload.js configured with elementid 'a7c8396b-cb08-4b2d-a4e5-9efd96026b72' 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.7.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.7.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.7.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-gl-0.12.7.min.js\"];\n", "\n", " var inline_js = [\n", " function(Bokeh) {\n", " Bokeh.set_log_level(\"info\");\n", " },\n", " \n", " function(Bokeh) {\n", " \n", " },\n", " \n", " function(Bokeh) {\n", " \n", " document.getElementById(\"a7c8396b-cb08-4b2d-a4e5-9efd96026b72\").textContent = \"BokehJS is loading...\";\n", "\n", " },\n", " function(Bokeh) {\n", " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.7.min.css\");\n", " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.7.min.css\");\n", " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.7.min.css\");\n", " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.7.min.css\");\n", " console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.7.min.css\");\n", " Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.7.min.css\");\n", " }\n", " ];\n", "\n", " function run_inline_js() {\n", " \n", " if ((root.Bokeh !== undefined) || (force === true)) {\n", " for (var i = 0; i < inline_js.length; i++) {\n", " inline_js[i].call(root, root.Bokeh);\n", " }if (force === true) {\n", " display_loaded();\n", " }} else if (Date.now() < root._bokeh_timeout) {\n", " setTimeout(run_inline_js, 100);\n", " } else if (!root._bokeh_failed_load) {\n", " console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n", " root._bokeh_failed_load = true;\n", " } else if (force !== true) {\n", " var cell = $(document.getElementById(\"a7c8396b-cb08-4b2d-a4e5-9efd96026b72\")).parents('.cell').data().cell;\n", " cell.output_area.append_execute_result(NB_LOAD_WARNING)\n", " }\n", "\n", " }\n", "\n", " if (root._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", "}(window));" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "
\n", "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Get output. Either to Jupyter notebook or html file \n", "if fig2d.isnotebook:\n", " from bokeh.io import output_notebook\n", " output_notebook()\n", " bplt.show(fig, notebook_handle=True)\n", "else:\n", " # Save to html\n", " filename = \"nmrglue_s4_2d_plotting.html\"\n", " bplt.output_file(filename)\n", " bplt.save(fig)\n", " # And auto open\n", " import webbrowser, os\n", " webbrowser.open('file://' + os.path.realpath(filename))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Change graph upon modification of contour_start" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#fig2d.change_contour_start(200e3)" ] } ], "metadata": {}, "nbformat": 4, "nbformat_minor": 2 }