{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)\n", "\n", "# Jupyter Notebooks\n", "\n", "Throughout the semester, we will work on exercises using the Python programming langugage and Jupyter Notebooks.\n", "\n", "## What are Jupyter Notebooks?\n", "\n", "
\n", "From Jupyer Notebook: An Introduction\n", "\n", "\n", "[Anaconda](https://www.anaconda.com/) (which we've just downloaded) comes with many scientific libraries preinstalled, including the Jupyter Notebook!\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Starting a Jupyter Notebook server\n", "1. Open your terminal application (**Terminal** on MacOS, **Anaconda Prompt** on Windows)\n", "2. Change your current directory to a location on your computer where you would like to save your notebook (for example: `cd /Users/home/notebooks`)\n", "3. Run the command `jupyter notebook` which will start your default browser (or open a new tab) to the following URL: http://localhost:8888/tree\n", "\n", "![OpenIPYNB](https://raw.githubusercontent.com/Summer-MIND/mind_2018/master/tutorials/jupyter/demo.gif)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Interactive Coding!!\n", "We will use Jupyter Notebooks to interface with Python. Rather than keeping code scripts code and execution separate, Jupyter integrates both together using the concept of cells. Two main types of cells are **code cells** and **markdown cells**. Cells pair \"snippets\" of code with the output obtained from running them and can contain plots/figures inline alongside code required to generate them.\n", "\n", "````{panels}\n", "**Code cells** contain actual code that you want to run. You can specify a cell as a code cell using the pulldown menu in the toolbar in your Jupyter notebook. Otherwise, you can can hit esc and then y (denoted \"*esc, y*\") while a cell is selected to specify that it is a code cell. Note that you will have to hit enter after doing this to start editing it. If you want to execute the code in a code cell, hit \"*shift + enter*\". Note that code cells are executed in the order you execute them. That is to say, the ordering of the cells for which you hit \"*shift + enter*\" is the order in which the code is executed. If you did not explicitly execute a cell early in the document, its results are now known to the Python interpreter.\n", "\n", "---\n", "\n", "**Markdown cells** contain text. The text is written in Markdown, a lightweight markup language. You can read about its syntax [here](https://daringfireball.net/projects/markdown/syntax). Note that you can also insert HTML into markdown cells, and this will be rendered properly. As you are typing the contents of these cells, the results appear as text. Hitting \"*shift + enter*\" renders the text in the formatting you specify. You can specify a cell as being a markdown cell in the Jupyter toolbar, or by hitting \"*esc, m*\" in the cell. Again, you have to hit enter after using the quick keys to bring the cell into edit mode.\n", "````\n", "\n", "In general, when you want to add a new cell, you can use the \"Insert\" pulldown menu from the Jupyter toolbar. The shortcut to insert a cell below is \"*esc, b*\" and to insert a cell above is \"*esc, a*\". Alternatively, you can execute a cell and automatically add a new one below it by hitting \"*alt + enter*\"." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# This is a code cell\n", "# Put some code here and get some output below!\n", "x = 10\n", "print(x)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Notebooks of the Future\n", "Not just for code:\n", "- Markdown, HTML, LaTeX integration\n", "- Slide shows\n", "- Keep your notes alongside your analysis routines\n", "- Embed images, videos, anything (it's all just HTML + javascript)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Markdown\n", "See this [comprehensive guide to Markdown](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) or [tutorial](https://www.markdowntutorial.com/). Here are some examples:\n", "\n", "#### Emphasis\n", "\n", "Here is one way to add emphasis to to Markdown cell text.\n", "```{tab} Markdown Input 1\n", "`Emphasis, aka italics, with *asterisks*.`\n", "```\n", "```{tab} Markdown Output 1\n", "Emphasis, aka italics, with *asterisks*.\n", "```\n", "\n", "Here is another way to add emphasis to to Markdown cell text.\n", "```{tab} Markdown Input 2\n", "`Strong emphasis, aka bold, with **asterisks**.`\n", "```\n", "```{tab} Markdown Output 2\n", "Strong emphasis, aka bold, with **asterisks**.\n", "```\n", "\n", "Here is another way to add emphasis to to Markdown cell text.\n", "```{tab} Markdown Input 3\n", "`Combined emphasis with ***asterisks***.`\n", "```\n", "```{tab} Markdown Output 3\n", "Combined emphasis with ***asterisks***.\n", "```\n", "\n", "Here is one way to add strikethough to Markdown cell text.\n", "```{tab} Markdown Input 4\n", "`Strikethrough uses two tildes. ~~Scratch this.~~`\n", "```\n", "```{tab} Markdown Output 4\n", "Strikethrough uses two tildes. ~~Scratch this.~~\n", "```\n", "\n", "#### Links\n", "\n", "Here is one way to insert hyperlinks into Markdown cells.\n", "```{tab} Markdown Input 5\n", "`[I'm an inline-style link](https://www.google.com)`\n", "```\n", "```{tab} Markdown Output 5\n", "[I'm an inline-style link](https://www.google.com)\n", "```\n", "\n", "Here is another way to insert hyperlinks into Markdown cells.\n", "```{tab} Markdown Input 6\n", "`[I'm a reference-style link][Arbitrary case-insensitive reference text]`\n", "```\n", "```{tab} Markdown Output 6\n", "[I'm a reference-style link][Arbitrary case-insensitive reference text]\n", "```\n", "\n", "[arbitrary case-insensitive reference text]: https://shawnrhoads.github.io/gu-psyc-347/\n", "[1]: https://shawnrhoads.github.io/gu-psyc-347/\n", "[link text itself]: https://shawnrhoads.github.io/gu-psyc-347/\n", "\n", "To reference the links above, we include the following text:\n", "```\n", "[arbitrary case-insensitive reference text]: https://shawnrhoads.github.io/gu-psyc-347/\n", "[1]: https://shawnrhoads.github.io/gu-psyc-347/\n", "[link text itself]: https://shawnrhoads.github.io/gu-psyc-347/\n", "```\n", "\n", "URLs and URLs in angle brackets will automatically get turned into links. http://www.example.com orThe Jupyter Notebook is an open source web application that you can use to create and share documents that contain live code, equations, visualizations, and text. Jupyter Notebook is maintained by the people at Project Jupyter.
\n", "\n", "Jupyter Notebooks are a spin-off project from the IPython project, which used to have an IPython Notebook project itself. The name, Jupyter, comes from the core supported programming languages that it supports: Julia, Python, and R. Jupyter ships with the IPython kernel, which allows you to write your programs in Python, but there are currently over 100 other kernels that you can also use.
\n", "