{ "metadata": { "celltoolbar": "Slideshow", "name": "", "signature": "sha256:de05ed6afd1ab1a4c724691582310c2cf946dbe911e7e503055791eada92da95" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Introducing the IPython Notebook" ] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Aron Ahmadia (US Army ERDC) and David Ketcheson (KAUST)" ] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Teaching Numerical Methods with IPython Notebooks, SciPy 2014" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "notes" } }, "source": [ "\"Creative
This lecture by Aron Ahmadia and David Ketcheson is licensed under a Creative Commons Attribution 4.0 International License. All code examples are also licensed under the [MIT license](http://opensource.org/licenses/MIT)." ] }, { "cell_type": "code", "collapsed": false, "input": [ "from IPython.core.display import HTML\n", "css_file = './example.css'\n", "HTML(open(css_file, \"r\").read())" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n" ], "metadata": {}, "output_type": "pyout", "prompt_number": 1, "text": [ "" ] } ], "prompt_number": 1 }, { "cell_type": "heading", "level": 2, "metadata": { "slideshow": { "slide_type": "notes" } }, "source": [ "What is this?" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "notes" } }, "source": [ "This is a gentle introduction to the IPython Notebook aimed at lecturers who wish to incorporate it in their teaching, written in an IPython Notebook. This presentation adapts material from the [IPython official documentation](http://nbviewer.ipython.org/github/ipython/ipython/blob/2.x/examples/Notebook)." ] }, { "cell_type": "heading", "level": 2, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "What is an IPython Notebook?" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "An IPython Notebook is a:\n", "\n", "**[A]** Interactive environment for writing and running code \n", "**[B]** Weave of code, data, prose, equations, analysis, and visualization \n", "**[C]** Tool for prototyping new code and analysis \n", "**[D]** Reproducible workflow for scientific research \n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "**[E]** **All of the above**" ] }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Writing and Running Code" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "The IPython Notebook consists of an ordered list of cells. \n", "\n", "There are four important cell types:\n", "\n", "* **Code**\n", "* **Markdown**\n", "* **Heading**\n", "* **Raw**" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "We briefly introduce how Code Cells work here. We will return to the other three cell types later." ] }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Code Cells" ] }, { "cell_type": "code", "collapsed": false, "input": [ "# This is a code cell made up of Python comments\n", "# We can execute it by clicking on it with the mouse\n", "# then clicking the \"Run Cell\" button" ], "language": "python", "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "# A comment is a pretty boring piece of code\n", "# This code cell generates \"Hello, World\" when executed\n", "\n", "print \"Hello, World\"" ], "language": "python", "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Hello, World\n" ] } ], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "# Code cells can also generate graphical output\n", "%matplotlib inline\n", "import matplotlib\n", "matplotlib.pyplot.hist([0, 1, 2, 2, 3, 3, 3, 4, 4, 4, 10]);" ], "language": "python", "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "metadata": {}, "output_type": "display_data", "png": "iVBORw0KGgoAAAANSUhEUgAAAXUAAAEACAYAAABMEua6AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADYRJREFUeJzt3G+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j8BngE2A78M/DeWiuqz2HgH4BfAQeBI6QP/nG2nMXLww9R4m79\nCx3qZW9eGidTpP7p3cBbNddSl08Dr5P66f3ulYhuknTF2IPF12OM71+zq4AvkBY9l5N+V/6qzoIa\nJqdEpl7oUD9AOkG4YIa0Wh9XS4DvA98ltV/G1fWk/zPoNeBR4M+B79RaUX32F9vPiv3HGd/Lgj8G\n/AT4LXAS+AHpvTLODpHaLgAfIC2GalXm5qVxkZGC65t1F9Iw6xjvnjrAc8BVxXiO0+/YHicfJV0Z\n9h7S78tm4PO1VjR6s5x5onThqsGv0oATpdD75qVxdAOpf7yT1HbYweJ/vzDO1uHVLx8lrdTnSavT\ncb36BdKVHguXNG4m/XU7Lh4lnUv4Helc5G2kk8c/okGXNEqSJEmSJEmSJEmSJEmSJEmSJEm6SP0e\nKj+Dtwgqq5YAAAAASUVORK5CYII=\n", "text": [ "" ] } ], "prompt_number": 3 }, { "cell_type": "heading", "level": 2, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Modal editor" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Starting with IPython 2.0, the IPython Notebook has a modal user interface. This means that the keyboard does different things depending on which mode the Notebook is in. There are two modes: edit mode and command mode." ] }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Edit mode" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Edit mode is indicated by a green cell border and a prompt showing in the editor area:\n", "\n", "\n", "\n", "When a cell is in edit mode, you can type into the cell, like a normal text editor." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "
\n", "Enter edit mode by pressing `enter` or using the mouse to click on a cell's editor area.\n", "
" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "
\n", "While in edit mode, tab-completion works for variables the kernel knows about from executing previous cells.\n", "
" ] }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Command mode" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Command mode is indicated by a grey cell border:\n", "\n", "\n", "\n", "When you are in command mode, you are able to edit the notebook as a whole, but not type into individual cells. Most importantly, in command mode, the keyboard is mapped to a set of shortcuts that let you perform notebook and cell actions efficiently. For example, if you are in command mode and you press `c`, you will copy the current cell - no modifier is needed." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "
\n", "Don't try to type into a cell in command mode; unexpected things will happen!\n", "
" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "
\n", "Enter command mode by pressing `esc` or using the mouse to click *outside* a cell's editor area.\n", "
" ] }, { "cell_type": "heading", "level": 2, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Mouse navigation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "All navigation and actions in the Notebook are available using the mouse through the menubar and toolbar, which are both above the main Notebook area:\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "notes" } }, "source": [ "The first idea of mouse based navigation is that **cells can be selected by clicking on them.** The currently selected cell gets a grey or green border depending on whether the notebook is in edit or command mode. If you click inside a cell's editor area, you will enter edit mode. If you click on the prompt or output area of a cell you will enter command mode.\n", "\n", "If you are running this notebook in a live session (not on http://nbviewer.ipython.org) try selecting different cells and going between edit and command mode. Try typing into a cell." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "notes" } }, "source": [ "The second idea of mouse based navigation is that **cell actions usually apply to the currently selected cell**. Thus if you want to run the code in a cell, you would select it and click the \"Play\" button in the toolbar or the \"Cell:Run\" menu item. Similarly, to copy a cell you would select it and click the \"Copy\" button in the toolbar or the \"Edit:Copy\" menu item. With this simple pattern, you should be able to do most everything you need with the mouse.\n", "\n", "Markdown and heading cells have one other state that can be modified with the mouse. These cells can either be rendered or unrendered. When they are rendered, you will see a nice formatted representation of the cell's contents. When they are unrendered, you will see the raw text source of the cell. To render the selected cell with the mouse, click the \"Play\" button in the toolbar or the \"Cell:Run\" menu item. To unrender the selected cell, double click on the cell." ] }, { "cell_type": "heading", "level": 2, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Keyboard Navigation" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "The modal user interface of the IPython Notebook has been optimized for efficient keyboard usage. This is made possible by having two different sets of keyboard shortcuts: one set that is active in edit mode and another in command mode." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "The most important keyboard shortcuts are `enter`, which enters edit mode, and `esc`, which enters command mode.\n", "\n", "In edit mode, most of the keyboard is dedicated to typing into the cell's editor. Thus, in edit mode there are relatively few shortcuts:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In command mode, the entire keyboard is available for shortcuts:" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Here the rough order in which the IPython Developers recommend learning the command mode shortcuts:\n", "\n", "1. Basic navigation: `enter`, `shift-enter`, `up/k`, `down/j`\n", "2. Saving the notebook: `s`\n", "2. Cell types: `y`, `m`, `1-6`, `t`\n", "3. Cell creation and movement: `a`, `b`, `ctrl+k`, `ctrl+j`\n", "4. Cell editing: `x`, `c`, `v`, `d`, `z`, `shift+=`\n", "5. Kernel operations: `i`, `0`" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Aron and David humbly suggest learning `h` first!" ] }, { "cell_type": "heading", "level": 2, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "The IPython Notebook Architecture" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "notes" } }, "source": [ "So far, we have learned the basics of using IPython Notebooks.\n", "\n", "For simple demonstrations, the typical user doesn't need to understand how the computations are being handled, but to successfully write and present computational notebooks, **you** will need to understand how the notebook architecture works." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "notes" } }, "source": [ "A *live* notebook is composed of an interactive web page (the front end), a running IPython session (the kernel or back end), and a web server responsible for handling communication between the two (the, err..., middle-end)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "notes" } }, "source": [ "A *static* notebook, as for example seen on NBViewer, is a static view of the notebook's content. The default format is HTML, but a notebook can also be output in PDF or other formats." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The centerpiece of an IPython Notebook is the \"kernel\", the IPython instance responsible for executing all code. Your IPython kernel maintains its state between executed cells." ] }, { "cell_type": "code", "collapsed": false, "input": [ "x = 0\n", "print x" ], "language": "python", "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "0\n" ] } ], "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [ "x += 1\n", "print x" ], "language": "python", "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "1\n" ] } ], "prompt_number": 5 }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "notes" } }, "source": [ "There are two important actions for interacting with the kernel. The first is to interrupt it. This is the same as sending a Control-C from the command line. The second is to restart it. This completely terminates the kernel and starts it anew. None of the kernel state is saved across a restart. " ] }, { "cell_type": "heading", "level": 2, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Markdown cells" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Text can be added to IPython Notebooks using Markdown cells. Markdown is a popular markup language that is a superset of HTML. Its specification can be found here:\n", "\n", "" ] }, { "cell_type": "heading", "level": 2, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Markdown basics" ] }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Text formatting" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "You can make text *italic* or **bold**." ] }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Itemized Lists" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* One\n", " - Sublist\n", " - This\n", " - Sublist\n", " - That\n", " - The other thing\n", "* Two\n", " - Sublist\n", "* Three\n", " - Sublist" ] }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Enumerated Lists" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1. Here we go\n", " 1. Sublist\n", " 2. Sublist\n", "2. There we go\n", "3. Now this" ] }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Horizontal Rules" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "---\n", "\n", "---" ] }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Blockquotes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> To me programming is more than an important practical art. It is also a gigantic undertaking in the foundations of knowledge. -- Rear Admiral Grace Hopper" ] }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Links" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[IPython's website](http://ipython.org)" ] }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Code" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " def f(x):\n", " \"\"\"a docstring\"\"\"\n", " return x**2" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "You can also use triple-backticks to denote code blocks.\n", "This also allows you to choose the appropriate syntax highlighter.\n", "\n", "```C\n", "if (i=0; i\n", " " ], "metadata": {}, "output_type": "pyout", "prompt_number": 6, "text": [ "" ] } ], "prompt_number": 6 }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Other HTML" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " Be Bold! " ] }, { "cell_type": "heading", "level": 2, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Mathematical Equations" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "Courtesy of MathJax, you can beautifully render mathematical expressions, both inline: \n", "$e^{i\\pi} + 1 = 0$, and displayed:\n", "\n", "$$e^x=\\sum_{i=0}^\\infty \\frac{1}{i!}x^i$$" ] }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Equation Environments" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also use a number of equation environments, such as `align`:\n", "\n", "\\begin{align}\n", " x &= 4 \\\\\n", "y+z &= x\n", "\\end{align}\n", "\n", "[A full list of available TeX and LaTeX commands is maintained by Dr. Carol Burns.](http://www.onemathematicalcat.org/MathJaxDocumentation/TeXSyntax.htm)" ] }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Other Useful MathJax Notes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* inline math is demarcated by `$ $`, or `\\( \\)`\n", "* displayed math is demarcated by `$$ $$` or `\\[ \\]`\n", "* displayed math environments can also be directly demarcated by `\\begin` and `\\end`\n", "* `\\newcommand` and `\\def` are supported, *within* areas MathJax processes (such as in a `\\[ \\]` block)\n", "* equation numbering is not officially supported, but it can be indirectly enabled" ] }, { "cell_type": "heading", "level": 2, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "A Note about Notebook Security" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By default, a notebook downloaded to a new computer is *untrusted*\n", "\n", "* HTML and Javascript in Markdown cells is now *never* executed\n", "* HTML and Javascript code outputs must be explicitly *re-executed*\n", "* Some of these restrictions can be mitigrated through shared accounts (Sage MathCloud) and secrets" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "notes" } }, "source": [ "More information on notebook security is in the [IPython Notebook documentation](http://ipython.org/ipython-doc/stable/notebook/security.html)" ] }, { "cell_type": "heading", "level": 2, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Magics" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "IPython kernels execute a superset of the Python language. The extension functions, commonly referred to as *magics*, come in two variants. " ] }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Line Magics" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "* A *line magic* looks like a command line call. The most important of these is `%matplotlib inline`, which embeds all matplotlib plot output as images in the notebook itself." ] }, { "cell_type": "code", "collapsed": false, "input": [ "%matplotlib inline" ], "language": "python", "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "prompt_number": 7 }, { "cell_type": "code", "collapsed": false, "input": [ "%whos" ], "language": "python", "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Variable Type Data/Info\n", "----------------------------------\n", "YouTubeVideo type \n", "matplotlib module matplotlib/__init__.pyc'>\n", "x int 1\n" ] } ], "prompt_number": 8 }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Cell Magics" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "* A *cell magic* takes its entire cell as an argument. Although there are a number of useful cell magics, you may find `%%timeit` to be useful for exploring code performance." ] }, { "cell_type": "code", "collapsed": false, "input": [ "%%timeit\n", "\n", "import numpy as np\n", "np.sum(np.random.rand(1000))" ], "language": "python", "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "10000 loops, best of 3: 23.2 \u00b5s per loop\n" ] } ], "prompt_number": 9 }, { "cell_type": "heading", "level": 3, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Interacting with the Command Line" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "IPython supports one final trick, the ability to interact directly with your shell by using the `!` operator." ] }, { "cell_type": "code", "collapsed": false, "input": [ "!ls" ], "language": "python", "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Aliasing.ipynb Markdown Cells.ipynb README.md finite_difference_lab.ipynb\r\n", "Introducing the IPython Notebook.ipynb Multigrid.ipynb example.css \u001b[34mimages\u001b[m\u001b[m\r\n" ] } ], "prompt_number": 10 }, { "cell_type": "code", "collapsed": false, "input": [ "x = !ls" ], "language": "python", "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [], "prompt_number": 11 }, { "cell_type": "code", "collapsed": false, "input": [ "print x" ], "language": "python", "metadata": { "slideshow": { "slide_type": "fragment" } }, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "['Aliasing.ipynb', 'Introducing the IPython Notebook.ipynb', 'Markdown Cells.ipynb', 'Multigrid.ipynb', 'README.md', 'example.css', 'finite_difference_lab.ipynb', 'images']\n" ] } ], "prompt_number": 12 }, { "cell_type": "heading", "level": 2, "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "A Note about Notebook Version Control" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "The IPython Notebook is stored using canonicalized JSON for ease of use with version control systems.\n", "\n", "There are two things to be aware of:\n", "\n", "* By default, IPython embeds all content and saves kernel execution numbers. You may want to get in the habit of clearing all cells before committing.\n", "\n", "* As of IPython 2.0, all notebooks are signed on save. This increases the chances of a commit collision during merge, forcing a manual resolution. Either signature can be safely deleted in this situation." ] } ], "metadata": {} } ] }