add slideshow cell meta-data

The notebook can now be viewed in slideshow mode
This commit is contained in:
Kasper D. Fischer 2021-04-18 20:58:41 +02:00
parent 98d9187918
commit 0c0be93f92

View File

@ -2,7 +2,11 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"<div style='background-image: url(\"../images/header.svg\") ; padding: 0px ; background-size: cover ; border-radius: 5px ; height: 250px'>\n",
" <div style=\"float: right ; margin: 50px ; padding: 20px ; background: rgba(255 , 255 , 255 , 0.7) ; width: 50% ; height: 150px\">\n",
@ -11,13 +15,8 @@
" <div style=\"font-size: large ; padding-top: 20px ; color: rgba(0 , 0 , 0 , 0.5)\">A super quick crash course</div>\n",
" </div>\n",
" </div>\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"</div>\n",
"\n",
"Seismo-Live: http://seismo-live.org\n",
"\n",
"##### Authors:\n",
@ -28,14 +27,26 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"This notebook is a very quick introduction to Python and in particular its scientific ecosystem in case you have never seen it before. It furthermore grants a possibility to get to know the [IPython/Jupyter notebook](http://www.nature.com/news/interactive-notebooks-sharing-the-code-1.16261). [See here for the official documentation](http://nbviewer.jupyter.org/github/jupyter/notebook/blob/master/docs/source/examples/Notebook/Notebook%20Basics.ipynb) of the Jupyter notebook - a ton more information can be found online.\n",
"\n",
"\n",
"A lot of motivational writing on *Why Python?* is out there so we will not repeat it here and just condense it to a single sentence: **Python is a good and easy to learn, open-source, general purpose programming language that happens to be very good for many scientific tasks (due to its vast scientific ecosystem).**\n",
"\n",
"\n",
"A lot of motivational writing on *Why Python?* is out there so we will not repeat it here and just condense it to a single sentence: **Python is a good and easy to learn, open-source, general purpose programming language that happens to be very good for many scientific tasks (due to its vast scientific ecosystem).**"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"#### Quick Reference on How to Use This Notebook\n",
"\n",
"\n",
@ -57,8 +68,17 @@
"\n",
"```bash\n",
"$ ipython\n",
"```\n",
"\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Notebook Setup\n",
"\n",
"First things first: In many notebooks you will find a cell similar to the following one. **Always execute it!** They do a couple of things:\n",
@ -71,13 +91,17 @@
"\n",
"This essentially makes the notebooks work under Python 2 and Python 3.\n",
"\n",
"* Plots look quite a bit nicer (this is optional).\n"
"* Plots look quite a bit nicer (this is optional)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"# Plots now appear in the notebook.\n",
@ -90,7 +114,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"---\n",
"\n",
@ -100,6 +128,8 @@
"\n",
"If you have any question regarding some specific Python functionality you can consult the official [Python documenation](http://docs.python.org/).\n",
" \n",
"### Tutorials\n",
"\n",
"Furthermore a large number of Python tutorials, introductions, and books are available online. Here are some examples for those interested in learning more.\n",
" \n",
"* [Learn Python The Hard Way](http://learnpythonthehardway.org/book/)\n",
@ -107,11 +137,23 @@
"* [The Official Python Tutorial](http://docs.python.org/2/tutorial/index.html)\n",
"* [Think Python Book](http://www.greenteapress.com/thinkpython/thinkpython.html)\n",
" \n",
"### Matlab\n",
"\n",
"Some people might be used to Matlab - this helps:\n",
" \n",
"* [NumPy for Matlab Users Introdution](http://wiki.scipy.org/NumPy_for_Matlab_Users)\n",
"* [NumPy for Matlab Users Cheatsheet](http://mathesaurus.sourceforge.net/matlab-numpy.html)\n",
" \n",
"* [NumPy for Matlab Users Cheatsheet](http://mathesaurus.sourceforge.net/matlab-numpy.html)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### More\n",
"\n",
"Additionally there is an abundance of resources introducing and teaching parts of the scientific Python ecosystem.\n",
" \n",
@ -133,7 +175,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Core Python Crash Course\n",
"\n",
@ -150,7 +196,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"# Three basic types of numbers\n",
@ -170,22 +220,25 @@
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2. Strings"
]
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2. Strings\n",
"\n",
"Just enclose something in single or double quotes and it will become a string. On Python 3 it defaults to unicode strings, e.g. non Latin alphabets and other symbols."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"# You can use single or double quotes to create strings.\n",
@ -210,7 +263,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"#### Exercise\n",
"\n",
@ -220,7 +277,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"name = \"kasper\"\n",
@ -229,22 +290,25 @@
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3. Lists"
]
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3. Lists\n",
"\n",
"Python has two main collection types: List and dictionaries. The former is just an ordered collection of objects and is introduced here."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"# List use square brackets and are simple ordered collections of things.\n",
@ -266,7 +330,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### 4. Dictionaries\n",
"\n",
@ -276,7 +344,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"# Dictionaries have named fields and no inherent order. As is\n",
@ -304,7 +376,10 @@
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
"collapsed": true,
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### 5. Functions\n",
@ -315,7 +390,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"# Functions are defined using the def keyword.\n",
@ -339,7 +418,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### 6. Imports\n",
"\n",
@ -349,7 +432,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"# Import anything, and use it with the dot accessor.\n",
@ -369,7 +456,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"How to know what is available?\n",
"\n",
@ -380,7 +471,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"print(dir(math))"
@ -388,7 +483,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Typing the dot and the TAB will kick off tab-completion."
]
@ -396,7 +495,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"math."
@ -404,7 +507,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"In the IPython framework you can also use a question mark to view the documentation of modules and functions."
]
@ -412,7 +519,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"math.cos?"
@ -420,7 +531,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### 7. Control Flow\n",
"\n",
@ -430,7 +545,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"temp = [\"a\", \"b\", \"c\"]\n",
@ -447,7 +566,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"# Useful to know is the range() function.\n",
@ -457,15 +580,23 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"The second crucial control flow structure are if/else conditional and they work the same as in any other language."
"The second crucial control flow structure are ***if/else*** conditional and they work the same as in any other language."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"# If/else works as expected.\n",
@ -479,15 +610,27 @@
" print(\"wait what?\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"List comprehensions are a nice way to write compact loops. Make sure you understand this as it is very common in Python."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"# List comprehensions are a nice way to write compact loops.\n",
"# Make sure you understand this as it is very common in Python.\n",
"\n",
"a = list(range(10))\n",
"print(a)\n",
"b = [i for i in a if not i % 2]\n",
@ -503,7 +646,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### 8. Error Messages\n",
"\n",
@ -513,7 +660,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"def do_something(a, b): \n",
@ -524,7 +675,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## The Scientific Python Ecosystem\n",
"\n",
@ -539,7 +694,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### 9. NumPy\n",
"\n",
@ -549,7 +708,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"import numpy as np\n",
@ -571,7 +734,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### 10. SciPy\n",
"\n",
@ -581,7 +748,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"from scipy.interpolate import interp1d\n",
@ -595,7 +766,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### 11. Matplotlib\n",
"\n",
@ -605,7 +780,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
@ -619,7 +798,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Exercises\n",
"\n",
@ -637,7 +820,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
@ -652,7 +839,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"#### 99 Bottles of Beer\n",
"\n",
@ -674,7 +865,12 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"scrolled": true,
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"print(\"99 bottles of beer on the wall, 99 bottles of beer.\")\n",
@ -684,7 +880,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"#### Ceasar Cipher\n",
"\n",
@ -714,7 +914,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [],
"source": [
"sentence = \"Pnrfne pvcure? V zhpu cersre Pnrfne fnynq!\"\n",
@ -739,7 +943,11 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"### Encoder ###\n",
"Idea: Iterrate over all letters of a sentence and find the key (k) which contains the letter as value (v) in the code dictionary"
@ -748,7 +956,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"sentence = \"Geophysics with Python is fun!\"\n",
@ -763,16 +975,10 @@
"\n",
"print(result)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 3",
"language": "python",