{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "## Welcome to the Jupyter Quickstart Notebook!\n",
    "\n",
    "This Notebook was created to help you get familiar with the Jupyter Notebook interface. Follow each step and experiment as much as you'd like! Each step will help prepare you for the next step. As you get more advanced, feel free to read further in the Jupyter Documentation\n",
    "\n",
    "### Table of Contents\n",
    "  * [Run a cell](#runcell)\n",
    "  * [Magic commands](#magic)\n",
    "  * [Help](#help)\n",
    "  * [Imports](#imports)\n",
    "  * [Functions](#functions)\n",
    "  * [Are the modules loaded?](#loaded)\n",
    "  * [Autocomplete](#autocomplete)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Run a cell <a id=\"runcell\"></a>\n",
    "\n",
    "The cell below is a Python cell that contains a simple function. In order to run its code, you must:\n",
    "\n",
    "1. Click on the cell to select it.\n",
    "2. Press `SHIFT+ENTER` on your keyboard or press the \"run cell\" button in the toolbar above.\n",
    "3. Confirm that \"Congrats! You ran your first code cell!\" was printed below the cell.\n",
    "\n",
    "<div class=\"alert alert-warning\" role=\"alert\" style=\"margin: 10px\">\n",
    "<p>**NOTE**</p>\n",
    "<p>Not every cell will have output and it may seem like it was not run. Check which cell is selected. After you run a cell, the next cell down should be selected. </p>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Congrats! You ran your first code cell!\n"
     ]
    }
   ],
   "source": [
    "print(\"Congrats! You ran your first code cell!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Magic commands <a id=\"magic\"></a>\n",
    "\n",
    "Jupyter has an extensive list of special functions called Magic commands. These commands are built-in and can be run from anywhere. They are generally identified by their preceding % sign.\n",
    "\n",
    "Let's practice with the \"%quickref\" command. This command will give a cheat sheet of useful commands.\n",
    "\n",
    "1. Run the cell\n",
    "2. Confirm that the documentation appears\n",
    "\n",
    "_For a full list of magic commands, run the %magic command._"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%quickref"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Help and Documentation <a id=\"help\"></a>\n",
    "\n",
    "Not everything is self-explanatory. If you find yourself getting stuck, refer to the documentation for help. Most of the time, a simple question mark (?) after your command can give you plenty of information about it.\n",
    "\n",
    "Try to retrieve the documentation for these magic commands:\n",
    "* `%matplotlib`\n",
    "* `%pastebin`\n",
    "* `%history`\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%matplotlib?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Import a package <a id=\"imports\"></a>\n",
    "\n",
    "Before we can use any package, it must be imported into the environment. Let's practice by importing the datetime module.\n",
    "\n",
    "1. Declare which package to import\n",
    "2. Run the cell\n",
    "\n",
    "<div class=\"alert alert-warning\" role=\"alert\" style=\"margin: 10px\">\n",
    "<p>**NOTE**</p>\n",
    "<p>Generally, imports will not show an output</p>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import datetime"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Functions <a id=\"functions\"></a>\n",
    "\n",
    "The LiPD package should cover all the functions you need, but if you'd like to write your own functions you can! Run the cell below and it will import some example functions into the environment.\n",
    "\n",
    "1. Run the cell\n",
    "2. Functions are now in the environment\n",
    "\n",
    "What happened? \n",
    "* Some example functions were loaded from an external python file\n",
    "* The \"example_function()\" is loaded from the cell\n",
    "\n",
    "_To learn about Python functions and more, visit [python.org](http://pythonprogramminglanguage.com)_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# %run Magic Command: run a python script\n",
    "%run ./examples/quickstart_functions.py\n",
    "\n",
    "# Create a python function\n",
    "def example_function():\n",
    "    print(\"This is a custom function\")\n",
    "    return"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Are the modules loaded? <a id=\"loaded\"></a>\n",
    "\n",
    "Sometimes it's helpful to see a complete snapshot of your Notebook. If you want to be sure that modules and functions are loaded correctly, the `%whos` magic command is a great way to do that. Now that we have some custom functions and modules loaded, let's try the `%whos` command.\n",
    "\n",
    "1. Run the cell\n",
    "2. Confirm that the list includes our custom functions and modules from the previous steps"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Variable           Type        Data/Info\n",
      "----------------------------------------\n",
      "datetime           module      <module 'datetime' from '<...>b/python3.4/datetime.py'>\n",
      "example_function   function    <function example_function at 0x103d62a60>\n",
      "random             module      <module 'random' from '/L<...>lib/python3.4/random.py'>\n",
      "tell_me_a_joke     function    <function tell_me_a_joke at 0x103d628c8>\n",
      "what_is_my_name    function    <function what_is_my_name at 0x103d626a8>\n",
      "what_time_is_it    function    <function what_time_is_it at 0x103d62950>\n"
     ]
    }
   ],
   "source": [
    "# %whos Magic Command: Show all variables in the environment\n",
    "%whos"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Autocomplete <a id=\"autocomplete\"></a>\n",
    "\n",
    "Autocomplete remembers names so you don't have to. It will help you finish a command with a partial name. As the Notebook grows, the list of variables, functions, and modules can be overwhelming. Start typing the name of what you're looking for, and then press `TAB` to show a filtered list.\n",
    "\n",
    "Try the two examples below!\n",
    "\n",
    "<div class=\"alert alert-warning\" role=\"alert\" style=\"margin: 10px\">\n",
    "<p>**NOTE**</p>\n",
    "<p> <b>Referencing</b> a function and <b>running</b> are not the same thing. For example, running <code class=\"inlinecode\">tell_me_a_joke</code> will give you information about the function. However, running <code class=\"inlinecode\">tell_me_a_joke()</code> will run the function.</p>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Autocomplete: Example 1\n",
    "\n",
    "-----\n",
    "\n",
    "If there is only one match for your input, the whole function autocompletes for you.\n",
    "\n",
    "Function: <pre>tell_me_a_joke()</pre>\n",
    "\n",
    "1. Type \"tell\"\n",
    "2. Press `TAB` key\n",
    "3. Add \"()\" at the end of the function name\n",
    "4. Run the cell"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Autocomplete: Example 1\n",
    "tell_me_a_joke()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Autocomplete: Example 2\n",
    "\n",
    "-----\n",
    "\n",
    "If there are multiple matches for your input, autocomplete provides a list of options.\n",
    "\n",
    "Function: <pre>what_time_is_it()</pre>\n",
    "\n",
    "1. Type \"what\"\n",
    "2. Press the `TAB` key\n",
    "3. Use the `UP` and `DOWN` arrow keys to highlight the function\n",
    "4. Press `ENTER` to choose the function\n",
    "3. Add `()` at the end of the function name\n",
    "4. Run the cell"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Autocomplete: Example 2\n",
    "what_time_is_it()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### That's it!\n",
    "\n",
    "If you feel more comfortable with Jupyter now, I'd recommend heading to the LiPD Quickstart notebook"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.4.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
