<jupyter_start><jupyter_text>"Jupyter notebooks for remote science"> "Using Jupyter notebooks for remote science"- toc: true - badges: false- comments: false Computational notebooks have massively gained in popularity in the past years. They allow to share rich documents with text, code, mathematical formulas, images, videos etc. both in static and interactive ways. They are heavily used both in research to document projects and in teaching to provide content support. Notebooks exist in different flavors, but currently the most popular form is the Jupyter (**Ju**lia, **Py**thon, **R**) notebook. Here, we briefly describe  1. [What type of content they can be used for](1.-What-is-a-notebook), 2. [Solutions to write/run notebooks online (no installation required)](2.-Using-Jupyter-notebooks), 3. [How to share the documents, interactively or not and](3.-Sharing-documents) 4. [A few examples of courses given as notebooks](4.-Examples-of-courses).  1. What is a notebookNotebooks are interactive documents with rich content that run directly in the internet browser. They are composed of series of blocks, called cells that can be executed individually. Notebooks are typically used when computer coding is involved but they provide a rich environment to create interactive documentation in general. So even if you don't need the coding part, you can still use notebooks to create documents and use the many existing resources to share them. Notebooks are composed of mainly two types of cells: text cells and code cells. Text cells MarkdownThe content of text cells is formatted using the Markdown language, a very simple markup language allowing to create formatted text. For example *italic* and **bold** are generated by surrounding text with one ```*italic*```or two stars ```**bold**```. Titles and subtitles are generated by preceding text by a series of hash signs ``` My Title```, ``` My subtitle```. ImagesImages can be embedded using either a simple markdown syntax ```![](myimage)``` or directly html language which can be customized (e.g. for image size) `````` where ```myimage``` is a path or a weblink to an image (e.g. https://img.myswitzerland.com/671846/407):![](https://img.myswitzerland.com/671846/407) EquationsFortunately, Jupyter also allows to embed $\LaTeX$ text. There a multiple solutions for this: surround your equation $\vec F = m*\vec{a}$ with dollar signs ```$\vec F = m*\vec{a}$```, use double dollar ```$$\vec F = m*\vec{a}$$``` to create a block:$$\vec F = m*\vec{a}$$or in a separate cell use the standard ```\begin{equation} ... \end{equation}```: \begin{equation}\vec F = m*\vec{a}\end{equation}  Code cells Computational codeThe most common type of code cell, is a cell with actual computational code demonstrating some algorithm or function. It has an input and if some output is generated also an output cell:<jupyter_code>def my_fun(x):
    y = x**2 + 3*x + 2
    return y

my_fun(5)<jupyter_output><empty_output><jupyter_text>Not only numerical calculations are possible but also symbolic ones, e.g. using sympy:<jupyter_code>import sympy
import warnings
warnings.filterwarnings("ignore")
from ipywidgets import interact, FloatSlider
import numpy as np
import matplotlib.pyplot as plt

t, k, c, y_0, ydot_0 = sympy.symbols('t k c y_0 ydot_0')
y = sympy.Function('y')
damped_oscillator = sympy.Eq(y(t).diff(t, t) + c* y(t).diff(t) + k*y(t), 0)
fun_solved = sympy.dsolve(damped_oscillator, y(t), ics={y(0):y_0, y(t).diff(t,1).subs(t, 0): ydot_0})
damped_oscillator
fun_solved<jupyter_output><empty_output><jupyter_text>Output codeCode cells can however also be used to display interactive content, in particular the output of an analysis e.g. with Matplotlib:<jupyter_code>plt.plot(np.arange(-10,11),my_fun(np.arange(-10,11)));<jupyter_output><empty_output><jupyter_text>Results can also be shown as interactive plots which the user can play with to get an intuition:<jupyter_code>def myfun(var):
    solved = fun_solved.subs({y_0:1, ydot_0:0, k:var, c : 1})
    sympy.plot(solved.rhs,ylim = (-1,1),xlim = (0,10));
interact(myfun, var = FloatSlider(min=1, max = 10,step = .5));<jupyter_output><empty_output><jupyter_text>Multimedia outputIn addition to these standard ways of showing code, Jupyter can also be used to display other types of information. For example a movie uploaded from Youtube:<jupyter_code>from IPython.display import YouTubeVideo
YouTubeVideo("6FZ5k9_6Vlw",560,rel=0)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10651152383083463, 'fraction_numerical': 0.015887223092414412, 'mean_word_length': 5.431654676258993, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '380141', 'license': 'Apache-2.0', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1321, 'n_words': 547, 'path': '_notebooks/2020-03-23-Jupyter-in-remote-times.ipynb', 'repo_name': 'guiwitz/blog', 'size': '4469'}