<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 # Table of Contents
<div class="toc" style="margin-top
Step1:  Hi this is normal text
It can contain raw input text djdasjdaos
It can contain markdown formatted text
Step3:  We can define functions and call them later
Step4:  The output can be suppressed adding a ";" at the end of the command, e.g.
Step5:  Text formatting is very handy. It is based on Markdown directives, see here a useful cheatsheet.
Markdown allows you to write even LaTex text, which enables a nice way of presenting results.
In the example above we assumed a sinusoidal signal defined as
Step6:  Better with "?" or "??" at the end
Step7:  Embedding plots
These are the typical init lines to get plots embedded.
matplotlib is one choice among many libraries. 
(A future code corner could cover plotting libraries
Step8:  Let's plot!
Step9:  Jupyter magics
Step11:  Example
Step12:  You can time any function by simply using the %%timeit magic
Step13:  Warning
Step14:  Executing code other than Python
You can also execute single bash lines prepending a "!"
Step15:  or more compicated bash scripts as
Step17:  Widgets
iPython widgets are nice and simple tools to produce interactive data presentations.
Detailed documentation with examples here
<ASSISTANT_TASK:>
Python Code:
x=5
print(x)
Explanation: # Table of Contents
<div class="toc" style="margin-top: 1em;"><ul class="toc-item" id="toc-level0"><li><span><a href="http://localhost:8888/notebooks/2017_10_17_CC01_Intro_Jupyter.ipynb#Welcome-to-the-IoA-Code-Corners!" data-toc-modified-id="Welcome-to-the-IoA-Code-Corners!-1"><span class="toc-item-num">1&nbsp;&nbsp;</span>Welcome to the IoA Code Corners!</a></span><ul class="toc-item"><li><span><a href="http://localhost:8888/notebooks/2017_10_17_CC01_Intro_Jupyter.ipynb#This-is-a-Jupyter-notebook!" data-toc-modified-id="This-is-a-Jupyter-notebook!-1.1"><span class="toc-item-num">1.1&nbsp;&nbsp;</span>This is a Jupyter notebook!</a></span><ul class="toc-item"><ul class="toc-item"><li><span><a href="http://localhost:8888/notebooks/2017_10_17_CC01_Intro_Jupyter.ipynb#Code-inspection:-docstrings" data-toc-modified-id="Code-inspection:-docstrings-1.1.0.1"><span class="toc-item-num">1.1.0.1&nbsp;&nbsp;</span>Code inspection: docstrings</a></span></li></ul></ul></li><li><span><a href="http://localhost:8888/notebooks/2017_10_17_CC01_Intro_Jupyter.ipynb#Embedding-plots" data-toc-modified-id="Embedding-plots-1.2"><span class="toc-item-num">1.2&nbsp;&nbsp;</span>Embedding plots</a></span></li></ul></li><li><span><a href="http://localhost:8888/notebooks/2017_10_17_CC01_Intro_Jupyter.ipynb#Jupyter-magics" data-toc-modified-id="Jupyter-magics-2"><span class="toc-item-num">2&nbsp;&nbsp;</span>Jupyter magics</a></span><ul class="toc-item"><ul class="toc-item"><li><span><a href="http://localhost:8888/notebooks/2017_10_17_CC01_Intro_Jupyter.ipynb#Example:-%%timeit" data-toc-modified-id="Example:-%%timeit-2.0.1"><span class="toc-item-num">2.0.1&nbsp;&nbsp;</span>Example: <code>%%timeit</code></a></span><ul class="toc-item"><li><span><a href="http://localhost:8888/notebooks/2017_10_17_CC01_Intro_Jupyter.ipynb#Another-useful-helper-func:-whos" data-toc-modified-id="Another-useful-helper-func:-whos-2.0.1.1"><span class="toc-item-num">2.0.1.1&nbsp;&nbsp;</span>Another useful helper func: <code>whos</code></a></span></li></ul></li><li><span><a href="http://localhost:8888/notebooks/2017_10_17_CC01_Intro_Jupyter.ipynb#Executing-code-other-than-Python" data-toc-modified-id="Executing-code-other-than-Python-2.0.2"><span class="toc-item-num">2.0.2&nbsp;&nbsp;</span>Executing code other than Python</a></span></li></ul><li><span><a href="http://localhost:8888/notebooks/2017_10_17_CC01_Intro_Jupyter.ipynb#Widgets" data-toc-modified-id="Widgets-2.1"><span class="toc-item-num">2.1&nbsp;&nbsp;</span>Widgets</a></span></li><li><span><a href="http://localhost:8888/notebooks/2017_10_17_CC01_Intro_Jupyter.ipynb#Extensions" data-toc-modified-id="Extensions-2.2"><span class="toc-item-num">2.2&nbsp;&nbsp;</span>Extensions</a></span><ul class="toc-item"><li><span><a href="http://localhost:8888/notebooks/2017_10_17_CC01_Intro_Jupyter.ipynb#Extension-example:-table-of-Content" data-toc-modified-id="Extension-example:-table-of-Content-2.2.1"><span class="toc-item-num">2.2.1&nbsp;&nbsp;</span>Extension example: table of Content</a></span></li></ul></li></ul></li></ul></div>
Welcome to the IoA Code Corners!
 17 Oct 2017 
Idea: 30-45 weekly informal meeting to share coding knowledge and expertise, via:
tutorials
code demonstrations
discussions
When: Tuesdays at 15:00. (except today and next week: 16:00)
Where: Hoyle Committee Room (HCR)
Organized by: Marco Tazzari, Matt Auger, Davide Fiacconi
Code Corners are driven by your interests: 
If you would like to present something (e.g., to give a code demonstration), please e-mail us
All the contents presented/discussed here will be uploaded to the github repository https://github.com/IoA-coding/codecorners
Suggestions for future topics are very welcome! Post them as issues on the github repository!
We also have a Google Calendar here.
This is a Jupyter notebook!
End of explanation
import numpy as np
Explanation: Hi this is normal text
It can contain raw input text djdasjdaos
It can contain markdown formatted text::
x = 5
y = sum(x
It can contain code:
End of explanation
def sin_signal(t, omega=0.1, t0=0.):
    A sinusoidal signal
    signal = np.sin(omega * (t-t0))
    return signal
# let's try
t = np.linspace(0., 100., 10)
# The output of the last entry in a cell gets printed
sin_signal(t)
# Sometimes, the output is too much..
sin_signal(np.linspace(0., 100., 1000))
Explanation: We can define functions and call them later:
End of explanation
sin_signal(np.linspace(0., 100., 1000));
Explanation: The output can be suppressed adding a ";" at the end of the command, e.g.:
End of explanation
np.histogram
Explanation: Text formatting is very handy. It is based on Markdown directives, see here a useful cheatsheet.
Markdown allows you to write even LaTex text, which enables a nice way of presenting results.
In the example above we assumed a sinusoidal signal defined as:
$$
f(t) = sin(\omega (t-t_0))
$$
where $t$ (s) is time, $\omega$ (rad/s) is frequency, and $t_0$ (s) is the initial offset.
Learn shortcuts: CMD+Shift+P is your friend! 
Code inspection: docstrings
To inspect that a function does, you can print it, but the output is not very informative:
End of explanation
np.histogram?
# or ?np.histogram
np.histogram??
Explanation: Better with "?" or "??" at the end
End of explanation
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
mpl.rcParams['figure.figsize'] = (8,5)
mpl.rcParams['font.size'] = 18
Explanation: Embedding plots
These are the typical init lines to get plots embedded.
matplotlib is one choice among many libraries. 
(A future code corner could cover plotting libraries: interested?)
End of explanation
%%writefile plot.py
t = np.linspace(0., 100., 1000)
plt.plot(t, sin_signal(t))
plt.plot(t, sin_signal(t, omega=0.2))
# plt.plot(t, signal(t, omega=0.2, t0=-15))
plt.xlabel("Time (t)")
plt.ylabel("Signal")
plt.savefig("figure.png")
%pycat plot.py
Explanation: Let's plot!
End of explanation
## Jupyter magics
# This will list all magic commands
%lsmagic
Explanation: Jupyter magics
End of explanation
def sum_py(x):
    A not very smart sum function
    N = len(x)
    sum = 0
    for i in range(N):
        sum += x[i]
    return sum
Explanation: Example: %%timeit
End of explanation
N = 1000
%%timeit
sum_py(np.arange(N, dtype='float64'))
N = 100000
%%timeit
sum_py(np.arange(N, dtype='float64'))
Explanation: You can time any function by simply using the %%timeit magic:
End of explanation
whos
%who function
Explanation: Warning: all the variables and functions that you defined in the notebook are retained in memory in the same namespace.
Sometimes this makes debuggin rather tricky, but whos comes in our rescue: it shows all the defined objects variables, functions,...
Another useful helper func: whos
End of explanation
! ls .
Explanation: Executing code other than Python
You can also execute single bash lines prepending a "!":
End of explanation
%%bash
for i in `seq 1 10`;
    do
            echo $i
    done 
Explanation: or more compicated bash scripts as:
End of explanation
from ipywidgets import interactive
def f(m, b):
    plt.figure(2)
    x = np.linspace(-10, 10, num=1000)
    plt.plot(x, m * x + b)
    plt.ylim(-5, 5)
    plt.show()
interactive_plot = interactive(f, m=(-2.0, 2.0), b=(-3, 3, 0.5))
output = interactive_plot.children[-1]
output.layout.height = '350px'
interactive_plot
def sin_signal(omega=0.1, t0=0.):
    A sinusoidal signal
    
    N = 10000
    t = np.linspace(0., 100., N)
    signal = np.sin(omega * (t-t0))
    plt.plot(t, signal)
    plt.show()
    return 
interactive_plot2 = interactive(sin_signal, omega=(0, 1, 0.1), t0=(-30, 30, 0.5))
output = interactive_plot2.children[-1]
output.layout.height = '350px'
interactive_plot2
Explanation: Widgets
iPython widgets are nice and simple tools to produce interactive data presentations.
Detailed documentation with examples here: https://ipywidgets.readthedocs.io/en/stable/index.html
End of explanation
<END_TASK>