jmquintana79
6/24/2016 - 5:18 AM

## Jupyter Usage

Jupyter Notebook / Lab usage: tools, commands

### IMPORT FUNCTIONS OF ipython SCRIPTS ###
# ref: https://stackoverflow.com/questions/19564625/how-can-i-import-from-another-ipython-notebook

# repository script
def f(x):
print(x)

# main script
import nbimporter
import repository as repo
repo.f('Hola mundo')

### Linking other ipynb files like libraries ###

### DEBUGGING-Library pdb ###
# commands: https://rukbottoland.com/blog/como-utilizar-pdb-el-debugger-de-python/

x = 0
for i in range(10):
import pdb; pdb.set_trace()
x = i*2

# typing "n" or "next" pass to the next line
# typing the value of any variable display the current value
## reference: http://ipython.readthedocs.io/en/stable/interactive/magics.html

## ipynb to py usage
# it is necessary run using "ipython", comment "%matplotlib inline" and add:
from IPython import get_ipython

## display inside of notebook browser
%matplotlib inline

## list magic commands available
%%lsmagic

### run / import notebook in another notebook ##
%run <<notebook.ipynb>>

### run bash commands in a cell ###
%%bash
ls -la

### run latex commands in a cell ###
%%latex
# Maxwell Equations
\begin{aligned}
\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{aligned}

### amount of time needed to run the cell ###
%%time
# or
%%timeit

### amount of time needed to run a sentence ###
%timeit <<sentence>>

### create alias for bash commands ###
%alias bracket echo "Input in brackets: <%l>"
bracket 'hello world'
#[out]: Input in brackets: <hello world>

### HELP
# f -> any function, variable or object
help(f) # basic information
f?      # basic information
f??     # basic information and source