Python --> IPython --> (IPython) Notebook

What, Why ?

  • Python = language interpreter
  • IPython = enhanced interaction, shortcuts, ..
  • IPython notebook = html frontend + protocol
  • Jupyter notebook = language independent interface
    • multiple backends: python, julia, R, Haskell, Ruby, bash, ....

In [ ]:
## Let's have a short look at the IPython web site:
from IPython.display import display, Image, HTML
HTML('<iframe src=http://ipython.org width=1000 height=400> </iframe>')

Das ist eine Demozelle

$ \int_{a}^{b} f(x) dx $


In [ ]:
40 + 90

computing backend (e.g. IPython) + Notebook

--> Importance for us (and scientists) ?

Jim Gray et al. "Scientific Data Management in the coming Decade" (2005)

"The goal is a smart notebook that empowers scientists to explore the world’s data. Science data centers with computational resources to explore huge data archives will be central to enabling such notebooks. Because data is so large, and IO bandwidth is not keeping pace, moving code to data will be essential to performance. Consequently, science centers will remain the core vehicle and federations will likely be secondary. Science centers will provide both the archives and the institutional infrastructure to develop these peta-scale archives and the algorithms and tools to analyze them."

"Smart notebooks" + scientific toolboxes + (meta-)data --> open science

The Notebook Interface


In [ ]:
HTML('<iframe src=http://nbviewer.ipython.org/github/ipython/ipython-in-depth/blob/master/examples/Notebook/What%20is%20the%20IPython%20Notebook.ipynb width=1000 height=600></iframe>')

Remark: This presentation is an interactive notebook document !!Generation of presentations from notebooks:

this notebook:

  • !jupyter nbconvert --to slides/html/pdf (via latex) ..

Researchers View: "Toolbox"


In [ ]:
HTML("""<iframe 
     src=http://www.nature.com/news/my-digital-toolbox-climate-scientist-damien-irving-on-python-libraries-1.16805 
     width=1000 height=600>
     </iframe>""")

From his Blog post (https://drclimate.wordpress.com/2014/10/30/software-installation-explained/): ...
The software installation problem is a source of frustration for all of us and is a key roadblock on the path to open science, so it’s great that solutions like Binstar are starting to pop up. ...

--> siehe die TGIF Vorträge von Carsten zu conda und binstar ..

Generating Publications (or addons containing reproducable code) from Notebooks:

Nature has a news item about IPython notebook http://www.nature.com/news/interactive-notebooks-sharing-the-code-1.16261 accompanied by live sample notebook: http://www.nature.com/news/ipython-interactive-demo-7.21492


In [ ]:
HTML("""<iframe
          src=http://www.nature.com/news/interactive-notebooks-sharing-the-code-1.16261
          width=1000 height=400>
     </iframe>""")

Rich syntactic cells:

This is rich text with links, equations:

$$\hat{f}(\xi) = \int_{-\infty}^{+\infty} f(x)\, \mathrm{e}^{-i \xi x}$$

code with syntax highlighting:

print("Hello world!")

and images:

Some example cells


In [ ]:
%lsmagic

In [ ]:
from IPython.display import HTML, SVG
HTML('''
         <table style="border: 2px solid black;">
         ''' + 
         ''.join(['<tr>' + 
                  ''.join(['<td>{row},{col}</td>'.format(
                                 row=row, col=col
                                 ) for col in range(5)]) +
                  '</tr>' for row in range(5)]) +
         '''
         </table>
         ''')

Interactive widgets: Example


In [ ]:
from ipywidgets import interact
import matplotlib.pyplot as plt
import networkx as nx
%matplotlib inline

In [ ]:
# wrap a few graph generation functions so they have the same signature

def random_lobster(n, m, k, p):
    return nx.random_lobster(n, p, p / m)

def powerlaw_cluster(n, m, k, p):
    return nx.powerlaw_cluster_graph(n, m, p)

def erdos_renyi(n, m, k, p):
    return nx.erdos_renyi_graph(n, p)

def newman_watts_strogatz(n, m, k, p):
    return nx.newman_watts_strogatz_graph(n, k, p)

def plot_random_graph(n, m, k, p, generator):
    g = generator(n, m, k, p)
    nx.draw(g)
    plt.show()

In [ ]:
interact(plot_random_graph, n=(2,30), m=(1,10), k=(1,10), p=(0.0, 1.0, 0.001),
        generator={'lobster': random_lobster,'power law': powerlaw_cluster,
                   'Newman-Watts-Strogatz': newman_watts_strogatz,u'Erdős-Rényi': erdos_renyi,});

In [ ]: