Jupyter notebook

Sposoby interakcji z programem komputerowym:

  • terminal tekstowy
  • GUI
  • notatnik (NEW!)

Jupyter

Środowisko typu "notatnik"

Notatnik:

  • Dokument
  • Środowisko
  • Aplikacja "sieciowa"

Jupyterhub

alfa - jupyterhub @ UŚ

adres: http://alfa.smcebi.us.edu.pl

Wymaga współczesnej przeglądarki internetowej.

Informacje:

Jupyter notebook

  • komórki tekstowe (markdown cells) - przykład
  • komórki z kodem (code cells)
  • kernel - czyli jądro obsługuje komórki z kodem
  • lista kerneli (jąder) jest długa....

system $\LaTeX$:

\begin{align} \nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\ \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\ \nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\ \nabla \cdot \vec{\mathbf{B}} & = 0 \end{align}

Markdown

asdfa sdfa sdf adf df asdf asfd s

  • asdf asdf
  • asd fas f
  • asd fa
  1. a dsfa
  2. asd fa
  3. sadf asd

In [ ]:


In [3]:
for i in range(4):
    print(i)


0
1
2
3

In [4]:
%matplotlib notebook
import matplotlib.pyplot as plt
import numpy as np

In [5]:
X = np.linspace(-np.pi, np.pi, 656)
F = np.sin(1/(X**2+0.07))
plt.plot(X,F)


Out[5]:
[<matplotlib.lines.Line2D at 0x7fcdb69d2748>]

widgets


In [9]:
from ipywidgets import interact
def f(x):
    print(x)

interact(f, x=10);


7

In [22]:
from ipywidgets import widgets
w = widgets.IntSlider(min=0,max=10,value=3,step=1,width="430px")

In [24]:
w

In [25]:
w.value


Out[25]:
8

In [28]:
w.value = 4

Notebook magics

Komórki zaczynające się od

  • "%" - line magics
  • "%%" - cell magics

Line magics - przykład


In [29]:
from  math import sin,cos
%timeit sin(cos(sin(1.23)))


The slowest run took 30.38 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 173 ns per loop

In [30]:
import numpy as np 
%timeit np.sum(np.sin(np.random.randn(int(1e6))))


10 loops, best of 3: 73.7 ms per loop

In [14]:
%timeit np.sum(np.sin(np.random.randn(int(1e6))))


10 loops, best of 3: 72.2 ms per loop

In [31]:
%time np.sum(np.sin(np.random.randn(int(1e6))))


CPU times: user 76 ms, sys: 8 ms, total: 84 ms
Wall time: 81.6 ms
Out[31]:
-127.15000366106875

In [16]:
%%sh
pwd
for i in `ls`
do
 echo Plik: $i
done


/home/users/marcin.kostur/Jupyter_SMCEBI
Plik: Anim_gizeh_4fractallab.ipynb
Plik: Examples_pythreejs.ipynb
Plik: FAQ.ipynb
Plik: Images_in_jupyter.ipynb
Plik: Jupyter_intro-from0.ipynb
Plik: Jupyter_intro.ipynb
Plik: NBgrader
Plik: Untitled.ipynb
Plik: Untitled1.ipynb
Plik: Untitled2.ipynb
Plik: Untitled3.ipynb
Plik: a2ztutors.txt
Plik: async_tst.ipynb
Plik: blueradsquares.gif
Plik: chk_users.ipynb
Plik: circle.gif
Plik: demo_tests_etc.ipynb
Plik: movie.mp4
Plik: mpl_example.ipynb
Plik: numpy_speed.ipynb
Plik: program.py
Plik: rk_test.ipynb
Plik: update_dynamically_mpl_widget.ipynb
Plik: users_smcebi.ipynb
Plik: vpython.ipynb
Plik: wat.ipynb
Plik: what_is_jupyterhub.png
Plik: yingyang.gif

Widget callback przykład


In [32]:
from ipywidgets import widgets

In [33]:
w = widgets.Text()

In [34]:
w


OK uuu
OK uuuhh
OK ---- uuuhh
OK ---- uuuhh

In [37]:
def mojcallback(w):
    
    print("OK ----",w.value)
    
w.on_submit(mojcallback)

In [5]:
w.value = "dads"

In [ ]:


In [ ]: