Skip to content

Instantly share code, notes, and snippets.

@janfreyberg
Last active March 3, 2017 14:05
Show Gist options
  • Save janfreyberg/193d38f4bd1aeca6980c6b9888674008 to your computer and use it in GitHub Desktop.
Save janfreyberg/193d38f4bd1aeca6980c6b9888674008 to your computer and use it in GitHub Desktop.
Ipython notebooks
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"nbpresent": {
"id": "4bb8fc1b-b50e-4b9d-8c78-525bfa902082"
},
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Using jupyter notebooks in science\n",
"\n",
"Jupyter notebook is a document format that combines rich text (written in markdown) and code (written in one (or more!) of many languages).\n",
"\n",
"While originally specifically for python (hence the misspelling of jupyter), it is now language-agnostic. The computing is handled by _kernels_, and you can use python kernels, R kernels, or MATLAB/Octave kernels."
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpresent": {
"id": "3316a159-8026-4726-b3cb-a297fd04e0f7"
},
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### What are the benefits of using notebooks?\n",
"\n",
"- Your code and your results are in the same document (no more 20 figure windows)\n",
"- You can document your code much more readably\n",
"- You can share the document combining code, results, and documentation all in one file.\n",
" - (notebooks render nicely on e.g. [github](https://www.github.com/autism-research-centre/Autism-Gradients))\n",
"- Notebooks can combine multiple languages\n",
"- Notebooks can include interactive graphics\n",
"- Notebooks can be hosted online on e.g. [mybinder.org](http://www.mybinder.org)\n",
"- Notebooks work through your browser"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false,
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"This\n",
"is\n",
"a\n",
"python\n",
"notebook!\n"
]
}
],
"source": [
"for a in ['This', 'is', 'a', 'python', 'notebook!']:\n",
" print a"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"You can also use shell commands with this kernel, so you could call Freesurfer.\n",
"You just need to put an exclamation mark at the beginning of your line.\n"
]
}
],
"source": [
"!echo \"You can also use shell commands with this kernel, so you could call Freesurfer.\"\n",
"!echo \"You just need to put an exclamation mark at the beginning of your line.\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# So what do you need to get started?\n",
"\n",
"While jupyter notebooks are language agnostic, the application itself is written in python, so you still need to install python. An easy way to do this is to [install miniconda](https://conda.io/miniconda.html). This exists on all operating systems.\n",
"\n",
"You then want to install jupyter notebook. The python package manager pip comes with miniconda, so you can do the following:\n",
"\n",
"```\n",
"pip install jupyter\n",
"```\n",
"\n",
"This installs jupyter notebook, as well as dependencies such as iPython and others.\n",
"\n",
"Then, simply open a terminal, and type:\n",
"```\n",
"jupyter notebook\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### How do you interact with jupyter notebooks?\n",
"\n",
"The whole application works through your browser, and when you open jupyter notebook, you also open a browser window. It starts as a filebrowser, and you can then create files.\n",
"\n",
"[Let's try that now](http://localhost:8888/tree/Dropbox/Documents/side-projects/jupyter-tutorial)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Let's try some other languages\n",
"\n",
"- [R Kernel](http://localhost:8888/notebooks/Dropbox/Documents/side-projects/jupyter-tutorial/r-example.ipynb)\n",
"- [Matlab Kernel](http://localhost:8888/notebooks/Dropbox/Documents/side-projects/jupyter-tutorial/matlab-example.ipynb)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### How can you share your notebooks?\n",
"\n",
"There are many different ways you can do this.\n",
"\n",
"- One simple one is: Host your notebook on github, and others clone the repository.\n",
"- If you want people to view the file without running it themselves: Host it on github and just [send people the link](https://github.com/janfreyberg/ninotebooks/blob/master/receptive-fields/samsrf/02-cookbook.ipynb).\n",
"- If you want people to just play around with your code online: [Submit your github repo to mybinder.org](http://mybinder.org)\n",
"- Or try a local implementation of jupyter hub."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda root]",
"language": "python",
"name": "conda-root-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
},
"nbpresent": {
"slides": {
"54064bd0-f411-4d72-9793-90997ad730b4": {
"id": "54064bd0-f411-4d72-9793-90997ad730b4",
"layout": "manual",
"prev": null,
"regions": {
"6faa5134-1532-45e9-b91c-25fc058ec978": {
"attrs": {
"height": 0.8,
"width": 0.8,
"x": 0.1,
"y": 0.1
},
"content": {
"cell": "4bb8fc1b-b50e-4b9d-8c78-525bfa902082",
"part": "whole"
},
"id": "6faa5134-1532-45e9-b91c-25fc058ec978"
},
"9ef932da-62db-476f-b055-81e85268ad08": {
"attrs": {
"height": 0.8,
"width": 0.8,
"x": 0.1,
"y": 0.1
},
"id": "9ef932da-62db-476f-b055-81e85268ad08"
}
}
},
"57c428c5-e200-4745-be5e-ac71b6c75514": {
"id": "57c428c5-e200-4745-be5e-ac71b6c75514",
"prev": "54064bd0-f411-4d72-9793-90997ad730b4",
"regions": {
"4b7dd67b-6927-496e-a78c-af9cd86e6d2d": {
"attrs": {
"height": 0.8,
"width": 0.8,
"x": 0.1,
"y": 0.1
},
"content": {
"cell": "3316a159-8026-4726-b3cb-a297fd04e0f7",
"part": "whole"
},
"id": "4b7dd67b-6927-496e-a78c-af9cd86e6d2d"
}
}
},
"f3287480-36ed-4944-9f12-360fb4abaece": {
"id": "f3287480-36ed-4944-9f12-360fb4abaece",
"prev": "57c428c5-e200-4745-be5e-ac71b6c75514",
"regions": {
"1e581c09-72b4-489d-b14a-b55cf354bd10": {
"attrs": {
"height": 0.8,
"width": 0.8,
"x": 0.1,
"y": 0.1
},
"content": {
"cell": "dbfdd33a-5547-432d-944d-59611ba914b5",
"part": "whole"
},
"id": "1e581c09-72b4-489d-b14a-b55cf354bd10"
}
}
}
},
"themes": {}
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment