Skip to content

Instantly share code, notes, and snippets.

@zonca
Created October 14, 2015 07:16
Show Gist options
  • Save zonca/9fb017ad4a5587269067 to your computer and use it in GitHub Desktop.
Save zonca/9fb017ad4a5587269067 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{"worksheets": [{"cells": [{"cell_type": "markdown", "metadata": {}, "source": "<div class=\"clearfix\" style=\"padding: 10px; padding-left: 0px\">\n<img src=\"https://cloud.githubusercontent.com/assets/836375/4911394/dd819b7e-648c-11e4-8c6d-755b9d4d9ea3.png\" width=\"150px\" style=\"display: inline-block; margin-top: 5px;\">\n<a href=\"http://bit.ly/naturedevplus\"><img src=\"https://cloud.githubusercontent.com/assets/836375/4916141/2732892e-64d6-11e4-980f-11afcf03ca31.png\" width=\"150px\" class=\"pull-right\" style=\"display: inline-block; margin: 0px;\"></a>\n</div>"}, {"cell_type": "markdown", "metadata": {}, "source": "# Introduction"}, {"cell_type": "markdown", "metadata": {}, "source": "Welcome! You have just launched a live example of an IPython Notebook. The notebook is an open-source, interactive computing environment that lets you combine live code, narrative text, mathematics, plots and rich media in one document. Notebook documents provide a complete reproducible record of a computation and its results and can be shared with colleagues (through, for example, email, web-hosting services such as GitHub, Dropbox, and [nbviewer](http://nbviewer.ipython.org)).\n\nYou can edit anything in this temporary demonstration notebook, including the text you are reading. To see it full-screen, click on the 'Expand' icon in the lower right corner of the frame around this notebook. \n\nThis notebook showcases some of IPython's capabilities for researchers.\n\nThis demonstration is hosted by [Rackspace](http://bit.ly/naturedevplus) and is running on its bare metal offering, [OnMetal](http://www.rackspace.com/cloud/servers/onmetal/). Try out these cloud services yourself through [Rackspace's developer+ page](http://bit.ly/naturedevplus)."}, {"cell_type": "markdown", "metadata": {}, "source": "## Basic Python code and plotting"}, {"cell_type": "markdown", "metadata": {}, "source": "The box below (known as a code cell) contains the Python code to plot $y=x^2$ over the range $[0,5]$. The blue comments preceded by `#` explain what the code does.\n\nTo run the code:\n\n1. Click on the cell to select it.\n2. Press `SHIFT+ENTER` on your keyboard or press the play button (<button class='fa fa-play icon-play btn btn-xs btn-default'></button>) in the toolbar above.\n\nA full tutorial for using the notebook interface is available [here](http://nbviewer.ipython.org/github/ipython/ipython/blob/2.x/examples/Notebook/Index.ipynb)."}, {"cell_type": "code", "outputs": [{"text": "<matplotlib.figure.Figure at 0x7fe1c553f828>", "metadata": {}, "png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAEdCAYAAADgjbcLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHlZJREFUeJzt3XecnGW99/HPN/SmgYMmBIKAdEFDRwJk6b0rTR6qAo9S\nghRpLwmHcxBQylERjg8BCxBAeOgtEQgHpENCR0ESehKkSJAOv/PHdS9ZJrvZ2c3MXPfMfN+v17x2\nZnbmvn87Sb575bqvoojAzMzaw4DcBZiZWeM49M3M2ohD38ysjTj0zczaiEPfzKyNOPTNzNqIQ9/M\nrI049M3M2sicuQsws+YjaTlgFeCbwPUR8UjmkqxKbulbw0h6QtKGdTjuZEmb1Pq4tVbLOiWtIGmi\npHckHVKLY/bRtsArwFnAURnOb/3klr5VTdJ4UstucER81Nf3R8QqNS+qOHRxK7ta1nkMcFtEDKvR\n8fokIs4GkLQyMClHDdY/bulbVSQtBawNTAO2z1pMJpLK1Ej6GvBU7iKAnYD/zF2EVc+hb9XaG/gz\n8Edgn1m9UNJPJL1cdD08I2mj4vnJkjbucv8oSY9Jmi5ptKRBkm6W9E9J4yQN7HLMyZKOlfSkpDcl\nXShpnh7OP0TSVZKmSXpe0qGzqHV1SROKWq+QdLmkUyrOe4ykx4B3JZ0g6bni9U9K2rHieL3VuZqk\nRyW9Lemynn6G4lgrSRov6a2ia2y74vnbgQ7g10Udy87ij6NuJG0P/BJYPMf5rZ8iwjffer0BzwHf\nA5YDPgK+2sPrVgBeJHUBASwJLFPcnwRsXNyfDNwDfAUYAkwFHgG+BcwD3Ab8tMtxJwOPkQJmYeBu\n4JRujjsAeBg4kdR9u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XrEqSTgHm\nBeYDXoqI0zOXZNZnDn2zKhUrfT4EvA98O/yPx5qQu3fMqrcosACwIKm1b9Z03NI3q5Kk64BLgWWA\nxSLi0MwlmfXZnLkLMGsGkvYGPoyIyyQNAO6R1BER4zOXZtYnbumbmbUR9+mbmbURh76ZWRtx6JuZ\ntRGHvplZG3Hom5m1EYe+mVkbceibmbURh76ZWRv5X9o7XVxOTPSMAAAAAElFTkSuQmCC\n", "output_type": "display_data"}], "prompt_number": 1, "input": "# Import matplotlib (plotting) and numpy (numerical arrays).\n# This enables their use in the Notebook.\n%matplotlib inline\nimport matplotlib.pyplot as plt \nimport numpy as np\n\n# Create an array of 30 values for x equally spaced from 0 to 5. \nx = np.linspace(0, 5, 30)\ny = x**2\n\n# Plot y versus x\nfig, ax = plt.subplots(nrows=1, ncols=1)\nax.plot(x, y, color='red')\nax.set_xlabel('x')\nax.set_ylabel('y')\nax.set_title('A simple graph of $y=x^2$');", "metadata": {"trusted": true}, "collapsed": false, "language": "python"}, {"cell_type": "markdown", "metadata": {}, "source": "Above, you should see a plot of $y=x^2$.\n\nYou can edit this code and re-run it. For example, try replacing `y = x**2` with `y=np.sin(x)`. For a list of valid functions, see the [NumPy Reference Manual](http://docs.scipy.org/doc/numpy/reference/routines.math.html). You can also update the plot title and axis labels.\n\nText in the plot as well as narrative text in the notebook can contain equations that are formatted using $\\LaTeX$. To edit text written in $\\LaTeX$, double click on the text or press `ENTER` when the text is selected."}, {"cell_type": "markdown", "metadata": {}, "source": "## Interactive illustration of aliasing"}, {"cell_type": "markdown", "metadata": {}, "source": "Notebooks can also link code and data to user interfaces (such as sliders, checkboxes, dropdowns) that facilitate interactive exploration.\n\nAron Ahmadia (Coastal & Hydraulics Laboratory at the US Army Engineer Research and Development Center) and David Ketcheson (King Abdullah University of Science & Technology) created the following example to illustrate the perils of aliasing, which occurs when a rapidly-changing periodic signal is sampled too infrequently, and creates a false impression of the true frequency of the signal. \n\nKetcheson explains:\n\n> \"As an undergraduate, I did some observational astronomy looking at variable stars.\n> These are stars whose brightness oscillates, usually on a fairly regular basis. \n> Many published results claim to measure how quickly the star's brightness oscillates - \n> but actually report the oscillations at some multiple of the real answer, owing to\n> insufficient observation and (as a result) aliasing.\"\n\nThis example shows how trying to reconstruct a simple sine wave signal from discrete measurements can fail. The sliders allow you to adjust the frequency of the underlying periodic sine wave signal (represented by `frequency`), and also how often the signal is sampled (represented by `grid_points`). Get it wrong, and a high-frequency sine wave is measured as a lower-frequency signal.\n\nTo see the effects of aliasing:\n\n1. Run the next cell, then set the `grid_points` slider to `13`.\n2. Move the `frequency` slider to values above `10`.\n3. As the frequency increases, the measured signal (blue) has a lower frequency than the real one (red)."}, {"cell_type": "code", "outputs": [], "input": "# Import matplotlib (plotting) and numpy (numerical arrays).\n# This enables their use in the Notebook.\n%matplotlib inline\nimport matplotlib.pyplot as plt\nimport numpy as np\n\n# Import IPython's interact function which is used below to\n# build the interactive widgets\nfrom IPython.html.widgets import interact\n\ndef plot_sine(frequency=4.0, grid_points=12, plot_original=True):\n \"\"\"\n Plot discrete samples of a sine wave on the interval ``[0, 1]``.\n \"\"\"\n x = np.linspace(0, 1, grid_points + 2)\n y = np.sin(2 * frequency * np.pi * x)\n\n xf = np.linspace(0, 1, 1000)\n yf = np.sin(2 * frequency * np.pi * xf)\n\n fig, ax = plt.subplots(figsize=(8, 6))\n ax.set_xlabel('x')\n ax.set_ylabel('signal')\n ax.set_title('Aliasing in discretely sampled periodic signal')\n\n if plot_original:\n ax.plot(xf, yf, color='red', linestyle='solid', linewidth=2)\n\n ax.plot(x, y, marker='o', linewidth=2)\n\n# The interact function automatically builds a user interface for exploring the\n# plot_sine function.\ninteract(plot_sine, frequency=(1.0, 22.0, 0.5), grid_points=(10, 16, 1), plot_original=True);", "metadata": {"trusted": true}, "collapsed": false, "language": "python"}, {"cell_type": "markdown", "metadata": {}, "source": "## Counting galaxies in the Hubble deep field"}, {"cell_type": "markdown", "metadata": {}, "source": "The notebook can utilize powerful Python libraries that span everything from statistics and machine learning to signal and image processing. This example uses the image-processing library [scikit-image](http://scikit-image.org/) to identify galaxies in an image of the sky provided by the Hubble Space Telescope using a blob feature detection algorithm (an approach known as the [determinant of Hessian](http://en.wikipedia.org/wiki/Blob_detection#The_determinant_of_the_Hessian) ).\n\nAfter running the cell, you can play with the parameters of the detection algorithm to find galaxies of different sizes and prominences:\n\n* The `max_sigma` parameter determines the maximum size of the objects that will be identified.\n* The `threshold` parameter can be reduced to detect less prominent objects."}, {"cell_type": "code", "outputs": [], "input": "# Import matplotlib (plotting), skimage (image processing) and interact (user interfaces)\n# This enables their use in the Notebook.\n%matplotlib inline\nfrom matplotlib import pyplot as plt\n\nfrom skimage import data\nfrom skimage.feature import blob_doh\nfrom skimage.color import rgb2gray\n\nfrom IPython.html.widgets import interact, fixed\n\n# Extract the first 500px square of the Hubble Deep Field.\nimage = data.hubble_deep_field()[0:500, 0:500]\nimage_gray = rgb2gray(image)\n\ndef plot_blobs(max_sigma=30, threshold=0.1, gray=False):\n \"\"\"\n Plot the image and the blobs that have been found.\n \"\"\"\n blobs = blob_doh(image_gray, max_sigma=max_sigma, threshold=threshold)\n \n fig, ax = plt.subplots(figsize=(8,8))\n ax.set_title('Galaxies in the Hubble Deep Field')\n \n if gray:\n ax.imshow(image_gray, interpolation='nearest', cmap='gray_r')\n circle_color = 'red'\n else:\n ax.imshow(image, interpolation='nearest')\n circle_color = 'yellow'\n for blob in blobs:\n y, x, r = blob\n c = plt.Circle((x, y), r, color=circle_color, linewidth=2, fill=False)\n ax.add_patch(c)\n\n# Use interact to explore the galaxy detection algorithm.\ninteract(plot_blobs, max_sigma=(10, 40, 2), threshold=(0.005, 0.02, 0.001));", "metadata": {"trusted": true}, "collapsed": false, "language": "python"}, {"cell_type": "markdown", "metadata": {}, "source": "## Notebooks for academic publications"}, {"cell_type": "markdown", "metadata": {}, "source": "IPython notebooks are being distributed as supplementary materials in peer-reviewed academic publications to enable readers to reproduce the computational aspects of the work. Here are three prominent examples:\n\n* Gross, A. M. *et al*., *[Multi-tiered genomic analysis of head and neck cancer ties TP53 mutation to 3p loss]( http://www.nature.com/ng/journal/v46/n9/full/ng.3051.html)*, *Nature Genet.* **46**, 939\u2013943 (2014). (A GitHub repository with all the notebooks required to reproduce this analysis can be found [here](https://github.com/theandygross/TCGA/tree/master/Analysis_Notebooks#guide-to-running). The notebooks can be viewed directly [here](http://nbviewer.ipython.org/github/theandygross/TCGA/tree/master/Analysis_Notebooks/).\n* Ragan-Kelley, B. *et al*., *[Collaborative cloud-enabled tools allow rapid, reproducible biological insights](http://www.nature.com/ismej/journal/v7/n3/full/ismej2012123a.html)*, *ISME* **7**, 461\u2013464 (2013). [Supplementary notebook](http://nbviewer.ipython.org/gist/gregcaporaso/3693491/cloud_demo_complete.ipynb)\n* Ding, T. & Schloss, T. D. *[Dynamics and associations of microbial community types across the human body](http://www.nature.com/nature/journal/v509/n7500/full/nature13178.html)*, *Nature* **509**, 357\u2013360 (2014). [Supplementary notebook](http://nbviewer.ipython.org/gist/pschloss/9815766/notebook.ipynb)\n\nA longer list of peer-reviewed publications that have supplementary notebooks can be found [here](https://github.com/ipython/ipython/wiki/A-gallery-of-interesting-IPython-Notebooks#reproducible-academic-publications).\n"}, {"cell_type": "markdown", "metadata": {}, "source": "## Next steps"}, {"cell_type": "markdown", "metadata": {}, "source": "The IPython Project maintains a curated list of notebooks that provide examples of its use across a wide range of fields and topics. You can find these examples at [this gallery](https://github.com/ipython/ipython/wiki/A-gallery-of-interesting-IPython-Notebooks).\n\nDirections on how to install software to run the IPython notebook on your own computer can be found [here](http://ipython.org/install.html).\n\nIt is also possible to run a notebook in the cloud, without installing the software, using the following services:\n\n* [Authorea](https://www.authorea.com/)\n* [Sage Math Cloud](https://cloud.sagemath.com/)\n* [Wakari](https://wakari.io/)"}, {"cell_type": "markdown", "metadata": {}, "source": "The notebook is being moved into a project called Jupyter, which aims to make the IPython software package more compatible with other languages, including Julia and R. Further information can be found on the [IPython](http://ipython.org/install.html) and [Jupyter](http://jupyter.org) websites.\n\n<img src=\"https://raw.githubusercontent.com/jupyter/nature-demo/master/images/ipython-logo.png\" width=\"250px\" style=\"margin: 20px auto;\">\n<img src=\"https://raw.githubusercontent.com/jupyter/nature-demo/master/images/jupyter-logo.png\" width=\"250px\" style=\"margin: 20px auto;\">\n\nThe IPython and Jupyter projects are sponsored by the Alfred P. Sloan Foundation, Rackspace, Google, Microsoft, the National Science Foundation and the Simons Foundation.\n\nThis demonstration was created with the help of: Kyle Kelley, Brian Granger, Fernando Perez, Matthias Bussonnier, Aron Ahmadia, David Ketcheson, Chris Ryan, Richard Van Noorden and St\u00e9fan van der Walt."}], "metadata": {}}], "nbformat_minor": 0, "metadata": {"signature": "sha256:cca5c2f49cd54364602f451658d17e063c414b59bc5dd36aa6e10ac28dd48e66", "kernelspec": {"display_name": "IPython (Python 3)", "name": "python3"}, "language_info": {"codemirror_mode": {"version": 3, "name": "ipython"}, "mimetype": "text/x-python", "name": "python", "pygments_lexer": "ipython3"}, "name": ""}, "nbformat": 3}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment