{
"cells": [
{
"cell_type": "raw",
"metadata": {},
"source": [
"%This notebook demonstrates the use of the workpackage template, replace with your own.\n",
"\n",
"\\documentclass[english]{workpackage}[1996/06/02]\n",
"\n",
"% input the common preamble content (required by the ipnb2latex converter)\n",
"\\input{header.tex}\n",
"\n",
"% the following three lines are required to support the tikz examples\n",
"\\usepackage{tikz}\n",
"\\usepackage{sansmath}\n",
"\\usetikzlibrary{shadings,intersections}\n",
"\n",
"% then follows the rest of the preamble to be placed before the begin document\n",
"% this preamble content is special to the documentclass you defined above.\n",
"\\WPproject{Computational Radiometry} % project name\n",
"\\WPequipment{} % equipment name\n",
"\\WPsubject{01-IPythonHintsAndTips} % main heading \n",
"\\WPconclusions{} \n",
"\\WPclassification{} \n",
"\\WPdocauthor{CJ Willers}\n",
"\\WPcurrentpackdate{\\today}\n",
"\\WPcurrentpacknumber{} % work package number\n",
"\\WPdocnumber{} % this doc number hosts all the work packages\n",
"\\WPprevpackdate{} % work package which this one supersedes\n",
"\\WPprevpacknumber{} % work package which this one supersedes\n",
"\\WPsuperpackdate{} % work package which comes after this one\n",
"\\WPsuperpacknumber{} % work package which comes after this one\n",
"\\WPdocontractdetails{false}\n",
"\\WPcontractname{} % contract name \n",
"\\WPorderno{} % contract order number\n",
"\\WPmilestonenumber{} % contract milestone number\n",
"\\WPmilestonetitle{} % contract milestone title\n",
"\\WPcontractline{} % contract milestone line number \n",
"\\WPdocECPnumber{} % ecp\\ecr number\n",
"\\WPdistribution{}\n",
"\n",
"% bibfile added in this notebook\n",
"%\\addbibresource{.\\analyseRio.bib} \n",
"\n",
"% this is entered just before the end{document}\n",
"\\newcommand{\\atendofdoc}{\n",
"\\bibliographystyle{IEEEtran}\n",
"\\bibliography{01-IPythonHintsAndTips}\n",
"}\n",
"\n",
"%and finally the document begin.\n",
"\\begin{document}\n",
"\\WPlayout\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
}
},
"source": [
"This notebook forms part of a series on [computational optical radiometry](https://github.com/NelisW/ComputationalRadiometry#computational-optical-radiometry-with-pyradi). The notebooks can be downloaded from [Github](https://github.com/NelisW/ComputationalRadiometry#computational-optical-radiometry-with-pyradi). These notebooks are constantly revised and updated, please revisit from time to time. \n",
"\n",
"This notebook was written several Ipython/Jupyter generations ago, some information may be no longer applicable.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
}
},
"source": [
"# 1 Jupyter / IPython notebook hints and tips "
]
},
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
}
},
"source": [
"The date of this document and module versions used in this document are given at the end of the file. \n",
"Feedback is appreciated: neliswillers at gmail dot com. \n",
"\n",
" This notebook is relatively old, not recently updated. However, most of the info should still be relevant. "
]
},
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
}
},
"source": [
"# Jupyter and IPython"
]
},
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
}
},
"source": [
"
The IPython notebook is an effective means to capture technical story lines or flow-of-thought;
being initially conceived as a lab book for science and technology investigations. \n",
"It is now also used for slides and as lecturing medium.\n",
"
Markdown basics: lists, markup and code
\n", " \n", "list item
\n", " \n", "italics
fixed_font
Code examples:
\n", " \n", "def hello_ipython():\n",
" print \"Hello IPython!\"\n",
"
"
]
},
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
}
},
"source": [
"Markdown cells can also contain HTML\n",
"\n",
"Markdown basics: lists, markup and code
\n", "\n", "list item
\n", "\n", "italics
fixed_font
Code examples:
\n", "\n", "def hello_ipython():\n",
" print \"Hello IPython!\"\n",
"
"
]
},
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
}
},
"source": [
"Type this to get the output shown below:\n",
"\n",
" Using math mode (anything delimited before and after by single or double `$` symbols is interpreted as LaTeX math:\n",
"\n",
" $$ D_{KL}(P||Q) = \\sum\\limits_{i}ln (\\frac{P(i)}{Q(i)}) P(i)$$"
]
},
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
}
},
"source": [
"Using math mode (anything delimited before and after by single or double `$` symbols is interpreted as LaTeX math:\n",
"\n",
"$$ D_{KL}(P||Q) = \\sum\\limits_{i}ln (\\frac{P(i)}{Q(i)}) P(i)$$\n",
"\n",
"$$e^{i\\pi} + 1 = 0 \n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
}
},
"source": [
"### Github markdown can also be used"
]
},
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
}
},
"source": [
"The Notebook webapp support Github flavored markdown meaning that you can use triple backticks for code blocks\n",
"\n",
" ```python\n",
" print \"Hello World\"\n",
" ```\n",
"\n",
" ```javascript\n",
" console.log(\"Hello World\")\n",
" ```\n",
"gives"
]
},
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
}
},
"source": [
"```python\n",
"print \"Hello World\"\n",
"```\n",
"\n",
"```javascript\n",
"console.log(\"Hello World\")\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
}
},
"source": [
"And a table like this :\n",
"\n",
" | This | is |\n",
" |------|------|\n",
" | a | table| \n",
" \n",
"gives\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
}
},
"source": [
"| This | is |\n",
"|------|------|\n",
"| a | table| \n"
]
},
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
}
},
"source": [
"### Citations and links"
]
},
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
}
},
"source": [
"Markdown syntax does not have any means to provide citations as often required in formal documentation.\n",
" \n",
"Markdown hyperlinks to external websites: [pyradi](https://code.google.com/p/pyradi/ \"on Google Code\") Python package. You can provide the display text, the ling address and amouse-over attribute.\n",
"\n",
"HTML anchors can be used to create links to other locations in the same file. Put an anchor definition in the place you want to link to, using this format: ``. It seems the best place to put this anchor is in a dedicated markdown cell immediatelty in front of where you want to link to, it does not work in a cell with other text.\n",
"From elsewhere in the file link to this anchor by using the following format \n",
"`my anchor`\n",
"\n",
"It is also possible to attach anchors to headers as explained in This is a mixture of markdown and html:
\n",
"The square root of 2 used to be somewhere near 1.4142135623730951
Length 0"
],
"text/plain": [
" Length 1"
],
"text/plain": [
" Length 2"
],
"text/plain": [
" Length \" + str(x) + \"\")) "
]
},
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
},
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### Displaying tables in HTML\n",
"\n",
"\"]\n",
" for row in self:\n",
" html.append(\"
\")\n",
" return ''.join(html)"
]
},
{
"cell_type": "code",
"execution_count": 92,
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
}
},
"outputs": [
{
"data": {
"text/html": [
"\")\n",
" \n",
" for col in row:\n",
" html.append(\" \")\n",
" html.append(\"{0} \".format(col))\n",
" \n",
" html.append(\"
"
],
"text/plain": [
"[['x', 'y', 'x-y', '(x-y)**2'],\n",
" [7.961474434798401, 6.865343639904734, 1.096130794893667, 1.201502719514222],\n",
" [5.201977519140058, 7.346595757886568, -2.14461823874651, 4.599387389964183],\n",
" [4.696815945296278, 3.42530669581821, 1.2715092494780675, 1.6167357715082786],\n",
" [6.2854048732677565,\n",
" 9.328224476424943,\n",
" -3.042819603157186,\n",
" 9.258751137357656],\n",
" [1.337242255262987, 6.186116388698062, -4.848874133435075, 23.51158036189575],\n",
" [7.040166772972675, 3.984930885436305, 3.0552358875363703, 9.334466328490153],\n",
" [3.941562299040963, 1.4756150197404327, 2.46594727930053, 6.080895984289687]]"
]
},
"execution_count": 92,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import random\n",
"table = ListTable()\n",
"table.append(['x', 'y', 'x-y', '(x-y)**2'])\n",
"for i in range(7):\n",
" x = random.uniform(0, 10)\n",
" y = random.uniform(0, 10)\n",
" table.append([x, y, x-y, (x-y)**2])\n",
" \n",
"table"
]
},
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
},
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Fine-tuning IPython typographic output appearance\n",
"\n",
"Changing the fonts, colours and layout to suit your own style. \n",
"x y x-y (x-y)**2 7.961474434798401 6.865343639904734 1.096130794893667 1.201502719514222 5.201977519140058 7.346595757886568 -2.14461823874651 4.599387389964183 4.696815945296278 3.42530669581821 1.2715092494780675 1.6167357715082786 6.2854048732677565 9.328224476424943 -3.042819603157186 9.258751137357656 1.337242255262987 6.186116388698062 -4.848874133435075 23.51158036189575 7.040166772972675 3.984930885436305 3.0552358875363703 9.334466328490153 3.941562299040963 1.4756150197404327 2.46594727930053 6.080895984289687
\n",
"`ipython nbconvert --to slides --post serve filename`
\n",
"where `filename` is the name of the ipython notebook you want to convert to a slide show.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"run_control": {
"frozen": false,
"read_only": false
}
},
"source": [
"## Blogging with IPython\n",
"\n",
"IPython is also used to created blogging pages: \n",
" \n",
"This is an autogenerated header
' + str(text) + '
'\n",
" return raw_html\n",
"\n",
"def box(text):\n",
" raw_html = '